Sun, 11 Oct 2009 16:19:25 -0700
6888953: some calls to function-like macros are missing semicolons
Reviewed-by: pbk, kvn
1 /*
2 * Copyright 1997-2009 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 *
23 */
25 # include "incls/_precompiled.incl"
26 # include "incls/_invocationCounter.cpp.incl"
29 // Implementation of InvocationCounter
31 void InvocationCounter::init() {
32 _counter = 0; // reset all the bits, including the sticky carry
33 reset();
34 }
36 void InvocationCounter::reset() {
37 // Only reset the state and don't make the method look like it's never
38 // been executed
39 set_state(wait_for_compile);
40 }
42 void InvocationCounter::set_carry() {
43 _counter |= carry_mask;
45 // The carry bit now indicates that this counter had achieved a very
46 // large value. Now reduce the value, so that the method can be
47 // executed many more times before re-entering the VM.
48 int old_count = count();
49 int new_count = MIN2(old_count, (int) (CompileThreshold / 2));
50 // prevent from going to zero, to distinguish from never-executed methods
51 if (new_count == 0) new_count = 1;
52 if (old_count != new_count) set(state(), new_count);
53 }
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 }
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 }
73 void InvocationCounter::print_short() {
74 tty->print(" [%d%s;%s]", count(), carry()?"+carry":"", state_as_short_string(state()));
75 }
77 // Initialization
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;
85 // Tier1 limits
86 int InvocationCounter::Tier1InvocationLimit;
87 int InvocationCounter::Tier1BackEdgeLimit;
91 const char* InvocationCounter::state_as_string(State state) {
92 switch (state) {
93 case wait_for_nothing : return "wait_for_nothing";
94 case wait_for_compile : return "wait_for_compile";
95 }
96 ShouldNotReachHere();
97 return NULL;
98 }
100 const char* InvocationCounter::state_as_short_string(State state) {
101 switch (state) {
102 case wait_for_nothing : return "not comp.";
103 case wait_for_compile : return "compileable";
104 }
105 ShouldNotReachHere();
106 return NULL;
107 }
110 static address do_nothing(methodHandle method, TRAPS) {
111 // dummy action for inactive invocation counters
112 method->invocation_counter()->set_carry();
113 method->invocation_counter()->set_state(InvocationCounter::wait_for_nothing);
114 return NULL;
115 }
118 static address do_decay(methodHandle method, TRAPS) {
119 // decay invocation counters so compilation gets delayed
120 method->invocation_counter()->decay();
121 return NULL;
122 }
125 void InvocationCounter::def(State state, int init, Action action) {
126 assert(0 <= state && state < number_of_states, "illegal state");
127 assert(0 <= init && init < count_limit, "initial value out of range");
128 _init [state] = init;
129 _action[state] = action;
130 }
132 address dummy_invocation_counter_overflow(methodHandle m, TRAPS) {
133 ShouldNotReachHere();
134 return NULL;
135 }
137 void InvocationCounter::reinitialize(bool delay_overflow) {
138 // define states
139 guarantee((int)number_of_states <= (int)state_limit, "adjust number_of_state_bits");
140 def(wait_for_nothing, 0, do_nothing);
141 if (delay_overflow) {
142 def(wait_for_compile, 0, do_decay);
143 } else {
144 def(wait_for_compile, 0, dummy_invocation_counter_overflow);
145 }
147 InterpreterInvocationLimit = CompileThreshold << number_of_noncount_bits;
148 InterpreterProfileLimit = ((CompileThreshold * InterpreterProfilePercentage) / 100)<< number_of_noncount_bits;
149 Tier1InvocationLimit = Tier2CompileThreshold << number_of_noncount_bits;
150 Tier1BackEdgeLimit = Tier2BackEdgeThreshold << number_of_noncount_bits;
152 // When methodData is collected, the backward branch limit is compared against a
153 // methodData counter, rather than an InvocationCounter. In the former case, we
154 // don't need the shift by number_of_noncount_bits, but we do need to adjust
155 // the factor by which we scale the threshold.
156 if (ProfileInterpreter) {
157 InterpreterBackwardBranchLimit = (CompileThreshold * (OnStackReplacePercentage - InterpreterProfilePercentage)) / 100;
158 } else {
159 InterpreterBackwardBranchLimit = ((CompileThreshold * OnStackReplacePercentage) / 100) << number_of_noncount_bits;
160 }
162 assert(0 <= InterpreterBackwardBranchLimit,
163 "OSR threshold should be non-negative");
164 assert(0 <= InterpreterProfileLimit &&
165 InterpreterProfileLimit <= InterpreterInvocationLimit,
166 "profile threshold should be less than the compilation threshold "
167 "and non-negative");
168 }
170 void invocationCounter_init() {
171 InvocationCounter::reinitialize(DelayCompilationDuringStartup);
172 }