Skip to content

Commit 8b31b00

Browse files
author
duke
committedJul 3, 2024
Automatic merge of jdk:master into master
2 parents f3adc2d + 8a664a4 commit 8b31b00

File tree

9 files changed

+58
-168
lines changed

9 files changed

+58
-168
lines changed
 

‎src/java.base/share/classes/java/lang/classfile/ClassReader.java

-75
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@
2727
import java.lang.classfile.constantpool.ClassEntry;
2828
import java.lang.classfile.constantpool.ConstantPool;
2929
import java.lang.classfile.constantpool.ConstantPoolException;
30-
import java.lang.classfile.constantpool.MethodHandleEntry;
31-
import java.lang.classfile.constantpool.ModuleEntry;
32-
import java.lang.classfile.constantpool.NameAndTypeEntry;
33-
import java.lang.classfile.constantpool.PackageEntry;
3430
import java.lang.classfile.constantpool.PoolEntry;
3531
import java.lang.classfile.constantpool.Utf8Entry;
3632
import jdk.internal.classfile.impl.ClassReaderImpl;
@@ -130,77 +126,6 @@ public sealed interface ClassReader extends ConstantPool
130126
*/
131127
<T extends PoolEntry> T readEntryOrNull(int offset, Class<T> cls);
132128

133-
/**
134-
* {@return the UTF8 entry whose index is given at the specified
135-
* offset within the classfile}
136-
* @param offset the offset of the index within the classfile
137-
* @throws ConstantPoolException if the index is out of range of the
138-
* constant pool size, or zero, or the index does not correspond to
139-
* a UTF8 entry
140-
*/
141-
Utf8Entry readUtf8Entry(int offset);
142-
143-
/**
144-
* {@return the UTF8 entry whose index is given at the specified
145-
* offset within the classfile, or null if the index at the specified
146-
* offset is zero}
147-
* @param offset the offset of the index within the classfile
148-
* @throws ConstantPoolException if the index is out of range of the
149-
* constant pool size, or the index does not correspond to
150-
* a UTF8 entry
151-
*/
152-
Utf8Entry readUtf8EntryOrNull(int offset);
153-
154-
/**
155-
* {@return the module entry whose index is given at the specified
156-
* offset within the classfile}
157-
* @param offset the offset of the index within the classfile
158-
* @throws ConstantPoolException if the index is out of range of the
159-
* constant pool size, or zero, or the index does not correspond to
160-
* a module entry
161-
*/
162-
ModuleEntry readModuleEntry(int offset);
163-
164-
/**
165-
* {@return the package entry whose index is given at the specified
166-
* offset within the classfile}
167-
* @param offset the offset of the index within the classfile
168-
* @throws ConstantPoolException if the index is out of range of the
169-
* constant pool size, or zero, or the index does not correspond to
170-
* a package entry
171-
*/
172-
PackageEntry readPackageEntry(int offset);
173-
174-
/**
175-
* {@return the class entry whose index is given at the specified
176-
* offset within the classfile}
177-
* @param offset the offset of the index within the classfile
178-
* @throws ConstantPoolException if the index is out of range of the
179-
* constant pool size, or zero, or the index does not correspond to
180-
* a class entry
181-
*/
182-
ClassEntry readClassEntry(int offset);
183-
184-
/**
185-
* {@return the name-and-type entry whose index is given at the specified
186-
* offset within the classfile}
187-
* @param offset the offset of the index within the classfile
188-
* @throws ConstantPoolException if the index is out of range of the
189-
* constant pool size, or zero, or the index does not correspond to
190-
* a name-and-type entry
191-
*/
192-
NameAndTypeEntry readNameAndTypeEntry(int offset);
193-
194-
/**
195-
* {@return the method handle entry whose index is given at the specified
196-
* offset within the classfile}
197-
* @param offset the offset of the index within the classfile
198-
* @throws ConstantPoolException if the index is out of range of the
199-
* constant pool size, or zero, or the index does not correspond to
200-
* a method handle entry
201-
*/
202-
MethodHandleEntry readMethodHandleEntry(int offset);
203-
204129
/**
205130
* {@return the unsigned byte at the specified offset within the classfile}
206131
* @param offset the offset within the classfile

‎src/java.base/share/classes/jdk/internal/classfile/impl/AbstractInstruction.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ public static final class BoundNewObjectInstruction
529529
@Override
530530
public ClassEntry className() {
531531
if (classEntry == null)
532-
classEntry = code.classReader.readClassEntry(pos + 1);
532+
classEntry = code.classReader.readEntry(pos + 1, ClassEntry.class);
533533
return classEntry;
534534
}
535535

@@ -576,7 +576,7 @@ public BoundNewReferenceArrayInstruction(Opcode op, CodeImpl code, int pos) {
576576

577577
@Override
578578
public ClassEntry componentType() {
579-
return code.classReader.readClassEntry(pos + 1);
579+
return code.classReader.readEntry(pos + 1, ClassEntry.class);
580580
}
581581

582582
@Override
@@ -607,7 +607,7 @@ public int dimensions() {
607607

608608
@Override
609609
public ClassEntry arrayType() {
610-
return code.classReader.readClassEntry(pos + 1);
610+
return code.classReader.readEntry(pos + 1, ClassEntry.class);
611611
}
612612

613613
@Override
@@ -636,7 +636,7 @@ public BoundTypeCheckInstruction(Opcode op, CodeImpl code, int pos) {
636636
@Override
637637
public ClassEntry type() {
638638
if (typeEntry == null)
639-
typeEntry = code.classReader.readClassEntry(pos + 1);
639+
typeEntry = code.classReader.readEntry(pos + 1, ClassEntry.class);
640640
return typeEntry;
641641
}
642642

‎src/java.base/share/classes/jdk/internal/classfile/impl/AnnotationReader.java

+7-6
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,10 @@ public static AnnotationValue readElementValue(ClassReader classReader, int p) {
6666
case AEV_LONG -> new AnnotationImpl.OfLongImpl(classReader.readEntry(p, LongEntry.class));
6767
case AEV_SHORT -> new AnnotationImpl.OfShortImpl(classReader.readEntry(p, IntegerEntry.class));
6868
case AEV_BOOLEAN -> new AnnotationImpl.OfBooleanImpl(classReader.readEntry(p, IntegerEntry.class));
69-
case AEV_STRING -> new AnnotationImpl.OfStringImpl(classReader.readUtf8Entry(p));
70-
case AEV_ENUM -> new AnnotationImpl.OfEnumImpl(classReader.readUtf8Entry(p), classReader.readUtf8Entry(p + 2));
71-
case AEV_CLASS -> new AnnotationImpl.OfClassImpl(classReader.readUtf8Entry(p));
69+
case AEV_STRING -> new AnnotationImpl.OfStringImpl(classReader.readEntry(p, Utf8Entry.class));
70+
case AEV_ENUM -> new AnnotationImpl.OfEnumImpl(classReader.readEntry(p, Utf8Entry.class),
71+
classReader.readEntry(p + 2, Utf8Entry.class));
72+
case AEV_CLASS -> new AnnotationImpl.OfClassImpl(classReader.readEntry(p, Utf8Entry.class));
7273
case AEV_ANNOTATION -> new AnnotationImpl.OfAnnotationImpl(readAnnotation(classReader, p));
7374
case AEV_ARRAY -> {
7475
int numValues = classReader.readU2(p);
@@ -127,7 +128,7 @@ private static int skipElementValue(ClassReader classReader, int p) {
127128
}
128129

129130
private static Annotation readAnnotation(ClassReader classReader, int p) {
130-
Utf8Entry annotationClass = classReader.entryByIndex(classReader.readU2(p), Utf8Entry.class);
131+
Utf8Entry annotationClass = classReader.readEntry(p, Utf8Entry.class);
131132
p += 2;
132133
List<AnnotationElement> elems = readAnnotationElementValuePairs(classReader, p);
133134
return new AnnotationImpl(annotationClass, elems);
@@ -150,7 +151,7 @@ private static List<AnnotationElement> readAnnotationElementValuePairs(ClassRead
150151
p += 2;
151152
var annotationElements = new Object[numElementValuePairs];
152153
for (int i = 0; i < numElementValuePairs; ++i) {
153-
Utf8Entry elementName = classReader.readUtf8Entry(p);
154+
Utf8Entry elementName = classReader.readEntry(p, Utf8Entry.class);
154155
p += 2;
155156
AnnotationValue value = readElementValue(classReader, p);
156157
annotationElements[i] = new AnnotationImpl.AnnotationElementImpl(elementName, value);
@@ -239,7 +240,7 @@ private static TypeAnnotation readTypeAnnotation(ClassReader classReader, int p,
239240
};
240241
}
241242
// the annotation info for this annotation
242-
Utf8Entry type = classReader.readUtf8Entry(p);
243+
Utf8Entry type = classReader.readEntry(p, Utf8Entry.class);
243244
p += 2;
244245
return TypeAnnotation.of(targetInfo, List.of(typePath), type,
245246
readAnnotationElementValuePairs(classReader, p));

‎src/java.base/share/classes/jdk/internal/classfile/impl/BoundAttribute.java

+20-21
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public static List<Attribute<?>> readAttributes(AttributedElement enclosing, Cla
135135
int cfLen = reader.classfileLength();
136136
var apo = ((ClassReaderImpl)reader).context().attributesProcessingOption();
137137
for (int i = 0; i < size; ++i) {
138-
Utf8Entry name = reader.readUtf8Entry(p);
138+
Utf8Entry name = reader.readEntry(p, Utf8Entry.class);
139139
int len = reader.readInt(p + 2);
140140
p += 6;
141141
if (len < 0 || len > cfLen - p) {
@@ -347,7 +347,7 @@ public List<MethodParameterInfo> parameters() {
347347
int p = payloadStart + 1;
348348
int pEnd = p + (cnt * 4);
349349
for (int i = 0; p < pEnd; p += 4, i++) {
350-
Utf8Entry name = classReader.readUtf8EntryOrNull(p);
350+
Utf8Entry name = classReader.readEntryOrNull(p, Utf8Entry.class);
351351
int accessFlags = classReader.readU2(p + 2);
352352
elements[i] = MethodParameterInfo.of(Optional.ofNullable(name), accessFlags);
353353
}
@@ -367,7 +367,7 @@ public BoundModuleHashesAttribute(ClassReader cf, AttributeMapper<ModuleHashesAt
367367

368368
@Override
369369
public Utf8Entry algorithm() {
370-
return classReader.readUtf8Entry(payloadStart);
370+
return classReader.readEntry(payloadStart, Utf8Entry.class);
371371
}
372372

373373
@Override
@@ -378,7 +378,7 @@ public List<ModuleHashInfo> hashes() {
378378
int p = payloadStart + 4;
379379
//System.err.printf("%5d: ModuleHashesAttr alg = %s, cnt = %d%n", pos, algorithm(), cnt);
380380
for (int i = 0; i < cnt; ++i) {
381-
ModuleEntry module = classReader.readModuleEntry(p);
381+
ModuleEntry module = classReader.readEntry(p, ModuleEntry.class);
382382
int hashLength = classReader.readU2(p + 2);
383383
//System.err.printf("%5d: [%d] module = %s, hashLength = %d%n", p, i, module, hashLength);
384384
p += 4;
@@ -430,7 +430,7 @@ public BoundSignatureAttribute(ClassReader cf, AttributeMapper<SignatureAttribut
430430

431431
@Override
432432
public Utf8Entry signature() {
433-
return classReader.readUtf8Entry(payloadStart);
433+
return classReader.readEntry(payloadStart, Utf8Entry.class);
434434
}
435435
}
436436

@@ -442,7 +442,7 @@ public BoundSourceFileAttribute(ClassReader cf, AttributeMapper<SourceFileAttrib
442442

443443
@Override
444444
public Utf8Entry sourceFile() {
445-
return classReader.readUtf8Entry(payloadStart);
445+
return classReader.readEntry(payloadStart, Utf8Entry.class);
446446
}
447447

448448
}
@@ -454,7 +454,7 @@ public BoundModuleMainClassAttribute(ClassReader cf, AttributeMapper<ModuleMainC
454454

455455
@Override
456456
public ClassEntry mainClass() {
457-
return classReader.readClassEntry(payloadStart);
457+
return classReader.readEntry(payloadStart, ClassEntry.class);
458458
}
459459
}
460460

@@ -466,7 +466,7 @@ public BoundNestHostAttribute(ClassReader cf, AttributeMapper<NestHostAttribute>
466466

467467
@Override
468468
public ClassEntry nestHost() {
469-
return classReader.readClassEntry(payloadStart);
469+
return classReader.readEntry(payloadStart, ClassEntry.class);
470470
}
471471
}
472472

@@ -498,7 +498,7 @@ public BoundModuleTargetAttribute(ClassReader cf, AttributeMapper<ModuleTargetAt
498498

499499
@Override
500500
public Utf8Entry targetPlatform() {
501-
return classReader.readUtf8Entry(payloadStart);
501+
return classReader.readEntry(payloadStart, Utf8Entry.class);
502502
}
503503
}
504504

@@ -510,7 +510,7 @@ public BoundCompilationIDAttribute(ClassReader cf, AttributeMapper<CompilationID
510510

511511
@Override
512512
public Utf8Entry compilationId() {
513-
return classReader.readUtf8Entry(payloadStart);
513+
return classReader.readEntry(payloadStart, Utf8Entry.class);
514514
}
515515
}
516516

@@ -522,7 +522,7 @@ public BoundSourceIDAttribute(ClassReader cf, AttributeMapper<SourceIDAttribute>
522522

523523
@Override
524524
public Utf8Entry sourceId() {
525-
return classReader.readUtf8Entry(payloadStart);
525+
return classReader.readEntry(payloadStart, Utf8Entry.class);
526526
}
527527
}
528528

@@ -569,7 +569,7 @@ public BoundModuleAttribute(ClassReader cf, AttributeMapper<ModuleAttribute> map
569569

570570
@Override
571571
public ModuleEntry moduleName() {
572-
return classReader.readModuleEntry(payloadStart);
572+
return classReader.readEntry(payloadStart, ModuleEntry.class);
573573
}
574574

575575
@Override
@@ -579,7 +579,7 @@ public int moduleFlagsMask() {
579579

580580
@Override
581581
public Optional<Utf8Entry> moduleVersion() {
582-
return Optional.ofNullable(classReader.readUtf8EntryOrNull(payloadStart + 4));
582+
return Optional.ofNullable(classReader.readEntryOrNull(payloadStart + 4, Utf8Entry.class));
583583
}
584584

585585
@Override
@@ -630,7 +630,7 @@ private void structure() {
630630
ModuleRequireInfo[] elements = new ModuleRequireInfo[cnt];
631631
int end = p + (cnt * 6);
632632
for (int i = 0; p < end; p += 6, i++) {
633-
elements[i] = ModuleRequireInfo.of(classReader.readModuleEntry(p),
633+
elements[i] = ModuleRequireInfo.of(classReader.readEntry(p, ModuleEntry.class),
634634
classReader.readU2(p + 2),
635635
classReader.readEntryOrNull(p + 4, Utf8Entry.class));
636636
}
@@ -642,7 +642,7 @@ private void structure() {
642642
p += 2;
643643
ModuleExportInfo[] elements = new ModuleExportInfo[cnt];
644644
for (int i = 0; i < cnt; i++) {
645-
PackageEntry pe = classReader.readPackageEntry(p);
645+
PackageEntry pe = classReader.readEntry(p, PackageEntry.class);
646646
int exportFlags = classReader.readU2(p + 2);
647647
p += 4;
648648
List<ModuleEntry> exportsTo = readEntryList(p);
@@ -657,7 +657,7 @@ private void structure() {
657657
p += 2;
658658
ModuleOpenInfo[] elements = new ModuleOpenInfo[cnt];
659659
for (int i = 0; i < cnt; i++) {
660-
PackageEntry po = classReader.readPackageEntry(p);
660+
PackageEntry po = classReader.readEntry(p, PackageEntry.class);
661661
int opensFlags = classReader.readU2(p + 2);
662662
p += 4;
663663
List<ModuleEntry> opensTo = readEntryList(p);
@@ -675,7 +675,7 @@ private void structure() {
675675
ModuleProvideInfo[] elements = new ModuleProvideInfo[cnt];
676676
provides = new ArrayList<>(cnt);
677677
for (int i = 0; i < cnt; i++) {
678-
ClassEntry c = classReader.readClassEntry(p);
678+
ClassEntry c = classReader.readEntry(p, ClassEntry.class);
679679
p += 2;
680680
List<ClassEntry> providesWith = readEntryList(p);
681681
p += 2 + providesWith.size() * 2;
@@ -743,8 +743,7 @@ public List<BootstrapMethodEntry> bootstrapMethods() {
743743
BootstrapMethodEntry[] bs = new BootstrapMethodEntry[size];
744744
int p = payloadStart + 2;
745745
for (int i = 0; i < size; ++i) {
746-
final AbstractPoolEntry.MethodHandleEntryImpl handle
747-
= (AbstractPoolEntry.MethodHandleEntryImpl) classReader.readMethodHandleEntry(p);
746+
final var handle = classReader.readEntry(p, AbstractPoolEntry.MethodHandleEntryImpl.class);
748747
final List<LoadableConstantEntry> args = readEntryList(p + 2);
749748
p += 4 + args.size() * 2;
750749
int hash = BootstrapMethodEntryImpl.computeHashCode(handle, args);
@@ -771,7 +770,7 @@ public List<InnerClassInfo> classes() {
771770
int p = payloadStart + 2;
772771
InnerClassInfo[] elements = new InnerClassInfo[cnt];
773772
for (int i = 0; i < cnt; i++) {
774-
ClassEntry innerClass = classReader.readClassEntry(p);
773+
ClassEntry innerClass = classReader.readEntry(p, ClassEntry.class);
775774
var outerClass = classReader.readEntryOrNull(p + 2, ClassEntry.class);
776775
var innerName = classReader.readEntryOrNull(p + 4, Utf8Entry.class);
777776
int flags = classReader.readU2(p + 6);
@@ -792,7 +791,7 @@ public BoundEnclosingMethodAttribute(ClassReader cf, AttributeMapper<EnclosingMe
792791

793792
@Override
794793
public ClassEntry enclosingClass() {
795-
return classReader.readClassEntry(payloadStart);
794+
return classReader.readEntry(payloadStart, ClassEntry.class);
796795
}
797796

798797
@Override

‎src/java.base/share/classes/jdk/internal/classfile/impl/BoundRecordComponentInfo.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -46,12 +46,12 @@ public BoundRecordComponentInfo(ClassReader reader, int startPos) {
4646

4747
@Override
4848
public Utf8Entry name() {
49-
return reader.readUtf8Entry(startPos);
49+
return reader.readEntry(startPos, Utf8Entry.class);
5050
}
5151

5252
@Override
5353
public Utf8Entry descriptor() {
54-
return reader.readUtf8Entry(startPos + 2);
54+
return reader.readEntry(startPos + 2, Utf8Entry.class);
5555
}
5656

5757
@Override

‎src/java.base/share/classes/jdk/internal/classfile/impl/ClassImpl.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public List<ClassEntry> interfaces() {
137137
pos += 2;
138138
var arr = new Object[cnt];
139139
for (int i = 0; i < cnt; ++i) {
140-
arr[i] = reader.readClassEntry(pos);
140+
arr[i] = reader.readEntry(pos, ClassEntry.class);
141141
pos += 2;
142142
}
143143
this.interfaces = SharedSecrets.getJavaUtilCollectionAccess().listFromTrustedArray(arr);

0 commit comments

Comments
 (0)
Please sign in to comment.