< prev index next >

test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateOverObjectsReachableFromObject/iterobjreachobj004/iterobjreachobj004.cpp

Print this page
rev 52200 : [mq]: spaces


  25 #include "jvmti.h"
  26 #include "agent_common.h"
  27 #include "jni_tools.h"
  28 #include "jvmti_tools.h"
  29 
  30 extern "C" {
  31 
  32 /* ============================================================================= */
  33 
  34 static jlong timeout = 0;
  35 static int fakeUserData = 0, objCounter = 0;
  36 static jvmtiEnv* st_jvmti = NULL;
  37 static const char *storage_data = "local_storage_data";
  38 static void *storage_ptr = NULL;
  39 static const char* debugeeClassSignature = "Lnsk/jvmti/IterateOverObjectsReachableFromObject/iterobjreachobj004;";
  40 static const char* objectFieldName = "object";
  41 
  42 /* ============================================================================= */
  43 
  44 jvmtiIterationControl JNICALL
  45 objectReferenceCallback( jvmtiObjectReferenceKind reference_kind,
  46                          jlong  class_tag,
  47                          jlong  size,
  48                          jlong* tag_ptr,
  49                          jlong  referrer_tag,
  50                          jint   referrer_index,
  51                          void*  user_data) {
  52 
  53     objCounter++;
  54 
  55     if (!NSK_JVMTI_VERIFY(st_jvmti->SetEnvironmentLocalStorage(storage_data))) {
  56         nsk_jvmti_setFailStatus();
  57     }
  58 
  59     if (!NSK_JVMTI_VERIFY(st_jvmti->GetEnvironmentLocalStorage(&storage_ptr))) {
  60         nsk_jvmti_setFailStatus();
  61     }
  62 
  63     /*  Iterate over only first object */
  64     return JVMTI_ITERATION_ABORT;
  65 }
  66 
  67 /* ============================================================================= */
  68 
  69 /** Agent algorithm. */
  70 static void JNICALL
  71 agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) {


  98                 jni->GetStaticObjectField(debugeeClass, objectField)) != NULL)) {
  99             nsk_jvmti_setFailStatus();
 100             break;
 101         }
 102 
 103         NSK_DISPLAY0("Calling IterateOverObjectsReachableFromObject with filter JVMTI_HEAP_OBJECT_EITHER\n");
 104         {
 105             if (!NSK_JVMTI_VERIFY(jvmti->IterateOverObjectsReachableFromObject(
 106                   object, objectReferenceCallback, &fakeUserData))) {
 107                 nsk_jvmti_setFailStatus();
 108             }
 109         }
 110 
 111         if (objCounter == 0) {
 112             NSK_COMPLAIN0("IterateOverObjectsReachableFromObject call had not visited any object\n");
 113             nsk_jvmti_setFailStatus();
 114         }
 115 
 116         if (storage_data != storage_ptr) {
 117             NSK_COMPLAIN2("Local storage address was corrupted: %p ,\n\texpected value: %p\n",
 118                              storage_ptr, storage_data);
 119             nsk_jvmti_setFailStatus();
 120         }
 121 
 122         if (strcmp(storage_data, (char *)storage_ptr) != 0) {
 123             NSK_COMPLAIN2("Local storage was corrupted: %s ,\n\texpected value: %s\n",
 124                              (char *)storage_ptr, storage_data );
 125             nsk_jvmti_setFailStatus();
 126         }
 127     } while (0);
 128 
 129     NSK_DISPLAY0("Let debugee to finish\n");
 130     if (!NSK_VERIFY(nsk_jvmti_resumeSync()))
 131         return;
 132 }
 133 
 134 /* ============================================================================= */
 135 
 136 /** Agent library initialization. */
 137 #ifdef STATIC_BUILD
 138 JNIEXPORT jint JNICALL Agent_OnLoad_iterobjreachobj004(JavaVM *jvm, char *options, void *reserved) {
 139     return Agent_Initialize(jvm, options, reserved);
 140 }
 141 JNIEXPORT jint JNICALL Agent_OnAttach_iterobjreachobj004(JavaVM *jvm, char *options, void *reserved) {
 142     return Agent_Initialize(jvm, options, reserved);
 143 }
 144 JNIEXPORT jint JNI_OnLoad_iterobjreachobj004(JavaVM *jvm, char *options, void *reserved) {




  25 #include "jvmti.h"
  26 #include "agent_common.h"
  27 #include "jni_tools.h"
  28 #include "jvmti_tools.h"
  29 
  30 extern "C" {
  31 
  32 /* ============================================================================= */
  33 
  34 static jlong timeout = 0;
  35 static int fakeUserData = 0, objCounter = 0;
  36 static jvmtiEnv* st_jvmti = NULL;
  37 static const char *storage_data = "local_storage_data";
  38 static void *storage_ptr = NULL;
  39 static const char* debugeeClassSignature = "Lnsk/jvmti/IterateOverObjectsReachableFromObject/iterobjreachobj004;";
  40 static const char* objectFieldName = "object";
  41 
  42 /* ============================================================================= */
  43 
  44 jvmtiIterationControl JNICALL
  45 objectReferenceCallback(jvmtiObjectReferenceKind reference_kind,
  46                         jlong  class_tag,
  47                         jlong  size,
  48                         jlong* tag_ptr,
  49                         jlong  referrer_tag,
  50                         jint   referrer_index,
  51                         void*  user_data) {
  52 
  53     objCounter++;
  54 
  55     if (!NSK_JVMTI_VERIFY(st_jvmti->SetEnvironmentLocalStorage(storage_data))) {
  56         nsk_jvmti_setFailStatus();
  57     }
  58 
  59     if (!NSK_JVMTI_VERIFY(st_jvmti->GetEnvironmentLocalStorage(&storage_ptr))) {
  60         nsk_jvmti_setFailStatus();
  61     }
  62 
  63     /*  Iterate over only first object */
  64     return JVMTI_ITERATION_ABORT;
  65 }
  66 
  67 /* ============================================================================= */
  68 
  69 /** Agent algorithm. */
  70 static void JNICALL
  71 agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) {


  98                 jni->GetStaticObjectField(debugeeClass, objectField)) != NULL)) {
  99             nsk_jvmti_setFailStatus();
 100             break;
 101         }
 102 
 103         NSK_DISPLAY0("Calling IterateOverObjectsReachableFromObject with filter JVMTI_HEAP_OBJECT_EITHER\n");
 104         {
 105             if (!NSK_JVMTI_VERIFY(jvmti->IterateOverObjectsReachableFromObject(
 106                   object, objectReferenceCallback, &fakeUserData))) {
 107                 nsk_jvmti_setFailStatus();
 108             }
 109         }
 110 
 111         if (objCounter == 0) {
 112             NSK_COMPLAIN0("IterateOverObjectsReachableFromObject call had not visited any object\n");
 113             nsk_jvmti_setFailStatus();
 114         }
 115 
 116         if (storage_data != storage_ptr) {
 117             NSK_COMPLAIN2("Local storage address was corrupted: %p ,\n\texpected value: %p\n",
 118                           storage_ptr, storage_data);
 119             nsk_jvmti_setFailStatus();
 120         }
 121 
 122         if (strcmp(storage_data, (char *)storage_ptr) != 0) {
 123             NSK_COMPLAIN2("Local storage was corrupted: %s ,\n\texpected value: %s\n",
 124                           (char *)storage_ptr, storage_data);
 125             nsk_jvmti_setFailStatus();
 126         }
 127     } while (0);
 128 
 129     NSK_DISPLAY0("Let debugee to finish\n");
 130     if (!NSK_VERIFY(nsk_jvmti_resumeSync()))
 131         return;
 132 }
 133 
 134 /* ============================================================================= */
 135 
 136 /** Agent library initialization. */
 137 #ifdef STATIC_BUILD
 138 JNIEXPORT jint JNICALL Agent_OnLoad_iterobjreachobj004(JavaVM *jvm, char *options, void *reserved) {
 139     return Agent_Initialize(jvm, options, reserved);
 140 }
 141 JNIEXPORT jint JNICALL Agent_OnAttach_iterobjreachobj004(JavaVM *jvm, char *options, void *reserved) {
 142     return Agent_Initialize(jvm, options, reserved);
 143 }
 144 JNIEXPORT jint JNI_OnLoad_iterobjreachobj004(JavaVM *jvm, char *options, void *reserved) {


< prev index next >