Skip to Main Content

Java HotSpot Virtual Machine

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

help needed with jvmti and jni

843811Nov 29 2004 — edited Dec 1 2004
Hi,

I have few questions about jvmti and jni. Searching in other forums and newsgroup was without any success so i hope someone here can help.

1. I am using MethodEntry and MethodExit events from jvmti. That way my c++ code can log certain method calls and returns. Method' s name, class, thread and some other information is being logged to a file.
To increase the performance jmethodID object and its jclass are being cached, so amount of called jvmti function is reduced by looking in the cache.
However, there are 2 problems with cache:
-All references passed to c++ code are local. In order to use them again i have converted jclass local references to global references. This seemed like a good idea but has one major drawback: in order to compare local jclass reference (which i get by calling GetMethodDeclaringClass(..) on received jmethodID object) with cached global reference jni function IsSameObject(...)is called multiple times. This is against the whole idea of cache being used to decrease amount of jni/jvmti function calls.
Is there a way to compare global references with local one without performance penalty?

-Beside jclass references I also cache jmethodId that is received as parameter when MethodEntry is called by jvm. On each call different jmethoid object is received even if it points to same method. Here its not possible to make jmethodId object global because it's not a reference.

According to following quote there is however a solution to above 2 problems.
Quote from http://java.sun.com/docs/books/tutorial/native1.1/implementing/method.html :
�It is important to keep in mind that a method ID is valid only for as long as the class from which it is derived is not unloaded. Once the class is unloaded, the method ID becomes invalid. As a result, if you want to cache the method ID, be sure to keep a live reference to the Java class from which the method ID is derived. As long as the reference to the Java class (the jclass value) exists, the native code keeps a live reference to the class.�

The thing is that above solution doesn't seem to work. I keep global reference to jclass in mine cache so it shouldn't unload. According to above quote that means that same method always gets same methodId. That is however not true, different methodIds are received.


I would appreciate if anyone can help in any way.

thx,
Svetozar
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 29 2004
Added on Nov 29 2004
1 comment
294 views