src/hotspot/share/runtime/simpleThresholdPolicy.hpp
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 46727 hotspot/src/share/vm/runtime/simpleThresholdPolicy.hpp@6e4a84748e2c
child 49340 4e82736053ae
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
     1
/*
46727
6e4a84748e2c 8183039: Re-examine methodHandle methods uninlined by 8144256
coleenp
parents: 42650
diff changeset
     2
 * Copyright (c) 2010, 2017, 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;
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    37
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    38
class SimpleThresholdPolicy : public CompilationPolicy {
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    39
  int _c1_count, _c2_count;
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    40
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    41
  // Check if the counter is big enough and set carry (effectively infinity).
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    42
  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
    43
  // 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
    44
  inline void handle_counter_overflow(Method* method);
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    45
  // Call and loop predicates determine whether a transition to a higher compilation
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    46
  // level should be performed (pointers to predicate functions are passed to common_TF().
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    47
  // 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
    48
  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
    49
  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
    50
  bool loop_predicate(int i, int b, CompLevel cur_level, Method* method);
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    51
  // 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
    52
  CompLevel common(Predicate p, Method* method, CompLevel cur_level);
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    53
  // Transition functions.
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    54
  // call_event determines if a method should be compiled at a different
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    55
  // 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
    56
  CompLevel call_event(Method* method, CompLevel cur_level, JavaThread* thread);
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    57
  // loop_event checks if a method should be OSR compiled at a different
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    58
  // level.
38666
5ff19807abd5 8152311: [JVMCI] allow JVMCI compiler to change the compilation policy for a method
dnsimon
parents: 38133
diff changeset
    59
  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
    60
  void print_counters(const char* prefix, const methodHandle& mh);
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    61
protected:
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    62
  int c1_count() const     { return _c1_count; }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    63
  int c2_count() const     { return _c2_count; }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    64
  void set_c1_count(int x) { _c1_count = x;    }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    65
  void set_c2_count(int x) { _c2_count = x;    }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    66
10014
a5c2141ee857 7057120: Tiered: Allow C1 to inline methods with loops
iveresov
parents: 9625
diff changeset
    67
  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
    68
  void print_event(EventType type, const methodHandle& mh, const methodHandle& imh, int bci, CompLevel level);
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    69
  // Print policy-specific information if necessary
46727
6e4a84748e2c 8183039: Re-examine methodHandle methods uninlined by 8144256
coleenp
parents: 42650
diff changeset
    70
  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
    71
  // 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
    72
  void compile(const methodHandle& mh, int bci, CompLevel level, JavaThread* thread);
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    73
  // Submit a given method for compilation
33593
60764a78fa5c 8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents: 28650
diff changeset
    74
  virtual void submit_compile(const methodHandle& mh, int bci, CompLevel level, JavaThread* thread);
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    75
  // Simple methods are as good being compiled with C1 as C2.
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    76
  // 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
    77
  inline bool is_trivial(Method* method);
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    78
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    79
  // Predicate helpers are used by .*_predicate() methods as well as others.
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    80
  // 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
    81
  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
    82
  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
    83
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    84
  // Get a compilation level for a given method.
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11572
diff changeset
    85
  static CompLevel comp_level(Method* method) {
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 33593
diff changeset
    86
    CompiledMethod *nm = method->code();
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    87
    if (nm != NULL && nm->is_in_use()) {
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    88
      return (CompLevel)nm->comp_level();
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    89
    }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    90
    return CompLevel_none;
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    91
  }
33593
60764a78fa5c 8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents: 28650
diff changeset
    92
  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
    93
                                       CompLevel level, CompiledMethod* nm, JavaThread* thread);
33593
60764a78fa5c 8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents: 28650
diff changeset
    94
  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
    95
                                        int bci, CompLevel level, CompiledMethod* nm, JavaThread* thread);
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    96
public:
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    97
  SimpleThresholdPolicy() : _c1_count(0), _c2_count(0) { }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    98
  virtual int compiler_count(CompLevel comp_level) {
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    99
    if (is_c1_compile(comp_level)) return c1_count();
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   100
    if (is_c2_compile(comp_level)) return c2_count();
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   101
    return 0;
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   102
  }
10250
0794cd144834 7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents: 10014
diff changeset
   103
  virtual CompLevel initial_compile_level() { return MIN2((CompLevel)TieredStopAtLevel, CompLevel_initial_compile); }
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   104
  virtual void do_safepoint_work() { }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11572
diff changeset
   105
  virtual void delay_compilation(Method* method) { }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11572
diff changeset
   106
  virtual void disable_compilation(Method* method) { }
8322
8f11ba61239f 7017434: Tiered needs to support reprofiling
iveresov
parents: 7397
diff changeset
   107
  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
   108
  virtual nmethod* event(const methodHandle& method, const methodHandle& inlinee,
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 33593
diff changeset
   109
                         int branch_bci, int bci, CompLevel comp_level, CompiledMethod* nm, JavaThread* thread);
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   110
  // Select task is called by CompileBroker. We should return a task or NULL.
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   111
  virtual CompileTask* select_task(CompileQueue* compile_queue);
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   112
  // 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
   113
  virtual bool is_mature(Method* method);
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   114
  // Initialize: set compiler thread count
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   115
  virtual void initialize();
10014
a5c2141ee857 7057120: Tiered: Allow C1 to inline methods with loops
iveresov
parents: 9625
diff changeset
   116
  virtual bool should_not_inline(ciEnv* env, ciMethod* callee) {
a5c2141ee857 7057120: Tiered: Allow C1 to inline methods with loops
iveresov
parents: 9625
diff changeset
   117
    return (env->comp_level() == CompLevel_limited_profile ||
a5c2141ee857 7057120: Tiered: Allow C1 to inline methods with loops
iveresov
parents: 9625
diff changeset
   118
            env->comp_level() == CompLevel_full_profile) &&
a5c2141ee857 7057120: Tiered: Allow C1 to inline methods with loops
iveresov
parents: 9625
diff changeset
   119
            callee->has_loops();
a5c2141ee857 7057120: Tiered: Allow C1 to inline methods with loops
iveresov
parents: 9625
diff changeset
   120
  }
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   121
};
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
   122
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 38666
diff changeset
   123
#endif // TIERED
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 38666
diff changeset
   124
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
   125
#endif // SHARE_VM_RUNTIME_SIMPLETHRESHOLDPOLICY_HPP