Search in sources :

Example 1 with EspressoContext

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

the class EspressoBindings method readMember.

@ExportMessage
Object readMember(String member, @CachedLibrary("this") InteropLibrary self, @Exclusive @Cached BranchProfile error) throws UnknownIdentifierException {
    if (!isMemberReadable(member)) {
        error.enter();
        throw UnknownIdentifierException.create(member);
    }
    EspressoContext context = EspressoContext.get(self);
    if (withNativeJavaVM && JAVA_VM.equals(member)) {
        return context.getVM().getJavaVM();
    }
    Meta meta = context.getMeta();
    try {
        StaticObject clazz = (StaticObject) meta.java_lang_Class_forName_String_boolean_ClassLoader.invokeDirect(null, meta.toGuestString(member), false, loader);
        return clazz.getMirrorKlass();
    } catch (EspressoException e) {
        error.enter();
        if (InterpreterToVM.instanceOf(e.getGuestException(), meta.java_lang_ClassNotFoundException)) {
            throw UnknownIdentifierException.create(member, e);
        }
        // exception during class loading
        throw e;
    }
}
Also used : Meta(com.oracle.truffle.espresso.meta.Meta) EspressoException(com.oracle.truffle.espresso.runtime.EspressoException) StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) EspressoContext(com.oracle.truffle.espresso.runtime.EspressoContext) ExportMessage(com.oracle.truffle.api.library.ExportMessage)

Example 2 with EspressoContext

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

the class LivenessAnalysis method analyze.

@SuppressWarnings("try")
public static LivenessAnalysis analyze(Method.MethodVersion methodVersion) {
    EspressoContext context = methodVersion.getMethod().getContext();
    if (!enableLivenessAnalysis(context, methodVersion)) {
        return NO_ANALYSIS;
    }
    Method method = methodVersion.getMethod();
    TimerCollection scope = method.getContext().getTimers();
    try (DebugCloseable liveness = LIVENESS_TIMER.scope(scope)) {
        Graph<? extends LinkedBlock> graph;
        try (DebugCloseable builder = BUILDER_TIMER.scope(scope)) {
            graph = GraphBuilder.build(method);
        }
        // Transform the graph into a more manageable graph consisting of only the history of
        // load/stores.
        LoadStoreFinder loadStoreClosure;
        try (DebugCloseable loadStore = LOADSTORE_TIMER.scope(scope)) {
            loadStoreClosure = new LoadStoreFinder(graph, method);
            loadStoreClosure.analyze();
        }
        // Computes the entry/end live sets for each variable for each block.
        BlockBoundaryFinder blockBoundaryFinder;
        try (DebugCloseable boundary = STATE_TIMER.scope(scope)) {
            blockBoundaryFinder = new BlockBoundaryFinder(methodVersion, loadStoreClosure.result());
            DepthFirstBlockIterator.analyze(method, graph, blockBoundaryFinder);
        }
        try (DebugCloseable propagation = PROPAGATE_TIMER.scope(scope)) {
            // Forces loop ends to inherit the loop entry state, and propagates the changes.
            LoopPropagatorClosure loopPropagation = new LoopPropagatorClosure(graph, blockBoundaryFinder.result());
            while (loopPropagation.process(graph)) {
            /*
                     * This loop should iterate at MOST exactly the maximum number of nested loops
                     * in the method.
                     *
                     * The reasoning is the following:
                     *
                     * - The only reason a new iteration is required is when a loop entry's state
                     * gets modified by the previous iteration.
                     *
                     * - This can happen only if a new live variable gets propagated from an outer
                     * loop.
                     *
                     * - Which means that we do not need to re-propagate the state of the outermost
                     * loop.
                     */
            }
        }
        // frees as early as possible each dead local.
        try (DebugCloseable actionFinder = ACTION_TIMER.scope(scope)) {
            Builder builder = new Builder(graph, methodVersion, blockBoundaryFinder.result());
            builder.build();
            return new LivenessAnalysis(builder.actions, builder.edge, builder.onStart);
        }
    }
}
Also used : TimerCollection(com.oracle.truffle.espresso.perf.TimerCollection) GraphBuilder(com.oracle.truffle.espresso.analysis.GraphBuilder) EspressoContext(com.oracle.truffle.espresso.runtime.EspressoContext) Method(com.oracle.truffle.espresso.impl.Method) DebugCloseable(com.oracle.truffle.espresso.perf.DebugCloseable)

Example 3 with EspressoContext

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

the class VM method JVM_MonitorWait.

