2007-12-01 00:00:00 +00:00
|
|
|
/*
|
2015-10-23 16:48:38 -04:00
|
|
|
* Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
|
2007-12-01 00:00:00 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
|
|
*
|
|
|
|
* This code is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License version 2 only, as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* version 2 for more details (a copy is included in the LICENSE file that
|
|
|
|
* accompanied this code).
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License version
|
|
|
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
2010-05-27 19:08:38 -07:00
|
|
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
|
|
* or visit www.oracle.com if you need additional information or have any
|
|
|
|
* questions.
|
2007-12-01 00:00:00 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2010-11-23 13:22:55 -08:00
|
|
|
#ifndef SHARE_VM_RUNTIME_COMPILATIONPOLICY_HPP
|
|
|
|
#define SHARE_VM_RUNTIME_COMPILATIONPOLICY_HPP
|
|
|
|
|
|
|
|
#include "code/nmethod.hpp"
|
|
|
|
#include "compiler/compileBroker.hpp"
|
|
|
|
#include "memory/allocation.hpp"
|
|
|
|
#include "runtime/vm_operations.hpp"
|
|
|
|
#include "utilities/growableArray.hpp"
|
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
// The CompilationPolicy selects which method (if any) should be compiled.
|
|
|
|
// It also decides which methods must always be compiled (i.e., are never
|
|
|
|
// interpreted).
|
2010-09-03 17:51:07 -07:00
|
|
|
class CompileTask;
|
|
|
|
class CompileQueue;
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2012-06-28 17:03:16 -04:00
|
|
|
class CompilationPolicy : public CHeapObj<mtCompiler> {
|
2007-12-01 00:00:00 +00:00
|
|
|
static CompilationPolicy* _policy;
|
|
|
|
// Accumulated time
|
|
|
|
static elapsedTimer _accumulated_time;
|
|
|
|
|
|
|
|
static bool _in_vm_startup;
|
2010-09-03 17:51:07 -07:00
|
|
|
public:
|
2007-12-01 00:00:00 +00:00
|
|
|
static void set_in_vm_startup(bool in_vm_startup) { _in_vm_startup = in_vm_startup; }
|
|
|
|
static void completed_vm_startup();
|
2010-09-03 17:51:07 -07:00
|
|
|
static bool delay_compilation_during_startup() { return _in_vm_startup; }
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2010-09-03 17:51:07 -07:00
|
|
|
// m must be compiled before executing it
|
|
|
|
static bool must_be_compiled(methodHandle m, int comp_level = CompLevel_all);
|
|
|
|
// m is allowed to be compiled
|
|
|
|
static bool can_be_compiled(methodHandle m, int comp_level = CompLevel_all);
|
2013-08-14 23:50:23 +04:00
|
|
|
// m is allowed to be osr compiled
|
|
|
|
static bool can_be_osr_compiled(methodHandle m, int comp_level = CompLevel_all);
|
2010-09-03 17:51:07 -07:00
|
|
|
static bool is_compilation_enabled();
|
2007-12-01 00:00:00 +00:00
|
|
|
static void set_policy(CompilationPolicy* policy) { _policy = policy; }
|
2010-09-03 17:51:07 -07:00
|
|
|
static CompilationPolicy* policy() { return _policy; }
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
// Profiling
|
|
|
|
elapsedTimer* accumulated_time() { return &_accumulated_time; }
|
|
|
|
void print_time() PRODUCT_RETURN;
|
2011-07-20 18:04:17 -07:00
|
|
|
// Return initial compile level that is used with Xcomp
|
|
|
|
virtual CompLevel initial_compile_level() = 0;
|
2010-09-03 17:51:07 -07:00
|
|
|
virtual int compiler_count(CompLevel comp_level) = 0;
|
|
|
|
// main notification entry, return a pointer to an nmethod if the OSR is required,
|
|
|
|
// returns NULL otherwise.
|
2015-10-23 16:48:38 -04:00
|
|
|
virtual nmethod* event(const methodHandle& method, const methodHandle& inlinee, int branch_bci, int bci, CompLevel comp_level, nmethod* nm, JavaThread* thread) = 0;
|
2010-09-03 17:51:07 -07:00
|
|
|
// safepoint() is called at the end of the safepoint
|
|
|
|
virtual void do_safepoint_work() = 0;
|
|
|
|
// reprofile request
|
|
|
|
virtual void reprofile(ScopeDesc* trap_scope, bool is_osr) = 0;
|
|
|
|
// delay_compilation(method) can be called by any component of the runtime to notify the policy
|
2014-01-23 14:47:23 +01:00
|
|
|
// that it's recommended to delay the compilation of this method.
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
virtual void delay_compilation(Method* method) = 0;
|
2010-09-03 17:51:07 -07:00
|
|
|
// disable_compilation() is called whenever the runtime decides to disable compilation of the
|
|
|
|
// specified method.
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
virtual void disable_compilation(Method* method) = 0;
|
2010-09-03 17:51:07 -07:00
|
|
|
// Select task is called by CompileBroker. The queue is guaranteed to have at least one
|
|
|
|
// element and is locked. The function should select one and return it.
|
|
|
|
virtual CompileTask* select_task(CompileQueue* compile_queue) = 0;
|
|
|
|
// Tell the runtime if we think a given method is adequately profiled.
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
virtual bool is_mature(Method* method) = 0;
|
2010-09-03 17:51:07 -07:00
|
|
|
// Do policy initialization
|
|
|
|
virtual void initialize() = 0;
|
2011-07-01 10:37:37 -07:00
|
|
|
virtual bool should_not_inline(ciEnv* env, ciMethod* method) { return false; }
|
2010-09-03 17:51:07 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
// A base class for baseline policies.
|
|
|
|
class NonTieredCompPolicy : public CompilationPolicy {
|
|
|
|
int _compiler_count;
|
|
|
|
protected:
|
2015-10-23 16:48:38 -04:00
|
|
|
static void trace_frequency_counter_overflow(const methodHandle& m, int branch_bci, int bci);
|
|
|
|
static void trace_osr_request(const methodHandle& method, nmethod* osr, int bci);
|
2010-09-03 17:51:07 -07:00
|
|
|
static void trace_osr_completion(nmethod* osr_nm);
|
2015-10-23 16:48:38 -04:00
|
|
|
void reset_counter_for_invocation_event(const methodHandle& method);
|
|
|
|
void reset_counter_for_back_branch_event(const methodHandle& method);
|
2010-09-03 17:51:07 -07:00
|
|
|
public:
|
|
|
|
NonTieredCompPolicy() : _compiler_count(0) { }
|
2013-04-09 09:54:17 -07:00
|
|
|
virtual CompLevel initial_compile_level() { return CompLevel_highest_tier; }
|
2010-09-03 17:51:07 -07:00
|
|
|
virtual int compiler_count(CompLevel comp_level);
|
|
|
|
virtual void do_safepoint_work();
|
|
|
|
virtual void reprofile(ScopeDesc* trap_scope, bool is_osr);
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
virtual void delay_compilation(Method* method);
|
|
|
|
virtual void disable_compilation(Method* method);
|
|
|
|
virtual bool is_mature(Method* method);
|
2010-09-03 17:51:07 -07:00
|
|
|
virtual void initialize();
|
|
|
|
virtual CompileTask* select_task(CompileQueue* compile_queue);
|
2015-10-23 16:48:38 -04:00
|
|
|
virtual nmethod* event(const methodHandle& method, const methodHandle& inlinee, int branch_bci, int bci, CompLevel comp_level, nmethod* nm, JavaThread* thread);
|
|
|
|
virtual void method_invocation_event(const methodHandle& m, JavaThread* thread) = 0;
|
|
|
|
virtual void method_back_branch_event(const methodHandle& m, int bci, JavaThread* thread) = 0;
|
2007-12-01 00:00:00 +00:00
|
|
|
};
|
|
|
|
|
2010-09-03 17:51:07 -07:00
|
|
|
class SimpleCompPolicy : public NonTieredCompPolicy {
|
2007-12-01 00:00:00 +00:00
|
|
|
public:
|
2015-10-23 16:48:38 -04:00
|
|
|
virtual void method_invocation_event(const methodHandle& m, JavaThread* thread);
|
|
|
|
virtual void method_back_branch_event(const methodHandle& m, int bci, JavaThread* thread);
|
2007-12-01 00:00:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// StackWalkCompPolicy - existing C2 policy
|
|
|
|
|
|
|
|
#ifdef COMPILER2
|
2010-09-03 17:51:07 -07:00
|
|
|
class StackWalkCompPolicy : public NonTieredCompPolicy {
|
2007-12-01 00:00:00 +00:00
|
|
|
public:
|
2015-10-23 16:48:38 -04:00
|
|
|
virtual void method_invocation_event(const methodHandle& m, JavaThread* thread);
|
|
|
|
virtual void method_back_branch_event(const methodHandle& m, int bci, JavaThread* thread);
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
RFrame* findTopInlinableFrame(GrowableArray<RFrame*>* stack);
|
|
|
|
RFrame* senderOf(RFrame* rf, GrowableArray<RFrame*>* stack);
|
|
|
|
|
|
|
|
// the following variables hold values computed by the last inlining decision
|
|
|
|
// they are used for performance debugging only (print better messages)
|
|
|
|
static const char* _msg; // reason for not inlining
|
|
|
|
|
2015-10-23 16:48:38 -04:00
|
|
|
static const char* shouldInline (const methodHandle& callee, float frequency, int cnt);
|
2007-12-01 00:00:00 +00:00
|
|
|
// positive filter: should send be inlined? returns NULL (--> yes) or rejection msg
|
2015-10-23 16:48:38 -04:00
|
|
|
static const char* shouldNotInline(const methodHandle& callee);
|
2007-12-01 00:00:00 +00:00
|
|
|
// negative filter: should send NOT be inlined? returns NULL (--> inline) or rejection msg
|
|
|
|
|
|
|
|
};
|
|
|
|
#endif
|
2010-11-23 13:22:55 -08:00
|
|
|
|
|
|
|
#endif // SHARE_VM_RUNTIME_COMPILATIONPOLICY_HPP
|