0 Replies Latest reply: Oct 1, 2008 11:17 AM by 843810 RSS

    How to get all the objects in a  stack frame

    843810
      Hi, what I'm trying to do is get all the objects on the top of the stack and time stamp them.


      What I have is this:

      static void mearthScanStack(jvmtiEnv *env, jmethodID method, jthread thread){
             jobject obj;
             int i;
             jlong tag;
             jvmtiError err;
             jvmtiLocalVariableEntry *localVarTable;
             jint entryCount;
            
             
           
                err = (*env)->GetLocalVariableTable(env, method, &entryCount, &localVarTable);
                if(err == JVMTI_ERROR_ABSENT_INFORMATION || err == JVMTI_ERROR_NATIVE_METHOD){
                     return;
                }
                
                check_jvmti_error(gdata->jvmti, err, "mearthScanStack: Could not get local variable table");
                
                for(i = 0; i < entryCount; i++){
                     if( (localVarTable.signature)[0] == 'L'){
                     
                          err = (*env)->GetLocalObject(env,     thread, 0, localVarTable[i].slot, &obj);
           check_jvmti_error(gdata->jvmti, err, "mearthScanStack: Could not get local object");
                               
                          err = (*env)->GetTag(env, obj, &tag);
                          
                          check_jvmti_error(gdata->jvmti, err, "mearthScanStack: Could not get tag for local object");
                          
                          timeStampObject(env, obj);
                     }      
                }
                
                (*env)->Deallocate(env, localVarTable);
      }
      To walk through, first I get the local object variable table, then I loop through each entry in the table. I check each entries signature to see if it is an object (starts with "L"), and if it is, I try get its tag, and time stamp it.
      
      This doesn't seem to work, however, because I get JVMTI_ERROR_INVALID_SLOT errors on the call to GetLocalObject. How can it be an invalid slot if I am getting the slot out of the local variable table?  Am I going about this the right way
      
      Additionally, when I get the the table, I'm ignoring the JVMTI_ERROR_ABSENT_INFORMATION error. I'm not exactly sure under what circustances this information is absent. Is there a way I could scan the stack frame even if it is not available (just probe through the slots maybe?)
      
      Any help is greatly appreciated.