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

Issue 2021323003: [wasm] remove faux code objects

Created:
4 years, 6 months ago by Mircea Trofin
Modified:
4 years, 6 months ago
CC:
v8-mips-ports_googlegroups.com, v8-ppc-ports_googlegroups.com, v8-reviews_googlegroups.com, v8-x87-ports_googlegroups.com
Base URL:
https://chromium.googlesource.com/v8/v8.git@master
Target Ref:
refs/pending/heads/master
Project:
v8
Visibility:
Public.

Description

[wasm] remove faux code objects This change decouples direct calls from Handle<Code> by introducing a wasm-specific relocation info, WASM_DIRECT_CALL, and compiling direct calls as having a relocatable int32 first operand (the call site). BUG=

Patch Set 1 #

Patch Set 2 : #

Total comments: 6

Patch Set 3 : #

Patch Set 4 : #

Unified diffs Side-by-side diffs Delta from patch set Stats (+293 lines, -173 lines) Patch
M src/arm/assembler-arm.cc View 1 2 1 chunk +5 lines, -0 lines 0 comments Download
M src/arm/assembler-arm-inl.h View 1 2 1 chunk +1 line, -1 line 0 comments Download
M src/arm64/assembler-arm64.cc View 1 2 1 chunk +5 lines, -0 lines 0 comments Download
M src/arm64/assembler-arm64-inl.h View 1 2 1 chunk +1 line, -1 line 0 comments Download
M src/assembler.h View 1 2 7 chunks +16 lines, -1 line 0 comments Download
M src/assembler.cc View 1 2 6 chunks +13 lines, -0 lines 0 comments Download
M src/compiler/arm/code-generator-arm.cc View 1 2 1 chunk +11 lines, -0 lines 0 comments Download
M src/compiler/arm64/code-generator-arm64.cc View 1 2 1 chunk +22 lines, -0 lines 0 comments Download
M src/compiler/ia32/code-generator-ia32.cc View 1 2 1 chunk +9 lines, -0 lines 0 comments Download
M src/compiler/instruction-codes.h View 1 2 1 chunk +1 line, -0 lines 0 comments Download
M src/compiler/instruction-scheduler.cc View 1 2 1 chunk +1 line, -0 lines 0 comments Download
M src/compiler/instruction-selector.cc View 1 2 2 chunks +8 lines, -0 lines 0 comments Download
M src/compiler/linkage.h View 1 2 1 chunk +4 lines, -3 lines 0 comments Download
M src/compiler/linkage.cc View 1 2 1 chunk +3 lines, -0 lines 0 comments Download
M src/compiler/mips/code-generator-mips.cc View 1 2 1 chunk +10 lines, -0 lines 0 comments Download
M src/compiler/mips64/code-generator-mips64.cc View 1 2 1 chunk +10 lines, -0 lines 0 comments Download
M src/compiler/wasm-compiler.h View 1 2 2 chunks +5 lines, -1 line 0 comments Download
M src/compiler/wasm-compiler.cc View 1 2 4 chunks +46 lines, -9 lines 0 comments Download
M src/compiler/wasm-linkage.cc View 1 2 2 chunks +14 lines, -13 lines 0 comments Download
M src/compiler/x64/code-generator-x64.cc View 1 2 1 chunk +9 lines, -0 lines 0 comments Download
M src/ia32/assembler-ia32.h View 1 2 1 chunk +1 line, -0 lines 0 comments Download
M src/ia32/assembler-ia32.cc View 1 2 2 chunks +14 lines, -0 lines 0 comments Download
M src/ia32/assembler-ia32-inl.h View 1 2 1 chunk +1 line, -1 line 0 comments Download
M src/mips/assembler-mips.cc View 1 2 1 chunk +5 lines, -0 lines 0 comments Download
M src/mips/assembler-mips-inl.h View 1 2 1 chunk +1 line, -1 line 0 comments Download
M src/mips64/assembler-mips64.cc View 1 2 1 chunk +6 lines, -0 lines 0 comments Download
M src/mips64/assembler-mips64-inl.h View 1 2 1 chunk +1 line, -1 line 0 comments Download
M src/wasm/wasm-module.h View 1 2 2 chunks +4 lines, -8 lines 0 comments Download
M src/wasm/wasm-module.cc View 1 2 7 chunks +31 lines, -128 lines 0 comments Download
M src/x64/assembler-x64.h View 1 2 1 chunk +1 line, -0 lines 0 comments Download
M src/x64/assembler-x64.cc View 1 2 2 chunks +14 lines, -0 lines 0 comments Download
M src/x64/assembler-x64-inl.h View 1 2 1 chunk +1 line, -1 line 0 comments Download
M test/cctest/wasm/wasm-run-utils.h View 1 2 5 chunks +19 lines, -3 lines 0 comments Download
M test/unittests/wasm/ast-decoder-unittest.cc View 1 chunk +0 lines, -1 line 0 comments Download

