Search code examples
javaagent

Agent from a static nested class


Why is not possible to create a agent from a static nested class? I don't get an error or anything, the program just doesn't run, so it's hard to say what goes wrong.

package sfjl;

import java.lang.instrument.Instrumentation;


public final class SFJL_Profiler {
     private SFJL_Profiler() {}

    
// 
static public final class SFJL_Profiler_Agent {

    private static Instrumentation instrumentation;

    public static void premain(String args, Instrumentation inst) {
        instrumentation = inst;
    }

    public static long sizeof(Object o) {
        return instrumentation.getObjectSize(o);
    }

}


// 
static public final class SFJL_Profiler_Console_Printer {
    
}


}

manifest:

Manifest-Version: 1.0
Premain-Class: sfjl.SFJL_Profiler.SFJL_Profiler_Agent
Agent-Class: sfjl.SFJL_Profiler.SFJL_Profiler_Agent
Can-Redefine-Classes: true
Can-Retransform-Classes: true

This is a non nested agent that is working:

https://stackoverflow.com/a/43296164/1022707


Solution

  • Since it is a nested class, the separator is $ not .

    sfjl.SFJL_Profiler$SFJL_Profiler_Agent