@VmImpl(isJni = true)
@TruffleBoundary
@SuppressFBWarnings(value = { "IMSE" }, justification = "Not dubious, .wait is just forwarded from the guest.")
@SuppressWarnings("try")
public void JVM_MonitorWait(@JavaType(Object.class) StaticObject self, long timeout, @Inject Meta meta, @Inject SubstitutionProfiler profiler) {
    EspressoContext context = getContext();
    StaticObject currentThread = context.getCurrentThread();
    State state = timeout > 0 ? State.TIMED_WAITING : State.WAITING;
    try (Transition transition = Transition.transition(context, state)) {
        if (context.EnableManagement) {
            // Locks bookkeeping.
            meta.HIDDEN_THREAD_BLOCKED_OBJECT.setHiddenObject(currentThread, self);
            Target_java_lang_Thread.incrementThreadCounter(currentThread, meta.HIDDEN_THREAD_WAITED_COUNT);
        }
        final boolean report = context.shouldReportVMEvents();
        if (report) {
            context.reportMonitorWait(self, timeout);
        }
        boolean timedOut = !InterpreterToVM.monitorWait(self.getLock(getContext()), timeout);
        if (report) {
            context.reportMonitorWaited(self, timedOut);
        }
    } catch (GuestInterruptedException e) {
        profiler.profile(0);
        if (getThreadAccess().isInterrupted(currentThread, true)) {
            throw meta.throwExceptionWithMessage(meta.java_lang_InterruptedException, e.getMessage());
        }
        getThreadAccess().fullSafePoint(currentThread);
    } catch (IllegalMonitorStateException e) {
        profiler.profile(1);
        throw meta.throwExceptionWithMessage(meta.java_lang_IllegalMonitorStateException, e.getMessage());
    } catch (IllegalArgumentException e) {
        profiler.profile(2);
        throw meta.throwExceptionWithMessage(meta.java_lang_IllegalArgumentException, e.getMessage());
    } finally {
        if (context.EnableManagement) {
            meta.HIDDEN_THREAD_BLOCKED_OBJECT.setHiddenObject(currentThread, null);
        }
    }
}
Also used : StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) GuestInterruptedException(com.oracle.truffle.espresso.blocking.GuestInterruptedException) State(com.oracle.truffle.espresso.threads.State) Transition(com.oracle.truffle.espresso.threads.Transition) EspressoContext(com.oracle.truffle.espresso.runtime.EspressoContext) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary) SuppressFBWarnings(com.oracle.truffle.espresso.impl.SuppressFBWarnings)

Example 4 with EspressoContext

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

the class InterpreterToVM method monitorEnter.

// endregion
// region Monitor enter/exit
public static void monitorEnter(@JavaType(Object.class) StaticObject obj, Meta meta) {
    final EspressoLock lock = obj.getLock(meta.getContext());
    EspressoContext context = meta.getContext();
    if (!monitorTryLock(lock)) {
        contendedMonitorEnter(obj, meta, lock, context);
    }
}
Also used : EspressoContext(com.oracle.truffle.espresso.runtime.EspressoContext) EspressoLock(com.oracle.truffle.espresso.blocking.EspressoLock)

Example 5 with EspressoContext

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

the class Target_java_lang_invoke_MethodHandleNatives method getMembers.

// TODO(garcia) verifyConstants
@Substitution
public static int getMembers(@JavaType(Class.class) StaticObject defc, @JavaType(String.class) StaticObject matchName, @JavaType(String.class) StaticObject matchSig, int matchFlags, @JavaType(Class.class) StaticObject originalCaller, int skip, @JavaType(internalName = "[Ljava/lang/invoke/MemberName;") StaticObject resultsArr, @Inject Meta meta) {
    if (StaticObject.isNull(defc) || StaticObject.isNull(resultsArr)) {
        return -1;
    }
    EspressoContext context = meta.getContext();
    StaticObject[] results = resultsArr.unwrap();
    Symbol<Name> name = null;
    if (!StaticObject.isNull(matchName)) {
        name = context.getNames().lookup(meta.toHostString(matchName));
        if (name == null) {
            return 0;
        }
    }
    String sig = meta.toHostString(matchSig);
    if (sig == null) {
        return 0;
    }
    Klass caller = null;
    if (!StaticObject.isNull(originalCaller)) {
        caller = originalCaller.getMirrorKlass();
        if (caller == null) {
            return -1;
        }
    }
    return findMemberNames(defc.getMirrorKlass(), name, sig, matchFlags, caller, skip, results);
}
Also used : Klass(com.oracle.truffle.espresso.impl.Klass) StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) EspressoContext(com.oracle.truffle.espresso.runtime.EspressoContext) Name(com.oracle.truffle.espresso.descriptors.Symbol.Name)

Aggregations

EspressoContext (com.oracle.truffle.espresso.runtime.EspressoContext)10 StaticObject (com.oracle.truffle.espresso.runtime.StaticObject)6 Klass (com.oracle.truffle.espresso.impl.Klass)3 Method (com.oracle.truffle.espresso.impl.Method)3 Meta (com.oracle.truffle.espresso.meta.Meta)3 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)2 EnclosingMethodAttribute (com.oracle.truffle.espresso.classfile.attributes.EnclosingMethodAttribute)2 InnerClassesAttribute (com.oracle.truffle.espresso.classfile.attributes.InnerClassesAttribute)2 MethodParametersAttribute (com.oracle.truffle.espresso.classfile.attributes.MethodParametersAttribute)2 PermittedSubclassesAttribute (com.oracle.truffle.espresso.classfile.attributes.PermittedSubclassesAttribute)2 RecordAttribute (com.oracle.truffle.espresso.classfile.attributes.RecordAttribute)2 SignatureAttribute (com.oracle.truffle.espresso.classfile.attributes.SignatureAttribute)2 ArrayKlass (com.oracle.truffle.espresso.impl.ArrayKlass)2 Field (com.oracle.truffle.espresso.impl.Field)2 ObjectKlass (com.oracle.truffle.espresso.impl.ObjectKlass)2 NoSafepoint (com.oracle.truffle.espresso.jni.NoSafepoint)2 Attribute (com.oracle.truffle.espresso.runtime.Attribute)2 JavaType (com.oracle.truffle.espresso.substitutions.JavaType)2 State (com.oracle.truffle.espresso.threads.State)2 Transition (com.oracle.truffle.espresso.threads.Transition)2