开发者

JVMTI Agent_OnLoad handler can't create a System Property

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 canno开发者_如何学Ct 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.


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 via System.getProperty, then you're probably stuck with doing it via JNI (per the JVMTI docs).


Add the property using -D<property name>=<property value> when launching from the command line.

system properties may be set before they have been used in the start-up of the VM

taken from http://docs.oracle.com/javase/1.5.0/docs/guide/jvmti/jvmti.html#starting

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