Search in sources :

Example 36 with StaticObject

use of com.oracle.truffle.espresso.runtime.StaticObject 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 37 with StaticObject

use of com.oracle.truffle.espresso.runtime.StaticObject 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 38 with StaticObject

use of com.oracle.truffle.espresso.runtime.StaticObject 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 39 with StaticObject

use of com.oracle.truffle.espresso.runtime.StaticObject in project graal by oracle.

the class VM method defineJavaBaseModule.

@SuppressWarnings("try")
public void defineJavaBaseModule(StaticObject module, String[] packages, SubstitutionProfiler profiler) {
    Meta meta = getMeta();
    StaticObject loader = meta.java_lang_Module_loader.getObject(module);
    if (!StaticObject.isNull(loader)) {
        profiler.profile(10);
        throw meta.throwExceptionWithMessage(meta.java_lang_IllegalArgumentException, "Class loader must be the bootclass loader");
    }
    PackageTable pkgTable = getRegistries().getBootClassRegistry().packages();
    ModuleEntry javaBaseEntry = getRegistries().getJavaBaseModule();
    try (EntryTable.BlockLock block = pkgTable.write()) {
        if (getRegistries().javaBaseDefined()) {
            profiler.profile(9);
            throw meta.throwException(meta.java_lang_InternalError);
        }
        for (String pkg : packages) {
            Symbol<Name> pkgName = getNames().getOrCreate(pkg);
            if (pkgTable.lookup(pkgName) == null) {
                pkgTable.createAndAddEntry(pkgName, javaBaseEntry);
            }
        }
        javaBaseEntry.setModule(module);
        meta.HIDDEN_MODULE_ENTRY.setHiddenObject(module, javaBaseEntry);
        getRegistries().processFixupList(module);
    }
}
Also used : Meta(com.oracle.truffle.espresso.meta.Meta) StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) EntryTable(com.oracle.truffle.espresso.impl.EntryTable) ModuleEntry(com.oracle.truffle.espresso.impl.ModuleTable.ModuleEntry) PackageTable(com.oracle.truffle.espresso.impl.PackageTable) Name(com.oracle.truffle.espresso.descriptors.Symbol.Name)

Example 40 with StaticObject

use of com.oracle.truffle.espresso.runtime.StaticObject 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

StaticObject (com.oracle.truffle.espresso.runtime.StaticObject)199 Method (com.oracle.truffle.espresso.impl.Method)57 JavaType (com.oracle.truffle.espresso.substitutions.JavaType)44 Klass (com.oracle.truffle.espresso.impl.Klass)32 ObjectKlass (com.oracle.truffle.espresso.impl.ObjectKlass)32 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)30 Meta (com.oracle.truffle.espresso.meta.Meta)29 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)26 ArrayKlass (com.oracle.truffle.espresso.impl.ArrayKlass)23 NoSafepoint (com.oracle.truffle.espresso.jni.NoSafepoint)17 ArrayList (java.util.ArrayList)13 EspressoException (com.oracle.truffle.espresso.runtime.EspressoException)9 Symbol (com.oracle.truffle.espresso.descriptors.Symbol)8 FrameInstance (com.oracle.truffle.api.frame.FrameInstance)7 ExportMessage (com.oracle.truffle.api.library.ExportMessage)7 BytecodeNode (com.oracle.truffle.espresso.nodes.BytecodeNode)7 TruffleSafepoint (com.oracle.truffle.api.TruffleSafepoint)6 Name (com.oracle.truffle.espresso.descriptors.Symbol.Name)6 EspressoContext (com.oracle.truffle.espresso.runtime.EspressoContext)6 Type (com.oracle.truffle.espresso.descriptors.Symbol.Type)5