src/share/vm/gc_implementation/parallelScavenge/gcTaskThread.cpp

Thu, 09 Apr 2015 15:58:49 +0200

author
mlarsson
date
Thu, 09 Apr 2015 15:58:49 +0200
changeset 7686
fb69749583e8
parent 6680
78bbf4d43a14
child 6876
710a3c8b516e
permissions
-rw-r--r--

8072621: Clean up around VM_GC_Operations
Reviewed-by: brutisso, jmasa

duke@435 1
duke@435 2 /*
drchase@6680 3 * Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved.
duke@435 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 5 *
duke@435 6 * This code is free software; you can redistribute it and/or modify it
duke@435 7 * under the terms of the GNU General Public License version 2 only, as
duke@435 8 * published by the Free Software Foundation.
duke@435 9 *
duke@435 10 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 13 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 14 * accompanied this code).
duke@435 15 *
duke@435 16 * You should have received a copy of the GNU General Public License version
duke@435 17 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 19 *
trims@1907 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 21 * or visit www.oracle.com if you need additional information or have any
trims@1907 22 * questions.
duke@435 23 *
duke@435 24 */
duke@435 25
stefank@2314 26 #include "precompiled.hpp"
stefank@2314 27 #include "gc_implementation/parallelScavenge/gcTaskManager.hpp"
stefank@2314 28 #include "gc_implementation/parallelScavenge/gcTaskThread.hpp"
stefank@2314 29 #include "memory/allocation.hpp"
stefank@2314 30 #include "memory/allocation.inline.hpp"
stefank@2314 31 #include "memory/resourceArea.hpp"
stefank@2314 32 #include "runtime/handles.hpp"
stefank@2314 33 #include "runtime/handles.inline.hpp"
stefank@2314 34 #include "runtime/os.hpp"
stefank@2314 35 #include "runtime/thread.hpp"
duke@435 36
drchase@6680 37 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
drchase@6680 38
duke@435 39 GCTaskThread::GCTaskThread(GCTaskManager* manager,
duke@435 40 uint which,
duke@435 41 uint processor_id) :
duke@435 42 _manager(manager),
duke@435 43 _processor_id(processor_id),
duke@435 44 _time_stamps(NULL),
duke@435 45 _time_stamp_index(0)
duke@435 46 {
duke@435 47 if (!os::create_thread(this, os::pgc_thread))
ccheung@4993 48 vm_exit_out_of_memory(0, OOM_MALLOC_ERROR, "Cannot create GC thread. Out of system resources.");
duke@435 49
duke@435 50 if (PrintGCTaskTimeStamps) {
zgu@3900 51 _time_stamps = NEW_C_HEAP_ARRAY(GCTaskTimeStamp, GCTaskTimeStampEntries, mtGC);
duke@435 52
duke@435 53 guarantee(_time_stamps != NULL, "Sanity");
duke@435 54 }
duke@435 55 set_id(which);
duke@435 56 set_name("GC task thread#%d (ParallelGC)", which);
duke@435 57 }
duke@435 58
duke@435 59 GCTaskThread::~GCTaskThread() {
duke@435 60 if (_time_stamps != NULL) {
zgu@3900 61 FREE_C_HEAP_ARRAY(GCTaskTimeStamp, _time_stamps, mtGC);
duke@435 62 }
duke@435 63 }
duke@435 64
duke@435 65 void GCTaskThread::start() {
duke@435 66 os::start_thread(this);
duke@435 67 }
duke@435 68
duke@435 69 GCTaskTimeStamp* GCTaskThread::time_stamp_at(uint index) {
duke@435 70 guarantee(index < GCTaskTimeStampEntries, "increase GCTaskTimeStampEntries");
duke@435 71
duke@435 72 return &(_time_stamps[index]);
duke@435 73 }
duke@435 74
duke@435 75 void GCTaskThread::print_task_time_stamps() {
duke@435 76 assert(PrintGCTaskTimeStamps, "Sanity");
duke@435 77 assert(_time_stamps != NULL, "Sanity (Probably set PrintGCTaskTimeStamps late)");
duke@435 78
duke@435 79 tty->print_cr("GC-Thread %u entries: %d", id(), _time_stamp_index);
duke@435 80 for(uint i=0; i<_time_stamp_index; i++) {
duke@435 81 GCTaskTimeStamp* time_stamp = time_stamp_at(i);
duke@435 82 tty->print_cr("\t[ %s " INT64_FORMAT " " INT64_FORMAT " ]",
duke@435 83 time_stamp->name(),
duke@435 84 time_stamp->entry_time(),
duke@435 85 time_stamp->exit_time());
duke@435 86 }
duke@435 87
duke@435 88 // Reset after dumping the data
duke@435 89 _time_stamp_index = 0;
duke@435 90 }
duke@435 91
duke@435 92 void GCTaskThread::print_on(outputStream* st) const {
duke@435 93 st->print("\"%s\" ", name());
duke@435 94 Thread::print_on(st);
duke@435 95 st->cr();
duke@435 96 }
duke@435 97
jmasa@3294 98 // GC workers get tasks from the GCTaskManager and execute
jmasa@3294 99 // them in this method. If there are no tasks to execute,
jmasa@3294 100 // the GC workers wait in the GCTaskManager's get_task()
jmasa@3294 101 // for tasks to be enqueued for execution.
jmasa@3294 102
duke@435 103 void GCTaskThread::run() {
duke@435 104 // Set up the thread for stack overflow support
duke@435 105 this->record_stack_base_and_size();
duke@435 106 this->initialize_thread_local_storage();
duke@435 107 // Bind yourself to your processor.
duke@435 108 if (processor_id() != GCTaskManager::sentinel_worker()) {
duke@435 109 if (TraceGCTaskThread) {
duke@435 110 tty->print_cr("GCTaskThread::run: "
duke@435 111 " binding to processor %u", processor_id());
duke@435 112 }
duke@435 113 if (!os::bind_to_processor(processor_id())) {
duke@435 114 DEBUG_ONLY(
duke@435 115 warning("Couldn't bind GCTaskThread %u to processor %u",
duke@435 116 which(), processor_id());
duke@435 117 )
duke@435 118 }
duke@435 119 }
duke@435 120 // Part of thread setup.
duke@435 121 // ??? Are these set up once here to make subsequent ones fast?
duke@435 122 HandleMark hm_outer;
duke@435 123 ResourceMark rm_outer;
duke@435 124
duke@435 125 TimeStamp timer;
duke@435 126
duke@435 127 for (;/* ever */;) {
duke@435 128 // These are so we can flush the resources allocated in the inner loop.
duke@435 129 HandleMark hm_inner;
duke@435 130 ResourceMark rm_inner;
duke@435 131 for (; /* break */; ) {
duke@435 132 // This will block until there is a task to be gotten.
duke@435 133 GCTask* task = manager()->get_task(which());
jmasa@3328 134 // Record if this is an idle task for later use.
jmasa@3328 135 bool is_idle_task = task->is_idle_task();
duke@435 136 // In case the update is costly
duke@435 137 if (PrintGCTaskTimeStamps) {
duke@435 138 timer.update();
duke@435 139 }
duke@435 140
duke@435 141 jlong entry_time = timer.ticks();
duke@435 142 char* name = task->name();
duke@435 143
jmasa@3328 144 // If this is the barrier task, it can be destroyed
jmasa@3328 145 // by the GC task manager once the do_it() executes.
duke@435 146 task->do_it(manager(), which());
duke@435 147
jmasa@3328 148 // Use the saved value of is_idle_task because references
jmasa@3328 149 // using "task" are not reliable for the barrier task.
jmasa@3328 150 if (!is_idle_task) {
jmasa@3294 151 manager()->note_completion(which());
duke@435 152
jmasa@3294 153 if (PrintGCTaskTimeStamps) {
jmasa@3294 154 assert(_time_stamps != NULL,
jmasa@3294 155 "Sanity (PrintGCTaskTimeStamps set late?)");
duke@435 156
jmasa@3294 157 timer.update();
duke@435 158
jmasa@3294 159 GCTaskTimeStamp* time_stamp = time_stamp_at(_time_stamp_index++);
jmasa@3294 160
jmasa@3294 161 time_stamp->set_name(name);
jmasa@3294 162 time_stamp->set_entry_time(entry_time);
jmasa@3294 163 time_stamp->set_exit_time(timer.ticks());
jmasa@3294 164 }
jmasa@3294 165 } else {
jmasa@3294 166 // idle tasks complete outside the normal accounting
jmasa@3294 167 // so that a task can complete without waiting for idle tasks.
jmasa@3294 168 // They have to be terminated separately.
jmasa@3294 169 IdleGCTask::destroy((IdleGCTask*)task);
jmasa@3294 170 set_is_working(true);
duke@435 171 }
duke@435 172
duke@435 173 // Check if we should release our inner resources.
duke@435 174 if (manager()->should_release_resources(which())) {
duke@435 175 manager()->note_release(which());
duke@435 176 break;
duke@435 177 }
duke@435 178 }
duke@435 179 }
duke@435 180 }

mercurial