OLD | NEW |
(Empty) | |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include <stdio.h> |
| 6 |
| 7 #include "include/libplatform/libplatform.h" |
| 8 #include "include/v8.h" |
| 9 |
| 10 #include "src/frames.h" |
| 11 #include "src/heap/heap.h" |
| 12 #include "src/heap/spaces.h" |
| 13 #include "src/isolate.h" |
| 14 #include "src/objects-inl.h" |
| 15 |
| 16 namespace v8 { |
| 17 |
| 18 static const char* kHeader = |
| 19 "# Copyright 2017 the V8 project authors. All rights reserved.\n" |
| 20 "# Use of this source code is governed by a BSD-style license that can\n" |
| 21 "# be found in the LICENSE file.\n" |
| 22 "\n" |
| 23 "# This file is automatically generated by mkgrokdump and should not\n" |
| 24 "# be modified manually.\n" |
| 25 "\n" |
| 26 "# List of known V8 instance types.\n"; |
| 27 |
| 28 // Non-snapshot builds allocate objects to different places. |
| 29 // Debug builds emit debug code, affecting code object sizes. |
| 30 #if defined(V8_USE_SNAPSHOT) && !defined(DEBUG) |
| 31 static const char* kBuild = "shipping"; |
| 32 #else |
| 33 static const char* kBuild = "non-shipping"; |
| 34 #endif |
| 35 |
| 36 class MockArrayBufferAllocator : public v8::ArrayBuffer::Allocator { |
| 37 public: |
| 38 void* Allocate(size_t length) override { return nullptr; } |
| 39 void* AllocateUninitialized(size_t length) override { return nullptr; } |
| 40 void Free(void* p, size_t) override {} |
| 41 }; |
| 42 |
| 43 static int DumpHeapConstants(const char* argv0) { |
| 44 // Start up V8. |
| 45 v8::Platform* platform = v8::platform::CreateDefaultPlatform(); |
| 46 v8::V8::InitializePlatform(platform); |
| 47 v8::V8::Initialize(); |
| 48 v8::V8::InitializeExternalStartupData(argv0); |
| 49 Isolate::CreateParams create_params; |
| 50 MockArrayBufferAllocator mock_arraybuffer_allocator; |
| 51 create_params.array_buffer_allocator = &mock_arraybuffer_allocator; |
| 52 Isolate* isolate = Isolate::New(create_params); |
| 53 { |
| 54 Isolate::Scope scope(isolate); |
| 55 i::Heap* heap = reinterpret_cast<i::Isolate*>(isolate)->heap(); |
| 56 i::PrintF("%s", kHeader); |
| 57 #define DUMP_TYPE(T) i::PrintF(" %d: \"%s\",\n", i::T, #T); |
| 58 i::PrintF("INSTANCE_TYPES = {\n"); |
| 59 INSTANCE_TYPE_LIST(DUMP_TYPE) |
| 60 i::PrintF("}\n"); |
| 61 #undef DUMP_TYPE |
| 62 |
| 63 // Dump the KNOWN_MAP table to the console. |
| 64 i::PrintF("\n# List of known V8 maps.\n"); |
| 65 #define ROOT_LIST_CASE(type, name, camel_name) \ |
| 66 if (n == NULL && o == heap->name()) n = #camel_name; |
| 67 #define STRUCT_LIST_CASE(upper_name, camel_name, name) \ |
| 68 if (n == NULL && o == heap->name##_map()) n = #camel_name "Map"; |
| 69 i::HeapObjectIterator it(heap->map_space()); |
| 70 i::PrintF("KNOWN_MAPS = {\n"); |
| 71 for (i::Object* o = it.Next(); o != NULL; o = it.Next()) { |
| 72 i::Map* m = i::Map::cast(o); |
| 73 const char* n = NULL; |
| 74 intptr_t p = reinterpret_cast<intptr_t>(m) & 0x7ffff; |
| 75 int t = m->instance_type(); |
| 76 ROOT_LIST(ROOT_LIST_CASE) |
| 77 STRUCT_LIST(STRUCT_LIST_CASE) |
| 78 if (n == NULL) continue; |
| 79 i::PrintF(" 0x%05" V8PRIxPTR ": (%d, \"%s\"),\n", p, t, n); |
| 80 } |
| 81 i::PrintF("}\n"); |
| 82 #undef STRUCT_LIST_CASE |
| 83 #undef ROOT_LIST_CASE |
| 84 |
| 85 // Dump the KNOWN_OBJECTS table to the console. |
| 86 i::PrintF("\n# List of known V8 objects.\n"); |
| 87 #define ROOT_LIST_CASE(type, name, camel_name) \ |
| 88 if (n == NULL && o == heap->name()) { \ |
| 89 n = #camel_name; \ |
| 90 i = i::Heap::k##camel_name##RootIndex; \ |
| 91 } |
| 92 i::OldSpaces spit(heap); |
| 93 i::PrintF("KNOWN_OBJECTS = {\n"); |
| 94 for (i::PagedSpace* s = spit.next(); s != NULL; s = spit.next()) { |
| 95 i::HeapObjectIterator it(s); |
| 96 // Code objects are generally platform-dependent. |
| 97 if (s->identity() == i::CODE_SPACE) continue; |
| 98 const char* sname = AllocationSpaceName(s->identity()); |
| 99 for (i::Object* o = it.Next(); o != NULL; o = it.Next()) { |
| 100 const char* n = NULL; |
| 101 i::Heap::RootListIndex i = i::Heap::kStrongRootListLength; |
| 102 intptr_t p = reinterpret_cast<intptr_t>(o) & 0x7ffff; |
| 103 ROOT_LIST(ROOT_LIST_CASE) |
| 104 if (n == NULL) continue; |
| 105 if (!i::Heap::RootIsImmortalImmovable(i)) continue; |
| 106 i::PrintF(" (\"%s\", 0x%05" V8PRIxPTR "): \"%s\",\n", sname, p, n); |
| 107 } |
| 108 } |
| 109 i::PrintF("}\n"); |
| 110 #undef ROOT_LIST_CASE |
| 111 |
| 112 // Dump frame markers |
| 113 i::PrintF("\n# List of known V8 Frame Markers.\n"); |
| 114 #define DUMP_MARKER(T, class) i::PrintF(" \"%s\",\n", #T); |
| 115 i::PrintF("FRAME_MARKERS = (\n"); |
| 116 STACK_FRAME_TYPE_LIST(DUMP_MARKER) |
| 117 i::PrintF(")\n"); |
| 118 #undef DUMP_TYPE |
| 119 } |
| 120 |
| 121 i::PrintF("\n# This set of constants is generated from a %s build.\n", |
| 122 kBuild); |
| 123 |
| 124 // Teardown. |
| 125 isolate->Dispose(); |
| 126 v8::V8::ShutdownPlatform(); |
| 127 delete platform; |
| 128 return 0; |
| 129 } |
| 130 |
| 131 } // namespace v8 |
| 132 |
| 133 int main(int argc, char* argv[]) { return v8::DumpHeapConstants(argv[0]); } |
OLD | NEW |