Thu, 14 Mar 2013 09:37:38 +0100
6733980: par compact - TraceGen1Time always shows 0.0000 seconds
Summary: Use the correct collector to retrieve accumulated gen1 trace time
Reviewed-by: johnc, jmasa
duke@435 | 1 | |
duke@435 | 2 | /* |
mikael@4153 | 3 | * Copyright (c) 2002, 2012, 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 | |
duke@435 | 37 | GCTaskThread::GCTaskThread(GCTaskManager* manager, |
duke@435 | 38 | uint which, |
duke@435 | 39 | uint processor_id) : |
duke@435 | 40 | _manager(manager), |
duke@435 | 41 | _processor_id(processor_id), |
duke@435 | 42 | _time_stamps(NULL), |
duke@435 | 43 | _time_stamp_index(0) |
duke@435 | 44 | { |
duke@435 | 45 | if (!os::create_thread(this, os::pgc_thread)) |
duke@435 | 46 | vm_exit_out_of_memory(0, "Cannot create GC thread. Out of system resources."); |
duke@435 | 47 | |
duke@435 | 48 | if (PrintGCTaskTimeStamps) { |
zgu@3900 | 49 | _time_stamps = NEW_C_HEAP_ARRAY(GCTaskTimeStamp, GCTaskTimeStampEntries, mtGC); |
duke@435 | 50 | |
duke@435 | 51 | guarantee(_time_stamps != NULL, "Sanity"); |
duke@435 | 52 | } |
duke@435 | 53 | set_id(which); |
duke@435 | 54 | set_name("GC task thread#%d (ParallelGC)", which); |
duke@435 | 55 | } |
duke@435 | 56 | |
duke@435 | 57 | GCTaskThread::~GCTaskThread() { |
duke@435 | 58 | if (_time_stamps != NULL) { |
zgu@3900 | 59 | FREE_C_HEAP_ARRAY(GCTaskTimeStamp, _time_stamps, mtGC); |
duke@435 | 60 | } |
duke@435 | 61 | } |
duke@435 | 62 | |
duke@435 | 63 | void GCTaskThread::start() { |
duke@435 | 64 | os::start_thread(this); |
duke@435 | 65 | } |
duke@435 | 66 | |
duke@435 | 67 | GCTaskTimeStamp* GCTaskThread::time_stamp_at(uint index) { |
duke@435 | 68 | guarantee(index < GCTaskTimeStampEntries, "increase GCTaskTimeStampEntries"); |
duke@435 | 69 | |
duke@435 | 70 | return &(_time_stamps[index]); |
duke@435 | 71 | } |
duke@435 | 72 | |
duke@435 | 73 | void GCTaskThread::print_task_time_stamps() { |
duke@435 | 74 | assert(PrintGCTaskTimeStamps, "Sanity"); |
duke@435 | 75 | assert(_time_stamps != NULL, "Sanity (Probably set PrintGCTaskTimeStamps late)"); |
duke@435 | 76 | |
duke@435 | 77 | tty->print_cr("GC-Thread %u entries: %d", id(), _time_stamp_index); |
duke@435 | 78 | for(uint i=0; i<_time_stamp_index; i++) { |
duke@435 | 79 | GCTaskTimeStamp* time_stamp = time_stamp_at(i); |
duke@435 | 80 | tty->print_cr("\t[ %s " INT64_FORMAT " " INT64_FORMAT " ]", |
duke@435 | 81 | time_stamp->name(), |
duke@435 | 82 | time_stamp->entry_time(), |
duke@435 | 83 | time_stamp->exit_time()); |
duke@435 | 84 | } |
duke@435 | 85 | |
duke@435 | 86 | // Reset after dumping the data |
duke@435 | 87 | _time_stamp_index = 0; |
duke@435 | 88 | } |
duke@435 | 89 | |
duke@435 | 90 | void GCTaskThread::print_on(outputStream* st) const { |
duke@435 | 91 | st->print("\"%s\" ", name()); |
duke@435 | 92 | Thread::print_on(st); |
duke@435 | 93 | st->cr(); |
duke@435 | 94 | } |
duke@435 | 95 | |
jmasa@3294 | 96 | // GC workers get tasks from the GCTaskManager and execute |
jmasa@3294 | 97 | // them in this method. If there are no tasks to execute, |
jmasa@3294 | 98 | // the GC workers wait in the GCTaskManager's get_task() |
jmasa@3294 | 99 | // for tasks to be enqueued for execution. |
jmasa@3294 | 100 | |
duke@435 | 101 | void GCTaskThread::run() { |
duke@435 | 102 | // Set up the thread for stack overflow support |
duke@435 | 103 | this->record_stack_base_and_size(); |
duke@435 | 104 | this->initialize_thread_local_storage(); |
duke@435 | 105 | // Bind yourself to your processor. |
duke@435 | 106 | if (processor_id() != GCTaskManager::sentinel_worker()) { |
duke@435 | 107 | if (TraceGCTaskThread) { |
duke@435 | 108 | tty->print_cr("GCTaskThread::run: " |
duke@435 | 109 | " binding to processor %u", processor_id()); |
duke@435 | 110 | } |
duke@435 | 111 | if (!os::bind_to_processor(processor_id())) { |
duke@435 | 112 | DEBUG_ONLY( |
duke@435 | 113 | warning("Couldn't bind GCTaskThread %u to processor %u", |
duke@435 | 114 | which(), processor_id()); |
duke@435 | 115 | ) |
duke@435 | 116 | } |
duke@435 | 117 | } |
duke@435 | 118 | // Part of thread setup. |
duke@435 | 119 | // ??? Are these set up once here to make subsequent ones fast? |
duke@435 | 120 | HandleMark hm_outer; |
duke@435 | 121 | ResourceMark rm_outer; |
duke@435 | 122 | |
duke@435 | 123 | TimeStamp timer; |
duke@435 | 124 | |
duke@435 | 125 | for (;/* ever */;) { |
duke@435 | 126 | // These are so we can flush the resources allocated in the inner loop. |
duke@435 | 127 | HandleMark hm_inner; |
duke@435 | 128 | ResourceMark rm_inner; |
duke@435 | 129 | for (; /* break */; ) { |
duke@435 | 130 | // This will block until there is a task to be gotten. |
duke@435 | 131 | GCTask* task = manager()->get_task(which()); |
jmasa@3328 | 132 | // Record if this is an idle task for later use. |
jmasa@3328 | 133 | bool is_idle_task = task->is_idle_task(); |
duke@435 | 134 | // In case the update is costly |
duke@435 | 135 | if (PrintGCTaskTimeStamps) { |
duke@435 | 136 | timer.update(); |
duke@435 | 137 | } |
duke@435 | 138 | |
duke@435 | 139 | jlong entry_time = timer.ticks(); |
duke@435 | 140 | char* name = task->name(); |
duke@435 | 141 | |
jmasa@3328 | 142 | // If this is the barrier task, it can be destroyed |
jmasa@3328 | 143 | // by the GC task manager once the do_it() executes. |
duke@435 | 144 | task->do_it(manager(), which()); |
duke@435 | 145 | |
jmasa@3328 | 146 | // Use the saved value of is_idle_task because references |
jmasa@3328 | 147 | // using "task" are not reliable for the barrier task. |
jmasa@3328 | 148 | if (!is_idle_task) { |
jmasa@3294 | 149 | manager()->note_completion(which()); |
duke@435 | 150 | |
jmasa@3294 | 151 | if (PrintGCTaskTimeStamps) { |
jmasa@3294 | 152 | assert(_time_stamps != NULL, |
jmasa@3294 | 153 | "Sanity (PrintGCTaskTimeStamps set late?)"); |
duke@435 | 154 | |
jmasa@3294 | 155 | timer.update(); |
duke@435 | 156 | |
jmasa@3294 | 157 | GCTaskTimeStamp* time_stamp = time_stamp_at(_time_stamp_index++); |
jmasa@3294 | 158 | |
jmasa@3294 | 159 | time_stamp->set_name(name); |
jmasa@3294 | 160 | time_stamp->set_entry_time(entry_time); |
jmasa@3294 | 161 | time_stamp->set_exit_time(timer.ticks()); |
jmasa@3294 | 162 | } |
jmasa@3294 | 163 | } else { |
jmasa@3294 | 164 | // idle tasks complete outside the normal accounting |
jmasa@3294 | 165 | // so that a task can complete without waiting for idle tasks. |
jmasa@3294 | 166 | // They have to be terminated separately. |
jmasa@3294 | 167 | IdleGCTask::destroy((IdleGCTask*)task); |
jmasa@3294 | 168 | set_is_working(true); |
duke@435 | 169 | } |
duke@435 | 170 | |
duke@435 | 171 | // Check if we should release our inner resources. |
duke@435 | 172 | if (manager()->should_release_resources(which())) { |
duke@435 | 173 | manager()->note_release(which()); |
duke@435 | 174 | break; |
duke@435 | 175 | } |
duke@435 | 176 | } |
duke@435 | 177 | } |
duke@435 | 178 | } |