From 747e7b037134eabe7af4ec3404cd02bc5b4b9604 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Sat, 18 Aug 2007 16:42:11 -0600 Subject: [PATCH] set minimum value for initial nextGen2 capacity; profile support --- makefile | 19 ++++++++++++++++--- src/heap.cpp | 25 +++++++++++++++++++------ 2 files changed, 35 insertions(+), 9 deletions(-) diff --git a/makefile b/makefile index 49dcb44027..9489c6ebdb 100644 --- a/makefile +++ b/makefile @@ -17,7 +17,7 @@ classpath = classpath test = test jscheme = /tmp/jscheme -input = $(cls)/GC.class +input = $(cls)/References.class cxx = g++ cc = gcc @@ -34,6 +34,8 @@ thread-lflags = -lpthread cflags = $(warnings) -fPIC -fno-rtti -fno-exceptions -fvisibility=hidden \ -I$(src) -I$(bld) $(thread-cflags) -D__STDC_LIMIT_MACROS +lflags = $(thread-lflags) -ldl -lm + ifeq ($(mode),debug) cflags += -O0 -g3 endif @@ -46,8 +48,10 @@ endif ifeq ($(mode),fast) cflags += -Os -DNDEBUG -DMONOLITHIC endif - -lflags = $(thread-lflags) -ldl -lm +ifeq ($(mode),profile) +cflags += -Os -pg -DNDEBUG -DMONOLITHIC +lflags += -pg +endif cpp-objects = $(foreach x,$(1),$(patsubst $(2)/%.cpp,$(bld)/%.o,$(x))) asm-objects = $(foreach x,$(1),$(patsubst $(2)/%.S,$(bld)/%.o,$(x))) @@ -141,6 +145,10 @@ $(input): $(classpath-objects) run: $(executable) $(input) LD_LIBRARY_PATH=$(bld) $(<) $(args) +.PHONY: run-jscheme +run-jscheme: $(executable) $(input) + LD_LIBRARY_PATH=$(bld) $(<) -cp $(cls):$(jscheme) jscheme/REPL + .PHONY: debug debug: $(executable) $(input) LD_LIBRARY_PATH=$(bld) gdb --args $(<) $(args) @@ -159,6 +167,11 @@ vg-jscheme: $(executable) $(input) LD_LIBRARY_PATH=$(bld) $(vg) $(<) -cp $(cls):$(jscheme) \ jscheme/REPL +.PHONY: profile-jscheme +profile-jscheme: $(executable) $(input) + echo '(+ 5 6)' | LD_LIBRARY_PATH=$(bld) $(<) -cp $(cls):$(jscheme) \ + jscheme/REPL + .PHONY: test test: $(executable) $(classpath-objects) $(test-classes) LD_LIBRARY_PATH=$(bld) /bin/bash $(test)/test.sh \ diff --git a/src/heap.cpp b/src/heap.cpp index e5accd0d38..9668ff95b1 100644 --- a/src/heap.cpp +++ b/src/heap.cpp @@ -12,7 +12,10 @@ const unsigned TenureThreshold = 3; const unsigned Top = ~static_cast(0); +const unsigned InitialGen2CapacityInBytes = 4 * 1024 * 1024; + const bool Verbose = true; +const bool Verbose2 = false; const bool Debug = false; class Context; @@ -285,7 +288,6 @@ class Segment { map(map) { if (desired) { - assert(context, minimum > 0); assert(context, desired >= minimum); capacity_ = desired; @@ -297,6 +299,9 @@ class Segment { if (data == 0) { if (capacity_ > minimum) { capacity_ = avg(minimum, capacity_); + if (capacity_ == 0) { + break; + } } else { abort(context); } @@ -489,7 +494,7 @@ initNextGen1(Context* c, unsigned footprint) new (&(c->nextGen1)) Segment(c, &(c->nextAgeMap), desired, minimum); - if (Verbose) { + if (Verbose2) { fprintf(stderr, "init nextGen1 to %d bytes\n", c->nextGen1.capacity() * BytesPerWord); } @@ -509,11 +514,12 @@ initNextGen2(Context* c) (&(c->nextGen2), 1, c->pageMap.scale * 1024, &(c->nextPageMap), true); unsigned minimum = c->gen2.position() + c->tenureFootprint + c->gen2padding; - unsigned desired = minimum * 2; + unsigned desired = max + (minimum * 2, InitialGen2CapacityInBytes / BytesPerWord); new (&(c->nextGen2)) Segment(c, &(c->nextHeapMap), desired, minimum); - if (Verbose) { + if (Verbose2) { fprintf(stderr, "init nextGen2 to %d bytes\n", c->nextGen2.capacity() * BytesPerWord); } @@ -1051,12 +1057,15 @@ collect(Context* c, unsigned footprint) c->mode = Heap::MajorCollection; } + int64_t then; if (Verbose) { if (c->mode == Heap::MajorCollection) { - fprintf(stderr, "major collection\n"); + fprintf(stderr, "major collection "); } else { - fprintf(stderr, "minor collection\n"); + fprintf(stderr, "minor collection "); } + + then = c->system->now(); } initNextGen1(c, footprint); @@ -1070,6 +1079,10 @@ collect(Context* c, unsigned footprint) if (c->mode == Heap::MajorCollection) { c->gen2.replaceWith(&(c->nextGen2)); } + + if (Verbose) { + fprintf(stderr, "- " LLD "ms\n", (c->system->now() - then)); + } } class MyHeap: public Heap {