mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-26 14:24:46 +02:00
8342458: More consistent constant instruction handling
Reviewed-by: asotona
This commit is contained in:
parent
29ae26517f
commit
3ccd2f757d
3 changed files with 147 additions and 77 deletions
|
@ -673,7 +673,8 @@ public abstract sealed class AbstractInstruction
|
|||
if (writer.canWriteDirect(code.constantPool()))
|
||||
super.writeTo(writer);
|
||||
else
|
||||
writer.writeLoadConstant(op, constantEntry());
|
||||
// We have writer.canWriteDirect(constantEntry().constantPool()) == false
|
||||
writer.writeAdaptLoadConstant(op, constantEntry());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1346,7 +1347,12 @@ public abstract sealed class AbstractInstruction
|
|||
|
||||
@Override
|
||||
public void writeTo(DirectCodeBuilder writer) {
|
||||
writer.writeLoadConstant(op, constant);
|
||||
var constant = this.constant;
|
||||
if (writer.canWriteDirect(constant.constantPool()))
|
||||
// Allows writing ldc_w small index constants upon user request
|
||||
writer.writeDirectLoadConstant(op, constant);
|
||||
else
|
||||
writer.writeAdaptLoadConstant(op, constant);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -670,16 +670,22 @@ public final class DirectCodeBuilder
|
|||
}
|
||||
}
|
||||
|
||||
public void writeLoadConstant(Opcode opcode, LoadableConstantEntry value) {
|
||||
// Make sure Long and Double have LDC2_W and
|
||||
// rewrite to _W if index is >= 256
|
||||
int index = AbstractPoolEntry.maybeClone(constantPool, value).index();
|
||||
if (value instanceof LongEntry || value instanceof DoubleEntry) {
|
||||
opcode = Opcode.LDC2_W;
|
||||
} else if (index >= 256)
|
||||
opcode = Opcode.LDC_W;
|
||||
// value may not be writable to this constant pool
|
||||
public void writeAdaptLoadConstant(Opcode opcode, LoadableConstantEntry value) {
|
||||
var pe = AbstractPoolEntry.maybeClone(constantPool, value);
|
||||
int index = pe.index();
|
||||
if (pe != value && opcode != Opcode.LDC2_W) {
|
||||
// rewrite ldc/ldc_w if external entry; ldc2_w never needs rewrites
|
||||
opcode = index <= 0xFF ? Opcode.LDC : Opcode.LDC_W;
|
||||
}
|
||||
|
||||
assert !opcode.isWide();
|
||||
writeDirectLoadConstant(opcode, pe);
|
||||
}
|
||||
|
||||
// the loadable entry is writable to this constant pool
|
||||
public void writeDirectLoadConstant(Opcode opcode, LoadableConstantEntry pe) {
|
||||
assert !opcode.isWide() && canWriteDirect(pe.constantPool());
|
||||
int index = pe.index();
|
||||
if (opcode.sizeIfFixed() == 3) {
|
||||
bytecodesBufWriter.writeU1U2(opcode.bytecode(), index);
|
||||
} else {
|
||||
|
@ -1654,7 +1660,8 @@ public final class DirectCodeBuilder
|
|||
|
||||
@Override
|
||||
public CodeBuilder ldc(LoadableConstantEntry entry) {
|
||||
writeLoadConstant(BytecodeHelpers.ldcOpcode(entry), entry);
|
||||
var direct = AbstractPoolEntry.maybeClone(constantPool, entry);
|
||||
writeDirectLoadConstant(BytecodeHelpers.ldcOpcode(direct), direct);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue