Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/interpreter/invocationCounter.cpp
32285 views
/*1* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include "precompiled.hpp"25#include "interpreter/invocationCounter.hpp"26#include "runtime/frame.hpp"27#include "runtime/handles.inline.hpp"282930// Implementation of InvocationCounter3132void InvocationCounter::init() {33_counter = 0; // reset all the bits, including the sticky carry34reset();35}3637void InvocationCounter::reset() {38// Only reset the state and don't make the method look like it's never39// been executed40set_state(wait_for_compile);41}4243void InvocationCounter::set_carry() {44set_carry_flag();45// The carry bit now indicates that this counter had achieved a very46// large value. Now reduce the value, so that the method can be47// executed many more times before re-entering the VM.48int old_count = count();49int new_count = MIN2(old_count, (int) (CompileThreshold / 2));50// prevent from going to zero, to distinguish from never-executed methods51if (new_count == 0) new_count = 1;52if (old_count != new_count) set(state(), new_count);53}5455void InvocationCounter::set_state(State state) {56assert(0 <= state && state < number_of_states, "illegal state");57int init = _init[state];58// prevent from going to zero, to distinguish from never-executed methods59if (init == 0 && count() > 0) init = 1;60int carry = (_counter & carry_mask); // the carry bit is sticky61_counter = (init << number_of_noncount_bits) | carry | state;62}636465void InvocationCounter::print() {66tty->print_cr("invocation count: up = %d, limit = %d, carry = %s, state = %s",67count(), limit(),68carry() ? "true" : "false",69state_as_string(state()));70}7172void InvocationCounter::print_short() {73tty->print(" [%d%s;%s]", count(), carry()?"+carry":"", state_as_short_string(state()));74}7576// Initialization7778int InvocationCounter::_init [InvocationCounter::number_of_states];79InvocationCounter::Action InvocationCounter::_action[InvocationCounter::number_of_states];80int InvocationCounter::InterpreterInvocationLimit;81int InvocationCounter::InterpreterBackwardBranchLimit;82int InvocationCounter::InterpreterProfileLimit;838485const char* InvocationCounter::state_as_string(State state) {86switch (state) {87case wait_for_nothing : return "wait_for_nothing";88case wait_for_compile : return "wait_for_compile";89}90ShouldNotReachHere();91return NULL;92}9394const char* InvocationCounter::state_as_short_string(State state) {95switch (state) {96case wait_for_nothing : return "not comp.";97case wait_for_compile : return "compileable";98}99ShouldNotReachHere();100return NULL;101}102103104static address do_nothing(methodHandle method, TRAPS) {105// dummy action for inactive invocation counters106MethodCounters* mcs = method->method_counters();107assert(mcs != NULL, "");108mcs->invocation_counter()->set_carry();109mcs->invocation_counter()->set_state(InvocationCounter::wait_for_nothing);110return NULL;111}112113114static address do_decay(methodHandle method, TRAPS) {115// decay invocation counters so compilation gets delayed116MethodCounters* mcs = method->method_counters();117assert(mcs != NULL, "");118mcs->invocation_counter()->decay();119return NULL;120}121122123void InvocationCounter::def(State state, int init, Action action) {124assert(0 <= state && state < number_of_states, "illegal state");125assert(0 <= init && init < count_limit, "initial value out of range");126_init [state] = init;127_action[state] = action;128}129130address dummy_invocation_counter_overflow(methodHandle m, TRAPS) {131ShouldNotReachHere();132return NULL;133}134135void InvocationCounter::reinitialize(bool delay_overflow) {136// define states137guarantee((int)number_of_states <= (int)state_limit, "adjust number_of_state_bits");138def(wait_for_nothing, 0, do_nothing);139if (delay_overflow) {140def(wait_for_compile, 0, do_decay);141} else {142def(wait_for_compile, 0, dummy_invocation_counter_overflow);143}144145InterpreterInvocationLimit = CompileThreshold << number_of_noncount_bits;146InterpreterProfileLimit = ((CompileThreshold * InterpreterProfilePercentage) / 100)<< number_of_noncount_bits;147148// When methodData is collected, the backward branch limit is compared against a149// methodData counter, rather than an InvocationCounter. In the former case, we150// don't need the shift by number_of_noncount_bits, but we do need to adjust151// the factor by which we scale the threshold.152if (ProfileInterpreter) {153InterpreterBackwardBranchLimit = (CompileThreshold * (OnStackReplacePercentage - InterpreterProfilePercentage)) / 100;154} else {155InterpreterBackwardBranchLimit = ((CompileThreshold * OnStackReplacePercentage) / 100) << number_of_noncount_bits;156}157158assert(0 <= InterpreterBackwardBranchLimit,159"OSR threshold should be non-negative");160assert(0 <= InterpreterProfileLimit &&161InterpreterProfileLimit <= InterpreterInvocationLimit,162"profile threshold should be less than the compilation threshold "163"and non-negative");164}165166void invocationCounter_init() {167InvocationCounter::reinitialize(DelayCompilationDuringStartup);168}169170171