Commit 20e6446b authored by alexeif@chromium.org's avatar alexeif@chromium.org

Refactoring of heap profiler: split ExtractReferences into several functions.

Review URL: https://chromiumcodereview.appspot.com/10198011

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@11424 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 83cbc638
......@@ -1978,10 +1978,37 @@ void V8HeapExplorer::ExtractReferences(HeapObject* obj) {
bool extract_indexed_refs = true;
if (obj->IsJSGlobalProxy()) {
ExtractJSGlobalProxy(JSGlobalProxy::cast(obj));
} else if (obj->IsJSObject()) {
ExtractJSObject(entry, JSObject::cast(obj));
} else if (obj->IsString()) {
ExtractString(entry, String::cast(obj));
extract_indexed_refs = false;
} else if (obj->IsContext()) {
ExtractContext(entry, Context::cast(obj));
} else if (obj->IsMap()) {
ExtractMap(entry, Map::cast(obj));
} else if (obj->IsSharedFunctionInfo()) {
ExtractSharedFunctionInfo(entry, SharedFunctionInfo::cast(obj));
} else if (obj->IsScript()) {
ExtractScript(entry, Script::cast(obj));
} else if (obj->IsCodeCache()) {
ExtractCodeCache(entry, CodeCache::cast(obj));
} else if (obj->IsCode()) {
ExtractCode(entry, Code::cast(obj));
}
if (extract_indexed_refs) {
SetInternalReference(obj, entry, "map", obj->map(), HeapObject::kMapOffset);
IndexedReferencesExtractor refs_extractor(this, obj, entry);
obj->Iterate(&refs_extractor);
}
}
void V8HeapExplorer::ExtractJSGlobalProxy(JSGlobalProxy* proxy) {
// We need to reference JS global objects from snapshot's root.
// We use JSGlobalProxy because this is what embedder (e.g. browser)
// uses for the global object.
JSGlobalProxy* proxy = JSGlobalProxy::cast(obj);
Object* object = proxy->map()->prototype();
bool is_debug_object = false;
#ifdef ENABLE_DEBUGGER_SUPPORT
......@@ -1991,8 +2018,11 @@ void V8HeapExplorer::ExtractReferences(HeapObject* obj) {
if (!is_debug_object) {
SetUserGlobalReference(object);
}
} else if (obj->IsJSObject()) {
JSObject* js_obj = JSObject::cast(obj);
}
void V8HeapExplorer::ExtractJSObject(HeapEntry* entry, JSObject* js_obj) {
HeapObject* obj = js_obj;
ExtractClosureReferences(js_obj, entry);
ExtractPropertyReferences(js_obj, entry);
ExtractElementReferences(js_obj, entry);
......@@ -2057,19 +2087,23 @@ void V8HeapExplorer::ExtractReferences(HeapObject* obj) {
SetInternalReference(obj, entry,
"elements", js_obj->elements(),
JSObject::kElementsOffset);
} else if (obj->IsString()) {
if (obj->IsConsString()) {
ConsString* cs = ConsString::cast(obj);
SetInternalReference(obj, entry, 1, cs->first());
SetInternalReference(obj, entry, 2, cs->second());
}
void V8HeapExplorer::ExtractString(HeapEntry* entry, String* string) {
if (string->IsConsString()) {
ConsString* cs = ConsString::cast(string);
SetInternalReference(cs, entry, 1, cs->first());
SetInternalReference(cs, entry, 2, cs->second());
}
if (obj->IsSlicedString()) {
SlicedString* ss = SlicedString::cast(obj);
SetInternalReference(obj, entry, "parent", ss->parent());
if (string->IsSlicedString()) {
SlicedString* ss = SlicedString::cast(string);
SetInternalReference(ss, entry, "parent", ss->parent());
}
extract_indexed_refs = false;
} else if (obj->IsContext()) {
Context* context = Context::cast(obj);
}
void V8HeapExplorer::ExtractContext(HeapEntry* entry, Context* context) {
#define EXTRACT_CONTEXT_FIELD(index, type, name) \
SetInternalReference(context, entry, #name, context->get(Context::index), \
FixedArray::OffsetOfElementAt(Context::index));
......@@ -2077,7 +2111,7 @@ void V8HeapExplorer::ExtractReferences(HeapObject* obj) {
EXTRACT_CONTEXT_FIELD(PREVIOUS_INDEX, Context, previous);
EXTRACT_CONTEXT_FIELD(EXTENSION_INDEX, Object, extension);
EXTRACT_CONTEXT_FIELD(GLOBAL_INDEX, GlobalObject, global);
if (obj->IsGlobalContext()) {
if (context->IsGlobalContext()) {
TagObject(context->jsfunction_result_caches(),
"(context func. result caches)");
TagObject(context->normalized_map_cache(), "(context norm. map cache)");
......@@ -2088,33 +2122,38 @@ void V8HeapExplorer::ExtractReferences(HeapObject* obj) {
for (int i = Context::FIRST_WEAK_SLOT;
i < Context::GLOBAL_CONTEXT_SLOTS;
++i) {
SetWeakReference(obj, entry,
i, context->get(i),
SetWeakReference(context, entry, i, context->get(i),
FixedArray::OffsetOfElementAt(i));
}
}
} else if (obj->IsMap()) {
Map* map = Map::cast(obj);
SetInternalReference(obj, entry,
}
void V8HeapExplorer::ExtractMap(HeapEntry* entry, Map* map) {
SetInternalReference(map, entry,
"prototype", map->prototype(), Map::kPrototypeOffset);
SetInternalReference(obj, entry,
SetInternalReference(map, entry,
"constructor", map->constructor(),
Map::kConstructorOffset);
if (!map->instance_descriptors()->IsEmpty()) {
TagObject(map->instance_descriptors(), "(map descriptors)");
SetInternalReference(obj, entry,
SetInternalReference(map, entry,
"descriptors", map->instance_descriptors(),
Map::kInstanceDescriptorsOrBitField3Offset);
}
TagObject(map->prototype_transitions(), "(prototype transitions)");
SetInternalReference(obj, entry,
SetInternalReference(map, entry,
"prototype_transitions", map->prototype_transitions(),
Map::kPrototypeTransitionsOffset);
SetInternalReference(obj, entry,
SetInternalReference(map, entry,
"code_cache", map->code_cache(),
Map::kCodeCacheOffset);
} else if (obj->IsSharedFunctionInfo()) {
SharedFunctionInfo* shared = SharedFunctionInfo::cast(obj);
}
void V8HeapExplorer::ExtractSharedFunctionInfo(
HeapEntry* entry, SharedFunctionInfo* shared) {
HeapObject* obj = shared;
SetInternalReference(obj, entry,
"name", shared->name(),
SharedFunctionInfo::kNameOffset);
......@@ -2152,8 +2191,11 @@ void V8HeapExplorer::ExtractReferences(HeapObject* obj) {
SetWeakReference(obj, entry,
1, shared->initial_map(),
SharedFunctionInfo::kInitialMapOffset);
} else if (obj->IsScript()) {
Script* script = Script::cast(obj);
}
void V8HeapExplorer::ExtractScript(HeapEntry* entry, Script* script) {
HeapObject* obj = script;
SetInternalReference(obj, entry,
"source", script->source(),
Script::kSourceOffset);
......@@ -2170,26 +2212,24 @@ void V8HeapExplorer::ExtractReferences(HeapObject* obj) {
SetInternalReference(obj, entry,
"line_ends", script->line_ends(),
Script::kLineEndsOffset);
} else if (obj->IsCodeCache()) {
CodeCache* code_cache = CodeCache::cast(obj);
}
void V8HeapExplorer::ExtractCodeCache(HeapEntry* entry, CodeCache* code_cache) {
TagObject(code_cache->default_cache(), "(default code cache)");
SetInternalReference(obj, entry,
SetInternalReference(code_cache, entry,
"default_cache", code_cache->default_cache(),
CodeCache::kDefaultCacheOffset);
TagObject(code_cache->normal_type_cache(), "(code type cache)");
SetInternalReference(obj, entry,
SetInternalReference(code_cache, entry,
"type_cache", code_cache->normal_type_cache(),
CodeCache::kNormalTypeCacheOffset);
} else if (obj->IsCode()) {
Code* code = Code::cast(obj);
}
void V8HeapExplorer::ExtractCode(HeapEntry* entry, Code* code) {
TagObject(code->unchecked_relocation_info(), "(code relocation info)");
TagObject(code->unchecked_deoptimization_data(), "(code deopt data)");
}
if (extract_indexed_refs) {
SetInternalReference(obj, entry, "map", obj->map(), HeapObject::kMapOffset);
IndexedReferencesExtractor refs_extractor(this, obj, entry);
obj->Iterate(&refs_extractor);
}
}
......
......@@ -975,7 +975,17 @@ class V8HeapExplorer : public HeapEntriesAllocator {
int children_count,
int retainers_count);
const char* GetSystemEntryName(HeapObject* object);
void ExtractReferences(HeapObject* obj);
void ExtractJSGlobalProxy(JSGlobalProxy* proxy);
void ExtractJSObject(HeapEntry* entry, JSObject* js_obj);
void ExtractString(HeapEntry* entry, String* obj);
void ExtractContext(HeapEntry* entry, Context* context);
void ExtractMap(HeapEntry* entry, Map* map);
void ExtractSharedFunctionInfo(HeapEntry* entry, SharedFunctionInfo* shared);
void ExtractScript(HeapEntry* entry, Script* script);
void ExtractCodeCache(HeapEntry* entry, CodeCache* code_cache);
void ExtractCode(HeapEntry* entry, Code* code);
void ExtractClosureReferences(JSObject* js_obj, HeapEntry* entry);
void ExtractPropertyReferences(JSObject* js_obj, HeapEntry* entry);
void ExtractElementReferences(JSObject* js_obj, HeapEntry* entry);
......
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