< prev index next >

test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP01/ap01t001/ap01t001.cpp

Print this page
rev 52200 : [mq]: spaces


  46 
  47 static volatile int obj_free = 0;
  48 static volatile long obj_count = 0;
  49 
  50 static jlong timeout = 0;
  51 static int user_data = 0;
  52 static const char* DEBUGEE_SIGNATURE = "Lnsk/jvmti/scenarios/allocation/AP01/ap01t001;";
  53 static const jlong DEBUGEE_CLASS_TAG = (jlong)1024;
  54 
  55 void JNICALL
  56 ObjectFree(jvmtiEnv *jvmti_env, jlong tag) {
  57     NSK_DISPLAY1("ObjectFree event received for an object with tag %ld\n\n", (long)tag);
  58     obj_free++;
  59 }
  60 
  61 void JNICALL
  62 VMDeath(jvmtiEnv *jvmti_env, JNIEnv *env) {
  63 
  64     NSK_DISPLAY0("VMDeath event received\n");
  65 
  66     if (obj_free != (EXP_OBJ_NUMBER - 1) ) {
  67         NSK_COMPLAIN2(
  68             "Received unexpected number of ObjectFree events: %d\n"
  69             "\texpected number: %d\n",
  70             obj_free, (EXP_OBJ_NUMBER - 1));
  71         exit(95 + STATUS_FAILED);
  72     }
  73 
  74     exit(95 + PASSED);
  75 }
  76 
  77 jvmtiIterationControl JNICALL
  78 heapObjectCallback(jlong class_tag,
  79                    jlong size,
  80                    jlong* tag_ptr,
  81                    void* user_data) {
  82 
  83     if (class_tag == DEBUGEE_CLASS_TAG) {
  84         obj_count++;
  85     }
  86 
  87     return JVMTI_ITERATION_CONTINUE;
  88 }
  89 
  90 jvmtiIterationControl JNICALL
  91 stackReferenceCallback( jvmtiHeapRootKind root_kind,
  92                         jlong     class_tag,
  93                         jlong     size,
  94                         jlong*    tag_ptr,
  95                         jlong     thread_tag,
  96                         jint      depth,
  97                         jmethodID method,
  98                         jint      slot,
  99                         void*     user_data) {
 100 
 101     if (class_tag == DEBUGEE_CLASS_TAG && *tag_ptr == 0) {
 102         obj_count++;
 103         *tag_ptr = obj_count;
 104     }
 105 
 106     return JVMTI_ITERATION_CONTINUE;
 107 }
 108 
 109 jvmtiIterationControl JNICALL
 110 heapRootCallback( jvmtiHeapRootKind root_kind,
 111                   jlong class_tag,
 112                   jlong size,
 113                   jlong* tag_ptr,
 114                   void* user_data) {
 115 
 116     if (class_tag == DEBUGEE_CLASS_TAG && *tag_ptr == 0) {
 117         obj_count++;
 118         *tag_ptr = obj_count;
 119     }
 120 
 121     return JVMTI_ITERATION_CONTINUE;
 122 }
 123 
 124 jvmtiIterationControl JNICALL
 125 objectReferenceCallback( jvmtiObjectReferenceKind reference_kind,
 126                          jlong  class_tag,
 127                          jlong  size,
 128                          jlong* tag_ptr,
 129                          jlong  referrer_tag,
 130                          jint   referrer_index,
 131                          void*  user_data) {
 132 
 133     if (class_tag == DEBUGEE_CLASS_TAG && *tag_ptr == 0) {
 134         obj_count++;
 135         *tag_ptr = obj_count;
 136     }
 137 
 138     return JVMTI_ITERATION_CONTINUE;
 139 }
 140 
 141 
 142 /************************/
 143 
 144 JNIEXPORT jobject JNICALL
 145 Java_nsk_jvmti_scenarios_allocation_AP01_ap01t001_newObject( JNIEnv* jni, jclass cls ) {
 146     jmethodID cid;
 147     jobject result;
 148 
 149     if (!NSK_JNI_VERIFY(jni, (cid = jni->GetMethodID(cls, "<init>", "()V" )) != NULL)) {
 150          NSK_COMPLAIN0("newObject: GetMethodID returned NULL\n\n");
 151          nsk_jvmti_setFailStatus();
 152          return NULL;
 153     }
 154 
 155     if (!NSK_JNI_VERIFY(jni, ( result = jni->NewObject(cls, cid)) != NULL)) {
 156 
 157          NSK_COMPLAIN0("newObject: NewObject returned NULL\n\n");
 158          nsk_jvmti_setFailStatus();
 159          return NULL;
 160     }
 161 
 162     return result;
 163 }
 164 
 165 JNIEXPORT jobject JNICALL
 166 Java_nsk_jvmti_scenarios_allocation_AP01_ap01t001_allocObject( JNIEnv* jni, jclass cls ) {
 167     jmethodID cid;
 168     jobject result;
 169 
 170     if (!NSK_JNI_VERIFY(jni, ( cid = jni->GetMethodID(cls, "<init>", "()V" )) != NULL)) {
 171 
 172          NSK_COMPLAIN0("allocObject: GetMethodID returned NULL\n\n");
 173          nsk_jvmti_setFailStatus();
 174          return NULL;
 175     }
 176 
 177     if (!NSK_JNI_VERIFY(jni, ( result = jni->AllocObject(cls)) != NULL)) {
 178 
 179          NSK_COMPLAIN0("allocObject: AllocObject returned NULL\n\n");
 180          nsk_jvmti_setFailStatus();
 181          return NULL;
 182     }
 183 
 184     if (!NSK_JNI_VERIFY_VOID(jni,jni->CallNonvirtualVoidMethod(result, cls, cid))) {
 185 
 186          NSK_COMPLAIN0("newObject: CallNonvirtualVoidMethod failed\n\n");
 187          nsk_jvmti_setFailStatus();
 188          return NULL;
 189     }
 190 
 191     return result;
 192 }
 193 
 194 static void JNICALL
 195 agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) {
 196 
 197     jclass debugeeClass = NULL;




  46 
  47 static volatile int obj_free = 0;
  48 static volatile long obj_count = 0;
  49 
  50 static jlong timeout = 0;
  51 static int user_data = 0;
  52 static const char* DEBUGEE_SIGNATURE = "Lnsk/jvmti/scenarios/allocation/AP01/ap01t001;";
  53 static const jlong DEBUGEE_CLASS_TAG = (jlong)1024;
  54 
  55 void JNICALL
  56 ObjectFree(jvmtiEnv *jvmti_env, jlong tag) {
  57     NSK_DISPLAY1("ObjectFree event received for an object with tag %ld\n\n", (long)tag);
  58     obj_free++;
  59 }
  60 
  61 void JNICALL
  62 VMDeath(jvmtiEnv *jvmti_env, JNIEnv *env) {
  63 
  64     NSK_DISPLAY0("VMDeath event received\n");
  65 
  66     if (obj_free != (EXP_OBJ_NUMBER - 1)) {
  67         NSK_COMPLAIN2(
  68             "Received unexpected number of ObjectFree events: %d\n"
  69             "\texpected number: %d\n",
  70             obj_free, (EXP_OBJ_NUMBER - 1));
  71         exit(95 + STATUS_FAILED);
  72     }
  73 
  74     exit(95 + PASSED);
  75 }
  76 
  77 jvmtiIterationControl JNICALL
  78 heapObjectCallback(jlong class_tag,
  79                    jlong size,
  80                    jlong* tag_ptr,
  81                    void* user_data) {
  82 
  83     if (class_tag == DEBUGEE_CLASS_TAG) {
  84         obj_count++;
  85     }
  86 
  87     return JVMTI_ITERATION_CONTINUE;
  88 }
  89 
  90 jvmtiIterationControl JNICALL
  91 stackReferenceCallback(jvmtiHeapRootKind root_kind,
  92                        jlong     class_tag,
  93                        jlong     size,
  94                        jlong*    tag_ptr,
  95                        jlong     thread_tag,
  96                        jint      depth,
  97                        jmethodID method,
  98                        jint      slot,
  99                        void*     user_data) {
 100 
 101     if (class_tag == DEBUGEE_CLASS_TAG && *tag_ptr == 0) {
 102         obj_count++;
 103         *tag_ptr = obj_count;
 104     }
 105 
 106     return JVMTI_ITERATION_CONTINUE;
 107 }
 108 
 109 jvmtiIterationControl JNICALL
 110 heapRootCallback(jvmtiHeapRootKind root_kind,
 111                  jlong class_tag,
 112                  jlong size,
 113                  jlong* tag_ptr,
 114                  void* user_data) {
 115 
 116     if (class_tag == DEBUGEE_CLASS_TAG && *tag_ptr == 0) {
 117         obj_count++;
 118         *tag_ptr = obj_count;
 119     }
 120 
 121     return JVMTI_ITERATION_CONTINUE;
 122 }
 123 
 124 jvmtiIterationControl JNICALL
 125 objectReferenceCallback(jvmtiObjectReferenceKind reference_kind,
 126                         jlong  class_tag,
 127                         jlong  size,
 128                         jlong* tag_ptr,
 129                         jlong  referrer_tag,
 130                         jint   referrer_index,
 131                         void*  user_data) {
 132 
 133     if (class_tag == DEBUGEE_CLASS_TAG && *tag_ptr == 0) {
 134         obj_count++;
 135         *tag_ptr = obj_count;
 136     }
 137 
 138     return JVMTI_ITERATION_CONTINUE;
 139 }
 140 
 141 
 142 /************************/
 143 
 144 JNIEXPORT jobject JNICALL
 145 Java_nsk_jvmti_scenarios_allocation_AP01_ap01t001_newObject(JNIEnv* jni, jclass cls) {
 146     jmethodID cid;
 147     jobject result;
 148 
 149     if (!NSK_JNI_VERIFY(jni, (cid = jni->GetMethodID(cls, "<init>", "()V")) != NULL)) {
 150          NSK_COMPLAIN0("newObject: GetMethodID returned NULL\n\n");
 151          nsk_jvmti_setFailStatus();
 152          return NULL;
 153     }
 154 
 155     if (!NSK_JNI_VERIFY(jni, (result = jni->NewObject(cls, cid)) != NULL)) {
 156 
 157          NSK_COMPLAIN0("newObject: NewObject returned NULL\n\n");
 158          nsk_jvmti_setFailStatus();
 159          return NULL;
 160     }
 161 
 162     return result;
 163 }
 164 
 165 JNIEXPORT jobject JNICALL
 166 Java_nsk_jvmti_scenarios_allocation_AP01_ap01t001_allocObject(JNIEnv* jni, jclass cls) {
 167     jmethodID cid;
 168     jobject result;
 169 
 170     if (!NSK_JNI_VERIFY(jni, (cid = jni->GetMethodID(cls, "<init>", "()V")) != NULL)) {
 171 
 172          NSK_COMPLAIN0("allocObject: GetMethodID returned NULL\n\n");
 173          nsk_jvmti_setFailStatus();
 174          return NULL;
 175     }
 176 
 177     if (!NSK_JNI_VERIFY(jni, (result = jni->AllocObject(cls)) != NULL)) {
 178 
 179          NSK_COMPLAIN0("allocObject: AllocObject returned NULL\n\n");
 180          nsk_jvmti_setFailStatus();
 181          return NULL;
 182     }
 183 
 184     if (!NSK_JNI_VERIFY_VOID(jni,jni->CallNonvirtualVoidMethod(result, cls, cid))) {
 185 
 186          NSK_COMPLAIN0("newObject: CallNonvirtualVoidMethod failed\n\n");
 187          nsk_jvmti_setFailStatus();
 188          return NULL;
 189     }
 190 
 191     return result;
 192 }
 193 
 194 static void JNICALL
 195 agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) {
 196 
 197     jclass debugeeClass = NULL;


< prev index next >