Bug 193546 - [JSC] Reduce size of memory used for ShadowChicken
Summary: [JSC] Reduce size of memory used for ShadowChicken
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Yusuke Suzuki
URL:
Keywords: InRadar
: 194431 (view as bug list)
Depends on:
Blocks: 193606
  Show dependency treegraph
 
Reported: 2019-01-17 11:55 PST by Yusuke Suzuki
Modified: 2019-02-08 10:48 PST (History)
6 users (show)

See Also:


Attachments
Patch (16.63 KB, patch)
2019-01-28 19:35 PST, Yusuke Suzuki
no flags Details | Formatted Diff | Diff
WIP (82.21 KB, patch)
2019-02-08 00:29 PST, Yusuke Suzuki
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Yusuke Suzuki 2019-01-17 11:55:17 PST
ShadowChicken's packet is large. It is 56 bytes. And we allocate 1000 packet storage for ShadowChicken. So ShadowChicken consumes 55K memory while VM is in action.
Comment 1 Yusuke Suzuki 2019-01-19 01:27:28 PST
1. Lazily allocate shadow chicken buffer
2. Reduce the size of packet anyway to reduce the buffer size even if it is allocated.
Comment 2 Yusuke Suzuki 2019-01-28 19:35:12 PST
Created attachment 360424 [details]
Patch
Comment 3 Mark Lam 2019-01-28 20:18:11 PST
Comment on attachment 360424 [details]
Patch

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

r=me with suggestions.

> Source/JavaScriptCore/ftl/FTLLowerDFGToB3.cpp:13472
> +        RELEASE_ASSERT(vm().shadowChicken());

nit: I know this is not a perf critical function, but can we pre-compute and cache vm().shadowChicken() in a local variable above and use the local shadowChicken variable in the 3 places in this function.  This more clearly communicates to the compiler that we're expecting the same shadowChicken value.  It also matches the idiom in the rest of this patch of fetching shadowChicken first (for the null check cases).

> Source/JavaScriptCore/jit/CCallHelpers.cpp:57
> +    RELEASE_ASSERT(vm.shadowChicken());

Ditto, precache shadowChicken?

> Source/JavaScriptCore/jit/JITOperations.cpp:2885
> +    RELEASE_ASSERT(vm.shadowChicken());

Ditto.  Precache shadowChicken?

> Source/JavaScriptCore/llint/LLIntSlowPaths.cpp:1894
> +    RELEASE_ASSERT(vm.shadowChicken());

Ditto.  Precache shadowChicken?

> Source/JavaScriptCore/llint/LLIntSlowPaths.cpp:1913
> +    RELEASE_ASSERT(vm.shadowChicken());

Ditto.  Precache shadowChicken?

> Source/JavaScriptCore/tools/JSDollarVM.cpp:2065
> +        vm->ensureShadowChicken();

Not that it matters that much because $vm is a debugging tool, but to be completely correct, I think this should be conditional on if (newDebuggerMode == DebuggerOn).  In fact, we can even releaseShadowChicken if newDebuggerMode == DebuggerOff (though we've never done that before).
Comment 4 Yusuke Suzuki 2019-01-28 20:29:05 PST
Comment on attachment 360424 [details]
Patch

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

Thanks!

>> Source/JavaScriptCore/ftl/FTLLowerDFGToB3.cpp:13472
>> +        RELEASE_ASSERT(vm().shadowChicken());
> 
> nit: I know this is not a perf critical function, but can we pre-compute and cache vm().shadowChicken() in a local variable above and use the local shadowChicken variable in the 3 places in this function.  This more clearly communicates to the compiler that we're expecting the same shadowChicken value.  It also matches the idiom in the rest of this patch of fetching shadowChicken first (for the null check cases).

Make sense. Fixed.

>> Source/JavaScriptCore/jit/CCallHelpers.cpp:57
>> +    RELEASE_ASSERT(vm.shadowChicken());
> 
> Ditto, precache shadowChicken?

Fixed.

>> Source/JavaScriptCore/jit/JITOperations.cpp:2885
>> +    RELEASE_ASSERT(vm.shadowChicken());
> 
> Ditto.  Precache shadowChicken?

Fixed.

>> Source/JavaScriptCore/llint/LLIntSlowPaths.cpp:1894
>> +    RELEASE_ASSERT(vm.shadowChicken());
> 
> Ditto.  Precache shadowChicken?

Fixed.

>> Source/JavaScriptCore/llint/LLIntSlowPaths.cpp:1913
>> +    RELEASE_ASSERT(vm.shadowChicken());
> 
> Ditto.  Precache shadowChicken?

Fixed.

>> Source/JavaScriptCore/tools/JSDollarVM.cpp:2065
>> +        vm->ensureShadowChicken();
> 
> Not that it matters that much because $vm is a debugging tool, but to be completely correct, I think this should be conditional on if (newDebuggerMode == DebuggerOn).  In fact, we can even releaseShadowChicken if newDebuggerMode == DebuggerOff (though we've never done that before).

Nice, yeah. Fixed.
Comment 5 Yusuke Suzuki 2019-01-28 20:33:39 PST
Committed r240637: <https://trac.webkit.org/changeset/240637>
Comment 6 Radar WebKit Bug Importer 2019-01-28 20:34:29 PST
<rdar://problem/47621712>
Comment 7 Saam Barati 2019-01-31 00:00:33 PST
Comment on attachment 360424 [details]
Patch

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

> Source/JavaScriptCore/jit/JITExceptions.cpp:56
> +    if (auto* shadowChicken = vm->shadowChicken())

Do we ever call setDebugger with JS frames on the stack?
Comment 8 Yusuke Suzuki 2019-01-31 01:53:26 PST
Comment on attachment 360424 [details]
Patch

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

>> Source/JavaScriptCore/jit/JITExceptions.cpp:56
>> +    if (auto* shadowChicken = vm->shadowChicken())
> 
> Do we ever call setDebugger with JS frames on the stack?

I don't think so, but either is fine anyway since if there is no shadowChicken, tail-call log is not recorded.
Comment 9 Yusuke Suzuki 2019-02-08 00:29:01 PST
Reopening to attach new patch.
Comment 10 Yusuke Suzuki 2019-02-08 00:29:02 PST
Created attachment 361495 [details]
WIP
Comment 11 Saam Barati 2019-02-08 01:18:42 PST
(In reply to Yusuke Suzuki from comment #10)
> Created attachment 361495 [details]
> WIP

What does this have to do with ShadowChicken?
Comment 12 Yusuke Suzuki 2019-02-08 01:26:19 PST
(In reply to Saam Barati from comment #11)
> (In reply to Yusuke Suzuki from comment #10)
> > Created attachment 361495 [details]
> > WIP
> 
> What does this have to do with ShadowChicken?

Oooooooops, I uploaded the patch to the wrong issue. The correct issue is https://bugs.webkit.org/show_bug.cgi?id=194375. Thank you for letting me know!
Comment 13 Saam Barati 2019-02-08 10:48:15 PST
*** Bug 194431 has been marked as a duplicate of this bug. ***