duke@435: /* mikael@6198: * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. duke@435: * duke@435: */ duke@435: stefank@2314: #ifndef SHARE_VM_RUNTIME_COMPILATIONPOLICY_HPP stefank@2314: #define SHARE_VM_RUNTIME_COMPILATIONPOLICY_HPP stefank@2314: stefank@2314: #include "code/nmethod.hpp" stefank@2314: #include "compiler/compileBroker.hpp" stefank@2314: #include "memory/allocation.hpp" stefank@2314: #include "runtime/vm_operations.hpp" stefank@2314: #include "utilities/growableArray.hpp" stefank@2314: duke@435: // The CompilationPolicy selects which method (if any) should be compiled. duke@435: // It also decides which methods must always be compiled (i.e., are never duke@435: // interpreted). iveresov@2138: class CompileTask; iveresov@2138: class CompileQueue; duke@435: zgu@3900: class CompilationPolicy : public CHeapObj { duke@435: static CompilationPolicy* _policy; duke@435: // Accumulated time duke@435: static elapsedTimer _accumulated_time; duke@435: duke@435: static bool _in_vm_startup; iveresov@2138: public: duke@435: static void set_in_vm_startup(bool in_vm_startup) { _in_vm_startup = in_vm_startup; } duke@435: static void completed_vm_startup(); iveresov@2138: static bool delay_compilation_during_startup() { return _in_vm_startup; } duke@435: iveresov@2138: // m must be compiled before executing it iveresov@2138: static bool must_be_compiled(methodHandle m, int comp_level = CompLevel_all); iveresov@2138: // m is allowed to be compiled iveresov@2138: static bool can_be_compiled(methodHandle m, int comp_level = CompLevel_all); iignatyev@5541: // m is allowed to be osr compiled iignatyev@5541: static bool can_be_osr_compiled(methodHandle m, int comp_level = CompLevel_all); iveresov@2138: static bool is_compilation_enabled(); duke@435: static void set_policy(CompilationPolicy* policy) { _policy = policy; } iveresov@2138: static CompilationPolicy* policy() { return _policy; } duke@435: duke@435: // Profiling duke@435: elapsedTimer* accumulated_time() { return &_accumulated_time; } duke@435: void print_time() PRODUCT_RETURN; iveresov@3035: // Return initial compile level that is used with Xcomp iveresov@3035: virtual CompLevel initial_compile_level() = 0; iveresov@2138: virtual int compiler_count(CompLevel comp_level) = 0; iveresov@2138: // main notification entry, return a pointer to an nmethod if the OSR is required, iveresov@2138: // returns NULL otherwise. iveresov@3452: virtual nmethod* event(methodHandle method, methodHandle inlinee, int branch_bci, int bci, CompLevel comp_level, nmethod* nm, JavaThread* thread) = 0; iveresov@2138: // safepoint() is called at the end of the safepoint iveresov@2138: virtual void do_safepoint_work() = 0; iveresov@2138: // reprofile request iveresov@2138: virtual void reprofile(ScopeDesc* trap_scope, bool is_osr) = 0; iveresov@2138: // delay_compilation(method) can be called by any component of the runtime to notify the policy iveresov@2138: // that it's recommended to delay the complation of this method. coleenp@4037: virtual void delay_compilation(Method* method) = 0; iveresov@2138: // disable_compilation() is called whenever the runtime decides to disable compilation of the iveresov@2138: // specified method. coleenp@4037: virtual void disable_compilation(Method* method) = 0; iveresov@2138: // Select task is called by CompileBroker. The queue is guaranteed to have at least one iveresov@2138: // element and is locked. The function should select one and return it. iveresov@2138: virtual CompileTask* select_task(CompileQueue* compile_queue) = 0; iveresov@2138: // Tell the runtime if we think a given method is adequately profiled. coleenp@4037: virtual bool is_mature(Method* method) = 0; iveresov@2138: // Do policy initialization iveresov@2138: virtual void initialize() = 0; iveresov@2988: virtual bool should_not_inline(ciEnv* env, ciMethod* method) { return false; } duke@435: }; duke@435: iveresov@2138: // A base class for baseline policies. iveresov@2138: class NonTieredCompPolicy : public CompilationPolicy { iveresov@2138: int _compiler_count; iveresov@2138: protected: iveresov@2138: static void trace_frequency_counter_overflow(methodHandle m, int branch_bci, int bci); iveresov@2138: static void trace_osr_request(methodHandle method, nmethod* osr, int bci); iveresov@2138: static void trace_osr_completion(nmethod* osr_nm); iveresov@2138: void reset_counter_for_invocation_event(methodHandle method); iveresov@2138: void reset_counter_for_back_branch_event(methodHandle method); iveresov@2138: public: iveresov@2138: NonTieredCompPolicy() : _compiler_count(0) { } iignatyev@4908: virtual CompLevel initial_compile_level() { return CompLevel_highest_tier; } iveresov@2138: virtual int compiler_count(CompLevel comp_level); iveresov@2138: virtual void do_safepoint_work(); iveresov@2138: virtual void reprofile(ScopeDesc* trap_scope, bool is_osr); coleenp@4037: virtual void delay_compilation(Method* method); coleenp@4037: virtual void disable_compilation(Method* method); coleenp@4037: virtual bool is_mature(Method* method); iveresov@2138: virtual void initialize(); iveresov@2138: virtual CompileTask* select_task(CompileQueue* compile_queue); iveresov@3452: virtual nmethod* event(methodHandle method, methodHandle inlinee, int branch_bci, int bci, CompLevel comp_level, nmethod* nm, JavaThread* thread); iveresov@3452: virtual void method_invocation_event(methodHandle m, JavaThread* thread) = 0; iveresov@3452: virtual void method_back_branch_event(methodHandle m, int bci, JavaThread* thread) = 0; iveresov@2138: }; iveresov@2138: iveresov@2138: class SimpleCompPolicy : public NonTieredCompPolicy { duke@435: public: iveresov@3452: virtual void method_invocation_event(methodHandle m, JavaThread* thread); iveresov@3452: virtual void method_back_branch_event(methodHandle m, int bci, JavaThread* thread); duke@435: }; duke@435: duke@435: // StackWalkCompPolicy - existing C2 policy duke@435: duke@435: #ifdef COMPILER2 iveresov@2138: class StackWalkCompPolicy : public NonTieredCompPolicy { duke@435: public: iveresov@3452: virtual void method_invocation_event(methodHandle m, JavaThread* thread); iveresov@3452: virtual void method_back_branch_event(methodHandle m, int bci, JavaThread* thread); duke@435: duke@435: private: duke@435: RFrame* findTopInlinableFrame(GrowableArray* stack); duke@435: RFrame* senderOf(RFrame* rf, GrowableArray* stack); duke@435: duke@435: // the following variables hold values computed by the last inlining decision duke@435: // they are used for performance debugging only (print better messages) duke@435: static const char* _msg; // reason for not inlining duke@435: duke@435: static const char* shouldInline (methodHandle callee, float frequency, int cnt); duke@435: // positive filter: should send be inlined? returns NULL (--> yes) or rejection msg duke@435: static const char* shouldNotInline(methodHandle callee); duke@435: // negative filter: should send NOT be inlined? returns NULL (--> inline) or rejection msg duke@435: duke@435: }; duke@435: #endif stefank@2314: stefank@2314: #endif // SHARE_VM_RUNTIME_COMPILATIONPOLICY_HPP