8341906: Optimize ClassFile writing BufBuffer

Reviewed-by: liach
This commit is contained in:
Shaojin Wen 2024-10-11 00:29:14 +00:00
parent cd4981c292
commit 24eb360147
13 changed files with 119 additions and 111 deletions

View File

@ -140,14 +140,13 @@ public sealed abstract class AbstractAttributeMapper<T extends Attribute<T>>
} }
@Override @Override
protected void writeBody(BufWriter buf, CharacterRangeTableAttribute attr) { protected void writeBody(BufWriter bufWriter, CharacterRangeTableAttribute attr) {
List<CharacterRangeInfo> ranges = attr.characterRangeTable(); List<CharacterRangeInfo> ranges = attr.characterRangeTable();
BufWriterImpl buf = (BufWriterImpl) bufWriter;
buf.writeU2(ranges.size()); buf.writeU2(ranges.size());
for (CharacterRangeInfo info : ranges) { for (CharacterRangeInfo info : ranges) {
buf.writeU2(info.startPc()); buf.writeU2U2(info.startPc(), info.endPc());
buf.writeU2(info.endPc()); buf.writeIntInt(info.characterRangeStart(), info.characterRangeEnd());
buf.writeInt(info.characterRangeStart());
buf.writeInt(info.characterRangeEnd());
buf.writeU2(info.flags()); buf.writeU2(info.flags());
} }
} }
@ -238,9 +237,10 @@ public sealed abstract class AbstractAttributeMapper<T extends Attribute<T>>
} }
@Override @Override
protected void writeBody(BufWriter buf, EnclosingMethodAttribute attr) { protected void writeBody(BufWriter bufWriter, EnclosingMethodAttribute attr) {
buf.writeIndex(attr.enclosingClass()); BufWriterImpl buf = (BufWriterImpl) bufWriter;
buf.writeIndexOrZero(attr.enclosingMethod().orElse(null)); buf.writeU2U2(buf.cpIndex(attr.enclosingClass()),
buf.cpIndexOrZero(attr.enclosingMethod().orElse(null)));
} }
} }
@ -275,13 +275,14 @@ public sealed abstract class AbstractAttributeMapper<T extends Attribute<T>>
} }
@Override @Override
protected void writeBody(BufWriter buf, InnerClassesAttribute attr) { protected void writeBody(BufWriter bufWriter, InnerClassesAttribute attr) {
List<InnerClassInfo> classes = attr.classes(); List<InnerClassInfo> classes = attr.classes();
BufWriterImpl buf = (BufWriterImpl) bufWriter;
buf.writeU2(classes.size()); buf.writeU2(classes.size());
for (InnerClassInfo ic : classes) { for (InnerClassInfo ic : classes) {
buf.writeIndex(ic.innerClass()); buf.writeU2U2U2(buf.cpIndex(ic.innerClass()),
buf.writeIndexOrZero(ic.outerClass().orElse(null)); buf.cpIndexOrZero(ic.outerClass().orElse(null)),
buf.writeIndexOrZero(ic.innerName().orElse(null)); buf.cpIndexOrZero(ic.innerName().orElse(null)));
buf.writeU2(ic.flagsMask()); buf.writeU2(ic.flagsMask());
} }
} }
@ -300,12 +301,12 @@ public sealed abstract class AbstractAttributeMapper<T extends Attribute<T>>
} }
@Override @Override
protected void writeBody(BufWriter buf, LineNumberTableAttribute attr) { protected void writeBody(BufWriter bufWriter, LineNumberTableAttribute attr) {
List<LineNumberInfo> lines = attr.lineNumbers(); List<LineNumberInfo> lines = attr.lineNumbers();
BufWriterImpl buf = (BufWriterImpl) bufWriter;
buf.writeU2(lines.size()); buf.writeU2(lines.size());
for (LineNumberInfo line : lines) { for (LineNumberInfo line : lines) {
buf.writeU2(line.startPc()); buf.writeU2U2(line.startPc(), line.lineNumber());
buf.writeU2(line.lineNumber());
} }
} }
} }
@ -323,15 +324,13 @@ public sealed abstract class AbstractAttributeMapper<T extends Attribute<T>>
} }
@Override @Override
protected void writeBody(BufWriter buf, LocalVariableTableAttribute attr) { protected void writeBody(BufWriter bufWriter, LocalVariableTableAttribute attr) {
List<LocalVariableInfo> infos = attr.localVariables(); List<LocalVariableInfo> infos = attr.localVariables();
BufWriterImpl buf = (BufWriterImpl) bufWriter;
buf.writeU2(infos.size()); buf.writeU2(infos.size());
for (LocalVariableInfo info : infos) { for (LocalVariableInfo info : infos) {
buf.writeU2(info.startPc()); buf.writeU2U2(info.startPc(), info.length());
buf.writeU2(info.length()); buf.writeU2U2U2(buf.cpIndex(info.name()), buf.cpIndex(info.type()), info.slot());
buf.writeIndex(info.name());
buf.writeIndex(info.type());
buf.writeU2(info.slot());
} }
} }
} }
@ -349,15 +348,13 @@ public sealed abstract class AbstractAttributeMapper<T extends Attribute<T>>
} }
@Override @Override
protected void writeBody(BufWriter buf, LocalVariableTypeTableAttribute attr) { protected void writeBody(BufWriter bufWriter, LocalVariableTypeTableAttribute attr) {
List<LocalVariableTypeInfo> infos = attr.localVariableTypes(); List<LocalVariableTypeInfo> infos = attr.localVariableTypes();
BufWriterImpl buf = (BufWriterImpl) bufWriter;
buf.writeU2(infos.size()); buf.writeU2(infos.size());
for (LocalVariableTypeInfo info : infos) { for (LocalVariableTypeInfo info : infos) {
buf.writeU2(info.startPc()); buf.writeU2U2(info.startPc(), info.length());
buf.writeU2(info.length()); buf.writeU2U2U2(buf.cpIndex(info.name()), buf.cpIndex(info.signature()), info.slot());
buf.writeIndex(info.name());
buf.writeIndex(info.signature());
buf.writeU2(info.slot());
} }
} }
} }
@ -375,12 +372,13 @@ public sealed abstract class AbstractAttributeMapper<T extends Attribute<T>>
} }
@Override @Override
protected void writeBody(BufWriter buf, MethodParametersAttribute attr) { protected void writeBody(BufWriter bufWriter, MethodParametersAttribute attr) {
List<MethodParameterInfo> parameters = attr.parameters(); List<MethodParameterInfo> parameters = attr.parameters();
BufWriterImpl buf = (BufWriterImpl) bufWriter;
buf.writeU1(parameters.size()); buf.writeU1(parameters.size());
for (MethodParameterInfo info : parameters) { for (MethodParameterInfo info : parameters) {
buf.writeIndexOrZero(info.name().orElse(null)); buf.writeU2U2(buf.cpIndexOrZero(info.name().orElse(null)),
buf.writeU2(info.flagsMask()); info.flagsMask());
} }
} }
} }
@ -398,26 +396,27 @@ public sealed abstract class AbstractAttributeMapper<T extends Attribute<T>>
} }
@Override @Override
protected void writeBody(BufWriter buf, ModuleAttribute attr) { protected void writeBody(BufWriter bufWriter, ModuleAttribute attr) {
buf.writeIndex(attr.moduleName()); BufWriterImpl buf = (BufWriterImpl) bufWriter;
buf.writeU2(attr.moduleFlagsMask()); buf.writeU2U2U2(buf.cpIndex(attr.moduleName()),
buf.writeIndexOrZero(attr.moduleVersion().orElse(null)); attr.moduleFlagsMask(),
buf.cpIndexOrZero(attr.moduleVersion().orElse(null)));
buf.writeU2(attr.requires().size()); buf.writeU2(attr.requires().size());
for (ModuleRequireInfo require : attr.requires()) { for (ModuleRequireInfo require : attr.requires()) {
buf.writeIndex(require.requires()); buf.writeU2U2U2(buf.cpIndex(require.requires()),
buf.writeU2(require.requiresFlagsMask()); require.requiresFlagsMask(),
buf.writeIndexOrZero(require.requiresVersion().orElse(null)); buf.cpIndexOrZero(require.requiresVersion().orElse(null)));
} }
buf.writeU2(attr.exports().size()); buf.writeU2(attr.exports().size());
for (ModuleExportInfo export : attr.exports()) { for (ModuleExportInfo export : attr.exports()) {
buf.writeIndex(export.exportedPackage()); buf.writeU2U2(buf.cpIndex(export.exportedPackage()),
buf.writeU2(export.exportsFlagsMask()); export.exportsFlagsMask());
Util.writeListIndices(buf, export.exportsTo()); Util.writeListIndices(buf, export.exportsTo());
} }
buf.writeU2(attr.opens().size()); buf.writeU2(attr.opens().size());
for (ModuleOpenInfo open : attr.opens()) { for (ModuleOpenInfo open : attr.opens()) {
buf.writeIndex(open.openedPackage()); buf.writeU2U2(buf.cpIndex(open.openedPackage()),
buf.writeU2(open.opensFlagsMask()); open.opensFlagsMask());
Util.writeListIndices(buf, open.opensTo()); Util.writeListIndices(buf, open.opensTo());
} }
Util.writeListIndices(buf, attr.uses()); Util.writeListIndices(buf, attr.uses());
@ -442,13 +441,13 @@ public sealed abstract class AbstractAttributeMapper<T extends Attribute<T>>
} }
@Override @Override
protected void writeBody(BufWriter buf, ModuleHashesAttribute attr) { protected void writeBody(BufWriter bufWriter, ModuleHashesAttribute attr) {
buf.writeIndex(attr.algorithm());
List<ModuleHashInfo> hashes = attr.hashes(); List<ModuleHashInfo> hashes = attr.hashes();
buf.writeU2(hashes.size()); BufWriterImpl buf = (BufWriterImpl) bufWriter;
buf.writeU2U2(buf.cpIndex(attr.algorithm()), hashes.size());
for (ModuleHashInfo hash : hashes) { for (ModuleHashInfo hash : hashes) {
buf.writeIndex(hash.moduleName()); buf.writeU2U2(buf.cpIndex(hash.moduleName()),
buf.writeU2(hash.hash().length); hash.hash().length);
buf.writeBytes(hash.hash()); buf.writeBytes(hash.hash());
} }
} }
@ -593,13 +592,14 @@ public sealed abstract class AbstractAttributeMapper<T extends Attribute<T>>
} }
@Override @Override
protected void writeBody(BufWriter buf, RecordAttribute attr) { protected void writeBody(BufWriter bufWriter, RecordAttribute attr) {
List<RecordComponentInfo> components = attr.components(); List<RecordComponentInfo> components = attr.components();
BufWriterImpl buf = (BufWriterImpl) bufWriter;
buf.writeU2(components.size()); buf.writeU2(components.size());
for (RecordComponentInfo info : components) { for (RecordComponentInfo info : components) {
buf.writeIndex(info.name()); buf.writeU2U2(buf.cpIndex(info.name()),
buf.writeIndex(info.descriptor()); buf.cpIndex(info.descriptor()));
Util.writeAttributes((BufWriterImpl) buf, info.attributes()); Util.writeAttributes(buf, info.attributes());
} }
} }
} }

