src/share/vm/interpreter/invocationCounter.cpp

Fri, 03 Sep 2010 17:51:07 -0700

author
iveresov
date
Fri, 03 Sep 2010 17:51:07 -0700
changeset 2138
d5d065957597
parent 1907
c18cbe5936b8
child 2314
f95d63e2154a
permissions
-rw-r--r--

6953144: Tiered compilation
Summary: Infrastructure for tiered compilation support (interpreter + c1 + c2) for 32 and 64 bit. Simple tiered policy implementation.
Reviewed-by: kvn, never, phh, twisti

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

mercurial