annotate src/share/vm/interpreter/bytecodeStream.hpp @ 196:d1605aabd0a1 jdk7-b30

6719955: Update copyright year Summary: Update copyright year for files that have been modified in 2008 Reviewed-by: ohair, tbell
author xdono
date Wed, 02 Jul 2008 12:55:16 -0700
parents a61af66fc99e
children be93aad57795
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
2 * Copyright 1997-2005 Sun Microsystems, Inc. All Rights Reserved.
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
a61af66fc99e Initial load
duke
parents:
diff changeset
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
a61af66fc99e Initial load
duke
parents:
diff changeset
20 * CA 95054 USA or visit www.sun.com if you need additional information or
a61af66fc99e Initial load
duke
parents:
diff changeset
21 * have any questions.
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 // A BytecodeStream is used for fast iteration over the bytecodes
a61af66fc99e Initial load
duke
parents:
diff changeset
26 // of a methodOop.
a61af66fc99e Initial load
duke
parents:
diff changeset
27 //
a61af66fc99e Initial load
duke
parents:
diff changeset
28 // Usage:
a61af66fc99e Initial load
duke
parents:
diff changeset
29 //
a61af66fc99e Initial load
duke
parents:
diff changeset
30 // BytecodeStream s(method);
a61af66fc99e Initial load
duke
parents:
diff changeset
31 // Bytecodes::Code c;
a61af66fc99e Initial load
duke
parents:
diff changeset
32 // while ((c = s.next()) >= 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
33 // ...
a61af66fc99e Initial load
duke
parents:
diff changeset
34 // }
a61af66fc99e Initial load
duke
parents:
diff changeset
35 //
a61af66fc99e Initial load
duke
parents:
diff changeset
36 // A RawBytecodeStream is a simple version of BytecodeStream.
a61af66fc99e Initial load
duke
parents:
diff changeset
37 // It is used ONLY when we know the bytecodes haven't been rewritten
a61af66fc99e Initial load
duke
parents:
diff changeset
38 // yet, such as in the rewriter or the verifier. Currently only the
a61af66fc99e Initial load
duke
parents:
diff changeset
39 // verifier uses this class.
a61af66fc99e Initial load
duke
parents:
diff changeset
40
a61af66fc99e Initial load
duke
parents:
diff changeset
41 class RawBytecodeStream: StackObj {
a61af66fc99e Initial load
duke
parents:
diff changeset
42 protected:
a61af66fc99e Initial load
duke
parents:
diff changeset
43 // stream buffer
a61af66fc99e Initial load
duke
parents:
diff changeset
44 methodHandle _method; // read from method directly
a61af66fc99e Initial load
duke
parents:
diff changeset
45
a61af66fc99e Initial load
duke
parents:
diff changeset
46 // reading position
a61af66fc99e Initial load
duke
parents:
diff changeset
47 int _bci; // bci if current bytecode
a61af66fc99e Initial load
duke
parents:
diff changeset
48 int _next_bci; // bci of next bytecode
a61af66fc99e Initial load
duke
parents:
diff changeset
49 int _end_bci; // bci after the current iteration interval
a61af66fc99e Initial load
duke
parents:
diff changeset
50
a61af66fc99e Initial load
duke
parents:
diff changeset
51 // last bytecode read
a61af66fc99e Initial load
duke
parents:
diff changeset
52 Bytecodes::Code _code;
a61af66fc99e Initial load
duke
parents:
diff changeset
53 bool _is_wide;
a61af66fc99e Initial load
duke
parents:
diff changeset
54
a61af66fc99e Initial load
duke
parents:
diff changeset
55 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
56 // Construction
a61af66fc99e Initial load
duke
parents:
diff changeset
57 RawBytecodeStream(methodHandle method) : _method(method) {
a61af66fc99e Initial load
duke
parents:
diff changeset
58 set_interval(0, _method->code_size());
a61af66fc99e Initial load
duke
parents:
diff changeset
59 }
a61af66fc99e Initial load
duke
parents:
diff changeset
60
a61af66fc99e Initial load
duke
parents:
diff changeset
61 // Iteration control
a61af66fc99e Initial load
duke
parents:
diff changeset
62 void set_interval(int beg_bci, int end_bci) {
a61af66fc99e Initial load
duke
parents:
diff changeset
63 // iterate over the interval [beg_bci, end_bci)
a61af66fc99e Initial load
duke
parents:
diff changeset
64 assert(0 <= beg_bci && beg_bci <= method()->code_size(), "illegal beg_bci");
a61af66fc99e Initial load
duke
parents:
diff changeset
65 assert(0 <= end_bci && end_bci <= method()->code_size(), "illegal end_bci");
a61af66fc99e Initial load
duke
parents:
diff changeset
66 // setup of iteration pointers
a61af66fc99e Initial load
duke
parents:
diff changeset
67 _bci = beg_bci;
a61af66fc99e Initial load
duke
parents:
diff changeset
68 _next_bci = beg_bci;
a61af66fc99e Initial load
duke
parents:
diff changeset
69 _end_bci = end_bci;
a61af66fc99e Initial load
duke
parents:
diff changeset
70 }
a61af66fc99e Initial load
duke
parents:
diff changeset
71 void set_start (int beg_bci) {
a61af66fc99e Initial load
duke
parents:
diff changeset
72 set_interval(beg_bci, _method->code_size());
a61af66fc99e Initial load
duke
parents:
diff changeset
73 }
a61af66fc99e Initial load
duke
parents:
diff changeset
74
a61af66fc99e Initial load
duke
parents:
diff changeset
75 // Iteration
a61af66fc99e Initial load
duke
parents:
diff changeset
76 // Use raw_next() rather than next() for faster method reference
a61af66fc99e Initial load
duke
parents:
diff changeset
77 Bytecodes::Code raw_next() {
a61af66fc99e Initial load
duke
parents:
diff changeset
78 Bytecodes::Code code;
a61af66fc99e Initial load
duke
parents:
diff changeset
79 // set reading position
a61af66fc99e Initial load
duke
parents:
diff changeset
80 _bci = _next_bci;
a61af66fc99e Initial load
duke
parents:
diff changeset
81 assert(!is_last_bytecode(), "caller should check is_last_bytecode()");
a61af66fc99e Initial load
duke
parents:
diff changeset
82
a61af66fc99e Initial load
duke
parents:
diff changeset
83 address bcp = RawBytecodeStream::bcp();
a61af66fc99e Initial load
duke
parents:
diff changeset
84 code = Bytecodes::code_or_bp_at(bcp);
a61af66fc99e Initial load
duke
parents:
diff changeset
85
a61af66fc99e Initial load
duke
parents:
diff changeset
86 // set next bytecode position
a61af66fc99e Initial load
duke
parents:
diff changeset
87 int l = Bytecodes::length_for(code);
a61af66fc99e Initial load
duke
parents:
diff changeset
88 if (l > 0 && (_bci + l) <= _end_bci) {
a61af66fc99e Initial load
duke
parents:
diff changeset
89 assert(code != Bytecodes::_wide && code != Bytecodes::_tableswitch
a61af66fc99e Initial load
duke
parents:
diff changeset
90 && code != Bytecodes::_lookupswitch, "can't be special bytecode");
a61af66fc99e Initial load
duke
parents:
diff changeset
91 _is_wide = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
92 _next_bci += l;
a61af66fc99e Initial load
duke
parents:
diff changeset
93 _code = code;
a61af66fc99e Initial load
duke
parents:
diff changeset
94 return code;
a61af66fc99e Initial load
duke
parents:
diff changeset
95 } else if (code == Bytecodes::_wide && _bci + 1 >= _end_bci) {
a61af66fc99e Initial load
duke
parents:
diff changeset
96 return Bytecodes::_illegal;
a61af66fc99e Initial load
duke
parents:
diff changeset
97 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
98 return raw_next_special(code);
a61af66fc99e Initial load
duke
parents:
diff changeset
99 }
a61af66fc99e Initial load
duke
parents:
diff changeset
100 }
a61af66fc99e Initial load
duke
parents:
diff changeset
101 Bytecodes::Code raw_next_special(Bytecodes::Code code);
a61af66fc99e Initial load
duke
parents:
diff changeset
102
a61af66fc99e Initial load
duke
parents:
diff changeset
103 // Stream attributes
a61af66fc99e Initial load
duke
parents:
diff changeset
104 methodHandle method() const { return _method; }
a61af66fc99e Initial load
duke
parents:
diff changeset
105
a61af66fc99e Initial load
duke
parents:
diff changeset
106 int bci() const { return _bci; }
a61af66fc99e Initial load
duke
parents:
diff changeset
107 int next_bci() const { return _next_bci; }
a61af66fc99e Initial load
duke
parents:
diff changeset
108 int end_bci() const { return _end_bci; }
a61af66fc99e Initial load
duke
parents:
diff changeset
109
a61af66fc99e Initial load
duke
parents:
diff changeset
110 Bytecodes::Code code() const { return _code; }
a61af66fc99e Initial load
duke
parents:
diff changeset
111 bool is_wide() const { return _is_wide; }
a61af66fc99e Initial load
duke
parents:
diff changeset
112 bool is_last_bytecode() const { return _next_bci >= _end_bci; }
a61af66fc99e Initial load
duke
parents:
diff changeset
113
a61af66fc99e Initial load
duke
parents:
diff changeset
114 address bcp() const { return method()->code_base() + _bci; }
a61af66fc99e Initial load
duke
parents:
diff changeset
115 address next_bcp() { return method()->code_base() + _next_bci; }
a61af66fc99e Initial load
duke
parents:
diff changeset
116
a61af66fc99e Initial load
duke
parents:
diff changeset
117 // State changes
a61af66fc99e Initial load
duke
parents:
diff changeset
118 void set_next_bci(int bci) { assert(0 <= bci && bci <= method()->code_size(), "illegal bci"); _next_bci = bci; }
a61af66fc99e Initial load
duke
parents:
diff changeset
119
a61af66fc99e Initial load
duke
parents:
diff changeset
120 // Bytecode-specific attributes
a61af66fc99e Initial load
duke
parents:
diff changeset
121 int dest() const { return bci() + (short)Bytes::get_Java_u2(bcp() + 1); }
a61af66fc99e Initial load
duke
parents:
diff changeset
122 int dest_w() const { return bci() + (int )Bytes::get_Java_u4(bcp() + 1); }
a61af66fc99e Initial load
duke
parents:
diff changeset
123
a61af66fc99e Initial load
duke
parents:
diff changeset
124 // Unsigned indices, widening
a61af66fc99e Initial load
duke
parents:
diff changeset
125 int get_index() const { return (is_wide()) ? Bytes::get_Java_u2(bcp() + 2) : bcp()[1]; }
a61af66fc99e Initial load
duke
parents:
diff changeset
126 int get_index_big() const { return (int)Bytes::get_Java_u2(bcp() + 1); }
a61af66fc99e Initial load
duke
parents:
diff changeset
127 };
a61af66fc99e Initial load
duke
parents:
diff changeset
128
a61af66fc99e Initial load
duke
parents:
diff changeset
129 // In BytecodeStream, non-java bytecodes will be translated into the
a61af66fc99e Initial load
duke
parents:
diff changeset
130 // corresponding java bytecodes.
a61af66fc99e Initial load
duke
parents:
diff changeset
131
a61af66fc99e Initial load
duke
parents:
diff changeset
132 class BytecodeStream: public RawBytecodeStream {
a61af66fc99e Initial load
duke
parents:
diff changeset
133 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
134 // Construction
a61af66fc99e Initial load
duke
parents:
diff changeset
135 BytecodeStream(methodHandle method) : RawBytecodeStream(method) { }
a61af66fc99e Initial load
duke
parents:
diff changeset
136
a61af66fc99e Initial load
duke
parents:
diff changeset
137 // Iteration
a61af66fc99e Initial load
duke
parents:
diff changeset
138 Bytecodes::Code next() {
a61af66fc99e Initial load
duke
parents:
diff changeset
139 Bytecodes::Code code;
a61af66fc99e Initial load
duke
parents:
diff changeset
140 // set reading position
a61af66fc99e Initial load
duke
parents:
diff changeset
141 _bci = _next_bci;
a61af66fc99e Initial load
duke
parents:
diff changeset
142 if (is_last_bytecode()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
143 // indicate end of bytecode stream
a61af66fc99e Initial load
duke
parents:
diff changeset
144 code = Bytecodes::_illegal;
a61af66fc99e Initial load
duke
parents:
diff changeset
145 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
146 // get bytecode
a61af66fc99e Initial load
duke
parents:
diff changeset
147 address bcp = BytecodeStream::bcp();
a61af66fc99e Initial load
duke
parents:
diff changeset
148 code = Bytecodes::java_code_at(bcp);
a61af66fc99e Initial load
duke
parents:
diff changeset
149 // set next bytecode position
a61af66fc99e Initial load
duke
parents:
diff changeset
150 //
a61af66fc99e Initial load
duke
parents:
diff changeset
151 // note that we cannot advance before having the
a61af66fc99e Initial load
duke
parents:
diff changeset
152 // tty bytecode otherwise the stepping is wrong!
a61af66fc99e Initial load
duke
parents:
diff changeset
153 // (carefull: length_for(...) must be used first!)
a61af66fc99e Initial load
duke
parents:
diff changeset
154 int l = Bytecodes::length_for(code);
a61af66fc99e Initial load
duke
parents:
diff changeset
155 if (l == 0) l = Bytecodes::length_at(bcp);
a61af66fc99e Initial load
duke
parents:
diff changeset
156 _next_bci += l;
a61af66fc99e Initial load
duke
parents:
diff changeset
157 assert(_bci < _next_bci, "length must be > 0");
a61af66fc99e Initial load
duke
parents:
diff changeset
158 // set attributes
a61af66fc99e Initial load
duke
parents:
diff changeset
159 _is_wide = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
160 // check for special (uncommon) cases
a61af66fc99e Initial load
duke
parents:
diff changeset
161 if (code == Bytecodes::_wide) {
a61af66fc99e Initial load
duke
parents:
diff changeset
162 code = (Bytecodes::Code)bcp[1];
a61af66fc99e Initial load
duke
parents:
diff changeset
163 _is_wide = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
164 }
a61af66fc99e Initial load
duke
parents:
diff changeset
165 assert(Bytecodes::is_java_code(code), "sanity check");
a61af66fc99e Initial load
duke
parents:
diff changeset
166 }
a61af66fc99e Initial load
duke
parents:
diff changeset
167 _code = code;
a61af66fc99e Initial load
duke
parents:
diff changeset
168 return _code;
a61af66fc99e Initial load
duke
parents:
diff changeset
169 }
a61af66fc99e Initial load
duke
parents:
diff changeset
170
a61af66fc99e Initial load
duke
parents:
diff changeset
171 bool is_active_breakpoint() const { return Bytecodes::is_active_breakpoint_at(bcp()); }
a61af66fc99e Initial load
duke
parents:
diff changeset
172 };