hotspot/src/share/vm/gc/parallel/gcTaskThread.cpp
author dholmes
Fri, 04 Dec 2015 04:06:37 -0500
changeset 34633 2a6c7c7b30a7
parent 33126 260ff671354b
child 35061 be6025ebffea
permissions -rw-r--r--
8132510: Replace ThreadLocalStorage with compiler/language-based thread-local variables Summary: Used compiled-based TLS when available. Additional contributions by Thomas Stufe (AIX) and Andrew Haley (Aarch64) Reviewed-by: stuefe, bdelsart, dcubed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
29326
ebaa169c6dc3 8073464: GC workers do not have thread names
david
parents: 27880
diff changeset
     2
 * Copyright (c) 2002, 2015, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    20
 * 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
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    25
#include "precompiled.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 29798
diff changeset
    26
#include "gc/parallel/gcTaskManager.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 29798
diff changeset
    27
#include "gc/parallel/gcTaskThread.hpp"
33126
260ff671354b 8138707: TestPromotionEventWithParallelScavenge.java crashes using undefined GC id.
brutisso
parents: 30764
diff changeset
    28
#include "gc/shared/gcId.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
#include "memory/allocation.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    30
#include "memory/allocation.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    31
#include "memory/resourceArea.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    32
#include "runtime/handles.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    33
#include "runtime/handles.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    34
#include "runtime/os.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    35
#include "runtime/thread.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
GCTaskThread::GCTaskThread(GCTaskManager* manager,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
                           uint           which,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
                           uint           processor_id) :
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  _manager(manager),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  _processor_id(processor_id),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  _time_stamps(NULL),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  _time_stamp_index(0)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  if (!os::create_thread(this, os::pgc_thread))
17087
f0b76c4c93a0 8011661: Insufficient memory message says "malloc" when sometimes it should say "mmap"
ccheung
parents: 13963
diff changeset
    46
    vm_exit_out_of_memory(0, OOM_MALLOC_ERROR, "Cannot create GC thread. Out of system resources.");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  if (PrintGCTaskTimeStamps) {
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 11208
diff changeset
    49
    _time_stamps = NEW_C_HEAP_ARRAY(GCTaskTimeStamp, GCTaskTimeStampEntries, mtGC);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
    guarantee(_time_stamps != NULL, "Sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  set_id(which);
29464
02c245ad3ec9 8073545: Use shorter and more descriptive names for GC worker threads
david
parents: 29326
diff changeset
    54
  set_name("ParGC Thread#%d", which);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
GCTaskThread::~GCTaskThread() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  if (_time_stamps != NULL) {
27880
afb974a04396 8060074: os::free() takes MemoryTrackingLevel but doesn't need it
coleenp
parents: 24424
diff changeset
    59
    FREE_C_HEAP_ARRAY(GCTaskTimeStamp, _time_stamps);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
void GCTaskThread::start() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  os::start_thread(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
GCTaskTimeStamp* GCTaskThread::time_stamp_at(uint index) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  guarantee(index < GCTaskTimeStampEntries, "increase GCTaskTimeStampEntries");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  return &(_time_stamps[index]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
void GCTaskThread::print_task_time_stamps() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  assert(PrintGCTaskTimeStamps, "Sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  assert(_time_stamps != NULL, "Sanity (Probably set PrintGCTaskTimeStamps late)");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  tty->print_cr("GC-Thread %u entries: %d", id(), _time_stamp_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  for(uint i=0; i<_time_stamp_index; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
    GCTaskTimeStamp* time_stamp = time_stamp_at(i);
29798
451c73fdf690 8076071: parallelScavenge: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 29464
diff changeset
    80
    tty->print_cr("\t[ %s " JLONG_FORMAT " " JLONG_FORMAT " ]",
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
                  time_stamp->name(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
                  time_stamp->entry_time(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
                  time_stamp->exit_time());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  // Reset after dumping the data
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  _time_stamp_index = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
11174
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
    90
// GC workers get tasks from the GCTaskManager and execute
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
    91
// them in this method.  If there are no tasks to execute,
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
    92
// the GC workers wait in the GCTaskManager's get_task()
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
    93
// for tasks to be enqueued for execution.
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
    94
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
void GCTaskThread::run() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  // Set up the thread for stack overflow support
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  this->record_stack_base_and_size();
29326
ebaa169c6dc3 8073464: GC workers do not have thread names
david
parents: 27880
diff changeset
    98
  this->initialize_named_thread();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  // Bind yourself to your processor.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  if (processor_id() != GCTaskManager::sentinel_worker()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
    if (TraceGCTaskThread) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
      tty->print_cr("GCTaskThread::run: "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
                    "  binding to processor %u", processor_id());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
    if (!os::bind_to_processor(processor_id())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
      DEBUG_ONLY(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
        warning("Couldn't bind GCTaskThread %u to processor %u",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
                      which(), processor_id());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
      )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  // Part of thread setup.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  // ??? Are these set up once here to make subsequent ones fast?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  HandleMark   hm_outer;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  ResourceMark rm_outer;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  TimeStamp timer;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  for (;/* ever */;) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
    // These are so we can flush the resources allocated in the inner loop.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
    HandleMark   hm_inner;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
    ResourceMark rm_inner;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
    for (; /* break */; ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
      // This will block until there is a task to be gotten.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
      GCTask* task = manager()->get_task(which());
33126
260ff671354b 8138707: TestPromotionEventWithParallelScavenge.java crashes using undefined GC id.
brutisso
parents: 30764
diff changeset
   126
      GCIdMark gc_id_mark(task->gc_id());
11208
101816314520 7119584: UseParallelGC barrier task can be overwritten.
jmasa
parents: 11174
diff changeset
   127
      // Record if this is an idle task for later use.
101816314520 7119584: UseParallelGC barrier task can be overwritten.
jmasa
parents: 11174
diff changeset
   128
      bool is_idle_task = task->is_idle_task();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
      // In case the update is costly
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
      if (PrintGCTaskTimeStamps) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
        timer.update();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
      jlong entry_time = timer.ticks();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
      char* name = task->name();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
11208
101816314520 7119584: UseParallelGC barrier task can be overwritten.
jmasa
parents: 11174
diff changeset
   137
      // If this is the barrier task, it can be destroyed
101816314520 7119584: UseParallelGC barrier task can be overwritten.
jmasa
parents: 11174
diff changeset
   138
      // by the GC task manager once the do_it() executes.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
      task->do_it(manager(), which());
11174
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   140
11208
101816314520 7119584: UseParallelGC barrier task can be overwritten.
jmasa
parents: 11174
diff changeset
   141
      // Use the saved value of is_idle_task because references
101816314520 7119584: UseParallelGC barrier task can be overwritten.
jmasa
parents: 11174
diff changeset
   142
      // using "task" are not reliable for the barrier task.
101816314520 7119584: UseParallelGC barrier task can be overwritten.
jmasa
parents: 11174
diff changeset
   143
      if (!is_idle_task) {
11174
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   144
        manager()->note_completion(which());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
11174
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   146
        if (PrintGCTaskTimeStamps) {
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   147
          assert(_time_stamps != NULL,
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   148
            "Sanity (PrintGCTaskTimeStamps set late?)");
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   149
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   150
          timer.update();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
11174
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   152
          GCTaskTimeStamp* time_stamp = time_stamp_at(_time_stamp_index++);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
11174
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   154
          time_stamp->set_name(name);
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   155
          time_stamp->set_entry_time(entry_time);
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   156
          time_stamp->set_exit_time(timer.ticks());
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   157
        }
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   158
      } else {
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   159
        // idle tasks complete outside the normal accounting
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   160
        // so that a task can complete without waiting for idle tasks.
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   161
        // They have to be terminated separately.
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   162
        IdleGCTask::destroy((IdleGCTask*)task);
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   163
        set_is_working(true);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
      // Check if we should release our inner resources.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
      if (manager()->should_release_resources(which())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
        manager()->note_release(which());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
}