org.springsource.loaded.agent
Class JVMPlugin

java.lang.Object
  extended by org.springsource.loaded.agent.JVMPlugin
All Implemented Interfaces:
LoadtimeInstrumentationPlugin, Plugin, ReloadEventProcessorPlugin

public class JVMPlugin
extends java.lang.Object
implements ReloadEventProcessorPlugin, LoadtimeInstrumentationPlugin

Reloading plugin for 'poking' JVM classes that are known to cache reflective state. Some of the behaviour is switched ON based on which classes are loaded. For example the Introspector clearing logic is only activated if the Introspector gets loaded.

Since:
0.7.3

Constructor Summary
JVMPlugin()
           
 
Method Summary
 boolean accept(java.lang.String slashedTypeName, java.lang.ClassLoader classLoader, java.security.ProtectionDomain protectionDomain, byte[] bytes)
          Called by the agent to determine if this plugin is interested in changing the specified type at load time.
 byte[] modify(java.lang.String slashedClassName, java.lang.ClassLoader classLoader, byte[] bytes)
          Once accept has returned true for a type, the modify method will be called to make the actual change to the classfile bytes.
 void reloadEvent(java.lang.String typename, java.lang.Class<?> clazz, java.lang.String encodedTimestamp)
          Called when a type has been reloaded.
 boolean shouldRerunStaticInitializer(java.lang.String typename, java.lang.Class<?> clazz, java.lang.String encodedTimestamp)
          Called when a type has been reloaded, allows the plugin to decide if the static initializer should be re-run for the reloaded type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JVMPlugin

public JVMPlugin()
Method Detail

reloadEvent

public void reloadEvent(java.lang.String typename,
                        java.lang.Class<?> clazz,
                        java.lang.String encodedTimestamp)
Description copied from interface: ReloadEventProcessorPlugin
Called when a type has been reloaded. Note, the class is only truly defined to the VM once, and so the Class object (clazz parameter) is always the same for the same type (ignoring multiple classloader situations). It is passed here so that plugins processing events can clear any cached state related to it. The encodedTimestamp is an encoding of the ID that the agent has assigned to this reloaded version of this type.

Specified by:
reloadEvent in interface ReloadEventProcessorPlugin
Parameters:
typename - the (dotted) type name, for example java.lang.String
clazz - the Class object that has been reloaded
encodedTimestamp - an encoded time stamp for this version, containing chars (A-Za-z0-9)

accept

public boolean accept(java.lang.String slashedTypeName,
                      java.lang.ClassLoader classLoader,
                      java.security.ProtectionDomain protectionDomain,
                      byte[] bytes)
Description copied from interface: LoadtimeInstrumentationPlugin
Called by the agent to determine if this plugin is interested in changing the specified type at load time. This is used when the plugin wishes to do some kind of transformation itself before the type is loaded - for example modify it to record something that will later be used on a reload event.

Specified by:
accept in interface LoadtimeInstrumentationPlugin
Parameters:
slashedTypeName - the type name, slashed form (e.g. java/lang/String)
classLoader - the classloader loading the type
bytes - the classfile contents for the type
Returns:
true if this plugin wants to change the bytes for the named type

modify

public byte[] modify(java.lang.String slashedClassName,
                     java.lang.ClassLoader classLoader,
                     byte[] bytes)
Description copied from interface: LoadtimeInstrumentationPlugin
Once accept has returned true for a type, the modify method will be called to make the actual change to the classfile bytes.

Specified by:
modify in interface LoadtimeInstrumentationPlugin
classLoader - the classloader loading the type
bytes - the classfile contents for the type
Returns:
the new (modified) bytes for the class

shouldRerunStaticInitializer

public boolean shouldRerunStaticInitializer(java.lang.String typename,
                                            java.lang.Class<?> clazz,
                                            java.lang.String encodedTimestamp)
Description copied from interface: ReloadEventProcessorPlugin
Called when a type has been reloaded, allows the plugin to decide if the static initializer should be re-run for the reloaded type. If the reloaded type has a different static initializer, the new one is the one that will run.

Specified by:
shouldRerunStaticInitializer in interface ReloadEventProcessorPlugin
Parameters:
typename - the (dotted) type name, for example java.lang.String
clazz - the Class object that has been reloaded
encodedTimestamp - an encoded time stamp for this version, containing chars (A-Za-z0-9)
Returns:
true if the static initializer should be re-run