aoqi@0: /* aoqi@0: * Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: * aoqi@0: */ aoqi@0: aoqi@0: #include "precompiled.hpp" aoqi@0: #include "classfile/systemDictionary.hpp" aoqi@0: #include "compiler/compilerOracle.hpp" aoqi@0: #include "interpreter/bytecode.hpp" aoqi@0: #include "interpreter/bytecodeStream.hpp" aoqi@0: #include "interpreter/linkResolver.hpp" aoqi@0: #include "memory/heapInspection.hpp" aoqi@0: #include "oops/methodData.hpp" aoqi@0: #include "prims/jvmtiRedefineClasses.hpp" aoqi@0: #include "runtime/compilationPolicy.hpp" aoqi@0: #include "runtime/deoptimization.hpp" aoqi@0: #include "runtime/handles.inline.hpp" aoqi@0: aoqi@0: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC aoqi@0: aoqi@0: // ================================================================== aoqi@0: // DataLayout aoqi@0: // aoqi@0: // Overlay for generic profiling data. aoqi@0: aoqi@0: // Some types of data layouts need a length field. aoqi@0: bool DataLayout::needs_array_len(u1 tag) { aoqi@0: return (tag == multi_branch_data_tag) || (tag == arg_info_data_tag) || (tag == parameters_type_data_tag); aoqi@0: } aoqi@0: aoqi@0: // Perform generic initialization of the data. More specific aoqi@0: // initialization occurs in overrides of ProfileData::post_initialize. aoqi@0: void DataLayout::initialize(u1 tag, u2 bci, int cell_count) { aoqi@0: _header._bits = (intptr_t)0; aoqi@0: _header._struct._tag = tag; aoqi@0: _header._struct._bci = bci; aoqi@0: for (int i = 0; i < cell_count; i++) { aoqi@0: set_cell_at(i, (intptr_t)0); aoqi@0: } aoqi@0: if (needs_array_len(tag)) { aoqi@0: set_cell_at(ArrayData::array_len_off_set, cell_count - 1); // -1 for header. aoqi@0: } aoqi@0: if (tag == call_type_data_tag) { aoqi@0: CallTypeData::initialize(this, cell_count); aoqi@0: } else if (tag == virtual_call_type_data_tag) { aoqi@0: VirtualCallTypeData::initialize(this, cell_count); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: void DataLayout::clean_weak_klass_links(BoolObjectClosure* cl) { aoqi@0: ResourceMark m; aoqi@0: data_in()->clean_weak_klass_links(cl); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: // ================================================================== aoqi@0: // ProfileData aoqi@0: // aoqi@0: // A ProfileData object is created to refer to a section of profiling aoqi@0: // data in a structured way. aoqi@0: aoqi@0: // Constructor for invalid ProfileData. aoqi@0: ProfileData::ProfileData() { aoqi@0: _data = NULL; aoqi@0: } aoqi@0: aoqi@0: char* ProfileData::print_data_on_helper(const MethodData* md) const { aoqi@0: DataLayout* dp = md->extra_data_base(); aoqi@0: DataLayout* end = md->extra_data_limit(); aoqi@0: stringStream ss; aoqi@0: for (;; dp = MethodData::next_extra(dp)) { aoqi@0: assert(dp < end, "moved past end of extra data"); aoqi@0: switch(dp->tag()) { aoqi@0: case DataLayout::speculative_trap_data_tag: aoqi@0: if (dp->bci() == bci()) { aoqi@0: SpeculativeTrapData* data = new SpeculativeTrapData(dp); aoqi@0: int trap = data->trap_state(); aoqi@0: char buf[100]; aoqi@0: ss.print("trap/"); aoqi@0: data->method()->print_short_name(&ss); aoqi@0: ss.print("(%s) ", Deoptimization::format_trap_state(buf, sizeof(buf), trap)); aoqi@0: } aoqi@0: break; aoqi@0: case DataLayout::bit_data_tag: aoqi@0: break; aoqi@0: case DataLayout::no_tag: aoqi@0: case DataLayout::arg_info_data_tag: aoqi@0: return ss.as_string(); aoqi@0: break; aoqi@0: default: aoqi@0: fatal(err_msg("unexpected tag %d", dp->tag())); aoqi@0: } aoqi@0: } aoqi@0: return NULL; aoqi@0: } aoqi@0: aoqi@0: void ProfileData::print_data_on(outputStream* st, const MethodData* md) const { aoqi@0: print_data_on(st, print_data_on_helper(md)); aoqi@0: } aoqi@0: aoqi@0: #ifndef PRODUCT aoqi@0: void ProfileData::print_shared(outputStream* st, const char* name, const char* extra) const { aoqi@0: st->print("bci: %d", bci()); aoqi@0: st->fill_to(tab_width_one); aoqi@0: st->print("%s", name); aoqi@0: tab(st); aoqi@0: int trap = trap_state(); aoqi@0: if (trap != 0) { aoqi@0: char buf[100]; aoqi@0: st->print("trap(%s) ", Deoptimization::format_trap_state(buf, sizeof(buf), trap)); aoqi@0: } aoqi@0: if (extra != NULL) { aoqi@0: st->print("%s", extra); aoqi@0: } aoqi@0: int flags = data()->flags(); aoqi@0: if (flags != 0) { aoqi@0: st->print("flags(%d) ", flags); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: void ProfileData::tab(outputStream* st, bool first) const { aoqi@0: st->fill_to(first ? tab_width_one : tab_width_two); aoqi@0: } aoqi@0: #endif // !PRODUCT aoqi@0: aoqi@0: // ================================================================== aoqi@0: // BitData aoqi@0: // aoqi@0: // A BitData corresponds to a one-bit flag. This is used to indicate aoqi@0: // whether a checkcast bytecode has seen a null value. aoqi@0: aoqi@0: aoqi@0: #ifndef PRODUCT aoqi@0: void BitData::print_data_on(outputStream* st, const char* extra) const { aoqi@0: print_shared(st, "BitData", extra); aoqi@0: } aoqi@0: #endif // !PRODUCT aoqi@0: aoqi@0: // ================================================================== aoqi@0: // CounterData aoqi@0: // aoqi@0: // A CounterData corresponds to a simple counter. aoqi@0: aoqi@0: #ifndef PRODUCT aoqi@0: void CounterData::print_data_on(outputStream* st, const char* extra) const { aoqi@0: print_shared(st, "CounterData", extra); aoqi@0: st->print_cr("count(%u)", count()); aoqi@0: } aoqi@0: #endif // !PRODUCT aoqi@0: aoqi@0: // ================================================================== aoqi@0: // JumpData aoqi@0: // aoqi@0: // A JumpData is used to access profiling information for a direct aoqi@0: // branch. It is a counter, used for counting the number of branches, aoqi@0: // plus a data displacement, used for realigning the data pointer to aoqi@0: // the corresponding target bci. aoqi@0: aoqi@0: void JumpData::post_initialize(BytecodeStream* stream, MethodData* mdo) { aoqi@0: assert(stream->bci() == bci(), "wrong pos"); aoqi@0: int target; aoqi@0: Bytecodes::Code c = stream->code(); aoqi@0: if (c == Bytecodes::_goto_w || c == Bytecodes::_jsr_w) { aoqi@0: target = stream->dest_w(); aoqi@0: } else { aoqi@0: target = stream->dest(); aoqi@0: } aoqi@0: int my_di = mdo->dp_to_di(dp()); aoqi@0: int target_di = mdo->bci_to_di(target); aoqi@0: int offset = target_di - my_di; aoqi@0: set_displacement(offset); aoqi@0: } aoqi@0: aoqi@0: #ifndef PRODUCT aoqi@0: void JumpData::print_data_on(outputStream* st, const char* extra) const { aoqi@0: print_shared(st, "JumpData", extra); aoqi@0: st->print_cr("taken(%u) displacement(%d)", taken(), displacement()); aoqi@0: } aoqi@0: #endif // !PRODUCT aoqi@0: aoqi@0: int TypeStackSlotEntries::compute_cell_count(Symbol* signature, bool include_receiver, int max) { aoqi@0: // Parameter profiling include the receiver aoqi@0: int args_count = include_receiver ? 1 : 0; aoqi@0: ResourceMark rm; aoqi@0: SignatureStream ss(signature); aoqi@0: args_count += ss.reference_parameter_count(); aoqi@0: args_count = MIN2(args_count, max); aoqi@0: return args_count * per_arg_cell_count; aoqi@0: } aoqi@0: aoqi@0: int TypeEntriesAtCall::compute_cell_count(BytecodeStream* stream) { aoqi@0: assert(Bytecodes::is_invoke(stream->code()), "should be invoke"); aoqi@0: assert(TypeStackSlotEntries::per_arg_count() > ReturnTypeEntry::static_cell_count(), "code to test for arguments/results broken"); aoqi@0: Bytecode_invoke inv(stream->method(), stream->bci()); aoqi@0: int args_cell = 0; aoqi@0: if (arguments_profiling_enabled()) { aoqi@0: args_cell = TypeStackSlotEntries::compute_cell_count(inv.signature(), false, TypeProfileArgsLimit); aoqi@0: } aoqi@0: int ret_cell = 0; aoqi@0: if (return_profiling_enabled() && (inv.result_type() == T_OBJECT || inv.result_type() == T_ARRAY)) { aoqi@0: ret_cell = ReturnTypeEntry::static_cell_count(); aoqi@0: } aoqi@0: int header_cell = 0; aoqi@0: if (args_cell + ret_cell > 0) { aoqi@0: header_cell = header_cell_count(); aoqi@0: } aoqi@0: aoqi@0: return header_cell + args_cell + ret_cell; aoqi@0: } aoqi@0: aoqi@0: class ArgumentOffsetComputer : public SignatureInfo { aoqi@0: private: aoqi@0: int _max; aoqi@0: GrowableArray _offsets; aoqi@0: aoqi@0: void set(int size, BasicType type) { _size += size; } aoqi@0: void do_object(int begin, int end) { aoqi@0: if (_offsets.length() < _max) { aoqi@0: _offsets.push(_size); aoqi@0: } aoqi@0: SignatureInfo::do_object(begin, end); aoqi@0: } aoqi@0: void do_array (int begin, int end) { aoqi@0: if (_offsets.length() < _max) { aoqi@0: _offsets.push(_size); aoqi@0: } aoqi@0: SignatureInfo::do_array(begin, end); aoqi@0: } aoqi@0: aoqi@0: public: aoqi@0: ArgumentOffsetComputer(Symbol* signature, int max) aoqi@0: : SignatureInfo(signature), _max(max), _offsets(Thread::current(), max) { aoqi@0: } aoqi@0: aoqi@0: int total() { lazy_iterate_parameters(); return _size; } aoqi@0: aoqi@0: int off_at(int i) const { return _offsets.at(i); } aoqi@0: }; aoqi@0: aoqi@0: void TypeStackSlotEntries::post_initialize(Symbol* signature, bool has_receiver, bool include_receiver) { aoqi@0: ResourceMark rm; aoqi@0: int start = 0; aoqi@0: // Parameter profiling include the receiver aoqi@0: if (include_receiver && has_receiver) { aoqi@0: set_stack_slot(0, 0); aoqi@0: set_type(0, type_none()); aoqi@0: start += 1; aoqi@0: } aoqi@0: ArgumentOffsetComputer aos(signature, _number_of_entries-start); aoqi@0: aos.total(); aoqi@0: for (int i = start; i < _number_of_entries; i++) { aoqi@0: set_stack_slot(i, aos.off_at(i-start) + (has_receiver ? 1 : 0)); aoqi@0: set_type(i, type_none()); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: void CallTypeData::post_initialize(BytecodeStream* stream, MethodData* mdo) { aoqi@0: assert(Bytecodes::is_invoke(stream->code()), "should be invoke"); aoqi@0: Bytecode_invoke inv(stream->method(), stream->bci()); aoqi@0: aoqi@0: SignatureStream ss(inv.signature()); aoqi@0: if (has_arguments()) { aoqi@0: #ifdef ASSERT aoqi@0: ResourceMark rm; aoqi@0: int count = MIN2(ss.reference_parameter_count(), (int)TypeProfileArgsLimit); aoqi@0: assert(count > 0, "room for args type but none found?"); aoqi@0: check_number_of_arguments(count); aoqi@0: #endif aoqi@0: _args.post_initialize(inv.signature(), inv.has_receiver(), false); aoqi@0: } aoqi@0: aoqi@0: if (has_return()) { aoqi@0: assert(inv.result_type() == T_OBJECT || inv.result_type() == T_ARRAY, "room for a ret type but doesn't return obj?"); aoqi@0: _ret.post_initialize(); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: void VirtualCallTypeData::post_initialize(BytecodeStream* stream, MethodData* mdo) { aoqi@0: assert(Bytecodes::is_invoke(stream->code()), "should be invoke"); aoqi@0: Bytecode_invoke inv(stream->method(), stream->bci()); aoqi@0: aoqi@0: if (has_arguments()) { aoqi@0: #ifdef ASSERT aoqi@0: ResourceMark rm; aoqi@0: SignatureStream ss(inv.signature()); aoqi@0: int count = MIN2(ss.reference_parameter_count(), (int)TypeProfileArgsLimit); aoqi@0: assert(count > 0, "room for args type but none found?"); aoqi@0: check_number_of_arguments(count); aoqi@0: #endif aoqi@0: _args.post_initialize(inv.signature(), inv.has_receiver(), false); aoqi@0: } aoqi@0: aoqi@0: if (has_return()) { aoqi@0: assert(inv.result_type() == T_OBJECT || inv.result_type() == T_ARRAY, "room for a ret type but doesn't return obj?"); aoqi@0: _ret.post_initialize(); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: bool TypeEntries::is_loader_alive(BoolObjectClosure* is_alive_cl, intptr_t p) { aoqi@0: Klass* k = (Klass*)klass_part(p); aoqi@0: return k != NULL && k->is_loader_alive(is_alive_cl); aoqi@0: } aoqi@0: aoqi@0: void TypeStackSlotEntries::clean_weak_klass_links(BoolObjectClosure* is_alive_cl) { aoqi@0: for (int i = 0; i < _number_of_entries; i++) { aoqi@0: intptr_t p = type(i); aoqi@0: if (!is_loader_alive(is_alive_cl, p)) { aoqi@0: set_type(i, with_status((Klass*)NULL, p)); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: void ReturnTypeEntry::clean_weak_klass_links(BoolObjectClosure* is_alive_cl) { aoqi@0: intptr_t p = type(); aoqi@0: if (!is_loader_alive(is_alive_cl, p)) { aoqi@0: set_type(with_status((Klass*)NULL, p)); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: bool TypeEntriesAtCall::return_profiling_enabled() { aoqi@0: return MethodData::profile_return(); aoqi@0: } aoqi@0: aoqi@0: bool TypeEntriesAtCall::arguments_profiling_enabled() { aoqi@0: return MethodData::profile_arguments(); aoqi@0: } aoqi@0: aoqi@0: #ifndef PRODUCT aoqi@0: void TypeEntries::print_klass(outputStream* st, intptr_t k) { aoqi@0: if (is_type_none(k)) { aoqi@0: st->print("none"); aoqi@0: } else if (is_type_unknown(k)) { aoqi@0: st->print("unknown"); aoqi@0: } else { aoqi@0: valid_klass(k)->print_value_on(st); aoqi@0: } aoqi@0: if (was_null_seen(k)) { aoqi@0: st->print(" (null seen)"); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: void TypeStackSlotEntries::print_data_on(outputStream* st) const { aoqi@0: for (int i = 0; i < _number_of_entries; i++) { aoqi@0: _pd->tab(st); aoqi@0: st->print("%d: stack(%u) ", i, stack_slot(i)); aoqi@0: print_klass(st, type(i)); aoqi@0: st->cr(); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: void ReturnTypeEntry::print_data_on(outputStream* st) const { aoqi@0: _pd->tab(st); aoqi@0: print_klass(st, type()); aoqi@0: st->cr(); aoqi@0: } aoqi@0: aoqi@0: void CallTypeData::print_data_on(outputStream* st, const char* extra) const { aoqi@0: CounterData::print_data_on(st, extra); aoqi@0: if (has_arguments()) { aoqi@0: tab(st, true); aoqi@0: st->print("argument types"); aoqi@0: _args.print_data_on(st); aoqi@0: } aoqi@0: if (has_return()) { aoqi@0: tab(st, true); aoqi@0: st->print("return type"); aoqi@0: _ret.print_data_on(st); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: void VirtualCallTypeData::print_data_on(outputStream* st, const char* extra) const { aoqi@0: VirtualCallData::print_data_on(st, extra); aoqi@0: if (has_arguments()) { aoqi@0: tab(st, true); aoqi@0: st->print("argument types"); aoqi@0: _args.print_data_on(st); aoqi@0: } aoqi@0: if (has_return()) { aoqi@0: tab(st, true); aoqi@0: st->print("return type"); aoqi@0: _ret.print_data_on(st); aoqi@0: } aoqi@0: } aoqi@0: #endif aoqi@0: aoqi@0: // ================================================================== aoqi@0: // ReceiverTypeData aoqi@0: // aoqi@0: // A ReceiverTypeData is used to access profiling information about a aoqi@0: // dynamic type check. It consists of a counter which counts the total times aoqi@0: // that the check is reached, and a series of (Klass*, count) pairs aoqi@0: // which are used to store a type profile for the receiver of the check. aoqi@0: aoqi@0: void ReceiverTypeData::clean_weak_klass_links(BoolObjectClosure* is_alive_cl) { aoqi@0: for (uint row = 0; row < row_limit(); row++) { aoqi@0: Klass* p = receiver(row); aoqi@0: if (p != NULL && !p->is_loader_alive(is_alive_cl)) { aoqi@0: clear_row(row); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: #ifndef PRODUCT aoqi@0: void ReceiverTypeData::print_receiver_data_on(outputStream* st) const { aoqi@0: uint row; aoqi@0: int entries = 0; aoqi@0: for (row = 0; row < row_limit(); row++) { aoqi@0: if (receiver(row) != NULL) entries++; aoqi@0: } aoqi@0: st->print_cr("count(%u) entries(%u)", count(), entries); aoqi@0: int total = count(); aoqi@0: for (row = 0; row < row_limit(); row++) { aoqi@0: if (receiver(row) != NULL) { aoqi@0: total += receiver_count(row); aoqi@0: } aoqi@0: } aoqi@0: for (row = 0; row < row_limit(); row++) { aoqi@0: if (receiver(row) != NULL) { aoqi@0: tab(st); aoqi@0: receiver(row)->print_value_on(st); aoqi@0: st->print_cr("(%u %4.2f)", receiver_count(row), (float) receiver_count(row) / (float) total); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: void ReceiverTypeData::print_data_on(outputStream* st, const char* extra) const { aoqi@0: print_shared(st, "ReceiverTypeData", extra); aoqi@0: print_receiver_data_on(st); aoqi@0: } aoqi@0: void VirtualCallData::print_data_on(outputStream* st, const char* extra) const { aoqi@0: print_shared(st, "VirtualCallData", extra); aoqi@0: print_receiver_data_on(st); aoqi@0: } aoqi@0: #endif // !PRODUCT aoqi@0: aoqi@0: // ================================================================== aoqi@0: // RetData aoqi@0: // aoqi@0: // A RetData is used to access profiling information for a ret bytecode. aoqi@0: // It is composed of a count of the number of times that the ret has aoqi@0: // been executed, followed by a series of triples of the form aoqi@0: // (bci, count, di) which count the number of times that some bci was the aoqi@0: // target of the ret and cache a corresponding displacement. aoqi@0: aoqi@0: void RetData::post_initialize(BytecodeStream* stream, MethodData* mdo) { aoqi@0: for (uint row = 0; row < row_limit(); row++) { aoqi@0: set_bci_displacement(row, -1); aoqi@0: set_bci(row, no_bci); aoqi@0: } aoqi@0: // release so other threads see a consistent state. bci is used as aoqi@0: // a valid flag for bci_displacement. aoqi@0: OrderAccess::release(); aoqi@0: } aoqi@0: aoqi@0: // This routine needs to atomically update the RetData structure, so the aoqi@0: // caller needs to hold the RetData_lock before it gets here. Since taking aoqi@0: // the lock can block (and allow GC) and since RetData is a ProfileData is a aoqi@0: // wrapper around a derived oop, taking the lock in _this_ method will aoqi@0: // basically cause the 'this' pointer's _data field to contain junk after the aoqi@0: // lock. We require the caller to take the lock before making the ProfileData aoqi@0: // structure. Currently the only caller is InterpreterRuntime::update_mdp_for_ret aoqi@0: address RetData::fixup_ret(int return_bci, MethodData* h_mdo) { aoqi@0: // First find the mdp which corresponds to the return bci. aoqi@0: address mdp = h_mdo->bci_to_dp(return_bci); aoqi@0: aoqi@0: // Now check to see if any of the cache slots are open. aoqi@0: for (uint row = 0; row < row_limit(); row++) { aoqi@0: if (bci(row) == no_bci) { aoqi@0: set_bci_displacement(row, mdp - dp()); aoqi@0: set_bci_count(row, DataLayout::counter_increment); aoqi@0: // Barrier to ensure displacement is written before the bci; allows aoqi@0: // the interpreter to read displacement without fear of race condition. aoqi@0: release_set_bci(row, return_bci); aoqi@0: break; aoqi@0: } aoqi@0: } aoqi@0: return mdp; aoqi@0: } aoqi@0: aoqi@0: #ifdef CC_INTERP aoqi@0: DataLayout* RetData::advance(MethodData *md, int bci) { aoqi@0: return (DataLayout*) md->bci_to_dp(bci); aoqi@0: } aoqi@0: #endif // CC_INTERP aoqi@0: aoqi@0: #ifndef PRODUCT aoqi@0: void RetData::print_data_on(outputStream* st, const char* extra) const { aoqi@0: print_shared(st, "RetData", extra); aoqi@0: uint row; aoqi@0: int entries = 0; aoqi@0: for (row = 0; row < row_limit(); row++) { aoqi@0: if (bci(row) != no_bci) entries++; aoqi@0: } aoqi@0: st->print_cr("count(%u) entries(%u)", count(), entries); aoqi@0: for (row = 0; row < row_limit(); row++) { aoqi@0: if (bci(row) != no_bci) { aoqi@0: tab(st); aoqi@0: st->print_cr("bci(%d: count(%u) displacement(%d))", aoqi@0: bci(row), bci_count(row), bci_displacement(row)); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: #endif // !PRODUCT aoqi@0: aoqi@0: // ================================================================== aoqi@0: // BranchData aoqi@0: // aoqi@0: // A BranchData is used to access profiling data for a two-way branch. aoqi@0: // It consists of taken and not_taken counts as well as a data displacement aoqi@0: // for the taken case. aoqi@0: aoqi@0: void BranchData::post_initialize(BytecodeStream* stream, MethodData* mdo) { aoqi@0: assert(stream->bci() == bci(), "wrong pos"); aoqi@0: int target = stream->dest(); aoqi@0: int my_di = mdo->dp_to_di(dp()); aoqi@0: int target_di = mdo->bci_to_di(target); aoqi@0: int offset = target_di - my_di; aoqi@0: set_displacement(offset); aoqi@0: } aoqi@0: aoqi@0: #ifndef PRODUCT aoqi@0: void BranchData::print_data_on(outputStream* st, const char* extra) const { aoqi@0: print_shared(st, "BranchData", extra); aoqi@0: st->print_cr("taken(%u) displacement(%d)", aoqi@0: taken(), displacement()); aoqi@0: tab(st); aoqi@0: st->print_cr("not taken(%u)", not_taken()); aoqi@0: } aoqi@0: #endif aoqi@0: aoqi@0: // ================================================================== aoqi@0: // MultiBranchData aoqi@0: // aoqi@0: // A MultiBranchData is used to access profiling information for aoqi@0: // a multi-way branch (*switch bytecodes). It consists of a series aoqi@0: // of (count, displacement) pairs, which count the number of times each aoqi@0: // case was taken and specify the data displacment for each branch target. aoqi@0: aoqi@0: int MultiBranchData::compute_cell_count(BytecodeStream* stream) { aoqi@0: int cell_count = 0; aoqi@0: if (stream->code() == Bytecodes::_tableswitch) { aoqi@0: Bytecode_tableswitch sw(stream->method()(), stream->bcp()); aoqi@0: cell_count = 1 + per_case_cell_count * (1 + sw.length()); // 1 for default aoqi@0: } else { aoqi@0: Bytecode_lookupswitch sw(stream->method()(), stream->bcp()); aoqi@0: cell_count = 1 + per_case_cell_count * (sw.number_of_pairs() + 1); // 1 for default aoqi@0: } aoqi@0: return cell_count; aoqi@0: } aoqi@0: aoqi@0: void MultiBranchData::post_initialize(BytecodeStream* stream, aoqi@0: MethodData* mdo) { aoqi@0: assert(stream->bci() == bci(), "wrong pos"); aoqi@0: int target; aoqi@0: int my_di; aoqi@0: int target_di; aoqi@0: int offset; aoqi@0: if (stream->code() == Bytecodes::_tableswitch) { aoqi@0: Bytecode_tableswitch sw(stream->method()(), stream->bcp()); aoqi@0: int len = sw.length(); aoqi@0: assert(array_len() == per_case_cell_count * (len + 1), "wrong len"); aoqi@0: for (int count = 0; count < len; count++) { aoqi@0: target = sw.dest_offset_at(count) + bci(); aoqi@0: my_di = mdo->dp_to_di(dp()); aoqi@0: target_di = mdo->bci_to_di(target); aoqi@0: offset = target_di - my_di; aoqi@0: set_displacement_at(count, offset); aoqi@0: } aoqi@0: target = sw.default_offset() + bci(); aoqi@0: my_di = mdo->dp_to_di(dp()); aoqi@0: target_di = mdo->bci_to_di(target); aoqi@0: offset = target_di - my_di; aoqi@0: set_default_displacement(offset); aoqi@0: aoqi@0: } else { aoqi@0: Bytecode_lookupswitch sw(stream->method()(), stream->bcp()); aoqi@0: int npairs = sw.number_of_pairs(); aoqi@0: assert(array_len() == per_case_cell_count * (npairs + 1), "wrong len"); aoqi@0: for (int count = 0; count < npairs; count++) { aoqi@0: LookupswitchPair pair = sw.pair_at(count); aoqi@0: target = pair.offset() + bci(); aoqi@0: my_di = mdo->dp_to_di(dp()); aoqi@0: target_di = mdo->bci_to_di(target); aoqi@0: offset = target_di - my_di; aoqi@0: set_displacement_at(count, offset); aoqi@0: } aoqi@0: target = sw.default_offset() + bci(); aoqi@0: my_di = mdo->dp_to_di(dp()); aoqi@0: target_di = mdo->bci_to_di(target); aoqi@0: offset = target_di - my_di; aoqi@0: set_default_displacement(offset); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: #ifndef PRODUCT aoqi@0: void MultiBranchData::print_data_on(outputStream* st, const char* extra) const { aoqi@0: print_shared(st, "MultiBranchData", extra); aoqi@0: st->print_cr("default_count(%u) displacement(%d)", aoqi@0: default_count(), default_displacement()); aoqi@0: int cases = number_of_cases(); aoqi@0: for (int i = 0; i < cases; i++) { aoqi@0: tab(st); aoqi@0: st->print_cr("count(%u) displacement(%d)", aoqi@0: count_at(i), displacement_at(i)); aoqi@0: } aoqi@0: } aoqi@0: #endif aoqi@0: aoqi@0: #ifndef PRODUCT aoqi@0: void ArgInfoData::print_data_on(outputStream* st, const char* extra) const { aoqi@0: print_shared(st, "ArgInfoData", extra); aoqi@0: int nargs = number_of_args(); aoqi@0: for (int i = 0; i < nargs; i++) { aoqi@0: st->print(" 0x%x", arg_modified(i)); aoqi@0: } aoqi@0: st->cr(); aoqi@0: } aoqi@0: aoqi@0: #endif aoqi@0: aoqi@0: int ParametersTypeData::compute_cell_count(Method* m) { aoqi@0: if (!MethodData::profile_parameters_for_method(m)) { aoqi@0: return 0; aoqi@0: } aoqi@0: int max = TypeProfileParmsLimit == -1 ? INT_MAX : TypeProfileParmsLimit; aoqi@0: int obj_args = TypeStackSlotEntries::compute_cell_count(m->signature(), !m->is_static(), max); aoqi@0: if (obj_args > 0) { aoqi@0: return obj_args + 1; // 1 cell for array len aoqi@0: } aoqi@0: return 0; aoqi@0: } aoqi@0: aoqi@0: void ParametersTypeData::post_initialize(BytecodeStream* stream, MethodData* mdo) { aoqi@0: _parameters.post_initialize(mdo->method()->signature(), !mdo->method()->is_static(), true); aoqi@0: } aoqi@0: aoqi@0: bool ParametersTypeData::profiling_enabled() { aoqi@0: return MethodData::profile_parameters(); aoqi@0: } aoqi@0: aoqi@0: #ifndef PRODUCT aoqi@0: void ParametersTypeData::print_data_on(outputStream* st, const char* extra) const { aoqi@0: st->print("parameter types"); // FIXME extra ignored? aoqi@0: _parameters.print_data_on(st); aoqi@0: } aoqi@0: aoqi@0: void SpeculativeTrapData::print_data_on(outputStream* st, const char* extra) const { aoqi@0: print_shared(st, "SpeculativeTrapData", extra); aoqi@0: tab(st); aoqi@0: method()->print_short_name(st); aoqi@0: st->cr(); aoqi@0: } aoqi@0: #endif aoqi@0: aoqi@0: // ================================================================== aoqi@0: // MethodData* aoqi@0: // aoqi@0: // A MethodData* holds information which has been collected about aoqi@0: // a method. aoqi@0: aoqi@0: MethodData* MethodData::allocate(ClassLoaderData* loader_data, methodHandle method, TRAPS) { aoqi@0: int size = MethodData::compute_allocation_size_in_words(method); aoqi@0: aoqi@0: return new (loader_data, size, false, MetaspaceObj::MethodDataType, THREAD) aoqi@0: MethodData(method(), size, CHECK_NULL); aoqi@0: } aoqi@0: aoqi@0: int MethodData::bytecode_cell_count(Bytecodes::Code code) { aoqi@0: #if defined(COMPILER1) && !defined(COMPILER2) aoqi@0: return no_profile_data; aoqi@0: #else aoqi@0: switch (code) { aoqi@0: case Bytecodes::_checkcast: aoqi@0: case Bytecodes::_instanceof: aoqi@0: case Bytecodes::_aastore: aoqi@0: if (TypeProfileCasts) { aoqi@0: return ReceiverTypeData::static_cell_count(); aoqi@0: } else { aoqi@0: return BitData::static_cell_count(); aoqi@0: } aoqi@0: case Bytecodes::_invokespecial: aoqi@0: case Bytecodes::_invokestatic: aoqi@0: if (MethodData::profile_arguments() || MethodData::profile_return()) { aoqi@0: return variable_cell_count; aoqi@0: } else { aoqi@0: return CounterData::static_cell_count(); aoqi@0: } aoqi@0: case Bytecodes::_goto: aoqi@0: case Bytecodes::_goto_w: aoqi@0: case Bytecodes::_jsr: aoqi@0: case Bytecodes::_jsr_w: aoqi@0: return JumpData::static_cell_count(); aoqi@0: case Bytecodes::_invokevirtual: aoqi@0: case Bytecodes::_invokeinterface: aoqi@0: if (MethodData::profile_arguments() || MethodData::profile_return()) { aoqi@0: return variable_cell_count; aoqi@0: } else { aoqi@0: return VirtualCallData::static_cell_count(); aoqi@0: } aoqi@0: case Bytecodes::_invokedynamic: aoqi@0: if (MethodData::profile_arguments() || MethodData::profile_return()) { aoqi@0: return variable_cell_count; aoqi@0: } else { aoqi@0: return CounterData::static_cell_count(); aoqi@0: } aoqi@0: case Bytecodes::_ret: aoqi@0: return RetData::static_cell_count(); aoqi@0: case Bytecodes::_ifeq: aoqi@0: case Bytecodes::_ifne: aoqi@0: case Bytecodes::_iflt: aoqi@0: case Bytecodes::_ifge: aoqi@0: case Bytecodes::_ifgt: aoqi@0: case Bytecodes::_ifle: aoqi@0: case Bytecodes::_if_icmpeq: aoqi@0: case Bytecodes::_if_icmpne: aoqi@0: case Bytecodes::_if_icmplt: aoqi@0: case Bytecodes::_if_icmpge: aoqi@0: case Bytecodes::_if_icmpgt: aoqi@0: case Bytecodes::_if_icmple: aoqi@0: case Bytecodes::_if_acmpeq: aoqi@0: case Bytecodes::_if_acmpne: aoqi@0: case Bytecodes::_ifnull: aoqi@0: case Bytecodes::_ifnonnull: aoqi@0: return BranchData::static_cell_count(); aoqi@0: case Bytecodes::_lookupswitch: aoqi@0: case Bytecodes::_tableswitch: aoqi@0: return variable_cell_count; aoqi@0: } aoqi@0: return no_profile_data; aoqi@0: #endif aoqi@0: } aoqi@0: aoqi@0: // Compute the size of the profiling information corresponding to aoqi@0: // the current bytecode. aoqi@0: int MethodData::compute_data_size(BytecodeStream* stream) { aoqi@0: int cell_count = bytecode_cell_count(stream->code()); aoqi@0: if (cell_count == no_profile_data) { aoqi@0: return 0; aoqi@0: } aoqi@0: if (cell_count == variable_cell_count) { aoqi@0: switch (stream->code()) { aoqi@0: case Bytecodes::_lookupswitch: aoqi@0: case Bytecodes::_tableswitch: aoqi@0: cell_count = MultiBranchData::compute_cell_count(stream); aoqi@0: break; aoqi@0: case Bytecodes::_invokespecial: aoqi@0: case Bytecodes::_invokestatic: aoqi@0: case Bytecodes::_invokedynamic: aoqi@0: assert(MethodData::profile_arguments() || MethodData::profile_return(), "should be collecting args profile"); aoqi@0: if (profile_arguments_for_invoke(stream->method(), stream->bci()) || aoqi@0: profile_return_for_invoke(stream->method(), stream->bci())) { aoqi@0: cell_count = CallTypeData::compute_cell_count(stream); aoqi@0: } else { aoqi@0: cell_count = CounterData::static_cell_count(); aoqi@0: } aoqi@0: break; aoqi@0: case Bytecodes::_invokevirtual: aoqi@0: case Bytecodes::_invokeinterface: { aoqi@0: assert(MethodData::profile_arguments() || MethodData::profile_return(), "should be collecting args profile"); aoqi@0: if (profile_arguments_for_invoke(stream->method(), stream->bci()) || aoqi@0: profile_return_for_invoke(stream->method(), stream->bci())) { aoqi@0: cell_count = VirtualCallTypeData::compute_cell_count(stream); aoqi@0: } else { aoqi@0: cell_count = VirtualCallData::static_cell_count(); aoqi@0: } aoqi@0: break; aoqi@0: } aoqi@0: default: aoqi@0: fatal("unexpected bytecode for var length profile data"); aoqi@0: } aoqi@0: } aoqi@0: // Note: cell_count might be zero, meaning that there is just aoqi@0: // a DataLayout header, with no extra cells. aoqi@0: assert(cell_count >= 0, "sanity"); aoqi@0: return DataLayout::compute_size_in_bytes(cell_count); aoqi@0: } aoqi@0: aoqi@0: bool MethodData::is_speculative_trap_bytecode(Bytecodes::Code code) { aoqi@0: // Bytecodes for which we may use speculation aoqi@0: switch (code) { aoqi@0: case Bytecodes::_checkcast: aoqi@0: case Bytecodes::_instanceof: aoqi@0: case Bytecodes::_aastore: aoqi@0: case Bytecodes::_invokevirtual: aoqi@0: case Bytecodes::_invokeinterface: aoqi@0: case Bytecodes::_if_acmpeq: aoqi@0: case Bytecodes::_if_acmpne: aoqi@0: case Bytecodes::_invokestatic: aoqi@0: #ifdef COMPILER2 aoqi@0: return UseTypeSpeculation; aoqi@0: #endif aoqi@0: default: aoqi@0: return false; aoqi@0: } aoqi@0: return false; aoqi@0: } aoqi@0: aoqi@0: int MethodData::compute_extra_data_count(int data_size, int empty_bc_count, bool needs_speculative_traps) { aoqi@0: if (ProfileTraps) { aoqi@0: // Assume that up to 3% of BCIs with no MDP will need to allocate one. aoqi@0: int extra_data_count = (uint)(empty_bc_count * 3) / 128 + 1; aoqi@0: // If the method is large, let the extra BCIs grow numerous (to ~1%). aoqi@0: int one_percent_of_data aoqi@0: = (uint)data_size / (DataLayout::header_size_in_bytes()*128); aoqi@0: if (extra_data_count < one_percent_of_data) aoqi@0: extra_data_count = one_percent_of_data; aoqi@0: if (extra_data_count > empty_bc_count) aoqi@0: extra_data_count = empty_bc_count; // no need for more aoqi@0: aoqi@0: // Make sure we have a minimum number of extra data slots to aoqi@0: // allocate SpeculativeTrapData entries. We would want to have one aoqi@0: // entry per compilation that inlines this method and for which aoqi@0: // some type speculation assumption fails. So the room we need for aoqi@0: // the SpeculativeTrapData entries doesn't directly depend on the aoqi@0: // size of the method. Because it's hard to estimate, we reserve aoqi@0: // space for an arbitrary number of entries. aoqi@0: int spec_data_count = (needs_speculative_traps ? SpecTrapLimitExtraEntries : 0) * aoqi@0: (SpeculativeTrapData::static_cell_count() + DataLayout::header_size_in_cells()); aoqi@0: aoqi@0: return MAX2(extra_data_count, spec_data_count); aoqi@0: } else { aoqi@0: return 0; aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // Compute the size of the MethodData* necessary to store aoqi@0: // profiling information about a given method. Size is in bytes. aoqi@0: int MethodData::compute_allocation_size_in_bytes(methodHandle method) { aoqi@0: int data_size = 0; aoqi@0: BytecodeStream stream(method); aoqi@0: Bytecodes::Code c; aoqi@0: int empty_bc_count = 0; // number of bytecodes lacking data aoqi@0: bool needs_speculative_traps = false; aoqi@0: while ((c = stream.next()) >= 0) { aoqi@0: int size_in_bytes = compute_data_size(&stream); aoqi@0: data_size += size_in_bytes; aoqi@0: if (size_in_bytes == 0) empty_bc_count += 1; aoqi@0: needs_speculative_traps = needs_speculative_traps || is_speculative_trap_bytecode(c); aoqi@0: } aoqi@0: int object_size = in_bytes(data_offset()) + data_size; aoqi@0: aoqi@0: // Add some extra DataLayout cells (at least one) to track stray traps. aoqi@0: int extra_data_count = compute_extra_data_count(data_size, empty_bc_count, needs_speculative_traps); aoqi@0: object_size += extra_data_count * DataLayout::compute_size_in_bytes(0); aoqi@0: aoqi@0: // Add a cell to record information about modified arguments. aoqi@0: int arg_size = method->size_of_parameters(); aoqi@0: object_size += DataLayout::compute_size_in_bytes(arg_size+1); aoqi@0: aoqi@0: // Reserve room for an area of the MDO dedicated to profiling of aoqi@0: // parameters aoqi@0: int args_cell = ParametersTypeData::compute_cell_count(method()); aoqi@0: if (args_cell > 0) { aoqi@0: object_size += DataLayout::compute_size_in_bytes(args_cell); aoqi@0: } aoqi@0: return object_size; aoqi@0: } aoqi@0: aoqi@0: // Compute the size of the MethodData* necessary to store aoqi@0: // profiling information about a given method. Size is in words aoqi@0: int MethodData::compute_allocation_size_in_words(methodHandle method) { aoqi@0: int byte_size = compute_allocation_size_in_bytes(method); aoqi@0: int word_size = align_size_up(byte_size, BytesPerWord) / BytesPerWord; aoqi@0: return align_object_size(word_size); aoqi@0: } aoqi@0: aoqi@0: // Initialize an individual data segment. Returns the size of aoqi@0: // the segment in bytes. aoqi@0: int MethodData::initialize_data(BytecodeStream* stream, aoqi@0: int data_index) { aoqi@0: #if defined(COMPILER1) && !defined(COMPILER2) aoqi@0: return 0; aoqi@0: #else aoqi@0: int cell_count = -1; aoqi@0: int tag = DataLayout::no_tag; aoqi@0: DataLayout* data_layout = data_layout_at(data_index); aoqi@0: Bytecodes::Code c = stream->code(); aoqi@0: switch (c) { aoqi@0: case Bytecodes::_checkcast: aoqi@0: case Bytecodes::_instanceof: aoqi@0: case Bytecodes::_aastore: aoqi@0: if (TypeProfileCasts) { aoqi@0: cell_count = ReceiverTypeData::static_cell_count(); aoqi@0: tag = DataLayout::receiver_type_data_tag; aoqi@0: } else { aoqi@0: cell_count = BitData::static_cell_count(); aoqi@0: tag = DataLayout::bit_data_tag; aoqi@0: } aoqi@0: break; aoqi@0: case Bytecodes::_invokespecial: aoqi@0: case Bytecodes::_invokestatic: { aoqi@0: int counter_data_cell_count = CounterData::static_cell_count(); aoqi@0: if (profile_arguments_for_invoke(stream->method(), stream->bci()) || aoqi@0: profile_return_for_invoke(stream->method(), stream->bci())) { aoqi@0: cell_count = CallTypeData::compute_cell_count(stream); aoqi@0: } else { aoqi@0: cell_count = counter_data_cell_count; aoqi@0: } aoqi@0: if (cell_count > counter_data_cell_count) { aoqi@0: tag = DataLayout::call_type_data_tag; aoqi@0: } else { aoqi@0: tag = DataLayout::counter_data_tag; aoqi@0: } aoqi@0: break; aoqi@0: } aoqi@0: case Bytecodes::_goto: aoqi@0: case Bytecodes::_goto_w: aoqi@0: case Bytecodes::_jsr: aoqi@0: case Bytecodes::_jsr_w: aoqi@0: cell_count = JumpData::static_cell_count(); aoqi@0: tag = DataLayout::jump_data_tag; aoqi@0: break; aoqi@0: case Bytecodes::_invokevirtual: aoqi@0: case Bytecodes::_invokeinterface: { aoqi@0: int virtual_call_data_cell_count = VirtualCallData::static_cell_count(); aoqi@0: if (profile_arguments_for_invoke(stream->method(), stream->bci()) || aoqi@0: profile_return_for_invoke(stream->method(), stream->bci())) { aoqi@0: cell_count = VirtualCallTypeData::compute_cell_count(stream); aoqi@0: } else { aoqi@0: cell_count = virtual_call_data_cell_count; aoqi@0: } aoqi@0: if (cell_count > virtual_call_data_cell_count) { aoqi@0: tag = DataLayout::virtual_call_type_data_tag; aoqi@0: } else { aoqi@0: tag = DataLayout::virtual_call_data_tag; aoqi@0: } aoqi@0: break; aoqi@0: } aoqi@0: case Bytecodes::_invokedynamic: { aoqi@0: // %%% should make a type profile for any invokedynamic that takes a ref argument aoqi@0: int counter_data_cell_count = CounterData::static_cell_count(); aoqi@0: if (profile_arguments_for_invoke(stream->method(), stream->bci()) || aoqi@0: profile_return_for_invoke(stream->method(), stream->bci())) { aoqi@0: cell_count = CallTypeData::compute_cell_count(stream); aoqi@0: } else { aoqi@0: cell_count = counter_data_cell_count; aoqi@0: } aoqi@0: if (cell_count > counter_data_cell_count) { aoqi@0: tag = DataLayout::call_type_data_tag; aoqi@0: } else { aoqi@0: tag = DataLayout::counter_data_tag; aoqi@0: } aoqi@0: break; aoqi@0: } aoqi@0: case Bytecodes::_ret: aoqi@0: cell_count = RetData::static_cell_count(); aoqi@0: tag = DataLayout::ret_data_tag; aoqi@0: break; aoqi@0: case Bytecodes::_ifeq: aoqi@0: case Bytecodes::_ifne: aoqi@0: case Bytecodes::_iflt: aoqi@0: case Bytecodes::_ifge: aoqi@0: case Bytecodes::_ifgt: aoqi@0: case Bytecodes::_ifle: aoqi@0: case Bytecodes::_if_icmpeq: aoqi@0: case Bytecodes::_if_icmpne: aoqi@0: case Bytecodes::_if_icmplt: aoqi@0: case Bytecodes::_if_icmpge: aoqi@0: case Bytecodes::_if_icmpgt: aoqi@0: case Bytecodes::_if_icmple: aoqi@0: case Bytecodes::_if_acmpeq: aoqi@0: case Bytecodes::_if_acmpne: aoqi@0: case Bytecodes::_ifnull: aoqi@0: case Bytecodes::_ifnonnull: aoqi@0: cell_count = BranchData::static_cell_count(); aoqi@0: tag = DataLayout::branch_data_tag; aoqi@0: break; aoqi@0: case Bytecodes::_lookupswitch: aoqi@0: case Bytecodes::_tableswitch: aoqi@0: cell_count = MultiBranchData::compute_cell_count(stream); aoqi@0: tag = DataLayout::multi_branch_data_tag; aoqi@0: break; aoqi@0: } aoqi@0: assert(tag == DataLayout::multi_branch_data_tag || aoqi@0: ((MethodData::profile_arguments() || MethodData::profile_return()) && aoqi@0: (tag == DataLayout::call_type_data_tag || aoqi@0: tag == DataLayout::counter_data_tag || aoqi@0: tag == DataLayout::virtual_call_type_data_tag || aoqi@0: tag == DataLayout::virtual_call_data_tag)) || aoqi@0: cell_count == bytecode_cell_count(c), "cell counts must agree"); aoqi@0: if (cell_count >= 0) { aoqi@0: assert(tag != DataLayout::no_tag, "bad tag"); aoqi@0: assert(bytecode_has_profile(c), "agree w/ BHP"); aoqi@0: data_layout->initialize(tag, stream->bci(), cell_count); aoqi@0: return DataLayout::compute_size_in_bytes(cell_count); aoqi@0: } else { aoqi@0: assert(!bytecode_has_profile(c), "agree w/ !BHP"); aoqi@0: return 0; aoqi@0: } aoqi@0: #endif aoqi@0: } aoqi@0: aoqi@0: // Get the data at an arbitrary (sort of) data index. aoqi@0: ProfileData* MethodData::data_at(int data_index) const { aoqi@0: if (out_of_bounds(data_index)) { aoqi@0: return NULL; aoqi@0: } aoqi@0: DataLayout* data_layout = data_layout_at(data_index); aoqi@0: return data_layout->data_in(); aoqi@0: } aoqi@0: aoqi@0: ProfileData* DataLayout::data_in() { aoqi@0: switch (tag()) { aoqi@0: case DataLayout::no_tag: aoqi@0: default: aoqi@0: ShouldNotReachHere(); aoqi@0: return NULL; aoqi@0: case DataLayout::bit_data_tag: aoqi@0: return new BitData(this); aoqi@0: case DataLayout::counter_data_tag: aoqi@0: return new CounterData(this); aoqi@0: case DataLayout::jump_data_tag: aoqi@0: return new JumpData(this); aoqi@0: case DataLayout::receiver_type_data_tag: aoqi@0: return new ReceiverTypeData(this); aoqi@0: case DataLayout::virtual_call_data_tag: aoqi@0: return new VirtualCallData(this); aoqi@0: case DataLayout::ret_data_tag: aoqi@0: return new RetData(this); aoqi@0: case DataLayout::branch_data_tag: aoqi@0: return new BranchData(this); aoqi@0: case DataLayout::multi_branch_data_tag: aoqi@0: return new MultiBranchData(this); aoqi@0: case DataLayout::arg_info_data_tag: aoqi@0: return new ArgInfoData(this); aoqi@0: case DataLayout::call_type_data_tag: aoqi@0: return new CallTypeData(this); aoqi@0: case DataLayout::virtual_call_type_data_tag: aoqi@0: return new VirtualCallTypeData(this); aoqi@0: case DataLayout::parameters_type_data_tag: aoqi@0: return new ParametersTypeData(this); aoqi@0: }; aoqi@0: } aoqi@0: aoqi@0: // Iteration over data. aoqi@0: ProfileData* MethodData::next_data(ProfileData* current) const { aoqi@0: int current_index = dp_to_di(current->dp()); aoqi@0: int next_index = current_index + current->size_in_bytes(); aoqi@0: ProfileData* next = data_at(next_index); aoqi@0: return next; aoqi@0: } aoqi@0: aoqi@0: // Give each of the data entries a chance to perform specific aoqi@0: // data initialization. aoqi@0: void MethodData::post_initialize(BytecodeStream* stream) { aoqi@0: ResourceMark rm; aoqi@0: ProfileData* data; aoqi@0: for (data = first_data(); is_valid(data); data = next_data(data)) { aoqi@0: stream->set_start(data->bci()); aoqi@0: stream->next(); aoqi@0: data->post_initialize(stream, this); aoqi@0: } aoqi@0: if (_parameters_type_data_di != -1) { aoqi@0: parameters_type_data()->post_initialize(NULL, this); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // Initialize the MethodData* corresponding to a given method. aoqi@0: MethodData::MethodData(methodHandle method, int size, TRAPS) aoqi@0: : _extra_data_lock(Monitor::leaf, "MDO extra data lock") { aoqi@0: No_Safepoint_Verifier no_safepoint; // init function atomic wrt GC aoqi@0: ResourceMark rm; aoqi@0: // Set the method back-pointer. aoqi@0: _method = method(); aoqi@0: aoqi@0: init(); aoqi@0: set_creation_mileage(mileage_of(method())); aoqi@0: aoqi@0: // Go through the bytecodes and allocate and initialize the aoqi@0: // corresponding data cells. aoqi@0: int data_size = 0; aoqi@0: int empty_bc_count = 0; // number of bytecodes lacking data aoqi@0: _data[0] = 0; // apparently not set below. aoqi@0: BytecodeStream stream(method); aoqi@0: Bytecodes::Code c; aoqi@0: bool needs_speculative_traps = false; aoqi@0: while ((c = stream.next()) >= 0) { aoqi@0: int size_in_bytes = initialize_data(&stream, data_size); aoqi@0: data_size += size_in_bytes; aoqi@0: if (size_in_bytes == 0) empty_bc_count += 1; aoqi@0: needs_speculative_traps = needs_speculative_traps || is_speculative_trap_bytecode(c); aoqi@0: } aoqi@0: _data_size = data_size; aoqi@0: int object_size = in_bytes(data_offset()) + data_size; aoqi@0: aoqi@0: // Add some extra DataLayout cells (at least one) to track stray traps. aoqi@0: int extra_data_count = compute_extra_data_count(data_size, empty_bc_count, needs_speculative_traps); aoqi@0: int extra_size = extra_data_count * DataLayout::compute_size_in_bytes(0); aoqi@0: aoqi@0: // Let's zero the space for the extra data aoqi@0: Copy::zero_to_bytes(((address)_data) + data_size, extra_size); aoqi@0: aoqi@0: // Add a cell to record information about modified arguments. aoqi@0: // Set up _args_modified array after traps cells so that aoqi@0: // the code for traps cells works. aoqi@0: DataLayout *dp = data_layout_at(data_size + extra_size); aoqi@0: aoqi@0: int arg_size = method->size_of_parameters(); aoqi@0: dp->initialize(DataLayout::arg_info_data_tag, 0, arg_size+1); aoqi@0: aoqi@0: int arg_data_size = DataLayout::compute_size_in_bytes(arg_size+1); aoqi@0: object_size += extra_size + arg_data_size; aoqi@0: aoqi@0: int parms_cell = ParametersTypeData::compute_cell_count(method()); aoqi@0: // If we are profiling parameters, we reserver an area near the end aoqi@0: // of the MDO after the slots for bytecodes (because there's no bci aoqi@0: // for method entry so they don't fit with the framework for the aoqi@0: // profiling of bytecodes). We store the offset within the MDO of aoqi@0: // this area (or -1 if no parameter is profiled) aoqi@0: if (parms_cell > 0) { aoqi@0: object_size += DataLayout::compute_size_in_bytes(parms_cell); aoqi@0: _parameters_type_data_di = data_size + extra_size + arg_data_size; aoqi@0: DataLayout *dp = data_layout_at(data_size + extra_size + arg_data_size); aoqi@0: dp->initialize(DataLayout::parameters_type_data_tag, 0, parms_cell); aoqi@0: } else { aoqi@0: _parameters_type_data_di = -1; aoqi@0: } aoqi@0: aoqi@0: // Set an initial hint. Don't use set_hint_di() because aoqi@0: // first_di() may be out of bounds if data_size is 0. aoqi@0: // In that situation, _hint_di is never used, but at aoqi@0: // least well-defined. aoqi@0: _hint_di = first_di(); aoqi@0: aoqi@0: post_initialize(&stream); aoqi@0: aoqi@0: set_size(object_size); aoqi@0: } aoqi@0: aoqi@0: void MethodData::init() { aoqi@0: _invocation_counter.init(); aoqi@0: _backedge_counter.init(); aoqi@0: _invocation_counter_start = 0; aoqi@0: _backedge_counter_start = 0; aoqi@0: _num_loops = 0; aoqi@0: _num_blocks = 0; aoqi@0: _highest_comp_level = 0; aoqi@0: _highest_osr_comp_level = 0; aoqi@0: _would_profile = true; aoqi@0: aoqi@0: #if INCLUDE_RTM_OPT aoqi@0: _rtm_state = NoRTM; // No RTM lock eliding by default aoqi@0: if (UseRTMLocking && aoqi@0: !CompilerOracle::has_option_string(_method, "NoRTMLockEliding")) { aoqi@0: if (CompilerOracle::has_option_string(_method, "UseRTMLockEliding") || !UseRTMDeopt) { aoqi@0: // Generate RTM lock eliding code without abort ratio calculation code. aoqi@0: _rtm_state = UseRTM; aoqi@0: } else if (UseRTMDeopt) { aoqi@0: // Generate RTM lock eliding code and include abort ratio calculation aoqi@0: // code if UseRTMDeopt is on. aoqi@0: _rtm_state = ProfileRTM; aoqi@0: } aoqi@0: } aoqi@0: #endif aoqi@0: aoqi@0: // Initialize flags and trap history. aoqi@0: _nof_decompiles = 0; aoqi@0: _nof_overflow_recompiles = 0; aoqi@0: _nof_overflow_traps = 0; aoqi@0: clear_escape_info(); aoqi@0: assert(sizeof(_trap_hist) % sizeof(HeapWord) == 0, "align"); aoqi@0: Copy::zero_to_words((HeapWord*) &_trap_hist, aoqi@0: sizeof(_trap_hist) / sizeof(HeapWord)); aoqi@0: } aoqi@0: aoqi@0: // Get a measure of how much mileage the method has on it. aoqi@0: int MethodData::mileage_of(Method* method) { aoqi@0: int mileage = 0; aoqi@0: if (TieredCompilation) { aoqi@0: mileage = MAX2(method->invocation_count(), method->backedge_count()); aoqi@0: } else { aoqi@0: int iic = method->interpreter_invocation_count(); aoqi@0: if (mileage < iic) mileage = iic; aoqi@0: MethodCounters* mcs = method->method_counters(); aoqi@0: if (mcs != NULL) { aoqi@0: InvocationCounter* ic = mcs->invocation_counter(); aoqi@0: InvocationCounter* bc = mcs->backedge_counter(); aoqi@0: int icval = ic->count(); aoqi@0: if (ic->carry()) icval += CompileThreshold; aoqi@0: if (mileage < icval) mileage = icval; aoqi@0: int bcval = bc->count(); aoqi@0: if (bc->carry()) bcval += CompileThreshold; aoqi@0: if (mileage < bcval) mileage = bcval; aoqi@0: } aoqi@0: } aoqi@0: return mileage; aoqi@0: } aoqi@0: aoqi@0: bool MethodData::is_mature() const { aoqi@0: return CompilationPolicy::policy()->is_mature(_method); aoqi@0: } aoqi@0: aoqi@0: // Translate a bci to its corresponding data index (di). aoqi@0: address MethodData::bci_to_dp(int bci) { aoqi@0: ResourceMark rm; aoqi@0: ProfileData* data = data_before(bci); aoqi@0: ProfileData* prev = NULL; aoqi@0: for ( ; is_valid(data); data = next_data(data)) { aoqi@0: if (data->bci() >= bci) { aoqi@0: if (data->bci() == bci) set_hint_di(dp_to_di(data->dp())); aoqi@0: else if (prev != NULL) set_hint_di(dp_to_di(prev->dp())); aoqi@0: return data->dp(); aoqi@0: } aoqi@0: prev = data; aoqi@0: } aoqi@0: return (address)limit_data_position(); aoqi@0: } aoqi@0: aoqi@0: // Translate a bci to its corresponding data, or NULL. aoqi@0: ProfileData* MethodData::bci_to_data(int bci) { aoqi@0: ProfileData* data = data_before(bci); aoqi@0: for ( ; is_valid(data); data = next_data(data)) { aoqi@0: if (data->bci() == bci) { aoqi@0: set_hint_di(dp_to_di(data->dp())); aoqi@0: return data; aoqi@0: } else if (data->bci() > bci) { aoqi@0: break; aoqi@0: } aoqi@0: } aoqi@0: return bci_to_extra_data(bci, NULL, false); aoqi@0: } aoqi@0: aoqi@0: DataLayout* MethodData::next_extra(DataLayout* dp) { aoqi@0: int nb_cells = 0; aoqi@0: switch(dp->tag()) { aoqi@0: case DataLayout::bit_data_tag: aoqi@0: case DataLayout::no_tag: aoqi@0: nb_cells = BitData::static_cell_count(); aoqi@0: break; aoqi@0: case DataLayout::speculative_trap_data_tag: aoqi@0: nb_cells = SpeculativeTrapData::static_cell_count(); aoqi@0: break; aoqi@0: default: aoqi@0: fatal(err_msg("unexpected tag %d", dp->tag())); aoqi@0: } aoqi@0: return (DataLayout*)((address)dp + DataLayout::compute_size_in_bytes(nb_cells)); aoqi@0: } aoqi@0: aoqi@0: ProfileData* MethodData::bci_to_extra_data_helper(int bci, Method* m, DataLayout*& dp, bool concurrent) { aoqi@0: DataLayout* end = extra_data_limit(); aoqi@0: aoqi@0: for (;; dp = next_extra(dp)) { aoqi@0: assert(dp < end, "moved past end of extra data"); aoqi@0: // No need for "OrderAccess::load_acquire" ops, aoqi@0: // since the data structure is monotonic. aoqi@0: switch(dp->tag()) { aoqi@0: case DataLayout::no_tag: aoqi@0: return NULL; aoqi@0: case DataLayout::arg_info_data_tag: aoqi@0: dp = end; aoqi@0: return NULL; // ArgInfoData is at the end of extra data section. aoqi@0: case DataLayout::bit_data_tag: aoqi@0: if (m == NULL && dp->bci() == bci) { aoqi@0: return new BitData(dp); aoqi@0: } aoqi@0: break; aoqi@0: case DataLayout::speculative_trap_data_tag: aoqi@0: if (m != NULL) { aoqi@0: SpeculativeTrapData* data = new SpeculativeTrapData(dp); aoqi@0: // data->method() may be null in case of a concurrent aoqi@0: // allocation. Maybe it's for the same method. Try to use that aoqi@0: // entry in that case. aoqi@0: if (dp->bci() == bci) { aoqi@0: if (data->method() == NULL) { aoqi@0: assert(concurrent, "impossible because no concurrent allocation"); aoqi@0: return NULL; aoqi@0: } else if (data->method() == m) { aoqi@0: return data; aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: break; aoqi@0: default: aoqi@0: fatal(err_msg("unexpected tag %d", dp->tag())); aoqi@0: } aoqi@0: } aoqi@0: return NULL; aoqi@0: } aoqi@0: aoqi@0: aoqi@0: // Translate a bci to its corresponding extra data, or NULL. aoqi@0: ProfileData* MethodData::bci_to_extra_data(int bci, Method* m, bool create_if_missing) { aoqi@0: // This code assumes an entry for a SpeculativeTrapData is 2 cells aoqi@0: assert(2*DataLayout::compute_size_in_bytes(BitData::static_cell_count()) == aoqi@0: DataLayout::compute_size_in_bytes(SpeculativeTrapData::static_cell_count()), aoqi@0: "code needs to be adjusted"); aoqi@0: aoqi@0: DataLayout* dp = extra_data_base(); aoqi@0: DataLayout* end = extra_data_limit(); aoqi@0: aoqi@0: // Allocation in the extra data space has to be atomic because not aoqi@0: // all entries have the same size and non atomic concurrent aoqi@0: // allocation would result in a corrupted extra data space. aoqi@0: ProfileData* result = bci_to_extra_data_helper(bci, m, dp, true); aoqi@0: if (result != NULL) { aoqi@0: return result; aoqi@0: } aoqi@0: aoqi@0: if (create_if_missing && dp < end) { aoqi@0: MutexLocker ml(&_extra_data_lock); aoqi@0: // Check again now that we have the lock. Another thread may aoqi@0: // have added extra data entries. aoqi@0: ProfileData* result = bci_to_extra_data_helper(bci, m, dp, false); aoqi@0: if (result != NULL || dp >= end) { aoqi@0: return result; aoqi@0: } aoqi@0: aoqi@0: assert(dp->tag() == DataLayout::no_tag || (dp->tag() == DataLayout::speculative_trap_data_tag && m != NULL), "should be free"); aoqi@0: assert(next_extra(dp)->tag() == DataLayout::no_tag || next_extra(dp)->tag() == DataLayout::arg_info_data_tag, "should be free or arg info"); aoqi@0: u1 tag = m == NULL ? DataLayout::bit_data_tag : DataLayout::speculative_trap_data_tag; aoqi@0: // SpeculativeTrapData is 2 slots. Make sure we have room. aoqi@0: if (m != NULL && next_extra(dp)->tag() != DataLayout::no_tag) { aoqi@0: return NULL; aoqi@0: } aoqi@0: DataLayout temp; aoqi@0: temp.initialize(tag, bci, 0); aoqi@0: aoqi@0: dp->set_header(temp.header()); aoqi@0: assert(dp->tag() == tag, "sane"); aoqi@0: assert(dp->bci() == bci, "no concurrent allocation"); aoqi@0: if (tag == DataLayout::bit_data_tag) { aoqi@0: return new BitData(dp); aoqi@0: } else { aoqi@0: SpeculativeTrapData* data = new SpeculativeTrapData(dp); aoqi@0: data->set_method(m); aoqi@0: return data; aoqi@0: } aoqi@0: } aoqi@0: return NULL; aoqi@0: } aoqi@0: aoqi@0: ArgInfoData *MethodData::arg_info() { aoqi@0: DataLayout* dp = extra_data_base(); aoqi@0: DataLayout* end = extra_data_limit(); aoqi@0: for (; dp < end; dp = next_extra(dp)) { aoqi@0: if (dp->tag() == DataLayout::arg_info_data_tag) aoqi@0: return new ArgInfoData(dp); aoqi@0: } aoqi@0: return NULL; aoqi@0: } aoqi@0: aoqi@0: // Printing aoqi@0: aoqi@0: #ifndef PRODUCT aoqi@0: aoqi@0: void MethodData::print_on(outputStream* st) const { aoqi@0: assert(is_methodData(), "should be method data"); aoqi@0: st->print("method data for "); aoqi@0: method()->print_value_on(st); aoqi@0: st->cr(); aoqi@0: print_data_on(st); aoqi@0: } aoqi@0: aoqi@0: #endif //PRODUCT aoqi@0: aoqi@0: void MethodData::print_value_on(outputStream* st) const { aoqi@0: assert(is_methodData(), "should be method data"); aoqi@0: st->print("method data for "); aoqi@0: method()->print_value_on(st); aoqi@0: } aoqi@0: aoqi@0: #ifndef PRODUCT aoqi@0: void MethodData::print_data_on(outputStream* st) const { aoqi@0: ResourceMark rm; aoqi@0: ProfileData* data = first_data(); aoqi@0: if (_parameters_type_data_di != -1) { aoqi@0: parameters_type_data()->print_data_on(st); aoqi@0: } aoqi@0: for ( ; is_valid(data); data = next_data(data)) { aoqi@0: st->print("%d", dp_to_di(data->dp())); aoqi@0: st->fill_to(6); aoqi@0: data->print_data_on(st, this); aoqi@0: } aoqi@0: st->print_cr("--- Extra data:"); aoqi@0: DataLayout* dp = extra_data_base(); aoqi@0: DataLayout* end = extra_data_limit(); aoqi@0: for (;; dp = next_extra(dp)) { aoqi@0: assert(dp < end, "moved past end of extra data"); aoqi@0: // No need for "OrderAccess::load_acquire" ops, aoqi@0: // since the data structure is monotonic. aoqi@0: switch(dp->tag()) { aoqi@0: case DataLayout::no_tag: aoqi@0: continue; aoqi@0: case DataLayout::bit_data_tag: aoqi@0: data = new BitData(dp); aoqi@0: break; aoqi@0: case DataLayout::speculative_trap_data_tag: aoqi@0: data = new SpeculativeTrapData(dp); aoqi@0: break; aoqi@0: case DataLayout::arg_info_data_tag: aoqi@0: data = new ArgInfoData(dp); aoqi@0: dp = end; // ArgInfoData is at the end of extra data section. aoqi@0: break; aoqi@0: default: aoqi@0: fatal(err_msg("unexpected tag %d", dp->tag())); aoqi@0: } aoqi@0: st->print("%d", dp_to_di(data->dp())); aoqi@0: st->fill_to(6); aoqi@0: data->print_data_on(st); aoqi@0: if (dp >= end) return; aoqi@0: } aoqi@0: } aoqi@0: #endif aoqi@0: aoqi@0: #if INCLUDE_SERVICES aoqi@0: // Size Statistics aoqi@0: void MethodData::collect_statistics(KlassSizeStats *sz) const { aoqi@0: int n = sz->count(this); aoqi@0: sz->_method_data_bytes += n; aoqi@0: sz->_method_all_bytes += n; aoqi@0: sz->_rw_bytes += n; aoqi@0: } aoqi@0: #endif // INCLUDE_SERVICES aoqi@0: aoqi@0: // Verification aoqi@0: aoqi@0: void MethodData::verify_on(outputStream* st) { aoqi@0: guarantee(is_methodData(), "object must be method data"); aoqi@0: // guarantee(m->is_perm(), "should be in permspace"); aoqi@0: this->verify_data_on(st); aoqi@0: } aoqi@0: aoqi@0: void MethodData::verify_data_on(outputStream* st) { aoqi@0: NEEDS_CLEANUP; aoqi@0: // not yet implemented. aoqi@0: } aoqi@0: aoqi@0: bool MethodData::profile_jsr292(methodHandle m, int bci) { aoqi@0: if (m->is_compiled_lambda_form()) { aoqi@0: return true; aoqi@0: } aoqi@0: aoqi@0: Bytecode_invoke inv(m , bci); aoqi@0: return inv.is_invokedynamic() || inv.is_invokehandle(); aoqi@0: } aoqi@0: aoqi@0: int MethodData::profile_arguments_flag() { aoqi@0: return TypeProfileLevel % 10; aoqi@0: } aoqi@0: aoqi@0: bool MethodData::profile_arguments() { aoqi@0: return profile_arguments_flag() > no_type_profile && profile_arguments_flag() <= type_profile_all; aoqi@0: } aoqi@0: aoqi@0: bool MethodData::profile_arguments_jsr292_only() { aoqi@0: return profile_arguments_flag() == type_profile_jsr292; aoqi@0: } aoqi@0: aoqi@0: bool MethodData::profile_all_arguments() { aoqi@0: return profile_arguments_flag() == type_profile_all; aoqi@0: } aoqi@0: aoqi@0: bool MethodData::profile_arguments_for_invoke(methodHandle m, int bci) { aoqi@0: if (!profile_arguments()) { aoqi@0: return false; aoqi@0: } aoqi@0: aoqi@0: if (profile_all_arguments()) { aoqi@0: return true; aoqi@0: } aoqi@0: aoqi@0: assert(profile_arguments_jsr292_only(), "inconsistent"); aoqi@0: return profile_jsr292(m, bci); aoqi@0: } aoqi@0: aoqi@0: int MethodData::profile_return_flag() { aoqi@0: return (TypeProfileLevel % 100) / 10; aoqi@0: } aoqi@0: aoqi@0: bool MethodData::profile_return() { aoqi@0: return profile_return_flag() > no_type_profile && profile_return_flag() <= type_profile_all; aoqi@0: } aoqi@0: aoqi@0: bool MethodData::profile_return_jsr292_only() { aoqi@0: return profile_return_flag() == type_profile_jsr292; aoqi@0: } aoqi@0: aoqi@0: bool MethodData::profile_all_return() { aoqi@0: return profile_return_flag() == type_profile_all; aoqi@0: } aoqi@0: aoqi@0: bool MethodData::profile_return_for_invoke(methodHandle m, int bci) { aoqi@0: if (!profile_return()) { aoqi@0: return false; aoqi@0: } aoqi@0: aoqi@0: if (profile_all_return()) { aoqi@0: return true; aoqi@0: } aoqi@0: aoqi@0: assert(profile_return_jsr292_only(), "inconsistent"); aoqi@0: return profile_jsr292(m, bci); aoqi@0: } aoqi@0: aoqi@0: int MethodData::profile_parameters_flag() { aoqi@0: return TypeProfileLevel / 100; aoqi@0: } aoqi@0: aoqi@0: bool MethodData::profile_parameters() { aoqi@0: return profile_parameters_flag() > no_type_profile && profile_parameters_flag() <= type_profile_all; aoqi@0: } aoqi@0: aoqi@0: bool MethodData::profile_parameters_jsr292_only() { aoqi@0: return profile_parameters_flag() == type_profile_jsr292; aoqi@0: } aoqi@0: aoqi@0: bool MethodData::profile_all_parameters() { aoqi@0: return profile_parameters_flag() == type_profile_all; aoqi@0: } aoqi@0: aoqi@0: bool MethodData::profile_parameters_for_method(methodHandle m) { aoqi@0: if (!profile_parameters()) { aoqi@0: return false; aoqi@0: } aoqi@0: aoqi@0: if (profile_all_parameters()) { aoqi@0: return true; aoqi@0: } aoqi@0: aoqi@0: assert(profile_parameters_jsr292_only(), "inconsistent"); aoqi@0: return m->is_compiled_lambda_form(); aoqi@0: } aoqi@0: aoqi@0: void MethodData::clean_extra_data_helper(DataLayout* dp, int shift, bool reset) { aoqi@0: if (shift == 0) { aoqi@0: return; aoqi@0: } aoqi@0: if (!reset) { aoqi@0: // Move all cells of trap entry at dp left by "shift" cells aoqi@0: intptr_t* start = (intptr_t*)dp; aoqi@0: intptr_t* end = (intptr_t*)next_extra(dp); aoqi@0: for (intptr_t* ptr = start; ptr < end; ptr++) { aoqi@0: *(ptr-shift) = *ptr; aoqi@0: } aoqi@0: } else { aoqi@0: // Reset "shift" cells stopping at dp aoqi@0: intptr_t* start = ((intptr_t*)dp) - shift; aoqi@0: intptr_t* end = (intptr_t*)dp; aoqi@0: for (intptr_t* ptr = start; ptr < end; ptr++) { aoqi@0: *ptr = 0; aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // Remove SpeculativeTrapData entries that reference an unloaded aoqi@0: // method aoqi@0: void MethodData::clean_extra_data(BoolObjectClosure* is_alive) { aoqi@0: DataLayout* dp = extra_data_base(); aoqi@0: DataLayout* end = extra_data_limit(); aoqi@0: aoqi@0: int shift = 0; aoqi@0: for (; dp < end; dp = next_extra(dp)) { aoqi@0: switch(dp->tag()) { aoqi@0: case DataLayout::speculative_trap_data_tag: { aoqi@0: SpeculativeTrapData* data = new SpeculativeTrapData(dp); aoqi@0: Method* m = data->method(); aoqi@0: assert(m != NULL, "should have a method"); aoqi@0: if (!m->method_holder()->is_loader_alive(is_alive)) { aoqi@0: // "shift" accumulates the number of cells for dead aoqi@0: // SpeculativeTrapData entries that have been seen so aoqi@0: // far. Following entries must be shifted left by that many aoqi@0: // cells to remove the dead SpeculativeTrapData entries. aoqi@0: shift += (int)((intptr_t*)next_extra(dp) - (intptr_t*)dp); aoqi@0: } else { aoqi@0: // Shift this entry left if it follows dead aoqi@0: // SpeculativeTrapData entries aoqi@0: clean_extra_data_helper(dp, shift); aoqi@0: } aoqi@0: break; aoqi@0: } aoqi@0: case DataLayout::bit_data_tag: aoqi@0: // Shift this entry left if it follows dead SpeculativeTrapData aoqi@0: // entries aoqi@0: clean_extra_data_helper(dp, shift); aoqi@0: continue; aoqi@0: case DataLayout::no_tag: aoqi@0: case DataLayout::arg_info_data_tag: aoqi@0: // We are at end of the live trap entries. The previous "shift" aoqi@0: // cells contain entries that are either dead or were shifted aoqi@0: // left. They need to be reset to no_tag aoqi@0: clean_extra_data_helper(dp, shift, true); aoqi@0: return; aoqi@0: default: aoqi@0: fatal(err_msg("unexpected tag %d", dp->tag())); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // Verify there's no unloaded method referenced by a aoqi@0: // SpeculativeTrapData entry aoqi@0: void MethodData::verify_extra_data_clean(BoolObjectClosure* is_alive) { aoqi@0: #ifdef ASSERT aoqi@0: DataLayout* dp = extra_data_base(); aoqi@0: DataLayout* end = extra_data_limit(); aoqi@0: aoqi@0: for (; dp < end; dp = next_extra(dp)) { aoqi@0: switch(dp->tag()) { aoqi@0: case DataLayout::speculative_trap_data_tag: { aoqi@0: SpeculativeTrapData* data = new SpeculativeTrapData(dp); aoqi@0: Method* m = data->method(); aoqi@0: assert(m != NULL && m->method_holder()->is_loader_alive(is_alive), "Method should exist"); aoqi@0: break; aoqi@0: } aoqi@0: case DataLayout::bit_data_tag: aoqi@0: continue; aoqi@0: case DataLayout::no_tag: aoqi@0: case DataLayout::arg_info_data_tag: aoqi@0: return; aoqi@0: default: aoqi@0: fatal(err_msg("unexpected tag %d", dp->tag())); aoqi@0: } aoqi@0: } aoqi@0: #endif aoqi@0: } aoqi@0: aoqi@0: void MethodData::clean_method_data(BoolObjectClosure* is_alive) { aoqi@0: for (ProfileData* data = first_data(); aoqi@0: is_valid(data); aoqi@0: data = next_data(data)) { aoqi@0: data->clean_weak_klass_links(is_alive); aoqi@0: } aoqi@0: ParametersTypeData* parameters = parameters_type_data(); aoqi@0: if (parameters != NULL) { aoqi@0: parameters->clean_weak_klass_links(is_alive); aoqi@0: } aoqi@0: aoqi@0: clean_extra_data(is_alive); aoqi@0: verify_extra_data_clean(is_alive); aoqi@0: }