Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/gc_implementation/parallelScavenge/gcTaskThread.cpp
38920 views
1/*2* Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved.3* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.4*5* This code is free software; you can redistribute it and/or modify it6* under the terms of the GNU General Public License version 2 only, as7* published by the Free Software Foundation.8*9* This code is distributed in the hope that it will be useful, but WITHOUT10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12* version 2 for more details (a copy is included in the LICENSE file that13* accompanied this code).14*15* You should have received a copy of the GNU General Public License version16* 2 along with this work; if not, write to the Free Software Foundation,17* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.18*19* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA20* or visit www.oracle.com if you need additional information or have any21* questions.22*23*/2425#include "precompiled.hpp"26#include "gc_implementation/parallelScavenge/gcTaskManager.hpp"27#include "gc_implementation/parallelScavenge/gcTaskThread.hpp"28#include "memory/allocation.hpp"29#include "memory/allocation.inline.hpp"30#include "memory/resourceArea.hpp"31#include "runtime/handles.hpp"32#include "runtime/handles.inline.hpp"33#include "runtime/os.hpp"34#include "runtime/thread.hpp"3536PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC3738GCTaskThread::GCTaskThread(GCTaskManager* manager,39uint which,40uint processor_id) :41_manager(manager),42_processor_id(processor_id),43_time_stamps(NULL),44_time_stamp_index(0)45{46if (!os::create_thread(this, os::pgc_thread))47vm_exit_out_of_memory(0, OOM_MALLOC_ERROR, "Cannot create GC thread. Out of system resources.");4849if (PrintGCTaskTimeStamps) {50_time_stamps = NEW_C_HEAP_ARRAY(GCTaskTimeStamp, GCTaskTimeStampEntries, mtGC);5152guarantee(_time_stamps != NULL, "Sanity");53}54set_id(which);55set_name("GC task thread#%d (ParallelGC)", which);56}5758GCTaskThread::~GCTaskThread() {59if (_time_stamps != NULL) {60FREE_C_HEAP_ARRAY(GCTaskTimeStamp, _time_stamps, mtGC);61}62}6364void GCTaskThread::start() {65os::start_thread(this);66}6768GCTaskTimeStamp* GCTaskThread::time_stamp_at(uint index) {69guarantee(index < GCTaskTimeStampEntries, "increase GCTaskTimeStampEntries");7071return &(_time_stamps[index]);72}7374void GCTaskThread::print_task_time_stamps() {75assert(PrintGCTaskTimeStamps, "Sanity");76assert(_time_stamps != NULL, "Sanity (Probably set PrintGCTaskTimeStamps late)");7778tty->print_cr("GC-Thread %u entries: %d", id(), _time_stamp_index);79for(uint i=0; i<_time_stamp_index; i++) {80GCTaskTimeStamp* time_stamp = time_stamp_at(i);81tty->print_cr("\t[ %s " INT64_FORMAT " " INT64_FORMAT " ]",82time_stamp->name(),83time_stamp->entry_time(),84time_stamp->exit_time());85}8687// Reset after dumping the data88_time_stamp_index = 0;89}9091void GCTaskThread::print_on(outputStream* st) const {92st->print("\"%s\" ", name());93Thread::print_on(st);94st->cr();95}9697// GC workers get tasks from the GCTaskManager and execute98// them in this method. If there are no tasks to execute,99// the GC workers wait in the GCTaskManager's get_task()100// for tasks to be enqueued for execution.101102void GCTaskThread::run() {103// Set up the thread for stack overflow support104this->record_stack_base_and_size();105this->initialize_thread_local_storage();106// Bind yourself to your processor.107if (processor_id() != GCTaskManager::sentinel_worker()) {108if (TraceGCTaskThread) {109tty->print_cr("GCTaskThread::run: "110" binding to processor %u", processor_id());111}112if (!os::bind_to_processor(processor_id())) {113DEBUG_ONLY(114warning("Couldn't bind GCTaskThread %u to processor %u",115which(), processor_id());116)117}118}119// Part of thread setup.120// ??? Are these set up once here to make subsequent ones fast?121HandleMark hm_outer;122ResourceMark rm_outer;123124TimeStamp timer;125126for (;/* ever */;) {127// These are so we can flush the resources allocated in the inner loop.128HandleMark hm_inner;129ResourceMark rm_inner;130for (; /* break */; ) {131// This will block until there is a task to be gotten.132GCTask* task = manager()->get_task(which());133// Record if this is an idle task for later use.134bool is_idle_task = task->is_idle_task();135// In case the update is costly136if (PrintGCTaskTimeStamps) {137timer.update();138}139140jlong entry_time = timer.ticks();141char* name = task->name();142143// If this is the barrier task, it can be destroyed144// by the GC task manager once the do_it() executes.145task->do_it(manager(), which());146147// Use the saved value of is_idle_task because references148// using "task" are not reliable for the barrier task.149if (!is_idle_task) {150manager()->note_completion(which());151152if (PrintGCTaskTimeStamps) {153assert(_time_stamps != NULL,154"Sanity (PrintGCTaskTimeStamps set late?)");155156timer.update();157158GCTaskTimeStamp* time_stamp = time_stamp_at(_time_stamp_index++);159160time_stamp->set_name(name);161time_stamp->set_entry_time(entry_time);162time_stamp->set_exit_time(timer.ticks());163}164} else {165// idle tasks complete outside the normal accounting166// so that a task can complete without waiting for idle tasks.167// They have to be terminated separately.168IdleGCTask::destroy((IdleGCTask*)task);169set_is_working(true);170}171172// Check if we should release our inner resources.173if (manager()->should_release_resources(which())) {174manager()->note_release(which());175break;176}177}178}179}180181182