4949import java .lang .classfile .attribute .StackMapTableAttribute ;
5050import java .lang .constant .ConstantDescs ;
5151import static java .lang .constant .ConstantDescs .*;
52+ import static jdk .internal .constant .ConstantUtils .*;
53+
5254import java .lang .constant .DirectMethodHandleDesc ;
5355import java .lang .constant .DynamicConstantDesc ;
5456
@@ -134,7 +136,7 @@ final class ProxyGenerator {
134136 /**
135137 * Name of proxy class
136138 */
137- private ClassEntry classEntry ;
139+ private final ClassEntry classEntry ;
138140
139141 /**
140142 * Proxy interfaces
@@ -160,10 +162,10 @@ final class ProxyGenerator {
160162 * A ProxyGenerator object contains the state for the ongoing
161163 * generation of a particular proxy class.
162164 */
163- private ProxyGenerator (ClassLoader loader , String className , List <Class <?>> interfaces ,
165+ private ProxyGenerator (String className , List <Class <?>> interfaces ,
164166 int accessFlags ) {
165167 this .cp = ConstantPoolBuilder .of ();
166- this .classEntry = cp .classEntry (ReferenceClassDescImpl . ofValidatedBinaryName (className ));
168+ this .classEntry = cp .classEntry (ConstantUtils . binaryNameToDesc (className ));
167169 this .interfaces = interfaces ;
168170 this .accessFlags = accessFlags ;
169171 this .throwableStack = List .of (StackMapFrameInfo .ObjectVerificationTypeInfo .of (cp .classEntry (CD_Throwable )));
@@ -190,7 +192,7 @@ static byte[] generateProxyClass(ClassLoader loader,
190192 List <Class <?>> interfaces ,
191193 int accessFlags ) {
192194 Objects .requireNonNull (interfaces );
193- ProxyGenerator gen = new ProxyGenerator (loader , name , interfaces , accessFlags );
195+ ProxyGenerator gen = new ProxyGenerator (name , interfaces , accessFlags );
194196 final byte [] classFile = gen .generateClassFile ();
195197
196198 if (SAVE_GENERATED_FILES ) {
@@ -227,18 +229,10 @@ public Void run() {
227229 private static List <ClassEntry > toClassEntries (ConstantPoolBuilder cp , List <Class <?>> types ) {
228230 var ces = new ArrayList <ClassEntry >(types .size ());
229231 for (var t : types )
230- ces .add (cp .classEntry (ReferenceClassDescImpl . ofValidatedBinaryName (t .getName ())));
232+ ces .add (cp .classEntry (ConstantUtils . binaryNameToDesc (t .getName ())));
231233 return ces ;
232234 }
233235
234- /**
235- * {@return the {@code ClassDesc} of the given type}
236- * @param type the {@code Class} object
237- */
238- private static ClassDesc toClassDesc (Class <?> type ) {
239- return ClassDesc .ofDescriptor (type .descriptorString ());
240- }
241-
242236 /**
243237 * For a given set of proxy methods with the same signature, check
244238 * that their return types are compatible according to the Proxy
@@ -325,7 +319,7 @@ private static void checkReturnTypes(List<ProxyMethod> methods) {
325319 * not assignable from any of the others.
326320 */
327321 if (uncoveredReturnTypes .size () > 1 ) {
328- ProxyMethod pm = methods .get ( 0 );
322+ ProxyMethod pm = methods .getFirst ( );
329323 throw new IllegalArgumentException (
330324 "methods with same signature " +
331325 pm .shortSignature +
@@ -501,7 +495,7 @@ private void addProxyMethod(Method m, Class<?> fromClass) {
501495
502496 String sig = m .toShortSignature ();
503497 List <ProxyMethod > sigmethods = proxyMethods .computeIfAbsent (sig ,
504- ( f ) -> new ArrayList <>(3 ));
498+ _ -> new ArrayList <>(3 ));
505499 for (ProxyMethod pm : sigmethods ) {
506500 if (returnType == pm .returnType ) {
507501 /*
@@ -531,7 +525,7 @@ private void addProxyMethod(Method m, Class<?> fromClass) {
531525 private void addProxyMethod (ProxyMethod pm ) {
532526 String sig = pm .shortSignature ;
533527 List <ProxyMethod > sigmethods = proxyMethods .computeIfAbsent (sig ,
534- ( f ) -> new ArrayList <>(3 ));
528+ _ -> new ArrayList <>(3 ));
535529 sigmethods .add (pm );
536530 }
537531
@@ -637,7 +631,6 @@ private ProxyMethod(Method method, String sig, Class<?>[] parameterTypes,
637631 * Create a new specific ProxyMethod with a specific field name
638632 *
639633 * @param method The method for which to create a proxy
640- * @param methodFieldName the fieldName to generate
641634 */
642635 private ProxyMethod (Method method ) {
643636 this (method , method .toShortSignature (),
@@ -650,11 +643,7 @@ private ProxyMethod(Method method) {
650643 */
651644 private void generateMethod (ProxyGenerator pg , ClassBuilder clb ) {
652645 var cp = pg .cp ;
653- var pTypes = new ClassDesc [parameterTypes .length ];
654- for (int i = 0 ; i < pTypes .length ; i ++) {
655- pTypes [i ] = toClassDesc (parameterTypes [i ]);
656- }
657- MethodTypeDesc desc = MethodTypeDescImpl .ofTrusted (toClassDesc (returnType ), pTypes );
646+ var desc = methodTypeDesc (returnType , parameterTypes );
658647 int accessFlags = (method .isVarArgs ()) ? ACC_VARARGS | ACC_PUBLIC | ACC_FINAL
659648 : ACC_PUBLIC | ACC_FINAL ;
660649 var catchList = computeUniqueCatchList (exceptionTypes );
@@ -665,7 +654,7 @@ private void generateMethod(ProxyGenerator pg, ClassBuilder clb) {
665654 .getfield (pg .handlerField )
666655 .aload (0 )
667656 .ldc (DynamicConstantDesc .of (pg .bsm ,
668- toClassDesc (fromClass ),
657+ referenceClassDesc (fromClass ),
669658 method .getName (),
670659 desc ));
671660 if (parameterTypes .length > 0 ) {
@@ -693,7 +682,7 @@ private void generateMethod(ProxyGenerator pg, ClassBuilder clb) {
693682 if (!catchList .isEmpty ()) {
694683 var c1 = cob .newBoundLabel ();
695684 for (var exc : catchList ) {
696- cob .exceptionCatch (cob .startLabel (), c1 , c1 , toClassDesc (exc ));
685+ cob .exceptionCatch (cob .startLabel (), c1 , c1 , referenceClassDesc (exc ));
697686 }
698687 cob .athrow (); // just rethrow the exception
699688 var c2 = cob .newBoundLabel ();
@@ -739,7 +728,7 @@ private void codeUnwrapReturnValue(CodeBuilder cob, Class<?> type) {
739728 .invokevirtual (prim .unwrapMethodRef (cob .constantPool ()))
740729 .return_ (TypeKind .from (type ).asLoadable ());
741730 } else {
742- cob .checkcast (toClassDesc (type ))
731+ cob .checkcast (referenceClassDesc (type ))
743732 .areturn ();
744733 }
745734 }
0 commit comments