8323058: Revisit j.l.classfile.CodeBuilder API surface

Reviewed-by: briangoetz, psandoz
This commit is contained in:
Adam Sotona 2024-05-02 10:08:29 +00:00
parent 286cbf831c
commit ae82405ff7
53 changed files with 725 additions and 876 deletions

View File

@ -228,7 +228,7 @@
* instruction invoking {@code println} could have been generated with {@link * instruction invoking {@code println} could have been generated with {@link
* java.lang.classfile.CodeBuilder#invokevirtual(java.lang.constant.ClassDesc, * java.lang.classfile.CodeBuilder#invokevirtual(java.lang.constant.ClassDesc,
* java.lang.String, java.lang.constant.MethodTypeDesc) CodeBuilder.invokevirtual}, {@link * java.lang.String, java.lang.constant.MethodTypeDesc) CodeBuilder.invokevirtual}, {@link
* java.lang.classfile.CodeBuilder#invokeInstruction(java.lang.classfile.Opcode, * java.lang.classfile.CodeBuilder#invoke(java.lang.classfile.Opcode,
* java.lang.constant.ClassDesc, java.lang.String, java.lang.constant.MethodTypeDesc, * java.lang.constant.ClassDesc, java.lang.String, java.lang.constant.MethodTypeDesc,
* boolean) CodeBuilder.invokeInstruction}, or {@link * boolean) CodeBuilder.invokeInstruction}, or {@link
* java.lang.classfile.CodeBuilder#with(java.lang.classfile.ClassFileElement) * java.lang.classfile.CodeBuilder#with(java.lang.classfile.ClassFileElement)

View File

@ -213,7 +213,7 @@ class PackageSnippets {
if (e instanceof InvokeInstruction i if (e instanceof InvokeInstruction i
&& i.owner().asInternalName().equals("Foo") && i.owner().asInternalName().equals("Foo")
&& i.opcode() == Opcode.INVOKESTATIC) && i.opcode() == Opcode.INVOKESTATIC)
b.invokeInstruction(i.opcode(), CD_Bar, i.name().stringValue(), i.typeSymbol(), i.isInterface()); b.invoke(i.opcode(), CD_Bar, i.name().stringValue(), i.typeSymbol(), i.isInterface());
else b.with(e); else b.with(e);
}; };
// @end // @end
@ -327,7 +327,7 @@ class PackageSnippets {
for (CodeElement e : xm) { for (CodeElement e : xm) {
if (e instanceof InvokeInstruction i && i.owner().asInternalName().equals("Foo") if (e instanceof InvokeInstruction i && i.owner().asInternalName().equals("Foo")
&& i.opcode() == Opcode.INVOKESTATIC) && i.opcode() == Opcode.INVOKESTATIC)
codeBuilder.invokeInstruction(i.opcode(), CD_Bar, codeBuilder.invoke(i.opcode(), CD_Bar,
i.name().stringValue(), i.typeSymbol(), i.isInterface()); i.name().stringValue(), i.typeSymbol(), i.isInterface());
else codeBuilder.with(e); else codeBuilder.with(e);
}}); }});

View File

@ -382,7 +382,7 @@ public class MethodHandleProxies {
// <clinit> // <clinit>
clb.withMethodBody(CLASS_INIT_NAME, MTD_void, ACC_STATIC, cob -> { clb.withMethodBody(CLASS_INIT_NAME, MTD_void, ACC_STATIC, cob -> {
cob.constantInstruction(ifaceDesc); cob.loadConstant(ifaceDesc);
cob.putstatic(proxyDesc, TYPE_NAME, CD_Class); cob.putstatic(proxyDesc, TYPE_NAME, CD_Class);
cob.return_(); cob.return_();
}); });
@ -406,7 +406,7 @@ public class MethodHandleProxies {
// this.m<i> = callerBoundTarget.asType(xxType); // this.m<i> = callerBoundTarget.asType(xxType);
cob.aload(0); cob.aload(0);
cob.aload(3); cob.aload(3);
cob.constantInstruction(mi.desc); cob.loadConstant(mi.desc);
cob.invokevirtual(CD_MethodHandle, "asType", MTD_MethodHandle_MethodType); cob.invokevirtual(CD_MethodHandle, "asType", MTD_MethodHandle_MethodType);
cob.putfield(proxyDesc, mi.fieldName, CD_MethodHandle); cob.putfield(proxyDesc, mi.fieldName, CD_MethodHandle);
} }
@ -423,12 +423,12 @@ public class MethodHandleProxies {
// check lookupClass // check lookupClass
cob.aload(0); cob.aload(0);
cob.invokevirtual(CD_MethodHandles_Lookup, "lookupClass", MTD_Class); cob.invokevirtual(CD_MethodHandles_Lookup, "lookupClass", MTD_Class);
cob.constantInstruction(proxyDesc); cob.loadConstant(proxyDesc);
cob.if_acmpne(failLabel); cob.if_acmpne(failLabel);
// check original access // check original access
cob.aload(0); cob.aload(0);
cob.invokevirtual(CD_MethodHandles_Lookup, "lookupModes", MTD_int); cob.invokevirtual(CD_MethodHandles_Lookup, "lookupModes", MTD_int);
cob.constantInstruction(Lookup.ORIGINAL); cob.loadConstant(Lookup.ORIGINAL);
cob.iand(); cob.iand();
cob.ifeq(failLabel); cob.ifeq(failLabel);
// success // success
@ -452,11 +452,11 @@ public class MethodHandleProxies {
bcb.aload(0); bcb.aload(0);
bcb.getfield(proxyDesc, mi.fieldName, CD_MethodHandle); bcb.getfield(proxyDesc, mi.fieldName, CD_MethodHandle);
for (int j = 0; j < mi.desc.parameterCount(); j++) { for (int j = 0; j < mi.desc.parameterCount(); j++) {
bcb.loadInstruction(TypeKind.from(mi.desc.parameterType(j)), bcb.loadLocal(TypeKind.from(mi.desc.parameterType(j)),
bcb.parameterSlot(j)); bcb.parameterSlot(j));
} }
bcb.invokevirtual(CD_MethodHandle, "invokeExact", mi.desc); bcb.invokevirtual(CD_MethodHandle, "invokeExact", mi.desc);
bcb.returnInstruction(TypeKind.from(mi.desc.returnType())); bcb.return_(TypeKind.from(mi.desc.returnType()));
}, ctb -> ctb }, ctb -> ctb
// catch (Error | RuntimeException | Declared ex) { throw ex; } // catch (Error | RuntimeException | Declared ex) { throw ex; }
.catchingMulti(mi.thrown, CodeBuilder::athrow) .catchingMulti(mi.thrown, CodeBuilder::athrow)

View File

@ -1124,7 +1124,7 @@ public final class StringConcatFactory {
} }
} }
len += args.parameterCount() * ARGUMENT_SIZE_FACTOR; len += args.parameterCount() * ARGUMENT_SIZE_FACTOR;
cb.constantInstruction(len); cb.loadConstant(len);
cb.invokespecial(STRING_BUILDER, "<init>", INT_CONSTRUCTOR_TYPE); cb.invokespecial(STRING_BUILDER, "<init>", INT_CONSTRUCTOR_TYPE);
// At this point, we have a blank StringBuilder on stack, fill it in with .append calls. // At this point, we have a blank StringBuilder on stack, fill it in with .append calls.
@ -1137,7 +1137,7 @@ public final class StringConcatFactory {
} }
Class<?> cl = args.parameterType(c); Class<?> cl = args.parameterType(c);
TypeKind kind = TypeKind.from(cl); TypeKind kind = TypeKind.from(cl);
cb.loadInstruction(kind, off); cb.loadLocal(kind, off);
off += kind.slotSize(); off += kind.slotSize();
MethodTypeDesc desc = getSBAppendDesc(cl); MethodTypeDesc desc = getSBAppendDesc(cl);
cb.invokevirtual(STRING_BUILDER, "append", desc); cb.invokevirtual(STRING_BUILDER, "append", desc);

View File

