src/share/vm/ci/ciStreams.cpp

Mon, 04 Jan 2010 18:38:08 +0100

author
twisti
date
Mon, 04 Jan 2010 18:38:08 +0100
changeset 1570
e66fd840cb6b
parent 1279
bd02caa94611
child 1572
97125851f396
permissions
-rw-r--r--

6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
Summary: During the work for 6829187 we have fixed a number of basic bugs which are logically grouped with 6815692 and 6858164 but which must be reviewed and pushed separately.
Reviewed-by: kvn, never

duke@435 1 /*
xdono@1279 2 * Copyright 1999-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 #include "incls/_precompiled.incl"
duke@435 26 #include "incls/_ciStreams.cpp.incl"
duke@435 27
duke@435 28 // ciExceptionHandlerStream
duke@435 29 //
duke@435 30 // Walk over some selected set of a methods exception handlers.
duke@435 31
duke@435 32 // ------------------------------------------------------------------
duke@435 33 // ciExceptionHandlerStream::count
duke@435 34 //
duke@435 35 // How many exception handlers are there in this stream?
duke@435 36 //
duke@435 37 // Implementation note: Compiler2 needs this functionality, so I had
duke@435 38 int ciExceptionHandlerStream::count() {
duke@435 39 int save_pos = _pos;
duke@435 40 int save_end = _end;
duke@435 41
duke@435 42 int count = 0;
duke@435 43
duke@435 44 _pos = -1;
duke@435 45 _end = _method->_handler_count;
duke@435 46
duke@435 47
duke@435 48 next();
duke@435 49 while (!is_done()) {
duke@435 50 count++;
duke@435 51 next();
duke@435 52 }
duke@435 53
duke@435 54 _pos = save_pos;
duke@435 55 _end = save_end;
duke@435 56
duke@435 57 return count;
duke@435 58 }
duke@435 59
duke@435 60 int ciExceptionHandlerStream::count_remaining() {
duke@435 61 int save_pos = _pos;
duke@435 62 int save_end = _end;
duke@435 63
duke@435 64 int count = 0;
duke@435 65
duke@435 66 while (!is_done()) {
duke@435 67 count++;
duke@435 68 next();
duke@435 69 }
duke@435 70
duke@435 71 _pos = save_pos;
duke@435 72 _end = save_end;
duke@435 73
duke@435 74 return count;
duke@435 75 }
duke@435 76
duke@435 77 // ciBytecodeStream
duke@435 78 //
duke@435 79 // The class is used to iterate over the bytecodes of a method.
duke@435 80 // It hides the details of constant pool structure/access by
duke@435 81 // providing accessors for constant pool items.
duke@435 82
duke@435 83 // ------------------------------------------------------------------
duke@435 84 // ciBytecodeStream::wide
duke@435 85 //
duke@435 86 // Special handling for the wide bytcode
duke@435 87 Bytecodes::Code ciBytecodeStream::wide()
duke@435 88 {
duke@435 89 // Get following bytecode; do not return wide
duke@435 90 Bytecodes::Code bc = (Bytecodes::Code)_pc[1];
duke@435 91 _pc += 2; // Skip both bytecodes
duke@435 92 _pc += 2; // Skip index always
duke@435 93 if( bc == Bytecodes::_iinc )
duke@435 94 _pc += 2; // Skip optional constant
duke@435 95 _was_wide = _pc; // Flag last wide bytecode found
duke@435 96 return bc;
duke@435 97 }
duke@435 98
duke@435 99 // ------------------------------------------------------------------
duke@435 100 // ciBytecodeStream::table
duke@435 101 //
duke@435 102 // Special handling for switch ops
duke@435 103 Bytecodes::Code ciBytecodeStream::table( Bytecodes::Code bc ) {
duke@435 104 switch( bc ) { // Check for special bytecode handling
duke@435 105
duke@435 106 case Bytecodes::_lookupswitch:
duke@435 107 _pc++; // Skip wide bytecode
duke@435 108 _pc += (_start-_pc)&3; // Word align
duke@435 109 _table_base = (jint*)_pc; // Capture for later usage
duke@435 110 // table_base[0] is default far_dest
duke@435 111 // Table has 2 lead elements (default, length), then pairs of u4 values.
duke@435 112 // So load table length, and compute address at end of table
duke@435 113 _pc = (address)&_table_base[2+ 2*Bytes::get_Java_u4((address)&_table_base[1])];
duke@435 114 break;
duke@435 115
duke@435 116 case Bytecodes::_tableswitch: {
duke@435 117 _pc++; // Skip wide bytecode
duke@435 118 _pc += (_start-_pc)&3; // Word align
duke@435 119 _table_base = (jint*)_pc; // Capture for later usage
duke@435 120 // table_base[0] is default far_dest
duke@435 121 int lo = Bytes::get_Java_u4((address)&_table_base[1]);// Low bound
duke@435 122 int hi = Bytes::get_Java_u4((address)&_table_base[2]);// High bound
duke@435 123 int len = hi - lo + 1; // Dense table size
duke@435 124 _pc = (address)&_table_base[3+len]; // Skip past table
duke@435 125 break;
duke@435 126 }
duke@435 127
duke@435 128 default:
duke@435 129 fatal("unhandled bytecode");
duke@435 130 }
duke@435 131 return bc;
duke@435 132 }
duke@435 133
duke@435 134 // ------------------------------------------------------------------
duke@435 135 // ciBytecodeStream::reset_to_bci
duke@435 136 void ciBytecodeStream::reset_to_bci( int bci ) {
duke@435 137 _bc_start=_was_wide=0;
duke@435 138 _pc = _start+bci;
duke@435 139 }
duke@435 140
duke@435 141 // ------------------------------------------------------------------
duke@435 142 // ciBytecodeStream::force_bci
duke@435 143 void ciBytecodeStream::force_bci(int bci) {
duke@435 144 if (bci < 0) {
duke@435 145 reset_to_bci(0);
duke@435 146 _bc_start = _start + bci;
duke@435 147 _bc = EOBC();
duke@435 148 } else {
duke@435 149 reset_to_bci(bci);
duke@435 150 next();
duke@435 151 }
duke@435 152 }
duke@435 153
duke@435 154
duke@435 155 // ------------------------------------------------------------------
duke@435 156 // Constant pool access
duke@435 157 // ------------------------------------------------------------------
duke@435 158
duke@435 159 // ------------------------------------------------------------------
duke@435 160 // ciBytecodeStream::get_klass_index
duke@435 161 //
duke@435 162 // If this bytecodes references a klass, return the index of the
duke@435 163 // referenced klass.
duke@435 164 int ciBytecodeStream::get_klass_index() const {
duke@435 165 switch(cur_bc()) {
duke@435 166 case Bytecodes::_ldc:
duke@435 167 return get_index();
duke@435 168 case Bytecodes::_ldc_w:
duke@435 169 case Bytecodes::_ldc2_w:
duke@435 170 case Bytecodes::_checkcast:
duke@435 171 case Bytecodes::_instanceof:
duke@435 172 case Bytecodes::_anewarray:
duke@435 173 case Bytecodes::_multianewarray:
duke@435 174 case Bytecodes::_new:
duke@435 175 case Bytecodes::_newarray:
duke@435 176 return get_index_big();
duke@435 177 default:
duke@435 178 ShouldNotReachHere();
duke@435 179 return 0;
duke@435 180 }
duke@435 181 }
duke@435 182
duke@435 183 // ------------------------------------------------------------------
duke@435 184 // ciBytecodeStream::get_klass
duke@435 185 //
duke@435 186 // If this bytecode is a new, newarray, multianewarray, instanceof,
duke@435 187 // or checkcast, get the referenced klass.
duke@435 188 ciKlass* ciBytecodeStream::get_klass(bool& will_link) {
duke@435 189 return CURRENT_ENV->get_klass_by_index(_holder, get_klass_index(),
duke@435 190 will_link);
duke@435 191 }
duke@435 192
duke@435 193 // ------------------------------------------------------------------
duke@435 194 // ciBytecodeStream::get_constant_index
duke@435 195 //
duke@435 196 // If this bytecode is one of the ldc variants, get the index of the
duke@435 197 // referenced constant.
duke@435 198 int ciBytecodeStream::get_constant_index() const {
duke@435 199 switch(cur_bc()) {
duke@435 200 case Bytecodes::_ldc:
duke@435 201 return get_index();
duke@435 202 case Bytecodes::_ldc_w:
duke@435 203 case Bytecodes::_ldc2_w:
duke@435 204 return get_index_big();
duke@435 205 default:
duke@435 206 ShouldNotReachHere();
duke@435 207 return 0;
duke@435 208 }
duke@435 209 }
duke@435 210 // ------------------------------------------------------------------
duke@435 211 // ciBytecodeStream::get_constant
duke@435 212 //
duke@435 213 // If this bytecode is one of the ldc variants, get the referenced
duke@435 214 // constant.
duke@435 215 ciConstant ciBytecodeStream::get_constant() {
duke@435 216 return CURRENT_ENV->get_constant_by_index(_holder, get_constant_index());
duke@435 217 }
duke@435 218
duke@435 219 // ------------------------------------------------------------------
duke@435 220 bool ciBytecodeStream::is_unresolved_string() const {
duke@435 221 return CURRENT_ENV->is_unresolved_string(_holder, get_constant_index());
duke@435 222 }
duke@435 223
duke@435 224 // ------------------------------------------------------------------
duke@435 225 bool ciBytecodeStream::is_unresolved_klass() const {
duke@435 226 return CURRENT_ENV->is_unresolved_klass(_holder, get_klass_index());
duke@435 227 }
duke@435 228
duke@435 229 // ------------------------------------------------------------------
duke@435 230 // ciBytecodeStream::get_field_index
duke@435 231 //
duke@435 232 // If this is a field access bytecode, get the constant pool
duke@435 233 // index of the referenced field.
duke@435 234 int ciBytecodeStream::get_field_index() {
duke@435 235 assert(cur_bc() == Bytecodes::_getfield ||
duke@435 236 cur_bc() == Bytecodes::_putfield ||
duke@435 237 cur_bc() == Bytecodes::_getstatic ||
duke@435 238 cur_bc() == Bytecodes::_putstatic, "wrong bc");
duke@435 239 return get_index_big();
duke@435 240 }
duke@435 241
duke@435 242
duke@435 243 // ------------------------------------------------------------------
duke@435 244 // ciBytecodeStream::get_field
duke@435 245 //
duke@435 246 // If this bytecode is one of get_field, get_static, put_field,
duke@435 247 // or put_static, get the referenced field.
duke@435 248 ciField* ciBytecodeStream::get_field(bool& will_link) {
duke@435 249 ciField* f = CURRENT_ENV->get_field_by_index(_holder, get_field_index());
duke@435 250 will_link = f->will_link(_holder, _bc);
duke@435 251 return f;
duke@435 252 }
duke@435 253
duke@435 254
duke@435 255 // ------------------------------------------------------------------
duke@435 256 // ciBytecodeStream::get_declared_field_holder
duke@435 257 //
duke@435 258 // Get the declared holder of the currently referenced field.
duke@435 259 //
duke@435 260 // Usage note: the holder() of a ciField class returns the canonical
duke@435 261 // holder of the field, rather than the holder declared in the
duke@435 262 // bytecodes.
duke@435 263 //
duke@435 264 // There is no "will_link" result passed back. The user is responsible
duke@435 265 // for checking linkability when retrieving the associated field.
duke@435 266 ciInstanceKlass* ciBytecodeStream::get_declared_field_holder() {
duke@435 267 int holder_index = get_field_holder_index();
duke@435 268 bool ignore;
duke@435 269 return CURRENT_ENV->get_klass_by_index(_holder, holder_index, ignore)
duke@435 270 ->as_instance_klass();
duke@435 271 }
duke@435 272
duke@435 273 // ------------------------------------------------------------------
duke@435 274 // ciBytecodeStream::get_field_holder_index
duke@435 275 //
duke@435 276 // Get the constant pool index of the declared holder of the field
duke@435 277 // referenced by the current bytecode. Used for generating
duke@435 278 // deoptimization information.
duke@435 279 int ciBytecodeStream::get_field_holder_index() {
duke@435 280 VM_ENTRY_MARK;
duke@435 281 constantPoolOop cpool = _holder->get_instanceKlass()->constants();
duke@435 282 return cpool->klass_ref_index_at(get_field_index());
duke@435 283 }
duke@435 284
duke@435 285 // ------------------------------------------------------------------
duke@435 286 // ciBytecodeStream::get_field_signature_index
duke@435 287 //
duke@435 288 // Get the constant pool index of the signature of the field
duke@435 289 // referenced by the current bytecode. Used for generating
duke@435 290 // deoptimization information.
duke@435 291 int ciBytecodeStream::get_field_signature_index() {
duke@435 292 VM_ENTRY_MARK;
duke@435 293 constantPoolOop cpool = _holder->get_instanceKlass()->constants();
duke@435 294 int nt_index = cpool->name_and_type_ref_index_at(get_field_index());
duke@435 295 return cpool->signature_ref_index_at(nt_index);
duke@435 296 }
duke@435 297
duke@435 298 // ------------------------------------------------------------------
duke@435 299 // ciBytecodeStream::get_method_index
duke@435 300 //
duke@435 301 // If this is a method invocation bytecode, get the constant pool
duke@435 302 // index of the invoked method.
duke@435 303 int ciBytecodeStream::get_method_index() {
jrose@1161 304 #ifdef ASSERT
duke@435 305 switch (cur_bc()) {
duke@435 306 case Bytecodes::_invokeinterface:
duke@435 307 case Bytecodes::_invokevirtual:
duke@435 308 case Bytecodes::_invokespecial:
duke@435 309 case Bytecodes::_invokestatic:
jrose@1161 310 case Bytecodes::_invokedynamic:
jrose@1161 311 break;
duke@435 312 default:
duke@435 313 ShouldNotReachHere();
duke@435 314 }
jrose@1161 315 #endif
jrose@1161 316 return get_index_int();
duke@435 317 }
duke@435 318
duke@435 319 // ------------------------------------------------------------------
duke@435 320 // ciBytecodeStream::get_method
duke@435 321 //
duke@435 322 // If this is a method invocation bytecode, get the invoked method.
duke@435 323 ciMethod* ciBytecodeStream::get_method(bool& will_link) {
duke@435 324 ciMethod* m = CURRENT_ENV->get_method_by_index(_holder, get_method_index(),cur_bc());
duke@435 325 will_link = m->is_loaded();
duke@435 326 return m;
duke@435 327 }
duke@435 328
duke@435 329 // ------------------------------------------------------------------
duke@435 330 // ciBytecodeStream::get_declared_method_holder
duke@435 331 //
duke@435 332 // Get the declared holder of the currently referenced method.
duke@435 333 //
duke@435 334 // Usage note: the holder() of a ciMethod class returns the canonical
duke@435 335 // holder of the method, rather than the holder declared in the
duke@435 336 // bytecodes.
duke@435 337 //
duke@435 338 // There is no "will_link" result passed back. The user is responsible
duke@435 339 // for checking linkability when retrieving the associated method.
duke@435 340 ciKlass* ciBytecodeStream::get_declared_method_holder() {
duke@435 341 bool ignore;
twisti@1570 342 // report as InvokeDynamic for invokedynamic, which is syntactically classless
jrose@1161 343 if (cur_bc() == Bytecodes::_invokedynamic)
twisti@1570 344 return CURRENT_ENV->get_klass_by_name(_holder, ciSymbol::java_dyn_InvokeDynamic(), false);
duke@435 345 return CURRENT_ENV->get_klass_by_index(_holder, get_method_holder_index(), ignore);
duke@435 346 }
duke@435 347
duke@435 348 // ------------------------------------------------------------------
duke@435 349 // ciBytecodeStream::get_method_holder_index
duke@435 350 //
duke@435 351 // Get the constant pool index of the declared holder of the method
duke@435 352 // referenced by the current bytecode. Used for generating
duke@435 353 // deoptimization information.
duke@435 354 int ciBytecodeStream::get_method_holder_index() {
duke@435 355 VM_ENTRY_MARK;
duke@435 356 constantPoolOop cpool = _holder->get_instanceKlass()->constants();
duke@435 357 return cpool->klass_ref_index_at(get_method_index());
duke@435 358 }
duke@435 359
duke@435 360 // ------------------------------------------------------------------
duke@435 361 // ciBytecodeStream::get_method_signature_index
duke@435 362 //
duke@435 363 // Get the constant pool index of the signature of the method
duke@435 364 // referenced by the current bytecode. Used for generating
duke@435 365 // deoptimization information.
duke@435 366 int ciBytecodeStream::get_method_signature_index() {
duke@435 367 VM_ENTRY_MARK;
duke@435 368 constantPoolOop cpool = _holder->get_instanceKlass()->constants();
duke@435 369 int method_index = get_method_index();
duke@435 370 int name_and_type_index = cpool->name_and_type_ref_index_at(method_index);
duke@435 371 return cpool->signature_ref_index_at(name_and_type_index);
duke@435 372 }

mercurial