use of com.oracle.truffle.espresso.impl.Method in project graal by oracle.
the class JniEnv method CallStaticCharMethodVarargs.
@JniImpl
public char CallStaticCharMethodVarargs(@JavaType(Class.class) StaticObject clazz, @Handle(Method.class) long methodId, @Pointer TruffleObject varargsPtr) {
Method method = methodIds.getObject(methodId);
assert method.isStatic();
assert (clazz.getMirrorKlass()) == method.getDeclaringKlass();
Object result = method.invokeDirect(null, popVarArgs(varargsPtr, method.getParsedSignature()));
return getMeta().asChar(result, true);
}
use of com.oracle.truffle.espresso.impl.Method 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.impl.Method in project graal by oracle.
the class VM method JVM_DoPrivileged.
@VmImpl(isJni = true)
@SuppressWarnings("unused")
@JavaType(Object.class)
public StaticObject JVM_DoPrivileged(@JavaType(Class.class) StaticObject cls, /* PrivilegedAction or PrivilegedActionException */
@JavaType(Object.class) StaticObject action, @JavaType(AccessControlContext.class) StaticObject context, boolean wrapException, @Inject Meta meta, @Inject SubstitutionProfiler profiler) {
if (StaticObject.isNull(action)) {
profiler.profile(0);
throw meta.throwNullPointerException();
}
FrameInstance callerFrame = getCallerFrame(1, false, meta);
assert callerFrame != null : "No caller ?";
Klass caller = getMethodFromFrame(callerFrame).getDeclaringKlass();
StaticObject acc = context;
if (!StaticObject.isNull(context)) {
if (!isAuthorized(context, caller)) {
acc = createDummyACC();
}
}
Method run = action.getKlass().lookupMethod(Name.run, Signature.Object);
if (run == null || !run.isPublic() || run.isStatic()) {
profiler.profile(1);
throw meta.throwException(meta.java_lang_InternalError);
}
// Prepare the privileged stack
PrivilegedStack stack = getPrivilegedStack();
stack.push(callerFrame, acc, caller);
// Execute the action.
StaticObject result;
try {
result = (StaticObject) run.invokeDirect(action);
} catch (EspressoException e) {
profiler.profile(2);
if (meta.java_lang_Exception.isAssignableFrom(e.getGuestException().getKlass()) && !meta.java_lang_RuntimeException.isAssignableFrom(e.getGuestException().getKlass())) {
profiler.profile(3);
StaticObject wrapper = meta.java_security_PrivilegedActionException.allocateInstance();
getMeta().java_security_PrivilegedActionException_init_Exception.invokeDirect(wrapper, e.getGuestException());
throw meta.throwException(wrapper);
}
profiler.profile(4);
throw e;
} finally {
stack.pop();
}
return result;
}
use of com.oracle.truffle.espresso.impl.Method in project graal by oracle.
the class VM method JVM_InitProperties.
@VmImpl(isJni = true)
@TruffleBoundary
@JavaType(Properties.class)
public StaticObject JVM_InitProperties(@JavaType(Properties.class) StaticObject properties) {
Map<String, String> props = buildPropertiesMap();
Method setProperty = properties.getKlass().lookupMethod(Name.setProperty, Signature.Object_String_String);
for (Map.Entry<String, String> entry : props.entrySet()) {
setProperty.invokeWithConversions(properties, entry.getKey(), entry.getValue());
}
return properties;
}
use of com.oracle.truffle.espresso.impl.Method in project graal by oracle.
the class VM method DetachCurrentThread.
@VmImpl
@TruffleBoundary
public int DetachCurrentThread(@Inject EspressoContext context) {
StaticObject currentThread = context.getCurrentThread();
if (currentThread == null) {
return JNI_OK;
}
getLogger().fine(() -> {
String guestName = getThreadAccess().getThreadName(currentThread);
return "DetachCurrentThread: " + guestName;
});
// HotSpot will wait forever if the current VM this thread was attached to has exited
// Should we reproduce this behaviour?
Method lastJavaMethod = Truffle.getRuntime().iterateFrames(new FrameInstanceVisitor<Method>() {
@Override
public Method visitFrame(FrameInstance frameInstance) {
Method method = getMethodFromFrame(frameInstance);
if (method != null && method.getContext() == context) {
return method;
}
return null;
}
});
if (lastJavaMethod != null) {
// this thread is executing
getLogger().warning(() -> {
String guestName = getThreadAccess().getThreadName(currentThread);
return "DetachCurrentThread called while thread is still executing Java code (" + guestName + ")";
});
return JNI_ERR;
}
StaticObject pendingException = jniEnv.getPendingException();
jniEnv.clearPendingException();
Meta meta = context.getMeta();
try {
if (pendingException != null) {
meta.java_lang_Thread_dispatchUncaughtException.invokeDirect(currentThread, pendingException);
}
getThreadAccess().terminate(currentThread);
} catch (EspressoException e) {
try {
StaticObject ex = e.getGuestException();
String exception = ex.getKlass().getExternalName();
String threadName = getThreadAccess().getThreadName(currentThread);
context.getLogger().warning(String.format("Exception: %s thrown while terminating thread \"%s\"", exception, threadName));
Method printStackTrace = ex.getKlass().lookupMethod(Name.printStackTrace, Signature._void);
printStackTrace.invokeDirect(ex);
} catch (EspressoException ee) {
String exception = ee.getGuestException().getKlass().getExternalName();
context.getLogger().warning(String.format("Exception: %s thrown while trying to print stack trace", exception));
} catch (EspressoExitException ee) {
// ignore
}
} catch (EspressoExitException e) {
// ignore
} catch (Throwable t) {
context.getLogger().severe("Host exception thrown while trying to terminate thread");
t.printStackTrace();
}
return JNI_OK;
}
Aggregations