Commit f51e1d92 authored by Peter Marshall's avatar Peter Marshall Committed by Commit Bot

[cleanup] Reduce code size in heap snapshot generator.

This reduces the usage of macros and shrinks the binary size (by 4 KiB).

Bug: v8:8238
Change-Id: Ic689f8ce7dabe481125fcdb74a265155431317b6
Reviewed-on: https://chromium-review.googlesource.com/1253605Reviewed-by: 's avatarYang Guo <yangguo@chromium.org>
Commit-Queue: Peter Marshall <petermarshall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#56316}
parent 6cb0a014
......@@ -1040,6 +1040,22 @@ void V8HeapExplorer::ExtractEphemeronHashTableReferences(
}
}
// These static arrays are used to prevent excessive code-size in
// ExtractContextReferences below, which would happen if we called
// SetInternalReference for every native context field in a macro.
static const int native_context_indices[] = {
#define CONTEXT_FIELD_INDEX(index, ...) Context::index,
NATIVE_CONTEXT_FIELDS(CONTEXT_FIELD_INDEX)
#undef CONTEXT_FIELD_INDEX
};
static const char* native_context_names[] = {
#define CONTEXT_FIELD_NAME(index, _, name) #name,
NATIVE_CONTEXT_FIELDS(CONTEXT_FIELD_NAME)
#undef CONTEXT_FIELD_NAME
};
STATIC_ASSERT(arraysize(native_context_indices) ==
arraysize(native_context_names));
void V8HeapExplorer::ExtractContextReferences(int entry, Context* context) {
if (!context->IsNativeContext() && context->is_declaration_context()) {
ScopeInfo* scope_info = context->scope_info();
......@@ -1061,26 +1077,38 @@ void V8HeapExplorer::ExtractContextReferences(int entry, Context* context) {
}
}
#define EXTRACT_CONTEXT_FIELD(index, type, name) \
if (Context::index < Context::FIRST_WEAK_SLOT || \
Context::index == Context::MAP_CACHE_INDEX) { \
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)); \
}
EXTRACT_CONTEXT_FIELD(SCOPE_INFO_INDEX, ScopeInfo, scope_info);
EXTRACT_CONTEXT_FIELD(PREVIOUS_INDEX, Context, previous);
EXTRACT_CONTEXT_FIELD(EXTENSION_INDEX, HeapObject, extension);
EXTRACT_CONTEXT_FIELD(NATIVE_CONTEXT_INDEX, Context, native_context);
SetInternalReference(
context, entry, "scope_info", context->get(Context::SCOPE_INFO_INDEX),
FixedArray::OffsetOfElementAt(Context::SCOPE_INFO_INDEX));
SetInternalReference(context, entry, "previous",
context->get(Context::PREVIOUS_INDEX),
FixedArray::OffsetOfElementAt(Context::PREVIOUS_INDEX));
SetInternalReference(context, entry, "extension",
context->get(Context::EXTENSION_INDEX),
FixedArray::OffsetOfElementAt(Context::EXTENSION_INDEX));
SetInternalReference(
context, entry, "native_context",
context->get(Context::NATIVE_CONTEXT_INDEX),
FixedArray::OffsetOfElementAt(Context::NATIVE_CONTEXT_INDEX));
if (context->IsNativeContext()) {
TagObject(context->normalized_map_cache(), "(context norm. map cache)");
TagObject(context->embedder_data(), "(context data)");
NATIVE_CONTEXT_FIELDS(EXTRACT_CONTEXT_FIELD)
EXTRACT_CONTEXT_FIELD(OPTIMIZED_CODE_LIST, unused, optimized_code_list);
EXTRACT_CONTEXT_FIELD(DEOPTIMIZED_CODE_LIST, unused, deoptimized_code_list);
#undef EXTRACT_CONTEXT_FIELD
for (size_t i = 0; i < arraysize(native_context_indices); i++) {
int index = native_context_indices[i];
const char* name = native_context_names[i];
SetInternalReference(context, entry, name, context->get(index),
FixedArray::OffsetOfElementAt(index));
}
SetWeakReference(
context, entry, "optimized_code_list",
context->get(Context::OPTIMIZED_CODE_LIST),
FixedArray::OffsetOfElementAt(Context::OPTIMIZED_CODE_LIST));
SetWeakReference(
context, entry, "deoptimized_code_list",
context->get(Context::DEOPTIMIZED_CODE_LIST),
FixedArray::OffsetOfElementAt(Context::DEOPTIMIZED_CODE_LIST));
STATIC_ASSERT(Context::OPTIMIZED_CODE_LIST == Context::FIRST_WEAK_SLOT);
STATIC_ASSERT(Context::NEXT_CONTEXT_LINK + 1 ==
Context::NATIVE_CONTEXT_SLOTS);
......@@ -1089,7 +1117,6 @@ void V8HeapExplorer::ExtractContextReferences(int entry, Context* context) {
}
}
void V8HeapExplorer::ExtractMapReferences(int entry, Map* map) {
MaybeObject* maybe_raw_transitions_or_prototype_info = map->raw_transitions();
HeapObject* raw_transitions_or_prototype_info;
......
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