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