Search in sources :

Example 51 with Klass

use of com.oracle.truffle.espresso.impl.Klass 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 52 with Klass

use of com.oracle.truffle.espresso.impl.Klass 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)

Example 53 with Klass

use of com.oracle.truffle.espresso.impl.Klass in project graal by oracle.

the class BytecodeNode method resolveExceptionHandlers.

@ExplodeLoop
@SuppressWarnings("unused")
private ExceptionHandler resolveExceptionHandlers(int bci, StaticObject ex) {
    CompilerAsserts.partialEvaluationConstant(bci);
    ExceptionHandler[] handlers = getMethodVersion().getExceptionHandlers();
    ExceptionHandler resolved = null;
    for (ExceptionHandler toCheck : handlers) {
        if (bci >= toCheck.getStartBCI() && bci < toCheck.getEndBCI()) {
            Klass catchType = null;
            if (!toCheck.isCatchAll()) {
                // exception handlers are similar to instanceof bytecodes, so we pass instanceof
                catchType = resolveType(Bytecodes.INSTANCEOF, (char) toCheck.catchTypeCPI());
            }
            if (catchType == null || InterpreterToVM.instanceOf(ex, catchType)) {
                // the first found exception handler is our exception handler
                resolved = toCheck;
                break;
            }
        }
    }
    return resolved;
}
Also used : ExceptionHandler(com.oracle.truffle.espresso.meta.ExceptionHandler) Klass(com.oracle.truffle.espresso.impl.Klass) ArrayKlass(com.oracle.truffle.espresso.impl.ArrayKlass) ExplodeLoop(com.oracle.truffle.api.nodes.ExplodeLoop)

Example 54 with Klass

use of com.oracle.truffle.espresso.impl.Klass in project graal by oracle.

the class BytecodeNode method putPoolConstant.

private void putPoolConstant(VirtualFrame frame, int top, char cpi, int opcode) {
    assert opcode == LDC || opcode == LDC_W || opcode == LDC2_W;
    RuntimeConstantPool pool = getConstantPool();
    PoolConstant constant = pool.at(cpi);
    if (constant instanceof IntegerConstant) {
        assert opcode == LDC || opcode == LDC_W;
        putInt(frame, top, ((IntegerConstant) constant).value());
    } else if (constant instanceof LongConstant) {
        assert opcode == LDC2_W;
        putLong(frame, top, ((LongConstant) constant).value());
    } else if (constant instanceof DoubleConstant) {
        assert opcode == LDC2_W;
        putDouble(frame, top, ((DoubleConstant) constant).value());
    } else if (constant instanceof FloatConstant) {
        assert opcode == LDC || opcode == LDC_W;
        putFloat(frame, top, ((FloatConstant) constant).value());
    } else if (constant instanceof StringConstant) {
        assert opcode == LDC || opcode == LDC_W;
        StaticObject internedString = pool.resolvedStringAt(cpi);
        putObject(frame, top, internedString);
    } else if (constant instanceof ClassConstant) {
        assert opcode == LDC || opcode == LDC_W;
        Klass klass = pool.resolvedKlassAt(getDeclaringKlass(), cpi);
        putObject(frame, top, klass.mirror());
    } else if (constant instanceof MethodHandleConstant) {
        assert opcode == LDC || opcode == LDC_W;
        StaticObject methodHandle = pool.resolvedMethodHandleAt(getDeclaringKlass(), cpi);
        putObject(frame, top, methodHandle);
    } else if (constant instanceof MethodTypeConstant) {
        assert opcode == LDC || opcode == LDC_W;
        StaticObject methodType = pool.resolvedMethodTypeAt(getDeclaringKlass(), cpi);
        putObject(frame, top, methodType);
    } else if (constant instanceof DynamicConstant) {
        DynamicConstant.Resolved dynamicConstant = pool.resolvedDynamicConstantAt(getDeclaringKlass(), cpi);
        dynamicConstant.putResolved(frame, top, this);
    } else {
        CompilerDirectives.transferToInterpreter();
        throw EspressoError.unimplemented(constant.toString());
    }
}
Also used : LongConstant(com.oracle.truffle.espresso.classfile.constantpool.LongConstant) DoubleConstant(com.oracle.truffle.espresso.classfile.constantpool.DoubleConstant) PoolConstant(com.oracle.truffle.espresso.classfile.constantpool.PoolConstant) FloatConstant(com.oracle.truffle.espresso.classfile.constantpool.FloatConstant) MethodHandleConstant(com.oracle.truffle.espresso.classfile.constantpool.MethodHandleConstant) IntegerConstant(com.oracle.truffle.espresso.classfile.constantpool.IntegerConstant) InvokeDynamicConstant(com.oracle.truffle.espresso.classfile.constantpool.InvokeDynamicConstant) DynamicConstant(com.oracle.truffle.espresso.classfile.constantpool.DynamicConstant) RuntimeConstantPool(com.oracle.truffle.espresso.classfile.RuntimeConstantPool) Klass(com.oracle.truffle.espresso.impl.Klass) ArrayKlass(com.oracle.truffle.espresso.impl.ArrayKlass) StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) StringConstant(com.oracle.truffle.espresso.classfile.constantpool.StringConstant) ClassConstant(com.oracle.truffle.espresso.classfile.constantpool.ClassConstant) MethodTypeConstant(com.oracle.truffle.espresso.classfile.constantpool.MethodTypeConstant)

