【问题标题】:Agent from a static nested class来自静态嵌套类的代理
【发布时间】:2020-11-18 01:13:16
【问题描述】:

为什么不能从静态嵌套类创建代理? 我没有收到错误或任何东西,程序只是没有运行,所以很难说出了什么问题。

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-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

这是一个正在工作的非嵌套代理:

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

【问题讨论】:

    标签: java agent


    【解决方案1】:

    由于是嵌套类,所以分隔符是$不是。

    sfjl.SFJL_Profiler$SFJL_Profiler_Agent
    

    【讨论】:

      【解决方案2】:

      它工作正常,但 Agent-Class 的值(就此而言,Main-ClassPremain-Class 也是)是 JVM 格式。所以,试试吧:

      Agent-Class: sfjl.SFJL_Profiler$SFJL_Profiler_Agent
      

      $ 在 JVM 语法中分隔内部类,而不是点。

      【讨论】:

      • 再次感谢,从你那里学到了很多东西 :) 我给了 smr 接受,因为你同时发帖,但他可以使用一些代表。
      猜你喜欢
      • 1970-01-01
      • 2011-09-11
      • 1970-01-01
      • 1970-01-01
      • 2013-05-11
      • 1970-01-01
      • 2021-12-02
      • 2013-08-05
      • 2015-09-15
      相关资源
      最近更新 更多