use of com.oracle.truffle.api.CompilerDirectives.TruffleBoundary in project graal by oracle.
the class OptimizedAssumption method invalidateImpl.
@TruffleBoundary
private synchronized void invalidateImpl(String message) {
/*
* Check again, now that we are holding the lock. Since isValid is defined volatile,
* double-checked locking is allowed.
*/
if (!isValid) {
return;
}
boolean invalidatedADependency = false;
Entry e = dependencies;
while (e != null) {
OptimizedAssumptionDependency dependency = e.awaitDependency();
if (dependency != null) {
OptimizedCallTarget callTarget = invalidateWithReason(dependency, "assumption invalidated");
invalidatedADependency = true;
if (TruffleCompilerOptions.getValue(TraceTruffleAssumptions)) {
logInvalidatedDependency(dependency, message);
}
if (callTarget != null) {
callTarget.getCompilationProfile().reportInvalidated();
}
}
e = e.next;
}
dependencies = null;
size = 0;
sizeAfterLastRemove = 0;
isValid = false;
if (TruffleCompilerOptions.getValue(TraceTruffleAssumptions)) {
if (invalidatedADependency) {
logStackTrace();
}
}
}
use of com.oracle.truffle.api.CompilerDirectives.TruffleBoundary in project graal by oracle.
the class DebuggerSessionSnippets method notifyCallback.
@TruffleBoundary
void notifyCallback(DebuggerNode source, MaterializedFrame frame, SuspendAnchor suspendAnchor, InputValuesProvider inputValuesProvider, Object returnValue, BreakpointConditionFailure conditionFailure) {
ThreadSuspension suspensionDisabled = threadSuspensions.get();
if (suspensionDisabled != null && !suspensionDisabled.enabled) {
return;
}
// SuspensionFilter:
if (source.isStepNode()) {
if (ignoreLanguageContextInitialization.get() && !source.getContext().isLanguageContextInitialized()) {
return;
}
}
Thread currentThread = Thread.currentThread();
SuspendedEvent event = currentSuspendedEventMap.get(currentThread);
if (event != null) {
if (Debugger.TRACE) {
trace("ignored suspended reason: recursive from source:%s context:%s location:%s", source, source.getContext(), source.getSuspendAnchors());
}
// avoid recursive suspensions in non legacy mode.
return;
}
if (source.consumeIsDuplicate(this)) {
if (Debugger.TRACE) {
trace("ignored suspended reason: duplicate from source:%s context:%s location:%s", source, source.getContext(), source.getSuspendAnchors());
}
return;
}
// only the first DebuggerNode for a source location and thread will reach here.
// mark all other nodes at this source location as duplicates
List<DebuggerNode> nodes = collectDebuggerNodes(source, suspendAnchor);
for (DebuggerNode node : nodes) {
if (node == source) {
// for the current one we won't call isDuplicate
continue;
}
node.markAsDuplicate(this);
}
SteppingStrategy s = getSteppingStrategy(currentThread);
if (suspendNext) {
synchronized (this) {
// double checked locking to avoid more than one suspension
if (suspendNext) {
s = SteppingStrategy.createAlwaysHalt();
setSteppingStrategy(currentThread, s, true);
suspendNext = false;
}
}
}
if (s == null) {
// a new Thread just appeared
s = notifyNewThread(currentThread);
}
Map<Breakpoint, Throwable> breakpointFailures = null;
if (conditionFailure != null) {
breakpointFailures = new HashMap<>();
Breakpoint fb = conditionFailure.getBreakpoint();
if (fb.isGlobal()) {
fb = fb.getROWrapper();
}
breakpointFailures.put(fb, conditionFailure.getConditionFailure());
}
List<Breakpoint> breaks = null;
for (DebuggerNode node : nodes) {
Breakpoint breakpoint = node.getBreakpoint();
if (breakpoint == null || !isBreakpointsActive()) {
// not a breakpoint node
continue;
}
boolean hit = true;
BreakpointConditionFailure failure = null;
try {
hit = breakpoint.notifyIndirectHit(source, node, frame);
} catch (BreakpointConditionFailure e) {
failure = e;
}
if (hit) {
if (breaks == null) {
breaks = new ArrayList<>();
}
breaks.add(breakpoint.isGlobal() ? breakpoint.getROWrapper() : breakpoint);
}
if (failure != null) {
if (breakpointFailures == null) {
breakpointFailures = new HashMap<>();
}
Breakpoint fb = failure.getBreakpoint();
if (fb.isGlobal()) {
fb = fb.getROWrapper();
}
breakpointFailures.put(fb, failure.getConditionFailure());
}
}
boolean hitStepping = s.step(this, source.getContext(), suspendAnchor);
boolean hitBreakpoint = breaks != null && !breaks.isEmpty();
if (hitStepping || hitBreakpoint) {
s.consume();
doSuspend(SuspendedContext.create(source.getContext()), suspendAnchor, frame, inputValuesProvider, returnValue, breaks, breakpointFailures);
} else {
if (Debugger.TRACE) {
trace("ignored suspended reason: strategy(%s) from source:%s context:%s location:%s", s, source, source.getContext(), source.getSuspendAnchors());
}
}
if (s.isKill()) {
// ComposedStrategy can become kill
throw new KillException();
}
}
use of com.oracle.truffle.api.CompilerDirectives.TruffleBoundary in project graal by oracle.
the class SetThreadSuspensionEnabledNode method getThreadSuspension.
@TruffleBoundary
protected ThreadSuspension getThreadSuspension(DebuggerSession[] sessions) {
assert sessions.length == 1;
ThreadSuspension threadSuspension = new ThreadSuspension(true);
sessions[0].threadSuspensions.set(threadSuspension);
return threadSuspension;
}
use of com.oracle.truffle.api.CompilerDirectives.TruffleBoundary in project graal by oracle.
the class PolyglotContextImpl method printResult.
@TruffleBoundary
private static void printResult(PolyglotLanguageContext languageContext, Object result) {
String stringResult = LANGUAGE.toStringIfVisible(languageContext.env, result, true);
if (stringResult != null) {
try {
OutputStream out = languageContext.context.out;
out.write(stringResult.getBytes(StandardCharsets.UTF_8));
out.write(System.getProperty("line.separator").getBytes(StandardCharsets.UTF_8));
} catch (IOException ioex) {
// out stream has problems.
throw new IllegalStateException(ioex);
}
}
}
use of com.oracle.truffle.api.CompilerDirectives.TruffleBoundary in project graal by oracle.
the class TruffleBoundaryPhase method run.
@Override
@SuppressWarnings("deprecation")
protected void run(StructuredGraph graph) {
for (Node n : graph.getNodes()) {
if (n instanceof InvokeWithExceptionNode) {
InvokeWithExceptionNode invoke = (InvokeWithExceptionNode) n;
ExceptionObjectNode exceptionObject = (ExceptionObjectNode) invoke.exceptionEdge();
FixedNode originalNext = exceptionObject.next();
if (!(originalNext instanceof DeoptimizeNode)) {
TruffleBoundary truffleBoundary = invoke.callTarget().targetMethod().getAnnotation(TruffleBoundary.class);
if (truffleBoundary != null) {
if (!truffleBoundary.throwsControlFlowException() && truffleBoundary.transferToInterpreterOnException()) {
addDeoptimizeNode(graph, originalNext);
}
}
}
}
}
}
Aggregations