Search in sources :

Example 11 with Type

use of com.oracle.truffle.espresso.descriptors.Symbol.Type 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)

Example 12 with Type

use of com.oracle.truffle.espresso.descriptors.Symbol.Type in project graal by oracle.

the class VM method JVM_FindLoadedClass.

@VmImpl(isJni = true)
@JavaType(Class.class)
public StaticObject JVM_FindLoadedClass(@JavaType(ClassLoader.class) StaticObject loader, @JavaType(String.class) StaticObject name) {
    Symbol<Type> type = getTypes().fromClassGetName(getMeta().toHostString(name));
    // HotSpot skips reflection (DelegatingClassLoader) class loaders.
    Klass klass = getRegistries().findLoadedClass(type, nonReflectionClassLoader(loader));
    if (klass == null) {
        return StaticObject.NULL;
    }
    return klass.mirror();
}
Also used : NativeType(com.oracle.truffle.espresso.ffi.NativeType) Type(com.oracle.truffle.espresso.descriptors.Symbol.Type) JavaType(com.oracle.truffle.espresso.substitutions.JavaType) Klass(com.oracle.truffle.espresso.impl.Klass) ObjectKlass(com.oracle.truffle.espresso.impl.ObjectKlass) ArrayKlass(com.oracle.truffle.espresso.impl.ArrayKlass) JavaType(com.oracle.truffle.espresso.substitutions.JavaType)

Example 13 with Type

use of com.oracle.truffle.espresso.descriptors.Symbol.Type in project graal by oracle.

the class VM method JVM_DefineClass.

@VmImpl(isJni = true)
@TruffleBoundary
@JavaType(Class.class)
public StaticObject JVM_DefineClass(@Pointer TruffleObject namePtr, @JavaType(ClassLoader.class) StaticObject loader, @Pointer TruffleObject bufPtr, int len, @JavaType(ProtectionDomain.class) StaticObject pd) {
    ByteBuffer buf = NativeUtils.directByteBuffer(bufPtr, len, JavaKind.Byte);
    final byte[] bytes = new byte[len];
    buf.get(bytes);
    // can be null
    Symbol<Type> type = namePtrToInternal(namePtr);
    StaticObject clazz = getContext().getRegistries().defineKlass(type, bytes, loader, new ClassRegistry.ClassDefinitionInfo(pd)).mirror();
    assert clazz != null;
    return clazz;
}
Also used : NativeType(com.oracle.truffle.espresso.ffi.NativeType) Type(com.oracle.truffle.espresso.descriptors.Symbol.Type) JavaType(com.oracle.truffle.espresso.substitutions.JavaType) StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) ByteBuffer(java.nio.ByteBuffer) JavaType(com.oracle.truffle.espresso.substitutions.JavaType) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 14 with Type

use of com.oracle.truffle.espresso.descriptors.Symbol.Type in project graal by oracle.

the class VM method JVM_FindClassFromCaller.

@VmImpl(isJni = true)
@TruffleBoundary
@JavaType(Class.class)
public StaticObject JVM_FindClassFromCaller(@Pointer TruffleObject namePtr, boolean init, @JavaType(ClassLoader.class) StaticObject loader, @JavaType(Class.class) StaticObject caller) {
    Meta meta = getMeta();
    Symbol<Type> type = namePtrToInternal(namePtr);
    Klass result;
    if (Types.isPrimitive(type)) {
        result = null;
    } else {
        StaticObject protectionDomain;
        // manager to avoid the performance cost of getting the calling class.
        if (!StaticObject.isNull(caller) && !StaticObject.isNull(loader)) {
            protectionDomain = JVM_GetProtectionDomain(caller);
        } else {
            protectionDomain = StaticObject.NULL;
        }
        result = meta.resolveSymbolOrNull(type, loader, protectionDomain);
    }
    if (result == null) {
        throw meta.throwExceptionWithMessage(meta.java_lang_ClassNotFoundException, NativeUtils.interopPointerToString(namePtr));
    }
    if (init) {
        result.safeInitialize();
    }
    return result.mirror();
}
Also used : Meta(com.oracle.truffle.espresso.meta.Meta) NativeType(com.oracle.truffle.espresso.ffi.NativeType) Type(com.oracle.truffle.espresso.descriptors.Symbol.Type) JavaType(com.oracle.truffle.espresso.substitutions.JavaType) Klass(com.oracle.truffle.espresso.impl.Klass) ObjectKlass(com.oracle.truffle.espresso.impl.ObjectKlass) ArrayKlass(com.oracle.truffle.espresso.impl.ArrayKlass) StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) JavaType(com.oracle.truffle.espresso.substitutions.JavaType) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 15 with Type

