comparison src/share/vm/ci/ciStreams.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 de847cac9235
comparison
equal deleted inserted replaced
2130:34d64ad817f4 2142:8012aa3ccede
1 /* 1 /*
2 * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 1999, 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.
76 if (require_wide) 76 if (require_wide)
77 { assert(is_wide(), "must be a wide instruction"); } 77 { assert(is_wide(), "must be a wide instruction"); }
78 else { assert(!is_wide(), "must not be a wide instruction"); } 78 else { assert(!is_wide(), "must not be a wide instruction"); }
79 } 79 }
80 80
81 Bytecode* bytecode() const { return Bytecode_at(_bc_start); } 81 Bytecode bytecode() const { return Bytecode(this, _bc_start); }
82 Bytecode* next_bytecode() const { return Bytecode_at(_pc); } 82 Bytecode next_bytecode() const { return Bytecode(this, _pc); }
83 83
84 public: 84 public:
85 // End-Of-Bytecodes 85 // End-Of-Bytecodes
86 static Bytecodes::Code EOBC() { 86 static Bytecodes::Code EOBC() {
87 return Bytecodes::_illegal; 87 return Bytecodes::_illegal;
149 149
150 // Does this instruction contain an index which refes into the CP cache? 150 // Does this instruction contain an index which refes into the CP cache?
151 bool has_cache_index() const { return Bytecodes::uses_cp_cache(cur_bc_raw()); } 151 bool has_cache_index() const { return Bytecodes::uses_cp_cache(cur_bc_raw()); }
152 152
153 int get_index_u1() const { 153 int get_index_u1() const {
154 return bytecode()->get_index_u1(cur_bc_raw()); 154 return bytecode().get_index_u1(cur_bc_raw());
155 } 155 }
156 156
157 int get_index_u1_cpcache() const { 157 int get_index_u1_cpcache() const {
158 return bytecode()->get_index_u1_cpcache(cur_bc_raw()); 158 return bytecode().get_index_u1_cpcache(cur_bc_raw());
159 } 159 }
160 160
161 // Get a byte index following this bytecode. 161 // Get a byte index following this bytecode.
162 // If prefixed with a wide bytecode, get a wide index. 162 // If prefixed with a wide bytecode, get a wide index.
163 int get_index() const { 163 int get_index() const {
167 : get_index_u1(); // no, return narrow index 167 : get_index_u1(); // no, return narrow index
168 } 168 }
169 169
170 // Get 2-byte index (byte swapping depending on which bytecode) 170 // Get 2-byte index (byte swapping depending on which bytecode)
171 int get_index_u2(bool is_wide = false) const { 171 int get_index_u2(bool is_wide = false) const {
172 return bytecode()->get_index_u2(cur_bc_raw(), is_wide); 172 return bytecode().get_index_u2(cur_bc_raw(), is_wide);
173 } 173 }
174 174
175 // Get 2-byte index in native byte order. (Rewriter::rewrite makes these.) 175 // Get 2-byte index in native byte order. (Rewriter::rewrite makes these.)
176 int get_index_u2_cpcache() const { 176 int get_index_u2_cpcache() const {
177 return bytecode()->get_index_u2_cpcache(cur_bc_raw()); 177 return bytecode().get_index_u2_cpcache(cur_bc_raw());
178 } 178 }
179 179
180 // Get 4-byte index, for invokedynamic. 180 // Get 4-byte index, for invokedynamic.
181 int get_index_u4() const { 181 int get_index_u4() const {
182 return bytecode()->get_index_u4(cur_bc_raw()); 182 return bytecode().get_index_u4(cur_bc_raw());
183 } 183 }
184 184
185 bool has_index_u4() const { 185 bool has_index_u4() const {
186 return bytecode()->has_index_u4(cur_bc_raw()); 186 return bytecode().has_index_u4(cur_bc_raw());
187 } 187 }
188 188
189 // Get dimensions byte (multinewarray) 189 // Get dimensions byte (multinewarray)
190 int get_dimensions() const { return *(unsigned char*)(_pc-1); } 190 int get_dimensions() const { return *(unsigned char*)(_pc-1); }
191 191
192 // Sign-extended index byte/short, no widening 192 // Sign-extended index byte/short, no widening
193 int get_constant_u1() const { return bytecode()->get_constant_u1(instruction_size()-1, cur_bc_raw()); } 193 int get_constant_u1() const { return bytecode().get_constant_u1(instruction_size()-1, cur_bc_raw()); }
194 int get_constant_u2(bool is_wide = false) const { return bytecode()->get_constant_u2(instruction_size()-2, cur_bc_raw(), is_wide); } 194 int get_constant_u2(bool is_wide = false) const { return bytecode().get_constant_u2(instruction_size()-2, cur_bc_raw(), is_wide); }
195 195
196 // Get a byte signed constant for "iinc". Invalid for other bytecodes. 196 // Get a byte signed constant for "iinc". Invalid for other bytecodes.
197 // If prefixed with a wide bytecode, get a wide constant 197 // If prefixed with a wide bytecode, get a wide constant
198 int get_iinc_con() const {return (_pc==_was_wide) ? (jshort) get_constant_u2(true) : (jbyte) get_constant_u1();} 198 int get_iinc_con() const {return (_pc==_was_wide) ? (jshort) get_constant_u2(true) : (jbyte) get_constant_u1();}
199 199
200 // 2-byte branch offset from current pc 200 // 2-byte branch offset from current pc
201 int get_dest() const { 201 int get_dest() const {
202 return cur_bci() + bytecode()->get_offset_s2(cur_bc_raw()); 202 return cur_bci() + bytecode().get_offset_s2(cur_bc_raw());
203 } 203 }
204 204
205 // 2-byte branch offset from next pc 205 // 2-byte branch offset from next pc
206 int next_get_dest() const { 206 int next_get_dest() const {
207 assert(_pc < _end, ""); 207 assert(_pc < _end, "");
208 return next_bci() + next_bytecode()->get_offset_s2(Bytecodes::_ifeq); 208 return next_bci() + next_bytecode().get_offset_s2(Bytecodes::_ifeq);
209 } 209 }
210 210
211 // 4-byte branch offset from current pc 211 // 4-byte branch offset from current pc
212 int get_far_dest() const { 212 int get_far_dest() const {
213 return cur_bci() + bytecode()->get_offset_s4(cur_bc_raw()); 213 return cur_bci() + bytecode().get_offset_s4(cur_bc_raw());
214 } 214 }
215 215
216 // For a lookup or switch table, return target destination 216 // For a lookup or switch table, return target destination
217 int get_int_table( int index ) const { 217 int get_int_table( int index ) const {
218 return Bytes::get_Java_u4((address)&_table_base[index]); } 218 return Bytes::get_Java_u4((address)&_table_base[index]); }
405 ciExceptionHandler* handler() { 405 ciExceptionHandler* handler() {
406 return _method->_exception_handlers[_pos]; 406 return _method->_exception_handlers[_pos];
407 } 407 }
408 }; 408 };
409 409
410
411
412 // Implementation for declarations in bytecode.hpp
413 Bytecode::Bytecode(const ciBytecodeStream* stream, address bcp): _bcp(bcp != NULL ? bcp : stream->cur_bcp()), _code(Bytecodes::code_at(NULL, addr_at(0))) {}
414 Bytecode_lookupswitch::Bytecode_lookupswitch(const ciBytecodeStream* stream): Bytecode(stream) { verify(); }
415 Bytecode_tableswitch::Bytecode_tableswitch(const ciBytecodeStream* stream): Bytecode(stream) { verify(); }
416
410 #endif // SHARE_VM_CI_CISTREAMS_HPP 417 #endif // SHARE_VM_CI_CISTREAMS_HPP