Bug 194675 - Move bytecode cache-related filesystem code out of CodeCache
Summary: Move bytecode cache-related filesystem code out of CodeCache
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Tadeu Zagallo
URL:
Keywords: InRadar
Depends on: 194762
Blocks:
  Show dependency treegraph
 
Reported: 2019-02-14 14:37 PST by Tadeu Zagallo
Modified: 2019-02-19 02:05 PST (History)
7 users (show)

See Also:


Attachments
Patch (11.64 KB, patch)
2019-02-14 14:46 PST, Tadeu Zagallo
no flags Details | Formatted Diff | Diff
Patch (12.26 KB, patch)
2019-02-15 03:07 PST, Tadeu Zagallo
no flags Details | Formatted Diff | Diff
Patch (12.28 KB, patch)
2019-02-15 04:52 PST, Tadeu Zagallo
no flags Details | Formatted Diff | Diff
Patch (13.07 KB, patch)
2019-02-18 01:39 PST, Tadeu Zagallo
no flags Details | Formatted Diff | Diff
Patch (13.10 KB, patch)
2019-02-18 02:42 PST, Tadeu Zagallo
no flags Details | Formatted Diff | Diff
Patch (12.95 KB, patch)
2019-02-18 13:20 PST, Tadeu Zagallo
no flags Details | Formatted Diff | Diff
Patch for landing (13.11 KB, patch)
2019-02-19 01:26 PST, Tadeu Zagallo
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Tadeu Zagallo 2019-02-14 14:37:07 PST
That code is only used for the bytecode-cache tests, so it should probably live in jsc.cpp rather than in the CodeCache.
Comment 1 Tadeu Zagallo 2019-02-14 14:46:15 PST
Created attachment 362064 [details]
Patch
Comment 2 Saam Barati 2019-02-14 15:41:35 PST
Comment on attachment 362064 [details]
Patch

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

This is a nice improvement, but I have one comment. Also you probably need to comment out more code on non-darwin platforms.

> Source/JavaScriptCore/runtime/CodeCache.cpp:206
> +    CachedBytecode cachedBytecode { WTFMove(result.first), result.second };
> +    key.source().provider().cacheBytecode(cachedBytecode);

Seems weird to have this function predicated on the cachePath above. Why not just make source provider tell you if it can cache or not?
Comment 3 Saam Barati 2019-02-14 15:42:04 PST
Comment on attachment 362064 [details]
Patch

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

> Source/JavaScriptCore/ChangeLog:8
> +        That code is only used for the bytecode-cache tests, so it should probably

no "probably"

