src/hotspot/share/runtime/tieredThresholdPolicy.cpp
author rehn
Wed, 06 Mar 2019 11:15:16 +0100
changeset 54009 13acb4339895
parent 53895 b22d8ae270a2
child 54015 cd701366fcf8
permissions -rw-r--r--
8220151: SafepointTracing::end_of_last_safepoint_ms should return ms since epoch. Reviewed-by: dholmes, redestad
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
     1
/*
53193
184c51e48260 8216262: Remove develop flag DelayCompilationDuringStartup
redestad
parents: 52934
diff changeset
     2
 * Copyright (c) 2010, 2019, Oracle and/or its affiliates. All rights reserved.
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
     4
 *
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
     7
 * published by the Free Software Foundation.
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
     8
 *
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    13
 * accompanied this code).
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    14
 *
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    18
 *
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    21
 * questions.
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    22
 *
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    23
 */
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7389
diff changeset
    25
#include "precompiled.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7389
diff changeset
    26
#include "compiler/compileBroker.hpp"
51369
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
    27
#include "compiler/compilerOracle.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7389
diff changeset
    28
#include "memory/resourceArea.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7389
diff changeset
    29
#include "runtime/arguments.hpp"
49480
d7df2dd501ce 8199809: Don't include frame.inline.hpp and other.inline.hpp from .hpp files
coleenp
parents: 49449
diff changeset
    30
#include "runtime/handles.inline.hpp"
53628
213a2377b792 8218276: AIX build fails in tieredThresholdPolicy.cpp
mbaesken
parents: 53195
diff changeset
    31
#include "runtime/safepoint.hpp"
49594
898ef81cbc0e 8200106: Move NoSafepointVerifier out from gcLocker.hpp
stefank
parents: 49480
diff changeset
    32
#include "runtime/safepointVerifiers.hpp"
51369
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
    33
#include "runtime/tieredThresholdPolicy.hpp"
8322
8f11ba61239f 7017434: Tiered needs to support reprofiling
iveresov
parents: 7397
diff changeset
    34
#include "code/scopeDesc.hpp"
51369
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
    35
#include "oops/method.inline.hpp"
38666
5ff19807abd5 8152311: [JVMCI] allow JVMCI compiler to change the compilation policy for a method
dnsimon
parents: 38218
diff changeset
    36
#if INCLUDE_JVMCI
5ff19807abd5 8152311: [JVMCI] allow JVMCI compiler to change the compilation policy for a method
dnsimon
parents: 38218
diff changeset
    37
#include "jvmci/jvmciRuntime.hpp"
5ff19807abd5 8152311: [JVMCI] allow JVMCI compiler to change the compilation policy for a method
dnsimon
parents: 38218
diff changeset
    38
#endif
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    39
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40364
diff changeset
    40
#ifdef TIERED
11192
ff37c2093a0d 7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents: 10250
diff changeset
    41
52325
0451e0a2f1f5 8177899: Tests fail due to code cache exhaustion on machines with many cores
thartmann
parents: 51369
diff changeset
    42
#include "c1/c1_Compiler.hpp"
0451e0a2f1f5 8177899: Tests fail due to code cache exhaustion on machines with many cores
thartmann
parents: 51369
diff changeset
    43
#include "opto/c2compiler.hpp"
0451e0a2f1f5 8177899: Tests fail due to code cache exhaustion on machines with many cores
thartmann
parents: 51369
diff changeset
    44
51369
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
    45
template<CompLevel level>
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
    46
bool TieredThresholdPolicy::call_predicate_helper(int i, int b, double scale, Method* method) {
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
    47
  double threshold_scaling;
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
    48
  if (CompilerOracle::has_option_value(method, "CompileThresholdScaling", threshold_scaling)) {
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
    49
    scale *= threshold_scaling;
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
    50
  }
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
    51
  switch(level) {
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
    52
  case CompLevel_aot:
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
    53
    return (i >= Tier3AOTInvocationThreshold * scale) ||
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
    54
           (i >= Tier3AOTMinInvocationThreshold * scale && i + b >= Tier3AOTCompileThreshold * scale);
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
    55
  case CompLevel_none:
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
    56
  case CompLevel_limited_profile:
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
    57
    return (i >= Tier3InvocationThreshold * scale) ||
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
    58
           (i >= Tier3MinInvocationThreshold * scale && i + b >= Tier3CompileThreshold * scale);
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
    59
  case CompLevel_full_profile:
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
    60
   return (i >= Tier4InvocationThreshold * scale) ||
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
    61
          (i >= Tier4MinInvocationThreshold * scale && i + b >= Tier4CompileThreshold * scale);
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
    62
  }
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
    63
  return true;
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
    64
}
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
    65
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
    66
template<CompLevel level>
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
    67
bool TieredThresholdPolicy::loop_predicate_helper(int i, int b, double scale, Method* method) {
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
    68
  double threshold_scaling;
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
    69
  if (CompilerOracle::has_option_value(method, "CompileThresholdScaling", threshold_scaling)) {
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
    70
    scale *= threshold_scaling;
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
    71
  }
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
    72
  switch(level) {
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
    73
  case CompLevel_aot:
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
    74
    return b >= Tier3AOTBackEdgeThreshold * scale;
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
    75
  case CompLevel_none:
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
    76
  case CompLevel_limited_profile:
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
    77
    return b >= Tier3BackEdgeThreshold * scale;
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
    78
  case CompLevel_full_profile:
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
    79
    return b >= Tier4BackEdgeThreshold * scale;
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
    80
  }
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
    81
  return true;
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
    82
}
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
    83
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
    84
// Simple methods are as good being compiled with C1 as C2.
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
    85
// Determine if a given method is such a case.
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
    86
bool TieredThresholdPolicy::is_trivial(Method* method) {
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
    87
  if (method->is_accessor() ||
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
    88
      method->is_constant_getter()) {
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
    89
    return true;
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
    90
  }
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
    91
  return false;
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
    92
}
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
    93
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
    94
CompLevel TieredThresholdPolicy::comp_level(Method* method) {
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
    95
  CompiledMethod *nm = method->code();
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
    96
  if (nm != NULL && nm->is_in_use()) {
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
    97
    return (CompLevel)nm->comp_level();
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
    98
  }
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
    99
  return CompLevel_none;
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
   100
}
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
   101
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
   102
void TieredThresholdPolicy::print_counters(const char* prefix, const methodHandle& mh) {
11192
ff37c2093a0d 7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents: 10250
diff changeset
   103
  int invocation_count = mh->invocation_count();
ff37c2093a0d 7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents: 10250
diff changeset
   104
  int backedge_count = mh->backedge_count();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11572
diff changeset
   105
  MethodData* mdh = mh->method_data();
11192
ff37c2093a0d 7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents: 10250
diff changeset
   106
  int mdo_invocations = 0, mdo_backedges = 0;
ff37c2093a0d 7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents: 10250
diff changeset
   107
  int mdo_invocations_start = 0, mdo_backedges_start = 0;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11572
diff changeset
   108
  if (mdh != NULL) {
11192
ff37c2093a0d 7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents: 10250
diff changeset
   109
    mdo_invocations = mdh->invocation_count();
ff37c2093a0d 7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents: 10250
diff changeset
   110
    mdo_backedges = mdh->backedge_count();
ff37c2093a0d 7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents: 10250
diff changeset
   111
    mdo_invocations_start = mdh->invocation_count_start();
ff37c2093a0d 7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents: 10250
diff changeset
   112
    mdo_backedges_start = mdh->backedge_count_start();
ff37c2093a0d 7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents: 10250
diff changeset
   113
  }
13891
35dabd293e56 7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents: 13728
diff changeset
   114
  tty->print(" %stotal=%d,%d %smdo=%d(%d),%d(%d)", prefix,
11192
ff37c2093a0d 7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents: 10250
diff changeset
   115
      invocation_count, backedge_count, prefix,
ff37c2093a0d 7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents: 10250
diff changeset
   116
      mdo_invocations, mdo_invocations_start,
ff37c2093a0d 7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents: 10250
diff changeset
   117
      mdo_backedges, mdo_backedges_start);
13891
35dabd293e56 7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents: 13728
diff changeset
   118
  tty->print(" %smax levels=%d,%d", prefix,
11192
ff37c2093a0d 7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents: 10250
diff changeset
   119
      mh->highest_comp_level(), mh->highest_osr_comp_level());
ff37c2093a0d 7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents: 10250
diff changeset
   120
}
ff37c2093a0d 7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents: 10250
diff changeset
   121
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   122
// Print an event.
51369
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
   123
