From ae82405ff7a48bc6e61b1d05bf74839b7ed50c11 Mon Sep 17 00:00:00 2001 From: Adam Sotona Date: Thu, 2 May 2024 10:08:29 +0000 Subject: [PATCH] 8323058: Revisit j.l.classfile.CodeBuilder API surface Reviewed-by: briangoetz, psandoz --- .../java/lang/classfile/CodeBuilder.java | 707 +++++++----------- .../java/lang/classfile/package-info.java | 2 +- .../snippet-files/PackageSnippets.java | 4 +- .../java/lang/invoke/MethodHandleProxies.java | 12 +- .../java/lang/invoke/StringConcatFactory.java | 4 +- .../java/lang/reflect/ProxyGenerator.java | 14 +- .../java/lang/runtime/SwitchBootstraps.java | 26 +- .../classfile/impl/CatchBuilderImpl.java | 4 +- .../classfile/impl/ClassRemapperImpl.java | 12 +- .../classfile/impl/CodeLocalsShifterImpl.java | 6 +- .../classfile/impl/CodeRelabelerImpl.java | 6 +- .../foreign/abi/BindingSpecializer.java | 130 ++-- .../jfr/internal/EventInstrumentation.java | 14 +- .../internal/plugins/SystemModulesPlugin.java | 122 +-- .../internal/plugins/VersionPropsPlugin.java | 2 +- .../records/ProhibitedMethods.java | 2 +- .../records/SerialPersistentFieldsTest.java | 6 +- .../instrument/NativeMethodPrefixAgent.java | 4 +- .../lang/instrument/RetransformAgent.java | 2 +- .../lang/instrument/asmlib/Instrumentor.java | 6 +- .../WrapperHiddenClassTest.java | 2 +- .../classData/ClassDataTest.java | 12 +- .../lang/invoke/lib/InstructionHelper.java | 6 +- .../lang/invoke/condy/CondyNestedTest.java | 2 +- .../lang/invoke/lookup/SpecialStatic.java | 2 +- .../TestPrivateInterfaceMethodReflect.java | 2 +- test/jdk/jdk/classfile/AdaptCodeTest.java | 2 +- test/jdk/jdk/classfile/BSMTest.java | 2 +- test/jdk/jdk/classfile/BuilderBlockTest.java | 16 +- .../jdk/classfile/BuilderTryCatchTest.java | 44 +- .../DiscontinuedInstructionsTest.java | 4 +- test/jdk/jdk/classfile/LDCTest.java | 22 +- test/jdk/jdk/classfile/LowAdaptTest.java | 18 +- test/jdk/jdk/classfile/LvtTest.java | 58 +- test/jdk/jdk/classfile/OneToOneTest.java | 40 +- .../jdk/classfile/OpcodesValidationTest.java | 4 +- .../classfile/PrimitiveClassConstantTest.java | 2 +- test/jdk/jdk/classfile/ShortJumpsFixTest.java | 10 +- test/jdk/jdk/classfile/StackMapsTest.java | 8 +- test/jdk/jdk/classfile/StackTrackerTest.java | 4 +- .../TempConstantPoolBuilderTest.java | 6 +- test/jdk/jdk/classfile/TransformTests.java | 2 +- test/jdk/jdk/classfile/Utf8EntryTest.java | 4 +- test/jdk/jdk/classfile/WriteTest.java | 80 +- .../classfile/examples/ExampleGallery.java | 6 +- .../InstructionModelToCodeBuilder.java | 48 +- .../helpers/RebuildingTransformation.java | 16 +- .../jdk/jdk/classfile/helpers/Transforms.java | 2 +- .../separate/ClassToInterfaceConverter.java | 2 +- .../java/lang/invoke/LazyStaticColdStart.java | 2 +- .../jdk/classfile/RebuildMethodBodies.java | 6 +- .../bench/jdk/classfile/Transforms.java | 2 +- .../openjdk/bench/jdk/classfile/Write.java | 80 +- 53 files changed, 725 insertions(+), 876 deletions(-) diff --git a/src/java.base/share/classes/java/lang/classfile/CodeBuilder.java b/src/java.base/share/classes/java/lang/classfile/CodeBuilder.java index 544d7322c1c..e954be079fa 100644 --- a/src/java.base/share/classes/java/lang/classfile/CodeBuilder.java +++ b/src/java.base/share/classes/java/lang/classfile/CodeBuilder.java @@ -212,8 +212,7 @@ public sealed interface CodeBuilder child.start(); handler.accept(child); child.end(); - labelBinding(breakLabel); - return this; + return labelBinding(breakLabel); } /** @@ -253,12 +252,11 @@ public sealed interface CodeBuilder Label breakLabel = newLabel(); BlockCodeBuilderImpl thenBlock = new BlockCodeBuilderImpl(this, breakLabel); - branchInstruction(BytecodeHelpers.reverseBranchOpcode(opcode), thenBlock.endLabel()); + branch(BytecodeHelpers.reverseBranchOpcode(opcode), thenBlock.endLabel()); thenBlock.start(); thenHandler.accept(thenBlock); thenBlock.end(); - labelBinding(breakLabel); - return this; + return labelBinding(breakLabel); } /** @@ -305,17 +303,16 @@ public sealed interface CodeBuilder Label breakLabel = newLabel(); BlockCodeBuilderImpl thenBlock = new BlockCodeBuilderImpl(this, breakLabel); BlockCodeBuilderImpl elseBlock = new BlockCodeBuilderImpl(this, breakLabel); - branchInstruction(BytecodeHelpers.reverseBranchOpcode(opcode), elseBlock.startLabel()); + branch(BytecodeHelpers.reverseBranchOpcode(opcode), elseBlock.startLabel()); thenBlock.start(); thenHandler.accept(thenBlock); if (thenBlock.reachable()) - thenBlock.branchInstruction(Opcode.GOTO, thenBlock.breakLabel()); + thenBlock.branch(Opcode.GOTO, thenBlock.breakLabel()); thenBlock.end(); elseBlock.start(); elseHandler.accept(elseBlock); elseBlock.end(); - labelBinding(breakLabel); - return this; + return labelBinding(breakLabel); } /** @@ -416,10 +413,10 @@ public sealed interface CodeBuilder * @param tk the load type * @param slot the local variable slot * @return this builder + * @since 23 */ - default CodeBuilder loadInstruction(TypeKind tk, int slot) { - with(LoadInstruction.of(tk, slot)); - return this; + default CodeBuilder loadLocal(TypeKind tk, int slot) { + return with(LoadInstruction.of(tk, slot)); } /** @@ -427,21 +424,10 @@ public sealed interface CodeBuilder * @param tk the store type * @param slot the local variable slot * @return this builder + * @since 23 */ - default CodeBuilder storeInstruction(TypeKind tk, int slot) { - with(StoreInstruction.of(tk, slot)); - return this; - } - - /** - * Generate an instruction to increment a local variable by a constant - * @param slot the local variable slot - * @param val the increment value - * @return this builder - */ - default CodeBuilder incrementInstruction(int slot, int val) { - with(IncrementInstruction.of(slot, val)); - return this; + default CodeBuilder storeLocal(TypeKind tk, int slot) { + return with(StoreInstruction.of(tk, slot)); } /** @@ -450,53 +436,20 @@ public sealed interface CodeBuilder * @param op the branch opcode * @param target the branch target * @return this builder + * @since 23 */ - default CodeBuilder branchInstruction(Opcode op, Label target) { - with(BranchInstruction.of(op, target)); - return this; - } - - /** - * Generate an instruction to access a jump table by key match and jump - * @param defaultTarget the default jump target - * @param cases the switch cases - * @return this builder - */ - default CodeBuilder lookupSwitchInstruction(Label defaultTarget, List cases) { - with(LookupSwitchInstruction.of(defaultTarget, cases)); - return this; - } - - /** - * Generate an instruction to access a jump table by index and jump - * @param lowValue the low key value - * @param highValue the high key value - * @param defaultTarget the default jump target - * @param cases the switch cases - * @return this builder - */ - default CodeBuilder tableSwitchInstruction(int lowValue, int highValue, Label defaultTarget, List cases) { - with(TableSwitchInstruction.of(lowValue, highValue, defaultTarget, cases)); - return this; + default CodeBuilder branch(Opcode op, Label target) { + return with(BranchInstruction.of(op, target)); } /** * Generate return instruction * @param tk the return type * @return this builder + * @since 23 */ - default CodeBuilder returnInstruction(TypeKind tk) { - with(ReturnInstruction.of(tk)); - return this; - } - - /** - * Generate an instruction to throw an exception or error - * @return this builder - */ - default CodeBuilder throwInstruction() { - with(ThrowInstruction.of()); - return this; + default CodeBuilder return_(TypeKind tk) { + return with(ReturnInstruction.of(tk)); } /** @@ -505,10 +458,10 @@ public sealed interface CodeBuilder * @param opcode the field access opcode * @param ref the field reference * @return this builder + * @since 23 */ - default CodeBuilder fieldInstruction(Opcode opcode, FieldRefEntry ref) { - with(FieldInstruction.of(opcode, ref)); - return this; + default CodeBuilder fieldAccess(Opcode opcode, FieldRefEntry ref) { + return with(FieldInstruction.of(opcode, ref)); } /** @@ -519,9 +472,10 @@ public sealed interface CodeBuilder * @param name the field name * @param type the field type * @return this builder + * @since 23 */ - default CodeBuilder fieldInstruction(Opcode opcode, ClassDesc owner, String name, ClassDesc type) { - return fieldInstruction(opcode, constantPool().fieldRefEntry(owner, name, type)); + default CodeBuilder fieldAccess(Opcode opcode, ClassDesc owner, String name, ClassDesc type) { + return fieldAccess(opcode, constantPool().fieldRefEntry(owner, name, type)); } /** @@ -530,8 +484,9 @@ public sealed interface CodeBuilder * @param opcode the invoke opcode * @param ref the interface method or method reference * @return this builder + * @since 23 */ - default CodeBuilder invokeInstruction(Opcode opcode, MemberRefEntry ref) { + default CodeBuilder invoke(Opcode opcode, MemberRefEntry ref) { return with(InvokeInstruction.of(opcode, ref)); } @@ -544,191 +499,101 @@ public sealed interface CodeBuilder * @param desc the method type * @param isInterface the interface method invocation indication * @return this builder + * @since 23 */ - default CodeBuilder invokeInstruction(Opcode opcode, ClassDesc owner, String name, MethodTypeDesc desc, boolean isInterface) { - return invokeInstruction(opcode, + default CodeBuilder invoke(Opcode opcode, ClassDesc owner, String name, MethodTypeDesc desc, boolean isInterface) { + return invoke(opcode, isInterface ? constantPool().interfaceMethodRefEntry(owner, name, desc) : constantPool().methodRefEntry(owner, name, desc)); } - /** - * Generate an instruction to invoke a dynamically-computed call site - * @param ref the dynamic call site - * @return this builder - */ - default CodeBuilder invokeDynamicInstruction(InvokeDynamicEntry ref) { - with(InvokeDynamicInstruction.of(ref)); - return this; - } - - /** - * Generate an instruction to invoke a dynamically-computed call site - * @param desc the dynamic call site - * @return this builder - */ - default CodeBuilder invokeDynamicInstruction(DynamicCallSiteDesc desc) { - MethodHandleEntry bsMethod = handleDescToHandleInfo(constantPool(), (DirectMethodHandleDesc) desc.bootstrapMethod()); - var cpArgs = desc.bootstrapArgs(); - List bsArguments = new ArrayList<>(cpArgs.length); - for (var constantValue : cpArgs) { - bsArguments.add(BytecodeHelpers.constantEntry(constantPool(), constantValue)); - } - BootstrapMethodEntry bm = constantPool().bsmEntry(bsMethod, bsArguments); - NameAndTypeEntry nameAndType = constantPool().nameAndTypeEntry(desc.invocationName(), desc.invocationType()); - invokeDynamicInstruction(constantPool().invokeDynamicEntry(bm, nameAndType)); - return this; - } - - /** - * Generate an instruction to create a new object - * @param type the object type - * @return this builder - */ - default CodeBuilder newObjectInstruction(ClassEntry type) { - with(NewObjectInstruction.of(type)); - return this; - } - - /** - * Generate an instruction to create a new object - * @param type the object type - * @return this builder - * @throws IllegalArgumentException if {@code type} represents a primitive type - */ - default CodeBuilder newObjectInstruction(ClassDesc type) { - return newObjectInstruction(constantPool().classEntry(type)); - } - - /** - * Generate an instruction to create a new array of a primitive type - * @param typeKind the primitive component type - * @return this builder - */ - default CodeBuilder newPrimitiveArrayInstruction(TypeKind typeKind) { - with(NewPrimitiveArrayInstruction.of(typeKind)); - return this; - } - - /** - * Generate an instruction to create a new array of reference - * @param type the component type - * @return this builder - */ - default CodeBuilder newReferenceArrayInstruction(ClassEntry type) { - with(NewReferenceArrayInstruction.of(type)); - return this; - } - - /** - * Generate an instruction to create a new array of reference - * @param type the component type - * @return this builder - * @throws IllegalArgumentException if {@code type} represents a primitive type - */ - default CodeBuilder newReferenceArrayInstruction(ClassDesc type) { - return newReferenceArrayInstruction(constantPool().classEntry(type)); - } - - /** - * Generate an instruction to create a new multidimensional array - * @param dimensions the number of dimensions - * @param type the array type - * @return this builder - */ - default CodeBuilder newMultidimensionalArrayInstruction(int dimensions, - ClassEntry type) { - with(NewMultiArrayInstruction.of(type, dimensions)); - return this; - } - - /** - * Generate an instruction to create a new multidimensional array - * @param dimensions the number of dimensions - * @param type the array type - * @return this builder - */ - default CodeBuilder newMultidimensionalArrayInstruction(int dimensions, - ClassDesc type) { - return newMultidimensionalArrayInstruction(dimensions, constantPool().classEntry(type)); - } - /** * Generate an instruction to load from an array * @param tk the array element type * @return this builder + * @since 23 */ - default CodeBuilder arrayLoadInstruction(TypeKind tk) { + default CodeBuilder arrayLoad(TypeKind tk) { Opcode opcode = BytecodeHelpers.arrayLoadOpcode(tk); - with(ArrayLoadInstruction.of(opcode)); - return this; + return with(ArrayLoadInstruction.of(opcode)); } /** * Generate an instruction to store into an array * @param tk the array element type * @return this builder + * @since 23 */ - default CodeBuilder arrayStoreInstruction(TypeKind tk) { + default CodeBuilder arrayStore(TypeKind tk) { Opcode opcode = BytecodeHelpers.arrayStoreOpcode(tk); - with(ArrayStoreInstruction.of(opcode)); - return this; + return with(ArrayStoreInstruction.of(opcode)); } /** - * Generate a type checking instruction - * @see Opcode.Kind#TYPE_CHECK - * @param opcode the type check instruction opcode - * @param type the type - * @return this builder - */ - default CodeBuilder typeCheckInstruction(Opcode opcode, - ClassEntry type) { - with(TypeCheckInstruction.of(opcode, type)); - return this; - } - - /** - * Generate a type checking instruction - * @see Opcode.Kind#TYPE_CHECK - * @param opcode the type check instruction opcode - * @param type the type - * @return this builder - */ - default CodeBuilder typeCheckInstruction(Opcode opcode, ClassDesc type) { - return typeCheckInstruction(opcode, constantPool().classEntry(type)); - } - - /** - * Generate a type converting instruction + * Generate instruction(s) to convert {@code fromType} to {@code toType} * @param fromType the source type * @param toType the target type * @return this builder + * @throws IllegalArgumentException for conversions of {@code VoidType} or {@code ReferenceType} + * @since 23 */ - default CodeBuilder convertInstruction(TypeKind fromType, TypeKind toType) { - with(ConvertInstruction.of(fromType, toType)); - return this; - } - - /** - * Generate a stack manipulating instruction - * @param opcode the stack instruction opcode - * @see Opcode.Kind#STACK - * @return this builder - */ - default CodeBuilder stackInstruction(Opcode opcode) { - with(StackInstruction.of(opcode)); - return this; - } - - /** - * Generate an operator instruction - * @see Opcode.Kind#OPERATOR - * @param opcode the operator instruction opcode - * @return this builder - */ - default CodeBuilder operatorInstruction(Opcode opcode) { - with(OperatorInstruction.of(opcode)); - return this; + default CodeBuilder conversion(TypeKind fromType, TypeKind toType) { + return switch (fromType) { + case IntType, ByteType, CharType, ShortType, BooleanType -> + switch (toType) { + case IntType -> this; + case LongType -> i2l(); + case DoubleType -> i2d(); + case FloatType -> i2f(); + case ByteType -> i2b(); + case CharType -> i2c(); + case ShortType -> i2s(); + case BooleanType -> iconst_1().iand(); + case VoidType, ReferenceType -> + throw new IllegalArgumentException(String.format("convert %s -> %s", fromType, toType)); + }; + case LongType -> + switch (toType) { + case IntType -> l2i(); + case LongType -> this; + case DoubleType -> l2d(); + case FloatType -> l2f(); + case ByteType -> l2i().i2b(); + case CharType -> l2i().i2c(); + case ShortType -> l2i().i2s(); + case BooleanType -> l2i().iconst_1().iand(); + case VoidType, ReferenceType -> + throw new IllegalArgumentException(String.format("convert %s -> %s", fromType, toType)); + }; + case DoubleType -> + switch (toType) { + case IntType -> d2i(); + case LongType -> d2l(); + case DoubleType -> this; + case FloatType -> d2f(); + case ByteType -> d2i().i2b(); + case CharType -> d2i().i2c(); + case ShortType -> d2i().i2s(); + case BooleanType -> d2i().iconst_1().iand(); + case VoidType, ReferenceType -> + throw new IllegalArgumentException(String.format("convert %s -> %s", fromType, toType)); + }; + case FloatType -> + switch (toType) { + case IntType -> f2i(); + case LongType -> f2l(); + case DoubleType -> f2d(); + case FloatType -> this; + case ByteType -> f2i().i2b(); + case CharType -> f2i().i2c(); + case ShortType -> f2i().i2s(); + case BooleanType -> f2i().iconst_1().iand(); + case VoidType, ReferenceType -> + throw new IllegalArgumentException(String.format("convert %s -> %s", fromType, toType)); + }; + case VoidType, ReferenceType -> + throw new IllegalArgumentException(String.format("convert %s -> %s", fromType, toType)); + }; } /** @@ -737,8 +602,9 @@ public sealed interface CodeBuilder * @param opcode the constant instruction opcode * @param value the constant value * @return this builder + * @since 23 */ - default CodeBuilder constantInstruction(Opcode opcode, ConstantDesc value) { + default CodeBuilder loadConstant(Opcode opcode, ConstantDesc value) { BytecodeHelpers.validateValue(opcode, value); return with(switch (opcode) { case SIPUSH, BIPUSH -> ConstantInstruction.ofArgument(opcode, ((Number)value).intValue()); @@ -751,8 +617,9 @@ public sealed interface CodeBuilder * Generate an instruction pushing a constant onto the operand stack * @param value the constant value * @return this builder + * @since 23 */ - default CodeBuilder constantInstruction(ConstantDesc value) { + default CodeBuilder loadConstant(ConstantDesc value) { //avoid switch expressions here if (value == null || value == ConstantDescs.NULL) return aconst_null(); @@ -785,32 +652,12 @@ public sealed interface CodeBuilder return ldc(value); } - /** - * Generate a monitor instruction - * @see Opcode.Kind#MONITOR - * @param opcode the monitor instruction opcode - * @return this builder - */ - default CodeBuilder monitorInstruction(Opcode opcode) { - with(MonitorInstruction.of(opcode)); - return null; - } - - /** - * Generate a do nothing instruction - * @return this builder - */ - default CodeBuilder nopInstruction() { - with(NopInstruction.of()); - return this; - } - /** * Generate a do nothing instruction * @return this builder */ default CodeBuilder nop() { - return nopInstruction(); + return with(NopInstruction.of()); } // Base pseudo-instruction builder methods @@ -831,8 +678,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder labelBinding(Label label) { - with((LabelImpl) label); - return this; + return with((LabelImpl) label); } /** @@ -841,8 +687,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder lineNumber(int line) { - with(LineNumber.of(line)); - return this; + return with(LineNumber.of(line)); } /** @@ -854,8 +699,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder exceptionCatch(Label start, Label end, Label handler, ClassEntry catchType) { - with(ExceptionCatch.of(handler, start, end, Optional.of(catchType))); - return this; + return with(ExceptionCatch.of(handler, start, end, Optional.of(catchType))); } /** @@ -867,8 +711,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder exceptionCatch(Label start, Label end, Label handler, Optional catchType) { - with(ExceptionCatch.of(handler, start, end, catchType)); - return this; + return with(ExceptionCatch.of(handler, start, end, catchType)); } /** @@ -892,8 +735,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder exceptionCatchAll(Label start, Label end, Label handler) { - with(ExceptionCatch.of(handler, start, end)); - return this; + return with(ExceptionCatch.of(handler, start, end)); } /** @@ -906,8 +748,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder characterRange(Label startScope, Label endScope, int characterRangeStart, int characterRangeEnd, int flags) { - with(CharacterRange.of(startScope, endScope, characterRangeStart, characterRangeEnd, flags)); - return this; + return with(CharacterRange.of(startScope, endScope, characterRangeStart, characterRangeEnd, flags)); } /** @@ -920,8 +761,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder localVariable(int slot, Utf8Entry nameEntry, Utf8Entry descriptorEntry, Label startScope, Label endScope) { - with(LocalVariable.of(slot, nameEntry, descriptorEntry, startScope, endScope)); - return this; + return with(LocalVariable.of(slot, nameEntry, descriptorEntry, startScope, endScope)); } /** @@ -950,8 +790,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder localVariableType(int slot, Utf8Entry nameEntry, Utf8Entry signatureEntry, Label startScope, Label endScope) { - with(LocalVariableType.of(slot, nameEntry, signatureEntry, startScope, endScope)); - return this; + return with(LocalVariableType.of(slot, nameEntry, signatureEntry, startScope, endScope)); } /** @@ -985,7 +824,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder aaload() { - return arrayLoadInstruction(TypeKind.ReferenceType); + return arrayLoad(TypeKind.ReferenceType); } /** @@ -993,7 +832,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder aastore() { - return arrayStoreInstruction(TypeKind.ReferenceType); + return arrayStore(TypeKind.ReferenceType); } /** @@ -1002,7 +841,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder aload(int slot) { - return loadInstruction(TypeKind.ReferenceType, slot); + return loadLocal(TypeKind.ReferenceType, slot); } /** @@ -1011,7 +850,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder anewarray(ClassEntry classEntry) { - return newReferenceArrayInstruction(classEntry); + return with(NewReferenceArrayInstruction.of(classEntry)); } /** @@ -1021,7 +860,7 @@ public sealed interface CodeBuilder * @throws IllegalArgumentException if {@code className} represents a primitive type */ default CodeBuilder anewarray(ClassDesc className) { - return newReferenceArrayInstruction(constantPool().classEntry(className)); + return anewarray(constantPool().classEntry(className)); } /** @@ -1029,7 +868,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder areturn() { - return returnInstruction(TypeKind.ReferenceType); + return return_(TypeKind.ReferenceType); } /** @@ -1037,7 +876,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder arraylength() { - return operatorInstruction(Opcode.ARRAYLENGTH); + return with(OperatorInstruction.of(Opcode.ARRAYLENGTH)); } /** @@ -1046,7 +885,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder astore(int slot) { - return storeInstruction(TypeKind.ReferenceType, slot); + return storeLocal(TypeKind.ReferenceType, slot); } /** @@ -1054,7 +893,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder athrow() { - return throwInstruction(); + return with(ThrowInstruction.of()); } /** @@ -1062,7 +901,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder baload() { - return arrayLoadInstruction(TypeKind.ByteType); + return arrayLoad(TypeKind.ByteType); } /** @@ -1070,7 +909,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder bastore() { - return arrayStoreInstruction(TypeKind.ByteType); + return arrayStore(TypeKind.ByteType); } /** @@ -1079,7 +918,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder bipush(int b) { - return constantInstruction(Opcode.BIPUSH, b); + return loadConstant(Opcode.BIPUSH, b); } /** @@ -1087,7 +926,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder caload() { - return arrayLoadInstruction(TypeKind.CharType); + return arrayLoad(TypeKind.CharType); } /** @@ -1095,7 +934,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder castore() { - return arrayStoreInstruction(TypeKind.CharType); + return arrayStore(TypeKind.CharType); } /** @@ -1104,7 +943,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder checkcast(ClassEntry type) { - return typeCheckInstruction(Opcode.CHECKCAST, type); + return with(TypeCheckInstruction.of(Opcode.CHECKCAST, type)); } /** @@ -1114,7 +953,7 @@ public sealed interface CodeBuilder * @throws IllegalArgumentException if {@code type} represents a primitive type */ default CodeBuilder checkcast(ClassDesc type) { - return typeCheckInstruction(Opcode.CHECKCAST, type); + return checkcast(constantPool().classEntry(type)); } /** @@ -1122,7 +961,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder d2f() { - return convertInstruction(TypeKind.DoubleType, TypeKind.FloatType); + return with(ConvertInstruction.of(Opcode.D2F)); } /** @@ -1130,7 +969,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder d2i() { - return convertInstruction(TypeKind.DoubleType, TypeKind.IntType); + return with(ConvertInstruction.of(Opcode.D2I)); } /** @@ -1138,7 +977,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder d2l() { - return convertInstruction(TypeKind.DoubleType, TypeKind.LongType); + return with(ConvertInstruction.of(Opcode.D2L)); } /** @@ -1146,7 +985,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder dadd() { - return operatorInstruction(Opcode.DADD); + return with(OperatorInstruction.of(Opcode.DADD)); } /** @@ -1154,7 +993,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder daload() { - return arrayLoadInstruction(TypeKind.DoubleType); + return arrayLoad(TypeKind.DoubleType); } /** @@ -1162,7 +1001,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder dastore() { - return arrayStoreInstruction(TypeKind.DoubleType); + return arrayStore(TypeKind.DoubleType); } /** @@ -1170,7 +1009,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder dcmpg() { - return operatorInstruction(Opcode.DCMPG); + return with(OperatorInstruction.of(Opcode.DCMPG)); } /** @@ -1178,7 +1017,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder dcmpl() { - return operatorInstruction(Opcode.DCMPL); + return with(OperatorInstruction.of(Opcode.DCMPL)); } /** @@ -1202,7 +1041,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder ddiv() { - return operatorInstruction(Opcode.DDIV); + return with(OperatorInstruction.of(Opcode.DDIV)); } /** @@ -1211,7 +1050,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder dload(int slot) { - return loadInstruction(TypeKind.DoubleType, slot); + return loadLocal(TypeKind.DoubleType, slot); } /** @@ -1219,7 +1058,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder dmul() { - return operatorInstruction(Opcode.DMUL); + return with(OperatorInstruction.of(Opcode.DMUL)); } /** @@ -1227,7 +1066,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder dneg() { - return operatorInstruction(Opcode.DNEG); + return with(OperatorInstruction.of(Opcode.DNEG)); } /** @@ -1235,7 +1074,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder drem() { - return operatorInstruction(Opcode.DREM); + return with(OperatorInstruction.of(Opcode.DREM)); } /** @@ -1243,7 +1082,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder dreturn() { - return returnInstruction(TypeKind.DoubleType); + return return_(TypeKind.DoubleType); } /** @@ -1252,7 +1091,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder dstore(int slot) { - return storeInstruction(TypeKind.DoubleType, slot); + return storeLocal(TypeKind.DoubleType, slot); } /** @@ -1260,7 +1099,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder dsub() { - return operatorInstruction(Opcode.DSUB); + return with(OperatorInstruction.of(Opcode.DSUB)); } /** @@ -1268,7 +1107,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder dup() { - return stackInstruction(Opcode.DUP); + return with(StackInstruction.of(Opcode.DUP)); } /** @@ -1276,7 +1115,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder dup2() { - return stackInstruction(Opcode.DUP2); + return with(StackInstruction.of(Opcode.DUP2)); } /** @@ -1285,7 +1124,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder dup2_x1() { - return stackInstruction(Opcode.DUP2_X1); + return with(StackInstruction.of(Opcode.DUP2_X1)); } /** @@ -1294,7 +1133,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder dup2_x2() { - return stackInstruction(Opcode.DUP2_X2); + return with(StackInstruction.of(Opcode.DUP2_X2)); } /** @@ -1302,7 +1141,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder dup_x1() { - return stackInstruction(Opcode.DUP_X1); + return with(StackInstruction.of(Opcode.DUP_X1)); } /** @@ -1310,7 +1149,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder dup_x2() { - return stackInstruction(Opcode.DUP_X2); + return with(StackInstruction.of(Opcode.DUP_X2)); } /** @@ -1318,7 +1157,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder f2d() { - return convertInstruction(TypeKind.FloatType, TypeKind.DoubleType); + return with(ConvertInstruction.of(Opcode.F2D)); } /** @@ -1326,7 +1165,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder f2i() { - return convertInstruction(TypeKind.FloatType, TypeKind.IntType); + return with(ConvertInstruction.of(Opcode.F2I)); } /** @@ -1334,7 +1173,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder f2l() { - return convertInstruction(TypeKind.FloatType, TypeKind.LongType); + return with(ConvertInstruction.of(Opcode.F2L)); } /** @@ -1342,7 +1181,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder fadd() { - return operatorInstruction(Opcode.FADD); + return with(OperatorInstruction.of(Opcode.FADD)); } /** @@ -1350,7 +1189,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder faload() { - return arrayLoadInstruction(TypeKind.FloatType); + return arrayLoad(TypeKind.FloatType); } /** @@ -1358,7 +1197,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder fastore() { - return arrayStoreInstruction(TypeKind.FloatType); + return arrayStore(TypeKind.FloatType); } /** @@ -1366,7 +1205,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder fcmpg() { - return operatorInstruction(Opcode.FCMPG); + return with(OperatorInstruction.of(Opcode.FCMPG)); } /** @@ -1374,7 +1213,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder fcmpl() { - return operatorInstruction(Opcode.FCMPL); + return with(OperatorInstruction.of(Opcode.FCMPL)); } /** @@ -1406,7 +1245,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder fdiv() { - return operatorInstruction(Opcode.FDIV); + return with(OperatorInstruction.of(Opcode.FDIV)); } /** @@ -1415,7 +1254,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder fload(int slot) { - return loadInstruction(TypeKind.FloatType, slot); + return loadLocal(TypeKind.FloatType, slot); } /** @@ -1423,7 +1262,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder fmul() { - return operatorInstruction(Opcode.FMUL); + return with(OperatorInstruction.of(Opcode.FMUL)); } /** @@ -1431,7 +1270,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder fneg() { - return operatorInstruction(Opcode.FNEG); + return with(OperatorInstruction.of(Opcode.FNEG)); } /** @@ -1439,7 +1278,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder frem() { - return operatorInstruction(Opcode.FREM); + return with(OperatorInstruction.of(Opcode.FREM)); } /** @@ -1447,7 +1286,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder freturn() { - return returnInstruction(TypeKind.FloatType); + return return_(TypeKind.FloatType); } /** @@ -1456,7 +1295,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder fstore(int slot) { - return storeInstruction(TypeKind.FloatType, slot); + return storeLocal(TypeKind.FloatType, slot); } /** @@ -1464,7 +1303,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder fsub() { - return operatorInstruction(Opcode.FSUB); + return with(OperatorInstruction.of(Opcode.FSUB)); } /** @@ -1473,7 +1312,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder getfield(FieldRefEntry ref) { - return fieldInstruction(Opcode.GETFIELD, ref); + return fieldAccess(Opcode.GETFIELD, ref); } /** @@ -1485,7 +1324,7 @@ public sealed interface CodeBuilder * @throws IllegalArgumentException if {@code owner} represents a primitive type */ default CodeBuilder getfield(ClassDesc owner, String name, ClassDesc type) { - return fieldInstruction(Opcode.GETFIELD, owner, name, type); + return fieldAccess(Opcode.GETFIELD, owner, name, type); } /** @@ -1494,7 +1333,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder getstatic(FieldRefEntry ref) { - return fieldInstruction(Opcode.GETSTATIC, ref); + return fieldAccess(Opcode.GETSTATIC, ref); } /** @@ -1506,7 +1345,7 @@ public sealed interface CodeBuilder * @throws IllegalArgumentException if {@code owner} represents a primitive type */ default CodeBuilder getstatic(ClassDesc owner, String name, ClassDesc type) { - return fieldInstruction(Opcode.GETSTATIC, owner, name, type); + return fieldAccess(Opcode.GETSTATIC, owner, name, type); } /** @@ -1515,7 +1354,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder goto_(Label target) { - return branchInstruction(Opcode.GOTO, target); + return branch(Opcode.GOTO, target); } /** @@ -1524,7 +1363,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder goto_w(Label target) { - return branchInstruction(Opcode.GOTO_W, target); + return branch(Opcode.GOTO_W, target); } /** @@ -1532,7 +1371,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder i2b() { - return convertInstruction(TypeKind.IntType, TypeKind.ByteType); + return with(ConvertInstruction.of(Opcode.I2B)); } /** @@ -1540,7 +1379,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder i2c() { - return convertInstruction(TypeKind.IntType, TypeKind.CharType); + return with(ConvertInstruction.of(Opcode.I2C)); } /** @@ -1548,7 +1387,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder i2d() { - return convertInstruction(TypeKind.IntType, TypeKind.DoubleType); + return with(ConvertInstruction.of(Opcode.I2D)); } /** @@ -1556,7 +1395,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder i2f() { - return convertInstruction(TypeKind.IntType, TypeKind.FloatType); + return with(ConvertInstruction.of(Opcode.I2F)); } /** @@ -1564,7 +1403,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder i2l() { - return convertInstruction(TypeKind.IntType, TypeKind.LongType); + return with(ConvertInstruction.of(Opcode.I2L)); } /** @@ -1572,7 +1411,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder i2s() { - return convertInstruction(TypeKind.IntType, TypeKind.ShortType); + return with(ConvertInstruction.of(Opcode.I2S)); } /** @@ -1580,7 +1419,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder iadd() { - return operatorInstruction(Opcode.IADD); + return with(OperatorInstruction.of(Opcode.IADD)); } /** @@ -1588,7 +1427,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder iaload() { - return arrayLoadInstruction(TypeKind.IntType); + return arrayLoad(TypeKind.IntType); } /** @@ -1596,7 +1435,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder iand() { - return operatorInstruction(Opcode.IAND); + return with(OperatorInstruction.of(Opcode.IAND)); } /** @@ -1604,7 +1443,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder iastore() { - return arrayStoreInstruction(TypeKind.IntType); + return arrayStore(TypeKind.IntType); } /** @@ -1668,7 +1507,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder idiv() { - return operatorInstruction(Opcode.IDIV); + return with(OperatorInstruction.of(Opcode.IDIV)); } /** @@ -1677,7 +1516,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder if_acmpeq(Label target) { - return branchInstruction(Opcode.IF_ACMPEQ, target); + return branch(Opcode.IF_ACMPEQ, target); } /** @@ -1686,7 +1525,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder if_acmpne(Label target) { - return branchInstruction(Opcode.IF_ACMPNE, target); + return branch(Opcode.IF_ACMPNE, target); } /** @@ -1695,7 +1534,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder if_icmpeq(Label target) { - return branchInstruction(Opcode.IF_ICMPEQ, target); + return branch(Opcode.IF_ICMPEQ, target); } /** @@ -1704,7 +1543,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder if_icmpge(Label target) { - return branchInstruction(Opcode.IF_ICMPGE, target); + return branch(Opcode.IF_ICMPGE, target); } /** @@ -1713,7 +1552,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder if_icmpgt(Label target) { - return branchInstruction(Opcode.IF_ICMPGT, target); + return branch(Opcode.IF_ICMPGT, target); } /** @@ -1722,7 +1561,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder if_icmple(Label target) { - return branchInstruction(Opcode.IF_ICMPLE, target); + return branch(Opcode.IF_ICMPLE, target); } /** @@ -1731,7 +1570,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder if_icmplt(Label target) { - return branchInstruction(Opcode.IF_ICMPLT, target); + return branch(Opcode.IF_ICMPLT, target); } /** @@ -1740,7 +1579,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder if_icmpne(Label target) { - return branchInstruction(Opcode.IF_ICMPNE, target); + return branch(Opcode.IF_ICMPNE, target); } /** @@ -1749,7 +1588,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder if_nonnull(Label target) { - return branchInstruction(Opcode.IFNONNULL, target); + return branch(Opcode.IFNONNULL, target); } /** @@ -1758,7 +1597,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder if_null(Label target) { - return branchInstruction(Opcode.IFNULL, target); + return branch(Opcode.IFNULL, target); } /** @@ -1767,7 +1606,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder ifeq(Label target) { - return branchInstruction(Opcode.IFEQ, target); + return branch(Opcode.IFEQ, target); } /** @@ -1776,7 +1615,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder ifge(Label target) { - return branchInstruction(Opcode.IFGE, target); + return branch(Opcode.IFGE, target); } /** @@ -1785,7 +1624,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder ifgt(Label target) { - return branchInstruction(Opcode.IFGT, target); + return branch(Opcode.IFGT, target); } /** @@ -1794,7 +1633,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder ifle(Label target) { - return branchInstruction(Opcode.IFLE, target); + return branch(Opcode.IFLE, target); } /** @@ -1803,7 +1642,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder iflt(Label target) { - return branchInstruction(Opcode.IFLT, target); + return branch(Opcode.IFLT, target); } /** @@ -1812,7 +1651,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder ifne(Label target) { - return branchInstruction(Opcode.IFNE, target); + return branch(Opcode.IFNE, target); } /** @@ -1822,7 +1661,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder iinc(int slot, int val) { - return incrementInstruction(slot, val); + return with(IncrementInstruction.of(slot, val)); } /** @@ -1831,7 +1670,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder iload(int slot) { - return loadInstruction(TypeKind.IntType, slot); + return loadLocal(TypeKind.IntType, slot); } /** @@ -1839,7 +1678,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder imul() { - return operatorInstruction(Opcode.IMUL); + return with(OperatorInstruction.of(Opcode.IMUL)); } /** @@ -1847,16 +1686,17 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder ineg() { - return operatorInstruction(Opcode.INEG); + return with(OperatorInstruction.of(Opcode.INEG)); } /** * Generate an instruction to determine if an object is of the given type * @param target the target type * @return this builder + * @since 23 */ - default CodeBuilder instanceof_(ClassEntry target) { - return typeCheckInstruction(Opcode.INSTANCEOF, target); + default CodeBuilder instanceOf(ClassEntry target) { + return with(TypeCheckInstruction.of(Opcode.INSTANCEOF, target)); } /** @@ -1864,9 +1704,10 @@ public sealed interface CodeBuilder * @param target the target type * @return this builder * @throws IllegalArgumentException if {@code target} represents a primitive type + * @since 23 */ - default CodeBuilder instanceof_(ClassDesc target) { - return typeCheckInstruction(Opcode.INSTANCEOF, constantPool().classEntry(target)); + default CodeBuilder instanceOf(ClassDesc target) { + return instanceOf(constantPool().classEntry(target)); } /** @@ -1875,7 +1716,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder invokedynamic(InvokeDynamicEntry ref) { - return invokeDynamicInstruction(ref); + return with(InvokeDynamicInstruction.of(ref)); } /** @@ -1884,7 +1725,15 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder invokedynamic(DynamicCallSiteDesc ref) { - return invokeDynamicInstruction(ref); + MethodHandleEntry bsMethod = handleDescToHandleInfo(constantPool(), (DirectMethodHandleDesc) ref.bootstrapMethod()); + var cpArgs = ref.bootstrapArgs(); + List bsArguments = new ArrayList<>(cpArgs.length); + for (var constantValue : cpArgs) { + bsArguments.add(BytecodeHelpers.constantEntry(constantPool(), constantValue)); + } + BootstrapMethodEntry bm = constantPool().bsmEntry(bsMethod, bsArguments); + NameAndTypeEntry nameAndType = constantPool().nameAndTypeEntry(ref.invocationName(), ref.invocationType()); + return invokedynamic(constantPool().invokeDynamicEntry(bm, nameAndType)); } /** @@ -1893,7 +1742,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder invokeinterface(InterfaceMethodRefEntry ref) { - return invokeInstruction(Opcode.INVOKEINTERFACE, ref); + return invoke(Opcode.INVOKEINTERFACE, ref); } /** @@ -1905,7 +1754,7 @@ public sealed interface CodeBuilder * @throws IllegalArgumentException if {@code owner} represents a primitive type */ default CodeBuilder invokeinterface(ClassDesc owner, String name, MethodTypeDesc type) { - return invokeInstruction(Opcode.INVOKEINTERFACE, constantPool().interfaceMethodRefEntry(owner, name, type)); + return invoke(Opcode.INVOKEINTERFACE, constantPool().interfaceMethodRefEntry(owner, name, type)); } /** @@ -1915,7 +1764,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder invokespecial(InterfaceMethodRefEntry ref) { - return invokeInstruction(Opcode.INVOKESPECIAL, ref); + return invoke(Opcode.INVOKESPECIAL, ref); } /** @@ -1925,7 +1774,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder invokespecial(MethodRefEntry ref) { - return invokeInstruction(Opcode.INVOKESPECIAL, ref); + return invoke(Opcode.INVOKESPECIAL, ref); } /** @@ -1938,7 +1787,7 @@ public sealed interface CodeBuilder * @throws IllegalArgumentException if {@code owner} represents a primitive type */ default CodeBuilder invokespecial(ClassDesc owner, String name, MethodTypeDesc type) { - return invokeInstruction(Opcode.INVOKESPECIAL, owner, name, type, false); + return invoke(Opcode.INVOKESPECIAL, owner, name, type, false); } /** @@ -1952,7 +1801,7 @@ public sealed interface CodeBuilder * @throws IllegalArgumentException if {@code owner} represents a primitive type */ default CodeBuilder invokespecial(ClassDesc owner, String name, MethodTypeDesc type, boolean isInterface) { - return invokeInstruction(Opcode.INVOKESPECIAL, owner, name, type, isInterface); + return invoke(Opcode.INVOKESPECIAL, owner, name, type, isInterface); } /** @@ -1961,7 +1810,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder invokestatic(InterfaceMethodRefEntry ref) { - return invokeInstruction(Opcode.INVOKESTATIC, ref); + return invoke(Opcode.INVOKESTATIC, ref); } /** @@ -1970,7 +1819,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder invokestatic(MethodRefEntry ref) { - return invokeInstruction(Opcode.INVOKESTATIC, ref); + return invoke(Opcode.INVOKESTATIC, ref); } /** @@ -1982,7 +1831,7 @@ public sealed interface CodeBuilder * @throws IllegalArgumentException if {@code owner} represents a primitive type */ default CodeBuilder invokestatic(ClassDesc owner, String name, MethodTypeDesc type) { - return invokeInstruction(Opcode.INVOKESTATIC, owner, name, type, false); + return invoke(Opcode.INVOKESTATIC, owner, name, type, false); } /** @@ -1995,7 +1844,7 @@ public sealed interface CodeBuilder * @throws IllegalArgumentException if {@code owner} represents a primitive type */ default CodeBuilder invokestatic(ClassDesc owner, String name, MethodTypeDesc type, boolean isInterface) { - return invokeInstruction(Opcode.INVOKESTATIC, owner, name, type, isInterface); + return invoke(Opcode.INVOKESTATIC, owner, name, type, isInterface); } /** @@ -2004,7 +1853,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder invokevirtual(MethodRefEntry ref) { - return invokeInstruction(Opcode.INVOKEVIRTUAL, ref); + return invoke(Opcode.INVOKEVIRTUAL, ref); } /** @@ -2016,7 +1865,7 @@ public sealed interface CodeBuilder * @throws IllegalArgumentException if {@code owner} represents a primitive type */ default CodeBuilder invokevirtual(ClassDesc owner, String name, MethodTypeDesc type) { - return invokeInstruction(Opcode.INVOKEVIRTUAL, owner, name, type, false); + return invoke(Opcode.INVOKEVIRTUAL, owner, name, type, false); } /** @@ -2024,7 +1873,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder ior() { - return operatorInstruction(Opcode.IOR); + return with(OperatorInstruction.of(Opcode.IOR)); } /** @@ -2032,7 +1881,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder irem() { - return operatorInstruction(Opcode.IREM); + return with(OperatorInstruction.of(Opcode.IREM)); } /** @@ -2040,7 +1889,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder ireturn() { - return returnInstruction(TypeKind.IntType); + return return_(TypeKind.IntType); } /** @@ -2048,7 +1897,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder ishl() { - return operatorInstruction(Opcode.ISHL); + return with(OperatorInstruction.of(Opcode.ISHL)); } /** @@ -2056,7 +1905,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder ishr() { - return operatorInstruction(Opcode.ISHR); + return with(OperatorInstruction.of(Opcode.ISHR)); } /** @@ -2065,7 +1914,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder istore(int slot) { - return storeInstruction(TypeKind.IntType, slot); + return storeLocal(TypeKind.IntType, slot); } /** @@ -2073,7 +1922,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder isub() { - return operatorInstruction(Opcode.ISUB); + return with(OperatorInstruction.of(Opcode.ISUB)); } /** @@ -2081,7 +1930,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder iushr() { - return operatorInstruction(Opcode.IUSHR); + return with(OperatorInstruction.of(Opcode.IUSHR)); } /** @@ -2089,7 +1938,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder ixor() { - return operatorInstruction(Opcode.IXOR); + return with(OperatorInstruction.of(Opcode.IXOR)); } /** @@ -2099,7 +1948,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder lookupswitch(Label defaultTarget, List cases) { - return lookupSwitchInstruction(defaultTarget, cases); + return with(LookupSwitchInstruction.of(defaultTarget, cases)); } /** @@ -2107,7 +1956,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder l2d() { - return convertInstruction(TypeKind.LongType, TypeKind.DoubleType); + return with(ConvertInstruction.of(Opcode.L2D)); } /** @@ -2115,7 +1964,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder l2f() { - return convertInstruction(TypeKind.LongType, TypeKind.FloatType); + return with(ConvertInstruction.of(Opcode.L2F)); } /** @@ -2123,7 +1972,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder l2i() { - return convertInstruction(TypeKind.LongType, TypeKind.IntType); + return with(ConvertInstruction.of(Opcode.L2I)); } /** @@ -2131,7 +1980,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder ladd() { - return operatorInstruction(Opcode.LADD); + return with(OperatorInstruction.of(Opcode.LADD)); } /** @@ -2139,7 +1988,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder laload() { - return arrayLoadInstruction(TypeKind.LongType); + return arrayLoad(TypeKind.LongType); } /** @@ -2147,7 +1996,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder land() { - return operatorInstruction(Opcode.LAND); + return with(OperatorInstruction.of(Opcode.LAND)); } /** @@ -2155,7 +2004,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder lastore() { - return arrayStoreInstruction(TypeKind.LongType); + return arrayStore(TypeKind.LongType); } /** @@ -2163,7 +2012,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder lcmp() { - return operatorInstruction(Opcode.LCMP); + return with(OperatorInstruction.of(Opcode.LCMP)); } /** @@ -2208,7 +2057,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder ldiv() { - return operatorInstruction(Opcode.LDIV); + return with(OperatorInstruction.of(Opcode.LDIV)); } /** @@ -2217,7 +2066,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder lload(int slot) { - return loadInstruction(TypeKind.LongType, slot); + return loadLocal(TypeKind.LongType, slot); } /** @@ -2225,7 +2074,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder lmul() { - return operatorInstruction(Opcode.LMUL); + return with(OperatorInstruction.of(Opcode.LMUL)); } /** @@ -2233,7 +2082,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder lneg() { - return operatorInstruction(Opcode.LNEG); + return with(OperatorInstruction.of(Opcode.LNEG)); } /** @@ -2241,7 +2090,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder lor() { - return operatorInstruction(Opcode.LOR); + return with(OperatorInstruction.of(Opcode.LOR)); } /** @@ -2249,7 +2098,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder lrem() { - return operatorInstruction(Opcode.LREM); + return with(OperatorInstruction.of(Opcode.LREM)); } /** @@ -2257,7 +2106,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder lreturn() { - return returnInstruction(TypeKind.LongType); + return return_(TypeKind.LongType); } /** @@ -2265,7 +2114,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder lshl() { - return operatorInstruction(Opcode.LSHL); + return with(OperatorInstruction.of(Opcode.LSHL)); } /** @@ -2273,7 +2122,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder lshr() { - return operatorInstruction(Opcode.LSHR); + return with(OperatorInstruction.of(Opcode.LSHR)); } /** @@ -2282,7 +2131,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder lstore(int slot) { - return storeInstruction(TypeKind.LongType, slot); + return storeLocal(TypeKind.LongType, slot); } /** @@ -2290,7 +2139,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder lsub() { - return operatorInstruction(Opcode.LSUB); + return with(OperatorInstruction.of(Opcode.LSUB)); } /** @@ -2298,7 +2147,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder lushr() { - return operatorInstruction(Opcode.LUSHR); + return with(OperatorInstruction.of(Opcode.LUSHR)); } /** @@ -2306,7 +2155,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder lxor() { - return operatorInstruction(Opcode.LXOR); + return with(OperatorInstruction.of(Opcode.LXOR)); } /** @@ -2314,7 +2163,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder monitorenter() { - return monitorInstruction(Opcode.MONITORENTER); + return with(MonitorInstruction.of(Opcode.MONITORENTER)); } /** @@ -2322,7 +2171,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder monitorexit() { - return monitorInstruction(Opcode.MONITOREXIT); + return with(MonitorInstruction.of(Opcode.MONITOREXIT)); } /** @@ -2332,7 +2181,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder multianewarray(ClassEntry array, int dims) { - return newMultidimensionalArrayInstruction(dims, array); + return with(NewMultiArrayInstruction.of(array, dims)); } /** @@ -2343,7 +2192,7 @@ public sealed interface CodeBuilder * @throws IllegalArgumentException if {@code array} represents a primitive type */ default CodeBuilder multianewarray(ClassDesc array, int dims) { - return newMultidimensionalArrayInstruction(dims, constantPool().classEntry(array)); + return multianewarray(constantPool().classEntry(array), dims); } /** @@ -2352,7 +2201,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder new_(ClassEntry clazz) { - return newObjectInstruction(clazz); + return with(NewObjectInstruction.of(clazz)); } /** @@ -2362,7 +2211,7 @@ public sealed interface CodeBuilder * @throws IllegalArgumentException if {@code clazz} represents a primitive type */ default CodeBuilder new_(ClassDesc clazz) { - return newObjectInstruction(constantPool().classEntry(clazz)); + return new_(constantPool().classEntry(clazz)); } /** @@ -2371,7 +2220,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder newarray(TypeKind typeKind) { - return newPrimitiveArrayInstruction(typeKind); + return with(NewPrimitiveArrayInstruction.of(typeKind)); } /** @@ -2379,7 +2228,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder pop() { - return stackInstruction(Opcode.POP); + return with(StackInstruction.of(Opcode.POP)); } /** @@ -2387,7 +2236,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder pop2() { - return stackInstruction(Opcode.POP2); + return with(StackInstruction.of(Opcode.POP2)); } /** @@ -2396,7 +2245,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder putfield(FieldRefEntry ref) { - return fieldInstruction(Opcode.PUTFIELD, ref); + return fieldAccess(Opcode.PUTFIELD, ref); } /** @@ -2408,7 +2257,7 @@ public sealed interface CodeBuilder * @throws IllegalArgumentException if {@code owner} represents a primitive type */ default CodeBuilder putfield(ClassDesc owner, String name, ClassDesc type) { - return fieldInstruction(Opcode.PUTFIELD, owner, name, type); + return fieldAccess(Opcode.PUTFIELD, owner, name, type); } /** @@ -2417,7 +2266,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder putstatic(FieldRefEntry ref) { - return fieldInstruction(Opcode.PUTSTATIC, ref); + return fieldAccess(Opcode.PUTSTATIC, ref); } /** @@ -2429,7 +2278,7 @@ public sealed interface CodeBuilder * @throws IllegalArgumentException if {@code owner} represents a primitive type */ default CodeBuilder putstatic(ClassDesc owner, String name, ClassDesc type) { - return fieldInstruction(Opcode.PUTSTATIC, owner, name, type); + return fieldAccess(Opcode.PUTSTATIC, owner, name, type); } /** @@ -2437,7 +2286,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder return_() { - return returnInstruction(TypeKind.VoidType); + return return_(TypeKind.VoidType); } /** @@ -2445,7 +2294,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder saload() { - return arrayLoadInstruction(TypeKind.ShortType); + return arrayLoad(TypeKind.ShortType); } /** @@ -2453,7 +2302,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder sastore() { - return arrayStoreInstruction(TypeKind.ShortType); + return arrayStore(TypeKind.ShortType); } /** @@ -2462,7 +2311,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder sipush(int s) { - return constantInstruction(Opcode.SIPUSH, s); + return loadConstant(Opcode.SIPUSH, s); } /** @@ -2470,7 +2319,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder swap() { - return stackInstruction(Opcode.SWAP); + return with(StackInstruction.of(Opcode.SWAP)); } /** @@ -2482,7 +2331,7 @@ public sealed interface CodeBuilder * @return this builder */ default CodeBuilder tableswitch(int low, int high, Label defaultTarget, List cases) { - return tableSwitchInstruction(low, high, defaultTarget, cases); + return with(TableSwitchInstruction.of(low, high, defaultTarget, cases)); } /** @@ -2499,6 +2348,6 @@ public sealed interface CodeBuilder if (i < low) low = i; if (i > high) high = i; } - return tableSwitchInstruction(low, high, defaultTarget, cases); + return tableswitch(low, high, defaultTarget, cases); } } diff --git a/src/java.base/share/classes/java/lang/classfile/package-info.java b/src/java.base/share/classes/java/lang/classfile/package-info.java index edeafc439d3..49413d35660 100644 --- a/src/java.base/share/classes/java/lang/classfile/package-info.java +++ b/src/java.base/share/classes/java/lang/classfile/package-info.java @@ -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) diff --git a/src/java.base/share/classes/java/lang/classfile/snippet-files/PackageSnippets.java b/src/java.base/share/classes/java/lang/classfile/snippet-files/PackageSnippets.java index 3776c6f66e9..5073e108465 100644 --- a/src/java.base/share/classes/java/lang/classfile/snippet-files/PackageSnippets.java +++ b/src/java.base/share/classes/java/lang/classfile/snippet-files/PackageSnippets.java @@ -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); }}); diff --git a/src/java.base/share/classes/java/lang/invoke/MethodHandleProxies.java b/src/java.base/share/classes/java/lang/invoke/MethodHandleProxies.java index 15dc1301db5..5ca45e3fe52 100644 --- a/src/java.base/share/classes/java/lang/invoke/MethodHandleProxies.java +++ b/src/java.base/share/classes/java/lang/invoke/MethodHandleProxies.java @@ -382,7 +382,7 @@ public class MethodHandleProxies { // 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 = 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) diff --git a/src/java.base/share/classes/java/lang/invoke/StringConcatFactory.java b/src/java.base/share/classes/java/lang/invoke/StringConcatFactory.java index cd2f7ec170a..3499fd83525 100644 --- a/src/java.base/share/classes/java/lang/invoke/StringConcatFactory.java +++ b/src/java.base/share/classes/java/lang/invoke/StringConcatFactory.java @@ -1124,7 +1124,7 @@ public final class StringConcatFactory { } } len += args.parameterCount() * ARGUMENT_SIZE_FACTOR; - cb.constantInstruction(len); + cb.loadConstant(len); cb.invokespecial(STRING_BUILDER, "", 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); diff --git a/src/java.base/share/classes/java/lang/reflect/ProxyGenerator.java b/src/java.base/share/classes/java/lang/reflect/ProxyGenerator.java index 9637af4b251..08f971b0902 100644 --- a/src/java.base/share/classes/java/lang/reflect/ProxyGenerator.java +++ b/src/java.base/share/classes/java/lang/reflect/ProxyGenerator.java @@ -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); diff --git a/src/java.base/share/classes/java/lang/runtime/SwitchBootstraps.java b/src/java.base/share/classes/java/lang/runtime/SwitchBootstraps.java index f91a9ad4de3..9ec60d9a152 100644 --- a/src/java.base/share/classes/java/lang/runtime/SwitchBootstraps.java +++ b/src/java.base/share/classes/java/lang/runtime/SwitchBootstraps.java @@ -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 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(); }; } diff --git a/src/java.base/share/classes/jdk/internal/classfile/impl/CatchBuilderImpl.java b/src/java.base/share/classes/jdk/internal/classfile/impl/CatchBuilderImpl.java index 0878682ae56..5d262c397f6 100644 --- a/src/java.base/share/classes/jdk/internal/classfile/impl/CatchBuilderImpl.java +++ b/src/java.base/share/classes/jdk/internal/classfile/impl/CatchBuilderImpl.java @@ -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); } } diff --git a/src/java.base/share/classes/jdk/internal/classfile/impl/ClassRemapperImpl.java b/src/java.base/share/classes/jdk/internal/classfile/impl/ClassRemapperImpl.java index 8f35b85b5de..6e80e289064 100644 --- a/src/java.base/share/classes/jdk/internal/classfile/impl/ClassRemapperImpl.java +++ b/src/java.base/share/classes/jdk/internal/classfile/impl/ClassRemapperImpl.java @@ -231,25 +231,25 @@ public record ClassRemapperImpl(Function 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 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( diff --git a/src/java.base/share/classes/jdk/internal/classfile/impl/CodeLocalsShifterImpl.java b/src/java.base/share/classes/jdk/internal/classfile/impl/CodeLocalsShifterImpl.java index 9b301ccc822..a68225fbf27 100644 --- a/src/java.base/share/classes/jdk/internal/classfile/impl/CodeLocalsShifterImpl.java +++ b/src/java.base/share/classes/jdk/internal/classfile/impl/CodeLocalsShifterImpl.java @@ -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 -> diff --git a/src/java.base/share/classes/jdk/internal/classfile/impl/CodeRelabelerImpl.java b/src/java.base/share/classes/jdk/internal/classfile/impl/CodeRelabelerImpl.java index 0e9bacd1cd9..f191cbf3c1f 100644 --- a/src/java.base/share/classes/jdk/internal/classfile/impl/CodeRelabelerImpl.java +++ b/src/java.base/share/classes/jdk/internal/classfile/impl/CodeRelabelerImpl.java @@ -51,18 +51,18 @@ public record CodeRelabelerImpl(BiFunction 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), diff --git a/src/java.base/share/classes/jdk/internal/foreign/abi/BindingSpecializer.java b/src/java.base/share/classes/jdk/internal/foreign/abi/BindingSpecializer.java index a399b815ee6..7f5ef54bdca 100644 --- a/src/java.base/share/classes/jdk/internal/foreign/abi/BindingSpecializer.java +++ b/src/java.base/share/classes/jdk/internal/foreign/abi/BindingSpecializer.java @@ -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); } diff --git a/src/jdk.jfr/share/classes/jdk/jfr/internal/EventInstrumentation.java b/src/jdk.jfr/share/classes/jdk/jfr/internal/EventInstrumentation.java index 9e99c90788c..cf7e162a42e 100644 --- a/src/jdk.jfr/share/classes/jdk/jfr/internal/EventInstrumentation.java +++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/EventInstrumentation.java @@ -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); diff --git a/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/SystemModulesPlugin.java b/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/SystemModulesPlugin.java index 40693b33d6d..96b7c76f24d 100644 --- a/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/SystemModulesPlugin.java +++ b/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/SystemModulesPlugin.java @@ -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 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) { 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 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) { 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) { 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) { 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 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 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 entry : systemModulesMap) { cob.dup() // arrayref - .constantInstruction(index) - .constantInstruction(entry.getValue().replace('/', '.')) + .loadConstant(index) + .loadConstant(entry.getValue().replace('/', '.')) .aastore(); index++; } diff --git a/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/VersionPropsPlugin.java b/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/VersionPropsPlugin.java index 42b6357866f..973fa4d1268 100644 --- a/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/VersionPropsPlugin.java +++ b/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/VersionPropsPlugin.java @@ -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); diff --git a/test/jdk/java/io/Serializable/records/ProhibitedMethods.java b/test/jdk/java/io/Serializable/records/ProhibitedMethods.java index 371500497f9..53252aaf558 100644 --- a/test/jdk/java/io/Serializable/records/ProhibitedMethods.java +++ b/test/jdk/java/io/Serializable/records/ProhibitedMethods.java @@ -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_(); diff --git a/test/jdk/java/io/Serializable/records/SerialPersistentFieldsTest.java b/test/jdk/java/io/Serializable/records/SerialPersistentFieldsTest.java index 31397ad60cb..4ff15aa84d4 100644 --- a/test/jdk/java/io/Serializable/records/SerialPersistentFieldsTest.java +++ b/test/jdk/java/io/Serializable/records/SerialPersistentFieldsTest.java @@ -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(); diff --git a/test/jdk/java/lang/instrument/NativeMethodPrefixAgent.java b/test/jdk/java/lang/instrument/NativeMethodPrefixAgent.java index e8b5bbe7dd9..daf36c2c0b5 100644 --- a/test/jdk/java/lang/instrument/NativeMethodPrefixAgent.java +++ b/test/jdk/java/lang/instrument/NativeMethodPrefixAgent.java @@ -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", diff --git a/test/jdk/java/lang/instrument/RetransformAgent.java b/test/jdk/java/lang/instrument/RetransformAgent.java index f5eadabad16..89300a43a7d 100644 --- a/test/jdk/java/lang/instrument/RetransformAgent.java +++ b/test/jdk/java/lang/instrument/RetransformAgent.java @@ -91,7 +91,7 @@ class RetransformAgent { .addMethodEntryInjection( nname, cb -> { - cb.constantInstruction(fixedIndex); + cb.loadConstant(fixedIndex); cb.invokestatic( CD_RetransformAgent, "callTracker", MTD_void_int); diff --git a/test/jdk/java/lang/instrument/asmlib/Instrumentor.java b/test/jdk/java/lang/instrument/asmlib/Instrumentor.java index ed5e219dd4d..29f2740a874 100644 --- a/test/jdk/java/lang/instrument/asmlib/Instrumentor.java +++ b/test/jdk/java/lang/instrument/asmlib/Instrumentor.java @@ -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())); })); } })); diff --git a/test/jdk/java/lang/invoke/MethodHandleProxies/WrapperHiddenClassTest.java b/test/jdk/java/lang/invoke/MethodHandleProxies/WrapperHiddenClassTest.java index 435f59fe755..3e1f0f41d6f 100644 --- a/test/jdk/java/lang/invoke/MethodHandleProxies/WrapperHiddenClassTest.java +++ b/test/jdk/java/lang/invoke/MethodHandleProxies/WrapperHiddenClassTest.java @@ -95,7 +95,7 @@ public class WrapperHiddenClassTest { // 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_(); }); diff --git a/test/jdk/java/lang/invoke/MethodHandles/classData/ClassDataTest.java b/test/jdk/java/lang/invoke/MethodHandles/classData/ClassDataTest.java index edcc095c77b..af35d0edd03 100644 --- a/test/jdk/java/lang/invoke/MethodHandles/classData/ClassDataTest.java +++ b/test/jdk/java/lang/invoke/MethodHandles/classData/ClassDataTest.java @@ -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; diff --git a/test/jdk/java/lang/invoke/common/test/java/lang/invoke/lib/InstructionHelper.java b/test/jdk/java/lang/invoke/common/test/java/lang/invoke/lib/InstructionHelper.java index 722f0ee4d8f..4b9a4fa8f8b 100644 --- a/test/jdk/java/lang/invoke/common/test/java/lang/invoke/lib/InstructionHelper.java +++ b/test/jdk/java/lang/invoke/common/test/java/lang/invoke/lib/InstructionHelper.java @@ -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())); diff --git a/test/jdk/java/lang/invoke/condy/CondyNestedTest.java b/test/jdk/java/lang/invoke/condy/CondyNestedTest.java index 53275905abb..2cdbff4ffdd 100644 --- a/test/jdk/java/lang/invoke/condy/CondyNestedTest.java +++ b/test/jdk/java/lang/invoke/condy/CondyNestedTest.java @@ -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 diff --git a/test/jdk/java/lang/invoke/lookup/SpecialStatic.java b/test/jdk/java/lang/invoke/lookup/SpecialStatic.java index 59db5d29788..4a44a898a77 100644 --- a/test/jdk/java/lang/invoke/lookup/SpecialStatic.java +++ b/test/jdk/java/lang/invoke/lookup/SpecialStatic.java @@ -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, diff --git a/test/jdk/java/lang/reflect/Method/invoke/TestPrivateInterfaceMethodReflect.java b/test/jdk/java/lang/reflect/Method/invoke/TestPrivateInterfaceMethodReflect.java index 17f9c6665c1..2b19189ceed 100644 --- a/test/jdk/java/lang/reflect/Method/invoke/TestPrivateInterfaceMethodReflect.java +++ b/test/jdk/java/lang/reflect/Method/invoke/TestPrivateInterfaceMethodReflect.java @@ -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(); }); }); diff --git a/test/jdk/jdk/classfile/AdaptCodeTest.java b/test/jdk/jdk/classfile/AdaptCodeTest.java index 2fd9fcb2c95..2a75cd7e020 100644 --- a/test/jdk/jdk/classfile/AdaptCodeTest.java +++ b/test/jdk/jdk/classfile/AdaptCodeTest.java @@ -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); } diff --git a/test/jdk/jdk/classfile/BSMTest.java b/test/jdk/jdk/classfile/BSMTest.java index 79ecfb2f53e..927549f0210 100644 --- a/test/jdk/jdk/classfile/BSMTest.java +++ b/test/jdk/jdk/classfile/BSMTest.java @@ -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); } diff --git a/test/jdk/jdk/classfile/BuilderBlockTest.java b/test/jdk/jdk/classfile/BuilderBlockTest.java index c75869f740f..c8e13b79f72 100644 --- a/test/jdk/jdk/classfile/BuilderBlockTest.java +++ b/test/jdk/jdk/classfile/BuilderBlockTest.java @@ -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) diff --git a/test/jdk/jdk/classfile/BuilderTryCatchTest.java b/test/jdk/jdk/classfile/BuilderTryCatchTest.java index 89117d4abd1..666b36e11a7 100644 --- a/test/jdk/jdk/classfile/BuilderTryCatchTest.java +++ b/test/jdk/jdk/classfile/BuilderTryCatchTest.java @@ -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(); }); }); }); diff --git a/test/jdk/jdk/classfile/DiscontinuedInstructionsTest.java b/test/jdk/jdk/classfile/DiscontinuedInstructionsTest.java index 8d5b11c28e6..be7e425c694 100644 --- a/test/jdk/jdk/classfile/DiscontinuedInstructionsTest.java +++ b/test/jdk/jdk/classfile/DiscontinuedInstructionsTest.java @@ -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_(); }) diff --git a/test/jdk/jdk/classfile/LDCTest.java b/test/jdk/jdk/classfile/LDCTest.java index 1ece8967576..1e7639de4bb 100644 --- a/test/jdk/jdk/classfile/LDCTest.java +++ b/test/jdk/jdk/classfile/LDCTest.java @@ -49,9 +49,9 @@ class LDCTest { cb.withFlags(AccessFlag.PUBLIC); cb.withVersion(52, 0); cb.withMethod("", MethodTypeDesc.of(CD_void), 0, mb -> mb - .withCode(codeb -> codeb.loadInstruction(TypeKind.ReferenceType, 0) - .invokeInstruction(INVOKESPECIAL, CD_Object, "", MTD_VOID, false) - .returnInstruction(VoidType) + .withCode(codeb -> codeb.aload(0) + .invokespecial(CD_Object, "", 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_(); })); }); diff --git a/test/jdk/jdk/classfile/LowAdaptTest.java b/test/jdk/jdk/classfile/LowAdaptTest.java index 4be4a259ac0..46d033a8676 100644 --- a/test/jdk/jdk/classfile/LowAdaptTest.java +++ b/test/jdk/jdk/classfile/LowAdaptTest.java @@ -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(); })); }); diff --git a/test/jdk/jdk/classfile/LvtTest.java b/test/jdk/jdk/classfile/LvtTest.java index 1c35b071cc2..35ec8dfcfa3 100644 --- a/test/jdk/jdk/classfile/LvtTest.java +++ b/test/jdk/jdk/classfile/LvtTest.java @@ -122,9 +122,9 @@ class LvtTest { cb.withVersion(52, 0); cb.with(SourceFileAttribute.of(cb.constantPool().utf8Entry(("MyClass.java")))) .withMethod("", MethodTypeDesc.of(CD_void), 0, mb -> mb - .withCode(codeb -> codeb.loadInstruction(TypeKind.ReferenceType, 0) - .invokeInstruction(INVOKESPECIAL, CD_Object, "", MTD_VOID, false) - .returnInstruction(VoidType) + .withCode(codeb -> codeb.aload(0) + .invokespecial(CD_Object, "", 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("", MethodTypeDesc.of(CD_void), 0, mb -> mb - .withCode(codeb -> codeb.loadInstruction(TypeKind.ReferenceType, 0) - .invokeInstruction(INVOKESPECIAL, CD_Object, "", MTD_VOID, false) - .returnInstruction(VoidType) + .withCode(codeb -> codeb.aload(0) + .invokespecial(CD_Object, "", 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, "", MTD_VOID, false) - .storeInstruction(TypeKind.ReferenceType, 2) + .new_(ClassDesc.of("java.util.ArrayList")) + .dup() + .invokespecial(CD_ArrayList, "", 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); diff --git a/test/jdk/jdk/classfile/OneToOneTest.java b/test/jdk/jdk/classfile/OneToOneTest.java index 5db0489ac3e..b20d07025e6 100644 --- a/test/jdk/jdk/classfile/OneToOneTest.java +++ b/test/jdk/jdk/classfile/OneToOneTest.java @@ -68,9 +68,9 @@ class OneToOneTest { cb.with(SourceFileAttribute.of(cb.constantPool().utf8Entry(("MyClass.java")))) .withMethod("", MethodTypeDesc.of(CD_void), 0, mb -> mb - .withCode(codeb -> codeb.loadInstruction(TypeKind.ReferenceType, 0) - .invokeInstruction(INVOKESPECIAL, CD_Object, "", MTD_VOID, false) - .returnInstruction(TypeKind.VoidType) + .withCode(codeb -> codeb.aload(0) + .invokespecial(CD_Object, "", 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_(); } ) ); diff --git a/test/jdk/jdk/classfile/OpcodesValidationTest.java b/test/jdk/jdk/classfile/OpcodesValidationTest.java index 085ba631349..f44bdfd2725 100644 --- a/test/jdk/jdk/classfile/OpcodesValidationTest.java +++ b/test/jdk/jdk/classfile/OpcodesValidationTest.java @@ -107,7 +107,7 @@ public class OpcodesValidationTest { cb -> cb.withFlags(AccessFlag.PUBLIC) .withMethod("", 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("", MethodTypeDesc.of(CD_void), 0, mb -> mb .withCode( - codeb -> codeb.constantInstruction(opcode, (ConstantDesc)constant)))); + codeb -> codeb.loadConstant(opcode, (ConstantDesc)constant)))); } } diff --git a/test/jdk/jdk/classfile/PrimitiveClassConstantTest.java b/test/jdk/jdk/classfile/PrimitiveClassConstantTest.java index 376fe389826..89cf43751f8 100644 --- a/test/jdk/jdk/classfile/PrimitiveClassConstantTest.java +++ b/test/jdk/jdk/classfile/PrimitiveClassConstantTest.java @@ -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 -> { diff --git a/test/jdk/jdk/classfile/ShortJumpsFixTest.java b/test/jdk/jdk/classfile/ShortJumpsFixTest.java index 15a777bf713..a259795b551 100644 --- a/test/jdk/jdk/classfile/ShortJumpsFixTest.java +++ b/test/jdk/jdk/classfile/ShortJumpsFixTest.java @@ -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); })); } diff --git a/test/jdk/jdk/classfile/StackMapsTest.java b/test/jdk/jdk/classfile/StackMapsTest.java index 88858ce8394..b3df31291bc 100644 --- a/test/jdk/jdk/classfile/StackMapsTest.java +++ b/test/jdk/jdk/classfile/StackMapsTest.java @@ -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(); }))); diff --git a/test/jdk/jdk/classfile/StackTrackerTest.java b/test/jdk/jdk/classfile/StackTrackerTest.java index 15a5fe490ba..ba472231079 100644 --- a/test/jdk/jdk/classfile/StackTrackerTest.java +++ b/test/jdk/jdk/classfile/StackTrackerTest.java @@ -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(); diff --git a/test/jdk/jdk/classfile/TempConstantPoolBuilderTest.java b/test/jdk/jdk/classfile/TempConstantPoolBuilderTest.java index 0c324846647..f2debf041e4 100644 --- a/test/jdk/jdk/classfile/TempConstantPoolBuilderTest.java +++ b/test/jdk/jdk/classfile/TempConstantPoolBuilderTest.java @@ -58,9 +58,9 @@ class TempConstantPoolBuilderTest { cb.withFlags(AccessFlag.PUBLIC) .with(SourceFileAttribute.of(cb.constantPool().utf8Entry(("MyClass.java")))) .withMethod("", MethodTypeDesc.of(CD_void), 0, mb -> mb - .withCode(codeb -> codeb.loadInstruction(TypeKind.ReferenceType, 0) - .invokeInstruction(INVOKESPECIAL, CD_Object, "", MTD_VOID, false) - .returnInstruction(VoidType) + .withCode(codeb -> codeb.aload(0) + .invokespecial(CD_Object, "", MTD_VOID, false) + .return_() ) .with(RuntimeVisibleAnnotationsAttribute.of(Annotation.of(INTERFACE, AnnotationElement.ofString("foo", "bar")))) diff --git a/test/jdk/jdk/classfile/TransformTests.java b/test/jdk/jdk/classfile/TransformTests.java index 31e75dc2ef2..13abca0ec52 100644 --- a/test/jdk/jdk/classfile/TransformTests.java +++ b/test/jdk/jdk/classfile/TransformTests.java @@ -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); diff --git a/test/jdk/jdk/classfile/Utf8EntryTest.java b/test/jdk/jdk/classfile/Utf8EntryTest.java index e4cc5664992..82815755761 100644 --- a/test/jdk/jdk/classfile/Utf8EntryTest.java +++ b/test/jdk/jdk/classfile/Utf8EntryTest.java @@ -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_()))); } } diff --git a/test/jdk/jdk/classfile/WriteTest.java b/test/jdk/jdk/classfile/WriteTest.java index afd5c9f5e34..b4af9135d12 100644 --- a/test/jdk/jdk/classfile/WriteTest.java +++ b/test/jdk/jdk/classfile/WriteTest.java @@ -54,10 +54,10 @@ class WriteTest { cb.withFlags(AccessFlag.PUBLIC); cb.with(SourceFileAttribute.of(cb.constantPool().utf8Entry(("MyClass.java")))) .withMethod("", MethodTypeDesc.of(CD_void), 0, mb -> mb - .withCode(codeb -> codeb.loadInstruction(TypeKind.ReferenceType, 0) - .invokeInstruction(INVOKESPECIAL, CD_Object, "", + .withCode(codeb -> codeb.aload(0) + .invokespecial(CD_Object, "", 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("", MethodTypeDesc.of(CD_void), 0, mb -> mb - .withCode(codeb -> codeb.loadInstruction(ReferenceType, 0) - .invokeInstruction(INVOKESPECIAL, CD_Object, "", MTD_VOID, false) - .returnInstruction(VoidType) + .withCode(codeb -> codeb.aload(0) + .invokespecial(CD_Object, "", 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_(); })); }); } diff --git a/test/jdk/jdk/classfile/examples/ExampleGallery.java b/test/jdk/jdk/classfile/examples/ExampleGallery.java index cb155e6f64a..736725eeebe 100644 --- a/test/jdk/jdk/classfile/examples/ExampleGallery.java +++ b/test/jdk/jdk/classfile/examples/ExampleGallery.java @@ -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); diff --git a/test/jdk/jdk/classfile/helpers/InstructionModelToCodeBuilder.java b/test/jdk/jdk/classfile/helpers/InstructionModelToCodeBuilder.java index 828862ef2cc..d7d9e9c267f 100644 --- a/test/jdk/jdk/classfile/helpers/InstructionModelToCodeBuilder.java +++ b/test/jdk/jdk/classfile/helpers/InstructionModelToCodeBuilder.java @@ -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 -> diff --git a/test/jdk/jdk/classfile/helpers/RebuildingTransformation.java b/test/jdk/jdk/classfile/helpers/RebuildingTransformation.java index 88958939317..85fac494066 100644 --- a/test/jdk/jdk/classfile/helpers/RebuildingTransformation.java +++ b/test/jdk/jdk/classfile/helpers/RebuildingTransformation.java @@ -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"); } } diff --git a/test/jdk/jdk/classfile/helpers/Transforms.java b/test/jdk/jdk/classfile/helpers/Transforms.java index a08c5d25717..64b4836d50a 100644 --- a/test/jdk/jdk/classfile/helpers/Transforms.java +++ b/test/jdk/jdk/classfile/helpers/Transforms.java @@ -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) { diff --git a/test/jdk/jdk/lambda/separate/ClassToInterfaceConverter.java b/test/jdk/jdk/lambda/separate/ClassToInterfaceConverter.java index 44c5c6ab179..26c17901281 100644 --- a/test/jdk/jdk/lambda/separate/ClassToInterfaceConverter.java +++ b/test/jdk/jdk/lambda/separate/ClassToInterfaceConverter.java @@ -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); diff --git a/test/micro/org/openjdk/bench/java/lang/invoke/LazyStaticColdStart.java b/test/micro/org/openjdk/bench/java/lang/invoke/LazyStaticColdStart.java index 45fc67aea25..fb73901adf4 100644 --- a/test/micro/org/openjdk/bench/java/lang/invoke/LazyStaticColdStart.java +++ b/test/micro/org/openjdk/bench/java/lang/invoke/LazyStaticColdStart.java @@ -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); diff --git a/test/micro/org/openjdk/bench/jdk/classfile/RebuildMethodBodies.java b/test/micro/org/openjdk/bench/jdk/classfile/RebuildMethodBodies.java index 4c657b961b1..d5e77c1a2a7 100644 --- a/test/micro/org/openjdk/bench/jdk/classfile/RebuildMethodBodies.java +++ b/test/micro/org/openjdk/bench/jdk/classfile/RebuildMethodBodies.java @@ -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); } })); diff --git a/test/micro/org/openjdk/bench/jdk/classfile/Transforms.java b/test/micro/org/openjdk/bench/jdk/classfile/Transforms.java index b5582bcf52e..def55b5f20c 100644 --- a/test/micro/org/openjdk/bench/jdk/classfile/Transforms.java +++ b/test/micro/org/openjdk/bench/jdk/classfile/Transforms.java @@ -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) { diff --git a/test/micro/org/openjdk/bench/jdk/classfile/Write.java b/test/micro/org/openjdk/bench/jdk/classfile/Write.java index 96aafb6f38e..59d07b05927 100644 --- a/test/micro/org/openjdk/bench/jdk/classfile/Write.java +++ b/test/micro/org/openjdk/bench/jdk/classfile/Write.java @@ -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_(); })); } });