hotspot/src/share/vm/interpreter/invocationCounter.cpp
author trims
Thu, 27 May 2010 19:08:38 -0700
changeset 5547 f4b087cbb361
parent 3261 c7d5aae8d3f7
child 6453 970dc585ab63
permissions -rw-r--r--
6941466: Oracle rebranding changes for Hotspot repositories Summary: Change all the Sun copyrights to Oracle copyright Reviewed-by: ohair
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 3261
diff changeset
     2
 * Copyright (c) 1997, 2009, 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: 3261
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 3261
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: 3261
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
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
# include "incls/_precompiled.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
# include "incls/_invocationCounter.cpp.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
// Implementation of InvocationCounter
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
void InvocationCounter::init() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
  _counter = 0;  // reset all the bits, including the sticky carry
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
  reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
void InvocationCounter::reset() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
  // Only reset the state and don't make the method look like it's never
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  // been executed
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
  set_state(wait_for_compile);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
void InvocationCounter::set_carry() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  _counter |= carry_mask;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  // The carry bit now indicates that this counter had achieved a very
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  // large value.  Now reduce the value, so that the method can be
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  // executed many more times before re-entering the VM.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  int old_count = count();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  int new_count = MIN2(old_count, (int) (CompileThreshold / 2));
2266
fe08ea2948cf 6805748: Assertion "don't reset to 0 -- could be mistaken for never-executed" in CompilationPolicy
coleenp
parents: 1
diff changeset
    50
  // prevent from going to zero, to distinguish from never-executed methods
fe08ea2948cf 6805748: Assertion "don't reset to 0 -- could be mistaken for never-executed" in CompilationPolicy
coleenp
parents: 1
diff changeset
    51
  if (new_count == 0)  new_count = 1;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  if (old_count != new_count)  set(state(), new_count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
void InvocationCounter::set_state(State state) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  assert(0 <= state && state < number_of_states, "illegal state");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  int init = _init[state];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  // prevent from going to zero, to distinguish from never-executed methods
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  if (init == 0 && count() > 0)  init = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  int carry = (_counter & carry_mask);    // the carry bit is sticky
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  _counter = (init << number_of_noncount_bits) | carry | state;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
void InvocationCounter::print() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  tty->print_cr("invocation count: up = %d, limit = %d, carry = %s, state = %s",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
                                   count(), limit(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
                                   carry() ? "true" : "false",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
                                   state_as_string(state()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
void InvocationCounter::print_short() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  tty->print(" [%d%s;%s]", count(), carry()?"+carry":"", state_as_short_string(state()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
// Initialization
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
int                       InvocationCounter::_init  [InvocationCounter::number_of_states];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
InvocationCounter::Action InvocationCounter::_action[InvocationCounter::number_of_states];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
int                       InvocationCounter::InterpreterInvocationLimit;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
int                       InvocationCounter::InterpreterBackwardBranchLimit;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
int                       InvocationCounter::InterpreterProfileLimit;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
// Tier1 limits
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
int                       InvocationCounter::Tier1InvocationLimit;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
int                       InvocationCounter::Tier1BackEdgeLimit;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
const char* InvocationCounter::state_as_string(State state) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  switch (state) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
    case wait_for_nothing            : return "wait_for_nothing";
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
    case wait_for_compile            : return "wait_for_compile";
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
const char* InvocationCounter::state_as_short_string(State state) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  switch (state) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
    case wait_for_nothing            : return "not comp.";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
    case wait_for_compile            : return "compileable";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
static address do_nothing(methodHandle method, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  // dummy action for inactive invocation counters
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  method->invocation_counter()->set_carry();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  method->invocation_counter()->set_state(InvocationCounter::wait_for_nothing);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
static address do_decay(methodHandle method, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  // decay invocation counters so compilation gets delayed
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  method->invocation_counter()->decay();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
void InvocationCounter::def(State state, int init, Action action) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  assert(0 <= state && state < number_of_states, "illegal state");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  assert(0 <= init  && init  < count_limit, "initial value out of range");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  _init  [state] = init;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  _action[state] = action;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
address dummy_invocation_counter_overflow(methodHandle m, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
void InvocationCounter::reinitialize(bool delay_overflow) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  // define states
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  guarantee((int)number_of_states <= (int)state_limit, "adjust number_of_state_bits");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  def(wait_for_nothing, 0, do_nothing);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  if (delay_overflow) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
    def(wait_for_compile, 0, do_decay);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
    def(wait_for_compile, 0, dummy_invocation_counter_overflow);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  InterpreterInvocationLimit = CompileThreshold << number_of_noncount_bits;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  InterpreterProfileLimit = ((CompileThreshold * InterpreterProfilePercentage) / 100)<< number_of_noncount_bits;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  Tier1InvocationLimit = Tier2CompileThreshold << number_of_noncount_bits;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  Tier1BackEdgeLimit   = Tier2BackEdgeThreshold << number_of_noncount_bits;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  // When methodData is collected, the backward branch limit is compared against a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  // methodData counter, rather than an InvocationCounter.  In the former case, we
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  // don't need the shift by number_of_noncount_bits, but we do need to adjust
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  // the factor by which we scale the threshold.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
  if (ProfileInterpreter) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
    InterpreterBackwardBranchLimit = (CompileThreshold * (OnStackReplacePercentage - InterpreterProfilePercentage)) / 100;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
    InterpreterBackwardBranchLimit = ((CompileThreshold * OnStackReplacePercentage) / 100) << number_of_noncount_bits;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
  assert(0 <= InterpreterBackwardBranchLimit,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
         "OSR threshold should be non-negative");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
  assert(0 <= InterpreterProfileLimit &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
         InterpreterProfileLimit <= InterpreterInvocationLimit,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
         "profile threshold should be less than the compilation threshold "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
         "and non-negative");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
void invocationCounter_init() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
  InvocationCounter::reinitialize(DelayCompilationDuringStartup);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
}