void TieredThresholdPolicy::print_event(EventType type, const methodHandle& mh, const methodHandle& imh,
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   124
                                        int bci, CompLevel level) {
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   125
  bool inlinee_event = mh() != imh();
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   126
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   127
  ttyLocker tty_lock;
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   128
  tty->print("%lf: [", os::elapsedTime());
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   129
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   130
  switch(type) {
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   131
  case CALL:
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   132
    tty->print("call");
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   133
    break;
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   134
  case LOOP:
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   135
    tty->print("loop");
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   136
    break;
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   137
  case COMPILE:
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   138
    tty->print("compile");
8322
8f11ba61239f 7017434: Tiered needs to support reprofiling
iveresov
parents: 7397
diff changeset
   139
    break;
10014
a5c2141ee857 7057120: Tiered: Allow C1 to inline methods with loops
iveresov
parents: 10013
diff changeset
   140
  case REMOVE_FROM_QUEUE:
a5c2141ee857 7057120: Tiered: Allow C1 to inline methods with loops
iveresov
parents: 10013
diff changeset
   141
    tty->print("remove-from-queue");
8322
8f11ba61239f 7017434: Tiered needs to support reprofiling
iveresov
parents: 7397
diff changeset
   142
    break;
10014
a5c2141ee857 7057120: Tiered: Allow C1 to inline methods with loops
iveresov
parents: 10013
diff changeset
   143
  case UPDATE_IN_QUEUE:
a5c2141ee857 7057120: Tiered: Allow C1 to inline methods with loops
iveresov
parents: 10013
diff changeset
   144
    tty->print("update-in-queue");
8322
8f11ba61239f 7017434: Tiered needs to support reprofiling
iveresov
parents: 7397
diff changeset
   145
    break;
8f11ba61239f 7017434: Tiered needs to support reprofiling
iveresov
parents: 7397
diff changeset
   146
  case REPROFILE:
8f11ba61239f 7017434: Tiered needs to support reprofiling
iveresov
parents: 7397
diff changeset
   147
    tty->print("reprofile");
8f11ba61239f 7017434: Tiered needs to support reprofiling
iveresov
parents: 7397
diff changeset
   148
    break;
10014
a5c2141ee857 7057120: Tiered: Allow C1 to inline methods with loops
iveresov
parents: 10013
diff changeset
   149
  case MAKE_NOT_ENTRANT:
a5c2141ee857 7057120: Tiered: Allow C1 to inline methods with loops
iveresov
parents: 10013
diff changeset
   150
    tty->print("make-not-entrant");
a5c2141ee857 7057120: Tiered: Allow C1 to inline methods with loops
iveresov
parents: 10013
diff changeset
   151
    break;
8322
8f11ba61239f 7017434: Tiered needs to support reprofiling
iveresov
parents: 7397
diff changeset
   152
  default:
8f11ba61239f 7017434: Tiered needs to support reprofiling
iveresov
parents: 7397
diff changeset
   153
    tty->print("unknown");
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   154
  }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   155
13891
35dabd293e56 7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents: 13728
diff changeset
   156
  tty->print(" level=%d ", level);
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   157
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   158
  ResourceMark rm;
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   159
  char *method_name = mh->name_and_sig_as_C_string();
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   160
  tty->print("[%s", method_name);
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   161
  if (inlinee_event) {
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   162
    char *inlinee_name = imh->name_and_sig_as_C_string();
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   163
    tty->print(" [%s]] ", inlinee_name);
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   164
  }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   165
  else tty->print("] ");
13891
35dabd293e56 7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents: 13728
diff changeset
   166
  tty->print("@%d queues=%d,%d", bci, CompileBroker::queue_size(CompLevel_full_profile),
35dabd293e56 7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents: 13728
diff changeset
   167
                                      CompileBroker::queue_size(CompLevel_full_optimization));
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   168
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   169
  print_specific(type, mh, imh, bci, level);
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   170
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   171
  if (type != COMPILE) {
11192
ff37c2093a0d 7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents: 10250
diff changeset
   172
    print_counters("", mh);
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   173
    if (inlinee_event) {
11192
ff37c2093a0d 7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents: 10250
diff changeset
   174
      print_counters("inlinee ", imh);
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   175
    }
13891
35dabd293e56 7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents: 13728
diff changeset
   176
    tty->print(" compilable=");
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   177
    bool need_comma = false;
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   178
    if (!mh->is_not_compilable(CompLevel_full_profile)) {
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   179
      tty->print("c1");
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   180
      need_comma = true;
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   181
    }
13891
35dabd293e56 7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents: 13728
diff changeset
   182
    if (!mh->is_not_osr_compilable(CompLevel_full_profile)) {
35dabd293e56 7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents: 13728
diff changeset
   183
      if (need_comma) tty->print(",");
35dabd293e56 7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents: 13728
diff changeset
   184
      tty->print("c1-osr");
35dabd293e56 7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents: 13728
diff changeset
   185
      need_comma = true;
35dabd293e56 7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents: 13728
diff changeset
   186
    }
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   187
    if (!mh->is_not_compilable(CompLevel_full_optimization)) {
13891
35dabd293e56 7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents: 13728
diff changeset
   188
      if (need_comma) tty->print(",");
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   189
      tty->print("c2");
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   190
      need_comma = true;
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   191
    }
13891
35dabd293e56 7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents: 13728
diff changeset
   192
    if (!mh->is_not_osr_compilable(CompLevel_full_optimization)) {
35dabd293e56 7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents: 13728
diff changeset
   193
      if (need_comma) tty->print(",");
35dabd293e56 7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents: 13728
diff changeset
   194
      tty->print("c2-osr");
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   195
    }
13891
35dabd293e56 7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents: 13728
diff changeset
   196
    tty->print(" status=");
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   197
    if (mh->queued_for_compilation()) {
13891
35dabd293e56 7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents: 13728
diff changeset
   198
      tty->print("in-queue");
35dabd293e56 7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents: 13728
diff changeset
   199
    } else tty->print("idle");
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   200
  }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   201
  tty->print_cr("]");
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   202
}
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   203
51369
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
   204
