hotspot/src/share/vm/runtime/simpleThresholdPolicy.hpp
author ysr
Tue, 16 Nov 2010 13:58:48 -0800
changeset 7384 71eebb634028
parent 6453 970dc585ab63
child 7397 5b173b4ca846
permissions -rw-r--r--
7000578: CMS: assert(SafepointSynchronize::is_at_safepoint()) failed: Else races are possible Summary: Weakened assert in onj_is_alive() to allow its use at initialization time when is_at_safepoint() normally reports false; added some related asserts to check order of is_init_completed() after Universe::is_fully_initialized(). Reviewed-by: jcoomes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
     1
/*
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
     2
 * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
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
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    25
class CompileTask;
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    26
class CompileQueue;
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    27
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    28
class SimpleThresholdPolicy : public CompilationPolicy {
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    29
  int _c1_count, _c2_count;
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    30
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    31
  // Check if the counter is big enough and set carry (effectively infinity).
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    32
  inline void set_carry_if_necessary(InvocationCounter *counter);
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    33
  // Set carry flags in the counters (in methodOop and MDO).
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    34
  inline void handle_counter_overflow(methodOop method);
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    35
  // Call and loop predicates determine whether a transition to a higher compilation
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    36
  // level should be performed (pointers to predicate functions are passed to common_TF().
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    37
  // Predicates also take compiler load into account.
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    38
  typedef bool (SimpleThresholdPolicy::*Predicate)(int i, int b, CompLevel cur_level);
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    39
  bool call_predicate(int i, int b, CompLevel cur_level);
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    40
  bool loop_predicate(int i, int b, CompLevel cur_level);
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    41
  // Common transition function. Given a predicate determines if a method should transition to another level.
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    42
  CompLevel common(Predicate p, methodOop method, CompLevel cur_level);
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    43
  // Transition functions.
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    44
  // call_event determines if a method should be compiled at a different
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    45
  // level with a regular invocation entry.
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    46
  CompLevel call_event(methodOop method, CompLevel cur_level);
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    47
  // loop_event checks if a method should be OSR compiled at a different
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    48
  // level.
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    49
  CompLevel loop_event(methodOop method, CompLevel cur_level);
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    50
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    51
protected:
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    52
  int c1_count() const     { return _c1_count; }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    53
  int c2_count() const     { return _c2_count; }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    54
  void set_c1_count(int x) { _c1_count = x;    }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    55
  void set_c2_count(int x) { _c2_count = x;    }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    56
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    57
  enum EventType { CALL, LOOP, COMPILE };
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    58
  void print_event(EventType type, methodHandle mh, methodHandle imh, int bci, CompLevel level);
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    59
  // Print policy-specific information if necessary
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    60
  virtual void print_specific(EventType type, methodHandle mh, methodHandle imh, int bci, CompLevel level) { }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    61
  // Check if the method can be compiled, change level if necessary
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    62
  void compile(methodHandle mh, int bci, CompLevel level, TRAPS);
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    63
  // Submit a given method for compilation
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    64
  virtual void submit_compile(methodHandle mh, int bci, CompLevel level, TRAPS);
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    65
  // Simple methods are as good being compiled with C1 as C2.
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    66
  // This function tells if it's such a function.
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    67
  inline bool is_trivial(methodOop method);
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    68
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    69
  // Predicate helpers are used by .*_predicate() methods as well as others.
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    70
  // They check the given counter values, multiplied by the scale against the thresholds.
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    71
  template<CompLevel level> static inline bool call_predicate_helper(int i, int b, double scale);
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    72
  template<CompLevel level> static inline bool loop_predicate_helper(int i, int b, double scale);
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    73
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    74
  // Get a compilation level for a given method.
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    75
  static CompLevel comp_level(methodOop method) {
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    76
    nmethod *nm = method->code();
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    77
    if (nm != NULL && nm->is_in_use()) {
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    78
      return (CompLevel)nm->comp_level();
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    79
    }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    80
    return CompLevel_none;
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    81
  }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    82
  virtual void method_invocation_event(methodHandle method, methodHandle inlinee,
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    83
                                       CompLevel level, TRAPS);
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    84
  virtual void method_back_branch_event(methodHandle method, methodHandle inlinee,
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    85
                                        int bci, CompLevel level, TRAPS);
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    86
public:
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    87
  SimpleThresholdPolicy() : _c1_count(0), _c2_count(0) { }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    88
  virtual int compiler_count(CompLevel comp_level) {
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    89
    if (is_c1_compile(comp_level)) return c1_count();
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    90
    if (is_c2_compile(comp_level)) return c2_count();
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    91
    return 0;
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    92
  }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    93
  virtual void do_safepoint_work() { }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    94
  virtual void delay_compilation(methodOop method) { }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    95
  virtual void disable_compilation(methodOop method) { }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    96
  // TODO: we should honour reprofiling requests in the future. Currently reprofiling
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    97
  // would happen but not to the extent we would ideally like.
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    98
  virtual void reprofile(ScopeDesc* trap_scope, bool is_osr) { }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    99
  virtual nmethod* event(methodHandle method, methodHandle inlinee,
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   100
                         int branch_bci, int bci, CompLevel comp_level, TRAPS);
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   101
  // Select task is called by CompileBroker. We should return a task or NULL.
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   102
  virtual CompileTask* select_task(CompileQueue* compile_queue);
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   103
  // Tell the runtime if we think a given method is adequately profiled.
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   104
  virtual bool is_mature(methodOop method);
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   105
  // Initialize: set compiler thread count
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   106
  virtual void initialize();
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   107
};