Closed Bug 594591 Opened 14 years ago Closed 13 years ago

TM: abort recording if there are too many slots

Categories

(Core :: JavaScript Engine, defect)

x86
macOS
defect
Not set
normal

Tracking

()

RESOLVED WONTFIX

People

(Reporter: n.nethercote, Assigned: n.nethercote)

References

Details

Attachments

(1 file)

From bug 591631 comment 17, w.r.t. the example program in that bug:

> Having to walk 4,300 local slots every snapshot() to determine the typemap is
> sucky (academically, "total clownshoes"). We could keep track of the
> typemap incrementally as we record - which sounds tricky and error-prone
> given the current TR design. Easier might be caching the last known
> typemap and watermarking the -/+ positions on the stack, to only recompute
> a slice at the end.
>
> We'd have to be careful of opcodes like SETNAME or SETELEM which can
> change random stack slots.
>
> My guess is that test cases like this should be under the "don't bother
> tracing" category right now. If nfixed > XYZ, don't even record.

We've decided to do the latter -- abort recording if there are too many slots.
Can we detect this situation in jitprofiling and blacklist without even trying to record to start with, since the slot count should be known up front?
Attached patch profiler changeSplinter Review
This patch updates the profiler to avoid tracing if there are too many slots used.
Attachment #489581 - Flags: review?(bzbarsky)
I think this should be a hard check instead of inside the profiler.  In other words, we should avoid tracing such fragments even if -p is not specified.
Nicholas, I think it would make sense to check both places.

Bill, I'm not sure I'm qualified to review this patch, sorry...
(In reply to comment #4)
> Nicholas, I think it would make sense to check both places.

That doesn't make any sense.  If the check always occurs with -j then adding another check that only runs with -j -m -p will be redundant.

Another way to explain:  we currently abort recording for lots of reasons, right?  This is just another one.
(In reply to comment #5)
> That doesn't make any sense.  If the check always occurs with -j then adding
> another check that only runs with -j -m -p will be redundant.

Profiling is a lot cheaper than recording, so if we hit the check during profiling, we've wasted a lot less time than if we hit it during recording. So in that light, it probably does make sense to do it in both places.

Nick, could we just add an abort in monitorRecording if the number of slots in the current script is too high? Or did you have something else in mind?
(In reply to comment #6)
> 
> Nick, could we just add an abort in monitorRecording if the number of slots in
> the current script is too high? Or did you have something else in mind?

I was thinking we'd abort as early as possible in the recording process.  That way the overhead would be low but we'd only need to code the check once.  This case should be very rare in practice anyway.

BTW, did you get the 256 value from anywhere in particular?  That's a lot less than 4,300...
(In reply to comment #7)
> I was thinking we'd abort as early as possible in the recording process.  That
> way the overhead would be low but we'd only need to code the check once.  This
> case should be very rare in practice anyway.

I guess we could stick a check in MonitorLoopEdge. Should we worry about the case where the loop calls a function with lots of slots?

> BTW, did you get the 256 value from anywhere in particular?  That's a lot less
> than 4,300...

Making up arbitrary constants is my favorite part of working at Mozilla. It's especially thrilling when I don't #define them ahead of time.

I guess to do this right, we should somehow measure the cost of snapshotting and weigh it against the gain from tracing. But then we'd have to estimate the number of snapshots that the trace would require. An alternate idea is to count the total number of slots snapshotted during the trace and abort if it hits some threshold. But then we waste more time before aborting.

Maybe we should instrument a browser to print the max number of slots seen while browsing, and just use double this number as our threshold.
(In reply to comment #8)
> 
> I guess we could stick a check in MonitorLoopEdge. Should we worry about the
> case where the loop calls a function with lots of slots?

If it's difficult, and not worrying about it fixes this bug, then I wouldn't worry about it.

> Making up arbitrary constants is my favorite part of working at Mozilla. It's
> especially thrilling when I don't #define them ahead of time.

Good thing you're working on the profiler, then! :)

> I guess to do this right, we should somehow measure the cost of snapshotting
> and weigh it against the gain from tracing. But then we'd have to estimate the
> number of snapshots that the trace would require. An alternate idea is to count
> the total number of slots snapshotted during the trace and abort if it hits
> some threshold. But then we waste more time before aborting.
> 
> Maybe we should instrument a browser to print the max number of slots seen
> while browsing, and just use double this number as our threshold.

The latter sounds good -- ie. something not completely arbitrary, but let's not spend too much time on a rare case.
Comment on attachment 489581 [details] [diff] [review]
profiler change

This really needs a different reviewer, like I said.  Picking one via 6-sided coin flip.
Attachment #489581 - Flags: review?(bzbarsky) → review?(dmandelin)
Comment on attachment 489581 [details] [diff] [review]
profiler change

I think maxStackSlots isn't initialized. Looks like LoopProfile::reset is the place.

Otherwise, looks fine, although it would be nice if there was an additional pointer to the reader that |maxStackSlots| is a maximum observed value, as opposed to a maximum allowed value (which is my usual assumption when seeing 'max'). Adding 'seen' or 'observed' to the var name or comment would do it, I think.
Attachment #489581 - Flags: review?(dmandelin) → review-
TM's days are numbered:  WONTFIX.
Status: ASSIGNED → RESOLVED
Closed: 13 years ago
Resolution: --- → WONTFIX
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: