[kaffe] CVS kaffe (stack): Change allocation behavior to free large pools of memory after jitting

Kaffe CVS cvs-commits at kaffe.org
Tue Sep 16 12:26:02 PDT 2003


PatchSet 4042 
Date: 2003/09/16 19:23:35
Author: stack
Branch: HEAD
Tag: (none) 
Log:
Change allocation behavior to free large pools of memory after jitting
is done.

Members: 
	ChangeLog:1.1638->1.1639 
	kaffe/kaffevm/jni.c:1.93->1.94 
	kaffe/kaffevm/jit3/constpool.c:1.4->1.5 
	kaffe/kaffevm/jit3/constpool.h:1.4->1.5 
	kaffe/kaffevm/jit3/labels.c:1.9->1.10 
	kaffe/kaffevm/jit3/labels.h:1.7->1.8 
	kaffe/kaffevm/jit3/machine.c:1.40->1.41 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.1638 kaffe/ChangeLog:1.1639
--- kaffe/ChangeLog:1.1638	Tue Sep 16 14:49:34 2003
+++ kaffe/ChangeLog	Tue Sep 16 19:23:35 2003
@@ -1,3 +1,14 @@
+2003-09-16  Timothy S. Stack <stack at cs.utah.edu>
+
+	* kaffe/kaffevm/jit3/jni.c,
+	kaffe/kaffevm/jit3/constpool.h,
+	kaffe/kaffevm/jit3/constpool.c,
+	kaffe/kaffevm/jit3/labels.h,
+	kaffe/kaffevm/jit3/labels.c,
+	kaffe/kaffevm/jit3/machine.c:
+	Change allocation behavior to free large pools of memory after
+	jitting is done.
+	
 2003-09-16  Dalibor Topic <robilad at kaffe.org>
 
 	* developers/patch-libtool-amiga.diff,
Index: kaffe/kaffe/kaffevm/jni.c
diff -u kaffe/kaffe/kaffevm/jni.c:1.93 kaffe/kaffe/kaffevm/jni.c:1.94
--- kaffe/kaffe/kaffevm/jni.c:1.93	Mon Sep  1 20:28:02 2003
+++ kaffe/kaffe/kaffevm/jni.c	Tue Sep 16 19:23:37 2003
@@ -4018,6 +4018,9 @@
 		xmeth->accflags |= ACC_JNI;
 
 done:
+	resetConstants();
+	resetLabels();
+
 #if defined(KAFFE_PROFILER)
 	if (profFlag) {
 		profiler_click_t end;
Index: kaffe/kaffe/kaffevm/jit3/constpool.c
diff -u kaffe/kaffe/kaffevm/jit3/constpool.c:1.4 kaffe/kaffe/kaffevm/jit3/constpool.c:1.5
--- kaffe/kaffe/kaffevm/jit3/constpool.c:1.4	Tue Feb 11 16:54:45 2003
+++ kaffe/kaffe/kaffevm/jit3/constpool.c	Tue Sep 16 19:23:38 2003
@@ -20,8 +20,7 @@
 
 #include <stdarg.h>
 
-#define	gc_calloc_fixed(A,B)	gc_malloc((A)*(B), GC_ALLOC_JITTEMP)
-
+static constpoolchunk* poolchunks;
 constpool* firstConst;
 constpool* lastConst;
 constpool* currConst;
@@ -75,14 +74,20 @@
 		c = currConst;
 	}
 
