1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/runtime/compilationPolicy.hpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,145 @@ 1.4 +/* 1.5 + * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +#ifndef SHARE_VM_RUNTIME_COMPILATIONPOLICY_HPP 1.29 +#define SHARE_VM_RUNTIME_COMPILATIONPOLICY_HPP 1.30 + 1.31 +#include "code/nmethod.hpp" 1.32 +#include "compiler/compileBroker.hpp" 1.33 +#include "memory/allocation.hpp" 1.34 +#include "runtime/vm_operations.hpp" 1.35 +#include "utilities/growableArray.hpp" 1.36 + 1.37 +// The CompilationPolicy selects which method (if any) should be compiled. 1.38 +// It also decides which methods must always be compiled (i.e., are never 1.39 +// interpreted). 1.40 +class CompileTask; 1.41 +class CompileQueue; 1.42 + 1.43 +class CompilationPolicy : public CHeapObj<mtCompiler> { 1.44 + static CompilationPolicy* _policy; 1.45 + // Accumulated time 1.46 + static elapsedTimer _accumulated_time; 1.47 + 1.48 + static bool _in_vm_startup; 1.49 +public: 1.50 + static void set_in_vm_startup(bool in_vm_startup) { _in_vm_startup = in_vm_startup; } 1.51 + static void completed_vm_startup(); 1.52 + static bool delay_compilation_during_startup() { return _in_vm_startup; } 1.53 + 1.54 + // m must be compiled before executing it 1.55 + static bool must_be_compiled(methodHandle m, int comp_level = CompLevel_all); 1.56 + // m is allowed to be compiled 1.57 + static bool can_be_compiled(methodHandle m, int comp_level = CompLevel_all); 1.58 + // m is allowed to be osr compiled 1.59 + static bool can_be_osr_compiled(methodHandle m, int comp_level = CompLevel_all); 1.60 + static bool is_compilation_enabled(); 1.61 + static void set_policy(CompilationPolicy* policy) { _policy = policy; } 1.62 + static CompilationPolicy* policy() { return _policy; } 1.63 + 1.64 + // Profiling 1.65 + elapsedTimer* accumulated_time() { return &_accumulated_time; } 1.66 + void print_time() PRODUCT_RETURN; 1.67 + // Return initial compile level that is used with Xcomp 1.68 + virtual CompLevel initial_compile_level() = 0; 1.69 + virtual int compiler_count(CompLevel comp_level) = 0; 1.70 + // main notification entry, return a pointer to an nmethod if the OSR is required, 1.71 + // returns NULL otherwise. 1.72 + virtual nmethod* event(methodHandle method, methodHandle inlinee, int branch_bci, int bci, CompLevel comp_level, nmethod* nm, JavaThread* thread) = 0; 1.73 + // safepoint() is called at the end of the safepoint 1.74 + virtual void do_safepoint_work() = 0; 1.75 + // reprofile request 1.76 + virtual void reprofile(ScopeDesc* trap_scope, bool is_osr) = 0; 1.77 + // delay_compilation(method) can be called by any component of the runtime to notify the policy 1.78 + // that it's recommended to delay the complation of this method. 1.79 + virtual void delay_compilation(Method* method) = 0; 1.80 + // disable_compilation() is called whenever the runtime decides to disable compilation of the 1.81 + // specified method. 1.82 + virtual void disable_compilation(Method* method) = 0; 1.83 + // Select task is called by CompileBroker. The queue is guaranteed to have at least one 1.84 + // element and is locked. The function should select one and return it. 1.85 + virtual CompileTask* select_task(CompileQueue* compile_queue) = 0; 1.86 + // Tell the runtime if we think a given method is adequately profiled. 1.87 + virtual bool is_mature(Method* method) = 0; 1.88 + // Do policy initialization 1.89 + virtual void initialize() = 0; 1.90 + virtual bool should_not_inline(ciEnv* env, ciMethod* method) { return false; } 1.91 +}; 1.92 + 1.93 +// A base class for baseline policies. 1.94 +class NonTieredCompPolicy : public CompilationPolicy { 1.95 + int _compiler_count; 1.96 +protected: 1.97 + static void trace_frequency_counter_overflow(methodHandle m, int branch_bci, int bci); 1.98 + static void trace_osr_request(methodHandle method, nmethod* osr, int bci); 1.99 + static void trace_osr_completion(nmethod* osr_nm); 1.100 + void reset_counter_for_invocation_event(methodHandle method); 1.101 + void reset_counter_for_back_branch_event(methodHandle method); 1.102 +public: 1.103 + NonTieredCompPolicy() : _compiler_count(0) { } 1.104 + virtual CompLevel initial_compile_level() { return CompLevel_highest_tier; } 1.105 + virtual int compiler_count(CompLevel comp_level); 1.106 + virtual void do_safepoint_work(); 1.107 + virtual void reprofile(ScopeDesc* trap_scope, bool is_osr); 1.108 + virtual void delay_compilation(Method* method); 1.109 + virtual void disable_compilation(Method* method); 1.110 + virtual bool is_mature(Method* method); 1.111 + virtual void initialize(); 1.112 + virtual CompileTask* select_task(CompileQueue* compile_queue); 1.113 + virtual nmethod* event(methodHandle method, methodHandle inlinee, int branch_bci, int bci, CompLevel comp_level, nmethod* nm, JavaThread* thread); 1.114 + virtual void method_invocation_event(methodHandle m, JavaThread* thread) = 0; 1.115 + virtual void method_back_branch_event(methodHandle m, int bci, JavaThread* thread) = 0; 1.116 +}; 1.117 + 1.118 +class SimpleCompPolicy : public NonTieredCompPolicy { 1.119 + public: 1.120 + virtual void method_invocation_event(methodHandle m, JavaThread* thread); 1.121 + virtual void method_back_branch_event(methodHandle m, int bci, JavaThread* thread); 1.122 +}; 1.123 + 1.124 +// StackWalkCompPolicy - existing C2 policy 1.125 + 1.126 +#ifdef COMPILER2 1.127 +class StackWalkCompPolicy : public NonTieredCompPolicy { 1.128 + public: 1.129 + virtual void method_invocation_event(methodHandle m, JavaThread* thread); 1.130 + virtual void method_back_branch_event(methodHandle m, int bci, JavaThread* thread); 1.131 + 1.132 + private: 1.133 + RFrame* findTopInlinableFrame(GrowableArray<RFrame*>* stack); 1.134 + RFrame* senderOf(RFrame* rf, GrowableArray<RFrame*>* stack); 1.135 + 1.136 + // the following variables hold values computed by the last inlining decision 1.137 + // they are used for performance debugging only (print better messages) 1.138 + static const char* _msg; // reason for not inlining 1.139 + 1.140 + static const char* shouldInline (methodHandle callee, float frequency, int cnt); 1.141 + // positive filter: should send be inlined? returns NULL (--> yes) or rejection msg 1.142 + static const char* shouldNotInline(methodHandle callee); 1.143 + // negative filter: should send NOT be inlined? returns NULL (--> inline) or rejection msg 1.144 + 1.145 +}; 1.146 +#endif 1.147 + 1.148 +#endif // SHARE_VM_RUNTIME_COMPILATIONPOLICY_HPP