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
* java.lang.classfile.CodeBuilder#invokevirtual(java.lang.constant.ClassDesc,
* 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,
* boolean) CodeBuilder.invokeInstruction}, or {@link
* java.lang.classfile.CodeBuilder#with(java.lang.classfile.ClassFileElement)

View File

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

View File

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

View File

@ -1124,7 +1124,7 @@ public final class StringConcatFactory {
}
}
len += args.parameterCount() * ARGUMENT_SIZE_FACTOR;
cb.constantInstruction(len);
cb.loadConstant(len);
cb.invokespecial(STRING_BUILDER, "<init>", INT_CONSTRUCTOR_TYPE);
// 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);
TypeKind kind = TypeKind.from(cl);
cb.loadInstruction(kind, off);
cb.loadLocal(kind, off);
off += kind.slotSize();
MethodTypeDesc desc = getSBAppendDesc(cl);
cb.invokevirtual(STRING_BUILDER, "append", desc);

View File

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

View File

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

View File

@ -62,7 +62,7 @@ public final class CatchBuilderImpl implements CodeBuilder.CatchBuilder {
if (catchBlock == null) {
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) {
catchBlock.end();
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) -> {
switch (coe) {
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()));
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.isInterface());
case InvokeDynamicInstruction idi ->
cob.invokeDynamicInstruction(DynamicCallSiteDesc.of(
cob.invokedynamic(DynamicCallSiteDesc.of(
idi.bootstrapMethod(), idi.name().stringValue(),
mapMethodDesc(idi.typeSymbol()),
idi.bootstrapArgs().stream().map(this::mapConstantValue).toArray(ConstantDesc[]::new)));
case NewObjectInstruction c ->
cob.newObjectInstruction(map(c.className().asSymbol()));
cob.new_(map(c.className().asSymbol()));
case NewReferenceArrayInstruction c ->
cob.anewarray(map(c.componentType().asSymbol()));
case NewMultiArrayInstruction c ->
cob.multianewarray(map(c.arrayType().asSymbol()), c.dimensions());
case TypeCheckInstruction c ->
cob.typeCheckInstruction(c.opcode(), map(c.type().asSymbol()));
cob.with(TypeCheckInstruction.of(c.opcode(), map(c.type().asSymbol())));
case ExceptionCatch c ->
cob.exceptionCatch(c.tryStart(), c.tryEnd(), c.handler(),c.catchType()
.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(),
mapSignature(c.signatureSymbol()), c.startScope(), c.endScope());
case LoadConstantInstruction ldc ->
cob.constantInstruction(ldc.opcode(),
cob.loadConstant(ldc.opcode(),
mapConstantValue(ldc.constantValue()));
case RuntimeVisibleTypeAnnotationsAttribute aa ->
cob.with(RuntimeVisibleTypeAnnotationsAttribute.of(

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -245,7 +245,7 @@ public class ProhibitedMethods {
var cf = ClassFile.of();
return cf.transform(cf.parse(classBytes), ClassTransform.endHandler(clb -> {
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",
MethodTypeDesc.of(CD_void, CD_String));
cob.return_();

View File

@ -270,13 +270,13 @@ public class SerialPersistentFieldsTest {
cob.bipush(i);
cob.new_(CD_ObjectStreamField);
cob.dup();
cob.constantInstruction(osf.getName());
cob.loadConstant(osf.getName());
if (osf.isPrimitive()) {
cob.constantInstruction(DynamicConstantDesc.ofNamed(
cob.loadConstant(DynamicConstantDesc.ofNamed(
ConstantDescs.BSM_PRIMITIVE_CLASS, String.valueOf(osf.getTypeCode()), CD_Class));
} else {
// 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.aastore();

View File

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

View File

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

View File

@ -122,13 +122,13 @@ public class Instrumentor {
// load method parameters
for (int i = 0; i < mt.parameterCount(); i++) {
TypeKind kind = TypeKind.from(mt.parameterType(i));
cb.loadInstruction(kind, ptr);
cb.loadLocal(kind, ptr);
ptr += kind.slotSize();
}
cb.invokeInstruction(isStatic ? Opcode.INVOKESTATIC : Opcode.INVOKESPECIAL,
cb.invoke(isStatic ? Opcode.INVOKESTATIC : Opcode.INVOKESPECIAL,
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>
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.return_();
});

View File

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

View File

@ -62,7 +62,7 @@ public class InstructionHelper {
ClassFile.ACC_PUBLIC + ClassFile.ACC_STATIC, methodBuilder -> methodBuilder
.withCode(codeBuilder -> {
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(
MethodHandleDesc.ofMethod(
@ -74,7 +74,7 @@ public class InstructionHelper {
name,
MethodTypeDesc.ofDescriptor(type.toMethodDescriptorString()),
boostrapArgs));
codeBuilder.returnInstruction(TypeKind.from(type.returnType()));
codeBuilder.return_(TypeKind.from(type.returnType()));
}));
});
Class<?> gc = l.defineClass(byteArray);
@ -116,7 +116,7 @@ public class InstructionHelper {
name,
ClassDesc.ofDescriptor(type),
bootstrapArgs))
.returnInstruction(TypeKind.fromDescriptor(type))));
.return_(TypeKind.fromDescriptor(type))));
});
Class<?> gc = l.defineClass(bytes);
return l.findStatic(gc, "m", fromMethodDescriptorString(methodType, l.lookupClass().getClassLoader()));

View File

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

View File

@ -164,7 +164,7 @@ public class SpecialStatic {
});
clb.withMethodBody("getMethodHandle", MethodTypeDesc.of(CD_MethodHandle),
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();
});
clb.withMethodBody("getLookup", MTD_Lookup,

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -107,7 +107,7 @@ public class OpcodesValidationTest {
cb -> cb.withFlags(AccessFlag.PUBLIC)
.withMethod("<init>", MethodTypeDesc.of(CD_void), 0,
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)
.withMethod("<init>", MethodTypeDesc.of(CD_void), 0,
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_();
});
clb.withMethodBody("get", MethodTypeDesc.of(CD_Object), ACC_PUBLIC, cob -> {
cob.constantInstruction(CD_int);
cob.loadConstant(CD_int);
cob.areturn();
});
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
cob.with(ConstantInstruction.ofIntrinsic(sample.expected[i]));
var target = cob.newLabel();
cob.branchInstruction(sample.jumpCode, target);
cob.branch(sample.jumpCode, target);
for (int i = overflow ? 40000 : 1; i > 0; i--)
cob.nopInstruction();
cob.nop();
cob.labelBinding(target);
cob.return_();
}))));
@ -228,12 +228,12 @@ class ShortJumpsFixTest {
cob.goto_w(fwd);
cob.labelBinding(target);
for (int i = overflow ? 40000 : 1; i > 0; i--)
cob.nopInstruction();
cob.nop();
cob.return_();
cob.labelBinding(fwd);
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.branchInstruction(sample.jumpCode, target);
cob.branch(sample.jumpCode, target);
cob.return_();
}))));
}
@ -244,7 +244,7 @@ class ShortJumpsFixTest {
(cob, coe) -> {
if (coe instanceof NopInstruction)
for (int i = 0; i < 40000; i++) //cause label overflow during transform
cob.nopInstruction();
cob.nop();
cob.with(coe);
}));
}

View File

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

View File

@ -58,7 +58,7 @@ class StackTrackerTest {
assertIterableEquals(stackTracker.stack().get(), List.of(IntType, LongType, ReferenceType, DoubleType, FloatType));
tryb.ifThen(thb -> {
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));
thb.athrow();
assertFalse(stackTracker.stack().isPresent());
@ -91,7 +91,7 @@ class StackTrackerTest {
var l2 = stcb.newBoundLabel(); //back jump target
assertFalse(stackTracker.stack().isPresent()); //no stack
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.maxStackSize().isPresent()); //because tracking lost
stcb.athrow();

View File

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

View File

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

View File

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

View File

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

View File

@ -251,7 +251,7 @@ public class ExampleGallery {
@Override
public void accept(CodeBuilder codeB, CodeElement codeE) {
if (found) {
codeB.nopInstruction();
codeB.nop();
found = false;
}
codeB.with(codeE);
@ -265,7 +265,7 @@ public class ExampleGallery {
return ClassFile.of().transform(cm, ClassTransform.transformingMethodBodies((codeB, codeE) -> {
switch (codeE) {
case InvokeInstruction i -> {
codeB.nopInstruction();
codeB.nop();
codeB.with(codeE);
}
default -> codeB.with(codeE);
@ -277,7 +277,7 @@ public class ExampleGallery {
return ClassFile.of().transform(cm, ClassTransform.transformingMethodBodies((codeB, codeE) -> {
switch (codeE) {
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);
}
default -> codeB.with(codeE);

View File

@ -35,53 +35,53 @@ public class InstructionModelToCodeBuilder {
public static void toBuilder(CodeElement model, CodeBuilder cb) {
switch (model) {
case LoadInstruction im ->
cb.loadInstruction(im.typeKind(), im.slot());
cb.loadLocal(im.typeKind(), im.slot());
case StoreInstruction im ->
cb.storeInstruction(im.typeKind(), im.slot());
cb.storeLocal(im.typeKind(), im.slot());
case IncrementInstruction im ->
cb.incrementInstruction(im.slot(), im.constant());
cb.iinc(im.slot(), im.constant());
case BranchInstruction im ->
cb.branchInstruction(im.opcode(), im.target());
cb.branch(im.opcode(), im.target());
case LookupSwitchInstruction im ->
cb.lookupSwitchInstruction(im.defaultTarget(), im.cases());
cb.lookupswitch(im.defaultTarget(), im.cases());
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 ->
cb.returnInstruction(im.typeKind());
cb.return_(im.typeKind());
case ThrowInstruction im ->
cb.throwInstruction();
cb.athrow();
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 ->
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 ->
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 ->
cb.newObjectInstruction(im.className().asSymbol());
cb.new_(im.className().asSymbol());
case NewPrimitiveArrayInstruction im ->
cb.newPrimitiveArrayInstruction(im.typeKind());
cb.newarray(im.typeKind());
case NewReferenceArrayInstruction im ->
cb.newReferenceArrayInstruction(im.componentType());
cb.anewarray(im.componentType());
case NewMultiArrayInstruction im ->
cb.newMultidimensionalArrayInstruction(im.dimensions(), im.arrayType());
cb.multianewarray(im.arrayType(), im.dimensions());
case TypeCheckInstruction im ->
cb.typeCheckInstruction(im.opcode(), im.type().asSymbol());
cb.with(TypeCheckInstruction.of(im.opcode(), im.type().asSymbol()));
case ArrayLoadInstruction im ->
cb.arrayLoadInstruction(im.typeKind());
cb.arrayLoad(im.typeKind());
case ArrayStoreInstruction im ->
cb.arrayStoreInstruction(im.typeKind());
cb.arrayStore(im.typeKind());
case StackInstruction im ->
cb.stackInstruction(im.opcode());
cb.with(StackInstruction.of(im.opcode()));
case ConvertInstruction im ->
cb.convertInstruction(im.fromType(), im.toType());
cb.conversion(im.fromType(), im.toType());
case OperatorInstruction im ->
cb.operatorInstruction(im.opcode());
cb.with(OperatorInstruction.of(im.opcode()));
case ConstantInstruction im ->
cb.constantInstruction(im.opcode(), im.constantValue());
cb.loadConstant(im.opcode(), im.constantValue());
case MonitorInstruction im ->
cb.monitorInstruction(im.opcode());
cb.with(MonitorInstruction.of(im.opcode()));
case NopInstruction im ->
cb.nopInstruction();
cb.nop();
case LabelTarget im ->
cb.labelBinding(im.label());
case ExceptionCatch im ->

View File

@ -271,7 +271,7 @@ class RebuildingTransformation {
case ConstantInstruction i -> {
if (i.constantValue() == null)
if (pathSwitch.nextBoolean()) cob.aconst_null();
else cob.constantInstruction(null);
else cob.loadConstant(null);
else switch (i.constantValue()) {
case Integer iVal -> {
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 >= -128 && iVal <= 127 && pathSwitch.nextBoolean()) cob.bipush(iVal);
else if (iVal >= -32768 && iVal <= 32767 && pathSwitch.nextBoolean()) cob.sipush(iVal);
else cob.constantInstruction(iVal);
else cob.loadConstant(iVal);
}
case Long lVal -> {
if (lVal == 0 && pathSwitch.nextBoolean()) cob.lconst_0();
else if (lVal == 1 && pathSwitch.nextBoolean()) cob.lconst_1();
else cob.constantInstruction(lVal);
else cob.loadConstant(lVal);
}
case Float fVal -> {
if (fVal == 0.0 && pathSwitch.nextBoolean()) cob.fconst_0();
else if (fVal == 1.0 && pathSwitch.nextBoolean()) cob.fconst_1();
else if (fVal == 2.0 && pathSwitch.nextBoolean()) cob.fconst_2();
else cob.constantInstruction(fVal);
else cob.loadConstant(fVal);
}
case Double dVal -> {
if (dVal == 0.0d && pathSwitch.nextBoolean()) cob.dconst_0();
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 -> {
@ -549,13 +549,13 @@ class RebuildingTransformation {
if (pathSwitch.nextBoolean()) {
switch (i.opcode()) {
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");
}
} else {
switch (i.opcode()) {
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");
}
}

View File

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

View File

@ -43,7 +43,7 @@ public class ClassToInterfaceConverter implements ClassFilePreprocessor {
CodeTransform ct = (b, e) -> {
if (e instanceof InvokeInstruction i && i.owner() == classModel.thisClass()) {
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);
} else {
b.with(e);

View File

@ -76,7 +76,7 @@ public class LazyStaticColdStart {
static final byte[] classBytes = ClassFile.of().build(describedClass, clb -> {
clb.withField("v", CD_long, ACC_STATIC);
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_ThreadLocalRandom, "current", MTD_ThreadLocalRandom);
cob.invokevirtual(CD_ThreadLocalRandom, "nextLong", MTD_long);

View File

@ -91,11 +91,11 @@ public class RebuildMethodBodies {
cc.transform(clm, ClassTransform.transformingMethodBodies((cob, coe) -> {
switch (coe) {
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 ->
cob.invokedynamic(i.invokedynamic().asSymbol());
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 ->
cob.multianewarray(i.arrayType().asSymbol(), i.dimensions());
case NewObjectInstruction i ->
@ -103,7 +103,7 @@ public class RebuildMethodBodies {
case NewReferenceArrayInstruction i ->
cob.anewarray(i.componentType().asSymbol());
case TypeCheckInstruction i ->
cob.typeCheckInstruction(i.opcode(), i.type().asSymbol());
cob.with(TypeCheckInstruction.of(i.opcode(), i.type().asSymbol()));
default -> cob.with(coe);
}
}));

View File

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

View File

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