Reviewers: alph,

Description:
Revert "Allow arbitrary names for weak references in heap snapshots."

This reverts commit r18838 for breaking build with clang. Errors are:

../../src/heap-snapshot-generator.cc:1217:53: error: empty macro arguments were
standardized in C99 [-Werror,-pedantic]
EXTRACT_CONTEXT_FIELD(OPTIMIZED_FUNCTIONS_LIST, , optimized_functions_list); ../../src/heap-snapshot-generator.cc:1218:48: error: empty macro arguments were
standardized in C99 [-Werror,-pedantic]
    EXTRACT_CONTEXT_FIELD(OPTIMIZED_CODE_LIST, , optimized_code_list);
../../src/heap-snapshot-generator.cc:1219:50: error: empty macro arguments were
standardized in C99 [-Werror,-pedantic]
    EXTRACT_CONTEXT_FIELD(DEOPTIMIZED_CODE_LIST, , deoptimized_code_list);
../../src/heap-snapshot-generator.cc:1220:46: error: empty macro arguments were
standardized in C99 [-Werror,-pedantic]
    EXTRACT_CONTEXT_FIELD(NEXT_CONTEXT_LINK, , next_context_link);

[email protected]

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

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files (+35, -53 lines):
  src/api.cc
  src/heap-snapshot-generator.h
  src/heap-snapshot-generator.cc
  test/cctest/test-heap-profiler.cc


Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index 064a4b013f45e22b2327c4a451fae928cbfff27e..a00e6080145aaafab13bea181c366e1fb87c9743 100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -6944,11 +6944,11 @@ Handle<Value> HeapGraphEdge::GetName() const {
     case i::HeapGraphEdge::kInternal:
     case i::HeapGraphEdge::kProperty:
     case i::HeapGraphEdge::kShortcut:
-    case i::HeapGraphEdge::kWeak:
       return ToApiHandle<String>(
           isolate->factory()->InternalizeUtf8String(edge->name()));
     case i::HeapGraphEdge::kElement:
     case i::HeapGraphEdge::kHidden:
+    case i::HeapGraphEdge::kWeak:
       return ToApiHandle<Number>(
           isolate->factory()->NewNumberFromInt(edge->index()));
     default: UNREACHABLE();
Index: src/heap-snapshot-generator.cc
diff --git a/src/heap-snapshot-generator.cc b/src/heap-snapshot-generator.cc
index 887e9f56bbf1c92407d2a5912ca9b52a75b36472..8c8182e8dba617423c1cfa1e2d82b4e52749948a 100644
--- a/src/heap-snapshot-generator.cc
+++ b/src/heap-snapshot-generator.cc
@@ -47,8 +47,7 @@ HeapGraphEdge::HeapGraphEdge(Type type, const char* name, int from, int to)
   ASSERT(type == kContextVariable
       || type == kProperty
       || type == kInternal
-      || type == kShortcut
-      || type == kWeak);
+      || type == kShortcut);
 }


@@ -57,7 +56,7 @@ HeapGraphEdge::HeapGraphEdge(Type type, int index, int from, int to)
       from_index_(from),
       to_index_(to),
       index_(index) {
-  ASSERT(type == kElement || type == kHidden);
+  ASSERT(type == kElement || type == kHidden || type == kWeak);
 }


