public class GroovyPlugin extends java.lang.Object implements LoadtimeInstrumentationPlugin, ReloadEventProcessorPlugin
So far the GroovyPlugin can do two different things - configurable through the 'allowCompilableCallSites' flag.
If the flag is false: The plugin intercepts two of the main system types in groovy and turns OFF call site compilation. Without this compilation the compiler will not be generating classes, it will instead be using reflection all the time. This is simpler to handle (as we intercept reflection) but performance == thesuck.
If the flag is true: The plugin leaves groovy to compile call sites. We intercept the define method in the classloader used to define these generated call site classes and ensure they are rewritten correctly. Note there is an alternative here of getting the SpringLoadedPreProcessor to recognize these special classloaders and just instrument them that way. However, if we let the plugin do it it is easier to test!
To see the difference in these approaches, check the numbers in the Groovy Benchmark tests.
Constructor and Description |
---|
GroovyPlugin() |
Modifier and Type | Method and Description |
---|---|
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.
|
static void |
recordInstance(java.lang.Object obj) |
void |
reloadEvent(java.lang.String typename,
java.lang.Class<?> clazz,
java.lang.String versionsuffix)
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.
|
public boolean accept(java.lang.String slashedTypeName, java.lang.ClassLoader classLoader, java.security.ProtectionDomain protectionDomain, byte[] bytes)
LoadtimeInstrumentationPlugin
accept
in interface LoadtimeInstrumentationPlugin
slashedTypeName
- the type name, slashed form (e.g. java/lang/String)classLoader
- the classloader loading the typeprotectionDomain
- the ProtectionDomain for the class represented by the bytesbytes
- the classfile contents for the typepublic byte[] modify(java.lang.String slashedClassName, java.lang.ClassLoader classLoader, byte[] bytes)
LoadtimeInstrumentationPlugin
modify
in interface LoadtimeInstrumentationPlugin
slashedClassName
- the class name, slashed form (e.g. java/lang/String)classLoader
- the classloader loading the typebytes
- the classfile contents for the typepublic static void recordInstance(java.lang.Object obj)
public void reloadEvent(java.lang.String typename, java.lang.Class<?> clazz, java.lang.String versionsuffix)
ReloadEventProcessorPlugin
reloadEvent
in interface ReloadEventProcessorPlugin
typename
- the (dotted) type name, for example java.lang.Stringclazz
- the Class object that has been reloadedversionsuffix
- an encoded time stamp for this version, containing chars (A-Za-z0-9)public boolean shouldRerunStaticInitializer(java.lang.String typename, java.lang.Class<?> clazz, java.lang.String encodedTimestamp)
ReloadEventProcessorPlugin
shouldRerunStaticInitializer
in interface ReloadEventProcessorPlugin
typename
- the (dotted) type name, for example java.lang.Stringclazz
- the Class object that has been reloadedencodedTimestamp
- an encoded time stamp for this version, containing chars (A-Za-z0-9)