Mercurial > hg > truffle
comparison src/share/vm/interpreter/bytecodeStream.hpp @ 2142:8012aa3ccede
4926272: methodOopDesc::method_from_bcp is unsafe
Reviewed-by: coleenp, jrose, kvn, dcubed
author | never |
---|---|
date | Thu, 13 Jan 2011 22:15:41 -0800 |
parents | f95d63e2154a |
children | b92c45f2bc75 |
comparison
equal
deleted
inserted
replaced
2130:34d64ad817f4 | 2142:8012aa3ccede |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. | 2 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | 4 * |
5 * This code is free software; you can redistribute it and/or modify it | 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 | 6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
103 bool is_wide() const { return _is_wide; } | 103 bool is_wide() const { return _is_wide; } |
104 int instruction_size() const { return (_next_bci - _bci); } | 104 int instruction_size() const { return (_next_bci - _bci); } |
105 bool is_last_bytecode() const { return _next_bci >= _end_bci; } | 105 bool is_last_bytecode() const { return _next_bci >= _end_bci; } |
106 | 106 |
107 address bcp() const { return method()->code_base() + _bci; } | 107 address bcp() const { return method()->code_base() + _bci; } |
108 Bytecode* bytecode() const { return Bytecode_at(bcp()); } | 108 Bytecode bytecode() const { return Bytecode(_method(), bcp()); } |
109 | 109 |
110 // State changes | 110 // State changes |
111 void set_next_bci(int bci) { assert(0 <= bci && bci <= method()->code_size(), "illegal bci"); _next_bci = bci; } | 111 void set_next_bci(int bci) { assert(0 <= bci && bci <= method()->code_size(), "illegal bci"); _next_bci = bci; } |
112 | 112 |
113 // Bytecode-specific attributes | 113 // Bytecode-specific attributes |
114 int dest() const { return bci() + bytecode()->get_offset_s2(raw_code()); } | 114 int dest() const { return bci() + bytecode().get_offset_s2(raw_code()); } |
115 int dest_w() const { return bci() + bytecode()->get_offset_s4(raw_code()); } | 115 int dest_w() const { return bci() + bytecode().get_offset_s4(raw_code()); } |
116 | 116 |
117 // One-byte indices. | 117 // One-byte indices. |
118 int get_index_u1() const { assert_raw_index_size(1); return *(jubyte*)(bcp()+1); } | 118 int get_index_u1() const { assert_raw_index_size(1); return *(jubyte*)(bcp()+1); } |
119 | 119 |
120 protected: | 120 protected: |
187 // indicate end of bytecode stream | 187 // indicate end of bytecode stream |
188 raw_code = code = Bytecodes::_illegal; | 188 raw_code = code = Bytecodes::_illegal; |
189 } else { | 189 } else { |
190 // get bytecode | 190 // get bytecode |
191 address bcp = this->bcp(); | 191 address bcp = this->bcp(); |
192 raw_code = Bytecodes::code_at(bcp); | 192 raw_code = Bytecodes::code_at(_method(), bcp); |
193 code = Bytecodes::java_code(raw_code); | 193 code = Bytecodes::java_code(raw_code); |
194 // set next bytecode position | 194 // set next bytecode position |
195 // | 195 // |
196 // note that we cannot advance before having the | 196 // note that we cannot advance before having the |
197 // tty bytecode otherwise the stepping is wrong! | 197 // tty bytecode otherwise the stepping is wrong! |
198 // (carefull: length_for(...) must be used first!) | 198 // (carefull: length_for(...) must be used first!) |
199 int l = Bytecodes::length_for(code); | 199 int l = Bytecodes::length_for(code); |
200 if (l == 0) l = Bytecodes::length_at(bcp); | 200 if (l == 0) l = Bytecodes::length_at(_method(), bcp); |
201 _next_bci += l; | 201 _next_bci += l; |
202 assert(_bci < _next_bci, "length must be > 0"); | 202 assert(_bci < _next_bci, "length must be > 0"); |
203 // set attributes | 203 // set attributes |
204 _is_wide = false; | 204 _is_wide = false; |
205 // check for special (uncommon) cases | 205 // check for special (uncommon) cases |
217 | 217 |
218 bool is_active_breakpoint() const { return Bytecodes::is_active_breakpoint_at(bcp()); } | 218 bool is_active_breakpoint() const { return Bytecodes::is_active_breakpoint_at(bcp()); } |
219 Bytecodes::Code code() const { return _code; } | 219 Bytecodes::Code code() const { return _code; } |
220 | 220 |
221 // Unsigned indices, widening | 221 // Unsigned indices, widening |
222 int get_index() const { return is_wide() ? bytecode()->get_index_u2(raw_code(), true) : get_index_u1(); } | 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. | 223 // Get an unsigned 2-byte index, swapping the bytes if necessary. |
224 int get_index_u2() const { assert_raw_stream(false); | 224 int get_index_u2() const { assert_raw_stream(false); |
225 return bytecode()->get_index_u2(raw_code(), false); } | 225 return bytecode().get_index_u2(raw_code(), false); } |
226 // Get an unsigned 2-byte index in native order. | 226 // Get an unsigned 2-byte index in native order. |
227 int get_index_u2_cpcache() const { assert_raw_stream(false); | 227 int get_index_u2_cpcache() const { assert_raw_stream(false); |
228 return bytecode()->get_index_u2_cpcache(raw_code()); } | 228 return bytecode().get_index_u2_cpcache(raw_code()); } |
229 int get_index_u4() const { assert_raw_stream(false); | 229 int get_index_u4() const { assert_raw_stream(false); |
230 return bytecode()->get_index_u4(raw_code()); } | 230 return bytecode().get_index_u4(raw_code()); } |
231 bool has_index_u4() const { return bytecode()->has_index_u4(raw_code()); } | 231 bool has_index_u4() const { return bytecode().has_index_u4(raw_code()); } |
232 }; | 232 }; |
233 | 233 |
234 #endif // SHARE_VM_INTERPRETER_BYTECODESTREAM_HPP | 234 #endif // SHARE_VM_INTERPRETER_BYTECODESTREAM_HPP |