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

changeset 435
a61af66fc99e
child 1907
c18cbe5936b8
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/gc_implementation/parallelScavenge/gcTaskThread.cpp	Sat Dec 01 00:00:00 2007 +0000
     1.3 @@ -0,0 +1,150 @@
     1.4 +
     1.5 +/*
     1.6 + * Copyright 2002-2007 Sun Microsystems, Inc.  All Rights Reserved.
     1.7 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.8 + *
     1.9 + * This code is free software; you can redistribute it and/or modify it
    1.10 + * under the terms of the GNU General Public License version 2 only, as
    1.11 + * published by the Free Software Foundation.
    1.12 + *
    1.13 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.14 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.15 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.16 + * version 2 for more details (a copy is included in the LICENSE file that
    1.17 + * accompanied this code).
    1.18 + *
    1.19 + * You should have received a copy of the GNU General Public License version
    1.20 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.21 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.22 + *
    1.23 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    1.24 + * CA 95054 USA or visit www.sun.com if you need additional information or
    1.25 + * have any questions.
    1.26 + *
    1.27 + */
    1.28 +
    1.29 +#include "incls/_precompiled.incl"
    1.30 +#include "incls/_gcTaskThread.cpp.incl"
    1.31 +
    1.32 +GCTaskThread::GCTaskThread(GCTaskManager* manager,
    1.33 +                           uint           which,
    1.34 +                           uint           processor_id) :
    1.35 +  _manager(manager),
    1.36 +  _processor_id(processor_id),
    1.37 +  _time_stamps(NULL),
    1.38 +  _time_stamp_index(0)
    1.39 +{
    1.40 +  if (!os::create_thread(this, os::pgc_thread))
    1.41 +    vm_exit_out_of_memory(0, "Cannot create GC thread. Out of system resources.");
    1.42 +
    1.43 +  if (PrintGCTaskTimeStamps) {
    1.44 +    _time_stamps = NEW_C_HEAP_ARRAY(GCTaskTimeStamp, GCTaskTimeStampEntries );
    1.45 +
    1.46 +    guarantee(_time_stamps != NULL, "Sanity");
    1.47 +  }
    1.48 +  set_id(which);
    1.49 +  set_name("GC task thread#%d (ParallelGC)", which);
    1.50 +}
    1.51 +
    1.52 +GCTaskThread::~GCTaskThread() {
    1.53 +  if (_time_stamps != NULL) {
    1.54 +    FREE_C_HEAP_ARRAY(GCTaskTimeStamp, _time_stamps);
    1.55 +  }
    1.56 +}
    1.57 +
    1.58 +void GCTaskThread::start() {
    1.59 +  os::start_thread(this);
    1.60 +}
    1.61 +
    1.62 +GCTaskTimeStamp* GCTaskThread::time_stamp_at(uint index) {
    1.63 +  guarantee(index < GCTaskTimeStampEntries, "increase GCTaskTimeStampEntries");
    1.64 +
    1.65 +  return &(_time_stamps[index]);
    1.66 +}
    1.67 +
    1.68 +void GCTaskThread::print_task_time_stamps() {
    1.69 +  assert(PrintGCTaskTimeStamps, "Sanity");
    1.70 +  assert(_time_stamps != NULL, "Sanity (Probably set PrintGCTaskTimeStamps late)");
    1.71 +
    1.72 +  tty->print_cr("GC-Thread %u entries: %d", id(), _time_stamp_index);
    1.73 +  for(uint i=0; i<_time_stamp_index; i++) {
    1.74 +    GCTaskTimeStamp* time_stamp = time_stamp_at(i);
    1.75 +    tty->print_cr("\t[ %s " INT64_FORMAT " " INT64_FORMAT " ]",
    1.76 +                  time_stamp->name(),
    1.77 +                  time_stamp->entry_time(),
    1.78 +                  time_stamp->exit_time());
    1.79 +  }
    1.80 +
    1.81 +  // Reset after dumping the data
    1.82 +  _time_stamp_index = 0;
    1.83 +}
    1.84 +
    1.85 +void GCTaskThread::print_on(outputStream* st) const {
    1.86 +  st->print("\"%s\" ", name());
    1.87 +  Thread::print_on(st);
    1.88 +  st->cr();
    1.89 +}
    1.90 +
    1.91 +void GCTaskThread::run() {
    1.92 +  // Set up the thread for stack overflow support
    1.93 +  this->record_stack_base_and_size();
    1.94 +  this->initialize_thread_local_storage();
    1.95 +  // Bind yourself to your processor.
    1.96 +  if (processor_id() != GCTaskManager::sentinel_worker()) {
    1.97 +    if (TraceGCTaskThread) {
    1.98 +      tty->print_cr("GCTaskThread::run: "
    1.99 +                    "  binding to processor %u", processor_id());
   1.100 +    }
   1.101 +    if (!os::bind_to_processor(processor_id())) {
   1.102 +      DEBUG_ONLY(
   1.103 +        warning("Couldn't bind GCTaskThread %u to processor %u",
   1.104 +                      which(), processor_id());
   1.105 +      )
   1.106 +    }
   1.107 +  }
   1.108 +  // Part of thread setup.
   1.109 +  // ??? Are these set up once here to make subsequent ones fast?
   1.110 +  HandleMark   hm_outer;
   1.111 +  ResourceMark rm_outer;
   1.112 +
   1.113 +  TimeStamp timer;
   1.114 +
   1.115 +  for (;/* ever */;) {
   1.116 +    // These are so we can flush the resources allocated in the inner loop.
   1.117 +    HandleMark   hm_inner;
   1.118 +    ResourceMark rm_inner;
   1.119 +    for (; /* break */; ) {
   1.120 +      // This will block until there is a task to be gotten.
   1.121 +      GCTask* task = manager()->get_task(which());
   1.122 +
   1.123 +      // In case the update is costly
   1.124 +      if (PrintGCTaskTimeStamps) {
   1.125 +        timer.update();
   1.126 +      }
   1.127 +
   1.128 +      jlong entry_time = timer.ticks();
   1.129 +      char* name = task->name();
   1.130 +
   1.131 +      task->do_it(manager(), which());
   1.132 +      manager()->note_completion(which());
   1.133 +
   1.134 +      if (PrintGCTaskTimeStamps) {
   1.135 +        assert(_time_stamps != NULL, "Sanity (PrintGCTaskTimeStamps set late?)");
   1.136 +
   1.137 +        timer.update();
   1.138 +
   1.139 +        GCTaskTimeStamp* time_stamp = time_stamp_at(_time_stamp_index++);
   1.140 +
   1.141 +        time_stamp->set_name(name);
   1.142 +        time_stamp->set_entry_time(entry_time);
   1.143 +        time_stamp->set_exit_time(timer.ticks());
   1.144 +      }
   1.145 +
   1.146 +      // Check if we should release our inner resources.
   1.147 +      if (manager()->should_release_resources(which())) {
   1.148 +        manager()->note_release(which());
   1.149 +        break;
   1.150 +      }
   1.151 +    }
   1.152 +  }
   1.153 +}

mercurial