JVMTI gets local variable access capability on connect

I am writing a custom agent for java using JVMTI libraries and am trying to get access to local variables. when loading the agent in the OnLoad phase, the activation option can be enabled, but when loading in real time (OnAttach) it seems impossible and when I try to add it I get the error - JVMTI_ERROR_ABSENT_INFORMATION.

This is my OnAttach function (C language)

JNIEXPORT
jint
JNICALL
Agent_OnAttach(
    JavaVM *jvm,
    char *options,
    void *reserved
    )
{
    jvmtiEnv *jvmti;
    jvmtiCapabilities PotentialCap, RequestedCap;
    jvmtiError error;

    memset(&RequestedCap, 0, sizeof(RequestedCap));

    jvm->GetEnv((PVOID*)&jvmti, JVMTI_VERSION_1_0);
    jvmti->GetPotentialCapabilities(&PotentialCap);

    RequestedCap.can_access_local_variables = 1;

    error = jvmti->AddCapabilities(&RequestedCap);

    if (error != JVMTI_ERROR_NONE)
    {
        MessageBox(
            NULL,
            L"Fail to request local variable access",
            L"Native Agent",
            NULL);
    }

    return JNI_OK;
}

      

Is there a way to enable real-time access to a local variable?

thank

+3


source to share


1 answer


In JVM HotSpot, adding the ability to access local variables is not possible in the live phase, only in the on-load phase (as you noticed in your question).



You can see here (it's included in init_onload_capabilities

, not init_always_capabilities

).

0


source







All Articles