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 #include "precompiled.hpp"
26 #include "interpreter/invocationCounter.hpp"
27 #include "runtime/frame.hpp"
28 #include "runtime/handles.inline.hpp"
29
30
31 // Implementation of InvocationCounter
32
33 void InvocationCounter::init() {
34 _counter = 0; // reset all the bits, including the sticky carry
35 reset();
36 }
37
38 void InvocationCounter::reset() {
39 // Only reset the state and don't make the method look like it's never
40 // been executed
41 set_state(wait_for_compile);
42 }
43
44 void InvocationCounter::set_carry() {
45 set_carry_flag();
46 // The carry bit now indicates that this counter had achieved a very
47 // large value. Now reduce the value, so that the method can be
48 // executed many more times before re-entering the VM.
49 int old_count = count();
50 int new_count = MIN2(old_count, (int) (CompileThreshold / 2));
51 // prevent from going to zero, to distinguish from never-executed methods
52 if (new_count == 0) new_count = 1;
53 if (old_count != new_count) set(state(), new_count);
54 }
55
56 void InvocationCounter::set_state(State state) {
57 assert(0 <= state && state < number_of_states, "illegal state");
58 int init = _init[state];
59 // prevent from going to zero, to distinguish from never-executed methods
60 if (init == 0 && count() > 0) init = 1;
61 int carry = (_counter & carry_mask); // the carry bit is sticky
62 _counter = (init << number_of_noncount_bits) | carry | state;
63 }
64
65
66 void InvocationCounter::print() {
67 tty->print_cr("invocation count: up = %d, limit = %d, carry = %s, state = %s",
68 count(), limit(),
69 carry() ? "true" : "false",
70 state_as_string(state()));
71 }
72
73 void InvocationCounter::print_short() {
74 tty->print(" [%d%s;%s]", count(), carry()?"+carry":"", state_as_short_string(state()));
75 }
76
77 // Initialization
78
79 int InvocationCounter::_init [InvocationCounter::number_of_states];
80 InvocationCounter::Action InvocationCounter::_action[InvocationCounter::number_of_states];
81 int InvocationCounter::InterpreterInvocationLimit;
82 int InvocationCounter::InterpreterBackwardBranchLimit;
83 int InvocationCounter::InterpreterProfileLimit;
84
85
86 const char* InvocationCounter::state_as_string(State state) {
87 switch (state) {
88 case wait_for_nothing : return "wait_for_nothing";
89 case wait_for_compile : return "wait_for_compile";
90 }
91 ShouldNotReachHere();
92 return NULL;
93 }
94
95 const char* InvocationCounter::state_as_short_string(State state) {
96 switch (state) {
97 case wait_for_nothing : return "not comp.";
98 case wait_for_compile : return "compileable";
99 }
100 ShouldNotReachHere();
101 return NULL;
102 }
103
104
105 static address do_nothing(methodHandle method, TRAPS) {
106 // dummy action for inactive invocation counters
107 MethodCounters* mcs = method->method_counters();
108 assert(mcs != NULL, "");
109 mcs->invocation_counter()->set_carry();
110 mcs->invocation_counter()->set_state(InvocationCounter::wait_for_nothing);
111 return NULL;
112 }
113
114
115 static address do_decay(methodHandle method, TRAPS) {
116 // decay invocation counters so compilation gets delayed
117 MethodCounters* mcs = method->method_counters();
118 assert(mcs != NULL, "");
119 mcs->invocation_counter()->decay();
120 return NULL;
121 }
122
123
124 void InvocationCounter::def(State state, int init, Action action) {
125 assert(0 <= state && state < number_of_states, "illegal state");
126 assert(0 <= init && init < count_limit, "initial value out of range");
127 _init [state] = init;
128 _action[state] = action;
129 }
130
131 address dummy_invocation_counter_overflow(methodHandle m, TRAPS) {
132 ShouldNotReachHere();
133 return NULL;
134 }
135
136 void InvocationCounter::reinitialize(bool delay_overflow) {
137 // define states
138 guarantee((int)number_of_states <= (int)state_limit, "adjust number_of_state_bits");
139 def(wait_for_nothing, 0, do_nothing);
140 if (delay_overflow) {
141 def(wait_for_compile, 0, do_decay);
142 } else {
143 def(wait_for_compile, 0, dummy_invocation_counter_overflow);
144 }
145
146 InterpreterInvocationLimit = CompileThreshold << number_of_noncount_bits;
147 InterpreterProfileLimit = ((CompileThreshold * InterpreterProfilePercentage) / 100)<< number_of_noncount_bits;
148
149 // When methodData is collected, the backward branch limit is compared against a
150 // methodData counter, rather than an InvocationCounter. In the former case, we
151 // don't need the shift by number_of_noncount_bits, but we do need to adjust
152 // the factor by which we scale the threshold.
153 if (ProfileInterpreter) {
154 InterpreterBackwardBranchLimit = (CompileThreshold * (OnStackReplacePercentage - InterpreterProfilePercentage)) / 100;
155 } else {
156 InterpreterBackwardBranchLimit = ((CompileThreshold * OnStackReplacePercentage) / 100) << number_of_noncount_bits;
157 }
158
159 assert(0 <= InterpreterBackwardBranchLimit,
160 "OSR threshold should be non-negative");
161 assert(0 <= InterpreterProfileLimit &&
162 InterpreterProfileLimit <= InterpreterInvocationLimit,
163 "profile threshold should be less than the compilation threshold "
164 "and non-negative");
165 }
|
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 #include "precompiled.hpp"
26 #include "interpreter/invocationCounter.hpp"
27 #include "runtime/frame.hpp"
28 #include "runtime/handles.inline.hpp"
29
30
31 // Implementation of InvocationCounter
32
33 void InvocationCounter::init() {
34 _counter = 0; // reset all the bits, including the sticky carry
35 }
36
37 void InvocationCounter::reset() {
38 uint counter = raw_counter();
39 int init = 0;
40 // prevent from going to zero, to distinguish from never-executed methods
41 if (count(counter) > 0) {
42 init = 1;
43 }
44 counter = (init << number_of_noncount_bits) | (counter & carry_mask);
45 set_raw(counter);
46 }
47
48 void InvocationCounter::set_carry_and_reduce() {
49 // single read
50 uint counter = raw_counter();
51
52 //update
53 set_carry_flag(&counter);
54 int old_count = count(counter);
55 int new_count = MIN2(old_count, (int) (CompileThreshold / 2));
56 // prevent from going to zero, to distinguish from never-executed methods
57 if (new_count == 0) {
58 new_count = 1;
59 }
60 if (old_count != new_count) {
61 set_count(&counter, new_count);
62 }
63
64 // single write
65 set_raw(counter);
66 }
67
68 void InvocationCounter::set_carry_if_necessary() {
69 // single read
70 uint counter = raw_counter();
71
72 //update
73 if (!carry(counter) && count(counter) > count_limit / 2) {
74 set_carry_flag(&counter);
75 set_raw(counter);
76 }
77 }
78
79 void InvocationCounter::print() {
80 tty->print_cr("invocation count: up = %d, carry = %s",
81 count(), carry() ? "true" : "false");
82 }
83
84 void InvocationCounter::print_short() {
85 tty->print(" [%d%s]", count(), carry()?"+carry":"");
86 }
87
88 // Initialization
89 int InvocationCounter::InterpreterInvocationLimit;
90 int InvocationCounter::InterpreterBackwardBranchLimit;
91 int InvocationCounter::InterpreterProfileLimit;
92
93 void InvocationCounter::reinitialize(bool delay_overflow) {
94 InterpreterInvocationLimit = CompileThreshold << number_of_noncount_bits;
95 InterpreterProfileLimit = ((CompileThreshold * InterpreterProfilePercentage) / 100)<< number_of_noncount_bits;
96
97 // When methodData is collected, the backward branch limit is compared against a
98 // methodData counter, rather than an InvocationCounter. In the former case, we
99 // don't need the shift by number_of_noncount_bits, but we do need to adjust
100 // the factor by which we scale the threshold.
101 if (ProfileInterpreter) {
102 InterpreterBackwardBranchLimit = (CompileThreshold * (OnStackReplacePercentage - InterpreterProfilePercentage)) / 100;
103 } else {
104 InterpreterBackwardBranchLimit = ((CompileThreshold * OnStackReplacePercentage) / 100) << number_of_noncount_bits;
105 }
106
107 assert(0 <= InterpreterBackwardBranchLimit,
108 "OSR threshold should be non-negative");
109 assert(0 <= InterpreterProfileLimit &&
110 InterpreterProfileLimit <= InterpreterInvocationLimit,
111 "profile threshold should be less than the compilation threshold "
112 "and non-negative");
113 }
|