< prev index next >

src/java.base/share/classes/java/lang/invoke/AbstractValidatingLambdaMetafactory.java

Print this page




 126         this.samBase = invokedType.returnType();
 127 
 128         this.samMethodName = samMethodName;
 129         this.samMethodType  = samMethodType;
 130 
 131         this.implMethod = implMethod;
 132         this.implMethodType = implMethod.type();
 133         this.implInfo = caller.revealDirect(implMethod);
 134         switch (implInfo.getReferenceKind()) {
 135             case REF_invokeVirtual:
 136             case REF_invokeInterface:
 137                 this.implClass = implMethodType.parameterType(0);
 138                 // reference kind reported by implInfo may not match implMethodType's first param
 139                 // Example: implMethodType is (Cloneable)String, implInfo is for Object.toString
 140                 this.implKind = implClass.isInterface() ? REF_invokeInterface : REF_invokeVirtual;
 141                 this.implIsInstanceMethod = true;
 142                 break;
 143             case REF_invokeSpecial:
 144                 // JDK-8172817: should use referenced class here, but we don't know what it was
 145                 this.implClass = implInfo.getDeclaringClass();
 146                 this.implKind = REF_invokeSpecial;
 147                 this.implIsInstanceMethod = true;













 148                 break;
 149             case REF_invokeStatic:
 150             case REF_newInvokeSpecial:
 151                 // JDK-8172817: should use referenced class here for invokestatic, but we don't know what it was
 152                 this.implClass = implInfo.getDeclaringClass();
 153                 this.implKind = implInfo.getReferenceKind();
 154                 this.implIsInstanceMethod = false;
 155                 break;
 156             default:
 157                 throw new LambdaConversionException(String.format("Unsupported MethodHandle kind: %s", implInfo));
 158         }
 159 
 160         this.instantiatedMethodType = instantiatedMethodType;
 161         this.isSerializable = isSerializable;
 162         this.markerInterfaces = markerInterfaces;
 163         this.additionalBridges = additionalBridges;
 164 
 165         if (samMethodName.isEmpty() ||
 166                 samMethodName.indexOf('.') >= 0 ||
 167                 samMethodName.indexOf(';') >= 0 ||




 126         this.samBase = invokedType.returnType();
 127 
 128         this.samMethodName = samMethodName;
 129         this.samMethodType  = samMethodType;
 130 
 131         this.implMethod = implMethod;
 132         this.implMethodType = implMethod.type();
 133         this.implInfo = caller.revealDirect(implMethod);
 134         switch (implInfo.getReferenceKind()) {
 135             case REF_invokeVirtual:
 136             case REF_invokeInterface:
 137                 this.implClass = implMethodType.parameterType(0);
 138                 // reference kind reported by implInfo may not match implMethodType's first param
 139                 // Example: implMethodType is (Cloneable)String, implInfo is for Object.toString
 140                 this.implKind = implClass.isInterface() ? REF_invokeInterface : REF_invokeVirtual;
 141                 this.implIsInstanceMethod = true;
 142                 break;
 143             case REF_invokeSpecial:
 144                 // JDK-8172817: should use referenced class here, but we don't know what it was
 145                 this.implClass = implInfo.getDeclaringClass();

 146                 this.implIsInstanceMethod = true;
 147 
 148                 // Classes compiled prior to dynamic nestmate support invokes a private instance
 149                 // method with REF_invokeSpecial.
 150                 //
 151                 // invokespecial should only be used to invoke private nestmate constructors.
 152                 // The lambda proxy class will be defined as a nestmate of targetClass.
 153                 // If the method to be invoked is an instance method of targetClass, then
 154                 // convert to use invokevirtual or invokeinterface.
 155                 if (targetClass == implClass && !implInfo.getName().equals("<init>")) { 
 156                     this.implKind = implClass.isInterface() ? REF_invokeInterface : REF_invokeVirtual;
 157                 } else {
 158                     this.implKind = REF_invokeSpecial;
 159                 }
 160                 break;
 161             case REF_invokeStatic:
 162             case REF_newInvokeSpecial:
 163                 // JDK-8172817: should use referenced class here for invokestatic, but we don't know what it was
 164                 this.implClass = implInfo.getDeclaringClass();
 165                 this.implKind = implInfo.getReferenceKind();
 166                 this.implIsInstanceMethod = false;
 167                 break;
 168             default:
 169                 throw new LambdaConversionException(String.format("Unsupported MethodHandle kind: %s", implInfo));
 170         }
 171 
 172         this.instantiatedMethodType = instantiatedMethodType;
 173         this.isSerializable = isSerializable;
 174         this.markerInterfaces = markerInterfaces;
 175         this.additionalBridges = additionalBridges;
 176 
 177         if (samMethodName.isEmpty() ||
 178                 samMethodName.indexOf('.') >= 0 ||
 179                 samMethodName.indexOf(';') >= 0 ||


< prev index next >