Index: build/make/targets/jvmti.test.xml =================================================================== --- build/make/targets/jvmti.test.xml (revision 0) +++ build/make/targets/jvmti.test.xml (revision 0) @@ -0,0 +1,171 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ============================================== + Please set the classpath of junit as follows: + build.bat -Djunit.jar=%JUNIT_HOME% test + ============================================== + + + + + + + + + + + + + + ================================== + Run JVMTI tests using ${jvmti.tests.mode} + ================================== + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Index: build/make/targets/kernel.test.xml =================================================================== --- build/make/targets/kernel.test.xml (revision 473416) +++ build/make/targets/kernel.test.xml (working copy) @@ -124,7 +124,7 @@ ============================================== Please set the classpath of junit as follows: - build.bat -Djunit.jar=%JUNIT_HOME% test" + build.bat -Djunit.jar=%JUNIT_HOME% test ============================================== Index: build/make/targets/test.xml =================================================================== --- build/make/targets/test.xml (revision 473416) +++ build/make/targets/test.xml (working copy) @@ -18,6 +18,6 @@ Version: $Revision: 1.3.2.2 $ --> - + Index: build/make/build.xml =================================================================== --- build/make/build.xml (revision 473416) +++ build/make/build.xml (working copy) @@ -35,6 +35,7 @@ designated components smoke.test - builds and runs smoke tests for the designated components + jvmti.test - builds and runs JVMTI tests test - builds and runs unit & smoke tests for the designated components @@ -393,9 +394,12 @@ - - + + + + + @@ -403,6 +407,15 @@ + + + + + + + + + Index: vm/tests/jvmti/VMInit1/VMInit1.java =================================================================== --- vm/tests/jvmti/VMInit1/VMInit1.java (revision 0) +++ vm/tests/jvmti/VMInit1/VMInit1.java (revision 0) @@ -0,0 +1,23 @@ +package VMInit1; + +import junit.framework.TestCase; + +/** + * Test case for VMInit event. Should be executed with all JVMTI capabilies + * enabled. + */ +public class VMInit1 extends TestCase { + public static void main(String args[]) { + (new VMInit1()).test(); + } + + public void test() { + System.out.println("test done"); + assertTrue(Status.status); + } +} + +class Status { + public static boolean status = false; +} + Index: vm/tests/jvmti/VMInit1/VMInit1.cpp =================================================================== --- vm/tests/jvmti/VMInit1/VMInit1.cpp (revision 0) +++ vm/tests/jvmti/VMInit1/VMInit1.cpp (revision 0) @@ -0,0 +1,49 @@ +#include +#include + +static void JNICALL vm_init_callback(jvmtiEnv* jvmti_env, JNIEnv* jni_env, jthread thread) +{ + jclass cl = jni_env->FindClass("VMInit1/Status"); + if (NULL == cl) + return; + + jfieldID fid = jni_env->GetStaticFieldID(cl, "status", "Z"); + if (NULL == fid) + return; + + jni_env->SetStaticBooleanField(cl, fid, JNI_TRUE); +} + +JNIEXPORT jint JNICALL Agent_OnLoad(JavaVM *vm, char *options, void *reserved) +{ + jvmtiEnv *jvmti_env; + if(vm->GetEnv((void**)&jvmti_env, JVMTI_VERSION_1_0) != JNI_OK) + return JNI_ERR; + + // Get all supported capabilities + jvmtiCapabilities capabilities; + jvmtiError result = jvmti_env->GetPotentialCapabilities(&capabilities); + if (JVMTI_ERROR_NONE != result) + return JNI_ERR; + + // Enabled all supported capabilities + result = jvmti_env->AddCapabilities(&capabilities); + if (JVMTI_ERROR_NONE != result) + return JNI_ERR; + + jvmtiEventCallbacks callbacks; + memset(&callbacks, 0, sizeof(jvmtiEventCallbacks)); + callbacks.VMInit = vm_init_callback; + + // Set callback for VMInit + result = jvmti_env->SetEventCallbacks(&callbacks, (jint)sizeof(callbacks)); + if (JVMTI_ERROR_NONE != result) + return JNI_ERR; + + // Set event mode to true + result = jvmti_env->SetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_VM_INIT, NULL); + if (JVMTI_ERROR_NONE != result) + return JNI_ERR; + + return JNI_OK; +}