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