/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
#ifndef SHARE_VM_OOPS_METHODDATAOOP_HPP
#define SHARE_VM_OOPS_METHODDATAOOP_HPP
#include "interpreter/bytecodes.hpp"
#include "memory/universe.hpp"
#include "oops/methodOop.hpp"
#include "runtime/orderAccess.hpp"
class BytecodeStream;
// The MethodData object collects counts and other profile information
// during zeroth-tier (interpretive) and first-tier execution.
// The profile is used later by compilation heuristics. Some heuristics
// enable use of aggressive (or "heroic") optimizations. An aggressive
// optimization often has a down-side, a corner case that it handles
// poorly, but which is thought to be rare. The profile provides
// evidence of this rarity for a given method or even BCI. It allows
// the compiler to back out of the optimization at places where it
// has historically been a poor choice. Other heuristics try to use
// specific information gathered about types observed at a given site.
//
// All data in the profile is approximate. It is expected to be accurate
// on the whole, but the system expects occasional inaccuraces, due to
// counter overflow, multiprocessor races during data collection, space
// limitations, missing MDO blocks, etc. Bad or missing data will degrade
// optimization quality but will not affect correctness. Also, each MDO
// is marked with its birth-date ("creation_mileage") which can be used
// to assess the quality ("maturity") of its data.
//
// Short (<32-bit) counters are designed to overflow to a known "saturated"
// state. Also, certain recorded per-BCI events are given one-bit counters
// which overflow to a saturated state which applied to all counters at
// that BCI. In other words, there is a small lattice which approximates
// the ideal of an infinite-precision counter for each event at each BCI,
// and the lattice quickly "bottoms out" in a state where all counters
// are taken to be indefinitely large.
//
// The reader will find many data races in profile gathering code, starting
// with invocation counter incrementation. None of these races harm correct
// execution of the compiled code.
// forward decl
class ProfileData;
// DataLayout
//
// Overlay for generic profiling data.
private:
// Every data layout begins with a header. This header
// of the data, 4 bits of flags, which can be used in any way,
// and a bci, which is used to tie this piece of data to a
// specific bci in the bytecodes.
union {
struct {
} _struct;
} _header;
// The data layout has an arbitrary number of cells, each sized
// to accomodate a pointer or an integer.
// Some types of data layouts need a length field.
public:
enum {
};
enum {
};
// Tag values
enum {
};
enum {
// The _struct._flags word is formatted as [trap_state:4 | flags:4].
// The trap state breaks down further as [recompile:1 | reason:3].
// This further breakdown is defined in deoptimization.cpp.
// See Deoptimization::trap_state_reason for an assert that
// trap_bits is big enough to hold reasons < Reason_RECORDED_LIMIT.
//
// The trap_state is collected only if ProfileTraps is true.
first_flag = 0
};
// Size computation
static int header_size_in_bytes() {
return cell_size;
}
static int header_size_in_cells() {
return 1;
}
}
// Initialization
// Accessors
}
// Return a few bits of trap state. Range is [0..trap_mask].
// The state tells if traps with zero, one, or many reasons have occurred.
// It also tells whether zero or many recompilations have occurred.
// The associated trap histogram in the MDO itself tells whether
// traps are common or not. If a BCI shows that a trap X has
// occurred, and the MDO shows N occurrences of X, we make the
// simplifying assumption that all N occurrences can be blamed
// on that BCI.
int trap_state() {
}
}
}
}
}
}
}
}
}
}
}
}
}
bool flag_at(int flag_number) {
}
// Low-level support for code generation.
static ByteSize header_offset() {
}
static ByteSize tag_offset() {
}
static ByteSize flags_offset() {
}
static ByteSize bci_offset() {
}
}
// Return a value which, when or-ed as a byte into _flags, sets the flag.
static int flag_number_to_byte_constant(int flag_number) {
}
// Return a value which, when or-ed as a word into _header, sets the flag.
}
// GC support
ProfileData* data_in();
};
// ProfileData class hierarchy
class ProfileData;
class BitData;
class CounterData;
class ReceiverTypeData;
class VirtualCallData;
class RetData;
class JumpData;
class BranchData;
class ArrayData;
class MultiBranchData;
class ArgInfoData;
// ProfileData
//
// A ProfileData object is created to refer to a section of profiling
// data in a structured way.
class ProfileData : public ResourceObj {
private:
#ifndef PRODUCT
enum {
tab_width_one = 16,
tab_width_two = 36
};
#endif // !PRODUCT
// This is a pointer to a section of profiling data.
protected:
enum {
};
public:
// How many cells are in this?
virtual int cell_count() {
return -1;
}
// Return the size of this data.
int size_in_bytes() {
}
protected:
// Low-level accessors for underlying data
}
}
}
}
}
}
}
}
}
int int_at_unchecked(int index) {
}
}
}
}
void set_flag_at(int flag_number) {
}
bool flag_at(int flag_number) {
}
// two convenient imports for use by subclasses:
}
static int flag_number_to_byte_constant(int flag_number) {
}
}
public:
// Constructor for invalid ProfileData.
ProfileData();
}
}
int trap_state() {
return data()->trap_state();
}
void set_trap_state(int new_state) {
}
// Type checking
virtual bool is_BitData() { return false; }
virtual bool is_CounterData() { return false; }
virtual bool is_JumpData() { return false; }
virtual bool is_ReceiverTypeData(){ return false; }
virtual bool is_VirtualCallData() { return false; }
virtual bool is_RetData() { return false; }
virtual bool is_BranchData() { return false; }
virtual bool is_ArrayData() { return false; }
virtual bool is_MultiBranchData() { return false; }
virtual bool is_ArgInfoData() { return false; }
BitData* as_BitData() {
}
}
JumpData* as_JumpData() {
}
}
}
RetData* as_RetData() {
}
BranchData* as_BranchData() {
}
ArrayData* as_ArrayData() {
}
}
}
// Subclass specific initialization
// GC support
virtual void follow_contents() {}
virtual void adjust_pointers() {}
#ifndef SERIALGC
// Parallel old support
virtual void update_pointers() {}
#endif // SERIALGC
// CI translation: ProfileData can represent both MethodDataOop data
// as well as CIMethodData data. This function is provided for translating
// an oop in a ProfileData to the ci equivalent. Generally speaking,
// most ProfileData don't require any translation, so we provide the null
// translation here, and the required translators are in the ci subclasses.
}
#ifndef PRODUCT
#endif
};
// BitData
//
// A BitData holds a flag or two in its header.
class BitData : public ProfileData {
protected:
enum {
// null_seen:
// saw a null operand (cast/aastore/instanceof)
};
enum { bit_cell_count = 0 }; // no additional data fields needed.
public:
}
virtual bool is_BitData() { return true; }
static int static_cell_count() {
return bit_cell_count;
}
virtual int cell_count() {
return static_cell_count();
}
// Accessor
// The null_seen flag bit is specially known to the interpreter.
// Consulting it allows the compiler to avoid setting up null_check traps.
// Code generation support
static int null_seen_byte_constant() {
}
static ByteSize bit_data_size() {
return cell_offset(bit_cell_count);
}
#ifndef PRODUCT
#endif
};
// CounterData
//
// A CounterData corresponds to a simple counter.
class CounterData : public BitData {
protected:
enum {
};
public:
virtual bool is_CounterData() { return true; }
static int static_cell_count() {
return counter_cell_count;
}
virtual int cell_count() {
return static_cell_count();
}
// Direct accessor
}
// Code generation support
static ByteSize count_offset() {
return cell_offset(count_off);
}
static ByteSize counter_data_size() {
return cell_offset(counter_cell_count);
}
}
#ifndef PRODUCT
#endif
};
// JumpData
//
// A JumpData is used to access profiling information for a direct
// branch. It is a counter, used for counting the number of branches,
// plus a data displacement, used for realigning the data pointer to
// the corresponding target bci.
class JumpData : public ProfileData {
protected:
enum {
};
void set_displacement(int displacement) {
}
public:
}
virtual bool is_JumpData() { return true; }
static int static_cell_count() {
return jump_cell_count;
}
virtual int cell_count() {
return static_cell_count();
}
// Direct accessor
return uint_at(taken_off_set);
}
}
// Saturating counter
// Did we wrap? Will compiler screw us??
return cnt;
}
int displacement() {
return int_at(displacement_off_set);
}
// Code generation support
static ByteSize taken_offset() {
return cell_offset(taken_off_set);
}
static ByteSize displacement_offset() {
return cell_offset(displacement_off_set);
}
// Specific initialization.
#ifndef PRODUCT
#endif
};
// ReceiverTypeData
//
// A ReceiverTypeData is used to access profiling information about a
// dynamic type check. It consists of a counter which counts the total times
// that the check is reached, and a series of (klassOop, count) pairs
// which are used to store a type profile for the receiver of the check.
class ReceiverTypeData : public CounterData {
protected:
enum {
};
public:
}
virtual bool is_ReceiverTypeData() { return true; }
static int static_cell_count() {
}
virtual int cell_count() {
return static_cell_count();
}
// Direct accessors
return TypeProfileWidth;
}
}
}
// Get the receiver at row. The 'unchecked' version is needed by parallel old
// gc; it does not assert the receiver is a klass. During compaction of the
// perm gen, the klass may already have moved, so the is_klass() predicate
// would fail. The 'normal' version should be used whenever possible.
}
return recv;
}
}
}
}
// Clear total count - indicator of polymorphic call site.
// The site may look like as monomorphic after that but
// it allow to have more accurate profiling information because
// there was execution phase change since klasses were unloaded.
// If the site is still polymorphic then MDO will be updated
// to reflect it. But it could be the case that the site becomes
// only bimorphic. Then keeping total count not 0 will be wrong.
// Even if we use monomorphic (when it is not) for compilation
// we will only have trap, deoptimization and recompile again
// with updated MDO after executing method in Interpreter.
// An additional receiver will be recorded in the cleaned row
// during next call execution.
//
// Note: our profiling logic works with empty rows in any slot.
// We do sorting a profiling info (ciCallProfile) for compilation.
//
set_count(0);
set_receiver_count(row, 0);
}
// Code generation support
}
}
static ByteSize receiver_type_data_size() {
return cell_offset(static_cell_count());
}
// GC support
virtual void follow_contents();
virtual void adjust_pointers();
#ifndef SERIALGC
// Parallel old support
virtual void update_pointers();
#endif // SERIALGC
}
#ifndef PRODUCT
#endif
};
// VirtualCallData
//
// A VirtualCallData is used to access profiling information about a
// virtual call. For now, it has nothing more than a ReceiverTypeData.
class VirtualCallData : public ReceiverTypeData {
public:
}
virtual bool is_VirtualCallData() { return true; }
static int static_cell_count() {
// At this point we could add more profile state, e.g., for arguments.
// But for now it's the same size as the base record type.
return ReceiverTypeData::static_cell_count();
}
virtual int cell_count() {
return static_cell_count();
}
// Direct accessors
static ByteSize virtual_call_data_size() {
return cell_offset(static_cell_count());
}
#ifndef PRODUCT
#endif
};
// RetData
//
// A RetData is used to access profiling information for a ret bytecode.
// It is composed of a count of the number of times that the ret has
// been executed, followed by a series of triples of the form
// (bci, count, di) which count the number of times that some bci was the
// target of the ret and cache a corresponding data displacement.
class RetData : public CounterData {
protected:
enum {
};
}
// 'release' when setting the bci acts as a valid flag for other
// threads wrt bci_count and bci_displacement.
}
}
}
public:
}
virtual bool is_RetData() { return true; }
enum {
};
static int static_cell_count() {
}
virtual int cell_count() {
return static_cell_count();
}
return BciProfileWidth;
}
}
}
}
// Direct accessors
}
}
}
// Interpreter Runtime support
// Code generation support
}
}
}
// Specific initialization.
#ifndef PRODUCT
#endif
};
// BranchData
//
// A BranchData is used to access profiling data for a two-way branch.
// It consists of taken and not_taken counts as well as a data displacement
// for the taken case.
class BranchData : public JumpData {
protected:
enum {
};
void set_displacement(int displacement) {
}
public:
}
virtual bool is_BranchData() { return true; }
static int static_cell_count() {
return branch_cell_count;
}
virtual int cell_count() {
return static_cell_count();
}
// Direct accessor
return uint_at(not_taken_off_set);
}
}
uint inc_not_taken() {
// Did we wrap? Will compiler screw us??
return cnt;
}
// Code generation support
static ByteSize not_taken_offset() {
return cell_offset(not_taken_off_set);
}
static ByteSize branch_data_size() {
return cell_offset(branch_cell_count);
}
// Specific initialization.
#ifndef PRODUCT
#endif
};
// ArrayData
//
// A ArrayData is a base class for accessing profiling data which does
// not have a statically known size. It consists of an array length
// and an array start.
class ArrayData : public ProfileData {
protected:
friend class DataLayout;
enum {
};
}
int array_int_at(int index) {
}
}
}
// Code generation support for subclasses.
}
public:
virtual bool is_ArrayData() { return true; }
static int static_cell_count() {
return -1;
}
int array_len() {
return int_at_unchecked(array_len_off_set);
}
virtual int cell_count() {
return array_len() + 1;
}
// Code generation support
static ByteSize array_len_offset() {
return cell_offset(array_len_off_set);
}
static ByteSize array_start_offset() {
return cell_offset(array_start_off_set);
}
};
// MultiBranchData
//
// A MultiBranchData is used to access profiling information for
// a multi-way branch (*switch bytecodes). It consists of a series
// of (count, displacement) pairs, which count the number of times each
// case was taken and specify the data displacment for each branch target.
class MultiBranchData : public ArrayData {
protected:
enum {
};
enum {
};
void set_default_displacement(int displacement) {
}
}
public:
}
virtual bool is_MultiBranchData() { return true; }
int number_of_cases() {
return (alen / per_case_cell_count);
}
uint default_count() {
return array_uint_at(default_count_off_set);
}
int default_displacement() {
}
return array_uint_at(case_array_start +
}
int displacement_at(int index) {
return array_int_at(case_array_start +
}
// Code generation support
static ByteSize default_count_offset() {
}
static ByteSize default_displacement_offset() {
}
return case_array_offset() +
(per_case_size() * index) +
}
static ByteSize case_array_offset() {
return array_element_offset(case_array_start);
}
static ByteSize per_case_size() {
}
static ByteSize relative_count_offset() {
}
static ByteSize relative_displacement_offset() {
}
// Specific initialization.
#ifndef PRODUCT
#endif
};
class ArgInfoData : public ArrayData {
public:
}
virtual bool is_ArgInfoData() { return true; }
int number_of_args() {
return array_len();
}
return array_uint_at(arg);
}
}
#ifndef PRODUCT
#endif
};
// methodDataOop
//
// A methodDataOop holds information which has been collected about
// a method. Its layout looks like this:
//
// -----------------------------
// | header |
// | klass |
// -----------------------------
// | method |
// | size of the methodDataOop |
// -----------------------------
// | Data entries... |
// | (variable size) |
// | |
// . .
// . .
// . .
// | |
// -----------------------------
//
// The data entry area is a heterogeneous array of DataLayouts. Each
// DataLayout in the array corresponds to a specific bytecode in the
// method. The entries in the array are sorted by the corresponding
// bytecode. Access to the data is via resource-allocated ProfileData,
// which point to the underlying blocks of DataLayout structures.
//
// During interpretation, if profiling in enabled, the interpreter
// maintains a method data pointer (mdp), which points at the entry
// in the array corresponding to the current bci. In the course of
// intepretation, when a bytecode is encountered that has profile data
// associated with it, the entry pointed to by mdp is updated, then the
// mdp is adjusted to point to the next appropriate DataLayout. If mdp
// is NULL to begin with, the interpreter assumes that the current method
// is not (yet) being profiled.
//
// In methodDataOop parlance, "dp" is a "data pointer", the actual address
// of a DataLayout element. A "di" is a "data index", the offset in bytes
// from the base of the data entry array. A "displacement" is the byte offset
// in certain ProfileData objects that indicate the amount the mdp must be
// adjusted in the event of a change in control flow.
//
class methodDataOopDesc : public oopDesc {
friend class VMStructs;
private:
friend class ProfileData;
// Back pointer to the methodOop
// Size of this oop in bytes
int _size;
// Cached hint for bci_to_dp and bci_to_data
int _hint_di;
// Whole-method sticky bits and flags
public:
enum {
}; // Public flag values
private:
union {
} _trap_hist;
// Support for interprocedural escape analysis, from Thomas Kotzmann.
int _creation_mileage; // method mileage at MDO creation
// How many invocations has this MDO seen?
// These counters are used to determine the exact age of MDO.
// We need those because in tiered a method can be concurrently
// executed at different levels.
// Same for backedges.
// Counter values at the time profiling started.
// Number of loops and blocks is computed when compiling the first
// time with C1. It is used to determine if method is trivial.
short _num_loops;
short _num_blocks;
// Highest compile level this method has ever seen.
// Same for OSR level
// Does this method contain anything worth profiling?
bool _would_profile;
// Size of _data array in bytes. (Excludes header and extra_data fields.)
int _data_size;
// Beginning of the data entries
// Helper for size computation
// Helper for initialization
}
// Initialize an individual data segment. Returns the size of
// the segment in bytes.
// Helper for data_at
}
bool out_of_bounds(int data_index) {
return data_index >= data_size();
}
// Give each of the data entries a chance to perform specific
// data initialization.
// hint accessors
void set_hint_di(int di) {
}
// avoid SEGV on this edge case
if (data_size() == 0)
return NULL;
return first_data();
}
// What is the index of the first data entry?
int first_di() { return 0; }
// Find or create an extra ProfileData:
// return the argument info cell
ArgInfoData *arg_info();
public:
static int header_size() {
return sizeof(methodDataOopDesc)/wordSize;
}
// Compute the size of a methodDataOop before it is created.
// Determine if a given bytecode can have profile information.
}
// Perform initialization of a new methodDataOop
// My size
int object_size_in_bytes() { return _size; }
int object_size() {
}
int creation_mileage() const { return _creation_mileage; }
void set_creation_mileage(int x) { _creation_mileage = x; }
int invocation_count() {
if (invocation_counter()->carry()) {
return InvocationCounter::count_limit;
}
return invocation_counter()->count();
}
int backedge_count() {
return InvocationCounter::count_limit;
}
return backedge_counter()->count();
}
int invocation_count_start() {
if (invocation_counter()->carry()) {
return 0;
}
return _invocation_counter_start;
}
int backedge_count_start() {
if (backedge_counter()->carry()) {
return 0;
}
return _backedge_counter_start;
}
void reset_start_counters() {
}
bool is_mature() const; // consult mileage and ProfileMaturityPercentage
static int mileage_of(methodOop m);
// Support for interprocedural escape analysis, from Thomas Kotzmann.
enum EscapeFlag {
};
return aid->arg_modified(a); }
aid->set_arg_modified(a, v); }
// Location and size of data area
}
int data_size() {
return _data_size;
}
// Accessors
// Get the data at an arbitrary (sort of) data index.
// Walk through the data in order.
// Convert a dp (data pointer) to a di (data index).
}
}
}
// Get the data at an arbitrary bci, or NULL if there is none.
// Same, but try to create an extra_data record if one is needed:
}
// Add a handful of extra data records, for trap tracking.
- (address)extra_data_base(); }
static DataLayout* next_extra(DataLayout* dp) { return (DataLayout*)((address)dp + in_bytes(DataLayout::cell_offset(0))); }
// Return (uint)-1 for overflow.
}
// For loops:
// Count another trap, anywhere in this method.
return cnt1;
} else {
return _trap_hist_mask + (++_nof_overflow_traps);
}
} else {
// Could not represent the count in the histogram.
return (++_nof_overflow_traps);
}
}
return _nof_overflow_traps;
}
return _nof_overflow_recompiles;
}
void inc_overflow_recompile_count() {
_nof_overflow_recompiles += 1;
}
return _nof_decompiles;
}
void inc_decompile_count() {
_nof_decompiles += 1;
method()->set_not_compilable(CompLevel_full_optimization, true, "decompile_count > PerMethodRecompilationCutoff");
}
}
// Support for code generation
}
}
}
// GC support
#ifndef PRODUCT
// printing support for method data
#endif
// verification
};
#endif // SHARE_VM_OOPS_METHODDATAOOP_HPP