Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/ci/ciMethodData.hpp
32285 views
/*1* Copyright (c) 2001, 2013, 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_VM_CI_CIMETHODDATA_HPP25#define SHARE_VM_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.inline.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);72CURRENT_ENV->ensure_metadata_alive(klass);73return with_status(klass, k);74}75return with_status(NULL, k);76}7778public:79static ciKlass* valid_ciklass(intptr_t k) {80if (!TypeEntries::is_type_none(k) &&81!TypeEntries::is_type_unknown(k)) {82ciKlass* res = (ciKlass*)TypeEntries::klass_part(k);83assert(res != NULL, "invalid");84return res;85} else {86return NULL;87}88}8990static intptr_t with_status(ciKlass* k, intptr_t in) {91return TypeEntries::with_status((intptr_t)k, in);92}9394#ifndef PRODUCT95static void print_ciklass(outputStream* st, intptr_t k);96#endif97};9899class ciTypeStackSlotEntries : public TypeStackSlotEntries, ciTypeEntries {100public:101void translate_type_data_from(const TypeStackSlotEntries* args);102103ciKlass* valid_type(int i) const {104return valid_ciklass(type(i));105}106107bool maybe_null(int i) const {108return was_null_seen(type(i));109}110111#ifndef PRODUCT112void print_data_on(outputStream* st) const;113#endif114};115116class ciReturnTypeEntry : public ReturnTypeEntry, ciTypeEntries {117public:118void translate_type_data_from(const ReturnTypeEntry* ret);119120ciKlass* valid_type() const {121return valid_ciklass(type());122}123124bool maybe_null() const {125return was_null_seen(type());126}127128#ifndef PRODUCT129void print_data_on(outputStream* st) const;130#endif131};132133class ciCallTypeData : public CallTypeData {134public:135ciCallTypeData(DataLayout* layout) : CallTypeData(layout) {}136137ciTypeStackSlotEntries* args() const { return (ciTypeStackSlotEntries*)CallTypeData::args(); }138ciReturnTypeEntry* ret() const { return (ciReturnTypeEntry*)CallTypeData::ret(); }139140void translate_from(const ProfileData* data) {141if (has_arguments()) {142args()->translate_type_data_from(data->as_CallTypeData()->args());143}144if (has_return()) {145ret()->translate_type_data_from(data->as_CallTypeData()->ret());146}147}148149intptr_t argument_type(int i) const {150assert(has_arguments(), "no arg type profiling data");151return args()->type(i);152}153154ciKlass* valid_argument_type(int i) const {155assert(has_arguments(), "no arg type profiling data");156return args()->valid_type(i);157}158159intptr_t return_type() const {160assert(has_return(), "no ret type profiling data");161return ret()->type();162}163164ciKlass* valid_return_type() const {165assert(has_return(), "no ret type profiling data");166return ret()->valid_type();167}168169bool argument_maybe_null(int i) const {170return args()->maybe_null(i);171}172173bool return_maybe_null() const {174return ret()->maybe_null();175}176177#ifndef PRODUCT178void print_data_on(outputStream* st, const char* extra) const;179#endif180};181182class ciReceiverTypeData : public ReceiverTypeData {183public:184ciReceiverTypeData(DataLayout* layout) : ReceiverTypeData(layout) {};185186void set_receiver(uint row, ciKlass* recv) {187assert((uint)row < row_limit(), "oob");188set_intptr_at(receiver0_offset + row * receiver_type_row_cell_count,189(intptr_t) recv);190}191192ciKlass* receiver(uint row) const {193assert((uint)row < row_limit(), "oob");194ciKlass* recv = (ciKlass*)intptr_at(receiver0_offset + row * receiver_type_row_cell_count);195assert(recv == NULL || recv->is_klass(), "wrong type");196return recv;197}198199// Copy & translate from oop based ReceiverTypeData200virtual void translate_from(const ProfileData* data) {201translate_receiver_data_from(data);202}203void translate_receiver_data_from(const ProfileData* data);204#ifndef PRODUCT205void print_data_on(outputStream* st, const char* extra) const;206void print_receiver_data_on(outputStream* st) const;207#endif208};209210class ciVirtualCallData : public VirtualCallData {211// Fake multiple inheritance... It's a ciReceiverTypeData also.212ciReceiverTypeData* rtd_super() const { return (ciReceiverTypeData*) this; }213214public:215ciVirtualCallData(DataLayout* layout) : VirtualCallData(layout) {};216217void set_receiver(uint row, ciKlass* recv) {218rtd_super()->set_receiver(row, recv);219}220221ciKlass* receiver(uint row) {222return rtd_super()->receiver(row);223}224225// Copy & translate from oop based VirtualCallData226virtual void translate_from(const ProfileData* data) {227rtd_super()->translate_receiver_data_from(data);228}229#ifndef PRODUCT230void print_data_on(outputStream* st, const char* extra) const;231#endif232};233234class ciVirtualCallTypeData : public VirtualCallTypeData {235private:236// Fake multiple inheritance... It's a ciReceiverTypeData also.237ciReceiverTypeData* rtd_super() const { return (ciReceiverTypeData*) this; }238public:239ciVirtualCallTypeData(DataLayout* layout) : VirtualCallTypeData(layout) {}240241void set_receiver(uint row, ciKlass* recv) {242rtd_super()->set_receiver(row, recv);243}244245ciKlass* receiver(uint row) const {246return rtd_super()->receiver(row);247}248249ciTypeStackSlotEntries* args() const { return (ciTypeStackSlotEntries*)VirtualCallTypeData::args(); }250ciReturnTypeEntry* ret() const { return (ciReturnTypeEntry*)VirtualCallTypeData::ret(); }251252// Copy & translate from oop based VirtualCallData253virtual void translate_from(const ProfileData* data) {254rtd_super()->translate_receiver_data_from(data);255if (has_arguments()) {256args()->translate_type_data_from(data->as_VirtualCallTypeData()->args());257}258if (has_return()) {259ret()->translate_type_data_from(data->as_VirtualCallTypeData()->ret());260}261}262263intptr_t argument_type(int i) const {264assert(has_arguments(), "no arg type profiling data");265return args()->type(i);266}267268ciKlass* valid_argument_type(int i) const {269assert(has_arguments(), "no arg type profiling data");270return args()->valid_type(i);271}272273intptr_t return_type() const {274assert(has_return(), "no ret type profiling data");275return ret()->type();276}277278ciKlass* valid_return_type() const {279assert(has_return(), "no ret type profiling data");280return ret()->valid_type();281}282283bool argument_maybe_null(int i) const {284return args()->maybe_null(i);285}286287bool return_maybe_null() const {288return ret()->maybe_null();289}290291#ifndef PRODUCT292void print_data_on(outputStream* st, const char* extra) const;293#endif294};295296297class ciRetData : public RetData {298public:299ciRetData(DataLayout* layout) : RetData(layout) {};300};301302class ciBranchData : public BranchData {303public:304ciBranchData(DataLayout* layout) : BranchData(layout) {};305};306307class ciArrayData : public ArrayData {308public:309ciArrayData(DataLayout* layout) : ArrayData(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}335336bool parameter_maybe_null(int i) const {337return parameters()->maybe_null(i);338}339340#ifndef PRODUCT341void print_data_on(outputStream* st, const char* extra) 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(method_offset);353}354355void set_method(ciMethod* m) {356set_intptr_at(method_offset, (intptr_t)m);357}358359#ifndef PRODUCT360void print_data_on(outputStream* st, const char* extra) 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_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 arguments396397// Maturity of the oop when the snapshot is taken.398int _current_mileage;399400// These counters hold the age of MDO in tiered. In tiered we can have the same method401// running at different compilation levels concurrently. So, in order to precisely measure402// its maturity we need separate counters.403int _invocation_counter;404int _backedge_counter;405406// Coherent snapshot of original header.407MethodData _orig;408409// Dedicated area dedicated to parameters. Null if no parameter410// profiling for this method.411DataLayout* _parameters;412413ciMethodData(MethodData* md);414ciMethodData();415416// Accessors417int data_size() const { return _data_size; }418int extra_data_size() const { return _extra_data_size; }419intptr_t * data() const { return _data; }420421MethodData* get_MethodData() const {422return (MethodData*)_metadata;423}424425const char* type_string() { return "ciMethodData"; }426427void print_impl(outputStream* st);428429DataLayout* data_layout_at(int data_index) const {430assert(data_index % sizeof(intptr_t) == 0, "unaligned");431return (DataLayout*) (((address)_data) + data_index);432}433434bool out_of_bounds(int data_index) {435return data_index >= data_size();436}437438// hint accessors439int hint_di() const { return _hint_di; }440void set_hint_di(int di) {441assert(!out_of_bounds(di), "hint_di out of bounds");442_hint_di = di;443}444ciProfileData* data_before(int bci) {445// avoid SEGV on this edge case446if (data_size() == 0)447return NULL;448int hint = hint_di();449if (data_layout_at(hint)->bci() <= bci)450return data_at(hint);451return first_data();452}453454455// What is the index of the first data entry?456int first_di() { return 0; }457458ciArgInfoData *arg_info() const;459460address data_base() const {461return (address) _data;462}463DataLayout* limit_data_position() const {464return (DataLayout*)((address)data_base() + _data_size);465}466467void load_extra_data();468ciProfileData* bci_to_extra_data(int bci, ciMethod* m, bool& two_free_slots);469470public:471bool is_method_data() const { return true; }472473bool is_empty() { return _state == empty_state; }474bool is_mature() { return _state == mature_state; }475476int creation_mileage() { return _orig.creation_mileage(); }477int current_mileage() { return _current_mileage; }478479int invocation_count() { return _invocation_counter; }480int backedge_count() { return _backedge_counter; }481482#if INCLUDE_RTM_OPT483// return cached value484int rtm_state() {485if (is_empty()) {486return NoRTM;487} else {488return get_MethodData()->rtm_state();489}490}491#endif492493// Transfer information about the method to MethodData*.494// would_profile means we would like to profile this method,495// meaning it's not trivial.496void set_would_profile(bool p);497// Also set the numer of loops and blocks in the method.498// Again, this is used to determine if a method is trivial.499void set_compilation_stats(short loops, short blocks);500// If the compiler finds a profiled type that is known statically501// for sure, set it in the MethodData502void set_argument_type(int bci, int i, ciKlass* k);503void set_parameter_type(int i, ciKlass* k);504void set_return_type(int bci, ciKlass* k);505506void load_data();507508// Convert a dp (data pointer) to a di (data index).509int dp_to_di(address dp) {510return dp - ((address)_data);511}512513// Get the data at an arbitrary (sort of) data index.514ciProfileData* data_at(int data_index);515516// Walk through the data in order.517ciProfileData* first_data() { return data_at(first_di()); }518ciProfileData* next_data(ciProfileData* current);519bool is_valid(ciProfileData* current) { return current != NULL; }520521DataLayout* extra_data_base() const { return limit_data_position(); }522523// Get the data at an arbitrary bci, or NULL if there is none. If m524// is not NULL look for a SpeculativeTrapData if any first.525ciProfileData* bci_to_data(int bci, ciMethod* m = NULL);526527uint overflow_trap_count() const {528return _orig.overflow_trap_count();529}530uint overflow_recompile_count() const {531return _orig.overflow_recompile_count();532}533uint decompile_count() const {534return _orig.decompile_count();535}536uint trap_count(int reason) const {537return _orig.trap_count(reason);538}539uint trap_reason_limit() const { return _orig.trap_reason_limit(); }540uint trap_count_limit() const { return _orig.trap_count_limit(); }541542// Helpful query functions that decode trap_state.543int has_trap_at(ciProfileData* data, int reason);544int has_trap_at(int bci, ciMethod* m, int reason) {545assert((m != NULL) == Deoptimization::reason_is_speculate(reason), "inconsistent method/reason");546return has_trap_at(bci_to_data(bci, m), reason);547}548int trap_recompiled_at(ciProfileData* data);549int trap_recompiled_at(int bci, ciMethod* m) {550return trap_recompiled_at(bci_to_data(bci, m));551}552553void clear_escape_info();554bool has_escape_info();555void update_escape_info();556557void set_eflag(MethodData::EscapeFlag f);558void clear_eflag(MethodData::EscapeFlag f);559bool eflag_set(MethodData::EscapeFlag f) const;560561void set_arg_local(int i);562void set_arg_stack(int i);563void set_arg_returned(int i);564void set_arg_modified(int arg, uint val);565566bool is_arg_local(int i) const;567bool is_arg_stack(int i) const;568bool is_arg_returned(int i) const;569uint arg_modified(int arg) const;570571ciParametersTypeData* parameters_type_data() const {572return _parameters != NULL ? new ciParametersTypeData(_parameters) : NULL;573}574575// Code generation helper576ByteSize offset_of_slot(ciProfileData* data, ByteSize slot_offset_in_data);577int byte_offset_of_slot(ciProfileData* data, ByteSize slot_offset_in_data) { return in_bytes(offset_of_slot(data, slot_offset_in_data)); }578579#ifndef PRODUCT580// printing support for method data581void print();582void print_data_on(outputStream* st);583#endif584void dump_replay_data(outputStream* out);585};586587#endif // SHARE_VM_CI_CIMETHODDATA_HPP588589590