< prev index next >

test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/GetLocalVariable/getlocal004/getlocal004.cpp

Print this page
rev 51722 : 8210700: Clean up JNI_ENV_ARG and factorize the macros for vmTestbase/jvmti/unit tests
Summary:
Reviewed-by:


  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  */
  26 
  27 #include <stdio.h>
  28 #include <string.h>
  29 #include "jvmti.h"
  30 #include "jni_tools.h"
  31 #include "agent_common.h"
  32 #include "JVMTITools.h"
  33 
  34 #ifdef __cplusplus
  35 extern "C" {
  36 #endif
  37 
  38 #ifndef JNI_ENV_ARG
  39 
  40 #ifdef __cplusplus
  41 #define JNI_ENV_ARG(x, y) y
  42 #define JNI_ENV_PTR(x) x
  43 #else
  44 #define JNI_ENV_ARG(x,y) x, y
  45 #define JNI_ENV_PTR(x) (*x)
  46 #endif
  47 
  48 #endif
  49 
  50 #define PASSED 0
  51 #define STATUS_FAILED 2
  52 
  53 static jvmtiEnv *jvmti = NULL;
  54 static jvmtiCapabilities caps;
  55 static jint result = PASSED;
  56 static jboolean printdump = JNI_FALSE;
  57 static jmethodID mid = NULL;
  58 
  59 void print_LocalVariableEntry(jvmtiLocalVariableEntry *lvt_elem) {
  60   printf("\n Var name: %s, slot: %d", lvt_elem->name, lvt_elem->slot);
  61   printf(", start_bci: %" LL "d", lvt_elem->start_location);
  62   printf(", end_bci: %" LL "d",   lvt_elem->start_location + lvt_elem->length);
  63   printf(", signature: %s\n", lvt_elem->signature);
  64 }
  65 
  66 #ifdef STATIC_BUILD
  67 JNIEXPORT jint JNICALL Agent_OnLoad_getlocal004(JavaVM *jvm, char *options, void *reserved) {
  68     return Agent_Initialize(jvm, options, reserved);
  69 }
  70 JNIEXPORT jint JNICALL Agent_OnAttach_getlocal004(JavaVM *jvm, char *options, void *reserved) {
  71     return Agent_Initialize(jvm, options, reserved);
  72 }
  73 JNIEXPORT jint JNI_OnLoad_getlocal004(JavaVM *jvm, char *options, void *reserved) {
  74     return JNI_VERSION_1_8;
  75 }
  76 #endif
  77 jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
  78     jint res;
  79     jvmtiError err;
  80 
  81     if (options != NULL && strcmp(options, "printdump") == 0) {
  82         printdump = JNI_TRUE;
  83     }
  84 
  85     res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti),
  86         JVMTI_VERSION_1_1);
  87     if (res != JNI_OK || jvmti == NULL) {
  88         printf("Wrong result of a valid call to GetEnv!\n");
  89         return JNI_ERR;
  90     }
  91 
  92     err = jvmti->GetPotentialCapabilities(&caps);
  93     if (err != JVMTI_ERROR_NONE) {
  94         printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n",
  95                TranslateError(err), err);
  96         return JNI_ERR;
  97     }
  98 
  99     err = jvmti->AddCapabilities(&caps);
 100     if (err != JVMTI_ERROR_NONE) {
 101         printf("(AddCapabilities) unexpected error: %s (%d)\n",
 102                TranslateError(err), err);
 103         return JNI_ERR;
 104     }
 105 
 106     err = jvmti->GetCapabilities(&caps);


 111     }
 112 
 113     if (!caps.can_access_local_variables) {
 114         printf("Warning: Access to local variables is not implemented\n");
 115     }
 116 
 117     return JNI_OK;
 118 }
 119 
 120 JNIEXPORT void JNICALL
 121 Java_nsk_jvmti_unit_GetLocalVariable_getlocal004_getMeth(JNIEnv *env, jclass cls) {
 122     if (jvmti == NULL) {
 123         printf("JVMTI client was not properly loaded!\n");
 124         result = STATUS_FAILED;
 125         return;
 126     }
 127 
 128     if (!caps.can_access_local_variables ||
 129         !caps.can_generate_method_exit_events) return;
 130 
 131     mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cls),
 132                                               "staticMeth", "(I)I");
 133     if (mid == NULL) {
 134         printf("Cannot find Method ID for staticMeth\n");
 135         result = STATUS_FAILED;
 136         return;
 137     }
 138 
 139     fflush(stdout);
 140 }
 141 
 142 void checkErrorCodeIn(jvmtiError err, jint slot) {
 143     if (err != JVMTI_ERROR_NONE) {
 144         printf(" FAILURE: JVMTI_ERROR_NONE is expected, slot: %d\n\n", slot);
 145         result = STATUS_FAILED;
 146     } else {
 147         printf(" success: JVMTI_ERROR_NONE as expected, slot: %d\n\n", slot);
 148     }
 149 }
 150 
 151 void checkErrorCodeOut(jvmtiError err, jint slot) {
 152     if (err != JVMTI_ERROR_INVALID_SLOT) {


 226             printf(" slot%d: %d\n", slot, locInt);
 227         }
 228 
 229         err = jvmti->GetLocalLong(thr, 1, slot, &locLong);
 230         printf(" GetLocalLong: %s (%d)\n", TranslateError(err), err);
 231         checkErrorCodeOut(err, slot);
 232 
 233         err = jvmti->GetLocalDouble(thr, 1, slot, &locDouble);
 234         printf(" GetLocalDouble: %s (%d)\n", TranslateError(err), err);
 235         checkErrorCodeOut(err, slot);
 236     }
 237 
 238     fflush(stdout);
 239 }
 240 
 241 JNIEXPORT jint JNICALL
 242 Java_nsk_jvmti_unit_GetLocalVariable_getlocal004_getRes(JNIEnv *env, jclass cls) {
 243     return result;
 244 }
 245 
 246 #ifdef __cplusplus
 247 }
 248 #endif


  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  */
  26 
  27 #include <stdio.h>
  28 #include <string.h>
  29 #include "jvmti.h"
  30 #include "jni_tools.h"
  31 #include "agent_common.h"
  32 #include "JVMTITools.h"
  33 

  34 extern "C" {











  35 

  36 
  37 #define PASSED 0
  38 #define STATUS_FAILED 2
  39 
  40 static jvmtiEnv *jvmti = NULL;
  41 static jvmtiCapabilities caps;
  42 static jint result = PASSED;
  43 static jboolean printdump = JNI_FALSE;
  44 static jmethodID mid = NULL;
  45 
  46 void print_LocalVariableEntry(jvmtiLocalVariableEntry *lvt_elem) {
  47   printf("\n Var name: %s, slot: %d", lvt_elem->name, lvt_elem->slot);
  48   printf(", start_bci: %" LL "d", lvt_elem->start_location);
  49   printf(", end_bci: %" LL "d",   lvt_elem->start_location + lvt_elem->length);
  50   printf(", signature: %s\n", lvt_elem->signature);
  51 }
  52 
  53 #ifdef STATIC_BUILD
  54 JNIEXPORT jint JNICALL Agent_OnLoad_getlocal004(JavaVM *jvm, char *options, void *reserved) {
  55     return Agent_Initialize(jvm, options, reserved);
  56 }
  57 JNIEXPORT jint JNICALL Agent_OnAttach_getlocal004(JavaVM *jvm, char *options, void *reserved) {
  58     return Agent_Initialize(jvm, options, reserved);
  59 }
  60 JNIEXPORT jint JNI_OnLoad_getlocal004(JavaVM *jvm, char *options, void *reserved) {
  61     return JNI_VERSION_1_8;
  62 }
  63 #endif
  64 jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
  65     jint res;
  66     jvmtiError err;
  67 
  68     if (options != NULL && strcmp(options, "printdump") == 0) {
  69         printdump = JNI_TRUE;
  70     }
  71 
  72     res = jvm->GetEnv((void **) &jvmti, JVMTI_VERSION_1_1);

  73     if (res != JNI_OK || jvmti == NULL) {
  74         printf("Wrong result of a valid call to GetEnv!\n");
  75         return JNI_ERR;
  76     }
  77 
  78     err = jvmti->GetPotentialCapabilities(&caps);
  79     if (err != JVMTI_ERROR_NONE) {
  80         printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n",
  81                TranslateError(err), err);
  82         return JNI_ERR;
  83     }
  84 
  85     err = jvmti->AddCapabilities(&caps);
  86     if (err != JVMTI_ERROR_NONE) {
  87         printf("(AddCapabilities) unexpected error: %s (%d)\n",
  88                TranslateError(err), err);
  89         return JNI_ERR;
  90     }
  91 
  92     err = jvmti->GetCapabilities(&caps);


  97     }
  98 
  99     if (!caps.can_access_local_variables) {
 100         printf("Warning: Access to local variables is not implemented\n");
 101     }
 102 
 103     return JNI_OK;
 104 }
 105 
 106 JNIEXPORT void JNICALL
 107 Java_nsk_jvmti_unit_GetLocalVariable_getlocal004_getMeth(JNIEnv *env, jclass cls) {
 108     if (jvmti == NULL) {
 109         printf("JVMTI client was not properly loaded!\n");
 110         result = STATUS_FAILED;
 111         return;
 112     }
 113 
 114     if (!caps.can_access_local_variables ||
 115         !caps.can_generate_method_exit_events) return;
 116 
 117     mid = env->GetStaticMethodID(cls, "staticMeth", "(I)I");

 118     if (mid == NULL) {
 119         printf("Cannot find Method ID for staticMeth\n");
 120         result = STATUS_FAILED;
 121         return;
 122     }
 123 
 124     fflush(stdout);
 125 }
 126 
 127 void checkErrorCodeIn(jvmtiError err, jint slot) {
 128     if (err != JVMTI_ERROR_NONE) {
 129         printf(" FAILURE: JVMTI_ERROR_NONE is expected, slot: %d\n\n", slot);
 130         result = STATUS_FAILED;
 131     } else {
 132         printf(" success: JVMTI_ERROR_NONE as expected, slot: %d\n\n", slot);
 133     }
 134 }
 135 
 136 void checkErrorCodeOut(jvmtiError err, jint slot) {
 137     if (err != JVMTI_ERROR_INVALID_SLOT) {


 211             printf(" slot%d: %d\n", slot, locInt);
 212         }
 213 
 214         err = jvmti->GetLocalLong(thr, 1, slot, &locLong);
 215         printf(" GetLocalLong: %s (%d)\n", TranslateError(err), err);
 216         checkErrorCodeOut(err, slot);
 217 
 218         err = jvmti->GetLocalDouble(thr, 1, slot, &locDouble);
 219         printf(" GetLocalDouble: %s (%d)\n", TranslateError(err), err);
 220         checkErrorCodeOut(err, slot);
 221     }
 222 
 223     fflush(stdout);
 224 }
 225 
 226 JNIEXPORT jint JNICALL
 227 Java_nsk_jvmti_unit_GetLocalVariable_getlocal004_getRes(JNIEnv *env, jclass cls) {
 228     return result;
 229 }
 230 

 231 }

< prev index next >