Commit 0ddcee75 authored by Dan Elphick's avatar Dan Elphick Committed by Commit Bot

[explicit isolates] Convert regexp, debug and snapshot to use ReadOnlyRoots

In future the RO_SPACE root accessors in Heap will become private, so
instead convert them all to use ReadOnlyRoots.

Bug: v8:7786
Change-Id: I631fa1e44d2b9998a5567c96c6977955ac86d5a1
Reviewed-on: https://chromium-review.googlesource.com/1125931Reviewed-by: 's avatarYang Guo <yangguo@chromium.org>
Commit-Queue: Dan Elphick <delphick@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54215}
parent 85051099
...@@ -575,7 +575,7 @@ void Coverage::SelectMode(Isolate* isolate, debug::Coverage::Mode mode) { ...@@ -575,7 +575,7 @@ void Coverage::SelectMode(Isolate* isolate, debug::Coverage::Mode mode) {
isolate->debug()->RemoveAllCoverageInfos(); isolate->debug()->RemoveAllCoverageInfos();
if (!isolate->is_collecting_type_profile()) { if (!isolate->is_collecting_type_profile()) {
isolate->SetFeedbackVectorsForProfilingTools( isolate->SetFeedbackVectorsForProfilingTools(
isolate->heap()->undefined_value()); ReadOnlyRoots(isolate).undefined_value());
} }
break; break;
case debug::Coverage::kBlockBinary: case debug::Coverage::kBlockBinary:
......
...@@ -778,7 +778,7 @@ bool ScopeIterator::SetLocalVariableValue(Handle<String> variable_name, ...@@ -778,7 +778,7 @@ bool ScopeIterator::SetLocalVariableValue(Handle<String> variable_name,
case VariableLocation::UNALLOCATED: case VariableLocation::UNALLOCATED:
// Drop assignments to unallocated locals. // Drop assignments to unallocated locals.
DCHECK(var->is_this() || DCHECK(var->is_this() ||
*variable_name == isolate_->heap()->arguments_string()); *variable_name == ReadOnlyRoots(isolate_).arguments_string());
return false; return false;
case VariableLocation::PARAMETER: { case VariableLocation::PARAMETER: {
......
...@@ -100,7 +100,7 @@ void TypeProfile::SelectMode(Isolate* isolate, debug::TypeProfile::Mode mode) { ...@@ -100,7 +100,7 @@ void TypeProfile::SelectMode(Isolate* isolate, debug::TypeProfile::Mode mode) {
// coverage. // coverage.
if (isolate->is_best_effort_code_coverage()) { if (isolate->is_best_effort_code_coverage()) {
isolate->SetFeedbackVectorsForProfilingTools( isolate->SetFeedbackVectorsForProfilingTools(
isolate->heap()->undefined_value()); ReadOnlyRoots(isolate).undefined_value());
} }
} }
} else { } else {
......
...@@ -2194,7 +2194,7 @@ void Debug::StopSideEffectCheckMode() { ...@@ -2194,7 +2194,7 @@ void Debug::StopSideEffectCheckMode() {
DCHECK(isolate_->debug_execution_mode() == DebugInfo::kSideEffects); DCHECK(isolate_->debug_execution_mode() == DebugInfo::kSideEffects);
if (side_effect_check_failed_) { if (side_effect_check_failed_) {
DCHECK(isolate_->has_pending_exception()); DCHECK(isolate_->has_pending_exception());
DCHECK_EQ(isolate_->heap()->termination_exception(), DCHECK_EQ(ReadOnlyRoots(isolate_).termination_exception(),
isolate_->pending_exception()); isolate_->pending_exception());
// Convert the termination exception into a regular exception. // Convert the termination exception into a regular exception.
isolate_->CancelTerminateExecution(); isolate_->CancelTerminateExecution();
......
...@@ -6872,7 +6872,8 @@ void RegExpResultsCache::Enter(Isolate* isolate, Handle<String> key_string, ...@@ -6872,7 +6872,8 @@ void RegExpResultsCache::Enter(Isolate* isolate, Handle<String> key_string,
} }
} }
// Convert backing store to a copy-on-write array. // Convert backing store to a copy-on-write array.
value_array->set_map_no_write_barrier(isolate->heap()->fixed_cow_array_map()); value_array->set_map_no_write_barrier(
ReadOnlyRoots(isolate).fixed_cow_array_map());
} }
......
...@@ -1514,7 +1514,7 @@ class RegExpEngine: public AllStatic { ...@@ -1514,7 +1514,7 @@ class RegExpEngine: public AllStatic {
struct CompilationResult { struct CompilationResult {
CompilationResult(Isolate* isolate, const char* error_message) CompilationResult(Isolate* isolate, const char* error_message)
: error_message(error_message), : error_message(error_message),
code(isolate->heap()->the_hole_value()), code(ReadOnlyRoots(isolate).the_hole_value()),
num_registers(0) {} num_registers(0) {}
CompilationResult(Object* code, int registers) CompilationResult(Object* code, int registers)
: error_message(nullptr), code(code), num_registers(registers) {} : error_message(nullptr), code(code), num_registers(registers) {}
......
...@@ -164,29 +164,29 @@ void CodeSerializer::SerializeObject(HeapObject* obj, HowToCode how_to_code, ...@@ -164,29 +164,29 @@ void CodeSerializer::SerializeObject(HeapObject* obj, HowToCode how_to_code,
UNREACHABLE(); UNREACHABLE();
} }
ReadOnlyRoots roots(isolate());
if (ElideObject(obj)) { if (ElideObject(obj)) {
return SerializeObject(isolate()->heap()->undefined_value(), how_to_code, return SerializeObject(roots.undefined_value(), how_to_code, where_to_point,
where_to_point, skip); skip);
} }
if (obj->IsScript()) { if (obj->IsScript()) {
Script* script_obj = Script::cast(obj); Script* script_obj = Script::cast(obj);
DCHECK_NE(script_obj->compilation_type(), Script::COMPILATION_TYPE_EVAL); DCHECK_NE(script_obj->compilation_type(), Script::COMPILATION_TYPE_EVAL);
// Wrapper object is a context-dependent JSValue. Reset it here. // Wrapper object is a context-dependent JSValue. Reset it here.
script_obj->set_wrapper(isolate()->heap()->undefined_value()); script_obj->set_wrapper(roots.undefined_value());
// We want to differentiate between undefined and uninitialized_symbol for // We want to differentiate between undefined and uninitialized_symbol for
// context_data for now. It is hack to allow debugging for scripts that are // context_data for now. It is hack to allow debugging for scripts that are
// included as a part of custom snapshot. (see debug::Script::IsEmbedded()) // included as a part of custom snapshot. (see debug::Script::IsEmbedded())
Object* context_data = script_obj->context_data(); Object* context_data = script_obj->context_data();
if (context_data != isolate()->heap()->undefined_value() && if (context_data != roots.undefined_value() &&
context_data != isolate()->heap()->uninitialized_symbol()) { context_data != roots.uninitialized_symbol()) {
script_obj->set_context_data(isolate()->heap()->undefined_value()); script_obj->set_context_data(roots.undefined_value());
} }
// We don't want to serialize host options to avoid serializing unnecessary // We don't want to serialize host options to avoid serializing unnecessary
// object graph. // object graph.
FixedArray* host_options = script_obj->host_defined_options(); FixedArray* host_options = script_obj->host_defined_options();
script_obj->set_host_defined_options( script_obj->set_host_defined_options(roots.empty_fixed_array());
isolate()->heap()->empty_fixed_array());
SerializeGeneric(obj, how_to_code, where_to_point); SerializeGeneric(obj, how_to_code, where_to_point);
script_obj->set_host_defined_options(host_options); script_obj->set_host_defined_options(host_options);
script_obj->set_context_data(context_data); script_obj->set_context_data(context_data);
...@@ -315,7 +315,7 @@ MaybeHandle<SharedFunctionInfo> CodeSerializer::Deserialize( ...@@ -315,7 +315,7 @@ MaybeHandle<SharedFunctionInfo> CodeSerializer::Deserialize(
if (isolate->logger()->is_listening_to_code_events() || if (isolate->logger()->is_listening_to_code_events() ||
isolate->is_profiling()) { isolate->is_profiling()) {
String* name = isolate->heap()->empty_string(); String* name = ReadOnlyRoots(isolate).empty_string();
if (result->script()->IsScript()) { if (result->script()->IsScript()) {
Script* script = Script::cast(result->script()); Script* script = Script::cast(result->script());
if (script->name()->IsString()) name = String::cast(script->name()); if (script->name()->IsString()) name = String::cast(script->name());
......
...@@ -71,9 +71,9 @@ Address DefaultDeserializerAllocator::Allocate(AllocationSpace space, ...@@ -71,9 +71,9 @@ Address DefaultDeserializerAllocator::Allocate(AllocationSpace space,
// aligned object when the filler maps have not been deserialized yet. // aligned object when the filler maps have not been deserialized yet.
// We require filler maps as padding to align the object. // We require filler maps as padding to align the object.
Heap* heap = isolate()->heap(); Heap* heap = isolate()->heap();
DCHECK(heap->free_space_map()->IsMap()); DCHECK(ReadOnlyRoots(heap).free_space_map()->IsMap());
DCHECK(heap->one_pointer_filler_map()->IsMap()); DCHECK(ReadOnlyRoots(heap).one_pointer_filler_map()->IsMap());
DCHECK(heap->two_pointer_filler_map()->IsMap()); DCHECK(ReadOnlyRoots(heap).two_pointer_filler_map()->IsMap());
obj = heap->AlignWithFiller(obj, size, reserved, next_alignment_); obj = heap->AlignWithFiller(obj, size, reserved, next_alignment_);
address = obj->address(); address = obj->address();
next_alignment_ = kWordAligned; next_alignment_ = kWordAligned;
......
...@@ -182,7 +182,7 @@ HeapObject* Deserializer<AllocatorT>::PostProcessNewObject(HeapObject* obj, ...@@ -182,7 +182,7 @@ HeapObject* Deserializer<AllocatorT>::PostProcessNewObject(HeapObject* obj,
// as a (weak) root. If this root is relocated correctly, this becomes // as a (weak) root. If this root is relocated correctly, this becomes
// unnecessary. // unnecessary.
if (isolate_->heap()->allocation_sites_list() == Smi::kZero) { if (isolate_->heap()->allocation_sites_list() == Smi::kZero) {
site->set_weak_next(isolate_->heap()->undefined_value()); site->set_weak_next(ReadOnlyRoots(isolate_).undefined_value());
} else { } else {
site->set_weak_next(isolate_->heap()->allocation_sites_list()); site->set_weak_next(isolate_->heap()->allocation_sites_list());
} }
...@@ -203,7 +203,7 @@ HeapObject* Deserializer<AllocatorT>::PostProcessNewObject(HeapObject* obj, ...@@ -203,7 +203,7 @@ HeapObject* Deserializer<AllocatorT>::PostProcessNewObject(HeapObject* obj,
call_handler_infos_.push_back(CallHandlerInfo::cast(obj)); call_handler_infos_.push_back(CallHandlerInfo::cast(obj));
#endif #endif
} else if (obj->IsExternalString()) { } else if (obj->IsExternalString()) {
if (obj->map() == isolate_->heap()->native_source_string_map()) { if (obj->map() == ReadOnlyRoots(isolate_).native_source_string_map()) {
ExternalOneByteString* string = ExternalOneByteString::cast(obj); ExternalOneByteString* string = ExternalOneByteString::cast(obj);
DCHECK(string->is_short()); DCHECK(string->is_short());
string->set_resource( string->set_resource(
......
...@@ -37,11 +37,11 @@ void PartialSerializer::Serialize(Context** o, bool include_global_proxy) { ...@@ -37,11 +37,11 @@ void PartialSerializer::Serialize(Context** o, bool include_global_proxy) {
// it before serializing, it will get re-added to the context list // it before serializing, it will get re-added to the context list
// explicitly when it's loaded. // explicitly when it's loaded.
context_->set(Context::NEXT_CONTEXT_LINK, context_->set(Context::NEXT_CONTEXT_LINK,
isolate()->heap()->undefined_value()); ReadOnlyRoots(isolate()).undefined_value());
DCHECK(!context_->global_object()->IsUndefined()); DCHECK(!context_->global_object()->IsUndefined());
// Reset math random cache to get fresh random numbers. // Reset math random cache to get fresh random numbers.
context_->set_math_random_index(Smi::kZero); context_->set_math_random_index(Smi::kZero);
context_->set_math_random_cache(isolate()->heap()->undefined_value()); context_->set_math_random_cache(ReadOnlyRoots(isolate()).undefined_value());
VisitRootPointer(Root::kPartialSnapshotCache, nullptr, VisitRootPointer(Root::kPartialSnapshotCache, nullptr,
reinterpret_cast<Object**>(o)); reinterpret_cast<Object**>(o));
...@@ -125,8 +125,8 @@ bool PartialSerializer::ShouldBeInThePartialSnapshotCache(HeapObject* o) { ...@@ -125,8 +125,8 @@ bool PartialSerializer::ShouldBeInThePartialSnapshotCache(HeapObject* o) {
return o->IsName() || o->IsSharedFunctionInfo() || o->IsHeapNumber() || return o->IsName() || o->IsSharedFunctionInfo() || o->IsHeapNumber() ||
o->IsCode() || o->IsScopeInfo() || o->IsAccessorInfo() || o->IsCode() || o->IsScopeInfo() || o->IsAccessorInfo() ||
o->IsTemplateInfo() || o->IsTemplateInfo() ||
o->map() == o->map() == ReadOnlyRoots(startup_serializer_->isolate())
startup_serializer_->isolate()->heap()->fixed_cow_array_map(); .fixed_cow_array_map();
} }
void PartialSerializer::SerializeEmbedderFields() { void PartialSerializer::SerializeEmbedderFields() {
......
...@@ -500,7 +500,7 @@ void Serializer<AllocatorT>::ObjectSerializer::SerializeExternalString() { ...@@ -500,7 +500,7 @@ void Serializer<AllocatorT>::ObjectSerializer::SerializeExternalString() {
// for native native source code strings, we replace the resource field // for native native source code strings, we replace the resource field
// with the native source id. // with the native source id.
// For the rest we serialize them to look like ordinary sequential strings. // For the rest we serialize them to look like ordinary sequential strings.
if (object_->map() != heap->native_source_string_map()) { if (object_->map() != ReadOnlyRoots(heap).native_source_string_map()) {
ExternalString* string = ExternalString::cast(object_); ExternalString* string = ExternalString::cast(object_);
Address resource = string->resource_as_address(); Address resource = string->resource_as_address();
ExternalReferenceEncoder::Value reference; ExternalReferenceEncoder::Value reference;
...@@ -532,9 +532,9 @@ void Serializer< ...@@ -532,9 +532,9 @@ void Serializer<
AllocatorT>::ObjectSerializer::SerializeExternalStringAsSequentialString() { AllocatorT>::ObjectSerializer::SerializeExternalStringAsSequentialString() {
// Instead of serializing this as an external string, we serialize // Instead of serializing this as an external string, we serialize
// an imaginary sequential string with the same content. // an imaginary sequential string with the same content.
Isolate* isolate = serializer_->isolate(); ReadOnlyRoots roots(serializer_->isolate());
DCHECK(object_->IsExternalString()); DCHECK(object_->IsExternalString());
DCHECK(object_->map() != isolate->heap()->native_source_string_map()); DCHECK(object_->map() != roots.native_source_string_map());
ExternalString* string = ExternalString::cast(object_); ExternalString* string = ExternalString::cast(object_);
int length = string->length(); int length = string->length();
Map* map; Map* map;
...@@ -544,15 +544,14 @@ void Serializer< ...@@ -544,15 +544,14 @@ void Serializer<
// Find the map and size for the imaginary sequential string. // Find the map and size for the imaginary sequential string.
bool internalized = object_->IsInternalizedString(); bool internalized = object_->IsInternalizedString();
if (object_->IsExternalOneByteString()) { if (object_->IsExternalOneByteString()) {
map = internalized ? isolate->heap()->one_byte_internalized_string_map() map = internalized ? roots.one_byte_internalized_string_map()
: isolate->heap()->one_byte_string_map(); : roots.one_byte_string_map();
allocation_size = SeqOneByteString::SizeFor(length); allocation_size = SeqOneByteString::SizeFor(length);
content_size = length * kCharSize; content_size = length * kCharSize;
resource = reinterpret_cast<const byte*>( resource = reinterpret_cast<const byte*>(
ExternalOneByteString::cast(string)->resource()->data()); ExternalOneByteString::cast(string)->resource()->data());
} else { } else {
map = internalized ? isolate->heap()->internalized_string_map() map = internalized ? roots.internalized_string_map() : roots.string_map();
: isolate->heap()->string_map();
allocation_size = SeqTwoByteString::SizeFor(length); allocation_size = SeqTwoByteString::SizeFor(length);
content_size = length * kShortSize; content_size = length * kShortSize;
resource = reinterpret_cast<const byte*>( resource = reinterpret_cast<const byte*>(
...@@ -595,7 +594,8 @@ class UnlinkWeakNextScope { ...@@ -595,7 +594,8 @@ class UnlinkWeakNextScope {
if (object->IsAllocationSite()) { if (object->IsAllocationSite()) {
object_ = object; object_ = object;
next_ = AllocationSite::cast(object)->weak_next(); next_ = AllocationSite::cast(object)->weak_next();
AllocationSite::cast(object)->set_weak_next(heap->undefined_value()); AllocationSite::cast(object)->set_weak_next(
ReadOnlyRoots(heap).undefined_value());
} }
} }
...@@ -648,7 +648,7 @@ void Serializer<AllocatorT>::ObjectSerializer::Serialize() { ...@@ -648,7 +648,7 @@ void Serializer<AllocatorT>::ObjectSerializer::Serialize() {
if (object_->IsScript()) { if (object_->IsScript()) {
// Clear cached line ends. // Clear cached line ends.
Object* undefined = serializer_->isolate()->heap()->undefined_value(); Object* undefined = ReadOnlyRoots(serializer_->isolate()).undefined_value();
Script::cast(object_)->set_line_ends(undefined); Script::cast(object_)->set_line_ends(undefined);
} }
......
...@@ -52,12 +52,13 @@ void StartupDeserializer::DeserializeInto(Isolate* isolate) { ...@@ -52,12 +52,13 @@ void StartupDeserializer::DeserializeInto(Isolate* isolate) {
FlushICacheForNewIsolate(); FlushICacheForNewIsolate();
} }
isolate->heap()->set_native_contexts_list(isolate->heap()->undefined_value()); isolate->heap()->set_native_contexts_list(
ReadOnlyRoots(isolate).undefined_value());
// The allocation site list is build during root iteration, but if no sites // The allocation site list is build during root iteration, but if no sites
// were encountered then it needs to be initialized to undefined. // were encountered then it needs to be initialized to undefined.
if (isolate->heap()->allocation_sites_list() == Smi::kZero) { if (isolate->heap()->allocation_sites_list() == Smi::kZero) {
isolate->heap()->set_allocation_sites_list( isolate->heap()->set_allocation_sites_list(
isolate->heap()->undefined_value()); ReadOnlyRoots(isolate).undefined_value());
} }
// Issue code events for newly deserialized code objects. // Issue code events for newly deserialized code objects.
......
...@@ -65,12 +65,12 @@ void StartupSerializer::SerializeObject(HeapObject* obj, HowToCode how_to_code, ...@@ -65,12 +65,12 @@ void StartupSerializer::SerializeObject(HeapObject* obj, HowToCode how_to_code,
call_handler_infos_.push_back(info); call_handler_infos_.push_back(info);
} else if (obj->IsScript() && Script::cast(obj)->IsUserJavaScript()) { } else if (obj->IsScript() && Script::cast(obj)->IsUserJavaScript()) {
Script::cast(obj)->set_context_data( Script::cast(obj)->set_context_data(
isolate()->heap()->uninitialized_symbol()); ReadOnlyRoots(isolate()).uninitialized_symbol());
} else if (obj->IsSharedFunctionInfo()) { } else if (obj->IsSharedFunctionInfo()) {
// Clear inferred name for native functions. // Clear inferred name for native functions.
SharedFunctionInfo* shared = SharedFunctionInfo::cast(obj); SharedFunctionInfo* shared = SharedFunctionInfo::cast(obj);
if (!shared->IsSubjectToDebugging() && shared->HasInferredName()) { if (!shared->IsSubjectToDebugging() && shared->HasInferredName()) {
shared->set_inferred_name(isolate()->heap()->empty_string()); shared->set_inferred_name(ReadOnlyRoots(isolate()).empty_string());
} }
} }
...@@ -86,7 +86,7 @@ void StartupSerializer::SerializeWeakReferencesAndDeferred() { ...@@ -86,7 +86,7 @@ void StartupSerializer::SerializeWeakReferencesAndDeferred() {
// This comes right after serialization of the partial snapshot, where we // This comes right after serialization of the partial snapshot, where we
// add entries to the partial snapshot cache of the startup snapshot. Add // add entries to the partial snapshot cache of the startup snapshot. Add
// one entry with 'undefined' to terminate the partial snapshot cache. // one entry with 'undefined' to terminate the partial snapshot cache.
Object* undefined = isolate()->heap()->undefined_value(); Object* undefined = ReadOnlyRoots(isolate()).undefined_value();
VisitRootPointer(Root::kPartialSnapshotCache, nullptr, &undefined); VisitRootPointer(Root::kPartialSnapshotCache, nullptr, &undefined);
isolate()->heap()->IterateWeakRoots(this, VISIT_FOR_SERIALIZATION); isolate()->heap()->IterateWeakRoots(this, VISIT_FOR_SERIALIZATION);
SerializeDeferredObjects(); SerializeDeferredObjects();
......
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