annotate src/share/vm/interpreter/invocationCounter.hpp @ 9928:a9311ec68721

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