even though man page says otherwise, addr and len to mprotect must be page-aligned...
authorjjenista <jjenista>
Thu, 28 Oct 2010 01:01:24 +0000 (01:01 +0000)
committerjjenista <jjenista>
Thu, 28 Oct 2010 01:01:24 +0000 (01:01 +0000)
Robust/src/Benchmarks/oooJava/micro-master-makefile
Robust/src/Benchmarks/oooJava/micro4/test.java
Robust/src/Runtime/memPool.h

index 0107d28de4a799ffbfd6008a6b25d971a463885a..ad180512cb35c1a7bd1dee949fc88f2fe49d91a5 100644 (file)
@@ -32,7 +32,7 @@ USECOREPROF= #-coreprof $(COREPROFOVERFLOW) \
        -coreprof-enable cpe_taskstallmem
 
 
-USEOOO= -ooojava 24 2 -squeue -mempool-detect-misuse #-ooodebug-disable-task-mem-pool #-ooodebug 
+USEOOO= -ooojava 12 2 -squeue -mempool-detect-misuse #-ooodebug-disable-task-mem-pool #-ooodebug 
 BSFLAGS= -64bit -mainclass $(PROGRAM)  -heapsize-mb 50 -garbagestats -joptimize -noloop -debug -debug-deque # -optimize src-after-pp
 
 DRELEASEMODE=-disjoint-release-mode -disjoint-dvisit-stack-callees-on-top -disjoint-alias-file aliases.txt tabbed
index 5465abe4c5f50ed5eba3b4c2931630426eddae77..d6faa9fd197c43398ecedf9c646115fbe8876562 100644 (file)
@@ -8,8 +8,10 @@ public class test {
 
   public static void main( String argv[] ) {
     
-    long count  = 500;
-    int  numFoo = 1000;
+    //long count  = 500;
+    //int  numFoo = 1000;
+    long count  = 80;
+    int  numFoo = 10;
     
     if( argv.length > 0 ) {
       count = count * Integer.parseInt( argv[0] );
index 8724b19136a67f5fd4e47e1732e4220bb02acad3..0662e5fcca5949df2ca016f0910c46edd8b9e566 100644 (file)
@@ -53,6 +53,7 @@ typedef struct MemPool_t {
 
 #ifdef MEMPOOL_DETECT_MISUSE
   int allocSize;
+  int protectSize;
 #else
   //normal version
   MemPoolItem* head;
@@ -83,11 +84,18 @@ static MemPool* poolcreate( int itemSize,
 
   if( itemSize % pageSize == 0 ) {
     // if the item size is already an exact multiple
-    // of the page size, just increase by one page
+    // of the page size, just increase alloc by one page
     p->allocSize = itemSize + pageSize;
+
+    // and size for mprotect should be exact page multiple
+    p->protectSize = itemSize;
   } else {
     // otherwise, round down to a page size, then add two
     p->allocSize = (itemSize & ~(pageSize-1)) + 2*pageSize;
+
+    // and size for mprotect should be exact page multiple
+    // so round down, add one
+    p->protectSize = (itemSize & ~(pageSize-1)) + pageSize;
   }
 #else
 
@@ -113,8 +121,18 @@ static inline void poolfreeinto( MemPool* p, void* ptr ) {
   // don't actually return memory to the pool, just lock
   // it up tight so first code to touch it badly gets caught
   // also, mprotect automatically protects full pages
-  if( mprotect( ptr, p->itemSize, PROT_NONE ) != 0 ) {
-    printf( "mprotect failed, %s.\n", strerror( errno ) );
+  if( mprotect( ptr, p->protectSize, PROT_NONE ) != 0 ) {
+
+    switch( errno ) {
+      
+    case ENOMEM: {
+      printf( "mprotect failed, ENOMEM.\n" );
+    } break;
+
+    default:
+      printf( "mprotect failed, errno=%d.\n", errno );
+    } 
+
     exit( -1 );
   }
 }
@@ -166,6 +184,19 @@ static inline void* poolalloc( MemPool* p ) {
 
   void* newRec = (void*)((nonAligned + pageSize-1) & ~(pageSize-1));
 
+  //printf( "PageSize is %d or 0x%x.\n", (INTPTR)pageSize, (INTPTR)pageSize );
+  //printf( "itemSize is 0x%x and allocSize is 0x%x.\n", (INTPTR)p->itemSize, (INTPTR)p->allocSize );
+  //printf( "Allocation returned 0x%x to 0x%x,\n",   (INTPTR)nonAligned, (INTPTR)nonAligned + (INTPTR)(p->allocSize) );
+  //printf( "Intend to use       0x%x to 0x%x,\n\n", (INTPTR)newRec,     (INTPTR)newRec     + (INTPTR)(p->itemSize)  );
+  
+  // intentionally touch the top of the new, aligned record in terms of the
+  // pages that will be locked when it eventually is free'd
+  INTPTR topOfRec = (INTPTR)newRec;
+  topOfRec += p->protectSize - 1;
+  ((char*)topOfRec)[0] = 0x1;
+
+
+
   if( p->initFreshlyAllocated != NULL ) {
     p->initFreshlyAllocated( newRec );
   }