hotspot/src/share/vm/interpreter/invocationCounter.hpp
author psandoz
Thu, 24 Mar 2016 11:21:49 +0100
changeset 36819 bca375d368ed
parent 28650 772aaab2582f
child 41684 f02a4153a27a
permissions -rw-r--r--
8149644: Integrate VarHandles Reviewed-by: kvn, vlivanov
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
14477
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 7397
diff changeset
     2
 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    25
#ifndef SHARE_VM_INTERPRETER_INVOCATIONCOUNTER_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    26
#define SHARE_VM_INTERPRETER_INVOCATIONCOUNTER_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    27
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    28
#include "memory/allocation.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    29
#include "runtime/handles.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    30
#include "utilities/exceptions.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    31
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
// InvocationCounters are used to trigger actions when a limit (threshold) is reached.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
// For different states, different limits and actions can be defined in the initialization
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
// routine of InvocationCounters.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
// Implementation notes: For space reasons, state & counter are both encoded in one word,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
// The state is encoded using some of the least significant bits, the counter is using the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
// more significant bits. The counter is incremented before a method is activated and an
28650
772aaab2582f 8059606: Enable per-method usage of CompileThresholdScaling (per-method compilation thresholds)
zmajo
parents: 22836
diff changeset
    39
// action is triggered when count() > limit().
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
class InvocationCounter VALUE_OBJ_CLASS_SPEC {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  friend class VMStructs;
14477
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 7397
diff changeset
    43
  friend class ciReplay;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
 private:                             // bit no: |31  3|  2  | 1 0 |
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  unsigned int _counter;              // format: [count|carry|state]
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  enum PrivateConstants {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
    number_of_state_bits = 2,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
    number_of_carry_bits = 1,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
    number_of_noncount_bits = number_of_state_bits + number_of_carry_bits,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
    state_limit          = nth_bit(number_of_state_bits),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
    count_grain          = nth_bit(number_of_state_bits + number_of_carry_bits),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
    carry_mask           = right_n_bits(number_of_carry_bits) << number_of_state_bits,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
    state_mask           = right_n_bits(number_of_state_bits),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
    status_mask          = right_n_bits(number_of_state_bits + number_of_carry_bits),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
    count_mask           = ((int)(-1) ^ status_mask)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  static int InterpreterInvocationLimit;        // CompileThreshold scaled for interpreter use
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  static int InterpreterBackwardBranchLimit;    // A separate threshold for on stack replacement
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  static int InterpreterProfileLimit;           // Profiling threshold scaled for interpreter use
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  typedef address (*Action)(methodHandle method, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  enum PublicConstants {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
    count_increment      = count_grain,          // use this value to increment the 32bit _counter word
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5547
diff changeset
    68
    count_mask_value     = count_mask,           // use this value to mask the backedge counter
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5547
diff changeset
    69
    count_shift          = number_of_noncount_bits,
28650
772aaab2582f 8059606: Enable per-method usage of CompileThresholdScaling (per-method compilation thresholds)
zmajo
parents: 22836
diff changeset
    70
    number_of_count_bits = BitsPerInt - number_of_noncount_bits,
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5547
diff changeset
    71
    count_limit          = nth_bit(number_of_count_bits - 1)
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  enum State {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
    wait_for_nothing,                            // do nothing when count() > limit()
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
    wait_for_compile,                            // introduce nmethod when count() > limit()
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
    number_of_states                             // must be <= state_limit
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  // Manipulation
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  void reset();                                  // sets state to wait state
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  void init();                                   // sets state into original state
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  void set_state(State state);                   // sets state and initializes counter correspondingly
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  inline void set(State state, int count);       // sets state and counter
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  inline void decay();                           // decay counter (divide by two)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  void set_carry();                              // set the sticky carry bit
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5547
diff changeset
    87
  void set_carry_flag()                          {  _counter |= carry_mask; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
14477
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 7397
diff changeset
    89
  int raw_counter()                              { return _counter; }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 7397
diff changeset
    90
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  // Accessors
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  State  state() const                           { return (State)(_counter & state_mask); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  bool   carry() const                           { return (_counter & carry_mask) != 0; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  int    limit() const                           { return CompileThreshold; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  Action action() const                          { return _action[state()]; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  int    count() const                           { return _counter >> number_of_noncount_bits; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  int   get_InvocationLimit() const              { return InterpreterInvocationLimit >> number_of_noncount_bits; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  int   get_BackwardBranchLimit() const          { return InterpreterBackwardBranchLimit >> number_of_noncount_bits; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  int   get_ProfileLimit() const                 { return InterpreterProfileLimit >> number_of_noncount_bits; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
22836
e7e511228518 8024468: PPC64 (part 201): cppInterpreter: implement bytecode profiling
goetz
parents: 14477
diff changeset
   102
#ifdef CC_INTERP
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  // Test counter using scaled limits like the asm interpreter would do rather than doing
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  // the shifts to normalize the counter.
22836
e7e511228518 8024468: PPC64 (part 201): cppInterpreter: implement bytecode profiling
goetz
parents: 14477
diff changeset
   105
  // Checks sum of invocation_counter and backedge_counter as the template interpreter does.
e7e511228518 8024468: PPC64 (part 201): cppInterpreter: implement bytecode profiling
goetz
parents: 14477
diff changeset
   106
  bool reached_InvocationLimit(InvocationCounter *back_edge_count) const {
e7e511228518 8024468: PPC64 (part 201): cppInterpreter: implement bytecode profiling
goetz
parents: 14477
diff changeset
   107
    return (_counter & count_mask) + (back_edge_count->_counter & count_mask) >=
e7e511228518 8024468: PPC64 (part 201): cppInterpreter: implement bytecode profiling
goetz
parents: 14477
diff changeset
   108
           (unsigned int) InterpreterInvocationLimit;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  }
22836
e7e511228518 8024468: PPC64 (part 201): cppInterpreter: implement bytecode profiling
goetz
parents: 14477
diff changeset
   110
  bool reached_BackwardBranchLimit(InvocationCounter *back_edge_count) const {
e7e511228518 8024468: PPC64 (part 201): cppInterpreter: implement bytecode profiling
goetz
parents: 14477
diff changeset
   111
    return (_counter & count_mask) + (back_edge_count->_counter & count_mask) >=
e7e511228518 8024468: PPC64 (part 201): cppInterpreter: implement bytecode profiling
goetz
parents: 14477
diff changeset
   112
           (unsigned int) InterpreterBackwardBranchLimit;
e7e511228518 8024468: PPC64 (part 201): cppInterpreter: implement bytecode profiling
goetz
parents: 14477
diff changeset
   113
  }
e7e511228518 8024468: PPC64 (part 201): cppInterpreter: implement bytecode profiling
goetz
parents: 14477
diff changeset
   114
  // Do this just like asm interpreter does for max speed.
e7e511228518 8024468: PPC64 (part 201): cppInterpreter: implement bytecode profiling
goetz
parents: 14477
diff changeset
   115
  bool reached_ProfileLimit(InvocationCounter *back_edge_count) const {
e7e511228518 8024468: PPC64 (part 201): cppInterpreter: implement bytecode profiling
goetz
parents: 14477
diff changeset
   116
    return (_counter & count_mask) + (back_edge_count->_counter & count_mask) >=
e7e511228518 8024468: PPC64 (part 201): cppInterpreter: implement bytecode profiling
goetz
parents: 14477
diff changeset
   117
           (unsigned int) InterpreterProfileLimit;
e7e511228518 8024468: PPC64 (part 201): cppInterpreter: implement bytecode profiling
goetz
parents: 14477
diff changeset
   118
  }
e7e511228518 8024468: PPC64 (part 201): cppInterpreter: implement bytecode profiling
goetz
parents: 14477
diff changeset
   119
#endif // CC_INTERP
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  void increment()                               { _counter += count_increment; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  // Printing
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  void   print();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  void   print_short();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  // Miscellaneous
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  static ByteSize counter_offset()               { return byte_offset_of(InvocationCounter, _counter); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  static void reinitialize(bool delay_overflow);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  static int         _init  [number_of_states];  // the counter limits
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  static Action      _action[number_of_states];  // the actions
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  static void        def(State state, int init, Action action);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  static const char* state_as_string(State state);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  static const char* state_as_short_string(State state);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
inline void InvocationCounter::set(State state, int count) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  assert(0 <= state && state < number_of_states, "illegal state");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  int carry = (_counter & carry_mask);    // the carry bit is sticky
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  _counter = (count << number_of_noncount_bits) | carry | state;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
inline void InvocationCounter::decay() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  int c = count();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  int new_count = c >> 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  // prevent from going to zero, to distinguish from never-executed methods
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  if (c > 0 && new_count == 0) new_count = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  set(state(), new_count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
}
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5547
diff changeset
   154
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
   155
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
   156
#endif // SHARE_VM_INTERPRETER_INVOCATIONCOUNTER_HPP