背景:Java 有一种检测本地方法的机制,基本上允许您使用设置的前缀重命名本地方法,然后在字节码中创建一个委托(delegate)给它的方法。
默认情况下这是不允许的。调用 Instrumentation.setNativePrefix()
对 InstrumentationImpl.mEnvironmentSupportsNativeMethodPrefix
执行检查,我在 jvm C 代码中看到它默认为“false”。
我看到可能有一种方法可以通过 JVMTI 使用 native 代理启用它,但我找不到任何关于使用 Java 语言代理启用它的信息。
最佳答案
Java 代理所需的功能由其 jar 文件的 list 属性决定,如 the bottom of the package documentation 中指定的那样:
Manifest Attributes
The following manifest attributes are defined for an agent JAR file:
…
- Can-Set-Native-Method-Prefix
Boolean (true
orfalse
, case irrelevant). Is the ability to set native method prefix needed by this agent. Values other thantrue
are consideredfalse
. This attribute is optional, the default isfalse
.
我没有专门尝试使用本地方法前缀,但我从其他功能(重新定义和重新转换)中知道它们仅在先前通过请求时被报告为 Instrumentation
接口(interface)支持 list 属性。没有任何启动时代理请求该功能甚至可能导致以后无法通过 Attach API 加载的代理请求该功能。
关于java - 有没有办法在 java 语言(非 native )JVM 代理中启用 "native method prefix"功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52427608/