Depends on Patchset:

Messages

Total messages: 19 (6 generated)
Mircea Trofin
This is a refresh of the earlier 1962643004, which I'm closing. I preferred starting a ...
4 years, 6 months ago (2016-06-01 00:09:20 UTC) #3
Mircea Trofin
gentle reminder. thanks!
4 years, 6 months ago (2016-06-02 00:01:15 UTC) #4
titzer
+mstarzinger https://codereview.chromium.org/2021323003/diff/20001/src/arm/assembler-arm.cc File src/arm/assembler-arm.cc (right): https://codereview.chromium.org/2021323003/diff/20001/src/arm/assembler-arm.cc#newcode252 src/arm/assembler-arm.cc:252: uint32_t RelocInfo::wasm_function_index() { This function basically assumes that ...
4 years, 6 months ago (2016-06-02 13:17:08 UTC) #6
ahaas
On 2016/06/02 at 00:01:15, mtrofin wrote: > gentle reminder. > > thanks! There is one ...
4 years, 6 months ago (2016-06-02 13:46:59 UTC) #7
ahaas
https://codereview.chromium.org/2021323003/diff/20001/src/compiler/wasm-compiler.cc File src/compiler/wasm-compiler.cc (right): https://codereview.chromium.org/2021323003/diff/20001/src/compiler/wasm-compiler.cc#newcode3313 src/compiler/wasm-compiler.cc:3313: void Link(Isolate* isolate, std::vector<Handle<Code>>& functions) { What's the reason ...
4 years, 6 months ago (2016-06-02 13:48:28 UTC) #8
Mircea Trofin
https://codereview.chromium.org/2021323003/diff/20001/src/arm/assembler-arm.cc File src/arm/assembler-arm.cc (right): https://codereview.chromium.org/2021323003/diff/20001/src/arm/assembler-arm.cc#newcode252 src/arm/assembler-arm.cc:252: uint32_t RelocInfo::wasm_function_index() { On 2016/06/02 13:17:08, titzer wrote: > ...
4 years, 6 months ago (2016-06-02 14:46:21 UTC) #9
Mircea Trofin
On 2016/06/02 13:46:59, ahaas wrote: > On 2016/06/02 at 00:01:15, mtrofin wrote: > > gentle ...
4 years, 6 months ago (2016-06-02 14:49:16 UTC) #10
titzer
On 2016/06/02 14:49:16, Mircea Trofin wrote: > On 2016/06/02 13:46:59, ahaas wrote: > > On ...
4 years, 6 months ago (2016-06-06 07:32:59 UTC) #14
Mircea Trofin
On 2016/06/06 07:32:59, titzer wrote: > On 2016/06/02 14:49:16, Mircea Trofin wrote: > > On ...
4 years, 6 months ago (2016-06-06 15:25:07 UTC) #15
titzer
On 2016/06/06 15:25:07, Mircea Trofin wrote: > On 2016/06/06 07:32:59, titzer wrote: > > On ...
4 years, 6 months ago (2016-06-06 15:39:10 UTC) #16
titzer
On 2016/06/06 15:39:10, titzer wrote: > On 2016/06/06 15:25:07, Mircea Trofin wrote: > > On ...
4 years, 6 months ago (2016-06-06 15:44:52 UTC) #17
Mircea Trofin
On 2016/06/06 15:39:10, titzer wrote: > On 2016/06/06 15:25:07, Mircea Trofin wrote: > > On ...
4 years, 6 months ago (2016-06-06 15:50:36 UTC) #18
titzer
4 years, 6 months ago (2016-06-06 15:56:55 UTC) #19
On 2016/06/06 15:50:36, Mircea Trofin wrote:
> On 2016/06/06 15:39:10, titzer wrote:
> > On 2016/06/06 15:25:07, Mircea Trofin wrote:
> > > On 2016/06/06 07:32:59, titzer wrote:
> > > > On 2016/06/02 14:49:16, Mircea Trofin wrote:
> > > > > On 2016/06/02 13:46:59, ahaas wrote:
> > > > > > On 2016/06/02 at 00:01:15, mtrofin wrote:
> > > > > > > gentle reminder.
> > > > > > > 
> > > > > > > thanks!
> > > > > > 
> > > > > > There is one problem when you avoid the use of placeholder code
> objects
> > > > which
> > > > > is
> > > > > > garbage collection. The garbage collector may move code objects, and
> to
> > > > update
> > > > > > pointers between code objects these pointers have to be stored in
the
> > > > > relocation
> > > > > > info as CodeTargets. In the linking I think you have to set the
target
> > > > address
> > > > > > and change the mode of the relocation info to CodeTarget at the same
> > time,
> > > > > i.e.
> > > > > > no GC should happen between these steps.
> > > > > 
> > > > > Good point, thanks! I suppose we should disable GC for the duration of
> > > linking
> > > > > altogether, then.
> > > > 
> > > > That might not be enough. My earlier comment (about sometimes the call
> > address
> > > > encodes a WASM function index, and sometimes the direct address) could
> also
> > > > apply to the GC when it is walking code objects for compaction. We
> generally
> > > > don't want code compaction for WASM, but it could happen now, AFAIU.
> > > 
> > > Could you elaborate? Here's my understanding of the world today: call
sites
> > are
> > > encoded
> > >  as having reloc info CODE_TARGET, which is understood by GC and resilient
> > > (afaik) 
> > > in face of compaction, but compaction may still happen. How do we avoid
code
> > > compaction, 
> > > today, for WASM?
> > 
> > At any point that a GC occurs, it will try to decode the reloc_info for
> > CODE_TARGET in order to patch the call address. If this occurs for a WASM
code
> > object when the call target incorrectly, the GC will be trying to interpret
a
> > WASM function index as an instruction address and will find to find a code
> > object. Basically, the GC doesn't know about the two states of encoding.
> 
> Yes, but the call target isn't a CODE_TARGET when it encodes an index. It is
> a WASM_DIRECT_CALL. How would the GC see it?
> 
> BTW, today, for regular (non-wasm) CODE_TARGETs, we also store an index 
> there, for a while, marked as CODE_TARGET, and we avoid GC issues the same
way.
> See Factory::NewCode. We disable heap allocation, then copy the bytes (Code
> object
> is invalid, CODE_TARGETs are indexes) and then relocate.
> If anything, the mechanics in my change further avoid any GC issues by
> completely
> hiding the indexes from GC until the code is patched. 
> 

That's right, but this internal buffer is just raw_bytes and it doesn't have
encoded heap references in it. (It may have, however, encoded pointers to handle
locations that are undone during the copy).

See my earlier comment. I missed that you were proposing to change the
relocation mode afterwards.

> > 
> > > 
> > > With my change, the call sites are first encoded as WASM_DIRECT_CALL,
> > > when they store the index, and then, at link time, we stop GC, replace the
> > index
> > > with the address and 
> > > change the reloc info to CODE_TARGET, then resume the world. Everything
> looks,
> > > after linking, just 
> > > like before. What am I missing?
> > > 
> > 
> > A GC could occur before we even started linking, so it could observe
addresses
> > too early.
> > 
> 
> But the state of the world when we start linking should be consistent: the
> handles to
> the code objects are always correct.

Right.

> 
> > Generally it's not going be viable to disable compaction or other GC
activity
> > until we have WASM machine code out-of-heap (i.e., not code objects).
> > 
> > > Thanks!

Powered by Google App Engine
This is Rietveld 408576698