[ES6] Cache the resolution result in JSModuleRecord
authorutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 14 Sep 2015 21:15:19 +0000 (21:15 +0000)
committerutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 14 Sep 2015 21:15:19 +0000 (21:15 +0000)
commitd01d05839ffa95c1a94338fa7869c44d242fdf87
tree0ecfdef54e7c120cdcb15bc40cd88993aa0502ad
parentf6953a26bd3ef20cf6ca5313fd3db4ea9267e53f
[ES6] Cache the resolution result in JSModuleRecord
https://bugs.webkit.org/show_bug.cgi?id=148896

Reviewed by Saam Barati.

The resolveExport operation is frequently called. For example,
1. When instantiating the module environment, we call it for each exported name and imported
   name.
2. When linking the imported module environment to the code block, we call it to resolve the
   resolution.
3. When looking up the property from the namespace object, we call it to look up the original
   module for the imported binding.
4. When creating the namespace object, we need to collect all the exported names from the module
   and need to resolve them by calling resolveExport.

However, resolveExport takes some cost. It traces the imported modules and resolves the reference
queried by the original module.

The resolveExport operation is pure function; given a module record and an export name,
it always returns the same result. So we cache resolution results in the module record to avoid
repeated resolveExport calls with the same arguments.
Here, we only cache the correctly resolved references, since,
1. We rarely looked up the non-correctly-resolved ones. In the linking phase, attempting to
   resolve non-correctly-resolved ones throws a syntax error. So only namespace object creation
   phase does it in a syntax valid script.
2. This strategy limits the size of the cache map. The number of the correctly exported bindings
   is defined by the modules' code. So the size does not become infinitely large.

Currently, the all modules cannot be linked twice. For example,

  graph 1

  -> (A) -> (B)

  graph 2

  -> (C) -> (A) -> (B)

We cannot test the behavior now because when executing the graph 2, (A) and (B) are already linked,
it raises an error in the current loader spec. But it should be allowed[1] since it will occur when
there is multiple module tag in WebCore.

[1]: https://github.com/whatwg/loader/issues/41

