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