Example 55 with Klass

use of com.oracle.truffle.espresso.impl.Klass in project graal by oracle.

the class JniEnv method UnregisterNatives.

/**
 * <h3>jint UnregisterNatives(JNIEnv *env, jclass clazz);</h3>
 * <p>
 * Unregisters native methods of a class. The class goes back to the state before it was linked
 * or registered with its native method functions.
 * <p>
 * This function should not be used in normal native code. Instead, it provides special programs
 * a way to reload and relink native libraries.
 *
 * @param clazz a Java class object.
 *            <p>
 *            Returns 0 on success; returns a negative value on failure.
 */
@JniImpl
@TruffleBoundary
public int UnregisterNatives(@JavaType(Class.class) StaticObject clazz) {
    Klass klass = clazz.getMirrorKlass();
    for (Method m : klass.getDeclaredMethods()) {
        if (m.isNative()) {
            getSubstitutions().removeRuntimeSubstitution(m);
            m.unregisterNative();
        }
    }
    return JNI_OK;
}
Also used : Klass(com.oracle.truffle.espresso.impl.Klass) ObjectKlass(com.oracle.truffle.espresso.impl.ObjectKlass) ArrayKlass(com.oracle.truffle.espresso.impl.ArrayKlass) Method(com.oracle.truffle.espresso.impl.Method) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Aggregations

Klass (com.oracle.truffle.espresso.impl.Klass)71 ObjectKlass (com.oracle.truffle.espresso.impl.ObjectKlass)54 ArrayKlass (com.oracle.truffle.espresso.impl.ArrayKlass)49 StaticObject (com.oracle.truffle.espresso.runtime.StaticObject)33 JavaType (com.oracle.truffle.espresso.substitutions.JavaType)24 Meta (com.oracle.truffle.espresso.meta.Meta)21 Method (com.oracle.truffle.espresso.impl.Method)19 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)10 Name (com.oracle.truffle.espresso.descriptors.Symbol.Name)10 NoSafepoint (com.oracle.truffle.espresso.jni.NoSafepoint)10 ExportMessage (com.oracle.truffle.api.library.ExportMessage)8 Field (com.oracle.truffle.espresso.impl.Field)7 ArrayList (java.util.ArrayList)7 RuntimeConstantPool (com.oracle.truffle.espresso.classfile.RuntimeConstantPool)6 EspressoException (com.oracle.truffle.espresso.runtime.EspressoException)6 InnerClassesAttribute (com.oracle.truffle.espresso.classfile.attributes.InnerClassesAttribute)5 Type (com.oracle.truffle.espresso.descriptors.Symbol.Type)5 NativeType (com.oracle.truffle.espresso.ffi.NativeType)5 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)3 EnclosingMethodAttribute (com.oracle.truffle.espresso.classfile.attributes.EnclosingMethodAttribute)3