changes for reading input files
[IRC.git] / Robust / src / Runtime / bamboo / multicoreruntime.c
index c4f8918f562b3959034c21c9ff813bac51730971..bed80cf40a50b49fd462a29a29000cded452cf55 100644 (file)
@@ -13,6 +13,9 @@
 #ifdef PERFCOUNT
 #include "bme_perf_counter.h"
 #endif
+#ifdef MEMPERFCOUNT
+#include "memprof.h"
+#endif
 
 extern int classsize[];
 extern int typearray[];
@@ -298,6 +301,7 @@ void CALL11(___System______exit____I,
     print_statistics();
 #endif
     gc_outputProfileDataReadable();
+    tprintf("FINISH_EXECUTION\n");
   }
 #endif 
   BAMBOO_EXIT_APP(___status___);
@@ -334,6 +338,33 @@ long long CALL00(___System______currentTimeMillis____) {
 }
 #endif
 
+#ifdef D___System______numGCs____
+long long ___System______numGCs____(struct ___System______numGCs_____params * ___params___) {
+#ifdef MULTICORE_GC
+  return numGCs;
+#else
+  return 0;
+#endif
+}
+#endif
+
+#ifdef D___System______milliGcTime____
+long long CALL00(___System______milliGcTime____) {
+#ifdef MULTICORE_GC
+  return GCtime/700000;
+#else
+  return 0;
+#endif
+}
+#endif
+
+#ifdef D___System______nanoTime____ 
+long long CALL00(___System______nanoTime____) {
+  //TilePro64 is 700mHz
+  return ((unsigned long long)BAMBOO_GET_EXE_TIME())/700;
+}
+#endif
+
 #ifdef D___System______setgcprofileflag____
 void CALL00(___System______setgcprofileflag____) {
 #ifdef GC_PROFILE
@@ -370,7 +401,7 @@ void CALL00(___System______gc____) {
       }
       for(int i = 0; i < NUMCORES4GC; i++) {
         if(i != STARTUPCORE) {
-          send_msg_1_I(i,GCSTARTPRE);
+          send_msg_1(i,GCSTARTPRE);
         }
       }
     }
@@ -398,6 +429,97 @@ void CALL01(___System______printString____L___String___, struct ___String___ * _
 }
 #endif
 
+#ifdef D___Scanner______nextInt____ 
+int CALL01(___Scanner______nextInt____, struct ___Scanner___ * ___this___) {
+  int pos = VAR(___this___)->___currentpos___;
+  int i = 0;
+  unsigned char * filearray = (unsigned char *)(VAR(___this___)->___filearray___);
+  while((filearray[pos]==' ')||(filearray[pos]=='\n')){
+         pos++;
+  }
+  int value = 0;
+  bool isNeg=false;
+  int radix = 10;
+
+  if (filearray[pos]=='-') {
+         isNeg=true;
+      pos++;
+  }
+  bool cont=true;
+  do {
+         unsigned char b=filearray[pos];
+      int val;
+      if (b>='0'&&b<='9')
+        val=b-'0';
+      else if (b>='a'&&b<='z')
+        val=10+b-'a';
+      else if (b>='A'&&b<='Z')
+        val=10+b-'A';
+      else {
+        cont=false;
+      }
+      if (cont) {
+        if (val>=radix)
+          printf("Error in Scanner.nextInt(): val >= radix");
+        value=value*radix+val;
+               pos++;
+      }
+  }while(cont);
+  if (isNeg)
+         value=-value;
+
+  VAR(___this___)->___currentpos___ = pos;
+  return value;
+}
+#endif
+
+#ifdef D___Scanner______nextDouble____ 
+double CALL01(___Scanner______nextDouble____, struct ___Scanner___ * ___this___) {
+  int pos = VAR(___this___)->___currentpos___;
+  int i = 0;
+  unsigned char * filearray = (unsigned char *)(VAR(___this___)->___filearray___);
+  while((filearray[pos]==' ')||(filearray[pos]=='\n')){
+         pos++;
+  }
+  double value = 0.0;
+  bool isNeg=false;
+  int radix = 10;
+
+  if (filearray[pos]=='-') {
+         isNeg=true;
+      pos++;
+  } else if(filearray[pos]=='+') {
+         pos++;
+  }
+  bool cont=true;
+  // TODO
+  /*do {
+         unsigned char b=filearray[pos];
+      int val;
+      if (b>='0'&&b<='9')
+        val=b-'0';
+      else if (b>='a'&&b<='z')
+        val=10+b-'a';
+      else if (b>='A'&&b<='Z')
+        val=10+b-'A';
+      else {
+        cont=false;
+      }
+      if (cont) {
+        if (val>=radix)
+          System.error();
+        value=value*radix+val;
+               pos++;
+      }
+  }while(cont)*/
+  if (isNeg)
+         value=-value;
+
+  VAR(___this___)->___currentpos___ = pos;
+  return value;
+}
+#endif
+
 /* Object allocation function */
 
 #if defined(MULTICORE_GC)||defined(PMC_GC)
@@ -412,10 +534,6 @@ void * allocate_new(void * ptr,
   v->lockcount = 0;
 #endif
   initlock(v);
-#ifdef GC_PROFILE
-  extern unsigned int gc_num_obj;
-  gc_num_obj++;
-#endif
   return v;
 }
 
@@ -437,10 +555,6 @@ struct ArrayObject * allocate_newarray(void * ptr,
   }
   v->___length___=length;
   initlock((struct ___Object___ *)v);
-#ifdef GC_PROFILE
-  extern unsigned int gc_num_obj;
-  gc_num_obj++;
-#endif
   return v;
 }
 
@@ -765,6 +879,7 @@ void checkCoreStatus() {
 #endif
          gc_outputProfileDataReadable();
           disruntimedata();
+         tprintf("FINISH_EXECUTION\n");
           BAMBOO_ENTER_CLIENT_MODE_FROM_RUNTIME();
           terminate();  // All done.
         }
@@ -797,7 +912,12 @@ void run(int argc, char** argv) {
   pmc_onceInit();
 #endif
 #ifdef PERFCOUNT
-  profile_init(_LOCAL_DRD_CNT,_LOCAL_WR_CNT, _REMOTE_DRD_CNT, _REMOTE_WR_CNT);
+  if (BAMBOO_NUM_OF_CORE==STARTUPCORE)
+    profile_init(_LOCAL_DRD_CNT,_LOCAL_WR_CNT, _REMOTE_DRD_CNT, _REMOTE_WR_CNT);
+  else {
+    int offcore=4*(BAMBOO_NUM_OF_CORE-1);
+    profile_init(validevents[(offcore)%87], validevents[(offcore+1)%87], validevents[(offcore+2)%87], validevents[(offcore+3)%87]);
+  }
 #endif
   if (BAMBOO_NUM_OF_CORE==STARTUPCORE) {
     numconfirm=NUMCORES-1;