src/share/vm/interpreter/invocationCounter.hpp

Print this page




   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 // InvocationCounters are used to trigger actions when a limit (threshold) is reached.
  26 // For different states, different limits and actions can be defined in the initialization
  27 // routine of InvocationCounters.
  28 //
  29 // Implementation notes: For space reasons, state & counter are both encoded in one word,
  30 // The state is encoded using some of the least significant bits, the counter is using the
  31 // more significant bits. The counter is incremented before a method is activated and an
  32 // action is triggered when when count() > limit().
  33 
  34 class InvocationCounter VALUE_OBJ_CLASS_SPEC {
  35   friend class VMStructs;
  36  private:                             // bit no: |31  3|  2  | 1 0 |
  37   unsigned int _counter;              // format: [count|carry|state]
  38 
  39   enum PrivateConstants {
  40     number_of_state_bits = 2,
  41     number_of_carry_bits = 1,
  42     number_of_noncount_bits = number_of_state_bits + number_of_carry_bits,
  43     number_of_count_bits = BitsPerInt - number_of_noncount_bits,
  44     state_limit          = nth_bit(number_of_state_bits),


 117 
 118   static void        def(State state, int init, Action action);
 119   static const char* state_as_string(State state);
 120   static const char* state_as_short_string(State state);
 121 };
 122 
 123 inline void InvocationCounter::set(State state, int count) {
 124   assert(0 <= state && state < number_of_states, "illegal state");
 125   int carry = (_counter & carry_mask);    // the carry bit is sticky
 126   _counter = (count << number_of_noncount_bits) | carry | state;
 127 }
 128 
 129 inline void InvocationCounter::decay() {
 130   int c = count();
 131   int new_count = c >> 1;
 132   // prevent from going to zero, to distinguish from never-executed methods
 133   if (c > 0 && new_count == 0) new_count = 1;
 134   set(state(), new_count);
 135 }
 136 




   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_INTERPRETER_INVOCATIONCOUNTER_HPP
  26 #define SHARE_VM_INTERPRETER_INVOCATIONCOUNTER_HPP
  27 
  28 #include "memory/allocation.hpp"
  29 #include "runtime/handles.hpp"
  30 #include "utilities/exceptions.hpp"
  31 
  32 // InvocationCounters are used to trigger actions when a limit (threshold) is reached.
  33 // For different states, different limits and actions can be defined in the initialization
  34 // routine of InvocationCounters.
  35 //
  36 // Implementation notes: For space reasons, state & counter are both encoded in one word,
  37 // The state is encoded using some of the least significant bits, the counter is using the
  38 // more significant bits. The counter is incremented before a method is activated and an
  39 // action is triggered when when count() > limit().
  40 
  41 class InvocationCounter VALUE_OBJ_CLASS_SPEC {
  42   friend class VMStructs;
  43  private:                             // bit no: |31  3|  2  | 1 0 |
  44   unsigned int _counter;              // format: [count|carry|state]
  45 
  46   enum PrivateConstants {
  47     number_of_state_bits = 2,
  48     number_of_carry_bits = 1,
  49     number_of_noncount_bits = number_of_state_bits + number_of_carry_bits,
  50     number_of_count_bits = BitsPerInt - number_of_noncount_bits,
  51     state_limit          = nth_bit(number_of_state_bits),


 124 
 125   static void        def(State state, int init, Action action);
 126   static const char* state_as_string(State state);
 127   static const char* state_as_short_string(State state);
 128 };
 129 
 130 inline void InvocationCounter::set(State state, int count) {
 131   assert(0 <= state && state < number_of_states, "illegal state");
 132   int carry = (_counter & carry_mask);    // the carry bit is sticky
 133   _counter = (count << number_of_noncount_bits) | carry | state;
 134 }
 135 
 136 inline void InvocationCounter::decay() {
 137   int c = count();
 138   int new_count = c >> 1;
 139   // prevent from going to zero, to distinguish from never-executed methods
 140   if (c > 0 && new_count == 0) new_count = 1;
 141   set(state(), new_count);
 142 }
 143 
 144 
 145 #endif // SHARE_VM_INTERPRETER_INVOCATIONCOUNTER_HPP