src/hotspot/share/runtime/simpleThresholdPolicy.hpp
author jcbeyler
Tue, 17 Jul 2018 19:59:38 -0700
changeset 51138 914f305ba6fa
parent 50068 5201c9474ee7
permissions -rw-r--r--
8205725: Update the JVMTI Spec for Heap Sampling Summary: Update the JVMTI Spec for Heap Sampling Reviewed-by: amenkov, sspitsyn Contributed-by: jcbeyler@google.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
     1
/*
49340
4e82736053ae 8191102: Incorrect include file use in classLoader.hpp
hseigel
parents: 47216
diff changeset
     2
 * Copyright (c) 2010, 2018, 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: 6453
diff changeset
    25
#ifndef SHARE_VM_RUNTIME_SIMPLETHRESHOLDPOLICY_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    26
#define SHARE_VM_RUNTIME_SIMPLETHRESHOLDPOLICY_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    27
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    28
#include "code/nmethod.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11572
diff changeset
    29
#include "oops/methodData.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    30
#include "runtime/compilationPolicy.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    31
#include "utilities/globalDefinitions.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    32
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 38666
diff changeset
    33
#ifdef TIERED
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 38666
diff changeset
    34
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    35
class CompileTask;
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    36
class CompileQueue;
50068
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
    37
/*
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
    38
 *  The system supports 5 execution levels:
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
    39
 *  * level 0 - interpreter
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
    40
 *  * level 1 - C1 with full optimization (no profiling)
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
    41
 *  * level 2 - C1 with invocation and backedge counters
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
    42
 *  * level 3 - C1 with full profiling (level 2 + MDO)
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
    43
 *  * level 4 - C2
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
    44
 *
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
    45
 * Levels 0, 2 and 3 periodically notify the runtime about the current value of the counters
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
    46
 * (invocation counters and backedge counters). The frequency of these notifications is
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
    47
 * different at each level. These notifications are used by the policy to decide what transition
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
    48
 * to make.
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
    49
 *
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
    50
 * Execution starts at level 0 (interpreter), then the policy can decide either to compile the
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
    51
 * method at level 3 or level 2. The decision is based on the following factors:
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
    52
 *    1. The length of the C2 queue determines the next level. The observation is that level 2
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
    53
 * is generally faster than level 3 by about 30%, therefore we would want to minimize the time
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
    54
 * a method spends at level 3. We should only spend the time at level 3 that is necessary to get
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
    55
 * adequate profiling. So, if the C2 queue is long enough it is more beneficial to go first to
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
    56
 * level 2, because if we transitioned to level 3 we would be stuck there until our C2 compile
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
    57
 * request makes its way through the long queue. When the load on C2 recedes we are going to
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
    58
 * recompile at level 3 and start gathering profiling information.
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
    59
 *    2. The length of C1 queue is used to dynamically adjust the thresholds, so as to introduce
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
    60
 * additional filtering if the compiler is overloaded. The rationale is that by the time a
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
    61
 * method gets compiled it can become unused, so it doesn't make sense to put too much onto the
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
    62
 * queue.
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
    63
 *
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
    64
 * After profiling is completed at level 3 the transition is made to level 4. Again, the length
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
    65
 * of the C2 queue is used as a feedback to adjust the thresholds.
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
    66
 *
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
    67
 * After the first C1 compile some basic information is determined about the code like the number
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
    68
 * of the blocks and the number of the loops. Based on that it can be decided that a method
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
    69
 * is trivial and compiling it with C1 will yield the same code. In this case the method is
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
    70
 * compiled at level 1 instead of 4.
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
    71
 *
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
    72
 * We also support profiling at level 0. If C1 is slow enough to produce the level 3 version of
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
    73
 * the code and the C2 queue is sufficiently small we can decide to start profiling in the
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
    74
 * interpreter (and continue profiling in the compiled code once the level 3 version arrives).
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
    75
 * If the profiling at level 0 is fully completed before level 3 version is produced, a level 2
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
    76
 * version is compiled instead in order to run faster waiting for a level 4 version.
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
    77
 *
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
    78
 * Compile queues are implemented as priority queues - for each method in the queue we compute
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
    79
 * the event rate (the number of invocation and backedge counter increments per unit of time).
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
    80
 * When getting an element off the queue we pick the one with the largest rate. Maintaining the
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
    81
 * rate also allows us to remove stale methods (the ones that got on the queue but stopped
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
    82
 * being used shortly after that).
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
    83
*/
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
    84
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
    85