@ -689,7 +689,7 @@ final class ProxyGenerator {
.block(blockBuilder -> blockBuilder .block(blockBuilder -> blockBuilder
.aload(cob.parameterSlot(0)) .aload(cob.parameterSlot(0))
.invokevirtual(CD_MethodHandles_Lookup, "lookupClass", MTD_Class) .invokevirtual(CD_MethodHandles_Lookup, "lookupClass", MTD_Class)
.constantInstruction(Opcode.LDC, CD_Proxy) .ldc(CD_Proxy)
.if_acmpne(blockBuilder.breakLabel()) .if_acmpne(blockBuilder.breakLabel())
.aload(cob.parameterSlot(0)) .aload(cob.parameterSlot(0))
.invokevirtual(CD_MethodHandles_Lookup, "hasFullPrivilegeAccess", MTD_boolean) .invokevirtual(CD_MethodHandles_Lookup, "hasFullPrivilegeAccess", MTD_boolean)
@ -763,11 +763,11 @@ final class ProxyGenerator {
if (parameterTypes.length > 0) { if (parameterTypes.length > 0) {
// Create an array and fill with the parameters converting primitives to wrappers // Create an array and fill with the parameters converting primitives to wrappers
cob.constantInstruction(parameterTypes.length) cob.loadConstant(parameterTypes.length)
.anewarray(CE_Object); .anewarray(CE_Object);
for (int i = 0; i < parameterTypes.length; i++) { for (int i = 0; i < parameterTypes.length; i++) {
cob.dup() cob.dup()
.constantInstruction(i); .loadConstant(i);
codeWrapArgument(cob, parameterTypes[i], cob.parameterSlot(i)); codeWrapArgument(cob, parameterTypes[i], cob.parameterSlot(i));
cob.aastore(); cob.aastore();
} }
@ -811,7 +811,7 @@ final class ProxyGenerator {
*/ */
private void codeWrapArgument(CodeBuilder cob, Class<?> type, int slot) { private void codeWrapArgument(CodeBuilder cob, Class<?> type, int slot) {
if (type.isPrimitive()) { if (type.isPrimitive()) {
cob.loadInstruction(TypeKind.from(type).asLoadable(), slot); cob.loadLocal(TypeKind.from(type).asLoadable(), slot);
PrimitiveTypeInfo prim = PrimitiveTypeInfo.get(type); PrimitiveTypeInfo prim = PrimitiveTypeInfo.get(type);
cob.invokestatic(prim.wrapperMethodRef); cob.invokestatic(prim.wrapperMethodRef);
} else { } else {
@ -830,7 +830,7 @@ final class ProxyGenerator {
cob.checkcast(prim.wrapperClass) cob.checkcast(prim.wrapperClass)
.invokevirtual(prim.unwrapMethodRef) .invokevirtual(prim.unwrapMethodRef)
.returnInstruction(TypeKind.from(type).asLoadable()); .return_(TypeKind.from(type).asLoadable());
} else { } else {
cob.checkcast(toClassDesc(type)) cob.checkcast(toClassDesc(type))
.areturn(); .areturn();
@ -847,13 +847,13 @@ final class ProxyGenerator {
codeClassForName(cob, fromClass); codeClassForName(cob, fromClass);
cob.ldc(method.getName()) cob.ldc(method.getName())
.constantInstruction(parameterTypes.length) .loadConstant(parameterTypes.length)
.anewarray(CE_Class); .anewarray(CE_Class);
// Construct an array with the parameter types mapping primitives to Wrapper types // Construct an array with the parameter types mapping primitives to Wrapper types
for (int i = 0; i < parameterTypes.length; i++) { for (int i = 0; i < parameterTypes.length; i++) {
cob.dup() cob.dup()
.constantInstruction(i); .loadConstant(i);
if (parameterTypes[i].isPrimitive()) { if (parameterTypes[i].isPrimitive()) {
PrimitiveTypeInfo prim = PrimitiveTypeInfo.get(parameterTypes[i]); PrimitiveTypeInfo prim = PrimitiveTypeInfo.get(parameterTypes[i]);
cob.getstatic(prim.typeFieldRef); cob.getstatic(prim.typeFieldRef);

View File

@ -414,7 +414,7 @@ public class SwitchBootstraps {
cb.ireturn(); cb.ireturn();
cb.labelBinding(nonNullLabel); cb.labelBinding(nonNullLabel);
if (labelConstants.length == 0) { if (labelConstants.length == 0) {
cb.constantInstruction(0) cb.loadConstant(0)
.ireturn(); .ireturn();
return; return;
} }
@ -454,7 +454,7 @@ public class SwitchBootstraps {
// Object o = ... // Object o = ...
// o instanceof Wrapped(float) // o instanceof Wrapped(float)
cb.aload(SELECTOR_OBJ); cb.aload(SELECTOR_OBJ);
cb.instanceof_(Wrapper.forBasicType(classLabel) cb.instanceOf(Wrapper.forBasicType(classLabel)
.wrapperType() .wrapperType()
.describeConstable() .describeConstable()
.orElseThrow()); .orElseThrow());
@ -464,7 +464,7 @@ public class SwitchBootstraps {
// o instanceof float // o instanceof float
Label notNumber = cb.newLabel(); Label notNumber = cb.newLabel();
cb.aload(SELECTOR_OBJ); cb.aload(SELECTOR_OBJ);
cb.instanceof_(ConstantDescs.CD_Number); cb.instanceOf(ConstantDescs.CD_Number);
if (selectorType == long.class || selectorType == float.class || selectorType == double.class || if (selectorType == long.class || selectorType == float.class || selectorType == double.class ||
selectorType == Long.class || selectorType == Float.class || selectorType == Double.class) { selectorType == Long.class || selectorType == Float.class || selectorType == Double.class) {
cb.ifeq(next); cb.ifeq(next);
@ -493,7 +493,7 @@ public class SwitchBootstraps {
cb.goto_(compare); cb.goto_(compare);
cb.labelBinding(notNumber); cb.labelBinding(notNumber);
cb.aload(SELECTOR_OBJ); cb.aload(SELECTOR_OBJ);
cb.instanceof_(ConstantDescs.CD_Character); cb.instanceOf(ConstantDescs.CD_Character);
cb.ifeq(next); cb.ifeq(next);
cb.aload(SELECTOR_OBJ); cb.aload(SELECTOR_OBJ);
cb.checkcast(ConstantDescs.CD_Character); cb.checkcast(ConstantDescs.CD_Character);
@ -514,11 +514,11 @@ public class SwitchBootstraps {
Optional<ClassDesc> classLabelConstableOpt = classLabel.describeConstable(); Optional<ClassDesc> classLabelConstableOpt = classLabel.describeConstable();
if (classLabelConstableOpt.isPresent()) { if (classLabelConstableOpt.isPresent()) {
cb.aload(SELECTOR_OBJ); cb.aload(SELECTOR_OBJ);
cb.instanceof_(classLabelConstableOpt.orElseThrow()); cb.instanceOf(classLabelConstableOpt.orElseThrow());
cb.ifeq(next); cb.ifeq(next);
} else { } else {
cb.aload(EXTRA_CLASS_LABELS); cb.aload(EXTRA_CLASS_LABELS);
cb.constantInstruction(extraClassLabels.size()); cb.loadConstant(extraClassLabels.size());
cb.invokeinterface(ConstantDescs.CD_List, cb.invokeinterface(ConstantDescs.CD_List,
"get", "get",
MethodTypeDesc.of(ConstantDescs.CD_Object, MethodTypeDesc.of(ConstantDescs.CD_Object,
@ -537,7 +537,7 @@ public class SwitchBootstraps {
int enumIdx = enumDescs.size(); int enumIdx = enumDescs.size();
enumDescs.add(enumLabel); enumDescs.add(enumLabel);
cb.aload(ENUM_CACHE); cb.aload(ENUM_CACHE);
cb.constantInstruction(enumIdx); cb.loadConstant(enumIdx);
cb.invokestatic(ConstantDescs.CD_Integer, cb.invokestatic(ConstantDescs.CD_Integer,
"valueOf", "valueOf",
MethodTypeDesc.of(ConstantDescs.CD_Integer, MethodTypeDesc.of(ConstantDescs.CD_Integer,
@ -561,7 +561,7 @@ public class SwitchBootstraps {
Label compare = cb.newLabel(); Label compare = cb.newLabel();
Label notNumber = cb.newLabel(); Label notNumber = cb.newLabel();
cb.aload(SELECTOR_OBJ); cb.aload(SELECTOR_OBJ);
cb.instanceof_(ConstantDescs.CD_Number); cb.instanceOf(ConstantDescs.CD_Number);
cb.ifeq(notNumber); cb.ifeq(notNumber);
cb.aload(SELECTOR_OBJ); cb.aload(SELECTOR_OBJ);
cb.checkcast(ConstantDescs.CD_Number); cb.checkcast(ConstantDescs.CD_Number);
@ -571,7 +571,7 @@ public class SwitchBootstraps {
cb.goto_(compare); cb.goto_(compare);
cb.labelBinding(notNumber); cb.labelBinding(notNumber);
cb.aload(SELECTOR_OBJ); cb.aload(SELECTOR_OBJ);
cb.instanceof_(ConstantDescs.CD_Character); cb.instanceOf(ConstantDescs.CD_Character);
cb.ifeq(next); cb.ifeq(next);
cb.aload(SELECTOR_OBJ); cb.aload(SELECTOR_OBJ);
cb.checkcast(ConstantDescs.CD_Character); cb.checkcast(ConstantDescs.CD_Character);
@ -587,9 +587,9 @@ public class SwitchBootstraps {
element.caseLabel() instanceof Double || element.caseLabel() instanceof Double ||
element.caseLabel() instanceof Boolean)) { element.caseLabel() instanceof Boolean)) {
if (element.caseLabel() instanceof Boolean c) { if (element.caseLabel() instanceof Boolean c) {
cb.constantInstruction(c ? 1 : 0); cb.loadConstant(c ? 1 : 0);
} else { } else {
cb.constantInstruction((ConstantDesc) element.caseLabel()); cb.loadConstant((ConstantDesc) element.caseLabel());
} }
cb.invokestatic(element.caseLabel().getClass().describeConstable().orElseThrow(), cb.invokestatic(element.caseLabel().getClass().describeConstable().orElseThrow(),
"valueOf", "valueOf",
@ -605,11 +605,11 @@ public class SwitchBootstraps {
throw new InternalError("Unsupported label type: " + throw new InternalError("Unsupported label type: " +
element.caseLabel().getClass()); element.caseLabel().getClass());
} }
cb.constantInstruction(idx); cb.loadConstant(idx);
cb.ireturn(); cb.ireturn();
} }
cb.labelBinding(dflt); cb.labelBinding(dflt);
cb.constantInstruction(cases.size()); cb.loadConstant(cases.size());
cb.ireturn(); cb.ireturn();
}; };
} }

View File

@ -62,7 +62,7 @@ public final class CatchBuilderImpl implements CodeBuilder.CatchBuilder {
if (catchBlock == null) { if (catchBlock == null) {
if (tryBlock.reachable()) { if (tryBlock.reachable()) {
b.branchInstruction(Opcode.GOTO, tryCatchEnd); b.branch(Opcode.GOTO, tryCatchEnd);
} }
} }
@ -76,7 +76,7 @@ public final class CatchBuilderImpl implements CodeBuilder.CatchBuilder {
if (catchBlock != null) { if (catchBlock != null) {
catchBlock.end(); catchBlock.end();
if (catchBlock.reachable()) { if (catchBlock.reachable()) {
b.branchInstruction(Opcode.GOTO, tryCatchEnd); b.branch(Opcode.GOTO, tryCatchEnd);
} }
} }

View File

@ -231,25 +231,25 @@ public record ClassRemapperImpl(Function<ClassDesc, ClassDesc> mapFunction) impl
return (CodeBuilder cob, CodeElement coe) -> { return (CodeBuilder cob, CodeElement coe) -> {
switch (coe) { switch (coe) {
case FieldInstruction fai -> case FieldInstruction fai ->
cob.fieldInstruction(fai.opcode(), map(fai.owner().asSymbol()), cob.fieldAccess(fai.opcode(), map(fai.owner().asSymbol()),
fai.name().stringValue(), map(fai.typeSymbol())); fai.name().stringValue(), map(fai.typeSymbol()));
case InvokeInstruction ii -> case InvokeInstruction ii ->
cob.invokeInstruction(ii.opcode(), map(ii.owner().asSymbol()), cob.invoke(ii.opcode(), map(ii.owner().asSymbol()),
ii.name().stringValue(), mapMethodDesc(ii.typeSymbol()), ii.name().stringValue(), mapMethodDesc(ii.typeSymbol()),
ii.isInterface()); ii.isInterface());
case InvokeDynamicInstruction idi -> case InvokeDynamicInstruction idi ->
cob.invokeDynamicInstruction(DynamicCallSiteDesc.of( cob.invokedynamic(DynamicCallSiteDesc.of(
idi.bootstrapMethod(), idi.name().stringValue(), idi.bootstrapMethod(), idi.name().stringValue(),
mapMethodDesc(idi.typeSymbol()), mapMethodDesc(idi.typeSymbol()),
idi.bootstrapArgs().stream().map(this::mapConstantValue).toArray(ConstantDesc[]::new))); idi.bootstrapArgs().stream().map(this::mapConstantValue).toArray(ConstantDesc[]::new)));
case NewObjectInstruction c -> case NewObjectInstruction c ->
cob.newObjectInstruction(map(c.className().asSymbol())); cob.new_(map(c.className().asSymbol()));
case NewReferenceArrayInstruction c -> case NewReferenceArrayInstruction c ->
cob.anewarray(map(c.componentType().asSymbol())); cob.anewarray(map(c.componentType().asSymbol()));
case NewMultiArrayInstruction c -> case NewMultiArrayInstruction c ->
cob.multianewarray(map(c.arrayType().asSymbol()), c.dimensions()); cob.multianewarray(map(c.arrayType().asSymbol()), c.dimensions());
case TypeCheckInstruction c -> case TypeCheckInstruction c ->
cob.typeCheckInstruction(c.opcode(), map(c.type().asSymbol())); cob.with(TypeCheckInstruction.of(c.opcode(), map(c.type().asSymbol())));
case ExceptionCatch c -> case ExceptionCatch c ->
cob.exceptionCatch(c.tryStart(), c.tryEnd(), c.handler(),c.catchType() cob.exceptionCatch(c.tryStart(), c.tryEnd(), c.handler(),c.catchType()
.map(d -> TemporaryConstantPool.INSTANCE.classEntry(map(d.asSymbol())))); .map(d -> TemporaryConstantPool.INSTANCE.classEntry(map(d.asSymbol()))));
@ -260,7 +260,7 @@ public record ClassRemapperImpl(Function<ClassDesc, ClassDesc> mapFunction) impl
cob.localVariableType(c.slot(), c.name().stringValue(), cob.localVariableType(c.slot(), c.name().stringValue(),
mapSignature(c.signatureSymbol()), c.startScope(), c.endScope()); mapSignature(c.signatureSymbol()), c.startScope(), c.endScope());
case LoadConstantInstruction ldc -> case LoadConstantInstruction ldc ->
cob.constantInstruction(ldc.opcode(), cob.loadConstant(ldc.opcode(),
mapConstantValue(ldc.constantValue())); mapConstantValue(ldc.constantValue()));
case RuntimeVisibleTypeAnnotationsAttribute aa -> case RuntimeVisibleTypeAnnotationsAttribute aa ->
cob.with(RuntimeVisibleTypeAnnotationsAttribute.of( cob.with(RuntimeVisibleTypeAnnotationsAttribute.of(

View File

@ -50,15 +50,15 @@ public final class CodeLocalsShifterImpl implements CodeLocalsShifter {
public void accept(CodeBuilder cob, CodeElement coe) { public void accept(CodeBuilder cob, CodeElement coe) {
switch (coe) { switch (coe) {
case LoadInstruction li -> case LoadInstruction li ->
cob.loadInstruction( cob.loadLocal(
li.typeKind(), li.typeKind(),
shift(cob, li.slot(), li.typeKind())); shift(cob, li.slot(), li.typeKind()));
case StoreInstruction si -> case StoreInstruction si ->
cob.storeInstruction( cob.storeLocal(
si.typeKind(), si.typeKind(),
shift(cob, si.slot(), si.typeKind())); shift(cob, si.slot(), si.typeKind()));
case IncrementInstruction ii -> case IncrementInstruction ii ->
cob.incrementInstruction( cob.iinc(
shift(cob, ii.slot(), TypeKind.IntType), shift(cob, ii.slot(), TypeKind.IntType),
ii.constant()); ii.constant());
case LocalVariable lv -> case LocalVariable lv ->

View File

@ -51,18 +51,18 @@ public record CodeRelabelerImpl(BiFunction<Label, CodeBuilder, Label> mapFunctio
public void accept(CodeBuilder cob, CodeElement coe) { public void accept(CodeBuilder cob, CodeElement coe) {
switch (coe) { switch (coe) {
case BranchInstruction bi -> case BranchInstruction bi ->
cob.branchInstruction( cob.branch(
bi.opcode(), bi.opcode(),
relabel(bi.target(), cob)); relabel(bi.target(), cob));
case LookupSwitchInstruction lsi -> case LookupSwitchInstruction lsi ->
cob.lookupSwitchInstruction( cob.lookupswitch(
relabel(lsi.defaultTarget(), cob), relabel(lsi.defaultTarget(), cob),
lsi.cases().stream().map(c -> lsi.cases().stream().map(c ->
SwitchCase.of( SwitchCase.of(
c.caseValue(), c.caseValue(),
relabel(c.target(), cob))).toList()); relabel(c.target(), cob))).toList());
case TableSwitchInstruction tsi -> case TableSwitchInstruction tsi ->
cob.tableSwitchInstruction( cob.tableswitch(
tsi.lowValue(), tsi.lowValue(),
tsi.highValue(), tsi.highValue(),
relabel(tsi.defaultTarget(), cob), relabel(tsi.defaultTarget(), cob),

View File

@ -274,8 +274,8 @@ public class BindingSpecializer {
if (shouldAcquire(i)) { if (shouldAcquire(i)) {
int scopeLocal = cb.allocateLocal(ReferenceType); int scopeLocal = cb.allocateLocal(ReferenceType);
initialScopeSlots[numScopes++] = scopeLocal; initialScopeSlots[numScopes++] = scopeLocal;
cb.constantInstruction(null); cb.loadConstant(null);
cb.storeInstruction(ReferenceType, scopeLocal); // need to initialize all scope locals here in case an exception occurs cb.storeLocal(ReferenceType, scopeLocal); // need to initialize all scope locals here in case an exception occurs
} }
} }
scopeSlots = Arrays.copyOf(initialScopeSlots, numScopes); // fit to size scopeSlots = Arrays.copyOf(initialScopeSlots, numScopes); // fit to size
@ -284,7 +284,7 @@ public class BindingSpecializer {
// create a Binding.Context for this call // create a Binding.Context for this call
if (callingSequence.allocationSize() != 0) { if (callingSequence.allocationSize() != 0) {
cb.constantInstruction(callingSequence.allocationSize()); cb.loadConstant(callingSequence.allocationSize());
cb.invokestatic(CD_SharedUtils, "newBoundedArena", MTD_NEW_BOUNDED_ARENA); cb.invokestatic(CD_SharedUtils, "newBoundedArena", MTD_NEW_BOUNDED_ARENA);
} else if (callingSequence.forUpcall() && needsSession()) { } else if (callingSequence.forUpcall() && needsSession()) {
cb.invokestatic(CD_SharedUtils, "newEmptyArena", MTD_NEW_EMPTY_ARENA); cb.invokestatic(CD_SharedUtils, "newEmptyArena", MTD_NEW_EMPTY_ARENA);
@ -292,7 +292,7 @@ public class BindingSpecializer {
cb.getstatic(CD_SharedUtils, "DUMMY_ARENA", CD_Arena); cb.getstatic(CD_SharedUtils, "DUMMY_ARENA", CD_Arena);
} }
contextIdx = cb.allocateLocal(ReferenceType); contextIdx = cb.allocateLocal(ReferenceType);
cb.storeInstruction(ReferenceType, contextIdx); cb.storeLocal(ReferenceType, contextIdx);
// in case the call needs a return buffer, allocate it here. // in case the call needs a return buffer, allocate it here.
// for upcalls the VM wrapper stub allocates the buffer. // for upcalls the VM wrapper stub allocates the buffer.
@ -300,7 +300,7 @@ public class BindingSpecializer {
emitLoadInternalAllocator(); emitLoadInternalAllocator();
emitAllocateCall(callingSequence.returnBufferSize(), 1); emitAllocateCall(callingSequence.returnBufferSize(), 1);
returnBufferIdx = cb.allocateLocal(ReferenceType); returnBufferIdx = cb.allocateLocal(ReferenceType);
cb.storeInstruction(ReferenceType, returnBufferIdx); cb.storeLocal(ReferenceType, returnBufferIdx);
} }
Label tryStart = cb.newLabel(); Label tryStart = cb.newLabel();
@ -323,7 +323,7 @@ public class BindingSpecializer {
// for downcalls, recipes have an input value, which we set up here // for downcalls, recipes have an input value, which we set up here
if (callingSequence.needsReturnBuffer() && i == 0) { if (callingSequence.needsReturnBuffer() && i == 0) {
assert returnBufferIdx != -1; assert returnBufferIdx != -1;
cb.loadInstruction(ReferenceType, returnBufferIdx); cb.loadLocal(ReferenceType, returnBufferIdx);
pushType(MemorySegment.class); pushType(MemorySegment.class);
} else { } else {
emitGetInput(); emitGetInput();
@ -339,7 +339,7 @@ public class BindingSpecializer {
// return buffer ptr is wrapped in a MemorySegment above, but not passed to the leaf handle // return buffer ptr is wrapped in a MemorySegment above, but not passed to the leaf handle
popType(MemorySegment.class); popType(MemorySegment.class);
returnBufferIdx = cb.allocateLocal(ReferenceType); returnBufferIdx = cb.allocateLocal(ReferenceType);
cb.storeInstruction(ReferenceType, returnBufferIdx); cb.storeLocal(ReferenceType, returnBufferIdx);
} else { } else {
// for upcalls the recipe result is an argument to the leaf handle // for upcalls the recipe result is an argument to the leaf handle
emitSetOutput(typeStack.pop()); emitSetOutput(typeStack.pop());
@ -352,14 +352,14 @@ public class BindingSpecializer {
// load the leaf MethodHandle // load the leaf MethodHandle
if (callingSequence.forDowncall()) { if (callingSequence.forDowncall()) {
cb.constantInstruction(CLASS_DATA_DESC); cb.loadConstant(CLASS_DATA_DESC);
} else { } else {
cb.loadInstruction(ReferenceType, 0); // load target arg cb.loadLocal(ReferenceType, 0); // load target arg
} }
cb.checkcast(CD_MethodHandle); cb.checkcast(CD_MethodHandle);
// load all the leaf args // load all the leaf args
for (int i = 0; i < leafArgSlots.length; i++) { for (int i = 0; i < leafArgSlots.length; i++) {
cb.loadInstruction(TypeKind.from(leafArgTypes.get(i)), leafArgSlots[i]); cb.loadLocal(TypeKind.from(leafArgTypes.get(i)), leafArgSlots[i]);
} }
// call leaf MH // call leaf MH
cb.invokevirtual(CD_MethodHandle, "invokeExact", desc(leafType)); cb.invokevirtual(CD_MethodHandle, "invokeExact", desc(leafType));
@ -396,7 +396,7 @@ public class BindingSpecializer {
} else { } else {
popType(callerMethodType.returnType()); popType(callerMethodType.returnType());
assert typeStack.isEmpty(); assert typeStack.isEmpty();
cb.returnInstruction(TypeKind.from(callerMethodType.returnType())); cb.return_(TypeKind.from(callerMethodType.returnType()));
} }
} else { } else {
assert callerMethodType.returnType() == void.class; assert callerMethodType.returnType() == void.class;
@ -411,13 +411,13 @@ public class BindingSpecializer {
// finally // finally
emitCleanup(); emitCleanup();
if (callingSequence.forDowncall()) { if (callingSequence.forDowncall()) {
cb.throwInstruction(); cb.athrow();
} else { } else {
cb.invokestatic(CD_SharedUtils, "handleUncaughtException", MTD_HANDLE_UNCAUGHT_EXCEPTION); cb.invokestatic(CD_SharedUtils, "handleUncaughtException", MTD_HANDLE_UNCAUGHT_EXCEPTION);
if (callerMethodType.returnType() != void.class) { if (callerMethodType.returnType() != void.class) {
TypeKind returnTypeKind = TypeKind.from(callerMethodType.returnType()); TypeKind returnTypeKind = TypeKind.from(callerMethodType.returnType());
emitConstZero(returnTypeKind); emitConstZero(returnTypeKind);
cb.returnInstruction(returnTypeKind); cb.return_(returnTypeKind);
} else { } else {
cb.return_(); cb.return_();
} }
@ -477,13 +477,13 @@ public class BindingSpecializer {
} }
private void emitSetOutput(Class<?> storeType) { private void emitSetOutput(Class<?> storeType) {
cb.storeInstruction(TypeKind.from(storeType), leafArgSlots[leafArgTypes.size()]); cb.storeLocal(TypeKind.from(storeType), leafArgSlots[leafArgTypes.size()]);
leafArgTypes.add(storeType); leafArgTypes.add(storeType);
} }
private void emitGetInput() { private void emitGetInput() {
Class<?> highLevelType = callerMethodType.parameterType(paramIndex); Class<?> highLevelType = callerMethodType.parameterType(paramIndex);
cb.loadInstruction(TypeKind.from(highLevelType), cb.parameterSlot(paramIndex)); cb.loadLocal(TypeKind.from(highLevelType), cb.parameterSlot(paramIndex));
if (shouldAcquire(paramIndex)) { if (shouldAcquire(paramIndex)) {
cb.dup(); cb.dup();
@ -505,7 +505,7 @@ public class BindingSpecializer {
boolean hasOtherScopes = curScopeLocalIdx != 0; boolean hasOtherScopes = curScopeLocalIdx != 0;
for (int i = 0; i < curScopeLocalIdx; i++) { for (int i = 0; i < curScopeLocalIdx; i++) {
cb.dup(); // dup for comparison cb.dup(); // dup for comparison
cb.loadInstruction(ReferenceType, scopeSlots[i]); cb.loadLocal(ReferenceType, scopeSlots[i]);
cb.if_acmpeq(skipAcquire); cb.if_acmpeq(skipAcquire);
} }
@ -514,7 +514,7 @@ public class BindingSpecializer {
int nextScopeLocal = scopeSlots[curScopeLocalIdx++]; int nextScopeLocal = scopeSlots[curScopeLocalIdx++];
// call acquire first here. So that if it fails, we don't call release // call acquire first here. So that if it fails, we don't call release
cb.invokevirtual(CD_MemorySessionImpl, "acquire0", MTD_ACQUIRE0); // call acquire on the other cb.invokevirtual(CD_MemorySessionImpl, "acquire0", MTD_ACQUIRE0); // call acquire on the other
cb.storeInstruction(ReferenceType, nextScopeLocal); // store off one to release later cb.storeLocal(ReferenceType, nextScopeLocal); // store off one to release later
if (hasOtherScopes) { // avoid ASM generating a bunch of nops for the dead code if (hasOtherScopes) { // avoid ASM generating a bunch of nops for the dead code
cb.goto_(end); cb.goto_(end);
@ -528,9 +528,9 @@ public class BindingSpecializer {
private void emitReleaseScopes() { private void emitReleaseScopes() {
for (int scopeLocal : scopeSlots) { for (int scopeLocal : scopeSlots) {
cb.loadInstruction(ReferenceType, scopeLocal); cb.loadLocal(ReferenceType, scopeLocal);
cb.ifThen(Opcode.IFNONNULL, ifCb -> { cb.ifThen(Opcode.IFNONNULL, ifCb -> {
ifCb.loadInstruction(ReferenceType, scopeLocal); ifCb.loadLocal(ReferenceType, scopeLocal);
ifCb.invokevirtual(CD_MemorySessionImpl, "release0", MTD_RELEASE0); ifCb.invokevirtual(CD_MemorySessionImpl, "release0", MTD_RELEASE0);
}); });
} }
@ -539,18 +539,18 @@ public class BindingSpecializer {
private void emitSaveReturnValue(Class<?> storeType) { private void emitSaveReturnValue(Class<?> storeType) {
TypeKind typeKind = TypeKind.from(storeType); TypeKind typeKind = TypeKind.from(storeType);
retValIdx = cb.allocateLocal(typeKind); retValIdx = cb.allocateLocal(typeKind);
cb.storeInstruction(typeKind, retValIdx); cb.storeLocal(typeKind, retValIdx);
} }
private void emitRestoreReturnValue(Class<?> loadType) { private void emitRestoreReturnValue(Class<?> loadType) {
assert retValIdx != -1; assert retValIdx != -1;
cb.loadInstruction(TypeKind.from(loadType), retValIdx); cb.loadLocal(TypeKind.from(loadType), retValIdx);
pushType(loadType); pushType(loadType);
} }
private void emitLoadInternalSession() { private void emitLoadInternalSession() {
assert contextIdx != -1; assert contextIdx != -1;
cb.loadInstruction(ReferenceType, contextIdx); cb.loadLocal(ReferenceType, contextIdx);
cb.checkcast(CD_Arena); cb.checkcast(CD_Arena);
cb.invokeinterface(CD_Arena, "scope", MTD_SCOPE); cb.invokeinterface(CD_Arena, "scope", MTD_SCOPE);
cb.checkcast(CD_MemorySessionImpl); cb.checkcast(CD_MemorySessionImpl);
@ -558,20 +558,20 @@ public class BindingSpecializer {
private void emitLoadInternalAllocator() { private void emitLoadInternalAllocator() {
assert contextIdx != -1; assert contextIdx != -1;
cb.loadInstruction(ReferenceType, contextIdx); cb.loadLocal(ReferenceType, contextIdx);
} }
private void emitCloseContext() { private void emitCloseContext() {
assert contextIdx != -1; assert contextIdx != -1;
cb.loadInstruction(ReferenceType, contextIdx); cb.loadLocal(ReferenceType, contextIdx);
cb.checkcast(CD_Arena); cb.checkcast(CD_Arena);
cb.invokeinterface(CD_Arena, "close", MTD_CLOSE); cb.invokeinterface(CD_Arena, "close", MTD_CLOSE);
} }
private void emitBoxAddress(BoxAddress boxAddress) { private void emitBoxAddress(BoxAddress boxAddress) {
popType(long.class); popType(long.class);
cb.constantInstruction(boxAddress.size()); cb.loadConstant(boxAddress.size());
cb.constantInstruction(boxAddress.align()); cb.loadConstant(boxAddress.align());
if (needsSession()) { if (needsSession()) {
emitLoadInternalSession(); emitLoadInternalSession();
cb.invokestatic(CD_Utils, "longToAddress", MTD_LONG_TO_ADDRESS_SCOPE); cb.invokestatic(CD_Utils, "longToAddress", MTD_LONG_TO_ADDRESS_SCOPE);
@ -584,7 +584,7 @@ public class BindingSpecializer {
private void emitAllocBuffer(Allocate binding) { private void emitAllocBuffer(Allocate binding) {
if (callingSequence.forDowncall()) { if (callingSequence.forDowncall()) {
assert returnAllocatorIdx != -1; assert returnAllocatorIdx != -1;
cb.loadInstruction(ReferenceType, returnAllocatorIdx); cb.loadLocal(ReferenceType, returnAllocatorIdx);
} else { } else {
emitLoadInternalAllocator(); emitLoadInternalAllocator();
} }
@ -603,11 +603,11 @@ public class BindingSpecializer {
if (SharedUtils.isPowerOfTwo(byteWidth)) { if (SharedUtils.isPowerOfTwo(byteWidth)) {
int valueIdx = cb.allocateLocal(storeTypeKind); int valueIdx = cb.allocateLocal(storeTypeKind);
cb.storeInstruction(storeTypeKind, valueIdx); cb.storeLocal(storeTypeKind, valueIdx);
ClassDesc valueLayoutType = emitLoadLayoutConstant(storeType); ClassDesc valueLayoutType = emitLoadLayoutConstant(storeType);
cb.constantInstruction(offset); cb.loadConstant(offset);
cb.loadInstruction(storeTypeKind, valueIdx); cb.loadLocal(storeTypeKind, valueIdx);
MethodTypeDesc descriptor = MethodTypeDesc.of(CD_void, valueLayoutType, CD_long, desc(storeType)); MethodTypeDesc descriptor = MethodTypeDesc.of(CD_void, valueLayoutType, CD_long, desc(storeType));
cb.invokeinterface(CD_MemorySegment, "set", descriptor); cb.invokeinterface(CD_MemorySegment, "set", descriptor);
} else { } else {
@ -618,9 +618,9 @@ public class BindingSpecializer {
assert storeType == long.class; // chunking only for int and long assert storeType == long.class; // chunking only for int and long
} }
int longValueIdx = cb.allocateLocal(LongType); int longValueIdx = cb.allocateLocal(LongType);
cb.storeInstruction(LongType, longValueIdx); cb.storeLocal(LongType, longValueIdx);
int writeAddrIdx = cb.allocateLocal(ReferenceType); int writeAddrIdx = cb.allocateLocal(ReferenceType);
cb.storeInstruction(ReferenceType, writeAddrIdx); cb.storeLocal(ReferenceType, writeAddrIdx);
int remaining = byteWidth; int remaining = byteWidth;
int chunkOffset = 0; int chunkOffset = 0;
@ -647,25 +647,25 @@ public class BindingSpecializer {
//int writeChunk = (int) (((0xFFFF_FFFFL << shiftAmount) & longValue) >>> shiftAmount); //int writeChunk = (int) (((0xFFFF_FFFFL << shiftAmount) & longValue) >>> shiftAmount);
int shiftAmount = chunkOffset * Byte.SIZE; int shiftAmount = chunkOffset * Byte.SIZE;
mask = mask << shiftAmount; mask = mask << shiftAmount;
cb.loadInstruction(LongType, longValueIdx); cb.loadLocal(LongType, longValueIdx);
cb.constantInstruction(mask); cb.loadConstant(mask);
cb.land(); cb.land();
if (shiftAmount != 0) { if (shiftAmount != 0) {
cb.constantInstruction(shiftAmount); cb.loadConstant(shiftAmount);
cb.lushr(); cb.lushr();
} }
cb.l2i(); cb.l2i();
TypeKind chunkStoreTypeKind = TypeKind.from(chunkStoreType); TypeKind chunkStoreTypeKind = TypeKind.from(chunkStoreType);
int chunkIdx = cb.allocateLocal(chunkStoreTypeKind); int chunkIdx = cb.allocateLocal(chunkStoreTypeKind);
cb.storeInstruction(chunkStoreTypeKind, chunkIdx); cb.storeLocal(chunkStoreTypeKind, chunkIdx);
// chunk done, now write it // chunk done, now write it
//writeAddress.set(JAVA_SHORT_UNALIGNED, offset, writeChunk); //writeAddress.set(JAVA_SHORT_UNALIGNED, offset, writeChunk);
cb.loadInstruction(ReferenceType, writeAddrIdx); cb.loadLocal(ReferenceType, writeAddrIdx);
ClassDesc valueLayoutType = emitLoadLayoutConstant(chunkStoreType); ClassDesc valueLayoutType = emitLoadLayoutConstant(chunkStoreType);
long writeOffset = offset + SharedUtils.pickChunkOffset(chunkOffset, byteWidth, chunkSize); long writeOffset = offset + SharedUtils.pickChunkOffset(chunkOffset, byteWidth, chunkSize);
cb.constantInstruction(writeOffset); cb.loadConstant(writeOffset);
cb.loadInstruction(chunkStoreTypeKind, chunkIdx); cb.loadLocal(chunkStoreTypeKind, chunkIdx);
MethodTypeDesc descriptor = MethodTypeDesc.of(CD_void, valueLayoutType, CD_long, desc(chunkStoreType)); MethodTypeDesc descriptor = MethodTypeDesc.of(CD_void, valueLayoutType, CD_long, desc(chunkStoreType));
cb.invokeinterface(CD_MemorySegment, "set", descriptor); cb.invokeinterface(CD_MemorySegment, "set", descriptor);
@ -690,13 +690,13 @@ public class BindingSpecializer {
emitSaveReturnValue(storeType); emitSaveReturnValue(storeType);
} else { } else {
int valueIdx = cb.allocateLocal(storeTypeKind); int valueIdx = cb.allocateLocal(storeTypeKind);
cb.storeInstruction(storeTypeKind, valueIdx); // store away the stored value, need it later cb.storeLocal(storeTypeKind, valueIdx); // store away the stored value, need it later
assert returnBufferIdx != -1; assert returnBufferIdx != -1;
cb.loadInstruction(ReferenceType, returnBufferIdx); cb.loadLocal(ReferenceType, returnBufferIdx);
ClassDesc valueLayoutType = emitLoadLayoutConstant(storeType); ClassDesc valueLayoutType = emitLoadLayoutConstant(storeType);
cb.constantInstruction(retBufOffset); cb.loadConstant(retBufOffset);
cb.loadInstruction(storeTypeKind, valueIdx); cb.loadLocal(storeTypeKind, valueIdx);
MethodTypeDesc descriptor = MethodTypeDesc.of(CD_void, valueLayoutType, CD_long, desc(storeType)); MethodTypeDesc descriptor = MethodTypeDesc.of(CD_void, valueLayoutType, CD_long, desc(storeType));
cb.invokeinterface(CD_MemorySegment, "set", descriptor); cb.invokeinterface(CD_MemorySegment, "set", descriptor);
retBufOffset += abi.arch.typeSize(vmStore.storage().type()); retBufOffset += abi.arch.typeSize(vmStore.storage().type());
@ -713,9 +713,9 @@ public class BindingSpecializer {
emitRestoreReturnValue(loadType); emitRestoreReturnValue(loadType);
} else { } else {
assert returnBufferIdx != -1; assert returnBufferIdx != -1;
cb.loadInstruction(ReferenceType, returnBufferIdx); cb.loadLocal(ReferenceType, returnBufferIdx);
ClassDesc valueLayoutType = emitLoadLayoutConstant(loadType); ClassDesc valueLayoutType = emitLoadLayoutConstant(loadType);
cb.constantInstruction(retBufOffset); cb.loadConstant(retBufOffset);
MethodTypeDesc descriptor = MethodTypeDesc.of(desc(loadType), valueLayoutType, CD_long); MethodTypeDesc descriptor = MethodTypeDesc.of(desc(loadType), valueLayoutType, CD_long);
cb.invokeinterface(CD_MemorySegment, "get", descriptor); cb.invokeinterface(CD_MemorySegment, "get", descriptor);
retBufOffset += abi.arch.typeSize(vmLoad.storage().type()); retBufOffset += abi.arch.typeSize(vmLoad.storage().type());
@ -735,14 +735,14 @@ public class BindingSpecializer {
private void emitShiftLeft(ShiftLeft shiftLeft) { private void emitShiftLeft(ShiftLeft shiftLeft) {
popType(long.class); popType(long.class);
cb.constantInstruction(shiftLeft.shiftAmount() * Byte.SIZE); cb.loadConstant(shiftLeft.shiftAmount() * Byte.SIZE);
cb.lshl(); cb.lshl();
pushType(long.class); pushType(long.class);
} }
private void emitShiftRight(ShiftRight shiftRight) { private void emitShiftRight(ShiftRight shiftRight) {
popType(long.class); popType(long.class);
cb.constantInstruction(shiftRight.shiftAmount() * Byte.SIZE); cb.loadConstant(shiftRight.shiftAmount() * Byte.SIZE);
cb.lushr(); cb.lushr();
pushType(long.class); pushType(long.class);
} }
@ -757,7 +757,7 @@ public class BindingSpecializer {
// implement least significant byte non-zero test // implement least significant byte non-zero test
// select first byte // select first byte
cb.constantInstruction(0xFF); cb.loadConstant(0xFF);
cb.iand(); cb.iand();
// convert to boolean // convert to boolean
@ -808,17 +808,17 @@ public class BindingSpecializer {
if (SharedUtils.isPowerOfTwo(byteWidth)) { if (SharedUtils.isPowerOfTwo(byteWidth)) {
ClassDesc valueLayoutType = emitLoadLayoutConstant(loadType); ClassDesc valueLayoutType = emitLoadLayoutConstant(loadType);
cb.constantInstruction(offset); cb.loadConstant(offset);
MethodTypeDesc descriptor = MethodTypeDesc.of(desc(loadType), valueLayoutType, CD_long); MethodTypeDesc descriptor = MethodTypeDesc.of(desc(loadType), valueLayoutType, CD_long);
cb.invokeinterface(CD_MemorySegment, "get", descriptor); cb.invokeinterface(CD_MemorySegment, "get", descriptor);
} else { } else {
// chunked // chunked
int readAddrIdx = cb.allocateLocal(ReferenceType); int readAddrIdx = cb.allocateLocal(ReferenceType);
cb.storeInstruction(ReferenceType, readAddrIdx); cb.storeLocal(ReferenceType, readAddrIdx);
cb.constantInstruction(0L); // result cb.loadConstant(0L); // result
int resultIdx = cb.allocateLocal(LongType); int resultIdx = cb.allocateLocal(LongType);
cb.storeInstruction(LongType, resultIdx); cb.storeLocal(LongType, resultIdx);
int remaining = byteWidth; int remaining = byteWidth;
int chunkOffset = 0; int chunkOffset = 0;
@ -847,30 +847,30 @@ public class BindingSpecializer {
throw new IllegalStateException("Unexpected chunk size for chunked write: " + chunkSize); throw new IllegalStateException("Unexpected chunk size for chunked write: " + chunkSize);
} }
// read from segment // read from segment
cb.loadInstruction(ReferenceType, readAddrIdx); cb.loadLocal(ReferenceType, readAddrIdx);
ClassDesc valueLayoutType = emitLoadLayoutConstant(chunkType); ClassDesc valueLayoutType = emitLoadLayoutConstant(chunkType);
MethodTypeDesc descriptor = MethodTypeDesc.of(desc(chunkType), valueLayoutType, CD_long); MethodTypeDesc descriptor = MethodTypeDesc.of(desc(chunkType), valueLayoutType, CD_long);
long readOffset = offset + SharedUtils.pickChunkOffset(chunkOffset, byteWidth, chunkSize); long readOffset = offset + SharedUtils.pickChunkOffset(chunkOffset, byteWidth, chunkSize);
cb.constantInstruction(readOffset); cb.loadConstant(readOffset);
cb.invokeinterface(CD_MemorySegment, "get", descriptor); cb.invokeinterface(CD_MemorySegment, "get", descriptor);
cb.invokestatic(toULongHolder, "toUnsignedLong", toULongDescriptor); cb.invokestatic(toULongHolder, "toUnsignedLong", toULongDescriptor);
// shift to right offset // shift to right offset
int shiftAmount = chunkOffset * Byte.SIZE; int shiftAmount = chunkOffset * Byte.SIZE;
if (shiftAmount != 0) { if (shiftAmount != 0) {
cb.constantInstruction(shiftAmount); cb.loadConstant(shiftAmount);
cb.lshl(); cb.lshl();
} }
// add to result // add to result
cb.loadInstruction(LongType, resultIdx); cb.loadLocal(LongType, resultIdx);
cb.lor(); cb.lor();
cb.storeInstruction(LongType, resultIdx); cb.storeLocal(LongType, resultIdx);
remaining -= chunkSize; remaining -= chunkSize;
chunkOffset += chunkSize; chunkOffset += chunkSize;
} while (remaining != 0); } while (remaining != 0);
cb.loadInstruction(LongType, resultIdx); cb.loadLocal(LongType, resultIdx);
if (loadType == int.class) { if (loadType == int.class) {
cb.l2i(); cb.l2i();
} else { } else {
@ -890,25 +890,25 @@ public class BindingSpecializer {
// operand/srcSegment is on the stack // operand/srcSegment is on the stack
// generating a call to: // generating a call to:
// MemorySegment::copy(MemorySegment srcSegment, long srcOffset, MemorySegment dstSegment, long dstOffset, long bytes) // MemorySegment::copy(MemorySegment srcSegment, long srcOffset, MemorySegment dstSegment, long dstOffset, long bytes)
cb.constantInstruction(0L); cb.loadConstant(0L);
// create the dstSegment by allocating it. Similar to: // create the dstSegment by allocating it. Similar to:
// context.allocator().allocate(size, alignment) // context.allocator().allocate(size, alignment)
emitLoadInternalAllocator(); emitLoadInternalAllocator();
emitAllocateCall(size, alignment); emitAllocateCall(size, alignment);
cb.dup(); cb.dup();
int storeIdx = cb.allocateLocal(ReferenceType); int storeIdx = cb.allocateLocal(ReferenceType);
cb.storeInstruction(ReferenceType, storeIdx); cb.storeLocal(ReferenceType, storeIdx);
cb.constantInstruction(0L); cb.loadConstant(0L);
cb.constantInstruction(size); cb.loadConstant(size);
cb.invokestatic(CD_MemorySegment, "copy", MTD_COPY, true); cb.invokestatic(CD_MemorySegment, "copy", MTD_COPY, true);
cb.loadInstruction(ReferenceType, storeIdx); cb.loadLocal(ReferenceType, storeIdx);
pushType(MemorySegment.class); pushType(MemorySegment.class);
} }
private void emitAllocateCall(long size, long alignment) { private void emitAllocateCall(long size, long alignment) {
cb.constantInstruction(size); cb.loadConstant(size);
cb.constantInstruction(alignment); cb.loadConstant(alignment);
cb.invokeinterface(CD_SegmentAllocator, "allocate", MTD_ALLOCATE); cb.invokeinterface(CD_SegmentAllocator, "allocate", MTD_ALLOCATE);
} }

View File

@ -470,7 +470,7 @@ final class EventInstrumentation {
// stack:[ex] [EW] // stack:[ex] [EW]
catchAllHandler.pop(); catchAllHandler.pop();
// stack:[ex] // stack:[ex]
catchAllHandler.throwInstruction(); catchAllHandler.athrow();
}); });
}); });
codeBuilder.labelBinding(excluded); codeBuilder.labelBinding(excluded);
@ -562,7 +562,7 @@ final class EventInstrumentation {
// write begin event // write begin event
getEventConfiguration(blockCodeBuilder); getEventConfiguration(blockCodeBuilder);
// stack: [EW], [EW], [EventConfiguration] // stack: [EW], [EW], [EventConfiguration]
blockCodeBuilder.constantInstruction(Opcode.LDC2_W, eventTypeId); blockCodeBuilder.loadConstant(Opcode.LDC2_W, eventTypeId);
// stack: [EW], [EW], [EventConfiguration] [long] // stack: [EW], [EW], [EventConfiguration] [long]
invokevirtual(blockCodeBuilder, TYPE_EVENT_WRITER, EventWriterMethod.BEGIN_EVENT.method()); invokevirtual(blockCodeBuilder, TYPE_EVENT_WRITER, EventWriterMethod.BEGIN_EVENT.method());
// stack: [EW], [integer] // stack: [EW], [integer]
@ -572,7 +572,7 @@ final class EventInstrumentation {
blockCodeBuilder.dup(); blockCodeBuilder.dup();
// stack: [EW], [EW] // stack: [EW], [EW]
tk = TypeKind.from(argumentTypes[argIndex++]); tk = TypeKind.from(argumentTypes[argIndex++]);
blockCodeBuilder.loadInstruction(tk, slotIndex); blockCodeBuilder.loadLocal(tk, slotIndex);
// stack: [EW], [EW], [long] // stack: [EW], [EW], [long]
slotIndex += tk.slotSize(); slotIndex += tk.slotSize();
invokevirtual(blockCodeBuilder, TYPE_EVENT_WRITER, EventWriterMethod.PUT_LONG.method()); invokevirtual(blockCodeBuilder, TYPE_EVENT_WRITER, EventWriterMethod.PUT_LONG.method());
@ -583,7 +583,7 @@ final class EventInstrumentation {
blockCodeBuilder.dup(); blockCodeBuilder.dup();
// stack: [EW], [EW] // stack: [EW], [EW]
tk = TypeKind.from(argumentTypes[argIndex++]); tk = TypeKind.from(argumentTypes[argIndex++]);
blockCodeBuilder.loadInstruction(tk, slotIndex); blockCodeBuilder.loadLocal(tk, slotIndex);
// stack: [EW], [EW], [long] // stack: [EW], [EW], [long]
slotIndex += tk.slotSize(); slotIndex += tk.slotSize();
invokevirtual(blockCodeBuilder, TYPE_EVENT_WRITER, EventWriterMethod.PUT_LONG.method()); invokevirtual(blockCodeBuilder, TYPE_EVENT_WRITER, EventWriterMethod.PUT_LONG.method());
@ -609,7 +609,7 @@ final class EventInstrumentation {
blockCodeBuilder.dup(); blockCodeBuilder.dup();
// stack: [EW], [EW] // stack: [EW], [EW]
tk = TypeKind.from(argumentTypes[argIndex++]); tk = TypeKind.from(argumentTypes[argIndex++]);
blockCodeBuilder.loadInstruction(tk, slotIndex); blockCodeBuilder.loadLocal(tk, slotIndex);
// stack:[EW], [EW], [field] // stack:[EW], [EW], [field]
slotIndex += tk.slotSize(); slotIndex += tk.slotSize();
FieldDesc field = fieldDescs.get(fieldIndex); FieldDesc field = fieldDescs.get(fieldIndex);
@ -676,7 +676,7 @@ final class EventInstrumentation {
// stack: [EW] [EW] // stack: [EW] [EW]
getEventConfiguration(blockCodeBuilder); getEventConfiguration(blockCodeBuilder);
// stack: [EW] [EW] [EC] // stack: [EW] [EW] [EC]
blockCodeBuilder.constantInstruction(Opcode.LDC2_W, eventTypeId); blockCodeBuilder.loadConstant(Opcode.LDC2_W, eventTypeId);
invokevirtual(blockCodeBuilder, TYPE_EVENT_WRITER, EventWriterMethod.BEGIN_EVENT.method()); invokevirtual(blockCodeBuilder, TYPE_EVENT_WRITER, EventWriterMethod.BEGIN_EVENT.method());
// stack: [EW] [int] // stack: [EW] [int]
blockCodeBuilder.ifeq(excluded); blockCodeBuilder.ifeq(excluded);
@ -738,7 +738,7 @@ final class EventInstrumentation {
Label nullLabel = codeBuilder.newLabel(); Label nullLabel = codeBuilder.newLabel();
if (guardEventConfiguration) { if (guardEventConfiguration) {
getEventConfiguration(codeBuilder); getEventConfiguration(codeBuilder);
codeBuilder.branchInstruction(Opcode.IFNULL, nullLabel); codeBuilder.if_null(nullLabel);
} }
getEventConfiguration(codeBuilder); getEventConfiguration(codeBuilder);
invokevirtual(codeBuilder, TYPE_EVENT_CONFIGURATION, METHOD_IS_ENABLED); invokevirtual(codeBuilder, TYPE_EVENT_CONFIGURATION, METHOD_IS_ENABLED);

View File

@ -668,7 +668,7 @@ public final class SystemModulesPlugin extends AbstractPlugin {
"hasSplitPackages", "hasSplitPackages",
MTD_boolean, MTD_boolean,
ACC_PUBLIC, ACC_PUBLIC,
cob -> cob.constantInstruction(hasSplitPackages ? 1 : 0) cob -> cob.loadConstant(hasSplitPackages ? 1 : 0)
.ireturn()); .ireturn());
} }
@ -686,7 +686,7 @@ public final class SystemModulesPlugin extends AbstractPlugin {
"hasIncubatorModules", "hasIncubatorModules",
MTD_boolean, MTD_boolean,
ACC_PUBLIC, ACC_PUBLIC,
cob -> cob.constantInstruction(hasIncubatorModules ? 1 : 0) cob -> cob.loadConstant(hasIncubatorModules ? 1 : 0)
.ireturn()); .ireturn());
} }
@ -700,7 +700,7 @@ public final class SystemModulesPlugin extends AbstractPlugin {
MTD_ModuleDescriptorArray, MTD_ModuleDescriptorArray,
ACC_PUBLIC, ACC_PUBLIC,
cob -> { cob -> {
cob.constantInstruction(moduleInfos.size()) cob.loadConstant(moduleInfos.size())
.anewarray(CD_MODULE_DESCRIPTOR) .anewarray(CD_MODULE_DESCRIPTOR)
.astore(MD_VAR); .astore(MD_VAR);
@ -764,13 +764,13 @@ public final class SystemModulesPlugin extends AbstractPlugin {
MTD_ModuleDescriptorArray, MTD_ModuleDescriptorArray,
ACC_PUBLIC, ACC_PUBLIC,
cob -> { cob -> {
cob.constantInstruction(moduleInfos.size()) cob.loadConstant(moduleInfos.size())
.anewarray(CD_MODULE_DESCRIPTOR) .anewarray(CD_MODULE_DESCRIPTOR)
.dup() .dup()
.astore(MD_VAR); .astore(MD_VAR);
cob.new_(arrayListClassDesc) cob.new_(arrayListClassDesc)
.dup() .dup()
.constantInstruction(moduleInfos.size()) .loadConstant(moduleInfos.size())
.invokespecial(arrayListClassDesc, INIT_NAME, MethodTypeDesc.of(CD_void, CD_int)) .invokespecial(arrayListClassDesc, INIT_NAME, MethodTypeDesc.of(CD_void, CD_int))
.astore(DEDUP_LIST_VAR); .astore(DEDUP_LIST_VAR);
cob.aload(0) cob.aload(0)
@ -797,7 +797,7 @@ public final class SystemModulesPlugin extends AbstractPlugin {
if (curDedupVar > dedupVarStart) { if (curDedupVar > dedupVarStart) {
for (int i = dedupVarStart; i < curDedupVar; i++) { for (int i = dedupVarStart; i < curDedupVar; i++) {
cob.aload(DEDUP_LIST_VAR) cob.aload(DEDUP_LIST_VAR)
.constantInstruction(i - dedupVarStart) .loadConstant(i - dedupVarStart)
.invokevirtual(arrayListClassDesc, "get", MethodTypeDesc.of(CD_Object, CD_int)) .invokevirtual(arrayListClassDesc, "get", MethodTypeDesc.of(CD_Object, CD_int))
.astore(i); .astore(i);
} }
@ -845,7 +845,7 @@ public final class SystemModulesPlugin extends AbstractPlugin {
MTD_ModuleTargetArray, MTD_ModuleTargetArray,
ACC_PUBLIC, ACC_PUBLIC,
cob -> { cob -> {
cob.constantInstruction(moduleInfos.size()) cob.loadConstant(moduleInfos.size())
.anewarray(CD_MODULE_TARGET) .anewarray(CD_MODULE_TARGET)
.astore(MT_VAR); .astore(MT_VAR);
@ -868,12 +868,12 @@ public final class SystemModulesPlugin extends AbstractPlugin {
ModuleInfo minfo = moduleInfos.get(index); ModuleInfo minfo = moduleInfos.get(index);
if (minfo.target() != null) { if (minfo.target() != null) {
cob.aload(MT_VAR) cob.aload(MT_VAR)
.constantInstruction(index); .loadConstant(index);
// new ModuleTarget(String) // new ModuleTarget(String)
cob.new_(CD_MODULE_TARGET) cob.new_(CD_MODULE_TARGET)
.dup() .dup()
.constantInstruction(minfo.target().targetPlatform()) .loadConstant(minfo.target().targetPlatform())
.invokespecial(CD_MODULE_TARGET, .invokespecial(CD_MODULE_TARGET,
INIT_NAME, INIT_NAME,
MTD_void_String); MTD_void_String);
@ -896,7 +896,7 @@ public final class SystemModulesPlugin extends AbstractPlugin {
MTD_ModuleHashesArray, MTD_ModuleHashesArray,
ACC_PUBLIC, ACC_PUBLIC,
cob -> { cob -> {
cob.constantInstruction(moduleInfos.size()) cob.loadConstant(moduleInfos.size())
.anewarray(CD_MODULE_HASHES) .anewarray(CD_MODULE_HASHES)
.astore(MH_VAR); .astore(MH_VAR);
@ -923,7 +923,7 @@ public final class SystemModulesPlugin extends AbstractPlugin {
MTD_ModuleResolutionArray, MTD_ModuleResolutionArray,
ACC_PUBLIC, ACC_PUBLIC,
cob -> { cob -> {
cob.constantInstruction(moduleInfos.size()) cob.loadConstant(moduleInfos.size())
.anewarray(CD_MODULE_RESOLUTION) .anewarray(CD_MODULE_RESOLUTION)
.astore(0); .astore(0);
@ -931,10 +931,10 @@ public final class SystemModulesPlugin extends AbstractPlugin {
ModuleInfo minfo = moduleInfos.get(index); ModuleInfo minfo = moduleInfos.get(index);
if (minfo.moduleResolution() != null) { if (minfo.moduleResolution() != null) {
cob.aload(0) cob.aload(0)
.constantInstruction(index) .loadConstant(index)
.new_(CD_MODULE_RESOLUTION) .new_(CD_MODULE_RESOLUTION)
.dup() .dup()
.constantInstruction(minfo.moduleResolution().value()) .loadConstant(minfo.moduleResolution().value())
.invokespecial(CD_MODULE_RESOLUTION, .invokespecial(CD_MODULE_RESOLUTION,
INIT_NAME, INIT_NAME,
MTD_void_int) MTD_void_int)
@ -1000,7 +1000,7 @@ public final class SystemModulesPlugin extends AbstractPlugin {
} }
// new Map$Entry[size] // new Map$Entry[size]
cob.constantInstruction(map.size()) cob.loadConstant(map.size())
.anewarray(CD_Map_Entry); .anewarray(CD_Map_Entry);
int index = 0; int index = 0;
@ -1009,8 +1009,8 @@ public final class SystemModulesPlugin extends AbstractPlugin {
Set<String> s = e.getValue(); Set<String> s = e.getValue();
cob.dup() cob.dup()
.constantInstruction(index) .loadConstant(index)
.constantInstruction(name); .loadConstant(name);
// if de-duplicated then load the local, otherwise generate code // if de-duplicated then load the local, otherwise generate code
Integer varIndex = locals.get(s); Integer varIndex = locals.get(s);
@ -1046,13 +1046,13 @@ public final class SystemModulesPlugin extends AbstractPlugin {
// use Set.of(Object[]) when there are more than 2 elements // use Set.of(Object[]) when there are more than 2 elements
// use Set.of(Object) or Set.of(Object, Object) when fewer // use Set.of(Object) or Set.of(Object, Object) when fewer
if (size > 2) { if (size > 2) {
cob.constantInstruction(size) cob.loadConstant(size)
.anewarray(CD_String); .anewarray(CD_String);
int i = 0; int i = 0;
for (String element : sorted(set)) { for (String element : sorted(set)) {
cob.dup() cob.dup()
.constantInstruction(i) .loadConstant(i)
.constantInstruction(element) .loadConstant(element)
.aastore(); .aastore();
i++; i++;
} }
@ -1062,7 +1062,7 @@ public final class SystemModulesPlugin extends AbstractPlugin {
true); true);
} else { } else {
for (String element : sorted(set)) { for (String element : sorted(set)) {
cob.constantInstruction(element); cob.loadConstant(element);
} }
var mtdArgs = new ClassDesc[size]; var mtdArgs = new ClassDesc[size];
Arrays.fill(mtdArgs, CD_Object); Arrays.fill(mtdArgs, CD_Object);
@ -1166,7 +1166,7 @@ public final class SystemModulesPlugin extends AbstractPlugin {
void newBuilder() { void newBuilder() {
cob.new_(CD_MODULE_BUILDER) cob.new_(CD_MODULE_BUILDER)
.dup() .dup()
.constantInstruction(md.name()) .loadConstant(md.name())
.invokespecial(CD_MODULE_BUILDER, .invokespecial(CD_MODULE_BUILDER,
INIT_NAME, INIT_NAME,
MTD_void_String) MTD_void_String)
@ -1188,7 +1188,7 @@ public final class SystemModulesPlugin extends AbstractPlugin {
*/ */
void setModuleBit(String methodName, boolean value) { void setModuleBit(String methodName, boolean value) {
cob.aload(BUILDER_VAR) cob.aload(BUILDER_VAR)
.constantInstruction(value ? 1 : 0) .loadConstant(value ? 1 : 0)
.invokevirtual(CD_MODULE_BUILDER, .invokevirtual(CD_MODULE_BUILDER,
methodName, methodName,
MTD_BOOLEAN) MTD_BOOLEAN)
@ -1200,9 +1200,9 @@ public final class SystemModulesPlugin extends AbstractPlugin {
*/ */
void putModuleDescriptor() { void putModuleDescriptor() {
cob.aload(MD_VAR) cob.aload(MD_VAR)
.constantInstruction(index) .loadConstant(index)
.aload(BUILDER_VAR) .aload(BUILDER_VAR)
.constantInstruction(md.hashCode()) .loadConstant(md.hashCode())
.invokevirtual(CD_MODULE_BUILDER, .invokevirtual(CD_MODULE_BUILDER,
"build", "build",
MTD_ModuleDescriptor_int) MTD_ModuleDescriptor_int)
@ -1217,7 +1217,7 @@ public final class SystemModulesPlugin extends AbstractPlugin {
*/ */
void requires(Set<Requires> requires) { void requires(Set<Requires> requires) {
cob.aload(BUILDER_VAR) cob.aload(BUILDER_VAR)
.constantInstruction(requires.size()) .loadConstant(requires.size())
.anewarray(CD_REQUIRES); .anewarray(CD_REQUIRES);
int arrayIndex = 0; int arrayIndex = 0;
for (Requires require : sorted(requires)) { for (Requires require : sorted(requires)) {
@ -1227,7 +1227,7 @@ public final class SystemModulesPlugin extends AbstractPlugin {
} }
cob.dup() // arrayref cob.dup() // arrayref
.constantInstruction(arrayIndex++); .loadConstant(arrayIndex++);
newRequires(require.modifiers(), require.name(), compiledVersion); newRequires(require.modifiers(), require.name(), compiledVersion);
cob.aastore(); cob.aastore();
} }
@ -1246,9 +1246,9 @@ public final class SystemModulesPlugin extends AbstractPlugin {
void newRequires(Set<Requires.Modifier> mods, String name, String compiledVersion) { void newRequires(Set<Requires.Modifier> mods, String name, String compiledVersion) {
int varIndex = dedupSetBuilder.indexOfRequiresModifiers(cob, mods); int varIndex = dedupSetBuilder.indexOfRequiresModifiers(cob, mods);
cob.aload(varIndex) cob.aload(varIndex)
.constantInstruction(name); .loadConstant(name);
if (compiledVersion != null) { if (compiledVersion != null) {
cob.constantInstruction(compiledVersion) cob.loadConstant(compiledVersion)
.invokestatic(CD_MODULE_BUILDER, .invokestatic(CD_MODULE_BUILDER,
"newRequires", "newRequires",
MTD_REQUIRES_SET_STRING_STRING); MTD_REQUIRES_SET_STRING_STRING);
@ -1267,12 +1267,12 @@ public final class SystemModulesPlugin extends AbstractPlugin {
*/ */
void exports(Set<Exports> exports) { void exports(Set<Exports> exports) {
cob.aload(BUILDER_VAR) cob.aload(BUILDER_VAR)
.constantInstruction(exports.size()) .loadConstant(exports.size())
.anewarray(CD_EXPORTS); .anewarray(CD_EXPORTS);
int arrayIndex = 0; int arrayIndex = 0;
for (Exports export : sorted(exports)) { for (Exports export : sorted(exports)) {
cob.dup() // arrayref cob.dup() // arrayref
.constantInstruction(arrayIndex++); .loadConstant(arrayIndex++);
newExports(export.modifiers(), export.source(), export.targets()); newExports(export.modifiers(), export.source(), export.targets());
cob.aastore(); cob.aastore();
} }
@ -1302,14 +1302,14 @@ public final class SystemModulesPlugin extends AbstractPlugin {
if (!targets.isEmpty()) { if (!targets.isEmpty()) {
int stringSetIndex = dedupSetBuilder.indexOfStringSet(cob, targets); int stringSetIndex = dedupSetBuilder.indexOfStringSet(cob, targets);
cob.aload(modifiersSetIndex) cob.aload(modifiersSetIndex)
.constantInstruction(pn) .loadConstant(pn)
.aload(stringSetIndex) .aload(stringSetIndex)
.invokestatic(CD_MODULE_BUILDER, .invokestatic(CD_MODULE_BUILDER,
"newExports", "newExports",
MTD_EXPORTS_MODIFIER_SET_STRING_SET); MTD_EXPORTS_MODIFIER_SET_STRING_SET);
} else { } else {
cob.aload(modifiersSetIndex) cob.aload(modifiersSetIndex)
.constantInstruction(pn) .loadConstant(pn)
.invokestatic(CD_MODULE_BUILDER, .invokestatic(CD_MODULE_BUILDER,
"newExports", "newExports",
MTD_EXPORTS_MODIFIER_SET_STRING); MTD_EXPORTS_MODIFIER_SET_STRING);
@ -1324,12 +1324,12 @@ public final class SystemModulesPlugin extends AbstractPlugin {
*/ */
void opens(Set<Opens> opens) { void opens(Set<Opens> opens) {
cob.aload(BUILDER_VAR) cob.aload(BUILDER_VAR)
.constantInstruction(opens.size()) .loadConstant(opens.size())
.anewarray(CD_OPENS); .anewarray(CD_OPENS);
int arrayIndex = 0; int arrayIndex = 0;
for (Opens open : sorted(opens)) { for (Opens open : sorted(opens)) {
cob.dup() // arrayref cob.dup() // arrayref
.constantInstruction(arrayIndex++); .loadConstant(arrayIndex++);
newOpens(open.modifiers(), open.source(), open.targets()); newOpens(open.modifiers(), open.source(), open.targets());
cob.aastore(); cob.aastore();
} }
@ -1359,14 +1359,14 @@ public final class SystemModulesPlugin extends AbstractPlugin {
if (!targets.isEmpty()) { if (!targets.isEmpty()) {
int stringSetIndex = dedupSetBuilder.indexOfStringSet(cob, targets); int stringSetIndex = dedupSetBuilder.indexOfStringSet(cob, targets);
cob.aload(modifiersSetIndex) cob.aload(modifiersSetIndex)
.constantInstruction(pn) .loadConstant(pn)
.aload(stringSetIndex) .aload(stringSetIndex)
.invokestatic(CD_MODULE_BUILDER, .invokestatic(CD_MODULE_BUILDER,
"newOpens", "newOpens",
MTD_OPENS_MODIFIER_SET_STRING_SET); MTD_OPENS_MODIFIER_SET_STRING_SET);
} else { } else {
cob.aload(modifiersSetIndex) cob.aload(modifiersSetIndex)
.constantInstruction(pn) .loadConstant(pn)
.invokestatic(CD_MODULE_BUILDER, .invokestatic(CD_MODULE_BUILDER,
"newOpens", "newOpens",
MTD_OPENS_MODIFIER_SET_STRING); MTD_OPENS_MODIFIER_SET_STRING);
@ -1394,12 +1394,12 @@ public final class SystemModulesPlugin extends AbstractPlugin {
*/ */
void provides(Collection<Provides> provides) { void provides(Collection<Provides> provides) {
cob.aload(BUILDER_VAR) cob.aload(BUILDER_VAR)
.constantInstruction(provides.size()) .loadConstant(provides.size())
.anewarray(CD_PROVIDES); .anewarray(CD_PROVIDES);
int arrayIndex = 0; int arrayIndex = 0;
for (Provides provide : sorted(provides)) { for (Provides provide : sorted(provides)) {
cob.dup() // arrayref cob.dup() // arrayref
.constantInstruction(arrayIndex++); .loadConstant(arrayIndex++);
newProvides(provide.service(), provide.providers()); newProvides(provide.service(), provide.providers());
cob.aastore(); cob.aastore();
} }
@ -1419,14 +1419,14 @@ public final class SystemModulesPlugin extends AbstractPlugin {
* Builder.newProvides(service, providers); * Builder.newProvides(service, providers);
*/ */
void newProvides(String service, List<String> providers) { void newProvides(String service, List<String> providers) {
cob.constantInstruction(service) cob.loadConstant(service)
.constantInstruction(providers.size()) .loadConstant(providers.size())
.anewarray(CD_String); .anewarray(CD_String);
int arrayIndex = 0; int arrayIndex = 0;
for (String provider : providers) { for (String provider : providers) {
cob.dup() // arrayref cob.dup() // arrayref
.constantInstruction(arrayIndex++) .loadConstant(arrayIndex++)
.constantInstruction(provider) .loadConstant(provider)
.aastore(); .aastore();
} }
cob.invokestatic(CD_List, cob.invokestatic(CD_List,
@ -1456,7 +1456,7 @@ public final class SystemModulesPlugin extends AbstractPlugin {
*/ */
void mainClass(String cn) { void mainClass(String cn) {
cob.aload(BUILDER_VAR) cob.aload(BUILDER_VAR)
.constantInstruction(cn) .loadConstant(cn)
.invokevirtual(CD_MODULE_BUILDER, .invokevirtual(CD_MODULE_BUILDER,
"mainClass", "mainClass",
MTD_STRING) MTD_STRING)
@ -1468,7 +1468,7 @@ public final class SystemModulesPlugin extends AbstractPlugin {
*/ */
void version(Version v) { void version(Version v) {
cob.aload(BUILDER_VAR) cob.aload(BUILDER_VAR)
.constantInstruction(v.toString()) .loadConstant(v.toString())
.invokevirtual(CD_MODULE_BUILDER, .invokevirtual(CD_MODULE_BUILDER,
"version", "version",
MTD_STRING) MTD_STRING)
@ -1477,7 +1477,7 @@ public final class SystemModulesPlugin extends AbstractPlugin {
void invokeBuilderMethod(String methodName, String value) { void invokeBuilderMethod(String methodName, String value) {
cob.aload(BUILDER_VAR) cob.aload(BUILDER_VAR)
.constantInstruction(value) .loadConstant(value)
.invokevirtual(CD_MODULE_BUILDER, .invokevirtual(CD_MODULE_BUILDER,
methodName, methodName,
MTD_STRING) MTD_STRING)
@ -1531,8 +1531,8 @@ public final class SystemModulesPlugin extends AbstractPlugin {
void newModuleHashesBuilder() { void newModuleHashesBuilder() {
cob.new_(MODULE_HASHES_BUILDER) cob.new_(MODULE_HASHES_BUILDER)
.dup() .dup()
.constantInstruction(recordedHashes.algorithm()) .loadConstant(recordedHashes.algorithm())
.constantInstruction(((4 * recordedHashes.names().size()) / 3) + 1) .loadConstant(((4 * recordedHashes.names().size()) / 3) + 1)
.invokespecial(MODULE_HASHES_BUILDER, .invokespecial(MODULE_HASHES_BUILDER,
INIT_NAME, INIT_NAME,
MTD_void_String_int) MTD_void_String_int)
@ -1547,7 +1547,7 @@ public final class SystemModulesPlugin extends AbstractPlugin {
*/ */
void pushModuleHashes() { void pushModuleHashes() {
cob.aload(MH_VAR) cob.aload(MH_VAR)
.constantInstruction(index) .loadConstant(index)
.aload(BUILDER_VAR) .aload(BUILDER_VAR)
.invokevirtual(MODULE_HASHES_BUILDER, .invokevirtual(MODULE_HASHES_BUILDER,
"build", "build",
@ -1560,13 +1560,13 @@ public final class SystemModulesPlugin extends AbstractPlugin {
*/ */
void hashForModule(String name, byte[] hash) { void hashForModule(String name, byte[] hash) {
cob.aload(BUILDER_VAR) cob.aload(BUILDER_VAR)
.constantInstruction(name) .loadConstant(name)
.constantInstruction(hash.length) .loadConstant(hash.length)
.newarray(TypeKind.ByteType); .newarray(TypeKind.ByteType);
for (int i = 0; i < hash.length; i++) { for (int i = 0; i < hash.length; i++) {
cob.dup() // arrayref cob.dup() // arrayref
.constantInstruction(i) .loadConstant(i)
.constantInstruction((int)hash[i]) .loadConstant((int)hash[i])
.bastore(); .bastore();
} }
@ -1729,7 +1729,7 @@ public final class SystemModulesPlugin extends AbstractPlugin {
* to the element onto the stack. * to the element onto the stack.
*/ */
void visitElement(T element, CodeBuilder cob) { void visitElement(T element, CodeBuilder cob) {
cob.constantInstruction((ConstantDesc)element); cob.loadConstant((ConstantDesc)element);
} }
/* /*
@ -1772,12 +1772,12 @@ public final class SystemModulesPlugin extends AbstractPlugin {
true); true);
} else { } else {
// call Set.of(E... elements) // call Set.of(E... elements)
cob.constantInstruction(elements.size()) cob.loadConstant(elements.size())
.anewarray(CD_String); .anewarray(CD_String);
int arrayIndex = 0; int arrayIndex = 0;
for (T t : sorted(elements)) { for (T t : sorted(elements)) {
cob.dup() // arrayref cob.dup() // arrayref
.constantInstruction(arrayIndex); .loadConstant(arrayIndex);
visitElement(t, cob); // value visitElement(t, cob); // value
cob.aastore(); cob.aastore();
arrayIndex++; arrayIndex++;
@ -1876,14 +1876,14 @@ public final class SystemModulesPlugin extends AbstractPlugin {
MTD_StringArray, MTD_StringArray,
ACC_STATIC, ACC_STATIC,
cob -> { cob -> {
cob.constantInstruction(map.size()); cob.loadConstant(map.size());
cob.anewarray(CD_String); cob.anewarray(CD_String);
int index = 0; int index = 0;
for (Map.Entry<String,String> entry : systemModulesMap) { for (Map.Entry<String,String> entry : systemModulesMap) {
cob.dup() // arrayref cob.dup() // arrayref
.constantInstruction(index) .loadConstant(index)
.constantInstruction(entry.getKey()) .loadConstant(entry.getKey())
.aastore(); .aastore();
index++; index++;
} }
@ -1897,14 +1897,14 @@ public final class SystemModulesPlugin extends AbstractPlugin {
MTD_StringArray, MTD_StringArray,
ACC_STATIC, ACC_STATIC,
cob -> { cob -> {
cob.constantInstruction(map.size()) cob.loadConstant(map.size())
.anewarray(CD_String); .anewarray(CD_String);
int index = 0; int index = 0;
for (Map.Entry<String,String> entry : systemModulesMap) { for (Map.Entry<String,String> entry : systemModulesMap) {
cob.dup() // arrayref cob.dup() // arrayref
.constantInstruction(index) .loadConstant(index)
.constantInstruction(entry.getValue().replace('/', '.')) .loadConstant(entry.getValue().replace('/', '.'))
.aastore(); .aastore();
index++; index++;
} }

View File

@ -143,7 +143,7 @@ abstract class VersionPropsPlugin extends AbstractPlugin {
// forget about it // forget about it
pendingLDC = null; pendingLDC = null;
// and add an ldc for the new value // and add an ldc for the new value
cob.constantInstruction(value); cob.loadConstant(value);
redefined = true; redefined = true;
} else { } else {
flushPendingLDC(cob); flushPendingLDC(cob);

View File

@ -245,7 +245,7 @@ public class ProhibitedMethods {
var cf = ClassFile.of(); var cf = ClassFile.of();
return cf.transform(cf.parse(classBytes), ClassTransform.endHandler(clb -> { return cf.transform(cf.parse(classBytes), ClassTransform.endHandler(clb -> {
clb.withMethodBody(name, desc, ACC_PRIVATE, cob -> { clb.withMethodBody(name, desc, ACC_PRIVATE, cob -> {
cob.constantInstruction(name + " should not be invoked"); cob.loadConstant(name + " should not be invoked");
cob.invokestatic(Assert.class.describeConstable().orElseThrow(), "fail", cob.invokestatic(Assert.class.describeConstable().orElseThrow(), "fail",
MethodTypeDesc.of(CD_void, CD_String)); MethodTypeDesc.of(CD_void, CD_String));
cob.return_(); cob.return_();

View File

@ -270,13 +270,13 @@ public class SerialPersistentFieldsTest {
cob.bipush(i); cob.bipush(i);
cob.new_(CD_ObjectStreamField); cob.new_(CD_ObjectStreamField);
cob.dup(); cob.dup();
cob.constantInstruction(osf.getName()); cob.loadConstant(osf.getName());
if (osf.isPrimitive()) { if (osf.isPrimitive()) {
cob.constantInstruction(DynamicConstantDesc.ofNamed( cob.loadConstant(DynamicConstantDesc.ofNamed(
ConstantDescs.BSM_PRIMITIVE_CLASS, String.valueOf(osf.getTypeCode()), CD_Class)); ConstantDescs.BSM_PRIMITIVE_CLASS, String.valueOf(osf.getTypeCode()), CD_Class));
} else { } else {
// Currently Classfile API cannot encode primitive classdescs as condy // Currently Classfile API cannot encode primitive classdescs as condy
cob.constantInstruction(osf.getType().describeConstable().orElseThrow()); cob.loadConstant(osf.getType().describeConstable().orElseThrow());
} }
cob.invokespecial(CD_ObjectStreamField, INIT_NAME, MethodTypeDesc.of(CD_void, CD_String, CD_Class)); cob.invokespecial(CD_ObjectStreamField, INIT_NAME, MethodTypeDesc.of(CD_void, CD_String, CD_Class));
cob.aastore(); cob.aastore();

View File

@ -83,8 +83,8 @@ class NativeMethodPrefixAgent {
byte[] newcf = Instrumentor.instrFor(classfileBuffer) byte[] newcf = Instrumentor.instrFor(classfileBuffer)
.addNativeMethodTrackingInjection( .addNativeMethodTrackingInjection(
"wrapped_" + trname + "_", (name, h) -> { "wrapped_" + trname + "_", (name, h) -> {
h.constantInstruction(name); h.loadConstant(name);
h.constantInstruction(transformId); h.loadConstant(transformId);
h.invokestatic( h.invokestatic(
CD_StringIdCallbackReporter, CD_StringIdCallbackReporter,
"tracker", "tracker",

View File

@ -91,7 +91,7 @@ class RetransformAgent {
.addMethodEntryInjection( .addMethodEntryInjection(
nname, nname,
cb -> { cb -> {
cb.constantInstruction(fixedIndex); cb.loadConstant(fixedIndex);
cb.invokestatic( cb.invokestatic(
CD_RetransformAgent, CD_RetransformAgent,
"callTracker", MTD_void_int); "callTracker", MTD_void_int);

View File

@ -122,13 +122,13 @@ public class Instrumentor {
// load method parameters // load method parameters
for (int i = 0; i < mt.parameterCount(); i++) { for (int i = 0; i < mt.parameterCount(); i++) {
TypeKind kind = TypeKind.from(mt.parameterType(i)); TypeKind kind = TypeKind.from(mt.parameterType(i));
cb.loadInstruction(kind, ptr); cb.loadLocal(kind, ptr);
ptr += kind.slotSize(); ptr += kind.slotSize();
} }
cb.invokeInstruction(isStatic ? Opcode.INVOKESTATIC : Opcode.INVOKESPECIAL, cb.invoke(isStatic ? Opcode.INVOKESTATIC : Opcode.INVOKESPECIAL,
model.thisClass().asSymbol(), newName, mt, false); model.thisClass().asSymbol(), newName, mt, false);
cb.returnInstruction(TypeKind.from(mt.returnType())); cb.return_(TypeKind.from(mt.returnType()));
})); }));
} }
})); }));

View File

@ -95,7 +95,7 @@ public class WrapperHiddenClassTest {
// <clinit> // <clinit>
clb.withMethodBody(CLASS_INIT_NAME, MTD_void, ACC_STATIC, cob -> { clb.withMethodBody(CLASS_INIT_NAME, MTD_void, ACC_STATIC, cob -> {
cob.constantInstruction(CD_Comparator); cob.loadConstant(CD_Comparator);
cob.putstatic(CD_HostileWrapper, TYPE, CD_Class); cob.putstatic(CD_HostileWrapper, TYPE, CD_Class);
cob.return_(); cob.return_();
}); });

View File

@ -390,8 +390,8 @@ public class ClassDataTest {
MethodTypeDesc mt = MethodTypeDesc.of(returnDesc); MethodTypeDesc mt = MethodTypeDesc.of(returnDesc);
cw = cw.andThen(clb -> { cw = cw.andThen(clb -> {
clb.withMethodBody("classData", mt, accessFlags, cob -> { clb.withMethodBody("classData", mt, accessFlags, cob -> {
cob.constantInstruction(DynamicConstantDesc.ofNamed(BSM_CLASS_DATA, DEFAULT_NAME, returnDesc)); cob.loadConstant(DynamicConstantDesc.ofNamed(BSM_CLASS_DATA, DEFAULT_NAME, returnDesc));
cob.returnInstruction(TypeKind.from(returnType)); cob.return_(TypeKind.from(returnType));
}); });
}); });
return this; return this;
@ -405,8 +405,8 @@ public class ClassDataTest {
MethodTypeDesc mt = MethodTypeDesc.of(returnDesc); MethodTypeDesc mt = MethodTypeDesc.of(returnDesc);
cw = cw.andThen(clb -> { cw = cw.andThen(clb -> {
clb.withMethodBody("classData", mt, accessFlags, cob -> { clb.withMethodBody("classData", mt, accessFlags, cob -> {
cob.constantInstruction(DynamicConstantDesc.ofNamed(BSM_CLASS_DATA_AT, DEFAULT_NAME, returnDesc, index)); cob.loadConstant(DynamicConstantDesc.ofNamed(BSM_CLASS_DATA_AT, DEFAULT_NAME, returnDesc, index));
cob.returnInstruction(TypeKind.from(returnType)); cob.return_(TypeKind.from(returnType));
}); });
}); });
return this; return this;
@ -417,8 +417,8 @@ public class ClassDataTest {
MethodTypeDesc mt = MethodTypeDesc.of(returnDesc); MethodTypeDesc mt = MethodTypeDesc.of(returnDesc);
cw = cw.andThen(clb -> { cw = cw.andThen(clb -> {
clb.withMethodBody(name, mt, accessFlags, cob -> { clb.withMethodBody(name, mt, accessFlags, cob -> {
cob.constantInstruction(dynamic); cob.loadConstant(dynamic);
cob.returnInstruction(TypeKind.from(returnType)); cob.return_(TypeKind.from(returnType));
}); });
}); });
return this; return this;

View File

@ -62,7 +62,7 @@ public class InstructionHelper {
ClassFile.ACC_PUBLIC + ClassFile.ACC_STATIC, methodBuilder -> methodBuilder ClassFile.ACC_PUBLIC + ClassFile.ACC_STATIC, methodBuilder -> methodBuilder
.withCode(codeBuilder -> { .withCode(codeBuilder -> {
for (int i = 0; i < type.parameterCount(); i++) { for (int i = 0; i < type.parameterCount(); i++) {
codeBuilder.loadInstruction(TypeKind.from(type.parameterType(i)), i); codeBuilder.loadLocal(TypeKind.from(type.parameterType(i)), i);
} }
codeBuilder.invokedynamic(DynamicCallSiteDesc.of( codeBuilder.invokedynamic(DynamicCallSiteDesc.of(
MethodHandleDesc.ofMethod( MethodHandleDesc.ofMethod(
@ -74,7 +74,7 @@ public class InstructionHelper {
name, name,
MethodTypeDesc.ofDescriptor(type.toMethodDescriptorString()), MethodTypeDesc.ofDescriptor(type.toMethodDescriptorString()),
boostrapArgs)); boostrapArgs));
codeBuilder.returnInstruction(TypeKind.from(type.returnType())); codeBuilder.return_(TypeKind.from(type.returnType()));
})); }));
}); });
Class<?> gc = l.defineClass(byteArray); Class<?> gc = l.defineClass(byteArray);
@ -116,7 +116,7 @@ public class InstructionHelper {
name, name,
ClassDesc.ofDescriptor(type), ClassDesc.ofDescriptor(type),
bootstrapArgs)) bootstrapArgs))
.returnInstruction(TypeKind.fromDescriptor(type)))); .return_(TypeKind.fromDescriptor(type))));
}); });
Class<?> gc = l.defineClass(bytes); Class<?> gc = l.defineClass(bytes);
return l.findStatic(gc, "m", fromMethodDescriptorString(methodType, l.lookupClass().getClassLoader())); return l.findStatic(gc, "m", fromMethodDescriptorString(methodType, l.lookupClass().getClassLoader()));

View File

@ -138,7 +138,7 @@ public class CondyNestedTest {
// .withCode(codeBuilder -> { // .withCode(codeBuilder -> {
// codeBuilder // codeBuilder
// .aload(2) // .aload(2)
// .instanceof_(ConstantDescs.CD_MethodType) // .instanceOf(ConstantDescs.CD_MethodType)
// .iconst_0(); // .iconst_0();
// Label condy = codeBuilder.newLabel(); // Label condy = codeBuilder.newLabel();
// codeBuilder // codeBuilder

View File

@ -164,7 +164,7 @@ public class SpecialStatic {
}); });
clb.withMethodBody("getMethodHandle", MethodTypeDesc.of(CD_MethodHandle), clb.withMethodBody("getMethodHandle", MethodTypeDesc.of(CD_MethodHandle),
ACC_PUBLIC | ACC_STATIC, cob -> { ACC_PUBLIC | ACC_STATIC, cob -> {
cob.constantInstruction(MethodHandleDesc.ofMethod(SPECIAL, CD_T1, METHOD_NAME, MTD_int)); cob.loadConstant(MethodHandleDesc.ofMethod(SPECIAL, CD_T1, METHOD_NAME, MTD_int));
cob.areturn(); cob.areturn();
}); });
clb.withMethodBody("getLookup", MTD_Lookup, clb.withMethodBody("getLookup", MTD_Lookup,

View File

@ -68,7 +68,7 @@ public class TestPrivateInterfaceMethodReflect {
clb.withFlags(AccessFlag.ABSTRACT, AccessFlag.INTERFACE, AccessFlag.PUBLIC); clb.withFlags(AccessFlag.ABSTRACT, AccessFlag.INTERFACE, AccessFlag.PUBLIC);
clb.withSuperclass(CD_Object); clb.withSuperclass(CD_Object);
clb.withMethodBody("privInstance", MethodTypeDesc.of(CD_int), ACC_PRIVATE, cob -> { clb.withMethodBody("privInstance", MethodTypeDesc.of(CD_int), ACC_PRIVATE, cob -> {
cob.constantInstruction(EXPECTED); cob.loadConstant(EXPECTED);
cob.ireturn(); cob.ireturn();
}); });
}); });

View File

@ -95,7 +95,7 @@ class AdaptCodeTest {
if ((val instanceof Integer) && ((Integer) val) == 13) { if ((val instanceof Integer) && ((Integer) val) == 13) {
val = 7; val = 7;
} }
codeB.constantInstruction(i.opcode(), val); codeB.loadConstant(i.opcode(), val);
} }
default -> codeB.with(codeE); default -> codeB.with(codeE);
} }

View File

@ -78,7 +78,7 @@ public class BSMTest {
BootstrapMethodEntry bme = cpb.bsmEntry(methodHandleEntry, staticArgs); BootstrapMethodEntry bme = cpb.bsmEntry(methodHandleEntry, staticArgs);
ConstantDynamicEntry cde = cpb.constantDynamicEntry(bme, cpb.nameAndTypeEntry("name", CD_String)); ConstantDynamicEntry cde = cpb.constantDynamicEntry(bme, cpb.nameAndTypeEntry("name", CD_String));
codeB.constantInstruction(Opcode.LDC, cde.constantValue()); codeB.ldc(cde.constantValue());
} }
default -> codeB.with(codeE); default -> codeB.with(codeE);
} }

View File

@ -64,7 +64,7 @@ class BuilderBlockTest {
mb -> mb.withCode(xb -> { mb -> mb.withCode(xb -> {
startEnd[0] = xb.startLabel(); startEnd[0] = xb.startLabel();
startEnd[1] = xb.endLabel(); startEnd[1] = xb.endLabel();
xb.returnInstruction(TypeKind.VoidType); xb.return_();
assertEquals(((LabelImpl) startEnd[0]).getBCI(), 0); assertEquals(((LabelImpl) startEnd[0]).getBCI(), 0);
assertEquals(((LabelImpl) startEnd[1]).getBCI(), -1); assertEquals(((LabelImpl) startEnd[1]).getBCI(), -1);
})); }));
@ -83,13 +83,13 @@ class BuilderBlockTest {
mb -> mb.withCode(xb -> { mb -> mb.withCode(xb -> {
startEnd[0] = xb.startLabel(); startEnd[0] = xb.startLabel();
startEnd[1] = xb.endLabel(); startEnd[1] = xb.endLabel();
xb.nopInstruction(); xb.nop();
xb.block(xxb -> { xb.block(xxb -> {
startEnd[2] = xxb.startLabel(); startEnd[2] = xxb.startLabel();
startEnd[3] = xxb.endLabel(); startEnd[3] = xxb.endLabel();
xxb.nopInstruction(); xxb.nop();
}); });
xb.returnInstruction(TypeKind.VoidType); xb.return_();
})); }));
}); });
@ -106,9 +106,9 @@ class BuilderBlockTest {
cb.withMethod("foo", MethodTypeDesc.of(CD_int, CD_int), cb.withMethod("foo", MethodTypeDesc.of(CD_int, CD_int),
AccessFlags.ofMethod(AccessFlag.PUBLIC, AccessFlag.STATIC).flagsMask(), AccessFlags.ofMethod(AccessFlag.PUBLIC, AccessFlag.STATIC).flagsMask(),
mb -> mb.withCode(xb -> xb.iload(0) mb -> mb.withCode(xb -> xb.iload(0)
.ifThen(xxb -> xxb.iconst_1().returnInstruction(TypeKind.IntType)) .ifThen(xxb -> xxb.iconst_1().ireturn())
.iconst_2() .iconst_2()
.returnInstruction(TypeKind.IntType))); .ireturn()));
}); });
Method fooMethod = new ByteArrayClassLoader(BuilderBlockTest.class.getClassLoader(), "Foo", bytes) Method fooMethod = new ByteArrayClassLoader(BuilderBlockTest.class.getClassLoader(), "Foo", bytes)
@ -125,8 +125,8 @@ class BuilderBlockTest {
cb.withMethod("foo", MethodTypeDesc.of(CD_int, CD_int), cb.withMethod("foo", MethodTypeDesc.of(CD_int, CD_int),
AccessFlags.ofMethod(AccessFlag.PUBLIC, AccessFlag.STATIC).flagsMask(), AccessFlags.ofMethod(AccessFlag.PUBLIC, AccessFlag.STATIC).flagsMask(),
mb -> mb.withCode(xb -> xb.iload(0) mb -> mb.withCode(xb -> xb.iload(0)
.ifThenElse(xxb -> xxb.iconst_1().returnInstruction(TypeKind.IntType), .ifThenElse(xxb -> xxb.iconst_1().ireturn(),
xxb -> xxb.iconst_2().returnInstruction(TypeKind.IntType)))); xxb -> xxb.iconst_2().ireturn())));
}); });
Method fooMethod = new ByteArrayClassLoader(BuilderBlockTest.class.getClassLoader(), "Foo", bytes) Method fooMethod = new ByteArrayClassLoader(BuilderBlockTest.class.getClassLoader(), "Foo", bytes)

View File

@ -66,13 +66,13 @@ class BuilderTryCatchTest {
catchBuilder.catching(CD_IOOBE, tb -> { catchBuilder.catching(CD_IOOBE, tb -> {
tb.pop(); tb.pop();
tb.constantInstruction(Opcode.LDC, "IndexOutOfBoundsException"); tb.ldc("IndexOutOfBoundsException");
tb.returnInstruction(TypeKind.ReferenceType); tb.areturn();
}).catchingAll(tb -> { }).catchingAll(tb -> {
tb.pop(); tb.pop();
tb.constantInstruction(Opcode.LDC, "any"); tb.ldc("any");
tb.returnInstruction(TypeKind.ReferenceType); tb.areturn();
}); });
}); });
@ -91,12 +91,12 @@ class BuilderTryCatchTest {
catchBuilder.catching(CD_IOOBE, tb -> { catchBuilder.catching(CD_IOOBE, tb -> {
tb.pop(); tb.pop();
tb.constantInstruction(Opcode.LDC, "IndexOutOfBoundsException"); tb.ldc("IndexOutOfBoundsException");
tb.astore(1); tb.astore(1);
}).catchingAll(tb -> { }).catchingAll(tb -> {
tb.pop(); tb.pop();
tb.constantInstruction(Opcode.LDC, "any"); tb.ldc("any");
tb.astore(1); tb.astore(1);
}); });
}); });
@ -132,8 +132,8 @@ class BuilderTryCatchTest {
catchBuilder.catching(CD_IOOBE, tb -> { catchBuilder.catching(CD_IOOBE, tb -> {
tb.pop(); tb.pop();
tb.constantInstruction(Opcode.LDC, "IndexOutOfBoundsException"); tb.ldc("IndexOutOfBoundsException");
tb.returnInstruction(TypeKind.ReferenceType); tb.areturn();
}); });
}); });
@ -153,8 +153,8 @@ class BuilderTryCatchTest {
catchBuilder.catchingAll(tb -> { catchBuilder.catchingAll(tb -> {
tb.pop(); tb.pop();
tb.constantInstruction(Opcode.LDC, "any"); tb.ldc("any");
tb.returnInstruction(TypeKind.ReferenceType); tb.areturn();
}); });
}); });
@ -187,7 +187,7 @@ class BuilderTryCatchTest {
AccessFlags.ofMethod(AccessFlag.PUBLIC, AccessFlag.STATIC).flagsMask(), mb -> { AccessFlags.ofMethod(AccessFlag.PUBLIC, AccessFlag.STATIC).flagsMask(), mb -> {
mb.withCode(xb -> { mb.withCode(xb -> {
int stringSlot = xb.allocateLocal(TypeKind.ReferenceType); int stringSlot = xb.allocateLocal(TypeKind.ReferenceType);
xb.constantInstruction("S"); xb.loadConstant("S");
xb.astore(stringSlot); xb.astore(stringSlot);
assertThrows(IllegalArgumentException.class, () -> { assertThrows(IllegalArgumentException.class, () -> {
@ -198,14 +198,14 @@ class BuilderTryCatchTest {
catchBuilder.catchingAll(tb -> { catchBuilder.catchingAll(tb -> {
tb.pop(); tb.pop();
tb.constantInstruction(Opcode.LDC, "any"); tb.ldc("any");
tb.returnInstruction(TypeKind.ReferenceType); tb.areturn();
}); });
}); });
}); });
xb.aload(stringSlot); xb.aload(stringSlot);
xb.returnInstruction(TypeKind.ReferenceType); xb.areturn();
}); });
}); });
}); });
@ -218,14 +218,14 @@ class BuilderTryCatchTest {
AccessFlags.ofMethod(AccessFlag.PUBLIC, AccessFlag.STATIC).flagsMask(), mb -> { AccessFlags.ofMethod(AccessFlag.PUBLIC, AccessFlag.STATIC).flagsMask(), mb -> {
mb.withCode(xb -> { mb.withCode(xb -> {
int stringSlot = xb.allocateLocal(TypeKind.ReferenceType); int stringSlot = xb.allocateLocal(TypeKind.ReferenceType);
xb.constantInstruction("S"); xb.loadConstant("S");
xb.astore(stringSlot); xb.astore(stringSlot);
xb.trying(tb -> { xb.trying(tb -> {
int intSlot = tb.allocateLocal(TypeKind.IntType); int intSlot = tb.allocateLocal(TypeKind.IntType);
tb.aload(0); tb.aload(0);
tb.constantInstruction(0); tb.loadConstant(0);
// IndexOutOfBoundsException // IndexOutOfBoundsException
tb.aaload(); tb.aaload();
// NullPointerException // NullPointerException
@ -240,7 +240,7 @@ class BuilderTryCatchTest {
tb.pop(); tb.pop();
int doubleSlot = tb.allocateLocal(TypeKind.DoubleType); int doubleSlot = tb.allocateLocal(TypeKind.DoubleType);
tb.constantInstruction(Math.PI); tb.loadConstant(Math.PI);
tb.dstore(doubleSlot); tb.dstore(doubleSlot);
tb.dload(doubleSlot); tb.dload(doubleSlot);
@ -250,7 +250,7 @@ class BuilderTryCatchTest {
tb.pop(); tb.pop();
int refSlot = tb.allocateLocal(TypeKind.ReferenceType); int refSlot = tb.allocateLocal(TypeKind.ReferenceType);
tb.constantInstruction("REF"); tb.loadConstant("REF");
tb.astore(refSlot); tb.astore(refSlot);
tb.aload(refSlot); tb.aload(refSlot);
@ -260,7 +260,7 @@ class BuilderTryCatchTest {
}); });
xb.aload(stringSlot); xb.aload(stringSlot);
xb.returnInstruction(TypeKind.ReferenceType); xb.areturn();
}); });
}); });
}); });
@ -281,12 +281,12 @@ class BuilderTryCatchTest {
AccessFlags.ofMethod(AccessFlag.PUBLIC, AccessFlag.STATIC).flagsMask(), mb -> { AccessFlags.ofMethod(AccessFlag.PUBLIC, AccessFlag.STATIC).flagsMask(), mb -> {
mb.withCode(xb -> { mb.withCode(xb -> {
int stringSlot = xb.allocateLocal(TypeKind.ReferenceType); int stringSlot = xb.allocateLocal(TypeKind.ReferenceType);
xb.constantInstruction("S"); xb.loadConstant("S");
xb.astore(stringSlot); xb.astore(stringSlot);
xb.trying(tb -> { xb.trying(tb -> {
tb.aload(0); tb.aload(0);
tb.constantInstruction(0); tb.loadConstant(0);
// IndexOutOfBoundsException // IndexOutOfBoundsException
tb.aaload(); tb.aaload();
// NullPointerException // NullPointerException
@ -295,7 +295,7 @@ class BuilderTryCatchTest {
}, c); }, c);
xb.aload(stringSlot); xb.aload(stringSlot);
xb.returnInstruction(TypeKind.ReferenceType); xb.areturn();
}); });
}); });
}); });

View File

@ -50,9 +50,9 @@ class DiscontinuedInstructionsTest {
.withVersion(JAVA_5_VERSION, 0) .withVersion(JAVA_5_VERSION, 0)
.withMethodBody(testMethod, MethodTypeDesc.of(CD_void, cd_list), ACC_PUBLIC | ACC_STATIC, cob -> cob .withMethodBody(testMethod, MethodTypeDesc.of(CD_void, cd_list), ACC_PUBLIC | ACC_STATIC, cob -> cob
.block(bb -> { .block(bb -> {
bb.constantInstruction("Hello") bb.loadConstant("Hello")
.with(DiscontinuedInstruction.JsrInstruction.of(bb.breakLabel())); .with(DiscontinuedInstruction.JsrInstruction.of(bb.breakLabel()));
bb.constantInstruction("World") bb.loadConstant("World")
.with(DiscontinuedInstruction.JsrInstruction.of(Opcode.JSR_W, bb.breakLabel())) .with(DiscontinuedInstruction.JsrInstruction.of(Opcode.JSR_W, bb.breakLabel()))
.return_(); .return_();
}) })

View File

@ -49,9 +49,9 @@ class LDCTest {
cb.withFlags(AccessFlag.PUBLIC); cb.withFlags(AccessFlag.PUBLIC);
cb.withVersion(52, 0); cb.withVersion(52, 0);
cb.withMethod("<init>", MethodTypeDesc.of(CD_void), 0, mb -> mb cb.withMethod("<init>", MethodTypeDesc.of(CD_void), 0, mb -> mb
.withCode(codeb -> codeb.loadInstruction(TypeKind.ReferenceType, 0) .withCode(codeb -> codeb.aload(0)
.invokeInstruction(INVOKESPECIAL, CD_Object, "<init>", MTD_VOID, false) .invokespecial(CD_Object, "<init>", MTD_VOID, false)
.returnInstruction(VoidType) .return_()
) )
) )
@ -62,15 +62,15 @@ class LDCTest {
for (int i = 0; i <= 256/2 + 2; i++) { // two entries per String for (int i = 0; i <= 256/2 + 2; i++) { // two entries per String
StringEntry s = cpb.stringEntry("string" + i); StringEntry s = cpb.stringEntry("string" + i);
} }
c0.constantInstruction(LDC, "string0") c0.loadConstant(LDC, "string0")
.constantInstruction(LDC, "string131") .loadConstant(LDC, "string131")
.constantInstruction(LDC, "string50") .loadConstant(LDC, "string50")
.constantInstruction(-0.0f) .loadConstant(-0.0f)
.constantInstruction(-0.0d) .loadConstant(-0.0d)
//non-LDC test cases //non-LDC test cases
.constantInstruction(0.0f) .loadConstant(0.0f)
.constantInstruction(0.0d) .loadConstant(0.0d)
.returnInstruction(VoidType); .return_();
})); }));
}); });

View File

@ -80,15 +80,15 @@ class LowAdaptTest {
cb.withMethod("doit", MethodTypeDesc.of(CD_int, CD_int), cb.withMethod("doit", MethodTypeDesc.of(CD_int, CD_int),
AccessFlags.ofMethod(AccessFlag.PUBLIC, AccessFlag.STATIC).flagsMask(), AccessFlags.ofMethod(AccessFlag.PUBLIC, AccessFlag.STATIC).flagsMask(),
mb -> mb.withCode(xb -> { mb -> mb.withCode(xb -> {
xb.invokeDynamicInstruction(indy); xb.invokedynamic(indy);
xb.storeInstruction(TypeKind.ReferenceType, 1); xb.astore(1);
xb.loadInstruction(TypeKind.ReferenceType, 1); xb.aload(1);
xb.loadInstruction(TypeKind.IntType, 0); xb.iload(0);
xb.invokeInstruction(Opcode.INVOKEINTERFACE, ClassDesc.of("java.util.function.IntUnaryOperator"), xb.invokeinterface(ClassDesc.of("java.util.function.IntUnaryOperator"),
"applyAsInt", MethodTypeDesc.ofDescriptor("(I)I"), true); "applyAsInt", MethodTypeDesc.ofDescriptor("(I)I"));
xb.storeInstruction(TypeKind.IntType, 2); xb.istore(2);
xb.loadInstruction(TypeKind.IntType, 2); xb.iload(2);
xb.returnInstruction(TypeKind.IntType); xb.ireturn();
})); }));
}); });

View File

@ -122,9 +122,9 @@ class LvtTest {
cb.withVersion(52, 0); cb.withVersion(52, 0);
cb.with(SourceFileAttribute.of(cb.constantPool().utf8Entry(("MyClass.java")))) cb.with(SourceFileAttribute.of(cb.constantPool().utf8Entry(("MyClass.java"))))
.withMethod("<init>", MethodTypeDesc.of(CD_void), 0, mb -> mb .withMethod("<init>", MethodTypeDesc.of(CD_void), 0, mb -> mb
.withCode(codeb -> codeb.loadInstruction(TypeKind.ReferenceType, 0) .withCode(codeb -> codeb.aload(0)
.invokeInstruction(INVOKESPECIAL, CD_Object, "<init>", MTD_VOID, false) .invokespecial(CD_Object, "<init>", MTD_VOID, false)
.returnInstruction(VoidType) .return_()
) )
) )
.withMethod("main", MethodTypeDesc.of(CD_void, CD_String.arrayType()), .withMethod("main", MethodTypeDesc.of(CD_void, CD_String.arrayType()),
@ -146,27 +146,27 @@ class LvtTest {
c0.localVariable(1, i1n, intSig, i1, preEnd) // LV Entries can be added before the labels c0.localVariable(1, i1n, intSig, i1, preEnd) // LV Entries can be added before the labels
.localVariable(2, i2, intSig, loopTop, preEnd) .localVariable(2, i2, intSig, loopTop, preEnd)
.labelBinding(start) .labelBinding(start)
.constantInstruction(ICONST_1, 1) // 0 .iconst_1() // 0
.storeInstruction(TypeKind.IntType, 1) // 1 .istore(1) // 1
.labelBinding(i1) .labelBinding(i1)
.constantInstruction(ICONST_1, 1) // 2 .iconst_1() // 2
.storeInstruction(TypeKind.IntType, 2) // 3 .istore(2) // 3
.labelBinding(loopTop) .labelBinding(loopTop)
.loadInstruction(TypeKind.IntType, 2) // 4 .iload(2) // 4
.constantInstruction(BIPUSH, 10) // 5 .bipush(10) // 5
.branchInstruction(IF_ICMPGE, loopEnd) // 6 .if_icmpge(loopEnd) // 6
.loadInstruction(TypeKind.IntType, 1) // 7 .iload(1) // 7
.loadInstruction(TypeKind.IntType, 2) // 8 .iload(2) // 8
.operatorInstruction(IMUL) // 9 .imul() // 9
.storeInstruction(TypeKind.IntType, 1) // 10 .istore(1) // 10
.incrementInstruction(2, 1) // 11 .iinc(2, 1) // 11
.branchInstruction(GOTO, loopTop) // 12 .goto_(loopTop) // 12
.labelBinding(loopEnd) .labelBinding(loopEnd)
.fieldInstruction(GETSTATIC, CD_System, "out", CD_PrintStream) // 13 .getstatic(CD_System, "out", CD_PrintStream) // 13
.loadInstruction(TypeKind.IntType, 1) .iload(1)
.invokeInstruction(INVOKEVIRTUAL, CD_PrintStream, "println", MTD_INT_VOID, false) // 15 .invokevirtual(CD_PrintStream, "println", MTD_INT_VOID) // 15
.labelBinding(preEnd) .labelBinding(preEnd)
.returnInstruction(VoidType) .return_()
.labelBinding(end) .labelBinding(end)
.localVariable(0, slotName, desc, start, end); // and lv entries can be added after the labels .localVariable(0, slotName, desc, start, end); // and lv entries can be added after the labels
})); }));
@ -236,9 +236,9 @@ class LvtTest {
cb.with(SourceFileAttribute.of(cb.constantPool().utf8Entry(("MyClass.java")))) cb.with(SourceFileAttribute.of(cb.constantPool().utf8Entry(("MyClass.java"))))
.withMethod("<init>", MethodTypeDesc.of(CD_void), 0, mb -> mb .withMethod("<init>", MethodTypeDesc.of(CD_void), 0, mb -> mb
.withCode(codeb -> codeb.loadInstruction(TypeKind.ReferenceType, 0) .withCode(codeb -> codeb.aload(0)
.invokeInstruction(INVOKESPECIAL, CD_Object, "<init>", MTD_VOID, false) .invokespecial(CD_Object, "<init>", MTD_VOID, false)
.returnInstruction(VoidType) .return_()
) )
) )
@ -263,14 +263,14 @@ class LvtTest {
c0.localVariable(2, l, juList, beforeRet, end) c0.localVariable(2, l, juList, beforeRet, end)
.localVariableType(1, u, TU, start, end) .localVariableType(1, u, TU, start, end)
.labelBinding(start) .labelBinding(start)
.newObjectInstruction(ClassDesc.of("java.util.ArrayList")) .new_(ClassDesc.of("java.util.ArrayList"))
.stackInstruction(DUP) .dup()
.invokeInstruction(INVOKESPECIAL, CD_ArrayList, "<init>", MTD_VOID, false) .invokespecial(CD_ArrayList, "<init>", MTD_VOID, false)
.storeInstruction(TypeKind.ReferenceType, 2) .astore(2)
.labelBinding(beforeRet) .labelBinding(beforeRet)
.localVariableType(2, l, sig, beforeRet, end) .localVariableType(2, l, sig, beforeRet, end)
.loadInstruction(TypeKind.ReferenceType, 1) .aload(1)
.returnInstruction(TypeKind.ReferenceType) .areturn()
.labelBinding(end) .labelBinding(end)
.localVariable(0, slotName, desc, start, end) .localVariable(0, slotName, desc, start, end)
.localVariable(1, u, jlObject, start, end); .localVariable(1, u, jlObject, start, end);

View File

@ -68,9 +68,9 @@ class OneToOneTest {
cb.with(SourceFileAttribute.of(cb.constantPool().utf8Entry(("MyClass.java")))) cb.with(SourceFileAttribute.of(cb.constantPool().utf8Entry(("MyClass.java"))))
.withMethod("<init>", MethodTypeDesc.of(CD_void), 0, mb -> mb .withMethod("<init>", MethodTypeDesc.of(CD_void), 0, mb -> mb
.withCode(codeb -> codeb.loadInstruction(TypeKind.ReferenceType, 0) .withCode(codeb -> codeb.aload(0)
.invokeInstruction(INVOKESPECIAL, CD_Object, "<init>", MTD_VOID, false) .invokespecial(CD_Object, "<init>", MTD_VOID, false)
.returnInstruction(TypeKind.VoidType) .return_()
) )
) )
.withMethod("main", MethodTypeDesc.of(CD_void, CD_String.arrayType()), .withMethod("main", MethodTypeDesc.of(CD_void, CD_String.arrayType()),
@ -80,25 +80,25 @@ class OneToOneTest {
Label loopEnd = c0.newLabel(); Label loopEnd = c0.newLabel();
int fac = 1; int fac = 1;
int i = 2; int i = 2;
c0.constantInstruction(ICONST_1, 1) // 0 c0.iconst_1() // 0
.storeInstruction(TypeKind.IntType, fac) // 1 .istore(fac) // 1
.constantInstruction(ICONST_1, 1) // 2 .iconst_1() // 2
.storeInstruction(TypeKind.IntType, i) // 3 .istore(i) // 3
.labelBinding(loopTop) .labelBinding(loopTop)
.loadInstruction(TypeKind.IntType, i) // 4 .iload(i) // 4
.constantInstruction(BIPUSH, 10) // 5 .bipush(10) // 5
.branchInstruction(IF_ICMPGE, loopEnd) // 6 .if_icmpge(loopEnd) // 6
.loadInstruction(TypeKind.IntType, fac) // 7 .iload(fac) // 7
.loadInstruction(TypeKind.IntType, i) // 8 .iload(i) // 8
.operatorInstruction(IMUL) // 9 .imul() // 9
.storeInstruction(TypeKind.IntType, fac) // 10 .istore(fac) // 10
.incrementInstruction(i, 1) // 11 .iinc(i, 1) // 11
.branchInstruction(GOTO, loopTop) // 12 .goto_(loopTop) // 12
.labelBinding(loopEnd) .labelBinding(loopEnd)
.fieldInstruction(GETSTATIC, CD_System, "out", CD_PrintStream) // 13 .getstatic(CD_System, "out", CD_PrintStream) // 13
.loadInstruction(TypeKind.IntType, fac) .iload(fac)
.invokeInstruction(INVOKEVIRTUAL, CD_PrintStream, "println", MTD_INT_VOID, false) // 15 .invokevirtual(CD_PrintStream, "println", MTD_INT_VOID) // 15
.returnInstruction(TypeKind.VoidType); .return_();
} }
) )
); );

View File

@ -107,7 +107,7 @@ public class OpcodesValidationTest {
cb -> cb.withFlags(AccessFlag.PUBLIC) cb -> cb.withFlags(AccessFlag.PUBLIC)
.withMethod("<init>", MethodTypeDesc.of(CD_void), 0, .withMethod("<init>", MethodTypeDesc.of(CD_void), 0,
mb -> mb.withCode( mb -> mb.withCode(
codeb -> codeb.constantInstruction(opcode, (ConstantDesc) constant)))); codeb -> codeb.loadConstant(opcode, (ConstantDesc) constant))));
} }
@ -124,6 +124,6 @@ public class OpcodesValidationTest {
cb -> cb.withFlags(AccessFlag.PUBLIC) cb -> cb.withFlags(AccessFlag.PUBLIC)
.withMethod("<init>", MethodTypeDesc.of(CD_void), 0, .withMethod("<init>", MethodTypeDesc.of(CD_void), 0,
mb -> mb .withCode( mb -> mb .withCode(
codeb -> codeb.constantInstruction(opcode, (ConstantDesc)constant)))); codeb -> codeb.loadConstant(opcode, (ConstantDesc)constant))));
} }
} }

View File

@ -60,7 +60,7 @@ public final class PrimitiveClassConstantTest {
cob.return_(); cob.return_();
}); });
clb.withMethodBody("get", MethodTypeDesc.of(CD_Object), ACC_PUBLIC, cob -> { clb.withMethodBody("get", MethodTypeDesc.of(CD_Object), ACC_PUBLIC, cob -> {
cob.constantInstruction(CD_int); cob.loadConstant(CD_int);
cob.areturn(); cob.areturn();
}); });
clb.withMethodBody("get2", MethodTypeDesc.of(CD_Class), ACC_PUBLIC, cob -> { clb.withMethodBody("get2", MethodTypeDesc.of(CD_Class), ACC_PUBLIC, cob -> {

View File

@ -211,9 +211,9 @@ class ShortJumpsFixTest {
for (int i = 0; i < sample.expected.length - 4; i++) //cherry-pick XCONST_ instructions from expected output for (int i = 0; i < sample.expected.length - 4; i++) //cherry-pick XCONST_ instructions from expected output
cob.with(ConstantInstruction.ofIntrinsic(sample.expected[i])); cob.with(ConstantInstruction.ofIntrinsic(sample.expected[i]));
var target = cob.newLabel(); var target = cob.newLabel();
cob.branchInstruction(sample.jumpCode, target); cob.branch(sample.jumpCode, target);
for (int i = overflow ? 40000 : 1; i > 0; i--) for (int i = overflow ? 40000 : 1; i > 0; i--)
cob.nopInstruction(); cob.nop();
cob.labelBinding(target); cob.labelBinding(target);
cob.return_(); cob.return_();
})))); }))));
@ -228,12 +228,12 @@ class ShortJumpsFixTest {
cob.goto_w(fwd); cob.goto_w(fwd);
cob.labelBinding(target); cob.labelBinding(target);
for (int i = overflow ? 40000 : 1; i > 0; i--) for (int i = overflow ? 40000 : 1; i > 0; i--)
cob.nopInstruction(); cob.nop();
cob.return_(); cob.return_();
cob.labelBinding(fwd); cob.labelBinding(fwd);
for (int i = 3; i < sample.expected.length - 3; i++) //cherry-pick XCONST_ instructions from expected output for (int i = 3; i < sample.expected.length - 3; i++) //cherry-pick XCONST_ instructions from expected output
cob.with(ConstantInstruction.ofIntrinsic(sample.expected[i])); cob.with(ConstantInstruction.ofIntrinsic(sample.expected[i]));
cob.branchInstruction(sample.jumpCode, target); cob.branch(sample.jumpCode, target);
cob.return_(); cob.return_();
})))); }))));
} }
@ -244,7 +244,7 @@ class ShortJumpsFixTest {
(cob, coe) -> { (cob, coe) -> {
if (coe instanceof NopInstruction) if (coe instanceof NopInstruction)
for (int i = 0; i < 40000; i++) //cause label overflow during transform for (int i = 0; i < 40000; i++) //cause label overflow during transform
cob.nopInstruction(); cob.nop();
cob.with(coe); cob.with(coe);
})); }));
} }

View File

@ -286,10 +286,10 @@ class StackMapsTest {
Label next = cb.newLabel(); Label next = cb.newLabel();
cb.iload(0); cb.iload(0);
cb.ifeq(next); cb.ifeq(next);
cb.constantInstruction(0.0d); cb.loadConstant(0.0d);
cb.goto_(target); cb.goto_(target);
cb.labelBinding(next); cb.labelBinding(next);
cb.constantInstruction(0); cb.loadConstant(0);
cb.labelBinding(target); cb.labelBinding(target);
cb.pop(); cb.pop();
}))); })));
@ -304,10 +304,10 @@ class StackMapsTest {
Label next = cb.newLabel(); Label next = cb.newLabel();
cb.iload(0); cb.iload(0);
cb.ifeq(next); cb.ifeq(next);
cb.constantInstruction(0.0f); cb.loadConstant(0.0f);
cb.goto_(target); cb.goto_(target);
cb.labelBinding(next); cb.labelBinding(next);
cb.constantInstruction(0); cb.loadConstant(0);
cb.labelBinding(target); cb.labelBinding(target);
cb.pop(); cb.pop();
}))); })));

View File

@ -58,7 +58,7 @@ class StackTrackerTest {
assertIterableEquals(stackTracker.stack().get(), List.of(IntType, LongType, ReferenceType, DoubleType, FloatType)); assertIterableEquals(stackTracker.stack().get(), List.of(IntType, LongType, ReferenceType, DoubleType, FloatType));
tryb.ifThen(thb -> { tryb.ifThen(thb -> {
assertIterableEquals(stackTracker.stack().get(), List.of(LongType, ReferenceType, DoubleType, FloatType)); assertIterableEquals(stackTracker.stack().get(), List.of(LongType, ReferenceType, DoubleType, FloatType));
thb.constantInstruction(ClassDesc.of("Phee")); thb.loadConstant(ClassDesc.of("Phee"));
assertIterableEquals(stackTracker.stack().get(), List.of(ReferenceType, LongType, ReferenceType, DoubleType, FloatType)); assertIterableEquals(stackTracker.stack().get(), List.of(ReferenceType, LongType, ReferenceType, DoubleType, FloatType));
thb.athrow(); thb.athrow();
assertFalse(stackTracker.stack().isPresent()); assertFalse(stackTracker.stack().isPresent());
@ -91,7 +91,7 @@ class StackTrackerTest {
var l2 = stcb.newBoundLabel(); //back jump target var l2 = stcb.newBoundLabel(); //back jump target
assertFalse(stackTracker.stack().isPresent()); //no stack assertFalse(stackTracker.stack().isPresent()); //no stack
assertTrue(stackTracker.maxStackSize().isPresent()); //however still tracking assertTrue(stackTracker.maxStackSize().isPresent()); //however still tracking
stcb.constantInstruction(ClassDesc.of("Phee")); //stack instruction on unknown stack cause tracking lost stcb.loadConstant(ClassDesc.of("Phee")); //stack instruction on unknown stack cause tracking lost
assertFalse(stackTracker.stack().isPresent()); //no stack assertFalse(stackTracker.stack().isPresent()); //no stack
assertFalse(stackTracker.maxStackSize().isPresent()); //because tracking lost assertFalse(stackTracker.maxStackSize().isPresent()); //because tracking lost
stcb.athrow(); stcb.athrow();

View File

@ -58,9 +58,9 @@ class TempConstantPoolBuilderTest {
cb.withFlags(AccessFlag.PUBLIC) cb.withFlags(AccessFlag.PUBLIC)
.with(SourceFileAttribute.of(cb.constantPool().utf8Entry(("MyClass.java")))) .with(SourceFileAttribute.of(cb.constantPool().utf8Entry(("MyClass.java"))))
.withMethod("<init>", MethodTypeDesc.of(CD_void), 0, mb -> mb .withMethod("<init>", MethodTypeDesc.of(CD_void), 0, mb -> mb
.withCode(codeb -> codeb.loadInstruction(TypeKind.ReferenceType, 0) .withCode(codeb -> codeb.aload(0)
.invokeInstruction(INVOKESPECIAL, CD_Object, "<init>", MTD_VOID, false) .invokespecial(CD_Object, "<init>", MTD_VOID, false)
.returnInstruction(VoidType) .return_()
) )
.with(RuntimeVisibleAnnotationsAttribute.of(Annotation.of(INTERFACE, .with(RuntimeVisibleAnnotationsAttribute.of(Annotation.of(INTERFACE,
AnnotationElement.ofString("foo", "bar")))) AnnotationElement.ofString("foo", "bar"))))

View File

@ -59,7 +59,7 @@ class TransformTests {
static CodeTransform swapLdc(String x, String y) { static CodeTransform swapLdc(String x, String y) {
return (b, e) -> { return (b, e) -> {
if (e instanceof ConstantInstruction ci && ci.constantValue().equals(x)) { if (e instanceof ConstantInstruction ci && ci.constantValue().equals(x)) {
b.constantInstruction(y); b.loadConstant(y);
} }
else else
b.with(e); b.with(e);

View File

@ -196,7 +196,7 @@ class Utf8EntryTest {
static byte[] createClassFile(String s) { static byte[] createClassFile(String s) {
return ClassFile.of().build(ClassDesc.of("C"), return ClassFile.of().build(ClassDesc.of("C"),
clb -> clb.withMethod("m", MethodTypeDesc.of(CD_void), 0, clb -> clb.withMethod("m", MethodTypeDesc.of(CD_void), 0,
mb -> mb.withCode(cb -> cb.constantInstruction(s) mb -> mb.withCode(cb -> cb.loadConstant(s)
.returnInstruction(VoidType)))); .return_())));
} }
} }

View File

@ -54,10 +54,10 @@ class WriteTest {
cb.withFlags(AccessFlag.PUBLIC); cb.withFlags(AccessFlag.PUBLIC);
cb.with(SourceFileAttribute.of(cb.constantPool().utf8Entry(("MyClass.java")))) cb.with(SourceFileAttribute.of(cb.constantPool().utf8Entry(("MyClass.java"))))
.withMethod("<init>", MethodTypeDesc.of(CD_void), 0, mb -> mb .withMethod("<init>", MethodTypeDesc.of(CD_void), 0, mb -> mb
.withCode(codeb -> codeb.loadInstruction(TypeKind.ReferenceType, 0) .withCode(codeb -> codeb.aload(0)
.invokeInstruction(INVOKESPECIAL, CD_Object, "<init>", .invokespecial(CD_Object, "<init>",
MethodTypeDesc.ofDescriptor("()V"), false) MethodTypeDesc.ofDescriptor("()V"), false)
.returnInstruction(VoidType) .return_()
) )
) )
.withMethod("main", MethodTypeDesc.of(CD_void, CD_String.arrayType()), .withMethod("main", MethodTypeDesc.of(CD_void, CD_String.arrayType()),
@ -66,25 +66,25 @@ class WriteTest {
Label loopTop = c0.newLabel(); Label loopTop = c0.newLabel();
Label loopEnd = c0.newLabel(); Label loopEnd = c0.newLabel();
c0 c0
.constantInstruction(ICONST_1, 1) // 0 .iconst_1() // 0
.storeInstruction(TypeKind.IntType, 1) // 1 .istore(1) // 1
.constantInstruction(ICONST_1, 1) // 2 .iconst_1() // 2
.storeInstruction(TypeKind.IntType, 2) // 3 .istore(2) // 3
.labelBinding(loopTop) .labelBinding(loopTop)
.loadInstruction(TypeKind.IntType, 2) // 4 .iload(2) // 4
.constantInstruction(BIPUSH, 10) // 5 .bipush(10) // 5
.branchInstruction(IF_ICMPGE, loopEnd) // 6 .if_icmpge(loopEnd) // 6
.loadInstruction(TypeKind.IntType, 1) // 7 .iload(1) // 7
.loadInstruction(TypeKind.IntType, 2) // 8 .iload(2) // 8
.operatorInstruction(IMUL) // 9 .imul() // 9
.storeInstruction(TypeKind.IntType, 1) // 10 .istore(1) // 10
.incrementInstruction(2, 1) // 11 .iinc(2, 1) // 11
.branchInstruction(GOTO, loopTop) // 12 .goto_(loopTop) // 12
.labelBinding(loopEnd) .labelBinding(loopEnd)
.fieldInstruction(GETSTATIC, TestConstants.CD_System, "out", TestConstants.CD_PrintStream) // 13 .getstatic(TestConstants.CD_System, "out", TestConstants.CD_PrintStream) // 13
.loadInstruction(TypeKind.IntType, 1) .iload(1)
.invokeInstruction(INVOKEVIRTUAL, TestConstants.CD_PrintStream, "println", TestConstants.MTD_INT_VOID, false) // 15 .invokevirtual(TestConstants.CD_PrintStream, "println", TestConstants.MTD_INT_VOID) // 15
.returnInstruction(VoidType); .return_();
})); }));
}); });
} }
@ -96,9 +96,9 @@ class WriteTest {
cb.withFlags(AccessFlag.PUBLIC) cb.withFlags(AccessFlag.PUBLIC)
.with(SourceFileAttribute.of(cb.constantPool().utf8Entry(("MyClass.java")))) .with(SourceFileAttribute.of(cb.constantPool().utf8Entry(("MyClass.java"))))
.withMethod("<init>", MethodTypeDesc.of(CD_void), 0, mb -> mb .withMethod("<init>", MethodTypeDesc.of(CD_void), 0, mb -> mb
.withCode(codeb -> codeb.loadInstruction(ReferenceType, 0) .withCode(codeb -> codeb.aload(0)
.invokeInstruction(INVOKESPECIAL, CD_Object, "<init>", MTD_VOID, false) .invokespecial(CD_Object, "<init>", MTD_VOID, false)
.returnInstruction(VoidType) .return_()
) )
) )
.withMethod("main", MethodTypeDesc.of(CD_void, CD_String.arrayType()), .withMethod("main", MethodTypeDesc.of(CD_void, CD_String.arrayType()),
@ -107,25 +107,25 @@ class WriteTest {
Label loopTop = c0.newLabel(); Label loopTop = c0.newLabel();
Label loopEnd = c0.newLabel(); Label loopEnd = c0.newLabel();
c0 c0
.constantInstruction(ICONST_1, 1) // 0 .iconst_1() // 0
.storeInstruction(IntType, 1) // 1 .istore(1) // 1
.constantInstruction(ICONST_1, 1) // 2 .iconst_1() // 2
.storeInstruction(IntType, 2) // 3 .istore(2) // 3
.labelBinding(loopTop) .labelBinding(loopTop)
.loadInstruction(IntType, 2) // 4 .iload(2) // 4
.constantInstruction(BIPUSH, 10) // 5 .bipush(10) // 5
.branchInstruction(IF_ICMPGE, loopEnd) // 6 .if_icmpge(loopEnd) // 6
.loadInstruction(IntType, 1) // 7 .iload(1) // 7
.loadInstruction(IntType, 2) // 8 .iload(2) // 8
.operatorInstruction(IMUL) // 9 .imul() // 9
.storeInstruction(IntType, 1) // 10 .istore(1) // 10
.incrementInstruction(2, 1) // 11 .iinc(2, 1) // 11
.branchInstruction(GOTO, loopTop) // 12 .goto_(loopTop) // 12
.labelBinding(loopEnd) .labelBinding(loopEnd)
.fieldInstruction(GETSTATIC, TestConstants.CD_System, "out", TestConstants.CD_PrintStream) // 13 .getstatic(TestConstants.CD_System, "out", TestConstants.CD_PrintStream) // 13
.loadInstruction(IntType, 1) .iload(1)
.invokeInstruction(INVOKEVIRTUAL, TestConstants.CD_PrintStream, "println", TestConstants.MTD_INT_VOID, false) // 15 .invokevirtual(TestConstants.CD_PrintStream, "println", TestConstants.MTD_INT_VOID) // 15
.returnInstruction(VoidType); .return_();
})); }));
}); });
} }

View File

@ -251,7 +251,7 @@ public class ExampleGallery {
@Override @Override
public void accept(CodeBuilder codeB, CodeElement codeE) { public void accept(CodeBuilder codeB, CodeElement codeE) {
if (found) { if (found) {
codeB.nopInstruction(); codeB.nop();
found = false; found = false;
} }
codeB.with(codeE); codeB.with(codeE);
@ -265,7 +265,7 @@ public class ExampleGallery {
return ClassFile.of().transform(cm, ClassTransform.transformingMethodBodies((codeB, codeE) -> { return ClassFile.of().transform(cm, ClassTransform.transformingMethodBodies((codeB, codeE) -> {
switch (codeE) { switch (codeE) {
case InvokeInstruction i -> { case InvokeInstruction i -> {
codeB.nopInstruction(); codeB.nop();
codeB.with(codeE); codeB.with(codeE);
} }
default -> codeB.with(codeE); default -> codeB.with(codeE);
@ -277,7 +277,7 @@ public class ExampleGallery {
return ClassFile.of().transform(cm, ClassTransform.transformingMethodBodies((codeB, codeE) -> { return ClassFile.of().transform(cm, ClassTransform.transformingMethodBodies((codeB, codeE) -> {
switch (codeE) { switch (codeE) {
case ConstantInstruction ci -> { case ConstantInstruction ci -> {
if (ci.constantValue() instanceof Integer i) codeB.constantInstruction(i + 1); if (ci.constantValue() instanceof Integer i) codeB.loadConstant(i + 1);
else codeB.with(codeE); else codeB.with(codeE);
} }
default -> codeB.with(codeE); default -> codeB.with(codeE);

View File

@ -35,53 +35,53 @@ public class InstructionModelToCodeBuilder {
public static void toBuilder(CodeElement model, CodeBuilder cb) { public static void toBuilder(CodeElement model, CodeBuilder cb) {
switch (model) { switch (model) {
case LoadInstruction im -> case LoadInstruction im ->
cb.loadInstruction(im.typeKind(), im.slot()); cb.loadLocal(im.typeKind(), im.slot());
case StoreInstruction im -> case StoreInstruction im ->
cb.storeInstruction(im.typeKind(), im.slot()); cb.storeLocal(im.typeKind(), im.slot());
case IncrementInstruction im -> case IncrementInstruction im ->
cb.incrementInstruction(im.slot(), im.constant()); cb.iinc(im.slot(), im.constant());
case BranchInstruction im -> case BranchInstruction im ->
cb.branchInstruction(im.opcode(), im.target()); cb.branch(im.opcode(), im.target());
case LookupSwitchInstruction im -> case LookupSwitchInstruction im ->
cb.lookupSwitchInstruction(im.defaultTarget(), im.cases()); cb.lookupswitch(im.defaultTarget(), im.cases());
case TableSwitchInstruction im -> case TableSwitchInstruction im ->
cb.tableSwitchInstruction(im.lowValue(), im.highValue(), im.defaultTarget(), im.cases()); cb.tableswitch(im.lowValue(), im.highValue(), im.defaultTarget(), im.cases());
case ReturnInstruction im -> case ReturnInstruction im ->
cb.returnInstruction(im.typeKind()); cb.return_(im.typeKind());
case ThrowInstruction im -> case ThrowInstruction im ->
cb.throwInstruction(); cb.athrow();
case FieldInstruction im -> case FieldInstruction im ->
cb.fieldInstruction(im.opcode(), im.owner().asSymbol(), im.name().stringValue(), im.typeSymbol()); cb.fieldAccess(im.opcode(), im.owner().asSymbol(), im.name().stringValue(), im.typeSymbol());
case InvokeInstruction im -> case InvokeInstruction im ->
cb.invokeInstruction(im.opcode(), im.owner().asSymbol(), im.name().stringValue(), im.typeSymbol(), im.isInterface()); cb.invoke(im.opcode(), im.owner().asSymbol(), im.name().stringValue(), im.typeSymbol(), im.isInterface());
case InvokeDynamicInstruction im -> case InvokeDynamicInstruction im ->
cb.invokeDynamicInstruction(DynamicCallSiteDesc.of(im.bootstrapMethod(), im.name().stringValue(), MethodTypeDesc.ofDescriptor(im.type().stringValue()), im.bootstrapArgs().toArray(ConstantDesc[]::new))); cb.invokedynamic(DynamicCallSiteDesc.of(im.bootstrapMethod(), im.name().stringValue(), MethodTypeDesc.ofDescriptor(im.type().stringValue()), im.bootstrapArgs().toArray(ConstantDesc[]::new)));
case NewObjectInstruction im -> case NewObjectInstruction im ->
cb.newObjectInstruction(im.className().asSymbol()); cb.new_(im.className().asSymbol());
case NewPrimitiveArrayInstruction im -> case NewPrimitiveArrayInstruction im ->
cb.newPrimitiveArrayInstruction(im.typeKind()); cb.newarray(im.typeKind());
case NewReferenceArrayInstruction im -> case NewReferenceArrayInstruction im ->
cb.newReferenceArrayInstruction(im.componentType()); cb.anewarray(im.componentType());
case NewMultiArrayInstruction im -> case NewMultiArrayInstruction im ->
cb.newMultidimensionalArrayInstruction(im.dimensions(), im.arrayType()); cb.multianewarray(im.arrayType(), im.dimensions());
case TypeCheckInstruction im -> case TypeCheckInstruction im ->
cb.typeCheckInstruction(im.opcode(), im.type().asSymbol()); cb.with(TypeCheckInstruction.of(im.opcode(), im.type().asSymbol()));
case ArrayLoadInstruction im -> case ArrayLoadInstruction im ->
cb.arrayLoadInstruction(im.typeKind()); cb.arrayLoad(im.typeKind());
case ArrayStoreInstruction im -> case ArrayStoreInstruction im ->
cb.arrayStoreInstruction(im.typeKind()); cb.arrayStore(im.typeKind());
case StackInstruction im -> case StackInstruction im ->
cb.stackInstruction(im.opcode()); cb.with(StackInstruction.of(im.opcode()));
case ConvertInstruction im -> case ConvertInstruction im ->
cb.convertInstruction(im.fromType(), im.toType()); cb.conversion(im.fromType(), im.toType());
case OperatorInstruction im -> case OperatorInstruction im ->
cb.operatorInstruction(im.opcode()); cb.with(OperatorInstruction.of(im.opcode()));
case ConstantInstruction im -> case ConstantInstruction im ->
cb.constantInstruction(im.opcode(), im.constantValue()); cb.loadConstant(im.opcode(), im.constantValue());
case MonitorInstruction im -> case MonitorInstruction im ->
cb.monitorInstruction(im.opcode()); cb.with(MonitorInstruction.of(im.opcode()));
case NopInstruction im -> case NopInstruction im ->
cb.nopInstruction(); cb.nop();
case LabelTarget im -> case LabelTarget im ->
cb.labelBinding(im.label()); cb.labelBinding(im.label());
case ExceptionCatch im -> case ExceptionCatch im ->

View File

@ -271,7 +271,7 @@ class RebuildingTransformation {
case ConstantInstruction i -> { case ConstantInstruction i -> {
if (i.constantValue() == null) if (i.constantValue() == null)
if (pathSwitch.nextBoolean()) cob.aconst_null(); if (pathSwitch.nextBoolean()) cob.aconst_null();
else cob.constantInstruction(null); else cob.loadConstant(null);
else switch (i.constantValue()) { else switch (i.constantValue()) {
case Integer iVal -> { case Integer iVal -> {
if (iVal == 1 && pathSwitch.nextBoolean()) cob.iconst_1(); if (iVal == 1 && pathSwitch.nextBoolean()) cob.iconst_1();
@ -282,25 +282,25 @@ class RebuildingTransformation {
else if (iVal == -1 && pathSwitch.nextBoolean()) cob.iconst_m1(); else if (iVal == -1 && pathSwitch.nextBoolean()) cob.iconst_m1();
else if (iVal >= -128 && iVal <= 127 && pathSwitch.nextBoolean()) cob.bipush(iVal); else if (iVal >= -128 && iVal <= 127 && pathSwitch.nextBoolean()) cob.bipush(iVal);
else if (iVal >= -32768 && iVal <= 32767 && pathSwitch.nextBoolean()) cob.sipush(iVal); else if (iVal >= -32768 && iVal <= 32767 && pathSwitch.nextBoolean()) cob.sipush(iVal);
else cob.constantInstruction(iVal); else cob.loadConstant(iVal);
} }
case Long lVal -> { case Long lVal -> {
if (lVal == 0 && pathSwitch.nextBoolean()) cob.lconst_0(); if (lVal == 0 && pathSwitch.nextBoolean()) cob.lconst_0();
else if (lVal == 1 && pathSwitch.nextBoolean()) cob.lconst_1(); else if (lVal == 1 && pathSwitch.nextBoolean()) cob.lconst_1();
else cob.constantInstruction(lVal); else cob.loadConstant(lVal);
} }
case Float fVal -> { case Float fVal -> {
if (fVal == 0.0 && pathSwitch.nextBoolean()) cob.fconst_0(); if (fVal == 0.0 && pathSwitch.nextBoolean()) cob.fconst_0();
else if (fVal == 1.0 && pathSwitch.nextBoolean()) cob.fconst_1(); else if (fVal == 1.0 && pathSwitch.nextBoolean()) cob.fconst_1();
else if (fVal == 2.0 && pathSwitch.nextBoolean()) cob.fconst_2(); else if (fVal == 2.0 && pathSwitch.nextBoolean()) cob.fconst_2();
else cob.constantInstruction(fVal); else cob.loadConstant(fVal);
} }
case Double dVal -> { case Double dVal -> {
if (dVal == 0.0d && pathSwitch.nextBoolean()) cob.dconst_0(); if (dVal == 0.0d && pathSwitch.nextBoolean()) cob.dconst_0();
else if (dVal == 1.0d && pathSwitch.nextBoolean()) cob.dconst_1(); else if (dVal == 1.0d && pathSwitch.nextBoolean()) cob.dconst_1();
else cob.constantInstruction(dVal); else cob.loadConstant(dVal);
} }
default -> cob.constantInstruction(i.constantValue()); default -> cob.loadConstant(i.constantValue());
} }
} }
case ConvertInstruction i -> { case ConvertInstruction i -> {
@ -549,13 +549,13 @@ class RebuildingTransformation {
if (pathSwitch.nextBoolean()) { if (pathSwitch.nextBoolean()) {
switch (i.opcode()) { switch (i.opcode()) {
case CHECKCAST -> cob.checkcast(i.type().asSymbol()); case CHECKCAST -> cob.checkcast(i.type().asSymbol());
case INSTANCEOF -> cob.instanceof_(i.type().asSymbol()); case INSTANCEOF -> cob.instanceOf(i.type().asSymbol());
default -> throw new AssertionError("Should not reach here"); default -> throw new AssertionError("Should not reach here");
} }
} else { } else {
switch (i.opcode()) { switch (i.opcode()) {
case CHECKCAST -> cob.checkcast(i.type()); case CHECKCAST -> cob.checkcast(i.type());
case INSTANCEOF -> cob.instanceof_(i.type()); case INSTANCEOF -> cob.instanceOf(i.type());
default -> throw new AssertionError("Should not reach here"); default -> throw new AssertionError("Should not reach here");
} }
} }

View File

@ -217,7 +217,7 @@ public class Transforms {
cb.transformMethod(mm, (mb, me) -> { cb.transformMethod(mm, (mb, me) -> {
if (me instanceof CodeModel xm) { if (me instanceof CodeModel xm) {
mb.withCode(xb -> { mb.withCode(xb -> {
xb.nopInstruction(); xb.nop();
xm.forEachElement(new Consumer<>() { xm.forEachElement(new Consumer<>() {
@Override @Override
public void accept(CodeElement e) { public void accept(CodeElement e) {

View File

@ -43,7 +43,7 @@ public class ClassToInterfaceConverter implements ClassFilePreprocessor {
CodeTransform ct = (b, e) -> { CodeTransform ct = (b, e) -> {
if (e instanceof InvokeInstruction i && i.owner() == classModel.thisClass()) { if (e instanceof InvokeInstruction i && i.owner() == classModel.thisClass()) {
Opcode opcode = i.opcode() == Opcode.INVOKEVIRTUAL ? Opcode.INVOKEINTERFACE : i.opcode(); Opcode opcode = i.opcode() == Opcode.INVOKEVIRTUAL ? Opcode.INVOKEINTERFACE : i.opcode();
b.invokeInstruction(opcode, i.owner().asSymbol(), b.invoke(opcode, i.owner().asSymbol(),
i.name().stringValue(), i.typeSymbol(), true); i.name().stringValue(), i.typeSymbol(), true);
} else { } else {
b.with(e); b.with(e);

View File

@ -76,7 +76,7 @@ public class LazyStaticColdStart {
static final byte[] classBytes = ClassFile.of().build(describedClass, clb -> { static final byte[] classBytes = ClassFile.of().build(describedClass, clb -> {
clb.withField("v", CD_long, ACC_STATIC); clb.withField("v", CD_long, ACC_STATIC);
clb.withMethodBody(CLASS_INIT_NAME, MTD_void, ACC_STATIC, cob -> { clb.withMethodBody(CLASS_INIT_NAME, MTD_void, ACC_STATIC, cob -> {
cob.constantInstruction(100L); cob.loadConstant(100L);
cob.invokestatic(CD_Blackhole, "consumeCPU", MTD_void_long); cob.invokestatic(CD_Blackhole, "consumeCPU", MTD_void_long);
cob.invokestatic(CD_ThreadLocalRandom, "current", MTD_ThreadLocalRandom); cob.invokestatic(CD_ThreadLocalRandom, "current", MTD_ThreadLocalRandom);
cob.invokevirtual(CD_ThreadLocalRandom, "nextLong", MTD_long); cob.invokevirtual(CD_ThreadLocalRandom, "nextLong", MTD_long);

View File

@ -91,11 +91,11 @@ public class RebuildMethodBodies {
cc.transform(clm, ClassTransform.transformingMethodBodies((cob, coe) -> { cc.transform(clm, ClassTransform.transformingMethodBodies((cob, coe) -> {
switch (coe) { switch (coe) {
case FieldInstruction i -> case FieldInstruction i ->
cob.fieldInstruction(i.opcode(), i.owner().asSymbol(), i.name().stringValue(), i.typeSymbol()); cob.fieldAccess(i.opcode(), i.owner().asSymbol(), i.name().stringValue(), i.typeSymbol());
case InvokeDynamicInstruction i -> case InvokeDynamicInstruction i ->
cob.invokedynamic(i.invokedynamic().asSymbol()); cob.invokedynamic(i.invokedynamic().asSymbol());
case InvokeInstruction i -> case InvokeInstruction i ->
cob.invokeInstruction(i.opcode(), i.owner().asSymbol(), i.name().stringValue(), i.typeSymbol(), i.isInterface()); cob.invoke(i.opcode(), i.owner().asSymbol(), i.name().stringValue(), i.typeSymbol(), i.isInterface());
case NewMultiArrayInstruction i -> case NewMultiArrayInstruction i ->
cob.multianewarray(i.arrayType().asSymbol(), i.dimensions()); cob.multianewarray(i.arrayType().asSymbol(), i.dimensions());
case NewObjectInstruction i -> case NewObjectInstruction i ->
@ -103,7 +103,7 @@ public class RebuildMethodBodies {
case NewReferenceArrayInstruction i -> case NewReferenceArrayInstruction i ->
cob.anewarray(i.componentType().asSymbol()); cob.anewarray(i.componentType().asSymbol());
case TypeCheckInstruction i -> case TypeCheckInstruction i ->
cob.typeCheckInstruction(i.opcode(), i.type().asSymbol()); cob.with(TypeCheckInstruction.of(i.opcode(), i.type().asSymbol()));
default -> cob.with(coe); default -> cob.with(coe);
} }
})); }));

View File

@ -203,7 +203,7 @@ public class Transforms {
cb.transformMethod(mm, (mb, me) -> { cb.transformMethod(mm, (mb, me) -> {
if (me instanceof CodeModel xm) { if (me instanceof CodeModel xm) {
mb.withCode(xb -> { mb.withCode(xb -> {
xb.nopInstruction(); xb.nop();
xm.forEachElement(new Consumer<>() { xm.forEachElement(new Consumer<>() {
@Override @Override
public void accept(CodeElement e) { public void accept(CodeElement e) {

View File

@ -141,9 +141,9 @@ public class Write {
cb.withVersion(52, 0); cb.withVersion(52, 0);
cb.with(SourceFileAttribute.of(cb.constantPool().utf8Entry(("MyClass.java")))) cb.with(SourceFileAttribute.of(cb.constantPool().utf8Entry(("MyClass.java"))))
.withMethod(INIT_NAME, MTD_void, 0, mb -> mb .withMethod(INIT_NAME, MTD_void, 0, mb -> mb
.withCode(codeb -> codeb.loadInstruction(TypeKind.ReferenceType, 0) .withCode(codeb -> codeb.loadLocal(TypeKind.ReferenceType, 0)
.invokeInstruction(INVOKESPECIAL, CD_Object, INIT_NAME, MTD_void, false) .invoke(INVOKESPECIAL, CD_Object, INIT_NAME, MTD_void, false)
.returnInstruction(VoidType) .return_(VoidType)
) )
); );
for (int xi = 0; xi < 40; ++xi) { for (int xi = 0; xi < 40; ++xi) {
@ -154,25 +154,25 @@ public class Write {
java.lang.classfile.Label loopEnd = c0.newLabel(); java.lang.classfile.Label loopEnd = c0.newLabel();
int vFac = 1; int vFac = 1;
int vI = 2; int vI = 2;
c0.constantInstruction(ICONST_1, 1) // 0 c0.iconst_1() // 0
.storeInstruction(IntType, vFac) // 1 .istore(vFac) // 1
.constantInstruction(ICONST_1, 1) // 2 .iconst_1() // 2
.storeInstruction(IntType, vI) // 3 .istore(vI) // 3
.labelBinding(loopTop) .labelBinding(loopTop)
.loadInstruction(IntType, vI) // 4 .iload(vI) // 4
.constantInstruction(BIPUSH, 10) // 5 .bipush(10) // 5
.branchInstruction(IF_ICMPGE, loopEnd) // 6 .if_icmpge(loopEnd) // 6
.loadInstruction(IntType, vFac) // 7 .iload(vFac) // 7
.loadInstruction(IntType, vI) // 8 .iload(vI) // 8
.operatorInstruction(IMUL) // 9 .imul() // 9
.storeInstruction(IntType, vFac) // 10 .istore(vFac) // 10
.incrementInstruction(vI, 1) // 11 .iinc(vI, 1) // 11
.branchInstruction(GOTO, loopTop) // 12 .goto_(loopTop) // 12
.labelBinding(loopEnd) .labelBinding(loopEnd)
.fieldInstruction(GETSTATIC, CD_System, "out", CD_PrintStream) // 13 .getstatic(CD_System, "out", CD_PrintStream) // 13
.loadInstruction(IntType, vFac) .iload(vFac)
.invokeInstruction(INVOKEVIRTUAL, CD_PrintStream, "println", MTD_void_int, false) // 15 .invokevirtual(CD_PrintStream, "println", MTD_void_int) // 15
.returnInstruction(VoidType); .return_();
})); }));
} }
}); });
@ -189,9 +189,9 @@ public class Write {
cb.withVersion(52, 0); cb.withVersion(52, 0);
cb.with(SourceFileAttribute.of(cb.constantPool().utf8Entry(("MyClass.java")))) cb.with(SourceFileAttribute.of(cb.constantPool().utf8Entry(("MyClass.java"))))
.withMethod(INIT_NAME, MTD_void, 0, .withMethod(INIT_NAME, MTD_void, 0,
mb -> mb.withCode(codeb -> codeb.loadInstruction(ReferenceType, 0) mb -> mb.withCode(codeb -> codeb.loadLocal(ReferenceType, 0)
.invokeInstruction(INVOKESPECIAL, CD_Object, INIT_NAME, MTD_void, false) .invokespecial(CD_Object, INIT_NAME, MTD_void, false)
.returnInstruction(VoidType) .return_()
) )
); );
for (int xi = 0; xi < 40; ++xi) { for (int xi = 0; xi < 40; ++xi) {
@ -202,25 +202,25 @@ public class Write {
java.lang.classfile.Label loopEnd = c0.newLabel(); java.lang.classfile.Label loopEnd = c0.newLabel();
int vFac = 1; int vFac = 1;
int vI = 2; int vI = 2;
c0.constantInstruction(ICONST_1, 1) // 0 c0.iconst_1() // 0
.storeInstruction(IntType, 1) // 1 .istore(1) // 1
.constantInstruction(ICONST_1, 1) // 2 .iconst_1() // 2
.storeInstruction(IntType, 2) // 3 .istore(2) // 3
.labelBinding(loopTop) .labelBinding(loopTop)
.loadInstruction(IntType, 2) // 4 .iload(2) // 4
.constantInstruction(BIPUSH, 10) // 5 .bipush(10) // 5
.branchInstruction(IF_ICMPGE, loopEnd) // 6 .if_icmpge(loopEnd) // 6
.loadInstruction(IntType, 1) // 7 .iload(1) // 7
.loadInstruction(IntType, 2) // 8 .iload(2) // 8
.operatorInstruction(IMUL) // 9 .imul() // 9
.storeInstruction(IntType, 1) // 10 .istore(1) // 10
.incrementInstruction(2, 1) // 11 .iinc(2, 1) // 11
.branchInstruction(GOTO, loopTop) // 12 .goto_(loopTop) // 12
.labelBinding(loopEnd) .labelBinding(loopEnd)
.fieldInstruction(GETSTATIC, CD_System, "out", CD_PrintStream) // 13 .getstatic(CD_System, "out", CD_PrintStream) // 13
.loadInstruction(IntType, 1) .iload(1)
.invokeInstruction(INVOKEVIRTUAL, CD_PrintStream, "println", MTD_void_int, false) // 15 .invokevirtual(CD_PrintStream, "println", MTD_void_int) // 15
.returnInstruction(VoidType); .return_();
})); }));
} }
}); });