Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/interpreter/invocationCounter.hpp
32285 views
/*1* Copyright (c) 1997, 2012, 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#ifndef SHARE_VM_INTERPRETER_INVOCATIONCOUNTER_HPP25#define SHARE_VM_INTERPRETER_INVOCATIONCOUNTER_HPP2627#include "memory/allocation.hpp"28#include "runtime/handles.hpp"29#include "utilities/exceptions.hpp"3031// InvocationCounters are used to trigger actions when a limit (threshold) is reached.32// For different states, different limits and actions can be defined in the initialization33// routine of InvocationCounters.34//35// Implementation notes: For space reasons, state & counter are both encoded in one word,36// The state is encoded using some of the least significant bits, the counter is using the37// more significant bits. The counter is incremented before a method is activated and an38// action is triggered when when count() > limit().3940class InvocationCounter VALUE_OBJ_CLASS_SPEC {41friend class VMStructs;42friend class ciReplay;43private: // bit no: |31 3| 2 | 1 0 |44unsigned int _counter; // format: [count|carry|state]4546enum PrivateConstants {47number_of_state_bits = 2,48number_of_carry_bits = 1,49number_of_noncount_bits = number_of_state_bits + number_of_carry_bits,50number_of_count_bits = BitsPerInt - number_of_noncount_bits,51state_limit = nth_bit(number_of_state_bits),52count_grain = nth_bit(number_of_state_bits + number_of_carry_bits),53carry_mask = right_n_bits(number_of_carry_bits) << number_of_state_bits,54state_mask = right_n_bits(number_of_state_bits),55status_mask = right_n_bits(number_of_state_bits + number_of_carry_bits),56count_mask = ((int)(-1) ^ status_mask)57};5859public:60static int InterpreterInvocationLimit; // CompileThreshold scaled for interpreter use61static int InterpreterBackwardBranchLimit; // A separate threshold for on stack replacement62static int InterpreterProfileLimit; // Profiling threshold scaled for interpreter use6364typedef address (*Action)(methodHandle method, TRAPS);6566enum PublicConstants {67count_increment = count_grain, // use this value to increment the 32bit _counter word68count_mask_value = count_mask, // use this value to mask the backedge counter69count_shift = number_of_noncount_bits,70count_limit = nth_bit(number_of_count_bits - 1)71};7273enum State {74wait_for_nothing, // do nothing when count() > limit()75wait_for_compile, // introduce nmethod when count() > limit()76number_of_states // must be <= state_limit77};7879// Manipulation80void reset(); // sets state to wait state81void init(); // sets state into original state82void set_state(State state); // sets state and initializes counter correspondingly83inline void set(State state, int count); // sets state and counter84inline void decay(); // decay counter (divide by two)85void set_carry(); // set the sticky carry bit86void set_carry_flag() { _counter |= carry_mask; }8788int raw_counter() { return _counter; }8990// Accessors91State state() const { return (State)(_counter & state_mask); }92bool carry() const { return (_counter & carry_mask) != 0; }93int limit() const { return CompileThreshold; }94Action action() const { return _action[state()]; }95int count() const { return _counter >> number_of_noncount_bits; }9697int get_InvocationLimit() const { return InterpreterInvocationLimit >> number_of_noncount_bits; }98int get_BackwardBranchLimit() const { return InterpreterBackwardBranchLimit >> number_of_noncount_bits; }99int get_ProfileLimit() const { return InterpreterProfileLimit >> number_of_noncount_bits; }100101#ifdef CC_INTERP102// Test counter using scaled limits like the asm interpreter would do rather than doing103// the shifts to normalize the counter.104// Checks sum of invocation_counter and backedge_counter as the template interpreter does.105bool reached_InvocationLimit(InvocationCounter *back_edge_count) const {106return (_counter & count_mask) + (back_edge_count->_counter & count_mask) >=107(unsigned int) InterpreterInvocationLimit;108}109bool reached_BackwardBranchLimit(InvocationCounter *back_edge_count) const {110return (_counter & count_mask) + (back_edge_count->_counter & count_mask) >=111(unsigned int) InterpreterBackwardBranchLimit;112}113// Do this just like asm interpreter does for max speed.114bool reached_ProfileLimit(InvocationCounter *back_edge_count) const {115return (_counter & count_mask) + (back_edge_count->_counter & count_mask) >=116(unsigned int) InterpreterProfileLimit;117}118#endif // CC_INTERP119120void increment() { _counter += count_increment; }121122123// Printing124void print();125void print_short();126127// Miscellaneous128static ByteSize counter_offset() { return byte_offset_of(InvocationCounter, _counter); }129static void reinitialize(bool delay_overflow);130131private:132static int _init [number_of_states]; // the counter limits133static Action _action[number_of_states]; // the actions134135static void def(State state, int init, Action action);136static const char* state_as_string(State state);137static const char* state_as_short_string(State state);138};139140inline void InvocationCounter::set(State state, int count) {141assert(0 <= state && state < number_of_states, "illegal state");142int carry = (_counter & carry_mask); // the carry bit is sticky143_counter = (count << number_of_noncount_bits) | carry | state;144}145146inline void InvocationCounter::decay() {147int c = count();148int new_count = c >> 1;149// prevent from going to zero, to distinguish from never-executed methods150if (c > 0 && new_count == 0) new_count = 1;151set(state(), new_count);152}153154155#endif // SHARE_VM_INTERPRETER_INVOCATIONCOUNTER_HPP156157158