@@ -151,7 +150,7 @@ void HeapEntry::Print(
         break;
       case HeapGraphEdge::kWeak:
         edge_prefix = "w";
-        edge_name = edge.name();
+        OS::SNPrintF(index, "%d", edge.index());
         break;
       default:
         OS::SNPrintF(index, "!!! unknown edge type: %d ", edge.type());
@@ -1115,13 +1114,11 @@ void V8HeapExplorer::ExtractJSObjectReferences(
     SetInternalReference(js_fun, entry,
                          "context", js_fun->context(),
                          JSFunction::kContextOffset);
-    SetWeakReference(js_fun, entry,
-                     "next_function_link", js_fun->next_function_link(),
-                     JSFunction::kNextFunctionLinkOffset);
-    STATIC_CHECK(JSFunction::kNextFunctionLinkOffset
-                 == JSFunction::kNonWeakFieldsEndOffset);
-    STATIC_CHECK(JSFunction::kNextFunctionLinkOffset + kPointerSize
-                 == JSFunction::kSize);
+    for (int i = JSFunction::kNonWeakFieldsEndOffset;
+         i < JSFunction::kSize;
+         i += kPointerSize) {
+ SetWeakReference(js_fun, entry, i, *HeapObject::RawField(js_fun, i), i);
+    }
   } else if (obj->IsGlobalObject()) {
     GlobalObject* global_obj = GlobalObject::cast(obj);
     SetInternalReference(global_obj, entry,
@@ -1137,14 +1134,13 @@ void V8HeapExplorer::ExtractJSObjectReferences(
     JSArrayBufferView* view = JSArrayBufferView::cast(obj);
     SetInternalReference(view, entry, "buffer", view->buffer(),
                          JSArrayBufferView::kBufferOffset);
-    SetWeakReference(view, entry, "weak_next", view->weak_next(),
+    SetWeakReference(view, entry, 1, view->weak_next(),
                      JSArrayBufferView::kWeakNextOffset);
   } else if (obj->IsJSArrayBuffer()) {
     JSArrayBuffer* buffer = JSArrayBuffer::cast(obj);
-    SetWeakReference(buffer, entry, "weak_next", buffer->weak_next(),
+    SetWeakReference(buffer, entry, 1, buffer->weak_next(),
                      JSArrayBuffer::kWeakNextOffset);
-    SetWeakReference(buffer, entry,
-                     "weak_first_view", buffer->weak_first_view(),
+    SetWeakReference(buffer, entry, 2, buffer->weak_first_view(),
                      JSArrayBuffer::kWeakFirstViewOffset);
   }
   TagObject(js_obj->properties(), "(object properties)");
@@ -1196,13 +1192,8 @@ void V8HeapExplorer::ExtractContextReferences(int entry, Context* context) {
   }

 #define EXTRACT_CONTEXT_FIELD(index, type, name) \
-  if (Context::index < Context::FIRST_WEAK_SLOT) { \
- SetInternalReference(context, entry, #name, context->get(Context::index), \
-        FixedArray::OffsetOfElementAt(Context::index)); \
-  } else { \
-    SetWeakReference(context, entry, #name, context->get(Context::index), \
-        FixedArray::OffsetOfElementAt(Context::index)); \
-  }
+ SetInternalReference(context, entry, #name, context->get(Context::index), \
+      FixedArray::OffsetOfElementAt(Context::index));
   EXTRACT_CONTEXT_FIELD(CLOSURE_INDEX, JSFunction, closure);
   EXTRACT_CONTEXT_FIELD(PREVIOUS_INDEX, Context, previous);
   EXTRACT_CONTEXT_FIELD(EXTENSION_INDEX, Object, extension);
@@ -1214,15 +1205,13 @@ void V8HeapExplorer::ExtractContextReferences(int entry, Context* context) {
     TagObject(context->runtime_context(), "(runtime context)");
     TagObject(context->embedder_data(), "(context data)");
     NATIVE_CONTEXT_FIELDS(EXTRACT_CONTEXT_FIELD);
- EXTRACT_CONTEXT_FIELD(OPTIMIZED_FUNCTIONS_LIST, , optimized_functions_list);
-    EXTRACT_CONTEXT_FIELD(OPTIMIZED_CODE_LIST, , optimized_code_list);
-    EXTRACT_CONTEXT_FIELD(DEOPTIMIZED_CODE_LIST, , deoptimized_code_list);
-    EXTRACT_CONTEXT_FIELD(NEXT_CONTEXT_LINK, , next_context_link);
 #undef EXTRACT_CONTEXT_FIELD
- STATIC_CHECK(Context::OPTIMIZED_FUNCTIONS_LIST == Context::FIRST_WEAK_SLOT);
-    STATIC_CHECK(Context::NEXT_CONTEXT_LINK + 1
-                 == Context::NATIVE_CONTEXT_SLOTS);
- STATIC_CHECK(Context::FIRST_WEAK_SLOT + 5 == Context::NATIVE_CONTEXT_SLOTS);
+    for (int i = Context::FIRST_WEAK_SLOT;
+         i < Context::NATIVE_CONTEXT_SLOTS;
+         ++i) {
+      SetWeakReference(context, entry, i, context->get(i),
+          FixedArray::OffsetOfElementAt(i));
+    }
   }
 }

@@ -1316,7 +1305,7 @@ void V8HeapExplorer::ExtractSharedFunctionInfoReferences(
                        "optimized_code_map", shared->optimized_code_map(),
                        SharedFunctionInfo::kOptimizedCodeMapOffset);
   SetWeakReference(obj, entry,
-                   "initial_map", shared->initial_map(),
+                   1, shared->initial_map(),
                    SharedFunctionInfo::kInitialMapOffset);
 }

@@ -1846,17 +1835,17 @@ void V8HeapExplorer::SetHiddenReference(HeapObject* parent_obj,

 void V8HeapExplorer::SetWeakReference(HeapObject* parent_obj,
                                       int parent_entry,
-                                      const char* reference_name,
+                                      int index,
                                       Object* child_obj,
                                       int field_offset) {
   ASSERT(parent_entry == GetEntry(parent_obj)->index());
   HeapEntry* child_entry = GetEntry(child_obj);
   if (child_entry == NULL) return;
   if (IsEssentialObject(child_obj)) {
-    filler_->SetNamedReference(HeapGraphEdge::kWeak,
-                               parent_entry,
-                               reference_name,
-                               child_entry);
+    filler_->SetIndexedReference(HeapGraphEdge::kWeak,
+                                 parent_entry,
+                                 index,
+                                 child_entry);
   }
   IndexedReferencesExtractor::MarkVisitedField(parent_obj, field_offset);
 }
@@ -1928,17 +1917,10 @@ void V8HeapExplorer::SetGcSubrootReference(
           name,
           child_entry);
     } else {
-      if (is_weak) {
-        filler_->SetNamedAutoIndexReference(
-            HeapGraphEdge::kWeak,
-            snapshot_->gc_subroot(tag)->index(),
-            child_entry);
-      } else {
-        filler_->SetIndexedAutoIndexReference(
-            HeapGraphEdge::kElement,
-            snapshot_->gc_subroot(tag)->index(),
-            child_entry);
-      }
+      filler_->SetIndexedAutoIndexReference(
+          is_weak ? HeapGraphEdge::kWeak : HeapGraphEdge::kElement,
+          snapshot_->gc_subroot(tag)->index(),
+          child_entry);
     }

     // Add a shortcut to JS global object reference at snapshot root.
@@ -2672,6 +2654,7 @@ void HeapSnapshotJSONSerializer::SerializeEdge(HeapGraphEdge* edge,
   EmbeddedVector<char, kBufferSize> buffer;
   int edge_name_or_index = edge->type() == HeapGraphEdge::kElement
       || edge->type() == HeapGraphEdge::kHidden
+      || edge->type() == HeapGraphEdge::kWeak
       ? edge->index() : GetStringId(edge->name());
   int buffer_pos = 0;
   if (!first_edge) {
Index: src/heap-snapshot-generator.h
diff --git a/src/heap-snapshot-generator.h b/src/heap-snapshot-generator.h
index 59d324e499cf8daeabc404a6f05f501a28397d0e..d93362f63bc1a6d61fa90792b660a1e0b9432a2a 100644
--- a/src/heap-snapshot-generator.h
+++ b/src/heap-snapshot-generator.h
@@ -57,15 +57,14 @@ class HeapGraphEdge BASE_EMBEDDED {

   Type type() const { return static_cast<Type>(type_); }
   int index() const {
-    ASSERT(type_ == kElement || type_ == kHidden);
+    ASSERT(type_ == kElement || type_ == kHidden || type_ == kWeak);
     return index_;
   }
   const char* name() const {
     ASSERT(type_ == kContextVariable
         || type_ == kProperty
         || type_ == kInternal
-        || type_ == kShortcut
-        || type_ == kWeak);
+        || type_ == kShortcut);
     return name_;
   }
   INLINE(HeapEntry* from() const);
@@ -449,7 +448,7 @@ class V8HeapExplorer : public HeapEntriesAllocator {
                           Object* child);
   void SetWeakReference(HeapObject* parent_obj,
                         int parent,
-                        const char* reference_name,
+                        int index,
                         Object* child_obj,
                         int field_offset);
   void SetPropertyReference(HeapObject* parent_obj,
Index: test/cctest/test-heap-profiler.cc
diff --git a/test/cctest/test-heap-profiler.cc b/test/cctest/test-heap-profiler.cc index fdaf9fa6c9a7fa111848b0b20bc57f39aa087fe4..39b12c9e87414c4595c12e074f57b02d17eeed44 100644
--- a/test/cctest/test-heap-profiler.cc
+++ b/test/cctest/test-heap-profiler.cc
@@ -2337,6 +2337,6 @@ TEST(ArrayBufferAndArrayBufferView) {
       GetProperty(arr1_obj, v8::HeapGraphEdge::kInternal, "buffer");
   CHECK_NE(NULL, arr1_buffer);
   const v8::HeapGraphNode* first_view =
- GetProperty(arr1_buffer, v8::HeapGraphEdge::kWeak, "weak_first_view");
+      GetProperty(arr1_buffer, v8::HeapGraphEdge::kWeak, "2");
   CHECK_NE(NULL, first_view);
 }


--
--
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/groups/opt_out.

Reply via email to