Search in sources :

Example 51 with StaticObject

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

the class Management method GetMemoryUsage.

@ManagementImpl
@JavaType(Object.class)
public StaticObject GetMemoryUsage(@SuppressWarnings("unused") boolean heap) {
    Method init = getMeta().java_lang_management_MemoryUsage.lookupDeclaredMethod(Symbol.Name._init_, getSignatures().makeRaw(Symbol.Type._void, Symbol.Type._long, Symbol.Type._long, Symbol.Type._long, Symbol.Type._long));
    StaticObject instance = getMeta().java_lang_management_MemoryUsage.allocateInstance();
    init.invokeDirect(instance, 0L, 0L, 0L, 0L);
    return instance;
}
Also used : StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) Method(com.oracle.truffle.espresso.impl.Method) JavaType(com.oracle.truffle.espresso.substitutions.JavaType)

Example 52 with StaticObject

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

the class VM method JVM_ClassLoaderDepth.

@VmImpl(isJni = true)
public int JVM_ClassLoaderDepth() {
    PrivilegedStack stack = getPrivilegedStack();
    Integer res = Truffle.getRuntime().iterateFrames(new FrameInstanceVisitor<Integer>() {

        int depth = 0;

        @Override
        public Integer visitFrame(FrameInstance frameInstance) {
            Method m = getMethodFromFrame(frameInstance);
            if (m != null) {
                if (isTrustedFrame(frameInstance, stack)) {
                    return -1;
                }
                if (!m.isNative()) {
                    ObjectKlass klass = m.getDeclaringKlass();
                    StaticObject loader = klass.getDefiningClassLoader();
                    if (StaticObject.notNull(loader) && !isTrustedLoader(loader)) {
                        return depth;
                    }
                    depth++;
                }
            }
            return null;
        }
    });
    return res == null ? -1 : res;
}
Also used : StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) ObjectKlass(com.oracle.truffle.espresso.impl.ObjectKlass) Method(com.oracle.truffle.espresso.impl.Method) NoSafepoint(com.oracle.truffle.espresso.jni.NoSafepoint) FrameInstance(com.oracle.truffle.api.frame.FrameInstance)

Example 53 with StaticObject

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

the class VM method JVM_DefineModule.

@VmImpl(isJni = true)
@TruffleBoundary
public void JVM_DefineModule(@JavaType(internalName = "Ljava/lang/Module;") StaticObject module, boolean is_open, @SuppressWarnings("unused") @JavaType(String.class) StaticObject version, @SuppressWarnings("unused") @JavaType(String.class) StaticObject location, @Pointer TruffleObject pkgs, int num_package, @Inject Meta meta, @Inject SubstitutionProfiler profiler) {
    if (StaticObject.isNull(module)) {
        profiler.profile(0);
        throw meta.throwNullPointerException();
    }
    if (num_package < 0) {
        profiler.profile(1);
        throw meta.throwExceptionWithMessage(meta.java_lang_IllegalArgumentException, "num_package must be >= 0");
    }
    if (getUncached().isNull(pkgs) && num_package > 0) {
        profiler.profile(2);
        throw meta.throwExceptionWithMessage(meta.java_lang_IllegalArgumentException, "num_packages must be 0 if packages is null");
    }
    if (!meta.java_lang_Module.isAssignableFrom(module.getKlass())) {
        profiler.profile(3);
        throw meta.throwExceptionWithMessage(meta.java_lang_IllegalArgumentException, "module is not an instance of java.lang.Module");
    }
    StaticObject guestName = meta.java_lang_Module_name.getObject(module);
    if (StaticObject.isNull(guestName)) {
        profiler.profile(4);
        throw meta.throwExceptionWithMessage(meta.java_lang_IllegalArgumentException, "modue name cannot be null");
    }
    String hostName = meta.toHostString(guestName);
    if (hostName.equals(JAVA_BASE)) {
        profiler.profile(5);
        defineJavaBaseModule(module, extractNativePackages(pkgs, num_package, profiler), profiler);
        return;
    }
    profiler.profile(6);
    defineModule(module, hostName, is_open, extractNativePackages(pkgs, num_package, profiler), profiler);
}
Also used : StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 54 with StaticObject

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

the class VM method getGuestReflectiveMethodRoot.

// endregion stack inspection
// region annotations
@JavaType(java.lang.reflect.Method.class)
private static StaticObject getGuestReflectiveMethodRoot(@JavaType(java.lang.reflect.Method.class) StaticObject seed, Meta meta) {
    assert InterpreterToVM.instanceOf(seed, meta.java_lang_reflect_Method);
    StaticObject curMethod = seed;
    Method target = null;
    while (target == null) {
        target = (Method) meta.HIDDEN_METHOD_KEY.getHiddenObject(curMethod);
        if (target == null) {
            curMethod = meta.java_lang_reflect_Method_root.getObject(curMethod);
        }
    }
    return curMethod;
}
Also used : StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) Method(com.oracle.truffle.espresso.impl.Method) JavaType(com.oracle.truffle.espresso.substitutions.JavaType)

Example 55 with StaticObject

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

the class VM method getACCUntil11.

private StaticObject getACCUntil11() {
    ArrayList<StaticObject> domains = new ArrayList<>();
    final PrivilegedStack stack = getPrivilegedStack();
    final boolean[] isPrivileged = new boolean[] { false };
    StaticObject context = Truffle.getRuntime().iterateFrames(new FrameInstanceVisitor<StaticObject>() {

        StaticObject prevDomain = StaticObject.NULL;

        @Override
        public StaticObject visitFrame(FrameInstance frameInstance) {
            Method m = getMethodFromFrame(frameInstance);
            if (m != null) {
                if (stack.compare(frameInstance)) {
                    isPrivileged[0] = true;
                }
                StaticObject domain = JVM_GetProtectionDomain(m.getDeclaringKlass().mirror());
                if (domain != prevDomain && domain != StaticObject.NULL) {
                    domains.add(domain);
                    prevDomain = domain;
                }
                if (isPrivileged[0]) {
                    return stack.peekContext();
                }
            }
            return null;
        }
    });
    return getAccFromContext(domains, isPrivileged[0], context);
}
Also used : StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) ArrayList(java.util.ArrayList) Method(com.oracle.truffle.espresso.impl.Method) FrameInstance(com.oracle.truffle.api.frame.FrameInstance)

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