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. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 // A BytecodeStream is used for fast iteration over the bytecodes 26 // of a methodOop. 27 // 28 // Usage: 29 // 30 // BytecodeStream s(method); 31 // Bytecodes::Code c; 32 // while ((c = s.next()) >= 0) { 33 // ... 34 // } 35 36 // A RawBytecodeStream is a simple version of BytecodeStream. 37 // It is used ONLY when we know the bytecodes haven't been rewritten 38 // yet, such as in the rewriter or the verifier. 39 40 // Here is the common base class for both RawBytecodeStream and BytecodeStream: 41 class BaseBytecodeStream: StackObj { 42 protected: 43 // stream buffer 44 methodHandle _method; // read from method directly 197 _raw_code = raw_code; 198 _code = code; 199 return _code; 200 } 201 202 bool is_active_breakpoint() const { return Bytecodes::is_active_breakpoint_at(bcp()); } 203 Bytecodes::Code code() const { return _code; } 204 205 // Unsigned indices, widening 206 int get_index() const { return is_wide() ? bytecode()->get_index_u2(raw_code(), true) : get_index_u1(); } 207 // Get an unsigned 2-byte index, swapping the bytes if necessary. 208 int get_index_u2() const { assert_raw_stream(false); 209 return bytecode()->get_index_u2(raw_code(), false); } 210 // Get an unsigned 2-byte index in native order. 211 int get_index_u2_cpcache() const { assert_raw_stream(false); 212 return bytecode()->get_index_u2_cpcache(raw_code()); } 213 int get_index_u4() const { assert_raw_stream(false); 214 return bytecode()->get_index_u4(raw_code()); } 215 bool has_index_u4() const { return bytecode()->has_index_u4(raw_code()); } 216 }; | 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. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #ifndef SHARE_VM_INTERPRETER_BYTECODESTREAM_HPP 26 #define SHARE_VM_INTERPRETER_BYTECODESTREAM_HPP 27 28 #include "interpreter/bytecode.hpp" 29 #include "memory/allocation.hpp" 30 #include "oops/methodOop.hpp" 31 #ifdef TARGET_ARCH_x86 32 # include "bytes_x86.hpp" 33 #endif 34 #ifdef TARGET_ARCH_sparc 35 # include "bytes_sparc.hpp" 36 #endif 37 #ifdef TARGET_ARCH_zero 38 # include "bytes_zero.hpp" 39 #endif 40 41 // A BytecodeStream is used for fast iteration over the bytecodes 42 // of a methodOop. 43 // 44 // Usage: 45 // 46 // BytecodeStream s(method); 47 // Bytecodes::Code c; 48 // while ((c = s.next()) >= 0) { 49 // ... 50 // } 51 52 // A RawBytecodeStream is a simple version of BytecodeStream. 53 // It is used ONLY when we know the bytecodes haven't been rewritten 54 // yet, such as in the rewriter or the verifier. 55 56 // Here is the common base class for both RawBytecodeStream and BytecodeStream: 57 class BaseBytecodeStream: StackObj { 58 protected: 59 // stream buffer 60 methodHandle _method; // read from method directly 213 _raw_code = raw_code; 214 _code = code; 215 return _code; 216 } 217 218 bool is_active_breakpoint() const { return Bytecodes::is_active_breakpoint_at(bcp()); } 219 Bytecodes::Code code() const { return _code; } 220 221 // Unsigned indices, widening 222 int get_index() const { return is_wide() ? bytecode()->get_index_u2(raw_code(), true) : get_index_u1(); } 223 // Get an unsigned 2-byte index, swapping the bytes if necessary. 224 int get_index_u2() const { assert_raw_stream(false); 225 return bytecode()->get_index_u2(raw_code(), false); } 226 // Get an unsigned 2-byte index in native order. 227 int get_index_u2_cpcache() const { assert_raw_stream(false); 228 return bytecode()->get_index_u2_cpcache(raw_code()); } 229 int get_index_u4() const { assert_raw_stream(false); 230 return bytecode()->get_index_u4(raw_code()); } 231 bool has_index_u4() const { return bytecode()->has_index_u4(raw_code()); } 232 }; 233 234 #endif // SHARE_VM_INTERPRETER_BYTECODESTREAM_HPP |