Reviewers: Hannes Payer,
Description:
Only reference constant root list entries in the snapshot.
[email protected]
Please review this at https://codereview.chromium.org/979003003/
Base URL: https://chromium.googlesource.com/v8/v8.git@master
Affected files (+56, -29 lines):
M src/arm/macro-assembler-arm.cc
M src/arm64/macro-assembler-arm64.cc
M src/heap/heap.h
M src/heap/heap.cc
M src/mips/macro-assembler-mips.cc
M src/mips64/macro-assembler-mips64.cc
M src/ppc/macro-assembler-ppc.cc
M src/serialize.cc
M src/x64/macro-assembler-x64.cc
M test/cctest/test-heap.cc
Index: src/arm/macro-assembler-arm.cc
diff --git a/src/arm/macro-assembler-arm.cc b/src/arm/macro-assembler-arm.cc
index
2051974171d6c5a2ed8b510055d7809f5ea7bd76..06bfe3c1cec810019d20ede859963ffd0261323a
100644
--- a/src/arm/macro-assembler-arm.cc
+++ b/src/arm/macro-assembler-arm.cc
@@ -439,6 +439,7 @@ void MacroAssembler::LoadRoot(Register destination,
void MacroAssembler::StoreRoot(Register source,
Heap::RootListIndex index,
Condition cond) {
+ DCHECK(Heap::RootCanBeWrittenAfterInitialization(index));
str(source, MemOperand(kRootRegister, index << kPointerSizeLog2), cond);
}
Index: src/arm64/macro-assembler-arm64.cc
diff --git a/src/arm64/macro-assembler-arm64.cc
b/src/arm64/macro-assembler-arm64.cc
index
628c061e43be14ef8a5f5d8cbf2075d64137741f..87bb2966b09796d050ce1a264e1ee3d3fb42f77b
100644
--- a/src/arm64/macro-assembler-arm64.cc
+++ b/src/arm64/macro-assembler-arm64.cc
@@ -1403,6 +1403,7 @@ void MacroAssembler::LoadRoot(CPURegister destination,
void MacroAssembler::StoreRoot(Register source,
Heap::RootListIndex index) {
+ DCHECK(Heap::RootCanBeWrittenAfterInitialization(index));
Str(source, MemOperand(root, index << kPointerSizeLog2));
}
Index: src/heap/heap.cc
diff --git a/src/heap/heap.cc b/src/heap/heap.cc
index
16b5deccf6ebf97253d04db7e49c8a40f2285ac8..8bd250406b4b2380336ae9f726175c64b4a3f3dc
100644
--- a/src/heap/heap.cc
+++ b/src/heap/heap.cc
@@ -3148,30 +3148,33 @@ void Heap::CreateInitialObjects() {
bool Heap::RootCanBeWrittenAfterInitialization(Heap::RootListIndex
root_index) {
- RootListIndex writable_roots[] = {
- kStoreBufferTopRootIndex,
- kStackLimitRootIndex,
- kNumberStringCacheRootIndex,
- kInstanceofCacheFunctionRootIndex,
- kInstanceofCacheMapRootIndex,
- kInstanceofCacheAnswerRootIndex,
- kCodeStubsRootIndex,
- kNonMonomorphicCacheRootIndex,
- kPolymorphicCodeCacheRootIndex,
- kLastScriptIdRootIndex,
- kEmptyScriptRootIndex,
- kRealStackLimitRootIndex,
- kArgumentsAdaptorDeoptPCOffsetRootIndex,
- kConstructStubDeoptPCOffsetRootIndex,
- kGetterStubDeoptPCOffsetRootIndex,
- kSetterStubDeoptPCOffsetRootIndex,
- kStringTableRootIndex,
- };
+ switch (root_index) {
+ case kStoreBufferTopRootIndex:
+ case kNumberStringCacheRootIndex:
+ case kInstanceofCacheFunctionRootIndex:
+ case kInstanceofCacheMapRootIndex:
+ case kInstanceofCacheAnswerRootIndex:
+ case kCodeStubsRootIndex:
+ case kNonMonomorphicCacheRootIndex:
+ case kPolymorphicCodeCacheRootIndex:
+ case kEmptyScriptRootIndex:
+ case kSymbolRegistryRootIndex:
+ case kMaterializedObjectsRootIndex:
+ case kAllocationSitesScratchpadRootIndex:
+ case kMicrotaskQueueRootIndex:
+ case kDetachedContextsRootIndex:
+ case kWeakObjectToCodeTableRootIndex:
+// Smi values
+#define SMI_ENTRY(type, name, Name) case k##Name##RootIndex:
+ SMI_ROOT_LIST(SMI_ENTRY)
+#undef SMI_ENTRY
+ // String table
+ case kStringTableRootIndex:
+ return true;
- for (unsigned int i = 0; i < arraysize(writable_roots); i++) {
- if (root_index == writable_roots[i]) return true;
+ default:
+ return false;
}
- return false;
}
Index: src/heap/heap.h
diff --git a/src/heap/heap.h b/src/heap/heap.h
index
1b16ced9064bf6752adc4c3dc7cc03169a17d913..13e62a1ef374a68fdb210eeb8d9369c8709bcf41
100644
--- a/src/heap/heap.h
+++ b/src/heap/heap.h
@@ -159,10 +159,11 @@ namespace internal {
V(Map, termination_exception_map,
TerminationExceptionMap) \
V(Map, message_object_map,
JSMessageObjectMap) \
V(Map, foreign_map,
ForeignMap) \
+ V(Map, neander_map,
NeanderMap) \
+ V(Map, external_map,
ExternalMap) \
V(HeapNumber, nan_value,
NanValue) \
V(HeapNumber, infinity_value,
InfinityValue) \
V(HeapNumber, minus_zero_value,
MinusZeroValue) \
- V(Map, neander_map,
NeanderMap) \
V(JSObject, message_listeners,
MessageListeners) \
V(UnseededNumberDictionary, code_stubs,
CodeStubs) \
V(UnseededNumberDictionary, non_monomorphic_cache,
NonMonomorphicCache) \
@@ -172,9 +173,8 @@ namespace internal {
V(FixedArray, natives_source_cache,
NativesSourceCache) \
V(Script, empty_script,
EmptyScript) \
V(NameDictionary, intrinsic_function_names,
IntrinsicFunctionNames) \
- V(Cell, undefined_cell,
UndefineCell) \
+ V(Cell, undefined_cell,
UndefinedCell) \
V(JSObject, observation_state,
ObservationState) \
- V(Map, external_map,
ExternalMap) \
V(Object, symbol_registry,
SymbolRegistry) \
V(SeededNumberDictionary,
empty_slow_element_dictionary, \
EmptySlowElementDictionary) \
@@ -1600,6 +1600,8 @@ class Heap {
inline void set_##name(type* value)
{ \
/* The deserializer makes use of the fact that these common roots are
*/ \
/* never in new space and never on a page that is being compacted.
*/ \
+ DCHECK(!deserialization_complete() |
| \
+
RootCanBeWrittenAfterInitialization(k##camel_name##RootIndex)); \
DCHECK(k##camel_name##RootIndex >= kOldSpaceRoots |
| !InNewSpace(value)); \
roots_[k##camel_name##RootIndex] =
value; \
}
Index: src/mips/macro-assembler-mips.cc
diff --git a/src/mips/macro-assembler-mips.cc
b/src/mips/macro-assembler-mips.cc
index
ae44b3d4db197cee34996f7e29fba11afb8322e1..1f0c9bf13ad3679843922254e7cc6db40ad1cb58
100644
--- a/src/mips/macro-assembler-mips.cc
+++ b/src/mips/macro-assembler-mips.cc
@@ -86,6 +86,7 @@ void MacroAssembler::LoadRoot(Register destination,
void MacroAssembler::StoreRoot(Register source,
Heap::RootListIndex index) {
+ DCHECK(Heap::RootCanBeWrittenAfterInitialization(index));
sw(source, MemOperand(s6, index << kPointerSizeLog2));
}
@@ -94,6 +95,7 @@ void MacroAssembler::StoreRoot(Register source,
Heap::RootListIndex index,
Condition cond,
Register src1, const Operand& src2) {
+ DCHECK(Heap::RootCanBeWrittenAfterInitialization(index));
Branch(2, NegateCondition(cond), src1, src2);
sw(source, MemOperand(s6, index << kPointerSizeLog2));
}
Index: src/mips64/macro-assembler-mips64.cc
diff --git a/src/mips64/macro-assembler-mips64.cc
b/src/mips64/macro-assembler-mips64.cc
index
d187fa5423702ddb8dc42648043a090d2605c48d..ef54ba5fa07d03613f80930e58b0828655aef552
100644
--- a/src/mips64/macro-assembler-mips64.cc
+++ b/src/mips64/macro-assembler-mips64.cc
@@ -89,6 +89,7 @@ void MacroAssembler::LoadRoot(Register destination,
void MacroAssembler::StoreRoot(Register source,
Heap::RootListIndex index) {
+ DCHECK(Heap::RootCanBeWrittenAfterInitialization(index));
sd(source, MemOperand(s6, index << kPointerSizeLog2));
}
@@ -97,6 +98,7 @@ void MacroAssembler::StoreRoot(Register source,
Heap::RootListIndex index,
Condition cond,
Register src1, const Operand& src2) {
+ DCHECK(Heap::RootCanBeWrittenAfterInitialization(index));
Branch(2, NegateCondition(cond), src1, src2);
sd(source, MemOperand(s6, index << kPointerSizeLog2));
}
Index: src/ppc/macro-assembler-ppc.cc
diff --git a/src/ppc/macro-assembler-ppc.cc b/src/ppc/macro-assembler-ppc.cc
index
513827b7b3af92156dff6e8ffa9715edd1572008..7a6228be88295c6c484df7d94243af12f87b0254
100644
--- a/src/ppc/macro-assembler-ppc.cc
+++ b/src/ppc/macro-assembler-ppc.cc
@@ -273,6 +273,7 @@ void MacroAssembler::LoadRoot(Register destination,
Heap::RootListIndex index,
void MacroAssembler::StoreRoot(Register source, Heap::RootListIndex index,
Condition cond) {
+ DCHECK(Heap::RootCanBeWrittenAfterInitialization(index));
DCHECK(cond == al);
StoreP(source, MemOperand(kRootRegister, index << kPointerSizeLog2), r0);
}
Index: src/serialize.cc
diff --git a/src/serialize.cc b/src/serialize.cc
index
0b39d25642a324f68ca766fc2223a98c2bc2e4ba..4a503fd1408c6852b120266f391cd4a20f9ad2fd
100644
--- a/src/serialize.cc
+++ b/src/serialize.cc
@@ -481,15 +481,18 @@ RootIndexMap::RootIndexMap(Isolate* isolate) {
map_ = new HashMap(HashMap::PointersMatch);
Object** root_array = isolate->heap()->roots_array_start();
for (uint32_t i = 0; i < Heap::kStrongRootListLength; i++) {
- Object* root = root_array[i];
- if (root->IsHeapObject() && !isolate->heap()->InNewSpace(root)) {
+ Heap::RootListIndex root_index = static_cast<Heap::RootListIndex>(i);
+ Object* root = root_array[root_index];
+ // Omit root entries that can be written after initialization. They
must
+ // not be referenced through the root list in the snapshot.
+ if (isolate->heap()->RootCanBeTreatedAsConstant(root_index)) {
HeapObject* heap_object = HeapObject::cast(root);
HashMap::Entry* entry = LookupEntry(map_, heap_object, false);
if (entry != NULL) {
// Some are initialized to a previous value in the root list.
- DCHECK_LT(GetValue(entry), i);
+ DCHECK_LT(GetValue(entry), root_index);
} else {
- SetValue(LookupEntry(map_, heap_object, true), i);
+ SetValue(LookupEntry(map_, heap_object, true), root_index);
}
}
}
Index: src/x64/macro-assembler-x64.cc
diff --git a/src/x64/macro-assembler-x64.cc b/src/x64/macro-assembler-x64.cc
index
e4203618fcaa818bdb4441ac3345e3c4d43f0e4f..c5d639755c746ed5e5279017d67912aa7fbf587e
100644
--- a/src/x64/macro-assembler-x64.cc
+++ b/src/x64/macro-assembler-x64.cc
@@ -177,6 +177,7 @@ void MacroAssembler::LoadRootIndexed(Register
destination,
void MacroAssembler::StoreRoot(Register source, Heap::RootListIndex index)
{
+ DCHECK(Heap::RootCanBeWrittenAfterInitialization(index));
DCHECK(root_array_available_);
movp(Operand(kRootRegister, (index << kPointerSizeLog2) -
kRootRegisterBias),
source);
Index: test/cctest/test-heap.cc
diff --git a/test/cctest/test-heap.cc b/test/cctest/test-heap.cc
index
d7c24156a3d2aed5fad23b591898cf7e510f4902..bc389718e874dc5fd06727118a2dac8af7bd4571
100644
--- a/test/cctest/test-heap.cc
+++ b/test/cctest/test-heap.cc
@@ -5092,3 +5092,14 @@ TEST(PathTracer) {
CcTest::i_isolate()->heap()->TracePathToObject(*o);
}
#endif // DEBUG
+
+
+TEST(WritableVsImmortalRoots) {
+ for (int i = 0; i < Heap::kStrongRootListLength; ++i) {
+ Heap::RootListIndex root_index = static_cast<Heap::RootListIndex>(i);
+ bool writable = Heap::RootCanBeWrittenAfterInitialization(root_index);
+ bool immortal = Heap::RootIsImmortalImmovable(root_index);
+ // A root value can be writable, immortal, or neither, but not both.
+ DCHECK(!immortal || !writable);
+ }
+}
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.