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;
}
}
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);
}
}
}
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);
}
}
}
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);
}
}
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);
}
Aggregations