Path: blob/master/src/hotspot/share/compiler/compilerThread.cpp
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#include "precompiled.hpp"25#include "compiler/compileBroker.hpp"26#include "compiler/compileTask.hpp"27#include "compiler/compilerThread.hpp"28#include "runtime/sweeper.hpp"29#include "runtime/thread.inline.hpp"3031// Create a CompilerThread32CompilerThread::CompilerThread(CompileQueue* queue,33CompilerCounters* counters)34: JavaThread(&CompilerThread::thread_entry) {35_env = NULL;36_log = NULL;37_task = NULL;38_queue = queue;39_counters = counters;40_buffer_blob = NULL;41_compiler = NULL;4243// Compiler uses resource area for compilation, let's bias it to mtCompiler44resource_area()->bias_to(mtCompiler);4546#ifndef PRODUCT47_ideal_graph_printer = NULL;48#endif49}5051CompilerThread::~CompilerThread() {52// Delete objects which were allocated on heap.53delete _counters;54}5556void CompilerThread::thread_entry(JavaThread* thread, TRAPS) {57assert(thread->is_Compiler_thread(), "must be compiler thread");58CompileBroker::compiler_thread_loop();59}6061bool CompilerThread::can_call_java() const {62return _compiler != NULL && _compiler->is_jvmci();63}6465// Create sweeper thread66CodeCacheSweeperThread::CodeCacheSweeperThread()67: JavaThread(&CodeCacheSweeperThread::thread_entry) {68_scanned_compiled_method = NULL;69}7071void CodeCacheSweeperThread::thread_entry(JavaThread* thread, TRAPS) {72NMethodSweeper::sweeper_loop();73}7475void CodeCacheSweeperThread::oops_do_no_frames(OopClosure* f, CodeBlobClosure* cf) {76JavaThread::oops_do_no_frames(f, cf);77if (_scanned_compiled_method != NULL && cf != NULL) {78// Safepoints can occur when the sweeper is scanning an nmethod so79// process it here to make sure it isn't unloaded in the middle of80// a scan.81cf->do_code_blob(_scanned_compiled_method);82}83}8485void CodeCacheSweeperThread::nmethods_do(CodeBlobClosure* cf) {86JavaThread::nmethods_do(cf);87if (_scanned_compiled_method != NULL && cf != NULL) {88// Safepoints can occur when the sweeper is scanning an nmethod so89// process it here to make sure it isn't unloaded in the middle of90// a scan.91cf->do_code_blob(_scanned_compiled_method);92}93}94959697