54
54
import jdk .internal .access .JavaLangAccess ;
55
55
import jdk .internal .access .SharedSecrets ;
56
56
import jdk .internal .util .ArraysSupport ;
57
+ import jdk .internal .vm .annotation .Stable ;
57
58
58
59
public abstract sealed class AbstractPoolEntry {
59
60
/*
@@ -146,12 +147,14 @@ enum State { RAW, BYTE, CHAR, STRING }
146
147
private final int offset ;
147
148
private final int rawLen ;
148
149
// Set in any state other than RAW
149
- private int hash ;
150
- private int charLen ;
150
+ private @ Stable int hash ;
151
+ private @ Stable int charLen ;
151
152
// Set in CHAR state
152
- private char [] chars ;
153
+ private @ Stable char [] chars ;
153
154
// Only set in STRING state
154
- private String stringValue ;
155
+ private @ Stable String stringValue ;
156
+ // The descriptor symbol, if this is a descriptor
157
+ @ Stable TypeDescriptor typeSym ;
155
158
156
159
Utf8EntryImpl (ConstantPool cpm , int index ,
157
160
byte [] rawBytes , int offset , int rawLen ) {
@@ -187,6 +190,7 @@ enum State { RAW, BYTE, CHAR, STRING }
187
190
this .charLen = u .charLen ;
188
191
this .chars = u .chars ;
189
192
this .stringValue = u .stringValue ;
193
+ this .typeSym = u .typeSym ;
190
194
}
191
195
192
196
/**
@@ -419,6 +423,22 @@ void writeTo(BufWriterImpl pool) {
419
423
pool .writeUTF (stringValue );
420
424
}
421
425
}
426
+
427
+ public ClassDesc fieldTypeSymbol () {
428
+ if (typeSym instanceof ClassDesc cd )
429
+ return cd ;
430
+ var ret = ClassDesc .ofDescriptor (stringValue ());
431
+ typeSym = ret ;
432
+ return ret ;
433
+ }
434
+
435
+ public MethodTypeDesc methodTypeSymbol () {
436
+ if (typeSym instanceof MethodTypeDesc mtd )
437
+ return mtd ;
438
+ var ret = MethodTypeDesc .ofDescriptor (stringValue ());
439
+ typeSym = ret ;
440
+ return ret ;
441
+ }
422
442
}
423
443
424
444
abstract static sealed class AbstractRefEntry <T extends PoolEntry > extends AbstractPoolEntry {
@@ -585,8 +605,6 @@ public boolean equals(Object o) {
585
605
public static final class NameAndTypeEntryImpl extends AbstractRefsEntry <Utf8EntryImpl , Utf8EntryImpl >
586
606
implements NameAndTypeEntry {
587
607
588
- public TypeDescriptor typeSym = null ;
589
-
590
608
NameAndTypeEntryImpl (ConstantPool cpm , int index , Utf8EntryImpl name , Utf8EntryImpl type ) {
591
609
super (cpm , ClassFile .TAG_NAMEANDTYPE , index , name , type );
592
610
}
@@ -601,31 +619,12 @@ public Utf8Entry type() {
601
619
return ref2 ;
602
620
}
603
621
604
- public ClassDesc fieldTypeSymbol () {
605
- if (typeSym instanceof ClassDesc cd ) {
606
- return cd ;
607
- } else {
608
- return (ClassDesc )(typeSym = ClassDesc .ofDescriptor (ref2 .stringValue ()));
609
- }
610
- }
611
-
612
- public MethodTypeDesc methodTypeSymbol () {
613
- if (typeSym instanceof MethodTypeDesc mtd ) {
614
- return mtd ;
615
- } else {
616
- return (MethodTypeDesc )(typeSym = MethodTypeDesc .ofDescriptor (ref2 .stringValue ()));
617
- }
618
- }
619
-
620
622
@ Override
621
623
public NameAndTypeEntry clone (ConstantPoolBuilder cp ) {
622
624
if (cp .canWriteDirect (constantPool )) {
623
625
return this ;
624
- } else {
625
- var ret = (NameAndTypeEntryImpl )cp .nameAndTypeEntry (ref1 , ref2 );
626
- ret .typeSym = typeSym ;
627
- return ret ;
628
626
}
627
+ return cp .nameAndTypeEntry (ref1 , ref2 );
629
628
}
630
629
631
630
@ Override
@@ -897,8 +896,6 @@ public static final class MethodTypeEntryImpl
897
896
extends AbstractRefEntry <Utf8EntryImpl >
898
897
implements MethodTypeEntry {
899
898
900
- public MethodTypeDesc sym = null ;
901
-
902
899
MethodTypeEntryImpl (ConstantPool cpm , int index , Utf8EntryImpl descriptor ) {
903
900
super (cpm , ClassFile .TAG_METHODTYPE , index , descriptor );
904
901
}
@@ -912,20 +909,13 @@ public Utf8Entry descriptor() {
912
909
public MethodTypeEntry clone (ConstantPoolBuilder cp ) {
913
910
if (cp .canWriteDirect (constantPool )) {
914
911
return this ;
915
- } else {
916
- var ret = (MethodTypeEntryImpl )cp .methodTypeEntry (ref1 );
917
- ret .sym = sym ;
918
- return ret ;
919
912
}
913
+ return cp .methodTypeEntry (ref1 );
920
914
}
921
915
922
916
@ Override
923
917
public MethodTypeDesc asSymbol () {
924
- var sym = this .sym ;
925
- if (sym != null ) {
926
- return sym ;
927
- }
928
- return this .sym = MethodTypeDesc .ofDescriptor (descriptor ().stringValue ());
918
+ return ref1 .methodTypeSymbol ();
929
919
}
930
920
931
921
@ Override
0 commit comments