来自静态嵌套类的代理

huangapple go评论80阅读模式
英文:

Agent from a static nested class

问题

为什么无法从静态嵌套类中创建代理?
我没有收到任何错误信息,程序也没有运行,所以很难说出了什么问题。

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

英文:

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

答案1

得分: 1

因为它是一个嵌套类,分隔符是 $ 而不是 .

sfjl.SFJL_Profiler$SFJL_Profiler_Agent
英文:

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

sfjl.SFJL_Profiler$SFJL_Profiler_Agent

答案2

得分: 1

这段代码的翻译如下:

它正常工作,但是`Agent-Class`的值(以及同样的`Main-Class`和`Premain-Class`)是以JVM格式表示的。因此,请尝试:

Agent-Class: sfjl.SFJL_Profiler$SFJL_Profiler_Agent


在JVM语法中,$符号用于分隔内部类,而不是使用点。
英文:

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.

huangapple
  • 本文由 发表于 2020年7月28日 22:42:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/63136782.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定