> Source/JavaScriptCore/jsc.cpp:957
> +class CliSourceProvider : public StringSourceProvider {

I'd just call this "ShellSourceProvider" or "CommandLineSourceProvider"
Comment 4 Tadeu Zagallo 2019-02-15 03:07:19 PST
Created attachment 362108 [details]
Patch
Comment 5 Tadeu Zagallo 2019-02-15 03:07:42 PST
Comment on attachment 362064 [details]
Patch

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

>> Source/JavaScriptCore/runtime/CodeCache.cpp:206
>> +    key.source().provider().cacheBytecode(cachedBytecode);
> 
> Seems weird to have this function predicated on the cachePath above. Why not just make source provider tell you if it can cache or not?

Oops, this was an oversight. It shouldn't be darwin-specific either.
Comment 6 Tadeu Zagallo 2019-02-15 04:52:34 PST
Created attachment 362111 [details]
Patch
Comment 7 WebKit Commit Bot 2019-02-15 13:28:00 PST
Comment on attachment 362111 [details]
Patch

Clearing flags on attachment: 362111

Committed r241612: <https://trac.webkit.org/changeset/241612>
Comment 8 WebKit Commit Bot 2019-02-15 13:28:01 PST
All reviewed patches have been landed.  Closing bug.
Comment 9 Radar WebKit Bug Importer 2019-02-15 13:28:27 PST
<rdar://problem/48122052>
Comment 10 Saam Barati 2019-02-17 10:09:10 PST
Comment on attachment 362111 [details]
Patch

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

> Source/JavaScriptCore/runtime/CodeCache.cpp:199
>      std::pair<MallocPtr<uint8_t>, size_t> result = encodeCodeBlock(vm, key, codeBlock);

This patch made it so that we're now eagerly encoding CodeBlocks even if we can't cache it. And we're doing it as we remove entries from the cache. That's not the behavior we want
Comment 11 WebKit Commit Bot 2019-02-17 10:10:06 PST
Re-opened since this is blocked by bug 194762
Comment 12 Tadeu Zagallo 2019-02-17 10:30:41 PST
(In reply to Saam Barati from comment #10)
> Comment on attachment 362111 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=362111&action=review
> 
> > Source/JavaScriptCore/runtime/CodeCache.cpp:199
> >      std::pair<MallocPtr<uint8_t>, size_t> result = encodeCodeBlock(vm, key, codeBlock);
> 
> This patch made it so that we're now eagerly encoding CodeBlocks even if we
> can't cache it. And we're doing it as we remove entries from the cache.
> That's not the behavior we want

Oops, that's not good... I'll upload a correct patch soon.
Comment 13 Tadeu Zagallo 2019-02-18 01:39:21 PST
Created attachment 362271 [details]
Patch
Comment 14 Tadeu Zagallo 2019-02-18 01:43:56 PST
I attached the new patch, which now has SourceProvider::useBytecodeCache to avoid the wasteful computations. I also merged the `flock` flags into `open` and added the `makeScopeExit` as Saam suggested in https://bugs.webkit.org/show_bug.cgi?id=194768.
Comment 15 Tadeu Zagallo 2019-02-18 02:42:04 PST
Created attachment 362281 [details]
Patch

Rebase
Comment 16 Saam Barati 2019-02-18 11:35:56 PST
Comment on attachment 362281 [details]
Patch

r=me. I think you need to also return true for useBytecodeCache in JSScriptSourceProvider
Comment 17 Tadeu Zagallo 2019-02-18 12:34:04 PST
(In reply to Saam Barati from comment #16)
> Comment on attachment 362281 [details]
> Patch
> 
> r=me. I think you need to also return true for useBytecodeCache in
> JSScriptSourceProvider

Good point. I'll update it. Thanks!
Comment 18 Tadeu Zagallo 2019-02-18 13:20:38 PST
Created attachment 362322 [details]
Patch
Comment 19 Tadeu Zagallo 2019-02-18 13:25:39 PST
(In reply to Tadeu Zagallo from comment #17)
> (In reply to Saam Barati from comment #16)
> > Comment on attachment 362281 [details]
> > Patch
> > 
> > r=me. I think you need to also return true for useBytecodeCache in
> > JSScriptSourceProvider
> 
> Good point. I'll update it. Thanks!

When I went to update JSScriptSourceProvider, I realized that we would still unnecessarily encode all the CodeBlocks for it, since it'd return `true` from `useBytecodeCache` in order to be able to provide a cache, but it never writes through the `cacheBytecode` callback.

I changed `cacheBytecode` to take a function that generates the cached bytecode, so I put it up for review again just in case.
Comment 20 Saam Barati 2019-02-18 15:07:36 PST
Comment on attachment 362322 [details]
Patch

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

r=me

> Source/JavaScriptCore/ChangeLog:9
> +        That code is only used for the bytecode-cache tests, so it should live in
> +        jsc.cpp rather than in the CodeCache.

You should make a couple comments about how this changes the interface for caching.

> Source/JavaScriptCore/parser/SourceProvider.h:120
> +        virtual void cacheBytecode(const BytecodeCacheGenerator&) const { }

I agree this is nicer than the canCache and solves the issue you found.

> Source/JavaScriptCore/runtime/CodeCache.cpp:202
> +    key.source().provider().cacheBytecode([&]() {

style nit: no need for "()"
Comment 21 Tadeu Zagallo 2019-02-19 01:26:19 PST
Created attachment 362374 [details]
Patch for landing
Comment 22 WebKit Commit Bot 2019-02-19 02:04:58 PST
Comment on attachment 362374 [details]
Patch for landing

Clearing flags on attachment: 362374

Committed r241758: <https://trac.webkit.org/changeset/241758>
Comment 23 WebKit Commit Bot 2019-02-19 02:05:00 PST
All reviewed patches have been landed.  Closing bug.