use of com.oracle.truffle.espresso.nodes.IntrinsicSubstitutorNode in project graal by oracle.
the class Substitutions method registerStaticSubstitution.
@SuppressWarnings({ "unchecked", "rawtypes" })
private static void registerStaticSubstitution(JavaSubstitution.Factory substitutorFactory) {
List<Symbol<Type>> parameterTypes = new ArrayList<>();
for (int i = substitutorFactory.hasReceiver() ? 1 : 0; i < substitutorFactory.parameterTypes().length; i++) {
String type = substitutorFactory.parameterTypes()[i];
parameterTypes.add(StaticSymbols.putType(type));
}
Symbol<Type> returnType = StaticSymbols.putType(substitutorFactory.returnType());
Symbol<Signature> signature = StaticSymbols.putSignature(returnType, parameterTypes.toArray(Symbol.EMPTY_ARRAY));
EspressoRootNodeFactory factory = new EspressoRootNodeFactory() {
@Override
public EspressoRootNode createNodeIfValid(Method methodToSubstitute, boolean forceValid) {
if (!substitutorFactory.isValidFor(methodToSubstitute.getJavaVersion())) {
return null;
}
StaticObject classLoader = methodToSubstitute.getDeclaringKlass().getDefiningClassLoader();
if (forceValid || ClassRegistry.loaderIsBootOrPlatform(classLoader, methodToSubstitute.getMeta())) {
return EspressoRootNode.create(null, new IntrinsicSubstitutorNode(substitutorFactory, methodToSubstitute));
}
getLogger().warning(new Supplier<String>() {
@Override
public String get() {
StaticObject givenLoader = methodToSubstitute.getDeclaringKlass().getDefiningClassLoader();
return "Static substitution for " + methodToSubstitute + " does not apply.\n" + "\tExpected class loader: Boot (null) or platform class loader\n" + "\tGiven class loader: " + EspressoInterop.toDisplayString(givenLoader, false) + "\n";
}
});
return null;
}
};
String[] classNames = substitutorFactory.substitutionClassNames();
String[] methodNames = substitutorFactory.getMethodNames();
for (int i = 0; i < classNames.length; i++) {
assert classNames[i].startsWith("Target_");
Symbol<Type> classType = StaticSymbols.putType("L" + classNames[i].substring("Target_".length()).replace('_', '/') + ";");
Symbol<Name> methodName = StaticSymbols.putName(methodNames[i]);
registerStaticSubstitution(classType, methodName, signature, factory, true);
}
}
Aggregations