methodDataOop.cpp revision 726
0N/A/*
1472N/A * Copyright 2000-2008 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 *
1472N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
1472N/A * CA 95054 USA or visit www.sun.com if you need additional information or
1472N/A * have any questions.
0N/A *
0N/A */
0N/A
0N/A# include "incls/_precompiled.incl"
0N/A# include "incls/_methodDataOop.cpp.incl"
0N/A
0N/A// ==================================================================
0N/A// DataLayout
0N/A//
0N/A// Overlay for generic profiling data.
0N/A
0N/A// Some types of data layouts need a length field.
0N/Abool DataLayout::needs_array_len(u1 tag) {
0N/A return (tag == multi_branch_data_tag) || (tag == arg_info_data_tag);
0N/A}
0N/A
0N/A// Perform generic initialization of the data. More specific
0N/A// initialization occurs in overrides of ProfileData::post_initialize.
0N/Avoid DataLayout::initialize(u1 tag, u2 bci, int cell_count) {
0N/A _header._bits = (intptr_t)0;
0N/A _header._struct._tag = tag;
0N/A _header._struct._bci = bci;
0N/A for (int i = 0; i < cell_count; i++) {
0N/A set_cell_at(i, (intptr_t)0);
0N/A }
0N/A if (needs_array_len(tag)) {
0N/A set_cell_at(ArrayData::array_len_off_set, cell_count - 1); // -1 for header.
0N/A }
0N/A}
0N/A
0N/A// ==================================================================
0N/A// ProfileData
0N/A//
0N/A// A ProfileData object is created to refer to a section of profiling
0N/A// data in a structured way.
0N/A
0N/A// Constructor for invalid ProfileData.
0N/AProfileData::ProfileData() {
0N/A _data = NULL;
0N/A}
0N/A
0N/A#ifndef PRODUCT
0N/Avoid ProfileData::print_shared(outputStream* st, const char* name) {
0N/A st->print("bci: %d", bci());
0N/A st->fill_to(tab_width_one);
0N/A st->print("%s", name);
0N/A tab(st);
0N/A int trap = trap_state();
0N/A if (trap != 0) {
0N/A char buf[100];
0N/A st->print("trap(%s) ", Deoptimization::format_trap_state(buf, sizeof(buf), trap));
0N/A }
0N/A int flags = data()->flags();
0N/A if (flags != 0)
0N/A st->print("flags(%d) ", flags);
0N/A}
0N/A
0N/Avoid ProfileData::tab(outputStream* st) {
0N/A st->fill_to(tab_width_two);
0N/A}
0N/A#endif // !PRODUCT
0N/A
0N/A// ==================================================================
0N/A// BitData
0N/A//
0N/A// A BitData corresponds to a one-bit flag. This is used to indicate
0N/A// whether a checkcast bytecode has seen a null value.
0N/A
0N/A
0N/A#ifndef PRODUCT
0N/Avoid BitData::print_data_on(outputStream* st) {
0N/A print_shared(st, "BitData");
0N/A}
0N/A#endif // !PRODUCT
0N/A
0N/A// ==================================================================
0N/A// CounterData
0N/A//
0N/A// A CounterData corresponds to a simple counter.
0N/A
0N/A#ifndef PRODUCT
0N/Avoid CounterData::print_data_on(outputStream* st) {
0N/A print_shared(st, "CounterData");
0N/A st->print_cr("count(%u)", count());
0N/A}
0N/A#endif // !PRODUCT
0N/A
0N/A// ==================================================================
0N/A// JumpData
0N/A//
0N/A// A JumpData is used to access profiling information for a direct
0N/A// branch. It is a counter, used for counting the number of branches,
0N/A// plus a data displacement, used for realigning the data pointer to
0N/A// the corresponding target bci.
0N/A
0N/Avoid JumpData::post_initialize(BytecodeStream* stream, methodDataOop mdo) {
0N/A assert(stream->bci() == bci(), "wrong pos");
0N/A int target;
0N/A Bytecodes::Code c = stream->code();
0N/A if (c == Bytecodes::_goto_w || c == Bytecodes::_jsr_w) {
0N/A target = stream->dest_w();
0N/A } else {
0N/A target = stream->dest();
0N/A }
0N/A int my_di = mdo->dp_to_di(dp());
0N/A int target_di = mdo->bci_to_di(target);
0N/A int offset = target_di - my_di;
0N/A set_displacement(offset);
0N/A}
0N/A
0N/A#ifndef PRODUCT
0N/Avoid JumpData::print_data_on(outputStream* st) {
0N/A print_shared(st, "JumpData");
0N/A st->print_cr("taken(%u) displacement(%d)", taken(), displacement());
0N/A}
0N/A#endif // !PRODUCT
0N/A
0N/A// ==================================================================
0N/A// ReceiverTypeData
0N/A//
0N/A// A ReceiverTypeData is used to access profiling information about a
0N/A// dynamic type check. It consists of a counter which counts the total times
0N/A// that the check is reached, and a series of (klassOop, count) pairs
0N/A// which are used to store a type profile for the receiver of the check.
0N/A
0N/Avoid ReceiverTypeData::follow_contents() {
0N/A for (uint row = 0; row < row_limit(); row++) {
0N/A if (receiver(row) != NULL) {
0N/A MarkSweep::mark_and_push(adr_receiver(row));
0N/A }
0N/A }
0N/A}
0N/A
0N/A#ifndef SERIALGC
0N/Avoid ReceiverTypeData::follow_contents(ParCompactionManager* cm) {
0N/A for (uint row = 0; row < row_limit(); row++) {
0N/A if (receiver(row) != NULL) {
0N/A PSParallelCompact::mark_and_push(cm, adr_receiver(row));
0N/A }
0N/A }
0N/A}
0N/A#endif // SERIALGC
0N/A
0N/Avoid ReceiverTypeData::oop_iterate(OopClosure* blk) {
0N/A for (uint row = 0; row < row_limit(); row++) {
0N/A if (receiver(row) != NULL) {
0N/A blk->do_oop(adr_receiver(row));
0N/A }
0N/A }
0N/A}
0N/A
0N/Avoid ReceiverTypeData::oop_iterate_m(OopClosure* blk, MemRegion mr) {
0N/A for (uint row = 0; row < row_limit(); row++) {
0N/A if (receiver(row) != NULL) {
0N/A oop* adr = adr_receiver(row);
0N/A if (mr.contains(adr)) {
0N/A blk->do_oop(adr);
0N/A }
0N/A }
0N/A }
0N/A}
0N/A
0N/Avoid ReceiverTypeData::adjust_pointers() {
0N/A for (uint row = 0; row < row_limit(); row++) {
0N/A if (receiver(row) != NULL) {
0N/A MarkSweep::adjust_pointer(adr_receiver(row));
0N/A }
0N/A }
1273N/A}
1273N/A
1273N/A#ifndef SERIALGC
1273N/Avoid ReceiverTypeData::update_pointers() {
1273N/A for (uint row = 0; row < row_limit(); row++) {
1273N/A if (receiver_unchecked(row) != NULL) {
1273N/A PSParallelCompact::adjust_pointer(adr_receiver(row));
1273N/A }
0N/A }
0N/A}
0N/A
0N/Avoid ReceiverTypeData::update_pointers(HeapWord* beg_addr, HeapWord* end_addr) {
1273N/A // The loop bounds could be computed based on beg_addr/end_addr and the
1273N/A // boundary test hoisted outside the loop (see klassVTable for an example);
0N/A // however, row_limit() is small enough (2) to make that less efficient.
0N/A for (uint row = 0; row < row_limit(); row++) {
0N/A if (receiver_unchecked(row) != NULL) {
0N/A PSParallelCompact::adjust_pointer(adr_receiver(row), beg_addr, end_addr);
0N/A }
0N/A }
0N/A}
0N/A#endif // SERIALGC
0N/A
0N/A#ifndef PRODUCT
0N/Avoid ReceiverTypeData::print_receiver_data_on(outputStream* st) {
0N/A uint row;
0N/A int entries = 0;
0N/A for (row = 0; row < row_limit(); row++) {
0N/A if (receiver(row) != NULL) entries++;
0N/A }
0N/A st->print_cr("count(%u) entries(%u)", count(), entries);
0N/A for (row = 0; row < row_limit(); row++) {
0N/A if (receiver(row) != NULL) {
0N/A tab(st);
0N/A receiver(row)->print_value_on(st);
0N/A st->print_cr("(%u)", receiver_count(row));
0N/A }
0N/A }
0N/A}
0N/Avoid ReceiverTypeData::print_data_on(outputStream* st) {
0N/A print_shared(st, "ReceiverTypeData");
0N/A print_receiver_data_on(st);
1172N/A}
0N/Avoid VirtualCallData::print_data_on(outputStream* st) {
0N/A print_shared(st, "VirtualCallData");
0N/A print_receiver_data_on(st);
0N/A}
0N/A#endif // !PRODUCT
0N/A
0N/A// ==================================================================
0N/A// RetData
0N/A//
0N/A// A RetData is used to access profiling information for a ret bytecode.
0N/A// It is composed of a count of the number of times that the ret has
0N/A// been executed, followed by a series of triples of the form
0N/A// (bci, count, di) which count the number of times that some bci was the
0N/A// target of the ret and cache a corresponding displacement.
0N/A
0N/Avoid RetData::post_initialize(BytecodeStream* stream, methodDataOop mdo) {
0N/A for (uint row = 0; row < row_limit(); row++) {
0N/A set_bci_displacement(row, -1);
0N/A set_bci(row, no_bci);
0N/A }
0N/A // release so other threads see a consistent state. bci is used as
0N/A // a valid flag for bci_displacement.
0N/A OrderAccess::release();
0N/A}
0N/A
0N/A// This routine needs to atomically update the RetData structure, so the
0N/A// caller needs to hold the RetData_lock before it gets here. Since taking
0N/A// the lock can block (and allow GC) and since RetData is a ProfileData is a
0N/A// wrapper around a derived oop, taking the lock in _this_ method will
0N/A// basically cause the 'this' pointer's _data field to contain junk after the
0N/A// lock. We require the caller to take the lock before making the ProfileData
0N/A// structure. Currently the only caller is InterpreterRuntime::update_mdp_for_ret
0N/Aaddress RetData::fixup_ret(int return_bci, methodDataHandle h_mdo) {
0N/A // First find the mdp which corresponds to the return bci.
0N/A address mdp = h_mdo->bci_to_dp(return_bci);
0N/A
0N/A // Now check to see if any of the cache slots are open.
0N/A for (uint row = 0; row < row_limit(); row++) {
0N/A if (bci(row) == no_bci) {
0N/A set_bci_displacement(row, mdp - dp());
0N/A set_bci_count(row, DataLayout::counter_increment);
0N/A // Barrier to ensure displacement is written before the bci; allows
0N/A // the interpreter to read displacement without fear of race condition.
0N/A release_set_bci(row, return_bci);
0N/A break;
0N/A }
0N/A }
0N/A return mdp;
0N/A}
0N/A
0N/A
0N/A#ifndef PRODUCT
0N/Avoid RetData::print_data_on(outputStream* st) {
0N/A print_shared(st, "RetData");
0N/A uint row;
0N/A int entries = 0;
0N/A for (row = 0; row < row_limit(); row++) {
0N/A if (bci(row) != no_bci) entries++;
0N/A }
0N/A st->print_cr("count(%u) entries(%u)", count(), entries);
0N/A for (row = 0; row < row_limit(); row++) {
0N/A if (bci(row) != no_bci) {
0N/A tab(st);
0N/A st->print_cr("bci(%d: count(%u) displacement(%d))",
0N/A bci(row), bci_count(row), bci_displacement(row));
0N/A }
0N/A }
0N/A}
0N/A#endif // !PRODUCT
0N/A
0N/A// ==================================================================
0N/A// BranchData
0N/A//
0N/A// A BranchData is used to access profiling data for a two-way branch.
0N/A// It consists of taken and not_taken counts as well as a data displacement
0N/A// for the taken case.
0N/A
0N/Avoid BranchData::post_initialize(BytecodeStream* stream, methodDataOop mdo) {
0N/A assert(stream->bci() == bci(), "wrong pos");
0N/A int target = stream->dest();
0N/A int my_di = mdo->dp_to_di(dp());
0N/A int target_di = mdo->bci_to_di(target);
0N/A int offset = target_di - my_di;
0N/A set_displacement(offset);
0N/A}
0N/A
0N/A#ifndef PRODUCT
0N/Avoid BranchData::print_data_on(outputStream* st) {
0N/A print_shared(st, "BranchData");
0N/A st->print_cr("taken(%u) displacement(%d)",
0N/A taken(), displacement());
0N/A tab(st);
0N/A st->print_cr("not taken(%u)", not_taken());
0N/A}
0N/A#endif
0N/A
0N/A// ==================================================================
0N/A// MultiBranchData
0N/A//
605N/A// A MultiBranchData is used to access profiling information for
0N/A// a multi-way branch (*switch bytecodes). It consists of a series
0N/A// of (count, displacement) pairs, which count the number of times each
0N/A// case was taken and specify the data displacment for each branch target.
0N/A
0N/Aint MultiBranchData::compute_cell_count(BytecodeStream* stream) {
0N/A int cell_count = 0;
0N/A if (stream->code() == Bytecodes::_tableswitch) {
0N/A Bytecode_tableswitch* sw = Bytecode_tableswitch_at(stream->bcp());
0N/A cell_count = 1 + per_case_cell_count * (1 + sw->length()); // 1 for default
0N/A } else {
0N/A Bytecode_lookupswitch* sw = Bytecode_lookupswitch_at(stream->bcp());
0N/A cell_count = 1 + per_case_cell_count * (sw->number_of_pairs() + 1); // 1 for default
0N/A }
0N/A return cell_count;
0N/A}
0N/A
0N/Avoid MultiBranchData::post_initialize(BytecodeStream* stream,
0N/A methodDataOop mdo) {
0N/A assert(stream->bci() == bci(), "wrong pos");
0N/A int target;
0N/A int my_di;
0N/A int target_di;
0N/A int offset;
0N/A if (stream->code() == Bytecodes::_tableswitch) {
0N/A Bytecode_tableswitch* sw = Bytecode_tableswitch_at(stream->bcp());
0N/A int len = sw->length();
0N/A assert(array_len() == per_case_cell_count * (len + 1), "wrong len");
0N/A for (int count = 0; count < len; count++) {
0N/A target = sw->dest_offset_at(count) + bci();
0N/A my_di = mdo->dp_to_di(dp());
0N/A target_di = mdo->bci_to_di(target);
0N/A offset = target_di - my_di;
0N/A set_displacement_at(count, offset);
0N/A }
0N/A target = sw->default_offset() + bci();
0N/A my_di = mdo->dp_to_di(dp());
0N/A target_di = mdo->bci_to_di(target);
0N/A offset = target_di - my_di;
0N/A set_default_displacement(offset);
0N/A
0N/A } else {
0N/A Bytecode_lookupswitch* sw = Bytecode_lookupswitch_at(stream->bcp());
0N/A int npairs = sw->number_of_pairs();
0N/A assert(array_len() == per_case_cell_count * (npairs + 1), "wrong len");
0N/A for (int count = 0; count < npairs; count++) {
0N/A LookupswitchPair *pair = sw->pair_at(count);
0N/A target = pair->offset() + bci();
0N/A my_di = mdo->dp_to_di(dp());
0N/A target_di = mdo->bci_to_di(target);
0N/A offset = target_di - my_di;
0N/A set_displacement_at(count, offset);
0N/A }
0N/A target = sw->default_offset() + bci();
0N/A my_di = mdo->dp_to_di(dp());
0N/A target_di = mdo->bci_to_di(target);
0N/A offset = target_di - my_di;
0N/A set_default_displacement(offset);
0N/A }
0N/A}
0N/A
0N/A#ifndef PRODUCT
0N/Avoid MultiBranchData::print_data_on(outputStream* st) {
0N/A print_shared(st, "MultiBranchData");
0N/A st->print_cr("default_count(%u) displacement(%d)",
0N/A default_count(), default_displacement());
0N/A int cases = number_of_cases();
0N/A for (int i = 0; i < cases; i++) {
0N/A tab(st);
0N/A st->print_cr("count(%u) displacement(%d)",
0N/A count_at(i), displacement_at(i));
0N/A }
0N/A}
0N/A#endif
0N/A
0N/A#ifndef PRODUCT
0N/Avoid ArgInfoData::print_data_on(outputStream* st) {
0N/A print_shared(st, "ArgInfoData");
0N/A int nargs = number_of_args();
0N/A for (int i = 0; i < nargs; i++) {
0N/A st->print(" 0x%x", arg_modified(i));
0N/A }
0N/A st->cr();
0N/A}
0N/A
0N/A#endif
0N/A// ==================================================================
0N/A// methodDataOop
0N/A//
0N/A// A methodDataOop holds information which has been collected about
0N/A// a method.
0N/A
0N/Aint methodDataOopDesc::bytecode_cell_count(Bytecodes::Code code) {
0N/A switch (code) {
0N/A case Bytecodes::_checkcast:
0N/A case Bytecodes::_instanceof:
0N/A case Bytecodes::_aastore:
0N/A if (TypeProfileCasts) {
0N/A return ReceiverTypeData::static_cell_count();
0N/A } else {
0N/A return BitData::static_cell_count();
0N/A }
0N/A case Bytecodes::_invokespecial:
0N/A case Bytecodes::_invokestatic:
0N/A return CounterData::static_cell_count();
0N/A case Bytecodes::_goto:
0N/A case Bytecodes::_goto_w:
0N/A case Bytecodes::_jsr:
0N/A case Bytecodes::_jsr_w:
0N/A return JumpData::static_cell_count();
0N/A case Bytecodes::_invokevirtual:
0N/A case Bytecodes::_invokeinterface:
0N/A return VirtualCallData::static_cell_count();
0N/A case Bytecodes::_invokedynamic:
0N/A return CounterData::static_cell_count();
0N/A case Bytecodes::_ret:
0N/A return RetData::static_cell_count();
0N/A case Bytecodes::_ifeq:
0N/A case Bytecodes::_ifne:
0N/A case Bytecodes::_iflt:
0N/A case Bytecodes::_ifge:
0N/A case Bytecodes::_ifgt:
0N/A case Bytecodes::_ifle:
0N/A case Bytecodes::_if_icmpeq:
0N/A case Bytecodes::_if_icmpne:
0N/A case Bytecodes::_if_icmplt:
0N/A case Bytecodes::_if_icmpge:
0N/A case Bytecodes::_if_icmpgt:
0N/A case Bytecodes::_if_icmple:
0N/A case Bytecodes::_if_acmpeq:
0N/A case Bytecodes::_if_acmpne:
0N/A case Bytecodes::_ifnull:
0N/A case Bytecodes::_ifnonnull:
0N/A return BranchData::static_cell_count();
0N/A case Bytecodes::_lookupswitch:
0N/A case Bytecodes::_tableswitch:
0N/A return variable_cell_count;
0N/A }
0N/A return no_profile_data;
0N/A}
0N/A
0N/A// Compute the size of the profiling information corresponding to
0N/A// the current bytecode.
0N/Aint methodDataOopDesc::compute_data_size(BytecodeStream* stream) {
0N/A int cell_count = bytecode_cell_count(stream->code());
0N/A if (cell_count == no_profile_data) {
0N/A return 0;
0N/A }
0N/A if (cell_count == variable_cell_count) {
0N/A cell_count = MultiBranchData::compute_cell_count(stream);
0N/A }
0N/A // Note: cell_count might be zero, meaning that there is just
0N/A // a DataLayout header, with no extra cells.
0N/A assert(cell_count >= 0, "sanity");
0N/A return DataLayout::compute_size_in_bytes(cell_count);
0N/A}
0N/A
0N/Aint methodDataOopDesc::compute_extra_data_count(int data_size, int empty_bc_count) {
0N/A if (ProfileTraps) {
0N/A // Assume that up to 3% of BCIs with no MDP will need to allocate one.
0N/A int extra_data_count = (uint)(empty_bc_count * 3) / 128 + 1;
0N/A // If the method is large, let the extra BCIs grow numerous (to ~1%).
0N/A int one_percent_of_data
0N/A = (uint)data_size / (DataLayout::header_size_in_bytes()*128);
0N/A if (extra_data_count < one_percent_of_data)
0N/A extra_data_count = one_percent_of_data;
0N/A if (extra_data_count > empty_bc_count)
0N/A extra_data_count = empty_bc_count; // no need for more
0N/A return extra_data_count;
0N/A } else {
0N/A return 0;
0N/A }
0N/A}
0N/A
0N/A// Compute the size of the methodDataOop necessary to store
0N/A// profiling information about a given method. Size is in bytes.
0N/Aint methodDataOopDesc::compute_allocation_size_in_bytes(methodHandle method) {
0N/A int data_size = 0;
0N/A BytecodeStream stream(method);
0N/A Bytecodes::Code c;
0N/A int empty_bc_count = 0; // number of bytecodes lacking data
0N/A while ((c = stream.next()) >= 0) {
0N/A int size_in_bytes = compute_data_size(&stream);
0N/A data_size += size_in_bytes;
0N/A if (size_in_bytes == 0) empty_bc_count += 1;
0N/A }
0N/A int object_size = in_bytes(data_offset()) + data_size;
0N/A
0N/A // Add some extra DataLayout cells (at least one) to track stray traps.
0N/A int extra_data_count = compute_extra_data_count(data_size, empty_bc_count);
0N/A object_size += extra_data_count * DataLayout::compute_size_in_bytes(0);
0N/A
0N/A // Add a cell to record information about modified arguments.
0N/A int arg_size = method->size_of_parameters();
0N/A object_size += DataLayout::compute_size_in_bytes(arg_size+1);
0N/A return object_size;
0N/A}
0N/A
0N/A// Compute the size of the methodDataOop necessary to store
0N/A// profiling information about a given method. Size is in words
0N/Aint methodDataOopDesc::compute_allocation_size_in_words(methodHandle method) {
0N/A int byte_size = compute_allocation_size_in_bytes(method);
0N/A int word_size = align_size_up(byte_size, BytesPerWord) / BytesPerWord;
0N/A return align_object_size(word_size);
0N/A}
0N/A
0N/A// Initialize an individual data segment. Returns the size of
0N/A// the segment in bytes.
0N/Aint methodDataOopDesc::initialize_data(BytecodeStream* stream,
0N/A int data_index) {
0N/A int cell_count = -1;
0N/A int tag = DataLayout::no_tag;
0N/A DataLayout* data_layout = data_layout_at(data_index);
0N/A Bytecodes::Code c = stream->code();
0N/A switch (c) {
0N/A case Bytecodes::_checkcast:
case Bytecodes::_instanceof:
case Bytecodes::_aastore:
if (TypeProfileCasts) {
cell_count = ReceiverTypeData::static_cell_count();
tag = DataLayout::receiver_type_data_tag;
} else {
cell_count = BitData::static_cell_count();
tag = DataLayout::bit_data_tag;
}
break;
case Bytecodes::_invokespecial:
case Bytecodes::_invokestatic:
cell_count = CounterData::static_cell_count();
tag = DataLayout::counter_data_tag;
break;
case Bytecodes::_goto:
case Bytecodes::_goto_w:
case Bytecodes::_jsr:
case Bytecodes::_jsr_w:
cell_count = JumpData::static_cell_count();
tag = DataLayout::jump_data_tag;
break;
case Bytecodes::_invokevirtual:
case Bytecodes::_invokeinterface:
cell_count = VirtualCallData::static_cell_count();
tag = DataLayout::virtual_call_data_tag;
break;
case Bytecodes::_invokedynamic:
// %%% should make a type profile for any invokedynamic that takes a ref argument
cell_count = CounterData::static_cell_count();
tag = DataLayout::counter_data_tag;
break;
case Bytecodes::_ret:
cell_count = RetData::static_cell_count();
tag = DataLayout::ret_data_tag;
break;
case Bytecodes::_ifeq:
case Bytecodes::_ifne:
case Bytecodes::_iflt:
case Bytecodes::_ifge:
case Bytecodes::_ifgt:
case Bytecodes::_ifle:
case Bytecodes::_if_icmpeq:
case Bytecodes::_if_icmpne:
case Bytecodes::_if_icmplt:
case Bytecodes::_if_icmpge:
case Bytecodes::_if_icmpgt:
case Bytecodes::_if_icmple:
case Bytecodes::_if_acmpeq:
case Bytecodes::_if_acmpne:
case Bytecodes::_ifnull:
case Bytecodes::_ifnonnull:
cell_count = BranchData::static_cell_count();
tag = DataLayout::branch_data_tag;
break;
case Bytecodes::_lookupswitch:
case Bytecodes::_tableswitch:
cell_count = MultiBranchData::compute_cell_count(stream);
tag = DataLayout::multi_branch_data_tag;
break;
}
assert(tag == DataLayout::multi_branch_data_tag ||
cell_count == bytecode_cell_count(c), "cell counts must agree");
if (cell_count >= 0) {
assert(tag != DataLayout::no_tag, "bad tag");
assert(bytecode_has_profile(c), "agree w/ BHP");
data_layout->initialize(tag, stream->bci(), cell_count);
return DataLayout::compute_size_in_bytes(cell_count);
} else {
assert(!bytecode_has_profile(c), "agree w/ !BHP");
return 0;
}
}
// Get the data at an arbitrary (sort of) data index.
ProfileData* methodDataOopDesc::data_at(int data_index) {
if (out_of_bounds(data_index)) {
return NULL;
}
DataLayout* data_layout = data_layout_at(data_index);
switch (data_layout->tag()) {
case DataLayout::no_tag:
default:
ShouldNotReachHere();
return NULL;
case DataLayout::bit_data_tag:
return new BitData(data_layout);
case DataLayout::counter_data_tag:
return new CounterData(data_layout);
case DataLayout::jump_data_tag:
return new JumpData(data_layout);
case DataLayout::receiver_type_data_tag:
return new ReceiverTypeData(data_layout);
case DataLayout::virtual_call_data_tag:
return new VirtualCallData(data_layout);
case DataLayout::ret_data_tag:
return new RetData(data_layout);
case DataLayout::branch_data_tag:
return new BranchData(data_layout);
case DataLayout::multi_branch_data_tag:
return new MultiBranchData(data_layout);
case DataLayout::arg_info_data_tag:
return new ArgInfoData(data_layout);
};
}
// Iteration over data.
ProfileData* methodDataOopDesc::next_data(ProfileData* current) {
int current_index = dp_to_di(current->dp());
int next_index = current_index + current->size_in_bytes();
ProfileData* next = data_at(next_index);
return next;
}
// Give each of the data entries a chance to perform specific
// data initialization.
void methodDataOopDesc::post_initialize(BytecodeStream* stream) {
ResourceMark rm;
ProfileData* data;
for (data = first_data(); is_valid(data); data = next_data(data)) {
stream->set_start(data->bci());
stream->next();
data->post_initialize(stream, this);
}
}
// Initialize the methodDataOop corresponding to a given method.
void methodDataOopDesc::initialize(methodHandle method) {
ResourceMark rm;
// Set the method back-pointer.
_method = method();
set_creation_mileage(mileage_of(method()));
// Initialize flags and trap history.
_nof_decompiles = 0;
_nof_overflow_recompiles = 0;
_nof_overflow_traps = 0;
assert(sizeof(_trap_hist) % sizeof(HeapWord) == 0, "align");
Copy::zero_to_words((HeapWord*) &_trap_hist,
sizeof(_trap_hist) / sizeof(HeapWord));
// Go through the bytecodes and allocate and initialize the
// corresponding data cells.
int data_size = 0;
int empty_bc_count = 0; // number of bytecodes lacking data
BytecodeStream stream(method);
Bytecodes::Code c;
while ((c = stream.next()) >= 0) {
int size_in_bytes = initialize_data(&stream, data_size);
data_size += size_in_bytes;
if (size_in_bytes == 0) empty_bc_count += 1;
}
_data_size = data_size;
int object_size = in_bytes(data_offset()) + data_size;
// Add some extra DataLayout cells (at least one) to track stray traps.
int extra_data_count = compute_extra_data_count(data_size, empty_bc_count);
int extra_size = extra_data_count * DataLayout::compute_size_in_bytes(0);
// Add a cell to record information about modified arguments.
// Set up _args_modified array after traps cells so that
// the code for traps cells works.
DataLayout *dp = data_layout_at(data_size + extra_size);
int arg_size = method->size_of_parameters();
dp->initialize(DataLayout::arg_info_data_tag, 0, arg_size+1);
object_size += extra_size + DataLayout::compute_size_in_bytes(arg_size+1);
// Set an initial hint. Don't use set_hint_di() because
// first_di() may be out of bounds if data_size is 0.
// In that situation, _hint_di is never used, but at
// least well-defined.
_hint_di = first_di();
post_initialize(&stream);
set_object_is_parsable(object_size);
}
// Get a measure of how much mileage the method has on it.
int methodDataOopDesc::mileage_of(methodOop method) {
int mileage = 0;
int iic = method->interpreter_invocation_count();
if (mileage < iic) mileage = iic;
InvocationCounter* ic = method->invocation_counter();
InvocationCounter* bc = method->backedge_counter();
int icval = ic->count();
if (ic->carry()) icval += CompileThreshold;
if (mileage < icval) mileage = icval;
int bcval = bc->count();
if (bc->carry()) bcval += CompileThreshold;
if (mileage < bcval) mileage = bcval;
return mileage;
}
bool methodDataOopDesc::is_mature() const {
uint current = mileage_of(_method);
uint initial = creation_mileage();
if (current < initial)
return true; // some sort of overflow
uint target;
if (ProfileMaturityPercentage <= 0)
target = (uint) -ProfileMaturityPercentage; // absolute value
else
target = (uint)( (ProfileMaturityPercentage * CompileThreshold) / 100 );
return (current >= initial + target);
}
// Translate a bci to its corresponding data index (di).
address methodDataOopDesc::bci_to_dp(int bci) {
ResourceMark rm;
ProfileData* data = data_before(bci);
ProfileData* prev = NULL;
for ( ; is_valid(data); data = next_data(data)) {
if (data->bci() >= bci) {
if (data->bci() == bci) set_hint_di(dp_to_di(data->dp()));
else if (prev != NULL) set_hint_di(dp_to_di(prev->dp()));
return data->dp();
}
prev = data;
}
return (address)limit_data_position();
}
// Translate a bci to its corresponding data, or NULL.
ProfileData* methodDataOopDesc::bci_to_data(int bci) {
ProfileData* data = data_before(bci);
for ( ; is_valid(data); data = next_data(data)) {
if (data->bci() == bci) {
set_hint_di(dp_to_di(data->dp()));
return data;
} else if (data->bci() > bci) {
break;
}
}
return bci_to_extra_data(bci, false);
}
// Translate a bci to its corresponding extra data, or NULL.
ProfileData* methodDataOopDesc::bci_to_extra_data(int bci, bool create_if_missing) {
DataLayout* dp = extra_data_base();
DataLayout* end = extra_data_limit();
DataLayout* avail = NULL;
for (; dp < end; dp = next_extra(dp)) {
// No need for "OrderAccess::load_acquire" ops,
// since the data structure is monotonic.
if (dp->tag() == DataLayout::no_tag) break;
if (dp->tag() == DataLayout::arg_info_data_tag) {
dp = end; // ArgInfoData is at the end of extra data section.
break;
}
if (dp->bci() == bci) {
assert(dp->tag() == DataLayout::bit_data_tag, "sane");
return new BitData(dp);
}
}
if (create_if_missing && dp < end) {
// Allocate this one. There is no mutual exclusion,
// so two threads could allocate different BCIs to the
// same data layout. This means these extra data
// records, like most other MDO contents, must not be
// trusted too much.
DataLayout temp;
temp.initialize(DataLayout::bit_data_tag, bci, 0);
dp->release_set_header(temp.header());
assert(dp->tag() == DataLayout::bit_data_tag, "sane");
//NO: assert(dp->bci() == bci, "no concurrent allocation");
return new BitData(dp);
}
return NULL;
}
ArgInfoData *methodDataOopDesc::arg_info() {
DataLayout* dp = extra_data_base();
DataLayout* end = extra_data_limit();
for (; dp < end; dp = next_extra(dp)) {
if (dp->tag() == DataLayout::arg_info_data_tag)
return new ArgInfoData(dp);
}
return NULL;
}
#ifndef PRODUCT
void methodDataOopDesc::print_data_on(outputStream* st) {
ResourceMark rm;
ProfileData* data = first_data();
for ( ; is_valid(data); data = next_data(data)) {
st->print("%d", dp_to_di(data->dp()));
st->fill_to(6);
data->print_data_on(st);
}
st->print_cr("--- Extra data:");
DataLayout* dp = extra_data_base();
DataLayout* end = extra_data_limit();
for (; dp < end; dp = next_extra(dp)) {
// No need for "OrderAccess::load_acquire" ops,
// since the data structure is monotonic.
if (dp->tag() == DataLayout::no_tag) continue;
if (dp->tag() == DataLayout::bit_data_tag) {
data = new BitData(dp);
} else {
assert(dp->tag() == DataLayout::arg_info_data_tag, "must be BitData or ArgInfo");
data = new ArgInfoData(dp);
dp = end; // ArgInfoData is at the end of extra data section.
}
st->print("%d", dp_to_di(data->dp()));
st->fill_to(6);
data->print_data_on(st);
}
}
#endif
void methodDataOopDesc::verify_data_on(outputStream* st) {
NEEDS_CLEANUP;
// not yet implemented.
}