hotspot/src/share/vm/interpreter/invocationCounter.cpp
author coleenp
Thu, 27 Jul 2017 18:06:41 -0400
changeset 46727 6e4a84748e2c
parent 46630 75aa3e39d02c
permissions -rw-r--r--
8183039: Re-examine methodHandle methods uninlined by 8144256 Summary: Add more const references so out-of-line methodHandle destructor and copy ctor called infrequently Reviewed-by: hseigel, redestad
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
46630
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 17000
diff changeset
     2
 * Copyright (c) 1997, 2017, 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
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    25
#include "precompiled.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    26
#include "interpreter/invocationCounter.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    27
#include "runtime/frame.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    28
#include "runtime/handles.inline.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
// Implementation of InvocationCounter
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
void InvocationCounter::init() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
  _counter = 0;  // reset all the bits, including the sticky carry
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
  reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
void InvocationCounter::reset() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
  // Only reset the state and don't make the method look like it's never
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  // been executed
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  set_state(wait_for_compile);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
void InvocationCounter::set_carry() {
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5547
diff changeset
    45
  set_carry_flag();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  // The carry bit now indicates that this counter had achieved a very
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  // large value.  Now reduce the value, so that the method can be
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  // executed many more times before re-entering the VM.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  int old_count = count();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  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
    51
  // 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
    52
  if (new_count == 0)  new_count = 1;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  if (old_count != new_count)  set(state(), new_count);
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
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
const char* InvocationCounter::state_as_string(State state) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  switch (state) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
    case wait_for_nothing            : return "wait_for_nothing";
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
    case wait_for_compile            : return "wait_for_compile";
46630
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 17000
diff changeset
    90
    default:
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 17000
diff changeset
    91
      ShouldNotReachHere();
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 17000
diff changeset
    92
      return NULL;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
const char* InvocationCounter::state_as_short_string(State state) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  switch (state) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
    case wait_for_nothing            : return "not comp.";
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
    case wait_for_compile            : return "compileable";
46630
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 17000
diff changeset
   100
    default:
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 17000
diff changeset
   101
      ShouldNotReachHere();
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 17000
diff changeset
   102
      return NULL;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
46727
6e4a84748e2c 8183039: Re-examine methodHandle methods uninlined by 8144256
coleenp
parents: 46630
diff changeset
   107
static address do_nothing(const methodHandle& method, TRAPS) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  // dummy action for inactive invocation counters
17000
11bf92e571a2 8010862: The Method counter fields used for profiling can be allocated lazily.
jiangli
parents: 7397
diff changeset
   109
  MethodCounters* mcs = method->method_counters();
11bf92e571a2 8010862: The Method counter fields used for profiling can be allocated lazily.
jiangli
parents: 7397
diff changeset
   110
  assert(mcs != NULL, "");
11bf92e571a2 8010862: The Method counter fields used for profiling can be allocated lazily.
jiangli
parents: 7397
diff changeset
   111
  mcs->invocation_counter()->set_carry();
11bf92e571a2 8010862: The Method counter fields used for profiling can be allocated lazily.
jiangli
parents: 7397
diff changeset
   112
  mcs->invocation_counter()->set_state(InvocationCounter::wait_for_nothing);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
46727
6e4a84748e2c 8183039: Re-examine methodHandle methods uninlined by 8144256
coleenp
parents: 46630
diff changeset
   117
static address do_decay(const methodHandle& method, TRAPS) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  // decay invocation counters so compilation gets delayed
17000
11bf92e571a2 8010862: The Method counter fields used for profiling can be allocated lazily.
jiangli
parents: 7397
diff changeset
   119
  MethodCounters* mcs = method->method_counters();
11bf92e571a2 8010862: The Method counter fields used for profiling can be allocated lazily.
jiangli
parents: 7397
diff changeset
   120
  assert(mcs != NULL, "");
11bf92e571a2 8010862: The Method counter fields used for profiling can be allocated lazily.
jiangli
parents: 7397
diff changeset
   121
  mcs->invocation_counter()->decay();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
void InvocationCounter::def(State state, int init, Action action) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  assert(0 <= state && state < number_of_states, "illegal state");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  assert(0 <= init  && init  < count_limit, "initial value out of range");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  _init  [state] = init;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  _action[state] = action;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
46727
6e4a84748e2c 8183039: Re-examine methodHandle methods uninlined by 8144256
coleenp
parents: 46630
diff changeset
   133
address dummy_invocation_counter_overflow(const methodHandle& m, TRAPS) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
void InvocationCounter::reinitialize(bool delay_overflow) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  // define states
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  guarantee((int)number_of_states <= (int)state_limit, "adjust number_of_state_bits");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  def(wait_for_nothing, 0, do_nothing);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  if (delay_overflow) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
    def(wait_for_compile, 0, do_decay);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
    def(wait_for_compile, 0, dummy_invocation_counter_overflow);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  InterpreterInvocationLimit = CompileThreshold << number_of_noncount_bits;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  InterpreterProfileLimit = ((CompileThreshold * InterpreterProfilePercentage) / 100)<< number_of_noncount_bits;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  // When methodData is collected, the backward branch limit is compared against a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  // methodData counter, rather than an InvocationCounter.  In the former case, we
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  // don't need the shift by number_of_noncount_bits, but we do need to adjust
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  // the factor by which we scale the threshold.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  if (ProfileInterpreter) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
    InterpreterBackwardBranchLimit = (CompileThreshold * (OnStackReplacePercentage - InterpreterProfilePercentage)) / 100;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
    InterpreterBackwardBranchLimit = ((CompileThreshold * OnStackReplacePercentage) / 100) << number_of_noncount_bits;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
  assert(0 <= InterpreterBackwardBranchLimit,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
         "OSR threshold should be non-negative");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  assert(0 <= InterpreterProfileLimit &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
         InterpreterProfileLimit <= InterpreterInvocationLimit,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
         "profile threshold should be less than the compilation threshold "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
         "and non-negative");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
void invocationCounter_init() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
  InvocationCounter::reinitialize(DelayCompilationDuringStartup);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
}