compilationPolicy.hpp 6.6 KB
Newer Older
D
duke 已提交
1
/*
2
 * Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
D
duke 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
19 20 21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
D
duke 已提交
22 23 24
 *
 */

25 26 27 28 29 30 31 32 33
#ifndef SHARE_VM_RUNTIME_COMPILATIONPOLICY_HPP
#define SHARE_VM_RUNTIME_COMPILATIONPOLICY_HPP

#include "code/nmethod.hpp"
#include "compiler/compileBroker.hpp"
#include "memory/allocation.hpp"
#include "runtime/vm_operations.hpp"
#include "utilities/growableArray.hpp"

D
duke 已提交
34 35 36
// The CompilationPolicy selects which method (if any) should be compiled.
// It also decides which methods must always be compiled (i.e., are never
// interpreted).
I
iveresov 已提交
37 38
class CompileTask;
class CompileQueue;
D
duke 已提交
39

Z
zgu 已提交
40
class CompilationPolicy : public CHeapObj<mtCompiler> {
D
duke 已提交
41 42 43 44 45
  static CompilationPolicy* _policy;
  // Accumulated time
  static elapsedTimer       _accumulated_time;

  static bool               _in_vm_startup;
I
iveresov 已提交
46
public:
D
duke 已提交
47 48
  static  void set_in_vm_startup(bool in_vm_startup) { _in_vm_startup = in_vm_startup; }
  static  void completed_vm_startup();
I
iveresov 已提交
49
  static  bool delay_compilation_during_startup()    { return _in_vm_startup; }
D
duke 已提交
50

I
iveresov 已提交
51 52 53 54
  // m must be compiled before executing it
  static bool must_be_compiled(methodHandle m, int comp_level = CompLevel_all);
  // m is allowed to be compiled
  static bool can_be_compiled(methodHandle m, int comp_level = CompLevel_all);
55 56
  // m is allowed to be osr compiled
  static bool can_be_osr_compiled(methodHandle m, int comp_level = CompLevel_all);
I
iveresov 已提交
57
  static bool is_compilation_enabled();
D
duke 已提交
58
  static void set_policy(CompilationPolicy* policy) { _policy = policy; }
I
iveresov 已提交
59
  static CompilationPolicy* policy()                { return _policy; }
D
duke 已提交
60 61 62 63

  // Profiling
  elapsedTimer* accumulated_time() { return &_accumulated_time; }
  void print_time() PRODUCT_RETURN;
64 65
  // Return initial compile level that is used with Xcomp
  virtual CompLevel initial_compile_level() = 0;
I
iveresov 已提交
66 67 68
  virtual int compiler_count(CompLevel comp_level) = 0;
  // main notification entry, return a pointer to an nmethod if the OSR is required,
  // returns NULL otherwise.
69
  virtual nmethod* event(methodHandle method, methodHandle inlinee, int branch_bci, int bci, CompLevel comp_level, nmethod* nm, JavaThread* thread) = 0;
I
iveresov 已提交
70 71 72 73 74 75
  // safepoint() is called at the end of the safepoint
  virtual void do_safepoint_work() = 0;
  // reprofile request
  virtual void reprofile(ScopeDesc* trap_scope, bool is_osr) = 0;
  // delay_compilation(method) can be called by any component of the runtime to notify the policy
  // that it's recommended to delay the complation of this method.
76
  virtual void delay_compilation(Method* method) = 0;
I
iveresov 已提交
77 78
  // disable_compilation() is called whenever the runtime decides to disable compilation of the
  // specified method.
79
  virtual void disable_compilation(Method* method) = 0;
I
iveresov 已提交
80 81 82 83
  // Select task is called by CompileBroker. The queue is guaranteed to have at least one
  // element and is locked. The function should select one and return it.
  virtual CompileTask* select_task(CompileQueue* compile_queue) = 0;
  // Tell the runtime if we think a given method is adequately profiled.
84
  virtual bool is_mature(Method* method) = 0;
I
iveresov 已提交
85 86
  // Do policy initialization
  virtual void initialize() = 0;
87
  virtual bool should_not_inline(ciEnv* env, ciMethod* method) { return false; }
I
iveresov 已提交
88 89 90 91 92 93 94 95 96 97 98 99 100
};

// A base class for baseline policies.
class NonTieredCompPolicy : public CompilationPolicy {
  int _compiler_count;
protected:
  static void trace_frequency_counter_overflow(methodHandle m, int branch_bci, int bci);
  static void trace_osr_request(methodHandle method, nmethod* osr, int bci);
  static void trace_osr_completion(nmethod* osr_nm);
  void reset_counter_for_invocation_event(methodHandle method);
  void reset_counter_for_back_branch_event(methodHandle method);
public:
  NonTieredCompPolicy() : _compiler_count(0) { }
101
  virtual CompLevel initial_compile_level() { return CompLevel_highest_tier; }
I
iveresov 已提交
102 103 104
  virtual int compiler_count(CompLevel comp_level);
  virtual void do_safepoint_work();
  virtual void reprofile(ScopeDesc* trap_scope, bool is_osr);
105 106 107
  virtual void delay_compilation(Method* method);
  virtual void disable_compilation(Method* method);
  virtual bool is_mature(Method* method);
I
iveresov 已提交
108 109
  virtual void initialize();
  virtual CompileTask* select_task(CompileQueue* compile_queue);
110 111 112
  virtual nmethod* event(methodHandle method, methodHandle inlinee, int branch_bci, int bci, CompLevel comp_level, nmethod* nm, JavaThread* thread);
  virtual void method_invocation_event(methodHandle m, JavaThread* thread) = 0;
  virtual void method_back_branch_event(methodHandle m, int bci, JavaThread* thread) = 0;
D
duke 已提交
113 114
};

I
iveresov 已提交
115
class SimpleCompPolicy : public NonTieredCompPolicy {
D
duke 已提交
116
 public:
117 118
  virtual void method_invocation_event(methodHandle m, JavaThread* thread);
  virtual void method_back_branch_event(methodHandle m, int bci, JavaThread* thread);
D
duke 已提交
119 120 121 122 123
};

// StackWalkCompPolicy - existing C2 policy

#ifdef COMPILER2
I
iveresov 已提交
124
class StackWalkCompPolicy : public NonTieredCompPolicy {
D
duke 已提交
125
 public:
126 127
  virtual void method_invocation_event(methodHandle m, JavaThread* thread);
  virtual void method_back_branch_event(methodHandle m, int bci, JavaThread* thread);
D
duke 已提交
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143

 private:
  RFrame* findTopInlinableFrame(GrowableArray<RFrame*>* stack);
  RFrame* senderOf(RFrame* rf, GrowableArray<RFrame*>* stack);

  // the following variables hold values computed by the last inlining decision
  // they are used for performance debugging only (print better messages)
  static const char* _msg;            // reason for not inlining

  static const char* shouldInline   (methodHandle callee, float frequency, int cnt);
  // positive filter: should send be inlined?  returns NULL (--> yes) or rejection msg
  static const char* shouldNotInline(methodHandle callee);
  // negative filter: should send NOT be inlined?  returns NULL (--> inline) or rejection msg

};
#endif
144 145

#endif // SHARE_VM_RUNTIME_COMPILATIONPOLICY_HPP