hotspot/src/share/vm/runtime/advancedThresholdPolicy.hpp
author pliden
Fri, 11 Apr 2014 12:29:24 +0200
changeset 24094 5dbf1f44de18
parent 22234 da823d78ad65
child 28650 772aaab2582f
permissions -rw-r--r--
8039147: Cleanup SuspendibleThreadSet Reviewed-by: brutisso, tschatzl, mgerdin
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8667
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
     1
/*
22234
da823d78ad65 8029233: Update copyright year to match last edit in jdk8 hotspot repository for 2013
mikael
parents: 17617
diff changeset
     2
 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
9625
822a93889b58 7043564: compile warning and copyright fixes
iveresov
parents: 8667
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
822a93889b58 7043564: compile warning and copyright fixes
iveresov
parents: 8667
diff changeset
     4
 *
822a93889b58 7043564: compile warning and copyright fixes
iveresov
parents: 8667
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
822a93889b58 7043564: compile warning and copyright fixes
iveresov
parents: 8667
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
822a93889b58 7043564: compile warning and copyright fixes
iveresov
parents: 8667
diff changeset
     7
 * published by the Free Software Foundation.
822a93889b58 7043564: compile warning and copyright fixes
iveresov
parents: 8667
diff changeset
     8
 *
822a93889b58 7043564: compile warning and copyright fixes
iveresov
parents: 8667
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
822a93889b58 7043564: compile warning and copyright fixes
iveresov
parents: 8667
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
822a93889b58 7043564: compile warning and copyright fixes
iveresov
parents: 8667
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
822a93889b58 7043564: compile warning and copyright fixes
iveresov
parents: 8667
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
822a93889b58 7043564: compile warning and copyright fixes
iveresov
parents: 8667
diff changeset
    13
 * accompanied this code).
822a93889b58 7043564: compile warning and copyright fixes
iveresov
parents: 8667
diff changeset
    14
 *
822a93889b58 7043564: compile warning and copyright fixes
iveresov
parents: 8667
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
822a93889b58 7043564: compile warning and copyright fixes
iveresov
parents: 8667
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
822a93889b58 7043564: compile warning and copyright fixes
iveresov
parents: 8667
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
822a93889b58 7043564: compile warning and copyright fixes
iveresov
parents: 8667
diff changeset
    18
 *
822a93889b58 7043564: compile warning and copyright fixes
iveresov
parents: 8667
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
822a93889b58 7043564: compile warning and copyright fixes
iveresov
parents: 8667
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
822a93889b58 7043564: compile warning and copyright fixes
iveresov
parents: 8667
diff changeset
    21
 * questions.
822a93889b58 7043564: compile warning and copyright fixes
iveresov
parents: 8667
diff changeset
    22
 *
822a93889b58 7043564: compile warning and copyright fixes
iveresov
parents: 8667
diff changeset
    23
 */
8667
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
    24
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
    25
#ifndef SHARE_VM_RUNTIME_ADVANCEDTHRESHOLDPOLICY_HPP
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
    26
#define SHARE_VM_RUNTIME_ADVANCEDTHRESHOLDPOLICY_HPP
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
    27
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
    28
#include "runtime/simpleThresholdPolicy.hpp"
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
    29
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
    30
#ifdef TIERED
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
    31
class CompileTask;
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
    32
class CompileQueue;
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
    33
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
    34
