Kaffe 0.8.4: OutOfMemoryError exception does not occur

Frank Mehnert Frank.Mehnert at mchp.siemens.de
Tue Apr 22 06:22:27 PDT 1997


Hi Kaffe hackers,

there is a bug when the the OutOfMemoryError exception should occur. If
the heap space gets rare and this exception should occur, other memory
from heap is needed (execute_java_constructor, buildStackTrace). So we get
a fine endless loop. My suggestion for this is to introduce a safe heap
space respectively for this exception. See this:

========snipp=======
======== file kaffe/kaffevm/gc-malloc.c =================================
*** kaffe-0.8.4.ORIG/kaffe/kaffevm/gc-malloc.c	Tue Apr 22 15:07:50 1997
--- kaffe-0.8.4.my/kaffe/kaffevm/gc-malloc.c	Tue Apr 22 15:06:44 1997
***************
*** 62,68 ****
  #endif
  
  static void morecore();
- static int findbucket();
  
  /*
   * The overhead on a block is at least 4 bytes.  When free, this space
--- 62,67 ----
***************
*** 136,141 ****
--- 135,142 ----
  #define ASSERT(p)
  #endif
  
+ #define MEM_EXC_MEMORY  32*1024
+ 
  /*
   * Alloc some memory from the GC heap.
   */
***************
*** 144,149 ****
--- 145,151 ----
  gcheap_sbrk(size_t size)
  {
          char* ptr;
+     static exc_memory_used = 0;
  
          ptr = gcHeapptr;
  
***************
*** 151,158 ****
                  gcHeapptr += size;
                  return (ptr);
          }
!         return (0);
  }
  
  /*
   * Setup page size and align break pointer so all data will be page
--- 153,166 ----
                  gcHeapptr += size;
                  return (ptr);
          }
!         if (exc_memory_used) {
!             printf("Insufficient memory\n");
!             exit(-1);
          }
+         exc_memory_used = 1;
+         gcHeaptop += MEM_EXC_MEMORY;
+         return ((char*)-1);
+ }
  
  /*
   * Setup page size and align break pointer so all data will be page
***************
*** 174,181 ****
                  fprintf(stderr, "Failed to allocate heap (%dK)\n", heapsize/1024);
                  abort();
          }
          gcHeapptr = gcHeapbase;
!         gcHeaptop = gcHeapbase + heapsize;
  
          op = (union overhead *)gcHeapptr;
          n = n - sizeof (*op) - ((int)op & (n - 1));
--- 182,190 ----
                  fprintf(stderr, "Failed to allocate heap (%dK)\n", heapsize/1024);
                  abort();
          }
+         bzero(gcHeapbase, heapsize);
          gcHeapptr = gcHeapbase;
!         gcHeaptop = gcHeapbase + heapsize - MEM_EXC_MEMORY;
  
          op = (union overhead *)gcHeapptr;
          n = n - sizeof (*op) - ((int)op & (n - 1));
***************
*** 258,263 ****
--- 267,273 ----
  /*
   * Allocate more memory to the indicated bucket.
   */
+  
  static
  void
  morecore(int bucket)
***************
*** 328,355 ****
  #endif
  }
  
- /*
-  * Search ``srchlen'' elements of each free list for a block whose
-  * header starts at ``freep''.  If srchlen is -1 search the whole list.
-  * Return bucket number, or -1 if not found.
-  */
- static
- findbucket(union overhead* freep, int srchlen)
- {
-         register union overhead *p;
-         register int i, j;
- 
-         for (i = 0; i < NBUCKETS; i++) {
-                 j = 0;
-                 for (p = nextf[i]; p && j != srchlen; p = p->ov_next) {
-                         if (p == freep)
-                                 return (i);
-                         j++;
-                 }
-         }
-         return (-1);
- }
- 
  #ifdef MSTATS
  /*
   * mstats - print out statistics about malloc
--- 338,343 ----

==== file kaffe/kaffe/main.c ==========================================
*** kaffe-0.8.4.ORIG/kaffe/kaffe/main.c	Wed Apr 16 10:10:54 1997
--- kaffe-0.8.4.my/kaffe/kaffe/main.c	Tue Apr 22 14:55:48 1997
***************
*** 240,247 ****
  void
  throwOutOfMemory ()
  {
!         if (OutOfMemoryError != NULL)
!                 throwException(OutOfMemoryError);
          fprintf (stderr, "(Insufficient memory)\n");
          exit (-1);
  }
--- 240,249 ----
  void
  throwOutOfMemory ()
  {
!     Hjava_lang_Object *obj;
!         if ((obj = OutOfMemoryError) != NULL) {
!                 throwException(obj);
!         }
          fprintf (stderr, "(Insufficient memory)\n");
          exit (-1);
  }


=====schnipp============================================================

What do you think about it?

Frank

Frank Mehnert
email: Frank.Mehnert at mchp.siemens.de



More information about the kaffe mailing list