Commit e571065c authored by yangguo's avatar yangguo Committed by Commit bot

Only reference constant root list entries in the snapshot.

R=hpayer@chromium.org

Review URL: https://codereview.chromium.org/979003003

Cr-Commit-Position: refs/heads/master@{#27031}
parent 948a973d
......@@ -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);
}
......
......@@ -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));
}
......
......@@ -3144,30 +3144,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;
}
......
......@@ -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) \
......@@ -195,6 +195,7 @@ namespace internal {
V(Smi, getter_stub_deopt_pc_offset, GetterStubDeoptPCOffset) \
V(Smi, setter_stub_deopt_pc_offset, SetterStubDeoptPCOffset)
#define ROOT_LIST(V) \
STRONG_ROOT_LIST(V) \
SMI_ROOT_LIST(V) \
......@@ -1600,6 +1601,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; \
}
......
......@@ -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));
}
......
......@@ -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));
}
......
......@@ -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);
}
......
......@@ -481,8 +481,12 @@ 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 (root->IsHeapObject() &&
isolate->heap()->RootCanBeTreatedAsConstant(root_index)) {
HeapObject* heap_object = HeapObject::cast(root);
HashMap::Entry* entry = LookupEntry(map_, heap_object, false);
if (entry != NULL) {
......
......@@ -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);
......
......@@ -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.
CHECK(!immortal || !writable);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment