Reviewers: Hannes Payer,

Message:
PTAL

Description:
Verify that code stubs and full code do not have pointers that can retain
context.

BUG=v8:3629
LOG=N

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

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

Affected files (+42, -14 lines):
  M src/code-stubs.cc
  M src/full-codegen.cc
  M src/ic/handler-compiler.cc
  M src/ic/ic-compiler.cc
  M src/objects.h
  M src/objects-debug.cc


Index: src/code-stubs.cc
diff --git a/src/code-stubs.cc b/src/code-stubs.cc
index 895569d41357ca34acea2c232dc406044a8cd64d..3a15fdaabc162c341999b9a9954950259b85b283 100644
--- a/src/code-stubs.cc
+++ b/src/code-stubs.cc
@@ -81,6 +81,9 @@ void CodeStub::RecordCodeGeneration(Handle<Code> code) {
           CodeCreateEvent(Logger::STUB_TAG, *code, os.str().c_str()));
   Counters* counters = isolate()->counters();
   counters->total_stubs_code_size()->Increment(code->instruction_size());
+#ifdef DEBUG
+  code->VerifyEmbeddedObjects();
+#endif
 }


Index: src/full-codegen.cc
diff --git a/src/full-codegen.cc b/src/full-codegen.cc
index cc32c3e31fa50b5fd8e3601d69869dcc4187a56e..81f3baa1cc29f444661687ea42ea1b3dfd5febb3 100644
--- a/src/full-codegen.cc
+++ b/src/full-codegen.cc
@@ -351,7 +351,7 @@ bool FullCodeGenerator::MakeCode(CompilationInfo* info) {

 #ifdef DEBUG
   // Check that no context-specific object has been embedded.
-  code->VerifyEmbeddedObjectsInFullCode();
+  code->VerifyEmbeddedObjects(Code::kNoContextSpecificPointers);
 #endif  // DEBUG
   return true;
 }
Index: src/ic/handler-compiler.cc
diff --git a/src/ic/handler-compiler.cc b/src/ic/handler-compiler.cc
index 00df7be065371c46a40f732385eeae0b12a55840..4b253af197842a7cbd549ca5692fa5170a6cfff8 100644
--- a/src/ic/handler-compiler.cc
+++ b/src/ic/handler-compiler.cc
@@ -75,6 +75,9 @@ Handle<Code> PropertyHandlerCompiler::GetCode(Code::Kind kind, Code::Flags flags = Code::ComputeHandlerFlags(kind, type, cache_holder());
   Handle<Code> code = GetCodeWithFlags(flags, name);
   PROFILE(isolate(), CodeCreateEvent(Logger::STUB_TAG, *code, *name));
+#ifdef DEBUG
+  code->VerifyEmbeddedObjects();
+#endif
   return code;
 }

Index: src/ic/ic-compiler.cc
diff --git a/src/ic/ic-compiler.cc b/src/ic/ic-compiler.cc
index e087acfcb0e71f1be9d6a75a961a10f00563c477..7fca34bd9f84dc13a2bb3373668e6f335a15cc74 100644
--- a/src/ic/ic-compiler.cc
+++ b/src/ic/ic-compiler.cc
@@ -381,6 +381,9 @@ Handle<Code> PropertyICCompiler::GetCode(Code::Kind kind, Code::StubType type, Code::ComputeFlags(kind, state, extra_ic_state_, type, cache_holder());
   Handle<Code> code = GetCodeWithFlags(flags, name);
   PROFILE(isolate(), CodeCreateEvent(log_kind(code), *code, *name));
+#ifdef DEBUG
+  code->VerifyEmbeddedObjects();
+#endif
   return code;
 }

Index: src/objects-debug.cc
diff --git a/src/objects-debug.cc b/src/objects-debug.cc
index a8cbe9cf153dd91d01a6e20a02f006648f83cb06..256108a59658c73977f7f6b0c3d2db58f30e5856 100644
--- a/src/objects-debug.cc
+++ b/src/objects-debug.cc
@@ -1236,20 +1236,38 @@ bool TransitionArray::IsConsistentWithBackPointers(Map* current_map) {
 }


-void Code::VerifyEmbeddedObjectsInFullCode() {
-  // Check that no context-specific object has been embedded.
+bool CanLeak(Object* obj, Heap* heap, bool skip_weak_cell) {
+  if (!obj->IsHeapObject()) return false;
+  if (obj->IsWeakCell()) {
+    if (skip_weak_cell) return false;
+    return CanLeak(WeakCell::cast(obj)->value(), heap, skip_weak_cell);
+  }
+  if (obj->IsCell()) {
+    return CanLeak(Cell::cast(obj)->value(), heap, skip_weak_cell);
+  }
+  if (obj->IsPropertyCell()) {
+    return CanLeak(PropertyCell::cast(obj)->value(), heap, skip_weak_cell);
+  }
+  if (obj->IsContext()) return true;
+  if (obj->IsMap()) {
+    Map* map = Map::cast(obj);
+    for (int i = 0; i < Heap::kStrongRootListLength; i++) {
+      if (map == heap->roots_array_start()[i]) return false;
+    }
+    return true;
+  }
+  return CanLeak(HeapObject::cast(obj)->map(), heap, skip_weak_cell);
+}
+
+
+void Code::VerifyEmbeddedObjects(VerifyMode mode) {
+  if (kind() == OPTIMIZED_FUNCTION) return;
   Heap* heap = GetIsolate()->heap();
-  int mask = RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT);
+  int mask = RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT) |
+             RelocInfo::ModeMask(RelocInfo::CELL);
+ bool skip_weak_cell = (mode == kNoContextSpecificPointers) ? false : true;
   for (RelocIterator it(this, mask); !it.done(); it.next()) {
-    Object* obj = it.rinfo()->target_object();
-    if (obj->IsCell()) obj = Cell::cast(obj)->value();
-    if (obj->IsPropertyCell()) obj = PropertyCell::cast(obj)->value();
-    if (!obj->IsHeapObject()) continue;
- Map* map = obj->IsMap() ? Map::cast(obj) : HeapObject::cast(obj)->map();
-    int i = 0;
-    while (map != heap->roots_array_start()[i++]) {
-      CHECK_LT(i, Heap::kStrongRootListLength);
-    }
+    CHECK(!CanLeak(it.rinfo()->target_object(), heap, skip_weak_cell));
   }
 }

Index: src/objects.h
diff --git a/src/objects.h b/src/objects.h
index d1e5acff893d65b008606969db7241a873602656..c71dd9f3ef461ab43d5e355a5e888017a08f607c 100644
--- a/src/objects.h
+++ b/src/objects.h
@@ -5401,7 +5401,8 @@ class Code: public HeapObject {
 #endif

 #ifdef DEBUG
-  void VerifyEmbeddedObjectsInFullCode();
+ enum VerifyMode { kNoContextSpecificPointers, kNoContextRetainingPointers }; + void VerifyEmbeddedObjects(VerifyMode mode = kNoContextRetainingPointers);
 #endif  // DEBUG

   inline bool CanContainWeakObjects() {


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