Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(54)

Issue 11093074: Get rid of static module allocation, do it in code. (Closed)

Created:
8 years, 2 months ago by rossberg
Modified:
8 years ago
CC:
v8-dev
Visibility:
Public.

Description

Get rid of static module allocation, do it in code. Modules now have their own local scope, represented by their own context. Module instance objects have an accessor for every export that forwards access to the respective slot from the module's context. (Exports that are modules themselves, however, are simple data properties.) All modules have a _hosting_ scope/context, which (currently) is the (innermost) enclosing global scope. To deal with recursion, nested modules are hosted by the same scope as global ones. For every (global or nested) module literal, the hosting context has an internal slot that points directly to the respective module context. This enables quick access to (statically resolved) module members by 2-dimensional access through the hosting context. For example, module A { let x; module B { let y; } } module C { let z; } allocates contexts as follows: [header| .A | .B | .C | A | C ] (global) | | | | | +-- [header| z ] (module) | | | +------- [header| y ] (module) | +------------ [header| x | B ] (module) Here, .A, .B, .C are the internal slots pointing to the hosted module contexts, whereas A, B, C hold the actual instance objects (note that every module context also points to the respective instance object through its extension slot in the header). To deal with arbitrary recursion and aliases between modules, they are created and initialized in several stages. Each stage applies to all modules in the hosting global scope, including nested ones. 1. Allocate: for each module _literal_, allocate the module contexts and respective instance object and wire them up. This happens in the PushModuleContext runtime function, as generated by AllocateModules (invoked by VisitDeclarations in the hosting scope). 2. Bind: for each module _declaration_ (i.e. literals as well as aliases), assign the respective instance object to respective local variables. This happens in VisitModuleDeclaration, and uses the instance objects created in the previous stage. For each module _literal_, this phase also constructs a module descriptor for the next stage. This happens in VisitModuleLiteral. 3. Populate: invoke the DeclareModules runtime function to populate each _instance_ object with accessors for it exports. This is generated by DeclareModules (invoked by VisitDeclarations in the hosting scope again), and uses the descriptors generated in the previous stage. 4. Initialize: execute the module bodies (and other code) in sequence. This happens by the separate statements generated for module bodies. To reenter the module scopes properly, the parser inserted ModuleStatements. R=mstarzinger@chromium.org,svenpanne@chromium.org BUG= Committed: https://code.google.com/p/v8/source/detail?r=13033

Patch Set 1 #

Total comments: 28

Patch Set 2 : Addressed comments #

Total comments: 4

Patch Set 3 : Addressed last comments; added other back-ends #

Unified diffs Side-by-side diffs Delta from patch set Stats (+783 lines, -401 lines) Patch
M src/arm/full-codegen-arm.cc View 1 2 3 chunks +35 lines, -28 lines 0 comments Download
M src/arm/macro-assembler-arm.h View 1 2 1 chunk +1 line, -0 lines 0 comments Download
M src/ast.h View 5 chunks +27 lines, -2 lines 0 comments Download
M src/ast.cc View 2 chunks +3 lines, -4 lines 0 comments Download
M src/contexts.h View 1 1 chunk +3 lines, -0 lines 0 comments Download
src/contexts.cc View 1 2 chunks +13 lines, -0 lines 0 comments Download
M src/full-codegen.h View 2 chunks +8 lines, -0 lines 0 comments Download
M src/full-codegen.cc View 1 2 7 chunks +193 lines, -36 lines 0 comments Download
M src/heap.cc View 1 chunk +1 line, -1 line 0 comments Download
M src/hydrogen.cc View 1 chunk +5 lines, -0 lines 0 comments Download
M src/ia32/full-codegen-ia32.cc View 1 2 4 chunks +37 lines, -31 lines 0 comments Download
M src/ia32/macro-assembler-ia32.h View 1 2 1 chunk +1 line, -0 lines 0 comments Download
M src/interface.h View 3 chunks +26 lines, -9 lines 0 comments Download
M src/interface.cc View 3 chunks +3 lines, -10 lines 0 comments Download
M src/objects.h View 1 chunk +1 line, -1 line 0 comments Download
M src/objects.cc View 1 chunk +4 lines, -0 lines 0 comments Download
M src/parser.cc View 4 chunks +11 lines, -9 lines 0 comments Download
M src/prettyprinter.cc View 2 chunks +15 lines, -0 lines 0 comments Download
src/property-details.h View 1 1 chunk +4 lines, -0 lines 0 comments Download
M src/rewriter.cc View 2 chunks +8 lines, -1 line 0 comments Download
M src/runtime.h View 2 chunks +2 lines, -1 line 0 comments Download
M src/runtime.cc View 1 2 3 chunks +82 lines, -15 lines 0 comments Download
M src/scopeinfo.h View 1 2 2 chunks +64 lines, -3 lines 0 comments Download
M src/scopeinfo.cc View 1 2 2 chunks +29 lines, -0 lines 0 comments Download
M src/scopes.h View 1 7 chunks +24 lines, -7 lines 0 comments Download
src/scopes.cc View 1 16 chunks +75 lines, -84 lines 0 comments Download
M src/v8globals.h View 3 chunks +13 lines, -11 lines 0 comments Download
M src/variables.cc View 2 chunks +4 lines, -2 lines 0 comments Download
src/x64/full-codegen-x64.cc View 1 2 4 chunks +35 lines, -29 lines 0 comments Download
M test/cctest/test-decls.cc View 1 2 chunks +51 lines, -116 lines 0 comments Download
M test/mjsunit/fuzz-natives-part1.js View 1 chunk +1 line, -0 lines 0 comments Download
M test/mjsunit/fuzz-natives-part2.js View 1 chunk +1 line, -0 lines 0 comments Download
M test/mjsunit/fuzz-natives-part3.js View 1 chunk +1 line, -0 lines 0 comments Download
M test/mjsunit/fuzz-natives-part4.js View 1 chunk +1 line, -0 lines 0 comments Download
M test/mjsunit/harmony/module-linking.js View 1 chunk +1 line, -1 line 0 comments Download

