< prev index next >

test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/GetLineNumberTable/linetab004/linetab004.cpp

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


  13  * accompanied this code).
  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 "agent_common.h"
  31 #include "JVMTITools.h"
  32 
  33 #ifdef __cplusplus
  34 extern "C" {
  35 #endif
  36 
  37 #ifndef JNI_ENV_ARG
  38 
  39 #ifdef __cplusplus
  40 #define JNI_ENV_ARG(x, y) y
  41 #define JNI_ENV_PTR(x) x
  42 #else
  43 #define JNI_ENV_ARG(x,y) x, y
  44 #define JNI_ENV_PTR(x) (*x)
  45 #endif
  46 
  47 #endif
  48 
  49 #define PASSED 0
  50 #define STATUS_FAILED 2
  51 
  52 static jvmtiEnv *jvmti = NULL;
  53 static jvmtiCapabilities caps;
  54 static jint result = PASSED;
  55 static jboolean printdump = JNI_FALSE;
  56 
  57 #ifdef STATIC_BUILD
  58 JNIEXPORT jint JNICALL Agent_OnLoad_linetab004(JavaVM *jvm, char *options, void *reserved) {
  59     return Agent_Initialize(jvm, options, reserved);
  60 }
  61 JNIEXPORT jint JNICALL Agent_OnAttach_linetab004(JavaVM *jvm, char *options, void *reserved) {
  62     return Agent_Initialize(jvm, options, reserved);
  63 }
  64 JNIEXPORT jint JNI_OnLoad_linetab004(JavaVM *jvm, char *options, void *reserved) {
  65     return JNI_VERSION_1_8;
  66 }
  67 #endif
  68 jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
  69     jvmtiError err;
  70     jint res;
  71 
  72     if (options != NULL && strcmp(options, "printdump") == 0) {
  73         printdump = JNI_TRUE;
  74     }
  75 
  76     res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti),
  77         JVMTI_VERSION_1_1);
  78     if (res != JNI_OK || jvmti == NULL) {
  79         printf("Wrong result of a valid call to GetEnv!\n");
  80         return JNI_ERR;
  81     }
  82 
  83     err = jvmti->GetPotentialCapabilities(&caps);
  84     if (err != JVMTI_ERROR_NONE) {
  85         printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n",
  86                TranslateError(err), err);
  87         return JNI_ERR;
  88     }
  89 
  90     err = jvmti->AddCapabilities(&caps);
  91     if (err != JVMTI_ERROR_NONE) {
  92         printf("(AddCapabilities) unexpected error: %s (%d)\n",
  93                TranslateError(err), err);
  94         return JNI_ERR;
  95     }
  96 
  97     err = jvmti->GetCapabilities(&caps);


 141 }
 142 
 143 JNIEXPORT jint JNICALL
 144 Java_nsk_jvmti_unit_GetLineNumberTable_linetab004_check(JNIEnv *env, jclass cls) {
 145     jmethodID mid;
 146     jclass abstr;
 147     jclass interf;
 148 
 149     if (jvmti == NULL) {
 150         printf("JVMTI client was not properly loaded!\n");
 151         return STATUS_FAILED;
 152     }
 153 
 154     if (!caps.can_get_line_numbers) {
 155         return result;
 156     }
 157 
 158     if (printdump == JNI_TRUE) {
 159         printf("\n Check methods of interface:\n");
 160     }
 161     interf = JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG(env,
 162         "nsk/jvmti/unit/GetLineNumberTable/Interface004"));
 163     if (interf == NULL) {
 164         printf("Cannot get Interface class!\n");
 165         return STATUS_FAILED;
 166     }
 167 
 168     mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls),
 169         "instanceMeth0", "()I");
 170     if (mid == NULL) {
 171         printf("Cannot get method ID!\n");
 172         return STATUS_FAILED;
 173     }
 174     checkGetLineNumberTable(mid, "instanceMeth0", 1,
 175         JVMTI_ERROR_ABSENT_INFORMATION);
 176 
 177     mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls),
 178         "instanceMeth1", "()I");
 179     if (mid == NULL) {
 180         printf("Cannot get method ID!\n");
 181         return STATUS_FAILED;
 182     }
 183     checkGetLineNumberTable(mid, "instanceMeth1", 1,
 184         JVMTI_ERROR_ABSENT_INFORMATION);
 185 
 186     if (printdump == JNI_TRUE) {
 187         printf("\n Check methods of abstract class:\n");
 188     }
 189     abstr = JNI_ENV_PTR(env)->GetSuperclass(JNI_ENV_ARG(env, cls));
 190     if (abstr == NULL) {
 191         printf("Cannot get super class!\n");
 192         return STATUS_FAILED;
 193     }
 194 
 195     mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, abstr),
 196         "instanceMeth0", "()I");
 197     if (mid == NULL) {
 198         printf("Cannot get method ID!\n");
 199         return STATUS_FAILED;
 200     }
 201     checkGetLineNumberTable(mid, "instanceMeth0", 1,
 202         JVMTI_ERROR_ABSENT_INFORMATION);
 203 
 204     mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, abstr),
 205         "instanceMeth1", "()I");
 206     if (mid == NULL) {
 207         printf("Cannot get method ID!\n");
 208         return STATUS_FAILED;
 209     }
 210     checkGetLineNumberTable(mid, "instanceMeth1", 0,
 211         JVMTI_ERROR_ABSENT_INFORMATION);
 212 
 213     if (printdump == JNI_TRUE) {
 214         printf("\n Check methods of regular class:\n");
 215     }
 216     mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls),
 217         "instanceMeth0", "()I");
 218     if (mid == NULL) {
 219         printf("Cannot get method ID!\n");
 220         return STATUS_FAILED;
 221     }
 222     checkGetLineNumberTable(mid, "instanceMeth0", 0,
 223         JVMTI_ERROR_ABSENT_INFORMATION);
 224 
 225     mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls),
 226         "instanceMeth1", "()I");
 227     if (mid == NULL) {
 228         printf("Cannot get method ID!\n");
 229         return STATUS_FAILED;
 230     }
 231     checkGetLineNumberTable(mid, "instanceMeth1", 0,
 232         JVMTI_ERROR_ABSENT_INFORMATION);
 233 
 234     mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls),
 235         "instanceMeth2", "()I");
 236     if (mid == NULL) {
 237         printf("Cannot get method ID!\n");
 238         return STATUS_FAILED;
 239     }
 240     checkGetLineNumberTable(mid, "instanceMeth2", 0,
 241         JVMTI_ERROR_ABSENT_INFORMATION);
 242 
 243     if (printdump == JNI_TRUE) {
 244         printf("\n Check native methods of regular class:\n");
 245     }
 246     mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls),
 247         "instanceNativeMeth", "()I");
 248     if (mid == NULL) {
 249         printf("Cannot get method ID!\n");
 250         return STATUS_FAILED;
 251     }
 252     checkGetLineNumberTable(mid, "instanceNativeMeth", 1,
 253         JVMTI_ERROR_NATIVE_METHOD);
 254 
 255     mid = JNI_ENV_PTR(env)->GetStaticMethodID(JNI_ENV_ARG(env, cls),
 256         "staticNativeMeth", "()I");
 257     if (mid == NULL) {
 258         printf("Cannot get method ID!\n");
 259         return STATUS_FAILED;
 260     }
 261     checkGetLineNumberTable(mid, "staticNativeMeth", 1,
 262         JVMTI_ERROR_NATIVE_METHOD);
 263 
 264     if (printdump == JNI_TRUE) {
 265         printf(">>> ... done\n");
 266     }
 267 
 268     return result;
 269 }
 270 
 271 #ifdef __cplusplus
 272 }
 273 #endif


  13  * accompanied this code).
  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 "agent_common.h"
  31 #include "JVMTITools.h"
  32 

  33 extern "C" {











  34 

  35 
  36 #define PASSED 0
  37 #define STATUS_FAILED 2
  38 
  39 static jvmtiEnv *jvmti = NULL;
  40 static jvmtiCapabilities caps;
  41 static jint result = PASSED;
  42 static jboolean printdump = JNI_FALSE;
  43 
  44 #ifdef STATIC_BUILD
  45 JNIEXPORT jint JNICALL Agent_OnLoad_linetab004(JavaVM *jvm, char *options, void *reserved) {
  46     return Agent_Initialize(jvm, options, reserved);
  47 }
  48 JNIEXPORT jint JNICALL Agent_OnAttach_linetab004(JavaVM *jvm, char *options, void *reserved) {
  49     return Agent_Initialize(jvm, options, reserved);
  50 }
  51 JNIEXPORT jint JNI_OnLoad_linetab004(JavaVM *jvm, char *options, void *reserved) {
  52     return JNI_VERSION_1_8;
  53 }
  54 #endif
  55 jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
  56     jvmtiError err;
  57     jint res;
  58 
  59     if (options != NULL && strcmp(options, "printdump") == 0) {
  60         printdump = JNI_TRUE;
  61     }
  62 
  63     res = jvm->GetEnv((void **) &jvmti, JVMTI_VERSION_1_1);

  64     if (res != JNI_OK || jvmti == NULL) {
  65         printf("Wrong result of a valid call to GetEnv!\n");
  66         return JNI_ERR;
  67     }
  68 
  69     err = jvmti->GetPotentialCapabilities(&caps);
  70     if (err != JVMTI_ERROR_NONE) {
  71         printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n",
  72                TranslateError(err), err);
  73         return JNI_ERR;
  74     }
  75 
  76     err = jvmti->AddCapabilities(&caps);
  77     if (err != JVMTI_ERROR_NONE) {
  78         printf("(AddCapabilities) unexpected error: %s (%d)\n",
  79                TranslateError(err), err);
  80         return JNI_ERR;
  81     }
  82 
  83     err = jvmti->GetCapabilities(&caps);


 127 }
 128 
 129 JNIEXPORT jint JNICALL
 130 Java_nsk_jvmti_unit_GetLineNumberTable_linetab004_check(JNIEnv *env, jclass cls) {
 131     jmethodID mid;
 132     jclass abstr;
 133     jclass interf;
 134 
 135     if (jvmti == NULL) {
 136         printf("JVMTI client was not properly loaded!\n");
 137         return STATUS_FAILED;
 138     }
 139 
 140     if (!caps.can_get_line_numbers) {
 141         return result;
 142     }
 143 
 144     if (printdump == JNI_TRUE) {
 145         printf("\n Check methods of interface:\n");
 146     }
 147     interf = env->FindClass("nsk/jvmti/unit/GetLineNumberTable/Interface004");

 148     if (interf == NULL) {
 149         printf("Cannot get Interface class!\n");
 150         return STATUS_FAILED;
 151     }
 152 
 153     mid = env->GetMethodID(cls, "instanceMeth0", "()I");

 154     if (mid == NULL) {
 155         printf("Cannot get method ID!\n");
 156         return STATUS_FAILED;
 157     }
 158     checkGetLineNumberTable(mid, "instanceMeth0", 1,
 159         JVMTI_ERROR_ABSENT_INFORMATION);
 160 
 161     mid = env->GetMethodID(cls, "instanceMeth1", "()I");

 162     if (mid == NULL) {
 163         printf("Cannot get method ID!\n");
 164         return STATUS_FAILED;
 165     }
 166     checkGetLineNumberTable(mid, "instanceMeth1", 1,
 167         JVMTI_ERROR_ABSENT_INFORMATION);
 168 
 169     if (printdump == JNI_TRUE) {
 170         printf("\n Check methods of abstract class:\n");
 171     }
 172     abstr = env->GetSuperclass(cls);
 173     if (abstr == NULL) {
 174         printf("Cannot get super class!\n");
 175         return STATUS_FAILED;
 176     }
 177 
 178     mid = env->GetMethodID(abstr, "instanceMeth0", "()I");

 179     if (mid == NULL) {
 180         printf("Cannot get method ID!\n");
 181         return STATUS_FAILED;
 182     }
 183     checkGetLineNumberTable(mid, "instanceMeth0", 1,
 184         JVMTI_ERROR_ABSENT_INFORMATION);
 185 
 186     mid = env->GetMethodID(abstr, "instanceMeth1", "()I");

 187     if (mid == NULL) {
 188         printf("Cannot get method ID!\n");
 189         return STATUS_FAILED;
 190     }
 191     checkGetLineNumberTable(mid, "instanceMeth1", 0,
 192         JVMTI_ERROR_ABSENT_INFORMATION);
 193 
 194     if (printdump == JNI_TRUE) {
 195         printf("\n Check methods of regular class:\n");
 196     }
 197     mid = env->GetMethodID(cls, "instanceMeth0", "()I");

 198     if (mid == NULL) {
 199         printf("Cannot get method ID!\n");
 200         return STATUS_FAILED;
 201     }
 202     checkGetLineNumberTable(mid, "instanceMeth0", 0,
 203         JVMTI_ERROR_ABSENT_INFORMATION);
 204 
 205     mid = env->GetMethodID(cls, "instanceMeth1", "()I");

 206     if (mid == NULL) {
 207         printf("Cannot get method ID!\n");
 208         return STATUS_FAILED;
 209     }
 210     checkGetLineNumberTable(mid, "instanceMeth1", 0,
 211         JVMTI_ERROR_ABSENT_INFORMATION);
 212 
 213     mid = env->GetMethodID(cls, "instanceMeth2", "()I");

 214     if (mid == NULL) {
 215         printf("Cannot get method ID!\n");
 216         return STATUS_FAILED;
 217     }
 218     checkGetLineNumberTable(mid, "instanceMeth2", 0,
 219         JVMTI_ERROR_ABSENT_INFORMATION);
 220 
 221     if (printdump == JNI_TRUE) {
 222         printf("\n Check native methods of regular class:\n");
 223     }
 224     mid = env->GetMethodID(cls, "instanceNativeMeth", "()I");

 225     if (mid == NULL) {
 226         printf("Cannot get method ID!\n");
 227         return STATUS_FAILED;
 228     }
 229     checkGetLineNumberTable(mid, "instanceNativeMeth", 1,
 230         JVMTI_ERROR_NATIVE_METHOD);
 231 
 232     mid = env->GetStaticMethodID(cls, "staticNativeMeth", "()I");

 233     if (mid == NULL) {
 234         printf("Cannot get method ID!\n");
 235         return STATUS_FAILED;
 236     }
 237     checkGetLineNumberTable(mid, "staticNativeMeth", 1,
 238         JVMTI_ERROR_NATIVE_METHOD);
 239 
 240     if (printdump == JNI_TRUE) {
 241         printf(">>> ... done\n");
 242     }
 243 
 244     return result;
 245 }
 246 

 247 }

< prev index next >