void TieredThresholdPolicy::initialize() {
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   205
  int count = CICompilerCount;
52325
0451e0a2f1f5 8177899: Tests fail due to code cache exhaustion on machines with many cores
thartmann
parents: 51369
diff changeset
   206
  bool c1_only = TieredStopAtLevel < CompLevel_full_optimization;
36556
7f092a7ce938 8150839: Adjust the number of compiler threads for 32-bit platforms
zmajo
parents: 35547
diff changeset
   207
#ifdef _LP64
50068
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   208
  // Turn on ergonomic compiler count selection
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   209
  if (FLAG_IS_DEFAULT(CICompilerCountPerCPU) && FLAG_IS_DEFAULT(CICompilerCount)) {
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   210
    FLAG_SET_DEFAULT(CICompilerCountPerCPU, true);
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   211
  }
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   212
  if (CICompilerCountPerCPU) {
50068
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   213
    // Simple log n seems to grow too slowly for tiered, try something faster: log n * log log n
52675
7d3cde494494 8214206: Fix for JDK-8213419 is broken on 32-bit
roland
parents: 52325
diff changeset
   214
    int log_cpu = log2_int(os::active_processor_count());
7d3cde494494 8214206: Fix for JDK-8213419 is broken on 32-bit
roland
parents: 52325
diff changeset
   215
    int loglog_cpu = log2_int(MAX2(log_cpu, 1));
50068
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   216
    count = MAX2(log_cpu * loglog_cpu * 3 / 2, 2);
52325
0451e0a2f1f5 8177899: Tests fail due to code cache exhaustion on machines with many cores
thartmann
parents: 51369
diff changeset
   217
    // Make sure there is enough space in the code cache to hold all the compiler buffers
0451e0a2f1f5 8177899: Tests fail due to code cache exhaustion on machines with many cores
thartmann
parents: 51369
diff changeset
   218
    size_t c1_size = Compiler::code_buffer_size();
0451e0a2f1f5 8177899: Tests fail due to code cache exhaustion on machines with many cores
thartmann
parents: 51369
diff changeset
   219
    size_t c2_size = C2Compiler::initial_code_buffer_size();
0451e0a2f1f5 8177899: Tests fail due to code cache exhaustion on machines with many cores
thartmann
parents: 51369
diff changeset
   220
    size_t buffer_size = c1_only ? c1_size : (c1_size/3 + 2*c2_size/3);
0451e0a2f1f5 8177899: Tests fail due to code cache exhaustion on machines with many cores
thartmann
parents: 51369
diff changeset
   221
    int max_count = (ReservedCodeCacheSize - (CodeCacheMinimumUseSpace DEBUG_ONLY(* 3))) / (int)buffer_size;
0451e0a2f1f5 8177899: Tests fail due to code cache exhaustion on machines with many cores
thartmann
parents: 51369
diff changeset
   222
    if (count > max_count) {
0451e0a2f1f5 8177899: Tests fail due to code cache exhaustion on machines with many cores
thartmann
parents: 51369
diff changeset
   223
      // Lower the compiler count such that all buffers fit into the code cache
0451e0a2f1f5 8177899: Tests fail due to code cache exhaustion on machines with many cores
thartmann
parents: 51369
diff changeset
   224
      count = MAX2(max_count, c1_only ? 1 : 2);
0451e0a2f1f5 8177899: Tests fail due to code cache exhaustion on machines with many cores
thartmann
parents: 51369
diff changeset
   225
    }
50068
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   226
    FLAG_SET_ERGO(intx, CICompilerCount, count);
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   227
  }
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   228
#else
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   229
  // On 32-bit systems, the number of compiler threads is limited to 3.
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   230
  // On these systems, the virtual address space available to the JVM
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   231
  // is usually limited to 2-4 GB (the exact value depends on the platform).
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   232
  // As the compilers (especially C2) can consume a large amount of
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   233
  // memory, scaling the number of compiler threads with the number of
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   234
  // available cores can result in the exhaustion of the address space
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   235
  /// available to the VM and thus cause the VM to crash.
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   236
  if (FLAG_IS_DEFAULT(CICompilerCount)) {
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   237
    count = 3;
40364
5bf8fa4fddfd 8162881: Effect of -XX:CICompilerCount depends on ordering of other flags
thartmann
parents: 40074
diff changeset
   238
    FLAG_SET_ERGO(intx, CICompilerCount, count);
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   239
  }
36556
7f092a7ce938 8150839: Adjust the number of compiler threads for 32-bit platforms
zmajo
parents: 35547
diff changeset
   240
#endif
50068
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   241
52325
0451e0a2f1f5 8177899: Tests fail due to code cache exhaustion on machines with many cores
thartmann
parents: 51369
diff changeset
   242
  if (c1_only) {
40364
5bf8fa4fddfd 8162881: Effect of -XX:CICompilerCount depends on ordering of other flags
thartmann
parents: 40074
diff changeset
   243
    // No C2 compiler thread required
5bf8fa4fddfd 8162881: Effect of -XX:CICompilerCount depends on ordering of other flags
thartmann
parents: 40074
diff changeset
   244
    set_c1_count(count);
5bf8fa4fddfd 8162881: Effect of -XX:CICompilerCount depends on ordering of other flags
thartmann
parents: 40074
diff changeset
   245
  } else {
5bf8fa4fddfd 8162881: Effect of -XX:CICompilerCount depends on ordering of other flags
thartmann
parents: 40074
diff changeset
   246
    set_c1_count(MAX2(count / 3, 1));
5bf8fa4fddfd 8162881: Effect of -XX:CICompilerCount depends on ordering of other flags
thartmann
parents: 40074
diff changeset
   247
    set_c2_count(MAX2(count - c1_count(), 1));
5bf8fa4fddfd 8162881: Effect of -XX:CICompilerCount depends on ordering of other flags
thartmann
parents: 40074
diff changeset
   248
  }
5bf8fa4fddfd 8162881: Effect of -XX:CICompilerCount depends on ordering of other flags
thartmann
parents: 40074
diff changeset
   249
  assert(count == c1_count() + c2_count(), "inconsistent compiler thread count");
50068
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   250
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   251
  // Some inlining tuning
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   252
#ifdef X86
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   253
  if (FLAG_IS_DEFAULT(InlineSmallCode)) {
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   254
    FLAG_SET_DEFAULT(InlineSmallCode, 2000);
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   255
  }
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   256
#endif
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   257
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   258
#if defined SPARC || defined AARCH64
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   259
  if (FLAG_IS_DEFAULT(InlineSmallCode)) {
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   260
    FLAG_SET_DEFAULT(InlineSmallCode, 2500);
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   261
  }
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   262
#endif
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   263
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   264
  set_increase_threshold_at_ratio();
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   265
  set_start_time(os::javaTimeMillis());
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   266
}
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   267
51369
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
   268
void TieredThresholdPolicy::set_carry_if_necessary(InvocationCounter *counter) {
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   269
  if (!counter->carry() && counter->count() > InvocationCounter::count_limit / 2) {
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   270
    counter->set_carry_flag();
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   271
  }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   272
}
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   273
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   274
// Set carry flags on the counters if necessary
51369
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
   275
