Path: blob/master/src/hotspot/share/compiler/compileTask.hpp
40930 views
/*1* Copyright (c) 1998, 2020, 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_COMPILER_COMPILETASK_HPP25#define SHARE_COMPILER_COMPILETASK_HPP2627#include "ci/ciMethod.hpp"28#include "code/nmethod.hpp"29#include "compiler/compileLog.hpp"30#include "memory/allocation.hpp"31#include "utilities/xmlstream.hpp"3233JVMCI_ONLY(class JVMCICompileState;)3435// CompileTask36//37// An entry in the compile queue. It represents a pending or current38// compilation.3940class CompileTask : public CHeapObj<mtCompiler> {41friend class VMStructs;42friend class JVMCIVMStructs;4344public:45// Different reasons for a compilation46// The order is important - mapped to reason_names[]47enum CompileReason {48Reason_None,49Reason_InvocationCount, // Simple/StackWalk-policy50Reason_BackedgeCount, // Simple/StackWalk-policy51Reason_Tiered, // Tiered-policy52Reason_Replay, // ciReplay53Reason_Whitebox, // Whitebox API54Reason_MustBeCompiled, // Used for -Xcomp or AlwaysCompileLoopMethods (see CompilationPolicy::must_be_compiled())55Reason_Bootstrap, // JVMCI bootstrap56Reason_Count57};5859static const char* reason_name(CompileTask::CompileReason compile_reason) {60static const char* reason_names[] = {61"no_reason",62"count",63"backedge_count",64"tiered",65"replay",66"whitebox",67"must_be_compiled",68"bootstrap"69};70return reason_names[compile_reason];71}7273private:74static CompileTask* _task_free_list;75Monitor* _lock;76uint _compile_id;77Method* _method;78jobject _method_holder;79int _osr_bci;80bool _is_complete;81bool _is_success;82bool _is_blocking;83#if INCLUDE_JVMCI84bool _has_waiter;85// Compilation state for a blocking JVMCI compilation86JVMCICompileState* _blocking_jvmci_compile_state;87#endif88int _comp_level;89int _num_inlined_bytecodes;90nmethodLocker* _code_handle; // holder of eventual result91CompileTask* _next, *_prev;92bool _is_free;93// Fields used for logging why the compilation was initiated:94jlong _time_queued; // time when task was enqueued95jlong _time_started; // time when compilation started96Method* _hot_method; // which method actually triggered this task97jobject _hot_method_holder;98int _hot_count; // information about its invocation counter99CompileReason _compile_reason; // more info about the task100const char* _failure_reason;101// Specifies if _failure_reason is on the C heap.102bool _failure_reason_on_C_heap;103104public:105CompileTask() : _failure_reason(NULL), _failure_reason_on_C_heap(false) {106_lock = new Monitor(Mutex::nonleaf+2, "CompileTaskLock");107}108109void initialize(int compile_id, const methodHandle& method, int osr_bci, int comp_level,110const methodHandle& hot_method, int hot_count,111CompileTask::CompileReason compile_reason, bool is_blocking);112113static CompileTask* allocate();114static void free(CompileTask* task);115116int compile_id() const { return _compile_id; }117Method* method() const { return _method; }118Method* hot_method() const { return _hot_method; }119int osr_bci() const { return _osr_bci; }120bool is_complete() const { return _is_complete; }121bool is_blocking() const { return _is_blocking; }122bool is_success() const { return _is_success; }123bool can_become_stale() const {124switch (_compile_reason) {125case Reason_BackedgeCount:126case Reason_InvocationCount:127case Reason_Tiered:128return !_is_blocking;129default:130return false;131}132}133#if INCLUDE_JVMCI134bool should_wait_for_compilation() const {135// Wait for blocking compilation to finish.136switch (_compile_reason) {137case Reason_Replay:138case Reason_Whitebox:139case Reason_Bootstrap:140return _is_blocking;141default:142return false;143}144}145146bool has_waiter() const { return _has_waiter; }147void clear_waiter() { _has_waiter = false; }148JVMCICompileState* blocking_jvmci_compile_state() const { return _blocking_jvmci_compile_state; }149void set_blocking_jvmci_compile_state(JVMCICompileState* state) {150_blocking_jvmci_compile_state = state;151}152#endif153154nmethodLocker* code_handle() const { return _code_handle; }155void set_code_handle(nmethodLocker* l) { _code_handle = l; }156nmethod* code() const; // _code_handle->code()157void set_code(nmethod* nm); // _code_handle->set_code(nm)158159Monitor* lock() const { return _lock; }160161void mark_complete() { _is_complete = true; }162void mark_success() { _is_success = true; }163void mark_started(jlong time) { _time_started = time; }164165int comp_level() { return _comp_level;}166void set_comp_level(int comp_level) { _comp_level = comp_level;}167168AbstractCompiler* compiler();169CompileTask* select_for_compilation();170171int num_inlined_bytecodes() const { return _num_inlined_bytecodes; }172void set_num_inlined_bytecodes(int n) { _num_inlined_bytecodes = n; }173174CompileTask* next() const { return _next; }175void set_next(CompileTask* next) { _next = next; }176CompileTask* prev() const { return _prev; }177void set_prev(CompileTask* prev) { _prev = prev; }178bool is_free() const { return _is_free; }179void set_is_free(bool val) { _is_free = val; }180bool is_unloaded() const;181182// RedefineClasses support183void metadata_do(MetadataClosure* f);184void mark_on_stack();185186private:187static void print_impl(outputStream* st, Method* method, int compile_id, int comp_level,188bool is_osr_method = false, int osr_bci = -1, bool is_blocking = false,189const char* msg = NULL, bool short_form = false, bool cr = true,190jlong time_queued = 0, jlong time_started = 0);191192public:193void print(outputStream* st = tty, const char* msg = NULL, bool short_form = false, bool cr = true);194void print_ul(const char* msg = NULL);195static void print(outputStream* st, const nmethod* nm, const char* msg = NULL, bool short_form = false, bool cr = true) {196print_impl(st, nm->method(), nm->compile_id(), nm->comp_level(),197nm->is_osr_method(), nm->is_osr_method() ? nm->osr_entry_bci() : -1, /*is_blocking*/ false,198msg, short_form, cr);199}200static void print_ul(const nmethod* nm, const char* msg = NULL);201202static void print_inline_indent(int inline_level, outputStream* st = tty);203204void print_tty();205void print_line_on_error(outputStream* st, char* buf, int buflen);206207void log_task(xmlStream* log);208void log_task_queued();209void log_task_start(CompileLog* log);210void log_task_done(CompileLog* log);211212void set_failure_reason(const char* reason, bool on_C_heap = false) {213_failure_reason = reason;214_failure_reason_on_C_heap = on_C_heap;215}216217bool check_break_at_flags();218219static void print_inlining_inner(outputStream* st, ciMethod* method, int inline_level, int bci, const char* msg = NULL);220static void print_inlining_tty(ciMethod* method, int inline_level, int bci, const char* msg = NULL) {221print_inlining_inner(tty, method, inline_level, bci, msg);222}223static void print_inlining_ul(ciMethod* method, int inline_level, int bci, const char* msg = NULL);224};225226#endif // SHARE_COMPILER_COMPILETASK_HPP227228229