switch to spaces only..
[IRC.git] / Robust / src / Runtime / runtime.c
index b8240d22ef7d44db277961c944d2c6d604e0dd9b..ff7e5d95435323a18db467289b6b5c7d814a9be4 100644 (file)
@@ -7,13 +7,26 @@
 #include <stdio.h>
 #include "option.h"
 #include "methodheaders.h"
+
+#if defined(THREADS)||defined(DSTM)||defined(STM)||defined(MLP)
+#include "thread.h"
+#endif
+
 #ifdef DSTM
 #ifdef RECOVERY
 #include "DSTM/interface_recovery/dstm.h"
-#include "DSTM/interface_recovery/prelookup.h"
+#include "DSTM/interface_recovery/altprelookup.h"
+
+#ifdef RECOVERYSTATS
+extern int numRecovery;
+extern unsigned int deadMachine[8];
+extern unsigned int sizeOfRedupedData[8];
+extern double elapsedTime[8];
+#endif
+
 #else
 #include "DSTM/interface/dstm.h"
-#include "DSTM/interface/prelookup.h"
+#include "DSTM/interface/altprelookup.h"
 #include "DSTM/interface/prefetch.h"
 #endif
 #endif
 #include <pthread.h>
 #endif
 #ifdef STMLOG
+#define ARRAY_LENGTH 700003
 __thread int counter;
-__thread int event[100000*7+3];
-__thread unsigned long long clkticks[100000*7+3];
+__thread int event[ARRAY_LENGTH];
+__thread unsigned long long clkticks[ARRAY_LENGTH];
+unsigned long long beginClock=0;
 #define FILENAME  "log"
 #endif
+#ifdef EVENTMONITOR
+#include "monitor.h"
+__thread int objcount=0;
+#define ASSIGNUID(x) {                                  \
+    int number=((objcount++)<<EVTHREADSHIFT)|threadnum; \
+    x->objuid=number;                                   \
+}
+#else
+#define ASSIGNUID(x)
+#endif
 
 #if defined(THREADS)||defined(STM)
+#ifndef MAC
 /* Global barrier for STM */
 pthread_barrier_t barrier;
 pthread_barrierattr_t attr;
 #endif
+#endif
 
 #include <string.h>
 
+#ifndef bool
+#define bool int
+#endif
+#define GCPOINT(x) ((INTPTR)((x)*0.99))
+
+
 extern int classsize[];
 extern int typearray[];
 extern int typearray2[];
