1 /*
  2  * Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  5  * This code is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.  Oracle designates this
  8  * particular file as subject to the "Classpath" exception as provided
  9  * by Oracle in the LICENSE file that accompanied this code.
 10  *
 11  * This code is distributed in the hope that it will be useful, but WITHOUT
 12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 14  * version 2 for more details (a copy is included in the LICENSE file that
 15  * accompanied this code).
 16  *
 17  * You should have received a copy of the GNU General Public License version
 18  * 2 along with this work; if not, write to the Free Software Foundation,
 19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 20  *
 21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 22  * or visit www.oracle.com if you need additional information or have any
 23  * questions.
 24  */
 25 package jdk.internal.classfile.impl;
 26 
 27 import java.lang.classfile.*;
 28 import java.lang.classfile.attribute.CodeAttribute;
 29 import java.lang.classfile.attribute.RuntimeInvisibleTypeAnnotationsAttribute;
 30 import java.lang.classfile.attribute.RuntimeVisibleTypeAnnotationsAttribute;
 31 import java.lang.classfile.attribute.StackMapTableAttribute;
 32 import java.lang.classfile.constantpool.ClassEntry;
 33 import java.lang.classfile.instruction.*;
 34 import java.util.ArrayList;
 35 import java.util.Collections;
 36 import java.util.List;
 37 import java.util.Objects;
 38 import java.util.Optional;
 39 import java.util.function.Consumer;
 40 
 41 import static jdk.internal.classfile.impl.RawBytecodeHelper.*;
 42 
 43 public final class CodeImpl
 44         extends BoundAttribute.BoundCodeAttribute
 45         implements LabelContext {
 46 
 47     static final Instruction[] SINGLETON_INSTRUCTIONS = new Instruction[256];
 48 
 49     static {
 50         for (var o : Opcode.values()) {
 51             if (o.sizeIfFixed() == 1) {
 52                 SINGLETON_INSTRUCTIONS[o.bytecode()] = switch (o.kind()) {
 53                     case ARRAY_LOAD -> ArrayLoadInstruction.of(o);
 54                     case ARRAY_STORE -> ArrayStoreInstruction.of(o);
 55                     case CONSTANT -> ConstantInstruction.ofIntrinsic(o);
 56                     case CONVERT -> ConvertInstruction.of(o);
 57                     case LOAD -> new AbstractInstruction.UnboundLoadInstruction(o, BytecodeHelpers.intrinsicLoadSlot(o));
 58                     case MONITOR -> MonitorInstruction.of(o);
 59                     case NOP -> NopInstruction.of();
 60                     case OPERATOR -> OperatorInstruction.of(o);
 61                     case RETURN -> ReturnInstruction.of(o);
 62                     case STACK -> StackInstruction.of(o);
 63                     case STORE -> new AbstractInstruction.UnboundStoreInstruction(o, BytecodeHelpers.intrinsicStoreSlot(o));
 64                     case THROW_EXCEPTION -> ThrowInstruction.of();
 65                     default -> throw new AssertionError("invalid opcode: " + o);
 66                 };
 67             }
 68         }
 69     }
 70 
 71     List<ExceptionCatch> exceptionTable;
 72     List<Attribute<?>> attributes;
 73 
 74     // Inflated for iteration
 75     LabelImpl[] labels;
 76     int[] lineNumbers;
 77     boolean inflated;
 78 
 79     public CodeImpl(AttributedElement enclosing,
 80                     ClassReader reader,
 81                     AttributeMapper<CodeAttribute> mapper,
 82                     int payloadStart) {
 83         super(enclosing, reader, mapper, payloadStart);
 84     }
 85 
 86     // LabelContext
 87 
 88     @Override
 89     public Label newLabel() {
 90         throw new UnsupportedOperationException("CodeAttribute only supports fixed labels");
 91     }
 92 
 93     @Override
 94     public void setLabelTarget(Label label, int bci) {
 95         throw new UnsupportedOperationException("CodeAttribute only supports fixed labels");
 96     }
 97 
 98     @Override
 99     public Label getLabel(int bci) {
100         if (bci < 0 || bci > codeLength)
101             throw new IllegalArgumentException(String.format("Bytecode offset out of range; bci=%d, codeLength=%d",
102                                                              bci, codeLength));
103         if (labels == null)
104             labels = new LabelImpl[codeLength + 1];
105         LabelImpl l = labels[bci];
106         if (l == null)
107             l = labels[bci] = new LabelImpl(this, bci);
108         return l;
109     }
110 
111     @Override
112     public int labelToBci(Label label) {
113         LabelImpl lab = (LabelImpl) label;
114         if (lab.labelContext() != this)
115             throw new IllegalArgumentException(String.format("Illegal label reuse; context=%s, label=%s",
116                                                              this, lab.labelContext()));
117         return lab.getBCI();
118     }
119 
120     private void inflateMetadata() {
121         if (!inflated) {
122             if (labels == null)
123                 labels = new LabelImpl[codeLength + 1];
124             if (classReader.context().passLineNumbers())
125                 inflateLineNumbers();
126             inflateJumpTargets();
127             inflateTypeAnnotations();
128             inflated = true;
129         }
130     }
131 
132     // CodeAttribute
133 
134     @Override
135     public List<Attribute<?>> attributes() {
136         if (attributes == null) {
137             attributes = BoundAttribute.readAttributes(this, classReader, attributePos, classReader.customAttributes());
138         }
139         return attributes;
140     }
141 
142     @Override
143     public void writeTo(BufWriterImpl buf) {
144         if (buf.canWriteDirect(classReader)) {
145             super.writeTo(buf);
146         }
147         else {
148             DirectCodeBuilder.build((MethodInfo) enclosingMethod,
149                                     Util.writingAll(this),
150                                     (SplitConstantPool)buf.constantPool(),
151                                     buf.context(),
152                                     null).writeTo(buf);
153         }
154     }
155 
156     // CodeModel
157 
158     @Override
159     public Optional<MethodModel> parent() {
160         return Optional.of(enclosingMethod);
161     }
162 
163     @Override
164     public void forEach(Consumer<? super CodeElement> consumer) {
165         Objects.requireNonNull(consumer);
166         inflateMetadata();
167         boolean doLineNumbers = (lineNumbers != null);
168         generateCatchTargets(consumer);
169         if (classReader.context().passDebugElements())
170             generateDebugElements(consumer);
171         for (int pos=codeStart; pos<codeEnd; ) {
172             if (labels[pos - codeStart] != null)
173                 consumer.accept(labels[pos - codeStart]);
174             if (doLineNumbers && lineNumbers[pos - codeStart] != 0)
175                 consumer.accept(LineNumberImpl.of(lineNumbers[pos - codeStart]));
176             int bc = classReader.readU1(pos);
177             Instruction instr = bcToInstruction(bc, pos);
178             consumer.accept(instr);
179             pos += instr.sizeInBytes();
180         }
181         // There might be labels pointing to the bci at codeEnd
182         if (labels[codeEnd-codeStart] != null)
183             consumer.accept(labels[codeEnd - codeStart]);
184         if (doLineNumbers && lineNumbers[codeEnd - codeStart] != 0)
185             consumer.accept(LineNumberImpl.of(lineNumbers[codeEnd - codeStart]));
186     }
187 
188     @Override
189     public List<ExceptionCatch> exceptionHandlers() {
190         if (exceptionTable == null) {
191             inflateMetadata();
192             exceptionTable = new ArrayList<>(exceptionHandlerCnt);
193             iterateExceptionHandlers(new ExceptionHandlerAction() {
194                 @Override
195                 public void accept(int s, int e, int h, int c) {
196                     ClassEntry catchTypeEntry = c == 0
197                                                              ? null
198                                                              : constantPool().entryByIndex(c, ClassEntry.class);
199                     exceptionTable.add(new AbstractPseudoInstruction.ExceptionCatchImpl(getLabel(h), getLabel(s), getLabel(e), catchTypeEntry));
200                 }
201             });
202             exceptionTable = Collections.unmodifiableList(exceptionTable);
203         }
204         return exceptionTable;
205     }
206 
207     public boolean compareCodeBytes(BufWriterImpl buf, int offset, int len) {
208         return codeLength == len
209                && classReader.compare(buf, offset, codeStart, codeLength);
210     }
211 
212     private int adjustForObjectOrUninitialized(int bci) {
213         int vt = classReader.readU1(bci);
214         //inflate newTarget labels from Uninitialized VTIs
215         if (vt == 8) inflateLabel(classReader.readU2(bci + 1));
216         return (vt == 7 || vt == 8) ? bci + 3 : bci + 1;
217     }
218 
219     private void inflateLabel(int bci) {
220         if (bci < 0 || bci > codeLength)
221             throw new IllegalArgumentException(String.format("Bytecode offset out of range; bci=%d, codeLength=%d",
222                                                              bci, codeLength));
223         if (labels[bci] == null)
224             labels[bci] = new LabelImpl(this, bci);
225     }
226 
227     private void inflateLineNumbers() {
228         for (Attribute<?> a : attributes()) {
229             if (a.attributeMapper() == Attributes.lineNumberTable()) {
230                 BoundLineNumberTableAttribute attr = (BoundLineNumberTableAttribute) a;
231                 if (lineNumbers == null)
232                     lineNumbers = new int[codeLength + 1];
233 
234                 int nLn = classReader.readU2(attr.payloadStart);
235                 int p = attr.payloadStart + 2;
236                 int pEnd = p + (nLn * 4);
237                 for (; p < pEnd; p += 4) {
238                     int startPc = classReader.readU2(p);
239                     if (startPc > codeLength) {
240                         throw new IllegalArgumentException(String.format(
241                                 "Line number start_pc out of range; start_pc=%d, codeLength=%d", startPc, codeLength));
242                     }
243                     int lineNumber = classReader.readU2(p + 2);
244                     lineNumbers[startPc] = lineNumber;
245                 }
246             }
247         }
248     }
249 
250     private void inflateJumpTargets() {
251         Optional<StackMapTableAttribute> a = findAttribute(Attributes.stackMapTable());
252         if (a.isEmpty()) {
253             if (classReader.readU2(6) <= ClassFile.JAVA_6_VERSION) {
254                 //fallback to jump targets inflation without StackMapTableAttribute
255                 for (int pos=codeStart; pos<codeEnd; ) {
256                     var i = bcToInstruction(classReader.readU1(pos), pos);
257                     switch (i) {
258                         case BranchInstruction br -> br.target();
259                         case DiscontinuedInstruction.JsrInstruction jsr -> jsr.target();
260                         case LookupSwitchInstruction ls -> {
261                             ls.defaultTarget();
262                             ls.cases();
263                         }
264                         case TableSwitchInstruction ts -> {
265                             ts.defaultTarget();
266                             ts.cases();
267                         }
268                         default -> {}
269                     }
270                     pos += i.sizeInBytes();
271                 }
272             }
273             return;
274         }
275         int stackMapPos = ((BoundAttribute<StackMapTableAttribute>) a.get()).payloadStart;
276 
277         int bci = -1; //compensate for offsetDelta + 1
278         int nEntries = classReader.readU2(stackMapPos);
279         int p = stackMapPos + 2;
280         for (int i = 0; i < nEntries; ++i) {
281             int frameType = classReader.readU1(p);
282             int offsetDelta;
283             if (frameType < 64) {
284                 offsetDelta = frameType;
285                 ++p;
286             }
287             else if (frameType < 128) {
288                 offsetDelta = frameType & 0x3f;
289                 p = adjustForObjectOrUninitialized(p + 1);
290             }
291             else
292                 switch (frameType) {
293                     case 247 -> {
294                         offsetDelta = classReader.readU2(p + 1);
295                         p = adjustForObjectOrUninitialized(p + 3);
296                     }
297                     case 248, 249, 250, 251 -> {
298                         offsetDelta = classReader.readU2(p + 1);
299                         p += 3;
300                     }
301                     case 252, 253, 254 -> {
302                         offsetDelta = classReader.readU2(p + 1);
303                         int k = frameType - 251;
304                         p += 3;
305                         for (int c = 0; c < k; ++c) {
306                             p = adjustForObjectOrUninitialized(p);
307                         }
308                     }
309                     case 255 -> {
310                         offsetDelta = classReader.readU2(p + 1);
311                         p += 3;
312                         int k = classReader.readU2(p);
313                         p += 2;
314                         for (int c = 0; c < k; ++c) {
315                             p = adjustForObjectOrUninitialized(p);
316                         }
317                         k = classReader.readU2(p);
318                         p += 2;
319                         for (int c = 0; c < k; ++c) {
320                             p = adjustForObjectOrUninitialized(p);
321                         }
322                     }
323                     default -> throw new IllegalArgumentException("Bad frame type: " + frameType);
324                 }
325             bci += offsetDelta + 1;
326             inflateLabel(bci);
327         }
328     }
329 
330     private void inflateTypeAnnotations() {
331         findAttribute(Attributes.runtimeVisibleTypeAnnotations()).ifPresent(RuntimeVisibleTypeAnnotationsAttribute::annotations);
332         findAttribute(Attributes.runtimeInvisibleTypeAnnotations()).ifPresent(RuntimeInvisibleTypeAnnotationsAttribute::annotations);
333     }
334 
335     private void generateCatchTargets(Consumer<? super CodeElement> consumer) {
336         // We attach all catch targets to bci zero, because trying to attach them
337         // to their range could subtly affect the order of exception processing
338         iterateExceptionHandlers(new ExceptionHandlerAction() {
339             @Override
340             public void accept(int s, int e, int h, int c) {
341                 ClassEntry catchType = c == 0
342                                                     ? null
343                                                     : classReader.entryByIndex(c, ClassEntry.class);
344                 consumer.accept(new AbstractPseudoInstruction.ExceptionCatchImpl(getLabel(h), getLabel(s), getLabel(e), catchType));
345             }
346         });
347     }
348 
349     private void generateDebugElements(Consumer<? super CodeElement> consumer) {
350         for (Attribute<?> a : attributes()) {
351             if (a.attributeMapper() == Attributes.characterRangeTable()) {
352                 var attr = (BoundCharacterRangeTableAttribute) a;
353                 int cnt = classReader.readU2(attr.payloadStart);
354                 int p = attr.payloadStart + 2;
355                 int pEnd = p + (cnt * 14);
356                 for (; p < pEnd; p += 14) {
357                     var instruction = new BoundCharacterRange(this, p);
358                     inflateLabel(instruction.startPc());
359                     inflateLabel(instruction.endPc() + 1);
360                     consumer.accept(instruction);
361                 }
362             }
363             else if (a.attributeMapper() == Attributes.localVariableTable()) {
364                 var attr = (BoundLocalVariableTableAttribute) a;
365                 int cnt = classReader.readU2(attr.payloadStart);
366                 int p = attr.payloadStart + 2;
367                 int pEnd = p + (cnt * 10);
368                 for (; p < pEnd; p += 10) {
369                     BoundLocalVariable instruction = new BoundLocalVariable(this, p);
370                     inflateLabel(instruction.startPc());
371                     inflateLabel(instruction.startPc() + instruction.length());
372                     consumer.accept(instruction);
373                 }
374             }
375             else if (a.attributeMapper() == Attributes.localVariableTypeTable()) {
376                 var attr = (BoundLocalVariableTypeTableAttribute) a;
377                 int cnt = classReader.readU2(attr.payloadStart);
378                 int p = attr.payloadStart + 2;
379                 int pEnd = p + (cnt * 10);
380                 for (; p < pEnd; p += 10) {
381                     BoundLocalVariableType instruction = new BoundLocalVariableType(this, p);
382                     inflateLabel(instruction.startPc());
383                     inflateLabel(instruction.startPc() + instruction.length());
384                     consumer.accept(instruction);
385                 }
386             }
387             else if (a.attributeMapper() == Attributes.runtimeVisibleTypeAnnotations()) {
388                 consumer.accept((BoundRuntimeVisibleTypeAnnotationsAttribute) a);
389             }
390             else if (a.attributeMapper() == Attributes.runtimeInvisibleTypeAnnotations()) {
391                 consumer.accept((BoundRuntimeInvisibleTypeAnnotationsAttribute) a);
392             }
393         }
394     }
395 
396     public interface ExceptionHandlerAction {
397         void accept(int start, int end, int handler, int catchTypeIndex);
398     }
399 
400     public void iterateExceptionHandlers(ExceptionHandlerAction a) {
401         int p = exceptionHandlerPos + 2;
402         for (int i = 0; i < exceptionHandlerCnt; ++i) {
403             a.accept(classReader.readU2(p), classReader.readU2(p + 2), classReader.readU2(p + 4), classReader.readU2(p + 6));
404             p += 8;
405         }
406     }
407 
408     private Instruction bcToInstruction(int bc, int pos) {
409         return switch (bc) {
410             case BIPUSH -> new AbstractInstruction.BoundArgumentConstantInstruction(Opcode.BIPUSH, CodeImpl.this, pos);
411             case SIPUSH -> new AbstractInstruction.BoundArgumentConstantInstruction(Opcode.SIPUSH, CodeImpl.this, pos);
412             case LDC -> new AbstractInstruction.BoundLoadConstantInstruction(Opcode.LDC, CodeImpl.this, pos);
413             case LDC_W -> new AbstractInstruction.BoundLoadConstantInstruction(Opcode.LDC_W, CodeImpl.this, pos);
414             case LDC2_W -> new AbstractInstruction.BoundLoadConstantInstruction(Opcode.LDC2_W, CodeImpl.this, pos);
415             case ILOAD -> new AbstractInstruction.BoundLoadInstruction(Opcode.ILOAD, CodeImpl.this, pos);
416             case LLOAD -> new AbstractInstruction.BoundLoadInstruction(Opcode.LLOAD, CodeImpl.this, pos);
417             case FLOAD -> new AbstractInstruction.BoundLoadInstruction(Opcode.FLOAD, CodeImpl.this, pos);
418             case DLOAD -> new AbstractInstruction.BoundLoadInstruction(Opcode.DLOAD, CodeImpl.this, pos);
419             case ALOAD -> new AbstractInstruction.BoundLoadInstruction(Opcode.ALOAD, CodeImpl.this, pos);
420             case ISTORE -> new AbstractInstruction.BoundStoreInstruction(Opcode.ISTORE, CodeImpl.this, pos);
421             case LSTORE -> new AbstractInstruction.BoundStoreInstruction(Opcode.LSTORE, CodeImpl.this, pos);
422             case FSTORE -> new AbstractInstruction.BoundStoreInstruction(Opcode.FSTORE, CodeImpl.this, pos);
423             case DSTORE -> new AbstractInstruction.BoundStoreInstruction(Opcode.DSTORE, CodeImpl.this, pos);
424             case ASTORE -> new AbstractInstruction.BoundStoreInstruction(Opcode.ASTORE, CodeImpl.this, pos);
425             case IINC -> new AbstractInstruction.BoundIncrementInstruction(Opcode.IINC, CodeImpl.this, pos);
426             case IFEQ -> new AbstractInstruction.BoundBranchInstruction(Opcode.IFEQ, CodeImpl.this, pos);
427             case IFNE -> new AbstractInstruction.BoundBranchInstruction(Opcode.IFNE, CodeImpl.this, pos);
428             case IFLT -> new AbstractInstruction.BoundBranchInstruction(Opcode.IFLT, CodeImpl.this, pos);
429             case IFGE -> new AbstractInstruction.BoundBranchInstruction(Opcode.IFGE, CodeImpl.this, pos);
430             case IFGT -> new AbstractInstruction.BoundBranchInstruction(Opcode.IFGT, CodeImpl.this, pos);
431             case IFLE -> new AbstractInstruction.BoundBranchInstruction(Opcode.IFLE, CodeImpl.this, pos);
432             case IF_ICMPEQ -> new AbstractInstruction.BoundBranchInstruction(Opcode.IF_ICMPEQ, CodeImpl.this, pos);
433             case IF_ICMPNE -> new AbstractInstruction.BoundBranchInstruction(Opcode.IF_ICMPNE, CodeImpl.this, pos);
434             case IF_ICMPLT -> new AbstractInstruction.BoundBranchInstruction(Opcode.IF_ICMPLT, CodeImpl.this, pos);
435             case IF_ICMPGE -> new AbstractInstruction.BoundBranchInstruction(Opcode.IF_ICMPGE, CodeImpl.this, pos);
436             case IF_ICMPGT -> new AbstractInstruction.BoundBranchInstruction(Opcode.IF_ICMPGT, CodeImpl.this, pos);
437             case IF_ICMPLE -> new AbstractInstruction.BoundBranchInstruction(Opcode.IF_ICMPLE, CodeImpl.this, pos);
438             case IF_ACMPEQ -> new AbstractInstruction.BoundBranchInstruction(Opcode.IF_ACMPEQ, CodeImpl.this, pos);
439             case IF_ACMPNE -> new AbstractInstruction.BoundBranchInstruction(Opcode.IF_ACMPNE, CodeImpl.this, pos);
440             case GOTO -> new AbstractInstruction.BoundBranchInstruction(Opcode.GOTO, CodeImpl.this, pos);
441             case TABLESWITCH -> new AbstractInstruction.BoundTableSwitchInstruction(Opcode.TABLESWITCH, CodeImpl.this, pos);
442             case LOOKUPSWITCH -> new AbstractInstruction.BoundLookupSwitchInstruction(Opcode.LOOKUPSWITCH, CodeImpl.this, pos);
443             case GETSTATIC -> new AbstractInstruction.BoundFieldInstruction(Opcode.GETSTATIC, CodeImpl.this, pos);
444             case PUTSTATIC -> new AbstractInstruction.BoundFieldInstruction(Opcode.PUTSTATIC, CodeImpl.this, pos);
445             case GETFIELD -> new AbstractInstruction.BoundFieldInstruction(Opcode.GETFIELD, CodeImpl.this, pos);
446             case PUTFIELD -> new AbstractInstruction.BoundFieldInstruction(Opcode.PUTFIELD, CodeImpl.this, pos);
447             case INVOKEVIRTUAL -> new AbstractInstruction.BoundInvokeInstruction(Opcode.INVOKEVIRTUAL, CodeImpl.this, pos);
448             case INVOKESPECIAL -> new AbstractInstruction.BoundInvokeInstruction(Opcode.INVOKESPECIAL, CodeImpl.this, pos);
449             case INVOKESTATIC -> new AbstractInstruction.BoundInvokeInstruction(Opcode.INVOKESTATIC, CodeImpl.this, pos);
450             case INVOKEINTERFACE -> new AbstractInstruction.BoundInvokeInterfaceInstruction(Opcode.INVOKEINTERFACE, CodeImpl.this, pos);
451             case INVOKEDYNAMIC -> new AbstractInstruction.BoundInvokeDynamicInstruction(Opcode.INVOKEDYNAMIC, CodeImpl.this, pos);
452             case NEW -> new AbstractInstruction.BoundNewObjectInstruction(CodeImpl.this, pos);
453             case NEWARRAY -> new AbstractInstruction.BoundNewPrimitiveArrayInstruction(Opcode.NEWARRAY, CodeImpl.this, pos);
454             case ANEWARRAY -> new AbstractInstruction.BoundNewReferenceArrayInstruction(Opcode.ANEWARRAY, CodeImpl.this, pos);
455             case CHECKCAST -> new AbstractInstruction.BoundTypeCheckInstruction(Opcode.CHECKCAST, CodeImpl.this, pos);
456             case INSTANCEOF -> new AbstractInstruction.BoundTypeCheckInstruction(Opcode.INSTANCEOF, CodeImpl.this, pos);
457 
458             case WIDE -> {
459                 int bclow = classReader.readU1(pos + 1);
460                 yield switch (bclow) {
461                     case ILOAD -> new AbstractInstruction.BoundLoadInstruction(Opcode.ILOAD_W, this, pos);
462                     case LLOAD -> new AbstractInstruction.BoundLoadInstruction(Opcode.LLOAD_W, this, pos);
463                     case FLOAD -> new AbstractInstruction.BoundLoadInstruction(Opcode.FLOAD_W, this, pos);
464                     case DLOAD -> new AbstractInstruction.BoundLoadInstruction(Opcode.DLOAD_W, this, pos);
465                     case ALOAD -> new AbstractInstruction.BoundLoadInstruction(Opcode.ALOAD_W, this, pos);
466                     case ISTORE -> new AbstractInstruction.BoundStoreInstruction(Opcode.ISTORE_W, this, pos);
467                     case LSTORE -> new AbstractInstruction.BoundStoreInstruction(Opcode.LSTORE_W, this, pos);
468                     case FSTORE -> new AbstractInstruction.BoundStoreInstruction(Opcode.FSTORE_W, this, pos);
469                     case DSTORE -> new AbstractInstruction.BoundStoreInstruction(Opcode.DSTORE_W, this, pos);
470                     case ASTORE -> new AbstractInstruction.BoundStoreInstruction(Opcode.ASTORE_W, this, pos);
471                     case IINC -> new AbstractInstruction.BoundIncrementInstruction(Opcode.IINC_W, this, pos);
472                     case RET ->  new AbstractInstruction.BoundRetInstruction(Opcode.RET_W, this, pos);
473                     default -> throw new IllegalArgumentException("unknown wide instruction: " + bclow);
474                 };
475             }
476 
477             case MULTIANEWARRAY -> new AbstractInstruction.BoundNewMultidimensionalArrayInstruction(Opcode.MULTIANEWARRAY, CodeImpl.this, pos);
478             case IFNULL -> new AbstractInstruction.BoundBranchInstruction(Opcode.IFNULL, CodeImpl.this, pos);
479             case IFNONNULL -> new AbstractInstruction.BoundBranchInstruction(Opcode.IFNONNULL, CodeImpl.this, pos);
480             case GOTO_W -> new AbstractInstruction.BoundBranchInstruction(Opcode.GOTO_W, CodeImpl.this, pos);
481 
482             case JSR -> new AbstractInstruction.BoundJsrInstruction(Opcode.JSR, CodeImpl.this, pos);
483             case RET ->  new AbstractInstruction.BoundRetInstruction(Opcode.RET, this, pos);
484             case JSR_W -> new AbstractInstruction.BoundJsrInstruction(Opcode.JSR_W, CodeImpl.this, pos);
485             default -> {
486                 Instruction instr = SINGLETON_INSTRUCTIONS[bc];
487                 if (instr == null)
488                     throw new IllegalArgumentException("unknown instruction: " + bc);
489                 yield instr;
490             }
491         };
492     }
493 
494     @Override
495     public String toString() {
496         return String.format("CodeModel[id=%d]", System.identityHashCode(this));
497     }
498 }