Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(148)

Side by Side Diff: tools/mkgrokdump.cc

Issue 2809653003: Introduce mkgrokdump to update tools/v8heapconst.py. (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 class MockArrayBufferAllocator : public v8::ArrayBuffer::Allocator {
29 public:
30 void* Allocate(size_t length) override { return nullptr; }
31 void* AllocateUninitialized(size_t length) override { return nullptr; }
32 void Free(void* p, size_t) override {}
33 };
34
35 static int DumpHeapConstants(const char* argv0) {
36 // Start up V8.
37 v8::Platform* platform = v8::platform::CreateDefaultPlatform();
38 v8::V8::InitializePlatform(platform);
39 v8::V8::Initialize();
40 v8::V8::InitializeExternalStartupData(argv0);
41 Isolate::CreateParams create_params;
42 MockArrayBufferAllocator mock_arraybuffer_allocator;
43 create_params.array_buffer_allocator = &mock_arraybuffer_allocator;
44 Isolate* isolate = Isolate::New(create_params);
45 {
46 Isolate::Scope scope(isolate);
47 i::Heap* heap = reinterpret_cast<i::Isolate*>(isolate)->heap();
48 printf("%s", kHeader);
49 #define DUMP_TYPE(T) printf(" %d: \"%s\",\n", i::T, #T);
50 printf("INSTANCE_TYPES = {\n");
51 INSTANCE_TYPE_LIST(DUMP_TYPE)
52 printf("}\n");
53 #undef DUMP_TYPE
54
55 // Dump the KNOWN_MAP table to the console.
56 printf("\n# List of known V8 maps.\n");
57 #define ROOT_LIST_CASE(type, name, camel_name) \
58 if (n == NULL && o == heap->name()) n = #camel_name;
59 #define STRUCT_LIST_CASE(upper_name, camel_name, name) \
60 if (n == NULL && o == heap->name##_map()) n = #camel_name "Map";
61 i::HeapObjectIterator it(heap->map_space());
62 printf("KNOWN_MAPS = {\n");
63 for (i::Object* o = it.Next(); o != NULL; o = it.Next()) {
64 i::Map* m = i::Map::cast(o);
65 const char* n = NULL;
66 intptr_t p = reinterpret_cast<intptr_t>(m) & 0x7ffff;
67 int t = m->instance_type();
68 ROOT_LIST(ROOT_LIST_CASE)
69 STRUCT_LIST(STRUCT_LIST_CASE)
70 if (n == NULL) continue;
71 printf(" 0x%05" V8PRIxPTR ": (%d, \"%s\"),\n", p, t, n);
72 }
73 printf("}\n");
74 #undef STRUCT_LIST_CASE
75 #undef ROOT_LIST_CASE
76
77 // Dump the KNOWN_OBJECTS table to the console.
78 printf("\n# List of known V8 objects.\n");
79 #define ROOT_LIST_CASE(type, name, camel_name) \
80 if (n == NULL && o == heap->name()) n = #camel_name;
81 i::OldSpaces spit(heap);
82 printf("KNOWN_OBJECTS = {\n");
83 for (i::PagedSpace* s = spit.next(); s != NULL; s = spit.next()) {
84 i::HeapObjectIterator it(s);
85 const char* sname = AllocationSpaceName(s->identity());
86 for (i::Object* o = it.Next(); o != NULL; o = it.Next()) {
87 const char* n = NULL;
88 intptr_t p = reinterpret_cast<intptr_t>(o) & 0x7ffff;
89 ROOT_LIST(ROOT_LIST_CASE)
90 if (n == NULL) continue;
91 printf(" (\"%s\", 0x%05" V8PRIxPTR "): \"%s\",\n", sname, p, n);
92 }
93 }
94 printf("}\n");
95 #undef ROOT_LIST_CASE
96
97 // Dump frame markers
98 printf("\n# List of known V8 Frame Markers.\n");
99 #define DUMP_MARKER(T, class) printf(" \"%s\",\n", #T);
100 printf("FRAME_MARKERS = (\n");
101 STACK_FRAME_TYPE_LIST(DUMP_MARKER)
102 printf(")\n");
103 #undef DUMP_TYPE
104 }
105 // Teardown.
106 isolate->Dispose();
107 v8::V8::ShutdownPlatform();
108 delete platform;
109 return 0;
110 }
111
112 } // namespace v8
113
114 int main(int argc, char* argv[]) { return v8::DumpHeapConstants(argv[0]); }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698