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