3

I'm writing a native agent to java using the JVMTI libraries and trying to get the capability for accessing local variables. when loading the agent in the OnLoad phase that capability can be enabled, but when loading it in the live phase (OnAttach) is seems to be not possible and when I'm trying to add it I'm getting the error - JVMTI_ERROR_ABSENT_INFORMATION.

That 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 any way to enable local variable access in live phase?

Thanks

stylo
  • 496
  • 4
  • 12

1 Answers1

0

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

You can see this here (it is enabled in init_onload_capabilities, rather than init_always_capabilities).

Sam Marsh
  • 166
  • 2
  • 6