void TieredThresholdPolicy::handle_counter_overflow(Method* method) {
17000
11bf92e571a2 8010862: The Method counter fields used for profiling can be allocated lazily.
jiangli
parents: 13891
diff changeset
   276
  MethodCounters *mcs = method->method_counters();
17130
6853aae617cb 8013036: vm/runtime/simpleThresholdPolicy.cpp: assert(mcs != NULL).
jiangli
parents: 17000
diff changeset
   277
  if (mcs != NULL) {
6853aae617cb 8013036: vm/runtime/simpleThresholdPolicy.cpp: assert(mcs != NULL).
jiangli
parents: 17000
diff changeset
   278
    set_carry_if_necessary(mcs->invocation_counter());
6853aae617cb 8013036: vm/runtime/simpleThresholdPolicy.cpp: assert(mcs != NULL).
jiangli
parents: 17000
diff changeset
   279
    set_carry_if_necessary(mcs->backedge_counter());
6853aae617cb 8013036: vm/runtime/simpleThresholdPolicy.cpp: assert(mcs != NULL).
jiangli
parents: 17000
diff changeset
   280
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11572
diff changeset
   281
  MethodData* mdo = method->method_data();
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   282
  if (mdo != NULL) {
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   283
    set_carry_if_necessary(mdo->invocation_counter());
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   284
    set_carry_if_necessary(mdo->backedge_counter());
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   285
  }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   286
}
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   287
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   288
// Called with the queue locked and with at least one element
51369
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
   289
CompileTask* TieredThresholdPolicy::select_task(CompileQueue* compile_queue) {
50068
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   290
  CompileTask *max_blocking_task = NULL;
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   291
  CompileTask *max_task = NULL;
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   292
  Method* max_method = NULL;
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   293
  jlong t = os::javaTimeMillis();
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   294
  // Iterate through the queue and find a method with a maximum rate.
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   295
  for (CompileTask* task = compile_queue->first(); task != NULL;) {
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   296
    CompileTask* next_task = task->next();
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   297
    Method* method = task->method();
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   298
    update_rate(t, method);
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   299
    if (max_task == NULL) {
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   300
      max_task = task;
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   301
      max_method = method;
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   302
    } else {
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   303
      // If a method has been stale for some time, remove it from the queue.
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   304
      // Blocking tasks and tasks submitted from whitebox API don't become stale
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   305
      if (task->can_become_stale() && is_stale(t, TieredCompileTaskTimeout, method) && !is_old(method)) {
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   306
        if (PrintTieredEvents) {
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   307
          print_event(REMOVE_FROM_QUEUE, method, method, task->osr_bci(), (CompLevel)task->comp_level());
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   308
        }
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   309
        compile_queue->remove_and_mark_stale(task);
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   310
        method->clear_queued_for_compilation();
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   311
        task = next_task;
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   312
        continue;
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   313
      }
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   314
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   315
      // Select a method with a higher rate
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   316
      if (compare_methods(method, max_method)) {
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   317
        max_task = task;
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   318
        max_method = method;
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   319
      }
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   320
    }
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   321
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   322
    if (task->is_blocking()) {
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   323
      if (max_blocking_task == NULL || compare_methods(method, max_blocking_task->method())) {
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   324
        max_blocking_task = task;
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   325
      }
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   326
    }
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   327
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   328
    task = next_task;
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   329
  }
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   330
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   331
  if (max_blocking_task != NULL) {
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   332
    // In blocking compilation mode, the CompileBroker will make
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   333
    // compilations submitted by a JVMCI compiler thread non-blocking. These
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   334
    // compilations should be scheduled after all blocking compilations
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   335
    // to service non-compiler related compilations sooner and reduce the
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   336
    // chance of such compilations timing out.
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   337
    max_task = max_blocking_task;
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   338
    max_method = max_task->method();
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   339
  }
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   340
51078
fc6cfe40e32a 8207049: Minor improvements of compiler code.
goetz
parents: 50068
diff changeset
   341
  if (max_task != NULL && max_task->comp_level() == CompLevel_full_profile &&
fc6cfe40e32a 8207049: Minor improvements of compiler code.
goetz
parents: 50068
diff changeset
   342
      TieredStopAtLevel > CompLevel_full_profile &&
fc6cfe40e32a 8207049: Minor improvements of compiler code.
goetz
parents: 50068
diff changeset
   343
      max_method != NULL && is_method_profiled(max_method)) {
50068
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   344
    max_task->set_comp_level(CompLevel_limited_profile);
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   345
    if (PrintTieredEvents) {
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   346
      print_event(UPDATE_IN_QUEUE, max_method, max_method, max_task->osr_bci(), (CompLevel)max_task->comp_level());
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   347
    }
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   348
  }
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   349
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   350
  return max_task;
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   351
}
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   352
51369
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
   353
void TieredThresholdPolicy::reprofile(ScopeDesc* trap_scope, bool is_osr) {
8322
8f11ba61239f 7017434: Tiered needs to support reprofiling
iveresov
parents: 7397
diff changeset
   354
  for (ScopeDesc* sd = trap_scope;; sd = sd->sender()) {
8f11ba61239f 7017434: Tiered needs to support reprofiling
iveresov
parents: 7397
diff changeset
   355
    if (PrintTieredEvents) {
8f11ba61239f 7017434: Tiered needs to support reprofiling
iveresov
parents: 7397
diff changeset
   356
      methodHandle mh(sd->method());
8f11ba61239f 7017434: Tiered needs to support reprofiling
iveresov
parents: 7397
diff changeset
   357
      print_event(REPROFILE, mh, mh, InvocationEntryBci, CompLevel_none);
8f11ba61239f 7017434: Tiered needs to support reprofiling
iveresov
parents: 7397
diff changeset
   358
    }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11572
diff changeset
   359
    MethodData* mdo = sd->method()->method_data();
8322
8f11ba61239f 7017434: Tiered needs to support reprofiling
iveresov
parents: 7397
diff changeset
   360
    if (mdo != NULL) {
8f11ba61239f 7017434: Tiered needs to support reprofiling
iveresov
parents: 7397
diff changeset
   361
      mdo->reset_start_counters();
8f11ba61239f 7017434: Tiered needs to support reprofiling
iveresov
parents: 7397
diff changeset
   362
    }
8f11ba61239f 7017434: Tiered needs to support reprofiling
iveresov
parents: 7397
diff changeset
   363
    if (sd->is_top()) break;
8f11ba61239f 7017434: Tiered needs to support reprofiling
iveresov
parents: 7397
diff changeset
   364
  }
8f11ba61239f 7017434: Tiered needs to support reprofiling
iveresov
parents: 7397
diff changeset
   365
}
8f11ba61239f 7017434: Tiered needs to support reprofiling
iveresov
parents: 7397
diff changeset
   366
51369
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
   367
nmethod* TieredThresholdPolicy::event(const methodHandle& method, const methodHandle& inlinee,
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 37281
diff changeset
   368
                                      int branch_bci, int bci, CompLevel comp_level, CompiledMethod* nm, JavaThread* thread) {
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   369
  if (comp_level == CompLevel_none &&
11572
84afef481892 7131259: compile_method and CompilationPolicy::event shouldn't be declared TRAPS
iveresov
parents: 11192
diff changeset
   370
      JvmtiExport::can_post_interpreter_events() &&
84afef481892 7131259: compile_method and CompilationPolicy::event shouldn't be declared TRAPS
iveresov
parents: 11192
diff changeset
   371
      thread->is_interp_only_mode()) {
84afef481892 7131259: compile_method and CompilationPolicy::event shouldn't be declared TRAPS
iveresov
parents: 11192
diff changeset
   372
    return NULL;
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   373
  }
52934
8deeb7bba516 8214917: CTW testlibrary shouldn't ignore errors raised by the library itself
iignatyev
parents: 52675
diff changeset
   374
  if (ReplayCompiles) {
24324
e18584aa83e2 8041959: Skip replay parsing errors with ReplayIgnoreInitErrors
kvn
parents: 24321
diff changeset
   375
    // Don't trigger other compiles in testing mode
e18584aa83e2 8041959: Skip replay parsing errors with ReplayIgnoreInitErrors
kvn
parents: 24321
diff changeset
   376
    return NULL;
e18584aa83e2 8041959: Skip replay parsing errors with ReplayIgnoreInitErrors
kvn
parents: 24321
diff changeset
   377
  }
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   378
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   379
  handle_counter_overflow(method());
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   380
  if (method() != inlinee()) {
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   381
    handle_counter_overflow(inlinee());
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   382
  }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   383
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   384
  if (PrintTieredEvents) {
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   385
    print_event(bci == InvocationEntryBci ? CALL : LOOP, method, inlinee, bci, comp_level);
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   386
  }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   387
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   388
  if (bci == InvocationEntryBci) {
11572
84afef481892 7131259: compile_method and CompilationPolicy::event shouldn't be declared TRAPS
iveresov
parents: 11192
diff changeset
   389
    method_invocation_event(method, inlinee, comp_level, nm, thread);
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   390
  } else {
27447
5cd7caca045d 8062169: Multiple OSR compilations issued for same bci
thartmann
parents: 24324
diff changeset
   391
    // method == inlinee if the event originated in the main method
11572
84afef481892 7131259: compile_method and CompilationPolicy::event shouldn't be declared TRAPS
iveresov
parents: 11192
diff changeset
   392
    method_back_branch_event(method, inlinee, bci, comp_level, nm, thread);
27447
5cd7caca045d 8062169: Multiple OSR compilations issued for same bci
thartmann
parents: 24324
diff changeset
   393
    // Check if event led to a higher level OSR compilation
5cd7caca045d 8062169: Multiple OSR compilations issued for same bci
thartmann
parents: 24324
diff changeset
   394
    nmethod* osr_nm = inlinee->lookup_osr_nmethod_for(bci, comp_level, false);
5cd7caca045d 8062169: Multiple OSR compilations issued for same bci
thartmann
parents: 24324
diff changeset
   395
    if (osr_nm != NULL && osr_nm->comp_level() > comp_level) {
5cd7caca045d 8062169: Multiple OSR compilations issued for same bci
thartmann
parents: 24324
diff changeset
   396
      // Perform OSR with new nmethod
5cd7caca045d 8062169: Multiple OSR compilations issued for same bci
thartmann
parents: 24324
diff changeset
   397
      return osr_nm;
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   398
    }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   399
  }
27447
5cd7caca045d 8062169: Multiple OSR compilations issued for same bci
thartmann
parents: 24324
diff changeset
   400
  return NULL;
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   401
}
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   402
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   403
// Check if the method can be compiled, change level if necessary
51369
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
   404
void TieredThresholdPolicy::compile(const methodHandle& mh, int bci, CompLevel level, JavaThread* thread) {
10250
0794cd144834 7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents: 10014
diff changeset
   405
  assert(level <= TieredStopAtLevel, "Invalid compilation level");
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   406
  if (level == CompLevel_none) {
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   407
    return;
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   408
  }
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40364
diff changeset
   409
  if (level == CompLevel_aot) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40364
diff changeset
   410
    if (mh->has_aot_code()) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40364
diff changeset
   411
      if (PrintTieredEvents) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40364
diff changeset
   412
        print_event(COMPILE, mh, mh, bci, level);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40364
diff changeset
   413
      }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40364
diff changeset
   414
      MutexLocker ml(Compile_lock);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40364
diff changeset
   415
      NoSafepointVerifier nsv;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40364
diff changeset
   416
      if (mh->has_aot_code() && mh->code() != mh->aot_code()) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40364
diff changeset
   417
        mh->aot_code()->make_entrant();
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40364
diff changeset
   418
        if (mh->has_compiled_code()) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40364
diff changeset
   419
          mh->code()->make_not_entrant();
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40364
diff changeset
   420
        }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40364
diff changeset
   421
        Method::set_code(mh, mh->aot_code());
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40364
diff changeset
   422
      }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40364
diff changeset
   423
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40364
diff changeset
   424
    return;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40364
diff changeset
   425
  }
37281
c4e7456d6ae1 8144964: JVMCI compilations need to be disabled until the module system is initialized
twisti
parents: 36556
diff changeset
   426
7389
93110864f81e 7000349: Tiered reacts incorrectly to C1 compilation failures
iveresov
parents: 6453
diff changeset
   427
  // Check if the method can be compiled. If it cannot be compiled with C1, continue profiling
93110864f81e 7000349: Tiered reacts incorrectly to C1 compilation failures
iveresov
parents: 6453
diff changeset
   428
  // in the interpreter and then compile with C2 (the transition function will request that,
93110864f81e 7000349: Tiered reacts incorrectly to C1 compilation failures
iveresov
parents: 6453
diff changeset
   429
  // see common() ). If the method cannot be compiled with C2 but still can with C1, compile it with
