Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / May 2007

Tip: Looking for answers? Try searching our database.

JVMTI/JNI and JVMTI_ERROR_INVALID_ENVIRONMENT

Thread view: 
Yao Qi - 09 May 2007 18:42 GMT
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.

Signature

Yao Qi <qiyaoltc@gmail.com>    GNU/Linux Developer
http://duewayqi.googlepages.com/

To give of yourself, you must first know yourself.

Gordon Beaton - 10 May 2007 08:29 GMT
> 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

--
Yao Qi - 10 May 2007 17:51 GMT
>> 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.

Yes, that is right.  My code works when I replace env by jvmti in the
first argument.  Thanks.

Signature

Yao Qi <qiyaoltc@gmail.com>    GNU/Linux Developer
http://duewayqi.googlepages.com/

One doesn't have a sense of humor.  It has you.
        -- Larry Gelbart



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.