src/share/vm/interpreter/invocationCounter.hpp

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

author
goetz
date
Sun, 15 Sep 2013 15:28:58 +0200
changeset 6470
abe03600372a
parent 4267
bd7a7ce2e264
child 6876
710a3c8b516e
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

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

mercurial