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