Skip to content

Commit c106dfd

Browse files
Generate grokdump constants with 'make grokdump' now.
[email protected] Review URL: https://codereview.chromium.org/21771002 git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@16022 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
1 parent d79f445 commit c106dfd

File tree

6 files changed

+370
-257
lines changed

6 files changed

+370
-257
lines changed

Makefile

+8-1
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ endif
192192

193193
# ----------------- available targets: --------------------
194194
# - "dependencies": pulls in external dependencies (currently: GYP)
195+
# - "grokdump": rebuilds heap constants lists used by grokdump
195196
# - any arch listed in ARCHES (see below)
196197
# - any mode listed in MODES
197198
# - every combination <arch>.<mode>, e.g. "ia32.release"
@@ -392,7 +393,7 @@ endif
392393
# Replaces the old with the new environment file if they're different, which
393394
# will trigger GYP to regenerate Makefiles.
394395
$(ENVFILE): $(ENVFILE).new
395-
@if test -r $(ENVFILE) && cmp $(ENVFILE).new $(ENVFILE) >/dev/null; \
396+
@if test -r $(ENVFILE) && cmp $(ENVFILE).new $(ENVFILE) > /dev/null; \
396397
then rm $(ENVFILE).new; \
397398
else mv $(ENVFILE).new $(ENVFILE); fi
398399

@@ -401,6 +402,12 @@ $(ENVFILE).new:
401402
@mkdir -p $(OUTDIR); echo "GYPFLAGS=$(GYPFLAGS)" > $(ENVFILE).new; \
402403
echo "CXX=$(CXX)" >> $(ENVFILE).new
403404

405+
# Heap constants for grokdump.
406+
DUMP_FILE = tools/v8heapconst.py
407+
grokdump: ia32.release
408+
@cat $(DUMP_FILE).tmpl > $(DUMP_FILE)
409+
@$(OUTDIR)/ia32.release/d8 --dump-heap-constants >> $(DUMP_FILE)
410+
404411
# Dependencies.
405412
# Remember to keep these in sync with the DEPS file.
406413
dependencies:

src/d8.cc

+72
Original file line numberDiff line numberDiff line change
@@ -1406,6 +1406,14 @@ bool Shell::SetOptions(int argc, char* argv[]) {
14061406
#else
14071407
options.num_parallel_files++;
14081408
#endif // V8_SHARED
1409+
} else if (strcmp(argv[i], "--dump-heap-constants") == 0) {
1410+
#ifdef V8_SHARED
1411+
printf("D8 with shared library does not support constant dumping\n");
1412+
return false;
1413+
#else
1414+
options.dump_heap_constants = true;
1415+
argv[i] = NULL;
1416+
#endif
14091417
}
14101418
#ifdef V8_SHARED
14111419
else if (strcmp(argv[i], "--dump-counters") == 0) {
@@ -1560,6 +1568,63 @@ static void SetStandaloneFlagsViaCommandLine() {
15601568
#endif
15611569

15621570

1571+
#ifndef V8_SHARED
1572+
static void DumpHeapConstants(i::Isolate* isolate) {
1573+
i::Heap* heap = isolate->heap();
1574+
1575+
// Dump the INSTANCE_TYPES table to the console.
1576+
printf("# List of known V8 instance types.\n");
1577+
#define DUMP_TYPE(T) printf(" %d: \"%s\",\n", i::T, #T);
1578+
printf("INSTANCE_TYPES = {\n");
1579+
INSTANCE_TYPE_LIST(DUMP_TYPE)
1580+
printf("}\n");
1581+
#undef DUMP_TYPE
1582+
1583+
// Dump the KNOWN_MAP table to the console.
1584+
printf("\n# List of known V8 maps.\n");
1585+
#define ROOT_LIST_CASE(type, name, camel_name) \
1586+
if (o == heap->name()) n = #camel_name;
1587+
#define STRUCT_LIST_CASE(upper_name, camel_name, name) \
1588+
if (o == heap->name##_map()) n = #camel_name "Map";
1589+
i::HeapObjectIterator it(heap->map_space());
1590+
printf("KNOWN_MAPS = {\n");
1591+
for (i::Object* o = it.Next(); o != NULL; o = it.Next()) {
1592+
i::Map* m = i::Map::cast(o);
1593+
const char* n = NULL;
1594+
intptr_t p = reinterpret_cast<intptr_t>(m) & 0xfffff;
1595+
int t = m->instance_type();
1596+
ROOT_LIST(ROOT_LIST_CASE)
1597+
STRUCT_LIST(STRUCT_LIST_CASE)
1598+
if (n == NULL) continue;
1599+
printf(" 0x%05" V8_PTR_PREFIX "x: (%d, \"%s\"),\n", p, t, n);
1600+
}
1601+
printf("}\n");
1602+
#undef STRUCT_LIST_CASE
1603+
#undef ROOT_LIST_CASE
1604+
1605+
// Dump the KNOWN_OBJECTS table to the console.
1606+
printf("\n# List of known V8 objects.\n");
1607+
#define ROOT_LIST_CASE(type, name, camel_name) \
1608+
if (o == heap->name()) n = #camel_name;
1609+
i::OldSpaces spit(heap);
1610+
printf("KNOWN_OBJECTS = {\n");
1611+
for (i::PagedSpace* s = spit.next(); s != NULL; s = spit.next()) {
1612+
i::HeapObjectIterator it(s);
1613+
const char* sname = AllocationSpaceName(s->identity());
1614+
for (i::Object* o = it.Next(); o != NULL; o = it.Next()) {
1615+
const char* n = NULL;
1616+
intptr_t p = reinterpret_cast<intptr_t>(o) & 0xfffff;
1617+
ROOT_LIST(ROOT_LIST_CASE)
1618+
if (n == NULL) continue;
1619+
printf(" (\"%s\", 0x%05" V8_PTR_PREFIX "x): \"%s\",\n", sname, p, n);
1620+
}
1621+
}
1622+
printf("}\n");
1623+
#undef ROOT_LIST_CASE
1624+
}
1625+
#endif // V8_SHARED
1626+
1627+
15631628
class ShellArrayBufferAllocator : public v8::ArrayBuffer::Allocator {
15641629
public:
15651630
virtual void* Allocate(size_t length) {
@@ -1597,6 +1662,13 @@ int Shell::Main(int argc, char* argv[]) {
15971662
PerIsolateData data(isolate);
15981663
InitializeDebugger(isolate);
15991664

1665+
#ifndef V8_SHARED
1666+
if (options.dump_heap_constants) {
1667+
DumpHeapConstants(reinterpret_cast<i::Isolate*>(isolate));
1668+
return 0;
1669+
}
1670+
#endif
1671+
16001672
if (options.stress_opt || options.stress_deopt) {
16011673
Testing::SetStressRunType(options.stress_opt
16021674
? Testing::kStressTypeOpt

src/d8.h

+2
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ class ShellOptions {
231231
stress_deopt(false),
232232
interactive_shell(false),
233233
test_shell(false),
234+
dump_heap_constants(false),
234235
num_isolates(1),
235236
isolate_sources(NULL) { }
236237

@@ -254,6 +255,7 @@ class ShellOptions {
254255
bool stress_deopt;
255256
bool interactive_shell;
256257
bool test_shell;
258+
bool dump_heap_constants;
257259
int num_isolates;
258260
SourceGroup* isolate_sources;
259261
};

0 commit comments

Comments
 (0)