Path: blob/master/src/hotspot/share/compiler/compilerThread.hpp
40930 views
/*1* Copyright (c) 2021, 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_COMPILERTHREAD_HPP25#define SHARE_COMPILER_COMPILERTHREAD_HPP2627#include "runtime/thread.hpp"2829class BufferBlob;30class AbstractCompiler;31class ciEnv;32class CompileThread;33class CompileLog;34class CompileTask;35class CompileQueue;36class CompilerCounters;37class IdealGraphPrinter;38class JVMCIEnv;39class JVMCIPrimitiveArray;4041// A thread used for Compilation.42class CompilerThread : public JavaThread {43friend class VMStructs;44private:45CompilerCounters* _counters;4647ciEnv* _env;48CompileLog* _log;49CompileTask* volatile _task; // print_threads_compiling can read this concurrently.50CompileQueue* _queue;51BufferBlob* _buffer_blob;5253AbstractCompiler* _compiler;54TimeStamp _idle_time;5556public:5758static CompilerThread* current() {59return CompilerThread::cast(JavaThread::current());60}6162static CompilerThread* cast(Thread* t) {63assert(t->is_Compiler_thread(), "incorrect cast to CompilerThread");64return static_cast<CompilerThread*>(t);65}6667CompilerThread(CompileQueue* queue, CompilerCounters* counters);68~CompilerThread();6970bool is_Compiler_thread() const { return true; }7172virtual bool can_call_java() const;7374// Hide native compiler threads from external view.75bool is_hidden_from_external_view() const { return !can_call_java(); }7677void set_compiler(AbstractCompiler* c) { _compiler = c; }78AbstractCompiler* compiler() const { return _compiler; }7980CompileQueue* queue() const { return _queue; }81CompilerCounters* counters() const { return _counters; }8283// Get/set the thread's compilation environment.84ciEnv* env() { return _env; }85void set_env(ciEnv* env) { _env = env; }8687BufferBlob* get_buffer_blob() const { return _buffer_blob; }88void set_buffer_blob(BufferBlob* b) { _buffer_blob = b; }8990// Get/set the thread's logging information91CompileLog* log() { return _log; }92void init_log(CompileLog* log) {93// Set once, for good.94assert(_log == NULL, "set only once");95_log = log;96}9798void start_idle_timer() { _idle_time.update(); }99jlong idle_time_millis() {100return TimeHelper::counter_to_millis(_idle_time.ticks_since_update());101}102103#ifndef PRODUCT104private:105IdealGraphPrinter *_ideal_graph_printer;106public:107IdealGraphPrinter *ideal_graph_printer() { return _ideal_graph_printer; }108void set_ideal_graph_printer(IdealGraphPrinter *n) { _ideal_graph_printer = n; }109#endif110111// Get/set the thread's current task112CompileTask* task() { return _task; }113void set_task(CompileTask* task) { _task = task; }114115static void thread_entry(JavaThread* thread, TRAPS);116};117118// Dedicated thread to sweep the code cache119class CodeCacheSweeperThread : public JavaThread {120CompiledMethod* _scanned_compiled_method; // nmethod being scanned by the sweeper121122static void thread_entry(JavaThread* thread, TRAPS);123124public:125CodeCacheSweeperThread();126// Track the nmethod currently being scanned by the sweeper127void set_scanned_compiled_method(CompiledMethod* cm) {128assert(_scanned_compiled_method == NULL || cm == NULL, "should reset to NULL before writing a new value");129_scanned_compiled_method = cm;130}131132// Hide sweeper thread from external view.133bool is_hidden_from_external_view() const { return true; }134135bool is_Code_cache_sweeper_thread() const { return true; }136137// Prevent GC from unloading _scanned_compiled_method138void oops_do_no_frames(OopClosure* f, CodeBlobClosure* cf);139void nmethods_do(CodeBlobClosure* cf);140};141142143#endif // SHARE_COMPILER_COMPILERTHREAD_HPP144145146