93110864f81e 7000349: Tiered reacts incorrectly to C1 compilation failures
iveresov
parents: 6453
diff changeset
   430
  // pure C1.
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   431
  if (!can_be_compiled(mh, level)) {
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   432
    if (level == CompLevel_full_optimization && can_be_compiled(mh, CompLevel_simple)) {
11572
84afef481892 7131259: compile_method and CompilationPolicy::event shouldn't be declared TRAPS
iveresov
parents: 11192
diff changeset
   433
        compile(mh, bci, CompLevel_simple, thread);
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   434
    }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   435
    return;
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   436
  }
13891
35dabd293e56 7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents: 13728
diff changeset
   437
  if (bci != InvocationEntryBci && mh->is_not_osr_compilable(level)) {
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   438
    return;
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   439
  }
24321
621f7e09fc0a 8040798: compiler/startup/SmallCodeCacheStartup.java timed out in RT_Baseline
anoll
parents: 24013
diff changeset
   440
  if (!CompileBroker::compilation_is_in_queue(mh)) {
10250
0794cd144834 7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents: 10014
diff changeset
   441
    if (PrintTieredEvents) {
0794cd144834 7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents: 10014
diff changeset
   442
      print_event(COMPILE, mh, mh, bci, level);
0794cd144834 7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents: 10014
diff changeset
   443
    }
11572
84afef481892 7131259: compile_method and CompilationPolicy::event shouldn't be declared TRAPS
iveresov
parents: 11192
diff changeset
   444
    submit_compile(mh, bci, level, thread);
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   445
  }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   446
}
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   447
50068
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   448
// Update the rate and submit compile
51369
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
   449
void TieredThresholdPolicy::submit_compile(const methodHandle& mh, int bci, CompLevel level, JavaThread* thread) {
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   450
  int hot_count = (bci == InvocationEntryBci) ? mh->invocation_count() : mh->backedge_count();
50068
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   451
  update_rate(os::javaTimeMillis(), mh());
38218
f5ba1dea04eb 8153013: BlockingCompilation test times out
neliasso
parents: 38133
diff changeset
   452
  CompileBroker::compile_method(mh, bci, level, mh, hot_count, CompileTask::Reason_Tiered, thread);
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   453
}
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   454
50068
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   455
// Print an event.
51369
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
   456
void TieredThresholdPolicy::print_specific(EventType type, const methodHandle& mh, const methodHandle& imh,
50068
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   457
                                             int bci, CompLevel level) {
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   458
  tty->print(" rate=");
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   459
  if (mh->prev_time() == 0) tty->print("n/a");
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   460
  else tty->print("%f", mh->rate());
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   461
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   462
  tty->print(" k=%.2lf,%.2lf", threshold_scale(CompLevel_full_profile, Tier3LoadFeedback),
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   463
                               threshold_scale(CompLevel_full_optimization, Tier4LoadFeedback));
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   464
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   465
}
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   466
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   467
// update_rate() is called from select_task() while holding a compile queue lock.
51369
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
   468
void TieredThresholdPolicy::update_rate(jlong t, Method* m) {
50068
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   469
  // Skip update if counters are absent.
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   470
  // Can't allocate them since we are holding compile queue lock.
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   471
  if (m->method_counters() == NULL)  return;
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   472
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   473
  if (is_old(m)) {
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   474
    // We don't remove old methods from the queue,
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   475
    // so we can just zero the rate.
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   476
    m->set_rate(0);
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   477
    return;
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   478
  }
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   479
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   480
  // We don't update the rate if we've just came out of a safepoint.
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   481
  // delta_s is the time since last safepoint in milliseconds.
54009
13acb4339895 8220151: SafepointTracing::end_of_last_safepoint_ms should return ms since epoch.
rehn
parents: 53895
diff changeset
   482
  jlong delta_s = t - SafepointTracing::end_of_last_safepoint_epoch_ms();
50068
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   483
  jlong delta_t = t - (m->prev_time() != 0 ? m->prev_time() : start_time()); // milliseconds since the last measurement
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   484
  // How many events were there since the last time?
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   485
  int event_count = m->invocation_count() + m->backedge_count();
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   486
  int delta_e = event_count - m->prev_event_count();
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   487
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   488
  // We should be running for at least 1ms.
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   489
  if (delta_s >= TieredRateUpdateMinTime) {
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   490
    // And we must've taken the previous point at least 1ms before.
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   491
    if (delta_t >= TieredRateUpdateMinTime && delta_e > 0) {
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   492
      m->set_prev_time(t);
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   493
      m->set_prev_event_count(event_count);
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   494
      m->set_rate((float)delta_e / (float)delta_t); // Rate is events per millisecond
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   495
    } else {
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   496
      if (delta_t > TieredRateUpdateMaxTime && delta_e == 0) {
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   497
        // If nothing happened for 25ms, zero the rate. Don't modify prev values.
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   498
        m->set_rate(0);
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   499
      }
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   500
    }
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   501
  }
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   502
}
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   503
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   504
// Check if this method has been stale from a given number of milliseconds.
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   505
// See select_task().
51369
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
   506
bool TieredThresholdPolicy::is_stale(jlong t, jlong timeout, Method* m) {
54009
13acb4339895 8220151: SafepointTracing::end_of_last_safepoint_ms should return ms since epoch.
rehn
parents: 53895
diff changeset
   507
  jlong delta_s = t - SafepointTracing::end_of_last_safepoint_epoch_ms();
50068
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   508
  jlong delta_t = t - m->prev_time();
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   509
  if (delta_t > timeout && delta_s > timeout) {
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   510
    int event_count = m->invocation_count() + m->backedge_count();
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   511
    int delta_e = event_count - m->prev_event_count();
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   512
    // Return true if there were no events.
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   513
    return delta_e == 0;
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   514
  }
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   515
  return false;
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   516
}
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   517
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   518
// We don't remove old methods from the compile queue even if they have
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   519
// very low activity. See select_task().
51369
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
   520
bool TieredThresholdPolicy::is_old(Method* method) {
50068
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   521
  return method->invocation_count() > 50000 || method->backedge_count() > 500000;
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   522
}
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   523
51369
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
   524
double TieredThresholdPolicy::weight(Method* method) {
50068
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   525
  return (double)(method->rate() + 1) *
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   526
    (method->invocation_count() + 1) * (method->backedge_count() + 1);
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   527
}
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   528
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   529
// Apply heuristics and return true if x should be compiled before y
51369
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
   530
bool TieredThresholdPolicy::compare_methods(Method* x, Method* y) {
50068
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   531
  if (x->highest_comp_level() > y->highest_comp_level()) {
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   532
    // recompilation after deopt
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   533
    return true;
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   534
  } else
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   535
    if (x->highest_comp_level() == y->highest_comp_level()) {
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   536
      if (weight(x) > weight(y)) {
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   537
        return true;
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   538
      }
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   539
    }
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   540
  return false;
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   541
}
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   542
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   543
// Is method profiled enough?
51369
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
   544
bool TieredThresholdPolicy::is_method_profiled(Method* method) {
50068
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   545
  MethodData* mdo = method->method_data();
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   546
  if (mdo != NULL) {
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   547
    int i = mdo->invocation_count_delta();
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   548
    int b = mdo->backedge_count_delta();
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   549
    return call_predicate_helper<CompLevel_full_profile>(i, b, 1, method);
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   550
  }
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   551
  return false;
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   552
}
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   553
51369
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
   554
double TieredThresholdPolicy::threshold_scale(CompLevel level, int feedback_k) {
50068
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   555
  double queue_size = CompileBroker::queue_size(level);
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   556
  int comp_count = compiler_count(level);
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   557
  double k = queue_size / (feedback_k * comp_count) + 1;
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   558
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   559
  // Increase C1 compile threshold when the code cache is filled more
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   560
  // than specified by IncreaseFirstTierCompileThresholdAt percentage.
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   561
  // The main intention is to keep enough free space for C2 compiled code
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   562
  // to achieve peak performance if the code cache is under stress.
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   563
  if ((TieredStopAtLevel == CompLevel_full_optimization) && (level != CompLevel_full_optimization))  {
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   564
    double current_reverse_free_ratio = CodeCache::reverse_free_ratio(CodeCache::get_code_blob_type(level));
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   565
    if (current_reverse_free_ratio > _increase_threshold_at_ratio) {
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   566
      k *= exp(current_reverse_free_ratio - _increase_threshold_at_ratio);
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   567
    }
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   568
  }
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   569
  return k;
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   570
}
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   571
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   572
// Call and loop predicates determine whether a transition to a higher
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   573
// compilation level should be performed (pointers to predicate functions
50068
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   574
// are passed to common()).
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   575
// Tier?LoadFeedback is basically a coefficient that determines of
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   576
// how many methods per compiler thread can be in the queue before
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   577
// the threshold values double.
51369
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
   578
