rootscanstest.c

来自「This is a resource based on j2me embedde」· C语言 代码 · 共 423 行 · 第 1/2 页

C
423
字号
          afterGC[17] = CVMID_icellDirect(ee, boolICell);          afterGC[18] = CVMID_icellDirect(ee, exceptionICell);          afterGC[19] = CVMID_icellDirect(ee, threadICell);          afterGC[20] = CVMID_icellDirect(ee, intArrayICell);          afterGC[21] = CVMID_icellDirect(ee, floatArrayICell);          afterGC[22] = CVMID_icellDirect(ee, lObjICell);          afterGC[23] = CVMID_icellDirect(ee, lExceptionICell);          afterGC[24] = CVMID_icellDirect(ee, stringICell);          afterGC[25] = (CVMObject *) CVMID_icellDirect(ee, charArrayICell);          afterGC[26] = (CVMObject *) CVMID_icellDirect(ee, refArrayICell);          for(i=0; i < 27; i++) {             if(beforeGC[i] == afterGC[i])                ++failCount;          }      });   }CVMID_localrootEnd();   if(failCount)      printf("FAIL: RootScansTest1, All roots were not scanned\n");   else      printf("PASS: RootScansTest1, All roots were scanned\n");}JNIEXPORT void JNICALLJava_RootScansTest_scanRootsTest2(JNIEnv *env, jobject thisObj) {   jbyteArray byteArray;   jshortArray shortArray;   jintArray intArray;   jlongArray longArray;   jfloatArray floatArray;   jdoubleArray doubleArray;   jcharArray charArray;   jbooleanArray boolArray;   jmethodID mid1, mid2;   static jobject savedRef;   jclass clazz, iclazz, fclazz, sclazz, lclazz;   jclass dclazz, bclazz, shclazz, blclazz;   jobject iobj, fobj, sobj, lobj;   jobject dobj, bobj, shobj, blobj;   jobject ilref, flref, slref, llref;   jobject dlref, blref, shlref, bllref;   jobject igref, fgref, sgref, lgref;   jobject dgref, bgref, shgref, blgref;   jobject iwref, fwref, swref, lwref;   jobject dwref, bwref, shwref, blwref;   jobjectArray iarr, farr, sarr, larr;   jobjectArray darr, barr, sharr, blarr;   jobject obj;   CVMExecEnv *ee;   CVMObjectICell *objICell;   CVMClassICell *classICell;   CVMThreadICell *threadICell;      #ifndef CVM_DEBUG_ASSERTS      printf("UNRESOLVED: RootScansTest2, can be tested only when debug is turned on");      return;   #endif   ee = CVMjniEnv2ExecEnv(env);   clazz = (*env)->FindClass(env, "RootScansTest");   mid1 = (*env)->GetMethodID(env, clazz, "<init>", "()V");   mid2 = (*env)->GetMethodID(env, clazz, "createJavaRoots", "()V");   obj = (*env)->NewObject(env, clazz, mid1);   iclazz = (*env)->FindClass(env, "java/lang/Integer");   fclazz = (*env)->FindClass(env, "java/lang/Float");   sclazz = (*env)->FindClass(env, "java/lang/String");   lclazz = (*env)->FindClass(env, "java/lang/Long");   dclazz = (*env)->FindClass(env, "java/lang/Double");   bclazz = (*env)->FindClass(env, "java/lang/Byte");   shclazz = (*env)->FindClass(env, "java/lang/Short");   blclazz = (*env)->FindClass(env, "java/lang/Boolean");   /* Create JNI local refs */   byteArray = (*env)->NewByteArray(env, 10);   shortArray = (*env)->NewShortArray(env, 10);   intArray = (*env)->NewIntArray(env, 10);   longArray = (*env)->NewLongArray(env, 10);   floatArray = (*env)->NewFloatArray(env, 10);   doubleArray = (*env)->NewDoubleArray(env, 10);   charArray = (*env)->NewCharArray(env, 10);   boolArray = (*env)->NewBooleanArray(env, 10);   iarr = (*env)->NewObjectArray(env, 3, iclazz, NULL);   farr = (*env)->NewObjectArray(env, 3, fclazz, NULL);   sarr = (*env)->NewObjectArray(env, 3, sclazz, NULL);   larr = (*env)->NewObjectArray(env, 3, lclazz, NULL);   darr = (*env)->NewObjectArray(env, 3, dclazz, NULL);   barr = (*env)->NewObjectArray(env, 3, bclazz, NULL);   sharr = (*env)->NewObjectArray(env, 3, shclazz, NULL);   blarr = (*env)->NewObjectArray(env, 3, blclazz, NULL);   iobj = (*env)->AllocObject(env, iclazz);   fobj = (*env)->AllocObject(env, fclazz);   sobj = (*env)->AllocObject(env, sclazz);   lobj = (*env)->AllocObject(env, lclazz);   dobj = (*env)->AllocObject(env, dclazz);   bobj = (*env)->AllocObject(env, bclazz);   shobj = (*env)->AllocObject(env, shclazz);   blobj = (*env)->AllocObject(env, blclazz);   ilref = (*env)->NewLocalRef(env, iobj);   flref = (*env)->NewLocalRef(env, fobj);   slref = (*env)->NewLocalRef(env, sobj);   llref = (*env)->NewLocalRef(env, lobj);   dlref = (*env)->NewLocalRef(env, dobj);   blref = (*env)->NewLocalRef(env, bobj);   shlref = (*env)->NewLocalRef(env, shobj);   bllref = (*env)->NewLocalRef(env, blobj);   /* Create JNI Global and Weak Global Refs */   savedRef = (*env)->NewGlobalRef(env, thisObj);   igref = (*env)->NewGlobalRef(env, iobj);   fgref = (*env)->NewGlobalRef(env, fobj);   sgref = (*env)->NewGlobalRef(env, sobj);   lgref = (*env)->NewGlobalRef(env, lobj);   dgref = (*env)->NewGlobalRef(env, dobj);   bgref = (*env)->NewGlobalRef(env, bobj);   shgref = (*env)->NewGlobalRef(env, shobj);   blgref = (*env)->NewGlobalRef(env, blobj);   iwref = (*env)->NewWeakGlobalRef(env, iobj);   fwref = (*env)->NewWeakGlobalRef(env, fobj);   swref = (*env)->NewWeakGlobalRef(env, sobj);   lwref = (*env)->NewWeakGlobalRef(env, lobj);   dwref = (*env)->NewWeakGlobalRef(env, dobj);   bwref = (*env)->NewWeakGlobalRef(env, bobj);   shwref = (*env)->NewWeakGlobalRef(env, shobj);   blwref = (*env)->NewWeakGlobalRef(env, blobj);   /* Create Global CVM roots */   objICell = CVMID_getGlobalRoot(ee);   threadICell = CVMID_getGlobalRoot(ee);   classICell = CVMID_getGlobalRoot(ee);   CVMID_allocNewInstance(ee,         (CVMClassBlock*)CVMsystemClass(java_lang_Object), objICell);   CVMID_allocNewInstance(ee,         (CVMClassBlock*)CVMsystemClass(java_lang_Thread), threadICell);   CVMID_allocNewInstance(ee,         (CVMClassBlock*)CVMsystemClass(java_lang_Object), classICell);   /* Create CVM local roots */   CVMID_localrootBegin(ee);{      CVMID_localrootDeclare(CVMObjectICell, lObjICell);      CVMID_localrootDeclare(CVMThrowableICell, exceptionICell);      CVMID_localrootDeclare(CVMStringICell, stringICell);      CVMID_localrootDeclare(CVMArrayOfCharICell, charArrayICell);      CVMID_localrootDeclare(CVMArrayOfRefICell, rootArray);      CVMID_allocNewInstance(ee,            (CVMClassBlock*)CVMsystemClass(java_lang_Object), lObjICell);      CVMID_allocNewInstance(ee,            (CVMClassBlock*)CVMsystemClass(java_lang_Exception), exceptionICell);      CVMID_allocNewInstance(ee,            (CVMClassBlock*)CVMsystemClass(java_lang_String), stringICell);      CVMID_allocNewArray(ee, CVM_T_CHAR,            (CVMClassBlock*)CVMbasicTypeArrayClassblocks[CVM_T_CHAR],            10, (CVMObjectICell*)charArrayICell);      CVMID_allocNewArray(ee, CVM_T_CLASS,            (CVMClassBlock*) CVMbasicTypeArrayClassblocks[CVM_T_CLASS],            1, (CVMObjectICell*)rootArray);         /* Create Java Roots */      (*env)->CallVoidMethod(env, obj, mid2);   } CVMID_localrootEnd();   /* Free JNI Global Roots */   (*env)->DeleteGlobalRef(env, igref);   (*env)->DeleteGlobalRef(env, fgref);   (*env)->DeleteGlobalRef(env, sgref);   (*env)->DeleteGlobalRef(env, lgref);   (*env)->DeleteGlobalRef(env, dgref);   (*env)->DeleteGlobalRef(env, bgref);   (*env)->DeleteGlobalRef(env, shgref);   (*env)->DeleteGlobalRef(env, blgref);   (*env)->DeleteWeakGlobalRef(env, iwref);   (*env)->DeleteWeakGlobalRef(env, fwref);   (*env)->DeleteWeakGlobalRef(env, swref);   (*env)->DeleteWeakGlobalRef(env, lwref);   (*env)->DeleteWeakGlobalRef(env, dwref);   (*env)->DeleteWeakGlobalRef(env, bwref);   (*env)->DeleteWeakGlobalRef(env, shwref);   (*env)->DeleteWeakGlobalRef(env, blwref);   /* Free CVM Global Roots */   CVMID_freeGlobalRoot(ee, objICell);   CVMID_freeGlobalRoot(ee, threadICell);   CVMID_freeGlobalRoot(ee, classICell);   printf("PASS: RootScansTest2, All roots were scanned only once\n");}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?