src/share/vm/runtime/compilationPolicy.hpp

Tue, 05 Nov 2013 17:38:04 -0800

author
kvn
date
Tue, 05 Nov 2013 17:38:04 -0800
changeset 6472
2b8e28fdf503
parent 5541
f99558245e5c
child 6198
55fb97c4c58d
permissions
-rw-r--r--

Merge

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

mercurial