Path: blob/master/src/hotspot/share/interpreter/invocationCounter.hpp
40949 views
/*1* Copyright (c) 1997, 2021, 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_INTERPRETER_INVOCATIONCOUNTER_HPP25#define SHARE_INTERPRETER_INVOCATIONCOUNTER_HPP2627#include "runtime/handles.hpp"28#include "utilities/exceptions.hpp"2930// InvocationCounters are used to trigger actions when a limit (threshold) is reached.31//32// The counter is incremented before a method is activated and an33// action is triggered when count() > limit().3435class InvocationCounter {36friend class VMStructs;37friend class JVMCIVMStructs;38friend class ciReplay;39private: // bit no: |31 1| 0 |40uint _counter; // format: [count|carry|4142enum PrivateConstants {43number_of_carry_bits = 1,44number_of_noncount_bits = number_of_carry_bits,45count_grain = nth_bit(number_of_carry_bits),46carry_mask = right_n_bits(number_of_carry_bits),47count_mask = ((int)(-1) ^ carry_mask)48};4950public:51enum PublicConstants {52count_increment = count_grain, // use this value to increment the 32bit _counter word53count_mask_value = count_mask, // use this value to mask the backedge counter54count_shift = number_of_noncount_bits,55number_of_count_bits = BitsPerInt - number_of_noncount_bits,56count_limit = nth_bit(number_of_count_bits - 1)57};5859// Manipulation60void reset();61void init();62void decay(); // decay counter (divide by two)63void set_carry_on_overflow();64void set(uint count);65void increment() { _counter += count_increment; }6667// Accessors68bool carry() const { return (_counter & carry_mask) != 0; }69uint count() const { return _counter >> number_of_noncount_bits; }70uint limit() const { return CompileThreshold; }71uint raw_counter() const { return _counter; }7273void print();7475private:76void set_carry() { _counter |= carry_mask; }77uint extract_carry(uint raw) const { return (raw & carry_mask); }78uint extract_count(uint raw) const { return raw >> number_of_noncount_bits; }79void update(uint new_count);80void set(uint count, uint carry);8182public:8384// Miscellaneous85static ByteSize counter_offset() { return byte_offset_of(InvocationCounter, _counter); }86};8788#endif // SHARE_INTERPRETER_INVOCATIONCOUNTER_HPP899091