src/share/vm/interpreter/invocationCounter.hpp

Tue, 08 Aug 2017 15:57:29 +0800

author
aoqi
date
Tue, 08 Aug 2017 15:57:29 +0800
changeset 6876
710a3c8b516e
parent 6470
abe03600372a
parent 0
f90c822e73f8
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #ifndef SHARE_VM_INTERPRETER_INVOCATIONCOUNTER_HPP
aoqi@0 26 #define SHARE_VM_INTERPRETER_INVOCATIONCOUNTER_HPP
aoqi@0 27
aoqi@0 28 #include "memory/allocation.hpp"
aoqi@0 29 #include "runtime/handles.hpp"
aoqi@0 30 #include "utilities/exceptions.hpp"
aoqi@0 31
aoqi@0 32 // InvocationCounters are used to trigger actions when a limit (threshold) is reached.
aoqi@0 33 // For different states, different limits and actions can be defined in the initialization
aoqi@0 34 // routine of InvocationCounters.
aoqi@0 35 //
aoqi@0 36 // Implementation notes: For space reasons, state & counter are both encoded in one word,
aoqi@0 37 // The state is encoded using some of the least significant bits, the counter is using the
aoqi@0 38 // more significant bits. The counter is incremented before a method is activated and an
aoqi@0 39 // action is triggered when when count() > limit().
aoqi@0 40
aoqi@0 41 class InvocationCounter VALUE_OBJ_CLASS_SPEC {
aoqi@0 42 friend class VMStructs;
aoqi@0 43 friend class ciReplay;
aoqi@0 44 private: // bit no: |31 3| 2 | 1 0 |
aoqi@0 45 unsigned int _counter; // format: [count|carry|state]
aoqi@0 46
aoqi@0 47 enum PrivateConstants {
aoqi@0 48 number_of_state_bits = 2,
aoqi@0 49 number_of_carry_bits = 1,
aoqi@0 50 number_of_noncount_bits = number_of_state_bits + number_of_carry_bits,
aoqi@0 51 number_of_count_bits = BitsPerInt - number_of_noncount_bits,
aoqi@0 52 state_limit = nth_bit(number_of_state_bits),
aoqi@0 53 count_grain = nth_bit(number_of_state_bits + number_of_carry_bits),
aoqi@0 54 carry_mask = right_n_bits(number_of_carry_bits) << number_of_state_bits,
aoqi@0 55 state_mask = right_n_bits(number_of_state_bits),
aoqi@0 56 status_mask = right_n_bits(number_of_state_bits + number_of_carry_bits),
aoqi@0 57 count_mask = ((int)(-1) ^ status_mask)
aoqi@0 58 };
aoqi@0 59
aoqi@0 60 public:
aoqi@0 61 static int InterpreterInvocationLimit; // CompileThreshold scaled for interpreter use
aoqi@0 62 static int InterpreterBackwardBranchLimit; // A separate threshold for on stack replacement
aoqi@0 63 static int InterpreterProfileLimit; // Profiling threshold scaled for interpreter use
aoqi@0 64
aoqi@0 65 typedef address (*Action)(methodHandle method, TRAPS);
aoqi@0 66
aoqi@0 67 enum PublicConstants {
aoqi@0 68 count_increment = count_grain, // use this value to increment the 32bit _counter word
aoqi@0 69 count_mask_value = count_mask, // use this value to mask the backedge counter
aoqi@0 70 count_shift = number_of_noncount_bits,
aoqi@0 71 count_limit = nth_bit(number_of_count_bits - 1)
aoqi@0 72 };
aoqi@0 73
aoqi@0 74 enum State {
aoqi@0 75 wait_for_nothing, // do nothing when count() > limit()
aoqi@0 76 wait_for_compile, // introduce nmethod when count() > limit()
aoqi@0 77 number_of_states // must be <= state_limit
aoqi@0 78 };
aoqi@0 79
aoqi@0 80 // Manipulation
aoqi@0 81 void reset(); // sets state to wait state
aoqi@0 82 void init(); // sets state into original state
aoqi@0 83 void set_state(State state); // sets state and initializes counter correspondingly
aoqi@0 84 inline void set(State state, int count); // sets state and counter
aoqi@0 85 inline void decay(); // decay counter (divide by two)
aoqi@0 86 void set_carry(); // set the sticky carry bit
aoqi@0 87 void set_carry_flag() { _counter |= carry_mask; }
aoqi@0 88
aoqi@0 89 int raw_counter() { return _counter; }
aoqi@0 90
aoqi@0 91 // Accessors
aoqi@0 92 State state() const { return (State)(_counter & state_mask); }
aoqi@0 93 bool carry() const { return (_counter & carry_mask) != 0; }
aoqi@0 94 int limit() const { return CompileThreshold; }
aoqi@0 95 Action action() const { return _action[state()]; }
aoqi@0 96 int count() const { return _counter >> number_of_noncount_bits; }
aoqi@0 97
aoqi@0 98 int get_InvocationLimit() const { return InterpreterInvocationLimit >> number_of_noncount_bits; }
aoqi@0 99 int get_BackwardBranchLimit() const { return InterpreterBackwardBranchLimit >> number_of_noncount_bits; }
aoqi@0 100 int get_ProfileLimit() const { return InterpreterProfileLimit >> number_of_noncount_bits; }
aoqi@0 101
aoqi@0 102 #ifdef CC_INTERP
aoqi@0 103 // Test counter using scaled limits like the asm interpreter would do rather than doing
aoqi@0 104 // the shifts to normalize the counter.
aoqi@0 105 // Checks sum of invocation_counter and backedge_counter as the template interpreter does.
aoqi@0 106 bool reached_InvocationLimit(InvocationCounter *back_edge_count) const {
aoqi@0 107 return (_counter & count_mask) + (back_edge_count->_counter & count_mask) >=
aoqi@0 108 (unsigned int) InterpreterInvocationLimit;
aoqi@0 109 }
aoqi@0 110 bool reached_BackwardBranchLimit(InvocationCounter *back_edge_count) const {
aoqi@0 111 return (_counter & count_mask) + (back_edge_count->_counter & count_mask) >=
aoqi@0 112 (unsigned int) InterpreterBackwardBranchLimit;
aoqi@0 113 }
aoqi@0 114 // Do this just like asm interpreter does for max speed.
aoqi@0 115 bool reached_ProfileLimit(InvocationCounter *back_edge_count) const {
aoqi@0 116 return (_counter & count_mask) + (back_edge_count->_counter & count_mask) >=
aoqi@0 117 (unsigned int) InterpreterProfileLimit;
aoqi@0 118 }
aoqi@0 119 #endif // CC_INTERP
aoqi@0 120
aoqi@0 121 void increment() { _counter += count_increment; }
aoqi@0 122
aoqi@0 123
aoqi@0 124 // Printing
aoqi@0 125 void print();
aoqi@0 126 void print_short();
aoqi@0 127
aoqi@0 128 // Miscellaneous
aoqi@0 129 static ByteSize counter_offset() { return byte_offset_of(InvocationCounter, _counter); }
aoqi@0 130 static void reinitialize(bool delay_overflow);
aoqi@0 131
aoqi@0 132 private:
aoqi@0 133 static int _init [number_of_states]; // the counter limits
aoqi@0 134 static Action _action[number_of_states]; // the actions
aoqi@0 135
aoqi@0 136 static void def(State state, int init, Action action);
aoqi@0 137 static const char* state_as_string(State state);
aoqi@0 138 static const char* state_as_short_string(State state);
aoqi@0 139 };
aoqi@0 140
aoqi@0 141 inline void InvocationCounter::set(State state, int count) {
aoqi@0 142 assert(0 <= state && state < number_of_states, "illegal state");
aoqi@0 143 int carry = (_counter & carry_mask); // the carry bit is sticky
aoqi@0 144 _counter = (count << number_of_noncount_bits) | carry | state;
aoqi@0 145 }
aoqi@0 146
aoqi@0 147 inline void InvocationCounter::decay() {
aoqi@0 148 int c = count();
aoqi@0 149 int new_count = c >> 1;
aoqi@0 150 // prevent from going to zero, to distinguish from never-executed methods
aoqi@0 151 if (c > 0 && new_count == 0) new_count = 1;
aoqi@0 152 set(state(), new_count);
aoqi@0 153 }
aoqi@0 154
aoqi@0 155
aoqi@0 156 #endif // SHARE_VM_INTERPRETER_INVOCATIONCOUNTER_HPP

mercurial