help needed with jvmti and jni

  • Thread starter Svetozar Misljencevic
  • Start date
S

Svetozar Misljencevic

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
 

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

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top