OnStackReplacement (OSR) Invocation

52 views
Skip to first unread message

Malek Musleh

unread,
Mar 13, 2015, 1:14:02 PM3/13/15
to v8-u...@googlegroups.com
Hi,

I am trying to get a better understanding of when the OSR optimization
is invoked. As per my understanding, CrankShaft is only invoked for
functions which have been seen at least 2, based on the parameter
kProfilerTicksBeforeOptimization = 2 in runtime-profiler.cc. But
because there might be functions that get invoked only once, because
they may be "long running", there is opportunity for optimizing the
long running function via on stack replacement.

My specific question is how does the runtime profiler determine if the
function in question is "long enough" to attempt OSR? I can see OSR is
not attempted if there are too many formal parameters, but not where
it is decided that it passes the checks?


Malek

Ben Noordhuis

unread,
Mar 13, 2015, 1:46:48 PM3/13/15
to v8-u...@googlegroups.com
If I understand your question right: V8 inserts checks in function
prologs and around loop edges where it calls into the run-time.[0] If
the run-time sees the same JS function at the top of the stack several
times in a row, and if that function meets all criteria, it will
optimize it.

Hope that helps. Let me know if I need to go into more detail.

[0] That's the "call StackCheck" and "call InterruptCheck"
instructions you see in the generated machine code. The stack check
doubles as an interrupt check.

Malek Musleh

unread,
Mar 13, 2015, 2:33:26 PM3/13/15
to v8-u...@googlegroups.com
So to be clear, this is for OSR or just invoking crankshaft? In my
mind, I am viewing them as 2 different things (although I guess OSR is
part of crankshaft), the first for optimizing the function as it goes,
and the other trying to recompile the function for its next use.

Is it that seeing the same JS Function at the top of the stack several
times in a row, which means that its still executing the same function
, or that the same function has been invoked multiple times and now
its deemed "hot" for optimization.
> --
> --
> v8-users mailing list
> v8-u...@googlegroups.com
> http://groups.google.com/group/v8-users
> ---
> You received this message because you are subscribed to a topic in the Google Groups "v8-users" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/v8-users/qXapyd-Yc_Q/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to v8-users+u...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Ben Noordhuis

unread,
Mar 13, 2015, 2:52:57 PM3/13/15
to v8-u...@googlegroups.com
On Fri, Mar 13, 2015 at 7:33 PM, Malek Musleh <malek....@gmail.com> wrote:
> So to be clear, this is for OSR or just invoking crankshaft? In my
> mind, I am viewing them as 2 different things (although I guess OSR is
> part of crankshaft), the first for optimizing the function as it goes,
> and the other trying to recompile the function for its next use.

OSR is part of Crankshaft. If you run d8 with `--nocrankshaft
--trace_osr`, you'll never see log messages about OSR.

> Is it that seeing the same JS Function at the top of the stack several
> times in a row, which means that its still executing the same function
> , or that the same function has been invoked multiple times and now
> its deemed "hot" for optimization.

Both. I don't think V8 makes that distinction.
Reply all
Reply to author
Forward
0 new messages