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