Z Z
Z Z

Reputation: 11

JVMTI GetLocalVariableTable() always gives JVMTI_ERROR_ABSENT_INFORMATION

First of all, I have tried to find the solution to my problem for a while, but got nothing useful. Therefore, I want to have some suggestions from the experts.

I'm using JVMTI to write an agent, in which I need to get local variable info of some method. Here's the summary of what I did:

(1) Turn on the corresponding capability.

JNIEXPORT jint JNICALL
Agent_OnLoad(JavaVM *jvm, char *options, void *reserved)
{
  ...
  jvmtiCapabilities capa = {0};
  ...
  capa.can_access_local_variables = 1;
  ...
}

(2) During the live phase (in my case, the handler of VMInit event), get the jclass through JNI FindClass(), and then get the jmethodID through JNI GetMethodID() (of course, if it's static method, I use GetStaticMethodID()). Each step is checked, and jclass and jmethodID are all good.

(3) Then, I try to get the local variable table.

...
jvmtiLocalVariableEntry *entTab = NULL;
jint entCnt = 0;
jvmtiError errNum = jvmti->GetLocalVariableTable(mthID, &entCnt, &entTab);
...

I checked the errNum, and find it is JVMTI_ERROR_ABSENT_INFORMATION every time. I also tried this in other event handlers, which behave the same.

Any ideas or suggestions?

Thanks!

Upvotes: 0

Views: 475

Answers (1)

rahulmutt
rahulmutt

Reputation: 446

The JVMTI_ERROR_ABSENT_INFORMATION error indicates that the method you're trying to load the local variable table for doesn't have a proper LocalVariableTable attribute in the corresponding file.

If you have access to the original source code, you can compile it with javac using the -g option to generate it.

If you just want to get the method signature information, you can try the GetMethodName function. Otherwise, you need to obtain a stack frame containing the method in question and you can retrieve the values of all the local variables using GetLocal* by passing in the slot number.

Upvotes: 3

Related Questions