private byte [ ] retransform ( byte [ ] bytes ) { if ( ! determinedNeedToRetransform ) { try { String s = System . getProperty ( "insight.enabled" , "false" ) ; if ( s . equals ( "true" ) ) { // Access the weavingTransformer field, of type WeavingTransformer ClassLoader cl = typeRegistry . getClassLoader ( ) ; Field f = cl . getClass ( ) . getSuperclass ( ) . getDeclaredField ( "weavingTransformer" ) ; if ( f != null ) { f . setAccessible ( true ) ; retransformWeavingTransformer = f . get ( cl ) ; // Stash the weavingtransformer instance and transformIfNecessaryMethod // byte[] transformIfNecessary(String className, byte[] bytes) { retransformWeavingTransformMethod = retransformWeavingTransformer . getClass ( ) . getDeclaredMethod ( "transformIfNecessary" , String . class , byte [ ] . class ) ; retransformNecessary = true ; } if ( GlobalConfiguration . isRuntimeLogging && log . isLoggable ( Level . INFO ) ) { log . info ( "Determining if retransform necessary, result = " + retransformNecessary ) ; } } } catch ( Exception e ) { log . log ( Level . SEVERE , "Unexpected exception when determining if Spring Insight enabled" , e ) ; retransformNecessary = false ; } determinedNeedToRetransform = true ; } if ( retransformNecessary ) { try { retransformWeavingTransformMethod . setAccessible ( true ) ; byte [ ] newdata = ( byte [ ] ) retransformWeavingTransformMethod . invoke ( retransformWeavingTransformer , this . slashedtypename , bytes ) ; // System.err.println("RETRANSFORMATION RUNNING. oldsize=" + bytes.length + " newsize=" + newdata.length); if ( GlobalConfiguration . isRuntimeLogging && log . isLoggable ( Level . INFO ) ) { log . info ( "retransform was attempted, oldsize=" + bytes . length + " newsize=" + newdata . length ) ; } return newdata ; } catch ( Exception e ) { if ( GlobalConfiguration . isRuntimeLogging ) { log . log ( Level . SEVERE , "Unexpected exception when trying to run other weaving transformers" , e ) ; } } } return bytes ; }
This method will attempt to apply any pre - existing transforms to the provided bytecode if it is thought to be necessary . Currently necessary is determined by finding ourselves running under tcServer and Spring Insight being turned on .