Lines Matching refs:code
21 * An iterator for editing a code attribute.
23 * <p>If there are multiple <code>CodeIterator</code>s referring to the
24 * same <code>Code_attribute</code>, then inserting a gap by one
25 * <code>CodeIterator</code> will break the other
26 * <code>CodeIterator</code>.
28 * <p>This iterator does not provide <code>remove()</code>.
29 * If a piece of code in a <code>Code_attribute</code> is unnecessary,
30 * it should be overwritten with <code>NOP</code>.
59 * The successive call to <code>next()</code>
60 * returns the index that has been given to <code>move()</code>.
63 * <code>get().getCode()</code>.
74 * when code blocks are inserted.
75 * If a code block is inclusively inserted at the position of the
76 * bytecode, the mark is set to the inserted code block.
87 * <code>setMark</code>.
96 * Returns a Code attribute read with this iterator.
103 * Returns <code>code_length</code> of <code>Code_attribute</code>.
159 * @param code may be a zero-length array.
161 public void write(byte[] code, int index) {
162 int len = code.length;
164 bytecode[index++] = code[j];
177 * <code>get().getCode()</code>.
190 * to <code>next()</code> will return.
193 * Successive calls to <code>lookAhead()</code> return the
194 * same value until <code>next()</code> is called.
202 * either <code>super()</code> or <code>this()</code>.
205 * to <code>super()</code> or <code>this()</code>, which should be
209 * executing <code>super()</code> or <code>this()</code>.
210 * A successive call to <code>next()</code> returns the
223 * Moves to the instruction for <code>super()</code>.
226 * <code>super()</code>, which should be
230 * executing <code>super()</code>.
231 * A successive call to <code>next()</code> returns the
238 * but <code>this()</code> is found.
245 * Moves to the instruction for <code>this()</code>.
248 * <code>this()</code>, which should be
252 * executing <code>this()</code>.
253 * A successive call to <code>next()</code> returns the
260 * but <code>super()</code> is found.
301 * <code>next()</code> (not before the instruction returned
302 * by the last call to <code>next()</code>).
309 * bytecode sequence for adjusting alignment if the code attribute
310 * includes <code>LOOKUPSWITCH</code> or <code>TABLESWITCH</code>.
312 * @param code inserted bytecode sequence.
316 public int insert(byte[] code)
319 return insert0(currentPos, code, false);
324 * before the instruction at the given index <code>pos</code>.
332 * bytecode sequence for adjusting alignment if the code attribute
333 * includes <code>LOOKUPSWITCH</code> or <code>TABLESWITCH</code>.
337 * inserted at other positions (e.g. to change <code>GOTO</code>
338 * to <code>GOTO_W</code>).
341 * @param code inserted bytecode sequence.
343 public void insert(int pos, byte[] code) throws BadBytecode {
344 insert0(pos, code, false);
349 * before the instruction at the given index <code>pos</code>.
357 * bytecode sequence for adjusting alignment if the code attribute
358 * includes <code>LOOKUPSWITCH</code> or <code>TABLESWITCH</code>.
361 * @param code inserted bytecode sequence.
367 public int insertAt(int pos, byte[] code) throws BadBytecode {
368 return insert0(pos, code, false);
374 * <code>next()</code> (not before the instruction returned
375 * by tha last call to <code>next()</code>).
382 * bytecode sequence for adjusting alignment if the code attribute
383 * includes <code>LOOKUPSWITCH</code> or <code>TABLESWITCH</code>.
385 * @param code inserted bytecode sequence.
389 public int insertEx(byte[] code)
392 return insert0(currentPos, code, true);
397 * before the instruction at the given index <code>pos</code>.
405 * bytecode sequence for adjusting alignment if the code attribute
406 * includes <code>LOOKUPSWITCH</code> or <code>TABLESWITCH</code>.
410 * inserted at other positions (e.g. to change <code>GOTO</code>
411 * to <code>GOTO_W</code>).
414 * @param code inserted bytecode sequence.
416 public void insertEx(int pos, byte[] code) throws BadBytecode {
417 insert0(pos, code, true);
422 * before the instruction at the given index <code>pos</code>.
430 * bytecode sequence for adjusting alignment if the code attribute
431 * includes <code>LOOKUPSWITCH</code> or <code>TABLESWITCH</code>.
434 * @param code inserted bytecode sequence.
440 public int insertExAt(int pos, byte[] code) throws BadBytecode {
441 return insert0(pos, code, true);
448 private int insert0(int pos, byte[] code, boolean exclusive)
451 int len = code.length;
460 bytecode[p++] = code[j];
468 * <code>next()</code> (not before the instruction returned
469 * by the last call to <code>next()</code>).
486 * index <code>pos</code>.
498 * It might be bigger than <code>length</code>.
507 * <code>next()</code> (not before the instruction returned
508 * by the last call to <code>next()</code>).
525 * index <code>pos</code>.
537 * It might be bigger than <code>length</code>.
562 * at the given index <code>pos</code>.
574 * inserted at other positions (e.g. to change <code>GOTO</code>
575 * to <code>GOTO_W</code>). The index is available from the <code>Gap</code>
580 * <code>next()</code> (not the last instruction returned
581 * by the last call to <code>next()</code>). The next
582 * instruction returned by <code>next()</code> after the gap is
583 * inserted is still the same instruction. It is not <code>NOP</code>
650 * at the beginning of the exception table in the code attribute
653 * @param offset the value added to the code positions included
663 * @param code the bytecode appended.
666 public int append(byte[] code) {
668 int len = code.length;
675 dest[i + size] = code[i];
686 byte[] code = bytecode;
687 int codeLength = code.length;
692 newcode[i] = code[i];
704 * at the end of the exception table in the code attribute
707 * @param offset the value added to the code positions included
735 static int nextOpcode(byte[] code, int index)
740 opcode = code[index] & 0xff;
751 if (code[index + 1] == (byte)IINC) // WIDE IINC
758 int npairs = ByteArray.read32bit(code, index2);
762 int low = ByteArray.read32bit(code, index2);
763 int high = ByteArray.read32bit(code, index2 + 4);
783 * It cannot handle a long code sequence more than 32K. All branch offsets must be
796 static byte[] insertGapCore0(byte[] code, int where, int gapLength,
801 return code;
804 return insertGapCore1(code, where, gapLength, exclusive, etable, ca);
808 return insertGapCore1(code, where, (gapLength + 3) & ~3,
817 private static byte[] insertGapCore1(byte[] code, int where, int gapLength,
822 int codeLength = code.length;
824 insertGap2(code, where, gapLength, codeLength, newcode, exclusive);
853 private static void insertGap2(byte[] code, int where, int gapLength,
867 nextPos = nextOpcode(code, i);
868 int inst = code[i] & 0xff;
873 int offset = (code[i + 1] << 8) | (code[i + 2] & 0xff);
875 newcode[j] = code[i];
881 int offset = ByteArray.read32bit(code, i + 1);
883 newcode[j++] = code[i];
892 // IBM JVM 1.4.2 cannot run the following code:
895 // newcode[j++] = code[i0++];
896 // So extracting this code into an external method.
898 j = copyGapBytes(newcode, j, code, i, i2);
900 int defaultbyte = newOffset(i, ByteArray.read32bit(code, i2),
903 int lowbyte = ByteArray.read32bit(code, i2 + 4);
905 int highbyte = ByteArray.read32bit(code, i2 + 8);
911 int offset = newOffset(i, ByteArray.read32bit(code, i0),
924 // IBM JVM 1.4.2 cannot run the following code:
927 // newcode[j++] = code[i0++];
928 // So extracting this code into an external method.
930 j = copyGapBytes(newcode, j, code, i, i2);
932 int defaultbyte = newOffset(i, ByteArray.read32bit(code, i2),
935 int npairs = ByteArray.read32bit(code, i2 + 4);
941 ByteArray.copy32bit(code, i0, newcode, j);
943 ByteArray.read32bit(code, i0 + 4),
952 newcode[j++] = code[i++];
957 private static int copyGapBytes(byte[] newcode, int j, byte[] code, int i, int iEnd) {
960 newcode[j++] = code[i++];
962 newcode[j++] = code[i++];
964 newcode[j++] = code[i++];
966 newcode[j++] = code[i++];
981 // This code is different from the code in Branch#shiftOffset().
1045 static byte[] changeLdcToLdcW(byte[] code, ExceptionTable etable,
1049 ArrayList jumps = makeJumpList(code, code.length);
1056 byte[] r = insertGap2w(code, 0, 0, false, jumps, pointers);
1074 * insertGapCore0w() can handle a long code sequence more than 32K.
1086 private byte[] insertGapCore0w(byte[] code, int where, int gapLength, boolean exclusive,
1091 return code;
1093 ArrayList jumps = makeJumpList(code, code.length);
1095 byte[] r = insertGap2w(code, where, gapLength, exclusive, jumps, pointers);
1110 private static byte[] insertGap2w(byte[] code, int where, int gapLength,
1151 return makeExapndedCode(code, jumps, where, gapLength);
1154 private static ArrayList makeJumpList(byte[] code, int endPos)
1160 nextPos = nextOpcode(code, i);
1161 int inst = code[i] & 0xff;
1166 int offset = (code[i + 1] << 8) | (code[i + 2] & 0xff);
1177 int offset = ByteArray.read32bit(code, i + 1);
1182 int defaultbyte = ByteArray.read32bit(code, i2);
1183 int lowbyte = ByteArray.read32bit(code, i2 + 4);
1184 int highbyte = ByteArray.read32bit(code, i2 + 8);
1189 offsets[j] = ByteArray.read32bit(code, i0);
1197 int defaultbyte = ByteArray.read32bit(code, i2);
1198 int npairs = ByteArray.read32bit(code, i2 + 4);
1203 matches[j] = ByteArray.read32bit(code, i0);
1204 offsets[j] = ByteArray.read32bit(code, i0 + 4);
1215 private static byte[] makeExapndedCode(byte[] code, ArrayList jumps,
1220 int size = code.length + gapLength;
1228 int len = code.length;
1248 newcode[dest++] = code[src++];
1250 int s = b.write(src, code, dest, newcode);
1283 // This code is different from the code in CodeIterator#newOffset().
1302 abstract int write(int srcPos, byte[] code, int destPos, byte[] newcode);
1327 int write(int srcPos, byte[] code, int destPos, byte[] newcode) {
1365 abstract void write32(int src, byte[] code, int dest, byte[] newcode);
1367 int write(int src, byte[] code, int dest, byte[] newcode) {
1369 write32(src, code, dest, newcode);
1371 newcode[dest] = code[src];
1389 void write32(int src, byte[] code, int dest, byte[] newcode) {
1390 newcode[dest] = (byte)(((code[src] & 0xff) == GOTO) ? GOTO_W : JSR_W);
1405 code, int dest, byte[] newcode) {
1406 newcode[dest] = (byte)opcode(code[src] & 0xff);
1440 int write(int src, byte[] code, int dest, byte[] newcode) {
1441 newcode[dest] = code[src];
1483 int write(int src, byte[] code, int dest, byte[] newcode) {
1488 newcode[dest++] = code[src];
1510 * dead code. It complicates the generation of StackMap and