annotate src/share/vm/ci/ciStreams.cpp @ 844:bd02caa94611

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