src/share/vm/interpreter/bytecodeStream.hpp

Tue, 11 May 2010 14:35:43 -0700

author
prr
date
Tue, 11 May 2010 14:35:43 -0700
changeset 1840
fb57d4cf76c2
parent 1279
bd02caa94611
child 1907
c18cbe5936b8
child 1920
ab102d5d923e
permissions
-rw-r--r--

6931180: Migration to recent versions of MS Platform SDK
6951582: Build problems on win64
Summary: Changes to enable building JDK7 with Microsoft Visual Studio 2010
Reviewed-by: ohair, art, ccheung, dcubed

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

mercurial