/** * Creates an exception thrown to enter a slow path. * * @since 0.8 or earlier */ public SlowPathException(String message) { super(message); CompilerDirectives.transferToInterpreterAndInvalidate(); }
Env requireEnv() { Env localEnv = this.env; if (localEnv == null) { CompilerDirectives.transferToInterpreter(); throw new AssertionError( "No language context is active on this thread."); } return localEnv; }
@Override public boolean profile(boolean value) { if (value) { if (trueCount == 0) { CompilerDirectives.transferToInterpreterAndInvalidate(); } if (CompilerDirectives.inInterpreter()) { trueCount++; } } else { if (falseCount == 0) { CompilerDirectives.transferToInterpreterAndInvalidate(); } if (CompilerDirectives.inInterpreter()) { falseCount++; } } return CompilerDirectives.injectBranchProbability((double) trueCount / (double) (trueCount + falseCount), value); }
@Override public boolean inject(boolean condition) { if (CompilerDirectives.inCompiledCode()) { return CompilerDirectives.injectBranchProbability(calculateProbability(trueCount, falseCount), condition); } else { return condition; } }
@Override protected void onEnter(VirtualFrame frame) { if (CompilerDirectives.inCompiledCode() && ignoreInlinedRoots && isAttachedToRootTag && !CompilerDirectives.inCompilationRoot()) { return; } doOnEnter(); }
@Override protected void onEnter(VirtualFrame frame) { if (CompilerDirectives.inInterpreter()) { counter.interpretedInvocations++; } else { counter.compiledInvocations++; } }
private void doOnEnter() { StackTraceEntry location = CompilerDirectives.inInterpreter() ? interpretedLocation : (CompilerDirectives.inCompilationRoot() ? compiledLocation : compilationRootLocation); if (seenOtherThreads) { pushSlow(location); } else if (cachedThread == Thread.currentThread()) { cachedStack.push(location); } else { CompilerDirectives.transferToInterpreterAndInvalidate(); seenOtherThreads = true; pushSlow(location); } }
void leave(Object prev) { assert current() == this : "Cannot leave context that is currently not entered. Forgot to enter or leave a context?"; PolyglotThreadInfo info = getCachedThreadInfo(); if (CompilerDirectives.injectBranchProbability(CompilerDirectives.LIKELY_PROBABILITY, info.thread == Thread.currentThread())) { info.leave(); } else { if (singleThreaded.isValid()) { CompilerDirectives.transferToInterpreter(); } leaveThreadChanged(); } SINGLE_CONTEXT_STATE.contextThreadLocal.set(prev); }
/** * Returns the size of an array which is needed for storing all the frame slots. (The number may * be bigger than the number of slots, if some slots are removed.) * * @return the size of the frame * @since 0.8 or earlier */ public int getSize() { if (CompilerDirectives.inCompiledCode()) { if (!this.version.isValid()) { CompilerDirectives.transferToInterpreterAndInvalidate(); } } return this.size; }
@Override protected void onReturnValue(VirtualFrame frame, Object result) { if (ignoreInlinedRoots) { if (CompilerDirectives.inCompiledCode()) { if (isAttachedToRootTag && !CompilerDirectives.inCompilationRoot()) { return; } } else { // This is needed to control for the case that an invalidation happened in an // inlined root. // Than there should be no stack pop until we exit the original compilation // root. // Not needed if stack overflowed final ThreadLocalStack stack = getStack(); if (!stack.hasStackOverflowed() && stack.top().getInstrumentedNode() != interpretedLocation.getInstrumentedNode()) { return; } } } if (seenOtherThreads) { popSlow(compiledLocation); } else if (cachedThread == Thread.currentThread()) { cachedStack.pop(compiledLocation); } else { CompilerDirectives.transferToInterpreterAndInvalidate(); seenOtherThreads = true; popSlow(compiledLocation); } }
@Override public void executeVoid(VirtualFrame frame) { final boolean condition; try { condition = conditionNode.executeBoolean(frame); } catch (UnexpectedResultException e) { // TODO throw new UnsupportedOperationException(e); } if (CompilerDirectives.injectBranchProbability(getBranchProbability(), condition)) { if (CompilerDirectives.inInterpreter()) { thenCount++; } thenProfile.enter(); thenPartNode.executeVoid(frame); } else { if (CompilerDirectives.inInterpreter()) { elseCount++; } elseProfile.enter(); elsePartNode.executeVoid(frame); } }
private TruffleOptInstrumentNode(AbstractInstrumentNode nextNode) { super(nextNode); this.isCompiled = CompilerDirectives.inCompiledCode(); }
/** * Assertion that the corresponding value is reduced to a constant during compilation. * * @param value the value that must be constant during compilation */ public static <T> void compilationConstant(Object value) { if (!CompilerDirectives.isCompilationConstant(value)) { neverPartOfCompilation("Value is not compilation constant"); } }
@Override protected void onEnter(VirtualFrame frame) { if (CompilerDirectives.inInterpreter()) { payload.countInterpreted++; } else { payload.countCompiled++; } }
void leave(Object prev) { assert current() == this : "Cannot leave context that is currently not entered. Forgot to enter or leave a context?"; PolyglotThreadInfo info = getCachedThreadInfo(); if (CompilerDirectives.injectBranchProbability(CompilerDirectives.LIKELY_PROBABILITY, info.thread == (TruffleOptions.AOT ? ContextThreadLocal.currentThread() : Thread.currentThread()))) { info.leave(); } else { if (singleThreaded.isValid()) { CompilerDirectives.transferToInterpreter(); } leaveThreadChanged(); } singleContextState.contextThreadLocal.set(prev); }
@Override public boolean inject(boolean condition) { if (CompilerDirectives.inCompiledCode()) { return CompilerDirectives.injectBranchProbability(calculateProbability(trueCount, falseCount), condition); } else { return condition; } }
public void enter(Node node, VirtualFrame vFrame) { if (this.isCompiled != CompilerDirectives.inCompiledCode()) { this.isCompiled = CompilerDirectives.inCompiledCode(); TruffleOptInstrument.this.toolOptListener.notifyIsCompiled(this.isCompiled); } if (nextInstrumentNode != null) { nextInstrumentNode.enter(node, vFrame); } }
/** * Assertion that the corresponding value is reduced to a constant during compilation. * * @param value the value that must be constant during compilation * @since 0.8 or earlier */ public static <T> void compilationConstant(Object value) { if (!CompilerDirectives.isCompilationConstant(value)) { neverPartOfCompilation("Value is not compilation constant"); } }
/** * Creates an exception thrown to enter a slow path. * * @since 0.8 or earlier */ public SlowPathException(Throwable cause) { super(cause); CompilerDirectives.transferToInterpreterAndInvalidate(); }
if (value) { if (t == 0) { CompilerDirectives.transferToInterpreterAndInvalidate(); if (CompilerDirectives.inInterpreter()) { if (t < MAX_VALUE) { trueCount = t + 1; CompilerDirectives.transferToInterpreterAndInvalidate(); if (CompilerDirectives.inInterpreter()) { if (f < MAX_VALUE) { falseCount = f + 1; if (CompilerDirectives.inInterpreter()) { return CompilerDirectives.injectBranchProbability((double) t / (double) sum, value);