JVMTI/JNI and JVMTI_ERROR_INVALID_ENVIRONMENT

Y

Yao Qi

I write a sample code to get some information via JVMTI, but error
JVMTI_ERROR_INVALID_ENVIRONMENT is always here.

HelloWorld.java,

class HelloWorld {
private native void print();
public static void main(String[] args) {
new HelloWorld().print();
}
}

libjvmtiagent.c,

.....
JNIEXPORT void JNICALL
Java_HelloWorld_print(JNIEnv *env, jobject obj)
{
jvmtiError err;
jint owned_monitor_count, res;
jobject* owned_monitors_ptr;

/*
JavaVM* jvm;
res = (*env)->GetJavaVM(env, &jvm);
res = (*jvm)->GetEnv(jvm, (void **) &jvmti, JVMTI_VERSION_1_0);

if (res != JNI_OK || jvmti == NULL)
{
printf("ERROR: Unable to access JVMTI Version 1 (0x%x),"
" is your J2SE a 1.5 or newer version?"
" JNIEnv's GetEnv() returned %d\n",
JVMTI_VERSION_1, res);

}
*/

err = (*jvmti)->GetOwnedMonitorInfo (env, NULL, &owned_monitor_count, &owned_monitors_ptr);
check_jvmti_error(jvmti, err, "Cannot get owned monitor infor\n");

printf ("owned monitors is %d\n", (int)owned_monitor_count);
err = (*jvmti)->Deallocate (env, owned_monitors_ptr);
check_jvmti_error(jvmti, err, "Cannot deallocate\n");


return;
}

Agent_OnLoad has been implemented properly, however when I run my
program like this,

$ LD_LIBRARY_PATH=. java -agentlib:jvmtiagent HelloWorld
jvmti = 0x831a7a8Got VM init event
callbackVMInit: main thread
ERROR: JVMTI: 116(JVMTI_ERROR_INVALID_ENVIRONMENT): Cannot get owned monitor infor

owned monitors is -1309188692
ERROR: JVMTI: 116(JVMTI_ERROR_INVALID_ENVIRONMENT): Cannot deallocate

Got VM Death event
Agent_OnUnload


Even I remove these comments in Java_HelloWorld_print above, this error
does not go away.

I am a newibe in JNI, and googled JVMTI_ERROR_INVALID_ENVIRONMENT for a
long time without any useful results.
Could anyone here give me some help on this? Thanks in advance.
 
G

Gordon Beaton

err = (*jvmti)->GetOwnedMonitorInfo (env, NULL, &owned_monitor_count, &owned_monitors_ptr);

I don't know JVMTI, but suspect strongly that the first argument to
the JVMTI functions should be jvmti, not env.

/gordon

--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

JNI Invocation API example 4
JNI and GetFieldID 12
JNI UnsatisfiedLinkError 11
jni libjvm sigsegv 1
JNI problem 14
JNI and pointer deletion 2
Using JNI from Managed C++ 2
JNI JNI_CreateJavaVM hangs Linux 3

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top