From: Brian Demsky <bdemsky@uci.edu>
Date: Sat, 19 May 2012 01:14:26 +0000 (-0700)
Subject: let us set the size of the heap in a sane way
X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=322fd21c16209780d43872cc44bb68d38172eabc;p=cdsspec-compiler.git

let us set the size of the heap in a sane way
---

diff --git a/main.cc b/main.cc
index e629f60..4de5967 100644
--- a/main.cc
+++ b/main.cc
@@ -78,5 +78,5 @@ int main(int numargs, char ** args) {
   main_args=args;
 
   /* Let's jump in quickly and start running stuff */
-  initSnapShotLibrary(10000 /*int numbackingpages*/, 1024 /*unsigned int numsnapshots*/, 1024 /*unsigned int nummemoryregions*/ , &real_main /*MyFuncPtr entryPoint*/);
+  initSnapShotLibrary(10000 /*int numbackingpages*/, 1024 /*unsigned int numsnapshots*/, 1024 /*unsigned int nummemoryregions*/ , 1000 /*int numheappages*/, &real_main /*MyFuncPtr entryPoint*/);
 }
diff --git a/mymemory.cc b/mymemory.cc
index ac46b11..891a93f 100644
--- a/mymemory.cc
+++ b/mymemory.cc
@@ -52,13 +52,8 @@ void MYFREE(void *ptr) {
   mspace_free( sStaticSpace, ptr );
 #endif
 }
-static mspace mySpace = NULL;
+mspace mySpace = NULL;
 void *malloc( size_t size ) {
-  if( NULL == mySpace ){
-    //void * mem = MYMALLOC( MSPACE_SIZE );
-    mySpace = create_mspace( MSPACE_SIZE, 1 );
-    AddUserHeapToSnapshot();
-  }
   return mspace_malloc( mySpace, size );
 }
 
@@ -66,13 +61,6 @@ void free( void * ptr ){
   mspace_free( mySpace, ptr );
 }
 
-void AddUserHeapToSnapshot(){
-  static bool alreadySnapshotted = false;
-  if( alreadySnapshotted ) return;
-  addMemoryRegionToSnapShot( mySpace, MSPACE_SIZE / PAGESIZE );
-}
-
-
 void * operator new(size_t size) throw(std::bad_alloc) {
   return MYMALLOC(size);
 }
diff --git a/mymemory.h b/mymemory.h
index f2f2c2b..2bec138 100644
--- a/mymemory.h
+++ b/mymemory.h
@@ -18,7 +18,6 @@
 
 void *MYMALLOC(size_t size);
 void MYFREE(void *ptr);
-void AddUserHeapToSnapshot();												
 /*
 The following code example is taken from the book
 The C++ Standard Library - A Tutorial and Reference
@@ -109,7 +108,6 @@ template <class T>
      return false;
  }
 
-
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -118,6 +116,7 @@ extern void* mspace_malloc(mspace msp, size_t bytes);
 extern void mspace_free(mspace msp, void* mem);
 extern mspace create_mspace_with_base(void* base, size_t capacity, int locked);
 extern mspace create_mspace(size_t capacity, int locked);
+extern mspace mySpace;
 #ifdef __cplusplus
 };  /* end of extern "C" */
 #endif
diff --git a/snapshot-interface.cc b/snapshot-interface.cc
index 2ee01a4..952d790 100644
--- a/snapshot-interface.cc
+++ b/snapshot-interface.cc
@@ -77,7 +77,6 @@ void SnapshotGlobalSegments(){
 //declaration of constructor....
 snapshotStack::snapshotStack(){
   SnapshotGlobalSegments();
-  AddUserHeapToSnapshot();
   stack=NULL;
 }
 	
diff --git a/snapshot.cc b/snapshot.cc
index 8761862..b848d02 100644
--- a/snapshot.cc
+++ b/snapshot.cc
@@ -123,7 +123,7 @@ void createSharedLibrary(){
 #ifdef __cplusplus
 }
 #endif
-void initSnapShotLibrary(unsigned int numbackingpages, unsigned int numsnapshots, unsigned int nummemoryregions , MyFuncPtr entryPoint){
+void initSnapShotLibrary(unsigned int numbackingpages, unsigned int numsnapshots, unsigned int nummemoryregions, unsigned int numheappages, MyFuncPtr entryPoint){
 #if USE_CHECKPOINTING
   struct sigaction sa;
   sa.sa_flags = SA_SIGINFO | SA_NODEFER | SA_RESTART;
@@ -134,6 +134,8 @@ void initSnapShotLibrary(unsigned int numbackingpages, unsigned int numsnapshots
     exit(-1);
   }
   initSnapShotRecord(numbackingpages, numsnapshots, nummemoryregions);
+  mySpace = create_mspace( numheappages*PAGESIZE, 1 );
+  addMemoryRegionToSnapShot(mySpace, numheappages);
   entryPoint();
 #else
   //add a signal to indicate that the process is going to terminate.
diff --git a/snapshot.h b/snapshot.h
index 16d9cd7..a0f2757 100644
--- a/snapshot.h
+++ b/snapshot.h
@@ -5,7 +5,7 @@
 
 typedef unsigned int snapshot_id;
 typedef void (*MyFuncPtr)();
-void initSnapShotLibrary(unsigned int numbackingpages, unsigned int numsnapshots, unsigned int nummemoryregions, MyFuncPtr entryPoint);
+void initSnapShotLibrary(unsigned int numbackingpages, unsigned int numsnapshots, unsigned int nummemoryregions, unsigned int numheappages, MyFuncPtr entryPoint);
 
 void addMemoryRegionToSnapShot( void * ptr, unsigned int numPages );