Skip to content

Commit 179c96c

Browse files
rmacnak-googlecommit-bot@chromium.org
authored andcommitted
[vm] Switch Context to compressed pointers.
TEST=ci Change-Id: I2511dcc9234dbe29dcbc3abf3db7a8a080dc5436 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/213112 Reviewed-by: Liam Appelbe <[email protected]> Commit-Queue: Ryan Macnak <[email protected]>
1 parent 703dad5 commit 179c96c

13 files changed

+145
-175
lines changed

runtime/vm/clustered_snapshot.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2920,10 +2920,10 @@ class ContextSerializationCluster : public SerializationCluster {
29202920
ContextPtr context = Context::RawCast(object);
29212921
objects_.Add(context);
29222922

2923-
s->Push(context->untag()->parent_);
2923+
s->Push(context->untag()->parent());
29242924
const intptr_t length = context->untag()->num_variables_;
29252925
for (intptr_t i = 0; i < length; i++) {
2926-
s->Push(context->untag()->data()[i]);
2926+
s->Push(context->untag()->element(i));
29272927
}
29282928
}
29292929

@@ -2947,9 +2947,9 @@ class ContextSerializationCluster : public SerializationCluster {
29472947
AutoTraceObject(context);
29482948
const intptr_t length = context->untag()->num_variables_;
29492949
s->WriteUnsigned(length);
2950-
WriteField(context, parent_);
2950+
WriteField(context, parent());
29512951
for (intptr_t j = 0; j < length; j++) {
2952-
s->WriteElementRef(context->untag()->data()[j], j);
2952+
s->WriteElementRef(context->untag()->element(j), j);
29532953
}
29542954
}
29552955
}

runtime/vm/compiler/runtime_api.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,6 +1003,7 @@ namespace compiler {
10031003
namespace target {
10041004

10051005
const word Array::kMaxElements = Array_kMaxElements;
1006+
const word Context::kMaxElements = Context_kMaxElements;
10061007

10071008
} // namespace target
10081009
} // namespace compiler

runtime/vm/compiler/runtime_api.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1324,6 +1324,8 @@ class Context : public AllStatic {
13241324
static word InstanceSize(intptr_t length);
13251325
static word InstanceSize();
13261326
FINAL_CLASS();
1327+
1328+
static const word kMaxElements;
13271329
};
13281330

13291331
class Closure : public AllStatic {

runtime/vm/compiler/runtime_offsets_extracted.h

Lines changed: 68 additions & 32 deletions
Large diffs are not rendered by default.

runtime/vm/compiler/runtime_offsets_list.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
ARRAY_SIZEOF(TwoByteString, InstanceSize, element_offset) \
6969
CONSTANT(Array, kMaxElements) \
7070
CONSTANT(Array, kMaxNewSpaceElements) \
71+
CONSTANT(Context, kMaxElements) \
7172
CONSTANT(Instructions, kMonomorphicEntryOffsetJIT) \
7273
CONSTANT(Instructions, kPolymorphicEntryOffsetJIT) \
7374
CONSTANT(Instructions, kMonomorphicEntryOffsetAOT) \

runtime/vm/compiler/stub_code_compiler_arm64.cc

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -488,10 +488,11 @@ void StubCodeCompiler::GenerateBuildMethodExtractorStub(
488488
R0, // instance
489489
R1, // end address
490490
R2, R3);
491-
__ ldr(R1, Address(THR, target::Thread::object_null_offset()));
492-
__ str(R1, FieldAddress(R0, target::Context::parent_offset()));
491+
__ StoreCompressedIntoObjectNoBarrier(
492+
R0, FieldAddress(R0, target::Context::parent_offset()), NULL_REG);
493493
__ LoadImmediate(R1, 1);
494-
__ str(R1, FieldAddress(R0, target::Context::num_variables_offset()));
494+
__ str(R1, FieldAddress(R0, target::Context::num_variables_offset()),
495+
kFourBytes);
495496
__ b(&done);
496497
}
497498

