hotspot/src/share/vm/interpreter/invocationCounter.cpp
author twisti
Fri, 27 Feb 2009 13:27:09 -0800
changeset 2131 98f9cef66a34
parent 1 489c9b5090e2
child 2266 fe08ea2948cf
permissions -rw-r--r--
6810672: Comment typos Summary: I have collected some typos I have found while looking at the code. Reviewed-by: kvn, never
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1997-2007 Sun Microsystems, Inc.  All Rights Reserved.
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
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
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));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  if (old_count != new_count)  set(state(), new_count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
void InvocationCounter::set_state(State state) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  assert(0 <= state && state < number_of_states, "illegal state");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  int init = _init[state];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  // prevent from going to zero, to distinguish from never-executed methods
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  if (init == 0 && count() > 0)  init = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  int carry = (_counter & carry_mask);    // the carry bit is sticky
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  _counter = (init << number_of_noncount_bits) | carry | state;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
void InvocationCounter::print() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  tty->print_cr("invocation count: up = %d, limit = %d, carry = %s, state = %s",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
                                   count(), limit(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
                                   carry() ? "true" : "false",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
                                   state_as_string(state()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
void InvocationCounter::print_short() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  tty->print(" [%d%s;%s]", count(), carry()?"+carry":"", state_as_short_string(state()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
// Initialization
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
int                       InvocationCounter::_init  [InvocationCounter::number_of_states];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
InvocationCounter::Action InvocationCounter::_action[InvocationCounter::number_of_states];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
int                       InvocationCounter::InterpreterInvocationLimit;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
int                       InvocationCounter::InterpreterBackwardBranchLimit;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
int                       InvocationCounter::InterpreterProfileLimit;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
// Tier1 limits
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
int                       InvocationCounter::Tier1InvocationLimit;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
int                       InvocationCounter::Tier1BackEdgeLimit;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
const char* InvocationCounter::state_as_string(State state) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  switch (state) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
    case wait_for_nothing            : return "wait_for_nothing";
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
    case wait_for_compile            : return "wait_for_compile";
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
const char* InvocationCounter::state_as_short_string(State state) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  switch (state) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
    case wait_for_nothing            : return "not comp.";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
    case wait_for_compile            : return "compileable";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
static address do_nothing(methodHandle method, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  // dummy action for inactive invocation counters
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  method->invocation_counter()->set_carry();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  method->invocation_counter()->set_state(InvocationCounter::wait_for_nothing);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
static address do_decay(methodHandle method, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  // decay invocation counters so compilation gets delayed
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  method->invocation_counter()->decay();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
void InvocationCounter::def(State state, int init, Action action) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  assert(0 <= state && state < number_of_states, "illegal state");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  assert(0 <= init  && init  < count_limit, "initial value out of range");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  _init  [state] = init;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  _action[state] = action;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
address dummy_invocation_counter_overflow(methodHandle m, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
void InvocationCounter::reinitialize(bool delay_overflow) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  // define states
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  guarantee((int)number_of_states <= (int)state_limit, "adjust number_of_state_bits");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  def(wait_for_nothing, 0, do_nothing);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  if (delay_overflow) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
    def(wait_for_compile, 0, do_decay);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
    def(wait_for_compile, 0, dummy_invocation_counter_overflow);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  InterpreterInvocationLimit = CompileThreshold << number_of_noncount_bits;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  InterpreterProfileLimit = ((CompileThreshold * InterpreterProfilePercentage) / 100)<< number_of_noncount_bits;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  Tier1InvocationLimit = Tier2CompileThreshold << number_of_noncount_bits;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  Tier1BackEdgeLimit   = Tier2BackEdgeThreshold << number_of_noncount_bits;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  // When methodData is collected, the backward branch limit is compared against a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  // methodData counter, rather than an InvocationCounter.  In the former case, we
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  // don't need the shift by number_of_noncount_bits, but we do need to adjust
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  // the factor by which we scale the threshold.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  if (ProfileInterpreter) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
    InterpreterBackwardBranchLimit = (CompileThreshold * (OnStackReplacePercentage - InterpreterProfilePercentage)) / 100;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
    InterpreterBackwardBranchLimit = ((CompileThreshold * OnStackReplacePercentage) / 100) << number_of_noncount_bits;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  assert(0 <= InterpreterBackwardBranchLimit,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
         "OSR threshold should be non-negative");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
  assert(0 <= InterpreterProfileLimit &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
         InterpreterProfileLimit <= InterpreterInvocationLimit,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
         "profile threshold should be less than the compilation threshold "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
         "and non-negative");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
void invocationCounter_init() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  InvocationCounter::reinitialize(DelayCompilationDuringStartup);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
}