Mercurial > hg > truffle
comparison graal/com.oracle.graal.bytecode/src/com/oracle/graal/bytecode/BytecodeStream.java @ 19507:1cde96b96673
Fixed code format issues.
author | Roland Schatz <roland.schatz@oracle.com> |
---|---|
date | Thu, 19 Feb 2015 16:15:56 +0100 |
parents | 7ef66078d837 |
children | 27943aac2e3c |
comparison
equal
deleted
inserted
replaced
19506:8c7536965c95 | 19507:1cde96b96673 |
---|---|
34 private int curBCI; | 34 private int curBCI; |
35 private int nextBCI; | 35 private int nextBCI; |
36 | 36 |
37 /** | 37 /** |
38 * Creates a new {@code BytecodeStream} for the specified bytecode. | 38 * Creates a new {@code BytecodeStream} for the specified bytecode. |
39 * | 39 * |
40 * @param code the array of bytes that contains the bytecode | 40 * @param code the array of bytes that contains the bytecode |
41 */ | 41 */ |
42 public BytecodeStream(byte[] code) { | 42 public BytecodeStream(byte[] code) { |
43 assert code != null; | 43 assert code != null; |
44 this.code = code; | 44 this.code = code; |
52 setBCI(nextBCI); | 52 setBCI(nextBCI); |
53 } | 53 } |
54 | 54 |
55 /** | 55 /** |
56 * Gets the next bytecode index (no side-effects). | 56 * Gets the next bytecode index (no side-effects). |
57 * | 57 * |
58 * @return the next bytecode index | 58 * @return the next bytecode index |
59 */ | 59 */ |
60 public int nextBCI() { | 60 public int nextBCI() { |
61 return nextBCI; | 61 return nextBCI; |
62 } | 62 } |
63 | 63 |
64 /** | 64 /** |
65 * Gets the current bytecode index. | 65 * Gets the current bytecode index. |
66 * | 66 * |
67 * @return the current bytecode index | 67 * @return the current bytecode index |
68 */ | 68 */ |
69 public int currentBCI() { | 69 public int currentBCI() { |
70 return curBCI; | 70 return curBCI; |
71 } | 71 } |
72 | 72 |
73 /** | 73 /** |
74 * Gets the bytecode index of the end of the code. | 74 * Gets the bytecode index of the end of the code. |
75 * | 75 * |
76 * @return the index of the end of the code | 76 * @return the index of the end of the code |
77 */ | 77 */ |
78 public int endBCI() { | 78 public int endBCI() { |
79 return code.length; | 79 return code.length; |
80 } | 80 } |
81 | 81 |
82 /** | 82 /** |
83 * Gets the current opcode. This method will never return the {@link Bytecodes#WIDE WIDE} | 83 * Gets the current opcode. This method will never return the {@link Bytecodes#WIDE WIDE} |
84 * opcode, but will instead return the opcode that is modified by the {@code WIDE} opcode. | 84 * opcode, but will instead return the opcode that is modified by the {@code WIDE} opcode. |
85 * | 85 * |
86 * @return the current opcode; {@link Bytecodes#END} if at or beyond the end of the code | 86 * @return the current opcode; {@link Bytecodes#END} if at or beyond the end of the code |
87 */ | 87 */ |
88 public int currentBC() { | 88 public int currentBC() { |
89 if (opcode == Bytecodes.WIDE) { | 89 if (opcode == Bytecodes.WIDE) { |
90 return Bytes.beU1(code, curBCI + 1); | 90 return Bytes.beU1(code, curBCI + 1); |
94 } | 94 } |
95 | 95 |
96 /** | 96 /** |
97 * Reads the index of a local variable for one of the load or store instructions. The WIDE | 97 * Reads the index of a local variable for one of the load or store instructions. The WIDE |
98 * modifier is handled internally. | 98 * modifier is handled internally. |
99 * | 99 * |
100 * @return the index of the local variable | 100 * @return the index of the local variable |
101 */ | 101 */ |
102 public int readLocalIndex() { | 102 public int readLocalIndex() { |
103 // read local variable index for load/store | 103 // read local variable index for load/store |
104 if (opcode == Bytecodes.WIDE) { | 104 if (opcode == Bytecodes.WIDE) { |
107 return Bytes.beU1(code, curBCI + 1); | 107 return Bytes.beU1(code, curBCI + 1); |
108 } | 108 } |
109 | 109 |
110 /** | 110 /** |
111 * Read the delta for an {@link Bytecodes#IINC} bytecode. | 111 * Read the delta for an {@link Bytecodes#IINC} bytecode. |
112 * | 112 * |
113 * @return the delta for the {@code IINC} | 113 * @return the delta for the {@code IINC} |
114 */ | 114 */ |
115 public int readIncrement() { | 115 public int readIncrement() { |
116 // read the delta for the iinc bytecode | 116 // read the delta for the iinc bytecode |
117 if (opcode == Bytecodes.WIDE) { | 117 if (opcode == Bytecodes.WIDE) { |
120 return Bytes.beS1(code, curBCI + 2); | 120 return Bytes.beS1(code, curBCI + 2); |
121 } | 121 } |
122 | 122 |
123 /** | 123 /** |
124 * Read the destination of a {@link Bytecodes#GOTO} or {@code IF} instructions. | 124 * Read the destination of a {@link Bytecodes#GOTO} or {@code IF} instructions. |
125 * | 125 * |
126 * @return the destination bytecode index | 126 * @return the destination bytecode index |
127 */ | 127 */ |
128 public int readBranchDest() { | 128 public int readBranchDest() { |
129 // reads the destination for a branch bytecode | 129 // reads the destination for a branch bytecode |
130 if (opcode == Bytecodes.GOTO_W || opcode == Bytecodes.JSR_W) { | 130 if (opcode == Bytecodes.GOTO_W || opcode == Bytecodes.JSR_W) { |
134 } | 134 } |
135 } | 135 } |
136 | 136 |
137 /** | 137 /** |
138 * Read a signed 4-byte integer from the bytecode stream at the specified bytecode index. | 138 * Read a signed 4-byte integer from the bytecode stream at the specified bytecode index. |
139 * | 139 * |
140 * @param bci the bytecode index | 140 * @param bci the bytecode index |
141 * @return the integer value | 141 * @return the integer value |
142 */ | 142 */ |
143 public int readInt(int bci) { | 143 public int readInt(int bci) { |
144 // reads a 4-byte signed value | 144 // reads a 4-byte signed value |
145 return Bytes.beS4(code, bci); | 145 return Bytes.beS4(code, bci); |
146 } | 146 } |
147 | 147 |
148 /** | 148 /** |
149 * Reads an unsigned, 1-byte value from the bytecode stream at the specified bytecode index. | 149 * Reads an unsigned, 1-byte value from the bytecode stream at the specified bytecode index. |
150 * | 150 * |
151 * @param bci the bytecode index | 151 * @param bci the bytecode index |
152 * @return the byte | 152 * @return the byte |
153 */ | 153 */ |
154 public int readUByte(int bci) { | 154 public int readUByte(int bci) { |
155 return Bytes.beU1(code, bci); | 155 return Bytes.beU1(code, bci); |
156 } | 156 } |
157 | 157 |
158 /** | 158 /** |
159 * Reads a constant pool index for the current instruction. | 159 * Reads a constant pool index for the current instruction. |
160 * | 160 * |
161 * @return the constant pool index | 161 * @return the constant pool index |
162 */ | 162 */ |
163 public char readCPI() { | 163 public char readCPI() { |
164 if (opcode == Bytecodes.LDC) { | 164 if (opcode == Bytecodes.LDC) { |
165 return (char) Bytes.beU1(code, curBCI + 1); | 165 return (char) Bytes.beU1(code, curBCI + 1); |
167 return (char) Bytes.beU2(code, curBCI + 1); | 167 return (char) Bytes.beU2(code, curBCI + 1); |
168 } | 168 } |
169 | 169 |
170 /** | 170 /** |
171 * Reads a constant pool index for an invokedynamic instruction. | 171 * Reads a constant pool index for an invokedynamic instruction. |
172 * | 172 * |
173 * @return the constant pool index | 173 * @return the constant pool index |
174 */ | 174 */ |
175 public int readCPI4() { | 175 public int readCPI4() { |
176 assert opcode == Bytecodes.INVOKEDYNAMIC; | 176 assert opcode == Bytecodes.INVOKEDYNAMIC; |
177 return Bytes.beS4(code, curBCI + 1); | 177 return Bytes.beS4(code, curBCI + 1); |
178 } | 178 } |
179 | 179 |
180 /** | 180 /** |
181 * Reads a signed, 1-byte value for the current instruction (e.g. BIPUSH). | 181 * Reads a signed, 1-byte value for the current instruction (e.g. BIPUSH). |
182 * | 182 * |
183 * @return the byte | 183 * @return the byte |
184 */ | 184 */ |
185 public byte readByte() { | 185 public byte readByte() { |
186 return code[curBCI + 1]; | 186 return code[curBCI + 1]; |
187 } | 187 } |
188 | 188 |
189 /** | 189 /** |
190 * Reads a signed, 2-byte short for the current instruction (e.g. SIPUSH). | 190 * Reads a signed, 2-byte short for the current instruction (e.g. SIPUSH). |
191 * | 191 * |
192 * @return the short value | 192 * @return the short value |
193 */ | 193 */ |
194 public short readShort() { | 194 public short readShort() { |
195 return (short) Bytes.beS2(code, curBCI + 1); | 195 return (short) Bytes.beS2(code, curBCI + 1); |
196 } | 196 } |
197 | 197 |
198 /** | 198 /** |
199 * Sets the bytecode index to the specified value. If {@code bci} is beyond the end of the | 199 * Sets the bytecode index to the specified value. If {@code bci} is beyond the end of the |
200 * array, {@link #currentBC} will return {@link Bytecodes#END} and other methods may throw | 200 * array, {@link #currentBC} will return {@link Bytecodes#END} and other methods may throw |
201 * {@link ArrayIndexOutOfBoundsException}. | 201 * {@link ArrayIndexOutOfBoundsException}. |
202 * | 202 * |
203 * @param bci the new bytecode index | 203 * @param bci the new bytecode index |
204 */ | 204 */ |
205 public void setBCI(int bci) { | 205 public void setBCI(int bci) { |
206 curBCI = bci; | 206 curBCI = bci; |
207 if (curBCI < code.length) { | 207 if (curBCI < code.length) { |