@@ -511,10 +512,11 @@ void StubCodeCompiler::GenerateBuildMethodExtractorStub(
511512
// Store receiver in context
512513
__ ldr(AllocateClosureABI::kScratchReg,
513514
Address(FP, target::kWordSize * kReceiverOffset));
514-
__ StoreIntoObject(AllocateClosureABI::kContextReg,
515-
FieldAddress(AllocateClosureABI::kContextReg,
516-
target::Context::variable_offset(0)),
517-
AllocateClosureABI::kScratchReg);
515+
__ StoreCompressedIntoObject(
516+
AllocateClosureABI::kContextReg,
517+
FieldAddress(AllocateClosureABI::kContextReg,
518+
target::Context::variable_offset(0)),
519+
AllocateClosureABI::kScratchReg);
518520

519521
// Pop function before pushing context.
520522
__ Pop(AllocateClosureABI::kFunctionReg);
@@ -1487,7 +1489,7 @@ static void GenerateAllocateContextSpaceStub(Assembler* assembler,
14871489
target::Context::header_size() +
14881490
target::ObjectAlignment::kObjectAlignment - 1;
14891491
__ LoadImmediate(R2, fixed_size_plus_alignment_padding);
1490-
__ add(R2, R2, Operand(R1, LSL, 3));
1492+
__ add(R2, R2, Operand(R1, LSL, kCompressedWordSizeLog2));
14911493
ASSERT(kSmiTagShift == 1);
14921494
__ andi(R2, R2, Immediate(~(target::ObjectAlignment::kObjectAlignment - 1)));
14931495

@@ -1539,7 +1541,8 @@ static void GenerateAllocateContextSpaceStub(Assembler* assembler,
15391541
// Setup up number of context variables field.
15401542
// R0: new object.
15411543
// R1: number of context variables as integer value (not object).
1542-
__ StoreFieldToOffset(R1, R0, target::Context::num_variables_offset());
1544+
__ StoreFieldToOffset(R1, R0, target::Context::num_variables_offset(),
1545+
kFourBytes);
15431546
}
15441547

15451548
// Called for inline allocation of contexts.
@@ -1558,21 +1561,20 @@ void StubCodeCompiler::GenerateAllocateContextStub(Assembler* assembler) {
15581561
// Setup the parent field.
15591562
// R0: new object.
15601563
// R1: number of context variables.
1561-
__ LoadObject(R2, NullObject());
1562-
__ StoreFieldToOffset(R2, R0, target::Context::parent_offset());
1564+
__ StoreCompressedIntoObjectOffset(R0, target::Context::parent_offset(),
1565+
NULL_REG);
15631566

15641567
// Initialize the context variables.
15651568
// R0: new object.
15661569
// R1: number of context variables.
1567-
// R2: raw null.
15681570
{
15691571
Label loop, done;
15701572
__ AddImmediate(R3, R0,
15711573
target::Context::variable_offset(0) - kHeapObjectTag);
15721574
__ Bind(&loop);
15731575
__ subs(R1, R1, Operand(1));
15741576
__ b(&done, MI);
1575-
__ str(R2, Address(R3, R1, UXTX, Address::Scaled));
1577+
__ str(NULL_REG, Address(R3, R1, UXTX, Address::Scaled), kObjectBytes);
15761578
__ b(&loop, NE); // Loop if R1 not zero.
15771579
__ Bind(&done);
15781580
}
@@ -1626,10 +1628,10 @@ void StubCodeCompiler::GenerateCloneContextStub(Assembler* assembler) {
16261628
GenerateAllocateContextSpaceStub(assembler, &slow_case);
16271629

16281630
// Load parent in the existing context.
1629-
__ ldr(R3, FieldAddress(R5, target::Context::parent_offset()));
1631+
__ LoadCompressed(R3, FieldAddress(R5, target::Context::parent_offset()));
16301632
// Setup the parent field.
16311633
// R0: new context.
1632-
__ StoreIntoObjectNoBarrier(
1634+
__ StoreCompressedIntoObjectNoBarrier(
16331635
R0, FieldAddress(R0, target::Context::parent_offset()), R3);
16341636

16351637
// Clone the context variables.
@@ -1648,8 +1650,8 @@ void StubCodeCompiler::GenerateCloneContextStub(Assembler* assembler) {
16481650
__ subs(R1, R1, Operand(1));
16491651
__ b(&done, MI);
16501652

1651-
__ ldr(R5, Address(R4, R1, UXTX, Address::Scaled));
1652-
__ str(R5, Address(R3, R1, UXTX, Address::Scaled));
1653+
__ ldr(R5, Address(R4, R1, UXTX, Address::Scaled), kObjectBytes);
1654+
__ str(R5, Address(R3, R1, UXTX, Address::Scaled), kObjectBytes);
16531655
__ b(&loop, NE); // Loop if R1 not zero.
16541656

16551657
__ Bind(&done);

runtime/vm/compiler/stub_code_compiler_x64.cc

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -434,8 +434,9 @@ void StubCodeCompiler::GenerateBuildMethodExtractorStub(
434434
RSI, // end address
435435
RDI);
436436
__ movq(RSI, Address(THR, target::Thread::object_null_offset()));
437-
__ movq(FieldAddress(RAX, target::Context::parent_offset()), RSI);
438-
__ movq(FieldAddress(RAX, target::Context::num_variables_offset()),
437+
__ StoreCompressedIntoObjectNoBarrier(
438+
RAX, FieldAddress(RAX, target::Context::parent_offset()), RSI);
439+
__ movl(FieldAddress(RAX, target::Context::num_variables_offset()),
439440
Immediate(1));
440441
__ jmp(&done);
441442
}
@@ -455,10 +456,11 @@ void StubCodeCompiler::GenerateBuildMethodExtractorStub(
455456
// Store receiver in context
456457
__ movq(AllocateClosureABI::kScratchReg,
457458
Address(RBP, target::kWordSize * kReceiverOffsetInWords));
458-
__ StoreIntoObject(AllocateClosureABI::kContextReg,
459-
FieldAddress(AllocateClosureABI::kContextReg,
460-
target::Context::variable_offset(0)),
461-
AllocateClosureABI::kScratchReg);
459+
__ StoreCompressedIntoObject(
460+
AllocateClosureABI::kContextReg,
461+
FieldAddress(AllocateClosureABI::kContextReg,
462+
target::Context::variable_offset(0)),
463+
AllocateClosureABI::kScratchReg);
462464

463465
// Pop function.
464466
__ popq(AllocateClosureABI::kFunctionReg);
@@ -1420,7 +1422,8 @@ static void GenerateAllocateContextSpaceStub(Assembler* assembler,
14201422
intptr_t fixed_size_plus_alignment_padding =
14211423
(target::Context::header_size() +
14221424
target::ObjectAlignment::kObjectAlignment - 1);
1423-
__ leaq(R13, Address(R10, TIMES_8, fixed_size_plus_alignment_padding));
1425+
__ leaq(R13, Address(R10, TIMES_COMPRESSED_WORD_SIZE,
1426+
fixed_size_plus_alignment_padding));
14241427
__ andq(R13, Immediate(-target::ObjectAlignment::kObjectAlignment));
14251428

14261429
// Check for allocation tracing.
@@ -1454,7 +1457,8 @@ static void GenerateAllocateContextSpaceStub(Assembler* assembler,
14541457
// R10: number of context variables.
14551458
{
14561459
Label size_tag_overflow, done;
1457-
__ leaq(R13, Address(R10, TIMES_8, fixed_size_plus_alignment_padding));
1460+
__ leaq(R13, Address(R10, TIMES_COMPRESSED_WORD_SIZE,
1461+
fixed_size_plus_alignment_padding));
14581462
__ andq(R13, Immediate(-target::ObjectAlignment::kObjectAlignment));
14591463
__ cmpq(R13, Immediate(target::UntaggedObject::kSizeTagMaxSizeTag));
14601464
__ j(ABOVE, &size_tag_overflow, Assembler::kNearJump);
@@ -1478,7 +1482,7 @@ static void GenerateAllocateContextSpaceStub(Assembler* assembler,
14781482
// Setup up number of context variables field.
14791483
// RAX: new object.
14801484
// R10: number of context variables as integer value (not object).
1481-
__ movq(FieldAddress(RAX, target::Context::num_variables_offset()), R10);
1485+
__ movl(FieldAddress(RAX, target::Context::num_variables_offset()), R10);
14821486
}
14831487

14841488
// Called for inline allocation of contexts.
@@ -1499,7 +1503,7 @@ void StubCodeCompiler::GenerateAllocateContextStub(Assembler* assembler) {
14991503
// RAX: new object.
15001504
// R9: Parent object, initialised to null.
15011505
// No generational barrier needed, since we are storing null.
1502-
__ StoreIntoObjectNoBarrier(
1506+
__ StoreCompressedIntoObjectNoBarrier(
15031507
RAX, FieldAddress(RAX, target::Context::parent_offset()), R9);
15041508

15051509
// Initialize the context variables.
@@ -1517,7 +1521,8 @@ void StubCodeCompiler::GenerateAllocateContextStub(Assembler* assembler) {
15171521
__ Bind(&loop);
15181522
__ decq(R10);
15191523
// No generational barrier needed, since we are storing null.
1520-
__ StoreIntoObjectNoBarrier(RAX, Address(R13, R10, TIMES_8, 0), R9);
1524+
__ StoreCompressedIntoObjectNoBarrier(
1525+
RAX, Address(R13, R10, TIMES_COMPRESSED_WORD_SIZE, 0), R9);
15211526
__ Bind(&entry);
15221527
__ cmpq(R10, Immediate(0));
15231528
__ j(NOT_EQUAL, &loop, Assembler::kNearJump);
@@ -1567,11 +1572,11 @@ void StubCodeCompiler::GenerateCloneContextStub(Assembler* assembler) {
15671572
GenerateAllocateContextSpaceStub(assembler, &slow_case);
15681573

15691574
// Load parent in the existing context.
1570-
__ movq(R13, FieldAddress(R9, target::Context::parent_offset()));
1575+
__ LoadCompressed(R13, FieldAddress(R9, target::Context::parent_offset()));
15711576
// Setup the parent field.
15721577
// RAX: new object.
15731578
// R9: Old parent object.
1574-
__ StoreIntoObjectNoBarrier(
1579+
__ StoreCompressedIntoObjectNoBarrier(
15751580
RAX, FieldAddress(RAX, target::Context::parent_offset()), R13);
15761581

15771582
// Clone the context variables.
@@ -1582,11 +1587,12 @@ void StubCodeCompiler::GenerateCloneContextStub(Assembler* assembler) {
15821587
__ jmp(&entry, Assembler::kNearJump);
15831588
__ Bind(&loop);
15841589
__ decq(R10);
1585-
__ movq(R13, FieldAddress(R9, R10, TIMES_8,
1586-
target::Context::variable_offset(0)));
1587-
__ StoreIntoObjectNoBarrier(
1590+
__ LoadCompressed(R13, FieldAddress(R9, R10, TIMES_COMPRESSED_WORD_SIZE,
1591+
target::Context::variable_offset(0)));
1592+
__ StoreCompressedIntoObjectNoBarrier(
15881593
RAX,
1589-
FieldAddress(RAX, R10, TIMES_8, target::Context::variable_offset(0)),
1594+
FieldAddress(RAX, R10, TIMES_COMPRESSED_WORD_SIZE,
1595+
target::Context::variable_offset(0)),
15901596
R13);
15911597
__ Bind(&entry);
15921598
__ cmpq(R10, Immediate(0));

runtime/vm/deferred_objects.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,8 @@ void DeferredObject::Create() {
273273
}
274274

275275
static intptr_t ToContextIndex(intptr_t offset_in_bytes) {
276-
intptr_t result = (offset_in_bytes - Context::variable_offset(0)) / kWordSize;
276+
intptr_t result = (offset_in_bytes - Context::variable_offset(0)) /
277+
Context::kBytesPerElement;
277278
ASSERT(result >= 0);
278279
return result;
279280
}

runtime/vm/object.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6821,7 +6821,7 @@ class Context : public Object {
68216821

68226822
void Dump(int indent = 0) const;
68236823

6824-
static const intptr_t kBytesPerElement = kWordSize;
6824+
static const intptr_t kBytesPerElement = kCompressedWordSize;
68256825
static const intptr_t kMaxElements = kSmiMax / kBytesPerElement;
68266826

68276827
static const intptr_t kAwaitJumpVarIndex = 0;
@@ -6838,11 +6838,11 @@ class Context : public Object {
68386838

68396839
static intptr_t variable_offset(intptr_t context_index) {
68406840
return OFFSET_OF_RETURNED_VALUE(UntaggedContext, data) +
6841-
(kWordSize * context_index);
6841+
(kBytesPerElement * context_index);
68426842
}
68436843

68446844
static bool IsValidLength(intptr_t len) {
6845-
return 0 <= len && len <= compiler::target::Array::kMaxElements;
6845+
return 0 <= len && len <= compiler::target::Context::kMaxElements;
68466846
}
68476847

68486848
static intptr_t InstanceSize() {

0 commit comments

Comments
 (0)