/*
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
    35
 *  The system supports 5 execution levels:
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
    36
 *  * level 0 - interpreter
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
    37
 *  * level 1 - C1 with full optimization (no profiling)
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
    38
 *  * level 2 - C1 with invocation and backedge counters
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
    39
 *  * level 3 - C1 with full profiling (level 2 + MDO)
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
    40
 *  * level 4 - C2
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
    41
 *
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
    42
 * Levels 0, 2 and 3 periodically notify the runtime about the current value of the counters
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
    43
 * (invocation counters and backedge counters). The frequency of these notifications is
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
    44
 * different at each level. These notifications are used by the policy to decide what transition
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
    45
 * to make.
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
    46
 *
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
    47
 * Execution starts at level 0 (interpreter), then the policy can decide either to compile the
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
    48
 * method at level 3 or level 2. The decision is based on the following factors:
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
    49
 *    1. The length of the C2 queue determines the next level. The observation is that level 2
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
    50
 * is generally faster than level 3 by about 30%, therefore we would want to minimize the time
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
    51
 * a method spends at level 3. We should only spend the time at level 3 that is necessary to get
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
    52
 * adequate profiling. So, if the C2 queue is long enough it is more beneficial to go first to
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
    53
 * level 2, because if we transitioned to level 3 we would be stuck there until our C2 compile
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
    54
 * request makes its way through the long queue. When the load on C2 recedes we are going to
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
    55
 * recompile at level 3 and start gathering profiling information.
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
    56
 *    2. The length of C1 queue is used to dynamically adjust the thresholds, so as to introduce
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
    57
 * additional filtering if the compiler is overloaded. The rationale is that by the time a
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
    58
 * method gets compiled it can become unused, so it doesn't make sense to put too much onto the
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
    59
 * queue.
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
    60
 *
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
    61
 * After profiling is completed at level 3 the transition is made to level 4. Again, the length
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
    62
 * of the C2 queue is used as a feedback to adjust the thresholds.
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
    63
 *
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
    64
 * After the first C1 compile some basic information is determined about the code like the number
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
    65
 * of the blocks and the number of the loops. Based on that it can be decided that a method
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
    66
 * is trivial and compiling it with C1 will yield the same code. In this case the method is
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
    67
 * compiled at level 1 instead of 4.
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
    68
 *
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
    69
 * We also support profiling at level 0. If C1 is slow enough to produce the level 3 version of
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
    70
 * the code and the C2 queue is sufficiently small we can decide to start profiling in the
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
    71
 * interpreter (and continue profiling in the compiled code once the level 3 version arrives).
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
    72
 * If the profiling at level 0 is fully completed before level 3 version is produced, a level 2
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
    73
 * version is compiled instead in order to run faster waiting for a level 4 version.
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
    74
 *
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
    75
 * Compile queues are implemented as priority queues - for each method in the queue we compute
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
    76
 * the event rate (the number of invocation and backedge counter increments per unit of time).
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
    77
 * When getting an element off the queue we pick the one with the largest rate. Maintaining the
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
    78
 * rate also allows us to remove stale methods (the ones that got on the queue but stopped
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
    79
 * being used shortly after that).
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
    80
*/
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
    81
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
    82
