Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/runtime/compilationPolicy.hpp
32285 views
/*1* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_VM_RUNTIME_COMPILATIONPOLICY_HPP25#define SHARE_VM_RUNTIME_COMPILATIONPOLICY_HPP2627#include "code/nmethod.hpp"28#include "compiler/compileBroker.hpp"29#include "memory/allocation.hpp"30#include "runtime/vm_operations.hpp"31#include "utilities/growableArray.hpp"3233// The CompilationPolicy selects which method (if any) should be compiled.34// It also decides which methods must always be compiled (i.e., are never35// interpreted).36class CompileTask;37class CompileQueue;3839class CompilationPolicy : public CHeapObj<mtCompiler> {40static CompilationPolicy* _policy;41// Accumulated time42static elapsedTimer _accumulated_time;4344static bool _in_vm_startup;45public:46static void set_in_vm_startup(bool in_vm_startup) { _in_vm_startup = in_vm_startup; }47static void completed_vm_startup();48static bool delay_compilation_during_startup() { return _in_vm_startup; }4950// m must be compiled before executing it51static bool must_be_compiled(methodHandle m, int comp_level = CompLevel_all);52// m is allowed to be compiled53static bool can_be_compiled(methodHandle m, int comp_level = CompLevel_all);54// m is allowed to be osr compiled55static bool can_be_osr_compiled(methodHandle m, int comp_level = CompLevel_all);56static bool is_compilation_enabled();57static void set_policy(CompilationPolicy* policy) { _policy = policy; }58static CompilationPolicy* policy() { return _policy; }5960// Profiling61elapsedTimer* accumulated_time() { return &_accumulated_time; }62void print_time() PRODUCT_RETURN;63// Return initial compile level that is used with Xcomp64virtual CompLevel initial_compile_level() = 0;65virtual int compiler_count(CompLevel comp_level) = 0;66// main notification entry, return a pointer to an nmethod if the OSR is required,67// returns NULL otherwise.68virtual nmethod* event(methodHandle method, methodHandle inlinee, int branch_bci, int bci, CompLevel comp_level, nmethod* nm, JavaThread* thread) = 0;69// safepoint() is called at the end of the safepoint70virtual void do_safepoint_work() = 0;71// reprofile request72virtual void reprofile(ScopeDesc* trap_scope, bool is_osr) = 0;73// delay_compilation(method) can be called by any component of the runtime to notify the policy74// that it's recommended to delay the complation of this method.75virtual void delay_compilation(Method* method) = 0;76// disable_compilation() is called whenever the runtime decides to disable compilation of the77// specified method.78virtual void disable_compilation(Method* method) = 0;79// Select task is called by CompileBroker. The queue is guaranteed to have at least one80// element and is locked. The function should select one and return it.81virtual CompileTask* select_task(CompileQueue* compile_queue) = 0;82// Tell the runtime if we think a given method is adequately profiled.83virtual bool is_mature(Method* method) = 0;84// Do policy initialization85virtual void initialize() = 0;86virtual bool should_not_inline(ciEnv* env, ciMethod* method) { return false; }87};8889// A base class for baseline policies.90class NonTieredCompPolicy : public CompilationPolicy {91int _compiler_count;92protected:93static void trace_frequency_counter_overflow(methodHandle m, int branch_bci, int bci);94static void trace_osr_request(methodHandle method, nmethod* osr, int bci);95static void trace_osr_completion(nmethod* osr_nm);96void reset_counter_for_invocation_event(methodHandle method);97void reset_counter_for_back_branch_event(methodHandle method);98public:99NonTieredCompPolicy() : _compiler_count(0) { }100virtual CompLevel initial_compile_level() { return CompLevel_highest_tier; }101virtual int compiler_count(CompLevel comp_level);102virtual void do_safepoint_work();103virtual void reprofile(ScopeDesc* trap_scope, bool is_osr);104virtual void delay_compilation(Method* method);105virtual void disable_compilation(Method* method);106virtual bool is_mature(Method* method);107virtual void initialize();108virtual CompileTask* select_task(CompileQueue* compile_queue);109virtual nmethod* event(methodHandle method, methodHandle inlinee, int branch_bci, int bci, CompLevel comp_level, nmethod* nm, JavaThread* thread);110virtual void method_invocation_event(methodHandle m, JavaThread* thread) = 0;111virtual void method_back_branch_event(methodHandle m, int bci, JavaThread* thread) = 0;112};113114class SimpleCompPolicy : public NonTieredCompPolicy {115public:116virtual void method_invocation_event(methodHandle m, JavaThread* thread);117virtual void method_back_branch_event(methodHandle m, int bci, JavaThread* thread);118};119120// StackWalkCompPolicy - existing C2 policy121122#ifdef COMPILER2123class StackWalkCompPolicy : public NonTieredCompPolicy {124public:125virtual void method_invocation_event(methodHandle m, JavaThread* thread);126virtual void method_back_branch_event(methodHandle m, int bci, JavaThread* thread);127128private:129RFrame* findTopInlinableFrame(GrowableArray<RFrame*>* stack);130RFrame* senderOf(RFrame* rf, GrowableArray<RFrame*>* stack);131132// the following variables hold values computed by the last inlining decision133// they are used for performance debugging only (print better messages)134static const char* _msg; // reason for not inlining135136static const char* shouldInline (methodHandle callee, float frequency, int cnt);137// positive filter: should send be inlined? returns NULL (--> yes) or rejection msg138static const char* shouldNotInline(methodHandle callee);139// negative filter: should send NOT be inlined? returns NULL (--> inline) or rejection msg140141};142#endif143144#endif // SHARE_VM_RUNTIME_COMPILATIONPOLICY_HPP145146147