< prev index next >

test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP05/ap05t002/ap05t002.cpp

Print this page
rev 52215 : 8212770: Remove spaces before/after () for vmTestbase/jvmti/[s-u]
Summary:
Reviewed-by:


  31 #include "JVMTITools.h"
  32 #include "jvmti_tools.h"
  33 
  34 extern "C" {
  35 
  36 #define EXP_OBJ_NUMBER 1
  37 
  38 static JNIEnv *jni = NULL;
  39 static jvmtiEnv *jvmti = NULL;
  40 static jvmtiEventCallbacks callbacks;
  41 static jvmtiCapabilities caps;
  42 
  43 static jlong timeout = 0;
  44 static jobject referrer = NULL;
  45 static const char* SUBCLASS_SIGNATURE   = "Lnsk/jvmti/scenarios/allocation/AP05/ap05t002Subclass;";
  46 static const long  TAG1 = 1l, TAG2 = 2l;
  47 static int caseNumber = 0, forthRef = 0, backRef = 0;
  48 
  49 /* jvmtiHeapRootCallback */
  50 jvmtiIterationControl JNICALL
  51 heapRootCallback( jvmtiHeapRootKind root_kind,
  52                   jlong class_tag,
  53                   jlong size,
  54                   jlong* tag_ptr,
  55                   void* user_data) {
  56     return JVMTI_ITERATION_CONTINUE;
  57 }
  58 
  59 /* jvmtiStackReferenceCallback */
  60 jvmtiIterationControl JNICALL
  61 stackReferenceCallback( jvmtiHeapRootKind root_kind,
  62                         jlong     class_tag,
  63                         jlong     size,
  64                         jlong*    tag_ptr,
  65                         jlong     thread_tag,
  66                         jint      depth,
  67                         jmethodID method,
  68                         jint      slot,
  69                         void*     user_data) {
  70     return JVMTI_ITERATION_CONTINUE;
  71 }
  72 
  73 
  74 /* jvmtiObjectReferenceCallback */
  75 jvmtiIterationControl JNICALL
  76 objectReferenceCallback( jvmtiObjectReferenceKind reference_kind,
  77                          jlong  class_tag,
  78                          jlong  size,
  79                          jlong* tag_ptr,
  80                          jlong  referrer_tag,
  81                          jint   referrer_index,
  82                          void*  user_data) {
  83 
  84     if (*tag_ptr != 0 && referrer_tag != 0) {
  85         NSK_DISPLAY4("objectReferenceCallback: reference kind=%s, referrer_index=%d, referrer_tag=%d, referree_tag=%d\n",
  86             TranslateObjectRefKind(reference_kind), (int)referrer_index, (long)referrer_tag, (long)*tag_ptr);
  87 
  88         if (*tag_ptr == TAG1 && referrer_tag == TAG2) {
  89             forthRef++;
  90         } else if (*tag_ptr == TAG2 && referrer_tag == TAG1) {
  91             backRef++;
  92         }
  93     }
  94     return JVMTI_ITERATION_CONTINUE;
  95 }
  96 
  97 
  98 /************************/
  99 
 100 JNIEXPORT void JNICALL
 101 Java_nsk_jvmti_scenarios_allocation_AP05_ap05t002_setTag( JNIEnv* jni,
 102                                                           jobject obj,
 103                                                           jobject target,
 104                                                           jlong   tag ) {
 105 
 106     if (!NSK_JVMTI_VERIFY(jvmti->SetTag(target, tag))) {
 107         nsk_jvmti_setFailStatus();
 108     }
 109 }
 110 
 111 JNIEXPORT void JNICALL
 112 Java_nsk_jvmti_scenarios_allocation_AP05_ap05t002_setReferrer( JNIEnv* jni, jclass klass, jobject ref, jint caseNum) {
 113     caseNumber = caseNum;
 114     if (!NSK_JNI_VERIFY(jni, (referrer = jni->NewGlobalRef(ref)) != NULL))
 115         nsk_jvmti_setFailStatus();
 116 }
 117 
 118 static void runCase() {
 119     NSK_DISPLAY0("\nCalling IterateOverReachableObjects\n");
 120     forthRef = 0;
 121     backRef = 0;
 122     if (!NSK_JVMTI_VERIFY(jvmti->IterateOverReachableObjects(heapRootCallback,
 123                                                              stackReferenceCallback,
 124                                                              objectReferenceCallback,
 125                                                              NULL /*user_data*/))) {
 126         nsk_jvmti_setFailStatus();
 127     }
 128     if (forthRef != 1) {
 129         NSK_COMPLAIN1("IterateOverReachableObjects found unexpected number of references\n\t"
 130               "from referrer to referree; found: %d, expected: 1\n\n", forthRef);
 131         nsk_jvmti_setFailStatus();
 132     }




  31 #include "JVMTITools.h"
  32 #include "jvmti_tools.h"
  33 
  34 extern "C" {
  35 
  36 #define EXP_OBJ_NUMBER 1
  37 
  38 static JNIEnv *jni = NULL;
  39 static jvmtiEnv *jvmti = NULL;
  40 static jvmtiEventCallbacks callbacks;
  41 static jvmtiCapabilities caps;
  42 
  43 static jlong timeout = 0;
  44 static jobject referrer = NULL;
  45 static const char* SUBCLASS_SIGNATURE   = "Lnsk/jvmti/scenarios/allocation/AP05/ap05t002Subclass;";
  46 static const long  TAG1 = 1l, TAG2 = 2l;
  47 static int caseNumber = 0, forthRef = 0, backRef = 0;
  48 
  49 /* jvmtiHeapRootCallback */
  50 jvmtiIterationControl JNICALL
  51 heapRootCallback(jvmtiHeapRootKind root_kind,
  52                   jlong class_tag,
  53                   jlong size,
  54                   jlong* tag_ptr,
  55                   void* user_data) {
  56     return JVMTI_ITERATION_CONTINUE;
  57 }
  58 
  59 /* jvmtiStackReferenceCallback */
  60 jvmtiIterationControl JNICALL
  61 stackReferenceCallback(jvmtiHeapRootKind root_kind,
  62                        jlong     class_tag,
  63                        jlong     size,
  64                        jlong*    tag_ptr,
  65                        jlong     thread_tag,
  66                        jint      depth,
  67                        jmethodID method,
  68                        jint      slot,
  69                        void*     user_data) {
  70     return JVMTI_ITERATION_CONTINUE;
  71 }
  72 
  73 
  74 /* jvmtiObjectReferenceCallback */
  75 jvmtiIterationControl JNICALL
  76 objectReferenceCallback(jvmtiObjectReferenceKind reference_kind,
  77                         jlong  class_tag,
  78                         jlong  size,
  79                         jlong* tag_ptr,
  80                         jlong  referrer_tag,
  81                         jint   referrer_index,
  82                         void*  user_data) {
  83 
  84     if (*tag_ptr != 0 && referrer_tag != 0) {
  85         NSK_DISPLAY4("objectReferenceCallback: reference kind=%s, referrer_index=%d, referrer_tag=%d, referree_tag=%d\n",
  86             TranslateObjectRefKind(reference_kind), (int)referrer_index, (long)referrer_tag, (long)*tag_ptr);
  87 
  88         if (*tag_ptr == TAG1 && referrer_tag == TAG2) {
  89             forthRef++;
  90         } else if (*tag_ptr == TAG2 && referrer_tag == TAG1) {
  91             backRef++;
  92         }
  93     }
  94     return JVMTI_ITERATION_CONTINUE;
  95 }
  96 
  97 
  98 /************************/
  99 
 100 JNIEXPORT void JNICALL
 101 Java_nsk_jvmti_scenarios_allocation_AP05_ap05t002_setTag(JNIEnv* jni,
 102                                                          jobject obj,
 103                                                          jobject target,
 104                                                          jlong   tag) {
 105 
 106     if (!NSK_JVMTI_VERIFY(jvmti->SetTag(target, tag))) {
 107         nsk_jvmti_setFailStatus();
 108     }
 109 }
 110 
 111 JNIEXPORT void JNICALL
 112 Java_nsk_jvmti_scenarios_allocation_AP05_ap05t002_setReferrer(JNIEnv* jni, jclass klass, jobject ref, jint caseNum) {
 113     caseNumber = caseNum;
 114     if (!NSK_JNI_VERIFY(jni, (referrer = jni->NewGlobalRef(ref)) != NULL))
 115         nsk_jvmti_setFailStatus();
 116 }
 117 
 118 static void runCase() {
 119     NSK_DISPLAY0("\nCalling IterateOverReachableObjects\n");
 120     forthRef = 0;
 121     backRef = 0;
 122     if (!NSK_JVMTI_VERIFY(jvmti->IterateOverReachableObjects(heapRootCallback,
 123                                                              stackReferenceCallback,
 124                                                              objectReferenceCallback,
 125                                                              NULL /*user_data*/))) {
 126         nsk_jvmti_setFailStatus();
 127     }
 128     if (forthRef != 1) {
 129         NSK_COMPLAIN1("IterateOverReachableObjects found unexpected number of references\n\t"
 130               "from referrer to referree; found: %d, expected: 1\n\n", forthRef);
 131         nsk_jvmti_setFailStatus();
 132     }


< prev index next >