0

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

clankill3r
  • 9,146
  • 20
  • 70
  • 126

2 Answers2

1

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

sfjl.SFJL_Profiler$SFJL_Profiler_Agent
smr
  • 71
  • 6
1

It works fine, but the value of the Agent-Class (and for that matter, Main-Class and Premain-Class too) are in JVM format. So, try:

Agent-Class: sfjl.SFJL_Profiler$SFJL_Profiler_Agent

$ separates inner classes, not dots, in JVM syntax.

rzwitserloot
  • 85,357
  • 5
  • 51
  • 72
  • 1
    Thanks again, learning so much from you :) I give smr the accept since you posted at the same time but he could use some rep. – clankill3r Jul 28 '20 at 15:44