Reviewers: Michael Lippautz, Yang,

Message:
Yang: PTAL at bootstrapper and deserializer.
Mike: PTAL.

Description:
[heap] Limit friendship of the Heap class to essentials.

This makes it clear that only components within the "heap" directory
should be friends with the Heap class. The two notable exceptions are
Factory and Isolate which represent external interfaces into the heap.

[email protected]

Please review this at https://codereview.chromium.org/1320843002/

Base URL: https://chromium.googlesource.com/v8/v8.git@master

Affected files (+34, -27 lines):
  M src/bootstrapper.cc
  M src/factory.h
  M src/heap/heap.h
  M src/heap/heap.cc
  M src/objects.cc
  M src/snapshot/serialize.cc


Index: src/bootstrapper.cc
diff --git a/src/bootstrapper.cc b/src/bootstrapper.cc
index 640ba1e9a33785f03c603015db6984292075796c..f753623185f34f354e6d6a5011fbed9ad432214b 100644
--- a/src/bootstrapper.cc
+++ b/src/bootstrapper.cc
@@ -344,13 +344,13 @@ bool Bootstrapper::CreateCodeStubContext(Isolate* isolate) {
   Handle<Context> native_context = CreateEnvironment(
       MaybeHandle<JSGlobalProxy>(), v8::Local<v8::ObjectTemplate>(),
       &no_extensions, THIN_CONTEXT);
-  isolate->heap()->set_code_stub_context(*native_context);
+  isolate->heap()->public_set_code_stub_context(*native_context);
   isolate->set_context(*native_context);
   Handle<JSObject> code_stub_exports =
       isolate->factory()->NewJSObject(isolate->object_function());
JSObject::NormalizeProperties(code_stub_exports, CLEAR_INOBJECT_PROPERTIES, 2,
                                 "container to export to extra natives");
-  isolate->heap()->set_code_stub_exports_object(*code_stub_exports);
+  isolate->heap()->public_set_code_stub_exports_object(*code_stub_exports);
   return InstallCodeStubNatives(isolate);
 }

@@ -2173,11 +2173,6 @@ bool Genesis::InstallNatives(ContextType context_type) {
           script_is_embedder_debug_script, attribs);
       script_map->AppendDescriptor(&d);
     }
