Path: blob/master/src/hotspot/share/ci/ciMethodData.hpp
40930 views
/*1* Copyright (c) 2001, 2019, 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#ifndef SHARE_CI_CIMETHODDATA_HPP25#define SHARE_CI_CIMETHODDATA_HPP2627#include "ci/ciClassList.hpp"28#include "ci/ciKlass.hpp"29#include "ci/ciObject.hpp"30#include "ci/ciUtilities.hpp"31#include "oops/methodData.hpp"32#include "oops/oop.hpp"33#include "runtime/deoptimization.hpp"3435class ciBitData;36class ciCounterData;37class ciJumpData;38class ciReceiverTypeData;39class ciRetData;40class ciBranchData;41class ciArrayData;42class ciMultiBranchData;43class ciArgInfoData;44class ciCallTypeData;45class ciVirtualCallTypeData;46class ciParametersTypeData;47class ciSpeculativeTrapData;4849typedef ProfileData ciProfileData;5051class ciBitData : public BitData {52public:53ciBitData(DataLayout* layout) : BitData(layout) {};54};5556class ciCounterData : public CounterData {57public:58ciCounterData(DataLayout* layout) : CounterData(layout) {};59};6061class ciJumpData : public JumpData {62public:63ciJumpData(DataLayout* layout) : JumpData(layout) {};64};6566class ciTypeEntries {67protected:68static intptr_t translate_klass(intptr_t k) {69Klass* v = TypeEntries::valid_klass(k);70if (v != NULL) {71ciKlass* klass = CURRENT_ENV->get_klass(v);72return with_status(klass, k);73}74return with_status(NULL, k);75}7677public:78static ciKlass* valid_ciklass(intptr_t k) {79if (!TypeEntries::is_type_none(k) &&80!TypeEntries::is_type_unknown(k)) {81ciKlass* res = (ciKlass*)TypeEntries::klass_part(k);82assert(res != NULL, "invalid");83return res;84} else {85return NULL;86}87}8889static ProfilePtrKind ptr_kind(intptr_t v) {90bool maybe_null = TypeEntries::was_null_seen(v);91if (!maybe_null) {92return ProfileNeverNull;93} else if (TypeEntries::is_type_none(v)) {94return ProfileAlwaysNull;95} else {96return ProfileMaybeNull;97}98}99100static intptr_t with_status(ciKlass* k, intptr_t in) {101return TypeEntries::with_status((intptr_t)k, in);102}103104#ifndef PRODUCT105static void print_ciklass(outputStream* st, intptr_t k);106#endif107};108109class ciTypeStackSlotEntries : public TypeStackSlotEntries, ciTypeEntries {110public:111void translate_type_data_from(const TypeStackSlotEntries* args);112113ciKlass* valid_type(int i) const {114return valid_ciklass(type(i));115}116117ProfilePtrKind ptr_kind(int i) const {118return ciTypeEntries::ptr_kind(type(i));119}120121#ifndef PRODUCT122void print_data_on(outputStream* st) const;123#endif124};125126class ciReturnTypeEntry : public ReturnTypeEntry, ciTypeEntries {127public:128void translate_type_data_from(const ReturnTypeEntry* ret);129130ciKlass* valid_type() const {131return valid_ciklass(type());132}133134ProfilePtrKind ptr_kind() const {135return ciTypeEntries::ptr_kind(type());136}137138#ifndef PRODUCT139void print_data_on(outputStream* st) const;140#endif141};142143class ciCallTypeData : public CallTypeData {144public:145ciCallTypeData(DataLayout* layout) : CallTypeData(layout) {}146147ciTypeStackSlotEntries* args() const { return (ciTypeStackSlotEntries*)CallTypeData::args(); }148ciReturnTypeEntry* ret() const { return (ciReturnTypeEntry*)CallTypeData::ret(); }149150void translate_from(const ProfileData* data) {151if (has_arguments()) {152args()->translate_type_data_from(data->as_CallTypeData()->args());153}154if (has_return()) {155ret()->translate_type_data_from(data->as_CallTypeData()->ret());156}157}158159intptr_t argument_type(int i) const {160assert(has_arguments(), "no arg type profiling data");161return args()->type(i);162}163164ciKlass* valid_argument_type(int i) const {165assert(has_arguments(), "no arg type profiling data");166return args()->valid_type(i);167}168169intptr_t return_type() const {170assert(has_return(), "no ret type profiling data");171return ret()->type();172}173174ciKlass* valid_return_type() const {175assert(has_return(), "no ret type profiling data");176return ret()->valid_type();177}178179ProfilePtrKind argument_ptr_kind(int i) const {180return args()->ptr_kind(i);181}182183ProfilePtrKind return_ptr_kind() const {184return ret()->ptr_kind();185}186187#ifndef PRODUCT188void print_data_on(outputStream* st, const char* extra = NULL) const;189#endif190};191192class ciReceiverTypeData : public ReceiverTypeData {193public:194ciReceiverTypeData(DataLayout* layout) : ReceiverTypeData(layout) {};195196void set_receiver(uint row, ciKlass* recv) {197assert((uint)row < row_limit(), "oob");198set_intptr_at(receiver0_offset + row * receiver_type_row_cell_count,199(intptr_t) recv);200}201202ciKlass* receiver(uint row) const {203assert((uint)row < row_limit(), "oob");204ciKlass* recv = (ciKlass*)intptr_at(receiver0_offset + row * receiver_type_row_cell_count);205assert(recv == NULL || recv->is_klass(), "wrong type");206return recv;207}208209// Copy & translate from oop based ReceiverTypeData210virtual void translate_from(const ProfileData* data) {211translate_receiver_data_from(data);212}213void translate_receiver_data_from(const ProfileData* data);214#ifndef PRODUCT215void print_data_on(outputStream* st, const char* extra = NULL) const;216void print_receiver_data_on(outputStream* st) const;217#endif218};219220class ciVirtualCallData : public VirtualCallData {221// Fake multiple inheritance... It's a ciReceiverTypeData also.222ciReceiverTypeData* rtd_super() const { return (ciReceiverTypeData*) this; }223224public:225ciVirtualCallData(DataLayout* layout) : VirtualCallData(layout) {};226227void set_receiver(uint row, ciKlass* recv) {228rtd_super()->set_receiver(row, recv);229}230231ciKlass* receiver(uint row) {232return rtd_super()->receiver(row);233}234235// Copy & translate from oop based VirtualCallData236virtual void translate_from(const ProfileData* data) {237rtd_super()->translate_receiver_data_from(data);238}239#ifndef PRODUCT240void print_data_on(outputStream* st, const char* extra = NULL) const;241#endif242};243244class ciVirtualCallTypeData : public VirtualCallTypeData {245private:246// Fake multiple inheritance... It's a ciReceiverTypeData also.247ciReceiverTypeData* rtd_super() const { return (ciReceiverTypeData*) this; }248public:249ciVirtualCallTypeData(DataLayout* layout) : VirtualCallTypeData(layout) {}250251void set_receiver(uint row, ciKlass* recv) {252rtd_super()->set_receiver(row, recv);253}254255ciKlass* receiver(uint row) const {256return rtd_super()->receiver(row);257}258259ciTypeStackSlotEntries* args() const { return (ciTypeStackSlotEntries*)VirtualCallTypeData::args(); }260ciReturnTypeEntry* ret() const { return (ciReturnTypeEntry*)VirtualCallTypeData::ret(); }261262// Copy & translate from oop based VirtualCallData263virtual void translate_from(const ProfileData* data) {264rtd_super()->translate_receiver_data_from(data);265if (has_arguments()) {266args()->translate_type_data_from(data->as_VirtualCallTypeData()->args());267}268if (has_return()) {269ret()->translate_type_data_from(data->as_VirtualCallTypeData()->ret());270}271}272273ciKlass* valid_argument_type(int i) const {274assert(has_arguments(), "no arg type profiling data");275return args()->valid_type(i);276}277278intptr_t return_type() const {279assert(has_return(), "no ret type profiling data");280return ret()->type();281}282283ciKlass* valid_return_type() const {284assert(has_return(), "no ret type profiling data");285return ret()->valid_type();286}287288ProfilePtrKind argument_ptr_kind(int i) const {289return args()->ptr_kind(i);290}291292ProfilePtrKind return_ptr_kind() const {293return ret()->ptr_kind();294}295296#ifndef PRODUCT297void print_data_on(outputStream* st, const char* extra = NULL) const;298#endif299};300301302class ciRetData : public RetData {303public:304ciRetData(DataLayout* layout) : RetData(layout) {};305};306307class ciBranchData : public BranchData {308public:309ciBranchData(DataLayout* layout) : BranchData(layout) {};310};311312class ciMultiBranchData : public MultiBranchData {313public:314ciMultiBranchData(DataLayout* layout) : MultiBranchData(layout) {};315};316317class ciArgInfoData : public ArgInfoData {318public:319ciArgInfoData(DataLayout* layout) : ArgInfoData(layout) {};320};321322class ciParametersTypeData : public ParametersTypeData {323public:324ciParametersTypeData(DataLayout* layout) : ParametersTypeData(layout) {}325326virtual void translate_from(const ProfileData* data) {327parameters()->translate_type_data_from(data->as_ParametersTypeData()->parameters());328}329330ciTypeStackSlotEntries* parameters() const { return (ciTypeStackSlotEntries*)ParametersTypeData::parameters(); }331332ciKlass* valid_parameter_type(int i) const {333return parameters()->valid_type(i);334}335336ProfilePtrKind parameter_ptr_kind(int i) const {337return parameters()->ptr_kind(i);338}339340#ifndef PRODUCT341void print_data_on(outputStream* st, const char* extra = NULL) const;342#endif343};344345class ciSpeculativeTrapData : public SpeculativeTrapData {346public:347ciSpeculativeTrapData(DataLayout* layout) : SpeculativeTrapData(layout) {}348349virtual void translate_from(const ProfileData* data);350351ciMethod* method() const {352return (ciMethod*)intptr_at(speculative_trap_method);353}354355void set_method(ciMethod* m) {356set_intptr_at(speculative_trap_method, (intptr_t)m);357}358359#ifndef PRODUCT360void print_data_on(outputStream* st, const char* extra = NULL) const;361#endif362};363364// ciMethodData365//366// This class represents a MethodData* in the HotSpot virtual367// machine.368369class ciMethodData : public ciMetadata {370CI_PACKAGE_ACCESS371friend class ciReplay;372373private:374// Size in bytes375int _data_size;376int _extra_data_size;377378// Data entries379intptr_t* _data;380381// Cached hint for data_layout_before()382int _hint_di;383384// Is data attached? And is it mature?385enum { empty_state, immature_state, mature_state };386u_char _state;387388// Set this true if empty extra_data slots are ever witnessed.389u_char _saw_free_extra_data;390391// Support for interprocedural escape analysis392intx _eflags; // flags on escape information393intx _arg_local; // bit set of non-escaping arguments394intx _arg_stack; // bit set of stack-allocatable arguments395intx _arg_returned; // bit set of returned arguments396397int _creation_mileage; // method mileage at MDO creation398399// Maturity of the oop when the snapshot is taken.400int _current_mileage;401402// These counters hold the age of MDO in tiered. In tiered we can have the same method403// running at different compilation levels concurrently. So, in order to precisely measure404// its maturity we need separate counters.405int _invocation_counter;406int _backedge_counter;407408// Coherent snapshot of original header.409MethodData::CompilerCounters _orig;410411// Area dedicated to parameters. NULL if no parameter profiling for this method.412DataLayout* _parameters;413int parameters_size() const {414return _parameters == NULL ? 0 : parameters_type_data()->size_in_bytes();415}416417ciMethodData(MethodData* md = NULL);418419// Accessors420int data_size() const { return _data_size; }421int extra_data_size() const { return _extra_data_size; }422intptr_t * data() const { return _data; }423424MethodData* get_MethodData() const {425return (MethodData*)_metadata;426}427428const char* type_string() { return "ciMethodData"; }429430void print_impl(outputStream* st);431432DataLayout* data_layout_at(int data_index) const {433assert(data_index % sizeof(intptr_t) == 0, "unaligned");434return (DataLayout*) (((address)_data) + data_index);435}436437bool out_of_bounds(int data_index) {438return data_index >= data_size();439}440441// hint accessors442int hint_di() const { return _hint_di; }443void set_hint_di(int di) {444assert(!out_of_bounds(di), "hint_di out of bounds");445_hint_di = di;446}447448DataLayout* data_layout_before(int bci) {449// avoid SEGV on this edge case450if (data_size() == 0)451return NULL;452DataLayout* layout = data_layout_at(hint_di());453if (layout->bci() <= bci)454return layout;455return data_layout_at(first_di());456}457458// What is the index of the first data entry?459int first_di() { return 0; }460461ciArgInfoData *arg_info() const;462463void prepare_metadata();464void load_remaining_extra_data();465ciProfileData* bci_to_extra_data(int bci, ciMethod* m, bool& two_free_slots);466467void dump_replay_data_type_helper(outputStream* out, int round, int& count, ProfileData* pdata, ByteSize offset, ciKlass* k);468template<class T> void dump_replay_data_call_type_helper(outputStream* out, int round, int& count, T* call_type_data);469template<class T> void dump_replay_data_receiver_type_helper(outputStream* out, int round, int& count, T* call_type_data);470void dump_replay_data_extra_data_helper(outputStream* out, int round, int& count);471ciProfileData* data_from(DataLayout* data_layout);472473public:474bool is_method_data() const { return true; }475476bool is_empty() { return _state == empty_state; }477bool is_mature() { return _state == mature_state; }478479int creation_mileage() { return _creation_mileage; }480int current_mileage() { return _current_mileage; }481482int invocation_count() { return _invocation_counter; }483int backedge_count() { return _backedge_counter; }484485#if INCLUDE_RTM_OPT486// return cached value487int rtm_state() {488if (is_empty()) {489return NoRTM;490} else {491return get_MethodData()->rtm_state();492}493}494#endif495496// Transfer information about the method to MethodData*.497// would_profile means we would like to profile this method,498// meaning it's not trivial.499void set_would_profile(bool p);500// Also set the numer of loops and blocks in the method.501// Again, this is used to determine if a method is trivial.502void set_compilation_stats(short loops, short blocks);503// If the compiler finds a profiled type that is known statically504// for sure, set it in the MethodData505void set_argument_type(int bci, int i, ciKlass* k);506void set_parameter_type(int i, ciKlass* k);507void set_return_type(int bci, ciKlass* k);508509bool load_data();510511// Convert a dp (data pointer) to a di (data index).512int dp_to_di(address dp) {513return dp - ((address)_data);514}515516// Get the data at an arbitrary (sort of) data index.517ciProfileData* data_at(int data_index);518519// Walk through the data in order.520ciProfileData* first_data() { return data_at(first_di()); }521ciProfileData* next_data(ciProfileData* current);522DataLayout* next_data_layout(DataLayout* current);523bool is_valid(ciProfileData* current) { return current != NULL; }524bool is_valid(DataLayout* current) { return current != NULL; }525526DataLayout* extra_data_base() const { return data_layout_at(data_size()); }527DataLayout* args_data_limit() const { return data_layout_at(data_size() + extra_data_size() -528parameters_size()); }529530// Get the data at an arbitrary bci, or NULL if there is none. If m531// is not NULL look for a SpeculativeTrapData if any first.532ciProfileData* bci_to_data(int bci, ciMethod* m = NULL);533534uint overflow_trap_count() const {535return _orig.overflow_trap_count();536}537uint overflow_recompile_count() const {538return _orig.overflow_recompile_count();539}540uint decompile_count() const {541return _orig.decompile_count();542}543uint trap_count(int reason) const {544return _orig.trap_count(reason);545}546uint trap_reason_limit() const { return MethodData::trap_reason_limit(); }547uint trap_count_limit() const { return MethodData::trap_count_limit(); }548549// Helpful query functions that decode trap_state.550int has_trap_at(ciProfileData* data, int reason);551int has_trap_at(int bci, ciMethod* m, int reason) {552assert((m != NULL) == Deoptimization::reason_is_speculate(reason), "inconsistent method/reason");553return has_trap_at(bci_to_data(bci, m), reason);554}555int trap_recompiled_at(ciProfileData* data);556int trap_recompiled_at(int bci, ciMethod* m) {557return trap_recompiled_at(bci_to_data(bci, m));558}559560void clear_escape_info();561bool has_escape_info();562void update_escape_info();563564void set_eflag(MethodData::EscapeFlag f);565bool eflag_set(MethodData::EscapeFlag f) const;566567void set_arg_local(int i);568void set_arg_stack(int i);569void set_arg_returned(int i);570void set_arg_modified(int arg, uint val);571572bool is_arg_local(int i) const;573bool is_arg_stack(int i) const;574bool is_arg_returned(int i) const;575uint arg_modified(int arg) const;576577ciParametersTypeData* parameters_type_data() const {578return _parameters != NULL ? new ciParametersTypeData(_parameters) : NULL;579}580581// Code generation helper582ByteSize offset_of_slot(ciProfileData* data, ByteSize slot_offset_in_data);583int byte_offset_of_slot(ciProfileData* data, ByteSize slot_offset_in_data) { return in_bytes(offset_of_slot(data, slot_offset_in_data)); }584585#ifndef PRODUCT586// printing support for method data587void print();588void print_data_on(outputStream* st);589#endif590void dump_replay_data(outputStream* out);591};592593#endif // SHARE_CI_CIMETHODDATA_HPP594595596