Search in sources :

Example 11 with JavaType

use of com.oracle.truffle.espresso.substitutions.JavaType in project graal by oracle.

the class ConstantPool method verifyError.

@JavaType(VerifyError.class)
static EspressoException verifyError(String message) {
    CompilerDirectives.transferToInterpreter();
    Meta meta = EspressoContext.get(null).getMeta();
    throw meta.throwExceptionWithMessage(meta.java_lang_VerifyError, message);
}
Also used : Meta(com.oracle.truffle.espresso.meta.Meta) JavaType(com.oracle.truffle.espresso.substitutions.JavaType)

Example 12 with JavaType

use of com.oracle.truffle.espresso.substitutions.JavaType in project graal by oracle.

the class VM method JVM_LookupDefineClass.

@VmImpl(isJni = true)
@TruffleBoundary
@JavaType(Class.class)
public StaticObject JVM_LookupDefineClass(@JavaType(Class.class) StaticObject lookup, @Pointer TruffleObject namePtr, @Pointer TruffleObject bufPtr, int len, @JavaType(ProtectionDomain.class) StaticObject pd, boolean initialize, int flags, @JavaType(Object.class) StaticObject classData) {
    if (StaticObject.isNull(lookup)) {
        throw getMeta().throwExceptionWithMessage(getMeta().java_lang_InternalError, "Lookup class is null");
    }
    assert !getUncached().isNull(bufPtr);
    assert lookup.getMirrorKlass() instanceof ObjectKlass;
    boolean isNestMate = (flags & NESTMATE_CLASS) == NESTMATE_CLASS;
    boolean isHidden = (flags & HIDDEN_CLASS) == HIDDEN_CLASS;
    boolean isStrong = (flags & STRONG_LOADER_LINK) == STRONG_LOADER_LINK;
    boolean vmAnnotations = (flags & ACCESS_VM_ANNOTATIONS) == ACCESS_VM_ANNOTATIONS;
    ObjectKlass nest = null;
    if (isNestMate) {
        nest = (ObjectKlass) lookup.getMirrorKlass().nest();
    }
    if (!isHidden) {
        if (!StaticObject.isNull(classData)) {
            throw getMeta().throwExceptionWithMessage(getMeta().java_lang_IllegalArgumentException, "classData is only applicable for hidden classes");
        }
        if (isNestMate) {
            throw getMeta().throwExceptionWithMessage(getMeta().java_lang_IllegalArgumentException, "dynamic nestmate is only applicable for hidden classes");
        }
        if (!isStrong) {
            throw getMeta().throwExceptionWithMessage(getMeta().java_lang_IllegalArgumentException, "an ordinary class must be strongly referenced by its defining loader");
        }
        if (vmAnnotations) {
            throw getMeta().throwExceptionWithMessage(getMeta().java_lang_IllegalArgumentException, "vm annotations only allowed for hidden classes");
        }
        if (flags != STRONG_LOADER_LINK) {
            throw getMeta().throwExceptionWithMessage(getMeta().java_lang_IllegalArgumentException, String.format("invalid flag 0x%x", flags));
        }
    }
    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 loader = lookup.getMirrorKlass().getDefiningClassLoader();
    ObjectKlass k;
    if (isHidden) {
        // Special handling
        k = getRegistries().defineKlass(type, bytes, loader, new ClassRegistry.ClassDefinitionInfo(pd, nest, classData, isStrong));
    } else {
        k = getRegistries().defineKlass(type, bytes, loader, new ClassRegistry.ClassDefinitionInfo(pd));
    }
    if (initialize) {
        k.safeInitialize();
    } else {
        k.ensureLinked();
    }
    return k.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) StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) ObjectKlass(com.oracle.truffle.espresso.impl.ObjectKlass) ByteBuffer(java.nio.ByteBuffer) JavaType(com.oracle.truffle.espresso.substitutions.JavaType) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 13 with JavaType

use of com.oracle.truffle.espresso.substitutions.JavaType in project graal by oracle.

the class VM method createDummyACC.

@JavaType(AccessControlContext.class)
private StaticObject createDummyACC() {
    Klass pdKlass = getMeta().java_security_ProtectionDomain;
    StaticObject pd = pdKlass.allocateInstance();
    getMeta().java_security_ProtectionDomain_init_CodeSource_PermissionCollection.invokeDirect(pd, StaticObject.NULL, StaticObject.NULL);
    StaticObject context = StaticObject.wrap(new StaticObject[] { pd }, getMeta());
    return createACC(context, false, StaticObject.NULL);
}
Also used : 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)

Example 14 with JavaType

use of com.oracle.truffle.espresso.substitutions.JavaType in project graal by oracle.

the class VM method JVM_GetClassName.

@VmImpl(isJni = true)
@JavaType(String.class)
public StaticObject JVM_GetClassName(@JavaType(Class.class) StaticObject self) {
    Klass klass = self.getMirrorKlass();
    // Conversion from internal form.
    String externalName = klass.getExternalName();
    // Class names must be interned.
    StaticObject guestString = getMeta().toGuestString(externalName);
    return getStrings().intern(guestString);
}
Also used : 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)

Example 15 with JavaType

use of com.oracle.truffle.espresso.substitutions.JavaType in project graal by oracle.

the class VM method getGuestReflectiveFieldRoot.

@JavaType(java.lang.reflect.Field.class)
private static StaticObject getGuestReflectiveFieldRoot(@JavaType(java.lang.reflect.Field.class) StaticObject seed, Meta meta) {
    assert InterpreterToVM.instanceOf(seed, meta.java_lang_reflect_Field);
    StaticObject curField = seed;
    Field target = null;
    while (target == null) {
        target = (Field) meta.HIDDEN_FIELD_KEY.getHiddenObject(curField);
        if (target == null) {
            curField = meta.java_lang_reflect_Field_root.getObject(curField);
        }
    }
    return curField;
}
Also used : Field(com.oracle.truffle.espresso.impl.Field) StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) JavaType(com.oracle.truffle.espresso.substitutions.JavaType)

Aggregations

JavaType (com.oracle.truffle.espresso.substitutions.JavaType)58 StaticObject (com.oracle.truffle.espresso.runtime.StaticObject)44 ObjectKlass (com.oracle.truffle.espresso.impl.ObjectKlass)28 ArrayKlass (com.oracle.truffle.espresso.impl.ArrayKlass)24 Klass (com.oracle.truffle.espresso.impl.Klass)24 Meta (com.oracle.truffle.espresso.meta.Meta)20 Method (com.oracle.truffle.espresso.impl.Method)19 NoSafepoint (com.oracle.truffle.espresso.jni.NoSafepoint)15 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)13 Type (com.oracle.truffle.espresso.descriptors.Symbol.Type)8 NativeType (com.oracle.truffle.espresso.ffi.NativeType)8 Name (com.oracle.truffle.espresso.descriptors.Symbol.Name)5 Field (com.oracle.truffle.espresso.impl.Field)5 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)4 RuntimeConstantPool (com.oracle.truffle.espresso.classfile.RuntimeConstantPool)4 InnerClassesAttribute (com.oracle.truffle.espresso.classfile.attributes.InnerClassesAttribute)4 ArrayList (java.util.ArrayList)4 FrameInstance (com.oracle.truffle.api.frame.FrameInstance)3 EnclosingMethodAttribute (com.oracle.truffle.espresso.classfile.attributes.EnclosingMethodAttribute)3 MethodParametersAttribute (com.oracle.truffle.espresso.classfile.attributes.MethodParametersAttribute)3