View File

@ -88,15 +88,12 @@ public class AbstractBoundLocalVariable
return false; return false;
} }
int length = endBci - startBci; int length = endBci - startBci;
b.writeU2(startBci); b.writeU2U2(startBci, length);
b.writeU2(length);
if (b.canWriteDirect(code.constantPool())) { if (b.canWriteDirect(code.constantPool())) {
b.writeU2(nameIndex()); b.writeU2U2(nameIndex(), secondaryIndex());
b.writeU2(secondaryIndex());
} }
else { else {
b.writeIndex(name()); b.writeU2U2(b.cpIndex(name()), b.cpIndex(secondaryEntry()));
b.writeIndex(secondaryEntry());
} }
b.writeU2(slot()); b.writeU2(slot());
return true; return true;

View File

@ -200,11 +200,8 @@ public abstract sealed class AbstractPseudoInstruction
return false; return false;
} }
int length = endBci - startBci; int length = endBci - startBci;
b.writeU2(startBci); b.writeU2U2(startBci, length);
b.writeU2(length); b.writeU2U2U2(b.cpIndex(name), b.cpIndex(descriptor), slot());
b.writeIndex(name);
b.writeIndex(descriptor);
b.writeU2(slot());
return true; return true;
} }
} }

View File

@ -282,9 +282,8 @@ public final class AnnotationReader {
} }
public static void writeAnnotation(BufWriterImpl buf, Annotation annotation) { public static void writeAnnotation(BufWriterImpl buf, Annotation annotation) {
buf.writeIndex(annotation.className());
var elements = annotation.elements(); var elements = annotation.elements();
buf.writeU2(elements.size()); buf.writeU2U2(buf.cpIndex(annotation.className()), elements.size());
for (var e : elements) { for (var e : elements) {
buf.writeIndex(e.name()); buf.writeIndex(e.name());
AnnotationReader.writeAnnotationValue(buf, e.value()); AnnotationReader.writeAnnotationValue(buf, e.value());
@ -332,8 +331,8 @@ public final class AnnotationReader {
case TypeAnnotation.CatchTarget ct -> buf.writeU2(ct.exceptionTableIndex()); case TypeAnnotation.CatchTarget ct -> buf.writeU2(ct.exceptionTableIndex());
case TypeAnnotation.OffsetTarget ot -> buf.writeU2(labelToBci(lr, ot.target(), ta)); case TypeAnnotation.OffsetTarget ot -> buf.writeU2(labelToBci(lr, ot.target(), ta));
case TypeAnnotation.TypeArgumentTarget tat -> { case TypeAnnotation.TypeArgumentTarget tat -> {
buf.writeU2(labelToBci(lr, tat.target(), ta)); buf.writeU2U1(labelToBci(lr, tat.target(), ta),
buf.writeU1(tat.typeArgumentIndex()); tat.typeArgumentIndex());
} }
} }

View File

@ -168,6 +168,16 @@ public final class BufWriterImpl implements BufWriter {
this.offset = offset + 5; this.offset = offset + 5;
} }
public void writeU2U1(int x1, int x2) {
reserveSpace(3);
byte[] elems = this.elems;
int offset = this.offset;
elems[offset ] = (byte) (x1 >> 8);
elems[offset + 1] = (byte) x1;
elems[offset + 2] = (byte) x2;
this.offset = offset + 3;
}
public void writeU2U2(int x1, int x2) { public void writeU2U2(int x1, int x2) {
reserveSpace(4); reserveSpace(4);
byte[] elems = this.elems; byte[] elems = this.elems;
@ -204,6 +214,21 @@ public final class BufWriterImpl implements BufWriter {
this.offset = offset + 4; this.offset = offset + 4;
} }
public void writeIntInt(int x1, int x2) {
reserveSpace(8);
byte[] elems = this.elems;
int offset = this.offset;
elems[offset ] = (byte) (x1 >> 24);
elems[offset + 1] = (byte) (x1 >> 16);
elems[offset + 2] = (byte) (x1 >> 8);
elems[offset + 3] = (byte) x1;
elems[offset + 4] = (byte) (x2 >> 24);
elems[offset + 5] = (byte) (x2 >> 16);
elems[offset + 6] = (byte) (x2 >> 8);
elems[offset + 7] = (byte) x2;
this.offset = offset + 8;
}
@Override @Override
public void writeFloat(float x) { public void writeFloat(float x) {
writeInt(Float.floatToIntBits(x)); writeInt(Float.floatToIntBits(x));
@ -355,6 +380,12 @@ public final class BufWriterImpl implements BufWriter {
return idx; return idx;
} }
public int cpIndexOrZero(PoolEntry entry) {
if (entry == null || entry.index() == 0)
return 0;
return cpIndex(entry);
}
@ForceInline @ForceInline
@Override @Override
public void writeIndex(PoolEntry entry) { public void writeIndex(PoolEntry entry) {
@ -371,10 +402,7 @@ public final class BufWriterImpl implements BufWriter {
@Override @Override
public void writeIndexOrZero(PoolEntry entry) { public void writeIndexOrZero(PoolEntry entry) {
if (entry == null || entry.index() == 0) writeU2(cpIndexOrZero(entry));
writeU2(0);
else
writeIndex(entry);
} }
/** /**

View File

@ -219,12 +219,10 @@ public final class DirectClassBuilder
} }
// Now we can make the head // Now we can make the head
head.writeLong((((long) ClassFile.MAGIC_NUMBER) << 32) head.writeInt(ClassFile.MAGIC_NUMBER);
| ((minorVersion & 0xFFFFL) << 16) head.writeU2U2(minorVersion, majorVersion);
| (majorVersion & 0xFFFFL));
constantPool.writeTo(head); constantPool.writeTo(head);
head.writeU2U2(flags, head.cpIndex(thisClassEntry)); head.writeU2U2U2(flags, head.cpIndex(thisClassEntry), head.cpIndexOrZero(superclass));
head.writeIndexOrZero(superclass);
head.writeU2(interfaceEntriesSize); head.writeU2(interfaceEntriesSize);
for (int i = 0; i < interfaceEntriesSize; i++) { for (int i = 0; i < interfaceEntriesSize; i++) {
head.writeIndex(ies[i]); head.writeIndex(ies[i]);

View File

@ -257,8 +257,7 @@ public final class DirectCodeBuilder
} }
} else { } else {
b.writeU2U2(start, end - 1); b.writeU2U2(start, end - 1);
b.writeInt(cr.characterRangeStart()); b.writeIntInt(cr.characterRangeStart(), cr.characterRangeEnd());
b.writeInt(cr.characterRangeEnd());
b.writeU2(cr.flags()); b.writeU2(cr.flags());
} }
} }
@ -640,8 +639,7 @@ public final class DirectCodeBuilder
if (pad != 4) if (pad != 4)
bytecodesBufWriter.skip(pad); // padding content can be anything bytecodesBufWriter.skip(pad); // padding content can be anything
writeLongLabelOffset(instructionPc, defaultTarget); writeLongLabelOffset(instructionPc, defaultTarget);
bytecodesBufWriter.writeInt(low); bytecodesBufWriter.writeIntInt(low, high);
bytecodesBufWriter.writeInt(high);
var caseMap = new HashMap<Integer, Label>(cases.size()); var caseMap = new HashMap<Integer, Label>(cases.size());
for (var c : cases) { for (var c : cases) {
caseMap.put(c.caseValue(), c.target()); caseMap.put(c.caseValue(), c.target());
@ -668,8 +666,7 @@ public final class DirectCodeBuilder
} }
public void writeInvokeDynamic(InvokeDynamicEntry ref) { public void writeInvokeDynamic(InvokeDynamicEntry ref) {
bytecodesBufWriter.writeIndex(INVOKEDYNAMIC, ref); bytecodesBufWriter.writeU1U2U2(INVOKEDYNAMIC, bytecodesBufWriter.cpIndex(ref), 0);
bytecodesBufWriter.writeU2(0);
} }
public void writeNewObject(ClassEntry type) { public void writeNewObject(ClassEntry type) {

View File

@ -80,9 +80,7 @@ public final class DirectFieldBuilder
@Override @Override
public void writeTo(BufWriterImpl buf) { public void writeTo(BufWriterImpl buf) {
buf.writeU2(flags); buf.writeU2U2U2(flags, buf.cpIndex(name), buf.cpIndex(desc));
buf.writeIndex(name);
buf.writeIndex(desc);
attributes.writeTo(buf); attributes.writeTo(buf);
} }
} }

View File

@ -84,9 +84,9 @@ public final class FieldImpl
reader.copyBytesTo(buf, startPos, endPos - startPos); reader.copyBytesTo(buf, startPos, endPos - startPos);
} }
else { else {
buf.writeU2(flags().flagsMask()); buf.writeU2U2U2(flags().flagsMask(),
buf.writeIndex(fieldName()); buf.cpIndex(fieldName()),
buf.writeIndex(fieldType()); buf.cpIndex(fieldType()));
Util.writeAttributes(buf, attributes()); Util.writeAttributes(buf, attributes());
} }
} }

View File

@ -103,9 +103,9 @@ public final class MethodImpl
reader.copyBytesTo(buf, startPos, endPos - startPos); reader.copyBytesTo(buf, startPos, endPos - startPos);
} }
else { else {
buf.writeU2(flags().flagsMask()); buf.writeU2U2U2(flags().flagsMask(),
buf.writeIndex(methodName()); buf.cpIndex(methodName()),
buf.writeIndex(methodType()); buf.cpIndex(methodType()));
Util.writeAttributes(buf, attributes()); Util.writeAttributes(buf, attributes());
} }
} }

View File

@ -135,8 +135,7 @@ public class StackMapDecoder {
if (diffLocalsSize == 0 && offsetDelta < 64) { //same frame if (diffLocalsSize == 0 && offsetDelta < 64) { //same frame
out.writeU1(offsetDelta); out.writeU1(offsetDelta);
} else { //chop, same extended or append frame } else { //chop, same extended or append frame
out.writeU1(251 + diffLocalsSize); out.writeU1U2(251 + diffLocalsSize, offsetDelta);
out.writeU2(offsetDelta);
for (int i=commonLocalsSize; i<fr.locals().size(); i++) writeTypeInfo(out, fr.locals().get(i)); for (int i=commonLocalsSize; i<fr.locals().size(); i++) writeTypeInfo(out, fr.locals().get(i));
} }
return; return;
@ -145,16 +144,13 @@ public class StackMapDecoder {
if (offsetDelta < 64) { //same locals 1 stack item frame if (offsetDelta < 64) { //same locals 1 stack item frame
out.writeU1(64 + offsetDelta); out.writeU1(64 + offsetDelta);
} else { //same locals 1 stack item extended frame } else { //same locals 1 stack item extended frame
out.writeU1(247); out.writeU1U2(247, offsetDelta);
out.writeU2(offsetDelta);
} }
writeTypeInfo(out, fr.stack().get(0)); writeTypeInfo(out, fr.stack().get(0));
return; return;
} }
//full frame //full frame
out.writeU1(255); out.writeU1U2U2(255, offsetDelta, fr.locals().size());
out.writeU2(offsetDelta);
out.writeU2(fr.locals().size());
for (var l : fr.locals()) writeTypeInfo(out, l); for (var l : fr.locals()) writeTypeInfo(out, l);
out.writeU2(fr.stack().size()); out.writeU2(fr.stack().size());
for (var s : fr.stack()) writeTypeInfo(out, s); for (var s : fr.stack()) writeTypeInfo(out, s);
@ -168,15 +164,15 @@ public class StackMapDecoder {
} }
private static void writeTypeInfo(BufWriterImpl bw, VerificationTypeInfo vti) { private static void writeTypeInfo(BufWriterImpl bw, VerificationTypeInfo vti) {
bw.writeU1(vti.tag()); int tag = vti.tag();
switch (vti.tag()) { switch (tag) {
case ITEM_TOP, ITEM_INTEGER, ITEM_FLOAT, ITEM_DOUBLE, ITEM_LONG, ITEM_NULL, case ITEM_TOP, ITEM_INTEGER, ITEM_FLOAT, ITEM_DOUBLE, ITEM_LONG, ITEM_NULL,
ITEM_UNINITIALIZED_THIS -> ITEM_UNINITIALIZED_THIS ->
{} bw.writeU1(tag);
case ITEM_OBJECT -> case ITEM_OBJECT ->
bw.writeIndex(((ObjectVerificationTypeInfo)vti).className()); bw.writeU1U2(tag, bw.cpIndex(((ObjectVerificationTypeInfo)vti).className()));
case ITEM_UNINITIALIZED -> case ITEM_UNINITIALIZED ->
bw.writeU2(bw.labelContext().labelToBci(((UninitializedVerificationTypeInfo)vti).newTarget())); bw.writeU1U2(tag, bw.labelContext().labelToBci(((UninitializedVerificationTypeInfo)vti).newTarget()));
default -> throw new IllegalArgumentException("Invalid verification type tag: " + vti.tag()); default -> throw new IllegalArgumentException("Invalid verification type tag: " + vti.tag());
} }
} }

View File

@ -1432,8 +1432,7 @@ public final class StackMapGenerator {
return; return;
} }
//full frame //full frame
out.writeU1U2(255, offsetDelta); out.writeU1U2U2(255, offsetDelta, localsSize);
out.writeU2(localsSize);
for (int i=0; i<localsSize; i++) locals[i].writeTo(out, cp); for (int i=0; i<localsSize; i++) locals[i].writeTo(out, cp);
out.writeU2(stackSize); out.writeU2(stackSize);
for (int i=0; i<stackSize; i++) stack[i].writeTo(out, cp); for (int i=0; i<stackSize; i++) stack[i].writeTo(out, cp);
@ -1600,13 +1599,14 @@ public final class StackMapGenerator {
return Type.TOP_TYPE; return Type.TOP_TYPE;
} }
void writeTo(BufWriter bw, ConstantPoolBuilder cp) { void writeTo(BufWriterImpl bw, ConstantPoolBuilder cp) {
bw.writeU1(tag);
switch (tag) { switch (tag) {
case ITEM_OBJECT -> case ITEM_OBJECT ->
bw.writeU2(cp.classEntry(sym).index()); bw.writeU1U2(tag, cp.classEntry(sym).index());
case ITEM_UNINITIALIZED -> case ITEM_UNINITIALIZED ->
bw.writeU2(bci); bw.writeU1U2(tag, bci);
default ->
bw.writeU1(tag);
} }
} }
} }

View File

@ -287,12 +287,10 @@ public class Util {
((DirectMethodBuilder)mb).writeAttribute(new UnboundAttribute.AdHocAttribute<CodeAttribute>(Attributes.code()) { ((DirectMethodBuilder)mb).writeAttribute(new UnboundAttribute.AdHocAttribute<CodeAttribute>(Attributes.code()) {
@Override @Override
public void writeBody(BufWriterImpl b) { public void writeBody(BufWriterImpl b) {
b.writeU2(-1);//max stack b.writeU2U2(-1, -1);//max stack & locals
b.writeU2(-1);//max locals
b.writeInt(bytecode.length()); b.writeInt(bytecode.length());
b.writeBytes(bytecode.array(), 0, bytecode.length()); b.writeBytes(bytecode.array(), 0, bytecode.length());
b.writeU2(0);//exception handlers b.writeU2U2(0, 0);//exception handlers & attributes
b.writeU2(0);//attributes
} }
})))); }))));
ClassPrinter.toYaml(clm.methods().get(0).code().get(), ClassPrinter.Verbosity.TRACE_ALL, dump); ClassPrinter.toYaml(clm.methods().get(0).code().get(), ClassPrinter.Verbosity.TRACE_ALL, dump);