src/share/vm/runtime/compilationPolicy.hpp

Fri, 01 Jul 2011 10:37:37 -0700

author
iveresov
date
Fri, 01 Jul 2011 10:37:37 -0700
changeset 2988
2c359f27615c
parent 2314
f95d63e2154a
child 3035
43f9d800f276
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

duke@435 1 /*
iveresov@2138 2 * Copyright (c) 2000, 2010, 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
duke@435 40 class CompilationPolicy : public CHeapObj {
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);
iveresov@2138 55 static bool is_compilation_enabled();
duke@435 56 static void set_policy(CompilationPolicy* policy) { _policy = policy; }
iveresov@2138 57 static CompilationPolicy* policy() { return _policy; }
duke@435 58
duke@435 59 // Profiling
duke@435 60 elapsedTimer* accumulated_time() { return &_accumulated_time; }
duke@435 61 void print_time() PRODUCT_RETURN;
iveresov@2138 62 virtual int compiler_count(CompLevel comp_level) = 0;
iveresov@2138 63 // main notification entry, return a pointer to an nmethod if the OSR is required,
iveresov@2138 64 // returns NULL otherwise.
iveresov@2988 65 virtual nmethod* event(methodHandle method, methodHandle inlinee, int branch_bci, int bci, CompLevel comp_level, nmethod* nm, TRAPS) = 0;
iveresov@2138 66 // safepoint() is called at the end of the safepoint
iveresov@2138 67 virtual void do_safepoint_work() = 0;
iveresov@2138 68 // reprofile request
iveresov@2138 69 virtual void reprofile(ScopeDesc* trap_scope, bool is_osr) = 0;
iveresov@2138 70 // delay_compilation(method) can be called by any component of the runtime to notify the policy
iveresov@2138 71 // that it's recommended to delay the complation of this method.
iveresov@2138 72 virtual void delay_compilation(methodOop method) = 0;
iveresov@2138 73 // disable_compilation() is called whenever the runtime decides to disable compilation of the
iveresov@2138 74 // specified method.
iveresov@2138 75 virtual void disable_compilation(methodOop method) = 0;
iveresov@2138 76 // Select task is called by CompileBroker. The queue is guaranteed to have at least one
iveresov@2138 77 // element and is locked. The function should select one and return it.
iveresov@2138 78 virtual CompileTask* select_task(CompileQueue* compile_queue) = 0;
iveresov@2138 79 // Tell the runtime if we think a given method is adequately profiled.
iveresov@2138 80 virtual bool is_mature(methodOop method) = 0;
iveresov@2138 81 // Do policy initialization
iveresov@2138 82 virtual void initialize() = 0;
iveresov@2988 83 virtual bool should_not_inline(ciEnv* env, ciMethod* method) { return false; }
duke@435 84 };
duke@435 85
iveresov@2138 86 // A base class for baseline policies.
iveresov@2138 87 class NonTieredCompPolicy : public CompilationPolicy {
iveresov@2138 88 int _compiler_count;
iveresov@2138 89 protected:
iveresov@2138 90 static void trace_frequency_counter_overflow(methodHandle m, int branch_bci, int bci);
iveresov@2138 91 static void trace_osr_request(methodHandle method, nmethod* osr, int bci);
iveresov@2138 92 static void trace_osr_completion(nmethod* osr_nm);
iveresov@2138 93 void reset_counter_for_invocation_event(methodHandle method);
iveresov@2138 94 void reset_counter_for_back_branch_event(methodHandle method);
iveresov@2138 95 public:
iveresov@2138 96 NonTieredCompPolicy() : _compiler_count(0) { }
iveresov@2138 97 virtual int compiler_count(CompLevel comp_level);
iveresov@2138 98 virtual void do_safepoint_work();
iveresov@2138 99 virtual void reprofile(ScopeDesc* trap_scope, bool is_osr);
iveresov@2138 100 virtual void delay_compilation(methodOop method);
iveresov@2138 101 virtual void disable_compilation(methodOop method);
iveresov@2138 102 virtual bool is_mature(methodOop method);
iveresov@2138 103 virtual void initialize();
iveresov@2138 104 virtual CompileTask* select_task(CompileQueue* compile_queue);
iveresov@2988 105 virtual nmethod* event(methodHandle method, methodHandle inlinee, int branch_bci, int bci, CompLevel comp_level, nmethod* nm, TRAPS);
iveresov@2138 106 virtual void method_invocation_event(methodHandle m, TRAPS) = 0;
iveresov@2138 107 virtual void method_back_branch_event(methodHandle m, int bci, TRAPS) = 0;
iveresov@2138 108 };
iveresov@2138 109
iveresov@2138 110 class SimpleCompPolicy : public NonTieredCompPolicy {
duke@435 111 public:
iveresov@2138 112 virtual void method_invocation_event(methodHandle m, TRAPS);
iveresov@2138 113 virtual void method_back_branch_event(methodHandle m, int bci, TRAPS);
duke@435 114 };
duke@435 115
duke@435 116 // StackWalkCompPolicy - existing C2 policy
duke@435 117
duke@435 118 #ifdef COMPILER2
iveresov@2138 119 class StackWalkCompPolicy : public NonTieredCompPolicy {
duke@435 120 public:
iveresov@2138 121 virtual void method_invocation_event(methodHandle m, TRAPS);
iveresov@2138 122 virtual void method_back_branch_event(methodHandle m, int bci, TRAPS);
duke@435 123
duke@435 124 private:
duke@435 125 RFrame* findTopInlinableFrame(GrowableArray<RFrame*>* stack);
duke@435 126 RFrame* senderOf(RFrame* rf, GrowableArray<RFrame*>* stack);
duke@435 127
duke@435 128 // the following variables hold values computed by the last inlining decision
duke@435 129 // they are used for performance debugging only (print better messages)
duke@435 130 static const char* _msg; // reason for not inlining
duke@435 131
duke@435 132 static const char* shouldInline (methodHandle callee, float frequency, int cnt);
duke@435 133 // positive filter: should send be inlined? returns NULL (--> yes) or rejection msg
duke@435 134 static const char* shouldNotInline(methodHandle callee);
duke@435 135 // negative filter: should send NOT be inlined? returns NULL (--> inline) or rejection msg
duke@435 136
duke@435 137 };
duke@435 138 #endif
stefank@2314 139
stefank@2314 140 #endif // SHARE_VM_RUNTIME_COMPILATIONPOLICY_HPP

mercurial