-
-    // Allocate the empty script.
- Handle<Script> script = factory()->NewScript(factory()->empty_string());
-    script->set_type(Smi::FromInt(Script::TYPE_NATIVE));
-    heap()->public_set_empty_script(*script);
   }
   {
     // Builtin function for OpaqueReference -- a JSValue-based object,
Index: src/factory.h
diff --git a/src/factory.h b/src/factory.h
index aa49b99b54a2d743afc822433319ef1eab3aa873..501a517d782b7ed0a7305dc65ef14ca5ee8b8167 100644
--- a/src/factory.h
+++ b/src/factory.h
@@ -622,14 +622,6 @@ class Factory final {
   PUBLIC_SYMBOL_LIST(SYMBOL_ACCESSOR)
 #undef SYMBOL_ACCESSOR

-  inline void set_string_table(Handle<StringTable> table) {
-    isolate()->heap()->set_string_table(*table);
-  }
-
-  inline void set_weak_stack_trace_list(Handle<WeakFixedArray> list) {
-    isolate()->heap()->set_weak_stack_trace_list(*list);
-  }
-
   // Allocates a new SharedFunctionInfo object.
   Handle<SharedFunctionInfo> NewSharedFunctionInfo(
       Handle<String> name, int number_of_literals, FunctionKind kind,
Index: src/heap/heap.cc
diff --git a/src/heap/heap.cc b/src/heap/heap.cc
index 5d67854462dbaa5d3a6967a5696014509f9e8cf1..91f4ecc7ae57ce75b9b2f5193c9b66a01508c15d 100644
--- a/src/heap/heap.cc
+++ b/src/heap/heap.cc
@@ -3303,6 +3303,11 @@ void Heap::CreateInitialObjects() {
   // Handling of script id generation is in Factory::NewScript.
   set_last_script_id(Smi::FromInt(v8::UnboundScript::kNoScriptId));

+  // Allocate the empty script.
+  Handle<Script> script = factory->NewScript(factory->empty_string());
+  script->set_type(Smi::FromInt(Script::TYPE_NATIVE));
+  set_empty_script(*script);
+
   Handle<PropertyCell> cell = factory->NewPropertyCell();
   cell->set_value(Smi::FromInt(Isolate::kArrayProtectorValid));
   set_array_protector(*cell);
Index: src/heap/heap.h
diff --git a/src/heap/heap.h b/src/heap/heap.h
index 254b19f83cb54714fd80a897f14242331ff0fb59..c2cc3eb51d88860d2e09130d919c82aacde3c1cf 100644
--- a/src/heap/heap.h
+++ b/src/heap/heap.h
@@ -1224,14 +1224,26 @@ class Heap {
     roots_[kNonMonomorphicCacheRootIndex] = value;
   }

-  void public_set_empty_script(Script* script) {
-    roots_[kEmptyScriptRootIndex] = script;
-  }
-
   void public_set_materialized_objects(FixedArray* objects) {
     roots_[kMaterializedObjectsRootIndex] = objects;
   }

+  void public_set_code_stub_context(Object* value) {
+    roots_[kCodeStubContextRootIndex] = value;
+  }
+
+  void public_set_code_stub_exports_object(JSObject* value) {
+    roots_[kCodeStubExportsObjectRootIndex] = value;
+  }
+
+  void public_set_script_list(Object* value) {
+    roots_[kScriptListRootIndex] = value;
+  }
+
+  void public_set_string_table(StringTable* value) {
+    roots_[kStringTableRootIndex] = value;
+  }
+
   // Set the stack limit in the roots_ array.  Some architectures generate
// code that looks here, because it is faster than loading from the static
   // jslimit_/real_jslimit_ variable in the StackGuard.
@@ -2407,21 +2419,23 @@ class Heap {

   StrongRootsList* strong_roots_list_;

+  // Classes in "heap" can be friends.
   friend class AlwaysAllocateScope;
-  friend class Bootstrapper;
-  friend class Deserializer;
-  friend class Factory;
   friend class GCCallbacksScope;
   friend class GCTracer;
   friend class HeapIterator;
   friend class IncrementalMarking;
-  friend class Isolate;
   friend class MarkCompactCollector;
   friend class MarkCompactMarkingVisitor;
-  friend class MapCompact;
   friend class Page;
   friend class StoreBuffer;

+  // The allocator interface.
+  friend class Factory;
+
+  // The Isolate constructs us.
+  friend class Isolate;
+
   // Used in cctest.
   friend class HeapTester;

Index: src/objects.cc
diff --git a/src/objects.cc b/src/objects.cc
index e2e5d4dc0bd03f632bcb40655eaaf6b9d64bde84..05aca17be7fb6d4b6b75ea56168f39de9149e144 100644
--- a/src/objects.cc
+++ b/src/objects.cc
@@ -14107,7 +14107,7 @@ void StringTable::EnsureCapacityForDeserialization(Isolate* isolate,
   // We need a key instance for the virtual hash function.
   InternalizedStringKey dummy_key(Handle<String>::null());
   table = StringTable::EnsureCapacity(table, expected, &dummy_key);
-  isolate->factory()->set_string_table(table);
+  isolate->heap()->public_set_string_table(*table);
 }


@@ -14141,7 +14141,7 @@ Handle<String> StringTable::LookupKey(Isolate* isolate, HashTableKey* key) {
   table->set(EntryToIndex(entry), *string);
   table->ElementAdded();

-  isolate->factory()->set_string_table(table);
+  isolate->heap()->public_set_string_table(*table);
   return Handle<String>::cast(string);
 }

Index: src/snapshot/serialize.cc
diff --git a/src/snapshot/serialize.cc b/src/snapshot/serialize.cc
index b1bca7bbd88b4e645ccb227fefb5ceb59e918ff9..065b0680b31712a45a1ff39fedd5fbfdcf17d58b 100644
--- a/src/snapshot/serialize.cc
+++ b/src/snapshot/serialize.cc
@@ -776,7 +776,8 @@ void Deserializer::CommitPostProcessedObjects(Isolate* isolate) {
     // Assign a new script id to avoid collision.
     script->set_id(isolate_->heap()->NextScriptId());
     // Add script to list.
- heap->set_script_list(*WeakFixedArray::Add(factory->script_list(), script)); + Handle<Object> list = WeakFixedArray::Add(factory->script_list(), script);
+    heap->public_set_script_list(*list);
   }
 }



--
--
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.

Reply via email to