< prev index next >

test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach002/attach002Agent00.cpp

Print this page
rev 52432 : 8213501: Deploy ExceptionJniWrapper for a few tests
Summary:
Reviewed-by:


  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  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 #include <stdio.h>
  24 #include <stdlib.h>
  25 #include <string.h>
  26 #include <jni.h>
  27 #include <jvmti.h>
  28 #include <aod.h>
  29 #include <jvmti_aod.h>

  30 
  31 extern "C" {
  32 
  33 /*
  34  * Expected agent work scenario:
  35  *  - receive ClassFileLoadHook event for class 'ClassToRedefine'
  36  *  - receive ClassLoad event for class 'ClassToRedefine' and redefine class from ClassLoad event handler
  37  *  - receive one more ClassFileLoadHook event for class 'ClassToRedefine'
  38  *  - receive ClassPrepare event for class 'ClassToRedefine' and finish work
  39  */
  40 
  41 #define REDEFINED_CLASS_NAME "Lnsk/jvmti/AttachOnDemand/attach002/ClassToRedefine;"
  42 #define REDEFINED_CLASS_FILE_NAME "nsk/jvmti/AttachOnDemand/attach002/ClassToRedefine"
  43 
  44 // class name in the ClassFileLoadHook callback
  45 #define REDEFINED_CLASS_NAME_INTERNAL "nsk/jvmti/AttachOnDemand/attach002/ClassToRedefine"
  46 
  47 static Options* options = NULL;
  48 static const char* agentName;
  49 
  50 static volatile jboolean agentGotCapabilities = JNI_FALSE;
  51 
  52 static jvmtiEvent testEvents[] = {
  53         JVMTI_EVENT_CLASS_LOAD,
  54         JVMTI_EVENT_CLASS_PREPARE,
  55         JVMTI_EVENT_CLASS_FILE_LOAD_HOOK};
  56 
  57 static const int testEventsNumber = 3;
  58 
  59 static volatile int classLoadReceived = 0;
  60 static volatile int classFileLoadHookReceived = 0;
  61 
  62 JNIEXPORT jboolean JNICALL
  63 Java_nsk_jvmti_AttachOnDemand_attach002_attach002Target_agentGotCapabilities(JNIEnv * jni,
  64         jclass klass, jobject obj) {
  65     return agentGotCapabilities;
  66 }
  67 
  68 #define ATTACH002_TARGET_APP_CLASS_NAME "nsk/jvmti/AttachOnDemand/attach002/attach002Target"
  69 
  70 int registerNativeMethods(JNIEnv* jni) {

  71     jclass appClass;
  72     JNINativeMethod nativeMethods[] = {
  73             {(char*) "agentGotCapabilities", (char*) "()Z", (void*) Java_nsk_jvmti_AttachOnDemand_attach002_attach002Target_agentGotCapabilities}};
  74     jint nativeMethodsNumber = 1;
  75 
  76     appClass = jni->FindClass(ATTACH002_TARGET_APP_CLASS_NAME);
  77     if (!NSK_JNI_VERIFY(jni, appClass != NULL)) {
  78         return NSK_FALSE;
  79     }
  80 
  81     if (!NSK_JNI_VERIFY(jni,
  82             (jni->RegisterNatives(appClass, nativeMethods, nativeMethodsNumber) == 0))) {
  83         return NSK_FALSE;
  84     }
  85 
  86     return NSK_TRUE;
  87 }
  88 
  89 void JNICALL  classLoadHandler(
  90         jvmtiEnv *jvmti,
  91         JNIEnv* jni,
  92         jthread thread,
  93         jclass klass) {
  94     char className[MAX_STRING_LENGTH];
  95 
  96     if (!nsk_jvmti_aod_getClassName(jvmti, klass, className)) {
  97         nsk_jvmti_aod_disableEventsAndFinish(agentName, testEvents, testEventsNumber, 0, jvmti, jni);
  98         return;
  99     }
 100 
 101     NSK_DISPLAY2("%s: ClassLoad event was received for class '%s'\n", agentName, className);
 102 




  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  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 #include <stdio.h>
  24 #include <stdlib.h>
  25 #include <string.h>
  26 #include <jni.h>
  27 #include <jvmti.h>
  28 #include <aod.h>
  29 #include <jvmti_aod.h>
  30 #include "ExceptionCheckingJniEnv.hpp"
  31 
  32 extern "C" {
  33 
  34 /*
  35  * Expected agent work scenario:
  36  *  - receive ClassFileLoadHook event for class 'ClassToRedefine'
  37  *  - receive ClassLoad event for class 'ClassToRedefine' and redefine class from ClassLoad event handler
  38  *  - receive one more ClassFileLoadHook event for class 'ClassToRedefine'
  39  *  - receive ClassPrepare event for class 'ClassToRedefine' and finish work
  40  */
  41 
  42 #define REDEFINED_CLASS_NAME "Lnsk/jvmti/AttachOnDemand/attach002/ClassToRedefine;"
  43 #define REDEFINED_CLASS_FILE_NAME "nsk/jvmti/AttachOnDemand/attach002/ClassToRedefine"
  44 
  45 // class name in the ClassFileLoadHook callback
  46 #define REDEFINED_CLASS_NAME_INTERNAL "nsk/jvmti/AttachOnDemand/attach002/ClassToRedefine"
  47 
  48 static Options* options = NULL;
  49 static const char* agentName;
  50 
  51 static volatile jboolean agentGotCapabilities = JNI_FALSE;
  52 
  53 static jvmtiEvent testEvents[] = {
  54         JVMTI_EVENT_CLASS_LOAD,
  55         JVMTI_EVENT_CLASS_PREPARE,
  56         JVMTI_EVENT_CLASS_FILE_LOAD_HOOK};
  57 
  58 static const int testEventsNumber = 3;
  59 
  60 static volatile int classLoadReceived = 0;
  61 static volatile int classFileLoadHookReceived = 0;
  62 
  63 JNIEXPORT jboolean JNICALL
  64 Java_nsk_jvmti_AttachOnDemand_attach002_attach002Target_agentGotCapabilities(JNIEnv * jni,
  65         jclass klass, jobject obj) {
  66     return agentGotCapabilities;
  67 }
  68 
  69 #define ATTACH002_TARGET_APP_CLASS_NAME "nsk/jvmti/AttachOnDemand/attach002/attach002Target"
  70 
  71 int registerNativeMethods(JNIEnv* jni_env) {
  72     ExceptionCheckingJniEnvPtr jni(jni_env);
  73     jclass appClass;
  74     JNINativeMethod nativeMethods[] = {
  75             {(char*) "agentGotCapabilities", (char*) "()Z", (void*) Java_nsk_jvmti_AttachOnDemand_attach002_attach002Target_agentGotCapabilities}};
  76     jint nativeMethodsNumber = 1;
  77 
  78     appClass = jni->FindClass(ATTACH002_TARGET_APP_CLASS_NAME, TRACE_JNI_CALL);
  79     if (appClass == NULL) {
  80         return NSK_FALSE;
  81     }
  82 
  83     if (jni->RegisterNatives(appClass, nativeMethods, nativeMethodsNumber, TRACE_JNI_CALL) != 0) {

  84         return NSK_FALSE;
  85     }
  86 
  87     return NSK_TRUE;
  88 }
  89 
  90 void JNICALL  classLoadHandler(
  91         jvmtiEnv *jvmti,
  92         JNIEnv* jni,
  93         jthread thread,
  94         jclass klass) {
  95     char className[MAX_STRING_LENGTH];
  96 
  97     if (!nsk_jvmti_aod_getClassName(jvmti, klass, className)) {
  98         nsk_jvmti_aod_disableEventsAndFinish(agentName, testEvents, testEventsNumber, 0, jvmti, jni);
  99         return;
 100     }
 101 
 102     NSK_DISPLAY2("%s: ClassLoad event was received for class '%s'\n", agentName, className);
 103 


< prev index next >