< 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,10 +23,12 @@
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,10 +144,13 @@
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,11 +159,11 @@
/**
* Gets the resolved {@link Class} corresponding to this symbol or {@code null} if
* resolution fails.
*/
public Class<?> resolve() {
- if (resolved == null) {
+ 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,10 +225,24 @@
* 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,12 +469,12 @@
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);
+ 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,12 +753,12 @@
}
return null;
}
@SuppressWarnings("serial")
- static class InvocationPlugRegistrationError extends GraalError {
- InvocationPlugRegistrationError(Throwable cause) {
+ static class InvocationPluginRegistrationError extends GraalError {
+ InvocationPluginRegistrationError(Throwable cause) {
super(cause);
}
}
private void flushDeferrables() {
@@ -749,11 +768,11 @@
try {
for (Runnable deferrable : deferredRegistrations) {
deferrable.run();
}
deferredRegistrations = null;
- } catch (InvocationPlugRegistrationError t) {
+ } 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,11 +782,11 @@
*/
deferredRegistrations.clear();
Runnable rethrow = new Runnable() {
@Override
public void run() {
- throw new InvocationPlugRegistrationError(t);
+ throw new InvocationPluginRegistrationError(t);
}
};
deferredRegistrations.add(rethrow);
rethrow.run();
}
@@ -958,12 +977,12 @@
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);
+ 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,14 +1021,23 @@
*/
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;
}
}
- return get(method);
+ 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,29 +1167,31 @@
* The set of all {@link InvocationPlugin#apply} method signatures.
*/
static final Class<?>[][] SIGS;
static {
- if (!Assertions.assertionsEnabled()) {
+ 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);
- 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);
+ 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);
}
- 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());
}
- 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,10 +1304,13 @@
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 >