1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/interpreter/invocationCounter.cpp Sat Dec 01 00:00:00 2007 +0000 1.3 @@ -0,0 +1,170 @@ 1.4 +/* 1.5 + * Copyright 1997-2007 Sun Microsystems, Inc. All Rights Reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 1.24 + * have any questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +# include "incls/_precompiled.incl" 1.29 +# include "incls/_invocationCounter.cpp.incl" 1.30 + 1.31 + 1.32 +// Implementation of InvocationCounter 1.33 + 1.34 +void InvocationCounter::init() { 1.35 + _counter = 0; // reset all the bits, including the sticky carry 1.36 + reset(); 1.37 +} 1.38 + 1.39 +void InvocationCounter::reset() { 1.40 + // Only reset the state and don't make the method look like it's never 1.41 + // been executed 1.42 + set_state(wait_for_compile); 1.43 +} 1.44 + 1.45 +void InvocationCounter::set_carry() { 1.46 + _counter |= carry_mask; 1.47 + 1.48 + // The carry bit now indicates that this counter had achieved a very 1.49 + // large value. Now reduce the value, so that the method can be 1.50 + // executed many more times before re-entering the VM. 1.51 + int old_count = count(); 1.52 + int new_count = MIN2(old_count, (int) (CompileThreshold / 2)); 1.53 + if (old_count != new_count) set(state(), new_count); 1.54 +} 1.55 + 1.56 + 1.57 +void InvocationCounter::set_state(State state) { 1.58 + assert(0 <= state && state < number_of_states, "illegal state"); 1.59 + int init = _init[state]; 1.60 + // prevent from going to zero, to distinguish from never-executed methods 1.61 + if (init == 0 && count() > 0) init = 1; 1.62 + int carry = (_counter & carry_mask); // the carry bit is sticky 1.63 + _counter = (init << number_of_noncount_bits) | carry | state; 1.64 +} 1.65 + 1.66 + 1.67 +void InvocationCounter::print() { 1.68 + tty->print_cr("invocation count: up = %d, limit = %d, carry = %s, state = %s", 1.69 + count(), limit(), 1.70 + carry() ? "true" : "false", 1.71 + state_as_string(state())); 1.72 +} 1.73 + 1.74 +void InvocationCounter::print_short() { 1.75 + tty->print(" [%d%s;%s]", count(), carry()?"+carry":"", state_as_short_string(state())); 1.76 +} 1.77 + 1.78 +// Initialization 1.79 + 1.80 +int InvocationCounter::_init [InvocationCounter::number_of_states]; 1.81 +InvocationCounter::Action InvocationCounter::_action[InvocationCounter::number_of_states]; 1.82 +int InvocationCounter::InterpreterInvocationLimit; 1.83 +int InvocationCounter::InterpreterBackwardBranchLimit; 1.84 +int InvocationCounter::InterpreterProfileLimit; 1.85 + 1.86 +// Tier1 limits 1.87 +int InvocationCounter::Tier1InvocationLimit; 1.88 +int InvocationCounter::Tier1BackEdgeLimit; 1.89 + 1.90 + 1.91 + 1.92 +const char* InvocationCounter::state_as_string(State state) { 1.93 + switch (state) { 1.94 + case wait_for_nothing : return "wait_for_nothing"; 1.95 + case wait_for_compile : return "wait_for_compile"; 1.96 + } 1.97 + ShouldNotReachHere(); 1.98 + return NULL; 1.99 +} 1.100 + 1.101 +const char* InvocationCounter::state_as_short_string(State state) { 1.102 + switch (state) { 1.103 + case wait_for_nothing : return "not comp."; 1.104 + case wait_for_compile : return "compileable"; 1.105 + } 1.106 + ShouldNotReachHere(); 1.107 + return NULL; 1.108 +} 1.109 + 1.110 + 1.111 +static address do_nothing(methodHandle method, TRAPS) { 1.112 + // dummy action for inactive invocation counters 1.113 + method->invocation_counter()->set_carry(); 1.114 + method->invocation_counter()->set_state(InvocationCounter::wait_for_nothing); 1.115 + return NULL; 1.116 +} 1.117 + 1.118 + 1.119 +static address do_decay(methodHandle method, TRAPS) { 1.120 + // decay invocation counters so compilation gets delayed 1.121 + method->invocation_counter()->decay(); 1.122 + return NULL; 1.123 +} 1.124 + 1.125 + 1.126 +void InvocationCounter::def(State state, int init, Action action) { 1.127 + assert(0 <= state && state < number_of_states, "illegal state"); 1.128 + assert(0 <= init && init < count_limit, "initial value out of range"); 1.129 + _init [state] = init; 1.130 + _action[state] = action; 1.131 +} 1.132 + 1.133 +address dummy_invocation_counter_overflow(methodHandle m, TRAPS) { 1.134 + ShouldNotReachHere(); 1.135 + return NULL; 1.136 +} 1.137 + 1.138 +void InvocationCounter::reinitialize(bool delay_overflow) { 1.139 + // define states 1.140 + guarantee((int)number_of_states <= (int)state_limit, "adjust number_of_state_bits"); 1.141 + def(wait_for_nothing, 0, do_nothing); 1.142 + if (delay_overflow) { 1.143 + def(wait_for_compile, 0, do_decay); 1.144 + } else { 1.145 + def(wait_for_compile, 0, dummy_invocation_counter_overflow); 1.146 + } 1.147 + 1.148 + InterpreterInvocationLimit = CompileThreshold << number_of_noncount_bits; 1.149 + InterpreterProfileLimit = ((CompileThreshold * InterpreterProfilePercentage) / 100)<< number_of_noncount_bits; 1.150 + Tier1InvocationLimit = Tier2CompileThreshold << number_of_noncount_bits; 1.151 + Tier1BackEdgeLimit = Tier2BackEdgeThreshold << number_of_noncount_bits; 1.152 + 1.153 + // When methodData is collected, the backward branch limit is compared against a 1.154 + // methodData counter, rather than an InvocationCounter. In the former case, we 1.155 + // don't need the shift by number_of_noncount_bits, but we do need to adjust 1.156 + // the factor by which we scale the threshold. 1.157 + if (ProfileInterpreter) { 1.158 + InterpreterBackwardBranchLimit = (CompileThreshold * (OnStackReplacePercentage - InterpreterProfilePercentage)) / 100; 1.159 + } else { 1.160 + InterpreterBackwardBranchLimit = ((CompileThreshold * OnStackReplacePercentage) / 100) << number_of_noncount_bits; 1.161 + } 1.162 + 1.163 + assert(0 <= InterpreterBackwardBranchLimit, 1.164 + "OSR threshold should be non-negative"); 1.165 + assert(0 <= InterpreterProfileLimit && 1.166 + InterpreterProfileLimit <= InterpreterInvocationLimit, 1.167 + "profile threshold should be less than the compilation threshold " 1.168 + "and non-negative"); 1.169 +} 1.170 + 1.171 +void invocationCounter_init() { 1.172 + InvocationCounter::reinitialize(DelayCompilationDuringStartup); 1.173 +}