src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/graphbuilderconf/InvocationPlugins.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File hotspot Cdiff src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/graphbuilderconf/InvocationPlugins.java

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/graphbuilderconf/InvocationPlugins.java

Print this page

        

*** 28,52 **** import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.lang.reflect.Type; import java.util.ArrayList; import java.util.Arrays; - import java.util.Collections; - import java.util.HashMap; - import java.util.HashSet; import java.util.List; import java.util.Map; - import java.util.Set; - import org.graalvm.compiler.api.replacements.MethodSubstitution; import org.graalvm.compiler.api.replacements.MethodSubstitutionRegistry; import org.graalvm.compiler.bytecode.BytecodeProvider; import org.graalvm.compiler.debug.GraalError; import org.graalvm.compiler.graph.Node; import org.graalvm.compiler.graph.iterators.NodeIterable; import org.graalvm.compiler.nodes.ValueNode; import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver; import jdk.vm.ci.meta.MetaAccessProvider; import jdk.vm.ci.meta.MetaUtil; import jdk.vm.ci.meta.ResolvedJavaMethod; --- 28,51 ---- import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.lang.reflect.Type; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Map; import org.graalvm.compiler.api.replacements.MethodSubstitution; import org.graalvm.compiler.api.replacements.MethodSubstitutionRegistry; import org.graalvm.compiler.bytecode.BytecodeProvider; import org.graalvm.compiler.debug.GraalError; import org.graalvm.compiler.graph.Node; import org.graalvm.compiler.graph.iterators.NodeIterable; import org.graalvm.compiler.nodes.ValueNode; import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver; + import org.graalvm.util.Equivalence; + import org.graalvm.util.EconomicMap; + import org.graalvm.util.EconomicSet; + import org.graalvm.util.UnmodifiableMapCursor; import jdk.vm.ci.meta.MetaAccessProvider; import jdk.vm.ci.meta.MetaUtil; import jdk.vm.ci.meta.ResolvedJavaMethod;
*** 258,267 **** --- 257,286 ---- public void register5(String name, Type arg1, Type arg2, Type arg3, Type arg4, Type arg5, InvocationPlugin plugin) { plugins.register(plugin, false, allowOverwrite, declaringType, name, arg1, arg2, arg3, arg4, arg5); } /** + * Registers a plugin for a method with 6 arguments. + * + * @param name the name of the method + * @param plugin the plugin to be registered + */ + public void register6(String name, Type arg1, Type arg2, Type arg3, Type arg4, Type arg5, Type arg6, InvocationPlugin plugin) { + plugins.register(plugin, false, allowOverwrite, declaringType, name, arg1, arg2, arg3, arg4, arg5, arg6); + } + + /** + * Registers a plugin for a method with 7 arguments. + * + * @param name the name of the method + * @param plugin the plugin to be registered + */ + public void register7(String name, Type arg1, Type arg2, Type arg3, Type arg4, Type arg5, Type arg6, Type arg7, InvocationPlugin plugin) { + plugins.register(plugin, false, allowOverwrite, declaringType, name, arg1, arg2, arg3, arg4, arg5, arg6, arg7); + } + + /** * Registers a plugin for an optional method with no arguments. * * @param name the name of the method * @param plugin the plugin to be registered */
*** 335,348 **** * is non-static. Upon returning, element 0 will have been rewritten to * {@code declaringClass} */ @Override public void registerMethodSubstitution(Class<?> substituteDeclaringClass, String name, String substituteName, Type... argumentTypes) { assert methodSubstitutionBytecodeProvider != null : "Registration used for method substitutions requires a non-null methodSubstitutionBytecodeProvider"; MethodSubstitutionPlugin plugin = new MethodSubstitutionPlugin(methodSubstitutionBytecodeProvider, substituteDeclaringClass, substituteName, argumentTypes); ! plugins.register(plugin, false, allowOverwrite, declaringType, name, argumentTypes); } } /** * Key for a {@linkplain ClassPlugins#entries resolved} plugin registration. Due to the * possibility of class redefinition, we cannot directly use {@link ResolvedJavaMethod}s as --- 354,373 ---- * is non-static. Upon returning, element 0 will have been rewritten to * {@code declaringClass} */ @Override public void registerMethodSubstitution(Class<?> substituteDeclaringClass, String name, String substituteName, Type... argumentTypes) { + MethodSubstitutionPlugin plugin = createMethodSubstitution(substituteDeclaringClass, substituteName, argumentTypes); + plugins.register(plugin, false, allowOverwrite, declaringType, name, argumentTypes); + } + + public MethodSubstitutionPlugin createMethodSubstitution(Class<?> substituteDeclaringClass, String substituteName, Type... argumentTypes) { assert methodSubstitutionBytecodeProvider != null : "Registration used for method substitutions requires a non-null methodSubstitutionBytecodeProvider"; MethodSubstitutionPlugin plugin = new MethodSubstitutionPlugin(methodSubstitutionBytecodeProvider, substituteDeclaringClass, substituteName, argumentTypes); ! return plugin; } + } /** * Key for a {@linkplain ClassPlugins#entries resolved} plugin registration. Due to the * possibility of class redefinition, we cannot directly use {@link ResolvedJavaMethod}s as
*** 492,502 **** } } private final MetaAccessProvider metaAccess; ! private final Map<String, ClassPlugins> registrations = new HashMap<>(); /** * Deferred registrations as well as guard for initialization. The guard uses double-checked * locking which is why this field is {@code volatile}. */ --- 517,527 ---- } } private final MetaAccessProvider metaAccess; ! private final EconomicMap<String, ClassPlugins> registrations = EconomicMap.create(Equivalence.DEFAULT); /** * Deferred registrations as well as guard for initialization. The guard uses double-checked * locking which is why this field is {@code volatile}. */
*** 526,548 **** /** * Entry map that is initialized upon first call to {@link #get(ResolvedJavaMethod)}. * * Note: this must be volatile as threads may race to initialize it. */ ! private volatile Map<ResolvedJavaMethodKey, InvocationPlugin> entries; void initializeMap() { if (!isClosed()) { if (registrations.isEmpty()) { ! entries = Collections.emptyMap(); } else { Class<?> declaringClass = resolveType(declaringType, true); if (declaringClass == null) { // An optional type that could not be resolved ! entries = Collections.emptyMap(); } else { ! Map<ResolvedJavaMethodKey, InvocationPlugin> newEntries = new HashMap<>(); for (MethodKey methodKey : registrations) { ResolvedJavaMethod m = methodKey.resolve(declaringClass); if (m != null) { newEntries.put(new ResolvedJavaMethodKey(m), methodKey.value); if (entries != null) { --- 551,573 ---- /** * Entry map that is initialized upon first call to {@link #get(ResolvedJavaMethod)}. * * Note: this must be volatile as threads may race to initialize it. */ ! private volatile EconomicMap<ResolvedJavaMethodKey, InvocationPlugin> entries; void initializeMap() { if (!isClosed()) { if (registrations.isEmpty()) { ! entries = EconomicMap.create(Equivalence.DEFAULT); } else { Class<?> declaringClass = resolveType(declaringType, true); if (declaringClass == null) { // An optional type that could not be resolved ! entries = EconomicMap.create(Equivalence.DEFAULT); } else { ! EconomicMap<ResolvedJavaMethodKey, InvocationPlugin> newEntries = EconomicMap.create(Equivalence.DEFAULT); for (MethodKey methodKey : registrations) { ResolvedJavaMethod m = methodKey.resolve(declaringClass); if (m != null) { newEntries.put(new ResolvedJavaMethodKey(m), methodKey.value); if (entries != null) {
*** 563,573 **** } return entries.get(new ResolvedJavaMethodKey(method)); } public void register(MethodKey methodKey, boolean allowOverwrite) { ! assert !isClosed() : "registration is closed: " + methodKey + " " + Arrays.toString(entries.keySet().toArray()); if (allowOverwrite) { int index = registrations.indexOf(methodKey); if (index >= 0) { registrations.set(index, methodKey); return; --- 588,598 ---- } return entries.get(new ResolvedJavaMethodKey(method)); } public void register(MethodKey methodKey, boolean allowOverwrite) { ! assert !isClosed() : "registration is closed: " + methodKey; if (allowOverwrite) { int index = registrations.indexOf(methodKey); if (index >= 0) { registrations.set(index, methodKey); return;
*** 637,660 **** deferrable.run(); } deferredRegistrations = null; } } ! for (Map.Entry<String, ClassPlugins> e : registrations.entrySet()) { ! e.getValue().initializeMap(); } } } /** * Disallows new registrations of new plugins, and creates the internal tables for method * lookup. */ public void closeRegistration() { flushDeferrables(); ! for (Map.Entry<String, ClassPlugins> e : registrations.entrySet()) { ! e.getValue().initializeMap(); } } public int size() { return registrations.size(); --- 662,685 ---- deferrable.run(); } deferredRegistrations = null; } } ! for (ClassPlugins e : registrations.getValues()) { ! e.initializeMap(); } } } /** * Disallows new registrations of new plugins, and creates the internal tables for method * lookup. */ public void closeRegistration() { flushDeferrables(); ! for (ClassPlugins e : registrations.getValues()) { ! e.initializeMap(); } } public int size() { return registrations.size();
*** 692,702 **** String internalName = method.getDeclaringClass().getName(); ClassPlugins classPlugins = registrations.get(internalName); if (classPlugins == null) { classPlugins = new ClassPlugins(null); registrations.put(internalName, classPlugins); ! classPlugins.entries = new HashMap<>(); } classPlugins.entries.put(new ResolvedJavaMethodKey(method), plugin); } } --- 717,727 ---- String internalName = method.getDeclaringClass().getName(); ClassPlugins classPlugins = registrations.get(internalName); if (classPlugins == null) { classPlugins = new ClassPlugins(null); registrations.put(internalName, classPlugins); ! classPlugins.entries = EconomicMap.create(Equivalence.DEFAULT); } classPlugins.entries.put(new ResolvedJavaMethodKey(method), plugin); } }
*** 766,783 **** /** * Gets the set of methods for which invocation plugins have been registered. Once this method * is called, no further registrations can be made. */ ! public Set<ResolvedJavaMethod> getMethods() { ! Set<ResolvedJavaMethod> res = new HashSet<>(); if (parent != null) { res.addAll(parent.getMethods()); } flushDeferrables(); ! for (ClassPlugins cp : registrations.values()) { ! for (ResolvedJavaMethodKey key : cp.entries.keySet()) { res.add(key.method); } } return res; } --- 791,808 ---- /** * Gets the set of methods for which invocation plugins have been registered. Once this method * is called, no further registrations can be made. */ ! public EconomicSet<ResolvedJavaMethod> getMethods() { ! EconomicSet<ResolvedJavaMethod> res = EconomicSet.create(Equivalence.DEFAULT); if (parent != null) { res.addAll(parent.getMethods()); } flushDeferrables(); ! for (ClassPlugins cp : registrations.getValues()) { ! for (ResolvedJavaMethodKey key : cp.entries.getKeys()) { res.add(key.method); } } return res; }
*** 791,810 **** } @Override public String toString() { StringBuilder buf = new StringBuilder(); ! registrations.forEach((name, cp) -> buf.append(name).append('.').append(cp).append(", ")); String s = buf.toString(); if (buf.length() != 0) { s = s.substring(buf.length() - ", ".length()); } return s + " / parent: " + this.parent; } private static class Checker { ! private static final int MAX_ARITY = 5; /** * The set of all {@link InvocationPlugin#apply} method signatures. */ static final Class<?>[][] SIGS; --- 816,839 ---- } @Override public String toString() { StringBuilder buf = new StringBuilder(); ! UnmodifiableMapCursor<String, ClassPlugins> entries = registrations.getEntries(); ! while (entries.advance()) { ! buf.append(entries.getKey()).append('.').append(entries.getValue()).append(", "); ! } ! String s = buf.toString(); if (buf.length() != 0) { s = s.substring(buf.length() - ", ".length()); } return s + " / parent: " + this.parent; } private static class Checker { ! private static final int MAX_ARITY = 7; /** * The set of all {@link InvocationPlugin#apply} method signatures. */ static final Class<?>[][] SIGS;
src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/graphbuilderconf/InvocationPlugins.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File