[kaffe] CVS kaffe (robilad): Fixed runtime free and max memory reporting

Kaffe CVS cvs-commits at kaffe.org
Thu Oct 21 15:32:00 PDT 2004


PatchSet 5322 
Date: 2004/10/21 21:08:45
Author: robilad
Branch: HEAD
Tag: (none) 
Log:
Fixed runtime free and max memory reporting

2004-10-21  Dalibor Topic  <robilad at kaffe.org>

        * kaffe/kaffevm/gc.h:
        (GarbageCollectorInterface_Ops) Added getHeapFree.
        (KGC_getHeapFree) New macro.

        * kaffe/kaffevm/boehm-gc/gc2.c:
        (KaffeGC_HeapFree) New static function.
        (GarbageCollectorInterface_) Added KaffeGC_HeapFree.

        * kaffe/kaffevm/kaffe-gc/gc-incremental.c:
        (gcGetHeapFree) New static function.
        (GarbageCollectorInterface_) Added gcGetHeapFree.

        * libraries/clib/native/Runtime.c:
        (java_lang_Runtime_freeMemory) Use KGC_getHeapFree.
        (java_lang_Runtime_maxMemory) Return Long.MAX_VALUE if
        memory is unlimited.

        Reported by:  Matthew Toseland <mtoseland at blueyonder.co.uk>

Members: 
	ChangeLog:1.2874->1.2875 
	kaffe/kaffevm/gc.h:1.27->1.28 
	kaffe/kaffevm/boehm-gc/gc2.c:1.5->1.6 
	kaffe/kaffevm/kaffe-gc/gc-incremental.c:1.9->1.10 
	libraries/clib/native/Runtime.c:1.25->1.26 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.2874 kaffe/ChangeLog:1.2875
--- kaffe/ChangeLog:1.2874	Thu Oct 21 14:29:23 2004
+++ kaffe/ChangeLog	Thu Oct 21 21:08:45 2004
@@ -1,5 +1,26 @@
 2004-10-21  Dalibor Topic  <robilad at kaffe.org>
 
+	* kaffe/kaffevm/gc.h:
+	(GarbageCollectorInterface_Ops) Added getHeapFree.
+	(KGC_getHeapFree) New macro.
+
+	* kaffe/kaffevm/boehm-gc/gc2.c:
+	(KaffeGC_HeapFree) New static function.
+	(GarbageCollectorInterface_) Added KaffeGC_HeapFree.
+
+	* kaffe/kaffevm/kaffe-gc/gc-incremental.c:
+	(gcGetHeapFree) New static function.
+	(GarbageCollectorInterface_) Added gcGetHeapFree.
+
+	* libraries/clib/native/Runtime.c:
+	(java_lang_Runtime_freeMemory) Use KGC_getHeapFree.
+	(java_lang_Runtime_maxMemory) Return Long.MAX_VALUE if
+	memory is unlimited.
+
+	Reported by:  Matthew Toseland <mtoseland at blueyonder.co.uk>
+
+2004-10-21  Dalibor Topic  <robilad at kaffe.org>
+
 	* README: Added ports to x86_64-freebsd and
 	i386-darwin.
 
Index: kaffe/kaffe/kaffevm/gc.h
diff -u kaffe/kaffe/kaffevm/gc.h:1.27 kaffe/kaffe/kaffevm/gc.h:1.28
--- kaffe/kaffe/kaffevm/gc.h:1.27	Wed Oct 20 16:47:13 2004
+++ kaffe/kaffe/kaffevm/gc.h	Thu Oct 21 21:08:47 2004
@@ -131,7 +131,8 @@
 
 	void 	(*enableGC)(Collector *);
 	void 	(*disableGC)(Collector *);
-  
+
+        uintp   (*getHeapFree)(Collector *); 
         uintp   (*getHeapLimit)(Collector *);
         uintp   (*getHeapTotal)(Collector *);
 
@@ -194,6 +195,8 @@
 #define KGC_disableGC(G)		\
     ((G)->ops->disableGC)((Collector*)(G));
 
