Wed, 03 Jul 2013 11:50:29 -0700
Merge
duke@435 | 1 | /* |
jiangli@4936 | 2 | * Copyright (c) 1997, 2013, Oracle and/or its affiliates. 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 | * |
trims@1907 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
trims@1907 | 20 | * or visit www.oracle.com if you need additional information or have any |
trims@1907 | 21 | * questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
stefank@2314 | 25 | #include "precompiled.hpp" |
stefank@2314 | 26 | #include "interpreter/invocationCounter.hpp" |
stefank@2314 | 27 | #include "runtime/frame.hpp" |
stefank@2314 | 28 | #include "runtime/handles.inline.hpp" |
duke@435 | 29 | |
duke@435 | 30 | |
duke@435 | 31 | // Implementation of InvocationCounter |
duke@435 | 32 | |
duke@435 | 33 | void InvocationCounter::init() { |
duke@435 | 34 | _counter = 0; // reset all the bits, including the sticky carry |
duke@435 | 35 | reset(); |
duke@435 | 36 | } |
duke@435 | 37 | |
duke@435 | 38 | void InvocationCounter::reset() { |
duke@435 | 39 | // Only reset the state and don't make the method look like it's never |
duke@435 | 40 | // been executed |
duke@435 | 41 | set_state(wait_for_compile); |
duke@435 | 42 | } |
duke@435 | 43 | |
duke@435 | 44 | void InvocationCounter::set_carry() { |
iveresov@2138 | 45 | set_carry_flag(); |
duke@435 | 46 | // The carry bit now indicates that this counter had achieved a very |
duke@435 | 47 | // large value. Now reduce the value, so that the method can be |
duke@435 | 48 | // executed many more times before re-entering the VM. |
duke@435 | 49 | int old_count = count(); |
duke@435 | 50 | int new_count = MIN2(old_count, (int) (CompileThreshold / 2)); |
coleenp@1089 | 51 | // prevent from going to zero, to distinguish from never-executed methods |
coleenp@1089 | 52 | if (new_count == 0) new_count = 1; |
duke@435 | 53 | if (old_count != new_count) set(state(), new_count); |
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 | |
duke@435 | 86 | const char* InvocationCounter::state_as_string(State state) { |
duke@435 | 87 | switch (state) { |
duke@435 | 88 | case wait_for_nothing : return "wait_for_nothing"; |
duke@435 | 89 | case wait_for_compile : return "wait_for_compile"; |
duke@435 | 90 | } |
duke@435 | 91 | ShouldNotReachHere(); |
duke@435 | 92 | return NULL; |
duke@435 | 93 | } |
duke@435 | 94 | |
duke@435 | 95 | const char* InvocationCounter::state_as_short_string(State state) { |
duke@435 | 96 | switch (state) { |
duke@435 | 97 | case wait_for_nothing : return "not comp."; |
duke@435 | 98 | case wait_for_compile : return "compileable"; |
duke@435 | 99 | } |
duke@435 | 100 | ShouldNotReachHere(); |
duke@435 | 101 | return NULL; |
duke@435 | 102 | } |
duke@435 | 103 | |
duke@435 | 104 | |
duke@435 | 105 | static address do_nothing(methodHandle method, TRAPS) { |
duke@435 | 106 | // dummy action for inactive invocation counters |
jiangli@4936 | 107 | MethodCounters* mcs = method->method_counters(); |
jiangli@4936 | 108 | assert(mcs != NULL, ""); |
jiangli@4936 | 109 | mcs->invocation_counter()->set_carry(); |
jiangli@4936 | 110 | mcs->invocation_counter()->set_state(InvocationCounter::wait_for_nothing); |
duke@435 | 111 | return NULL; |
duke@435 | 112 | } |
duke@435 | 113 | |
duke@435 | 114 | |
duke@435 | 115 | static address do_decay(methodHandle method, TRAPS) { |
duke@435 | 116 | // decay invocation counters so compilation gets delayed |
jiangli@4936 | 117 | MethodCounters* mcs = method->method_counters(); |
jiangli@4936 | 118 | assert(mcs != NULL, ""); |
jiangli@4936 | 119 | mcs->invocation_counter()->decay(); |
duke@435 | 120 | return NULL; |
duke@435 | 121 | } |
duke@435 | 122 | |
duke@435 | 123 | |
duke@435 | 124 | void InvocationCounter::def(State state, int init, Action action) { |
duke@435 | 125 | assert(0 <= state && state < number_of_states, "illegal state"); |
duke@435 | 126 | assert(0 <= init && init < count_limit, "initial value out of range"); |
duke@435 | 127 | _init [state] = init; |
duke@435 | 128 | _action[state] = action; |
duke@435 | 129 | } |
duke@435 | 130 | |
duke@435 | 131 | address dummy_invocation_counter_overflow(methodHandle m, TRAPS) { |
duke@435 | 132 | ShouldNotReachHere(); |
duke@435 | 133 | return NULL; |
duke@435 | 134 | } |
duke@435 | 135 | |
duke@435 | 136 | void InvocationCounter::reinitialize(bool delay_overflow) { |
duke@435 | 137 | // define states |
duke@435 | 138 | guarantee((int)number_of_states <= (int)state_limit, "adjust number_of_state_bits"); |
duke@435 | 139 | def(wait_for_nothing, 0, do_nothing); |
duke@435 | 140 | if (delay_overflow) { |
duke@435 | 141 | def(wait_for_compile, 0, do_decay); |
duke@435 | 142 | } else { |
duke@435 | 143 | def(wait_for_compile, 0, dummy_invocation_counter_overflow); |
duke@435 | 144 | } |
duke@435 | 145 | |
duke@435 | 146 | InterpreterInvocationLimit = CompileThreshold << number_of_noncount_bits; |
duke@435 | 147 | InterpreterProfileLimit = ((CompileThreshold * InterpreterProfilePercentage) / 100)<< number_of_noncount_bits; |
duke@435 | 148 | |
duke@435 | 149 | // When methodData is collected, the backward branch limit is compared against a |
duke@435 | 150 | // methodData counter, rather than an InvocationCounter. In the former case, we |
duke@435 | 151 | // don't need the shift by number_of_noncount_bits, but we do need to adjust |
duke@435 | 152 | // the factor by which we scale the threshold. |
duke@435 | 153 | if (ProfileInterpreter) { |
duke@435 | 154 | InterpreterBackwardBranchLimit = (CompileThreshold * (OnStackReplacePercentage - InterpreterProfilePercentage)) / 100; |
duke@435 | 155 | } else { |
duke@435 | 156 | InterpreterBackwardBranchLimit = ((CompileThreshold * OnStackReplacePercentage) / 100) << number_of_noncount_bits; |
duke@435 | 157 | } |
duke@435 | 158 | |
duke@435 | 159 | assert(0 <= InterpreterBackwardBranchLimit, |
duke@435 | 160 | "OSR threshold should be non-negative"); |
duke@435 | 161 | assert(0 <= InterpreterProfileLimit && |
duke@435 | 162 | InterpreterProfileLimit <= InterpreterInvocationLimit, |
duke@435 | 163 | "profile threshold should be less than the compilation threshold " |
duke@435 | 164 | "and non-negative"); |
duke@435 | 165 | } |
duke@435 | 166 | |
duke@435 | 167 | void invocationCounter_init() { |
duke@435 | 168 | InvocationCounter::reinitialize(DelayCompilationDuringStartup); |
duke@435 | 169 | } |