@@ -318,7 +318,6 @@ protected FieldDescriptor createConstructor(ClassOutput classOutput, BeanInfo be
318318 }
319319
320320 MethodDescriptor methodDescriptor = MethodDescriptor .of (method );
321- MethodDescriptor originalMethodDescriptor = MethodDescriptor .of (method );
322321 InterceptionInfo interception = bean .getInterceptedMethods ().get (method );
323322 DecorationInfo decoration = bean .getDecoratedMethods ().get (method );
324323 MethodDescriptor forwardDescriptor = forwardingMethods .get (methodDescriptor );
@@ -392,20 +391,10 @@ protected FieldDescriptor createConstructor(ClassOutput classOutput, BeanInfo be
392391 if (decoratorMethod != null ) {
393392 AssignableResultHandle funDecoratorInstance = funcBytecode .createVariable (Object .class );
394393 funcBytecode .assign (funDecoratorInstance , decoratorHandle );
395- String declaringClass = decoratorMethod .decorator .getBeanClass ().toString ();
396- if (decoratorMethod .decorator .isAbstract ()) {
397- String baseName = DecoratorGenerator
398- .createBaseName (decoratorMethod .decorator .getTarget ().get ().asClass ());
399- String targetPackage = DotNames .packageName (decoratorMethod .decorator .getProviderType ().name ());
400- declaringClass = generatedNameFromTarget (targetPackage , baseName ,
401- DecoratorGenerator .ABSTRACT_IMPL_SUFFIX );
402- }
403- // We need to use the decorator method in order to support generic decorators
394+ // We need to use the decorator method in order to support not visible or generic decorators
404395 MethodDescriptor decoratorMethodDescriptor = MethodDescriptor .of (decoratorMethod .method );
405- MethodDescriptor virtualMethodDescriptor = MethodDescriptor .ofMethod (declaringClass ,
406- originalMethodDescriptor .getName (),
407- decoratorMethodDescriptor .getReturnType (), decoratorMethodDescriptor .getParameterTypes ());
408- ResultHandle superResult = funcBytecode .invokeVirtualMethod (virtualMethodDescriptor , funDecoratorInstance ,
396+ ResultHandle superResult = funcBytecode .invokeInterfaceMethod (decoratorMethodDescriptor ,
397+ funDecoratorInstance ,
409398 superParamHandles );
410399 funcBytecode .returnValue (superResult != null ? superResult : funcBytecode .loadNull ());
411400 } else {
@@ -474,19 +463,11 @@ protected FieldDescriptor createConstructor(ClassOutput classOutput, BeanInfo be
474463 ResultHandle decoratorInstance = decoratedMethod .readInstanceField (FieldDescriptor .of (subclass .getClassName (),
475464 firstDecorator .getIdentifier (), Object .class .getName ()), decoratedMethod .getThis ());
476465
477- String declaringClass = firstDecorator .getBeanClass ().toString ();
478- if (firstDecorator .isAbstract ()) {
479- String baseName = DecoratorGenerator .createBaseName (firstDecorator .getTarget ().get ().asClass ());
480- String targetPackage = DotNames .packageName (firstDecorator .getProviderType ().name ());
481- declaringClass = generatedNameFromTarget (targetPackage , baseName , DecoratorGenerator .ABSTRACT_IMPL_SUFFIX );
482- }
483- // We need to use the decorator method in order to support generic decorators
466+ // We need to use the decorator method in order to support not visible or generic decorators
484467 MethodDescriptor decoratorMethodDescriptor = MethodDescriptor .of (decoratorMethod .method );
485- MethodDescriptor virtualMethodDescriptor = MethodDescriptor .ofMethod (
486- declaringClass , methodDescriptor .getName (),
487- decoratorMethodDescriptor .getReturnType (), decoratorMethodDescriptor .getParameterTypes ());
488468 decoratedMethod
489- .returnValue (decoratedMethod .invokeVirtualMethod (virtualMethodDescriptor , decoratorInstance , params ));
469+ .returnValue (
470+ decoratedMethod .invokeInterfaceMethod (decoratorMethodDescriptor , decoratorInstance , params ));
490471 }
491472 }
492473
@@ -610,7 +591,7 @@ private void processDecorator(DecoratorInfo decorator, BeanInfo bean, Type provi
610591 int paramIndex , Map <String , ResultHandle > decoratorToResultHandle ,
611592 ResultHandle creationalContextHandle , Map <MethodDescriptor , MethodDescriptor > forwardingMethods ) {
612593
613- // First genetare the delegate subclass
594+ // First generate the delegate subclass
614595 // An instance of this subclass is injected in the delegate injection point of a decorator instance
615596 ClassInfo decoratorClass = decorator .getTarget ().get ().asClass ();
616597 String baseName ;
@@ -656,10 +637,14 @@ private void processDecorator(DecoratorInfo decorator, BeanInfo bean, Type provi
656637 constructorParameterTypes .add (subclass .getClassName ());
657638 Map <DecoratorInfo , FieldDescriptor > nextDecoratorToField = new HashMap <>();
658639 for (DecoratorInfo nextDecorator : decoratorParameters ) {
640+ // this can be always of type `Object`, because decorated types are always interfaces
641+ // and their methods are always invoked via `invokeinterface` (see `SubclassGenerator`)
642+ // and the JVM verifier doesn't care about the receiver type of interface method calls
643+ // (see e.g. https://wiki.openjdk.org/display/HotSpot/InterfaceCalls)
659644 FieldCreator nextDecoratorField = delegateSubclass
660- .getFieldCreator (nextDecorator .getIdentifier (), nextDecorator . getBeanClass (). toString () )
645+ .getFieldCreator (nextDecorator .getIdentifier (), Object . class )
661646 .setModifiers (ACC_PRIVATE | ACC_FINAL );
662- constructorParameterTypes .add (nextDecorator . getBeanClass (). toString ());
647+ constructorParameterTypes .add (Object . class . getName ());
663648 nextDecoratorToField .put (nextDecorator , nextDecoratorField .getFieldDescriptor ());
664649 }
665650
@@ -764,15 +749,7 @@ && isDecorated(decoratedMethodDescriptors, methodDescriptor, resolvedMethodDescr
764749 // This method is decorated by this decorator and there is a next decorator in the chain
765750 // Just delegate to the next decorator
766751 delegateTo = forward .readInstanceField (nextDecoratorToField .get (nextDecorator .decorator ), forward .getThis ());
767- if (delegateTypeIsInterface ) {
768- ret = forward .invokeInterfaceMethod (methodDescriptor , delegateTo , params );
769- } else {
770- MethodDescriptor virtualMethod = MethodDescriptor .ofMethod (providerTypeName ,
771- methodDescriptor .getName (),
772- nextDecorator .method .returnType (),
773- nextDecorator .method .parameterTypes ());
774- ret = forward .invokeVirtualMethod (virtualMethod , delegateTo , params );
775- }
752+ ret = forward .invokeInterfaceMethod (MethodDescriptor .of (nextDecorator .method ), delegateTo , params );
776753
777754 } else {
778755 // This method is not decorated or no next decorator was found in the chain
0 commit comments