< prev index next >

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

Print this page

        

*** 23,32 **** --- 23,34 ---- package org.graalvm.compiler.nodes.graphbuilderconf; import static java.lang.String.format; + import static jdk.vm.ci.services.Services.IS_BUILDING_NATIVE_IMAGE; + import static jdk.vm.ci.services.Services.IS_IN_NATIVE_IMAGE; import static org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.LateClassPlugins.CLOSED_LATE_CLASS_PLUGIN; import java.lang.reflect.Constructor; import java.lang.reflect.Method; import java.lang.reflect.Modifier;
*** 142,151 **** --- 144,156 ---- private final String name; private Class<?> resolved; OptionalLazySymbol(String name) { this.name = name; + if (IS_BUILDING_NATIVE_IMAGE) { + resolve(); + } } @Override public String getTypeName() { return name;
*** 154,164 **** /** * Gets the resolved {@link Class} corresponding to this symbol or {@code null} if * resolution fails. */ public Class<?> resolve() { ! if (resolved == null) { Class<?> resolvedOrNull = resolveClass(name, true); resolved = resolvedOrNull == null ? MASK_NULL : resolvedOrNull; } return resolved == MASK_NULL ? null : resolved; } --- 159,169 ---- /** * Gets the resolved {@link Class} corresponding to this symbol or {@code null} if * resolution fails. */ public Class<?> resolve() { ! if (!IS_IN_NATIVE_IMAGE && resolved == null) { Class<?> resolvedOrNull = resolveClass(name, true); resolved = resolvedOrNull == null ? MASK_NULL : resolvedOrNull; } return resolved == MASK_NULL ? null : resolved; }
*** 220,229 **** --- 225,248 ---- * given class. * * @param plugins where to register the plugins * @param declaringClassName the name of the class class declaring the methods for which * plugins will be registered via this object + */ + public Registration(InvocationPlugins plugins, String declaringClassName) { + this.plugins = plugins; + this.declaringType = new OptionalLazySymbol(declaringClassName); + this.methodSubstitutionBytecodeProvider = null; + } + + /** + * Creates an object for registering {@link InvocationPlugin}s for methods declared by a + * given class. + * + * @param plugins where to register the plugins + * @param declaringClassName the name of the class class declaring the methods for which + * plugins will be registered via this object * @param methodSubstitutionBytecodeProvider provider used to get the bytecodes to parse for * method substitutions */ public Registration(InvocationPlugins plugins, String declaringClassName, BytecodeProvider methodSubstitutionBytecodeProvider) { this.plugins = plugins;
*** 450,461 **** assert isStatic || argumentTypes[0] == declaringType; Binding binding = new Binding(plugin, isStatic, name, argumentTypes); bindings.add(binding); ! assert Checks.check(this.plugins, declaringType, binding); ! assert Checks.checkResolvable(false, declaringType, binding); } @Override public void close() { assert plugins != null : String.format("Late registrations of invocation plugins for %s is already closed", declaringType); --- 469,480 ---- assert isStatic || argumentTypes[0] == declaringType; Binding binding = new Binding(plugin, isStatic, name, argumentTypes); bindings.add(binding); ! assert IS_IN_NATIVE_IMAGE || Checks.check(this.plugins, declaringType, binding); ! assert IS_IN_NATIVE_IMAGE || Checks.checkResolvable(false, declaringType, binding); } @Override public void close() { assert plugins != null : String.format("Late registrations of invocation plugins for %s is already closed", declaringType);
*** 734,745 **** } return null; } @SuppressWarnings("serial") ! static class InvocationPlugRegistrationError extends GraalError { ! InvocationPlugRegistrationError(Throwable cause) { super(cause); } } private void flushDeferrables() { --- 753,764 ---- } return null; } @SuppressWarnings("serial") ! static class InvocationPluginRegistrationError extends GraalError { ! InvocationPluginRegistrationError(Throwable cause) { super(cause); } } private void flushDeferrables() {
*** 749,759 **** try { for (Runnable deferrable : deferredRegistrations) { deferrable.run(); } deferredRegistrations = null; ! } catch (InvocationPlugRegistrationError t) { throw t; } catch (Throwable t) { /* * Something went wrong during registration but it's possible we'll end up * coming back into this code. nulling out deferredRegistrations would just --- 768,778 ---- try { for (Runnable deferrable : deferredRegistrations) { deferrable.run(); } deferredRegistrations = null; ! } catch (InvocationPluginRegistrationError t) { throw t; } catch (Throwable t) { /* * Something went wrong during registration but it's possible we'll end up * coming back into this code. nulling out deferredRegistrations would just
*** 763,773 **** */ deferredRegistrations.clear(); Runnable rethrow = new Runnable() { @Override public void run() { ! throw new InvocationPlugRegistrationError(t); } }; deferredRegistrations.add(rethrow); rethrow.run(); } --- 782,792 ---- */ deferredRegistrations.clear(); Runnable rethrow = new Runnable() { @Override public void run() { ! throw new InvocationPluginRegistrationError(t); } }; deferredRegistrations.add(rethrow); rethrow.run(); }
*** 958,969 **** boolean isStatic = argumentTypes.length == 0 || argumentTypes[0] != InvocationPlugin.Receiver.class; if (!isStatic) { argumentTypes[0] = declaringClass; } Binding binding = put(plugin, isStatic, allowOverwrite, declaringClass, name, argumentTypes); ! assert Checks.check(this, declaringClass, binding); ! assert Checks.checkResolvable(isOptional, declaringClass, binding); } /** * Registers an invocation plugin for a given method. There must be no plugin currently * registered for {@code method}. --- 977,988 ---- boolean isStatic = argumentTypes.length == 0 || argumentTypes[0] != InvocationPlugin.Receiver.class; if (!isStatic) { argumentTypes[0] = declaringClass; } Binding binding = put(plugin, isStatic, allowOverwrite, declaringClass, name, argumentTypes); ! assert IS_IN_NATIVE_IMAGE || Checks.check(this, declaringClass, binding); ! assert IS_IN_NATIVE_IMAGE || Checks.checkResolvable(isOptional, declaringClass, binding); } /** * Registers an invocation plugin for a given method. There must be no plugin currently * registered for {@code method}.
*** 1002,1015 **** */ public InvocationPlugin lookupInvocation(ResolvedJavaMethod method) { if (parent != null) { InvocationPlugin plugin = parent.lookupInvocation(method); if (plugin != null) { return plugin; } } ! return get(method); } /** * Gets the set of registered invocation plugins. * --- 1021,1043 ---- */ public InvocationPlugin lookupInvocation(ResolvedJavaMethod method) { if (parent != null) { InvocationPlugin plugin = parent.lookupInvocation(method); if (plugin != null) { + if (IS_IN_NATIVE_IMAGE && plugin instanceof MethodSubstitutionPlugin) { + // Disable method substitutions until GR-13607 + return null; + } return plugin; } } ! InvocationPlugin invocationPlugin = get(method); ! if (IS_IN_NATIVE_IMAGE && invocationPlugin instanceof MethodSubstitutionPlugin) { ! // Disable method substitutions until GR-13607 ! return null; ! } ! return invocationPlugin; } /** * Gets the set of registered invocation plugins. *
*** 1139,1167 **** * The set of all {@link InvocationPlugin#apply} method signatures. */ static final Class<?>[][] SIGS; static { ! if (!Assertions.assertionsEnabled()) { throw new GraalError("%s must only be used in assertions", Checks.class.getName()); } ArrayList<Class<?>[]> sigs = new ArrayList<>(MAX_ARITY); ! for (Method method : InvocationPlugin.class.getDeclaredMethods()) { ! if (!Modifier.isStatic(method.getModifiers()) && method.getName().equals("apply")) { ! Class<?>[] sig = method.getParameterTypes(); ! assert sig[0] == GraphBuilderContext.class; ! assert sig[1] == ResolvedJavaMethod.class; ! assert sig[2] == InvocationPlugin.Receiver.class; ! assert Arrays.asList(sig).subList(3, sig.length).stream().allMatch(c -> c == ValueNode.class); ! while (sigs.size() < sig.length - 2) { ! sigs.add(null); } - sigs.set(sig.length - 3, sig); } } - assert sigs.indexOf(null) == -1 : format("need to add an apply() method to %s that takes %d %s arguments ", InvocationPlugin.class.getName(), sigs.indexOf(null), - ValueNode.class.getSimpleName()); SIGS = sigs.toArray(new Class<?>[sigs.size()][]); } static boolean containsBinding(InvocationPlugins p, Type declaringType, Binding key) { String internalName = MetaUtil.toInternalName(declaringType.getTypeName()); --- 1167,1197 ---- * The set of all {@link InvocationPlugin#apply} method signatures. */ static final Class<?>[][] SIGS; static { ! if (!Assertions.assertionsEnabled() && !IS_BUILDING_NATIVE_IMAGE) { throw new GraalError("%s must only be used in assertions", Checks.class.getName()); } ArrayList<Class<?>[]> sigs = new ArrayList<>(MAX_ARITY); ! if (!IS_IN_NATIVE_IMAGE) { ! for (Method method : InvocationPlugin.class.getDeclaredMethods()) { ! if (!Modifier.isStatic(method.getModifiers()) && method.getName().equals("apply")) { ! Class<?>[] sig = method.getParameterTypes(); ! assert sig[0] == GraphBuilderContext.class; ! assert sig[1] == ResolvedJavaMethod.class; ! assert sig[2] == InvocationPlugin.Receiver.class; ! assert Arrays.asList(sig).subList(3, sig.length).stream().allMatch(c -> c == ValueNode.class); ! while (sigs.size() < sig.length - 2) { ! sigs.add(null); ! } ! sigs.set(sig.length - 3, sig); } } + assert sigs.indexOf(null) == -1 : format("need to add an apply() method to %s that takes %d %s arguments ", InvocationPlugin.class.getName(), sigs.indexOf(null), + ValueNode.class.getSimpleName()); } SIGS = sigs.toArray(new Class<?>[sigs.size()][]); } static boolean containsBinding(InvocationPlugins p, Type declaringType, Binding key) { String internalName = MetaUtil.toInternalName(declaringType.getTypeName());
*** 1274,1283 **** --- 1304,1316 ---- return (Class<?>) type; } if (type instanceof OptionalLazySymbol) { return ((OptionalLazySymbol) type).resolve(); } + if (IS_IN_NATIVE_IMAGE) { + throw new GraalError("Unresolved type in native image image:" + type.getTypeName()); + } return resolveClass(type.getTypeName(), optional); } private static List<String> toInternalTypeNames(Class<?>[] types) { String[] res = new String[types.length];
< prev index next >