2007-12-01 00:00:00 +00:00
|
|
|
/*
|
2019-01-08 11:23:19 +01:00
|
|
|
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
|
2007-12-01 00:00:00 +00:00
|
|
|
* 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.
|
|
|
|
*
|
2010-05-27 19:08:38 -07:00
|
|
|
* 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.
|
2007-12-01 00:00:00 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2019-01-10 15:13:51 -05:00
|
|
|
#ifndef SHARE_INTERPRETER_INVOCATIONCOUNTER_HPP
|
|
|
|
#define SHARE_INTERPRETER_INVOCATIONCOUNTER_HPP
|
2010-11-23 13:22:55 -08:00
|
|
|
|
|
|
|
#include "runtime/handles.hpp"
|
|
|
|
#include "utilities/exceptions.hpp"
|
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
// InvocationCounters are used to trigger actions when a limit (threshold) is reached.
|
|
|
|
// For different states, different limits and actions can be defined in the initialization
|
|
|
|
// routine of InvocationCounters.
|
|
|
|
//
|
|
|
|
// Implementation notes: For space reasons, state & counter are both encoded in one word,
|
|
|
|
// The state is encoded using some of the least significant bits, the counter is using the
|
|
|
|
// more significant bits. The counter is incremented before a method is activated and an
|
2015-01-21 10:51:35 +01:00
|
|
|
// action is triggered when count() > limit().
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2018-03-09 10:46:02 -05:00
|
|
|
class InvocationCounter {
|
2007-12-01 00:00:00 +00:00
|
|
|
friend class VMStructs;
|
2016-10-05 11:32:50 -07:00
|
|
|
friend class JVMCIVMStructs;
|
2012-11-12 14:03:53 -08:00
|
|
|
friend class ciReplay;
|
2007-12-01 00:00:00 +00:00
|
|
|
private: // bit no: |31 3| 2 | 1 0 |
|
|
|
|
unsigned int _counter; // format: [count|carry|state]
|
|
|
|
|
|
|
|
enum PrivateConstants {
|
|
|
|
number_of_state_bits = 2,
|
|
|
|
number_of_carry_bits = 1,
|
|
|
|
number_of_noncount_bits = number_of_state_bits + number_of_carry_bits,
|
|
|
|
state_limit = nth_bit(number_of_state_bits),
|
|
|
|
count_grain = nth_bit(number_of_state_bits + number_of_carry_bits),
|
|
|
|
carry_mask = right_n_bits(number_of_carry_bits) << number_of_state_bits,
|
|
|
|
state_mask = right_n_bits(number_of_state_bits),
|
|
|
|
status_mask = right_n_bits(number_of_state_bits + number_of_carry_bits),
|
|
|
|
count_mask = ((int)(-1) ^ status_mask)
|
|
|
|
};
|
|
|
|
|
|
|
|
public:
|
2017-07-27 18:06:41 -04:00
|
|
|
typedef address (*Action)(const methodHandle& method, TRAPS);
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
enum PublicConstants {
|
|
|
|
count_increment = count_grain, // use this value to increment the 32bit _counter word
|
2010-09-03 17:51:07 -07:00
|
|
|
count_mask_value = count_mask, // use this value to mask the backedge counter
|
|
|
|
count_shift = number_of_noncount_bits,
|
2015-01-21 10:51:35 +01:00
|
|
|
number_of_count_bits = BitsPerInt - number_of_noncount_bits,
|
2010-09-03 17:51:07 -07:00
|
|
|
count_limit = nth_bit(number_of_count_bits - 1)
|
2007-12-01 00:00:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum State {
|
|
|
|
wait_for_nothing, // do nothing when count() > limit()
|
|
|
|
wait_for_compile, // introduce nmethod when count() > limit()
|
|
|
|
number_of_states // must be <= state_limit
|
|
|
|
};
|
|
|
|
|
|
|
|
// Manipulation
|
|
|
|
void reset(); // sets state to wait state
|
|
|
|
void init(); // sets state into original state
|
|
|
|
void set_state(State state); // sets state and initializes counter correspondingly
|
|
|
|
inline void set(State state, int count); // sets state and counter
|
|
|
|
inline void decay(); // decay counter (divide by two)
|
|
|
|
void set_carry(); // set the sticky carry bit
|
2010-09-03 17:51:07 -07:00
|
|
|
void set_carry_flag() { _counter |= carry_mask; }
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2012-11-12 14:03:53 -08:00
|
|
|
int raw_counter() { return _counter; }
|
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
// Accessors
|
|
|
|
State state() const { return (State)(_counter & state_mask); }
|
|
|
|
bool carry() const { return (_counter & carry_mask) != 0; }
|
|
|
|
int limit() const { return CompileThreshold; }
|
|
|
|
Action action() const { return _action[state()]; }
|
|
|
|
int count() const { return _counter >> number_of_noncount_bits; }
|
|
|
|
|
2013-09-15 15:28:58 +02:00
|
|
|
#ifdef CC_INTERP
|
2019-01-30 18:34:31 +01:00
|
|
|
static int InterpreterInvocationLimit; // CompileThreshold scaled for interpreter use
|
|
|
|
static int InterpreterBackwardBranchLimit; // A separate threshold for on stack replacement
|
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
// Test counter using scaled limits like the asm interpreter would do rather than doing
|
|
|
|
// the shifts to normalize the counter.
|
2013-09-15 15:28:58 +02:00
|
|
|
// Checks sum of invocation_counter and backedge_counter as the template interpreter does.
|
|
|
|
bool reached_InvocationLimit(InvocationCounter *back_edge_count) const {
|
|
|
|
return (_counter & count_mask) + (back_edge_count->_counter & count_mask) >=
|
|
|
|
(unsigned int) InterpreterInvocationLimit;
|
|
|
|
}
|
|
|
|
bool reached_BackwardBranchLimit(InvocationCounter *back_edge_count) const {
|
|
|
|
return (_counter & count_mask) + (back_edge_count->_counter & count_mask) >=
|
|
|
|
(unsigned int) InterpreterBackwardBranchLimit;
|
|
|
|
}
|
|
|
|
#endif // CC_INTERP
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
void increment() { _counter += count_increment; }
|
|
|
|
|
|
|
|
|
|
|
|
// Printing
|
|
|
|
void print();
|
|
|
|
void print_short();
|
|
|
|
|
|
|
|
// Miscellaneous
|
|
|
|
static ByteSize counter_offset() { return byte_offset_of(InvocationCounter, _counter); }
|
2019-01-08 11:23:19 +01:00
|
|
|
static void reinitialize();
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
static int _init [number_of_states]; // the counter limits
|
|
|
|
static Action _action[number_of_states]; // the actions
|
|
|
|
|
|
|
|
static void def(State state, int init, Action action);
|
|
|
|
static const char* state_as_string(State state);
|
|
|
|
static const char* state_as_short_string(State state);
|
|
|
|
};
|
|
|
|
|
|
|
|
inline void InvocationCounter::set(State state, int count) {
|
|
|
|
assert(0 <= state && state < number_of_states, "illegal state");
|
|
|
|
int carry = (_counter & carry_mask); // the carry bit is sticky
|
|
|
|
_counter = (count << number_of_noncount_bits) | carry | state;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void InvocationCounter::decay() {
|
|
|
|
int c = count();
|
|
|
|
int new_count = c >> 1;
|
|
|
|
// prevent from going to zero, to distinguish from never-executed methods
|
|
|
|
if (c > 0 && new_count == 0) new_count = 1;
|
|
|
|
set(state(), new_count);
|
|
|
|
}
|
2010-09-03 17:51:07 -07:00
|
|
|
|
2010-11-23 13:22:55 -08:00
|
|
|
|
2019-01-10 15:13:51 -05:00
|
|
|
#endif // SHARE_INTERPRETER_INVOCATIONCOUNTER_HPP
|