aoqi@0: /* aoqi@0: * Copyright (c) 2000, 2013, 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: #ifndef SHARE_VM_OOPS_METHODDATAOOP_HPP aoqi@0: #define SHARE_VM_OOPS_METHODDATAOOP_HPP aoqi@0: aoqi@0: #include "interpreter/bytecodes.hpp" aoqi@0: #include "memory/universe.hpp" aoqi@0: #include "oops/method.hpp" aoqi@0: #include "oops/oop.hpp" aoqi@0: #include "runtime/orderAccess.hpp" aoqi@0: aoqi@0: class BytecodeStream; aoqi@0: class KlassSizeStats; aoqi@0: aoqi@0: // The MethodData object collects counts and other profile information aoqi@0: // during zeroth-tier (interpretive) and first-tier execution. aoqi@0: // The profile is used later by compilation heuristics. Some heuristics aoqi@0: // enable use of aggressive (or "heroic") optimizations. An aggressive aoqi@0: // optimization often has a down-side, a corner case that it handles aoqi@0: // poorly, but which is thought to be rare. The profile provides aoqi@0: // evidence of this rarity for a given method or even BCI. It allows aoqi@0: // the compiler to back out of the optimization at places where it aoqi@0: // has historically been a poor choice. Other heuristics try to use aoqi@0: // specific information gathered about types observed at a given site. aoqi@0: // aoqi@0: // All data in the profile is approximate. It is expected to be accurate aoqi@0: // on the whole, but the system expects occasional inaccuraces, due to aoqi@0: // counter overflow, multiprocessor races during data collection, space aoqi@0: // limitations, missing MDO blocks, etc. Bad or missing data will degrade aoqi@0: // optimization quality but will not affect correctness. Also, each MDO aoqi@0: // is marked with its birth-date ("creation_mileage") which can be used aoqi@0: // to assess the quality ("maturity") of its data. aoqi@0: // aoqi@0: // Short (<32-bit) counters are designed to overflow to a known "saturated" aoqi@0: // state. Also, certain recorded per-BCI events are given one-bit counters aoqi@0: // which overflow to a saturated state which applied to all counters at aoqi@0: // that BCI. In other words, there is a small lattice which approximates aoqi@0: // the ideal of an infinite-precision counter for each event at each BCI, aoqi@0: // and the lattice quickly "bottoms out" in a state where all counters aoqi@0: // are taken to be indefinitely large. aoqi@0: // aoqi@0: // The reader will find many data races in profile gathering code, starting aoqi@0: // with invocation counter incrementation. None of these races harm correct aoqi@0: // execution of the compiled code. aoqi@0: aoqi@0: // forward decl aoqi@0: class ProfileData; aoqi@0: aoqi@0: // DataLayout aoqi@0: // aoqi@0: // Overlay for generic profiling data. aoqi@0: class DataLayout VALUE_OBJ_CLASS_SPEC { aoqi@0: friend class VMStructs; aoqi@0: aoqi@0: private: aoqi@0: // Every data layout begins with a header. This header aoqi@0: // contains a tag, which is used to indicate the size/layout aoqi@0: // of the data, 4 bits of flags, which can be used in any way, aoqi@0: // 4 bits of trap history (none/one reason/many reasons), aoqi@0: // and a bci, which is used to tie this piece of data to a aoqi@0: // specific bci in the bytecodes. aoqi@0: union { aoqi@0: intptr_t _bits; aoqi@0: struct { aoqi@0: u1 _tag; aoqi@0: u1 _flags; aoqi@0: u2 _bci; aoqi@0: } _struct; aoqi@0: } _header; aoqi@0: aoqi@0: // The data layout has an arbitrary number of cells, each sized aoqi@0: // to accomodate a pointer or an integer. aoqi@0: intptr_t _cells[1]; aoqi@0: aoqi@0: // Some types of data layouts need a length field. aoqi@0: static bool needs_array_len(u1 tag); aoqi@0: aoqi@0: public: aoqi@0: enum { aoqi@0: counter_increment = 1 aoqi@0: }; aoqi@0: aoqi@0: enum { aoqi@0: cell_size = sizeof(intptr_t) aoqi@0: }; aoqi@0: aoqi@0: // Tag values aoqi@0: enum { aoqi@0: no_tag, aoqi@0: bit_data_tag, aoqi@0: counter_data_tag, aoqi@0: jump_data_tag, aoqi@0: receiver_type_data_tag, aoqi@0: virtual_call_data_tag, aoqi@0: ret_data_tag, aoqi@0: branch_data_tag, aoqi@0: multi_branch_data_tag, aoqi@0: arg_info_data_tag, aoqi@0: call_type_data_tag, aoqi@0: virtual_call_type_data_tag, aoqi@0: parameters_type_data_tag, aoqi@0: speculative_trap_data_tag aoqi@0: }; aoqi@0: aoqi@0: enum { aoqi@0: // The _struct._flags word is formatted as [trap_state:4 | flags:4]. aoqi@0: // The trap state breaks down further as [recompile:1 | reason:3]. aoqi@0: // This further breakdown is defined in deoptimization.cpp. aoqi@0: // See Deoptimization::trap_state_reason for an assert that aoqi@0: // trap_bits is big enough to hold reasons < Reason_RECORDED_LIMIT. aoqi@0: // aoqi@0: // The trap_state is collected only if ProfileTraps is true. aoqi@0: trap_bits = 1+3, // 3: enough to distinguish [0..Reason_RECORDED_LIMIT]. aoqi@0: trap_shift = BitsPerByte - trap_bits, aoqi@0: trap_mask = right_n_bits(trap_bits), aoqi@0: trap_mask_in_place = (trap_mask << trap_shift), aoqi@0: flag_limit = trap_shift, aoqi@0: flag_mask = right_n_bits(flag_limit), aoqi@0: first_flag = 0 aoqi@0: }; aoqi@0: aoqi@0: // Size computation aoqi@0: static int header_size_in_bytes() { aoqi@0: return cell_size; aoqi@0: } aoqi@0: static int header_size_in_cells() { aoqi@0: return 1; aoqi@0: } aoqi@0: aoqi@0: static int compute_size_in_bytes(int cell_count) { aoqi@0: return header_size_in_bytes() + cell_count * cell_size; aoqi@0: } aoqi@0: aoqi@0: // Initialization aoqi@0: void initialize(u1 tag, u2 bci, int cell_count); aoqi@0: aoqi@0: // Accessors aoqi@0: u1 tag() { aoqi@0: return _header._struct._tag; aoqi@0: } aoqi@0: aoqi@0: // Return a few bits of trap state. Range is [0..trap_mask]. aoqi@0: // The state tells if traps with zero, one, or many reasons have occurred. aoqi@0: // It also tells whether zero or many recompilations have occurred. aoqi@0: // The associated trap histogram in the MDO itself tells whether aoqi@0: // traps are common or not. If a BCI shows that a trap X has aoqi@0: // occurred, and the MDO shows N occurrences of X, we make the aoqi@0: // simplifying assumption that all N occurrences can be blamed aoqi@0: // on that BCI. aoqi@0: int trap_state() const { aoqi@0: return ((_header._struct._flags >> trap_shift) & trap_mask); aoqi@0: } aoqi@0: aoqi@0: void set_trap_state(int new_state) { aoqi@0: assert(ProfileTraps, "used only under +ProfileTraps"); aoqi@0: uint old_flags = (_header._struct._flags & flag_mask); aoqi@0: _header._struct._flags = (new_state << trap_shift) | old_flags; aoqi@0: } aoqi@0: aoqi@0: u1 flags() const { aoqi@0: return _header._struct._flags; aoqi@0: } aoqi@0: aoqi@0: u2 bci() const { aoqi@0: return _header._struct._bci; aoqi@0: } aoqi@0: aoqi@0: void set_header(intptr_t value) { aoqi@0: _header._bits = value; aoqi@0: } aoqi@0: intptr_t header() { aoqi@0: return _header._bits; aoqi@0: } aoqi@0: void set_cell_at(int index, intptr_t value) { aoqi@0: _cells[index] = value; aoqi@0: } aoqi@0: void release_set_cell_at(int index, intptr_t value) { aoqi@0: OrderAccess::release_store_ptr(&_cells[index], value); aoqi@0: } aoqi@0: intptr_t cell_at(int index) const { aoqi@0: return _cells[index]; aoqi@0: } aoqi@0: aoqi@0: void set_flag_at(int flag_number) { aoqi@0: assert(flag_number < flag_limit, "oob"); aoqi@0: _header._struct._flags |= (0x1 << flag_number); aoqi@0: } aoqi@0: bool flag_at(int flag_number) const { aoqi@0: assert(flag_number < flag_limit, "oob"); aoqi@0: return (_header._struct._flags & (0x1 << flag_number)) != 0; aoqi@0: } aoqi@0: aoqi@0: // Low-level support for code generation. aoqi@0: static ByteSize header_offset() { aoqi@0: return byte_offset_of(DataLayout, _header); aoqi@0: } aoqi@0: static ByteSize tag_offset() { aoqi@0: return byte_offset_of(DataLayout, _header._struct._tag); aoqi@0: } aoqi@0: static ByteSize flags_offset() { aoqi@0: return byte_offset_of(DataLayout, _header._struct._flags); aoqi@0: } aoqi@0: static ByteSize bci_offset() { aoqi@0: return byte_offset_of(DataLayout, _header._struct._bci); aoqi@0: } aoqi@0: static ByteSize cell_offset(int index) { aoqi@0: return byte_offset_of(DataLayout, _cells) + in_ByteSize(index * cell_size); aoqi@0: } aoqi@0: #ifdef CC_INTERP aoqi@0: static int cell_offset_in_bytes(int index) { aoqi@0: return (int)offset_of(DataLayout, _cells[index]); aoqi@0: } aoqi@0: #endif // CC_INTERP aoqi@0: // Return a value which, when or-ed as a byte into _flags, sets the flag. aoqi@0: static int flag_number_to_byte_constant(int flag_number) { aoqi@0: assert(0 <= flag_number && flag_number < flag_limit, "oob"); aoqi@0: DataLayout temp; temp.set_header(0); aoqi@0: temp.set_flag_at(flag_number); aoqi@0: return temp._header._struct._flags; aoqi@0: } aoqi@0: // Return a value which, when or-ed as a word into _header, sets the flag. aoqi@0: static intptr_t flag_mask_to_header_mask(int byte_constant) { aoqi@0: DataLayout temp; temp.set_header(0); aoqi@0: temp._header._struct._flags = byte_constant; aoqi@0: return temp._header._bits; aoqi@0: } aoqi@0: aoqi@0: ProfileData* data_in(); aoqi@0: aoqi@0: // GC support aoqi@0: void clean_weak_klass_links(BoolObjectClosure* cl); roland@9183: roland@9183: // Redefinition support roland@9183: void clean_weak_method_links(); aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: // ProfileData class hierarchy aoqi@0: class ProfileData; aoqi@0: class BitData; aoqi@0: class CounterData; aoqi@0: class ReceiverTypeData; aoqi@0: class VirtualCallData; aoqi@0: class VirtualCallTypeData; aoqi@0: class RetData; aoqi@0: class CallTypeData; aoqi@0: class JumpData; aoqi@0: class BranchData; aoqi@0: class ArrayData; aoqi@0: class MultiBranchData; aoqi@0: class ArgInfoData; aoqi@0: class ParametersTypeData; aoqi@0: class SpeculativeTrapData; 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: class ProfileData : public ResourceObj { aoqi@0: friend class TypeEntries; aoqi@0: friend class ReturnTypeEntry; aoqi@0: friend class TypeStackSlotEntries; aoqi@0: private: aoqi@0: #ifndef PRODUCT aoqi@0: enum { aoqi@0: tab_width_one = 16, aoqi@0: tab_width_two = 36 aoqi@0: }; aoqi@0: #endif // !PRODUCT aoqi@0: aoqi@0: // This is a pointer to a section of profiling data. aoqi@0: DataLayout* _data; aoqi@0: aoqi@0: char* print_data_on_helper(const MethodData* md) const; aoqi@0: aoqi@0: protected: aoqi@0: DataLayout* data() { return _data; } aoqi@0: const DataLayout* data() const { return _data; } aoqi@0: aoqi@0: enum { aoqi@0: cell_size = DataLayout::cell_size aoqi@0: }; aoqi@0: aoqi@0: public: aoqi@0: // How many cells are in this? aoqi@0: virtual int cell_count() const { aoqi@0: ShouldNotReachHere(); aoqi@0: return -1; aoqi@0: } aoqi@0: aoqi@0: // Return the size of this data. aoqi@0: int size_in_bytes() { aoqi@0: return DataLayout::compute_size_in_bytes(cell_count()); aoqi@0: } aoqi@0: aoqi@0: protected: aoqi@0: // Low-level accessors for underlying data aoqi@0: void set_intptr_at(int index, intptr_t value) { aoqi@0: assert(0 <= index && index < cell_count(), "oob"); aoqi@0: data()->set_cell_at(index, value); aoqi@0: } aoqi@0: void release_set_intptr_at(int index, intptr_t value) { aoqi@0: assert(0 <= index && index < cell_count(), "oob"); aoqi@0: data()->release_set_cell_at(index, value); aoqi@0: } aoqi@0: intptr_t intptr_at(int index) const { aoqi@0: assert(0 <= index && index < cell_count(), "oob"); aoqi@0: return data()->cell_at(index); aoqi@0: } aoqi@0: void set_uint_at(int index, uint value) { aoqi@0: set_intptr_at(index, (intptr_t) value); aoqi@0: } aoqi@0: void release_set_uint_at(int index, uint value) { aoqi@0: release_set_intptr_at(index, (intptr_t) value); aoqi@0: } aoqi@0: uint uint_at(int index) const { aoqi@0: return (uint)intptr_at(index); aoqi@0: } aoqi@0: void set_int_at(int index, int value) { aoqi@0: set_intptr_at(index, (intptr_t) value); aoqi@0: } aoqi@0: void release_set_int_at(int index, int value) { aoqi@0: release_set_intptr_at(index, (intptr_t) value); aoqi@0: } aoqi@0: int int_at(int index) const { aoqi@0: return (int)intptr_at(index); aoqi@0: } aoqi@0: int int_at_unchecked(int index) const { aoqi@0: return (int)data()->cell_at(index); aoqi@0: } aoqi@0: void set_oop_at(int index, oop value) { aoqi@0: set_intptr_at(index, cast_from_oop(value)); aoqi@0: } aoqi@0: oop oop_at(int index) const { aoqi@0: return cast_to_oop(intptr_at(index)); aoqi@0: } aoqi@0: aoqi@0: void set_flag_at(int flag_number) { aoqi@0: data()->set_flag_at(flag_number); aoqi@0: } aoqi@0: bool flag_at(int flag_number) const { aoqi@0: return data()->flag_at(flag_number); aoqi@0: } aoqi@0: aoqi@0: // two convenient imports for use by subclasses: aoqi@0: static ByteSize cell_offset(int index) { aoqi@0: return DataLayout::cell_offset(index); aoqi@0: } aoqi@0: static int flag_number_to_byte_constant(int flag_number) { aoqi@0: return DataLayout::flag_number_to_byte_constant(flag_number); aoqi@0: } aoqi@0: aoqi@0: ProfileData(DataLayout* data) { aoqi@0: _data = data; aoqi@0: } aoqi@0: aoqi@0: #ifdef CC_INTERP aoqi@0: // Static low level accessors for DataLayout with ProfileData's semantics. aoqi@0: aoqi@0: static int cell_offset_in_bytes(int index) { aoqi@0: return DataLayout::cell_offset_in_bytes(index); aoqi@0: } aoqi@0: aoqi@0: static void increment_uint_at_no_overflow(DataLayout* layout, int index, aoqi@0: int inc = DataLayout::counter_increment) { aoqi@0: uint count = ((uint)layout->cell_at(index)) + inc; aoqi@0: if (count == 0) return; aoqi@0: layout->set_cell_at(index, (intptr_t) count); aoqi@0: } aoqi@0: aoqi@0: static int int_at(DataLayout* layout, int index) { aoqi@0: return (int)layout->cell_at(index); aoqi@0: } aoqi@0: aoqi@0: static int uint_at(DataLayout* layout, int index) { aoqi@0: return (uint)layout->cell_at(index); aoqi@0: } aoqi@0: aoqi@0: static oop oop_at(DataLayout* layout, int index) { aoqi@0: return cast_to_oop(layout->cell_at(index)); aoqi@0: } aoqi@0: aoqi@0: static void set_intptr_at(DataLayout* layout, int index, intptr_t value) { aoqi@0: layout->set_cell_at(index, (intptr_t) value); aoqi@0: } aoqi@0: aoqi@0: static void set_flag_at(DataLayout* layout, int flag_number) { aoqi@0: layout->set_flag_at(flag_number); aoqi@0: } aoqi@0: #endif // CC_INTERP aoqi@0: aoqi@0: public: aoqi@0: // Constructor for invalid ProfileData. aoqi@0: ProfileData(); aoqi@0: aoqi@0: u2 bci() const { aoqi@0: return data()->bci(); aoqi@0: } aoqi@0: aoqi@0: address dp() { aoqi@0: return (address)_data; aoqi@0: } aoqi@0: aoqi@0: int trap_state() const { aoqi@0: return data()->trap_state(); aoqi@0: } aoqi@0: void set_trap_state(int new_state) { aoqi@0: data()->set_trap_state(new_state); aoqi@0: } aoqi@0: aoqi@0: // Type checking aoqi@0: virtual bool is_BitData() const { return false; } aoqi@0: virtual bool is_CounterData() const { return false; } aoqi@0: virtual bool is_JumpData() const { return false; } aoqi@0: virtual bool is_ReceiverTypeData()const { return false; } aoqi@0: virtual bool is_VirtualCallData() const { return false; } aoqi@0: virtual bool is_RetData() const { return false; } aoqi@0: virtual bool is_BranchData() const { return false; } aoqi@0: virtual bool is_ArrayData() const { return false; } aoqi@0: virtual bool is_MultiBranchData() const { return false; } aoqi@0: virtual bool is_ArgInfoData() const { return false; } aoqi@0: virtual bool is_CallTypeData() const { return false; } aoqi@0: virtual bool is_VirtualCallTypeData()const { return false; } aoqi@0: virtual bool is_ParametersTypeData() const { return false; } aoqi@0: virtual bool is_SpeculativeTrapData()const { return false; } aoqi@0: aoqi@0: aoqi@0: BitData* as_BitData() const { aoqi@0: assert(is_BitData(), "wrong type"); aoqi@0: return is_BitData() ? (BitData*) this : NULL; aoqi@0: } aoqi@0: CounterData* as_CounterData() const { aoqi@0: assert(is_CounterData(), "wrong type"); aoqi@0: return is_CounterData() ? (CounterData*) this : NULL; aoqi@0: } aoqi@0: JumpData* as_JumpData() const { aoqi@0: assert(is_JumpData(), "wrong type"); aoqi@0: return is_JumpData() ? (JumpData*) this : NULL; aoqi@0: } aoqi@0: ReceiverTypeData* as_ReceiverTypeData() const { aoqi@0: assert(is_ReceiverTypeData(), "wrong type"); aoqi@0: return is_ReceiverTypeData() ? (ReceiverTypeData*)this : NULL; aoqi@0: } aoqi@0: VirtualCallData* as_VirtualCallData() const { aoqi@0: assert(is_VirtualCallData(), "wrong type"); aoqi@0: return is_VirtualCallData() ? (VirtualCallData*)this : NULL; aoqi@0: } aoqi@0: RetData* as_RetData() const { aoqi@0: assert(is_RetData(), "wrong type"); aoqi@0: return is_RetData() ? (RetData*) this : NULL; aoqi@0: } aoqi@0: BranchData* as_BranchData() const { aoqi@0: assert(is_BranchData(), "wrong type"); aoqi@0: return is_BranchData() ? (BranchData*) this : NULL; aoqi@0: } aoqi@0: ArrayData* as_ArrayData() const { aoqi@0: assert(is_ArrayData(), "wrong type"); aoqi@0: return is_ArrayData() ? (ArrayData*) this : NULL; aoqi@0: } aoqi@0: MultiBranchData* as_MultiBranchData() const { aoqi@0: assert(is_MultiBranchData(), "wrong type"); aoqi@0: return is_MultiBranchData() ? (MultiBranchData*)this : NULL; aoqi@0: } aoqi@0: ArgInfoData* as_ArgInfoData() const { aoqi@0: assert(is_ArgInfoData(), "wrong type"); aoqi@0: return is_ArgInfoData() ? (ArgInfoData*)this : NULL; aoqi@0: } aoqi@0: CallTypeData* as_CallTypeData() const { aoqi@0: assert(is_CallTypeData(), "wrong type"); aoqi@0: return is_CallTypeData() ? (CallTypeData*)this : NULL; aoqi@0: } aoqi@0: VirtualCallTypeData* as_VirtualCallTypeData() const { aoqi@0: assert(is_VirtualCallTypeData(), "wrong type"); aoqi@0: return is_VirtualCallTypeData() ? (VirtualCallTypeData*)this : NULL; aoqi@0: } aoqi@0: ParametersTypeData* as_ParametersTypeData() const { aoqi@0: assert(is_ParametersTypeData(), "wrong type"); aoqi@0: return is_ParametersTypeData() ? (ParametersTypeData*)this : NULL; aoqi@0: } aoqi@0: SpeculativeTrapData* as_SpeculativeTrapData() const { aoqi@0: assert(is_SpeculativeTrapData(), "wrong type"); aoqi@0: return is_SpeculativeTrapData() ? (SpeculativeTrapData*)this : NULL; aoqi@0: } aoqi@0: aoqi@0: aoqi@0: // Subclass specific initialization aoqi@0: virtual void post_initialize(BytecodeStream* stream, MethodData* mdo) {} aoqi@0: aoqi@0: // GC support aoqi@0: virtual void clean_weak_klass_links(BoolObjectClosure* is_alive_closure) {} aoqi@0: roland@9183: // Redefinition support roland@9183: virtual void clean_weak_method_links() {} roland@9183: aoqi@0: // CI translation: ProfileData can represent both MethodDataOop data aoqi@0: // as well as CIMethodData data. This function is provided for translating aoqi@0: // an oop in a ProfileData to the ci equivalent. Generally speaking, aoqi@0: // most ProfileData don't require any translation, so we provide the null aoqi@0: // translation here, and the required translators are in the ci subclasses. aoqi@0: virtual void translate_from(const ProfileData* data) {} aoqi@0: aoqi@0: virtual void print_data_on(outputStream* st, const char* extra = NULL) const { aoqi@0: ShouldNotReachHere(); aoqi@0: } aoqi@0: aoqi@0: void print_data_on(outputStream* st, const MethodData* md) const; aoqi@0: aoqi@0: #ifndef PRODUCT aoqi@0: void print_shared(outputStream* st, const char* name, const char* extra) const; aoqi@0: void tab(outputStream* st, bool first = false) const; aoqi@0: #endif aoqi@0: }; aoqi@0: aoqi@0: // BitData aoqi@0: // aoqi@0: // A BitData holds a flag or two in its header. aoqi@0: class BitData : public ProfileData { aoqi@0: protected: aoqi@0: enum { aoqi@0: // null_seen: aoqi@0: // saw a null operand (cast/aastore/instanceof) aoqi@0: null_seen_flag = DataLayout::first_flag + 0 aoqi@0: }; aoqi@0: enum { bit_cell_count = 0 }; // no additional data fields needed. aoqi@0: public: aoqi@0: BitData(DataLayout* layout) : ProfileData(layout) { aoqi@0: } aoqi@0: aoqi@0: virtual bool is_BitData() const { return true; } aoqi@0: aoqi@0: static int static_cell_count() { aoqi@0: return bit_cell_count; aoqi@0: } aoqi@0: aoqi@0: virtual int cell_count() const { aoqi@0: return static_cell_count(); aoqi@0: } aoqi@0: aoqi@0: // Accessor aoqi@0: aoqi@0: // The null_seen flag bit is specially known to the interpreter. aoqi@0: // Consulting it allows the compiler to avoid setting up null_check traps. aoqi@0: bool null_seen() { return flag_at(null_seen_flag); } aoqi@0: void set_null_seen() { set_flag_at(null_seen_flag); } aoqi@0: aoqi@0: aoqi@0: // Code generation support aoqi@0: static int null_seen_byte_constant() { aoqi@0: return flag_number_to_byte_constant(null_seen_flag); aoqi@0: } aoqi@0: aoqi@0: static ByteSize bit_data_size() { aoqi@0: return cell_offset(bit_cell_count); aoqi@0: } aoqi@0: aoqi@0: #ifdef CC_INTERP aoqi@0: static int bit_data_size_in_bytes() { aoqi@0: return cell_offset_in_bytes(bit_cell_count); aoqi@0: } aoqi@0: aoqi@0: static void set_null_seen(DataLayout* layout) { aoqi@0: set_flag_at(layout, null_seen_flag); aoqi@0: } aoqi@0: aoqi@0: static DataLayout* advance(DataLayout* layout) { aoqi@0: return (DataLayout*) (((address)layout) + (ssize_t)BitData::bit_data_size_in_bytes()); aoqi@0: } aoqi@0: #endif // CC_INTERP aoqi@0: aoqi@0: #ifndef PRODUCT aoqi@0: void print_data_on(outputStream* st, const char* extra = NULL) const; aoqi@0: #endif aoqi@0: }; aoqi@0: aoqi@0: // CounterData aoqi@0: // aoqi@0: // A CounterData corresponds to a simple counter. aoqi@0: class CounterData : public BitData { aoqi@0: protected: aoqi@0: enum { aoqi@0: count_off, aoqi@0: counter_cell_count aoqi@0: }; aoqi@0: public: aoqi@0: CounterData(DataLayout* layout) : BitData(layout) {} aoqi@0: aoqi@0: virtual bool is_CounterData() const { return true; } aoqi@0: aoqi@0: static int static_cell_count() { aoqi@0: return counter_cell_count; aoqi@0: } aoqi@0: aoqi@0: virtual int cell_count() const { aoqi@0: return static_cell_count(); aoqi@0: } aoqi@0: aoqi@0: // Direct accessor aoqi@0: uint count() const { aoqi@0: return uint_at(count_off); aoqi@0: } aoqi@0: aoqi@0: // Code generation support aoqi@0: static ByteSize count_offset() { aoqi@0: return cell_offset(count_off); aoqi@0: } aoqi@0: static ByteSize counter_data_size() { aoqi@0: return cell_offset(counter_cell_count); aoqi@0: } aoqi@0: aoqi@0: void set_count(uint count) { aoqi@0: set_uint_at(count_off, count); aoqi@0: } aoqi@0: aoqi@0: #ifdef CC_INTERP aoqi@0: static int counter_data_size_in_bytes() { aoqi@0: return cell_offset_in_bytes(counter_cell_count); aoqi@0: } aoqi@0: aoqi@0: static void increment_count_no_overflow(DataLayout* layout) { aoqi@0: increment_uint_at_no_overflow(layout, count_off); aoqi@0: } aoqi@0: aoqi@0: // Support counter decrementation at checkcast / subtype check failed. aoqi@0: static void decrement_count(DataLayout* layout) { aoqi@0: increment_uint_at_no_overflow(layout, count_off, -1); aoqi@0: } aoqi@0: aoqi@0: static DataLayout* advance(DataLayout* layout) { aoqi@0: return (DataLayout*) (((address)layout) + (ssize_t)CounterData::counter_data_size_in_bytes()); aoqi@0: } aoqi@0: #endif // CC_INTERP aoqi@0: aoqi@0: #ifndef PRODUCT aoqi@0: void print_data_on(outputStream* st, const char* extra = NULL) const; aoqi@0: #endif 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: class JumpData : public ProfileData { aoqi@0: protected: aoqi@0: enum { aoqi@0: taken_off_set, aoqi@0: displacement_off_set, aoqi@0: jump_cell_count aoqi@0: }; aoqi@0: aoqi@0: void set_displacement(int displacement) { aoqi@0: set_int_at(displacement_off_set, displacement); aoqi@0: } aoqi@0: aoqi@0: public: aoqi@0: JumpData(DataLayout* layout) : ProfileData(layout) { aoqi@0: assert(layout->tag() == DataLayout::jump_data_tag || aoqi@0: layout->tag() == DataLayout::branch_data_tag, "wrong type"); aoqi@0: } aoqi@0: aoqi@0: virtual bool is_JumpData() const { return true; } aoqi@0: aoqi@0: static int static_cell_count() { aoqi@0: return jump_cell_count; aoqi@0: } aoqi@0: aoqi@0: virtual int cell_count() const { aoqi@0: return static_cell_count(); aoqi@0: } aoqi@0: aoqi@0: // Direct accessor aoqi@0: uint taken() const { aoqi@0: return uint_at(taken_off_set); aoqi@0: } aoqi@0: aoqi@0: void set_taken(uint cnt) { aoqi@0: set_uint_at(taken_off_set, cnt); aoqi@0: } aoqi@0: aoqi@0: // Saturating counter aoqi@0: uint inc_taken() { aoqi@0: uint cnt = taken() + 1; aoqi@0: // Did we wrap? Will compiler screw us?? aoqi@0: if (cnt == 0) cnt--; aoqi@0: set_uint_at(taken_off_set, cnt); aoqi@0: return cnt; aoqi@0: } aoqi@0: aoqi@0: int displacement() const { aoqi@0: return int_at(displacement_off_set); aoqi@0: } aoqi@0: aoqi@0: // Code generation support aoqi@0: static ByteSize taken_offset() { aoqi@0: return cell_offset(taken_off_set); aoqi@0: } aoqi@0: aoqi@0: static ByteSize displacement_offset() { aoqi@0: return cell_offset(displacement_off_set); aoqi@0: } aoqi@0: aoqi@0: #ifdef CC_INTERP aoqi@0: static void increment_taken_count_no_overflow(DataLayout* layout) { aoqi@0: increment_uint_at_no_overflow(layout, taken_off_set); aoqi@0: } aoqi@0: aoqi@0: static DataLayout* advance_taken(DataLayout* layout) { aoqi@0: return (DataLayout*) (((address)layout) + (ssize_t)int_at(layout, displacement_off_set)); aoqi@0: } aoqi@0: aoqi@0: static uint taken_count(DataLayout* layout) { aoqi@0: return (uint) uint_at(layout, taken_off_set); aoqi@0: } aoqi@0: #endif // CC_INTERP aoqi@0: aoqi@0: // Specific initialization. aoqi@0: void post_initialize(BytecodeStream* stream, MethodData* mdo); aoqi@0: aoqi@0: #ifndef PRODUCT aoqi@0: void print_data_on(outputStream* st, const char* extra = NULL) const; aoqi@0: #endif aoqi@0: }; aoqi@0: aoqi@0: // Entries in a ProfileData object to record types: it can either be aoqi@0: // none (no profile), unknown (conflicting profile data) or a klass if aoqi@0: // a single one is seen. Whether a null reference was seen is also aoqi@0: // recorded. No counter is associated with the type and a single type aoqi@0: // is tracked (unlike VirtualCallData). aoqi@0: class TypeEntries { aoqi@0: aoqi@0: public: aoqi@0: aoqi@0: // A single cell is used to record information for a type: aoqi@0: // - the cell is initialized to 0 aoqi@0: // - when a type is discovered it is stored in the cell aoqi@0: // - bit zero of the cell is used to record whether a null reference aoqi@0: // was encountered or not aoqi@0: // - bit 1 is set to record a conflict in the type information aoqi@0: aoqi@0: enum { aoqi@0: null_seen = 1, aoqi@0: type_mask = ~null_seen, aoqi@0: type_unknown = 2, aoqi@0: status_bits = null_seen | type_unknown, aoqi@0: type_klass_mask = ~status_bits aoqi@0: }; aoqi@0: aoqi@0: // what to initialize a cell to aoqi@0: static intptr_t type_none() { aoqi@0: return 0; aoqi@0: } aoqi@0: aoqi@0: // null seen = bit 0 set? aoqi@0: static bool was_null_seen(intptr_t v) { aoqi@0: return (v & null_seen) != 0; aoqi@0: } aoqi@0: aoqi@0: // conflicting type information = bit 1 set? aoqi@0: static bool is_type_unknown(intptr_t v) { aoqi@0: return (v & type_unknown) != 0; aoqi@0: } aoqi@0: aoqi@0: // not type information yet = all bits cleared, ignoring bit 0? aoqi@0: static bool is_type_none(intptr_t v) { aoqi@0: return (v & type_mask) == 0; aoqi@0: } aoqi@0: aoqi@0: // recorded type: cell without bit 0 and 1 aoqi@0: static intptr_t klass_part(intptr_t v) { aoqi@0: intptr_t r = v & type_klass_mask; aoqi@0: return r; aoqi@0: } aoqi@0: aoqi@0: // type recorded aoqi@0: static Klass* valid_klass(intptr_t k) { aoqi@0: if (!is_type_none(k) && aoqi@0: !is_type_unknown(k)) { aoqi@0: Klass* res = (Klass*)klass_part(k); aoqi@0: assert(res != NULL, "invalid"); aoqi@0: return res; aoqi@0: } else { aoqi@0: return NULL; aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: static intptr_t with_status(intptr_t k, intptr_t in) { aoqi@0: return k | (in & status_bits); aoqi@0: } aoqi@0: aoqi@0: static intptr_t with_status(Klass* k, intptr_t in) { aoqi@0: return with_status((intptr_t)k, in); aoqi@0: } aoqi@0: aoqi@0: #ifndef PRODUCT aoqi@0: static void print_klass(outputStream* st, intptr_t k); aoqi@0: #endif aoqi@0: aoqi@0: // GC support aoqi@0: static bool is_loader_alive(BoolObjectClosure* is_alive_cl, intptr_t p); aoqi@0: aoqi@0: protected: aoqi@0: // ProfileData object these entries are part of aoqi@0: ProfileData* _pd; aoqi@0: // offset within the ProfileData object where the entries start aoqi@0: const int _base_off; aoqi@0: aoqi@0: TypeEntries(int base_off) aoqi@0: : _base_off(base_off), _pd(NULL) {} aoqi@0: aoqi@0: void set_intptr_at(int index, intptr_t value) { aoqi@0: _pd->set_intptr_at(index, value); aoqi@0: } aoqi@0: aoqi@0: intptr_t intptr_at(int index) const { aoqi@0: return _pd->intptr_at(index); aoqi@0: } aoqi@0: aoqi@0: public: aoqi@0: void set_profile_data(ProfileData* pd) { aoqi@0: _pd = pd; aoqi@0: } aoqi@0: }; aoqi@0: aoqi@0: // Type entries used for arguments passed at a call and parameters on aoqi@0: // method entry. 2 cells per entry: one for the type encoded as in aoqi@0: // TypeEntries and one initialized with the stack slot where the aoqi@0: // profiled object is to be found so that the interpreter can locate aoqi@0: // it quickly. aoqi@0: class TypeStackSlotEntries : public TypeEntries { aoqi@0: aoqi@0: private: aoqi@0: enum { aoqi@0: stack_slot_entry, aoqi@0: type_entry, aoqi@0: per_arg_cell_count aoqi@0: }; aoqi@0: aoqi@0: // offset of cell for stack slot for entry i within ProfileData object aoqi@0: int stack_slot_offset(int i) const { aoqi@0: return _base_off + stack_slot_local_offset(i); aoqi@0: } aoqi@0: aoqi@0: protected: aoqi@0: const int _number_of_entries; aoqi@0: aoqi@0: // offset of cell for type for entry i within ProfileData object aoqi@0: int type_offset(int i) const { aoqi@0: return _base_off + type_local_offset(i); aoqi@0: } aoqi@0: aoqi@0: public: aoqi@0: aoqi@0: TypeStackSlotEntries(int base_off, int nb_entries) aoqi@0: : TypeEntries(base_off), _number_of_entries(nb_entries) {} aoqi@0: aoqi@0: static int compute_cell_count(Symbol* signature, bool include_receiver, int max); aoqi@0: aoqi@0: void post_initialize(Symbol* signature, bool has_receiver, bool include_receiver); aoqi@0: aoqi@0: // offset of cell for stack slot for entry i within this block of cells for a TypeStackSlotEntries aoqi@0: static int stack_slot_local_offset(int i) { aoqi@0: return i * per_arg_cell_count + stack_slot_entry; aoqi@0: } aoqi@0: aoqi@0: // offset of cell for type for entry i within this block of cells for a TypeStackSlotEntries aoqi@0: static int type_local_offset(int i) { aoqi@0: return i * per_arg_cell_count + type_entry; aoqi@0: } aoqi@0: aoqi@0: // stack slot for entry i aoqi@0: uint stack_slot(int i) const { aoqi@0: assert(i >= 0 && i < _number_of_entries, "oob"); aoqi@0: return _pd->uint_at(stack_slot_offset(i)); aoqi@0: } aoqi@0: aoqi@0: // set stack slot for entry i aoqi@0: void set_stack_slot(int i, uint num) { aoqi@0: assert(i >= 0 && i < _number_of_entries, "oob"); aoqi@0: _pd->set_uint_at(stack_slot_offset(i), num); aoqi@0: } aoqi@0: aoqi@0: // type for entry i aoqi@0: intptr_t type(int i) const { aoqi@0: assert(i >= 0 && i < _number_of_entries, "oob"); aoqi@0: return _pd->intptr_at(type_offset(i)); aoqi@0: } aoqi@0: aoqi@0: // set type for entry i aoqi@0: void set_type(int i, intptr_t k) { aoqi@0: assert(i >= 0 && i < _number_of_entries, "oob"); aoqi@0: _pd->set_intptr_at(type_offset(i), k); aoqi@0: } aoqi@0: aoqi@0: static ByteSize per_arg_size() { aoqi@0: return in_ByteSize(per_arg_cell_count * DataLayout::cell_size); aoqi@0: } aoqi@0: aoqi@0: static int per_arg_count() { aoqi@0: return per_arg_cell_count ; aoqi@0: } aoqi@0: aoqi@0: // GC support aoqi@0: void clean_weak_klass_links(BoolObjectClosure* is_alive_closure); aoqi@0: aoqi@0: #ifndef PRODUCT aoqi@0: void print_data_on(outputStream* st) const; aoqi@0: #endif aoqi@0: }; aoqi@0: aoqi@0: // Type entry used for return from a call. A single cell to record the aoqi@0: // type. aoqi@0: class ReturnTypeEntry : public TypeEntries { aoqi@0: aoqi@0: private: aoqi@0: enum { aoqi@0: cell_count = 1 aoqi@0: }; aoqi@0: aoqi@0: public: aoqi@0: ReturnTypeEntry(int base_off) aoqi@0: : TypeEntries(base_off) {} aoqi@0: aoqi@0: void post_initialize() { aoqi@0: set_type(type_none()); aoqi@0: } aoqi@0: aoqi@0: intptr_t type() const { aoqi@0: return _pd->intptr_at(_base_off); aoqi@0: } aoqi@0: aoqi@0: void set_type(intptr_t k) { aoqi@0: _pd->set_intptr_at(_base_off, k); aoqi@0: } aoqi@0: aoqi@0: static int static_cell_count() { aoqi@0: return cell_count; aoqi@0: } aoqi@0: aoqi@0: static ByteSize size() { aoqi@0: return in_ByteSize(cell_count * DataLayout::cell_size); aoqi@0: } aoqi@0: aoqi@0: ByteSize type_offset() { aoqi@0: return DataLayout::cell_offset(_base_off); aoqi@0: } aoqi@0: aoqi@0: // GC support aoqi@0: void clean_weak_klass_links(BoolObjectClosure* is_alive_closure); aoqi@0: aoqi@0: #ifndef PRODUCT aoqi@0: void print_data_on(outputStream* st) const; aoqi@0: #endif aoqi@0: }; aoqi@0: aoqi@0: // Entries to collect type information at a call: contains arguments aoqi@0: // (TypeStackSlotEntries), a return type (ReturnTypeEntry) and a aoqi@0: // number of cells. Because the number of cells for the return type is aoqi@0: // smaller than the number of cells for the type of an arguments, the aoqi@0: // number of cells is used to tell how many arguments are profiled and aoqi@0: // whether a return value is profiled. See has_arguments() and aoqi@0: // has_return(). aoqi@0: class TypeEntriesAtCall { aoqi@0: private: aoqi@0: static int stack_slot_local_offset(int i) { aoqi@0: return header_cell_count() + TypeStackSlotEntries::stack_slot_local_offset(i); aoqi@0: } aoqi@0: aoqi@0: static int argument_type_local_offset(int i) { aoqi@0: return header_cell_count() + TypeStackSlotEntries::type_local_offset(i);; aoqi@0: } aoqi@0: aoqi@0: public: aoqi@0: aoqi@0: static int header_cell_count() { aoqi@0: return 1; aoqi@0: } aoqi@0: aoqi@0: static int cell_count_local_offset() { aoqi@0: return 0; aoqi@0: } aoqi@0: aoqi@0: static int compute_cell_count(BytecodeStream* stream); aoqi@0: aoqi@0: static void initialize(DataLayout* dl, int base, int cell_count) { aoqi@0: int off = base + cell_count_local_offset(); aoqi@0: dl->set_cell_at(off, cell_count - base - header_cell_count()); aoqi@0: } aoqi@0: aoqi@0: static bool arguments_profiling_enabled(); aoqi@0: static bool return_profiling_enabled(); aoqi@0: aoqi@0: // Code generation support aoqi@0: static ByteSize cell_count_offset() { aoqi@0: return in_ByteSize(cell_count_local_offset() * DataLayout::cell_size); aoqi@0: } aoqi@0: aoqi@0: static ByteSize args_data_offset() { aoqi@0: return in_ByteSize(header_cell_count() * DataLayout::cell_size); aoqi@0: } aoqi@0: aoqi@0: static ByteSize stack_slot_offset(int i) { aoqi@0: return in_ByteSize(stack_slot_local_offset(i) * DataLayout::cell_size); aoqi@0: } aoqi@0: aoqi@0: static ByteSize argument_type_offset(int i) { aoqi@0: return in_ByteSize(argument_type_local_offset(i) * DataLayout::cell_size); aoqi@0: } aoqi@0: aoqi@0: static ByteSize return_only_size() { aoqi@0: return ReturnTypeEntry::size() + in_ByteSize(header_cell_count() * DataLayout::cell_size); aoqi@0: } aoqi@0: aoqi@0: }; aoqi@0: aoqi@0: // CallTypeData aoqi@0: // aoqi@0: // A CallTypeData is used to access profiling information about a non aoqi@0: // virtual call for which we collect type information about arguments aoqi@0: // and return value. aoqi@0: class CallTypeData : public CounterData { aoqi@0: private: aoqi@0: // entries for arguments if any aoqi@0: TypeStackSlotEntries _args; aoqi@0: // entry for return type if any aoqi@0: ReturnTypeEntry _ret; aoqi@0: aoqi@0: int cell_count_global_offset() const { aoqi@0: return CounterData::static_cell_count() + TypeEntriesAtCall::cell_count_local_offset(); aoqi@0: } aoqi@0: aoqi@0: // number of cells not counting the header aoqi@0: int cell_count_no_header() const { aoqi@0: return uint_at(cell_count_global_offset()); aoqi@0: } aoqi@0: aoqi@0: void check_number_of_arguments(int total) { aoqi@0: assert(number_of_arguments() == total, "should be set in DataLayout::initialize"); aoqi@0: } aoqi@0: aoqi@0: public: aoqi@0: CallTypeData(DataLayout* layout) : aoqi@0: CounterData(layout), aoqi@0: _args(CounterData::static_cell_count()+TypeEntriesAtCall::header_cell_count(), number_of_arguments()), aoqi@0: _ret(cell_count() - ReturnTypeEntry::static_cell_count()) aoqi@0: { aoqi@0: assert(layout->tag() == DataLayout::call_type_data_tag, "wrong type"); aoqi@0: // Some compilers (VC++) don't want this passed in member initialization list aoqi@0: _args.set_profile_data(this); aoqi@0: _ret.set_profile_data(this); aoqi@0: } aoqi@0: aoqi@0: const TypeStackSlotEntries* args() const { aoqi@0: assert(has_arguments(), "no profiling of arguments"); aoqi@0: return &_args; aoqi@0: } aoqi@0: aoqi@0: const ReturnTypeEntry* ret() const { aoqi@0: assert(has_return(), "no profiling of return value"); aoqi@0: return &_ret; aoqi@0: } aoqi@0: aoqi@0: virtual bool is_CallTypeData() const { return true; } aoqi@0: aoqi@0: static int static_cell_count() { aoqi@0: return -1; aoqi@0: } aoqi@0: aoqi@0: static int compute_cell_count(BytecodeStream* stream) { aoqi@0: return CounterData::static_cell_count() + TypeEntriesAtCall::compute_cell_count(stream); aoqi@0: } aoqi@0: aoqi@0: static void initialize(DataLayout* dl, int cell_count) { aoqi@0: TypeEntriesAtCall::initialize(dl, CounterData::static_cell_count(), cell_count); aoqi@0: } aoqi@0: aoqi@0: virtual void post_initialize(BytecodeStream* stream, MethodData* mdo); aoqi@0: aoqi@0: virtual int cell_count() const { aoqi@0: return CounterData::static_cell_count() + aoqi@0: TypeEntriesAtCall::header_cell_count() + aoqi@0: int_at_unchecked(cell_count_global_offset()); aoqi@0: } aoqi@0: aoqi@0: int number_of_arguments() const { aoqi@0: return cell_count_no_header() / TypeStackSlotEntries::per_arg_count(); aoqi@0: } aoqi@0: aoqi@0: void set_argument_type(int i, Klass* k) { aoqi@0: assert(has_arguments(), "no arguments!"); aoqi@0: intptr_t current = _args.type(i); aoqi@0: _args.set_type(i, TypeEntries::with_status(k, current)); aoqi@0: } aoqi@0: aoqi@0: void set_return_type(Klass* k) { aoqi@0: assert(has_return(), "no return!"); aoqi@0: intptr_t current = _ret.type(); aoqi@0: _ret.set_type(TypeEntries::with_status(k, current)); aoqi@0: } aoqi@0: aoqi@0: // An entry for a return value takes less space than an entry for an aoqi@0: // argument so if the number of cells exceeds the number of cells aoqi@0: // needed for an argument, this object contains type information for aoqi@0: // at least one argument. aoqi@0: bool has_arguments() const { aoqi@0: bool res = cell_count_no_header() >= TypeStackSlotEntries::per_arg_count(); aoqi@0: assert (!res || TypeEntriesAtCall::arguments_profiling_enabled(), "no profiling of arguments"); aoqi@0: return res; aoqi@0: } aoqi@0: aoqi@0: // An entry for a return value takes less space than an entry for an aoqi@0: // argument, so if the remainder of the number of cells divided by aoqi@0: // the number of cells for an argument is not null, a return value aoqi@0: // is profiled in this object. aoqi@0: bool has_return() const { aoqi@0: bool res = (cell_count_no_header() % TypeStackSlotEntries::per_arg_count()) != 0; aoqi@0: assert (!res || TypeEntriesAtCall::return_profiling_enabled(), "no profiling of return values"); aoqi@0: return res; aoqi@0: } aoqi@0: aoqi@0: // Code generation support aoqi@0: static ByteSize args_data_offset() { aoqi@0: return cell_offset(CounterData::static_cell_count()) + TypeEntriesAtCall::args_data_offset(); aoqi@0: } aoqi@0: aoqi@0: // GC support aoqi@0: virtual void clean_weak_klass_links(BoolObjectClosure* is_alive_closure) { aoqi@0: if (has_arguments()) { aoqi@0: _args.clean_weak_klass_links(is_alive_closure); aoqi@0: } aoqi@0: if (has_return()) { aoqi@0: _ret.clean_weak_klass_links(is_alive_closure); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: #ifndef PRODUCT aoqi@0: virtual void print_data_on(outputStream* st, const char* extra = NULL) const; 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: class ReceiverTypeData : public CounterData { aoqi@0: protected: aoqi@0: enum { aoqi@0: receiver0_offset = counter_cell_count, aoqi@0: count0_offset, aoqi@0: receiver_type_row_cell_count = (count0_offset + 1) - receiver0_offset aoqi@0: }; aoqi@0: aoqi@0: public: aoqi@0: ReceiverTypeData(DataLayout* layout) : CounterData(layout) { aoqi@0: assert(layout->tag() == DataLayout::receiver_type_data_tag || aoqi@0: layout->tag() == DataLayout::virtual_call_data_tag || aoqi@0: layout->tag() == DataLayout::virtual_call_type_data_tag, "wrong type"); aoqi@0: } aoqi@0: aoqi@0: virtual bool is_ReceiverTypeData() const { return true; } aoqi@0: aoqi@0: static int static_cell_count() { aoqi@0: return counter_cell_count + (uint) TypeProfileWidth * receiver_type_row_cell_count; aoqi@0: } aoqi@0: aoqi@0: virtual int cell_count() const { aoqi@0: return static_cell_count(); aoqi@0: } aoqi@0: aoqi@0: // Direct accessors aoqi@0: static uint row_limit() { aoqi@0: return TypeProfileWidth; aoqi@0: } aoqi@0: static int receiver_cell_index(uint row) { aoqi@0: return receiver0_offset + row * receiver_type_row_cell_count; aoqi@0: } aoqi@0: static int receiver_count_cell_index(uint row) { aoqi@0: return count0_offset + row * receiver_type_row_cell_count; aoqi@0: } aoqi@0: aoqi@0: Klass* receiver(uint row) const { aoqi@0: assert(row < row_limit(), "oob"); aoqi@0: aoqi@0: Klass* recv = (Klass*)intptr_at(receiver_cell_index(row)); aoqi@0: assert(recv == NULL || recv->is_klass(), "wrong type"); aoqi@0: return recv; aoqi@0: } aoqi@0: aoqi@0: void set_receiver(uint row, Klass* k) { aoqi@0: assert((uint)row < row_limit(), "oob"); aoqi@0: set_intptr_at(receiver_cell_index(row), (uintptr_t)k); aoqi@0: } aoqi@0: aoqi@0: uint receiver_count(uint row) const { aoqi@0: assert(row < row_limit(), "oob"); aoqi@0: return uint_at(receiver_count_cell_index(row)); aoqi@0: } aoqi@0: aoqi@0: void set_receiver_count(uint row, uint count) { aoqi@0: assert(row < row_limit(), "oob"); aoqi@0: set_uint_at(receiver_count_cell_index(row), count); aoqi@0: } aoqi@0: aoqi@0: void clear_row(uint row) { aoqi@0: assert(row < row_limit(), "oob"); aoqi@0: // Clear total count - indicator of polymorphic call site. aoqi@0: // The site may look like as monomorphic after that but aoqi@0: // it allow to have more accurate profiling information because aoqi@0: // there was execution phase change since klasses were unloaded. aoqi@0: // If the site is still polymorphic then MDO will be updated aoqi@0: // to reflect it. But it could be the case that the site becomes aoqi@0: // only bimorphic. Then keeping total count not 0 will be wrong. aoqi@0: // Even if we use monomorphic (when it is not) for compilation aoqi@0: // we will only have trap, deoptimization and recompile again aoqi@0: // with updated MDO after executing method in Interpreter. aoqi@0: // An additional receiver will be recorded in the cleaned row aoqi@0: // during next call execution. aoqi@0: // aoqi@0: // Note: our profiling logic works with empty rows in any slot. aoqi@0: // We do sorting a profiling info (ciCallProfile) for compilation. aoqi@0: // aoqi@0: set_count(0); aoqi@0: set_receiver(row, NULL); aoqi@0: set_receiver_count(row, 0); aoqi@0: } aoqi@0: aoqi@0: // Code generation support aoqi@0: static ByteSize receiver_offset(uint row) { aoqi@0: return cell_offset(receiver_cell_index(row)); aoqi@0: } aoqi@0: static ByteSize receiver_count_offset(uint row) { aoqi@0: return cell_offset(receiver_count_cell_index(row)); aoqi@0: } aoqi@0: static ByteSize receiver_type_data_size() { aoqi@0: return cell_offset(static_cell_count()); aoqi@0: } aoqi@0: aoqi@0: // GC support aoqi@0: virtual void clean_weak_klass_links(BoolObjectClosure* is_alive_closure); aoqi@0: aoqi@0: #ifdef CC_INTERP aoqi@0: static int receiver_type_data_size_in_bytes() { aoqi@0: return cell_offset_in_bytes(static_cell_count()); aoqi@0: } aoqi@0: aoqi@0: static Klass *receiver_unchecked(DataLayout* layout, uint row) { aoqi@0: Klass* recv = (Klass*)layout->cell_at(receiver_cell_index(row)); aoqi@0: return recv; aoqi@0: } aoqi@0: aoqi@0: static void increment_receiver_count_no_overflow(DataLayout* layout, Klass *rcvr) { aoqi@0: const int num_rows = row_limit(); aoqi@0: // Receiver already exists? aoqi@0: for (int row = 0; row < num_rows; row++) { aoqi@0: if (receiver_unchecked(layout, row) == rcvr) { aoqi@0: increment_uint_at_no_overflow(layout, receiver_count_cell_index(row)); aoqi@0: return; aoqi@0: } aoqi@0: } aoqi@0: // New receiver, find a free slot. aoqi@0: for (int row = 0; row < num_rows; row++) { aoqi@0: if (receiver_unchecked(layout, row) == NULL) { aoqi@0: set_intptr_at(layout, receiver_cell_index(row), (intptr_t)rcvr); aoqi@0: increment_uint_at_no_overflow(layout, receiver_count_cell_index(row)); aoqi@0: return; aoqi@0: } aoqi@0: } aoqi@0: // Receiver did not match any saved receiver and there is no empty row for it. aoqi@0: // Increment total counter to indicate polymorphic case. aoqi@0: increment_count_no_overflow(layout); aoqi@0: } aoqi@0: aoqi@0: static DataLayout* advance(DataLayout* layout) { aoqi@0: return (DataLayout*) (((address)layout) + (ssize_t)ReceiverTypeData::receiver_type_data_size_in_bytes()); aoqi@0: } aoqi@0: #endif // CC_INTERP aoqi@0: aoqi@0: #ifndef PRODUCT aoqi@0: void print_receiver_data_on(outputStream* st) const; aoqi@0: void print_data_on(outputStream* st, const char* extra = NULL) const; aoqi@0: #endif aoqi@0: }; aoqi@0: aoqi@0: // VirtualCallData aoqi@0: // aoqi@0: // A VirtualCallData is used to access profiling information about a aoqi@0: // virtual call. For now, it has nothing more than a ReceiverTypeData. aoqi@0: class VirtualCallData : public ReceiverTypeData { aoqi@0: public: aoqi@0: VirtualCallData(DataLayout* layout) : ReceiverTypeData(layout) { aoqi@0: assert(layout->tag() == DataLayout::virtual_call_data_tag || aoqi@0: layout->tag() == DataLayout::virtual_call_type_data_tag, "wrong type"); aoqi@0: } aoqi@0: aoqi@0: virtual bool is_VirtualCallData() const { return true; } aoqi@0: aoqi@0: static int static_cell_count() { aoqi@0: // At this point we could add more profile state, e.g., for arguments. aoqi@0: // But for now it's the same size as the base record type. aoqi@0: return ReceiverTypeData::static_cell_count(); aoqi@0: } aoqi@0: aoqi@0: virtual int cell_count() const { aoqi@0: return static_cell_count(); aoqi@0: } aoqi@0: aoqi@0: // Direct accessors aoqi@0: static ByteSize virtual_call_data_size() { aoqi@0: return cell_offset(static_cell_count()); aoqi@0: } aoqi@0: aoqi@0: #ifdef CC_INTERP aoqi@0: static int virtual_call_data_size_in_bytes() { aoqi@0: return cell_offset_in_bytes(static_cell_count()); aoqi@0: } aoqi@0: aoqi@0: static DataLayout* advance(DataLayout* layout) { aoqi@0: return (DataLayout*) (((address)layout) + (ssize_t)VirtualCallData::virtual_call_data_size_in_bytes()); aoqi@0: } aoqi@0: #endif // CC_INTERP aoqi@0: aoqi@0: #ifndef PRODUCT aoqi@0: void print_data_on(outputStream* st, const char* extra = NULL) const; aoqi@0: #endif aoqi@0: }; aoqi@0: aoqi@0: // VirtualCallTypeData aoqi@0: // aoqi@0: // A VirtualCallTypeData is used to access profiling information about aoqi@0: // a virtual call for which we collect type information about aoqi@0: // arguments and return value. aoqi@0: class VirtualCallTypeData : public VirtualCallData { aoqi@0: private: aoqi@0: // entries for arguments if any aoqi@0: TypeStackSlotEntries _args; aoqi@0: // entry for return type if any aoqi@0: ReturnTypeEntry _ret; aoqi@0: aoqi@0: int cell_count_global_offset() const { aoqi@0: return VirtualCallData::static_cell_count() + TypeEntriesAtCall::cell_count_local_offset(); aoqi@0: } aoqi@0: aoqi@0: // number of cells not counting the header aoqi@0: int cell_count_no_header() const { aoqi@0: return uint_at(cell_count_global_offset()); aoqi@0: } aoqi@0: aoqi@0: void check_number_of_arguments(int total) { aoqi@0: assert(number_of_arguments() == total, "should be set in DataLayout::initialize"); aoqi@0: } aoqi@0: aoqi@0: public: aoqi@0: VirtualCallTypeData(DataLayout* layout) : aoqi@0: VirtualCallData(layout), aoqi@0: _args(VirtualCallData::static_cell_count()+TypeEntriesAtCall::header_cell_count(), number_of_arguments()), aoqi@0: _ret(cell_count() - ReturnTypeEntry::static_cell_count()) aoqi@0: { aoqi@0: assert(layout->tag() == DataLayout::virtual_call_type_data_tag, "wrong type"); aoqi@0: // Some compilers (VC++) don't want this passed in member initialization list aoqi@0: _args.set_profile_data(this); aoqi@0: _ret.set_profile_data(this); aoqi@0: } aoqi@0: aoqi@0: const TypeStackSlotEntries* args() const { aoqi@0: assert(has_arguments(), "no profiling of arguments"); aoqi@0: return &_args; aoqi@0: } aoqi@0: aoqi@0: const ReturnTypeEntry* ret() const { aoqi@0: assert(has_return(), "no profiling of return value"); aoqi@0: return &_ret; aoqi@0: } aoqi@0: aoqi@0: virtual bool is_VirtualCallTypeData() const { return true; } aoqi@0: aoqi@0: static int static_cell_count() { aoqi@0: return -1; aoqi@0: } aoqi@0: aoqi@0: static int compute_cell_count(BytecodeStream* stream) { aoqi@0: return VirtualCallData::static_cell_count() + TypeEntriesAtCall::compute_cell_count(stream); aoqi@0: } aoqi@0: aoqi@0: static void initialize(DataLayout* dl, int cell_count) { aoqi@0: TypeEntriesAtCall::initialize(dl, VirtualCallData::static_cell_count(), cell_count); aoqi@0: } aoqi@0: aoqi@0: virtual void post_initialize(BytecodeStream* stream, MethodData* mdo); aoqi@0: aoqi@0: virtual int cell_count() const { aoqi@0: return VirtualCallData::static_cell_count() + aoqi@0: TypeEntriesAtCall::header_cell_count() + aoqi@0: int_at_unchecked(cell_count_global_offset()); aoqi@0: } aoqi@0: aoqi@0: int number_of_arguments() const { aoqi@0: return cell_count_no_header() / TypeStackSlotEntries::per_arg_count(); aoqi@0: } aoqi@0: aoqi@0: void set_argument_type(int i, Klass* k) { aoqi@0: assert(has_arguments(), "no arguments!"); aoqi@0: intptr_t current = _args.type(i); aoqi@0: _args.set_type(i, TypeEntries::with_status(k, current)); aoqi@0: } aoqi@0: aoqi@0: void set_return_type(Klass* k) { aoqi@0: assert(has_return(), "no return!"); aoqi@0: intptr_t current = _ret.type(); aoqi@0: _ret.set_type(TypeEntries::with_status(k, current)); aoqi@0: } aoqi@0: aoqi@0: // An entry for a return value takes less space than an entry for an aoqi@0: // argument, so if the remainder of the number of cells divided by aoqi@0: // the number of cells for an argument is not null, a return value aoqi@0: // is profiled in this object. aoqi@0: bool has_return() const { aoqi@0: bool res = (cell_count_no_header() % TypeStackSlotEntries::per_arg_count()) != 0; aoqi@0: assert (!res || TypeEntriesAtCall::return_profiling_enabled(), "no profiling of return values"); aoqi@0: return res; aoqi@0: } aoqi@0: aoqi@0: // An entry for a return value takes less space than an entry for an aoqi@0: // argument so if the number of cells exceeds the number of cells aoqi@0: // needed for an argument, this object contains type information for aoqi@0: // at least one argument. aoqi@0: bool has_arguments() const { aoqi@0: bool res = cell_count_no_header() >= TypeStackSlotEntries::per_arg_count(); aoqi@0: assert (!res || TypeEntriesAtCall::arguments_profiling_enabled(), "no profiling of arguments"); aoqi@0: return res; aoqi@0: } aoqi@0: aoqi@0: // Code generation support aoqi@0: static ByteSize args_data_offset() { aoqi@0: return cell_offset(VirtualCallData::static_cell_count()) + TypeEntriesAtCall::args_data_offset(); aoqi@0: } aoqi@0: aoqi@0: // GC support aoqi@0: virtual void clean_weak_klass_links(BoolObjectClosure* is_alive_closure) { aoqi@0: ReceiverTypeData::clean_weak_klass_links(is_alive_closure); aoqi@0: if (has_arguments()) { aoqi@0: _args.clean_weak_klass_links(is_alive_closure); aoqi@0: } aoqi@0: if (has_return()) { aoqi@0: _ret.clean_weak_klass_links(is_alive_closure); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: #ifndef PRODUCT aoqi@0: virtual void print_data_on(outputStream* st, const char* extra = NULL) const; aoqi@0: #endif 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 data displacement. aoqi@0: class RetData : public CounterData { aoqi@0: protected: aoqi@0: enum { aoqi@0: bci0_offset = counter_cell_count, aoqi@0: count0_offset, aoqi@0: displacement0_offset, aoqi@0: ret_row_cell_count = (displacement0_offset + 1) - bci0_offset aoqi@0: }; aoqi@0: aoqi@0: void set_bci(uint row, int bci) { aoqi@0: assert((uint)row < row_limit(), "oob"); aoqi@0: set_int_at(bci0_offset + row * ret_row_cell_count, bci); aoqi@0: } aoqi@0: void release_set_bci(uint row, int bci) { aoqi@0: assert((uint)row < row_limit(), "oob"); aoqi@0: // 'release' when setting the bci acts as a valid flag for other aoqi@0: // threads wrt bci_count and bci_displacement. aoqi@0: release_set_int_at(bci0_offset + row * ret_row_cell_count, bci); aoqi@0: } aoqi@0: void set_bci_count(uint row, uint count) { aoqi@0: assert((uint)row < row_limit(), "oob"); aoqi@0: set_uint_at(count0_offset + row * ret_row_cell_count, count); aoqi@0: } aoqi@0: void set_bci_displacement(uint row, int disp) { aoqi@0: set_int_at(displacement0_offset + row * ret_row_cell_count, disp); aoqi@0: } aoqi@0: aoqi@0: public: aoqi@0: RetData(DataLayout* layout) : CounterData(layout) { aoqi@0: assert(layout->tag() == DataLayout::ret_data_tag, "wrong type"); aoqi@0: } aoqi@0: aoqi@0: virtual bool is_RetData() const { return true; } aoqi@0: aoqi@0: enum { aoqi@0: no_bci = -1 // value of bci when bci1/2 are not in use. aoqi@0: }; aoqi@0: aoqi@0: static int static_cell_count() { aoqi@0: return counter_cell_count + (uint) BciProfileWidth * ret_row_cell_count; aoqi@0: } aoqi@0: aoqi@0: virtual int cell_count() const { aoqi@0: return static_cell_count(); aoqi@0: } aoqi@0: aoqi@0: static uint row_limit() { aoqi@0: return BciProfileWidth; aoqi@0: } aoqi@0: static int bci_cell_index(uint row) { aoqi@0: return bci0_offset + row * ret_row_cell_count; aoqi@0: } aoqi@0: static int bci_count_cell_index(uint row) { aoqi@0: return count0_offset + row * ret_row_cell_count; aoqi@0: } aoqi@0: static int bci_displacement_cell_index(uint row) { aoqi@0: return displacement0_offset + row * ret_row_cell_count; aoqi@0: } aoqi@0: aoqi@0: // Direct accessors aoqi@0: int bci(uint row) const { aoqi@0: return int_at(bci_cell_index(row)); aoqi@0: } aoqi@0: uint bci_count(uint row) const { aoqi@0: return uint_at(bci_count_cell_index(row)); aoqi@0: } aoqi@0: int bci_displacement(uint row) const { aoqi@0: return int_at(bci_displacement_cell_index(row)); aoqi@0: } aoqi@0: aoqi@0: // Interpreter Runtime support aoqi@0: address fixup_ret(int return_bci, MethodData* mdo); aoqi@0: aoqi@0: // Code generation support aoqi@0: static ByteSize bci_offset(uint row) { aoqi@0: return cell_offset(bci_cell_index(row)); aoqi@0: } aoqi@0: static ByteSize bci_count_offset(uint row) { aoqi@0: return cell_offset(bci_count_cell_index(row)); aoqi@0: } aoqi@0: static ByteSize bci_displacement_offset(uint row) { aoqi@0: return cell_offset(bci_displacement_cell_index(row)); aoqi@0: } aoqi@0: aoqi@0: #ifdef CC_INTERP aoqi@0: static DataLayout* advance(MethodData *md, int bci); aoqi@0: #endif // CC_INTERP aoqi@0: aoqi@0: // Specific initialization. aoqi@0: void post_initialize(BytecodeStream* stream, MethodData* mdo); aoqi@0: aoqi@0: #ifndef PRODUCT aoqi@0: void print_data_on(outputStream* st, const char* extra = NULL) const; aoqi@0: #endif 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: class BranchData : public JumpData { aoqi@0: protected: aoqi@0: enum { aoqi@0: not_taken_off_set = jump_cell_count, aoqi@0: branch_cell_count aoqi@0: }; aoqi@0: aoqi@0: void set_displacement(int displacement) { aoqi@0: set_int_at(displacement_off_set, displacement); aoqi@0: } aoqi@0: aoqi@0: public: aoqi@0: BranchData(DataLayout* layout) : JumpData(layout) { aoqi@0: assert(layout->tag() == DataLayout::branch_data_tag, "wrong type"); aoqi@0: } aoqi@0: aoqi@0: virtual bool is_BranchData() const { return true; } aoqi@0: aoqi@0: static int static_cell_count() { aoqi@0: return branch_cell_count; aoqi@0: } aoqi@0: aoqi@0: virtual int cell_count() const { aoqi@0: return static_cell_count(); aoqi@0: } aoqi@0: aoqi@0: // Direct accessor aoqi@0: uint not_taken() const { aoqi@0: return uint_at(not_taken_off_set); aoqi@0: } aoqi@0: aoqi@0: void set_not_taken(uint cnt) { aoqi@0: set_uint_at(not_taken_off_set, cnt); aoqi@0: } aoqi@0: aoqi@0: uint inc_not_taken() { aoqi@0: uint cnt = not_taken() + 1; aoqi@0: // Did we wrap? Will compiler screw us?? aoqi@0: if (cnt == 0) cnt--; aoqi@0: set_uint_at(not_taken_off_set, cnt); aoqi@0: return cnt; aoqi@0: } aoqi@0: aoqi@0: // Code generation support aoqi@0: static ByteSize not_taken_offset() { aoqi@0: return cell_offset(not_taken_off_set); aoqi@0: } aoqi@0: static ByteSize branch_data_size() { aoqi@0: return cell_offset(branch_cell_count); aoqi@0: } aoqi@0: aoqi@0: #ifdef CC_INTERP aoqi@0: static int branch_data_size_in_bytes() { aoqi@0: return cell_offset_in_bytes(branch_cell_count); aoqi@0: } aoqi@0: aoqi@0: static void increment_not_taken_count_no_overflow(DataLayout* layout) { aoqi@0: increment_uint_at_no_overflow(layout, not_taken_off_set); aoqi@0: } aoqi@0: aoqi@0: static DataLayout* advance_not_taken(DataLayout* layout) { aoqi@0: return (DataLayout*) (((address)layout) + (ssize_t)BranchData::branch_data_size_in_bytes()); aoqi@0: } aoqi@0: #endif // CC_INTERP aoqi@0: aoqi@0: // Specific initialization. aoqi@0: void post_initialize(BytecodeStream* stream, MethodData* mdo); aoqi@0: aoqi@0: #ifndef PRODUCT aoqi@0: void print_data_on(outputStream* st, const char* extra = NULL) const; aoqi@0: #endif aoqi@0: }; aoqi@0: aoqi@0: // ArrayData aoqi@0: // aoqi@0: // A ArrayData is a base class for accessing profiling data which does aoqi@0: // not have a statically known size. It consists of an array length aoqi@0: // and an array start. aoqi@0: class ArrayData : public ProfileData { aoqi@0: protected: aoqi@0: friend class DataLayout; aoqi@0: aoqi@0: enum { aoqi@0: array_len_off_set, aoqi@0: array_start_off_set aoqi@0: }; aoqi@0: aoqi@0: uint array_uint_at(int index) const { aoqi@0: int aindex = index + array_start_off_set; aoqi@0: return uint_at(aindex); aoqi@0: } aoqi@0: int array_int_at(int index) const { aoqi@0: int aindex = index + array_start_off_set; aoqi@0: return int_at(aindex); aoqi@0: } aoqi@0: oop array_oop_at(int index) const { aoqi@0: int aindex = index + array_start_off_set; aoqi@0: return oop_at(aindex); aoqi@0: } aoqi@0: void array_set_int_at(int index, int value) { aoqi@0: int aindex = index + array_start_off_set; aoqi@0: set_int_at(aindex, value); aoqi@0: } aoqi@0: aoqi@0: #ifdef CC_INTERP aoqi@0: // Static low level accessors for DataLayout with ArrayData's semantics. aoqi@0: aoqi@0: static void increment_array_uint_at_no_overflow(DataLayout* layout, int index) { aoqi@0: int aindex = index + array_start_off_set; aoqi@0: increment_uint_at_no_overflow(layout, aindex); aoqi@0: } aoqi@0: aoqi@0: static int array_int_at(DataLayout* layout, int index) { aoqi@0: int aindex = index + array_start_off_set; aoqi@0: return int_at(layout, aindex); aoqi@0: } aoqi@0: #endif // CC_INTERP aoqi@0: aoqi@0: // Code generation support for subclasses. aoqi@0: static ByteSize array_element_offset(int index) { aoqi@0: return cell_offset(array_start_off_set + index); aoqi@0: } aoqi@0: aoqi@0: public: aoqi@0: ArrayData(DataLayout* layout) : ProfileData(layout) {} aoqi@0: aoqi@0: virtual bool is_ArrayData() const { return true; } aoqi@0: aoqi@0: static int static_cell_count() { aoqi@0: return -1; aoqi@0: } aoqi@0: aoqi@0: int array_len() const { aoqi@0: return int_at_unchecked(array_len_off_set); aoqi@0: } aoqi@0: aoqi@0: virtual int cell_count() const { aoqi@0: return array_len() + 1; aoqi@0: } aoqi@0: aoqi@0: // Code generation support aoqi@0: static ByteSize array_len_offset() { aoqi@0: return cell_offset(array_len_off_set); aoqi@0: } aoqi@0: static ByteSize array_start_offset() { aoqi@0: return cell_offset(array_start_off_set); aoqi@0: } 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: class MultiBranchData : public ArrayData { aoqi@0: protected: aoqi@0: enum { aoqi@0: default_count_off_set, aoqi@0: default_disaplacement_off_set, aoqi@0: case_array_start aoqi@0: }; aoqi@0: enum { aoqi@0: relative_count_off_set, aoqi@0: relative_displacement_off_set, aoqi@0: per_case_cell_count aoqi@0: }; aoqi@0: aoqi@0: void set_default_displacement(int displacement) { aoqi@0: array_set_int_at(default_disaplacement_off_set, displacement); aoqi@0: } aoqi@0: void set_displacement_at(int index, int displacement) { aoqi@0: array_set_int_at(case_array_start + aoqi@0: index * per_case_cell_count + aoqi@0: relative_displacement_off_set, aoqi@0: displacement); aoqi@0: } aoqi@0: aoqi@0: public: aoqi@0: MultiBranchData(DataLayout* layout) : ArrayData(layout) { aoqi@0: assert(layout->tag() == DataLayout::multi_branch_data_tag, "wrong type"); aoqi@0: } aoqi@0: aoqi@0: virtual bool is_MultiBranchData() const { return true; } aoqi@0: aoqi@0: static int compute_cell_count(BytecodeStream* stream); aoqi@0: aoqi@0: int number_of_cases() const { aoqi@0: int alen = array_len() - 2; // get rid of default case here. aoqi@0: assert(alen % per_case_cell_count == 0, "must be even"); aoqi@0: return (alen / per_case_cell_count); aoqi@0: } aoqi@0: aoqi@0: uint default_count() const { aoqi@0: return array_uint_at(default_count_off_set); aoqi@0: } aoqi@0: int default_displacement() const { aoqi@0: return array_int_at(default_disaplacement_off_set); aoqi@0: } aoqi@0: aoqi@0: uint count_at(int index) const { aoqi@0: return array_uint_at(case_array_start + aoqi@0: index * per_case_cell_count + aoqi@0: relative_count_off_set); aoqi@0: } aoqi@0: int displacement_at(int index) const { aoqi@0: return array_int_at(case_array_start + aoqi@0: index * per_case_cell_count + aoqi@0: relative_displacement_off_set); aoqi@0: } aoqi@0: aoqi@0: // Code generation support aoqi@0: static ByteSize default_count_offset() { aoqi@0: return array_element_offset(default_count_off_set); aoqi@0: } aoqi@0: static ByteSize default_displacement_offset() { aoqi@0: return array_element_offset(default_disaplacement_off_set); aoqi@0: } aoqi@0: static ByteSize case_count_offset(int index) { aoqi@0: return case_array_offset() + aoqi@0: (per_case_size() * index) + aoqi@0: relative_count_offset(); aoqi@0: } aoqi@0: static ByteSize case_array_offset() { aoqi@0: return array_element_offset(case_array_start); aoqi@0: } aoqi@0: static ByteSize per_case_size() { aoqi@0: return in_ByteSize(per_case_cell_count) * cell_size; aoqi@0: } aoqi@0: static ByteSize relative_count_offset() { aoqi@0: return in_ByteSize(relative_count_off_set) * cell_size; aoqi@0: } aoqi@0: static ByteSize relative_displacement_offset() { aoqi@0: return in_ByteSize(relative_displacement_off_set) * cell_size; aoqi@0: } aoqi@0: aoqi@0: #ifdef CC_INTERP aoqi@0: static void increment_count_no_overflow(DataLayout* layout, int index) { aoqi@0: if (index == -1) { aoqi@0: increment_array_uint_at_no_overflow(layout, default_count_off_set); aoqi@0: } else { aoqi@0: increment_array_uint_at_no_overflow(layout, case_array_start + aoqi@0: index * per_case_cell_count + aoqi@0: relative_count_off_set); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: static DataLayout* advance(DataLayout* layout, int index) { aoqi@0: if (index == -1) { aoqi@0: return (DataLayout*) (((address)layout) + (ssize_t)array_int_at(layout, default_disaplacement_off_set)); aoqi@0: } else { aoqi@0: return (DataLayout*) (((address)layout) + (ssize_t)array_int_at(layout, case_array_start + aoqi@0: index * per_case_cell_count + aoqi@0: relative_displacement_off_set)); aoqi@0: } aoqi@0: } aoqi@0: #endif // CC_INTERP aoqi@0: aoqi@0: // Specific initialization. aoqi@0: void post_initialize(BytecodeStream* stream, MethodData* mdo); aoqi@0: aoqi@0: #ifndef PRODUCT aoqi@0: void print_data_on(outputStream* st, const char* extra = NULL) const; aoqi@0: #endif aoqi@0: }; aoqi@0: aoqi@0: class ArgInfoData : public ArrayData { aoqi@0: aoqi@0: public: aoqi@0: ArgInfoData(DataLayout* layout) : ArrayData(layout) { aoqi@0: assert(layout->tag() == DataLayout::arg_info_data_tag, "wrong type"); aoqi@0: } aoqi@0: aoqi@0: virtual bool is_ArgInfoData() const { return true; } aoqi@0: aoqi@0: aoqi@0: int number_of_args() const { aoqi@0: return array_len(); aoqi@0: } aoqi@0: aoqi@0: uint arg_modified(int arg) const { aoqi@0: return array_uint_at(arg); aoqi@0: } aoqi@0: aoqi@0: void set_arg_modified(int arg, uint val) { aoqi@0: array_set_int_at(arg, val); aoqi@0: } aoqi@0: aoqi@0: #ifndef PRODUCT aoqi@0: void print_data_on(outputStream* st, const char* extra = NULL) const; aoqi@0: #endif aoqi@0: }; aoqi@0: aoqi@0: // ParametersTypeData aoqi@0: // aoqi@0: // A ParametersTypeData is used to access profiling information about aoqi@0: // types of parameters to a method aoqi@0: class ParametersTypeData : public ArrayData { aoqi@0: aoqi@0: private: aoqi@0: TypeStackSlotEntries _parameters; aoqi@0: aoqi@0: static int stack_slot_local_offset(int i) { aoqi@0: assert_profiling_enabled(); aoqi@0: return array_start_off_set + TypeStackSlotEntries::stack_slot_local_offset(i); aoqi@0: } aoqi@0: aoqi@0: static int type_local_offset(int i) { aoqi@0: assert_profiling_enabled(); aoqi@0: return array_start_off_set + TypeStackSlotEntries::type_local_offset(i); aoqi@0: } aoqi@0: aoqi@0: static bool profiling_enabled(); aoqi@0: static void assert_profiling_enabled() { aoqi@0: assert(profiling_enabled(), "method parameters profiling should be on"); aoqi@0: } aoqi@0: aoqi@0: public: aoqi@0: ParametersTypeData(DataLayout* layout) : ArrayData(layout), _parameters(1, number_of_parameters()) { aoqi@0: assert(layout->tag() == DataLayout::parameters_type_data_tag, "wrong type"); aoqi@0: // Some compilers (VC++) don't want this passed in member initialization list aoqi@0: _parameters.set_profile_data(this); aoqi@0: } aoqi@0: aoqi@0: static int compute_cell_count(Method* m); aoqi@0: aoqi@0: virtual bool is_ParametersTypeData() const { return true; } aoqi@0: aoqi@0: virtual void post_initialize(BytecodeStream* stream, MethodData* mdo); aoqi@0: aoqi@0: int number_of_parameters() const { aoqi@0: return array_len() / TypeStackSlotEntries::per_arg_count(); aoqi@0: } aoqi@0: aoqi@0: const TypeStackSlotEntries* parameters() const { return &_parameters; } aoqi@0: aoqi@0: uint stack_slot(int i) const { aoqi@0: return _parameters.stack_slot(i); aoqi@0: } aoqi@0: aoqi@0: void set_type(int i, Klass* k) { aoqi@0: intptr_t current = _parameters.type(i); aoqi@0: _parameters.set_type(i, TypeEntries::with_status((intptr_t)k, current)); aoqi@0: } aoqi@0: aoqi@0: virtual void clean_weak_klass_links(BoolObjectClosure* is_alive_closure) { aoqi@0: _parameters.clean_weak_klass_links(is_alive_closure); aoqi@0: } aoqi@0: aoqi@0: #ifndef PRODUCT aoqi@0: virtual void print_data_on(outputStream* st, const char* extra = NULL) const; aoqi@0: #endif aoqi@0: aoqi@0: static ByteSize stack_slot_offset(int i) { aoqi@0: return cell_offset(stack_slot_local_offset(i)); aoqi@0: } aoqi@0: aoqi@0: static ByteSize type_offset(int i) { aoqi@0: return cell_offset(type_local_offset(i)); aoqi@0: } aoqi@0: }; aoqi@0: aoqi@0: // SpeculativeTrapData aoqi@0: // aoqi@0: // A SpeculativeTrapData is used to record traps due to type aoqi@0: // speculation. It records the root of the compilation: that type aoqi@0: // speculation is wrong in the context of one compilation (for aoqi@0: // method1) doesn't mean it's wrong in the context of another one (for aoqi@0: // method2). Type speculation could have more/different data in the aoqi@0: // context of the compilation of method2 and it's worthwhile to try an aoqi@0: // optimization that failed for compilation of method1 in the context aoqi@0: // of compilation of method2. aoqi@0: // Space for SpeculativeTrapData entries is allocated from the extra aoqi@0: // data space in the MDO. If we run out of space, the trap data for aoqi@0: // the ProfileData at that bci is updated. aoqi@0: class SpeculativeTrapData : public ProfileData { aoqi@0: protected: aoqi@0: enum { aoqi@0: method_offset, aoqi@0: speculative_trap_cell_count aoqi@0: }; aoqi@0: public: aoqi@0: SpeculativeTrapData(DataLayout* layout) : ProfileData(layout) { aoqi@0: assert(layout->tag() == DataLayout::speculative_trap_data_tag, "wrong type"); aoqi@0: } aoqi@0: aoqi@0: virtual bool is_SpeculativeTrapData() const { return true; } aoqi@0: aoqi@0: static int static_cell_count() { aoqi@0: return speculative_trap_cell_count; aoqi@0: } aoqi@0: aoqi@0: virtual int cell_count() const { aoqi@0: return static_cell_count(); aoqi@0: } aoqi@0: aoqi@0: // Direct accessor aoqi@0: Method* method() const { aoqi@0: return (Method*)intptr_at(method_offset); aoqi@0: } aoqi@0: aoqi@0: void set_method(Method* m) { aoqi@0: set_intptr_at(method_offset, (intptr_t)m); aoqi@0: } aoqi@0: aoqi@0: #ifndef PRODUCT aoqi@0: virtual void print_data_on(outputStream* st, const char* extra = NULL) const; 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. Its layout looks like this: aoqi@0: // aoqi@0: // ----------------------------- aoqi@0: // | header | aoqi@0: // | klass | aoqi@0: // ----------------------------- aoqi@0: // | method | aoqi@0: // | size of the MethodData* | aoqi@0: // ----------------------------- aoqi@0: // | Data entries... | aoqi@0: // | (variable size) | aoqi@0: // | | aoqi@0: // . . aoqi@0: // . . aoqi@0: // . . aoqi@0: // | | aoqi@0: // ----------------------------- aoqi@0: // aoqi@0: // The data entry area is a heterogeneous array of DataLayouts. Each aoqi@0: // DataLayout in the array corresponds to a specific bytecode in the aoqi@0: // method. The entries in the array are sorted by the corresponding aoqi@0: // bytecode. Access to the data is via resource-allocated ProfileData, aoqi@0: // which point to the underlying blocks of DataLayout structures. aoqi@0: // aoqi@0: // During interpretation, if profiling in enabled, the interpreter aoqi@0: // maintains a method data pointer (mdp), which points at the entry aoqi@0: // in the array corresponding to the current bci. In the course of aoqi@0: // intepretation, when a bytecode is encountered that has profile data aoqi@0: // associated with it, the entry pointed to by mdp is updated, then the aoqi@0: // mdp is adjusted to point to the next appropriate DataLayout. If mdp aoqi@0: // is NULL to begin with, the interpreter assumes that the current method aoqi@0: // is not (yet) being profiled. aoqi@0: // aoqi@0: // In MethodData* parlance, "dp" is a "data pointer", the actual address aoqi@0: // of a DataLayout element. A "di" is a "data index", the offset in bytes aoqi@0: // from the base of the data entry array. A "displacement" is the byte offset aoqi@0: // in certain ProfileData objects that indicate the amount the mdp must be aoqi@0: // adjusted in the event of a change in control flow. aoqi@0: // aoqi@0: aoqi@0: CC_INTERP_ONLY(class BytecodeInterpreter;) roland@9183: class CleanExtraDataClosure; aoqi@0: aoqi@0: class MethodData : public Metadata { aoqi@0: friend class VMStructs; aoqi@0: CC_INTERP_ONLY(friend class BytecodeInterpreter;) aoqi@0: private: aoqi@0: friend class ProfileData; aoqi@0: aoqi@0: // Back pointer to the Method* aoqi@0: Method* _method; aoqi@0: aoqi@0: // Size of this oop in bytes aoqi@0: int _size; aoqi@0: aoqi@0: // Cached hint for bci_to_dp and bci_to_data aoqi@0: int _hint_di; aoqi@0: aoqi@0: Mutex _extra_data_lock; aoqi@0: aoqi@0: MethodData(methodHandle method, int size, TRAPS); aoqi@0: public: aoqi@0: static MethodData* allocate(ClassLoaderData* loader_data, methodHandle method, TRAPS); aoqi@0: MethodData() : _extra_data_lock(Monitor::leaf, "MDO extra data lock") {}; // For ciMethodData aoqi@0: aoqi@0: bool is_methodData() const volatile { return true; } aoqi@0: aoqi@0: // Whole-method sticky bits and flags aoqi@0: enum { rbackman@7153: _trap_hist_limit = 20, // decoupled from Deoptimization::Reason_LIMIT aoqi@0: _trap_hist_mask = max_jubyte, aoqi@0: _extra_data_count = 4 // extra DataLayout headers, for trap history aoqi@0: }; // Public flag values aoqi@0: private: aoqi@0: uint _nof_decompiles; // count of all nmethod removals aoqi@0: uint _nof_overflow_recompiles; // recompile count, excluding recomp. bits aoqi@0: uint _nof_overflow_traps; // trap count, excluding _trap_hist aoqi@0: union { aoqi@0: intptr_t _align; aoqi@0: u1 _array[_trap_hist_limit]; aoqi@0: } _trap_hist; aoqi@0: aoqi@0: // Support for interprocedural escape analysis, from Thomas Kotzmann. aoqi@0: intx _eflags; // flags on escape information aoqi@0: intx _arg_local; // bit set of non-escaping arguments aoqi@0: intx _arg_stack; // bit set of stack-allocatable arguments aoqi@0: intx _arg_returned; // bit set of returned arguments aoqi@0: aoqi@0: int _creation_mileage; // method mileage at MDO creation aoqi@0: aoqi@0: // How many invocations has this MDO seen? aoqi@0: // These counters are used to determine the exact age of MDO. aoqi@0: // We need those because in tiered a method can be concurrently aoqi@0: // executed at different levels. aoqi@0: InvocationCounter _invocation_counter; aoqi@0: // Same for backedges. aoqi@0: InvocationCounter _backedge_counter; aoqi@0: // Counter values at the time profiling started. aoqi@0: int _invocation_counter_start; aoqi@0: int _backedge_counter_start; aoqi@0: aoqi@0: #if INCLUDE_RTM_OPT aoqi@0: // State of RTM code generation during compilation of the method aoqi@0: int _rtm_state; aoqi@0: #endif aoqi@0: aoqi@0: // Number of loops and blocks is computed when compiling the first aoqi@0: // time with C1. It is used to determine if method is trivial. aoqi@0: short _num_loops; aoqi@0: short _num_blocks; aoqi@0: // Does this method contain anything worth profiling? thartmann@7365: enum WouldProfile {unknown, no_profile, profile}; thartmann@7365: WouldProfile _would_profile; aoqi@0: aoqi@0: // Size of _data array in bytes. (Excludes header and extra_data fields.) aoqi@0: int _data_size; aoqi@0: aoqi@0: // data index for the area dedicated to parameters. -1 if no aoqi@0: // parameter profiling. aoqi@0: int _parameters_type_data_di; aoqi@0: aoqi@0: // Beginning of the data entries aoqi@0: intptr_t _data[1]; aoqi@0: aoqi@0: // Helper for size computation aoqi@0: static int compute_data_size(BytecodeStream* stream); aoqi@0: static int bytecode_cell_count(Bytecodes::Code code); aoqi@0: static bool is_speculative_trap_bytecode(Bytecodes::Code code); aoqi@0: enum { no_profile_data = -1, variable_cell_count = -2 }; aoqi@0: aoqi@0: // Helper for initialization aoqi@0: DataLayout* data_layout_at(int data_index) const { aoqi@0: assert(data_index % sizeof(intptr_t) == 0, "unaligned"); aoqi@0: return (DataLayout*) (((address)_data) + data_index); aoqi@0: } aoqi@0: aoqi@0: // Initialize an individual data segment. Returns the size of aoqi@0: // the segment in bytes. aoqi@0: int initialize_data(BytecodeStream* stream, int data_index); aoqi@0: aoqi@0: // Helper for data_at aoqi@0: DataLayout* limit_data_position() const { aoqi@0: return (DataLayout*)((address)data_base() + _data_size); aoqi@0: } aoqi@0: bool out_of_bounds(int data_index) const { aoqi@0: return data_index >= data_size(); aoqi@0: } aoqi@0: aoqi@0: // Give each of the data entries a chance to perform specific aoqi@0: // data initialization. aoqi@0: void post_initialize(BytecodeStream* stream); aoqi@0: aoqi@0: // hint accessors aoqi@0: int hint_di() const { return _hint_di; } aoqi@0: void set_hint_di(int di) { aoqi@0: assert(!out_of_bounds(di), "hint_di out of bounds"); aoqi@0: _hint_di = di; aoqi@0: } aoqi@0: ProfileData* data_before(int bci) { aoqi@0: // avoid SEGV on this edge case aoqi@0: if (data_size() == 0) aoqi@0: return NULL; aoqi@0: int hint = hint_di(); aoqi@0: if (data_layout_at(hint)->bci() <= bci) aoqi@0: return data_at(hint); aoqi@0: return first_data(); aoqi@0: } aoqi@0: aoqi@0: // What is the index of the first data entry? aoqi@0: int first_di() const { return 0; } aoqi@0: aoqi@0: ProfileData* bci_to_extra_data_helper(int bci, Method* m, DataLayout*& dp, bool concurrent); aoqi@0: // Find or create an extra ProfileData: aoqi@0: ProfileData* bci_to_extra_data(int bci, Method* m, bool create_if_missing); aoqi@0: aoqi@0: // return the argument info cell aoqi@0: ArgInfoData *arg_info(); aoqi@0: aoqi@0: enum { aoqi@0: no_type_profile = 0, aoqi@0: type_profile_jsr292 = 1, aoqi@0: type_profile_all = 2 aoqi@0: }; aoqi@0: aoqi@0: static bool profile_jsr292(methodHandle m, int bci); aoqi@0: static int profile_arguments_flag(); aoqi@0: static bool profile_all_arguments(); aoqi@0: static bool profile_arguments_for_invoke(methodHandle m, int bci); aoqi@0: static int profile_return_flag(); aoqi@0: static bool profile_all_return(); aoqi@0: static bool profile_return_for_invoke(methodHandle m, int bci); aoqi@0: static int profile_parameters_flag(); aoqi@0: static bool profile_parameters_jsr292_only(); aoqi@0: static bool profile_all_parameters(); aoqi@0: roland@9183: void clean_extra_data(CleanExtraDataClosure* cl); aoqi@0: void clean_extra_data_helper(DataLayout* dp, int shift, bool reset = false); roland@9183: void verify_extra_data_clean(CleanExtraDataClosure* cl); aoqi@0: aoqi@0: public: aoqi@0: static int header_size() { aoqi@0: return sizeof(MethodData)/wordSize; aoqi@0: } aoqi@0: aoqi@0: // Compute the size of a MethodData* before it is created. aoqi@0: static int compute_allocation_size_in_bytes(methodHandle method); aoqi@0: static int compute_allocation_size_in_words(methodHandle method); aoqi@0: static int compute_extra_data_count(int data_size, int empty_bc_count, bool needs_speculative_traps); aoqi@0: aoqi@0: // Determine if a given bytecode can have profile information. aoqi@0: static bool bytecode_has_profile(Bytecodes::Code code) { aoqi@0: return bytecode_cell_count(code) != no_profile_data; aoqi@0: } aoqi@0: aoqi@0: // reset into original state aoqi@0: void init(); aoqi@0: aoqi@0: // My size aoqi@0: int size_in_bytes() const { return _size; } aoqi@0: int size() const { return align_object_size(align_size_up(_size, BytesPerWord)/BytesPerWord); } aoqi@0: #if INCLUDE_SERVICES aoqi@0: void collect_statistics(KlassSizeStats *sz) const; aoqi@0: #endif aoqi@0: aoqi@0: int creation_mileage() const { return _creation_mileage; } aoqi@0: void set_creation_mileage(int x) { _creation_mileage = x; } aoqi@0: aoqi@0: int invocation_count() { aoqi@0: if (invocation_counter()->carry()) { aoqi@0: return InvocationCounter::count_limit; aoqi@0: } aoqi@0: return invocation_counter()->count(); aoqi@0: } aoqi@0: int backedge_count() { aoqi@0: if (backedge_counter()->carry()) { aoqi@0: return InvocationCounter::count_limit; aoqi@0: } aoqi@0: return backedge_counter()->count(); aoqi@0: } aoqi@0: aoqi@0: int invocation_count_start() { aoqi@0: if (invocation_counter()->carry()) { aoqi@0: return 0; aoqi@0: } aoqi@0: return _invocation_counter_start; aoqi@0: } aoqi@0: aoqi@0: int backedge_count_start() { aoqi@0: if (backedge_counter()->carry()) { aoqi@0: return 0; aoqi@0: } aoqi@0: return _backedge_counter_start; aoqi@0: } aoqi@0: aoqi@0: int invocation_count_delta() { return invocation_count() - invocation_count_start(); } aoqi@0: int backedge_count_delta() { return backedge_count() - backedge_count_start(); } aoqi@0: aoqi@0: void reset_start_counters() { aoqi@0: _invocation_counter_start = invocation_count(); aoqi@0: _backedge_counter_start = backedge_count(); aoqi@0: } aoqi@0: aoqi@0: InvocationCounter* invocation_counter() { return &_invocation_counter; } aoqi@0: InvocationCounter* backedge_counter() { return &_backedge_counter; } aoqi@0: aoqi@0: #if INCLUDE_RTM_OPT aoqi@0: int rtm_state() const { aoqi@0: return _rtm_state; aoqi@0: } aoqi@0: void set_rtm_state(RTMState rstate) { aoqi@0: _rtm_state = (int)rstate; aoqi@0: } aoqi@0: void atomic_set_rtm_state(RTMState rstate) { aoqi@0: Atomic::store((int)rstate, &_rtm_state); aoqi@0: } aoqi@0: aoqi@0: static int rtm_state_offset_in_bytes() { aoqi@0: return offset_of(MethodData, _rtm_state); aoqi@0: } aoqi@0: #endif aoqi@0: thartmann@7365: void set_would_profile(bool p) { _would_profile = p ? profile : no_profile; } thartmann@7365: bool would_profile() const { return _would_profile != no_profile; } aoqi@0: aoqi@0: int num_loops() const { return _num_loops; } aoqi@0: void set_num_loops(int n) { _num_loops = n; } aoqi@0: int num_blocks() const { return _num_blocks; } aoqi@0: void set_num_blocks(int n) { _num_blocks = n; } aoqi@0: aoqi@0: bool is_mature() const; // consult mileage and ProfileMaturityPercentage aoqi@0: static int mileage_of(Method* m); aoqi@0: aoqi@0: // Support for interprocedural escape analysis, from Thomas Kotzmann. aoqi@0: enum EscapeFlag { aoqi@0: estimated = 1 << 0, aoqi@0: return_local = 1 << 1, aoqi@0: return_allocated = 1 << 2, aoqi@0: allocated_escapes = 1 << 3, aoqi@0: unknown_modified = 1 << 4 aoqi@0: }; aoqi@0: aoqi@0: intx eflags() { return _eflags; } aoqi@0: intx arg_local() { return _arg_local; } aoqi@0: intx arg_stack() { return _arg_stack; } aoqi@0: intx arg_returned() { return _arg_returned; } aoqi@0: uint arg_modified(int a) { ArgInfoData *aid = arg_info(); aoqi@0: assert(aid != NULL, "arg_info must be not null"); aoqi@0: assert(a >= 0 && a < aid->number_of_args(), "valid argument number"); aoqi@0: return aid->arg_modified(a); } aoqi@0: aoqi@0: void set_eflags(intx v) { _eflags = v; } aoqi@0: void set_arg_local(intx v) { _arg_local = v; } aoqi@0: void set_arg_stack(intx v) { _arg_stack = v; } aoqi@0: void set_arg_returned(intx v) { _arg_returned = v; } aoqi@0: void set_arg_modified(int a, uint v) { ArgInfoData *aid = arg_info(); aoqi@0: assert(aid != NULL, "arg_info must be not null"); aoqi@0: assert(a >= 0 && a < aid->number_of_args(), "valid argument number"); aoqi@0: aid->set_arg_modified(a, v); } aoqi@0: aoqi@0: void clear_escape_info() { _eflags = _arg_local = _arg_stack = _arg_returned = 0; } aoqi@0: aoqi@0: // Location and size of data area aoqi@0: address data_base() const { aoqi@0: return (address) _data; aoqi@0: } aoqi@0: int data_size() const { aoqi@0: return _data_size; aoqi@0: } aoqi@0: aoqi@0: // Accessors aoqi@0: Method* method() const { return _method; } aoqi@0: aoqi@0: // Get the data at an arbitrary (sort of) data index. aoqi@0: ProfileData* data_at(int data_index) const; aoqi@0: aoqi@0: // Walk through the data in order. aoqi@0: ProfileData* first_data() const { return data_at(first_di()); } aoqi@0: ProfileData* next_data(ProfileData* current) const; aoqi@0: bool is_valid(ProfileData* current) const { return current != NULL; } aoqi@0: aoqi@0: // Convert a dp (data pointer) to a di (data index). aoqi@0: int dp_to_di(address dp) const { aoqi@0: return dp - ((address)_data); aoqi@0: } aoqi@0: aoqi@0: address di_to_dp(int di) { aoqi@0: return (address)data_layout_at(di); aoqi@0: } aoqi@0: aoqi@0: // bci to di/dp conversion. aoqi@0: address bci_to_dp(int bci); aoqi@0: int bci_to_di(int bci) { aoqi@0: return dp_to_di(bci_to_dp(bci)); aoqi@0: } aoqi@0: aoqi@0: // Get the data at an arbitrary bci, or NULL if there is none. aoqi@0: ProfileData* bci_to_data(int bci); aoqi@0: aoqi@0: // Same, but try to create an extra_data record if one is needed: aoqi@0: ProfileData* allocate_bci_to_data(int bci, Method* m) { aoqi@0: ProfileData* data = NULL; aoqi@0: // If m not NULL, try to allocate a SpeculativeTrapData entry aoqi@0: if (m == NULL) { aoqi@0: data = bci_to_data(bci); aoqi@0: } aoqi@0: if (data != NULL) { aoqi@0: return data; aoqi@0: } aoqi@0: data = bci_to_extra_data(bci, m, true); aoqi@0: if (data != NULL) { aoqi@0: return data; aoqi@0: } aoqi@0: // If SpeculativeTrapData allocation fails try to allocate a aoqi@0: // regular entry aoqi@0: data = bci_to_data(bci); aoqi@0: if (data != NULL) { aoqi@0: return data; aoqi@0: } aoqi@0: return bci_to_extra_data(bci, NULL, true); aoqi@0: } aoqi@0: aoqi@0: // Add a handful of extra data records, for trap tracking. aoqi@0: DataLayout* extra_data_base() const { return limit_data_position(); } aoqi@0: DataLayout* extra_data_limit() const { return (DataLayout*)((address)this + size_in_bytes()); } aoqi@0: int extra_data_size() const { return (address)extra_data_limit() aoqi@0: - (address)extra_data_base(); } aoqi@0: static DataLayout* next_extra(DataLayout* dp); aoqi@0: aoqi@0: // Return (uint)-1 for overflow. aoqi@0: uint trap_count(int reason) const { aoqi@0: assert((uint)reason < _trap_hist_limit, "oob"); aoqi@0: return (int)((_trap_hist._array[reason]+1) & _trap_hist_mask) - 1; aoqi@0: } aoqi@0: // For loops: aoqi@0: static uint trap_reason_limit() { return _trap_hist_limit; } aoqi@0: static uint trap_count_limit() { return _trap_hist_mask; } aoqi@0: uint inc_trap_count(int reason) { aoqi@0: // Count another trap, anywhere in this method. aoqi@0: assert(reason >= 0, "must be single trap"); aoqi@0: if ((uint)reason < _trap_hist_limit) { aoqi@0: uint cnt1 = 1 + _trap_hist._array[reason]; aoqi@0: if ((cnt1 & _trap_hist_mask) != 0) { // if no counter overflow... aoqi@0: _trap_hist._array[reason] = cnt1; aoqi@0: return cnt1; aoqi@0: } else { aoqi@0: return _trap_hist_mask + (++_nof_overflow_traps); aoqi@0: } aoqi@0: } else { aoqi@0: // Could not represent the count in the histogram. aoqi@0: return (++_nof_overflow_traps); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: uint overflow_trap_count() const { aoqi@0: return _nof_overflow_traps; aoqi@0: } aoqi@0: uint overflow_recompile_count() const { aoqi@0: return _nof_overflow_recompiles; aoqi@0: } aoqi@0: void inc_overflow_recompile_count() { aoqi@0: _nof_overflow_recompiles += 1; aoqi@0: } aoqi@0: uint decompile_count() const { aoqi@0: return _nof_decompiles; aoqi@0: } aoqi@0: void inc_decompile_count() { aoqi@0: _nof_decompiles += 1; aoqi@0: if (decompile_count() > (uint)PerMethodRecompilationCutoff) { aoqi@0: method()->set_not_compilable(CompLevel_full_optimization, true, "decompile_count > PerMethodRecompilationCutoff"); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // Return pointer to area dedicated to parameters in MDO aoqi@0: ParametersTypeData* parameters_type_data() const { aoqi@0: return _parameters_type_data_di != -1 ? data_layout_at(_parameters_type_data_di)->data_in()->as_ParametersTypeData() : NULL; aoqi@0: } aoqi@0: aoqi@0: int parameters_type_data_di() const { aoqi@0: assert(_parameters_type_data_di != -1, "no args type data"); aoqi@0: return _parameters_type_data_di; aoqi@0: } aoqi@0: aoqi@0: // Support for code generation aoqi@0: static ByteSize data_offset() { aoqi@0: return byte_offset_of(MethodData, _data[0]); aoqi@0: } aoqi@0: aoqi@0: static ByteSize invocation_counter_offset() { aoqi@0: return byte_offset_of(MethodData, _invocation_counter); aoqi@0: } aoqi@0: static ByteSize backedge_counter_offset() { aoqi@0: return byte_offset_of(MethodData, _backedge_counter); aoqi@0: } aoqi@0: aoqi@0: static ByteSize parameters_type_data_di_offset() { aoqi@0: return byte_offset_of(MethodData, _parameters_type_data_di); aoqi@0: } aoqi@0: aoqi@0: // Deallocation support - no pointer fields to deallocate aoqi@0: void deallocate_contents(ClassLoaderData* loader_data) {} aoqi@0: aoqi@0: // GC support aoqi@0: void set_size(int object_size_in_bytes) { _size = object_size_in_bytes; } aoqi@0: aoqi@0: // Printing aoqi@0: #ifndef PRODUCT aoqi@0: void print_on (outputStream* st) const; aoqi@0: #endif aoqi@0: void print_value_on(outputStream* st) const; aoqi@0: aoqi@0: #ifndef PRODUCT aoqi@0: // printing support for method data aoqi@0: void print_data_on(outputStream* st) const; aoqi@0: #endif aoqi@0: aoqi@0: const char* internal_name() const { return "{method data}"; } aoqi@0: aoqi@0: // verification aoqi@0: void verify_on(outputStream* st); aoqi@0: void verify_data_on(outputStream* st); aoqi@0: aoqi@0: static bool profile_parameters_for_method(methodHandle m); aoqi@0: static bool profile_arguments(); aoqi@0: static bool profile_arguments_jsr292_only(); aoqi@0: static bool profile_return(); aoqi@0: static bool profile_parameters(); aoqi@0: static bool profile_return_jsr292_only(); aoqi@0: aoqi@0: void clean_method_data(BoolObjectClosure* is_alive); roland@9183: roland@9183: void clean_weak_method_links(); aoqi@0: }; aoqi@0: aoqi@0: #endif // SHARE_VM_OOPS_METHODDATAOOP_HPP