void GCTaskThread::print_task_time_stamps() {
  assert(PrintGCTaskTimeStamps, "Sanity");
  assert(_time_stamps != NULL, "Sanity (Probably set PrintGCTaskTimeStamps late)");

  tty->print_cr("GC-Thread %u entries: %d", id(), _time_stamp_index);
  for(uint i=0; i<_time_stamp_index; i++) {
    GCTaskTimeStamp* time_stamp = time_stamp_at(i);
    tty->print_cr("\t[ %s " INT64_FORMAT " " INT64_FORMAT " ]",
                  time_stamp->name(),
                  time_stamp->entry_time(),
                  time_stamp->exit_time());
  }

  // Reset after dumping the data
  _time_stamp_index = 0;
}
void GCTaskThread::print_task_time_stamps() {
  assert(PrintGCTaskTimeStamps, "Sanity");
  assert(_time_stamps != NULL, "Sanity (Probably set PrintGCTaskTimeStamps late)");

gclog_or_tty->print_cr("GC-Thread %u entries: %d",id(),_time_stamp_index);
  for(uint i=0; i<_time_stamp_index; i++) {
    GCTaskTimeStamp* time_stamp = time_stamp_at(i);
    if ( 1 ) {
gclog_or_tty->print_cr("\t[ %s %lld %lld %lld usecs ]",
                    time_stamp->name(),
                    time_stamp->entry_time(),
time_stamp->exit_time(),
                    ((time_stamp->exit_time()-time_stamp->entry_time())*1000000)/os::elapsed_frequency());
    } else {
gclog_or_tty->print_cr("\t[ %s %lld %lld ]",
                    time_stamp->name(),
                    time_stamp->entry_time(),
                    time_stamp->exit_time());
    }
  }

  // Reset after dumping the data
  _time_stamp_index = 0;
}
void GCTaskThread::run() {
  // Set up the thread for stack overflow support
  this->initialize_thread_local_storage();
  this->set_gcthread_lvb_trap_vector();
  this->set_gc_mode(true);
  this->set_vm_tag(VM_GCTask_tag);

  // Part of thread setup.
  // ??? Are these set up once here to make subsequent ones fast?
  HandleMark   hm_outer;
  ResourceMark rm_outer; 
 
  if ( manager()->gpgc_verify() ) {
    GPGC_VerifyClosure::task_thread_loop(this, which());
    return;
  }

  TimeStamp timer;

  for (;/* ever */;) {
    // These are so we can flush the resources allocated in the inner loop.
    HandleMark   hm_inner;
    ResourceMark rm_inner;
    for (; /* break */; ) {
      // This will block until there is a task to be gotten.
      GCTask* task = manager()->get_task(which());

      if ( _new_gc_mode_requested ) {
        _new_gc_mode_requested = false;
        this->set_gc_mode(_new_gc_mode);
      }
      // In case the update is costly
      if (PrintGCTaskTimeStamps) {
        timer.update();
      }

      jlong entry_time = timer.ticks();
const char*name=task->name();

      GCTask::Kind::kind task_kind = task->kind();
      task->do_it(manager(), which());
manager()->note_completion(task_kind,which());

      if (PrintGCTaskTimeStamps) {
        assert(_time_stamps != NULL, "Sanity (PrintGCTaskTimeStamps set late?)");

        timer.update();

        GCTaskTimeStamp* time_stamp = time_stamp_at(_time_stamp_index++);

        time_stamp->set_name(name);
        time_stamp->set_entry_time(entry_time);
        time_stamp->set_exit_time(timer.ticks());
      }

      // Check if we should release our inner resources.
      if (manager()->should_release_resources(which())) {
        manager()->note_release(which());
        break;
      }
    }
  }
}