@@ -68,7 +101,7 @@ int instanceof(struct ___Object___ *ptr, int type) {
   if (i>NUMCLASSES) {
     do {
       if (i==type)
-       return 1;
+        return 1;
       i=typearray2[i-NUMCLASSES];
     } while(i!=-1);
   }
@@ -99,7 +132,7 @@ void injectinstructionfailure() {
     instaccum+=failurecount;
     if ((((double)random())/RAND_MAX)<instfailurechance) {
       if (numfailures>0)
-       numfailures--;
+        numfailures--;
       printf("FAILURE!!! %d\n",numfailures);
       longjmp(error_handler,11);
     }
@@ -112,7 +145,7 @@ void injectinstructionfailure() {
     instaccum+=failurecount;
     if ((((double)random())/RAND_MAX)<instfailurechance) {
       if (numfailures>0)
-       numfailures--;
+        numfailures--;
       printf("FAILURE!!! %d\n",numfailures);
       threadexit();
     }
@@ -124,7 +157,7 @@ void injectinstructionfailure() {
 #ifdef D___Double______nativeparsedouble____L___String___
 double CALL01(___Double______nativeparsedouble____L___String___,struct ___String___ * ___str___) {
   int length=VAR(___str___)->___count___;
-  int maxlength=(length>60)?60:length;
+  int maxlength=(length>60) ? 60 : length;
   char str[maxlength+1];
   struct ArrayObject * chararray=VAR(___str___)->___value___;
   int i;
@@ -138,6 +171,66 @@ double CALL01(___Double______nativeparsedouble____L___String___,struct ___String
 }
 #endif
 
+#ifdef D___Double______nativeparsedouble_____AR_B_I_I
+double CALL23(___Double______nativeparsedouble_____AR_B_I_I, int start, int length,int start,int length,struct ArrayObject * ___str___) {
+  int maxlength=(length>60) ? 60 : length;
+  char str[maxlength+1];
+  struct ArrayObject * bytearray=VAR(___str___);
+  int i;
+  for(i=0; i<maxlength; i++) {
+    str[i]=(((char *)&bytearray->___length___)+sizeof(int))[i+start];
+  }
+  str[i]=0;
+  double d=atof(str);
+  return d;
+}
+#endif
+
+#ifdef D___Double______doubleToRawLongBits____D
+typedef union jvalue {
+  bool z;
+  char c;
+  short s;
+  int i;
+  long long j;
+  float f;
+  double d;
+} jvalue;
+
+long long CALL11(___Double______doubleToRawLongBits____D, double dval, double dval) {
+  jvalue val;
+  val.d = dval;
+
+#if defined(__IEEE_BYTES_LITTLE_ENDIAN)
+  /* On little endian ARM processors when using FPA, word order of
+     doubles is still big endian. So take that into account here. When
+     using VFP, word order of doubles follows byte order. */
+
+#define SWAP_DOUBLE(a)    (((a) << 32) | (((a) >> 32) & 0x00000000ffffffff))
+
+  val.j = SWAP_DOUBLE(val.j);
+#endif
+
+  return val.j;
+}
+#endif
+
+#ifdef D___Double______longBitsToDouble____J
+double CALL11(___Double______longBitsToDouble____J, long long lval, long long lval) {
+  jvalue val;
+  val.j = lval;
+
+#if defined(__IEEE_BYTES_LITTLE_ENDIAN)
+#ifndef SWAP_DOUBLE
+#define SWAP_DOUBLE(a)    (((a) << 32) | (((a) >> 32) & 0x00000000ffffffff))
+#endif
+  val.j = SWAP_DOUBLE(val.j);
+#endif
+
+  return val.d;
+}
+#endif
+
 #ifdef D___String______convertdoubletochar____D__AR_C
 int CALL12(___String______convertdoubletochar____D__AR_C, double ___val___, double ___val___, struct ArrayObject ___chararray___) {
   int length=VAR(___chararray___)->___length___;
@@ -156,6 +249,9 @@ int CALL12(___String______convertdoubletochar____D__AR_C, double ___val___, doub
 void deepArrayCopy(struct ___Object___ * dst, struct ___Object___ * src) {
   int dsttype=((int *)dst)[0];
   int srctype=((int *)src)[0];
+#ifdef STMARRAY
+  src=src->___objlocation___;
+#endif
   if (dsttype<NUMCLASSES||srctype<NUMCLASSES||srctype!=dsttype)
     return;
   struct ArrayObject *aodst=(struct ArrayObject *)dst;
@@ -169,19 +265,19 @@ void deepArrayCopy(struct ___Object___ * dst, struct ___Object___ * src) {
     int elementsize=classsize[srctype];
     int size=srclength*elementsize;
     //primitives
-    memcpy(((char *)&aodst->___length___)+sizeof(int) , ((char *)&aosrc->___length___)+sizeof(int), size);
+    memcpy(((char *)&aodst->___length___)+sizeof(int), ((char *)&aosrc->___length___)+sizeof(int), size);
   } else {
     //objects
     int i;
-    for(i=0;i<srclength;i++) {
+    for(i=0; i<srclength; i++) {
       struct ___Object___ * ptr=((struct ___Object___**)(((char*) &aosrc->___length___)+sizeof(int)))[i];
       int ptrtype=((int *)ptr)[0];
       if (ptrtype>=NUMCLASSES) {
-       struct ___Object___ * dstptr=((struct ___Object___**)(((char*) &aodst->___length___)+sizeof(int)))[i];
-       deepArrayCopy(dstptr,ptr);
+        struct ___Object___ * dstptr=((struct ___Object___**)(((char*) &aodst->___length___)+sizeof(int)))[i];
+        deepArrayCopy(dstptr,ptr);
       } else {
-       //hit an object
-       ((struct ___Object___ **)(((char*) &aodst->___length___)+sizeof(int)))[i]=ptr;
+        //hit an object
+        ((struct ___Object___ **)(((char*) &aodst->___length___)+sizeof(int)))[i]=ptr;
       }
     }
   }
@@ -192,11 +288,86 @@ void CALL02(___System______deepArrayCopy____L___Object____L___Object___, struct
 }
 #endif
 
+#ifdef D___System______arraycopy____L___Object____I_L___Object____I_I
+void arraycopy(struct ___Object___ *src, int srcPos, struct ___Object___ *dst, int destPos, int length) {
+  int dsttype=((int *)dst)[0];
+  int srctype=((int *)src)[0];
+
+  //not an array or type mismatch
+  if (dsttype<NUMCLASSES||srctype<NUMCLASSES)
+    return;
+  if (srctype!=dsttype)
+    printf("Potential type mismatch in arraycopy\n");
+
+  struct ArrayObject *aodst=(struct ArrayObject *)dst;
+  struct ArrayObject *aosrc=(struct ArrayObject *)src;
+  int dstlength=aodst->___length___;
+  int srclength=aosrc->___length___;
+
+  if (length<=0)
+    return;
+  if (srcPos+length>srclength)
+    return;
+  if (destPos+length>dstlength)
+    return;
+
+  unsigned INTPTR *pointer=pointerarray[srctype];
+  if (pointer==0) {
+    int elementsize=classsize[srctype];
+    int size=length*elementsize;
+    //primitives
+    memcpy(((char *)&aodst->___length___)+sizeof(int)+destPos*elementsize, ((char *)&aosrc->___length___)+sizeof(int)+srcPos*elementsize, size);
+  } else {
+    //objects
+    int i;
+    for(i=0; i<length; i++) {
+      struct ___Object___ * ptr=((struct ___Object___**)(((char*) &aosrc->___length___)+sizeof(int)))[i+srcPos];
+      //hit an object
+      ((struct ___Object___ **)(((char*) &aodst->___length___)+sizeof(int)))[i+destPos]=ptr;
+    }
+  }
+}
+
+void CALL35(___System______arraycopy____L___Object____I_L___Object____I_I, int ___srcPos___, int ___destPos___, int ___length___, struct ___Object___ * ___src___, int ___srcPos___, struct ___Object___ * ___dst___, int ___destPos___, int ___length___) {
+  arraycopy(VAR(___src___), ___srcPos___, VAR(___dst___), ___destPos___, ___length___);
+}
+#endif
+
+#ifdef D___Runtime______availableProcessors____
+int CALL01(___Runtime______availableProcessors____, struct ___Runtime___ * ___this___) {
+  printf("Unimplemented Runtime.availableProcessors\n");
+  return 24;
+}
+#endif
+
+#ifdef D___Runtime______freeMemory____
+long long CALL01(___Runtime______freeMemory____, struct ___Runtime___ * ___this___) {
+  printf("Unimplemented Runtime.freeMemory\n");
+  return 1024*1024*1024;
+}
+#endif
+
+#ifdef D___Runtime______totalMemory____
+long long CALL01(___Runtime______totalMemory____, struct ___Runtime___ * ___this___) {
+  printf("Unimplemented Runtime.totalMemory\n");
+  return 1024*1024*1024;
+}
+#endif
+
+#ifdef D___Runtime______maxMemory____
+long long CALL01(___Runtime______maxMemory____, struct ___Runtime___ * ___this___) {
+  printf("Unimplemented Runtime.maxMemory\n");
+  return 1024*1024*1024;
+}
+#endif
+#ifdef D___System______exit____I
 void CALL11(___System______exit____I,int ___status___, int ___status___) {
 #ifdef TRANSSTATS
+#ifndef RECOVERY
   printf("numTransCommit = %d\n", numTransCommit);
   printf("numTransAbort = %d\n", numTransAbort);
   printf("nSoftAbort = %d\n", nSoftAbort);
+#endif
 #ifdef STM
   printf("nSoftAbortCommit = %d\n", nSoftAbortCommit);
   printf("nSoftAbortAbort = %d\n", nSoftAbortAbort);
@@ -207,52 +378,15 @@ void CALL11(___System______exit____I,int ___status___, int ___status___) {
   }
 #endif
 #endif
+#endif
+#ifdef EVENTMONITOR
+  dumpdata();
 #endif
   exit(___status___);
 }
-
-#if defined(__i386__)
-
-static __inline__ unsigned long long rdtsc(void)
-{
-  unsigned long long int x;
-  __asm__ volatile (".byte 0x0f, 0x31" : "=A" (x));
-  return x;
-}
-#elif defined(__x86_64__)
-
-static __inline__ unsigned long long rdtsc(void)
-{
-  unsigned hi, lo;
-  __asm__ __volatile__ ("rdtsc" : "=a"(lo), "=d"(hi));
-  return ( (unsigned long long)lo)|( ((unsigned long long)hi)<<32 );
-}
-
-#elif defined(__powerpc__)
-
-typedef unsigned long long int unsigned long long;
-
-static __inline__ unsigned long long rdtsc(void)
-{
-  unsigned long long int result=0;
-  unsigned long int upper, lower,tmp;
-  __asm__ volatile(
-      "0:                  \n"
-      "\tmftbu   %0           \n"
-      "\tmftb    %1           \n"
-      "\tmftbu   %2           \n"
-      "\tcmpw    %2,%0        \n"
-      "\tbne     0b         \n"
-      : "=r"(upper),"=r"(lower),"=r"(tmp)
-      );
-  result = upper;
-  result = result<<32;
-  result = result|lower;
-
-  return(result);
-}
 #endif
 
+#ifdef D___System______logevent____I
 void CALL11(___System______logevent____I,int ___event___, int ___event___) {
 #ifdef STMLOG
   event[counter] = ___event___;
@@ -261,7 +395,18 @@ void CALL11(___System______logevent____I,int ___event___, int ___event___) {
 #endif
   return;
 }
+#endif
+
+#ifdef ___System______logevent____
+void CALL00(___System______logevent____) {
+#ifdef STMLOG
+  beginClock= rdtsc();
+#endif
+  return;
+}
+#endif
 
+#ifdef ___System______flushToFile____I
 void CALL11(___System______flushToFile____I, int ___threadid___, int ___threadid___) {
 #ifdef STMLOG
   FILE *fp;
@@ -275,21 +420,30 @@ void CALL11(___System______flushToFile____I, int ___threadid___, int ___threadid
   }
   int i;
   for (i = 0; i < counter-1; i++) {
-    fprintf(fp, "%d %lld %lld\n", event[i], clkticks[i], clkticks[i+1]);
+    fprintf(fp, "%d %lld %lld\n", event[i], clkticks[i]-beginClock, clkticks[i+1]-beginClock);
   }
-  fprintf(fp, "%d %lld\n", event[i], clkticks[i]);
+  fprintf(fp, "%d %lld\n", event[i], clkticks[i]-beginClock);
 
   fclose(fp);
 #endif
   return;
 }
+#endif
 
+#ifdef D___System______initLog____
 void CALL00(___System______initLog____) {
 #ifdef STMLOG
   counter=0;
+  int i;
+  for(i=0; i<ARRAY_LENGTH; i++) {
+    event[i] = 0;
+    clkticks[i] = 0;
+  }
+
 #endif
   return;
 }
+#endif
 
 #ifdef D___Vector______removeElement_____AR_L___Object____I_I
 void CALL23(___Vector______removeElement_____AR_L___Object____I_I, int ___index___, int ___size___, struct ArrayObject * ___array___, int ___index___, int ___size___) {
@@ -298,10 +452,13 @@ void CALL23(___Vector______removeElement_____AR_L___Object____I_I, int ___index_
 }
 #endif
 
+#ifdef D___System______printI____I
 void CALL11(___System______printI____I,int ___status___, int ___status___) {
   printf("%d\n",___status___);
 }
+#endif
 
+#ifdef D___System______currentTimeMillis____
 long long CALL00(___System______currentTimeMillis____) {
   struct timeval tv; long long retval;
   gettimeofday(&tv, NULL);
@@ -310,9 +467,63 @@ long long CALL00(___System______currentTimeMillis____) {
   retval+= (tv.tv_usec/1000); /* adjust milliseconds & add them in */
   return retval;
 }
+#endif
+
+#ifdef D___System______gc____
+void CALL00(___System______gc____) {
+#if defined(THREADS)||defined(DSTM)||defined(STM)||defined(MLP)
+  while (pthread_mutex_trylock(&gclock)!=0) {
+    stopforgc((struct garbagelist *)___params___);
+    restartaftergc();
+  }
+#endif
+
+  /* Grow the to heap if necessary */
+  {
+    INTPTR curr_heapsize=curr_heaptop-curr_heapbase;
+    INTPTR to_heapsize=to_heaptop-to_heapbase;
+
+    if (curr_heapsize>to_heapsize) {
+      free(to_heapbase);
+      to_heapbase=malloc(curr_heapsize);
+      if (to_heapbase==NULL) {
+        printf("Error Allocating enough memory\n");
+        exit(-1);
+      }
+      to_heaptop=to_heapbase+curr_heapsize;
+      to_heapptr=to_heapbase;
+    }
+  }
+
+
+  collect((struct garbagelist *)___params___);
+
+  {
+    void * tmp=to_heapbase;
+    to_heapbase=curr_heapbase;
+    curr_heapbase=tmp;
+
+    tmp=to_heaptop;
+    to_heaptop=curr_heaptop;
+    curr_heaptop=tmp;
+
+    tmp=to_heapptr;
+    curr_heapptr=to_heapptr;
+    curr_heapgcpoint=((char *) curr_heapbase)+GCPOINT(curr_heaptop-curr_heapbase);
+    to_heapptr=to_heapbase;
+    bzero(tmp, curr_heaptop-tmp);
+
+  }
+
+#if defined(THREADS)||defined(DSTM)||defined(STM)||defined(MLP)
+  pthread_mutex_unlock(&gclock);
+#endif
+}
+#endif
 
+#ifdef D___System______microTimes____
 long long CALL00(___System______microTimes____) {
-  struct timeval tv; 
+  struct timeval tv;
   long long retval;
   gettimeofday(&tv, NULL);
   retval = tv.tv_sec; /* seconds */
@@ -320,14 +531,18 @@ long long CALL00(___System______microTimes____) {
   retval+= (tv.tv_usec); /* adjust microseconds & add them in */
   return retval;
 }
+#endif
 
+#ifdef D___System______getticks____
 long long CALL00(___System______getticks____) {
   unsigned a, d;
-  asm("cpuid");
-  asm volatile("rdtsc" : "=a" (a), "=d" (d));
+  asm ("cpuid");
+  asm volatile ("rdtsc" : "=a" (a), "=d" (d));
   return (((ticks)a) | (((ticks)d) << 32));
 }
+#endif
 
+#ifdef D___System______printString____L___String___
 void CALL01(___System______printString____L___String___,struct ___String___ * ___s___) {
   struct ArrayObject * chararray=VAR(___s___)->___value___;
   int i;
@@ -336,14 +551,35 @@ void CALL01(___System______printString____L___String___,struct ___String___ * __
     short sc=((short *)(((char *)&chararray->___length___)+sizeof(int)))[i+offset];
     putchar(sc);
   }
+#ifdef RECOVERYSTATS
+  fflush(stdout);
+  fflush(stdout);
+#endif
+}
+#endif
+
+#ifdef D___RecoveryStat______printRecoveryStat____
+#ifdef RECOVERYSTATS
+void CALL00(___RecoveryStat______printRecoveryStat____) {
+  printRecoveryStat();
+}
+#else
+void CALL00(___RecoveryStat______printRecoveryStat____) {
+  printf("No Stat\n");
+  fflush(stdout);
 }
+#endif
+#endif
 
 #ifdef DSTM
+#ifdef D___System______clearPrefetchCache____
 void CALL00(___System______clearPrefetchCache____) {
   prehashClear();
 }
+#endif
 
 #ifdef RANGEPREFETCH
+#ifdef D___System______rangePrefetch____L___Object_____AR_S
 void CALL02(___System______rangePrefetch____L___Object_____AR_S, struct ___Object___ * ___o___, struct ArrayObject * ___offsets___) {
   /* Manual Prefetches to be inserted */
   //printf("DEBUG-> %s() ___Object___ * ___o___ = %x\n", __func__, VAR(___o___));
@@ -370,26 +606,26 @@ void CALL02(___System______rangePrefetch____L___Object_____AR_S, struct ___Objec
   return;
 }
 #endif
+#endif
 
-#ifdef D___Task______execution____ 
+#ifdef D___Task______execution____
 extern void* virtualtable[];
 // associated with Task.execution(). finds proper execute method and call it
-void CALL01(___Task______execution____,struct ___Task___ * ___this___)
-{
+void CALL01(___Task______execution____,struct ___Task___ * ___this___) {
   unsigned int oid;
   oid = (unsigned int) VAR(___this___);   // object id
   int type = getObjType(oid);             // object type
 
 #ifdef PRECISE_GC
-  int p[] = {1,0 , oid};
-   
-  ((void(*) (void *))virtualtable[type*MAXCOUNT + EXECUTEMETHOD])(p);
+  int p[] = {1,0, oid};
+  ((void (*)(void *))virtualtable[type*MAXCOUNT + EXECUTEMETHOD])(p);
 #else
   // call the proper execute method
-  ((void(*) (void *))virtualtable[type*MAXCOUNT + EXECUTEMETHOD])(oid);
+  ((void (*)(void *))virtualtable[type*MAXCOUNT + EXECUTEMETHOD])(oid);
 #endif
 }
 #endif
+
 #endif // DSTM
 
 /* STM Barrier constructs */
@@ -408,6 +644,9 @@ void CALL11(___Barrier______setBarrier____I, int nthreads, int nthreads) {
 void CALL00(___Barrier______enterBarrier____) {
   // Synchronization point
   int ret;
+#ifdef EVENTMONITOR
+  EVLOGEVENT(EV_ENTERBARRIER);
+#endif
 #ifdef PRECISE_GC
   stopforgc((struct garbagelist *)___params___);
 #endif
@@ -419,6 +658,9 @@ void CALL00(___Barrier______enterBarrier____) {
     printf("%s() Could not wait on barrier: error %d in %s\n", __func__, errno, __FILE__);
     exit(-1);
   }
+#ifdef EVENTMONITOR
+  EVLOGEVENT(EV_EXITBARRIER);
+#endif
 }
 #endif
 
@@ -428,10 +670,10 @@ void CALL00(___Barrier______enterBarrier____) {
 __attribute__((malloc)) void * allocate_newglobal(int type) {
   struct ___Object___ * v=(struct ___Object___ *) transCreateObj(classsize[type]);
   v->type=type;
+  v->hashcode=(int)(INTPTR)v;
+  //printf("DEBUG %s(), type= %x\n", __func__, type);
 #ifdef THREADS
   v->tid=0;
-  v->lockentry=0;
-  v->lockcount=0;
 #endif
   return v;
 }
@@ -445,11 +687,10 @@ __attribute__((malloc)) struct ArrayObject * allocate_newarrayglobal(int type, i
     return NULL;
   }
   v->type=type;
+  v->hashcode=(int)(INTPTR)v;
   v->___length___=length;
 #ifdef THREADS
   v->tid=0;
-  v->lockentry=0;
-  v->lockcount=0;
 #endif
   return v;
 }
@@ -461,8 +702,14 @@ __attribute__((malloc)) struct ArrayObject * allocate_newarrayglobal(int type, i
 
 /* Object allocation function */
 __attribute__((malloc)) void * allocate_newtrans(void * ptr, int type) {
+#ifdef STMARRAY
+  struct ___Object___ * v=(struct ___Object___ *) transCreateObj(ptr, classsize[type], 0);
+#else
   struct ___Object___ * v=(struct ___Object___ *) transCreateObj(ptr, classsize[type]);
+#endif
+  ASSIGNUID(v);
   v->type=type;
+  v->hashcode=(int)(INTPTR)v;
   v->___objlocation___=v;
   return v;
 }
@@ -470,16 +717,30 @@ __attribute__((malloc)) void * allocate_newtrans(void * ptr, int type) {
 /* Array allocation function */
 __attribute__((malloc)) struct ArrayObject * allocate_newarraytrans(void * ptr, int type, int length) {
 #ifdef STMARRAY
-  struct ArrayObject * v=(struct ArrayObject *)transCreateObj(ptr, sizeof(struct ArrayObject)+length*classsize[type]+sizeof(int)*(((length*classsize[type])>>DBLINDEXSHIFT)), (length*classsize[type])>>DBLINDEXSHIFT);
+  int basesize=length*classsize[type];
+  //round the base size up
+  basesize=(basesize+LOWMASK)&HIGHMASK;
+  int numlocks=basesize>>INDEXSHIFT;
+  int bookkeepsize=numlocks*2*sizeof(int);
+  struct ArrayObject * v=(struct ArrayObject *)transCreateObj(ptr, sizeof(struct ArrayObject)+basesize+bookkeepsize, bookkeepsize);
+  unsigned int *intptr=(unsigned int *)(((char *)v)-sizeof(objheader_t));
+  for(; numlocks>0; numlocks--) {
+    intptr-=2;
+    intptr[0]=1;
+  }
+  v->highindex=-1;
+  v->lowindex=MAXARRAYSIZE;
 #else
   struct ArrayObject * v=(struct ArrayObject *)transCreateObj(ptr, sizeof(struct ArrayObject)+length*classsize[type]);
 #endif
+  ASSIGNUID(v);
   if (length<0) {
     printf("ERROR: negative array\n");
     return NULL;
   }
   v->___objlocation___=(struct ___Object___*)v;
   v->type=type;
+  v->hashcode=(int)(INTPTR)v;
   v->___length___=length;
   return v;
 }
@@ -487,10 +748,12 @@ __attribute__((malloc)) struct ArrayObject * allocate_newarraytrans(void * ptr,
 __attribute__((malloc)) void * allocate_new(void * ptr, int type) {
   objheader_t *tmp=mygcmalloc((struct garbagelist *) ptr, classsize[type]+sizeof(objheader_t));
   struct ___Object___ * v=(struct ___Object___ *) &tmp[1];
+  ASSIGNUID(v);
   initdsmlocks(&tmp->lock);
   tmp->version = 1;
   v->___objlocation___=v;
   v->type = type;
+  v->hashcode=(int)(INTPTR)v;
   return v;
 }
 
@@ -498,15 +761,33 @@ __attribute__((malloc)) void * allocate_new(void * ptr, int type) {
 
 __attribute__((malloc)) struct ArrayObject * allocate_newarray(void * ptr, int type, int length) {
 #ifdef STMARRAY
-  int *tmpint=mygcmalloc((struct garbagelist *) ptr, sizeof(struct ArrayObject)+length*classsize[type]+sizeof(objheader_t)+sizeof(int)*(((length*classsize[type])>>DBLINDEXSHIFT)));
-  objheader_t *tmp=(objheader_t *)(tmpint+((length*classsize[type])>>DBLINDEXSHIFT));
+  int basesize=length*classsize[type];
+  //round the base size up
+  basesize=(basesize+LOWMASK)&HIGHMASK;
+  int numlocks=basesize>>INDEXSHIFT;
+  int bookkeepsize=(numlocks)*2*sizeof(int);
+  int *tmpint=mygcmalloc((struct garbagelist *) ptr, sizeof(struct ArrayObject)+basesize+sizeof(objheader_t)+bookkeepsize);
+  for(; numlocks>0; numlocks--) {
+    tmpint[0]=1;
+    tmpint+=2;
+  }
+  objheader_t *tmp=(objheader_t *)tmpint;
+  struct ArrayObject * v=(struct ArrayObject *) &tmp[1];
+  v->highindex=-1;
+  v->lowindex=MAXARRAYSIZE;
 #else
   objheader_t *tmp=mygcmalloc((struct garbagelist *) ptr, sizeof(struct ArrayObject)+length*classsize[type]+sizeof(objheader_t));
-#endif
   struct ArrayObject * v=(struct ArrayObject *) &tmp[1];
+#endif
+#ifdef DUALVIEW
+  tmp->lock=RW_LOCK_BIAS;
+#else
   initdsmlocks(&tmp->lock);
+#endif
   tmp->version=1;
+  ASSIGNUID(v);
   v->type=type;
+  v->hashcode=(int)(INTPTR)v;
   if (length<0) {
     printf("ERROR: negative array %d\n", length);
     return NULL;
@@ -519,25 +800,42 @@ __attribute__((malloc)) struct ArrayObject * allocate_newarray(void * ptr, int t
 
 #ifndef STM
 #if defined(PRECISE_GC)
+#ifdef MLP
+__attribute__((malloc)) void * allocate_new(void * ptr, int type) {
+  return allocate_new_mlp(ptr, type, 0, 0);
+}
+__attribute__((malloc)) void * allocate_new_mlp(void * ptr, int type, int oid, int allocsite) {
+#else
 __attribute__((malloc)) void * allocate_new(void * ptr, int type) {
+#endif
   struct ___Object___ * v=(struct ___Object___ *) mygcmalloc((struct garbagelist *) ptr, classsize[type]);
   v->type=type;
+  v->hashcode=(int)(INTPTR)v;
 #ifdef THREADS
   v->tid=0;
-  v->lockentry=0;
-  v->lockcount=0;
 #endif
 #ifdef OPTIONAL
   v->fses=0;
+#endif
+#ifdef MLP
+  v->oid=oid;
+  v->allocsite=allocsite;
 #endif
   return v;
 }
 
 /* Array allocation function */
-
+#ifdef MLP
+__attribute__((malloc)) struct ArrayObject * allocate_newarray(void * ptr, int type, int length) {
+  return allocate_newarray_mlp(ptr, type, length, 0, 0);
+}
+__attribute__((malloc)) struct ArrayObject * allocate_newarray_mlp(void * ptr, int type, int length, int oid, int allocsite) {
+#else
 __attribute__((malloc)) struct ArrayObject * allocate_newarray(void * ptr, int type, int length) {
+#endif
   struct ArrayObject * v=mygcmalloc((struct garbagelist *) ptr, sizeof(struct ArrayObject)+length*classsize[type]);
   v->type=type;
+  v->hashcode=(int)(INTPTR)v;
   if (length<0) {
     printf("ERROR: negative array\n");
     return NULL;
@@ -545,11 +843,13 @@ __attribute__((malloc)) struct ArrayObject * allocate_newarray(void * ptr, int t
   v->___length___=length;
 #ifdef THREADS
   v->tid=0;
-  v->lockentry=0;
-  v->lockcount=0;
 #endif
 #ifdef OPTIONAL
   v->fses=0;
+#endif
+#ifdef MLP
+  v->oid=oid;
+  v->allocsite=allocsite;
 #endif
   return v;
 }
@@ -558,6 +858,7 @@ __attribute__((malloc)) struct ArrayObject * allocate_newarray(void * ptr, int t
 __attribute__((malloc)) void * allocate_new(int type) {
   struct ___Object___ * v=FREEMALLOC(classsize[type]);
   v->type=type;
+  v->hashcode=(int)(INTPTR)v;
 #ifdef OPTIONAL
   v->fses=0;
 #endif
@@ -569,6 +870,7 @@ __attribute__((malloc)) void * allocate_new(int type) {
 __attribute__((malloc)) struct ArrayObject * allocate_newarray(int type, int length) {
   __attribute__((malloc))  struct ArrayObject * v=FREEMALLOC(sizeof(struct ArrayObject)+length*classsize[type]);
   v->type=type;
+  v->hashcode=(int)(INTPTR)v;
   v->___length___=length;
 #ifdef OPTIONAL
   v->fses=0;
@@ -578,6 +880,32 @@ __attribute__((malloc)) struct ArrayObject * allocate_newarray(int type, int len
 #endif
 #endif
 
+/* Converts C character arrays into Java strings */
+#ifdef PRECISE_GC
+__attribute__((malloc)) struct ___String___ * NewStringShort(void * ptr, const short *str,int length) {
+#else
+__attribute__((malloc)) struct ___String___ * NewStringShort(const short *str,int length) {
+#endif
+  int i;
+#ifdef PRECISE_GC
+  struct ArrayObject * chararray=allocate_newarray((struct garbagelist *)ptr, CHARARRAYTYPE, length);
+  INTPTR ptrarray[]={1, (INTPTR) ptr, (INTPTR) chararray};
+  struct ___String___ * strobj=allocate_new((struct garbagelist *) &ptrarray, STRINGTYPE);
+  chararray=(struct ArrayObject *) ptrarray[2];
+#else
+  struct ArrayObject * chararray=allocate_newarray(CHARARRAYTYPE, length);
+  struct ___String___ * strobj=allocate_new(STRINGTYPE);
+#endif
+  strobj->___value___=chararray;
+  strobj->___count___=length;
+  strobj->___offset___=0;
+
+  for(i=0; i<length; i++) {
+    ((short *)(((char *)&chararray->___length___)+sizeof(int)))[i]=str[i];
+  }
+  return strobj;
+}
+
 /* Converts C character arrays into Java strings */
 #ifdef PRECISE_GC
 __attribute__((malloc)) struct ___String___ * NewString(void * ptr, const char *str,int length) {
@@ -606,7 +934,7 @@ __attribute__((malloc)) struct ___String___ * NewString(const char *str,int leng
 
 /* Generated code calls this if we fail a bounds check */
 
-void failedboundschk() {
+void failedboundschk(int num) {
 #ifndef TASK
   printf("Array out of bounds\n");
 #ifdef THREADS
@@ -628,3 +956,14 @@ void abort_task() {
   exit(-1);
 #endif
 }
+
+#ifndef SANDBOX
+#ifdef D___System______Assert____Z
+void CALL11(___System______Assert____Z, int ___status___, int ___status___) {
+  if (!___status___) {
+    printf("Assertion violation\n");
+    *((int *)(NULL));  //force stack trace error
+  }
+}
+#endif
+#endif