@ UsedByGeneratedCode public __DynamicallyDispatchable determineDispatcher ( Object instance , String nameAndDescriptor ) { if ( nameAndDescriptor . startsWith ( "<init>" ) ) { // its a ctor, no dynamic lookup required if ( ! hasBeenReloaded ( ) ) { // TODO evaluate whether this is too naughty. it forces creation of the dispatcher so we can return it loadNewVersion ( "0" , bytesInitial ) ; } return ( __DynamicallyDispatchable ) getLiveVersion ( ) . dispatcherInstance ; } String dynamicTypeName = instance . getClass ( ) . getName ( ) ; // iterate up the hierarchy finding the first person that can satisfy that method from a virtual dispatch perspective ReloadableType rtype = typeRegistry . getReloadableType ( dynamicTypeName . replace ( ' ' , ' ' ) ) ; if ( rtype == null ) { throw new ReloadException ( "ReloadableType.determineDispatcher(): expected " + dynamicTypeName + " to be reloadable" ) ; } boolean found = false ; while ( rtype != null && ! found ) { if ( rtype . hasBeenReloaded ( ) ) { // Does the type now define it: // TODO not sure if we should be looking at deleted methods here. It is possible they are // handled by catchers/executors delegating as appropriate - and in those cases we never // end up in determineDispatcher List < MethodMember > mms = rtype . getLiveVersion ( ) . incrementalTypeDescriptor . getNewOrChangedMethods ( ) ; for ( MethodMember mm : mms ) { // boolean wd = IncrementalTypeDescriptor.wasDeleted(mm); if ( mm . isPrivate ( ) ) { // TODO is skipping of private methods correct thing to do continue ; } if ( mm . getNameAndDescriptor ( ) . equals ( nameAndDescriptor ) ) { // the reloaded version does implement this method found = true ; break ; } } } else { // Did the type originally define it: MethodMember [ ] mms = rtype . getTypeDescriptor ( ) . getMethods ( ) ; for ( MethodMember mm : mms ) { // TODO don't need superdispatcher check, name won't match will it... if ( mm . getNameAndDescriptor ( ) . equals ( nameAndDescriptor ) && ! MethodMember . isCatcher ( mm ) && ! MethodMember . isSuperDispatcher ( mm ) ) { // the original version does implement it found = true ; break ; } } } if ( ! found ) { String slashedSupername = rtype . getTypeDescriptor ( ) . getSupertypeName ( ) ; rtype = typeRegistry . getReloadableType ( slashedSupername ) ; } } if ( found ) { if ( GlobalConfiguration . isRuntimeLogging && log . isLoggable ( Level . INFO ) ) { log . log ( Level . INFO , "appears that type " + rtype . getName ( ) + " implements " + nameAndDescriptor ) ; } } if ( rtype == null ) { return null ; } if ( ! rtype . hasBeenReloaded ( ) ) { // TODO evaluate whether this is too naughty. it forces creation of the dispatcher so we can return it rtype . loadNewVersion ( "0" , rtype . bytesInitial ) ; } return ( __DynamicallyDispatchable ) rtype . getLiveVersion ( ) . dispatcherInstance ; }
Intended to handle dynamic dispatch . This will determine the right type to handle the specified method and return a dispatcher that can handle it .