49
49
import java .lang .classfile .attribute .StackMapTableAttribute ;
50
50
import java .lang .constant .ConstantDescs ;
51
51
import static java .lang .constant .ConstantDescs .*;
52
+ import static jdk .internal .constant .ConstantUtils .*;
53
+
52
54
import java .lang .constant .DirectMethodHandleDesc ;
53
55
import java .lang .constant .DynamicConstantDesc ;
54
56
@@ -134,7 +136,7 @@ final class ProxyGenerator {
134
136
/**
135
137
* Name of proxy class
136
138
*/
137
- private ClassEntry classEntry ;
139
+ private final ClassEntry classEntry ;
138
140
139
141
/**
140
142
* Proxy interfaces
@@ -160,10 +162,10 @@ final class ProxyGenerator {
160
162
* A ProxyGenerator object contains the state for the ongoing
161
163
* generation of a particular proxy class.
162
164
*/
163
- private ProxyGenerator (ClassLoader loader , String className , List <Class <?>> interfaces ,
165
+ private ProxyGenerator (String className , List <Class <?>> interfaces ,
164
166
int accessFlags ) {
165
167
this .cp = ConstantPoolBuilder .of ();
166
- this .classEntry = cp .classEntry (ReferenceClassDescImpl . ofValidatedBinaryName (className ));
168
+ this .classEntry = cp .classEntry (ConstantUtils . binaryNameToDesc (className ));
167
169
this .interfaces = interfaces ;
168
170
this .accessFlags = accessFlags ;
169
171
this .throwableStack = List .of (StackMapFrameInfo .ObjectVerificationTypeInfo .of (cp .classEntry (CD_Throwable )));
@@ -190,7 +192,7 @@ static byte[] generateProxyClass(ClassLoader loader,
190
192
List <Class <?>> interfaces ,
191
193
int accessFlags ) {
192
194
Objects .requireNonNull (interfaces );
193
- ProxyGenerator gen = new ProxyGenerator (loader , name , interfaces , accessFlags );
195
+ ProxyGenerator gen = new ProxyGenerator (name , interfaces , accessFlags );
194
196
final byte [] classFile = gen .generateClassFile ();
195
197
196
198
if (SAVE_GENERATED_FILES ) {
@@ -227,18 +229,10 @@ public Void run() {
227
229
private static List <ClassEntry > toClassEntries (ConstantPoolBuilder cp , List <Class <?>> types ) {
228
230
var ces = new ArrayList <ClassEntry >(types .size ());
229
231
for (var t : types )
230
- ces .add (cp .classEntry (ReferenceClassDescImpl . ofValidatedBinaryName (t .getName ())));
232
+ ces .add (cp .classEntry (ConstantUtils . binaryNameToDesc (t .getName ())));
231
233
return ces ;
232
234
}
233
235
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
-
242
236
/**
243
237
* For a given set of proxy methods with the same signature, check
244
238
* that their return types are compatible according to the Proxy
@@ -325,7 +319,7 @@ private static void checkReturnTypes(List<ProxyMethod> methods) {
325
319
* not assignable from any of the others.
326
320
*/
327
321
if (uncoveredReturnTypes .size () > 1 ) {
328
- ProxyMethod pm = methods .get ( 0 );
322
+ ProxyMethod pm = methods .getFirst ( );
329
323
throw new IllegalArgumentException (
330
324
"methods with same signature " +
331
325
pm .shortSignature +
@@ -501,7 +495,7 @@ private void addProxyMethod(Method m, Class<?> fromClass) {
501
495
502
496
String sig = m .toShortSignature ();
503
497
List <ProxyMethod > sigmethods = proxyMethods .computeIfAbsent (sig ,
504
- ( f ) -> new ArrayList <>(3 ));
498
+ _ -> new ArrayList <>(3 ));
505
499
for (ProxyMethod pm : sigmethods ) {
506
500
if (returnType == pm .returnType ) {
507
501
/*
@@ -531,7 +525,7 @@ private void addProxyMethod(Method m, Class<?> fromClass) {
531
525
private void addProxyMethod (ProxyMethod pm ) {
532
526
String sig = pm .shortSignature ;
533
527
List <ProxyMethod > sigmethods = proxyMethods .computeIfAbsent (sig ,
534
- ( f ) -> new ArrayList <>(3 ));
528
+ _ -> new ArrayList <>(3 ));
535
529
sigmethods .add (pm );
536
530
}
537
531
@@ -637,7 +631,6 @@ private ProxyMethod(Method method, String sig, Class<?>[] parameterTypes,
637
631
* Create a new specific ProxyMethod with a specific field name
638
632
*
639
633
* @param method The method for which to create a proxy
640
- * @param methodFieldName the fieldName to generate
641
634
*/
642
635
private ProxyMethod (Method method ) {
643
636
this (method , method .toShortSignature (),
@@ -650,11 +643,7 @@ private ProxyMethod(Method method) {
650
643
*/
651
644
private void generateMethod (ProxyGenerator pg , ClassBuilder clb ) {
652
645
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 );
658
647
int accessFlags = (method .isVarArgs ()) ? ACC_VARARGS | ACC_PUBLIC | ACC_FINAL
659
648
: ACC_PUBLIC | ACC_FINAL ;
660
649
var catchList = computeUniqueCatchList (exceptionTypes );
@@ -665,7 +654,7 @@ private void generateMethod(ProxyGenerator pg, ClassBuilder clb) {
665
654
.getfield (pg .handlerField )
666
655
.aload (0 )
667
656
.ldc (DynamicConstantDesc .of (pg .bsm ,
668
- toClassDesc (fromClass ),
657
+ referenceClassDesc (fromClass ),
669
658
method .getName (),
670
659
desc ));
671
660
if (parameterTypes .length > 0 ) {
@@ -693,7 +682,7 @@ private void generateMethod(ProxyGenerator pg, ClassBuilder clb) {
693
682
if (!catchList .isEmpty ()) {
694
683
var c1 = cob .newBoundLabel ();
695
684
for (var exc : catchList ) {
696
- cob .exceptionCatch (cob .startLabel (), c1 , c1 , toClassDesc (exc ));
685
+ cob .exceptionCatch (cob .startLabel (), c1 , c1 , referenceClassDesc (exc ));
697
686
}
698
687
cob .athrow (); // just rethrow the exception
699
688
var c2 = cob .newBoundLabel ();
@@ -739,7 +728,7 @@ private void codeUnwrapReturnValue(CodeBuilder cob, Class<?> type) {
739
728
.invokevirtual (prim .unwrapMethodRef (cob .constantPool ()))
740
729
.return_ (TypeKind .from (type ).asLoadable ());
741
730
} else {
742
- cob .checkcast (toClassDesc (type ))
731
+ cob .checkcast (referenceClassDesc (type ))
743
732
.areturn ();
744
733
}
745
734
}
0 commit comments