< prev index next >

src/share/vm/oops/methodCounters.hpp

Print this page


   1 /*
   2  * Copyright (c) 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  */
  24 
  25 #ifndef SHARE_VM_OOPS_METHODCOUNTERS_HPP
  26 #define SHARE_VM_OOPS_METHODCOUNTERS_HPP
  27 
  28 #include "oops/metadata.hpp"
  29 #include "compiler/compilerOracle.hpp"
  30 #include "interpreter/invocationCounter.hpp"
  31 #include "runtime/arguments.hpp"
  32 
  33 class MethodCounters: public MetaspaceObj {
  34  friend class VMStructs;
  35  friend class JVMCIVMStructs;
  36  private:

  37   int               _interpreter_invocation_count; // Count of times invoked (reused as prev_event_count in tiered)
  38   u2                _interpreter_throwout_count; // Count of times method was exited via exception while interpreting

  39   u2                _number_of_breakpoints;      // fullspeed debugging support
  40   InvocationCounter _invocation_counter;         // Incremented before each activation of the method - used to trigger frequency-based optimizations
  41   InvocationCounter _backedge_counter;           // Incremented before each backedge taken - used to trigger frequencey-based optimizations
  42   // NMethod age is a counter for warm methods detection in the code cache sweeper.
  43   // The counter is reset by the sweeper and is decremented by some of the compiled
  44   // code. The counter values are interpreted as follows:
  45   // 1. (HotMethodDetection..INT_MAX] - initial value, no counters inserted
  46   // 2. [1..HotMethodDetectionLimit)  - the method is warm, the counter is used
  47   //                                    to figure out which methods can be flushed.
  48   // 3. (INT_MIN..0]                  - method is hot and will deopt and get
  49   //                                    recompiled without the counters
  50   int               _nmethod_age;
  51   int               _interpreter_invocation_limit;        // per-method InterpreterInvocationLimit
  52   int               _interpreter_backward_branch_limit;   // per-method InterpreterBackwardBranchLimit
  53   int               _interpreter_profile_limit;           // per-method InterpreterProfileLimit
  54   int               _invoke_mask;                         // per-method Tier0InvokeNotifyFreqLog
  55   int               _backedge_mask;                       // per-method Tier0BackedgeNotifyFreqLog
  56 #ifdef TIERED
  57   float             _rate;                        // Events (invocation and backedge counter increments) per millisecond
  58   jlong             _prev_time;                   // Previous time the rate was acquired
  59   u1                _highest_comp_level;          // Highest compile level this method has ever seen.
  60   u1                _highest_osr_comp_level;      // Same for OSR level
  61 #endif
  62 
  63   MethodCounters(methodHandle mh) : _interpreter_invocation_count(0),
  64                                     _interpreter_throwout_count(0),
  65                                     _number_of_breakpoints(0),
  66                                     _nmethod_age(INT_MAX)
  67 #ifdef TIERED
  68                                  , _rate(0),
  69                                    _prev_time(0),
  70                                    _highest_comp_level(0),
  71                                    _highest_osr_comp_level(0)
  72 #endif
  73   {


  74     invocation_counter()->init();
  75     backedge_counter()->init();
  76 
  77     if (StressCodeAging) {
  78       set_nmethod_age(HotMethodDetectionLimit);
  79     }
  80 
  81     // Set per-method thresholds.
  82     double scale = 1.0;
  83     CompilerOracle::has_option_value(mh, "CompileThresholdScaling", scale);
  84 
  85     int compile_threshold = Arguments::scaled_compile_threshold(CompileThreshold, scale);
  86     _interpreter_invocation_limit = compile_threshold << InvocationCounter::count_shift;
  87     if (ProfileInterpreter) {
  88       // If interpreter profiling is enabled, the backward branch limit
  89       // is compared against the method data counter rather than an invocation
  90       // counter, therefore no shifting of bits is required.
  91       _interpreter_backward_branch_limit = (compile_threshold * (OnStackReplacePercentage - InterpreterProfilePercentage)) / 100;
  92     } else {
  93       _interpreter_backward_branch_limit = ((compile_threshold * OnStackReplacePercentage) / 100) << InvocationCounter::count_shift;
  94     }
  95     _interpreter_profile_limit = ((compile_threshold * InterpreterProfilePercentage) / 100) << InvocationCounter::count_shift;
  96     _invoke_mask = right_n_bits(Arguments::scaled_freq_log(Tier0InvokeNotifyFreqLog, scale)) << InvocationCounter::count_shift;
  97     _backedge_mask = right_n_bits(Arguments::scaled_freq_log(Tier0BackedgeNotifyFreqLog, scale)) << InvocationCounter::count_shift;
  98   }
  99 
 100  public:
 101   static MethodCounters* allocate(methodHandle mh, TRAPS);
 102 
 103   void deallocate_contents(ClassLoaderData* loader_data) {}
 104   DEBUG_ONLY(bool on_stack() { return false; })  // for template
 105 
 106   static int size() { return sizeof(MethodCounters) / wordSize; }
 107 
 108   bool is_klass() const { return false; }
 109 
 110   void clear_counters();
 111 
 112   int interpreter_invocation_count() {

 113     return _interpreter_invocation_count;



 114   }
 115   void set_interpreter_invocation_count(int count) {

 116     _interpreter_invocation_count = count;



 117   }

 118   int increment_interpreter_invocation_count() {
 119     return ++_interpreter_invocation_count;
 120   }

 121 

 122   void interpreter_throwout_increment() {
 123     if (_interpreter_throwout_count < 65534) {
 124       _interpreter_throwout_count++;
 125     }
 126   }

 127   int  interpreter_throwout_count() const {

 128     return _interpreter_throwout_count;



 129   }
 130   void set_interpreter_throwout_count(int count) {

 131     _interpreter_throwout_count = count;



 132   }
 133 
 134   u2   number_of_breakpoints() const   { return _number_of_breakpoints; }
 135   void incr_number_of_breakpoints()    { ++_number_of_breakpoints; }
 136   void decr_number_of_breakpoints()    { --_number_of_breakpoints; }
 137   void clear_number_of_breakpoints()   { _number_of_breakpoints = 0; }
 138 
 139 #ifdef TIERED
 140   jlong prev_time() const                        { return _prev_time; }
 141   void set_prev_time(jlong time)                 { _prev_time = time; }
 142   float rate() const                             { return _rate; }
 143   void set_rate(float rate)                      { _rate = rate; }
 144 #endif
 145 
 146   int highest_comp_level() const;
 147   void set_highest_comp_level(int level);
 148   int highest_osr_comp_level() const;
 149   void set_highest_osr_comp_level(int level);
 150 
 151   // invocation counter


 154 
 155   int nmethod_age() {
 156     return _nmethod_age;
 157   }
 158   void set_nmethod_age(int age) {
 159     _nmethod_age = age;
 160   }
 161   void reset_nmethod_age() {
 162     set_nmethod_age(HotMethodDetectionLimit);
 163   }
 164 
 165   static bool is_nmethod_hot(int age)       { return age <= 0; }
 166   static bool is_nmethod_warm(int age)      { return age < HotMethodDetectionLimit; }
 167   static bool is_nmethod_age_unset(int age) { return age > HotMethodDetectionLimit; }
 168 
 169   static ByteSize nmethod_age_offset() {
 170     return byte_offset_of(MethodCounters, _nmethod_age);
 171   }
 172 
 173   static ByteSize interpreter_invocation_counter_offset() {

 174     return byte_offset_of(MethodCounters, _interpreter_invocation_count);




 175   }
 176 
 177   static ByteSize invocation_counter_offset()    {
 178     return byte_offset_of(MethodCounters, _invocation_counter);
 179   }
 180 
 181   static ByteSize backedge_counter_offset()      {
 182     return byte_offset_of(MethodCounters, _backedge_counter);
 183   }
 184 

 185   static int interpreter_invocation_counter_offset_in_bytes() {
 186     return offset_of(MethodCounters, _interpreter_invocation_count);
 187   }

 188 
 189   static ByteSize interpreter_invocation_limit_offset() {
 190     return byte_offset_of(MethodCounters, _interpreter_invocation_limit);
 191   }
 192 
 193   static ByteSize interpreter_backward_branch_limit_offset() {
 194     return byte_offset_of(MethodCounters, _interpreter_backward_branch_limit);
 195   }
 196 
 197   static ByteSize interpreter_profile_limit_offset() {
 198     return byte_offset_of(MethodCounters, _interpreter_profile_limit);
 199   }
 200 
 201   static ByteSize invoke_mask_offset() {
 202     return byte_offset_of(MethodCounters, _invoke_mask);
 203   }
 204 
 205   static ByteSize backedge_mask_offset() {
 206     return byte_offset_of(MethodCounters, _backedge_mask);
 207   }
   1 /*
   2  * Copyright (c) 2013, 2016 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  */
  24 
  25 #ifndef SHARE_VM_OOPS_METHODCOUNTERS_HPP
  26 #define SHARE_VM_OOPS_METHODCOUNTERS_HPP
  27 
  28 #include "oops/metadata.hpp"
  29 #include "compiler/compilerOracle.hpp"
  30 #include "interpreter/invocationCounter.hpp"
  31 #include "runtime/arguments.hpp"
  32 
  33 class MethodCounters: public MetaspaceObj {
  34  friend class VMStructs;
  35  friend class JVMCIVMStructs;
  36  private:
  37 #if defined(COMPILER2) || INCLUDE_JVMCI
  38   int               _interpreter_invocation_count; // Count of times invoked (reused as prev_event_count in tiered)
  39   u2                _interpreter_throwout_count; // Count of times method was exited via exception while interpreting
  40 #endif
  41   u2                _number_of_breakpoints;      // fullspeed debugging support
  42   InvocationCounter _invocation_counter;         // Incremented before each activation of the method - used to trigger frequency-based optimizations
  43   InvocationCounter _backedge_counter;           // Incremented before each backedge taken - used to trigger frequencey-based optimizations
  44   // NMethod age is a counter for warm methods detection in the code cache sweeper.
  45   // The counter is reset by the sweeper and is decremented by some of the compiled
  46   // code. The counter values are interpreted as follows:
  47   // 1. (HotMethodDetection..INT_MAX] - initial value, no counters inserted
  48   // 2. [1..HotMethodDetectionLimit)  - the method is warm, the counter is used
  49   //                                    to figure out which methods can be flushed.
  50   // 3. (INT_MIN..0]                  - method is hot and will deopt and get
  51   //                                    recompiled without the counters
  52   int               _nmethod_age;
  53   int               _interpreter_invocation_limit;        // per-method InterpreterInvocationLimit
  54   int               _interpreter_backward_branch_limit;   // per-method InterpreterBackwardBranchLimit
  55   int               _interpreter_profile_limit;           // per-method InterpreterProfileLimit
  56   int               _invoke_mask;                         // per-method Tier0InvokeNotifyFreqLog
  57   int               _backedge_mask;                       // per-method Tier0BackedgeNotifyFreqLog
  58 #ifdef TIERED
  59   float             _rate;                        // Events (invocation and backedge counter increments) per millisecond
  60   jlong             _prev_time;                   // Previous time the rate was acquired
  61   u1                _highest_comp_level;          // Highest compile level this method has ever seen.
  62   u1                _highest_osr_comp_level;      // Same for OSR level
  63 #endif
  64 
  65   MethodCounters(methodHandle mh) : _number_of_breakpoints(0),


  66                                     _nmethod_age(INT_MAX)
  67 #ifdef TIERED
  68                                  , _rate(0),
  69                                    _prev_time(0),
  70                                    _highest_comp_level(0),
  71                                    _highest_osr_comp_level(0)
  72 #endif
  73   {
  74     set_interpreter_invocation_count(0);
  75     set_interpreter_throwout_count(0);
  76     invocation_counter()->init();
  77     backedge_counter()->init();
  78 
  79     if (StressCodeAging) {
  80       set_nmethod_age(HotMethodDetectionLimit);
  81     }
  82 
  83     // Set per-method thresholds.
  84     double scale = 1.0;
  85     CompilerOracle::has_option_value(mh, "CompileThresholdScaling", scale);
  86 
  87     int compile_threshold = Arguments::scaled_compile_threshold(CompileThreshold, scale);
  88     _interpreter_invocation_limit = compile_threshold << InvocationCounter::count_shift;
  89     if (ProfileInterpreter) {
  90       // If interpreter profiling is enabled, the backward branch limit
  91       // is compared against the method data counter rather than an invocation
  92       // counter, therefore no shifting of bits is required.
  93       _interpreter_backward_branch_limit = (compile_threshold * (OnStackReplacePercentage - InterpreterProfilePercentage)) / 100;
  94     } else {
  95       _interpreter_backward_branch_limit = ((compile_threshold * OnStackReplacePercentage) / 100) << InvocationCounter::count_shift;
  96     }
  97     _interpreter_profile_limit = ((compile_threshold * InterpreterProfilePercentage) / 100) << InvocationCounter::count_shift;
  98     _invoke_mask = right_n_bits(Arguments::scaled_freq_log(Tier0InvokeNotifyFreqLog, scale)) << InvocationCounter::count_shift;
  99     _backedge_mask = right_n_bits(Arguments::scaled_freq_log(Tier0BackedgeNotifyFreqLog, scale)) << InvocationCounter::count_shift;
 100   }
 101 
 102  public:
 103   static MethodCounters* allocate(methodHandle mh, TRAPS);
 104 
 105   void deallocate_contents(ClassLoaderData* loader_data) {}
 106   DEBUG_ONLY(bool on_stack() { return false; })  // for template
 107 
 108   static int size() { return sizeof(MethodCounters) / wordSize; }
 109 
 110   bool is_klass() const { return false; }
 111 
 112   void clear_counters();
 113 
 114   int interpreter_invocation_count() {
 115 #if defined(COMPILER2) || INCLUDE_JVMCI
 116     return _interpreter_invocation_count;
 117 #else
 118     return 0;
 119 #endif
 120   }
 121   void set_interpreter_invocation_count(int count) {
 122 #if defined(COMPILER2) || INCLUDE_JVMCI
 123     _interpreter_invocation_count = count;
 124 #else
 125     assert(count == 0, "count must be 0");
 126 #endif
 127   }
 128 #if defined(COMPILER2) || INCLUDE_JVMCI
 129   int increment_interpreter_invocation_count() {
 130     return ++_interpreter_invocation_count;
 131   }
 132 #endif
 133 
 134 #if defined(COMPILER2) || INCLUDE_JVMCI
 135   void interpreter_throwout_increment() {
 136     if (_interpreter_throwout_count < 65534) {
 137       _interpreter_throwout_count++;
 138     }
 139   }
 140 #endif
 141   int  interpreter_throwout_count() const {
 142 #if defined(COMPILER2) || INCLUDE_JVMCI
 143     return _interpreter_throwout_count;
 144 #else
 145     return 0;
 146 #endif
 147   }
 148   void set_interpreter_throwout_count(int count) {
 149 #if defined(COMPILER2) || INCLUDE_JVMCI
 150     _interpreter_throwout_count = count;
 151 #else
 152     assert(count == 0, "count must be 0");
 153 #endif
 154   }
 155 
 156   u2   number_of_breakpoints() const   { return _number_of_breakpoints; }
 157   void incr_number_of_breakpoints()    { ++_number_of_breakpoints; }
 158   void decr_number_of_breakpoints()    { --_number_of_breakpoints; }
 159   void clear_number_of_breakpoints()   { _number_of_breakpoints = 0; }
 160 
 161 #ifdef TIERED
 162   jlong prev_time() const                        { return _prev_time; }
 163   void set_prev_time(jlong time)                 { _prev_time = time; }
 164   float rate() const                             { return _rate; }
 165   void set_rate(float rate)                      { _rate = rate; }
 166 #endif
 167 
 168   int highest_comp_level() const;
 169   void set_highest_comp_level(int level);
 170   int highest_osr_comp_level() const;
 171   void set_highest_osr_comp_level(int level);
 172 
 173   // invocation counter


 176 
 177   int nmethod_age() {
 178     return _nmethod_age;
 179   }
 180   void set_nmethod_age(int age) {
 181     _nmethod_age = age;
 182   }
 183   void reset_nmethod_age() {
 184     set_nmethod_age(HotMethodDetectionLimit);
 185   }
 186 
 187   static bool is_nmethod_hot(int age)       { return age <= 0; }
 188   static bool is_nmethod_warm(int age)      { return age < HotMethodDetectionLimit; }
 189   static bool is_nmethod_age_unset(int age) { return age > HotMethodDetectionLimit; }
 190 
 191   static ByteSize nmethod_age_offset() {
 192     return byte_offset_of(MethodCounters, _nmethod_age);
 193   }
 194 
 195   static ByteSize interpreter_invocation_counter_offset() {
 196 #if defined(COMPILER2) || INCLUDE_JVMCI
 197     return byte_offset_of(MethodCounters, _interpreter_invocation_count);
 198 #else
 199     ShouldNotReachHere();
 200     return in_ByteSize(0); 
 201 #endif
 202   }
 203 
 204   static ByteSize invocation_counter_offset()    {
 205     return byte_offset_of(MethodCounters, _invocation_counter);
 206   }
 207 
 208   static ByteSize backedge_counter_offset()      {
 209     return byte_offset_of(MethodCounters, _backedge_counter);
 210   }
 211 
 212 #if defined(COMPILER2) || INCLUDE_JVMCI
 213   static int interpreter_invocation_counter_offset_in_bytes() {
 214     return offset_of(MethodCounters, _interpreter_invocation_count);
 215   }
 216 #endif
 217 
 218   static ByteSize interpreter_invocation_limit_offset() {
 219     return byte_offset_of(MethodCounters, _interpreter_invocation_limit);
 220   }
 221 
 222   static ByteSize interpreter_backward_branch_limit_offset() {
 223     return byte_offset_of(MethodCounters, _interpreter_backward_branch_limit);
 224   }
 225 
 226   static ByteSize interpreter_profile_limit_offset() {
 227     return byte_offset_of(MethodCounters, _interpreter_profile_limit);
 228   }
 229 
 230   static ByteSize invoke_mask_offset() {
 231     return byte_offset_of(MethodCounters, _invoke_mask);
 232   }
 233 
 234   static ByteSize backedge_mask_offset() {
 235     return byte_offset_of(MethodCounters, _backedge_mask);
 236   }
< prev index next >