< prev index next >

src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/GenerateJLIClassesPlugin.java

Print this page
rev 49207 : 8199471: Enable generation of callSiteForms at link time
Reviewed-by: TBD

*** 67,85 **** private static final String DMH_INVOKE_INTERFACE = "invokeInterface"; private static final String DMH_INVOKE_STATIC_INIT = "invokeStaticInit"; private static final String DELEGATING_HOLDER = "java/lang/invoke/DelegatingMethodHandle$Holder"; private static final String BASIC_FORMS_HOLDER = "java/lang/invoke/LambdaForm$Holder"; ! private static final String INVOKERS_HOLDER = "java/lang/invoke/Invokers$Holder"; private static final JavaLangInvokeAccess JLIA = SharedSecrets.getJavaLangInvokeAccess(); Set<String> speciesTypes = Set.of(); Set<String> invokerTypes = Set.of(); Map<String, Set<String>> dmhMethods = Map.of(); String mainArgument; public GenerateJLIClassesPlugin() { --- 67,92 ---- private static final String DMH_INVOKE_INTERFACE = "invokeInterface"; private static final String DMH_INVOKE_STATIC_INIT = "invokeStaticInit"; private static final String DELEGATING_HOLDER = "java/lang/invoke/DelegatingMethodHandle$Holder"; private static final String BASIC_FORMS_HOLDER = "java/lang/invoke/LambdaForm$Holder"; ! ! private static final String INVOKERS_HOLDER_NAME = "java.lang.invoke.Invokers$Holder"; ! private static final String INVOKERS_HOLDER_INTERNAL_NAME = INVOKERS_HOLDER_NAME.replace('.', '/'); ! ! private static final String INVOKERS_CS_HOLDER_NAME = "java.lang.invoke.Invokers$CSHolder"; ! private static final String INVOKERS_CS_HOLDER_INTERNAL_NAME = INVOKERS_CS_HOLDER_NAME.replace('.', '/'); private static final JavaLangInvokeAccess JLIA = SharedSecrets.getJavaLangInvokeAccess(); Set<String> speciesTypes = Set.of(); Set<String> invokerTypes = Set.of(); + Set<String> callSiteTypes = Set.of(); + Map<String, Set<String>> dmhMethods = Map.of(); String mainArgument; public GenerateJLIClassesPlugin() {
*** 207,216 **** --- 214,225 ---- // Use TreeSet/TreeMap to keep things sorted in a deterministic // order to avoid scrambling the layout on small changes and to // ease finding methods in the generated code speciesTypes = new TreeSet<>(speciesTypes); invokerTypes = new TreeSet<>(invokerTypes); + callSiteTypes = new TreeSet<>(callSiteTypes); + TreeMap<String, Set<String>> newDMHMethods = new TreeMap<>(); for (Map.Entry<String, Set<String>> entry : dmhMethods.entrySet()) { newDMHMethods.put(entry.getKey(), new TreeSet<>(entry.getValue())); } dmhMethods = newDMHMethods;
*** 227,238 **** } break; case "[LF_RESOLVE]": String methodType = parts[3]; validateMethodType(methodType); ! if (parts[1].contains("Invokers")) { invokerTypes.add(methodType); } else if (parts[1].contains("DirectMethodHandle")) { String dmh = parts[2]; // ignore getObject etc for now (generated // by default) if (DMH_METHOD_TYPE_MAP.containsKey(dmh)) { --- 236,249 ---- } break; case "[LF_RESOLVE]": String methodType = parts[3]; validateMethodType(methodType); ! if (parts[1].equals(INVOKERS_HOLDER_NAME)) { invokerTypes.add(methodType); + } else if (parts[1].equals(INVOKERS_CS_HOLDER_NAME)) { + callSiteTypes.add(methodType); } else if (parts[1].contains("DirectMethodHandle")) { String dmh = parts[2]; // ignore getObject etc for now (generated // by default) if (DMH_METHOD_TYPE_MAP.containsKey(dmh)) {
*** 292,305 **** public ResourcePool transform(ResourcePool in, ResourcePoolBuilder out) { initialize(in); // Copy all but DMH_ENTRY to out in.transformAndCopy(entry -> { // filter out placeholder entries ! if (entry.path().equals(DIRECT_METHOD_HOLDER_ENTRY) || ! entry.path().equals(DELEGATING_METHOD_HOLDER_ENTRY) || ! entry.path().equals(INVOKERS_HOLDER_ENTRY) || ! entry.path().equals(BASIC_FORMS_HOLDER_ENTRY)) { return null; } else { return entry; } }, out); --- 303,318 ---- public ResourcePool transform(ResourcePool in, ResourcePoolBuilder out) { initialize(in); // Copy all but DMH_ENTRY to out in.transformAndCopy(entry -> { // filter out placeholder entries ! String path = entry.path(); ! if (path.equals(DIRECT_METHOD_HOLDER_ENTRY) || ! path.equals(DELEGATING_METHOD_HOLDER_ENTRY) || ! path.equals(INVOKERS_HOLDER_ENTRY) || ! path.equals(INVOKERS_CS_HOLDER_ENTRY) || ! path.equals(BASIC_FORMS_HOLDER_ENTRY)) { return null; } else { return entry; } }, out);
*** 359,385 **** directMethodTypes[index] = mt.dropParameterTypes(0, 1); dmhTypes[index] = DMH_METHOD_TYPE_MAP.get(dmhType); index++; } } MethodType[] invokerMethodTypes = new MethodType[this.invokerTypes.size()]; int i = 0; for (String invokerType : invokerTypes) { - // The invoker type to ask for is retrieved by removing the first - // and the last argument, which needs to be of Object.class MethodType mt = asMethodType(invokerType); final int lastParam = mt.parameterCount() - 1; if (mt.parameterCount() < 2 || mt.parameterType(0) != Object.class || mt.parameterType(lastParam) != Object.class) { throw new PluginException( ! "Invoker type parameter must start and end with L"); } mt = mt.dropParameterTypes(lastParam, lastParam + 1); invokerMethodTypes[i] = mt.dropParameterTypes(0, 1); i++; } try { byte[] bytes = JLIA.generateDirectMethodHandleHolderClassBytes( DIRECT_HOLDER, directMethodTypes, dmhTypes); ResourcePoolEntry ndata = ResourcePoolEntry .create(DIRECT_METHOD_HOLDER_ENTRY, bytes); --- 372,415 ---- directMethodTypes[index] = mt.dropParameterTypes(0, 1); dmhTypes[index] = DMH_METHOD_TYPE_MAP.get(dmhType); index++; } } + + // The invoker type to ask for is retrieved by removing the first + // and the last argument, which needs to be of Object.class MethodType[] invokerMethodTypes = new MethodType[this.invokerTypes.size()]; int i = 0; for (String invokerType : invokerTypes) { MethodType mt = asMethodType(invokerType); final int lastParam = mt.parameterCount() - 1; if (mt.parameterCount() < 2 || mt.parameterType(0) != Object.class || mt.parameterType(lastParam) != Object.class) { throw new PluginException( ! "Invoker type parameter must start and end with Object: " + invokerType); } mt = mt.dropParameterTypes(lastParam, lastParam + 1); invokerMethodTypes[i] = mt.dropParameterTypes(0, 1); i++; } + + // The callSite type to ask for is retrieved by removing the last + // argument, which needs to be of Object.class + MethodType[] callSiteMethodTypes = new MethodType[this.callSiteTypes.size()]; + i = 0; + for (String callSiteType : callSiteTypes) { + MethodType mt = asMethodType(callSiteType); + final int lastParam = mt.parameterCount() - 1; + if (mt.parameterCount() < 1 || + mt.parameterType(lastParam) != Object.class) { + throw new PluginException( + "CallSite type parameter must end with Object: " + callSiteType); + } + callSiteMethodTypes[i] = mt.dropParameterTypes(lastParam, lastParam + 1); + i++; + } try { byte[] bytes = JLIA.generateDirectMethodHandleHolderClassBytes( DIRECT_HOLDER, directMethodTypes, dmhTypes); ResourcePoolEntry ndata = ResourcePoolEntry .create(DIRECT_METHOD_HOLDER_ENTRY, bytes);
*** 388,402 **** bytes = JLIA.generateDelegatingMethodHandleHolderClassBytes( DELEGATING_HOLDER, directMethodTypes); ndata = ResourcePoolEntry.create(DELEGATING_METHOD_HOLDER_ENTRY, bytes); out.add(ndata); ! bytes = JLIA.generateInvokersHolderClassBytes(INVOKERS_HOLDER, invokerMethodTypes); ndata = ResourcePoolEntry.create(INVOKERS_HOLDER_ENTRY, bytes); out.add(ndata); bytes = JLIA.generateBasicFormsClassBytes(BASIC_FORMS_HOLDER); ndata = ResourcePoolEntry.create(BASIC_FORMS_HOLDER_ENTRY, bytes); out.add(ndata); } catch (Exception ex) { throw new PluginException(ex); --- 418,437 ---- bytes = JLIA.generateDelegatingMethodHandleHolderClassBytes( DELEGATING_HOLDER, directMethodTypes); ndata = ResourcePoolEntry.create(DELEGATING_METHOD_HOLDER_ENTRY, bytes); out.add(ndata); ! bytes = JLIA.generateInvokersHolderClassBytes(INVOKERS_HOLDER_INTERNAL_NAME, invokerMethodTypes); ndata = ResourcePoolEntry.create(INVOKERS_HOLDER_ENTRY, bytes); out.add(ndata); + bytes = JLIA.generateCallSiteHolderClassBytes(INVOKERS_CS_HOLDER_INTERNAL_NAME, + callSiteMethodTypes); + ndata = ResourcePoolEntry.create(INVOKERS_CS_HOLDER_ENTRY, bytes); + out.add(ndata); + bytes = JLIA.generateBasicFormsClassBytes(BASIC_FORMS_HOLDER); ndata = ResourcePoolEntry.create(BASIC_FORMS_HOLDER_ENTRY, bytes); out.add(ndata); } catch (Exception ex) { throw new PluginException(ex);
*** 407,417 **** private static final String DELEGATING_METHOD_HOLDER_ENTRY = "/java.base/" + DELEGATING_HOLDER + ".class"; private static final String BASIC_FORMS_HOLDER_ENTRY = "/java.base/" + BASIC_FORMS_HOLDER + ".class"; private static final String INVOKERS_HOLDER_ENTRY = ! "/java.base/" + INVOKERS_HOLDER + ".class"; // Convert LL -> LL, L3 -> LLL public static String expandSignature(String signature) { StringBuilder sb = new StringBuilder(); char last = 'X'; --- 442,454 ---- private static final String DELEGATING_METHOD_HOLDER_ENTRY = "/java.base/" + DELEGATING_HOLDER + ".class"; private static final String BASIC_FORMS_HOLDER_ENTRY = "/java.base/" + BASIC_FORMS_HOLDER + ".class"; private static final String INVOKERS_HOLDER_ENTRY = ! "/java.base/" + INVOKERS_HOLDER_INTERNAL_NAME + ".class"; ! private static final String INVOKERS_CS_HOLDER_ENTRY = ! "/java.base/" + INVOKERS_CS_HOLDER_INTERNAL_NAME + ".class"; // Convert LL -> LL, L3 -> LLL public static String expandSignature(String signature) { StringBuilder sb = new StringBuilder(); char last = 'X';
< prev index next >