src/share/vm/interpreter/invocationCounter.cpp

Wed, 03 Jul 2019 20:42:37 +0800

author
aoqi
date
Wed, 03 Jul 2019 20:42:37 +0800
changeset 9637
eef07cd490d4
parent 6876
710a3c8b516e
permissions
-rw-r--r--

Merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #include "precompiled.hpp"
aoqi@0 26 #include "interpreter/invocationCounter.hpp"
aoqi@0 27 #include "runtime/frame.hpp"
aoqi@0 28 #include "runtime/handles.inline.hpp"
aoqi@0 29
aoqi@0 30
aoqi@0 31 // Implementation of InvocationCounter
aoqi@0 32
aoqi@0 33 void InvocationCounter::init() {
aoqi@0 34 _counter = 0; // reset all the bits, including the sticky carry
aoqi@0 35 reset();
aoqi@0 36 }
aoqi@0 37
aoqi@0 38 void InvocationCounter::reset() {
aoqi@0 39 // Only reset the state and don't make the method look like it's never
aoqi@0 40 // been executed
aoqi@0 41 set_state(wait_for_compile);
aoqi@0 42 }
aoqi@0 43
aoqi@0 44 void InvocationCounter::set_carry() {
aoqi@0 45 set_carry_flag();
aoqi@0 46 // The carry bit now indicates that this counter had achieved a very
aoqi@0 47 // large value. Now reduce the value, so that the method can be
aoqi@0 48 // executed many more times before re-entering the VM.
aoqi@0 49 int old_count = count();
aoqi@0 50 int new_count = MIN2(old_count, (int) (CompileThreshold / 2));
aoqi@0 51 // prevent from going to zero, to distinguish from never-executed methods
aoqi@0 52 if (new_count == 0) new_count = 1;
aoqi@0 53 if (old_count != new_count) set(state(), new_count);
aoqi@0 54 }
aoqi@0 55
aoqi@0 56 void InvocationCounter::set_state(State state) {
aoqi@0 57 assert(0 <= state && state < number_of_states, "illegal state");
aoqi@0 58 int init = _init[state];
aoqi@0 59 // prevent from going to zero, to distinguish from never-executed methods
aoqi@0 60 if (init == 0 && count() > 0) init = 1;
aoqi@0 61 int carry = (_counter & carry_mask); // the carry bit is sticky
aoqi@0 62 _counter = (init << number_of_noncount_bits) | carry | state;
aoqi@0 63 }
aoqi@0 64
aoqi@0 65
aoqi@0 66 void InvocationCounter::print() {
aoqi@0 67 tty->print_cr("invocation count: up = %d, limit = %d, carry = %s, state = %s",
aoqi@0 68 count(), limit(),
aoqi@0 69 carry() ? "true" : "false",
aoqi@0 70 state_as_string(state()));
aoqi@0 71 }
aoqi@0 72
aoqi@0 73 void InvocationCounter::print_short() {
aoqi@0 74 tty->print(" [%d%s;%s]", count(), carry()?"+carry":"", state_as_short_string(state()));
aoqi@0 75 }
aoqi@0 76
aoqi@0 77 // Initialization
aoqi@0 78
aoqi@0 79 int InvocationCounter::_init [InvocationCounter::number_of_states];
aoqi@0 80 InvocationCounter::Action InvocationCounter::_action[InvocationCounter::number_of_states];
aoqi@0 81 int InvocationCounter::InterpreterInvocationLimit;
aoqi@0 82 int InvocationCounter::InterpreterBackwardBranchLimit;
aoqi@0 83 int InvocationCounter::InterpreterProfileLimit;
aoqi@0 84
aoqi@0 85
aoqi@0 86 const char* InvocationCounter::state_as_string(State state) {
aoqi@0 87 switch (state) {
aoqi@0 88 case wait_for_nothing : return "wait_for_nothing";
aoqi@0 89 case wait_for_compile : return "wait_for_compile";
aoqi@0 90 }
aoqi@0 91 ShouldNotReachHere();
aoqi@0 92 return NULL;
aoqi@0 93 }
aoqi@0 94
aoqi@0 95 const char* InvocationCounter::state_as_short_string(State state) {
aoqi@0 96 switch (state) {
aoqi@0 97 case wait_for_nothing : return "not comp.";
aoqi@0 98 case wait_for_compile : return "compileable";
aoqi@0 99 }
aoqi@0 100 ShouldNotReachHere();
aoqi@0 101 return NULL;
aoqi@0 102 }
aoqi@0 103
aoqi@0 104
aoqi@0 105 static address do_nothing(methodHandle method, TRAPS) {
aoqi@0 106 // dummy action for inactive invocation counters
aoqi@0 107 MethodCounters* mcs = method->method_counters();
aoqi@0 108 assert(mcs != NULL, "");
aoqi@0 109 mcs->invocation_counter()->set_carry();
aoqi@0 110 mcs->invocation_counter()->set_state(InvocationCounter::wait_for_nothing);
aoqi@0 111 return NULL;
aoqi@0 112 }
aoqi@0 113
aoqi@0 114
aoqi@0 115 static address do_decay(methodHandle method, TRAPS) {
aoqi@0 116 // decay invocation counters so compilation gets delayed
aoqi@0 117 MethodCounters* mcs = method->method_counters();
aoqi@0 118 assert(mcs != NULL, "");
aoqi@0 119 mcs->invocation_counter()->decay();
aoqi@0 120 return NULL;
aoqi@0 121 }
aoqi@0 122
aoqi@0 123
aoqi@0 124 void InvocationCounter::def(State state, int init, Action action) {
aoqi@0 125 assert(0 <= state && state < number_of_states, "illegal state");
aoqi@0 126 assert(0 <= init && init < count_limit, "initial value out of range");
aoqi@0 127 _init [state] = init;
aoqi@0 128 _action[state] = action;
aoqi@0 129 }
aoqi@0 130
aoqi@0 131 address dummy_invocation_counter_overflow(methodHandle m, TRAPS) {
aoqi@0 132 ShouldNotReachHere();
aoqi@0 133 return NULL;
aoqi@0 134 }
aoqi@0 135
aoqi@0 136 void InvocationCounter::reinitialize(bool delay_overflow) {
aoqi@0 137 // define states
aoqi@0 138 guarantee((int)number_of_states <= (int)state_limit, "adjust number_of_state_bits");
aoqi@0 139 def(wait_for_nothing, 0, do_nothing);
aoqi@0 140 if (delay_overflow) {
aoqi@0 141 def(wait_for_compile, 0, do_decay);
aoqi@0 142 } else {
aoqi@0 143 def(wait_for_compile, 0, dummy_invocation_counter_overflow);
aoqi@0 144 }
aoqi@0 145
aoqi@0 146 InterpreterInvocationLimit = CompileThreshold << number_of_noncount_bits;
aoqi@0 147 InterpreterProfileLimit = ((CompileThreshold * InterpreterProfilePercentage) / 100)<< number_of_noncount_bits;
aoqi@0 148
aoqi@0 149 // When methodData is collected, the backward branch limit is compared against a
aoqi@0 150 // methodData counter, rather than an InvocationCounter. In the former case, we
aoqi@0 151 // don't need the shift by number_of_noncount_bits, but we do need to adjust
aoqi@0 152 // the factor by which we scale the threshold.
aoqi@0 153 if (ProfileInterpreter) {
aoqi@0 154 InterpreterBackwardBranchLimit = (CompileThreshold * (OnStackReplacePercentage - InterpreterProfilePercentage)) / 100;
aoqi@0 155 } else {
aoqi@0 156 InterpreterBackwardBranchLimit = ((CompileThreshold * OnStackReplacePercentage) / 100) << number_of_noncount_bits;
aoqi@0 157 }
aoqi@0 158
aoqi@0 159 assert(0 <= InterpreterBackwardBranchLimit,
aoqi@0 160 "OSR threshold should be non-negative");
aoqi@0 161 assert(0 <= InterpreterProfileLimit &&
aoqi@0 162 InterpreterProfileLimit <= InterpreterInvocationLimit,
aoqi@0 163 "profile threshold should be less than the compilation threshold "
aoqi@0 164 "and non-negative");
aoqi@0 165 }
aoqi@0 166
aoqi@0 167 void invocationCounter_init() {
aoqi@0 168 InvocationCounter::reinitialize(DelayCompilationDuringStartup);
aoqi@0 169 }

mercurial