bool TieredThresholdPolicy::loop_predicate(int i, int b, CompLevel cur_level, Method* method) {
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   579
  switch(cur_level) {
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40364
diff changeset
   580
  case CompLevel_aot: {
50068
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   581
    double k = threshold_scale(CompLevel_full_profile, Tier3LoadFeedback);
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   582
    return loop_predicate_helper<CompLevel_aot>(i, b, k, method);
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40364
diff changeset
   583
  }
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   584
  case CompLevel_none:
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   585
  case CompLevel_limited_profile: {
50068
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   586
    double k = threshold_scale(CompLevel_full_profile, Tier3LoadFeedback);
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   587
    return loop_predicate_helper<CompLevel_none>(i, b, k, method);
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   588
  }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   589
  case CompLevel_full_profile: {
50068
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   590
    double k = threshold_scale(CompLevel_full_optimization, Tier4LoadFeedback);
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   591
    return loop_predicate_helper<CompLevel_full_profile>(i, b, k, method);
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   592
  }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   593
  default:
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   594
    return true;
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   595
  }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   596
}
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   597
51369
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
   598
bool TieredThresholdPolicy::call_predicate(int i, int b, CompLevel cur_level, Method* method) {
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   599
  switch(cur_level) {
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40364
diff changeset
   600
  case CompLevel_aot: {
50068
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   601
    double k = threshold_scale(CompLevel_full_profile, Tier3LoadFeedback);
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   602
    return call_predicate_helper<CompLevel_aot>(i, b, k, method);
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40364
diff changeset
   603
  }
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   604
  case CompLevel_none:
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   605
  case CompLevel_limited_profile: {
50068
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   606
    double k = threshold_scale(CompLevel_full_profile, Tier3LoadFeedback);
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   607
    return call_predicate_helper<CompLevel_none>(i, b, k, method);
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   608
  }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   609
  case CompLevel_full_profile: {
50068
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   610
    double k = threshold_scale(CompLevel_full_optimization, Tier4LoadFeedback);
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   611
    return call_predicate_helper<CompLevel_full_profile>(i, b, k, method);
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   612
  }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   613
  default:
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   614
    return true;
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   615
  }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   616
}
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   617
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   618
// Determine is a method is mature.
51369
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
   619
bool TieredThresholdPolicy::is_mature(Method* method) {
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   620
  if (is_trivial(method)) return true;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11572
diff changeset
   621
  MethodData* mdo = method->method_data();
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   622
  if (mdo != NULL) {
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   623
    int i = mdo->invocation_count();
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   624
    int b = mdo->backedge_count();
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   625
    double k = ProfileMaturityPercentage / 100.0;
28650
772aaab2582f 8059606: Enable per-method usage of CompileThresholdScaling (per-method compilation thresholds)
zmajo
parents: 27447
diff changeset
   626
    return call_predicate_helper<CompLevel_full_profile>(i, b, k, method) ||
772aaab2582f 8059606: Enable per-method usage of CompileThresholdScaling (per-method compilation thresholds)
zmajo
parents: 27447
diff changeset
   627
           loop_predicate_helper<CompLevel_full_profile>(i, b, k, method);
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   628
  }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   629
  return false;
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   630
}
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   631
50068
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   632
// If a method is old enough and is still in the interpreter we would want to
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   633
// start profiling without waiting for the compiled method to arrive.
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   634
// We also take the load on compilers into the account.
51369
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
   635
bool TieredThresholdPolicy::should_create_mdo(Method* method, CompLevel cur_level) {
50068
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   636
  if (cur_level == CompLevel_none &&
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   637
      CompileBroker::queue_size(CompLevel_full_optimization) <=
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   638
      Tier3DelayOn * compiler_count(CompLevel_full_optimization)) {
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   639
    int i = method->invocation_count();
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   640
    int b = method->backedge_count();
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   641
    double k = Tier0ProfilingStartPercentage / 100.0;
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   642
    return call_predicate_helper<CompLevel_none>(i, b, k, method) || loop_predicate_helper<CompLevel_none>(i, b, k, method);
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   643
  }
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   644
  return false;
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   645
}
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   646
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   647
// Inlining control: if we're compiling a profiled method with C1 and the callee
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   648
// is known to have OSRed in a C2 version, don't inline it.
51369
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
   649
bool TieredThresholdPolicy::should_not_inline(ciEnv* env, ciMethod* callee) {
50068
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   650
  CompLevel comp_level = (CompLevel)env->comp_level();
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   651
  if (comp_level == CompLevel_full_profile ||
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   652
      comp_level == CompLevel_limited_profile) {
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   653
    return callee->highest_osr_comp_level() == CompLevel_full_optimization;
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   654
  }
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   655
  return false;
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   656
}
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   657
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   658
// Create MDO if necessary.
51369
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
   659
void TieredThresholdPolicy::create_mdo(const methodHandle& mh, JavaThread* THREAD) {
50068
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   660
  if (mh->is_native() ||
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   661
      mh->is_abstract() ||
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   662
      mh->is_accessor() ||
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   663
      mh->is_constant_getter()) {
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   664
    return;
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   665
  }
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   666
  if (mh->method_data() == NULL) {
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   667
    Method::build_interpreter_method_data(mh, CHECK_AND_CLEAR);
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   668
  }
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   669
}
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   670
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   671
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   672
/*
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   673
 * Method states:
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   674
 *   0 - interpreter (CompLevel_none)
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   675
 *   1 - pure C1 (CompLevel_simple)
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   676
 *   2 - C1 with invocation and backedge counting (CompLevel_limited_profile)
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   677
 *   3 - C1 with full profiling (CompLevel_full_profile)
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   678
 *   4 - C2 (CompLevel_full_optimization)
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   679
 *
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   680
 * Common state transition patterns:
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   681
 * a. 0 -> 3 -> 4.
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   682
 *    The most common path. But note that even in this straightforward case
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   683
 *    profiling can start at level 0 and finish at level 3.
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   684
 *
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   685
 * b. 0 -> 2 -> 3 -> 4.
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   686
 *    This case occurs when the load on C2 is deemed too high. So, instead of transitioning
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   687
 *    into state 3 directly and over-profiling while a method is in the C2 queue we transition to
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   688
 *    level 2 and wait until the load on C2 decreases. This path is disabled for OSRs.
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   689
 *
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   690
 * c. 0 -> (3->2) -> 4.
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   691
 *    In this case we enqueue a method for compilation at level 3, but the C1 queue is long enough
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   692
 *    to enable the profiling to fully occur at level 0. In this case we change the compilation level
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   693
 *    of the method to 2 while the request is still in-queue, because it'll allow it to run much faster
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   694
 *    without full profiling while c2 is compiling.
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   695
 *
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   696
 * d. 0 -> 3 -> 1 or 0 -> 2 -> 1.
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   697
 *    After a method was once compiled with C1 it can be identified as trivial and be compiled to
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   698
 *    level 1. These transition can also occur if a method can't be compiled with C2 but can with C1.
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   699
 *
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   700
 * e. 0 -> 4.
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   701
 *    This can happen if a method fails C1 compilation (it will still be profiled in the interpreter)
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   702
 *    or because of a deopt that didn't require reprofiling (compilation won't happen in this case because
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   703
 *    the compiled version already exists).
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   704
 *
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   705
 * Note that since state 0 can be reached from any other state via deoptimization different loops
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   706
 * are possible.
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   707
 *
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   708
 */
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   709
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   710
// Common transition function. Given a predicate determines if a method should transition to another level.
51369
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
   711
