Skip to content

Commit 4849e0d

Browse files
committed
More reconciliation
1 parent 7bfffc5 commit 4849e0d

24 files changed

+374
-296
lines changed

src/main/java/io/github/dmlloyd/classfile/CodeBuilder.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -557,10 +557,10 @@ default CodeBuilder loadConstant(ConstantDesc value) {
557557
if (value == null || value == ConstantDescs.NULL)
558558
return aconst_null();
559559
if (value instanceof Number) {
560-
if (value instanceof Integer v) return loadConstant(v);
561-
if (value instanceof Long v) return loadConstant(v);
562-
if (value instanceof Float v) return loadConstant(v);
563-
if (value instanceof Double v) return loadConstant(v);
560+
if (value instanceof Integer) return loadConstant((int) value);
561+
if (value instanceof Long ) return loadConstant((long) value);
562+
if (value instanceof Float ) return loadConstant((float) value);
563+
if (value instanceof Double ) return loadConstant((double) value);
564564
}
565565
return ldc(value);
566566
}

src/main/java/io/github/dmlloyd/classfile/TypeKind.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public enum TypeKind {
131131
VOID(0, -1);
132132
// End computational types
133133

134-
private ClassDesc upperBound;
134+
private /*@Stable*/ ClassDesc upperBound;
135135
private final int slots;
136136
private final int newarrayCode;
137137

src/main/java/io/github/dmlloyd/classfile/attribute/ConstantValueAttribute.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,18 @@ static ConstantValueAttribute of(ConstantValueEntry value) {
6969
* @param value the constant value
7070
*/
7171
static ConstantValueAttribute of(ConstantDesc value) {
72-
return of(
72+
return of(//switch(value) {
73+
//case Integer i -> TemporaryConstantPool.INSTANCE.intEntry(i);
7374
value instanceof Integer i ? TemporaryConstantPool.INSTANCE.intEntry(i) :
75+
//case Float f -> TemporaryConstantPool.INSTANCE.floatEntry(f);
7476
value instanceof Float f ? TemporaryConstantPool.INSTANCE.floatEntry(f) :
77+
//case Long l -> TemporaryConstantPool.INSTANCE.longEntry(l);
7578
value instanceof Long l ? TemporaryConstantPool.INSTANCE.longEntry(l) :
79+
//case Double d -> TemporaryConstantPool.INSTANCE.doubleEntry(d);
7680
value instanceof Double d ? TemporaryConstantPool.INSTANCE.doubleEntry(d) :
81+
//case String s -> TemporaryConstantPool.INSTANCE.stringEntry(s);
7782
value instanceof String s ? TemporaryConstantPool.INSTANCE.stringEntry(s) :
83+
//default -> throw new IllegalArgumentException("Invalid ConstantValueAttribute value: " + value);
7884
BackportUtil.throwAsObj(IllegalArgumentException::new, "Invalid ConstantValueAttribute value: " + value)
7985
);
8086
}

src/main/java/io/github/dmlloyd/classfile/extras/constant/ConstantUtils.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,16 @@
3434
import java.lang.invoke.MethodType;
3535
import java.util.Set;
3636

37-
import static java.lang.constant.ConstantDescs.*;
38-
//import jdk.internal.access.JavaLangAccess;
37+
import static io.github.dmlloyd.classfile.impl.BackportUtil.JLA;
3938
//import jdk.internal.access.SharedSecrets;
39+
import static java.lang.constant.ConstantDescs.*;
4040

4141
/**
4242
* Helper methods for the implementation of {@code java.lang.constant}.
4343
*/
4444
public final class ConstantUtils {
45+
//private static final JavaLangAccess JLA = SharedSecrets.getJavaLangAccess();
46+
4547
/** an empty constant descriptor */
4648
public static final ConstantDesc[] EMPTY_CONSTANTDESC = new ConstantDesc[0];
4749
public static final ClassDesc[] EMPTY_CLASSDESC = new ClassDesc[0];

src/main/java/io/github/dmlloyd/classfile/extras/constant/ModuleDesc.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
package io.github.dmlloyd.classfile.extras.constant;
2626

2727
import io.github.dmlloyd.classfile.extras.constant.ConstantUtils;
28+
import io.github.dmlloyd.classfile.extras.constant.ModuleDescImpl;
2829

2930
import static java.util.Objects.requireNonNull;
3031

src/main/java/io/github/dmlloyd/classfile/extras/reflect/AccessFlag.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ public Set<Location> apply(ClassFileFormatVersion cffv) {
435435
// Lambda to implement locations(ClassFileFormatVersion cffv)
436436
private final Function<ClassFileFormatVersion, Set<Location>> cffvToLocations;
437437

438-
AccessFlag(int mask,
438+
private AccessFlag(int mask,
439439
boolean sourceModifier,
440440
Set<Location> locations,
441441
Function<ClassFileFormatVersion, Set<Location>> cffvToLocations) {

src/main/java/io/github/dmlloyd/classfile/impl/AbstractPoolEntry.java

Lines changed: 12 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@
3030
import java.nio.charset.StandardCharsets;
3131
import java.util.Arrays;
3232

33-
//import jdk.internal.access.JavaLangAccess;
33+
import static io.github.dmlloyd.classfile.impl.BackportUtil.JLA;
3434
//import jdk.internal.access.SharedSecrets;
35-
//import jdk.internal.util.ArraysSupport;
35+
import static io.github.dmlloyd.classfile.impl.BackportUtil.ArraysSupport;
36+
//import jdk.internal.vm.annotation.Stable;
3637
import io.github.dmlloyd.classfile.extras.constant.ExtraClassDesc;
3738
import io.github.dmlloyd.classfile.extras.constant.ModuleDesc;
3839
import io.github.dmlloyd.classfile.extras.constant.PackageDesc;
39-
//import jdk.internal.vm.annotation.Stable;
4040

4141
import static java.util.Objects.requireNonNull;
4242

@@ -130,19 +130,21 @@ public static final class Utf8EntryImpl extends AbstractPoolEntry implements Utf
130130

131131
enum State { RAW, BYTE, CHAR, STRING }
132132

133+
//private static final JavaLangAccess JLA = SharedSecrets.getJavaLangAccess();
134+
133135
private State state;
134136
private final byte[] rawBytes; // null if initialized directly from a string
135137
private final int offset;
136138
private final int rawLen;
137139
// Set in any state other than RAW
138-
private int contentHash;
139-
private int charLen;
140+
private /*@Stable*/ int contentHash;
141+
private /*@Stable*/ int charLen;
140142
// Set in CHAR state
141-
private char[] chars;
143+
private /*@Stable*/ char[] chars;
142144
// Only set in STRING state
143-
private String stringValue;
145+
private /*@Stable*/ String stringValue;
144146
// The descriptor symbol, if this is a descriptor
145-
TypeDescriptor typeSym;
147+
/*@Stable*/ TypeDescriptor typeSym;
146148

147149
Utf8EntryImpl(ConstantPool cpm, int index,
148150
byte[] rawBytes, int offset, int rawLen) {
@@ -509,8 +511,8 @@ public String asInternalName() {
509511

510512
public static final class ClassEntryImpl extends AbstractNamedEntry implements ClassEntry {
511513

512-
public ClassDesc sym;
513-
private int hash;
514+
public /*@Stable*/ ClassDesc sym;
515+
private /*@Stable*/ int hash;
514516

515517
ClassEntryImpl(ConstantPool cpm, int index, Utf8EntryImpl name) {
516518
super(cpm, TAG_CLASS, index, name);
@@ -1235,39 +1237,4 @@ public boolean equals(Object o) {
12351237
return false;
12361238
}
12371239
}
1238-
1239-
// this trick helps to keep a smaller diff up above
1240-
private static class JLA {
1241-
private static int countPositives(byte[] ba, int off, int len) {
1242-
int limit = off + len;
1243-
for (int i = off; i < limit; i++) {
1244-
if (ba[i] < 0) {
1245-
return i - off;
1246-
}
1247-
}
1248-
return len;
1249-
}
1250-
private static void inflateBytesToChars(byte[] src, int srcOff, char[] dst, int dstOff, int len) {
1251-
for (int i = 0; i < len; i++) {
1252-
dst[dstOff++] = (char) Byte.toUnsignedInt(src[srcOff++]);
1253-
}
1254-
}
1255-
}
1256-
1257-
private static class ArraysSupport {
1258-
private static int hashCodeOfUnsigned(byte[] a, int fromIndex, int length, int initialValue) {
1259-
return switch (length) {
1260-
case 0 -> initialValue;
1261-
case 1 -> 31 * initialValue + Byte.toUnsignedInt(a[fromIndex]);
1262-
default -> unsignedHashCode(initialValue, a, fromIndex, length);
1263-
};
1264-
}
1265-
private static int unsignedHashCode(int result, byte[] a, int fromIndex, int length) {
1266-
int end = fromIndex + length;
1267-
for (int i = fromIndex; i < end; i++) {
1268-
result = 31 * result + Byte.toUnsignedInt(a[i]);
1269-
}
1270-
return result;
1271-
}
1272-
}
12731240
}

src/main/java/io/github/dmlloyd/classfile/impl/AnnotationReader.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,25 +307,36 @@ public static void writeTypeAnnotation(BufWriterImpl buf, TypeAnnotation ta) {
307307
buf.writeU1(ta.targetInfo().targetType().targetTypeValue());
308308

309309
// target_info
310+
//switch (ta.targetInfo()) {
311+
//case TypeAnnotation.TypeParameterTarget tpt -> buf.writeU1(tpt.typeParameterIndex());
310312
if (ta.targetInfo() instanceof TypeAnnotation.TypeParameterTarget tpt) buf.writeU1(tpt.typeParameterIndex());
313+
//case TypeAnnotation.SupertypeTarget st -> buf.writeU2(st.supertypeIndex());
311314
else if (ta.targetInfo() instanceof TypeAnnotation.SupertypeTarget st) buf.writeU2(st.supertypeIndex());
315+
//case TypeAnnotation.TypeParameterBoundTarget tpbt -> {
312316
else if (ta.targetInfo() instanceof TypeAnnotation.TypeParameterBoundTarget tpbt) {
313317
buf.writeU1U1(tpbt.typeParameterIndex(), tpbt.boundIndex());
314318
}
315-
else if (ta.targetInfo() instanceof TypeAnnotation.EmptyTarget __) {
319+
//case TypeAnnotation.EmptyTarget _ -> {
320+
else if (ta.targetInfo() instanceof TypeAnnotation.EmptyTarget) {
316321
// nothing to write
317322
}
323+
//case TypeAnnotation.FormalParameterTarget fpt -> buf.writeU1(fpt.formalParameterIndex());
318324
else if (ta.targetInfo() instanceof TypeAnnotation.FormalParameterTarget fpt) buf.writeU1(fpt.formalParameterIndex());
325+
//case TypeAnnotation.ThrowsTarget tt -> buf.writeU2(tt.throwsTargetIndex());
319326
else if (ta.targetInfo() instanceof TypeAnnotation.ThrowsTarget tt) buf.writeU2(tt.throwsTargetIndex());
327+
//case TypeAnnotation.LocalVarTarget lvt -> {
320328
else if (ta.targetInfo() instanceof TypeAnnotation.LocalVarTarget lvt) {
321329
buf.writeU2(lvt.table().size());
322330
for (var e : lvt.table()) {
323331
int startPc = labelToBci(lr, e.startLabel(), ta);
324332
buf.writeU2U2U2(startPc, labelToBci(lr, e.endLabel(), ta) - startPc, e.index());
325333
}
326334
}
335+
//case TypeAnnotation.CatchTarget ct -> buf.writeU2(ct.exceptionTableIndex());
327336
else if (ta.targetInfo() instanceof TypeAnnotation.CatchTarget ct) buf.writeU2(ct.exceptionTableIndex());
337+
//case TypeAnnotation.OffsetTarget ot -> buf.writeU2(labelToBci(lr, ot.target(), ta));
328338
else if (ta.targetInfo() instanceof TypeAnnotation.OffsetTarget ot) buf.writeU2(labelToBci(lr, ot.target(), ta));
339+
//case TypeAnnotation.TypeArgumentTarget tat -> {
329340
else if (ta.targetInfo() instanceof TypeAnnotation.TypeArgumentTarget tat) {
330341
buf.writeU2U1(labelToBci(lr, tat.target(), ta), tat.typeArgumentIndex());
331342
}

src/main/java/io/github/dmlloyd/classfile/impl/BackportUtil.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
import java.util.function.Function;
44
import java.util.function.Supplier;
55

6-
import io.github.dmlloyd.classfile.constantpool.ConstantValueEntry;
7-
86
/**
97
* Utilities specific to the backport.
108
*/
@@ -50,6 +48,10 @@ public static <T, E extends Exception> T throwAsObj(Function<String, E> factory,
5048
throw factory.apply(msg);
5149
}
5250

51+
public static <T, E extends Exception> T throwAsObj(Supplier<E> factory) throws E {
52+
throw factory.get();
53+
}
54+
5355
public static <E extends Exception> int throwAsInt(Function<String, E> factory, String msg) throws E {
5456
throw factory.apply(msg);
5557
}

src/main/java/io/github/dmlloyd/classfile/impl/BlockCodeBuilderImpl.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,12 @@ public boolean isEmpty() {
7272
}
7373

7474
private int topLocal(CodeBuilder parent) {
75+
//return switch (parent) {
76+
//case BlockCodeBuilderImpl b -> b.topLocal;
7577
if (parent instanceof BlockCodeBuilderImpl b) return b.topLocal;
78+
//case ChainedCodeBuilder b -> b.terminal.curTopLocal();
7679
else if (parent instanceof ChainedCodeBuilder b) return b.terminal.curTopLocal();
80+
//case TerminalCodeBuilder b -> b.curTopLocal();
7781
else if (parent instanceof TerminalCodeBuilder b) return b.curTopLocal();
7882
else throw new IllegalStateException();
7983
}

0 commit comments

Comments
 (0)