Messages

Total messages: 11 (0 generated)
rossberg
8 years, 2 months ago (2012-10-11 13:32:05 UTC) #1
rossberg
PS: Other back-ends will follow.
8 years, 2 months ago (2012-10-11 13:39:57 UTC) #2
rossberg
Ping. I really would like to land this this week, before modules are discussed at ...
8 years, 1 month ago (2012-11-20 10:02:47 UTC) #3
Michael Starzinger
First round of low-level comments. https://codereview.chromium.org/11093074/diff/1/src/full-codegen.cc File src/full-codegen.cc (right): https://codereview.chromium.org/11093074/diff/1/src/full-codegen.cc#newcode746 src/full-codegen.cc:746: __ push(Immediate(Smi::FromInt(interface->Index()))); See comment ...
8 years, 1 month ago (2012-11-20 12:05:04 UTC) #4
Sven Panne
https://codereview.chromium.org/11093074/diff/1/src/full-codegen.cc File src/full-codegen.cc (right): https://codereview.chromium.org/11093074/diff/1/src/full-codegen.cc#newcode764 src/full-codegen.cc:764: // context in the host context. Can we abstract ...
8 years, 1 month ago (2012-11-20 14:39:13 UTC) #5
rossberg
https://codereview.chromium.org/11093074/diff/1/src/full-codegen.cc File src/full-codegen.cc (right): https://codereview.chromium.org/11093074/diff/1/src/full-codegen.cc#newcode746 src/full-codegen.cc:746: __ push(Immediate(Smi::FromInt(interface->Index()))); On 2012/11/20 12:05:05, Michael Starzinger wrote: > ...
8 years, 1 month ago (2012-11-20 17:23:45 UTC) #6
Sven Panne
LGTM with a nit https://codereview.chromium.org/11093074/diff/8001/src/scopeinfo.h File src/scopeinfo.h (right): https://codereview.chromium.org/11093074/diff/8001/src/scopeinfo.h#newcode142 src/scopeinfo.h:142: return reinterpret_cast<ModuleDescription*>(FixedArray::cast(description)); static_cast should be ...
8 years ago (2012-11-21 07:20:47 UTC) #7
Michael Starzinger
LGTM with one comment. https://codereview.chromium.org/11093074/diff/8001/src/full-codegen.cc File src/full-codegen.cc (right): https://codereview.chromium.org/11093074/diff/8001/src/full-codegen.cc#newcode607 src/full-codegen.cc:607: __ push(Immediate(scope->GetScopeInfo())); The previous comment ...
8 years ago (2012-11-21 11:00:21 UTC) #8
rossberg
PTAL at the x64 and ARM back-ends. https://codereview.chromium.org/11093074/diff/8001/src/full-codegen.cc File src/full-codegen.cc (right): https://codereview.chromium.org/11093074/diff/8001/src/full-codegen.cc#newcode607 src/full-codegen.cc:607: __ push(Immediate(scope->GetScopeInfo())); ...
8 years ago (2012-11-21 13:50:40 UTC) #9
Michael Starzinger
Architecture ports also LGTM.
8 years ago (2012-11-21 17:21:36 UTC) #10
Sven Panne
8 years ago (2012-11-22 07:55:07 UTC) #11
LGTM for the ports, too...

Powered by Google App Engine
This is Rietveld 408576698