Search in sources :

Example 26 with JavaType

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

the class VM method getGuestReflectiveConstructorRoot.

@JavaType(java.lang.reflect.Constructor.class)
private static StaticObject getGuestReflectiveConstructorRoot(@JavaType(java.lang.reflect.Constructor.class) StaticObject seed, Meta meta) {
    assert InterpreterToVM.instanceOf(seed, meta.java_lang_reflect_Constructor);
    StaticObject curConstructor = seed;
    Method target = null;
    while (target == null) {
        target = (Method) meta.HIDDEN_CONSTRUCTOR_KEY.getHiddenObject(curConstructor);
        if (target == null) {
            curConstructor = meta.java_lang_reflect_Constructor_root.getObject(curConstructor);
        }
    }
    return curConstructor;
}
Also used : StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) Method(com.oracle.truffle.espresso.impl.Method) JavaType(com.oracle.truffle.espresso.substitutions.JavaType)

Example 27 with JavaType

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

the class VM method JVM_FindPrimitiveClass.

@VmImpl(isJni = true)
@JavaType(Class.class)
public StaticObject JVM_FindPrimitiveClass(@Pointer TruffleObject namePtr) {
    Meta meta = getMeta();
    String hostName = NativeUtils.interopPointerToString(namePtr);
    return findPrimitiveClass(meta, hostName);
}
Also used : Meta(com.oracle.truffle.espresso.meta.Meta) JavaType(com.oracle.truffle.espresso.substitutions.JavaType)

Example 28 with JavaType

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

the class VM method JVM_GetClassSignature.

@VmImpl(isJni = true)
@JavaType(String.class)
public StaticObject JVM_GetClassSignature(@JavaType(Class.class) StaticObject self) {
    if (self.getMirrorKlass() instanceof ObjectKlass) {
        ObjectKlass klass = (ObjectKlass) self.getMirrorKlass();
        SignatureAttribute signature = (SignatureAttribute) klass.getAttribute(Name.Signature);
        if (signature != null) {
            String sig = klass.getConstantPool().symbolAt(signature.getSignatureIndex(), "signature").toString();
            return getMeta().toGuestString(sig);
        }
    }
    return StaticObject.NULL;
}
Also used : SignatureAttribute(com.oracle.truffle.espresso.classfile.attributes.SignatureAttribute) ObjectKlass(com.oracle.truffle.espresso.impl.ObjectKlass) JavaType(com.oracle.truffle.espresso.substitutions.JavaType)

Example 29 with JavaType

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

the class VM method JVM_GetClassDeclaredMethods.

// TODO(tg): inject constructor calltarget.
@VmImpl(isJni = true)
@JavaType(java.lang.reflect.Method[].class)
public StaticObject JVM_GetClassDeclaredMethods(@JavaType(Class.class) StaticObject self, boolean publicOnly) {
    Meta meta = getMeta();
    ArrayList<Method> collectedMethods = new ArrayList<>();
    Klass klass = self.getMirrorKlass();
    klass.ensureLinked();
    for (Method m : klass.getDeclaredMethods()) {
        if ((!publicOnly || m.isPublic()) && // Filter out <init> and <clinit> from reflection.
        !Name._init_.equals(m.getName()) && !Name._clinit_.equals(m.getName())) {
            collectedMethods.add(m);
        }
    }
    final Method[] methods = collectedMethods.toArray(Method.EMPTY_ARRAY);
    return meta.java_lang_reflect_Method.allocateReferenceArray(methods.length, new IntFunction<StaticObject>() {

        @Override
        public StaticObject apply(int i) {
            return methods[i].makeMirror();
        }
    });
}
Also used : Meta(com.oracle.truffle.espresso.meta.Meta) 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) ArrayList(java.util.ArrayList) Method(com.oracle.truffle.espresso.impl.Method) NoSafepoint(com.oracle.truffle.espresso.jni.NoSafepoint) JavaType(com.oracle.truffle.espresso.substitutions.JavaType)

Example 30 with JavaType

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

the class Management method DumpThreads.

@ManagementImpl
@SuppressWarnings("unused")
@JavaType(internalName = "[Ljava/lang/management/ThreadInfo;")
public StaticObject DumpThreads(@JavaType(long[].class) StaticObject ids, boolean lockedMonitors, boolean lockedSynchronizers, @Inject SubstitutionProfiler profiler) {
    StaticObject threadIds = ids;
    if (StaticObject.isNull(threadIds)) {
        StaticObject[] activeThreads = getContext().getActiveThreads();
        threadIds = InterpreterToVM.allocatePrimitiveArray((byte) JavaKind.Long.getBasicType(), activeThreads.length, getMeta());
        for (int j = 0; j < activeThreads.length; ++j) {
            long tid = getThreadAccess().getThreadId(activeThreads[j]);
            getInterpreterToVM().setArrayLong(tid, j, threadIds);
        }
    }
    StaticObject result = getMeta().java_lang_management_ThreadInfo.allocateReferenceArray(threadIds.length());
    if (GetThreadInfo(threadIds, 0, result, profiler) != JNI_OK) {
        return StaticObject.NULL;
    }
    return result;
}
Also used : 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