use of org.graalvm.compiler.core.common.util.CompilationAlarm in project graal by oracle.
the class HotSpotGraalCompiler method compileMethod.
@SuppressWarnings("try")
CompilationRequestResult compileMethod(CompilationRequest request, boolean installAsDefault) {
if (graalRuntime.isShutdown()) {
return HotSpotCompilationRequestResult.failure(String.format("Shutdown entered"), false);
}
ResolvedJavaMethod method = request.getMethod();
OptionValues options = graalRuntime.getOptions(method);
if (graalRuntime.isBootstrapping()) {
if (DebugOptions.BootstrapInitializeOnly.getValue(options)) {
return HotSpotCompilationRequestResult.failure(String.format("Skip compilation because %s is enabled", DebugOptions.BootstrapInitializeOnly.getName()), true);
}
if (bootstrapWatchDog != null) {
if (bootstrapWatchDog.hitCriticalCompilationRateOrTimeout()) {
// Drain the compilation queue to expedite completion of the bootstrap
return HotSpotCompilationRequestResult.failure("hit critical bootstrap compilation rate or timeout", true);
}
}
}
HotSpotCompilationRequest hsRequest = (HotSpotCompilationRequest) request;
try (CompilationWatchDog w1 = CompilationWatchDog.watch(method, hsRequest.getId(), options);
BootstrapWatchDog.Watch w2 = bootstrapWatchDog == null ? null : bootstrapWatchDog.watch(request);
CompilationAlarm alarm = CompilationAlarm.trackCompilationPeriod(options)) {
if (compilationCounters != null) {
compilationCounters.countCompilation(method);
}
CompilationTask task = new CompilationTask(jvmciRuntime, this, hsRequest, true, installAsDefault, options);
CompilationRequestResult r = null;
try (DebugContext debug = graalRuntime.openDebugContext(options, task.getCompilationIdentifier(), method, getDebugHandlersFactories());
Activation a = debug.activate()) {
r = task.runCompilation(debug);
}
assert r != null;
return r;
}
}
use of org.graalvm.compiler.core.common.util.CompilationAlarm in project graal by oracle.
the class GraalCompiler method compile.
/**
* Services a given compilation request.
*
* @return the result of the compilation
*/
@SuppressWarnings("try")
public static <T extends CompilationResult> T compile(Request<T> r) {
DebugContext debug = r.graph.getDebug();
try (CompilationAlarm alarm = CompilationAlarm.trackCompilationPeriod(r.graph.getOptions())) {
assert !r.graph.isFrozen();
try (DebugContext.Scope s0 = debug.scope("GraalCompiler", r.graph, r.providers.getCodeCache());
DebugCloseable a = CompilerTimer.start(debug)) {
emitFrontEnd(r.providers, r.backend, r.graph, r.graphBuilderSuite, r.optimisticOpts, r.profilingInfo, r.suites);
emitBackEnd(r.graph, null, r.installedCodeOwner, r.backend, r.compilationResult, r.factory, null, r.lirSuites);
} catch (Throwable e) {
throw debug.handle(e);
}
checkForRequestedCrash(r.graph);
return r.compilationResult;
}
}
use of org.graalvm.compiler.core.common.util.CompilationAlarm in project graal by oracle.
the class ReentrantBlockIterator method apply.
public static <StateT> EconomicMap<FixedNode, StateT> apply(BlockIteratorClosure<StateT> closure, Block start, StateT initialState, Predicate<Block> stopAtBlock) {
Deque<Block> blockQueue = new ArrayDeque<>();
/*
* States are stored on EndNodes before merges, and on BeginNodes after ControlSplitNodes.
*/
EconomicMap<FixedNode, StateT> states = EconomicMap.create(Equivalence.IDENTITY);
StateT state = initialState;
Block current = start;
StructuredGraph graph = start.getBeginNode().graph();
CompilationAlarm compilationAlarm = CompilationAlarm.current();
while (true) {
if (compilationAlarm.hasExpired()) {
int period = CompilationAlarm.Options.CompilationExpirationPeriod.getValue(graph.getOptions());
if (period > 120) {
throw new PermanentBailoutException("Compilation exceeded %d seconds during CFG traversal", period);
} else {
throw new RetryableBailoutException("Compilation exceeded %d seconds during CFG traversal", period);
}
}
Block next = null;
if (stopAtBlock != null && stopAtBlock.test(current)) {
states.put(current.getBeginNode(), state);
} else {
state = closure.processBlock(current, state);
Block[] successors = current.getSuccessors();
if (successors.length == 0) {
// nothing to do...
} else if (successors.length == 1) {
Block successor = successors[0];
if (successor.isLoopHeader()) {
if (current.isLoopEnd()) {
// nothing to do... loop ends only lead to loop begins we've already
// visited
states.put(current.getEndNode(), state);
} else {
recurseIntoLoop(closure, blockQueue, states, state, successor);
}
} else if (current.getEndNode() instanceof AbstractEndNode) {
AbstractEndNode end = (AbstractEndNode) current.getEndNode();
// add the end node and see if the merge is ready for processing
AbstractMergeNode merge = end.merge();
if (allEndsVisited(states, current, merge)) {
ArrayList<StateT> mergedStates = mergeStates(states, state, current, successor, merge);
state = closure.merge(successor, mergedStates);
next = successor;
} else {
assert !states.containsKey(end);
states.put(end, state);
}
} else {
next = successor;
}
} else {
next = processMultipleSuccessors(closure, blockQueue, states, state, successors);
}
}
// get next queued block
if (next != null) {
current = next;
} else if (blockQueue.isEmpty()) {
return states;
} else {
current = blockQueue.removeFirst();
assert current.getPredecessorCount() == 1;
assert states.containsKey(current.getBeginNode());
state = states.removeKey(current.getBeginNode());
}
}
}
use of org.graalvm.compiler.core.common.util.CompilationAlarm in project graal by oracle.
the class EffectsPhase method runAnalysis.
@SuppressWarnings("try")
public boolean runAnalysis(StructuredGraph graph, PhaseContextT context) {
boolean changed = false;
CompilationAlarm compilationAlarm = CompilationAlarm.current();
DebugContext debug = graph.getDebug();
for (int iteration = 0; iteration < maxIterations && !compilationAlarm.hasExpired(); iteration++) {
try (DebugContext.Scope s = debug.scope(debug.areScopesEnabled() ? "iteration " + iteration : null)) {
ScheduleResult schedule;
ControlFlowGraph cfg;
if (unscheduled) {
schedule = null;
cfg = ControlFlowGraph.compute(graph, true, true, false, false);
} else {
new SchedulePhase(SchedulePhase.SchedulingStrategy.EARLIEST).apply(graph, false);
schedule = graph.getLastSchedule();
cfg = schedule.getCFG();
}
try (DebugContext.Scope scheduleScope = debug.scope("EffectsPhaseWithSchedule", schedule)) {
Closure<?> closure = createEffectsClosure(context, schedule, cfg);
ReentrantBlockIterator.apply(closure, cfg.getStartBlock());
if (closure.needsApplyEffects()) {
// apply the effects collected during this iteration
HashSetNodeEventListener listener = new HashSetNodeEventListener();
try (NodeEventScope nes = graph.trackNodeEvents(listener)) {
closure.applyEffects();
}
if (debug.isDumpEnabled(DebugContext.VERBOSE_LEVEL)) {
debug.dump(DebugContext.VERBOSE_LEVEL, graph, "%s iteration", getName());
}
new DeadCodeEliminationPhase(Required).apply(graph);
EconomicSet<Node> changedNodes = listener.getNodes();
for (Node node : graph.getNodes()) {
if (node instanceof Simplifiable) {
changedNodes.add(node);
}
}
postIteration(graph, context, changedNodes);
}
if (closure.hasChanged()) {
changed = true;
} else {
break;
}
} catch (Throwable t) {
throw debug.handle(t);
}
}
}
return changed;
}
use of org.graalvm.compiler.core.common.util.CompilationAlarm in project graal by oracle.
the class TruffleCompilerImpl method compileAST.
/**
* Compiles a Truffle AST. If compilation succeeds, the AST will have compiled code associated
* with it that can be executed instead of interpreting the AST.
*
* @param compilable representation of the AST to be compiled
* @param inliningPlan
* @param compilationId identifier to be used for the compilation
* @param cancellable an object polled during the compilation process to
* {@linkplain CancellationBailoutException abort} early if the thread owning the
* cancellable requests it
* @param listener
*/
@SuppressWarnings("try")
public void compileAST(DebugContext debug, final CompilableTruffleAST compilable, TruffleInliningPlan inliningPlan, CompilationIdentifier compilationId, Cancellable cancellable, TruffleCompilerListener listener) {
final CompilationPrinter printer = CompilationPrinter.begin(TruffleCompilerOptions.getOptions(), compilationId, new TruffleDebugJavaMethod(compilable), INVOCATION_ENTRY_BCI);
StructuredGraph graph = null;
try (CompilationAlarm alarm = CompilationAlarm.trackCompilationPeriod(TruffleCompilerOptions.getOptions())) {
PhaseSuite<HighTierContext> graphBuilderSuite = createGraphBuilderSuite();
// Failed speculations must be collected before any compilation or
// partial evaluation is performed.
SpeculationLog speculationLog = compilable.getSpeculationLog();
if (speculationLog != null) {
speculationLog.collectFailedSpeculations();
}
try (DebugCloseable a = PartialEvaluationTime.start(debug);
DebugCloseable c = PartialEvaluationMemUse.start(debug)) {
graph = partialEvaluator.createGraph(debug, compilable, inliningPlan, AllowAssumptions.YES, compilationId, speculationLog, cancellable);
}
// Check if the task has been cancelled
if (cancellable != null && cancellable.isCancelled()) {
return;
}
if (listener != null) {
listener.onTruffleTierFinished(compilable, inliningPlan, new GraphInfoImpl(graph));
}
CompilationResult compilationResult = compilePEGraph(graph, compilable.toString(), graphBuilderSuite, compilable, asCompilationRequest(compilationId), listener);
if (listener != null) {
listener.onSuccess(compilable, inliningPlan, new GraphInfoImpl(graph), new CompilationResultInfoImpl(compilationResult));
}
// Partial evaluation and installation are included in
// compilation time and memory usage reported by printer
printer.finish(compilationResult);
} catch (Throwable t) {
// graph is null
if (listener != null) {
BailoutException bailout = t instanceof BailoutException ? (BailoutException) t : null;
boolean permanentBailout = bailout != null ? bailout.isPermanent() : false;
listener.onFailure(compilable, t.toString(), bailout != null, permanentBailout);
}
throw t;
}
}
Aggregations