Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/oops/methodData.cpp
32285 views
/*1* Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include "precompiled.hpp"25#include "classfile/systemDictionary.hpp"26#include "compiler/compilerOracle.hpp"27#include "interpreter/bytecode.hpp"28#include "interpreter/bytecodeStream.hpp"29#include "interpreter/linkResolver.hpp"30#include "memory/heapInspection.hpp"31#include "oops/methodData.hpp"32#include "prims/jvmtiRedefineClasses.hpp"33#include "runtime/compilationPolicy.hpp"34#include "runtime/deoptimization.hpp"35#include "runtime/handles.inline.hpp"36#include "runtime/orderAccess.inline.hpp"3738PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC3940// ==================================================================41// DataLayout42//43// Overlay for generic profiling data.4445// Some types of data layouts need a length field.46bool DataLayout::needs_array_len(u1 tag) {47return (tag == multi_branch_data_tag) || (tag == arg_info_data_tag) || (tag == parameters_type_data_tag);48}4950// Perform generic initialization of the data. More specific51// initialization occurs in overrides of ProfileData::post_initialize.52void DataLayout::initialize(u1 tag, u2 bci, int cell_count) {53_header._bits = (intptr_t)0;54_header._struct._tag = tag;55_header._struct._bci = bci;56for (int i = 0; i < cell_count; i++) {57set_cell_at(i, (intptr_t)0);58}59if (needs_array_len(tag)) {60set_cell_at(ArrayData::array_len_off_set, cell_count - 1); // -1 for header.61}62if (tag == call_type_data_tag) {63CallTypeData::initialize(this, cell_count);64} else if (tag == virtual_call_type_data_tag) {65VirtualCallTypeData::initialize(this, cell_count);66}67}6869void DataLayout::clean_weak_klass_links(BoolObjectClosure* cl) {70ResourceMark m;71data_in()->clean_weak_klass_links(cl);72}737475// ==================================================================76// ProfileData77//78// A ProfileData object is created to refer to a section of profiling79// data in a structured way.8081// Constructor for invalid ProfileData.82ProfileData::ProfileData() {83_data = NULL;84}8586char* ProfileData::print_data_on_helper(const MethodData* md) const {87DataLayout* dp = md->extra_data_base();88DataLayout* end = md->extra_data_limit();89stringStream ss;90for (;; dp = MethodData::next_extra(dp)) {91assert(dp < end, "moved past end of extra data");92switch(dp->tag()) {93case DataLayout::speculative_trap_data_tag:94if (dp->bci() == bci()) {95SpeculativeTrapData* data = new SpeculativeTrapData(dp);96int trap = data->trap_state();97char buf[100];98ss.print("trap/");99data->method()->print_short_name(&ss);100ss.print("(%s) ", Deoptimization::format_trap_state(buf, sizeof(buf), trap));101}102break;103case DataLayout::bit_data_tag:104break;105case DataLayout::no_tag:106case DataLayout::arg_info_data_tag:107return ss.as_string();108break;109default:110fatal(err_msg("unexpected tag %d", dp->tag()));111}112}113return NULL;114}115116void ProfileData::print_data_on(outputStream* st, const MethodData* md) const {117print_data_on(st, print_data_on_helper(md));118}119120#ifndef PRODUCT121void ProfileData::print_shared(outputStream* st, const char* name, const char* extra) const {122st->print("bci: %d", bci());123st->fill_to(tab_width_one);124st->print("%s", name);125tab(st);126int trap = trap_state();127if (trap != 0) {128char buf[100];129st->print("trap(%s) ", Deoptimization::format_trap_state(buf, sizeof(buf), trap));130}131if (extra != NULL) {132st->print("%s", extra);133}134int flags = data()->flags();135if (flags != 0) {136st->print("flags(%d) ", flags);137}138}139140void ProfileData::tab(outputStream* st, bool first) const {141st->fill_to(first ? tab_width_one : tab_width_two);142}143#endif // !PRODUCT144145// ==================================================================146// BitData147//148// A BitData corresponds to a one-bit flag. This is used to indicate149// whether a checkcast bytecode has seen a null value.150151152#ifndef PRODUCT153void BitData::print_data_on(outputStream* st, const char* extra) const {154print_shared(st, "BitData", extra);155}156#endif // !PRODUCT157158// ==================================================================159// CounterData160//161// A CounterData corresponds to a simple counter.162163#ifndef PRODUCT164void CounterData::print_data_on(outputStream* st, const char* extra) const {165print_shared(st, "CounterData", extra);166st->print_cr("count(%u)", count());167}168#endif // !PRODUCT169170// ==================================================================171// JumpData172//173// A JumpData is used to access profiling information for a direct174// branch. It is a counter, used for counting the number of branches,175// plus a data displacement, used for realigning the data pointer to176// the corresponding target bci.177178void JumpData::post_initialize(BytecodeStream* stream, MethodData* mdo) {179assert(stream->bci() == bci(), "wrong pos");180int target;181Bytecodes::Code c = stream->code();182if (c == Bytecodes::_goto_w || c == Bytecodes::_jsr_w) {183target = stream->dest_w();184} else {185target = stream->dest();186}187int my_di = mdo->dp_to_di(dp());188int target_di = mdo->bci_to_di(target);189int offset = target_di - my_di;190set_displacement(offset);191}192193#ifndef PRODUCT194void JumpData::print_data_on(outputStream* st, const char* extra) const {195print_shared(st, "JumpData", extra);196st->print_cr("taken(%u) displacement(%d)", taken(), displacement());197}198#endif // !PRODUCT199200int TypeStackSlotEntries::compute_cell_count(Symbol* signature, bool include_receiver, int max) {201// Parameter profiling include the receiver202int args_count = include_receiver ? 1 : 0;203ResourceMark rm;204SignatureStream ss(signature);205args_count += ss.reference_parameter_count();206args_count = MIN2(args_count, max);207return args_count * per_arg_cell_count;208}209210int TypeEntriesAtCall::compute_cell_count(BytecodeStream* stream) {211assert(Bytecodes::is_invoke(stream->code()), "should be invoke");212assert(TypeStackSlotEntries::per_arg_count() > ReturnTypeEntry::static_cell_count(), "code to test for arguments/results broken");213Bytecode_invoke inv(stream->method(), stream->bci());214int args_cell = 0;215if (arguments_profiling_enabled()) {216args_cell = TypeStackSlotEntries::compute_cell_count(inv.signature(), false, TypeProfileArgsLimit);217}218int ret_cell = 0;219if (return_profiling_enabled() && (inv.result_type() == T_OBJECT || inv.result_type() == T_ARRAY)) {220ret_cell = ReturnTypeEntry::static_cell_count();221}222int header_cell = 0;223if (args_cell + ret_cell > 0) {224header_cell = header_cell_count();225}226227return header_cell + args_cell + ret_cell;228}229230class ArgumentOffsetComputer : public SignatureInfo {231private:232int _max;233GrowableArray<int> _offsets;234235void set(int size, BasicType type) { _size += size; }236void do_object(int begin, int end) {237if (_offsets.length() < _max) {238_offsets.push(_size);239}240SignatureInfo::do_object(begin, end);241}242void do_array (int begin, int end) {243if (_offsets.length() < _max) {244_offsets.push(_size);245}246SignatureInfo::do_array(begin, end);247}248249public:250ArgumentOffsetComputer(Symbol* signature, int max)251: SignatureInfo(signature), _max(max), _offsets(Thread::current(), max) {252}253254int total() { lazy_iterate_parameters(); return _size; }255256int off_at(int i) const { return _offsets.at(i); }257};258259void TypeStackSlotEntries::post_initialize(Symbol* signature, bool has_receiver, bool include_receiver) {260ResourceMark rm;261int start = 0;262// Parameter profiling include the receiver263if (include_receiver && has_receiver) {264set_stack_slot(0, 0);265set_type(0, type_none());266start += 1;267}268ArgumentOffsetComputer aos(signature, _number_of_entries-start);269aos.total();270for (int i = start; i < _number_of_entries; i++) {271set_stack_slot(i, aos.off_at(i-start) + (has_receiver ? 1 : 0));272set_type(i, type_none());273}274}275276void CallTypeData::post_initialize(BytecodeStream* stream, MethodData* mdo) {277assert(Bytecodes::is_invoke(stream->code()), "should be invoke");278Bytecode_invoke inv(stream->method(), stream->bci());279280SignatureStream ss(inv.signature());281if (has_arguments()) {282#ifdef ASSERT283ResourceMark rm;284int count = MIN2(ss.reference_parameter_count(), (int)TypeProfileArgsLimit);285assert(count > 0, "room for args type but none found?");286check_number_of_arguments(count);287#endif288_args.post_initialize(inv.signature(), inv.has_receiver(), false);289}290291if (has_return()) {292assert(inv.result_type() == T_OBJECT || inv.result_type() == T_ARRAY, "room for a ret type but doesn't return obj?");293_ret.post_initialize();294}295}296297void VirtualCallTypeData::post_initialize(BytecodeStream* stream, MethodData* mdo) {298assert(Bytecodes::is_invoke(stream->code()), "should be invoke");299Bytecode_invoke inv(stream->method(), stream->bci());300301if (has_arguments()) {302#ifdef ASSERT303ResourceMark rm;304SignatureStream ss(inv.signature());305int count = MIN2(ss.reference_parameter_count(), (int)TypeProfileArgsLimit);306assert(count > 0, "room for args type but none found?");307check_number_of_arguments(count);308#endif309_args.post_initialize(inv.signature(), inv.has_receiver(), false);310}311312if (has_return()) {313assert(inv.result_type() == T_OBJECT || inv.result_type() == T_ARRAY, "room for a ret type but doesn't return obj?");314_ret.post_initialize();315}316}317318bool TypeEntries::is_loader_alive(BoolObjectClosure* is_alive_cl, intptr_t p) {319Klass* k = (Klass*)klass_part(p);320return k != NULL && k->is_loader_alive(is_alive_cl);321}322323void TypeStackSlotEntries::clean_weak_klass_links(BoolObjectClosure* is_alive_cl) {324for (int i = 0; i < _number_of_entries; i++) {325intptr_t p = type(i);326if (!is_loader_alive(is_alive_cl, p)) {327set_type(i, with_status((Klass*)NULL, p));328}329}330}331332void ReturnTypeEntry::clean_weak_klass_links(BoolObjectClosure* is_alive_cl) {333intptr_t p = type();334if (!is_loader_alive(is_alive_cl, p)) {335set_type(with_status((Klass*)NULL, p));336}337}338339bool TypeEntriesAtCall::return_profiling_enabled() {340return MethodData::profile_return();341}342343bool TypeEntriesAtCall::arguments_profiling_enabled() {344return MethodData::profile_arguments();345}346347#ifndef PRODUCT348void TypeEntries::print_klass(outputStream* st, intptr_t k) {349if (is_type_none(k)) {350st->print("none");351} else if (is_type_unknown(k)) {352st->print("unknown");353} else {354valid_klass(k)->print_value_on(st);355}356if (was_null_seen(k)) {357st->print(" (null seen)");358}359}360361void TypeStackSlotEntries::print_data_on(outputStream* st) const {362for (int i = 0; i < _number_of_entries; i++) {363_pd->tab(st);364st->print("%d: stack(%u) ", i, stack_slot(i));365print_klass(st, type(i));366st->cr();367}368}369370void ReturnTypeEntry::print_data_on(outputStream* st) const {371_pd->tab(st);372print_klass(st, type());373st->cr();374}375376void CallTypeData::print_data_on(outputStream* st, const char* extra) const {377CounterData::print_data_on(st, extra);378if (has_arguments()) {379tab(st, true);380st->print("argument types");381_args.print_data_on(st);382}383if (has_return()) {384tab(st, true);385st->print("return type");386_ret.print_data_on(st);387}388}389390void VirtualCallTypeData::print_data_on(outputStream* st, const char* extra) const {391VirtualCallData::print_data_on(st, extra);392if (has_arguments()) {393tab(st, true);394st->print("argument types");395_args.print_data_on(st);396}397if (has_return()) {398tab(st, true);399st->print("return type");400_ret.print_data_on(st);401}402}403#endif404405// ==================================================================406// ReceiverTypeData407//408// A ReceiverTypeData is used to access profiling information about a409// dynamic type check. It consists of a counter which counts the total times410// that the check is reached, and a series of (Klass*, count) pairs411// which are used to store a type profile for the receiver of the check.412413void ReceiverTypeData::clean_weak_klass_links(BoolObjectClosure* is_alive_cl) {414for (uint row = 0; row < row_limit(); row++) {415Klass* p = receiver(row);416if (p != NULL && !p->is_loader_alive(is_alive_cl)) {417clear_row(row);418}419}420}421422#ifndef PRODUCT423void ReceiverTypeData::print_receiver_data_on(outputStream* st) const {424uint row;425int entries = 0;426for (row = 0; row < row_limit(); row++) {427if (receiver(row) != NULL) entries++;428}429st->print_cr("count(%u) entries(%u)", count(), entries);430int total = count();431for (row = 0; row < row_limit(); row++) {432if (receiver(row) != NULL) {433total += receiver_count(row);434}435}436for (row = 0; row < row_limit(); row++) {437if (receiver(row) != NULL) {438tab(st);439receiver(row)->print_value_on(st);440st->print_cr("(%u %4.2f)", receiver_count(row), (float) receiver_count(row) / (float) total);441}442}443}444void ReceiverTypeData::print_data_on(outputStream* st, const char* extra) const {445print_shared(st, "ReceiverTypeData", extra);446print_receiver_data_on(st);447}448void VirtualCallData::print_data_on(outputStream* st, const char* extra) const {449print_shared(st, "VirtualCallData", extra);450print_receiver_data_on(st);451}452#endif // !PRODUCT453454// ==================================================================455// RetData456//457// A RetData is used to access profiling information for a ret bytecode.458// It is composed of a count of the number of times that the ret has459// been executed, followed by a series of triples of the form460// (bci, count, di) which count the number of times that some bci was the461// target of the ret and cache a corresponding displacement.462463void RetData::post_initialize(BytecodeStream* stream, MethodData* mdo) {464for (uint row = 0; row < row_limit(); row++) {465set_bci_displacement(row, -1);466set_bci(row, no_bci);467}468// release so other threads see a consistent state. bci is used as469// a valid flag for bci_displacement.470OrderAccess::release();471}472473// This routine needs to atomically update the RetData structure, so the474// caller needs to hold the RetData_lock before it gets here. Since taking475// the lock can block (and allow GC) and since RetData is a ProfileData is a476// wrapper around a derived oop, taking the lock in _this_ method will477// basically cause the 'this' pointer's _data field to contain junk after the478// lock. We require the caller to take the lock before making the ProfileData479// structure. Currently the only caller is InterpreterRuntime::update_mdp_for_ret480address RetData::fixup_ret(int return_bci, MethodData* h_mdo) {481// First find the mdp which corresponds to the return bci.482address mdp = h_mdo->bci_to_dp(return_bci);483484// Now check to see if any of the cache slots are open.485for (uint row = 0; row < row_limit(); row++) {486if (bci(row) == no_bci) {487set_bci_displacement(row, mdp - dp());488set_bci_count(row, DataLayout::counter_increment);489// Barrier to ensure displacement is written before the bci; allows490// the interpreter to read displacement without fear of race condition.491release_set_bci(row, return_bci);492break;493}494}495return mdp;496}497498#ifdef CC_INTERP499DataLayout* RetData::advance(MethodData *md, int bci) {500return (DataLayout*) md->bci_to_dp(bci);501}502#endif // CC_INTERP503504#ifndef PRODUCT505void RetData::print_data_on(outputStream* st, const char* extra) const {506print_shared(st, "RetData", extra);507uint row;508int entries = 0;509for (row = 0; row < row_limit(); row++) {510if (bci(row) != no_bci) entries++;511}512st->print_cr("count(%u) entries(%u)", count(), entries);513for (row = 0; row < row_limit(); row++) {514if (bci(row) != no_bci) {515tab(st);516st->print_cr("bci(%d: count(%u) displacement(%d))",517bci(row), bci_count(row), bci_displacement(row));518}519}520}521#endif // !PRODUCT522523// ==================================================================524// BranchData525//526// A BranchData is used to access profiling data for a two-way branch.527// It consists of taken and not_taken counts as well as a data displacement528// for the taken case.529530void BranchData::post_initialize(BytecodeStream* stream, MethodData* mdo) {531assert(stream->bci() == bci(), "wrong pos");532int target = stream->dest();533int my_di = mdo->dp_to_di(dp());534int target_di = mdo->bci_to_di(target);535int offset = target_di - my_di;536set_displacement(offset);537}538539#ifndef PRODUCT540void BranchData::print_data_on(outputStream* st, const char* extra) const {541print_shared(st, "BranchData", extra);542st->print_cr("taken(%u) displacement(%d)",543taken(), displacement());544tab(st);545st->print_cr("not taken(%u)", not_taken());546}547#endif548549// ==================================================================550// MultiBranchData551//552// A MultiBranchData is used to access profiling information for553// a multi-way branch (*switch bytecodes). It consists of a series554// of (count, displacement) pairs, which count the number of times each555// case was taken and specify the data displacment for each branch target.556557int MultiBranchData::compute_cell_count(BytecodeStream* stream) {558int cell_count = 0;559if (stream->code() == Bytecodes::_tableswitch) {560Bytecode_tableswitch sw(stream->method()(), stream->bcp());561cell_count = 1 + per_case_cell_count * (1 + sw.length()); // 1 for default562} else {563Bytecode_lookupswitch sw(stream->method()(), stream->bcp());564cell_count = 1 + per_case_cell_count * (sw.number_of_pairs() + 1); // 1 for default565}566return cell_count;567}568569void MultiBranchData::post_initialize(BytecodeStream* stream,570MethodData* mdo) {571assert(stream->bci() == bci(), "wrong pos");572int target;573int my_di;574int target_di;575int offset;576if (stream->code() == Bytecodes::_tableswitch) {577Bytecode_tableswitch sw(stream->method()(), stream->bcp());578int len = sw.length();579assert(array_len() == per_case_cell_count * (len + 1), "wrong len");580for (int count = 0; count < len; count++) {581target = sw.dest_offset_at(count) + bci();582my_di = mdo->dp_to_di(dp());583target_di = mdo->bci_to_di(target);584offset = target_di - my_di;585set_displacement_at(count, offset);586}587target = sw.default_offset() + bci();588my_di = mdo->dp_to_di(dp());589target_di = mdo->bci_to_di(target);590offset = target_di - my_di;591set_default_displacement(offset);592593} else {594Bytecode_lookupswitch sw(stream->method()(), stream->bcp());595int npairs = sw.number_of_pairs();596assert(array_len() == per_case_cell_count * (npairs + 1), "wrong len");597for (int count = 0; count < npairs; count++) {598LookupswitchPair pair = sw.pair_at(count);599target = pair.offset() + bci();600my_di = mdo->dp_to_di(dp());601target_di = mdo->bci_to_di(target);602offset = target_di - my_di;603set_displacement_at(count, offset);604}605target = sw.default_offset() + bci();606my_di = mdo->dp_to_di(dp());607target_di = mdo->bci_to_di(target);608offset = target_di - my_di;609set_default_displacement(offset);610}611}612613#ifndef PRODUCT614void MultiBranchData::print_data_on(outputStream* st, const char* extra) const {615print_shared(st, "MultiBranchData", extra);616st->print_cr("default_count(%u) displacement(%d)",617default_count(), default_displacement());618int cases = number_of_cases();619for (int i = 0; i < cases; i++) {620tab(st);621st->print_cr("count(%u) displacement(%d)",622count_at(i), displacement_at(i));623}624}625#endif626627#ifndef PRODUCT628void ArgInfoData::print_data_on(outputStream* st, const char* extra) const {629print_shared(st, "ArgInfoData", extra);630int nargs = number_of_args();631for (int i = 0; i < nargs; i++) {632st->print(" 0x%x", arg_modified(i));633}634st->cr();635}636637#endif638639int ParametersTypeData::compute_cell_count(Method* m) {640if (!MethodData::profile_parameters_for_method(m)) {641return 0;642}643int max = TypeProfileParmsLimit == -1 ? INT_MAX : TypeProfileParmsLimit;644int obj_args = TypeStackSlotEntries::compute_cell_count(m->signature(), !m->is_static(), max);645if (obj_args > 0) {646return obj_args + 1; // 1 cell for array len647}648return 0;649}650651void ParametersTypeData::post_initialize(BytecodeStream* stream, MethodData* mdo) {652_parameters.post_initialize(mdo->method()->signature(), !mdo->method()->is_static(), true);653}654655bool ParametersTypeData::profiling_enabled() {656return MethodData::profile_parameters();657}658659#ifndef PRODUCT660void ParametersTypeData::print_data_on(outputStream* st, const char* extra) const {661st->print("parameter types"); // FIXME extra ignored?662_parameters.print_data_on(st);663}664665void SpeculativeTrapData::print_data_on(outputStream* st, const char* extra) const {666print_shared(st, "SpeculativeTrapData", extra);667tab(st);668method()->print_short_name(st);669st->cr();670}671#endif672673// ==================================================================674// MethodData*675//676// A MethodData* holds information which has been collected about677// a method.678679MethodData* MethodData::allocate(ClassLoaderData* loader_data, methodHandle method, TRAPS) {680int size = MethodData::compute_allocation_size_in_words(method);681682return new (loader_data, size, false, MetaspaceObj::MethodDataType, THREAD)683MethodData(method(), size, THREAD);684}685686int MethodData::bytecode_cell_count(Bytecodes::Code code) {687#if defined(COMPILER1) && !defined(COMPILER2)688return no_profile_data;689#else690switch (code) {691case Bytecodes::_checkcast:692case Bytecodes::_instanceof:693case Bytecodes::_aastore:694if (TypeProfileCasts) {695return ReceiverTypeData::static_cell_count();696} else {697return BitData::static_cell_count();698}699case Bytecodes::_invokespecial:700case Bytecodes::_invokestatic:701if (MethodData::profile_arguments() || MethodData::profile_return()) {702return variable_cell_count;703} else {704return CounterData::static_cell_count();705}706case Bytecodes::_goto:707case Bytecodes::_goto_w:708case Bytecodes::_jsr:709case Bytecodes::_jsr_w:710return JumpData::static_cell_count();711case Bytecodes::_invokevirtual:712case Bytecodes::_invokeinterface:713if (MethodData::profile_arguments() || MethodData::profile_return()) {714return variable_cell_count;715} else {716return VirtualCallData::static_cell_count();717}718case Bytecodes::_invokedynamic:719if (MethodData::profile_arguments() || MethodData::profile_return()) {720return variable_cell_count;721} else {722return CounterData::static_cell_count();723}724case Bytecodes::_ret:725return RetData::static_cell_count();726case Bytecodes::_ifeq:727case Bytecodes::_ifne:728case Bytecodes::_iflt:729case Bytecodes::_ifge:730case Bytecodes::_ifgt:731case Bytecodes::_ifle:732case Bytecodes::_if_icmpeq:733case Bytecodes::_if_icmpne:734case Bytecodes::_if_icmplt:735case Bytecodes::_if_icmpge:736case Bytecodes::_if_icmpgt:737case Bytecodes::_if_icmple:738case Bytecodes::_if_acmpeq:739case Bytecodes::_if_acmpne:740case Bytecodes::_ifnull:741case Bytecodes::_ifnonnull:742return BranchData::static_cell_count();743case Bytecodes::_lookupswitch:744case Bytecodes::_tableswitch:745return variable_cell_count;746}747return no_profile_data;748#endif749}750751// Compute the size of the profiling information corresponding to752// the current bytecode.753int MethodData::compute_data_size(BytecodeStream* stream) {754int cell_count = bytecode_cell_count(stream->code());755if (cell_count == no_profile_data) {756return 0;757}758if (cell_count == variable_cell_count) {759switch (stream->code()) {760case Bytecodes::_lookupswitch:761case Bytecodes::_tableswitch:762cell_count = MultiBranchData::compute_cell_count(stream);763break;764case Bytecodes::_invokespecial:765case Bytecodes::_invokestatic:766case Bytecodes::_invokedynamic:767assert(MethodData::profile_arguments() || MethodData::profile_return(), "should be collecting args profile");768if (profile_arguments_for_invoke(stream->method(), stream->bci()) ||769profile_return_for_invoke(stream->method(), stream->bci())) {770cell_count = CallTypeData::compute_cell_count(stream);771} else {772cell_count = CounterData::static_cell_count();773}774break;775case Bytecodes::_invokevirtual:776case Bytecodes::_invokeinterface: {777assert(MethodData::profile_arguments() || MethodData::profile_return(), "should be collecting args profile");778if (profile_arguments_for_invoke(stream->method(), stream->bci()) ||779profile_return_for_invoke(stream->method(), stream->bci())) {780cell_count = VirtualCallTypeData::compute_cell_count(stream);781} else {782cell_count = VirtualCallData::static_cell_count();783}784break;785}786default:787fatal("unexpected bytecode for var length profile data");788}789}790// Note: cell_count might be zero, meaning that there is just791// a DataLayout header, with no extra cells.792assert(cell_count >= 0, "sanity");793return DataLayout::compute_size_in_bytes(cell_count);794}795796bool MethodData::is_speculative_trap_bytecode(Bytecodes::Code code) {797// Bytecodes for which we may use speculation798switch (code) {799case Bytecodes::_checkcast:800case Bytecodes::_instanceof:801case Bytecodes::_aastore:802case Bytecodes::_invokevirtual:803case Bytecodes::_invokeinterface:804case Bytecodes::_if_acmpeq:805case Bytecodes::_if_acmpne:806case Bytecodes::_invokestatic:807#ifdef COMPILER2808return UseTypeSpeculation;809#endif810default:811return false;812}813return false;814}815816int MethodData::compute_extra_data_count(int data_size, int empty_bc_count, bool needs_speculative_traps) {817if (ProfileTraps) {818// Assume that up to 3% of BCIs with no MDP will need to allocate one.819int extra_data_count = (uint)(empty_bc_count * 3) / 128 + 1;820// If the method is large, let the extra BCIs grow numerous (to ~1%).821int one_percent_of_data822= (uint)data_size / (DataLayout::header_size_in_bytes()*128);823if (extra_data_count < one_percent_of_data)824extra_data_count = one_percent_of_data;825if (extra_data_count > empty_bc_count)826extra_data_count = empty_bc_count; // no need for more827828// Make sure we have a minimum number of extra data slots to829// allocate SpeculativeTrapData entries. We would want to have one830// entry per compilation that inlines this method and for which831// some type speculation assumption fails. So the room we need for832// the SpeculativeTrapData entries doesn't directly depend on the833// size of the method. Because it's hard to estimate, we reserve834// space for an arbitrary number of entries.835int spec_data_count = (needs_speculative_traps ? SpecTrapLimitExtraEntries : 0) *836(SpeculativeTrapData::static_cell_count() + DataLayout::header_size_in_cells());837838return MAX2(extra_data_count, spec_data_count);839} else {840return 0;841}842}843844// Compute the size of the MethodData* necessary to store845// profiling information about a given method. Size is in bytes.846int MethodData::compute_allocation_size_in_bytes(methodHandle method) {847int data_size = 0;848BytecodeStream stream(method);849Bytecodes::Code c;850int empty_bc_count = 0; // number of bytecodes lacking data851bool needs_speculative_traps = false;852while ((c = stream.next()) >= 0) {853int size_in_bytes = compute_data_size(&stream);854data_size += size_in_bytes;855if (size_in_bytes == 0) empty_bc_count += 1;856needs_speculative_traps = needs_speculative_traps || is_speculative_trap_bytecode(c);857}858int object_size = in_bytes(data_offset()) + data_size;859860// Add some extra DataLayout cells (at least one) to track stray traps.861int extra_data_count = compute_extra_data_count(data_size, empty_bc_count, needs_speculative_traps);862object_size += extra_data_count * DataLayout::compute_size_in_bytes(0);863864// Add a cell to record information about modified arguments.865int arg_size = method->size_of_parameters();866object_size += DataLayout::compute_size_in_bytes(arg_size+1);867868// Reserve room for an area of the MDO dedicated to profiling of869// parameters870int args_cell = ParametersTypeData::compute_cell_count(method());871if (args_cell > 0) {872object_size += DataLayout::compute_size_in_bytes(args_cell);873}874return object_size;875}876877// Compute the size of the MethodData* necessary to store878// profiling information about a given method. Size is in words879int MethodData::compute_allocation_size_in_words(methodHandle method) {880int byte_size = compute_allocation_size_in_bytes(method);881int word_size = align_size_up(byte_size, BytesPerWord) / BytesPerWord;882return align_object_size(word_size);883}884885// Initialize an individual data segment. Returns the size of886// the segment in bytes.887int MethodData::initialize_data(BytecodeStream* stream,888int data_index) {889#if defined(COMPILER1) && !defined(COMPILER2)890return 0;891#else892int cell_count = -1;893int tag = DataLayout::no_tag;894DataLayout* data_layout = data_layout_at(data_index);895Bytecodes::Code c = stream->code();896switch (c) {897case Bytecodes::_checkcast:898case Bytecodes::_instanceof:899case Bytecodes::_aastore:900if (TypeProfileCasts) {901cell_count = ReceiverTypeData::static_cell_count();902tag = DataLayout::receiver_type_data_tag;903} else {904cell_count = BitData::static_cell_count();905tag = DataLayout::bit_data_tag;906}907break;908case Bytecodes::_invokespecial:909case Bytecodes::_invokestatic: {910int counter_data_cell_count = CounterData::static_cell_count();911if (profile_arguments_for_invoke(stream->method(), stream->bci()) ||912profile_return_for_invoke(stream->method(), stream->bci())) {913cell_count = CallTypeData::compute_cell_count(stream);914} else {915cell_count = counter_data_cell_count;916}917if (cell_count > counter_data_cell_count) {918tag = DataLayout::call_type_data_tag;919} else {920tag = DataLayout::counter_data_tag;921}922break;923}924case Bytecodes::_goto:925case Bytecodes::_goto_w:926case Bytecodes::_jsr:927case Bytecodes::_jsr_w:928cell_count = JumpData::static_cell_count();929tag = DataLayout::jump_data_tag;930break;931case Bytecodes::_invokevirtual:932case Bytecodes::_invokeinterface: {933int virtual_call_data_cell_count = VirtualCallData::static_cell_count();934if (profile_arguments_for_invoke(stream->method(), stream->bci()) ||935profile_return_for_invoke(stream->method(), stream->bci())) {936cell_count = VirtualCallTypeData::compute_cell_count(stream);937} else {938cell_count = virtual_call_data_cell_count;939}940if (cell_count > virtual_call_data_cell_count) {941tag = DataLayout::virtual_call_type_data_tag;942} else {943tag = DataLayout::virtual_call_data_tag;944}945break;946}947case Bytecodes::_invokedynamic: {948// %%% should make a type profile for any invokedynamic that takes a ref argument949int counter_data_cell_count = CounterData::static_cell_count();950if (profile_arguments_for_invoke(stream->method(), stream->bci()) ||951profile_return_for_invoke(stream->method(), stream->bci())) {952cell_count = CallTypeData::compute_cell_count(stream);953} else {954cell_count = counter_data_cell_count;955}956if (cell_count > counter_data_cell_count) {957tag = DataLayout::call_type_data_tag;958} else {959tag = DataLayout::counter_data_tag;960}961break;962}963case Bytecodes::_ret:964cell_count = RetData::static_cell_count();965tag = DataLayout::ret_data_tag;966break;967case Bytecodes::_ifeq:968case Bytecodes::_ifne:969case Bytecodes::_iflt:970case Bytecodes::_ifge:971case Bytecodes::_ifgt:972case Bytecodes::_ifle:973case Bytecodes::_if_icmpeq:974case Bytecodes::_if_icmpne:975case Bytecodes::_if_icmplt:976case Bytecodes::_if_icmpge:977case Bytecodes::_if_icmpgt:978case Bytecodes::_if_icmple:979case Bytecodes::_if_acmpeq:980case Bytecodes::_if_acmpne:981case Bytecodes::_ifnull:982case Bytecodes::_ifnonnull:983cell_count = BranchData::static_cell_count();984tag = DataLayout::branch_data_tag;985break;986case Bytecodes::_lookupswitch:987case Bytecodes::_tableswitch:988cell_count = MultiBranchData::compute_cell_count(stream);989tag = DataLayout::multi_branch_data_tag;990break;991}992assert(tag == DataLayout::multi_branch_data_tag ||993((MethodData::profile_arguments() || MethodData::profile_return()) &&994(tag == DataLayout::call_type_data_tag ||995tag == DataLayout::counter_data_tag ||996tag == DataLayout::virtual_call_type_data_tag ||997tag == DataLayout::virtual_call_data_tag)) ||998cell_count == bytecode_cell_count(c), "cell counts must agree");999if (cell_count >= 0) {1000assert(tag != DataLayout::no_tag, "bad tag");1001assert(bytecode_has_profile(c), "agree w/ BHP");1002data_layout->initialize(tag, stream->bci(), cell_count);1003return DataLayout::compute_size_in_bytes(cell_count);1004} else {1005assert(!bytecode_has_profile(c), "agree w/ !BHP");1006return 0;1007}1008#endif1009}10101011// Get the data at an arbitrary (sort of) data index.1012ProfileData* MethodData::data_at(int data_index) const {1013if (out_of_bounds(data_index)) {1014return NULL;1015}1016DataLayout* data_layout = data_layout_at(data_index);1017return data_layout->data_in();1018}10191020ProfileData* DataLayout::data_in() {1021switch (tag()) {1022case DataLayout::no_tag:1023default:1024ShouldNotReachHere();1025return NULL;1026case DataLayout::bit_data_tag:1027return new BitData(this);1028case DataLayout::counter_data_tag:1029return new CounterData(this);1030case DataLayout::jump_data_tag:1031return new JumpData(this);1032case DataLayout::receiver_type_data_tag:1033return new ReceiverTypeData(this);1034case DataLayout::virtual_call_data_tag:1035return new VirtualCallData(this);1036case DataLayout::ret_data_tag:1037return new RetData(this);1038case DataLayout::branch_data_tag:1039return new BranchData(this);1040case DataLayout::multi_branch_data_tag:1041return new MultiBranchData(this);1042case DataLayout::arg_info_data_tag:1043return new ArgInfoData(this);1044case DataLayout::call_type_data_tag:1045return new CallTypeData(this);1046case DataLayout::virtual_call_type_data_tag:1047return new VirtualCallTypeData(this);1048case DataLayout::parameters_type_data_tag:1049return new ParametersTypeData(this);1050};1051}10521053// Iteration over data.1054ProfileData* MethodData::next_data(ProfileData* current) const {1055int current_index = dp_to_di(current->dp());1056int next_index = current_index + current->size_in_bytes();1057ProfileData* next = data_at(next_index);1058return next;1059}10601061// Give each of the data entries a chance to perform specific1062// data initialization.1063void MethodData::post_initialize(BytecodeStream* stream) {1064ResourceMark rm;1065ProfileData* data;1066for (data = first_data(); is_valid(data); data = next_data(data)) {1067stream->set_start(data->bci());1068stream->next();1069data->post_initialize(stream, this);1070}1071if (_parameters_type_data_di != -1) {1072parameters_type_data()->post_initialize(NULL, this);1073}1074}10751076// Initialize the MethodData* corresponding to a given method.1077MethodData::MethodData(methodHandle method, int size, TRAPS)1078: _extra_data_lock(Monitor::leaf, "MDO extra data lock") {1079No_Safepoint_Verifier no_safepoint; // init function atomic wrt GC1080ResourceMark rm;1081// Set the method back-pointer.1082_method = method();10831084init();1085set_creation_mileage(mileage_of(method()));10861087// Go through the bytecodes and allocate and initialize the1088// corresponding data cells.1089int data_size = 0;1090int empty_bc_count = 0; // number of bytecodes lacking data1091_data[0] = 0; // apparently not set below.1092BytecodeStream stream(method);1093Bytecodes::Code c;1094bool needs_speculative_traps = false;1095while ((c = stream.next()) >= 0) {1096int size_in_bytes = initialize_data(&stream, data_size);1097data_size += size_in_bytes;1098if (size_in_bytes == 0) empty_bc_count += 1;1099needs_speculative_traps = needs_speculative_traps || is_speculative_trap_bytecode(c);1100}1101_data_size = data_size;1102int object_size = in_bytes(data_offset()) + data_size;11031104// Add some extra DataLayout cells (at least one) to track stray traps.1105int extra_data_count = compute_extra_data_count(data_size, empty_bc_count, needs_speculative_traps);1106int extra_size = extra_data_count * DataLayout::compute_size_in_bytes(0);11071108// Let's zero the space for the extra data1109Copy::zero_to_bytes(((address)_data) + data_size, extra_size);11101111// Add a cell to record information about modified arguments.1112// Set up _args_modified array after traps cells so that1113// the code for traps cells works.1114DataLayout *dp = data_layout_at(data_size + extra_size);11151116int arg_size = method->size_of_parameters();1117dp->initialize(DataLayout::arg_info_data_tag, 0, arg_size+1);11181119int arg_data_size = DataLayout::compute_size_in_bytes(arg_size+1);1120object_size += extra_size + arg_data_size;11211122int parms_cell = ParametersTypeData::compute_cell_count(method());1123// If we are profiling parameters, we reserver an area near the end1124// of the MDO after the slots for bytecodes (because there's no bci1125// for method entry so they don't fit with the framework for the1126// profiling of bytecodes). We store the offset within the MDO of1127// this area (or -1 if no parameter is profiled)1128if (parms_cell > 0) {1129object_size += DataLayout::compute_size_in_bytes(parms_cell);1130_parameters_type_data_di = data_size + extra_size + arg_data_size;1131DataLayout *dp = data_layout_at(data_size + extra_size + arg_data_size);1132dp->initialize(DataLayout::parameters_type_data_tag, 0, parms_cell);1133} else {1134_parameters_type_data_di = -1;1135}11361137// Set an initial hint. Don't use set_hint_di() because1138// first_di() may be out of bounds if data_size is 0.1139// In that situation, _hint_di is never used, but at1140// least well-defined.1141_hint_di = first_di();11421143post_initialize(&stream);11441145set_size(object_size);1146}11471148void MethodData::init() {1149_invocation_counter.init();1150_backedge_counter.init();1151_invocation_counter_start = 0;1152_backedge_counter_start = 0;1153_num_loops = 0;1154_num_blocks = 0;1155_would_profile = unknown;11561157#if INCLUDE_RTM_OPT1158_rtm_state = NoRTM; // No RTM lock eliding by default1159if (UseRTMLocking &&1160!CompilerOracle::has_option_string(_method, "NoRTMLockEliding")) {1161if (CompilerOracle::has_option_string(_method, "UseRTMLockEliding") || !UseRTMDeopt) {1162// Generate RTM lock eliding code without abort ratio calculation code.1163_rtm_state = UseRTM;1164} else if (UseRTMDeopt) {1165// Generate RTM lock eliding code and include abort ratio calculation1166// code if UseRTMDeopt is on.1167_rtm_state = ProfileRTM;1168}1169}1170#endif11711172// Initialize flags and trap history.1173_nof_decompiles = 0;1174_nof_overflow_recompiles = 0;1175_nof_overflow_traps = 0;1176clear_escape_info();1177assert(sizeof(_trap_hist) % sizeof(HeapWord) == 0, "align");1178Copy::zero_to_words((HeapWord*) &_trap_hist,1179sizeof(_trap_hist) / sizeof(HeapWord));1180}11811182// Get a measure of how much mileage the method has on it.1183int MethodData::mileage_of(Method* method) {1184int mileage = 0;1185if (TieredCompilation) {1186mileage = MAX2(method->invocation_count(), method->backedge_count());1187} else {1188int iic = method->interpreter_invocation_count();1189if (mileage < iic) mileage = iic;1190MethodCounters* mcs = method->method_counters();1191if (mcs != NULL) {1192InvocationCounter* ic = mcs->invocation_counter();1193InvocationCounter* bc = mcs->backedge_counter();1194int icval = ic->count();1195if (ic->carry()) icval += CompileThreshold;1196if (mileage < icval) mileage = icval;1197int bcval = bc->count();1198if (bc->carry()) bcval += CompileThreshold;1199if (mileage < bcval) mileage = bcval;1200}1201}1202return mileage;1203}12041205bool MethodData::is_mature() const {1206return CompilationPolicy::policy()->is_mature(_method);1207}12081209// Translate a bci to its corresponding data index (di).1210address MethodData::bci_to_dp(int bci) {1211ResourceMark rm;1212ProfileData* data = data_before(bci);1213ProfileData* prev = NULL;1214for ( ; is_valid(data); data = next_data(data)) {1215if (data->bci() >= bci) {1216if (data->bci() == bci) set_hint_di(dp_to_di(data->dp()));1217else if (prev != NULL) set_hint_di(dp_to_di(prev->dp()));1218return data->dp();1219}1220prev = data;1221}1222return (address)limit_data_position();1223}12241225// Translate a bci to its corresponding data, or NULL.1226ProfileData* MethodData::bci_to_data(int bci) {1227ProfileData* data = data_before(bci);1228for ( ; is_valid(data); data = next_data(data)) {1229if (data->bci() == bci) {1230set_hint_di(dp_to_di(data->dp()));1231return data;1232} else if (data->bci() > bci) {1233break;1234}1235}1236return bci_to_extra_data(bci, NULL, false);1237}12381239DataLayout* MethodData::next_extra(DataLayout* dp) {1240int nb_cells = 0;1241switch(dp->tag()) {1242case DataLayout::bit_data_tag:1243case DataLayout::no_tag:1244nb_cells = BitData::static_cell_count();1245break;1246case DataLayout::speculative_trap_data_tag:1247nb_cells = SpeculativeTrapData::static_cell_count();1248break;1249default:1250fatal(err_msg("unexpected tag %d", dp->tag()));1251}1252return (DataLayout*)((address)dp + DataLayout::compute_size_in_bytes(nb_cells));1253}12541255ProfileData* MethodData::bci_to_extra_data_helper(int bci, Method* m, DataLayout*& dp, bool concurrent) {1256DataLayout* end = extra_data_limit();12571258for (;; dp = next_extra(dp)) {1259assert(dp < end, "moved past end of extra data");1260// No need for "OrderAccess::load_acquire" ops,1261// since the data structure is monotonic.1262switch(dp->tag()) {1263case DataLayout::no_tag:1264return NULL;1265case DataLayout::arg_info_data_tag:1266dp = end;1267return NULL; // ArgInfoData is at the end of extra data section.1268case DataLayout::bit_data_tag:1269if (m == NULL && dp->bci() == bci) {1270return new BitData(dp);1271}1272break;1273case DataLayout::speculative_trap_data_tag:1274if (m != NULL) {1275SpeculativeTrapData* data = new SpeculativeTrapData(dp);1276// data->method() may be null in case of a concurrent1277// allocation. Maybe it's for the same method. Try to use that1278// entry in that case.1279if (dp->bci() == bci) {1280if (data->method() == NULL) {1281assert(concurrent, "impossible because no concurrent allocation");1282return NULL;1283} else if (data->method() == m) {1284return data;1285}1286}1287}1288break;1289default:1290fatal(err_msg("unexpected tag %d", dp->tag()));1291}1292}1293return NULL;1294}129512961297// Translate a bci to its corresponding extra data, or NULL.1298ProfileData* MethodData::bci_to_extra_data(int bci, Method* m, bool create_if_missing) {1299// This code assumes an entry for a SpeculativeTrapData is 2 cells1300assert(2*DataLayout::compute_size_in_bytes(BitData::static_cell_count()) ==1301DataLayout::compute_size_in_bytes(SpeculativeTrapData::static_cell_count()),1302"code needs to be adjusted");13031304DataLayout* dp = extra_data_base();1305DataLayout* end = extra_data_limit();13061307// Allocation in the extra data space has to be atomic because not1308// all entries have the same size and non atomic concurrent1309// allocation would result in a corrupted extra data space.1310ProfileData* result = bci_to_extra_data_helper(bci, m, dp, true);1311if (result != NULL) {1312return result;1313}13141315if (create_if_missing && dp < end) {1316MutexLocker ml(&_extra_data_lock);1317// Check again now that we have the lock. Another thread may1318// have added extra data entries.1319ProfileData* result = bci_to_extra_data_helper(bci, m, dp, false);1320if (result != NULL || dp >= end) {1321return result;1322}13231324assert(dp->tag() == DataLayout::no_tag || (dp->tag() == DataLayout::speculative_trap_data_tag && m != NULL), "should be free");1325assert(next_extra(dp)->tag() == DataLayout::no_tag || next_extra(dp)->tag() == DataLayout::arg_info_data_tag, "should be free or arg info");1326u1 tag = m == NULL ? DataLayout::bit_data_tag : DataLayout::speculative_trap_data_tag;1327// SpeculativeTrapData is 2 slots. Make sure we have room.1328if (m != NULL && next_extra(dp)->tag() != DataLayout::no_tag) {1329return NULL;1330}1331DataLayout temp;1332temp.initialize(tag, bci, 0);13331334dp->set_header(temp.header());1335assert(dp->tag() == tag, "sane");1336assert(dp->bci() == bci, "no concurrent allocation");1337if (tag == DataLayout::bit_data_tag) {1338return new BitData(dp);1339} else {1340SpeculativeTrapData* data = new SpeculativeTrapData(dp);1341data->set_method(m);1342return data;1343}1344}1345return NULL;1346}13471348ArgInfoData *MethodData::arg_info() {1349DataLayout* dp = extra_data_base();1350DataLayout* end = extra_data_limit();1351for (; dp < end; dp = next_extra(dp)) {1352if (dp->tag() == DataLayout::arg_info_data_tag)1353return new ArgInfoData(dp);1354}1355return NULL;1356}13571358// Printing13591360#ifndef PRODUCT13611362void MethodData::print_on(outputStream* st) const {1363assert(is_methodData(), "should be method data");1364st->print("method data for ");1365method()->print_value_on(st);1366st->cr();1367print_data_on(st);1368}13691370#endif //PRODUCT13711372void MethodData::print_value_on(outputStream* st) const {1373assert(is_methodData(), "should be method data");1374st->print("method data for ");1375method()->print_value_on(st);1376}13771378#ifndef PRODUCT1379void MethodData::print_data_on(outputStream* st) const {1380ResourceMark rm;1381ProfileData* data = first_data();1382if (_parameters_type_data_di != -1) {1383parameters_type_data()->print_data_on(st);1384}1385for ( ; is_valid(data); data = next_data(data)) {1386st->print("%d", dp_to_di(data->dp()));1387st->fill_to(6);1388data->print_data_on(st, this);1389}1390st->print_cr("--- Extra data:");1391DataLayout* dp = extra_data_base();1392DataLayout* end = extra_data_limit();1393for (;; dp = next_extra(dp)) {1394assert(dp < end, "moved past end of extra data");1395// No need for "OrderAccess::load_acquire" ops,1396// since the data structure is monotonic.1397switch(dp->tag()) {1398case DataLayout::no_tag:1399continue;1400case DataLayout::bit_data_tag:1401data = new BitData(dp);1402break;1403case DataLayout::speculative_trap_data_tag:1404data = new SpeculativeTrapData(dp);1405break;1406case DataLayout::arg_info_data_tag:1407data = new ArgInfoData(dp);1408dp = end; // ArgInfoData is at the end of extra data section.1409break;1410default:1411fatal(err_msg("unexpected tag %d", dp->tag()));1412}1413st->print("%d", dp_to_di(data->dp()));1414st->fill_to(6);1415data->print_data_on(st);1416if (dp >= end) return;1417}1418}1419#endif14201421#if INCLUDE_SERVICES1422// Size Statistics1423void MethodData::collect_statistics(KlassSizeStats *sz) const {1424int n = sz->count(this);1425sz->_method_data_bytes += n;1426sz->_method_all_bytes += n;1427sz->_rw_bytes += n;1428}1429#endif // INCLUDE_SERVICES14301431// Verification14321433void MethodData::verify_on(outputStream* st) {1434guarantee(is_methodData(), "object must be method data");1435// guarantee(m->is_perm(), "should be in permspace");1436this->verify_data_on(st);1437}14381439void MethodData::verify_data_on(outputStream* st) {1440NEEDS_CLEANUP;1441// not yet implemented.1442}14431444bool MethodData::profile_jsr292(methodHandle m, int bci) {1445if (m->is_compiled_lambda_form()) {1446return true;1447}14481449Bytecode_invoke inv(m , bci);1450return inv.is_invokedynamic() || inv.is_invokehandle();1451}14521453int MethodData::profile_arguments_flag() {1454return TypeProfileLevel % 10;1455}14561457bool MethodData::profile_arguments() {1458return profile_arguments_flag() > no_type_profile && profile_arguments_flag() <= type_profile_all;1459}14601461bool MethodData::profile_arguments_jsr292_only() {1462return profile_arguments_flag() == type_profile_jsr292;1463}14641465bool MethodData::profile_all_arguments() {1466return profile_arguments_flag() == type_profile_all;1467}14681469bool MethodData::profile_arguments_for_invoke(methodHandle m, int bci) {1470if (!profile_arguments()) {1471return false;1472}14731474if (profile_all_arguments()) {1475return true;1476}14771478assert(profile_arguments_jsr292_only(), "inconsistent");1479return profile_jsr292(m, bci);1480}14811482int MethodData::profile_return_flag() {1483return (TypeProfileLevel % 100) / 10;1484}14851486bool MethodData::profile_return() {1487return profile_return_flag() > no_type_profile && profile_return_flag() <= type_profile_all;1488}14891490bool MethodData::profile_return_jsr292_only() {1491return profile_return_flag() == type_profile_jsr292;1492}14931494bool MethodData::profile_all_return() {1495return profile_return_flag() == type_profile_all;1496}14971498bool MethodData::profile_return_for_invoke(methodHandle m, int bci) {1499if (!profile_return()) {1500return false;1501}15021503if (profile_all_return()) {1504return true;1505}15061507assert(profile_return_jsr292_only(), "inconsistent");1508return profile_jsr292(m, bci);1509}15101511int MethodData::profile_parameters_flag() {1512return TypeProfileLevel / 100;1513}15141515bool MethodData::profile_parameters() {1516return profile_parameters_flag() > no_type_profile && profile_parameters_flag() <= type_profile_all;1517}15181519bool MethodData::profile_parameters_jsr292_only() {1520return profile_parameters_flag() == type_profile_jsr292;1521}15221523bool MethodData::profile_all_parameters() {1524return profile_parameters_flag() == type_profile_all;1525}15261527bool MethodData::profile_parameters_for_method(methodHandle m) {1528if (!profile_parameters()) {1529return false;1530}15311532if (profile_all_parameters()) {1533return true;1534}15351536assert(profile_parameters_jsr292_only(), "inconsistent");1537return m->is_compiled_lambda_form();1538}15391540void MethodData::clean_extra_data_helper(DataLayout* dp, int shift, bool reset) {1541if (shift == 0) {1542return;1543}1544if (!reset) {1545// Move all cells of trap entry at dp left by "shift" cells1546intptr_t* start = (intptr_t*)dp;1547intptr_t* end = (intptr_t*)next_extra(dp);1548for (intptr_t* ptr = start; ptr < end; ptr++) {1549*(ptr-shift) = *ptr;1550}1551} else {1552// Reset "shift" cells stopping at dp1553intptr_t* start = ((intptr_t*)dp) - shift;1554intptr_t* end = (intptr_t*)dp;1555for (intptr_t* ptr = start; ptr < end; ptr++) {1556*ptr = 0;1557}1558}1559}15601561class CleanExtraDataClosure : public StackObj {1562public:1563virtual bool is_live(Method* m) = 0;1564};15651566// Check for entries that reference an unloaded method1567class CleanExtraDataKlassClosure : public CleanExtraDataClosure {1568private:1569BoolObjectClosure* _is_alive;1570public:1571CleanExtraDataKlassClosure(BoolObjectClosure* is_alive) : _is_alive(is_alive) {}1572bool is_live(Method* m) {1573return m->method_holder()->is_loader_alive(_is_alive);1574}1575};15761577// Check for entries that reference a redefined method1578class CleanExtraDataMethodClosure : public CleanExtraDataClosure {1579public:1580CleanExtraDataMethodClosure() {}1581bool is_live(Method* m) {1582return m->on_stack();1583}1584};158515861587// Remove SpeculativeTrapData entries that reference an unloaded or1588// redefined method1589void MethodData::clean_extra_data(CleanExtraDataClosure* cl) {1590DataLayout* dp = extra_data_base();1591DataLayout* end = extra_data_limit();15921593int shift = 0;1594for (; dp < end; dp = next_extra(dp)) {1595switch(dp->tag()) {1596case DataLayout::speculative_trap_data_tag: {1597SpeculativeTrapData* data = new SpeculativeTrapData(dp);1598Method* m = data->method();1599assert(m != NULL, "should have a method");1600if (!cl->is_live(m)) {1601// "shift" accumulates the number of cells for dead1602// SpeculativeTrapData entries that have been seen so1603// far. Following entries must be shifted left by that many1604// cells to remove the dead SpeculativeTrapData entries.1605shift += (int)((intptr_t*)next_extra(dp) - (intptr_t*)dp);1606} else {1607// Shift this entry left if it follows dead1608// SpeculativeTrapData entries1609clean_extra_data_helper(dp, shift);1610}1611break;1612}1613case DataLayout::bit_data_tag:1614// Shift this entry left if it follows dead SpeculativeTrapData1615// entries1616clean_extra_data_helper(dp, shift);1617continue;1618case DataLayout::no_tag:1619case DataLayout::arg_info_data_tag:1620// We are at end of the live trap entries. The previous "shift"1621// cells contain entries that are either dead or were shifted1622// left. They need to be reset to no_tag1623clean_extra_data_helper(dp, shift, true);1624return;1625default:1626fatal(err_msg("unexpected tag %d", dp->tag()));1627}1628}1629}16301631// Verify there's no unloaded or redefined method referenced by a1632// SpeculativeTrapData entry1633void MethodData::verify_extra_data_clean(CleanExtraDataClosure* cl) {1634#ifdef ASSERT1635DataLayout* dp = extra_data_base();1636DataLayout* end = extra_data_limit();16371638for (; dp < end; dp = next_extra(dp)) {1639switch(dp->tag()) {1640case DataLayout::speculative_trap_data_tag: {1641SpeculativeTrapData* data = new SpeculativeTrapData(dp);1642Method* m = data->method();1643assert(m != NULL && cl->is_live(m), "Method should exist");1644break;1645}1646case DataLayout::bit_data_tag:1647continue;1648case DataLayout::no_tag:1649case DataLayout::arg_info_data_tag:1650return;1651default:1652fatal(err_msg("unexpected tag %d", dp->tag()));1653}1654}1655#endif1656}16571658void MethodData::clean_method_data(BoolObjectClosure* is_alive) {1659for (ProfileData* data = first_data();1660is_valid(data);1661data = next_data(data)) {1662data->clean_weak_klass_links(is_alive);1663}1664ParametersTypeData* parameters = parameters_type_data();1665if (parameters != NULL) {1666parameters->clean_weak_klass_links(is_alive);1667}16681669CleanExtraDataKlassClosure cl(is_alive);1670clean_extra_data(&cl);1671verify_extra_data_clean(&cl);1672}16731674void MethodData::clean_weak_method_links() {1675for (ProfileData* data = first_data();1676is_valid(data);1677data = next_data(data)) {1678data->clean_weak_method_links();1679}16801681CleanExtraDataMethodClosure cl;1682clean_extra_data(&cl);1683verify_extra_data_clean(&cl);1684}168516861687