CompLevel TieredThresholdPolicy::common(Predicate p, Method* method, CompLevel cur_level, bool disable_feedback) {
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   712
  CompLevel next_level = cur_level;
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   713
  int i = method->invocation_count();
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   714
  int b = method->backedge_count();
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   715
50068
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   716
  if (is_trivial(method)) {
10250
0794cd144834 7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents: 10014
diff changeset
   717
    next_level = CompLevel_simple;
0794cd144834 7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents: 10014
diff changeset
   718
  } else {
0794cd144834 7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents: 10014
diff changeset
   719
    switch(cur_level) {
50068
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   720
      default: break;
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   721
      case CompLevel_aot: {
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   722
      // If we were at full profile level, would we switch to full opt?
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   723
      if (common(p, method, CompLevel_full_profile, disable_feedback) == CompLevel_full_optimization) {
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   724
        next_level = CompLevel_full_optimization;
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   725
      } else if (disable_feedback || (CompileBroker::queue_size(CompLevel_full_optimization) <=
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   726
                               Tier3DelayOff * compiler_count(CompLevel_full_optimization) &&
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   727
                               (this->*p)(i, b, cur_level, method))) {
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40364
diff changeset
   728
        next_level = CompLevel_full_profile;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40364
diff changeset
   729
      }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40364
diff changeset
   730
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40364
diff changeset
   731
    break;
10250
0794cd144834 7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents: 10014
diff changeset
   732
    case CompLevel_none:
0794cd144834 7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents: 10014
diff changeset
   733
      // If we were at full profile level, would we switch to full opt?
50068
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   734
      if (common(p, method, CompLevel_full_profile, disable_feedback) == CompLevel_full_optimization) {
10250
0794cd144834 7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents: 10014
diff changeset
   735
        next_level = CompLevel_full_optimization;
28650
772aaab2582f 8059606: Enable per-method usage of CompileThresholdScaling (per-method compilation thresholds)
zmajo
parents: 27447
diff changeset
   736
      } else if ((this->*p)(i, b, cur_level, method)) {
50068
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   737
#if INCLUDE_JVMCI
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   738
        if (EnableJVMCI && UseJVMCICompiler) {
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   739
          // Since JVMCI takes a while to warm up, its queue inevitably backs up during
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   740
          // early VM execution. As of 2014-06-13, JVMCI's inliner assumes that the root
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   741
          // compilation method and all potential inlinees have mature profiles (which
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   742
          // includes type profiling). If it sees immature profiles, JVMCI's inliner
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   743
          // can perform pathologically bad (e.g., causing OutOfMemoryErrors due to
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   744
          // exploring/inlining too many graphs). Since a rewrite of the inliner is
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   745
          // in progress, we simply disable the dialing back heuristic for now and will
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   746
          // revisit this decision once the new inliner is completed.
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   747
          next_level = CompLevel_full_profile;
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   748
        } else
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   749
#endif
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   750
        {
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   751
          // C1-generated fully profiled code is about 30% slower than the limited profile
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   752
          // code that has only invocation and backedge counters. The observation is that
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   753
          // if C2 queue is large enough we can spend too much time in the fully profiled code
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   754
          // while waiting for C2 to pick the method from the queue. To alleviate this problem
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   755
          // we introduce a feedback on the C2 queue size. If the C2 queue is sufficiently long
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   756
          // we choose to compile a limited profiled version and then recompile with full profiling
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   757
          // when the load on C2 goes down.
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   758
          if (!disable_feedback && CompileBroker::queue_size(CompLevel_full_optimization) >
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   759
              Tier3DelayOn * compiler_count(CompLevel_full_optimization)) {
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   760
            next_level = CompLevel_limited_profile;
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   761
          } else {
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   762
            next_level = CompLevel_full_profile;
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   763
          }
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   764
        }
10250
0794cd144834 7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents: 10014
diff changeset
   765
      }
0794cd144834 7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents: 10014
diff changeset
   766
      break;
0794cd144834 7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents: 10014
diff changeset
   767
    case CompLevel_limited_profile:
50068
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   768
      if (is_method_profiled(method)) {
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   769
        // Special case: we got here because this method was fully profiled in the interpreter.
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   770
        next_level = CompLevel_full_optimization;
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   771
      } else {
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   772
        MethodData* mdo = method->method_data();
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   773
        if (mdo != NULL) {
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   774
          if (mdo->would_profile()) {
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   775
            if (disable_feedback || (CompileBroker::queue_size(CompLevel_full_optimization) <=
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   776
                                     Tier3DelayOff * compiler_count(CompLevel_full_optimization) &&
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   777
                                     (this->*p)(i, b, cur_level, method))) {
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   778
              next_level = CompLevel_full_profile;
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   779
            }
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   780
          } else {
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   781
            next_level = CompLevel_full_optimization;
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   782
          }
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   783
        } else {
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   784
          // If there is no MDO we need to profile
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   785
          if (disable_feedback || (CompileBroker::queue_size(CompLevel_full_optimization) <=
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   786
                                   Tier3DelayOff * compiler_count(CompLevel_full_optimization) &&
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   787
                                   (this->*p)(i, b, cur_level, method))) {
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   788
            next_level = CompLevel_full_profile;
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   789
          }
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   790
        }
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   791
      }
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   792
      break;
10250
0794cd144834 7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents: 10014
diff changeset
   793
    case CompLevel_full_profile:
0794cd144834 7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents: 10014
diff changeset
   794
      {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11572
diff changeset
   795
        MethodData* mdo = method->method_data();
10250
0794cd144834 7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents: 10014
diff changeset
   796
        if (mdo != NULL) {
0794cd144834 7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents: 10014
diff changeset
   797
          if (mdo->would_profile()) {
0794cd144834 7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents: 10014
diff changeset
   798
            int mdo_i = mdo->invocation_count_delta();
0794cd144834 7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents: 10014
diff changeset
   799
            int mdo_b = mdo->backedge_count_delta();
28650
772aaab2582f 8059606: Enable per-method usage of CompileThresholdScaling (per-method compilation thresholds)
zmajo
parents: 27447
diff changeset
   800
            if ((this->*p)(mdo_i, mdo_b, cur_level, method)) {
10250
0794cd144834 7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents: 10014
diff changeset
   801
              next_level = CompLevel_full_optimization;
0794cd144834 7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents: 10014
diff changeset
   802
            }
0794cd144834 7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents: 10014
diff changeset
   803
          } else {
8322
8f11ba61239f 7017434: Tiered needs to support reprofiling
iveresov
parents: 7397
diff changeset
   804
            next_level = CompLevel_full_optimization;
8f11ba61239f 7017434: Tiered needs to support reprofiling
iveresov
parents: 7397
diff changeset
   805
          }
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   806
        }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   807
      }
10250
0794cd144834 7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents: 10014
diff changeset
   808
      break;
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   809
    }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   810
  }
10250
0794cd144834 7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents: 10014
diff changeset
   811
  return MIN2(next_level, (CompLevel)TieredStopAtLevel);
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   812
}
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   813
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   814
// Determine if a method should be compiled with a normal entry point at a different level.
51369
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
   815
CompLevel TieredThresholdPolicy::call_event(Method* method, CompLevel cur_level, JavaThread * thread) {
10013
714ad59b56cb 7058689: Tiered: Reprofiling doesn't happen in presence of level 4 OSR methods
iveresov
parents: 9625
diff changeset
   816
  CompLevel osr_level = MIN2((CompLevel) method->highest_osr_comp_level(),
51369
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
   817
                             common(&TieredThresholdPolicy::loop_predicate, method, cur_level, true));
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
   818
  CompLevel next_level = common(&TieredThresholdPolicy::call_predicate, method, cur_level);
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   819
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   820
  // If OSR method level is greater than the regular method level, the levels should be
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   821
  // equalized by raising the regular method level in order to avoid OSRs during each
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   822
  // invocation of the method.
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   823
  if (osr_level == CompLevel_full_optimization && cur_level == CompLevel_full_profile) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11572
diff changeset
   824
    MethodData* mdo = method->method_data();
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   825
    guarantee(mdo != NULL, "MDO should not be NULL");
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   826
    if (mdo->invocation_count() >= 1) {
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   827
      next_level = CompLevel_full_optimization;
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   828
    }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   829
  } else {
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   830
    next_level = MAX2(osr_level, next_level);
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   831
  }
38666
5ff19807abd5 8152311: [JVMCI] allow JVMCI compiler to change the compilation policy for a method
dnsimon
parents: 38218
diff changeset
   832
#if INCLUDE_JVMCI
5ff19807abd5 8152311: [JVMCI] allow JVMCI compiler to change the compilation policy for a method
dnsimon
parents: 38218
diff changeset
   833
  if (UseJVMCICompiler) {
5ff19807abd5 8152311: [JVMCI] allow JVMCI compiler to change the compilation policy for a method
dnsimon
parents: 38218
diff changeset
   834
    next_level = JVMCIRuntime::adjust_comp_level(method, false, next_level, thread);
5ff19807abd5 8152311: [JVMCI] allow JVMCI compiler to change the compilation policy for a method
dnsimon
parents: 38218
diff changeset
   835
  }
5ff19807abd5 8152311: [JVMCI] allow JVMCI compiler to change the compilation policy for a method
dnsimon
parents: 38218
diff changeset
   836
#endif
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   837
  return next_level;
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   838
}
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   839
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   840
// Determine if we should do an OSR compilation of a given method.
51369
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
   841
