duke@435: /* xdono@1279: * Copyright 1999-2009 Sun Microsystems, Inc. All Rights Reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * duke@435: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, duke@435: * CA 95054 USA or visit www.sun.com if you need additional information or duke@435: * have any questions. duke@435: * duke@435: */ duke@435: duke@435: #include "incls/_precompiled.incl" duke@435: #include "incls/_ciStreams.cpp.incl" duke@435: duke@435: // ciExceptionHandlerStream duke@435: // duke@435: // Walk over some selected set of a methods exception handlers. duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciExceptionHandlerStream::count duke@435: // duke@435: // How many exception handlers are there in this stream? duke@435: // duke@435: // Implementation note: Compiler2 needs this functionality, so I had duke@435: int ciExceptionHandlerStream::count() { duke@435: int save_pos = _pos; duke@435: int save_end = _end; duke@435: duke@435: int count = 0; duke@435: duke@435: _pos = -1; duke@435: _end = _method->_handler_count; duke@435: duke@435: duke@435: next(); duke@435: while (!is_done()) { duke@435: count++; duke@435: next(); duke@435: } duke@435: duke@435: _pos = save_pos; duke@435: _end = save_end; duke@435: duke@435: return count; duke@435: } duke@435: duke@435: int ciExceptionHandlerStream::count_remaining() { duke@435: int save_pos = _pos; duke@435: int save_end = _end; duke@435: duke@435: int count = 0; duke@435: duke@435: while (!is_done()) { duke@435: count++; duke@435: next(); duke@435: } duke@435: duke@435: _pos = save_pos; duke@435: _end = save_end; duke@435: duke@435: return count; duke@435: } duke@435: duke@435: // ciBytecodeStream duke@435: // duke@435: // The class is used to iterate over the bytecodes of a method. duke@435: // It hides the details of constant pool structure/access by duke@435: // providing accessors for constant pool items. duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciBytecodeStream::wide duke@435: // duke@435: // Special handling for the wide bytcode duke@435: Bytecodes::Code ciBytecodeStream::wide() duke@435: { duke@435: // Get following bytecode; do not return wide duke@435: Bytecodes::Code bc = (Bytecodes::Code)_pc[1]; duke@435: _pc += 2; // Skip both bytecodes duke@435: _pc += 2; // Skip index always duke@435: if( bc == Bytecodes::_iinc ) duke@435: _pc += 2; // Skip optional constant duke@435: _was_wide = _pc; // Flag last wide bytecode found duke@435: return bc; duke@435: } duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciBytecodeStream::table duke@435: // duke@435: // Special handling for switch ops duke@435: Bytecodes::Code ciBytecodeStream::table( Bytecodes::Code bc ) { duke@435: switch( bc ) { // Check for special bytecode handling duke@435: duke@435: case Bytecodes::_lookupswitch: duke@435: _pc++; // Skip wide bytecode duke@435: _pc += (_start-_pc)&3; // Word align duke@435: _table_base = (jint*)_pc; // Capture for later usage duke@435: // table_base[0] is default far_dest duke@435: // Table has 2 lead elements (default, length), then pairs of u4 values. duke@435: // So load table length, and compute address at end of table duke@435: _pc = (address)&_table_base[2+ 2*Bytes::get_Java_u4((address)&_table_base[1])]; duke@435: break; duke@435: duke@435: case Bytecodes::_tableswitch: { duke@435: _pc++; // Skip wide bytecode duke@435: _pc += (_start-_pc)&3; // Word align duke@435: _table_base = (jint*)_pc; // Capture for later usage duke@435: // table_base[0] is default far_dest duke@435: int lo = Bytes::get_Java_u4((address)&_table_base[1]);// Low bound duke@435: int hi = Bytes::get_Java_u4((address)&_table_base[2]);// High bound duke@435: int len = hi - lo + 1; // Dense table size duke@435: _pc = (address)&_table_base[3+len]; // Skip past table duke@435: break; duke@435: } duke@435: duke@435: default: duke@435: fatal("unhandled bytecode"); duke@435: } duke@435: return bc; duke@435: } duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciBytecodeStream::reset_to_bci duke@435: void ciBytecodeStream::reset_to_bci( int bci ) { duke@435: _bc_start=_was_wide=0; duke@435: _pc = _start+bci; duke@435: } duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciBytecodeStream::force_bci duke@435: void ciBytecodeStream::force_bci(int bci) { duke@435: if (bci < 0) { duke@435: reset_to_bci(0); duke@435: _bc_start = _start + bci; duke@435: _bc = EOBC(); duke@435: } else { duke@435: reset_to_bci(bci); duke@435: next(); duke@435: } duke@435: } duke@435: duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // Constant pool access duke@435: // ------------------------------------------------------------------ duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciBytecodeStream::get_klass_index duke@435: // duke@435: // If this bytecodes references a klass, return the index of the duke@435: // referenced klass. duke@435: int ciBytecodeStream::get_klass_index() const { duke@435: switch(cur_bc()) { duke@435: case Bytecodes::_ldc: duke@435: return get_index(); duke@435: case Bytecodes::_ldc_w: duke@435: case Bytecodes::_ldc2_w: duke@435: case Bytecodes::_checkcast: duke@435: case Bytecodes::_instanceof: duke@435: case Bytecodes::_anewarray: duke@435: case Bytecodes::_multianewarray: duke@435: case Bytecodes::_new: duke@435: case Bytecodes::_newarray: duke@435: return get_index_big(); duke@435: default: duke@435: ShouldNotReachHere(); duke@435: return 0; duke@435: } duke@435: } duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciBytecodeStream::get_klass duke@435: // duke@435: // If this bytecode is a new, newarray, multianewarray, instanceof, duke@435: // or checkcast, get the referenced klass. duke@435: ciKlass* ciBytecodeStream::get_klass(bool& will_link) { duke@435: return CURRENT_ENV->get_klass_by_index(_holder, get_klass_index(), duke@435: will_link); duke@435: } duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciBytecodeStream::get_constant_index duke@435: // duke@435: // If this bytecode is one of the ldc variants, get the index of the duke@435: // referenced constant. duke@435: int ciBytecodeStream::get_constant_index() const { duke@435: switch(cur_bc()) { duke@435: case Bytecodes::_ldc: duke@435: return get_index(); duke@435: case Bytecodes::_ldc_w: duke@435: case Bytecodes::_ldc2_w: duke@435: return get_index_big(); duke@435: default: duke@435: ShouldNotReachHere(); duke@435: return 0; duke@435: } duke@435: } duke@435: // ------------------------------------------------------------------ duke@435: // ciBytecodeStream::get_constant duke@435: // duke@435: // If this bytecode is one of the ldc variants, get the referenced duke@435: // constant. duke@435: ciConstant ciBytecodeStream::get_constant() { duke@435: return CURRENT_ENV->get_constant_by_index(_holder, get_constant_index()); duke@435: } duke@435: duke@435: // ------------------------------------------------------------------ duke@435: bool ciBytecodeStream::is_unresolved_string() const { duke@435: return CURRENT_ENV->is_unresolved_string(_holder, get_constant_index()); duke@435: } duke@435: duke@435: // ------------------------------------------------------------------ duke@435: bool ciBytecodeStream::is_unresolved_klass() const { duke@435: return CURRENT_ENV->is_unresolved_klass(_holder, get_klass_index()); duke@435: } duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciBytecodeStream::get_field_index duke@435: // duke@435: // If this is a field access bytecode, get the constant pool duke@435: // index of the referenced field. duke@435: int ciBytecodeStream::get_field_index() { duke@435: assert(cur_bc() == Bytecodes::_getfield || duke@435: cur_bc() == Bytecodes::_putfield || duke@435: cur_bc() == Bytecodes::_getstatic || duke@435: cur_bc() == Bytecodes::_putstatic, "wrong bc"); duke@435: return get_index_big(); duke@435: } duke@435: duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciBytecodeStream::get_field duke@435: // duke@435: // If this bytecode is one of get_field, get_static, put_field, duke@435: // or put_static, get the referenced field. duke@435: ciField* ciBytecodeStream::get_field(bool& will_link) { duke@435: ciField* f = CURRENT_ENV->get_field_by_index(_holder, get_field_index()); duke@435: will_link = f->will_link(_holder, _bc); duke@435: return f; duke@435: } duke@435: duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciBytecodeStream::get_declared_field_holder duke@435: // duke@435: // Get the declared holder of the currently referenced field. duke@435: // duke@435: // Usage note: the holder() of a ciField class returns the canonical duke@435: // holder of the field, rather than the holder declared in the duke@435: // bytecodes. duke@435: // duke@435: // There is no "will_link" result passed back. The user is responsible duke@435: // for checking linkability when retrieving the associated field. duke@435: ciInstanceKlass* ciBytecodeStream::get_declared_field_holder() { duke@435: int holder_index = get_field_holder_index(); duke@435: bool ignore; duke@435: return CURRENT_ENV->get_klass_by_index(_holder, holder_index, ignore) duke@435: ->as_instance_klass(); duke@435: } duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciBytecodeStream::get_field_holder_index duke@435: // duke@435: // Get the constant pool index of the declared holder of the field duke@435: // referenced by the current bytecode. Used for generating duke@435: // deoptimization information. duke@435: int ciBytecodeStream::get_field_holder_index() { duke@435: VM_ENTRY_MARK; duke@435: constantPoolOop cpool = _holder->get_instanceKlass()->constants(); duke@435: return cpool->klass_ref_index_at(get_field_index()); duke@435: } duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciBytecodeStream::get_field_signature_index duke@435: // duke@435: // Get the constant pool index of the signature of the field duke@435: // referenced by the current bytecode. Used for generating duke@435: // deoptimization information. duke@435: int ciBytecodeStream::get_field_signature_index() { duke@435: VM_ENTRY_MARK; duke@435: constantPoolOop cpool = _holder->get_instanceKlass()->constants(); duke@435: int nt_index = cpool->name_and_type_ref_index_at(get_field_index()); duke@435: return cpool->signature_ref_index_at(nt_index); duke@435: } duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciBytecodeStream::get_method_index duke@435: // duke@435: // If this is a method invocation bytecode, get the constant pool duke@435: // index of the invoked method. duke@435: int ciBytecodeStream::get_method_index() { jrose@1161: #ifdef ASSERT duke@435: switch (cur_bc()) { duke@435: case Bytecodes::_invokeinterface: duke@435: case Bytecodes::_invokevirtual: duke@435: case Bytecodes::_invokespecial: duke@435: case Bytecodes::_invokestatic: jrose@1161: case Bytecodes::_invokedynamic: jrose@1161: break; duke@435: default: duke@435: ShouldNotReachHere(); duke@435: } jrose@1161: #endif jrose@1161: return get_index_int(); duke@435: } duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciBytecodeStream::get_method duke@435: // duke@435: // If this is a method invocation bytecode, get the invoked method. duke@435: ciMethod* ciBytecodeStream::get_method(bool& will_link) { twisti@1572: ciMethod* m = CURRENT_ENV->get_method_by_index(_holder, get_method_index(), cur_bc()); duke@435: will_link = m->is_loaded(); duke@435: return m; duke@435: } duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciBytecodeStream::get_declared_method_holder duke@435: // duke@435: // Get the declared holder of the currently referenced method. duke@435: // duke@435: // Usage note: the holder() of a ciMethod class returns the canonical duke@435: // holder of the method, rather than the holder declared in the duke@435: // bytecodes. duke@435: // duke@435: // There is no "will_link" result passed back. The user is responsible duke@435: // for checking linkability when retrieving the associated method. duke@435: ciKlass* ciBytecodeStream::get_declared_method_holder() { duke@435: bool ignore; twisti@1570: // report as InvokeDynamic for invokedynamic, which is syntactically classless jrose@1161: if (cur_bc() == Bytecodes::_invokedynamic) twisti@1570: return CURRENT_ENV->get_klass_by_name(_holder, ciSymbol::java_dyn_InvokeDynamic(), false); duke@435: return CURRENT_ENV->get_klass_by_index(_holder, get_method_holder_index(), ignore); duke@435: } duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciBytecodeStream::get_method_holder_index duke@435: // duke@435: // Get the constant pool index of the declared holder of the method duke@435: // referenced by the current bytecode. Used for generating duke@435: // deoptimization information. duke@435: int ciBytecodeStream::get_method_holder_index() { duke@435: VM_ENTRY_MARK; duke@435: constantPoolOop cpool = _holder->get_instanceKlass()->constants(); duke@435: return cpool->klass_ref_index_at(get_method_index()); duke@435: } duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciBytecodeStream::get_method_signature_index duke@435: // duke@435: // Get the constant pool index of the signature of the method duke@435: // referenced by the current bytecode. Used for generating duke@435: // deoptimization information. duke@435: int ciBytecodeStream::get_method_signature_index() { duke@435: VM_ENTRY_MARK; duke@435: constantPoolOop cpool = _holder->get_instanceKlass()->constants(); duke@435: int method_index = get_method_index(); duke@435: int name_and_type_index = cpool->name_and_type_ref_index_at(method_index); duke@435: return cpool->signature_ref_index_at(name_and_type_index); duke@435: } twisti@1572: twisti@1572: // ------------------------------------------------------------------ twisti@1572: // ciBytecodeStream::get_cpcache twisti@1572: ciCPCache* ciBytecodeStream::get_cpcache() { twisti@1572: VM_ENTRY_MARK; twisti@1572: // Get the constant pool. twisti@1572: constantPoolOop cpool = _holder->get_instanceKlass()->constants(); twisti@1572: constantPoolCacheOop cpcache = cpool->cache(); twisti@1572: twisti@1572: return CURRENT_ENV->get_object(cpcache)->as_cpcache(); twisti@1572: }