hotspot/src/share/vm/gc/parallel/gcTaskManager.cpp
author stefank
Fri, 18 Mar 2016 08:59:07 +0100
changeset 37146 209e0fe518bb
parent 35061 be6025ebffea
child 37224 fd3320bf6413
permissions -rw-r--r--
8152100: Rework and unify the GC phase logging Reviewed-by: sjohanss, jwilhelm
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 29798
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"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 29798
diff changeset
    28
#include "gc/shared/adaptiveSizePolicy.hpp"
33126
260ff671354b 8138707: TestPromotionEventWithParallelScavenge.java crashes using undefined GC id.
brutisso
parents: 33125
diff changeset
    29
#include "gc/shared/gcId.hpp"
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33126
diff changeset
    30
#include "logging/log.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    31
#include "memory/allocation.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    32
#include "memory/allocation.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    33
#include "runtime/mutex.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    34
#include "runtime/mutexLocker.hpp"
24351
61b33cc6d3cf 8042195: Introduce umbrella header orderAccess.inline.hpp.
goetz
parents: 24092
diff changeset
    35
#include "runtime/orderAccess.inline.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
// GCTask
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
const char* GCTask::Kind::to_string(kind value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  const char* result = "unknown GCTask kind";
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  switch (value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
    result = "unknown GCTask kind";
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  case unknown_task:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
    result = "unknown task";
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  case ordinary_task:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
    result = "ordinary task";
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
    break;
33124
e256f7a94c38 8138862: Remove some unused code and subclasses in gcTaskManager.hpp/cpp
brutisso
parents: 33105
diff changeset
    53
  case wait_for_barrier_task:
e256f7a94c38 8138862: Remove some unused code and subclasses in gcTaskManager.hpp/cpp
brutisso
parents: 33105
diff changeset
    54
    result = "wait for barrier task";
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  case noop_task:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
    result = "noop task";
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
    break;
11208
101816314520 7119584: UseParallelGC barrier task can be overwritten.
jmasa
parents: 11174
diff changeset
    59
  case idle_task:
101816314520 7119584: UseParallelGC barrier task can be overwritten.
jmasa
parents: 11174
diff changeset
    60
    result = "idle task";
101816314520 7119584: UseParallelGC barrier task can be overwritten.
jmasa
parents: 11174
diff changeset
    61
    break;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
33126
260ff671354b 8138707: TestPromotionEventWithParallelScavenge.java crashes using undefined GC id.
brutisso
parents: 33125
diff changeset
    66
GCTask::GCTask() {
260ff671354b 8138707: TestPromotionEventWithParallelScavenge.java crashes using undefined GC id.
brutisso
parents: 33125
diff changeset
    67
  initialize(Kind::ordinary_task, GCId::current());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
33126
260ff671354b 8138707: TestPromotionEventWithParallelScavenge.java crashes using undefined GC id.
brutisso
parents: 33125
diff changeset
    70
GCTask::GCTask(Kind::kind kind) {
260ff671354b 8138707: TestPromotionEventWithParallelScavenge.java crashes using undefined GC id.
brutisso
parents: 33125
diff changeset
    71
  initialize(kind, GCId::current());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
33126
260ff671354b 8138707: TestPromotionEventWithParallelScavenge.java crashes using undefined GC id.
brutisso
parents: 33125
diff changeset
    74
GCTask::GCTask(Kind::kind kind, uint gc_id) {
260ff671354b 8138707: TestPromotionEventWithParallelScavenge.java crashes using undefined GC id.
brutisso
parents: 33125
diff changeset
    75
  initialize(kind, gc_id);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
33126
260ff671354b 8138707: TestPromotionEventWithParallelScavenge.java crashes using undefined GC id.
brutisso
parents: 33125
diff changeset
    78
void GCTask::initialize(Kind::kind kind, uint gc_id) {
260ff671354b 8138707: TestPromotionEventWithParallelScavenge.java crashes using undefined GC id.
brutisso
parents: 33125
diff changeset
    79
  _kind = kind;
260ff671354b 8138707: TestPromotionEventWithParallelScavenge.java crashes using undefined GC id.
brutisso
parents: 33125
diff changeset
    80
  _affinity = GCTaskManager::sentinel_worker();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  _older = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  _newer = NULL;
33126
260ff671354b 8138707: TestPromotionEventWithParallelScavenge.java crashes using undefined GC id.
brutisso
parents: 33125
diff changeset
    83
  _gc_id = gc_id;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
void GCTask::destruct() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  assert(older() == NULL, "shouldn't have an older task");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  assert(newer() == NULL, "shouldn't have a newer task");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  // Nothing to do.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
NOT_PRODUCT(
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
void GCTask::print(const char* message) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  tty->print(INTPTR_FORMAT " <- " INTPTR_FORMAT "(%u) -> " INTPTR_FORMAT,
29798
451c73fdf690 8076071: parallelScavenge: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 28163
diff changeset
    95
             p2i(newer()), p2i(this), affinity(), p2i(older()));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
// GCTaskQueue
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
GCTaskQueue* GCTaskQueue::create() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  GCTaskQueue* result = new GCTaskQueue(false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  if (TraceGCTaskQueue) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
    tty->print_cr("GCTaskQueue::create()"
29798
451c73fdf690 8076071: parallelScavenge: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 28163
diff changeset
   107
                  " returns " INTPTR_FORMAT, p2i(result));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
GCTaskQueue* GCTaskQueue::create_on_c_heap() {
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 11208
diff changeset
   113
  GCTaskQueue* result = new(ResourceObj::C_HEAP, mtGC) GCTaskQueue(true);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  if (TraceGCTaskQueue) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
    tty->print_cr("GCTaskQueue::create_on_c_heap()"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
                  " returns " INTPTR_FORMAT,
29798
451c73fdf690 8076071: parallelScavenge: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 28163
diff changeset
   117
                  p2i(result));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
GCTaskQueue::GCTaskQueue(bool on_c_heap) :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  _is_c_heap_obj(on_c_heap) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  initialize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  if (TraceGCTaskQueue) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
    tty->print_cr("[" INTPTR_FORMAT "]"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
                  " GCTaskQueue::GCTaskQueue() constructor",
29798
451c73fdf690 8076071: parallelScavenge: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 28163
diff changeset
   128
                  p2i(this));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
void GCTaskQueue::destruct() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  // Nothing to do.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
void GCTaskQueue::destroy(GCTaskQueue* that) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  if (TraceGCTaskQueue) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
    tty->print_cr("[" INTPTR_FORMAT "]"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
                  " GCTaskQueue::destroy()"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
                  "  is_c_heap_obj:  %s",
29798
451c73fdf690 8076071: parallelScavenge: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 28163
diff changeset
   141
                  p2i(that),
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
                  that->is_c_heap_obj() ? "true" : "false");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  // That instance may have been allocated as a CHeapObj,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  // in which case we have to free it explicitly.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  if (that != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
    that->destruct();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
    assert(that->is_empty(), "should be empty");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
    if (that->is_c_heap_obj()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
      FreeHeap(that);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
void GCTaskQueue::initialize() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
  set_insert_end(NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  set_remove_end(NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  set_length(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
// Enqueue one task.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
void GCTaskQueue::enqueue(GCTask* task) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  if (TraceGCTaskQueue) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
    tty->print_cr("[" INTPTR_FORMAT "]"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
                  " GCTaskQueue::enqueue(task: "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
                  INTPTR_FORMAT ")",
29798
451c73fdf690 8076071: parallelScavenge: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 28163
diff changeset
   167
                  p2i(this), p2i(task));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
    print("before:");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
  assert(task != NULL, "shouldn't have null task");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
  assert(task->older() == NULL, "shouldn't be on queue");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
  assert(task->newer() == NULL, "shouldn't be on queue");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  task->set_newer(NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
  task->set_older(insert_end());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
  if (is_empty()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
    set_remove_end(task);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
    insert_end()->set_newer(task);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
  set_insert_end(task);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
  increment_length();
11174
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   182
  verify_length();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
  if (TraceGCTaskQueue) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
    print("after:");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
// Enqueue a whole list of tasks.  Empties the argument list.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
void GCTaskQueue::enqueue(GCTaskQueue* list) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
  if (TraceGCTaskQueue) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
    tty->print_cr("[" INTPTR_FORMAT "]"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
                  " GCTaskQueue::enqueue(list: "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
                  INTPTR_FORMAT ")",
29798
451c73fdf690 8076071: parallelScavenge: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 28163
diff changeset
   194
                  p2i(this), p2i(list));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
    print("before:");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
    list->print("list:");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
  if (list->is_empty()) {
22551
9bf46d16dcc6 8025856: Fix typos in the GC code
jwilhelm
parents: 13963
diff changeset
   199
    // Enqueueing the empty list: nothing to do.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
  uint list_length = list->length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
  if (is_empty()) {
22551
9bf46d16dcc6 8025856: Fix typos in the GC code
jwilhelm
parents: 13963
diff changeset
   204
    // Enqueueing to empty list: just acquire elements.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
    set_insert_end(list->insert_end());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
    set_remove_end(list->remove_end());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
    set_length(list_length);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
    // Prepend argument list to our queue.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
    list->remove_end()->set_older(insert_end());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
    insert_end()->set_newer(list->remove_end());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
    set_insert_end(list->insert_end());
11174
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   213
    set_length(length() + list_length);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
    // empty the argument list.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
  list->initialize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
  if (TraceGCTaskQueue) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
    print("after:");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
    list->print("list:");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
  }
11174
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   221
  verify_length();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
// Dequeue one task.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
GCTask* GCTaskQueue::dequeue() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
  if (TraceGCTaskQueue) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
    tty->print_cr("[" INTPTR_FORMAT "]"
29798
451c73fdf690 8076071: parallelScavenge: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 28163
diff changeset
   228
                  " GCTaskQueue::dequeue()", p2i(this));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
    print("before:");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
  assert(!is_empty(), "shouldn't dequeue from empty list");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
  GCTask* result = remove();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
  assert(result != NULL, "shouldn't have NULL task");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
  if (TraceGCTaskQueue) {
29798
451c73fdf690 8076071: parallelScavenge: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 28163
diff changeset
   235
    tty->print_cr("    return: " INTPTR_FORMAT, p2i(result));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
    print("after:");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
  return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
// Dequeue one task, preferring one with affinity.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
GCTask* GCTaskQueue::dequeue(uint affinity) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
  if (TraceGCTaskQueue) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
    tty->print_cr("[" INTPTR_FORMAT "]"
29798
451c73fdf690 8076071: parallelScavenge: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 28163
diff changeset
   245
                  " GCTaskQueue::dequeue(%u)", p2i(this), affinity);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
    print("before:");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
  assert(!is_empty(), "shouldn't dequeue from empty list");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
  // Look down to the next barrier for a task with this affinity.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
  GCTask* result = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
  for (GCTask* element = remove_end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
       element != NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
       element = element->newer()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
    if (element->is_barrier_task()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
      // Don't consider barrier tasks, nor past them.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
      result = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
    if (element->affinity() == affinity) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
      result = remove(element);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
  // If we didn't find anything with affinity, just take the next task.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
  if (result == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
    result = remove();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
  if (TraceGCTaskQueue) {
29798
451c73fdf690 8076071: parallelScavenge: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 28163
diff changeset
   269
    tty->print_cr("    return: " INTPTR_FORMAT, p2i(result));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
    print("after:");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
  return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
GCTask* GCTaskQueue::remove() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
  // Dequeue from remove end.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
  GCTask* result = remove_end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
  assert(result != NULL, "shouldn't have null task");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
  assert(result->older() == NULL, "not the remove_end");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
  set_remove_end(result->newer());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
  if (remove_end() == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
    assert(insert_end() == result, "not a singleton");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
    set_insert_end(NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
    remove_end()->set_older(NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
  result->set_newer(NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
  decrement_length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
  assert(result->newer() == NULL, "shouldn't be on queue");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
  assert(result->older() == NULL, "shouldn't be on queue");
11174
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   291
  verify_length();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
  return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
GCTask* GCTaskQueue::remove(GCTask* task) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
  // This is slightly more work, and has slightly fewer asserts
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
  // than removing from the remove end.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
  assert(task != NULL, "shouldn't have null task");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
  GCTask* result = task;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
  if (result->newer() != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
    result->newer()->set_older(result->older());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
    assert(insert_end() == result, "not youngest");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
    set_insert_end(result->older());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
  if (result->older() != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
    result->older()->set_newer(result->newer());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
    assert(remove_end() == result, "not oldest");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
    set_remove_end(result->newer());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
  result->set_newer(NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
  result->set_older(NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
  decrement_length();
11174
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   315
  verify_length();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
  return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
NOT_PRODUCT(
11174
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   320
// Count the elements in the queue and verify the length against
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   321
// that count.
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   322
void GCTaskQueue::verify_length() const {
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   323
  uint count = 0;
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   324
  for (GCTask* element = insert_end();
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   325
       element != NULL;
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   326
       element = element->older()) {
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   327
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   328
    count++;
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   329
  }
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   330
  assert(count == length(), "Length does not match queue");
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   331
}
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   332
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
void GCTaskQueue::print(const char* message) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
  tty->print_cr("[" INTPTR_FORMAT "] GCTaskQueue:"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
                "  insert_end: " INTPTR_FORMAT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
                "  remove_end: " INTPTR_FORMAT
11174
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   337
                "  length:       %d"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
                "  %s",
29798
451c73fdf690 8076071: parallelScavenge: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 28163
diff changeset
   339
                p2i(this), p2i(insert_end()), p2i(remove_end()), length(), message);
11174
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   340
  uint count = 0;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
  for (GCTask* element = insert_end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
       element != NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
       element = element->older()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
    element->print("    ");
11174
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   345
    count++;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
    tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
  }
11174
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   348
  tty->print("Total tasks: %d", count);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
// SynchronizedGCTaskQueue
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
SynchronizedGCTaskQueue::SynchronizedGCTaskQueue(GCTaskQueue* queue_arg,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
                                                 Monitor *       lock_arg) :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
  _unsynchronized_queue(queue_arg),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
  _lock(lock_arg) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
  assert(unsynchronized_queue() != NULL, "null queue");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
  assert(lock() != NULL, "null lock");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
SynchronizedGCTaskQueue::~SynchronizedGCTaskQueue() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
  // Nothing to do.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
// GCTaskManager
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
GCTaskManager::GCTaskManager(uint workers) :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
  _workers(workers),
11174
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   373
  _active_workers(0),
33124
e256f7a94c38 8138862: Remove some unused code and subclasses in gcTaskManager.hpp/cpp
brutisso
parents: 33105
diff changeset
   374
  _idle_workers(0) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
  initialize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
void GCTaskManager::initialize() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
  if (TraceGCTaskManager) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
    tty->print_cr("GCTaskManager::initialize: workers: %u", workers());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
  assert(workers() != 0, "no workers");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
  _monitor = new Monitor(Mutex::barrier,                // rank
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
                         "GCTaskManager monitor",       // name
28163
322d55d167be 8047290: Make Mutex::_no_safepoint_check_flag locks verify that this lock never checks for safepoint
coleenp
parents: 27880
diff changeset
   385
                         Mutex::_allow_vm_block_flag,   // allow_vm_block
322d55d167be 8047290: Make Mutex::_no_safepoint_check_flag locks verify that this lock never checks for safepoint
coleenp
parents: 27880
diff changeset
   386
                         Monitor::_safepoint_check_never);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
  // The queue for the GCTaskManager must be a CHeapObj.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
  GCTaskQueue* unsynchronized_queue = GCTaskQueue::create_on_c_heap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
  _queue = SynchronizedGCTaskQueue::create(unsynchronized_queue, lock());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
  _noop_task = NoopGCTask::create_on_c_heap();
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 11208
diff changeset
   391
  _resource_flag = NEW_C_HEAP_ARRAY(bool, workers(), mtGC);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
    // Set up worker threads.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
    //     Distribute the workers among the available processors,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
    //     unless we were told not to, or if the os doesn't want to.
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 11208
diff changeset
   396
    uint* processor_assignment = NEW_C_HEAP_ARRAY(uint, workers(), mtGC);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
    if (!BindGCTaskThreadsToCPUs ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
        !os::distribute_processes(workers(), processor_assignment)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
      for (uint a = 0; a < workers(); a += 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
        processor_assignment[a] = sentinel_worker();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
    }
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 11208
diff changeset
   403
    _thread = NEW_C_HEAP_ARRAY(GCTaskThread*, workers(), mtGC);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
    for (uint t = 0; t < workers(); t += 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
      set_thread(t, GCTaskThread::create(this, t, processor_assignment[t]));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
    if (TraceGCTaskThread) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
      tty->print("GCTaskManager::initialize: distribution:");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
      for (uint t = 0; t < workers(); t += 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
        tty->print("  %u", processor_assignment[t]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
      tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
    }
27880
afb974a04396 8060074: os::free() takes MemoryTrackingLevel but doesn't need it
coleenp
parents: 24424
diff changeset
   414
    FREE_C_HEAP_ARRAY(uint, processor_assignment);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
  reset_busy_workers();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
  set_unblocked();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
  for (uint w = 0; w < workers(); w += 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
    set_resource_flag(w, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
  reset_delivered_tasks();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
  reset_completed_tasks();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
  reset_barriers();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
  reset_emptied_queue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
  for (uint s = 0; s < workers(); s += 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
    thread(s)->start();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
GCTaskManager::~GCTaskManager() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
  assert(busy_workers() == 0, "still have busy workers");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
  assert(queue()->is_empty(), "still have queued work");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
  NoopGCTask::destroy(_noop_task);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
  _noop_task = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
  if (_thread != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
    for (uint i = 0; i < workers(); i += 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
      GCTaskThread::destroy(thread(i));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
      set_thread(i, NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
    }
27880
afb974a04396 8060074: os::free() takes MemoryTrackingLevel but doesn't need it
coleenp
parents: 24424
diff changeset
   440
    FREE_C_HEAP_ARRAY(GCTaskThread*, _thread);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
    _thread = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
  if (_resource_flag != NULL) {
27880
afb974a04396 8060074: os::free() takes MemoryTrackingLevel but doesn't need it
coleenp
parents: 24424
diff changeset
   444
    FREE_C_HEAP_ARRAY(bool, _resource_flag);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
    _resource_flag = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
  if (queue() != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
    GCTaskQueue* unsynchronized_queue = queue()->unsynchronized_queue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
    GCTaskQueue::destroy(unsynchronized_queue);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
    SynchronizedGCTaskQueue::destroy(queue());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
    _queue = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
  if (monitor() != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
    delete monitor();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
    _monitor = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
11174
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   459
void GCTaskManager::set_active_gang() {
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   460
  _active_workers =
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   461
    AdaptiveSizePolicy::calc_active_workers(workers(),
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   462
                                 active_workers(),
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   463
                                 Threads::number_of_non_daemon_threads());
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   464
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   465
  assert(!all_workers_active() || active_workers() == ParallelGCThreads,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31330
diff changeset
   466
         "all_workers_active() is  incorrect: "
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31330
diff changeset
   467
         "active %d  ParallelGCThreads %u", active_workers(),
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31330
diff changeset
   468
         ParallelGCThreads);
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33126
diff changeset
   469
  log_trace(gc, task)("GCTaskManager::set_active_gang(): "
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33126
diff changeset
   470
                      "all_workers_active()  %d  workers %d  "
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33126
diff changeset
   471
                      "active  %d  ParallelGCThreads %u",
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33126
diff changeset
   472
                      all_workers_active(), workers(),  active_workers(),
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33126
diff changeset
   473
                      ParallelGCThreads);
11174
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   474
}
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   475
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   476
// Create IdleGCTasks for inactive workers.
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   477
// Creates tasks in a ResourceArea and assumes
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   478
// an appropriate ResourceMark.
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   479
void GCTaskManager::task_idle_workers() {
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   480
  {
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   481
    int more_inactive_workers = 0;
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   482
    {
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   483
      // Stop any idle tasks from exiting their IdleGCTask's
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   484
      // and get the count for additional IdleGCTask's under
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   485
      // the GCTaskManager's monitor so that the "more_inactive_workers"
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   486
      // count is correct.
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   487
      MutexLockerEx ml(monitor(), Mutex::_no_safepoint_check_flag);
33125
bc61fce9bac3 8138863: Refactor WaitForBarrierGCTask
brutisso
parents: 33124
diff changeset
   488
      _wait_helper.set_should_wait(true);
11174
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   489
      // active_workers are a number being requested.  idle_workers
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   490
      // are the number currently idle.  If all the workers are being
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   491
      // requested to be active but some are already idle, reduce
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   492
      // the number of active_workers to be consistent with the
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   493
      // number of idle_workers.  The idle_workers are stuck in
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   494
      // idle tasks and will no longer be release (since a new GC
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   495
      // is starting).  Try later to release enough idle_workers
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   496
      // to allow the desired number of active_workers.
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   497
      more_inactive_workers =
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   498
        workers() - active_workers() - idle_workers();
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   499
      if (more_inactive_workers < 0) {
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   500
        int reduced_active_workers = active_workers() + more_inactive_workers;
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   501
        set_active_workers(reduced_active_workers);
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   502
        more_inactive_workers = 0;
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   503
      }
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33126
diff changeset
   504
      log_trace(gc, task)("JT: %d  workers %d  active  %d  idle %d  more %d",
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33126
diff changeset
   505
                          Threads::number_of_non_daemon_threads(),
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33126
diff changeset
   506
                          workers(),
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33126
diff changeset
   507
                          active_workers(),
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33126
diff changeset
   508
                          idle_workers(),
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33126
diff changeset
   509
                          more_inactive_workers);
11174
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   510
    }
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   511
    GCTaskQueue* q = GCTaskQueue::create();
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   512
    for(uint i = 0; i < (uint) more_inactive_workers; i++) {
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   513
      q->enqueue(IdleGCTask::create_on_c_heap());
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   514
      increment_idle_workers();
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   515
    }
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   516
    assert(workers() == active_workers() + idle_workers(),
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   517
      "total workers should equal active + inactive");
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   518
    add_list(q);
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   519
    // GCTaskQueue* q was created in a ResourceArea so a
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   520
    // destroy() call is not needed.
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   521
  }
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   522
}
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   523
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   524
void  GCTaskManager::release_idle_workers() {
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   525
  {
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   526
    MutexLockerEx ml(monitor(),
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   527
      Mutex::_no_safepoint_check_flag);
33125
bc61fce9bac3 8138863: Refactor WaitForBarrierGCTask
brutisso
parents: 33124
diff changeset
   528
    _wait_helper.set_should_wait(false);
11174
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   529
    monitor()->notify_all();
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   530
  // Release monitor
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   531
  }
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   532
}
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   533
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   534
void GCTaskManager::print_task_time_stamps() {
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33126
diff changeset
   535
  if (!log_is_enabled(Debug, gc, task, time)) {
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33126
diff changeset
   536
    return;
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33126
diff changeset
   537
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   538
  for(uint i=0; i<ParallelGCThreads; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   539
    GCTaskThread* t = thread(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   540
    t->print_task_time_stamps();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   541
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   542
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   543
489c9b5090e2 Initial load
duke
parents:
diff changeset
   544
void GCTaskManager::print_threads_on(outputStream* st) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   545
  uint num_thr = workers();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   546
  for (uint i = 0; i < num_thr; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   547
    thread(i)->print_on(st);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   548
    st->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   549
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   550
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   551
489c9b5090e2 Initial load
duke
parents:
diff changeset
   552
void GCTaskManager::threads_do(ThreadClosure* tc) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   553
  assert(tc != NULL, "Null ThreadClosure");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   554
  uint num_thr = workers();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   555
  for (uint i = 0; i < num_thr; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   556
    tc->do_thread(thread(i));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   557
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   558
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   559
489c9b5090e2 Initial load
duke
parents:
diff changeset
   560
GCTaskThread* GCTaskManager::thread(uint which) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   561
  assert(which < workers(), "index out of bounds");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   562
  assert(_thread[which] != NULL, "shouldn't have null thread");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   563
  return _thread[which];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   564
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   565
489c9b5090e2 Initial load
duke
parents:
diff changeset
   566
void GCTaskManager::set_thread(uint which, GCTaskThread* value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   567
  assert(which < workers(), "index out of bounds");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   568
  assert(value != NULL, "shouldn't have null thread");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   569
  _thread[which] = value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   570
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   571
489c9b5090e2 Initial load
duke
parents:
diff changeset
   572
void GCTaskManager::add_task(GCTask* task) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   573
  assert(task != NULL, "shouldn't have null task");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   574
  MutexLockerEx ml(monitor(), Mutex::_no_safepoint_check_flag);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   575
  if (TraceGCTaskManager) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   576
    tty->print_cr("GCTaskManager::add_task(" INTPTR_FORMAT " [%s])",
29798
451c73fdf690 8076071: parallelScavenge: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 28163
diff changeset
   577
                  p2i(task), GCTask::Kind::to_string(task->kind()));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   578
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   579
  queue()->enqueue(task);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   580
  // Notify with the lock held to avoid missed notifies.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   581
  if (TraceGCTaskManager) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   582
    tty->print_cr("    GCTaskManager::add_task (%s)->notify_all",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   583
                  monitor()->name());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   584
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   585
  (void) monitor()->notify_all();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   586
  // Release monitor().
489c9b5090e2 Initial load
duke
parents:
diff changeset
   587
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   588
489c9b5090e2 Initial load
duke
parents:
diff changeset
   589
void GCTaskManager::add_list(GCTaskQueue* list) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   590
  assert(list != NULL, "shouldn't have null task");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   591
  MutexLockerEx ml(monitor(), Mutex::_no_safepoint_check_flag);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   592
  if (TraceGCTaskManager) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   593
    tty->print_cr("GCTaskManager::add_list(%u)", list->length());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   594
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   595
  queue()->enqueue(list);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   596
  // Notify with the lock held to avoid missed notifies.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   597
  if (TraceGCTaskManager) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   598
    tty->print_cr("    GCTaskManager::add_list (%s)->notify_all",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   599
                  monitor()->name());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   600
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   601
  (void) monitor()->notify_all();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   602
  // Release monitor().
489c9b5090e2 Initial load
duke
parents:
diff changeset
   603
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   604
11174
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   605
// GC workers wait in get_task() for new work to be added
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   606
// to the GCTaskManager's queue.  When new work is added,
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   607
// a notify is sent to the waiting GC workers which then
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   608
// compete to get tasks.  If a GC worker wakes up and there
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   609
// is no work on the queue, it is given a noop_task to execute
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   610
// and then loops to find more work.
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   611
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   612
GCTask* GCTaskManager::get_task(uint which) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   613
  GCTask* result = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   614
  // Grab the queue lock.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   615
  MutexLockerEx ml(monitor(), Mutex::_no_safepoint_check_flag);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   616
  // Wait while the queue is block or
489c9b5090e2 Initial load
duke
parents:
diff changeset
   617
  // there is nothing to do, except maybe release resources.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   618
  while (is_blocked() ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   619
         (queue()->is_empty() && !should_release_resources(which))) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   620
    if (TraceGCTaskManager) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   621
      tty->print_cr("GCTaskManager::get_task(%u)"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   622
                    "  blocked: %s"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   623
                    "  empty: %s"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   624
                    "  release: %s",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   625
                    which,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   626
                    is_blocked() ? "true" : "false",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   627
                    queue()->is_empty() ? "true" : "false",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   628
                    should_release_resources(which) ? "true" : "false");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   629
      tty->print_cr("    => (%s)->wait()",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   630
                    monitor()->name());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   631
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   632
    monitor()->wait(Mutex::_no_safepoint_check_flag, 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   633
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   634
  // We've reacquired the queue lock here.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   635
  // Figure out which condition caused us to exit the loop above.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   636
  if (!queue()->is_empty()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   637
    if (UseGCTaskAffinity) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   638
      result = queue()->dequeue(which);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   639
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   640
      result = queue()->dequeue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   641
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   642
    if (result->is_barrier_task()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   643
      assert(which != sentinel_worker(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   644
             "blocker shouldn't be bogus");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   645
      set_blocking_worker(which);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   646
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   647
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   648
    // The queue is empty, but we were woken up.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   649
    // Just hand back a Noop task,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   650
    // in case someone wanted us to release resources, or whatever.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   651
    result = noop_task();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   652
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   653
  assert(result != NULL, "shouldn't have null task");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   654
  if (TraceGCTaskManager) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   655
    tty->print_cr("GCTaskManager::get_task(%u) => " INTPTR_FORMAT " [%s]",
29798
451c73fdf690 8076071: parallelScavenge: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 28163
diff changeset
   656
                  which, p2i(result), GCTask::Kind::to_string(result->kind()));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   657
    tty->print_cr("     %s", result->name());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   658
  }
11174
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   659
  if (!result->is_idle_task()) {
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   660
    increment_busy_workers();
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   661
    increment_delivered_tasks();
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   662
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   663
  return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   664
  // Release monitor().
489c9b5090e2 Initial load
duke
parents:
diff changeset
   665
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   666
489c9b5090e2 Initial load
duke
parents:
diff changeset
   667
void GCTaskManager::note_completion(uint which) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   668
  MutexLockerEx ml(monitor(), Mutex::_no_safepoint_check_flag);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   669
  if (TraceGCTaskManager) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   670
    tty->print_cr("GCTaskManager::note_completion(%u)", which);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   671
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   672
  // If we are blocked, check if the completing thread is the blocker.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   673
  if (blocking_worker() == which) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   674
    assert(blocking_worker() != sentinel_worker(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   675
           "blocker shouldn't be bogus");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   676
    increment_barriers();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   677
    set_unblocked();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   678
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   679
  increment_completed_tasks();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   680
  uint active = decrement_busy_workers();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   681
  if ((active == 0) && (queue()->is_empty())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   682
    increment_emptied_queue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   683
    if (TraceGCTaskManager) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   684
      tty->print_cr("    GCTaskManager::note_completion(%u) done", which);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   685
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   686
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   687
  if (TraceGCTaskManager) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   688
    tty->print_cr("    GCTaskManager::note_completion(%u) (%s)->notify_all",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   689
                  which, monitor()->name());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   690
    tty->print_cr("  "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   691
                  "  blocked: %s"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   692
                  "  empty: %s"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   693
                  "  release: %s",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   694
                  is_blocked() ? "true" : "false",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   695
                  queue()->is_empty() ? "true" : "false",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   696
                  should_release_resources(which) ? "true" : "false");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   697
    tty->print_cr("  "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   698
                  "  delivered: %u"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   699
                  "  completed: %u"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   700
                  "  barriers: %u"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   701
                  "  emptied: %u",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   702
                  delivered_tasks(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   703
                  completed_tasks(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   704
                  barriers(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   705
                  emptied_queue());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   706
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   707
  // Tell everyone that a task has completed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   708
  (void) monitor()->notify_all();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   709
  // Release monitor().
489c9b5090e2 Initial load
duke
parents:
diff changeset
   710
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   711
489c9b5090e2 Initial load
duke
parents:
diff changeset
   712
uint GCTaskManager::increment_busy_workers() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   713
  assert(queue()->own_lock(), "don't own the lock");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   714
  _busy_workers += 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   715
  return _busy_workers;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   716
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   717
489c9b5090e2 Initial load
duke
parents:
diff changeset
   718
uint GCTaskManager::decrement_busy_workers() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   719
  assert(queue()->own_lock(), "don't own the lock");
11174
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   720
  assert(_busy_workers > 0, "About to make a mistake");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   721
  _busy_workers -= 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   722
  return _busy_workers;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   723
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   724
489c9b5090e2 Initial load
duke
parents:
diff changeset
   725
void GCTaskManager::release_all_resources() {
33124
e256f7a94c38 8138862: Remove some unused code and subclasses in gcTaskManager.hpp/cpp
brutisso
parents: 33105
diff changeset
   726
  // If you want this to be done atomically, do it in a WaitForBarrierGCTask.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   727
  for (uint i = 0; i < workers(); i += 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   728
    set_resource_flag(i, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   729
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   730
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   731
489c9b5090e2 Initial load
duke
parents:
diff changeset
   732
bool GCTaskManager::should_release_resources(uint which) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   733
  // This can be done without a lock because each thread reads one element.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   734
  return resource_flag(which);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   735
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   736
489c9b5090e2 Initial load
duke
parents:
diff changeset
   737
void GCTaskManager::note_release(uint which) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   738
  // This can be done without a lock because each thread writes one element.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   739
  set_resource_flag(which, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   740
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   741
11174
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   742
// "list" contains tasks that are ready to execute.  Those
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   743
// tasks are added to the GCTaskManager's queue of tasks and
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   744
// then the GC workers are notified that there is new work to
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   745
// do.
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   746
//
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   747
// Typically different types of tasks can be added to the "list".
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   748
// For example in PSScavenge OldToYoungRootsTask, SerialOldToYoungRootsTask,
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   749
// ScavengeRootsTask, and StealTask tasks are all added to the list
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   750
// and then the GC workers are notified of new work.  The tasks are
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   751
// handed out in the order in which they are added to the list
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   752
// (although execution is not necessarily in that order).  As long
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   753
// as any tasks are running the GCTaskManager will wait for execution
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   754
// to complete.  GC workers that execute a stealing task remain in
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   755
// the stealing task until all stealing tasks have completed.  The load
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   756
// balancing afforded by the stealing tasks work best if the stealing
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   757
// tasks are added last to the list.
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   758
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   759
void GCTaskManager::execute_and_wait(GCTaskQueue* list) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   760
  WaitForBarrierGCTask* fin = WaitForBarrierGCTask::create();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   761
  list->enqueue(fin);
11208
101816314520 7119584: UseParallelGC barrier task can be overwritten.
jmasa
parents: 11174
diff changeset
   762
  // The barrier task will be read by one of the GC
101816314520 7119584: UseParallelGC barrier task can be overwritten.
jmasa
parents: 11174
diff changeset
   763
  // workers once it is added to the list of tasks.
101816314520 7119584: UseParallelGC barrier task can be overwritten.
jmasa
parents: 11174
diff changeset
   764
  // Be sure that is globally visible before the
101816314520 7119584: UseParallelGC barrier task can be overwritten.
jmasa
parents: 11174
diff changeset
   765
  // GC worker reads it (which is after the task is added
101816314520 7119584: UseParallelGC barrier task can be overwritten.
jmasa
parents: 11174
diff changeset
   766
  // to the list of tasks below).
101816314520 7119584: UseParallelGC barrier task can be overwritten.
jmasa
parents: 11174
diff changeset
   767
  OrderAccess::storestore();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   768
  add_list(list);
11174
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   769
  fin->wait_for(true /* reset */);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   770
  // We have to release the barrier tasks!
489c9b5090e2 Initial load
duke
parents:
diff changeset
   771
  WaitForBarrierGCTask::destroy(fin);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   772
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   773
489c9b5090e2 Initial load
duke
parents:
diff changeset
   774
bool GCTaskManager::resource_flag(uint which) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   775
  assert(which < workers(), "index out of bounds");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   776
  return _resource_flag[which];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   777
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   778
489c9b5090e2 Initial load
duke
parents:
diff changeset
   779
void GCTaskManager::set_resource_flag(uint which, bool value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   780
  assert(which < workers(), "index out of bounds");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   781
  _resource_flag[which] = value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   782
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   783
489c9b5090e2 Initial load
duke
parents:
diff changeset
   784
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   785
// NoopGCTask
489c9b5090e2 Initial load
duke
parents:
diff changeset
   786
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   787
489c9b5090e2 Initial load
duke
parents:
diff changeset
   788
NoopGCTask* NoopGCTask::create_on_c_heap() {
33124
e256f7a94c38 8138862: Remove some unused code and subclasses in gcTaskManager.hpp/cpp
brutisso
parents: 33105
diff changeset
   789
  NoopGCTask* result = new(ResourceObj::C_HEAP, mtGC) NoopGCTask();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   790
  return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   791
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   792
489c9b5090e2 Initial load
duke
parents:
diff changeset
   793
void NoopGCTask::destroy(NoopGCTask* that) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   794
  if (that != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   795
    that->destruct();
33124
e256f7a94c38 8138862: Remove some unused code and subclasses in gcTaskManager.hpp/cpp
brutisso
parents: 33105
diff changeset
   796
    FreeHeap(that);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   797
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   798
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   799
33126
260ff671354b 8138707: TestPromotionEventWithParallelScavenge.java crashes using undefined GC id.
brutisso
parents: 33125
diff changeset
   800
// This task should never be performing GC work that require
260ff671354b 8138707: TestPromotionEventWithParallelScavenge.java crashes using undefined GC id.
brutisso
parents: 33125
diff changeset
   801
// a valid GC id.
260ff671354b 8138707: TestPromotionEventWithParallelScavenge.java crashes using undefined GC id.
brutisso
parents: 33125
diff changeset
   802
NoopGCTask::NoopGCTask() : GCTask(GCTask::Kind::noop_task, GCId::undefined()) { }
260ff671354b 8138707: TestPromotionEventWithParallelScavenge.java crashes using undefined GC id.
brutisso
parents: 33125
diff changeset
   803
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   804
void NoopGCTask::destruct() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   805
  // This has to know it's superclass structure, just like the constructor.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   806
  this->GCTask::destruct();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   807
  // Nothing else to do.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   808
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   809
489c9b5090e2 Initial load
duke
parents:
diff changeset
   810
//
11174
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   811
// IdleGCTask
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   812
//
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   813
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   814
IdleGCTask* IdleGCTask::create() {
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   815
  IdleGCTask* result = new IdleGCTask(false);
11208
101816314520 7119584: UseParallelGC barrier task can be overwritten.
jmasa
parents: 11174
diff changeset
   816
  assert(UseDynamicNumberOfGCThreads,
101816314520 7119584: UseParallelGC barrier task can be overwritten.
jmasa
parents: 11174
diff changeset
   817
    "Should only be used with dynamic GC thread");
11174
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   818
  return result;
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   819
}
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   820
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   821
IdleGCTask* IdleGCTask::create_on_c_heap() {
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 11208
diff changeset
   822
  IdleGCTask* result = new(ResourceObj::C_HEAP, mtGC) IdleGCTask(true);
11208
101816314520 7119584: UseParallelGC barrier task can be overwritten.
jmasa
parents: 11174
diff changeset
   823
  assert(UseDynamicNumberOfGCThreads,
101816314520 7119584: UseParallelGC barrier task can be overwritten.
jmasa
parents: 11174
diff changeset
   824
    "Should only be used with dynamic GC thread");
11174
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   825
  return result;
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   826
}
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   827
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   828
void IdleGCTask::do_it(GCTaskManager* manager, uint which) {
33125
bc61fce9bac3 8138863: Refactor WaitForBarrierGCTask
brutisso
parents: 33124
diff changeset
   829
  WaitHelper* wait_helper = manager->wait_helper();
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33126
diff changeset
   830
  log_trace(gc, task)("[" INTPTR_FORMAT "] IdleGCTask:::do_it() should_wait: %s",
33125
bc61fce9bac3 8138863: Refactor WaitForBarrierGCTask
brutisso
parents: 33124
diff changeset
   831
      p2i(this), wait_helper->should_wait() ? "true" : "false");
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33126
diff changeset
   832
11174
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   833
  MutexLockerEx ml(manager->monitor(), Mutex::_no_safepoint_check_flag);
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33126
diff changeset
   834
  log_trace(gc, task)("--- idle %d", which);
11174
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   835
  // Increment has to be done when the idle tasks are created.
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   836
  // manager->increment_idle_workers();
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   837
  manager->monitor()->notify_all();
33125
bc61fce9bac3 8138863: Refactor WaitForBarrierGCTask
brutisso
parents: 33124
diff changeset
   838
  while (wait_helper->should_wait()) {
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33126
diff changeset
   839
    log_trace(gc, task)("[" INTPTR_FORMAT "] IdleGCTask::do_it()  [" INTPTR_FORMAT "] (%s)->wait()",
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33126
diff changeset
   840
      p2i(this), p2i(manager->monitor()), manager->monitor()->name());
11174
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   841
    manager->monitor()->wait(Mutex::_no_safepoint_check_flag, 0);
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   842
  }
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   843
  manager->decrement_idle_workers();
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33126
diff changeset
   844
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33126
diff changeset
   845
  log_trace(gc, task)("--- release %d", which);
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33126
diff changeset
   846
  log_trace(gc, task)("[" INTPTR_FORMAT "] IdleGCTask::do_it() returns should_wait: %s",
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33126
diff changeset
   847
    p2i(this), wait_helper->should_wait() ? "true" : "false");
11174
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   848
  // Release monitor().
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   849
}
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   850
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   851
void IdleGCTask::destroy(IdleGCTask* that) {
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   852
  if (that != NULL) {
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   853
    that->destruct();
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   854
    if (that->is_c_heap_obj()) {
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   855
      FreeHeap(that);
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   856
    }
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   857
  }
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   858
}
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   859
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   860
void IdleGCTask::destruct() {
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   861
  // This has to know it's superclass structure, just like the constructor.
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   862
  this->GCTask::destruct();
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   863
  // Nothing else to do.
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   864
}
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   865
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   866
//
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   867
// WaitForBarrierGCTask
489c9b5090e2 Initial load
duke
parents:
diff changeset
   868
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   869
WaitForBarrierGCTask* WaitForBarrierGCTask::create() {
33125
bc61fce9bac3 8138863: Refactor WaitForBarrierGCTask
brutisso
parents: 33124
diff changeset
   870
  WaitForBarrierGCTask* result = new WaitForBarrierGCTask();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   871
  return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   872
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   873
33125
bc61fce9bac3 8138863: Refactor WaitForBarrierGCTask
brutisso
parents: 33124
diff changeset
   874
WaitForBarrierGCTask::WaitForBarrierGCTask() : GCTask(GCTask::Kind::wait_for_barrier_task) { }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   875
489c9b5090e2 Initial load
duke
parents:
diff changeset
   876
void WaitForBarrierGCTask::destroy(WaitForBarrierGCTask* that) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   877
  if (that != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   878
    if (TraceGCTaskManager) {
33125
bc61fce9bac3 8138863: Refactor WaitForBarrierGCTask
brutisso
parents: 33124
diff changeset
   879
      tty->print_cr("[" INTPTR_FORMAT "] WaitForBarrierGCTask::destroy()", p2i(that));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   880
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   881
    that->destruct();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   882
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   883
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   884
489c9b5090e2 Initial load
duke
parents:
diff changeset
   885
void WaitForBarrierGCTask::destruct() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   886
  if (TraceGCTaskManager) {
33125
bc61fce9bac3 8138863: Refactor WaitForBarrierGCTask
brutisso
parents: 33124
diff changeset
   887
    tty->print_cr("[" INTPTR_FORMAT "] WaitForBarrierGCTask::destruct()", p2i(this));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   888
  }
33124
e256f7a94c38 8138862: Remove some unused code and subclasses in gcTaskManager.hpp/cpp
brutisso
parents: 33105
diff changeset
   889
  this->GCTask::destruct();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   890
  // Clean up that should be in the destructor,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   891
  // except that ResourceMarks don't call destructors.
33125
bc61fce9bac3 8138863: Refactor WaitForBarrierGCTask
brutisso
parents: 33124
diff changeset
   892
  _wait_helper.release_monitor();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   893
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   894
33124
e256f7a94c38 8138862: Remove some unused code and subclasses in gcTaskManager.hpp/cpp
brutisso
parents: 33105
diff changeset
   895
void WaitForBarrierGCTask::do_it_internal(GCTaskManager* manager, uint which) {
e256f7a94c38 8138862: Remove some unused code and subclasses in gcTaskManager.hpp/cpp
brutisso
parents: 33105
diff changeset
   896
  // Wait for this to be the only busy worker.
e256f7a94c38 8138862: Remove some unused code and subclasses in gcTaskManager.hpp/cpp
brutisso
parents: 33105
diff changeset
   897
  assert(manager->monitor()->owned_by_self(), "don't own the lock");
e256f7a94c38 8138862: Remove some unused code and subclasses in gcTaskManager.hpp/cpp
brutisso
parents: 33105
diff changeset
   898
  assert(manager->is_blocked(), "manager isn't blocked");
e256f7a94c38 8138862: Remove some unused code and subclasses in gcTaskManager.hpp/cpp
brutisso
parents: 33105
diff changeset
   899
  while (manager->busy_workers() > 1) {
e256f7a94c38 8138862: Remove some unused code and subclasses in gcTaskManager.hpp/cpp
brutisso
parents: 33105
diff changeset
   900
    if (TraceGCTaskManager) {
e256f7a94c38 8138862: Remove some unused code and subclasses in gcTaskManager.hpp/cpp
brutisso
parents: 33105
diff changeset
   901
      tty->print_cr("WaitForBarrierGCTask::do_it(%u) waiting on %u workers",
e256f7a94c38 8138862: Remove some unused code and subclasses in gcTaskManager.hpp/cpp
brutisso
parents: 33105
diff changeset
   902
                    which, manager->busy_workers());
e256f7a94c38 8138862: Remove some unused code and subclasses in gcTaskManager.hpp/cpp
brutisso
parents: 33105
diff changeset
   903
    }
e256f7a94c38 8138862: Remove some unused code and subclasses in gcTaskManager.hpp/cpp
brutisso
parents: 33105
diff changeset
   904
    manager->monitor()->wait(Mutex::_no_safepoint_check_flag, 0);
e256f7a94c38 8138862: Remove some unused code and subclasses in gcTaskManager.hpp/cpp
brutisso
parents: 33105
diff changeset
   905
  }
e256f7a94c38 8138862: Remove some unused code and subclasses in gcTaskManager.hpp/cpp
brutisso
parents: 33105
diff changeset
   906
}
e256f7a94c38 8138862: Remove some unused code and subclasses in gcTaskManager.hpp/cpp
brutisso
parents: 33105
diff changeset
   907
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   908
void WaitForBarrierGCTask::do_it(GCTaskManager* manager, uint which) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   909
  if (TraceGCTaskManager) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   910
    tty->print_cr("[" INTPTR_FORMAT "]"
33125
bc61fce9bac3 8138863: Refactor WaitForBarrierGCTask
brutisso
parents: 33124
diff changeset
   911
                  " WaitForBarrierGCTask::do_it() waiting for idle",
bc61fce9bac3 8138863: Refactor WaitForBarrierGCTask
brutisso
parents: 33124
diff changeset
   912
                  p2i(this));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   913
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   914
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   915
    // First, wait for the barrier to arrive.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   916
    MutexLockerEx ml(manager->lock(), Mutex::_no_safepoint_check_flag);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   917
    do_it_internal(manager, which);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   918
    // Release manager->lock().
489c9b5090e2 Initial load
duke
parents:
diff changeset
   919
  }
33125
bc61fce9bac3 8138863: Refactor WaitForBarrierGCTask
brutisso
parents: 33124
diff changeset
   920
  // Then notify the waiter.
bc61fce9bac3 8138863: Refactor WaitForBarrierGCTask
brutisso
parents: 33124
diff changeset
   921
  _wait_helper.notify();
bc61fce9bac3 8138863: Refactor WaitForBarrierGCTask
brutisso
parents: 33124
diff changeset
   922
}
bc61fce9bac3 8138863: Refactor WaitForBarrierGCTask
brutisso
parents: 33124
diff changeset
   923
bc61fce9bac3 8138863: Refactor WaitForBarrierGCTask
brutisso
parents: 33124
diff changeset
   924
WaitHelper::WaitHelper() : _should_wait(true), _monitor(MonitorSupply::reserve()) {
bc61fce9bac3 8138863: Refactor WaitForBarrierGCTask
brutisso
parents: 33124
diff changeset
   925
  if (TraceGCTaskManager) {
bc61fce9bac3 8138863: Refactor WaitForBarrierGCTask
brutisso
parents: 33124
diff changeset
   926
    tty->print_cr("[" INTPTR_FORMAT "]"
bc61fce9bac3 8138863: Refactor WaitForBarrierGCTask
brutisso
parents: 33124
diff changeset
   927
                  " WaitHelper::WaitHelper()"
bc61fce9bac3 8138863: Refactor WaitForBarrierGCTask
brutisso
parents: 33124
diff changeset
   928
                  "  monitor: " INTPTR_FORMAT,
bc61fce9bac3 8138863: Refactor WaitForBarrierGCTask
brutisso
parents: 33124
diff changeset
   929
                  p2i(this), p2i(monitor()));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   930
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   931
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   932
33125
bc61fce9bac3 8138863: Refactor WaitForBarrierGCTask
brutisso
parents: 33124
diff changeset
   933
void WaitHelper::release_monitor() {
bc61fce9bac3 8138863: Refactor WaitForBarrierGCTask
brutisso
parents: 33124
diff changeset
   934
  assert(_monitor != NULL, "");
bc61fce9bac3 8138863: Refactor WaitForBarrierGCTask
brutisso
parents: 33124
diff changeset
   935
  MonitorSupply::release(_monitor);
bc61fce9bac3 8138863: Refactor WaitForBarrierGCTask
brutisso
parents: 33124
diff changeset
   936
  _monitor = NULL;
bc61fce9bac3 8138863: Refactor WaitForBarrierGCTask
brutisso
parents: 33124
diff changeset
   937
}
bc61fce9bac3 8138863: Refactor WaitForBarrierGCTask
brutisso
parents: 33124
diff changeset
   938
bc61fce9bac3 8138863: Refactor WaitForBarrierGCTask
brutisso
parents: 33124
diff changeset
   939
WaitHelper::~WaitHelper() {
bc61fce9bac3 8138863: Refactor WaitForBarrierGCTask
brutisso
parents: 33124
diff changeset
   940
  release_monitor();
bc61fce9bac3 8138863: Refactor WaitForBarrierGCTask
brutisso
parents: 33124
diff changeset
   941
}
bc61fce9bac3 8138863: Refactor WaitForBarrierGCTask
brutisso
parents: 33124
diff changeset
   942
bc61fce9bac3 8138863: Refactor WaitForBarrierGCTask
brutisso
parents: 33124
diff changeset
   943
void WaitHelper::wait_for(bool reset) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   944
  if (TraceGCTaskManager) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   945
    tty->print_cr("[" INTPTR_FORMAT "]"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   946
                  " WaitForBarrierGCTask::wait_for()"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   947
      "  should_wait: %s",
29798
451c73fdf690 8076071: parallelScavenge: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 28163
diff changeset
   948
      p2i(this), should_wait() ? "true" : "false");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   949
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   950
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   951
    // Grab the lock and check again.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   952
    MutexLockerEx ml(monitor(), Mutex::_no_safepoint_check_flag);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   953
    while (should_wait()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   954
      if (TraceGCTaskManager) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   955
        tty->print_cr("[" INTPTR_FORMAT "]"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   956
                      " WaitForBarrierGCTask::wait_for()"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   957
          "  [" INTPTR_FORMAT "] (%s)->wait()",
29798
451c73fdf690 8076071: parallelScavenge: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 28163
diff changeset
   958
          p2i(this), p2i(monitor()), monitor()->name());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   959
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   960
      monitor()->wait(Mutex::_no_safepoint_check_flag, 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   961
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   962
    // Reset the flag in case someone reuses this task.
11174
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   963
    if (reset) {
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   964
      set_should_wait(true);
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   965
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   966
    if (TraceGCTaskManager) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   967
      tty->print_cr("[" INTPTR_FORMAT "]"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   968
                    " WaitForBarrierGCTask::wait_for() returns"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   969
        "  should_wait: %s",
29798
451c73fdf690 8076071: parallelScavenge: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 28163
diff changeset
   970
        p2i(this), should_wait() ? "true" : "false");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   971
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   972
    // Release monitor().
489c9b5090e2 Initial load
duke
parents:
diff changeset
   973
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   974
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   975
33125
bc61fce9bac3 8138863: Refactor WaitForBarrierGCTask
brutisso
parents: 33124
diff changeset
   976
void WaitHelper::notify() {
bc61fce9bac3 8138863: Refactor WaitForBarrierGCTask
brutisso
parents: 33124
diff changeset
   977
  MutexLockerEx ml(monitor(), Mutex::_no_safepoint_check_flag);
bc61fce9bac3 8138863: Refactor WaitForBarrierGCTask
brutisso
parents: 33124
diff changeset
   978
  set_should_wait(false);
bc61fce9bac3 8138863: Refactor WaitForBarrierGCTask
brutisso
parents: 33124
diff changeset
   979
  // Waiter doesn't miss the notify in the wait_for method
bc61fce9bac3 8138863: Refactor WaitForBarrierGCTask
brutisso
parents: 33124
diff changeset
   980
  // since it checks the flag after grabbing the monitor.
bc61fce9bac3 8138863: Refactor WaitForBarrierGCTask
brutisso
parents: 33124
diff changeset
   981
  if (TraceGCTaskManager) {
bc61fce9bac3 8138863: Refactor WaitForBarrierGCTask
brutisso
parents: 33124
diff changeset
   982
    tty->print_cr("[" INTPTR_FORMAT "]"
bc61fce9bac3 8138863: Refactor WaitForBarrierGCTask
brutisso
parents: 33124
diff changeset
   983
                  " WaitForBarrierGCTask::do_it()"
bc61fce9bac3 8138863: Refactor WaitForBarrierGCTask
brutisso
parents: 33124
diff changeset
   984
                  "  [" INTPTR_FORMAT "] (%s)->notify_all()",
bc61fce9bac3 8138863: Refactor WaitForBarrierGCTask
brutisso
parents: 33124
diff changeset
   985
                  p2i(this), p2i(monitor()), monitor()->name());
bc61fce9bac3 8138863: Refactor WaitForBarrierGCTask
brutisso
parents: 33124
diff changeset
   986
  }
bc61fce9bac3 8138863: Refactor WaitForBarrierGCTask
brutisso
parents: 33124
diff changeset
   987
  monitor()->notify_all();
bc61fce9bac3 8138863: Refactor WaitForBarrierGCTask
brutisso
parents: 33124
diff changeset
   988
}
bc61fce9bac3 8138863: Refactor WaitForBarrierGCTask
brutisso
parents: 33124
diff changeset
   989
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   990
Mutex*                   MonitorSupply::_lock     = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   991
GrowableArray<Monitor*>* MonitorSupply::_freelist = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   992
489c9b5090e2 Initial load
duke
parents:
diff changeset
   993
Monitor* MonitorSupply::reserve() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   994
  Monitor* result = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   995
  // Lazy initialization: possible race.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   996
  if (lock() == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   997
    _lock = new Mutex(Mutex::barrier,                  // rank
489c9b5090e2 Initial load
duke
parents:
diff changeset
   998
                      "MonitorSupply mutex",           // name
489c9b5090e2 Initial load
duke
parents:
diff changeset
   999
                      Mutex::_allow_vm_block_flag);    // allow_vm_block
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1000
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1001
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1002
    MutexLockerEx ml(lock());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1003
    // Lazy initialization.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1004
    if (freelist() == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1005
      _freelist =
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 11208
diff changeset
  1006
        new(ResourceObj::C_HEAP, mtGC) GrowableArray<Monitor*>(ParallelGCThreads,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1007
                                                         true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1008
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1009
    if (! freelist()->is_empty()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1010
      result = freelist()->pop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1011
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1012
      result = new Monitor(Mutex::barrier,                  // rank
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1013
                           "MonitorSupply monitor",         // name
28163
322d55d167be 8047290: Make Mutex::_no_safepoint_check_flag locks verify that this lock never checks for safepoint
coleenp
parents: 27880
diff changeset
  1014
                           Mutex::_allow_vm_block_flag,     // allow_vm_block
322d55d167be 8047290: Make Mutex::_no_safepoint_check_flag locks verify that this lock never checks for safepoint
coleenp
parents: 27880
diff changeset
  1015
                           Monitor::_safepoint_check_never);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1016
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1017
    guarantee(result != NULL, "shouldn't return NULL");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1018
    assert(!result->is_locked(), "shouldn't be locked");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1019
    // release lock().
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1020
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1021
  return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1022
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1023
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1024
void MonitorSupply::release(Monitor* instance) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1025
  assert(instance != NULL, "shouldn't release NULL");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1026
  assert(!instance->is_locked(), "shouldn't be locked");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1027
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1028
    MutexLockerEx ml(lock());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1029
    freelist()->push(instance);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1030
    // release lock().
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1031
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1032
}