@Override public boolean inject(boolean condition) { if (CompilerDirectives.inCompiledCode()) { return CompilerDirectives.injectBranchProbability(calculateProbability(trueCount, falseCount), condition); } else { return condition; } }
@Override public boolean inject(boolean condition) { if (CompilerDirectives.inCompiledCode()) { return CompilerDirectives.injectBranchProbability(calculateProbability(trueCount, falseCount), condition); } else { return condition; } }
@Override public boolean profile(boolean condition) { // locals required to guarantee no overflow in multi-threaded environments long trueCountLocal = trueCount; int falseCountLocal = falseCount; if (trueCountLocal == 0) { // Deopt for never entering the loop. if (condition) { CompilerDirectives.transferToInterpreterAndInvalidate(); } } // No deopt for not entering the loop. if (CompilerDirectives.inInterpreter()) { if (condition) { if (trueCountLocal < Long.MAX_VALUE) { trueCount = trueCountLocal + 1; } } else { if (falseCountLocal < Integer.MAX_VALUE) { falseCount = falseCountLocal + 1; } } // no branch probability calculation in the interpreter return condition; } else { return CompilerDirectives.injectBranchProbability(calculateProbability(trueCountLocal, falseCountLocal), condition); } }
@Override public boolean profile(boolean condition) { // locals required to guarantee no overflow in multi-threaded environments long trueCountLocal = trueCount; int falseCountLocal = falseCount; if (trueCountLocal == 0) { // Deopt for never entering the loop. if (condition) { CompilerDirectives.transferToInterpreterAndInvalidate(); } } // No deopt for not entering the loop. if (CompilerDirectives.inInterpreter()) { if (condition) { if (trueCountLocal < Long.MAX_VALUE) { trueCount = trueCountLocal + 1; } } else { if (falseCountLocal < Integer.MAX_VALUE) { falseCount = falseCountLocal + 1; } } // no branch probability calculation in the interpreter return condition; } else { return CompilerDirectives.injectBranchProbability(calculateProbability(trueCountLocal, falseCountLocal), condition); } }
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); }
@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); }
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); }
Object enter() { Object context; PolyglotThreadInfo info = getCachedThreadInfo(); if (CompilerDirectives.injectBranchProbability(CompilerDirectives.LIKELY_PROBABILITY, info.thread == Thread.currentThread())) { // fast-path -> same thread context = SINGLE_CONTEXT_STATE.contextThreadLocal.setReturnParent(this); info.enter(); } else { // slow path -> changed thread if (singleThreaded.isValid()) { CompilerDirectives.transferToInterpreter(); } context = enterThreadChanged(); } assert this == current(); return context; }
Object enter() { Object context; PolyglotThreadInfo info = getCachedThreadInfo(); if (CompilerDirectives.injectBranchProbability(CompilerDirectives.LIKELY_PROBABILITY, info.thread == (TruffleOptions.AOT ? ContextThreadLocal.currentThread() : Thread.currentThread()))) { // fast-path -> same thread context = singleContextState.contextThreadLocal.setReturnParent(this); info.enter(); } else { // slow path -> changed thread if (singleThreaded.isValid()) { CompilerDirectives.transferToInterpreter(); } context = enterThreadChanged(); } assert this == current(); return context; }
} else { int sum = t + f; return CompilerDirectives.injectBranchProbability((double) t / (double) sum, value);
} else { int sum = t + f; return CompilerDirectives.injectBranchProbability((double) t / (double) sum, value);
@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); } }