java.lang.Object
java.lang.runtime.TemplateRuntime
TemplateRuntime is a preview API of the Java platform.Programs can only use
TemplateRuntime when preview features are enabled.Preview features may be removed in a future release, or upgraded to permanent features of the Java platform.
Manages string template bootstrap methods. These methods may be used, for example, by Java compiler implementations to create to byte code that invokes the If the string template requires more than to byte code that invokes the
StringTemplatePREVIEW instances. For example, the java compiler will translate the following code;int x = 10;int y = 20;StringTemplate st = RAW."\{x} + \{y} = \{x + y}";newStringTemplate(java.lang.invoke.MethodHandles.Lookup, java.lang.String, java.lang.invoke.MethodType, java.lang.String...) bootstrap method to construct aCallSite that accepts two integers and produces a newStringTemplatePREVIEW instance.MethodHandles.Lookup lookup = MethodHandles.lookup();MethodType mt = MethodType.methodType(StringTemplate.class, int.class, int.class);CallSite cs = TemplateRuntime.newStringTemplate(lookup, "", mt, "", " + ", " = ", "");...int x = 10;int y = 20;StringTemplate st = (StringTemplate)cs.getTarget().invokeExact(x, y);StringConcatFactory.MAX_INDY_CONCAT_ARG_SLOTSPREVIEW value slots, then the java compiler will use thenewLargeStringTemplate(java.lang.invoke.MethodHandles.Lookup, java.lang.String, java.lang.invoke.MethodType) bootstrap method instead. For example, the java compiler will translate the following code;int[] a = new int[1000], b = new int[1000];...StringTemplate st = """ \{a[0]} - \{b[0]} \{a[1]} - \{b[1]} ... \{a[999]} - \{b[999]} """;newLargeStringTemplate(java.lang.invoke.MethodHandles.Lookup, java.lang.String, java.lang.invoke.MethodType) bootstrap method to construct aCallSite that accepts an array of integers and produces a newStringTemplatePREVIEW instance.MethodType mt = MethodType.methodType(StringTemplate.class, String[].class, Object[].class);CallSite cs = TemplateRuntime.newStringTemplate(lookup, "", mt);...int[] a = new int[1000], b = new int[1000];...StringTemplate st = (StringTemplate)cs.getTarget().invokeExact( new String[] { "", " - ", "\n", " - ", "\n", ... " - ", "\n" }, new Object[] { a[0], b[0], a[1], b[1], ..., a[999], b[999]} );- Since:
- 21
Method Summary
Modifier and TypeMethodDescriptionstaticCallSitenewLargeStringTemplate(MethodHandles.Lookup lookup,String name,MethodType type) String template bootstrap method for creating large string templates, i.e., when the number of value slots exceedsStringConcatFactory.MAX_INDY_CONCAT_ARG_SLOTSPREVIEW.staticCallSitenewStringTemplate(MethodHandles.Lookup lookup,String name,MethodType type,String... fragments) String template bootstrap method for creating string templates.staticCallSiteprocessStringTemplate(MethodHandles.Lookup lookup,String name,MethodType type,MethodHandle processorGetter,String... fragments) String template bootstrap method for static final processors.
Method Details
newStringTemplate
public static CallSite newStringTemplate(MethodHandles.Lookup lookup,String name,MethodType type,String... fragments) throwsThrowable String template bootstrap method for creating string templates. The static arguments include the fragments list. The non-static arguments are the values.- Parameters:
lookup- method lookup from call sitename- method name - not usedtype- method type (ptypes...) -> StringTemplatefragments- fragment array for string template- Returns:
CallSiteto handle create string template- Throws:
NullPointerException- if any of the arguments is nullThrowable- if linkage fails
newLargeStringTemplate
public static CallSite newLargeStringTemplate(MethodHandles.Lookup lookup,String name,MethodType type) throwsThrowable String template bootstrap method for creating large string templates, i.e., when the number of value slots exceedsStringConcatFactory.MAX_INDY_CONCAT_ARG_SLOTSPREVIEW. The non-static arguments are the fragments array and values array.- Parameters:
lookup- method lookup from call sitename- method name - not usedtype- method type (String[], Object[]) -> StringTemplate- Returns:
CallSiteto handle create large string template- Throws:
NullPointerException- if any of the arguments is nullThrowable- if linkage fails
processStringTemplate
public static CallSite processStringTemplate(MethodHandles.Lookup lookup,String name,MethodType type,MethodHandle processorGetter,String... fragments) throwsThrowable String template bootstrap method for static final processors. The static arguments include the fragments array and aMethodHandleto retrieve the value of the static final processor. The non-static arguments are the values.- Implementation Note:
- this method is likely to be revamped before exiting preview.
- Parameters:
lookup- method lookup from call sitename- method name - not usedtype- method type (ptypes...) -> ObjectprocessorGetter-MethodHandleto get static final processorfragments- fragments from string template- Returns:
CallSiteto handle string template processing- Throws:
NullPointerException- if any of the arguments is nullThrowable- if linkage fails