+#define KGC_getHeapFree(G) \
+    ((G)->ops->getHeapFree)((Collector *)(G));
 #define KGC_getHeapLimit(G) \
     ((G)->ops->getHeapLimit)((Collector *)(G));
 #define KGC_getHeapTotal(G) \
Index: kaffe/kaffe/kaffevm/boehm-gc/gc2.c
diff -u kaffe/kaffe/kaffevm/boehm-gc/gc2.c:1.5 kaffe/kaffe/kaffevm/boehm-gc/gc2.c:1.6
--- kaffe/kaffe/kaffevm/boehm-gc/gc2.c:1.5	Tue Aug 24 17:59:42 2004
+++ kaffe/kaffe/kaffevm/boehm-gc/gc2.c	Thu Oct 21 21:08:47 2004
@@ -423,6 +423,12 @@
 }
 
 static uintp
+KaffeGC_HeapFree(Collector *gcif UNUSED)
+{
+  return GC_get_free_bytes();
+}
+
+static uintp
 KaffeGC_HeapLimit(Collector *gcif UNUSED)
 {
   return 0;
@@ -564,6 +570,7 @@
   KaffeGC_ThrowOOM,
   KaffeGC_EnableGC,
   KaffeGC_DisableGC,
+  KaffeGC_HeapFree,
   KaffeGC_HeapLimit,
   KaffeGC_HeapTotal,
   KaffeGC_addRef,
Index: kaffe/kaffe/kaffevm/kaffe-gc/gc-incremental.c
diff -u kaffe/kaffe/kaffevm/kaffe-gc/gc-incremental.c:1.9 kaffe/kaffe/kaffevm/kaffe-gc/gc-incremental.c:1.10
--- kaffe/kaffe/kaffevm/kaffe-gc/gc-incremental.c:1.9	Fri Sep  3 19:08:20 2004
+++ kaffe/kaffe/kaffevm/kaffe-gc/gc-incremental.c	Thu Oct 21 21:08:49 2004
@@ -1430,6 +1430,13 @@
   return gc_get_heap_total();
 }
 
+static uintp
+gcGetHeapFree(Collector *gcif)
+{
+  return gcGetHeapTotal(gcif) - gcStats.totalmem;
+}
+
+
 static const char *
 gcGetName(UNUSED Collector *gcif)
 {
@@ -1461,6 +1468,7 @@
 	gcThrowOOM,
 	gcEnableGC,
 	gcDisableGC,
+	gcGetHeapFree,
 	gcGetHeapLimit,
 	gcGetHeapTotal,
 	KaffeGC_addRef,
Index: kaffe/libraries/clib/native/Runtime.c
diff -u kaffe/libraries/clib/native/Runtime.c:1.25 kaffe/libraries/clib/native/Runtime.c:1.26
--- kaffe/libraries/clib/native/Runtime.c:1.25	Sat Jul 17 07:58:13 2004
+++ kaffe/libraries/clib/native/Runtime.c	Thu Oct 21 21:08:49 2004
@@ -53,12 +53,7 @@
 jlong
 java_lang_Runtime_freeMemory(struct Hjava_lang_Runtime* this UNUSED)
 {
-	/* This is a particularly inaccurate guess - it's basically how
-	 * much more memory we can claim from the heap, and ignores any
-	 * free memory already within the GC system.
-	 * Well it'll do for now.
-	 */
-	return KGC_getHeapLimit(main_collector) - KGC_getHeapTotal(main_collector);
+	return KGC_getHeapFree(main_collector);
 }
 
 /*
@@ -67,7 +62,14 @@
 jlong
 java_lang_Runtime_maxMemory(struct Hjava_lang_Runtime* this UNUSED)
 {
-	return KGC_getHeapLimit(main_collector);
+	jlong max = KGC_getHeapLimit(main_collector);
+
+	if (max <= 0) {
+		return 0x7fffffffffffffffL;
+	}
+	else {
+		return max;
+	}
 }
 
 /*




More information about the kaffe mailing list