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