changes.
[IRC.git] / Robust / src / Runtime / runtime.h
index 3b4dd34cefad5b012ad163a529066013ed1e281a..de90cadd2efdb9451f303198aa6b1094d9e29afa 100644 (file)
@@ -1,32 +1,57 @@
 #ifndef RUNTIME
 #define RUNTIME
+#include <stdlib.h>
+#include "objtypes.h"
+#ifndef MULTICORE
 #include <setjmp.h>
 extern jmp_buf error_handler;
 extern int instructioncount;
 extern int failurecount;
+#endif
 #ifdef DSTM
-#include "dstm.h"
+#ifdef RECOVERY
+#include "DSTM/interface_recovery/dstm.h"
+#else
+#include "DSTM/interface/dstm.h"
+#endif
+#endif
+
+#ifdef AFFINITY
+void set_affinity();
 #endif
 
 #ifndef INTPTR
 #ifdef BIT64
 #define INTPTR long
+#define INTPTRSHIFT 3
 #else
 #define INTPTR int
+#define INTPTRSHIFT 2
+#endif
 #endif
+
+#ifndef CACHELINESIZE
+// The L1 and L2 cache line size for the
+// AMD Opteron 6168 (dc-10) is 64 bytes.  Source:
+// http://www.cs.virginia.edu/~skadron/cs451/opteron/opteron.ppt
+#define CACHELINESIZE 64
 #endif
 
 extern void * curr_heapbase;
 extern void * curr_heaptop;
 
+#define likely(x) __builtin_expect((x),1)
+#define unlikely(x) __builtin_expect((x),0)
+
+
 #define TAGARRAYINTERVAL 10
 #define OBJECTARRAYINTERVAL 10
 
 #define ARRAYSET(array, type, index, value) \
-  ((type *)(& (& array->___length___)[1]))[index]=value
+  ((type *)(&(&array->___length___)[1]))[index]=value
 
 #define ARRAYGET(array, type, index) \
-  ((type *)(& (& array->___length___)[1]))[index]
+  ((type *)(&(&array->___length___)[1]))[index]
 
 #ifdef OPTIONAL
 #define OPTARG(x) , x
