/* * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. * */ #include "precompiled.hpp" #include "interpreter/invocationCounter.hpp" #include "runtime/frame.hpp" #include "runtime/handles.inline.hpp" // Implementation of InvocationCounter void InvocationCounter::init() { _counter = 0; // reset all the bits, including the sticky carry } void InvocationCounter::reset() { uint counter = raw_counter(); int init = 0; // prevent from going to zero, to distinguish from never-executed methods if (count(counter) > 0) { init = 1; } counter = (init << number_of_noncount_bits) | (counter & carry_mask); set_raw(counter); } void InvocationCounter::set_carry_and_reduce() { // single read uint counter = raw_counter(); //update set_carry_flag(&counter); int old_count = count(counter); int new_count = MIN2(old_count, (int) (CompileThreshold / 2)); // prevent from going to zero, to distinguish from never-executed methods if (new_count == 0) { new_count = 1; } if (old_count != new_count) { set_count(&counter, new_count); } // single write set_raw(counter); } void InvocationCounter::set_carry_if_necessary() { // single read uint counter = raw_counter(); //update if (!carry(counter) && count(counter) > count_limit / 2) { set_carry_flag(&counter); set_raw(counter); } } void InvocationCounter::print() { tty->print_cr("invocation count: up = %d, carry = %s", count(), carry() ? "true" : "false"); } void InvocationCounter::print_short() { tty->print(" [%d%s]", count(), carry()?"+carry":""); } // Initialization int InvocationCounter::InterpreterInvocationLimit; int InvocationCounter::InterpreterBackwardBranchLimit; int InvocationCounter::InterpreterProfileLimit; void InvocationCounter::reinitialize(bool delay_overflow) { InterpreterInvocationLimit = CompileThreshold << number_of_noncount_bits; InterpreterProfileLimit = ((CompileThreshold * InterpreterProfilePercentage) / 100)<< number_of_noncount_bits; // When methodData is collected, the backward branch limit is compared against a // methodData counter, rather than an InvocationCounter. In the former case, we // don't need the shift by number_of_noncount_bits, but we do need to adjust // the factor by which we scale the threshold. if (ProfileInterpreter) { InterpreterBackwardBranchLimit = (CompileThreshold * (OnStackReplacePercentage - InterpreterProfilePercentage)) / 100; } else { InterpreterBackwardBranchLimit = ((CompileThreshold * OnStackReplacePercentage) / 100) << number_of_noncount_bits; } assert(0 <= InterpreterBackwardBranchLimit, "OSR threshold should be non-negative"); assert(0 <= InterpreterProfileLimit && InterpreterProfileLimit <= InterpreterInvocationLimit, "profile threshold should be less than the compilation threshold " "and non-negative"); } void invocationCounter_init() { InvocationCounter::reinitialize(DelayCompilationDuringStartup); }