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/method.hpp"
31 #include "runtime/handles.inline.hpp"
32 #include "utilities/bytes.hpp"
33
34 // A BytecodeStream is used for fast iteration over the bytecodes
35 // of a Method*.
36 //
37 // Usage:
38 //
39 // BytecodeStream s(method);
40 // Bytecodes::Code c;
41 // while ((c = s.next()) >= 0) {
42 // ...
43 // }
44
45 // A RawBytecodeStream is a simple version of BytecodeStream.
46 // It is used ONLY when we know the bytecodes haven't been rewritten
47 // yet, such as in the rewriter or the verifier.
48
49 // Here is the common base class for both RawBytecodeStream and BytecodeStream:
50 class BaseBytecodeStream: StackObj {
51 protected:
52 // stream buffer
53 methodHandle _method; // read from method directly
54
55 // reading position
56 int _bci; // bci if current bytecode
57 int _next_bci; // bci of next bytecode
58 int _end_bci; // bci after the current iteration interval
59
60 // last bytecode read
61 Bytecodes::Code _raw_code;
62 bool _is_wide;
63 bool _is_raw; // false in 'cooked' BytecodeStream
64
65 // Construction
66 BaseBytecodeStream(const methodHandle& method) : _method(method) {
67 set_interval(0, _method->code_size());
68 _is_raw = false;
69 }
70
71 public:
72 // Iteration control
73 void set_interval(int beg_bci, int end_bci) {
74 // iterate over the interval [beg_bci, end_bci)
75 assert(0 <= beg_bci && beg_bci <= method()->code_size(), "illegal beg_bci");
76 assert(0 <= end_bci && end_bci <= method()->code_size(), "illegal end_bci");
77 // setup of iteration pointers
78 _bci = beg_bci;
79 _next_bci = beg_bci;
80 _end_bci = end_bci;
81 }
82 void set_start (int beg_bci) {
83 set_interval(beg_bci, _method->code_size());
84 }
85
86 bool is_raw() const { return _is_raw; }
87
88 // Stream attributes
89 const methodHandle& method() const { return _method; }
|
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/method.hpp"
31 #include "utilities/bytes.hpp"
32
33 // A BytecodeStream is used for fast iteration over the bytecodes
34 // of a Method*.
35 //
36 // Usage:
37 //
38 // BytecodeStream s(method);
39 // Bytecodes::Code c;
40 // while ((c = s.next()) >= 0) {
41 // ...
42 // }
43
44 // A RawBytecodeStream is a simple version of BytecodeStream.
45 // It is used ONLY when we know the bytecodes haven't been rewritten
46 // yet, such as in the rewriter or the verifier.
47
48 // Here is the common base class for both RawBytecodeStream and BytecodeStream:
49 class BaseBytecodeStream: StackObj {
50 protected:
51 // stream buffer
52 methodHandle _method; // read from method directly
53
54 // reading position
55 int _bci; // bci if current bytecode
56 int _next_bci; // bci of next bytecode
57 int _end_bci; // bci after the current iteration interval
58
59 // last bytecode read
60 Bytecodes::Code _raw_code;
61 bool _is_wide;
62 bool _is_raw; // false in 'cooked' BytecodeStream
63
64 // Construction
65 BaseBytecodeStream(const methodHandle& method);
66
67 public:
68 // Iteration control
69 void set_interval(int beg_bci, int end_bci) {
70 // iterate over the interval [beg_bci, end_bci)
71 assert(0 <= beg_bci && beg_bci <= method()->code_size(), "illegal beg_bci");
72 assert(0 <= end_bci && end_bci <= method()->code_size(), "illegal end_bci");
73 // setup of iteration pointers
74 _bci = beg_bci;
75 _next_bci = beg_bci;
76 _end_bci = end_bci;
77 }
78 void set_start (int beg_bci) {
79 set_interval(beg_bci, _method->code_size());
80 }
81
82 bool is_raw() const { return _is_raw; }
83
84 // Stream attributes
85 const methodHandle& method() const { return _method; }
|