I am working on a JVMTI agent, and I want to identify the same thread when the method enters and exits. I can get the name of the stream, but this is not enough.
Imagine you have a method like this:
public class Main { public static void myMethod() { System.out.println("doing something as " + Thread.currentThread().getName()); Thread.currentThread().setName("SomethingDifferent"); System.out.println("doing something as same thread " + Thread.currentThread().getName()); } }
Thus, the input of this method will have one name and the output from this stream has a different name.
When using JVMTI, for example:
static void JNICALL callback_on_method_entry(jvmtiEnv *jvmti, JNIEnv* env, jthread thread, jmethodID method) { ... (*jvmti)->GetThreadInfo(jvmti, thread, &info); ... } static void JNICALL callback_on_method_exit(jvmtiEnv *jvmti, JNIEnv *env, jthread thread, jmethodID method, jboolean was_popped_by_exception, jvalue return_value) { ... (*jvmti)->GetThreadInfo(jvmti, thread, &info); ... }
Each info will report a different stream name, and I want to have the same identifier for them.
How can I get the same id for the stream?
One solution would be to get the field value for the Thread ( tid ) link. How to do it? I can iterate through the heap, but I cannot get the field name.