我正在使用 JVM 工具接口。我正在尝试使用 SetSystemProperty() 调用在 Agent_OnLoad 事件中创建 SystemProperty。如果该属性存在,它会正确设置一个新值。但是,如果该属性不存在,SetSystemProperty 将返回一个错误代码,指出它无法写入该属性(错误 98)。
是否有另一种方法可以在 JVM 生命周期的早期(在类加载之前)创建系统属性?
2012年5月24日更新:作为一名特工,我被各种程序加载。我无法要求程序设置此属性(在我的用例中不实用)。我正在寻找一种从代理代码本身设置属性的方法。经过大量实验后,我得出的结论是这是不可能的。
I'm using the JVM Tool Interface. I'm trying to create a SystemProperty in the Agent_OnLoad event using the SetSystemProperty() call. If the property exists, it correctly sets a new value. However, if the property does not exist, SetSystemProperty returns an error code saying it cannot write the property (error 98).
Is there another way to create a system property early in the JVM's life, before classes get loaded?
5/24/12 update: As an agent, I am loaded by various programs. I can't ask the programs to set this property (not practical in my use case). I'm looking for a way to do set the property from the agent code itself. After a lot of experimenting, I've come to the conclusion that it's not possible.
发布评论
评论(2)
如果您还没有查看 JVMTI 文档的系统属性,那么值得:
http://docs.oracle.com/javase/6/docs/platform/jvmti/jvmti.html#props
看起来 VM 系统属性和管理的物业
java.lang.System
。如果您确实想设置一个可通过 System.getProperty 获取的属性,那么您可能只能通过 JNI 来完成此操作(根据 JVMTI 文档)。If you haven't already looked at the JVMTI docs for system properties, it would be worthwhile:
http://docs.oracle.com/javase/6/docs/platform/jvmti/jvmti.html#props
It looks like there is a distinction made between VM system properties and the properties managed by
java.lang.System
. If you really want to set a property that will be available viaSystem.getProperty
, then you're probably stuck with doing it via JNI (per the JVMTI docs).从命令行启动时,使用
-D=
添加属性。取自 http:// /docs.oracle.com/javase/1.5.0/docs/guide/jvmti/jvmti.html#starting
Add the property using
-D<property name>=<property value>
when launching from the command line.taken from http://docs.oracle.com/javase/1.5.0/docs/guide/jvmti/jvmti.html#starting