/* Command line options:
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
    83
 * - Tier?InvokeNotifyFreqLog and Tier?BackedgeNotifyFreqLog control the frequency of method
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
    84
 *   invocation and backedge notifications. Basically every n-th invocation or backedge a mutator thread
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
    85
 *   makes a call into the runtime.
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
    86
 *
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
    87
 * - Tier?CompileThreshold, Tier?BackEdgeThreshold, Tier?MinInvocationThreshold control
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
    88
 *   compilation thresholds.
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
    89
 *   Level 2 thresholds are not used and are provided for option-compatibility and potential future use.
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
    90
 *   Other thresholds work as follows:
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
    91
 *
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
    92
 *   Transition from interpreter (level 0) to C1 with full profiling (level 3) happens when
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
    93
 *   the following predicate is true (X is the level):
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
    94
 *
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
    95
 *   i > TierXInvocationThreshold * s || (i > TierXMinInvocationThreshold * s  && i + b > TierXCompileThreshold * s),
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
    96
 *
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
    97
 *   where $i$ is the number of method invocations, $b$ number of backedges and $s$ is the scaling
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
    98
 *   coefficient that will be discussed further.
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
    99
 *   The intuition is to equalize the time that is spend profiling each method.
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   100
 *   The same predicate is used to control the transition from level 3 to level 4 (C2). It should be
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   101
 *   noted though that the thresholds are relative. Moreover i and b for the 0->3 transition come
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11572
diff changeset
   102
 *   from Method* and for 3->4 transition they come from MDO (since profiled invocations are
8667
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   103
 *   counted separately).
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   104
 *
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   105
 *   OSR transitions are controlled simply with b > TierXBackEdgeThreshold * s predicates.
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   106
 *
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   107
 * - Tier?LoadFeedback options are used to automatically scale the predicates described above depending
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   108
 *   on the compiler load. The scaling coefficients are computed as follows:
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   109
 *
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   110
 *   s = queue_size_X / (TierXLoadFeedback * compiler_count_X) + 1,
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   111
 *
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   112
 *   where queue_size_X is the current size of the compiler queue of level X, and compiler_count_X
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   113
 *   is the number of level X compiler threads.
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   114
 *
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   115
 *   Basically these parameters describe how many methods should be in the compile queue
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   116
 *   per compiler thread before the scaling coefficient increases by one.
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   117
 *
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   118
 *   This feedback provides the mechanism to automatically control the flow of compilation requests
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   119
 *   depending on the machine speed, mutator load and other external factors.
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   120
 *
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   121
 * - Tier3DelayOn and Tier3DelayOff parameters control another important feedback loop.
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   122
 *   Consider the following observation: a method compiled with full profiling (level 3)
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   123
 *   is about 30% slower than a method at level 2 (just invocation and backedge counters, no MDO).
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   124
 *   Normally, the following transitions will occur: 0->3->4. The problem arises when the C2 queue
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   125
 *   gets congested and the 3->4 transition is delayed. While the method is the C2 queue it continues
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   126
 *   executing at level 3 for much longer time than is required by the predicate and at suboptimal speed.
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   127
 *   The idea is to dynamically change the behavior of the system in such a way that if a substantial
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   128
 *   load on C2 is detected we would first do the 0->2 transition allowing a method to run faster.
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   129
 *   And then when the load decreases to allow 2->3 transitions.
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   130
 *
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   131
 *   Tier3Delay* parameters control this switching mechanism.
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   132
 *   Tier3DelayOn is the number of methods in the C2 queue per compiler thread after which the policy
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   133
 *   no longer does 0->3 transitions but does 0->2 transitions instead.
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   134
 *   Tier3DelayOff switches the original behavior back when the number of methods in the C2 queue
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   135
 *   per compiler thread falls below the specified amount.
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   136
 *   The hysteresis is necessary to avoid jitter.
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   137
 *
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   138
 * - TieredCompileTaskTimeout is the amount of time an idle method can spend in the compile queue.
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   139
 *   Basically, since we use the event rate d(i + b)/dt as a value of priority when selecting a method to
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   140
 *   compile from the compile queue, we also can detect stale methods for which the rate has been
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   141
 *   0 for some time in the same iteration. Stale methods can appear in the queue when an application
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   142
 *   abruptly changes its behavior.
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   143
 *
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   144
 * - TieredStopAtLevel, is used mostly for testing. It allows to bypass the policy logic and stick
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   145
 *   to a given level. For example it's useful to set TieredStopAtLevel = 1 in order to compile everything
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   146
 *   with pure c1.
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   147
 *
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   148
 * - Tier0ProfilingStartPercentage allows the interpreter to start profiling when the inequalities in the
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   149
 *   0->3 predicate are already exceeded by the given percentage but the level 3 version of the
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   150
 *   method is still not ready. We can even go directly from level 0 to 4 if c1 doesn't produce a compiled
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   151
 *   version in time. This reduces the overall transition to level 4 and decreases the startup time.
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   152
 *   Note that this behavior is also guarded by the Tier3Delay mechanism: when the c2 queue is too long
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   153
 *   these is not reason to start profiling prematurely.
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   154
 *
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   155
 * - TieredRateUpdateMinTime and TieredRateUpdateMaxTime are parameters of the rate computation.
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   156
 *   Basically, the rate is not computed more frequently than TieredRateUpdateMinTime and is considered
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   157
 *   to be zero if no events occurred in TieredRateUpdateMaxTime.
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   158
 */
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   159
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   160
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   161
class AdvancedThresholdPolicy : public SimpleThresholdPolicy {
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   162
  jlong _start_time;
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   163
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   164
  // Call and loop predicates determine whether a transition to a higher compilation
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   165
  // level should be performed (pointers to predicate functions are passed to common().
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   166
  // Predicates also take compiler load into account.
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   167
  typedef bool (AdvancedThresholdPolicy::*Predicate)(int i, int b, CompLevel cur_level);
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   168
  bool call_predicate(int i, int b, CompLevel cur_level);
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   169
  bool loop_predicate(int i, int b, CompLevel cur_level);
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   170
  // Common transition function. Given a predicate determines if a method should transition to another level.
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11572
diff changeset
   171
  CompLevel common(Predicate p, Method* method, CompLevel cur_level, bool disable_feedback = false);
8667
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   172
  // Transition functions.
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   173
  // call_event determines if a method should be compiled at a different
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   174
  // level with a regular invocation entry.
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11572
diff changeset
   175
  CompLevel call_event(Method* method, CompLevel cur_level);
8667
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   176
  // loop_event checks if a method should be OSR compiled at a different
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   177
  // level.
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11572
diff changeset
   178
  CompLevel loop_event(Method* method, CompLevel cur_level);
8667
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   179
  // Has a method been long around?
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   180
  // We don't remove old methods from the compile queue even if they have
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   181
  // very low activity (see select_task()).
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11572
diff changeset
   182
  inline bool is_old(Method* method);
8667
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   183
  // Was a given method inactive for a given number of milliseconds.
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   184
  // If it is, we would remove it from the queue (see select_task()).
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11572
diff changeset
   185
  inline bool is_stale(jlong t, jlong timeout, Method* m);
8667
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   186
  // Compute the weight of the method for the compilation scheduling
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11572
diff changeset
   187
  inline double weight(Method* method);
8667
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   188
  // Apply heuristics and return true if x should be compiled before y
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11572
diff changeset
   189
  inline bool compare_methods(Method* x, Method* y);
8667
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   190
  // Compute event rate for a given method. The rate is the number of event (invocations + backedges)
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   191
  // per millisecond.
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11572
diff changeset
   192
  inline void update_rate(jlong t, Method* m);
8667
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   193
  // Compute threshold scaling coefficient
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   194
  inline double threshold_scale(CompLevel level, int feedback_k);
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   195
  // If a method is old enough and is still in the interpreter we would want to
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   196
  // start profiling without waiting for the compiled method to arrive. This function
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   197
  // determines whether we should do that.
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11572
diff changeset
   198
  inline bool should_create_mdo(Method* method, CompLevel cur_level);
8667
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   199
  // Create MDO if necessary.
11572
84afef481892 7131259: compile_method and CompilationPolicy::event shouldn't be declared TRAPS
iveresov
parents: 10250
diff changeset
   200
  void create_mdo(methodHandle mh, JavaThread* thread);
8667
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   201
  // Is method profiled enough?
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11572
diff changeset
   202
  bool is_method_profiled(Method* method);
8667
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   203
17617
4e330bce1812 8012371: Adjust Tiered compile threshold according to available space in code cache
anoll
parents: 13728
diff changeset
   204
  double _increase_threshold_at_ratio;
4e330bce1812 8012371: Adjust Tiered compile threshold according to available space in code cache
anoll
parents: 13728
diff changeset
   205
8667
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   206
protected:
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   207
  void print_specific(EventType type, methodHandle mh, methodHandle imh, int bci, CompLevel level);
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   208
17617
4e330bce1812 8012371: Adjust Tiered compile threshold according to available space in code cache
anoll
parents: 13728
diff changeset
   209
  void set_increase_threshold_at_ratio() { _increase_threshold_at_ratio = 100 / (100 - (double)IncreaseFirstTierCompileThresholdAt); }
8667
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   210
  void set_start_time(jlong t) { _start_time = t;    }
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   211
  jlong start_time() const     { return _start_time; }
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   212
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   213
  // Submit a given method for compilation (and update the rate).
11572
84afef481892 7131259: compile_method and CompilationPolicy::event shouldn't be declared TRAPS
iveresov
parents: 10250
diff changeset
   214
  virtual void submit_compile(methodHandle mh, int bci, CompLevel level, JavaThread* thread);
8667
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   215
  // event() from SimpleThresholdPolicy would call these.
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   216
  virtual void method_invocation_event(methodHandle method, methodHandle inlinee,
11572
84afef481892 7131259: compile_method and CompilationPolicy::event shouldn't be declared TRAPS
iveresov
parents: 10250
diff changeset
   217
                                       CompLevel level, nmethod* nm, JavaThread* thread);
8667
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   218
  virtual void method_back_branch_event(methodHandle method, methodHandle inlinee,
11572
84afef481892 7131259: compile_method and CompilationPolicy::event shouldn't be declared TRAPS
iveresov
parents: 10250
diff changeset
   219
                                        int bci, CompLevel level, nmethod* nm, JavaThread* thread);
8667
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   220
public:
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   221
  AdvancedThresholdPolicy() : _start_time(0) { }
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   222
  // Select task is called by CompileBroker. We should return a task or NULL.
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   223
  virtual CompileTask* select_task(CompileQueue* compile_queue);
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   224
  virtual void initialize();
10014
a5c2141ee857 7057120: Tiered: Allow C1 to inline methods with loops
iveresov
parents: 9625
diff changeset
   225
  virtual bool should_not_inline(ciEnv* env, ciMethod* callee);
a5c2141ee857 7057120: Tiered: Allow C1 to inline methods with loops
iveresov
parents: 9625
diff changeset
   226
8667
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   227
};
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   228
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   229
#endif // TIERED
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   230
b32929355d27 7020403: Add AdvancedCompilationPolicy for tiered
iveresov
parents:
diff changeset
   231
#endif // SHARE_VM_RUNTIME_ADVANCEDTHRESHOLDPOLICY_HPP