Add some runtime support for MGC
authorjzhou <jzhou>
Sat, 19 Feb 2011 00:55:50 +0000 (00:55 +0000)
committerjzhou <jzhou>
Sat, 19 Feb 2011 00:55:50 +0000 (00:55 +0000)
Robust/src/ClassLibrary/gnu/Double.java
Robust/src/Runtime/bamboo/multicoreruntime.c
Robust/src/Runtime/math.c

index 93ab44cac15de21529afcf8853ea59f5892a0259..ea5c93343dbd9c385353e5751a283d8c6f2515e8 100644 (file)
@@ -287,7 +287,7 @@ public final class Double extends Number //implements Comparable<Double>
   }
 
   public static native double nativeparsedouble(String str);
-    public static native double nativeparsedouble(byte[] str, int start, int length);
+    public static native double nativeparsedouble(int start, int length, byte[] str);
 
   /**
    * Return <code>true</code> if the <code>double</code> has the same
index ad9567370ae42afd596444b2a5778cf5837e976b..f08c944723643d9d646e67928423fb8b5d3e5ca6 100644 (file)
@@ -5,6 +5,7 @@
 #include "runtime_arch.h"
 #include "GenericHashtable.h"
 #include "structdefs.h"
+#include "methodheaders.h"
 #include "mem.h"
 #ifndef RAW
 #include <stdio.h>
@@ -63,7 +64,7 @@ void injectinstructionfailure() {
 
 #ifdef D___Double______nativeparsedouble____L___String___
 double CALL01(___Double______nativeparsedouble____L___String___,struct ___String___ * ___str___) {
-  int length=VAR(___str___)->___count___;
+  /*int length=VAR(___str___)->___count___;
   int maxlength=(length>60) ? 60 : length;
   char str[maxlength+1];
   struct ArrayObject * chararray=VAR(___str___)->___value___;
@@ -73,13 +74,32 @@ double CALL01(___Double______nativeparsedouble____L___String___,struct ___String
     str[i]=((short *)(((char *)&chararray->___length___)+sizeof(int)))[i+offset];
   }
   str[i]=0;
-  double d=atof(str);
+  double d=atof(str);*/
+  printf("Unimplemented Double.nativeparsedouble(S) \n");
+  double d = 0.0;
+  return d;
+}
+#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);*/
+  printf("Unimplemented Double.nativeparsedouble() \n");
+  double d = 0.0;
   return d;
 }
 #endif
 
 #ifdef D___String______convertdoubletochar____D__AR_C
-int CALL12(___String______convertdoubletochar____D__AR_C, double ___val___, double ___val___, struct ArrayObject ___chararray___) {
+int CALL12(___String______convertdoubletochar____D__AR_C, double ___val___, double ___val___, struct ArrayObject ___chararray___) {
   int length=VAR(___chararray___)->___length___;
   char str[length];
   int i;
@@ -97,21 +117,107 @@ int CALL12(___String______convertdoubletochar____D__AR_C, double ___val___, doub
 }
 #endif
 
+#ifdef D___System______deepArrayCopy____L___Object____L___Object___
+void deepArrayCopy(struct ___Object___ * dst, struct ___Object___ * src) {
+  int dsttype=((int *)dst)[0];
+  int srctype=((int *)src)[0];
+  if (dsttype<NUMCLASSES||srctype<NUMCLASSES||srctype!=dsttype)
+    return;
+  struct ArrayObject *aodst=(struct ArrayObject *)dst;
+  struct ArrayObject *aosrc=(struct ArrayObject *)src;
+  int dstlength=aodst->___length___;
+  int srclength=aosrc->___length___;
+  if (dstlength!=srclength)
+    return;
+  unsigned INTPTR *pointer=pointerarray[srctype];
+  if (pointer==0) {
+    int elementsize=classsize[srctype];
+    int size=srclength*elementsize;
+    //primitives
+    memcpy(((char *)&aodst->___length___)+sizeof(int) , ((char *)&aosrc->___length___)+sizeof(int), size);
+  } else {
+    //objects
+    int 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);
+      } else {
+       //hit an object
+       ((struct ___Object___ **)(((char*) &aodst->___length___)+sizeof(int)))[i]=ptr;
+      }
+    }
+  }
+}
+
+void CALL02(___System______deepArrayCopy____L___Object____L___Object___, struct ___Object___ * ___dst___, struct ___Object___ * ___src___) {
+  deepArrayCopy(VAR(___dst___), VAR(___src___));
+}
+#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||srctype!=dsttype)
+    return;
+
+  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];
+      int ptrtype=((int *)ptr)[0];
+      //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
+
 void CALL11(___System______exit____I,int ___status___, int ___status___) {
   BAMBOO_EXIT(___status___);
 }
 
+#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___) {
   char* offset=((char *)(&VAR(___array___)->___length___))+sizeof(unsigned int)+sizeof(void *)*___index___;
   memmove(offset, offset+sizeof(void *),(___size___-___index___-1)*sizeof(void *));
 }
+#endif
 
 void CALL11(___System______printI____I,int ___status___, int ___status___) {
   BAMBOO_DEBUGPRINT(0x1111);
   BAMBOO_DEBUGPRINT_REG(___status___);
 }
 
-long CALL00(___System______currentTimeMillis____) {
+long long CALL00(___System______currentTimeMillis____) {
   // not supported in MULTICORE version
   return -1;
 }
index 0bd678e8f0034a1b9a6b991b4e73f82b0d7e3ff8..683c033cd0de0f1cc1ddd765685f048aa0e9cc19 100644 (file)
@@ -81,3 +81,10 @@ float CALL22(___Math______powf____F_F, float ___a___, float ___b___, float ___a_
 float CALL11(___Math______ceilf____F, float ___a___, float ___a___) {
   return ceilf(___a___);
 }
+
+#ifdef MGC
+float CALL22(___Math______IEEEremainder____F_F, float ___a___, float ___b___,  float ___a___, float ___b___) {
+  return fmod(___a___, ___b___);
+}
+
+#endif