Search in sources :

Example 1 with IntrinsicSubstitutorNode

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);
    }
}
Also used : Symbol(com.oracle.truffle.espresso.descriptors.Symbol) ArrayList(java.util.ArrayList) Method(com.oracle.truffle.espresso.impl.Method) Name(com.oracle.truffle.espresso.descriptors.Symbol.Name) Type(com.oracle.truffle.espresso.descriptors.Symbol.Type) StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) Signature(com.oracle.truffle.espresso.descriptors.Symbol.Signature) IntrinsicSubstitutorNode(com.oracle.truffle.espresso.nodes.IntrinsicSubstitutorNode)

Aggregations

Symbol (com.oracle.truffle.espresso.descriptors.Symbol)1 Name (com.oracle.truffle.espresso.descriptors.Symbol.Name)1 Signature (com.oracle.truffle.espresso.descriptors.Symbol.Signature)1 Type (com.oracle.truffle.espresso.descriptors.Symbol.Type)1 Method (com.oracle.truffle.espresso.impl.Method)1 IntrinsicSubstitutorNode (com.oracle.truffle.espresso.nodes.IntrinsicSubstitutorNode)1 StaticObject (com.oracle.truffle.espresso.runtime.StaticObject)1 ArrayList (java.util.ArrayList)1