@@ -46,27 +71,46 @@ __attribute__((malloc)) struct ArrayObject * allocate_newarraytrans(void * ptr,
 
 #ifdef PRECISE_GC
 #include "garbage.h"
+#ifdef MLP
+__attribute__((malloc)) void * allocate_new_mlp(void *, int type, int oid, int allocsite);
+__attribute__((malloc)) void * allocate_new(void *, int type);
+__attribute__((malloc)) struct ArrayObject * allocate_newarray_mlp(void *, int type, int length, int oid, int allocsite);
+__attribute__((malloc)) struct ArrayObject * allocate_newarray(void * ptr, int type, int length);
+#else
 __attribute__((malloc)) void * allocate_new(void *, int type);
 __attribute__((malloc)) struct ArrayObject * allocate_newarray(void *, int type, int length);
-__attribute__((malloc)) struct ___String___ * NewString(void *, const char *str,int length);
+#endif
+__attribute__((malloc)) StringPtr NewString(void *, const char *str,int length);
+__attribute__((malloc)) StringPtr NewStringShort(void *, const short *str,int length);
+__attribute__((malloc)) struct ___TagDescriptor___ * allocate_tag(void *ptr, int index);
+#elif defined(MULTICORE_GC)||defined(PMC_GC)
+__attribute__((malloc)) void * allocate_new(void *, int type);
+__attribute__((malloc)) struct ArrayObject * allocate_newarray(void *, int type, int length);
+__attribute__((malloc)) StringPtr NewString(void *, const char *str,int length);
+__attribute__((malloc)) StringPtr NewStringShort(void *, const short *str,int length);
 __attribute__((malloc)) struct ___TagDescriptor___ * allocate_tag(void *ptr, int index);
 #else
 __attribute__((malloc)) void * allocate_new(int type);
 __attribute__((malloc)) struct ArrayObject * allocate_newarray(int type, int length);
-__attribute__((malloc)) struct ___String___ * NewString(const char *str,int length);
+__attribute__((malloc)) StringPtr NewString(const char *str,int length);
+__attribute__((malloc)) StringPtr NewStringShort(const short *str,int length);
 __attribute__((malloc)) struct ___TagDescriptor___ * allocate_tag(int index);
 #endif
 
 
 
 void initializeexithandler();
-void failedboundschk();
-void failednullptr();
+void failedboundschk(int num, int index, struct ArrayObject * ao);
+void failednullptr(void * stackptr);
 void abort_task();
 void injectinstructionfailure();
+#ifdef MULTICORE
+void createstartupobject(int argc, char ** argv);
+#else
 void createstartupobject();
+#endif
 
-#ifdef PRECISE_GC
+#if defined(PRECISE_GC)||defined(MULTICORE_GC)||defined(PMC_GC)
 #define VAR(name) ___params___->name
 #define CALL00(name) name(struct name ## _params * ___params___)
 #define CALL01(name, alt) name(struct name ## _params * ___params___)
@@ -77,6 +121,7 @@ void createstartupobject();
 #define CALL23(name, rest, rest2, alt1, alt2, alt3) name(struct name ## _params * ___params___, rest, rest2)
 #define CALL24(name, rest, rest2, alt1, alt2, alt3, alt4) name(struct name ## _params * ___params___, rest, rest2)
 #define CALL34(name, rest, rest2, rest3, alt1, alt2, alt3, alt4) name(struct name ## _params * ___params___, rest, rest2, rest3)
+#define CALL35(name, rest, rest2, rest3, alt1, alt2, alt3, alt4, alt5) name(struct name ## _params * ___params___, rest, rest2, rest3)
 #else
 #define VAR(name) name
 #define CALL00(name) name()
@@ -88,12 +133,37 @@ void createstartupobject();
 #define CALL23(name, rest, rest2, alt1, alt2, alt3) name(alt1, alt2, alt3)
 #define CALL24(name, rest, rest2, alt1, alt2, alt3, alt4) name(alt1, alt2, alt3, alt4)
 #define CALL34(name, rest, rest2, rest3, alt1, alt2, alt3, alt4) name(alt1, alt2, alt3, alt4)
+#define CALL35(name, rest, rest2, rest3, alt1, alt2, alt3, alt4, alt5) name(alt1, alt2, alt3, alt4, alt5)
 #endif
 
-#ifdef TASK
+#ifdef MULTICORE
 #include "SimpleHash.h"
-#include "chash.h"
+void run(int argc, char** argv);
+int receiveObject_I();
+#endif
+
+#if (defined(THREADS)||defined(MGC))
+#define MAXLOCKS 256
+
+struct lockpair {
+  ObjectPtr object;
+  int islastlock;
+};
+
+struct lockvector {
+  int index;
+  struct lockpair locks[MAXLOCKS];
+};
+
+#ifndef MAC
+extern __thread struct lockvector lvector;
+extern __thread int mythreadid;
+#endif
+#endif
+
+#ifdef TASK
 #ifndef MULTICORE
+#include "chash.h"
 #include "ObjectHash.h"
 #include "structdefs.h"
 #endif
@@ -102,6 +172,7 @@ void createstartupobject();
 #include "optionalstruct.h"
 #endif
 
+
 #ifdef OPTIONAL
 struct failedtasklist {
   struct taskdescriptor *task;
@@ -119,18 +190,16 @@ struct transObjInfo {
   int * queues;
   int length;
 };
-struct RuntimeHash * lockRedirectTbl;
 #endif
 
 #ifdef FASTCHECK
-extern struct ___Object___ * ___fcrevert___;
+extern ObjectPtr ___fcrevert___;
 #endif
 
 #ifdef MULTICORE
-inline int receiveObject(void);
 void flagorand(void * ptr, int ormask, int andmask, struct parameterwrapper ** queues, int length);
 void flagorandinit(void * ptr, int ormask, int andmask);
-void enqueueObject(void * ptr, struct parameterwrapper ** queues, int length);
+void enqueueObject(void * ptr, struct parameterwrapper ** queues,int length);
 #ifdef PROFILE
 inline void setTaskExitIndex(int index);
 inline void addNewObjInfo(void * nobj);
@@ -194,8 +263,21 @@ void toiNext(struct tagobjectiterator *it, void ** objectarray OPTARG(int * fail
 void processobject(struct parameterwrapper *parameter, int index, struct parameterdescriptor *pd, int *iteratorcount, int * statusarray, int numparams);
 void processtags(struct parameterdescriptor *pd, int index, struct parameterwrapper *parameter, int * iteratorcount, int *statusarray, int numparams);
 void builditerators(struct taskdescriptor * task, int index, struct parameterwrapper * parameter);
-int enqueuetasks(struct parameterwrapper *parameter, struct parameterwrapper *prevptr, struct ___Object___ *ptr, int * enterflags, int numenterflags);
+int enqueuetasks(struct parameterwrapper *parameter, struct parameterwrapper *prevptr, ObjectPtr ptr, int * enterflags, int numenterflags);
 
 #endif
 
+#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 );
+}
+#endif
 #endif