Fri, 16 Jul 2010 21:33:21 -0700
6962947: shared TaskQueue statistics
Reviewed-by: tonyp, ysr
duke@435 | 1 | |
duke@435 | 2 | /* |
trims@1907 | 3 | * Copyright (c) 2002, 2007, 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 | |
duke@435 | 26 | #include "incls/_precompiled.incl" |
duke@435 | 27 | #include "incls/_gcTaskThread.cpp.incl" |
duke@435 | 28 | |
duke@435 | 29 | GCTaskThread::GCTaskThread(GCTaskManager* manager, |
duke@435 | 30 | uint which, |
duke@435 | 31 | uint processor_id) : |
duke@435 | 32 | _manager(manager), |
duke@435 | 33 | _processor_id(processor_id), |
duke@435 | 34 | _time_stamps(NULL), |
duke@435 | 35 | _time_stamp_index(0) |
duke@435 | 36 | { |
duke@435 | 37 | if (!os::create_thread(this, os::pgc_thread)) |
duke@435 | 38 | vm_exit_out_of_memory(0, "Cannot create GC thread. Out of system resources."); |
duke@435 | 39 | |
duke@435 | 40 | if (PrintGCTaskTimeStamps) { |
duke@435 | 41 | _time_stamps = NEW_C_HEAP_ARRAY(GCTaskTimeStamp, GCTaskTimeStampEntries ); |
duke@435 | 42 | |
duke@435 | 43 | guarantee(_time_stamps != NULL, "Sanity"); |
duke@435 | 44 | } |
duke@435 | 45 | set_id(which); |
duke@435 | 46 | set_name("GC task thread#%d (ParallelGC)", which); |
duke@435 | 47 | } |
duke@435 | 48 | |
duke@435 | 49 | GCTaskThread::~GCTaskThread() { |
duke@435 | 50 | if (_time_stamps != NULL) { |
duke@435 | 51 | FREE_C_HEAP_ARRAY(GCTaskTimeStamp, _time_stamps); |
duke@435 | 52 | } |
duke@435 | 53 | } |
duke@435 | 54 | |
duke@435 | 55 | void GCTaskThread::start() { |
duke@435 | 56 | os::start_thread(this); |
duke@435 | 57 | } |
duke@435 | 58 | |
duke@435 | 59 | GCTaskTimeStamp* GCTaskThread::time_stamp_at(uint index) { |
duke@435 | 60 | guarantee(index < GCTaskTimeStampEntries, "increase GCTaskTimeStampEntries"); |
duke@435 | 61 | |
duke@435 | 62 | return &(_time_stamps[index]); |
duke@435 | 63 | } |
duke@435 | 64 | |
duke@435 | 65 | void GCTaskThread::print_task_time_stamps() { |
duke@435 | 66 | assert(PrintGCTaskTimeStamps, "Sanity"); |
duke@435 | 67 | assert(_time_stamps != NULL, "Sanity (Probably set PrintGCTaskTimeStamps late)"); |
duke@435 | 68 | |
duke@435 | 69 | tty->print_cr("GC-Thread %u entries: %d", id(), _time_stamp_index); |
duke@435 | 70 | for(uint i=0; i<_time_stamp_index; i++) { |
duke@435 | 71 | GCTaskTimeStamp* time_stamp = time_stamp_at(i); |
duke@435 | 72 | tty->print_cr("\t[ %s " INT64_FORMAT " " INT64_FORMAT " ]", |
duke@435 | 73 | time_stamp->name(), |
duke@435 | 74 | time_stamp->entry_time(), |
duke@435 | 75 | time_stamp->exit_time()); |
duke@435 | 76 | } |
duke@435 | 77 | |
duke@435 | 78 | // Reset after dumping the data |
duke@435 | 79 | _time_stamp_index = 0; |
duke@435 | 80 | } |
duke@435 | 81 | |
duke@435 | 82 | void GCTaskThread::print_on(outputStream* st) const { |
duke@435 | 83 | st->print("\"%s\" ", name()); |
duke@435 | 84 | Thread::print_on(st); |
duke@435 | 85 | st->cr(); |
duke@435 | 86 | } |
duke@435 | 87 | |
duke@435 | 88 | void GCTaskThread::run() { |
duke@435 | 89 | // Set up the thread for stack overflow support |
duke@435 | 90 | this->record_stack_base_and_size(); |
duke@435 | 91 | this->initialize_thread_local_storage(); |
duke@435 | 92 | // Bind yourself to your processor. |
duke@435 | 93 | if (processor_id() != GCTaskManager::sentinel_worker()) { |
duke@435 | 94 | if (TraceGCTaskThread) { |
duke@435 | 95 | tty->print_cr("GCTaskThread::run: " |
duke@435 | 96 | " binding to processor %u", processor_id()); |
duke@435 | 97 | } |
duke@435 | 98 | if (!os::bind_to_processor(processor_id())) { |
duke@435 | 99 | DEBUG_ONLY( |
duke@435 | 100 | warning("Couldn't bind GCTaskThread %u to processor %u", |
duke@435 | 101 | which(), processor_id()); |
duke@435 | 102 | ) |
duke@435 | 103 | } |
duke@435 | 104 | } |
duke@435 | 105 | // Part of thread setup. |
duke@435 | 106 | // ??? Are these set up once here to make subsequent ones fast? |
duke@435 | 107 | HandleMark hm_outer; |
duke@435 | 108 | ResourceMark rm_outer; |
duke@435 | 109 | |
duke@435 | 110 | TimeStamp timer; |
duke@435 | 111 | |
duke@435 | 112 | for (;/* ever */;) { |
duke@435 | 113 | // These are so we can flush the resources allocated in the inner loop. |
duke@435 | 114 | HandleMark hm_inner; |
duke@435 | 115 | ResourceMark rm_inner; |
duke@435 | 116 | for (; /* break */; ) { |
duke@435 | 117 | // This will block until there is a task to be gotten. |
duke@435 | 118 | GCTask* task = manager()->get_task(which()); |
duke@435 | 119 | |
duke@435 | 120 | // In case the update is costly |
duke@435 | 121 | if (PrintGCTaskTimeStamps) { |
duke@435 | 122 | timer.update(); |
duke@435 | 123 | } |
duke@435 | 124 | |
duke@435 | 125 | jlong entry_time = timer.ticks(); |
duke@435 | 126 | char* name = task->name(); |
duke@435 | 127 | |
duke@435 | 128 | task->do_it(manager(), which()); |
duke@435 | 129 | manager()->note_completion(which()); |
duke@435 | 130 | |
duke@435 | 131 | if (PrintGCTaskTimeStamps) { |
duke@435 | 132 | assert(_time_stamps != NULL, "Sanity (PrintGCTaskTimeStamps set late?)"); |
duke@435 | 133 | |
duke@435 | 134 | timer.update(); |
duke@435 | 135 | |
duke@435 | 136 | GCTaskTimeStamp* time_stamp = time_stamp_at(_time_stamp_index++); |
duke@435 | 137 | |
duke@435 | 138 | time_stamp->set_name(name); |
duke@435 | 139 | time_stamp->set_entry_time(entry_time); |
duke@435 | 140 | time_stamp->set_exit_time(timer.ticks()); |
duke@435 | 141 | } |
duke@435 | 142 | |
duke@435 | 143 | // Check if we should release our inner resources. |
duke@435 | 144 | if (manager()->should_release_resources(which())) { |
duke@435 | 145 | manager()->note_release(which()); |
duke@435 | 146 | break; |
duke@435 | 147 | } |
duke@435 | 148 | } |
duke@435 | 149 | } |
duke@435 | 150 | } |