use of com.oracle.truffle.espresso.descriptors.Symbol.Type in project graal by oracle.

the class VM method JVM_FindClassFromBootLoader.

@VmImpl(isJni = true)
@TruffleBoundary
@JavaType(Class.class)
public StaticObject JVM_FindClassFromBootLoader(@Pointer TruffleObject namePtr) {
    String name = NativeUtils.interopPointerToString(namePtr);
    if (name == null) {
        return StaticObject.NULL;
    }
    String internalName = name;
    if (!name.startsWith("[")) {
        // Force 'L' type.
        internalName = "L" + name + ";";
    }
    if (!Validation.validTypeDescriptor(ByteSequence.create(internalName), false)) {
        return StaticObject.NULL;
    }
    Symbol<Type> type = getTypes().fromClassGetName(internalName);
    if (Types.isPrimitive(type)) {
        return StaticObject.NULL;
    }
    Klass klass = getMeta().resolveSymbolOrNull(type, StaticObject.NULL, StaticObject.NULL);
    if (klass == null) {
        return StaticObject.NULL;
    }
    return klass.mirror();
}
Also used : NativeType(com.oracle.truffle.espresso.ffi.NativeType) Type(com.oracle.truffle.espresso.descriptors.Symbol.Type) JavaType(com.oracle.truffle.espresso.substitutions.JavaType) Klass(com.oracle.truffle.espresso.impl.Klass) ObjectKlass(com.oracle.truffle.espresso.impl.ObjectKlass) ArrayKlass(com.oracle.truffle.espresso.impl.ArrayKlass) JavaType(com.oracle.truffle.espresso.substitutions.JavaType) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Aggregations

Type (com.oracle.truffle.espresso.descriptors.Symbol.Type)26 Name (com.oracle.truffle.espresso.descriptors.Symbol.Name)9 JavaType (com.oracle.truffle.espresso.substitutions.JavaType)9 NativeType (com.oracle.truffle.espresso.ffi.NativeType)8 ObjectKlass (com.oracle.truffle.espresso.impl.ObjectKlass)6 Meta (com.oracle.truffle.espresso.meta.Meta)6 StaticObject (com.oracle.truffle.espresso.runtime.StaticObject)6 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)5 ArrayKlass (com.oracle.truffle.espresso.impl.ArrayKlass)5 Klass (com.oracle.truffle.espresso.impl.Klass)5 TruffleSafepoint (com.oracle.truffle.api.TruffleSafepoint)3 ExplodeLoop (com.oracle.truffle.api.nodes.ExplodeLoop)3 EnclosingMethodAttribute (com.oracle.truffle.espresso.classfile.attributes.EnclosingMethodAttribute)3 MethodRefConstant (com.oracle.truffle.espresso.classfile.constantpool.MethodRefConstant)3 PoolConstant (com.oracle.truffle.espresso.classfile.constantpool.PoolConstant)3 Symbol (com.oracle.truffle.espresso.descriptors.Symbol)3 Signature (com.oracle.truffle.espresso.descriptors.Symbol.Signature)3 ParserField (com.oracle.truffle.espresso.impl.ParserField)3 DebugCloseable (com.oracle.truffle.espresso.perf.DebugCloseable)3 BootstrapMethodsAttribute (com.oracle.truffle.espresso.classfile.attributes.BootstrapMethodsAttribute)2