2017-04-20 06:14:53 +00:00
|
|
|
// Copyright 2012 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "include/libplatform/libplatform.h"
|
|
|
|
#include "include/v8.h"
|
|
|
|
|
2019-05-22 07:55:37 +00:00
|
|
|
#include "src/execution/frames.h"
|
|
|
|
#include "src/execution/isolate.h"
|
2019-02-14 21:10:30 +00:00
|
|
|
#include "src/heap/heap-inl.h"
|
2019-05-02 15:35:51 +00:00
|
|
|
#include "src/heap/read-only-heap.h"
|
2017-04-20 06:14:53 +00:00
|
|
|
#include "src/heap/spaces.h"
|
2019-05-23 08:51:46 +00:00
|
|
|
#include "src/objects/objects-inl.h"
|
2017-04-20 06:14:53 +00:00
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
|
|
|
|
static const char* kHeader =
|
2019-02-14 10:00:15 +00:00
|
|
|
"# Copyright 2019 the V8 project authors. All rights reserved.\n"
|
2017-04-20 06:14:53 +00:00
|
|
|
"# Use of this source code is governed by a BSD-style license that can\n"
|
|
|
|
"# be found in the LICENSE file.\n"
|
|
|
|
"\n"
|
|
|
|
"# This file is automatically generated by mkgrokdump and should not\n"
|
|
|
|
"# be modified manually.\n"
|
|
|
|
"\n"
|
|
|
|
"# List of known V8 instance types.\n";
|
|
|
|
|
|
|
|
// Non-snapshot builds allocate objects to different places.
|
|
|
|
// Debug builds emit debug code, affecting code object sizes.
|
2018-04-11 08:09:36 +00:00
|
|
|
// Embedded builtins cause objects to be allocated in different locations.
|
2018-06-05 09:47:16 +00:00
|
|
|
#if defined(V8_EMBEDDED_BUILTINS) && defined(V8_USE_SNAPSHOT) && !defined(DEBUG)
|
2017-04-20 06:14:53 +00:00
|
|
|
static const char* kBuild = "shipping";
|
|
|
|
#else
|
|
|
|
static const char* kBuild = "non-shipping";
|
|
|
|
#endif
|
|
|
|
|
|
|
|
class MockArrayBufferAllocator : public v8::ArrayBuffer::Allocator {
|
|
|
|
public:
|
|
|
|
void* Allocate(size_t length) override { return nullptr; }
|
|
|
|
void* AllocateUninitialized(size_t length) override { return nullptr; }
|
|
|
|
void Free(void* p, size_t) override {}
|
|
|
|
};
|
|
|
|
|
2019-05-21 15:46:26 +00:00
|
|
|
static void DumpKnownMap(i::Heap* heap, const char* space_name,
|
|
|
|
i::HeapObject object) {
|
2018-09-21 12:57:10 +00:00
|
|
|
#define RO_ROOT_LIST_CASE(type, name, CamelName) \
|
2019-05-21 15:46:26 +00:00
|
|
|
if (root_name == nullptr && object == roots.name()) root_name = #CamelName;
|
2018-09-24 10:37:57 +00:00
|
|
|
#define MUTABLE_ROOT_LIST_CASE(type, name, CamelName) \
|
2019-05-21 15:46:26 +00:00
|
|
|
if (root_name == nullptr && object == heap->name()) root_name = #CamelName;
|
|
|
|
|
|
|
|
i::ReadOnlyRoots roots(heap);
|
|
|
|
const char* root_name = nullptr;
|
|
|
|
i::Map map = i::Map::cast(object);
|
|
|
|
intptr_t root_ptr =
|
|
|
|
static_cast<intptr_t>(map.ptr()) & (i::Page::kPageSize - 1);
|
|
|
|
|
|
|
|
READ_ONLY_ROOT_LIST(RO_ROOT_LIST_CASE)
|
|
|
|
MUTABLE_ROOT_LIST(MUTABLE_ROOT_LIST_CASE)
|
|
|
|
|
|
|
|
if (root_name == nullptr) return;
|
|
|
|
i::PrintF(" (\"%s\", 0x%05" V8PRIxPTR "): (%d, \"%s\"),\n", space_name,
|
2019-05-23 07:47:44 +00:00
|
|
|
root_ptr, map.instance_type(), root_name);
|
2019-05-21 15:46:26 +00:00
|
|
|
|
2018-09-24 10:37:57 +00:00
|
|
|
#undef MUTABLE_ROOT_LIST_CASE
|
2018-07-03 14:27:16 +00:00
|
|
|
#undef RO_ROOT_LIST_CASE
|
2019-05-21 15:46:26 +00:00
|
|
|
}
|
2018-03-27 15:25:01 +00:00
|
|
|
|
2019-05-02 15:35:51 +00:00
|
|
|
static void DumpKnownObject(i::Heap* heap, const char* space_name,
|
|
|
|
i::HeapObject object) {
|
2019-05-21 15:46:26 +00:00
|
|
|
#define RO_ROOT_LIST_CASE(type, name, CamelName) \
|
|
|
|
if (root_name == nullptr && object == roots.name()) { \
|
|
|
|
root_name = #CamelName; \
|
|
|
|
root_index = i::RootIndex::k##CamelName; \
|
2019-05-02 15:35:51 +00:00
|
|
|
}
|
2019-05-21 15:46:26 +00:00
|
|
|
#define ROOT_LIST_CASE(type, name, CamelName) \
|
|
|
|
if (root_name == nullptr && object == heap->name()) { \
|
|
|
|
root_name = #CamelName; \
|
|
|
|
root_index = i::RootIndex::k##CamelName; \
|
2019-05-02 15:35:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
i::ReadOnlyRoots roots(heap);
|
|
|
|
const char* root_name = nullptr;
|
|
|
|
i::RootIndex root_index = i::RootIndex::kFirstSmiRoot;
|
|
|
|
intptr_t root_ptr = object.ptr() & (i::Page::kPageSize - 1);
|
|
|
|
|
|
|
|
STRONG_READ_ONLY_ROOT_LIST(RO_ROOT_LIST_CASE)
|
|
|
|
MUTABLE_ROOT_LIST(ROOT_LIST_CASE)
|
|
|
|
|
|
|
|
if (root_name == nullptr) return;
|
|
|
|
if (!i::RootsTable::IsImmortalImmovable(root_index)) return;
|
|
|
|
|
|
|
|
i::PrintF(" (\"%s\", 0x%05" V8PRIxPTR "): \"%s\",\n", space_name, root_ptr,
|
|
|
|
root_name);
|
|
|
|
|
|
|
|
#undef ROOT_LIST_CASE
|
|
|
|
#undef RO_ROOT_LIST_CASE
|
|
|
|
}
|
|
|
|
|
2017-04-20 06:14:53 +00:00
|
|
|
static int DumpHeapConstants(const char* argv0) {
|
|
|
|
// Start up V8.
|
2017-11-13 13:16:49 +00:00
|
|
|
std::unique_ptr<v8::Platform> platform = v8::platform::NewDefaultPlatform();
|
|
|
|
v8::V8::InitializePlatform(platform.get());
|
2017-04-20 06:14:53 +00:00
|
|
|
v8::V8::Initialize();
|
|
|
|
v8::V8::InitializeExternalStartupData(argv0);
|
|
|
|
Isolate::CreateParams create_params;
|
|
|
|
MockArrayBufferAllocator mock_arraybuffer_allocator;
|
|
|
|
create_params.array_buffer_allocator = &mock_arraybuffer_allocator;
|
|
|
|
Isolate* isolate = Isolate::New(create_params);
|
|
|
|
{
|
|
|
|
Isolate::Scope scope(isolate);
|
|
|
|
i::Heap* heap = reinterpret_cast<i::Isolate*>(isolate)->heap();
|
|
|
|
i::PrintF("%s", kHeader);
|
|
|
|
#define DUMP_TYPE(T) i::PrintF(" %d: \"%s\",\n", i::T, #T);
|
|
|
|
i::PrintF("INSTANCE_TYPES = {\n");
|
|
|
|
INSTANCE_TYPE_LIST(DUMP_TYPE)
|
|
|
|
i::PrintF("}\n");
|
|
|
|
#undef DUMP_TYPE
|
|
|
|
|
2019-05-21 15:46:26 +00:00
|
|
|
{
|
|
|
|
// Dump the KNOWN_MAP table to the console.
|
|
|
|
i::PrintF("\n# List of known V8 maps.\n");
|
|
|
|
i::PrintF("KNOWN_MAPS = {\n");
|
2019-06-13 10:51:22 +00:00
|
|
|
i::ReadOnlyHeapObjectIterator ro_iterator(heap->read_only_heap());
|
2019-05-21 15:46:26 +00:00
|
|
|
for (i::HeapObject object = ro_iterator.Next(); !object.is_null();
|
|
|
|
object = ro_iterator.Next()) {
|
2019-05-23 07:47:44 +00:00
|
|
|
if (!object.IsMap()) continue;
|
2019-05-21 15:46:26 +00:00
|
|
|
DumpKnownMap(heap, i::Heap::GetSpaceName(i::RO_SPACE), object);
|
|
|
|
}
|
2019-06-13 10:51:22 +00:00
|
|
|
i::PagedSpaceObjectIterator iterator(heap->map_space());
|
2019-05-21 15:46:26 +00:00
|
|
|
for (i::HeapObject object = iterator.Next(); !object.is_null();
|
|
|
|
object = iterator.Next()) {
|
2019-05-23 07:47:44 +00:00
|
|
|
if (!object.IsMap()) continue;
|
2019-05-21 15:46:26 +00:00
|
|
|
DumpKnownMap(heap, i::Heap::GetSpaceName(i::MAP_SPACE), object);
|
|
|
|
}
|
|
|
|
i::PrintF("}\n");
|
2019-05-02 15:35:51 +00:00
|
|
|
}
|
|
|
|
|
2019-05-21 15:46:26 +00:00
|
|
|
{
|
|
|
|
// Dump the KNOWN_OBJECTS table to the console.
|
|
|
|
i::PrintF("\n# List of known V8 objects.\n");
|
|
|
|
i::PrintF("KNOWN_OBJECTS = {\n");
|
2019-06-13 10:51:22 +00:00
|
|
|
i::ReadOnlyHeapObjectIterator ro_iterator(heap->read_only_heap());
|
2019-05-21 15:46:26 +00:00
|
|
|
for (i::HeapObject object = ro_iterator.Next(); !object.is_null();
|
|
|
|
object = ro_iterator.Next()) {
|
|
|
|
// Skip read-only heap maps, they will be reported elsewhere.
|
2019-05-23 07:47:44 +00:00
|
|
|
if (object.IsMap()) continue;
|
2019-05-21 15:46:26 +00:00
|
|
|
DumpKnownObject(heap, i::Heap::GetSpaceName(i::RO_SPACE), object);
|
|
|
|
}
|
|
|
|
|
2019-06-13 10:51:22 +00:00
|
|
|
i::PagedSpaceIterator spit(heap);
|
2019-05-31 10:59:12 +00:00
|
|
|
for (i::PagedSpace* s = spit.Next(); s != nullptr; s = spit.Next()) {
|
2019-06-13 10:51:22 +00:00
|
|
|
i::PagedSpaceObjectIterator it(s);
|
2019-05-21 15:46:26 +00:00
|
|
|
// Code objects are generally platform-dependent.
|
|
|
|
if (s->identity() == i::CODE_SPACE || s->identity() == i::MAP_SPACE)
|
|
|
|
continue;
|
|
|
|
const char* sname = s->name();
|
|
|
|
for (i::HeapObject o = it.Next(); !o.is_null(); o = it.Next()) {
|
|
|
|
DumpKnownObject(heap, sname, o);
|
|
|
|
}
|
2017-04-20 06:14:53 +00:00
|
|
|
}
|
2019-05-21 15:46:26 +00:00
|
|
|
i::PrintF("}\n");
|
2017-04-20 06:14:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Dump frame markers
|
|
|
|
i::PrintF("\n# List of known V8 Frame Markers.\n");
|
|
|
|
#define DUMP_MARKER(T, class) i::PrintF(" \"%s\",\n", #T);
|
|
|
|
i::PrintF("FRAME_MARKERS = (\n");
|
|
|
|
STACK_FRAME_TYPE_LIST(DUMP_MARKER)
|
|
|
|
i::PrintF(")\n");
|
2018-03-27 15:25:01 +00:00
|
|
|
#undef DUMP_MARKER
|
2017-04-20 06:14:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
i::PrintF("\n# This set of constants is generated from a %s build.\n",
|
|
|
|
kBuild);
|
|
|
|
|
|
|
|
// Teardown.
|
|
|
|
isolate->Dispose();
|
|
|
|
v8::V8::ShutdownPlatform();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace v8
|
|
|
|
|
|
|
|
int main(int argc, char* argv[]) { return v8::DumpHeapConstants(argv[0]); }
|