0N/A/*
2027N/A * Copyright (c) 2000, 2011, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
0N/A *
0N/A */
0N/A
1879N/A#include "precompiled.hpp"
1879N/A#include "classfile/systemDictionary.hpp"
1879N/A#include "gc_implementation/shared/markSweep.inline.hpp"
1879N/A#include "interpreter/bytecode.hpp"
1879N/A#include "interpreter/bytecodeStream.hpp"
1879N/A#include "interpreter/linkResolver.hpp"
1879N/A#include "oops/methodDataOop.hpp"
1879N/A#include "oops/oop.inline.hpp"
1879N/A#include "runtime/compilationPolicy.hpp"
1879N/A#include "runtime/deoptimization.hpp"
1879N/A#include "runtime/handles.inline.hpp"
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) {
45N/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
941N/Avoid DataLayout::follow_weak_refs(BoolObjectClosure* cl) {
941N/A ResourceMark m;
941N/A data_in()->follow_weak_refs(cl);
941N/A}
941N/A
941N/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() {
941N/A // This is a set of weak references that need
941N/A // to be followed at the end of the strong marking
941N/A // phase. Memoize this object so it can be visited
941N/A // in the weak roots processing phase.
941N/A MarkSweep::revisit_mdo(data());
0N/A}
0N/A
0N/A#ifndef SERIALGC
0N/Avoid ReceiverTypeData::follow_contents(ParCompactionManager* cm) {
941N/A // This is a set of weak references that need
941N/A // to be followed at the end of the strong marking
941N/A // phase. Memoize this object so it can be visited
941N/A // in the weak roots processing phase.
941N/A PSParallelCompact::revisit_mdo(cm, data());
0N/A}
0N/A#endif // SERIALGC
0N/A
0N/Avoid ReceiverTypeData::oop_iterate(OopClosure* blk) {
941N/A if (blk->should_remember_mdo()) {
941N/A // This is a set of weak references that need
941N/A // to be followed at the end of the strong marking
941N/A // phase. Memoize this object so it can be visited
941N/A // in the weak roots processing phase.
941N/A blk->remember_mdo(data());
941N/A } else { // normal scan
941N/A for (uint row = 0; row < row_limit(); row++) {
941N/A if (receiver(row) != NULL) {
941N/A oop* adr = adr_receiver(row);
0N/A blk->do_oop(adr);
0N/A }
0N/A }
0N/A }
0N/A}
0N/A
941N/Avoid ReceiverTypeData::oop_iterate_m(OopClosure* blk, MemRegion mr) {
941N/A // Currently, this interface is called only during card-scanning for
941N/A // a young gen gc, in which case this object cannot contribute anything,
941N/A // since it does not contain any references that cross out of
941N/A // the perm gen. However, for future more general use we allow
941N/A // the possibility of calling for instance from more general
941N/A // iterators (for example, a future regionalized perm gen for G1,
941N/A // or the possibility of moving some references out of perm in
941N/A // the case of other collectors). In that case, you will need
941N/A // to relax or remove some of the assertions below.
941N/A#ifdef ASSERT
941N/A // Verify that none of the embedded oop references cross out of
941N/A // this generation.
941N/A for (uint row = 0; row < row_limit(); row++) {
941N/A if (receiver(row) != NULL) {
941N/A oop* adr = adr_receiver(row);
941N/A CollectedHeap* h = Universe::heap();
941N/A assert(h->is_permanent(adr) && h->is_permanent_or_null(*adr), "Not intra-perm");
941N/A }
941N/A }
941N/A#endif // ASSERT
941N/A assert(!blk->should_remember_mdo(), "Not expected to remember MDO");
941N/A return; // Nothing to do, see comment above
941N/A#if 0
941N/A if (blk->should_remember_mdo()) {
941N/A // This is a set of weak references that need
941N/A // to be followed at the end of the strong marking
941N/A // phase. Memoize this object so it can be visited
941N/A // in the weak roots processing phase.
941N/A blk->remember_mdo(data());
941N/A } else { // normal scan
941N/A for (uint row = 0; row < row_limit(); row++) {
941N/A if (receiver(row) != NULL) {
941N/A oop* adr = adr_receiver(row);
941N/A if (mr.contains(adr)) {
941N/A blk->do_oop(adr);
941N/A } else if ((HeapWord*)adr >= mr.end()) {
941N/A // Test that the current cursor and the two ends of the range
941N/A // that we may have skipped iterating over are monotonically ordered;
941N/A // this is just a paranoid assertion, just in case represetations
941N/A // should change in the future rendering the short-circuit return
941N/A // here invalid.
941N/A assert((row+1 >= row_limit() || adr_receiver(row+1) > adr) &&
941N/A (row+2 >= row_limit() || adr_receiver(row_limit()-1) > adr_receiver(row+1)), "Reducing?");
941N/A break; // remaining should be outside this mr too
941N/A }
941N/A }
941N/A }
941N/A }
941N/A#endif
941N/A}
941N/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 }
0N/A}
0N/A
941N/Avoid ReceiverTypeData::follow_weak_refs(BoolObjectClosure* is_alive_cl) {
941N/A for (uint row = 0; row < row_limit(); row++) {
941N/A klassOop p = receiver(row);
941N/A if (p != NULL && !is_alive_cl->do_object_b(p)) {
941N/A clear_row(row);
941N/A }
941N/A }
941N/A}
941N/A
0N/A#ifndef SERIALGC
0N/Avoid ReceiverTypeData::update_pointers() {
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));
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);
1703N/A int total = count();
1703N/A for (row = 0; row < row_limit(); row++) {
1703N/A if (receiver(row) != NULL) {
1703N/A total += receiver_count(row);
1703N/A }
1703N/A }
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);
1703N/A st->print_cr("(%u %4.2f)", receiver_count(row), (float) receiver_count(row) / (float) total);
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);
0N/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//
0N/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) {
2027N/A Bytecode_tableswitch sw(stream->method()(), stream->bcp());
2027N/A cell_count = 1 + per_case_cell_count * (1 + sw.length()); // 1 for default
0N/A } else {
2027N/A Bytecode_lookupswitch sw(stream->method()(), stream->bcp());
2027N/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) {
2027N/A Bytecode_tableswitch sw(stream->method()(), stream->bcp());
2027N/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++) {
2027N/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 }
2027N/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 {
2027N/A Bytecode_lookupswitch sw(stream->method()(), stream->bcp());
2027N/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++) {
2027N/A LookupswitchPair pair = sw.pair_at(count);
2027N/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 }
2027N/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
45N/A#ifndef PRODUCT
45N/Avoid ArgInfoData::print_data_on(outputStream* st) {
45N/A print_shared(st, "ArgInfoData");
45N/A int nargs = number_of_args();
45N/A for (int i = 0; i < nargs; i++) {
45N/A st->print(" 0x%x", arg_modified(i));
45N/A }
45N/A st->cr();
45N/A}
45N/A
45N/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();
726N/A case Bytecodes::_invokedynamic:
726N/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
45N/A // Add a cell to record information about modified arguments.
45N/A int arg_size = method->size_of_parameters();
45N/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:
0N/A case Bytecodes::_instanceof:
0N/A case Bytecodes::_aastore:
0N/A if (TypeProfileCasts) {
0N/A cell_count = ReceiverTypeData::static_cell_count();
0N/A tag = DataLayout::receiver_type_data_tag;
0N/A } else {
0N/A cell_count = BitData::static_cell_count();
0N/A tag = DataLayout::bit_data_tag;
0N/A }
0N/A break;
0N/A case Bytecodes::_invokespecial:
0N/A case Bytecodes::_invokestatic:
0N/A cell_count = CounterData::static_cell_count();
0N/A tag = DataLayout::counter_data_tag;
0N/A break;
0N/A case Bytecodes::_goto:
0N/A case Bytecodes::_goto_w:
0N/A case Bytecodes::_jsr:
0N/A case Bytecodes::_jsr_w:
0N/A cell_count = JumpData::static_cell_count();
0N/A tag = DataLayout::jump_data_tag;
0N/A break;
0N/A case Bytecodes::_invokevirtual:
0N/A case Bytecodes::_invokeinterface:
0N/A cell_count = VirtualCallData::static_cell_count();
0N/A tag = DataLayout::virtual_call_data_tag;
0N/A break;
726N/A case Bytecodes::_invokedynamic:
726N/A // %%% should make a type profile for any invokedynamic that takes a ref argument
726N/A cell_count = CounterData::static_cell_count();
726N/A tag = DataLayout::counter_data_tag;
726N/A break;
0N/A case Bytecodes::_ret:
0N/A cell_count = RetData::static_cell_count();
0N/A tag = DataLayout::ret_data_tag;
0N/A break;
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 cell_count = BranchData::static_cell_count();
0N/A tag = DataLayout::branch_data_tag;
0N/A break;
0N/A case Bytecodes::_lookupswitch:
0N/A case Bytecodes::_tableswitch:
0N/A cell_count = MultiBranchData::compute_cell_count(stream);
0N/A tag = DataLayout::multi_branch_data_tag;
0N/A break;
0N/A }
0N/A assert(tag == DataLayout::multi_branch_data_tag ||
0N/A cell_count == bytecode_cell_count(c), "cell counts must agree");
0N/A if (cell_count >= 0) {
0N/A assert(tag != DataLayout::no_tag, "bad tag");
0N/A assert(bytecode_has_profile(c), "agree w/ BHP");
0N/A data_layout->initialize(tag, stream->bci(), cell_count);
0N/A return DataLayout::compute_size_in_bytes(cell_count);
0N/A } else {
0N/A assert(!bytecode_has_profile(c), "agree w/ !BHP");
0N/A return 0;
0N/A }
0N/A}
0N/A
0N/A// Get the data at an arbitrary (sort of) data index.
0N/AProfileData* methodDataOopDesc::data_at(int data_index) {
0N/A if (out_of_bounds(data_index)) {
0N/A return NULL;
0N/A }
0N/A DataLayout* data_layout = data_layout_at(data_index);
941N/A return data_layout->data_in();
941N/A}
0N/A
941N/AProfileData* DataLayout::data_in() {
941N/A switch (tag()) {
0N/A case DataLayout::no_tag:
0N/A default:
0N/A ShouldNotReachHere();
0N/A return NULL;
0N/A case DataLayout::bit_data_tag:
941N/A return new BitData(this);
0N/A case DataLayout::counter_data_tag:
941N/A return new CounterData(this);
0N/A case DataLayout::jump_data_tag:
941N/A return new JumpData(this);
0N/A case DataLayout::receiver_type_data_tag:
941N/A return new ReceiverTypeData(this);
0N/A case DataLayout::virtual_call_data_tag:
941N/A return new VirtualCallData(this);
0N/A case DataLayout::ret_data_tag:
941N/A return new RetData(this);
0N/A case DataLayout::branch_data_tag:
941N/A return new BranchData(this);
0N/A case DataLayout::multi_branch_data_tag:
941N/A return new MultiBranchData(this);
45N/A case DataLayout::arg_info_data_tag:
941N/A return new ArgInfoData(this);
0N/A };
0N/A}
0N/A
0N/A// Iteration over data.
0N/AProfileData* methodDataOopDesc::next_data(ProfileData* current) {
0N/A int current_index = dp_to_di(current->dp());
0N/A int next_index = current_index + current->size_in_bytes();
0N/A ProfileData* next = data_at(next_index);
0N/A return next;
0N/A}
0N/A
0N/A// Give each of the data entries a chance to perform specific
0N/A// data initialization.
0N/Avoid methodDataOopDesc::post_initialize(BytecodeStream* stream) {
0N/A ResourceMark rm;
0N/A ProfileData* data;
0N/A for (data = first_data(); is_valid(data); data = next_data(data)) {
0N/A stream->set_start(data->bci());
0N/A stream->next();
0N/A data->post_initialize(stream, this);
0N/A }
0N/A}
0N/A
0N/A// Initialize the methodDataOop corresponding to a given method.
0N/Avoid methodDataOopDesc::initialize(methodHandle method) {
0N/A ResourceMark rm;
0N/A // Set the method back-pointer.
0N/A _method = method();
1703N/A
1703N/A if (TieredCompilation) {
1703N/A _invocation_counter.init();
1703N/A _backedge_counter.init();
2124N/A _invocation_counter_start = 0;
2124N/A _backedge_counter_start = 0;
1703N/A _num_loops = 0;
1703N/A _num_blocks = 0;
1703N/A _highest_comp_level = 0;
1703N/A _highest_osr_comp_level = 0;
2124N/A _would_profile = true;
1703N/A }
0N/A set_creation_mileage(mileage_of(method()));
0N/A
0N/A // Initialize flags and trap history.
0N/A _nof_decompiles = 0;
0N/A _nof_overflow_recompiles = 0;
0N/A _nof_overflow_traps = 0;
0N/A assert(sizeof(_trap_hist) % sizeof(HeapWord) == 0, "align");
0N/A Copy::zero_to_words((HeapWord*) &_trap_hist,
0N/A sizeof(_trap_hist) / sizeof(HeapWord));
0N/A
0N/A // Go through the bytecodes and allocate and initialize the
0N/A // corresponding data cells.
0N/A int data_size = 0;
0N/A int empty_bc_count = 0; // number of bytecodes lacking data
0N/A BytecodeStream stream(method);
0N/A Bytecodes::Code c;
0N/A while ((c = stream.next()) >= 0) {
0N/A int size_in_bytes = initialize_data(&stream, data_size);
0N/A data_size += size_in_bytes;
0N/A if (size_in_bytes == 0) empty_bc_count += 1;
0N/A }
0N/A _data_size = data_size;
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);
45N/A int extra_size = extra_data_count * DataLayout::compute_size_in_bytes(0);
45N/A
45N/A // Add a cell to record information about modified arguments.
45N/A // Set up _args_modified array after traps cells so that
45N/A // the code for traps cells works.
45N/A DataLayout *dp = data_layout_at(data_size + extra_size);
45N/A
45N/A int arg_size = method->size_of_parameters();
45N/A dp->initialize(DataLayout::arg_info_data_tag, 0, arg_size+1);
45N/A
45N/A object_size += extra_size + DataLayout::compute_size_in_bytes(arg_size+1);
0N/A
0N/A // Set an initial hint. Don't use set_hint_di() because
0N/A // first_di() may be out of bounds if data_size is 0.
0N/A // In that situation, _hint_di is never used, but at
0N/A // least well-defined.
0N/A _hint_di = first_di();
0N/A
0N/A post_initialize(&stream);
0N/A
0N/A set_object_is_parsable(object_size);
0N/A}
0N/A
0N/A// Get a measure of how much mileage the method has on it.
0N/Aint methodDataOopDesc::mileage_of(methodOop method) {
0N/A int mileage = 0;
1703N/A if (TieredCompilation) {
1703N/A mileage = MAX2(method->invocation_count(), method->backedge_count());
1703N/A } else {
1703N/A int iic = method->interpreter_invocation_count();
1703N/A if (mileage < iic) mileage = iic;
1703N/A InvocationCounter* ic = method->invocation_counter();
1703N/A InvocationCounter* bc = method->backedge_counter();
1703N/A int icval = ic->count();
1703N/A if (ic->carry()) icval += CompileThreshold;
1703N/A if (mileage < icval) mileage = icval;
1703N/A int bcval = bc->count();
1703N/A if (bc->carry()) bcval += CompileThreshold;
1703N/A if (mileage < bcval) mileage = bcval;
1703N/A }
0N/A return mileage;
0N/A}
0N/A
0N/Abool methodDataOopDesc::is_mature() const {
1703N/A return CompilationPolicy::policy()->is_mature(_method);
0N/A}
0N/A
0N/A// Translate a bci to its corresponding data index (di).
0N/Aaddress methodDataOopDesc::bci_to_dp(int bci) {
0N/A ResourceMark rm;
0N/A ProfileData* data = data_before(bci);
0N/A ProfileData* prev = NULL;
0N/A for ( ; is_valid(data); data = next_data(data)) {
0N/A if (data->bci() >= bci) {
0N/A if (data->bci() == bci) set_hint_di(dp_to_di(data->dp()));
0N/A else if (prev != NULL) set_hint_di(dp_to_di(prev->dp()));
0N/A return data->dp();
0N/A }
0N/A prev = data;
0N/A }
0N/A return (address)limit_data_position();
0N/A}
0N/A
0N/A// Translate a bci to its corresponding data, or NULL.
0N/AProfileData* methodDataOopDesc::bci_to_data(int bci) {
0N/A ProfileData* data = data_before(bci);
0N/A for ( ; is_valid(data); data = next_data(data)) {
0N/A if (data->bci() == bci) {
0N/A set_hint_di(dp_to_di(data->dp()));
0N/A return data;
0N/A } else if (data->bci() > bci) {
0N/A break;
0N/A }
0N/A }
0N/A return bci_to_extra_data(bci, false);
0N/A}
0N/A
0N/A// Translate a bci to its corresponding extra data, or NULL.
0N/AProfileData* methodDataOopDesc::bci_to_extra_data(int bci, bool create_if_missing) {
0N/A DataLayout* dp = extra_data_base();
0N/A DataLayout* end = extra_data_limit();
0N/A DataLayout* avail = NULL;
0N/A for (; dp < end; dp = next_extra(dp)) {
0N/A // No need for "OrderAccess::load_acquire" ops,
0N/A // since the data structure is monotonic.
0N/A if (dp->tag() == DataLayout::no_tag) break;
45N/A if (dp->tag() == DataLayout::arg_info_data_tag) {
45N/A dp = end; // ArgInfoData is at the end of extra data section.
45N/A break;
45N/A }
0N/A if (dp->bci() == bci) {
0N/A assert(dp->tag() == DataLayout::bit_data_tag, "sane");
0N/A return new BitData(dp);
0N/A }
0N/A }
0N/A if (create_if_missing && dp < end) {
0N/A // Allocate this one. There is no mutual exclusion,
0N/A // so two threads could allocate different BCIs to the
0N/A // same data layout. This means these extra data
0N/A // records, like most other MDO contents, must not be
0N/A // trusted too much.
0N/A DataLayout temp;
0N/A temp.initialize(DataLayout::bit_data_tag, bci, 0);
0N/A dp->release_set_header(temp.header());
0N/A assert(dp->tag() == DataLayout::bit_data_tag, "sane");
0N/A //NO: assert(dp->bci() == bci, "no concurrent allocation");
0N/A return new BitData(dp);
0N/A }
0N/A return NULL;
0N/A}
0N/A
45N/AArgInfoData *methodDataOopDesc::arg_info() {
45N/A DataLayout* dp = extra_data_base();
45N/A DataLayout* end = extra_data_limit();
45N/A for (; dp < end; dp = next_extra(dp)) {
45N/A if (dp->tag() == DataLayout::arg_info_data_tag)
45N/A return new ArgInfoData(dp);
45N/A }
45N/A return NULL;
45N/A}
45N/A
0N/A#ifndef PRODUCT
0N/Avoid methodDataOopDesc::print_data_on(outputStream* st) {
0N/A ResourceMark rm;
0N/A ProfileData* data = first_data();
0N/A for ( ; is_valid(data); data = next_data(data)) {
0N/A st->print("%d", dp_to_di(data->dp()));
0N/A st->fill_to(6);
0N/A data->print_data_on(st);
0N/A }
45N/A st->print_cr("--- Extra data:");
0N/A DataLayout* dp = extra_data_base();
0N/A DataLayout* end = extra_data_limit();
0N/A for (; dp < end; dp = next_extra(dp)) {
0N/A // No need for "OrderAccess::load_acquire" ops,
0N/A // since the data structure is monotonic.
45N/A if (dp->tag() == DataLayout::no_tag) continue;
45N/A if (dp->tag() == DataLayout::bit_data_tag) {
45N/A data = new BitData(dp);
45N/A } else {
45N/A assert(dp->tag() == DataLayout::arg_info_data_tag, "must be BitData or ArgInfo");
45N/A data = new ArgInfoData(dp);
45N/A dp = end; // ArgInfoData is at the end of extra data section.
45N/A }
0N/A st->print("%d", dp_to_di(data->dp()));
0N/A st->fill_to(6);
0N/A data->print_data_on(st);
0N/A }
0N/A}
0N/A#endif
0N/A
0N/Avoid methodDataOopDesc::verify_data_on(outputStream* st) {
0N/A NEEDS_CLEANUP;
0N/A // not yet implemented.
0N/A}