Commit d6daf8b0 authored by Michael Lippautz's avatar Michael Lippautz Committed by Commit Bot

[object-stats] Record details for BytecodeArray and Code

FixedArrays hanging off recursively of the constant pool without any
real objects in between can be considered as meta data. They are shared
with optimized code (embedder pointers).

Bug: v8:7266
Change-Id: I4006675e17e8eea3bdc8565254d80e2ffece0ad0
Reviewed-on: https://chromium-review.googlesource.com/883361Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Commit-Queue: Michael Lippautz <mlippautz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#50837}
parent 3b7f2738
......@@ -214,11 +214,11 @@ class ObjectStatsCollectorImpl {
kIgnoreCow,
};
void RecordVirtualObjectStats(HeapObject* parent, HeapObject* obj,
bool RecordVirtualObjectStats(HeapObject* parent, HeapObject* obj,
ObjectStats::VirtualInstanceType type,
size_t size, size_t over_allocated);
// Gets size from |ob| and assumes no over allocating.
void RecordSimpleVirtualObjectStats(HeapObject* parent, HeapObject* obj,
bool RecordSimpleVirtualObjectStats(HeapObject* parent, HeapObject* obj,
ObjectStats::VirtualInstanceType type);
// For HashTable it is possible to compute over allocated memory.
void RecordHashTableVirtualObjectStats(HeapObject* parent,
......@@ -236,6 +236,12 @@ class ObjectStatsCollectorImpl {
void RecordObjectStats(HeapObject* obj, InstanceType type, size_t size);
// Specific recursion into constant pool or embedded code objects. Records
// FixedArrays and Tuple2 that look like ConstantElementsPair.
void RecordVirtualObjectsForConstantPoolOrEmbeddedObjects(
HeapObject* parent, HeapObject* object,
ObjectStats::VirtualInstanceType type);
// Details.
void RecordVirtualAllocationSiteDetails(AllocationSite* site);
void RecordVirtualBytecodeArrayDetails(BytecodeArray* bytecode);
......@@ -283,22 +289,25 @@ void ObjectStatsCollectorImpl::RecordHashTableVirtualObjectStats(
ObjectStats::kNoOverAllocation);
}
void ObjectStatsCollectorImpl::RecordSimpleVirtualObjectStats(
bool ObjectStatsCollectorImpl::RecordSimpleVirtualObjectStats(
HeapObject* parent, HeapObject* obj,
ObjectStats::VirtualInstanceType type) {
RecordVirtualObjectStats(parent, obj, type, obj->Size(),
ObjectStats::kNoOverAllocation);
return RecordVirtualObjectStats(parent, obj, type, obj->Size(),
ObjectStats::kNoOverAllocation);
}
void ObjectStatsCollectorImpl::RecordVirtualObjectStats(
bool ObjectStatsCollectorImpl::RecordVirtualObjectStats(
HeapObject* parent, HeapObject* obj, ObjectStats::VirtualInstanceType type,
size_t size, size_t over_allocated) {
if (!SameLiveness(parent, obj) || !ShouldRecordObject(obj, kCheckCow)) return;
if (!SameLiveness(parent, obj) || !ShouldRecordObject(obj, kCheckCow))
return false;
if (virtual_objects_.find(obj) == virtual_objects_.end()) {
virtual_objects_.insert(obj);
stats_->RecordVirtualObjectStats(type, size, over_allocated);
return true;
}
return false;
}
void ObjectStatsCollectorImpl::RecordVirtualAllocationSiteDetails(
......@@ -559,11 +568,53 @@ void ObjectStatsCollectorImpl::RecordVirtualSharedFunctionInfoDetails(
ObjectStats::SCOPE_INFO_TYPE);
}
namespace {
bool MatchesConstantElementsPair(Object* object) {
if (!object->IsTuple2()) return false;
Tuple2* tuple = Tuple2::cast(object);
return tuple->value1()->IsSmi() && tuple->value2()->IsFixedArray();
}
} // namespace
void ObjectStatsCollectorImpl::
RecordVirtualObjectsForConstantPoolOrEmbeddedObjects(
HeapObject* parent, HeapObject* object,
ObjectStats::VirtualInstanceType type) {
if (RecordSimpleVirtualObjectStats(parent, object, type)) {
if (object->IsFixedArray()) {
FixedArray* array = FixedArray::cast(object);
for (int i = 0; i < array->length(); i++) {
Object* entry = array->get(i);
if (!entry->IsHeapObject()) continue;
RecordVirtualObjectsForConstantPoolOrEmbeddedObjects(
array, HeapObject::cast(entry), type);
}
} else if (MatchesConstantElementsPair(object)) {
Tuple2* tuple = Tuple2::cast(object);
RecordVirtualObjectsForConstantPoolOrEmbeddedObjects(
tuple, HeapObject::cast(tuple->value2()), type);
}
}
}
void ObjectStatsCollectorImpl::RecordVirtualBytecodeArrayDetails(
BytecodeArray* bytecode) {
RecordSimpleVirtualObjectStats(
bytecode, bytecode->constant_pool(),
ObjectStats::BYTECODE_ARRAY_CONSTANT_POOL_TYPE);
// FixedArrays on constant pool are used for holding descriptor information.
// They are shared with optimized code.
FixedArray* constant_pool = FixedArray::cast(bytecode->constant_pool());
for (int i = 0; i < constant_pool->length(); i++) {
Object* entry = constant_pool->get(i);
if (entry->IsFixedArray() || MatchesConstantElementsPair(entry)) {
RecordVirtualObjectsForConstantPoolOrEmbeddedObjects(
constant_pool, HeapObject::cast(entry),
ObjectStats::EMBEDDED_OBJECT_TYPE);
}
}
RecordSimpleVirtualObjectStats(
bytecode, bytecode->handler_table(),
ObjectStats::BYTECODE_ARRAY_HANDLER_TABLE_TYPE);
......@@ -588,9 +639,30 @@ ObjectStats::VirtualInstanceType CodeKindToVirtualInstanceType(
} // namespace
void ObjectStatsCollectorImpl::RecordVirtualCodeDetails(Code* code) {
RecordVirtualObjectStats(nullptr, code,
CodeKindToVirtualInstanceType(code->kind()),
code->Size(), 0);
RecordSimpleVirtualObjectStats(nullptr, code,
CodeKindToVirtualInstanceType(code->kind()));
RecordSimpleVirtualObjectStats(code, code->deoptimization_data(),
ObjectStats::DEOPTIMIZATION_DATA_TYPE);
if (code->kind() == Code::Kind::OPTIMIZED_FUNCTION) {
DeoptimizationData* input_data =
DeoptimizationData::cast(code->deoptimization_data());
if (input_data->length() > 0) {
RecordSimpleVirtualObjectStats(code->deoptimization_data(),
input_data->LiteralArray(),
ObjectStats::OPTIMIZED_CODE_LITERALS_TYPE);
}
}
int const mode_mask = RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT);
for (RelocIterator it(code, mode_mask); !it.done(); it.next()) {
RelocInfo::Mode mode = it.rinfo()->rmode();
if (mode == RelocInfo::EMBEDDED_OBJECT) {
Object* target = it.rinfo()->target_object();
if (target->IsFixedArray() || MatchesConstantElementsPair(target)) {
RecordVirtualObjectsForConstantPoolOrEmbeddedObjects(
code, HeapObject::cast(target), ObjectStats::EMBEDDED_OBJECT_TYPE);
}
}
}
}
void ObjectStatsCollectorImpl::RecordVirtualContext(Context* context) {
......
......@@ -5,10 +5,6 @@
#ifndef V8_HEAP_OBJECT_STATS_H_
#define V8_HEAP_OBJECT_STATS_H_
#include <set>
#include "src/base/ieee754.h"
#include "src/heap/objects-visiting.h"
#include "src/objects.h"
#include "src/objects/code.h"
......@@ -27,8 +23,10 @@
V(BYTECODE_ARRAY_HANDLER_TABLE_TYPE) \
V(CODE_STUBS_TABLE_TYPE) \
V(COW_ARRAY_TYPE) \
V(DEOPTIMIZATION_DATA_TYPE) \
V(DEPENDENT_CODE_TYPE) \
V(ELEMENTS_TYPE) \
V(EMBEDDED_OBJECT_TYPE) \
V(ENUM_CACHE_TYPE) \
V(ENUM_INDICES_CACHE_TYPE) \
V(FEEDBACK_VECTOR_ENTRY_TYPE) \
......@@ -43,6 +41,7 @@
V(NUMBER_STRING_CACHE_TYPE) \
V(OBJECT_PROPERTY_DICTIONARY_TYPE) \
V(OBJECT_TO_CODE_TYPE) \
V(OPTIMIZED_CODE_LITERALS_TYPE) \
V(OTHER_CONTEXT_TYPE) \
V(PROTOTYPE_USERS_TYPE) \
V(REGEXP_MULTIPLE_CACHE_TYPE) \
......
......@@ -136,10 +136,13 @@ const CATEGORIES = new Map([
'BYTECODE_ARRAY_HANDLER_TABLE_TYPE',
'BYTECODE_ARRAY_TYPE',
'CODE_DATA_CONTAINER_TYPE',
'DEOPTIMIZATION_DATA_TYPE',
'EMBEDDED_OBJECT_TYPE',
'FEEDBACK_VECTOR_ENTRY_TYPE',
'FEEDBACK_VECTOR_TYPE',
'LOAD_HANDLER_TYPE',
'NOSCRIPT_SHARED_FUNCTION_INFOS_TYPE',
'OPTIMIZED_CODE_LITERALS_TYPE',
'SCRIPT_TYPE',
'SHARED_FUNCTION_INFO_TYPE',
'STORE_HANDLER_TYPE',
......
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