hotspot/src/share/vm/runtime/compilationPolicy.hpp
author iveresov
Fri, 01 Jul 2011 10:37:37 -0700
changeset 10014 a5c2141ee857
parent 7397 5b173b4ca846
child 10250 0794cd144834
permissions -rw-r--r--
7057120: Tiered: Allow C1 to inline methods with loops Summary: Recompile the enclosing methods without inlining of the method that has OSRed to level 4 or recompile the enclosing method at level 4. Reviewed-by: kvn, never
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5547
diff changeset
     2
 * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    25
#ifndef SHARE_VM_RUNTIME_COMPILATIONPOLICY_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    26
#define SHARE_VM_RUNTIME_COMPILATIONPOLICY_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"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    29
#include "compiler/compileBroker.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    30
#include "memory/allocation.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    31
#include "runtime/vm_operations.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    32
#include "utilities/growableArray.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    33
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
// The CompilationPolicy selects which method (if any) should be compiled.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
// It also decides which methods must always be compiled (i.e., are never
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
// interpreted).
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5547
diff changeset
    37
class CompileTask;
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5547
diff changeset
    38
class CompileQueue;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
class CompilationPolicy : public CHeapObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  static CompilationPolicy* _policy;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  // Accumulated time
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  static elapsedTimer       _accumulated_time;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  static bool               _in_vm_startup;
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5547
diff changeset
    46
public:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  static  void set_in_vm_startup(bool in_vm_startup) { _in_vm_startup = in_vm_startup; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  static  void completed_vm_startup();
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5547
diff changeset
    49
  static  bool delay_compilation_during_startup()    { return _in_vm_startup; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5547
diff changeset
    51
  // m must be compiled before executing it
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5547
diff changeset
    52
  static bool must_be_compiled(methodHandle m, int comp_level = CompLevel_all);
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5547
diff changeset
    53
  // m is allowed to be compiled
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5547
diff changeset
    54
  static bool can_be_compiled(methodHandle m, int comp_level = CompLevel_all);
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5547
diff changeset
    55
  static bool is_compilation_enabled();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  static void set_policy(CompilationPolicy* policy) { _policy = policy; }
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5547
diff changeset
    57
  static CompilationPolicy* policy()                { return _policy; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  // Profiling
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  elapsedTimer* accumulated_time() { return &_accumulated_time; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  void print_time() PRODUCT_RETURN;
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5547
diff changeset
    62
  virtual int compiler_count(CompLevel comp_level) = 0;
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5547
diff changeset
    63
  // main notification entry, return a pointer to an nmethod if the OSR is required,
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5547
diff changeset
    64
  // returns NULL otherwise.
10014
a5c2141ee857 7057120: Tiered: Allow C1 to inline methods with loops
iveresov
parents: 7397
diff changeset
    65
  virtual nmethod* event(methodHandle method, methodHandle inlinee, int branch_bci, int bci, CompLevel comp_level, nmethod* nm, TRAPS) = 0;
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5547
diff changeset
    66
  // safepoint() is called at the end of the safepoint
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5547
diff changeset
    67
  virtual void do_safepoint_work() = 0;
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5547
diff changeset
    68
  // reprofile request
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5547
diff changeset
    69
  virtual void reprofile(ScopeDesc* trap_scope, bool is_osr) = 0;
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5547
diff changeset
    70
  // delay_compilation(method) can be called by any component of the runtime to notify the policy
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5547
diff changeset
    71
  // that it's recommended to delay the complation of this method.
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5547
diff changeset
    72
  virtual void delay_compilation(methodOop method) = 0;
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5547
diff changeset
    73
  // disable_compilation() is called whenever the runtime decides to disable compilation of the
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5547
diff changeset
    74
  // specified method.
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5547
diff changeset
    75
  virtual void disable_compilation(methodOop method) = 0;
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5547
diff changeset
    76
  // Select task is called by CompileBroker. The queue is guaranteed to have at least one
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5547
diff changeset
    77
  // element and is locked. The function should select one and return it.
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5547
diff changeset
    78
  virtual CompileTask* select_task(CompileQueue* compile_queue) = 0;
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5547
diff changeset
    79
  // Tell the runtime if we think a given method is adequately profiled.
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5547
diff changeset
    80
  virtual bool is_mature(methodOop method) = 0;
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5547
diff changeset
    81
  // Do policy initialization
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5547
diff changeset
    82
  virtual void initialize() = 0;
10014
a5c2141ee857 7057120: Tiered: Allow C1 to inline methods with loops
iveresov
parents: 7397
diff changeset
    83
  virtual bool should_not_inline(ciEnv* env, ciMethod* method) { return false; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5547
diff changeset
    86
// A base class for baseline policies.
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5547
diff changeset
    87
class NonTieredCompPolicy : public CompilationPolicy {
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5547
diff changeset
    88
  int _compiler_count;
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5547
diff changeset
    89
protected:
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5547
diff changeset
    90
  static void trace_frequency_counter_overflow(methodHandle m, int branch_bci, int bci);
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5547
diff changeset
    91
  static void trace_osr_request(methodHandle method, nmethod* osr, int bci);
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5547
diff changeset
    92
  static void trace_osr_completion(nmethod* osr_nm);
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5547
diff changeset
    93
  void reset_counter_for_invocation_event(methodHandle method);
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5547
diff changeset
    94
  void reset_counter_for_back_branch_event(methodHandle method);
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5547
diff changeset
    95
public:
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5547
diff changeset
    96
  NonTieredCompPolicy() : _compiler_count(0) { }
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5547
diff changeset
    97
  virtual int compiler_count(CompLevel comp_level);
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5547
diff changeset
    98
  virtual void do_safepoint_work();
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5547
diff changeset
    99
  virtual void reprofile(ScopeDesc* trap_scope, bool is_osr);
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5547
diff changeset
   100
  virtual void delay_compilation(methodOop method);
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5547
diff changeset
   101
  virtual void disable_compilation(methodOop method);
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5547
diff changeset
   102
  virtual bool is_mature(methodOop method);
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5547
diff changeset
   103
  virtual void initialize();
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5547
diff changeset
   104
  virtual CompileTask* select_task(CompileQueue* compile_queue);
10014
a5c2141ee857 7057120: Tiered: Allow C1 to inline methods with loops
iveresov
parents: 7397
diff changeset
   105
  virtual nmethod* event(methodHandle method, methodHandle inlinee, int branch_bci, int bci, CompLevel comp_level, nmethod* nm, TRAPS);
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5547
diff changeset
   106
  virtual void method_invocation_event(methodHandle m, TRAPS) = 0;
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5547
diff changeset
   107
  virtual void method_back_branch_event(methodHandle m, int bci, TRAPS) = 0;
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5547
diff changeset
   108
};
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5547
diff changeset
   109
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5547
diff changeset
   110
class SimpleCompPolicy : public NonTieredCompPolicy {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
 public:
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5547
diff changeset
   112
  virtual void method_invocation_event(methodHandle m, TRAPS);
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5547
diff changeset
   113
  virtual void method_back_branch_event(methodHandle m, int bci, TRAPS);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
// StackWalkCompPolicy - existing C2 policy
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
#ifdef COMPILER2
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5547
diff changeset
   119
class StackWalkCompPolicy : public NonTieredCompPolicy {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
 public:
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5547
diff changeset
   121
  virtual void method_invocation_event(methodHandle m, TRAPS);
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5547
diff changeset
   122
  virtual void method_back_branch_event(methodHandle m, int bci, TRAPS);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  RFrame* findTopInlinableFrame(GrowableArray<RFrame*>* stack);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  RFrame* senderOf(RFrame* rf, GrowableArray<RFrame*>* stack);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  // the following variables hold values computed by the last inlining decision
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  // they are used for performance debugging only (print better messages)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  static const char* _msg;            // reason for not inlining
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  static const char* shouldInline   (methodHandle callee, float frequency, int cnt);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  // positive filter: should send be inlined?  returns NULL (--> yes) or rejection msg
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  static const char* shouldNotInline(methodHandle callee);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  // negative filter: should send NOT be inlined?  returns NULL (--> inline) or rejection msg
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
#endif
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
   139
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
   140
#endif // SHARE_VM_RUNTIME_COMPILATIONPOLICY_HPP