/* Command line options:
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
    86
 * - Tier?InvokeNotifyFreqLog and Tier?BackedgeNotifyFreqLog control the frequency of method
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
    87
 *   invocation and backedge notifications. Basically every n-th invocation or backedge a mutator thread
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
    88
 *   makes a call into the runtime.
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
    89
 *
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
    90
 * - Tier?InvocationThreshold, Tier?CompileThreshold, Tier?BackEdgeThreshold, Tier?MinInvocationThreshold control
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
    91
 *   compilation thresholds.
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
    92
 *   Level 2 thresholds are not used and are provided for option-compatibility and potential future use.
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
    93
 *   Other thresholds work as follows:
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
    94
 *
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
    95
 *   Transition from interpreter (level 0) to C1 with full profiling (level 3) happens when
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
    96
 *   the following predicate is true (X is the level):
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
    97
 *
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
    98
 *   i > TierXInvocationThreshold * s || (i > TierXMinInvocationThreshold * s  && i + b > TierXCompileThreshold * s),
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
    99
 *
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   100
 *   where $i$ is the number of method invocations, $b$ number of backedges and $s$ is the scaling
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   101
 *   coefficient that will be discussed further.
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   102
 *   The intuition is to equalize the time that is spend profiling each method.
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   103
 *   The same predicate is used to control the transition from level 3 to level 4 (C2). It should be
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   104
 *   noted though that the thresholds are relative. Moreover i and b for the 0->3 transition come
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   105
 *   from Method* and for 3->4 transition they come from MDO (since profiled invocations are
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   106
 *   counted separately). Finally, if a method does not contain anything worth profiling, a transition
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   107
 *   from level 3 to level 4 occurs without considering thresholds (e.g., with fewer invocations than
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   108
 *   what is specified by Tier4InvocationThreshold).
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   109
 *
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   110
 *   OSR transitions are controlled simply with b > TierXBackEdgeThreshold * s predicates.
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   111
 *
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   112
 * - Tier?LoadFeedback options are used to automatically scale the predicates described above depending
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   113
 *   on the compiler load. The scaling coefficients are computed as follows:
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   114
 *
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   115
 *   s = queue_size_X / (TierXLoadFeedback * compiler_count_X) + 1,
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   116
 *
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   117
 *   where queue_size_X is the current size of the compiler queue of level X, and compiler_count_X
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   118
 *   is the number of level X compiler threads.
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   119
 *
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   120
 *   Basically these parameters describe how many methods should be in the compile queue
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   121
 *   per compiler thread before the scaling coefficient increases by one.
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   122
 *
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   123
 *   This feedback provides the mechanism to automatically control the flow of compilation requests
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   124
 *   depending on the machine speed, mutator load and other external factors.
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   125
 *
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   126
 * - Tier3DelayOn and Tier3DelayOff parameters control another important feedback loop.
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   127
 *   Consider the following observation: a method compiled with full profiling (level 3)
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   128
 *   is about 30% slower than a method at level 2 (just invocation and backedge counters, no MDO).
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   129
 *   Normally, the following transitions will occur: 0->3->4. The problem arises when the C2 queue
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   130
 *   gets congested and the 3->4 transition is delayed. While the method is the C2 queue it continues
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   131
 *   executing at level 3 for much longer time than is required by the predicate and at suboptimal speed.
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   132
 *   The idea is to dynamically change the behavior of the system in such a way that if a substantial
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   133
 *   load on C2 is detected we would first do the 0->2 transition allowing a method to run faster.
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   134
 *   And then when the load decreases to allow 2->3 transitions.
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   135
 *
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   136
 *   Tier3Delay* parameters control this switching mechanism.
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   137
 *   Tier3DelayOn is the number of methods in the C2 queue per compiler thread after which the policy
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   138
 *   no longer does 0->3 transitions but does 0->2 transitions instead.
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   139
 *   Tier3DelayOff switches the original behavior back when the number of methods in the C2 queue
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   140
 *   per compiler thread falls below the specified amount.
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   141
 *   The hysteresis is necessary to avoid jitter.
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   142
 *
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   143
 * - TieredCompileTaskTimeout is the amount of time an idle method can spend in the compile queue.
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   144
 *   Basically, since we use the event rate d(i + b)/dt as a value of priority when selecting a method to
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   145
 *   compile from the compile queue, we also can detect stale methods for which the rate has been
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   146
 *   0 for some time in the same iteration. Stale methods can appear in the queue when an application
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   147
 *   abruptly changes its behavior.
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   148
 *
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   149
 * - TieredStopAtLevel, is used mostly for testing. It allows to bypass the policy logic and stick
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   150
 *   to a given level. For example it's useful to set TieredStopAtLevel = 1 in order to compile everything
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   151
 *   with pure c1.
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   152
 *
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   153
 * - Tier0ProfilingStartPercentage allows the interpreter to start profiling when the inequalities in the
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   154
 *   0->3 predicate are already exceeded by the given percentage but the level 3 version of the
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   155
 *   method is still not ready. We can even go directly from level 0 to 4 if c1 doesn't produce a compiled
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   156
 *   version in time. This reduces the overall transition to level 4 and decreases the startup time.
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   157
 *   Note that this behavior is also guarded by the Tier3Delay mechanism: when the c2 queue is too long
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   158
 *   these is not reason to start profiling prematurely.
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   159
 *
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   160
 * - TieredRateUpdateMinTime and TieredRateUpdateMaxTime are parameters of the rate computation.
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   161
 *   Basically, the rate is not computed more frequently than TieredRateUpdateMinTime and is considered
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   162
 *   to be zero if no events occurred in TieredRateUpdateMaxTime.
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   163
 */
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   164
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   165
class SimpleThresholdPolicy : public CompilationPolicy {
50068
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   166
  jlong _start_time;
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   167
  int _c1_count, _c2_count;
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   168
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   169
  // Check if the counter is big enough and set carry (effectively infinity).
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   170
  inline void set_carry_if_necessary(InvocationCounter *counter);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11572
diff changeset
   171
  // Set carry flags in the counters (in Method* and MDO).
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11572
diff changeset
   172
  inline void handle_counter_overflow(Method* method);
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   173
  // Call and loop predicates determine whether a transition to a higher compilation
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   174
  // level should be performed (pointers to predicate functions are passed to common_TF().
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   175
  // Predicates also take compiler load into account.
28650
772aaab2582f 8059606: Enable per-method usage of CompileThresholdScaling (per-method compilation thresholds)
zmajo
parents: 13728
diff changeset
   176
  typedef bool (SimpleThresholdPolicy::*Predicate)(int i, int b, CompLevel cur_level, Method* method);
772aaab2582f 8059606: Enable per-method usage of CompileThresholdScaling (per-method compilation thresholds)
zmajo
parents: 13728
diff changeset
   177
  bool call_predicate(int i, int b, CompLevel cur_level, Method* method);
772aaab2582f 8059606: Enable per-method usage of CompileThresholdScaling (per-method compilation thresholds)
zmajo
parents: 13728
diff changeset
   178
  bool loop_predicate(int i, int b, CompLevel cur_level, Method* method);
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   179
  // Common transition function. Given a predicate determines if a method should transition to another level.
50068
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   180
  CompLevel common(Predicate p, Method* method, CompLevel cur_level, bool disable_feedback = false);
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   181
  // Transition functions.
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   182
  // call_event determines if a method should be compiled at a different
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   183
  // level with a regular invocation entry.
38666
5ff19807abd5 8152311: [JVMCI] allow JVMCI compiler to change the compilation policy for a method
dnsimon
parents: 38133
diff changeset
   184
  CompLevel call_event(Method* method, CompLevel cur_level, JavaThread* thread);
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   185
  // loop_event checks if a method should be OSR compiled at a different
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   186
  // level.
38666
5ff19807abd5 8152311: [JVMCI] allow JVMCI compiler to change the compilation policy for a method
dnsimon
parents: 38133
diff changeset
   187
  CompLevel loop_event(Method* method, CompLevel cur_level, JavaThread* thread);
46727
6e4a84748e2c 8183039: Re-examine methodHandle methods uninlined by 8144256
coleenp
parents: 42650
diff changeset
   188
  void print_counters(const char* prefix, const methodHandle& mh);
50068
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   189
  // Has a method been long around?
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   190
  // We don't remove old methods from the compile queue even if they have
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   191
  // very low activity (see select_task()).
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   192
  inline bool is_old(Method* method);
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   193
  // Was a given method inactive for a given number of milliseconds.
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   194
  // If it is, we would remove it from the queue (see select_task()).
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   195
  inline bool is_stale(jlong t, jlong timeout, Method* m);
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   196
  // Compute the weight of the method for the compilation scheduling
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   197
  inline double weight(Method* method);
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   198
  // Apply heuristics and return true if x should be compiled before y
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   199
  inline bool compare_methods(Method* x, Method* y);
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   200
  // Compute event rate for a given method. The rate is the number of event (invocations + backedges)
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   201
  // per millisecond.
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   202
  inline void update_rate(jlong t, Method* m);
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   203
  // Compute threshold scaling coefficient
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   204
  inline double threshold_scale(CompLevel level, int feedback_k);
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   205
  // If a method is old enough and is still in the interpreter we would want to
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   206
  // start profiling without waiting for the compiled method to arrive. This function
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   207
  // determines whether we should do that.
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   208
  inline bool should_create_mdo(Method* method, CompLevel cur_level);
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   209
  // Create MDO if necessary.
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   210
  void create_mdo(const methodHandle& mh, JavaThread* thread);
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   211
  // Is method profiled enough?
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   212
  bool is_method_profiled(Method* method);
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   213
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   214
  double _increase_threshold_at_ratio;
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   215
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   216
  bool maybe_switch_to_aot(const methodHandle& mh, CompLevel cur_level, CompLevel next_level, JavaThread* thread);
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   217
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   218
protected:
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   219
  int c1_count() const     { return _c1_count; }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   220
  int c2_count() const     { return _c2_count; }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   221
  void set_c1_count(int x) { _c1_count = x;    }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   222
  void set_c2_count(int x) { _c2_count = x;    }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   223
10014
a5c2141ee857 7057120: Tiered: Allow C1 to inline methods with loops
iveresov
parents: 9625
diff changeset
   224
  enum EventType { CALL, LOOP, COMPILE, REMOVE_FROM_QUEUE, UPDATE_IN_QUEUE, REPROFILE, MAKE_NOT_ENTRANT };
46727
6e4a84748e2c 8183039: Re-examine methodHandle methods uninlined by 8144256
coleenp
parents: 42650
diff changeset
   225
  void print_event(EventType type, const methodHandle& mh, const methodHandle& imh, int bci, CompLevel level);
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   226
  // Print policy-specific information if necessary
50068
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   227
  virtual void print_specific(EventType type, const methodHandle& mh, const methodHandle& imh, int bci, CompLevel level);
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   228
  // Check if the method can be compiled, change level if necessary
33593
60764a78fa5c 8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents: 28650
diff changeset
   229
  void compile(const methodHandle& mh, int bci, CompLevel level, JavaThread* thread);
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   230
  // Submit a given method for compilation
33593
60764a78fa5c 8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents: 28650
diff changeset
   231
  virtual void submit_compile(const methodHandle& mh, int bci, CompLevel level, JavaThread* thread);
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   232
  // Simple methods are as good being compiled with C1 as C2.
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   233
  // This function tells if it's such a function.
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11572
diff changeset
   234
  inline bool is_trivial(Method* method);
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   235
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   236
  // Predicate helpers are used by .*_predicate() methods as well as others.
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   237
  // They check the given counter values, multiplied by the scale against the thresholds.
28650
772aaab2582f 8059606: Enable per-method usage of CompileThresholdScaling (per-method compilation thresholds)
zmajo
parents: 13728
diff changeset
   238
  template<CompLevel level> static inline bool call_predicate_helper(int i, int b, double scale, Method* method);
772aaab2582f 8059606: Enable per-method usage of CompileThresholdScaling (per-method compilation thresholds)
zmajo
parents: 13728
diff changeset
   239
  template<CompLevel level> static inline bool loop_predicate_helper(int i, int b, double scale, Method* method);
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   240
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   241
  // Get a compilation level for a given method.
49340
4e82736053ae 8191102: Incorrect include file use in classLoader.hpp
hseigel
parents: 47216
diff changeset
   242
  static CompLevel comp_level(Method* method);
33593
60764a78fa5c 8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents: 28650
diff changeset
   243
  virtual void method_invocation_event(const methodHandle& method, const methodHandle& inlinee,
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 33593
diff changeset
   244
                                       CompLevel level, CompiledMethod* nm, JavaThread* thread);
33593
60764a78fa5c 8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents: 28650
diff changeset
   245
  virtual void method_back_branch_event(const methodHandle& method, const methodHandle& inlinee,
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 33593
diff changeset
   246
                                        int bci, CompLevel level, CompiledMethod* nm, JavaThread* thread);
50068
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   247
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   248
  void set_increase_threshold_at_ratio() { _increase_threshold_at_ratio = 100 / (100 - (double)IncreaseFirstTierCompileThresholdAt); }
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   249
  void set_start_time(jlong t) { _start_time = t;    }
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   250
  jlong start_time() const     { return _start_time; }
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   251
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   252
public:
50068
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   253
  SimpleThresholdPolicy() : _start_time(0), _c1_count(0), _c2_count(0) { }
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   254
  virtual int compiler_count(CompLevel comp_level) {
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   255
    if (is_c1_compile(comp_level)) return c1_count();
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   256
    if (is_c2_compile(comp_level)) return c2_count();
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   257
    return 0;
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   258
  }
10250
0794cd144834 7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents: 10014
diff changeset
   259
  virtual CompLevel initial_compile_level() { return MIN2((CompLevel)TieredStopAtLevel, CompLevel_initial_compile); }
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   260
  virtual void do_safepoint_work() { }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11572
diff changeset
   261
  virtual void delay_compilation(Method* method) { }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11572
diff changeset
   262
  virtual void disable_compilation(Method* method) { }
8322
8f11ba61239f 7017434: Tiered needs to support reprofiling
iveresov
parents: 7397
diff changeset
   263
  virtual void reprofile(ScopeDesc* trap_scope, bool is_osr);
33593
60764a78fa5c 8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents: 28650
diff changeset
   264
  virtual nmethod* event(const methodHandle& method, const methodHandle& inlinee,
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 33593
diff changeset
   265
                         int branch_bci, int bci, CompLevel comp_level, CompiledMethod* nm, JavaThread* thread);
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   266
  // Select task is called by CompileBroker. We should return a task or NULL.
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   267
  virtual CompileTask* select_task(CompileQueue* compile_queue);
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   268
  // Tell the runtime if we think a given method is adequately profiled.
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11572
diff changeset
   269
  virtual bool is_mature(Method* method);
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   270
  // Initialize: set compiler thread count
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   271
  virtual void initialize();
50068
5201c9474ee7 8202711: Merge tiered compilation policies
redestad
parents: 49340
diff changeset
   272
  virtual bool should_not_inline(ciEnv* env, ciMethod* callee);
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   273
};
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
   274
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 38666
diff changeset
   275
#endif // TIERED
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 38666
diff changeset
   276
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
   277
#endif // SHARE_VM_RUNTIME_SIMPLETHRESHOLDPOLICY_HPP