src/share/vm/oops/methodData.hpp

Sun, 15 Sep 2013 15:28:58 +0200

author
goetz
date
Sun, 15 Sep 2013 15:28:58 +0200
changeset 6470
abe03600372a
parent 5097
92ef81e2f571
child 6472
2b8e28fdf503
permissions
-rw-r--r--

8024468: PPC64 (part 201): cppInterpreter: implement bytecode profiling
Summary: Implement profiling for c2 jit compilation. Also enable new cppInterpreter features.
Reviewed-by: kvn

     1 /*
     2  * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     8  *
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    12  * version 2 for more details (a copy is included in the LICENSE file that
    13  * accompanied this code).
    14  *
    15  * You should have received a copy of the GNU General Public License version
    16  * 2 along with this work; if not, write to the Free Software Foundation,
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    18  *
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    22  *
    23  */
    25 #ifndef SHARE_VM_OOPS_METHODDATAOOP_HPP
    26 #define SHARE_VM_OOPS_METHODDATAOOP_HPP
    28 #include "interpreter/bytecodes.hpp"
    29 #include "memory/universe.hpp"
    30 #include "oops/method.hpp"
    31 #include "oops/oop.hpp"
    32 #include "runtime/orderAccess.hpp"
    34 class BytecodeStream;
    35 class KlassSizeStats;
    37 // The MethodData object collects counts and other profile information
    38 // during zeroth-tier (interpretive) and first-tier execution.
    39 // The profile is used later by compilation heuristics.  Some heuristics
    40 // enable use of aggressive (or "heroic") optimizations.  An aggressive
    41 // optimization often has a down-side, a corner case that it handles
    42 // poorly, but which is thought to be rare.  The profile provides
    43 // evidence of this rarity for a given method or even BCI.  It allows
    44 // the compiler to back out of the optimization at places where it
    45 // has historically been a poor choice.  Other heuristics try to use
    46 // specific information gathered about types observed at a given site.
    47 //
    48 // All data in the profile is approximate.  It is expected to be accurate
    49 // on the whole, but the system expects occasional inaccuraces, due to
    50 // counter overflow, multiprocessor races during data collection, space
    51 // limitations, missing MDO blocks, etc.  Bad or missing data will degrade
    52 // optimization quality but will not affect correctness.  Also, each MDO
    53 // is marked with its birth-date ("creation_mileage") which can be used
    54 // to assess the quality ("maturity") of its data.
    55 //
    56 // Short (<32-bit) counters are designed to overflow to a known "saturated"
    57 // state.  Also, certain recorded per-BCI events are given one-bit counters
    58 // which overflow to a saturated state which applied to all counters at
    59 // that BCI.  In other words, there is a small lattice which approximates
    60 // the ideal of an infinite-precision counter for each event at each BCI,
    61 // and the lattice quickly "bottoms out" in a state where all counters
    62 // are taken to be indefinitely large.
    63 //
    64 // The reader will find many data races in profile gathering code, starting
    65 // with invocation counter incrementation.  None of these races harm correct
    66 // execution of the compiled code.
    68 // forward decl
    69 class ProfileData;
    71 // DataLayout
    72 //
    73 // Overlay for generic profiling data.
    74 class DataLayout VALUE_OBJ_CLASS_SPEC {
    75 private:
    76   // Every data layout begins with a header.  This header
    77   // contains a tag, which is used to indicate the size/layout
    78   // of the data, 4 bits of flags, which can be used in any way,
    79   // 4 bits of trap history (none/one reason/many reasons),
    80   // and a bci, which is used to tie this piece of data to a
    81   // specific bci in the bytecodes.
    82   union {
    83     intptr_t _bits;
    84     struct {
    85       u1 _tag;
    86       u1 _flags;
    87       u2 _bci;
    88     } _struct;
    89   } _header;
    91   // The data layout has an arbitrary number of cells, each sized
    92   // to accomodate a pointer or an integer.
    93   intptr_t _cells[1];
    95   // Some types of data layouts need a length field.
    96   static bool needs_array_len(u1 tag);
    98 public:
    99   enum {
   100     counter_increment = 1
   101   };
   103   enum {
   104     cell_size = sizeof(intptr_t)
   105   };
   107   // Tag values
   108   enum {
   109     no_tag,
   110     bit_data_tag,
   111     counter_data_tag,
   112     jump_data_tag,
   113     receiver_type_data_tag,
   114     virtual_call_data_tag,
   115     ret_data_tag,
   116     branch_data_tag,
   117     multi_branch_data_tag,
   118     arg_info_data_tag
   119   };
   121   enum {
   122     // The _struct._flags word is formatted as [trap_state:4 | flags:4].
   123     // The trap state breaks down further as [recompile:1 | reason:3].
   124     // This further breakdown is defined in deoptimization.cpp.
   125     // See Deoptimization::trap_state_reason for an assert that
   126     // trap_bits is big enough to hold reasons < Reason_RECORDED_LIMIT.
   127     //
   128     // The trap_state is collected only if ProfileTraps is true.
   129     trap_bits = 1+3,  // 3: enough to distinguish [0..Reason_RECORDED_LIMIT].
   130     trap_shift = BitsPerByte - trap_bits,
   131     trap_mask = right_n_bits(trap_bits),
   132     trap_mask_in_place = (trap_mask << trap_shift),
   133     flag_limit = trap_shift,
   134     flag_mask = right_n_bits(flag_limit),
   135     first_flag = 0
   136   };
   138   // Size computation
   139   static int header_size_in_bytes() {
   140     return cell_size;
   141   }
   142   static int header_size_in_cells() {
   143     return 1;
   144   }
   146   static int compute_size_in_bytes(int cell_count) {
   147     return header_size_in_bytes() + cell_count * cell_size;
   148   }
   150   // Initialization
   151   void initialize(u1 tag, u2 bci, int cell_count);
   153   // Accessors
   154   u1 tag() {
   155     return _header._struct._tag;
   156   }
   158   // Return a few bits of trap state.  Range is [0..trap_mask].
   159   // The state tells if traps with zero, one, or many reasons have occurred.
   160   // It also tells whether zero or many recompilations have occurred.
   161   // The associated trap histogram in the MDO itself tells whether
   162   // traps are common or not.  If a BCI shows that a trap X has
   163   // occurred, and the MDO shows N occurrences of X, we make the
   164   // simplifying assumption that all N occurrences can be blamed
   165   // on that BCI.
   166   int trap_state() {
   167     return ((_header._struct._flags >> trap_shift) & trap_mask);
   168   }
   170   void set_trap_state(int new_state) {
   171     assert(ProfileTraps, "used only under +ProfileTraps");
   172     uint old_flags = (_header._struct._flags & flag_mask);
   173     _header._struct._flags = (new_state << trap_shift) | old_flags;
   174   }
   176   u1 flags() {
   177     return _header._struct._flags;
   178   }
   180   u2 bci() {
   181     return _header._struct._bci;
   182   }
   184   void set_header(intptr_t value) {
   185     _header._bits = value;
   186   }
   187   void release_set_header(intptr_t value) {
   188     OrderAccess::release_store_ptr(&_header._bits, value);
   189   }
   190   intptr_t header() {
   191     return _header._bits;
   192   }
   193   void set_cell_at(int index, intptr_t value) {
   194     _cells[index] = value;
   195   }
   196   void release_set_cell_at(int index, intptr_t value) {
   197     OrderAccess::release_store_ptr(&_cells[index], value);
   198   }
   199   intptr_t cell_at(int index) {
   200     return _cells[index];
   201   }
   203   void set_flag_at(int flag_number) {
   204     assert(flag_number < flag_limit, "oob");
   205     _header._struct._flags |= (0x1 << flag_number);
   206   }
   207   bool flag_at(int flag_number) {
   208     assert(flag_number < flag_limit, "oob");
   209     return (_header._struct._flags & (0x1 << flag_number)) != 0;
   210   }
   212   // Low-level support for code generation.
   213   static ByteSize header_offset() {
   214     return byte_offset_of(DataLayout, _header);
   215   }
   216   static ByteSize tag_offset() {
   217     return byte_offset_of(DataLayout, _header._struct._tag);
   218   }
   219   static ByteSize flags_offset() {
   220     return byte_offset_of(DataLayout, _header._struct._flags);
   221   }
   222   static ByteSize bci_offset() {
   223     return byte_offset_of(DataLayout, _header._struct._bci);
   224   }
   225   static ByteSize cell_offset(int index) {
   226     return byte_offset_of(DataLayout, _cells) + in_ByteSize(index * cell_size);
   227   }
   228 #ifdef CC_INTERP
   229   static int cell_offset_in_bytes(int index) {
   230     return (int)offset_of(DataLayout, _cells[index]);
   231   }
   232 #endif // CC_INTERP
   233   // Return a value which, when or-ed as a byte into _flags, sets the flag.
   234   static int flag_number_to_byte_constant(int flag_number) {
   235     assert(0 <= flag_number && flag_number < flag_limit, "oob");
   236     DataLayout temp; temp.set_header(0);
   237     temp.set_flag_at(flag_number);
   238     return temp._header._struct._flags;
   239   }
   240   // Return a value which, when or-ed as a word into _header, sets the flag.
   241   static intptr_t flag_mask_to_header_mask(int byte_constant) {
   242     DataLayout temp; temp.set_header(0);
   243     temp._header._struct._flags = byte_constant;
   244     return temp._header._bits;
   245   }
   247   ProfileData* data_in();
   249   // GC support
   250   void clean_weak_klass_links(BoolObjectClosure* cl);
   251 };
   254 // ProfileData class hierarchy
   255 class ProfileData;
   256 class   BitData;
   257 class     CounterData;
   258 class       ReceiverTypeData;
   259 class         VirtualCallData;
   260 class       RetData;
   261 class   JumpData;
   262 class     BranchData;
   263 class   ArrayData;
   264 class     MultiBranchData;
   265 class     ArgInfoData;
   268 // ProfileData
   269 //
   270 // A ProfileData object is created to refer to a section of profiling
   271 // data in a structured way.
   272 class ProfileData : public ResourceObj {
   273 private:
   274 #ifndef PRODUCT
   275   enum {
   276     tab_width_one = 16,
   277     tab_width_two = 36
   278   };
   279 #endif // !PRODUCT
   281   // This is a pointer to a section of profiling data.
   282   DataLayout* _data;
   284 protected:
   285   DataLayout* data() { return _data; }
   287   enum {
   288     cell_size = DataLayout::cell_size
   289   };
   291 public:
   292   // How many cells are in this?
   293   virtual int cell_count() {
   294     ShouldNotReachHere();
   295     return -1;
   296   }
   298   // Return the size of this data.
   299   int size_in_bytes() {
   300     return DataLayout::compute_size_in_bytes(cell_count());
   301   }
   303 protected:
   304   // Low-level accessors for underlying data
   305   void set_intptr_at(int index, intptr_t value) {
   306     assert(0 <= index && index < cell_count(), "oob");
   307     data()->set_cell_at(index, value);
   308   }
   309   void release_set_intptr_at(int index, intptr_t value) {
   310     assert(0 <= index && index < cell_count(), "oob");
   311     data()->release_set_cell_at(index, value);
   312   }
   313   intptr_t intptr_at(int index) {
   314     assert(0 <= index && index < cell_count(), "oob");
   315     return data()->cell_at(index);
   316   }
   317   void set_uint_at(int index, uint value) {
   318     set_intptr_at(index, (intptr_t) value);
   319   }
   320   void release_set_uint_at(int index, uint value) {
   321     release_set_intptr_at(index, (intptr_t) value);
   322   }
   323   uint uint_at(int index) {
   324     return (uint)intptr_at(index);
   325   }
   326   void set_int_at(int index, int value) {
   327     set_intptr_at(index, (intptr_t) value);
   328   }
   329   void release_set_int_at(int index, int value) {
   330     release_set_intptr_at(index, (intptr_t) value);
   331   }
   332   int int_at(int index) {
   333     return (int)intptr_at(index);
   334   }
   335   int int_at_unchecked(int index) {
   336     return (int)data()->cell_at(index);
   337   }
   338   void set_oop_at(int index, oop value) {
   339     set_intptr_at(index, (intptr_t) value);
   340   }
   341   oop oop_at(int index) {
   342     return (oop)intptr_at(index);
   343   }
   345   void set_flag_at(int flag_number) {
   346     data()->set_flag_at(flag_number);
   347   }
   348   bool flag_at(int flag_number) {
   349     return data()->flag_at(flag_number);
   350   }
   352   // two convenient imports for use by subclasses:
   353   static ByteSize cell_offset(int index) {
   354     return DataLayout::cell_offset(index);
   355   }
   356   static int flag_number_to_byte_constant(int flag_number) {
   357     return DataLayout::flag_number_to_byte_constant(flag_number);
   358   }
   360   ProfileData(DataLayout* data) {
   361     _data = data;
   362   }
   364 #ifdef CC_INTERP
   365   // Static low level accessors for DataLayout with ProfileData's semantics.
   367   static int cell_offset_in_bytes(int index) {
   368     return DataLayout::cell_offset_in_bytes(index);
   369   }
   371   static void increment_uint_at_no_overflow(DataLayout* layout, int index,
   372                                             int inc = DataLayout::counter_increment) {
   373     uint count = ((uint)layout->cell_at(index)) + inc;
   374     if (count == 0) return;
   375     layout->set_cell_at(index, (intptr_t) count);
   376   }
   378   static int int_at(DataLayout* layout, int index) {
   379     return (int)layout->cell_at(index);
   380   }
   382   static int uint_at(DataLayout* layout, int index) {
   383     return (uint)layout->cell_at(index);
   384   }
   386   static oop oop_at(DataLayout* layout, int index) {
   387     return (oop)layout->cell_at(index);
   388   }
   390   static void set_intptr_at(DataLayout* layout, int index, intptr_t value) {
   391     layout->set_cell_at(index, (intptr_t) value);
   392   }
   394   static void set_flag_at(DataLayout* layout, int flag_number) {
   395     layout->set_flag_at(flag_number);
   396   }
   397 #endif // CC_INTERP
   399 public:
   400   // Constructor for invalid ProfileData.
   401   ProfileData();
   403   u2 bci() {
   404     return data()->bci();
   405   }
   407   address dp() {
   408     return (address)_data;
   409   }
   411   int trap_state() {
   412     return data()->trap_state();
   413   }
   414   void set_trap_state(int new_state) {
   415     data()->set_trap_state(new_state);
   416   }
   418   // Type checking
   419   virtual bool is_BitData()         { return false; }
   420   virtual bool is_CounterData()     { return false; }
   421   virtual bool is_JumpData()        { return false; }
   422   virtual bool is_ReceiverTypeData(){ return false; }
   423   virtual bool is_VirtualCallData() { return false; }
   424   virtual bool is_RetData()         { return false; }
   425   virtual bool is_BranchData()      { return false; }
   426   virtual bool is_ArrayData()       { return false; }
   427   virtual bool is_MultiBranchData() { return false; }
   428   virtual bool is_ArgInfoData()     { return false; }
   431   BitData* as_BitData() {
   432     assert(is_BitData(), "wrong type");
   433     return is_BitData()         ? (BitData*)        this : NULL;
   434   }
   435   CounterData* as_CounterData() {
   436     assert(is_CounterData(), "wrong type");
   437     return is_CounterData()     ? (CounterData*)    this : NULL;
   438   }
   439   JumpData* as_JumpData() {
   440     assert(is_JumpData(), "wrong type");
   441     return is_JumpData()        ? (JumpData*)       this : NULL;
   442   }
   443   ReceiverTypeData* as_ReceiverTypeData() {
   444     assert(is_ReceiverTypeData(), "wrong type");
   445     return is_ReceiverTypeData() ? (ReceiverTypeData*)this : NULL;
   446   }
   447   VirtualCallData* as_VirtualCallData() {
   448     assert(is_VirtualCallData(), "wrong type");
   449     return is_VirtualCallData() ? (VirtualCallData*)this : NULL;
   450   }
   451   RetData* as_RetData() {
   452     assert(is_RetData(), "wrong type");
   453     return is_RetData()         ? (RetData*)        this : NULL;
   454   }
   455   BranchData* as_BranchData() {
   456     assert(is_BranchData(), "wrong type");
   457     return is_BranchData()      ? (BranchData*)     this : NULL;
   458   }
   459   ArrayData* as_ArrayData() {
   460     assert(is_ArrayData(), "wrong type");
   461     return is_ArrayData()       ? (ArrayData*)      this : NULL;
   462   }
   463   MultiBranchData* as_MultiBranchData() {
   464     assert(is_MultiBranchData(), "wrong type");
   465     return is_MultiBranchData() ? (MultiBranchData*)this : NULL;
   466   }
   467   ArgInfoData* as_ArgInfoData() {
   468     assert(is_ArgInfoData(), "wrong type");
   469     return is_ArgInfoData() ? (ArgInfoData*)this : NULL;
   470   }
   473   // Subclass specific initialization
   474   virtual void post_initialize(BytecodeStream* stream, MethodData* mdo) {}
   476   // GC support
   477   virtual void clean_weak_klass_links(BoolObjectClosure* is_alive_closure) {}
   479   // CI translation: ProfileData can represent both MethodDataOop data
   480   // as well as CIMethodData data. This function is provided for translating
   481   // an oop in a ProfileData to the ci equivalent. Generally speaking,
   482   // most ProfileData don't require any translation, so we provide the null
   483   // translation here, and the required translators are in the ci subclasses.
   484   virtual void translate_from(ProfileData* data) {}
   486   virtual void print_data_on(outputStream* st) {
   487     ShouldNotReachHere();
   488   }
   490 #ifndef PRODUCT
   491   void print_shared(outputStream* st, const char* name);
   492   void tab(outputStream* st);
   493 #endif
   494 };
   496 // BitData
   497 //
   498 // A BitData holds a flag or two in its header.
   499 class BitData : public ProfileData {
   500 protected:
   501   enum {
   502     // null_seen:
   503     //  saw a null operand (cast/aastore/instanceof)
   504     null_seen_flag              = DataLayout::first_flag + 0
   505   };
   506   enum { bit_cell_count = 0 };  // no additional data fields needed.
   507 public:
   508   BitData(DataLayout* layout) : ProfileData(layout) {
   509   }
   511   virtual bool is_BitData() { return true; }
   513   static int static_cell_count() {
   514     return bit_cell_count;
   515   }
   517   virtual int cell_count() {
   518     return static_cell_count();
   519   }
   521   // Accessor
   523   // The null_seen flag bit is specially known to the interpreter.
   524   // Consulting it allows the compiler to avoid setting up null_check traps.
   525   bool null_seen()     { return flag_at(null_seen_flag); }
   526   void set_null_seen()    { set_flag_at(null_seen_flag); }
   529   // Code generation support
   530   static int null_seen_byte_constant() {
   531     return flag_number_to_byte_constant(null_seen_flag);
   532   }
   534   static ByteSize bit_data_size() {
   535     return cell_offset(bit_cell_count);
   536   }
   538 #ifdef CC_INTERP
   539   static int bit_data_size_in_bytes() {
   540     return cell_offset_in_bytes(bit_cell_count);
   541   }
   543   static void set_null_seen(DataLayout* layout) {
   544     set_flag_at(layout, null_seen_flag);
   545   }
   547   static DataLayout* advance(DataLayout* layout) {
   548     return (DataLayout*) (((address)layout) + (ssize_t)BitData::bit_data_size_in_bytes());
   549   }
   550 #endif // CC_INTERP
   552 #ifndef PRODUCT
   553   void print_data_on(outputStream* st);
   554 #endif
   555 };
   557 // CounterData
   558 //
   559 // A CounterData corresponds to a simple counter.
   560 class CounterData : public BitData {
   561 protected:
   562   enum {
   563     count_off,
   564     counter_cell_count
   565   };
   566 public:
   567   CounterData(DataLayout* layout) : BitData(layout) {}
   569   virtual bool is_CounterData() { return true; }
   571   static int static_cell_count() {
   572     return counter_cell_count;
   573   }
   575   virtual int cell_count() {
   576     return static_cell_count();
   577   }
   579   // Direct accessor
   580   uint count() {
   581     return uint_at(count_off);
   582   }
   584   // Code generation support
   585   static ByteSize count_offset() {
   586     return cell_offset(count_off);
   587   }
   588   static ByteSize counter_data_size() {
   589     return cell_offset(counter_cell_count);
   590   }
   592   void set_count(uint count) {
   593     set_uint_at(count_off, count);
   594   }
   596 #ifdef CC_INTERP
   597   static int counter_data_size_in_bytes() {
   598     return cell_offset_in_bytes(counter_cell_count);
   599   }
   601   static void increment_count_no_overflow(DataLayout* layout) {
   602     increment_uint_at_no_overflow(layout, count_off);
   603   }
   605   // Support counter decrementation at checkcast / subtype check failed.
   606   static void decrement_count(DataLayout* layout) {
   607     increment_uint_at_no_overflow(layout, count_off, -1);
   608   }
   610   static DataLayout* advance(DataLayout* layout) {
   611     return (DataLayout*) (((address)layout) + (ssize_t)CounterData::counter_data_size_in_bytes());
   612   }
   613 #endif // CC_INTERP
   615 #ifndef PRODUCT
   616   void print_data_on(outputStream* st);
   617 #endif
   618 };
   620 // JumpData
   621 //
   622 // A JumpData is used to access profiling information for a direct
   623 // branch.  It is a counter, used for counting the number of branches,
   624 // plus a data displacement, used for realigning the data pointer to
   625 // the corresponding target bci.
   626 class JumpData : public ProfileData {
   627 protected:
   628   enum {
   629     taken_off_set,
   630     displacement_off_set,
   631     jump_cell_count
   632   };
   634   void set_displacement(int displacement) {
   635     set_int_at(displacement_off_set, displacement);
   636   }
   638 public:
   639   JumpData(DataLayout* layout) : ProfileData(layout) {
   640     assert(layout->tag() == DataLayout::jump_data_tag ||
   641       layout->tag() == DataLayout::branch_data_tag, "wrong type");
   642   }
   644   virtual bool is_JumpData() { return true; }
   646   static int static_cell_count() {
   647     return jump_cell_count;
   648   }
   650   virtual int cell_count() {
   651     return static_cell_count();
   652   }
   654   // Direct accessor
   655   uint taken() {
   656     return uint_at(taken_off_set);
   657   }
   659   void set_taken(uint cnt) {
   660     set_uint_at(taken_off_set, cnt);
   661   }
   663   // Saturating counter
   664   uint inc_taken() {
   665     uint cnt = taken() + 1;
   666     // Did we wrap? Will compiler screw us??
   667     if (cnt == 0) cnt--;
   668     set_uint_at(taken_off_set, cnt);
   669     return cnt;
   670   }
   672   int displacement() {
   673     return int_at(displacement_off_set);
   674   }
   676   // Code generation support
   677   static ByteSize taken_offset() {
   678     return cell_offset(taken_off_set);
   679   }
   681   static ByteSize displacement_offset() {
   682     return cell_offset(displacement_off_set);
   683   }
   685 #ifdef CC_INTERP
   686   static void increment_taken_count_no_overflow(DataLayout* layout) {
   687     increment_uint_at_no_overflow(layout, taken_off_set);
   688   }
   690   static DataLayout* advance_taken(DataLayout* layout) {
   691     return (DataLayout*) (((address)layout) + (ssize_t)int_at(layout, displacement_off_set));
   692   }
   694   static uint taken_count(DataLayout* layout) {
   695     return (uint) uint_at(layout, taken_off_set);
   696   }
   697 #endif // CC_INTERP
   699   // Specific initialization.
   700   void post_initialize(BytecodeStream* stream, MethodData* mdo);
   702 #ifndef PRODUCT
   703   void print_data_on(outputStream* st);
   704 #endif
   705 };
   707 // ReceiverTypeData
   708 //
   709 // A ReceiverTypeData is used to access profiling information about a
   710 // dynamic type check.  It consists of a counter which counts the total times
   711 // that the check is reached, and a series of (Klass*, count) pairs
   712 // which are used to store a type profile for the receiver of the check.
   713 class ReceiverTypeData : public CounterData {
   714 protected:
   715   enum {
   716     receiver0_offset = counter_cell_count,
   717     count0_offset,
   718     receiver_type_row_cell_count = (count0_offset + 1) - receiver0_offset
   719   };
   721 public:
   722   ReceiverTypeData(DataLayout* layout) : CounterData(layout) {
   723     assert(layout->tag() == DataLayout::receiver_type_data_tag ||
   724            layout->tag() == DataLayout::virtual_call_data_tag, "wrong type");
   725   }
   727   virtual bool is_ReceiverTypeData() { return true; }
   729   static int static_cell_count() {
   730     return counter_cell_count + (uint) TypeProfileWidth * receiver_type_row_cell_count;
   731   }
   733   virtual int cell_count() {
   734     return static_cell_count();
   735   }
   737   // Direct accessors
   738   static uint row_limit() {
   739     return TypeProfileWidth;
   740   }
   741   static int receiver_cell_index(uint row) {
   742     return receiver0_offset + row * receiver_type_row_cell_count;
   743   }
   744   static int receiver_count_cell_index(uint row) {
   745     return count0_offset + row * receiver_type_row_cell_count;
   746   }
   748   Klass* receiver(uint row) {
   749     assert(row < row_limit(), "oob");
   751     Klass* recv = (Klass*)intptr_at(receiver_cell_index(row));
   752     assert(recv == NULL || recv->is_klass(), "wrong type");
   753     return recv;
   754   }
   756   void set_receiver(uint row, Klass* k) {
   757     assert((uint)row < row_limit(), "oob");
   758     set_intptr_at(receiver_cell_index(row), (uintptr_t)k);
   759   }
   761   uint receiver_count(uint row) {
   762     assert(row < row_limit(), "oob");
   763     return uint_at(receiver_count_cell_index(row));
   764   }
   766   void set_receiver_count(uint row, uint count) {
   767     assert(row < row_limit(), "oob");
   768     set_uint_at(receiver_count_cell_index(row), count);
   769   }
   771   void clear_row(uint row) {
   772     assert(row < row_limit(), "oob");
   773     // Clear total count - indicator of polymorphic call site.
   774     // The site may look like as monomorphic after that but
   775     // it allow to have more accurate profiling information because
   776     // there was execution phase change since klasses were unloaded.
   777     // If the site is still polymorphic then MDO will be updated
   778     // to reflect it. But it could be the case that the site becomes
   779     // only bimorphic. Then keeping total count not 0 will be wrong.
   780     // Even if we use monomorphic (when it is not) for compilation
   781     // we will only have trap, deoptimization and recompile again
   782     // with updated MDO after executing method in Interpreter.
   783     // An additional receiver will be recorded in the cleaned row
   784     // during next call execution.
   785     //
   786     // Note: our profiling logic works with empty rows in any slot.
   787     // We do sorting a profiling info (ciCallProfile) for compilation.
   788     //
   789     set_count(0);
   790     set_receiver(row, NULL);
   791     set_receiver_count(row, 0);
   792   }
   794   // Code generation support
   795   static ByteSize receiver_offset(uint row) {
   796     return cell_offset(receiver_cell_index(row));
   797   }
   798   static ByteSize receiver_count_offset(uint row) {
   799     return cell_offset(receiver_count_cell_index(row));
   800   }
   801   static ByteSize receiver_type_data_size() {
   802     return cell_offset(static_cell_count());
   803   }
   805   // GC support
   806   virtual void clean_weak_klass_links(BoolObjectClosure* is_alive_closure);
   808 #ifdef CC_INTERP
   809   static int receiver_type_data_size_in_bytes() {
   810     return cell_offset_in_bytes(static_cell_count());
   811   }
   813   static Klass *receiver_unchecked(DataLayout* layout, uint row) {
   814     oop recv = oop_at(layout, receiver_cell_index(row));
   815     return (Klass *)recv;
   816   }
   818   static void increment_receiver_count_no_overflow(DataLayout* layout, Klass *rcvr) {
   819     const int num_rows = row_limit();
   820     // Receiver already exists?
   821     for (int row = 0; row < num_rows; row++) {
   822       if (receiver_unchecked(layout, row) == rcvr) {
   823         increment_uint_at_no_overflow(layout, receiver_count_cell_index(row));
   824         return;
   825       }
   826     }
   827     // New receiver, find a free slot.
   828     for (int row = 0; row < num_rows; row++) {
   829       if (receiver_unchecked(layout, row) == NULL) {
   830         set_intptr_at(layout, receiver_cell_index(row), (intptr_t)rcvr);
   831         increment_uint_at_no_overflow(layout, receiver_count_cell_index(row));
   832         return;
   833       }
   834     }
   835     // Receiver did not match any saved receiver and there is no empty row for it.
   836     // Increment total counter to indicate polymorphic case.
   837     increment_count_no_overflow(layout);
   838   }
   840   static DataLayout* advance(DataLayout* layout) {
   841     return (DataLayout*) (((address)layout) + (ssize_t)ReceiverTypeData::receiver_type_data_size_in_bytes());
   842   }
   843 #endif // CC_INTERP
   845 #ifndef PRODUCT
   846   void print_receiver_data_on(outputStream* st);
   847   void print_data_on(outputStream* st);
   848 #endif
   849 };
   851 // VirtualCallData
   852 //
   853 // A VirtualCallData is used to access profiling information about a
   854 // virtual call.  For now, it has nothing more than a ReceiverTypeData.
   855 class VirtualCallData : public ReceiverTypeData {
   856 public:
   857   VirtualCallData(DataLayout* layout) : ReceiverTypeData(layout) {
   858     assert(layout->tag() == DataLayout::virtual_call_data_tag, "wrong type");
   859   }
   861   virtual bool is_VirtualCallData() { return true; }
   863   static int static_cell_count() {
   864     // At this point we could add more profile state, e.g., for arguments.
   865     // But for now it's the same size as the base record type.
   866     return ReceiverTypeData::static_cell_count();
   867   }
   869   virtual int cell_count() {
   870     return static_cell_count();
   871   }
   873   // Direct accessors
   874   static ByteSize virtual_call_data_size() {
   875     return cell_offset(static_cell_count());
   876   }
   878 #ifdef CC_INTERP
   879   static int virtual_call_data_size_in_bytes() {
   880     return cell_offset_in_bytes(static_cell_count());
   881   }
   883   static DataLayout* advance(DataLayout* layout) {
   884     return (DataLayout*) (((address)layout) + (ssize_t)VirtualCallData::virtual_call_data_size_in_bytes());
   885   }
   886 #endif // CC_INTERP
   888 #ifndef PRODUCT
   889   void print_data_on(outputStream* st);
   890 #endif
   891 };
   893 // RetData
   894 //
   895 // A RetData is used to access profiling information for a ret bytecode.
   896 // It is composed of a count of the number of times that the ret has
   897 // been executed, followed by a series of triples of the form
   898 // (bci, count, di) which count the number of times that some bci was the
   899 // target of the ret and cache a corresponding data displacement.
   900 class RetData : public CounterData {
   901 protected:
   902   enum {
   903     bci0_offset = counter_cell_count,
   904     count0_offset,
   905     displacement0_offset,
   906     ret_row_cell_count = (displacement0_offset + 1) - bci0_offset
   907   };
   909   void set_bci(uint row, int bci) {
   910     assert((uint)row < row_limit(), "oob");
   911     set_int_at(bci0_offset + row * ret_row_cell_count, bci);
   912   }
   913   void release_set_bci(uint row, int bci) {
   914     assert((uint)row < row_limit(), "oob");
   915     // 'release' when setting the bci acts as a valid flag for other
   916     // threads wrt bci_count and bci_displacement.
   917     release_set_int_at(bci0_offset + row * ret_row_cell_count, bci);
   918   }
   919   void set_bci_count(uint row, uint count) {
   920     assert((uint)row < row_limit(), "oob");
   921     set_uint_at(count0_offset + row * ret_row_cell_count, count);
   922   }
   923   void set_bci_displacement(uint row, int disp) {
   924     set_int_at(displacement0_offset + row * ret_row_cell_count, disp);
   925   }
   927 public:
   928   RetData(DataLayout* layout) : CounterData(layout) {
   929     assert(layout->tag() == DataLayout::ret_data_tag, "wrong type");
   930   }
   932   virtual bool is_RetData() { return true; }
   934   enum {
   935     no_bci = -1 // value of bci when bci1/2 are not in use.
   936   };
   938   static int static_cell_count() {
   939     return counter_cell_count + (uint) BciProfileWidth * ret_row_cell_count;
   940   }
   942   virtual int cell_count() {
   943     return static_cell_count();
   944   }
   946   static uint row_limit() {
   947     return BciProfileWidth;
   948   }
   949   static int bci_cell_index(uint row) {
   950     return bci0_offset + row * ret_row_cell_count;
   951   }
   952   static int bci_count_cell_index(uint row) {
   953     return count0_offset + row * ret_row_cell_count;
   954   }
   955   static int bci_displacement_cell_index(uint row) {
   956     return displacement0_offset + row * ret_row_cell_count;
   957   }
   959   // Direct accessors
   960   int bci(uint row) {
   961     return int_at(bci_cell_index(row));
   962   }
   963   uint bci_count(uint row) {
   964     return uint_at(bci_count_cell_index(row));
   965   }
   966   int bci_displacement(uint row) {
   967     return int_at(bci_displacement_cell_index(row));
   968   }
   970   // Interpreter Runtime support
   971   address fixup_ret(int return_bci, MethodData* mdo);
   973   // Code generation support
   974   static ByteSize bci_offset(uint row) {
   975     return cell_offset(bci_cell_index(row));
   976   }
   977   static ByteSize bci_count_offset(uint row) {
   978     return cell_offset(bci_count_cell_index(row));
   979   }
   980   static ByteSize bci_displacement_offset(uint row) {
   981     return cell_offset(bci_displacement_cell_index(row));
   982   }
   984 #ifdef CC_INTERP
   985   static DataLayout* advance(MethodData *md, int bci);
   986 #endif // CC_INTERP
   988   // Specific initialization.
   989   void post_initialize(BytecodeStream* stream, MethodData* mdo);
   991 #ifndef PRODUCT
   992   void print_data_on(outputStream* st);
   993 #endif
   994 };
   996 // BranchData
   997 //
   998 // A BranchData is used to access profiling data for a two-way branch.
   999 // It consists of taken and not_taken counts as well as a data displacement
  1000 // for the taken case.
  1001 class BranchData : public JumpData {
  1002 protected:
  1003   enum {
  1004     not_taken_off_set = jump_cell_count,
  1005     branch_cell_count
  1006   };
  1008   void set_displacement(int displacement) {
  1009     set_int_at(displacement_off_set, displacement);
  1012 public:
  1013   BranchData(DataLayout* layout) : JumpData(layout) {
  1014     assert(layout->tag() == DataLayout::branch_data_tag, "wrong type");
  1017   virtual bool is_BranchData() { return true; }
  1019   static int static_cell_count() {
  1020     return branch_cell_count;
  1023   virtual int cell_count() {
  1024     return static_cell_count();
  1027   // Direct accessor
  1028   uint not_taken() {
  1029     return uint_at(not_taken_off_set);
  1032   void set_not_taken(uint cnt) {
  1033     set_uint_at(not_taken_off_set, cnt);
  1036   uint inc_not_taken() {
  1037     uint cnt = not_taken() + 1;
  1038     // Did we wrap? Will compiler screw us??
  1039     if (cnt == 0) cnt--;
  1040     set_uint_at(not_taken_off_set, cnt);
  1041     return cnt;
  1044   // Code generation support
  1045   static ByteSize not_taken_offset() {
  1046     return cell_offset(not_taken_off_set);
  1048   static ByteSize branch_data_size() {
  1049     return cell_offset(branch_cell_count);
  1052 #ifdef CC_INTERP
  1053   static int branch_data_size_in_bytes() {
  1054     return cell_offset_in_bytes(branch_cell_count);
  1057   static void increment_not_taken_count_no_overflow(DataLayout* layout) {
  1058     increment_uint_at_no_overflow(layout, not_taken_off_set);
  1061   static DataLayout* advance_not_taken(DataLayout* layout) {
  1062     return (DataLayout*) (((address)layout) + (ssize_t)BranchData::branch_data_size_in_bytes());
  1064 #endif // CC_INTERP
  1066   // Specific initialization.
  1067   void post_initialize(BytecodeStream* stream, MethodData* mdo);
  1069 #ifndef PRODUCT
  1070   void print_data_on(outputStream* st);
  1071 #endif
  1072 };
  1074 // ArrayData
  1075 //
  1076 // A ArrayData is a base class for accessing profiling data which does
  1077 // not have a statically known size.  It consists of an array length
  1078 // and an array start.
  1079 class ArrayData : public ProfileData {
  1080 protected:
  1081   friend class DataLayout;
  1083   enum {
  1084     array_len_off_set,
  1085     array_start_off_set
  1086   };
  1088   uint array_uint_at(int index) {
  1089     int aindex = index + array_start_off_set;
  1090     return uint_at(aindex);
  1092   int array_int_at(int index) {
  1093     int aindex = index + array_start_off_set;
  1094     return int_at(aindex);
  1096   oop array_oop_at(int index) {
  1097     int aindex = index + array_start_off_set;
  1098     return oop_at(aindex);
  1100   void array_set_int_at(int index, int value) {
  1101     int aindex = index + array_start_off_set;
  1102     set_int_at(aindex, value);
  1105 #ifdef CC_INTERP
  1106   // Static low level accessors for DataLayout with ArrayData's semantics.
  1108   static void increment_array_uint_at_no_overflow(DataLayout* layout, int index) {
  1109     int aindex = index + array_start_off_set;
  1110     increment_uint_at_no_overflow(layout, aindex);
  1113   static int array_int_at(DataLayout* layout, int index) {
  1114     int aindex = index + array_start_off_set;
  1115     return int_at(layout, aindex);
  1117 #endif // CC_INTERP
  1119   // Code generation support for subclasses.
  1120   static ByteSize array_element_offset(int index) {
  1121     return cell_offset(array_start_off_set + index);
  1124 public:
  1125   ArrayData(DataLayout* layout) : ProfileData(layout) {}
  1127   virtual bool is_ArrayData() { return true; }
  1129   static int static_cell_count() {
  1130     return -1;
  1133   int array_len() {
  1134     return int_at_unchecked(array_len_off_set);
  1137   virtual int cell_count() {
  1138     return array_len() + 1;
  1141   // Code generation support
  1142   static ByteSize array_len_offset() {
  1143     return cell_offset(array_len_off_set);
  1145   static ByteSize array_start_offset() {
  1146     return cell_offset(array_start_off_set);
  1148 };
  1150 // MultiBranchData
  1151 //
  1152 // A MultiBranchData is used to access profiling information for
  1153 // a multi-way branch (*switch bytecodes).  It consists of a series
  1154 // of (count, displacement) pairs, which count the number of times each
  1155 // case was taken and specify the data displacment for each branch target.
  1156 class MultiBranchData : public ArrayData {
  1157 protected:
  1158   enum {
  1159     default_count_off_set,
  1160     default_disaplacement_off_set,
  1161     case_array_start
  1162   };
  1163   enum {
  1164     relative_count_off_set,
  1165     relative_displacement_off_set,
  1166     per_case_cell_count
  1167   };
  1169   void set_default_displacement(int displacement) {
  1170     array_set_int_at(default_disaplacement_off_set, displacement);
  1172   void set_displacement_at(int index, int displacement) {
  1173     array_set_int_at(case_array_start +
  1174                      index * per_case_cell_count +
  1175                      relative_displacement_off_set,
  1176                      displacement);
  1179 public:
  1180   MultiBranchData(DataLayout* layout) : ArrayData(layout) {
  1181     assert(layout->tag() == DataLayout::multi_branch_data_tag, "wrong type");
  1184   virtual bool is_MultiBranchData() { return true; }
  1186   static int compute_cell_count(BytecodeStream* stream);
  1188   int number_of_cases() {
  1189     int alen = array_len() - 2; // get rid of default case here.
  1190     assert(alen % per_case_cell_count == 0, "must be even");
  1191     return (alen / per_case_cell_count);
  1194   uint default_count() {
  1195     return array_uint_at(default_count_off_set);
  1197   int default_displacement() {
  1198     return array_int_at(default_disaplacement_off_set);
  1201   uint count_at(int index) {
  1202     return array_uint_at(case_array_start +
  1203                          index * per_case_cell_count +
  1204                          relative_count_off_set);
  1206   int displacement_at(int index) {
  1207     return array_int_at(case_array_start +
  1208                         index * per_case_cell_count +
  1209                         relative_displacement_off_set);
  1212   // Code generation support
  1213   static ByteSize default_count_offset() {
  1214     return array_element_offset(default_count_off_set);
  1216   static ByteSize default_displacement_offset() {
  1217     return array_element_offset(default_disaplacement_off_set);
  1219   static ByteSize case_count_offset(int index) {
  1220     return case_array_offset() +
  1221            (per_case_size() * index) +
  1222            relative_count_offset();
  1224   static ByteSize case_array_offset() {
  1225     return array_element_offset(case_array_start);
  1227   static ByteSize per_case_size() {
  1228     return in_ByteSize(per_case_cell_count) * cell_size;
  1230   static ByteSize relative_count_offset() {
  1231     return in_ByteSize(relative_count_off_set) * cell_size;
  1233   static ByteSize relative_displacement_offset() {
  1234     return in_ByteSize(relative_displacement_off_set) * cell_size;
  1237 #ifdef CC_INTERP
  1238   static void increment_count_no_overflow(DataLayout* layout, int index) {
  1239     if (index == -1) {
  1240       increment_array_uint_at_no_overflow(layout, default_count_off_set);
  1241     } else {
  1242       increment_array_uint_at_no_overflow(layout, case_array_start +
  1243                                                   index * per_case_cell_count +
  1244                                                   relative_count_off_set);
  1248   static DataLayout* advance(DataLayout* layout, int index) {
  1249     if (index == -1) {
  1250       return (DataLayout*) (((address)layout) + (ssize_t)array_int_at(layout, default_disaplacement_off_set));
  1251     } else {
  1252       return (DataLayout*) (((address)layout) + (ssize_t)array_int_at(layout, case_array_start +
  1253                                                                               index * per_case_cell_count +
  1254                                                                               relative_displacement_off_set));
  1257 #endif // CC_INTERP
  1259   // Specific initialization.
  1260   void post_initialize(BytecodeStream* stream, MethodData* mdo);
  1262 #ifndef PRODUCT
  1263   void print_data_on(outputStream* st);
  1264 #endif
  1265 };
  1267 class ArgInfoData : public ArrayData {
  1269 public:
  1270   ArgInfoData(DataLayout* layout) : ArrayData(layout) {
  1271     assert(layout->tag() == DataLayout::arg_info_data_tag, "wrong type");
  1274   virtual bool is_ArgInfoData() { return true; }
  1277   int number_of_args() {
  1278     return array_len();
  1281   uint arg_modified(int arg) {
  1282     return array_uint_at(arg);
  1285   void set_arg_modified(int arg, uint val) {
  1286     array_set_int_at(arg, val);
  1289 #ifndef PRODUCT
  1290   void print_data_on(outputStream* st);
  1291 #endif
  1292 };
  1294 // MethodData*
  1295 //
  1296 // A MethodData* holds information which has been collected about
  1297 // a method.  Its layout looks like this:
  1298 //
  1299 // -----------------------------
  1300 // | header                    |
  1301 // | klass                     |
  1302 // -----------------------------
  1303 // | method                    |
  1304 // | size of the MethodData* |
  1305 // -----------------------------
  1306 // | Data entries...           |
  1307 // |   (variable size)         |
  1308 // |                           |
  1309 // .                           .
  1310 // .                           .
  1311 // .                           .
  1312 // |                           |
  1313 // -----------------------------
  1314 //
  1315 // The data entry area is a heterogeneous array of DataLayouts. Each
  1316 // DataLayout in the array corresponds to a specific bytecode in the
  1317 // method.  The entries in the array are sorted by the corresponding
  1318 // bytecode.  Access to the data is via resource-allocated ProfileData,
  1319 // which point to the underlying blocks of DataLayout structures.
  1320 //
  1321 // During interpretation, if profiling in enabled, the interpreter
  1322 // maintains a method data pointer (mdp), which points at the entry
  1323 // in the array corresponding to the current bci.  In the course of
  1324 // intepretation, when a bytecode is encountered that has profile data
  1325 // associated with it, the entry pointed to by mdp is updated, then the
  1326 // mdp is adjusted to point to the next appropriate DataLayout.  If mdp
  1327 // is NULL to begin with, the interpreter assumes that the current method
  1328 // is not (yet) being profiled.
  1329 //
  1330 // In MethodData* parlance, "dp" is a "data pointer", the actual address
  1331 // of a DataLayout element.  A "di" is a "data index", the offset in bytes
  1332 // from the base of the data entry array.  A "displacement" is the byte offset
  1333 // in certain ProfileData objects that indicate the amount the mdp must be
  1334 // adjusted in the event of a change in control flow.
  1335 //
  1337 CC_INTERP_ONLY(class BytecodeInterpreter;)
  1339 class MethodData : public Metadata {
  1340   friend class VMStructs;
  1341   CC_INTERP_ONLY(friend class BytecodeInterpreter;)
  1342 private:
  1343   friend class ProfileData;
  1345   // Back pointer to the Method*
  1346   Method* _method;
  1348   // Size of this oop in bytes
  1349   int _size;
  1351   // Cached hint for bci_to_dp and bci_to_data
  1352   int _hint_di;
  1354   MethodData(methodHandle method, int size, TRAPS);
  1355 public:
  1356   static MethodData* allocate(ClassLoaderData* loader_data, methodHandle method, TRAPS);
  1357   MethodData() {}; // For ciMethodData
  1359   bool is_methodData() const volatile { return true; }
  1361   // Whole-method sticky bits and flags
  1362   enum {
  1363     _trap_hist_limit    = 17,   // decoupled from Deoptimization::Reason_LIMIT
  1364     _trap_hist_mask     = max_jubyte,
  1365     _extra_data_count   = 4     // extra DataLayout headers, for trap history
  1366   }; // Public flag values
  1367 private:
  1368   uint _nof_decompiles;             // count of all nmethod removals
  1369   uint _nof_overflow_recompiles;    // recompile count, excluding recomp. bits
  1370   uint _nof_overflow_traps;         // trap count, excluding _trap_hist
  1371   union {
  1372     intptr_t _align;
  1373     u1 _array[_trap_hist_limit];
  1374   } _trap_hist;
  1376   // Support for interprocedural escape analysis, from Thomas Kotzmann.
  1377   intx              _eflags;          // flags on escape information
  1378   intx              _arg_local;       // bit set of non-escaping arguments
  1379   intx              _arg_stack;       // bit set of stack-allocatable arguments
  1380   intx              _arg_returned;    // bit set of returned arguments
  1382   int _creation_mileage;              // method mileage at MDO creation
  1384   // How many invocations has this MDO seen?
  1385   // These counters are used to determine the exact age of MDO.
  1386   // We need those because in tiered a method can be concurrently
  1387   // executed at different levels.
  1388   InvocationCounter _invocation_counter;
  1389   // Same for backedges.
  1390   InvocationCounter _backedge_counter;
  1391   // Counter values at the time profiling started.
  1392   int               _invocation_counter_start;
  1393   int               _backedge_counter_start;
  1394   // Number of loops and blocks is computed when compiling the first
  1395   // time with C1. It is used to determine if method is trivial.
  1396   short             _num_loops;
  1397   short             _num_blocks;
  1398   // Highest compile level this method has ever seen.
  1399   u1                _highest_comp_level;
  1400   // Same for OSR level
  1401   u1                _highest_osr_comp_level;
  1402   // Does this method contain anything worth profiling?
  1403   bool              _would_profile;
  1405   // Size of _data array in bytes.  (Excludes header and extra_data fields.)
  1406   int _data_size;
  1408   // Beginning of the data entries
  1409   intptr_t _data[1];
  1411   // Helper for size computation
  1412   static int compute_data_size(BytecodeStream* stream);
  1413   static int bytecode_cell_count(Bytecodes::Code code);
  1414   enum { no_profile_data = -1, variable_cell_count = -2 };
  1416   // Helper for initialization
  1417   DataLayout* data_layout_at(int data_index) const {
  1418     assert(data_index % sizeof(intptr_t) == 0, "unaligned");
  1419     return (DataLayout*) (((address)_data) + data_index);
  1422   // Initialize an individual data segment.  Returns the size of
  1423   // the segment in bytes.
  1424   int initialize_data(BytecodeStream* stream, int data_index);
  1426   // Helper for data_at
  1427   DataLayout* limit_data_position() const {
  1428     return (DataLayout*)((address)data_base() + _data_size);
  1430   bool out_of_bounds(int data_index) const {
  1431     return data_index >= data_size();
  1434   // Give each of the data entries a chance to perform specific
  1435   // data initialization.
  1436   void post_initialize(BytecodeStream* stream);
  1438   // hint accessors
  1439   int      hint_di() const  { return _hint_di; }
  1440   void set_hint_di(int di)  {
  1441     assert(!out_of_bounds(di), "hint_di out of bounds");
  1442     _hint_di = di;
  1444   ProfileData* data_before(int bci) {
  1445     // avoid SEGV on this edge case
  1446     if (data_size() == 0)
  1447       return NULL;
  1448     int hint = hint_di();
  1449     if (data_layout_at(hint)->bci() <= bci)
  1450       return data_at(hint);
  1451     return first_data();
  1454   // What is the index of the first data entry?
  1455   int first_di() const { return 0; }
  1457   // Find or create an extra ProfileData:
  1458   ProfileData* bci_to_extra_data(int bci, bool create_if_missing);
  1460   // return the argument info cell
  1461   ArgInfoData *arg_info();
  1463 public:
  1464   static int header_size() {
  1465     return sizeof(MethodData)/wordSize;
  1468   // Compute the size of a MethodData* before it is created.
  1469   static int compute_allocation_size_in_bytes(methodHandle method);
  1470   static int compute_allocation_size_in_words(methodHandle method);
  1471   static int compute_extra_data_count(int data_size, int empty_bc_count);
  1473   // Determine if a given bytecode can have profile information.
  1474   static bool bytecode_has_profile(Bytecodes::Code code) {
  1475     return bytecode_cell_count(code) != no_profile_data;
  1478   // reset into original state
  1479   void init();
  1481   // My size
  1482   int size_in_bytes() const { return _size; }
  1483   int size() const    { return align_object_size(align_size_up(_size, BytesPerWord)/BytesPerWord); }
  1484 #if INCLUDE_SERVICES
  1485   void collect_statistics(KlassSizeStats *sz) const;
  1486 #endif
  1488   int      creation_mileage() const  { return _creation_mileage; }
  1489   void set_creation_mileage(int x)   { _creation_mileage = x; }
  1491   int invocation_count() {
  1492     if (invocation_counter()->carry()) {
  1493       return InvocationCounter::count_limit;
  1495     return invocation_counter()->count();
  1497   int backedge_count() {
  1498     if (backedge_counter()->carry()) {
  1499       return InvocationCounter::count_limit;
  1501     return backedge_counter()->count();
  1504   int invocation_count_start() {
  1505     if (invocation_counter()->carry()) {
  1506       return 0;
  1508     return _invocation_counter_start;
  1511   int backedge_count_start() {
  1512     if (backedge_counter()->carry()) {
  1513       return 0;
  1515     return _backedge_counter_start;
  1518   int invocation_count_delta() { return invocation_count() - invocation_count_start(); }
  1519   int backedge_count_delta()   { return backedge_count()   - backedge_count_start();   }
  1521   void reset_start_counters() {
  1522     _invocation_counter_start = invocation_count();
  1523     _backedge_counter_start = backedge_count();
  1526   InvocationCounter* invocation_counter()     { return &_invocation_counter; }
  1527   InvocationCounter* backedge_counter()       { return &_backedge_counter;   }
  1529   void set_would_profile(bool p)              { _would_profile = p;    }
  1530   bool would_profile() const                  { return _would_profile; }
  1532   int highest_comp_level() const              { return _highest_comp_level;      }
  1533   void set_highest_comp_level(int level)      { _highest_comp_level = level;     }
  1534   int highest_osr_comp_level() const          { return _highest_osr_comp_level;  }
  1535   void set_highest_osr_comp_level(int level)  { _highest_osr_comp_level = level; }
  1537   int num_loops() const                       { return _num_loops;  }
  1538   void set_num_loops(int n)                   { _num_loops = n;     }
  1539   int num_blocks() const                      { return _num_blocks; }
  1540   void set_num_blocks(int n)                  { _num_blocks = n;    }
  1542   bool is_mature() const;  // consult mileage and ProfileMaturityPercentage
  1543   static int mileage_of(Method* m);
  1545   // Support for interprocedural escape analysis, from Thomas Kotzmann.
  1546   enum EscapeFlag {
  1547     estimated    = 1 << 0,
  1548     return_local = 1 << 1,
  1549     return_allocated = 1 << 2,
  1550     allocated_escapes = 1 << 3,
  1551     unknown_modified = 1 << 4
  1552   };
  1554   intx eflags()                                  { return _eflags; }
  1555   intx arg_local()                               { return _arg_local; }
  1556   intx arg_stack()                               { return _arg_stack; }
  1557   intx arg_returned()                            { return _arg_returned; }
  1558   uint arg_modified(int a)                       { ArgInfoData *aid = arg_info();
  1559                                                    assert(aid != NULL, "arg_info must be not null");
  1560                                                    assert(a >= 0 && a < aid->number_of_args(), "valid argument number");
  1561                                                    return aid->arg_modified(a); }
  1563   void set_eflags(intx v)                        { _eflags = v; }
  1564   void set_arg_local(intx v)                     { _arg_local = v; }
  1565   void set_arg_stack(intx v)                     { _arg_stack = v; }
  1566   void set_arg_returned(intx v)                  { _arg_returned = v; }
  1567   void set_arg_modified(int a, uint v)           { ArgInfoData *aid = arg_info();
  1568                                                    assert(aid != NULL, "arg_info must be not null");
  1569                                                    assert(a >= 0 && a < aid->number_of_args(), "valid argument number");
  1570                                                    aid->set_arg_modified(a, v); }
  1572   void clear_escape_info()                       { _eflags = _arg_local = _arg_stack = _arg_returned = 0; }
  1574   // Location and size of data area
  1575   address data_base() const {
  1576     return (address) _data;
  1578   int data_size() const {
  1579     return _data_size;
  1582   // Accessors
  1583   Method* method() const { return _method; }
  1585   // Get the data at an arbitrary (sort of) data index.
  1586   ProfileData* data_at(int data_index) const;
  1588   // Walk through the data in order.
  1589   ProfileData* first_data() const { return data_at(first_di()); }
  1590   ProfileData* next_data(ProfileData* current) const;
  1591   bool is_valid(ProfileData* current) const { return current != NULL; }
  1593   // Convert a dp (data pointer) to a di (data index).
  1594   int dp_to_di(address dp) const {
  1595     return dp - ((address)_data);
  1598   address di_to_dp(int di) {
  1599     return (address)data_layout_at(di);
  1602   // bci to di/dp conversion.
  1603   address bci_to_dp(int bci);
  1604   int bci_to_di(int bci) {
  1605     return dp_to_di(bci_to_dp(bci));
  1608   // Get the data at an arbitrary bci, or NULL if there is none.
  1609   ProfileData* bci_to_data(int bci);
  1611   // Same, but try to create an extra_data record if one is needed:
  1612   ProfileData* allocate_bci_to_data(int bci) {
  1613     ProfileData* data = bci_to_data(bci);
  1614     return (data != NULL) ? data : bci_to_extra_data(bci, true);
  1617   // Add a handful of extra data records, for trap tracking.
  1618   DataLayout* extra_data_base() const { return limit_data_position(); }
  1619   DataLayout* extra_data_limit() const { return (DataLayout*)((address)this + size_in_bytes()); }
  1620   int extra_data_size() const { return (address)extra_data_limit()
  1621                                - (address)extra_data_base(); }
  1622   static DataLayout* next_extra(DataLayout* dp) { return (DataLayout*)((address)dp + in_bytes(DataLayout::cell_offset(0))); }
  1624   // Return (uint)-1 for overflow.
  1625   uint trap_count(int reason) const {
  1626     assert((uint)reason < _trap_hist_limit, "oob");
  1627     return (int)((_trap_hist._array[reason]+1) & _trap_hist_mask) - 1;
  1629   // For loops:
  1630   static uint trap_reason_limit() { return _trap_hist_limit; }
  1631   static uint trap_count_limit()  { return _trap_hist_mask; }
  1632   uint inc_trap_count(int reason) {
  1633     // Count another trap, anywhere in this method.
  1634     assert(reason >= 0, "must be single trap");
  1635     if ((uint)reason < _trap_hist_limit) {
  1636       uint cnt1 = 1 + _trap_hist._array[reason];
  1637       if ((cnt1 & _trap_hist_mask) != 0) {  // if no counter overflow...
  1638         _trap_hist._array[reason] = cnt1;
  1639         return cnt1;
  1640       } else {
  1641         return _trap_hist_mask + (++_nof_overflow_traps);
  1643     } else {
  1644       // Could not represent the count in the histogram.
  1645       return (++_nof_overflow_traps);
  1649   uint overflow_trap_count() const {
  1650     return _nof_overflow_traps;
  1652   uint overflow_recompile_count() const {
  1653     return _nof_overflow_recompiles;
  1655   void inc_overflow_recompile_count() {
  1656     _nof_overflow_recompiles += 1;
  1658   uint decompile_count() const {
  1659     return _nof_decompiles;
  1661   void inc_decompile_count() {
  1662     _nof_decompiles += 1;
  1663     if (decompile_count() > (uint)PerMethodRecompilationCutoff) {
  1664       method()->set_not_compilable(CompLevel_full_optimization, true, "decompile_count > PerMethodRecompilationCutoff");
  1668   // Support for code generation
  1669   static ByteSize data_offset() {
  1670     return byte_offset_of(MethodData, _data[0]);
  1673   static ByteSize invocation_counter_offset() {
  1674     return byte_offset_of(MethodData, _invocation_counter);
  1676   static ByteSize backedge_counter_offset() {
  1677     return byte_offset_of(MethodData, _backedge_counter);
  1680   // Deallocation support - no pointer fields to deallocate
  1681   void deallocate_contents(ClassLoaderData* loader_data) {}
  1683   // GC support
  1684   void set_size(int object_size_in_bytes) { _size = object_size_in_bytes; }
  1686   // Printing
  1687 #ifndef PRODUCT
  1688   void print_on      (outputStream* st) const;
  1689 #endif
  1690   void print_value_on(outputStream* st) const;
  1692 #ifndef PRODUCT
  1693   // printing support for method data
  1694   void print_data_on(outputStream* st) const;
  1695 #endif
  1697   const char* internal_name() const { return "{method data}"; }
  1699   // verification
  1700   void verify_on(outputStream* st);
  1701   void verify_data_on(outputStream* st);
  1702 };
  1704 #endif // SHARE_VM_OOPS_METHODDATAOOP_HPP

mercurial