-	if (!c) {
+	if (c == NULL) {
+		constpoolchunk *cpc;
 		int i;
 
 		/* Allocate chunk of constpool elements */
-		c = gc_calloc_fixed(ALLOCCONSTNR, sizeof(constpool));
+		cpc = gc_malloc(sizeof(constpoolchunk), GC_ALLOC_JITTEMP);
 		/* XXX Ack! */
-		assert(c != 0);
+		assert(cpc != 0);
+
+		cpc->next = poolchunks;
+		poolchunks = cpc;
 
+		c = &cpc->data[0];
+		
 		/* Attach to current chain */
 		if (lastConst == 0) {
 			firstConst = c;
@@ -90,13 +95,12 @@
 		else {
 			lastConst->next = c;
 		}
-		lastConst = &c[ALLOCCONSTNR-1];
+		lastConst = &cpc->data[ALLOCCONSTNR-1];
 
 		/* Link elements into list */
-		for (i = 0; i < ALLOCCONSTNR-1; i++) {
-			c[i].next = &c[i+1];
+		for (i = 0; i < ALLOCCONSTNR - 2; i++) {
+			cpc->data[i].next = &cpc->data[i+1];
 		}
-		c[ALLOCCONSTNR-1].next = NULL;
 	}
 
 	c->type = type;
@@ -173,4 +177,15 @@
 {
 	currConst = firstConst;
 	nConst = 0;
+	while( (poolchunks != NULL) && (poolchunks->next != NULL) )
+	{
+		constpoolchunk *cpc = poolchunks;
+
+		poolchunks = cpc->next;
+		gc_free(poolchunks);
+	}
+	if( poolchunks != NULL )
+	{
+		poolchunks->data[ALLOCCONSTNR - 1].next = NULL;
+	}
 }
Index: kaffe/kaffe/kaffevm/jit3/constpool.h
diff -u kaffe/kaffe/kaffevm/jit3/constpool.h:1.4 kaffe/kaffe/kaffevm/jit3/constpool.h:1.5
--- kaffe/kaffe/kaffevm/jit3/constpool.h:1.4	Mon May 12 21:13:30 2003
+++ kaffe/kaffe/kaffevm/jit3/constpool.h	Tue Sep 16 19:23:38 2003
@@ -69,7 +69,19 @@
 	} val;
 } constpool;
 
-#define ALLOCCONSTNR	32
+#define ALLOCCONSTNR	64
+
+/**
+ * constpools are allocated and tracked as part of a chunk as represented by
+ * this structure.
+ *
+ * next - Link to the next chunk in the list.
+ * data - The constpools contained in the chunk.
+ */
+typedef struct _constpoolchunk {
+	struct _constpoolchunk *next;
+	constpool data[ALLOCCONSTNR];
+} constpoolchunk;
 
 /**
  * These variables track the pool of constpool objects allocated by the jitter.
Index: kaffe/kaffe/kaffevm/jit3/labels.c
diff -u kaffe/kaffe/kaffevm/jit3/labels.c:1.9 kaffe/kaffe/kaffevm/jit3/labels.c:1.10
--- kaffe/kaffe/kaffevm/jit3/labels.c:1.9	Tue Mar 11 08:00:18 2003
+++ kaffe/kaffe/kaffevm/jit3/labels.c	Tue Sep 16 19:23:38 2003
@@ -25,6 +25,7 @@
 #include "thread.h"
 #include "jthread.h"
 
+static labelchunk* labelchunks;
 static label* firstLabel;
 static label* lastLabel;
 static label* currLabel;
@@ -33,7 +34,6 @@
 
 /* Custom edition */
 #define	kprintf	kaffe_dprintf
-#define	gc_calloc_fixed(A,B)	gc_malloc((A)*(B), GC_ALLOC_JITTEMP)
 #include "debug.h"
 
 #if defined(KAFFE_VMDEBUG)
@@ -66,6 +66,17 @@
 resetLabels(void)
 {
 	currLabel = firstLabel;
+	while( (labelchunks != NULL) && (labelchunks->next != NULL) )
+	{
+		labelchunk *lc = labelchunks;
+
+		labelchunks = lc->next;
+		gc_free(labelchunks);
+	}
+	if( labelchunks != NULL )
+	{
+		labelchunks->data[ALLOCLABELNR - 1].next = NULL;
+	}
 }
 
 label *getLastEpilogueLabel(void)
@@ -227,9 +238,17 @@
 
 	ret = currLabel;
 	if (ret == 0) {
+		labelchunk *lc;
+		
 		/* Allocate chunk of label elements */
-		ret = gc_calloc_fixed(ALLOCLABELNR, sizeof(label));
+		lc = gc_malloc(sizeof(labelchunk), GC_ALLOC_JITTEMP);
+		assert(lc != NULL);
+
+		lc->next = labelchunks;
+		labelchunks = lc;
 
+		ret = &lc->data[0];
+		
 		/* Attach to current chain */
 		if (lastLabel == 0) {
 			firstLabel = ret;
@@ -237,16 +256,15 @@
 		else {
 			lastLabel->next = ret;
 		}
-		lastLabel = &ret[ALLOCLABELNR-1];
+		lastLabel = &lc->data[ALLOCLABELNR-1];
 
 		/* Link elements into list */
-		for (i = 0; i < ALLOCLABELNR-1; i++) {
+		for (i = 0; i < ALLOCLABELNR - 2; i++) {
 #if defined(KAFFE_VMDEBUG)
-			sprintf(ret[i].name, "L%d", labelCount + i);
+			sprintf(lc->data[i].name, "L%d", labelCount + i);
 #endif
-			ret[i].next = &ret[i+1];
+			lc->data[i].next = &lc->data[i+1];
 		}
-		ret[ALLOCLABELNR-1].next = 0;
 	}
 	currLabel = ret->next;
 	labelCount += 1;
Index: kaffe/kaffe/kaffevm/jit3/labels.h
diff -u kaffe/kaffe/kaffevm/jit3/labels.h:1.7 kaffe/kaffe/kaffevm/jit3/labels.h:1.8
--- kaffe/kaffe/kaffevm/jit3/labels.h:1.7	Mon May 12 21:13:30 2003
+++ kaffe/kaffe/kaffevm/jit3/labels.h	Tue Sep 16 19:23:38 2003
@@ -113,6 +113,18 @@
 #define	ALLOCLABELNR	1024
 
 /**
+ * Labels are allocated and tracked as part of a chunk as represented by this
+ * structure.
+ *
+ * next - Link to the next chunk in the list.
+ * data - The labels contained in the chunk.
+ */
+typedef struct _labelchunk {
+	struct _labelchunk *next;
+	label data[ALLOCLABELNR];
+} labelchunk;
+
+/**
  * Set the address of all epilogue labels used in this method.
  *
  * Note:  There can be more than one epilogue label because there can be more
Index: kaffe/kaffe/kaffevm/jit3/machine.c
diff -u kaffe/kaffe/kaffevm/jit3/machine.c:1.40 kaffe/kaffe/kaffevm/jit3/machine.c:1.41
--- kaffe/kaffe/kaffevm/jit3/machine.c:1.40	Sat Aug 30 23:57:12 2003
+++ kaffe/kaffe/kaffevm/jit3/machine.c	Tue Sep 16 19:23:38 2003
@@ -374,6 +374,8 @@
 	}
 
 done:;
+	resetLabels();
+	resetConstants();
 	tidyAnalyzeMethod(&codeInfo);
 
 	reinvoke = false;
@@ -719,15 +721,9 @@
 	initSeq();
 	initRegisters();
 	initSlots(stackno);
-	resetLabels();
-	resetConstants();
 
 	/* Before generating code, try to guess how much space we'll need. */
-	if (codeblock_size < codesize)
-		codeblock_size = codesize;
-	if (codeblock_size < ALLOCCODEBLOCKSZ) {
-		codeblock_size = ALLOCCODEBLOCKSZ;
-	}
+	codeblock_size = ALLOCCODEBLOCKSZ;
 	codeblock = gc_malloc(codeblock_size + CODEBLOCKREDZONE, GC_ALLOC_JITTEMP);
 	if (codeblock == 0) {
 		postOutOfMemory(einfo);
@@ -759,11 +755,20 @@
 
 		/* If we overrun the codeblock, reallocate and continue.  */
 		if (CODEPC >= codeblock_size) {
+			nativecode *new_codeblock;
+			
 			codeblock_size += ALLOCCODEBLOCKSZ;
-			codeblock = gc_realloc(codeblock, codeblock_size + CODEBLOCKREDZONE, GC_ALLOC_JITTEMP);
-			if (codeblock == 0) {
+			new_codeblock = gc_realloc(codeblock,
+						   codeblock_size +
+						   CODEBLOCKREDZONE,
+						   GC_ALLOC_JITTEMP);
+			if (new_codeblock == NULL) {
+				gc_free(codeblock);
+				codeblock = NULL;
 				postOutOfMemory(einfo);
 				return (false);
+			} else {
+				codeblock = new_codeblock;
 			}
 		}
 




More information about the kaffe mailing list