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

Mon, 09 Mar 2009 13:28:46 -0700

author
xdono
date
Mon, 09 Mar 2009 13:28:46 -0700
changeset 1014
0fbdb4381b99
parent 435
a61af66fc99e
child 1907
c18cbe5936b8
permissions
-rw-r--r--

6814575: Update copyright year
Summary: Update copyright for files that have been modified in 2009, up to 03/09
Reviewed-by: katleman, tbell, ohair

     2 /*
     3  * Copyright 2002-2007 Sun Microsystems, Inc.  All Rights Reserved.
     4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     5  *
     6  * This code is free software; you can redistribute it and/or modify it
     7  * under the terms of the GNU General Public License version 2 only, as
     8  * published by the Free Software Foundation.
     9  *
    10  * This code is distributed in the hope that it will be useful, but WITHOUT
    11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    13  * version 2 for more details (a copy is included in the LICENSE file that
    14  * accompanied this code).
    15  *
    16  * You should have received a copy of the GNU General Public License version
    17  * 2 along with this work; if not, write to the Free Software Foundation,
    18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    19  *
    20  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    21  * CA 95054 USA or visit www.sun.com if you need additional information or
    22  * have any questions.
    23  *
    24  */
    26 #include "incls/_precompiled.incl"
    27 #include "incls/_gcTaskThread.cpp.incl"
    29 GCTaskThread::GCTaskThread(GCTaskManager* manager,
    30                            uint           which,
    31                            uint           processor_id) :
    32   _manager(manager),
    33   _processor_id(processor_id),
    34   _time_stamps(NULL),
    35   _time_stamp_index(0)
    36 {
    37   if (!os::create_thread(this, os::pgc_thread))
    38     vm_exit_out_of_memory(0, "Cannot create GC thread. Out of system resources.");
    40   if (PrintGCTaskTimeStamps) {
    41     _time_stamps = NEW_C_HEAP_ARRAY(GCTaskTimeStamp, GCTaskTimeStampEntries );
    43     guarantee(_time_stamps != NULL, "Sanity");
    44   }
    45   set_id(which);
    46   set_name("GC task thread#%d (ParallelGC)", which);
    47 }
    49 GCTaskThread::~GCTaskThread() {
    50   if (_time_stamps != NULL) {
    51     FREE_C_HEAP_ARRAY(GCTaskTimeStamp, _time_stamps);
    52   }
    53 }
    55 void GCTaskThread::start() {
    56   os::start_thread(this);
    57 }
    59 GCTaskTimeStamp* GCTaskThread::time_stamp_at(uint index) {
    60   guarantee(index < GCTaskTimeStampEntries, "increase GCTaskTimeStampEntries");
    62   return &(_time_stamps[index]);
    63 }
    65 void GCTaskThread::print_task_time_stamps() {
    66   assert(PrintGCTaskTimeStamps, "Sanity");
    67   assert(_time_stamps != NULL, "Sanity (Probably set PrintGCTaskTimeStamps late)");
    69   tty->print_cr("GC-Thread %u entries: %d", id(), _time_stamp_index);
    70   for(uint i=0; i<_time_stamp_index; i++) {
    71     GCTaskTimeStamp* time_stamp = time_stamp_at(i);
    72     tty->print_cr("\t[ %s " INT64_FORMAT " " INT64_FORMAT " ]",
    73                   time_stamp->name(),
    74                   time_stamp->entry_time(),
    75                   time_stamp->exit_time());
    76   }
    78   // Reset after dumping the data
    79   _time_stamp_index = 0;
    80 }
    82 void GCTaskThread::print_on(outputStream* st) const {
    83   st->print("\"%s\" ", name());
    84   Thread::print_on(st);
    85   st->cr();
    86 }
    88 void GCTaskThread::run() {
    89   // Set up the thread for stack overflow support
    90   this->record_stack_base_and_size();
    91   this->initialize_thread_local_storage();
    92   // Bind yourself to your processor.
    93   if (processor_id() != GCTaskManager::sentinel_worker()) {
    94     if (TraceGCTaskThread) {
    95       tty->print_cr("GCTaskThread::run: "
    96                     "  binding to processor %u", processor_id());
    97     }
    98     if (!os::bind_to_processor(processor_id())) {
    99       DEBUG_ONLY(
   100         warning("Couldn't bind GCTaskThread %u to processor %u",
   101                       which(), processor_id());
   102       )
   103     }
   104   }
   105   // Part of thread setup.
   106   // ??? Are these set up once here to make subsequent ones fast?
   107   HandleMark   hm_outer;
   108   ResourceMark rm_outer;
   110   TimeStamp timer;
   112   for (;/* ever */;) {
   113     // These are so we can flush the resources allocated in the inner loop.
   114     HandleMark   hm_inner;
   115     ResourceMark rm_inner;
   116     for (; /* break */; ) {
   117       // This will block until there is a task to be gotten.
   118       GCTask* task = manager()->get_task(which());
   120       // In case the update is costly
   121       if (PrintGCTaskTimeStamps) {
   122         timer.update();
   123       }
   125       jlong entry_time = timer.ticks();
   126       char* name = task->name();
   128       task->do_it(manager(), which());
   129       manager()->note_completion(which());
   131       if (PrintGCTaskTimeStamps) {
   132         assert(_time_stamps != NULL, "Sanity (PrintGCTaskTimeStamps set late?)");
   134         timer.update();
   136         GCTaskTimeStamp* time_stamp = time_stamp_at(_time_stamp_index++);
   138         time_stamp->set_name(name);
   139         time_stamp->set_entry_time(entry_time);
   140         time_stamp->set_exit_time(timer.ticks());
   141       }
   143       // Check if we should release our inner resources.
   144       if (manager()->should_release_resources(which())) {
   145         manager()->note_release(which());
   146         break;
   147       }
   148     }
   149   }
   150 }

mercurial