Skip to content
Permalink
Browse files
8260019: Move some Thread subtypes out of thread.hpp
Reviewed-by: dholmes, coleenp
  • Loading branch information
iklam committed Feb 5, 2021
1 parent 08f7454 commit c5bb1092725005b1cf0cb98fbdd3bcec8d5a59c3
@@ -31,6 +31,7 @@
#include "code/debugInfoRec.hpp"
#include "code/dependencies.hpp"
#include "code/exceptionHandlerTable.hpp"
#include "compiler/compilerThread.hpp"
#include "compiler/oopMap.hpp"
#include "oops/methodData.hpp"
#include "runtime/thread.hpp"
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -57,6 +57,7 @@ class nmethod;
class OopRecorder;
class xmlStream;
class CompileLog;
class CompileTask;
class DepChange;
class KlassDepChange;
class CallSiteDepChange;
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -78,6 +78,7 @@ NOT_PRODUCT(cflags(IGVPrintLevel, intx, PrintIdealGraphLevel, IGVPrintLeve
#define compilerdirectives_c2_flags(cflags)
#endif

class AbstractCompiler;
class CompilerDirectives;
class DirectiveSet;

@@ -0,0 +1,95 @@
/*
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
* 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.
*
* 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.
*
*/

#include "precompiled.hpp"
#include "compiler/compileBroker.hpp"
#include "compiler/compileTask.hpp"
#include "compiler/compilerThread.hpp"
#include "runtime/sweeper.hpp"
#include "runtime/thread.inline.hpp"

// Create a CompilerThread
CompilerThread::CompilerThread(CompileQueue* queue,
CompilerCounters* counters)
: JavaThread(&CompilerThread::thread_entry) {
_env = NULL;
_log = NULL;
_task = NULL;
_queue = queue;
_counters = counters;
_buffer_blob = NULL;
_compiler = NULL;

// Compiler uses resource area for compilation, let's bias it to mtCompiler
resource_area()->bias_to(mtCompiler);

#ifndef PRODUCT
_ideal_graph_printer = NULL;
#endif
}

CompilerThread::~CompilerThread() {
// Delete objects which were allocated on heap.
delete _counters;
}

void CompilerThread::thread_entry(JavaThread* thread, TRAPS) {
assert(thread->is_Compiler_thread(), "must be compiler thread");
CompileBroker::compiler_thread_loop();
}

bool CompilerThread::can_call_java() const {
return _compiler != NULL && _compiler->is_jvmci();
}

// Create sweeper thread
CodeCacheSweeperThread::CodeCacheSweeperThread()
: JavaThread(&CodeCacheSweeperThread::thread_entry) {
_scanned_compiled_method = NULL;
}

void CodeCacheSweeperThread::thread_entry(JavaThread* thread, TRAPS) {
NMethodSweeper::sweeper_loop();
}

void CodeCacheSweeperThread::oops_do_no_frames(OopClosure* f, CodeBlobClosure* cf) {
JavaThread::oops_do_no_frames(f, cf);
if (_scanned_compiled_method != NULL && cf != NULL) {
// Safepoints can occur when the sweeper is scanning an nmethod so
// process it here to make sure it isn't unloaded in the middle of
// a scan.
cf->do_code_blob(_scanned_compiled_method);
}
}

void CodeCacheSweeperThread::nmethods_do(CodeBlobClosure* cf) {
JavaThread::nmethods_do(cf);
if (_scanned_compiled_method != NULL && cf != NULL) {
// Safepoints can occur when the sweeper is scanning an nmethod so
// process it here to make sure it isn't unloaded in the middle of
// a scan.
cf->do_code_blob(_scanned_compiled_method);
}
}

@@ -0,0 +1,146 @@
/*
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
* 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.
*
* 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.
*
*/

#ifndef SHARE_COMPILER_COMPILERTHREAD_HPP
#define SHARE_COMPILER_COMPILERTHREAD_HPP

#include "runtime/thread.hpp"

class BufferBlob;
class AbstractCompiler;
class ciEnv;
class CompileThread;
class CompileLog;
class CompileTask;
class CompileQueue;
class CompilerCounters;
class IdealGraphPrinter;
class JVMCIEnv;
class JVMCIPrimitiveArray;

// A thread used for Compilation.
class CompilerThread : public JavaThread {
friend class VMStructs;
private:
CompilerCounters* _counters;

ciEnv* _env;
CompileLog* _log;
CompileTask* volatile _task; // print_threads_compiling can read this concurrently.
CompileQueue* _queue;
BufferBlob* _buffer_blob;

AbstractCompiler* _compiler;
TimeStamp _idle_time;

public:

static CompilerThread* current();

CompilerThread(CompileQueue* queue, CompilerCounters* counters);
~CompilerThread();

bool is_Compiler_thread() const { return true; }

virtual bool can_call_java() const;

// Hide native compiler threads from external view.
bool is_hidden_from_external_view() const { return !can_call_java(); }

void set_compiler(AbstractCompiler* c) { _compiler = c; }
AbstractCompiler* compiler() const { return _compiler; }

CompileQueue* queue() const { return _queue; }
CompilerCounters* counters() const { return _counters; }

// Get/set the thread's compilation environment.
ciEnv* env() { return _env; }
void set_env(ciEnv* env) { _env = env; }

BufferBlob* get_buffer_blob() const { return _buffer_blob; }
void set_buffer_blob(BufferBlob* b) { _buffer_blob = b; }

// Get/set the thread's logging information
CompileLog* log() { return _log; }
void init_log(CompileLog* log) {
// Set once, for good.
assert(_log == NULL, "set only once");
_log = log;
}

void start_idle_timer() { _idle_time.update(); }
jlong idle_time_millis() {
return TimeHelper::counter_to_millis(_idle_time.ticks_since_update());
}

#ifndef PRODUCT
private:
IdealGraphPrinter *_ideal_graph_printer;
public:
IdealGraphPrinter *ideal_graph_printer() { return _ideal_graph_printer; }
void set_ideal_graph_printer(IdealGraphPrinter *n) { _ideal_graph_printer = n; }
#endif

// Get/set the thread's current task
CompileTask* task() { return _task; }
void set_task(CompileTask* task) { _task = task; }

static void thread_entry(JavaThread* thread, TRAPS);
};

inline CompilerThread* JavaThread::as_CompilerThread() {
assert(is_Compiler_thread(), "just checking");
return (CompilerThread*)this;
}

inline CompilerThread* CompilerThread::current() {
return JavaThread::current()->as_CompilerThread();
}

// Dedicated thread to sweep the code cache
class CodeCacheSweeperThread : public JavaThread {
CompiledMethod* _scanned_compiled_method; // nmethod being scanned by the sweeper

static void thread_entry(JavaThread* thread, TRAPS);

public:
CodeCacheSweeperThread();
// Track the nmethod currently being scanned by the sweeper
void set_scanned_compiled_method(CompiledMethod* cm) {
assert(_scanned_compiled_method == NULL || cm == NULL, "should reset to NULL before writing a new value");
_scanned_compiled_method = cm;
}

// Hide sweeper thread from external view.
bool is_hidden_from_external_view() const { return true; }

bool is_Code_cache_sweeper_thread() const { return true; }

// Prevent GC from unloading _scanned_compiled_method
void oops_do_no_frames(OopClosure* f, CodeBlobClosure* cf);
void nmethods_do(CodeBlobClosure* cf);
};


#endif // SHARE_COMPILER_COMPILERTHREAD_HPP
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -25,6 +25,7 @@
#ifndef SHARE_GC_SHARED_CONCURRENTGCTHREAD_HPP
#define SHARE_GC_SHARED_CONCURRENTGCTHREAD_HPP

#include "runtime/nonJavaThread.hpp"
#include "runtime/thread.hpp"

class ConcurrentGCThread: public NamedThread {
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -25,6 +25,7 @@
#include "precompiled.hpp"
#include "jvm.h"
#include "gc/shared/gcId.hpp"
#include "runtime/nonJavaThread.hpp"
#include "runtime/safepoint.hpp"
#include "runtime/thread.inline.hpp"

@@ -39,6 +39,7 @@
#include "oops/access.inline.hpp"
#include "oops/oop.inline.hpp"
#include "runtime/java.hpp"
#include "runtime/nonJavaThread.hpp"

ReferencePolicy* ReferenceProcessor::_always_clear_soft_ref_policy = NULL;
ReferencePolicy* ReferenceProcessor::_default_soft_ref_policy = NULL;
@@ -29,6 +29,7 @@
#include "metaprogramming/enableIf.hpp"
#include "metaprogramming/logical.hpp"
#include "runtime/globals.hpp"
#include "runtime/nonJavaThread.hpp"
#include "runtime/thread.hpp"
#include "gc/shared/gcId.hpp"
#include "logging/log.hpp"
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -23,6 +23,7 @@

#include "precompiled.hpp"
#include "gc/z/zThread.inline.hpp"
#include "runtime/nonJavaThread.hpp"
#include "runtime/thread.hpp"
#include "utilities/debug.hpp"

@@ -33,6 +33,7 @@
#include "runtime/thread.hpp"
#include "utilities/macros.hpp"

class BufferBlob;
class CodeBuffer;

// The InterpreterRuntime is called by the interpreter for everything
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -26,6 +26,7 @@
#define SHARE_VM_JFR_UTILITIES_JFRTHREADITERATOR_HPP

#include "memory/allocation.hpp"
#include "runtime/nonJavaThread.hpp"
#include "runtime/thread.hpp"
#include "runtime/threadSMR.hpp"

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -24,6 +24,7 @@
#include "precompiled.hpp"
#include "classfile/systemDictionary.hpp"
#include "compiler/compileTask.hpp"
#include "compiler/compilerThread.hpp"
#include "gc/shared/collectedHeap.hpp"
#include "jvmci/jvmci.hpp"
#include "jvmci/jvmciJavaClasses.hpp"
Loading

0 comments on commit c5bb109

Please sign in to comment.