CompLevel TieredThresholdPolicy::loop_event(Method* method, CompLevel cur_level, JavaThread* thread) {
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
   842
  CompLevel next_level = common(&TieredThresholdPolicy::loop_predicate, method, cur_level, true);
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   843
  if (cur_level == CompLevel_none) {
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   844
    // If there is a live OSR method that means that we deopted to the interpreter
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   845
    // for the transition.
10013
714ad59b56cb 7058689: Tiered: Reprofiling doesn't happen in presence of level 4 OSR methods
iveresov
parents: 9625
diff changeset
   846
    CompLevel osr_level = MIN2((CompLevel)method->highest_osr_comp_level(), next_level);
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   847
    if (osr_level > CompLevel_none) {
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   848
      return osr_level;
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   849
    }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   850
  }
38666
5ff19807abd5 8152311: [JVMCI] allow JVMCI compiler to change the compilation policy for a method
dnsimon
parents: 38218
diff changeset
   851
#if INCLUDE_JVMCI
5ff19807abd5 8152311: [JVMCI] allow JVMCI compiler to change the compilation policy for a method
dnsimon
parents: 38218
diff changeset
   852
  if (UseJVMCICompiler) {
5ff19807abd5 8152311: [JVMCI] allow JVMCI compiler to change the compilation policy for a method
dnsimon
parents: 38218
diff changeset
   853
    next_level = JVMCIRuntime::adjust_comp_level(method, true, next_level, thread);
5ff19807abd5 8152311: [JVMCI] allow JVMCI compiler to change the compilation policy for a method
dnsimon
parents: 38218
diff changeset
   854
  }
5ff19807abd5 8152311: [JVMCI] allow JVMCI compiler to change the compilation policy for a method
dnsimon
parents: 38218
diff changeset
   855
#endif
10013
714ad59b56cb 7058689: Tiered: Reprofiling doesn't happen in presence of level 4 OSR methods
iveresov
parents: 9625
diff changeset
   856
  return next_level;
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   857
}
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   858
51369
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
   859
bool TieredThresholdPolicy::maybe_switch_to_aot(const methodHandle& mh, CompLevel cur_level, CompLevel next_level, JavaThread* thread) {
53193
184c51e48260 8216262: Remove develop flag DelayCompilationDuringStartup
redestad
parents: 52934
diff changeset
   860
  if (UseAOT) {
50068
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   861
    if (cur_level == CompLevel_full_profile || cur_level == CompLevel_none) {
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   862
      // If the current level is full profile or interpreter and we're switching to any other level,
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   863
      // activate the AOT code back first so that we won't waste time overprofiling.
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   864
      compile(mh, InvocationEntryBci, CompLevel_aot, thread);
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   865
      // Fall through for JIT compilation.
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   866
    }
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   867
    if (next_level == CompLevel_limited_profile && cur_level != CompLevel_aot && mh->has_aot_code()) {
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   868
      // If the next level is limited profile, use the aot code (if there is any),
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   869
      // since it's essentially the same thing.
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   870
      compile(mh, InvocationEntryBci, CompLevel_aot, thread);
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   871
      // Not need to JIT, we're done.
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   872
      return true;
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   873
    }
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   874
  }
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   875
  return false;
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   876
}
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   877
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   878
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   879
// Handle the invocation event.
51369
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
   880
void TieredThresholdPolicy::method_invocation_event(const methodHandle& mh, const methodHandle& imh,
50068
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   881
                                                      CompLevel level, CompiledMethod* nm, JavaThread* thread) {
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   882
  if (should_create_mdo(mh(), level)) {
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   883
    create_mdo(mh, thread);
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   884
  }
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   885
  CompLevel next_level = call_event(mh(), level, thread);
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   886
  if (next_level != level) {
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   887
    if (maybe_switch_to_aot(mh, level, next_level, thread)) {
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   888
      // No JITting necessary
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   889
      return;
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   890
    }
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   891
    if (is_compilation_enabled() && !CompileBroker::compilation_is_in_queue(mh)) {
11572
84afef481892 7131259: compile_method and CompilationPolicy::event shouldn't be declared TRAPS
iveresov
parents: 11192
diff changeset
   892
      compile(mh, InvocationEntryBci, next_level, thread);
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   893
    }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   894
  }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   895
}
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   896
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   897
// Handle the back branch event. Notice that we can compile the method
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   898
// with a regular entry from here.
51369
f32e61253792 8209186: Rename SimpleThresholdPolicy to TieredThresholdPolicy
redestad
parents: 51078
diff changeset
   899
void TieredThresholdPolicy::method_back_branch_event(const methodHandle& mh, const methodHandle& imh,
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 37281
diff changeset
   900
                                                     int bci, CompLevel level, CompiledMethod* nm, JavaThread* thread) {
50068
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   901
  if (should_create_mdo(mh(), level)) {
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   902
    create_mdo(mh, thread);
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   903
  }
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   904
  // Check if MDO should be created for the inlined method
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   905
  if (should_create_mdo(imh(), level)) {
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   906
    create_mdo(imh, thread);
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   907
  }
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   908
50068
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   909
  if (is_compilation_enabled()) {
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   910
    CompLevel next_osr_level = loop_event(imh(), level, thread);
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   911
    CompLevel max_osr_level = (CompLevel)imh->highest_osr_comp_level();
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   912
    // At the very least compile the OSR version
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   913
    if (!CompileBroker::compilation_is_in_queue(imh) && (next_osr_level != level)) {
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   914
      compile(imh, bci, next_osr_level, thread);
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   915
    }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   916
50068
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   917
    // Use loop event as an opportunity to also check if there's been
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   918
    // enough calls.
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   919
    CompLevel cur_level, next_level;
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   920
    if (mh() != imh()) { // If there is an enclosing method
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   921
      if (level == CompLevel_aot) {
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   922
        // Recompile the enclosing method to prevent infinite OSRs. Stay at AOT level while it's compiling.
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   923
        if (max_osr_level != CompLevel_none && !CompileBroker::compilation_is_in_queue(mh)) {
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   924
          compile(mh, InvocationEntryBci, MIN2((CompLevel)TieredStopAtLevel, CompLevel_full_profile), thread);
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   925
        }
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   926
      } else {
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   927
        // Current loop event level is not AOT
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   928
        guarantee(nm != NULL, "Should have nmethod here");
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   929
        cur_level = comp_level(mh());
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   930
        next_level = call_event(mh(), cur_level, thread);
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   931
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   932
        if (max_osr_level == CompLevel_full_optimization) {
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   933
          // The inlinee OSRed to full opt, we need to modify the enclosing method to avoid deopts
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   934
          bool make_not_entrant = false;
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   935
          if (nm->is_osr_method()) {
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   936
            // This is an osr method, just make it not entrant and recompile later if needed
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   937
            make_not_entrant = true;
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   938
          } else {
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   939
            if (next_level != CompLevel_full_optimization) {
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   940
              // next_level is not full opt, so we need to recompile the
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   941
              // enclosing method without the inlinee
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   942
              cur_level = CompLevel_none;
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   943
              make_not_entrant = true;
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   944
            }
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   945
          }
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   946
          if (make_not_entrant) {
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   947
            if (PrintTieredEvents) {
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   948
              int osr_bci = nm->is_osr_method() ? nm->osr_entry_bci() : InvocationEntryBci;
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   949
              print_event(MAKE_NOT_ENTRANT, mh(), mh(), osr_bci, level);
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   950
            }
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   951
            nm->make_not_entrant();
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   952
          }
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   953
        }
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   954
        // Fix up next_level if necessary to avoid deopts
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   955
        if (next_level == CompLevel_limited_profile && max_osr_level == CompLevel_full_profile) {
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   956
          next_level = CompLevel_full_profile;
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   957
        }
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   958
        if (cur_level != next_level) {
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   959
          if (!maybe_switch_to_aot(mh, cur_level, next_level, thread) && !CompileBroker::compilation_is_in_queue(mh)) {
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   960
            compile(mh, InvocationEntryBci, next_level, thread);
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   961
          }
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   962
        }
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   963
      }
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   964
    } else {
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   965
      cur_level = comp_level(mh());
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   966
      next_level = call_event(mh(), cur_level, thread);
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   967
      if (next_level != cur_level) {
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   968
        if (!maybe_switch_to_aot(mh, cur_level, next_level, thread) && !CompileBroker::compilation_is_in_queue(mh)) {
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   969
          compile(mh, InvocationEntryBci, next_level, thread);
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   970
        }
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49594
diff changeset
   971
      }
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   972
    }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   973
  }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   974
}
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40364
diff changeset
   975
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40364
diff changeset
   976
#endif