* runtime/JSModuleRecord.cpp:
(JSC::JSModuleRecord::ResolveQuery::Hash::hash):
(JSC::JSModuleRecord::ResolveQuery::Hash::equal):
(JSC::JSModuleRecord::cacheResolution):
(JSC::ResolveQueryHash::hash): Deleted.
(JSC::ResolveQueryHash::equal): Deleted.
(JSC::resolveExportLoop): Deleted.
* runtime/JSModuleRecord.h:
* tests/modules/caching-should-not-make-ambiguous.js: Added.
* tests/modules/caching-should-not-make-ambiguous/A.js: Added.
* tests/modules/caching-should-not-make-ambiguous/B.js: Added.
* tests/modules/caching-should-not-make-ambiguous/C.js: Added.
* tests/modules/caching-should-not-make-ambiguous/D.js: Added.
* tests/modules/caching-should-not-make-ambiguous/main.js: Added.
* tests/modules/different-view.js: Added.
(from.string_appeared_here.shouldThrow):
* tests/modules/different-view/A.js: Added.
* tests/modules/different-view/B.js: Added.
* tests/modules/different-view/C.js: Added.
* tests/modules/different-view/D.js: Added.
* tests/modules/different-view/E.js: Added.
* tests/modules/different-view/main.js: Added.
* tests/modules/fallback-ambiguous.js: Added.
(from.string_appeared_here.shouldThrow):
* tests/modules/fallback-ambiguous/A.js: Added.
* tests/modules/fallback-ambiguous/B.js: Added.
* tests/modules/fallback-ambiguous/C.js: Added.
* tests/modules/fallback-ambiguous/D.js: Added.
* tests/modules/fallback-ambiguous/E.js: Added.
* tests/modules/fallback-ambiguous/main.js: Added.
* tests/modules/self-star-link.js: Added.
* tests/modules/self-star-link/A.js: Added.
* tests/modules/self-star-link/B.js: Added.
* tests/modules/self-star-link/C.js: Added.
* tests/modules/self-star-link/D.js: Added.
* tests/modules/self-star-link/E.js: Added.
* tests/modules/uncacheable-when-see-star.js: Added.
* tests/modules/uncacheable-when-see-star/A-pre.js: Added.
* tests/modules/uncacheable-when-see-star/A.js: Added.
* tests/modules/uncacheable-when-see-star/B.js: Added.
* tests/modules/uncacheable-when-see-star/C.js: Added.
* tests/modules/uncacheable-when-see-star/D.js: Added.
* tests/modules/uncacheable-when-see-star/E-pre.js: Added.
* tests/modules/uncacheable-when-see-star/E.js: Added.
* tests/modules/uncacheable-when-see-star/main1.js: Added.
* tests/modules/uncacheable-when-see-star/main2.js: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@189747 268f45cc-cd09-0410-ab3c-d52691b4dbfc
39 files changed:
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/runtime/JSModuleRecord.cpp
Source/JavaScriptCore/runtime/JSModuleRecord.h
Source/JavaScriptCore/tests/modules/caching-should-not-make-ambiguous.js [new file with mode: 0644]
Source/JavaScriptCore/tests/modules/caching-should-not-make-ambiguous/A.js [new file with mode: 0644]
Source/JavaScriptCore/tests/modules/caching-should-not-make-ambiguous/B.js [new file with mode: 0644]
Source/JavaScriptCore/tests/modules/caching-should-not-make-ambiguous/C.js [new file with mode: 0644]
Source/JavaScriptCore/tests/modules/caching-should-not-make-ambiguous/D.js [new file with mode: 0644]
Source/JavaScriptCore/tests/modules/caching-should-not-make-ambiguous/main.js [new file with mode: 0644]
Source/JavaScriptCore/tests/modules/different-view.js [new file with mode: 0644]
Source/JavaScriptCore/tests/modules/different-view/A.js [new file with mode: 0644]
Source/JavaScriptCore/tests/modules/different-view/B.js [new file with mode: 0644]
Source/JavaScriptCore/tests/modules/different-view/C.js [new file with mode: 0644]
Source/JavaScriptCore/tests/modules/different-view/D.js [new file with mode: 0644]
Source/JavaScriptCore/tests/modules/different-view/E.js [new file with mode: 0644]
Source/JavaScriptCore/tests/modules/different-view/main.js [new file with mode: 0644]
Source/JavaScriptCore/tests/modules/fallback-ambiguous.js [new file with mode: 0644]
Source/JavaScriptCore/tests/modules/fallback-ambiguous/A.js [new file with mode: 0644]
Source/JavaScriptCore/tests/modules/fallback-ambiguous/B.js [new file with mode: 0644]
Source/JavaScriptCore/tests/modules/fallback-ambiguous/C.js [new file with mode: 0644]
Source/JavaScriptCore/tests/modules/fallback-ambiguous/D.js [new file with mode: 0644]
Source/JavaScriptCore/tests/modules/fallback-ambiguous/E.js [new file with mode: 0644]
Source/JavaScriptCore/tests/modules/fallback-ambiguous/main.js [new file with mode: 0644]
Source/JavaScriptCore/tests/modules/self-star-link.js [new file with mode: 0644]
Source/JavaScriptCore/tests/modules/self-star-link/A.js [new file with mode: 0644]
Source/JavaScriptCore/tests/modules/self-star-link/B.js [new file with mode: 0644]
Source/JavaScriptCore/tests/modules/self-star-link/C.js [new file with mode: 0644]
Source/JavaScriptCore/tests/modules/self-star-link/D.js [new file with mode: 0644]
Source/JavaScriptCore/tests/modules/self-star-link/E.js [new file with mode: 0644]
Source/JavaScriptCore/tests/modules/uncacheable-when-see-star.js [new file with mode: 0644]
Source/JavaScriptCore/tests/modules/uncacheable-when-see-star/A-pre.js [new file with mode: 0644]
Source/JavaScriptCore/tests/modules/uncacheable-when-see-star/A.js [new file with mode: 0644]
Source/JavaScriptCore/tests/modules/uncacheable-when-see-star/B.js [new file with mode: 0644]
Source/JavaScriptCore/tests/modules/uncacheable-when-see-star/C.js [new file with mode: 0644]
Source/JavaScriptCore/tests/modules/uncacheable-when-see-star/D.js [new file with mode: 0644]
Source/JavaScriptCore/tests/modules/uncacheable-when-see-star/E-pre.js [new file with mode: 0644]
Source/JavaScriptCore/tests/modules/uncacheable-when-see-star/E.js [new file with mode: 0644]
Source/JavaScriptCore/tests/modules/uncacheable-when-see-star/main1.js [new file with mode: 0644]
Source/JavaScriptCore/tests/modules/uncacheable-when-see-star/main2.js [new file with mode: 0644]