Bug 129355 - Compilation policy management belongs in operationOptimize(), not the DFG Driver.
Summary: Compilation policy management belongs in operationOptimize(), not the DFG Dri...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Mark Lam
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2014-02-25 18:40 PST by Filip Pizlo
Modified: 2014-02-26 12:09 PST (History)
10 users (show)

See Also:


Attachments
the patch. (5.15 KB, patch)
2014-02-26 04:08 PST, Mark Lam
fpizlo: review-
fpizlo: commit-queue-
Details | Formatted Diff | Diff
patch 2: applied Filip’s feedback. (8.03 KB, patch)
2014-02-26 11:38 PST, Mark Lam
fpizlo: review-
Details | Formatted Diff | Diff
patch 3: applied more feedback. (8.63 KB, patch)
2014-02-26 12:02 PST, Mark Lam
fpizlo: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Filip Pizlo 2014-02-25 18:40:38 PST
If you want to poll for an opportunity to compile code, then you should do that outside of the DFG::compile() driver.  Such polling belongs in operationOptimize().  We already do such polling for shouldAlwaysBeInlined and for the execution counter itself.
Comment 1 Radar WebKit Bug Importer 2014-02-25 20:26:37 PST
<rdar://problem/16169484>
Comment 2 Mark Lam 2014-02-26 03:58:27 PST
Moving the previous title here for reference:
"CompilationInvalidated is reserved for signaling concurrent JIT race conditions and should never be used to mean "I didn't feel like compiling right now so ask me again later”.

By compilation policy, I mean the rules for determining whether to compile, when to compile, when to attempt compilation again, etc.  The few of these policy decisions being made in the DFG driver are now moved to operationOptimize() where we keep the rest of the policy logic.  Decisions that are based on the capabilities supported by the DFG are moved to DFG capabiliityLevel().

Patch coming.
Comment 3 Mark Lam 2014-02-26 04:08:50 PST
Created attachment 225246 [details]
the patch.
Comment 4 Filip Pizlo 2014-02-26 09:50:23 PST
Comment on attachment 225246 [details]
the patch.

View in context: https://bugs.webkit.org/attachment.cgi?id=225246&action=review

> Source/JavaScriptCore/dfg/DFGCapabilities.cpp:232
> +
> +    if (!MacroAssembler::supportsFloatingPoint())
> +        return CannotCompile;
> +
> +    if (!Options::bytecodeRangeToDFGCompile().isInRange(codeBlock->instructionCount()))
> +        return CannotCompile;
> +

I would put these checks into the mightCompile... and mightInline... methods.  There are a handful of places that will call the mightInline() methods instead of calling capabilityLevel().  You could give them all a common helper function like "isSupported(CodeBlock*)" that will do checks like supportsFloatingPoint and the bytecodeRange.

> Source/JavaScriptCore/jit/JITOperations.cpp:1053
> +    if (!Options::useDFGJIT()) {
> +        codeBlock->dontOptimizeAnytimeSoon();
> +        return encodeResult(0, 0);
> +    }
> +
> +    if (vm.enabledProfiler()) {
> +        codeBlock->optimizeAfterWarmUp();
> +        return encodeResult(0, 0);
> +    }
> +
> +    Debugger* debugger = codeBlock->globalObject()->debugger();
> +    if (debugger && (debugger->isStepping() || codeBlock->baselineAlternative()->hasDebuggerRequests())) {
> +        codeBlock->optimizeAfterWarmUp();
> +        return encodeResult(0, 0);
> +    }
> +

This should all be placed below the call to checkIfOptimizationThresholdReached().  That call must be the first thing you do on an ExecutionCounter slow path.

Also, the !useDFGJIT() part should be in DFGCapabilities.
Comment 5 Mark Lam 2014-02-26 11:38:31 PST
Created attachment 225270 [details]
patch 2: applied Filip’s feedback.
Comment 6 Filip Pizlo 2014-02-26 11:41:11 PST
Comment on attachment 225270 [details]
patch 2: applied Filip’s feedback.

View in context: https://bugs.webkit.org/attachment.cgi?id=225270&action=review

Almost there.

> Source/JavaScriptCore/dfg/DFGCapabilities.cpp:45
> +    if (!Options::useDFGJIT()
> +        || !MacroAssembler::supportsFloatingPoint()
> +        || !Options::bytecodeRangeToDFGCompile().isInRange(codeBlock->instructionCount()))
> +        return false;
> +    return true;

Why not just turn this into a single return statement?

> Source/JavaScriptCore/jit/JITOperations.cpp:1065
> +        codeBlock->optimizeAfterWarmUp();

You could call updateAllPredictions() here.

> Source/JavaScriptCore/jit/JITOperations.cpp:1071
> +        codeBlock->optimizeAfterWarmUp();

And here.

You could even have a helper that calls both optimizeAfterWarmUp and updateAllPredictions.
Comment 7 Mark Lam 2014-02-26 12:02:37 PST
Created attachment 225273 [details]
patch 3: applied more feedback.
Comment 8 Mark Lam 2014-02-26 12:09:21 PST
Thanks.  Landed in r164734: <http://trac.webkit.org/r164734>.