[kaffe] CVS kaffe (guilhem): GC fix when throwing an OOM.
Kaffe CVS
cvs-commits at kaffe.org
Sat May 7 01:11:14 PDT 2005
PatchSet 6446
Date: 2005/05/07 08:06:26
Author: guilhem
Branch: HEAD
Tag: (none)
Log:
GC fix when throwing an OOM.
* kaffe/kaffevm/kaffe-gc/gc-incremental.c
(reserve): Removed.
(gcThrowOOM): Use gc_primitive_use_reserve.
(KaffeGC_Init): Adapted to the new prototype.
* kaffe/kaffevm/kaffe-gc/gc-mem.h
(KGC_NUMBER_OF_PAGES_IN_RESERVE): New constant.
* kaffe/kaffevm/kaffe-gc/gc-mem.c
(gc_reserve_pages): New variable.
(gc_primitive_reserve): Store the reserved block in a private
variable.
(gc_primitive_use_reserve): New function.
(gc_block_alloc): Update gc_reserve_pages if the block array is
reallocated.
Members:
ChangeLog:1.3974->1.3975
kaffe/kaffevm/kaffe-gc/gc-incremental.c:1.26->1.27
kaffe/kaffevm/kaffe-gc/gc-mem.c:1.28->1.29
kaffe/kaffevm/kaffe-gc/gc-mem.h:1.13->1.14
Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.3974 kaffe/ChangeLog:1.3975
--- kaffe/ChangeLog:1.3974 Sat May 7 03:56:55 2005
+++ kaffe/ChangeLog Sat May 7 08:06:26 2005
@@ -1,3 +1,21 @@
+2005-05-07 Guilhem Lavaux <guilhem at kaffe.org>
+
+ * kaffe/kaffevm/kaffe-gc/gc-incremental.c
+ (reserve): Removed.
+ (gcThrowOOM): Use gc_primitive_use_reserve.
+ (KaffeGC_Init): Adapted to the new prototype.
+
+ * kaffe/kaffevm/kaffe-gc/gc-mem.h
+ (KGC_NUMBER_OF_PAGES_IN_RESERVE): New constant.
+
+ * kaffe/kaffevm/kaffe-gc/gc-mem.c
+ (gc_reserve_pages): New variable.
+ (gc_primitive_reserve): Store the reserved block in a private
+ variable.
+ (gc_primitive_use_reserve): New function.
+ (gc_block_alloc): Update gc_reserve_pages if the block array is
+ reallocated.
+
2005-05-07 Ito Kazumitsu <kaz at maczuka.gcd.org>
* test/internal/jit_stub.c: Changed ABORT to KAFFEVM_ABORT.
Index: kaffe/kaffe/kaffevm/kaffe-gc/gc-incremental.c
diff -u kaffe/kaffe/kaffevm/kaffe-gc/gc-incremental.c:1.26 kaffe/kaffe/kaffevm/kaffe-gc/gc-incremental.c:1.27
--- kaffe/kaffe/kaffevm/kaffe-gc/gc-incremental.c:1.26 Fri May 6 16:58:57 2005
+++ kaffe/kaffe/kaffevm/kaffe-gc/gc-incremental.c Sat May 7 08:06:29 2005
@@ -87,7 +87,6 @@
((uintp) (from) >= gc_get_heap_base() && \
(uintp) (from) < gc_get_heap_base() + gc_get_heap_range())
-static void *reserve;
static void *outOfMem;
static void *outOfMem_allocator;
@@ -1199,9 +1198,7 @@
* outOfMemory error. We can use some or all of the reserved
* pages to actually grab an error.
*/
- if (reserve) {
- gc_primitive_free(reserve);
- reserve = NULL;
+ if (gc_primitive_use_reserve()) {
if (!ret || ret == OOM_ALLOCATING) {
unlockStaticMutex(&gc_lock);
ret = OutOfMemoryError; /* implicit allocation */
@@ -1521,7 +1518,7 @@
gc_obj.collector.ops = &KGC_Ops;
gc_heap_initialise ();
- reserve = gc_primitive_reserve ();
+ gc_primitive_reserve(KGC_NUMBER_OF_PAGES_IN_RESERVE);
return (&gc_obj.collector);
}
Index: kaffe/kaffe/kaffevm/kaffe-gc/gc-mem.c
diff -u kaffe/kaffe/kaffevm/kaffe-gc/gc-mem.c:1.28 kaffe/kaffe/kaffevm/kaffe-gc/gc-mem.c:1.29
--- kaffe/kaffe/kaffevm/kaffe-gc/gc-mem.c:1.28 Fri May 6 15:24:30 2005
+++ kaffe/kaffe/kaffevm/kaffe-gc/gc-mem.c Sat May 7 08:06:29 2005
@@ -40,6 +40,7 @@
#endif
static gc_block *gc_last_block;
+static gc_block *gc_reserve_pages;
static iStaticLock gc_heap_lock;
#if defined(KAFFE_STATS)
@@ -945,14 +946,17 @@
/*
* Try to reserve some memory for OOM exception handling. Gc once at
* the beginning. We start out looking for an arbitrary number of
- * pages (4), and cut our expectations in half until we are able to
+ * pages, and cut our expectations in half until we are able to
* meet them.
*/
-gc_block *
-gc_primitive_reserve(void)
+void
+gc_primitive_reserve(size_t numpages)
{
gc_block *r = NULL;
- size_t size = 4 * gc_pgsize;
+ size_t size = numpages * gc_pgsize;
+
+ if (gc_reserve_pages != NULL)
+ return;
while (size >= gc_pgsize && !(r = gc_primitive_alloc(size))) {
if (size == gc_pgsize) {
@@ -960,9 +964,28 @@
}
size /= 2;
}
- return r;
+ /* As it is done just at the initialization it is expected to have at
+ * least one page free */
+ assert(r != NULL);
+ gc_reserve_pages = r;
+}
+
+/*
+ * We return the reserve to the heap if it has not been already used.
+ * This function returns true if some reserve was still available.
+ */
+bool
+gc_primitive_use_reserve()
+{
+ if (gc_reserve_pages == NULL)
+ return false;
+ gc_primitive_free(gc_reserve_pages);
+ gc_reserve_pages = NULL;
+
+ return true;
}
+
/*
* System memory management: Obtaining additional memory from the
* OS. This looks more complicated than it is, since it does not require
@@ -1129,6 +1152,7 @@
return NULL;
}
+ DBG(GCSYSALLOC, dprintf("old block_base = %p, new block_base = %p\n", old_blocks, gc_block_base));
/* If the array's address has changed, we have to fix
up the pointers in the gc_blocks, as well as all
external pointers to the gc_blocks. We can only
@@ -1160,6 +1184,8 @@
for (i = 0; freelist[i].list != (void*)-1; i++)
R(gc_block, freelist[i].list);
+
+ R(gc_block, gc_reserve_pages);
#undef R
}
KTHREAD(spinoff)(NULL);
Index: kaffe/kaffe/kaffevm/kaffe-gc/gc-mem.h
diff -u kaffe/kaffe/kaffevm/kaffe-gc/gc-mem.h:1.13 kaffe/kaffe/kaffevm/kaffe-gc/gc-mem.h:1.14
--- kaffe/kaffe/kaffevm/kaffe-gc/gc-mem.h:1.13 Sun Mar 13 12:57:24 2005
+++ kaffe/kaffe/kaffevm/kaffe-gc/gc-mem.h Sat May 7 08:06:29 2005
@@ -36,6 +36,7 @@
#define MAX_SMALL_OBJECT_SIZE 8192
#define NR_FREELISTS 20
#define KGC_SMALL_OBJECT(S) ((S) <= max_small_object_size)
+#define KGC_NUMBER_PAGE_IN_RESERVE 4
/**
* Alignment for gc_blocks
@@ -88,7 +89,8 @@
uint8* data; /* Address of first object in */
} gc_block;
-extern gc_block * gc_primitive_reserve(void);
+extern void gc_primitive_reserve(size_t numpages);
+extern bool gc_primitive_use_reserve();
extern void gc_primitive_free(gc_block* mem);
extern gc_block * gc_mem2block(const void * mem);
More information about the kaffe
mailing list