hotspot/src/share/vm/gc/shared/gcId.cpp
author brutisso
Thu, 14 Jan 2016 09:18:11 +0100
changeset 35491 663c609dfeee
parent 35227 176e593eb364
child 46560 388aa8d67c80
permissions -rw-r--r--
8147000: VM crashes during initialization trying to print log message Reviewed-by: kbarrett, dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
25350
6423a57e5451 8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff changeset
     1
/*
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 25350
diff changeset
     2
 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
25350
6423a57e5451 8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6423a57e5451 8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff changeset
     4
 *
6423a57e5451 8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
6423a57e5451 8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
6423a57e5451 8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff changeset
     7
 * published by the Free Software Foundation.
6423a57e5451 8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff changeset
     8
 *
6423a57e5451 8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
6423a57e5451 8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6423a57e5451 8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
6423a57e5451 8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
6423a57e5451 8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff changeset
    13
 * accompanied this code).
6423a57e5451 8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff changeset
    14
 *
6423a57e5451 8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
6423a57e5451 8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
6423a57e5451 8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
6423a57e5451 8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff changeset
    18
 *
6423a57e5451 8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
6423a57e5451 8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
6423a57e5451 8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff changeset
    21
 * questions.
6423a57e5451 8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff changeset
    22
 *
6423a57e5451 8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff changeset
    23
 */
6423a57e5451 8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff changeset
    24
6423a57e5451 8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff changeset
    25
#include "precompiled.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 25350
diff changeset
    26
#include "gc/shared/gcId.hpp"
25350
6423a57e5451 8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff changeset
    27
#include "runtime/safepoint.hpp"
33107
77bf0d2069a3 8134953: Make the GC ID available in a central place
brutisso
parents: 30764
diff changeset
    28
#include "runtime/thread.inline.hpp"
25350
6423a57e5451 8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff changeset
    29
6423a57e5451 8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff changeset
    30
uint GCId::_next_id = 0;
6423a57e5451 8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff changeset
    31
33107
77bf0d2069a3 8134953: Make the GC ID available in a central place
brutisso
parents: 30764
diff changeset
    32
NamedThread* currentNamedthread() {
77bf0d2069a3 8134953: Make the GC ID available in a central place
brutisso
parents: 30764
diff changeset
    33
  assert(Thread::current()->is_Named_thread(), "This thread must be NamedThread");
77bf0d2069a3 8134953: Make the GC ID available in a central place
brutisso
parents: 30764
diff changeset
    34
  return (NamedThread*)Thread::current();
25350
6423a57e5451 8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff changeset
    35
}
33107
77bf0d2069a3 8134953: Make the GC ID available in a central place
brutisso
parents: 30764
diff changeset
    36
77bf0d2069a3 8134953: Make the GC ID available in a central place
brutisso
parents: 30764
diff changeset
    37
const uint GCId::create() {
77bf0d2069a3 8134953: Make the GC ID available in a central place
brutisso
parents: 30764
diff changeset
    38
  return _next_id++;
77bf0d2069a3 8134953: Make the GC ID available in a central place
brutisso
parents: 30764
diff changeset
    39
}
77bf0d2069a3 8134953: Make the GC ID available in a central place
brutisso
parents: 30764
diff changeset
    40
35227
176e593eb364 8065331: Add trace events for failed allocations
mlarsson
parents: 35061
diff changeset
    41
const uint GCId::peek() {
176e593eb364 8065331: Add trace events for failed allocations
mlarsson
parents: 35061
diff changeset
    42
  return _next_id;
176e593eb364 8065331: Add trace events for failed allocations
mlarsson
parents: 35061
diff changeset
    43
}
176e593eb364 8065331: Add trace events for failed allocations
mlarsson
parents: 35061
diff changeset
    44
33107
77bf0d2069a3 8134953: Make the GC ID available in a central place
brutisso
parents: 30764
diff changeset
    45
const uint GCId::current() {
77bf0d2069a3 8134953: Make the GC ID available in a central place
brutisso
parents: 30764
diff changeset
    46
  assert(currentNamedthread()->gc_id() != undefined(), "Using undefined GC id.");
77bf0d2069a3 8134953: Make the GC ID available in a central place
brutisso
parents: 30764
diff changeset
    47
  return current_raw();
25350
6423a57e5451 8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff changeset
    48
}
33107
77bf0d2069a3 8134953: Make the GC ID available in a central place
brutisso
parents: 30764
diff changeset
    49
77bf0d2069a3 8134953: Make the GC ID available in a central place
brutisso
parents: 30764
diff changeset
    50
const uint GCId::current_raw() {
77bf0d2069a3 8134953: Make the GC ID available in a central place
brutisso
parents: 30764
diff changeset
    51
  return currentNamedthread()->gc_id();
77bf0d2069a3 8134953: Make the GC ID available in a central place
brutisso
parents: 30764
diff changeset
    52
}
77bf0d2069a3 8134953: Make the GC ID available in a central place
brutisso
parents: 30764
diff changeset
    53
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33229
diff changeset
    54
size_t GCId::print_prefix(char* buf, size_t len) {
35491
663c609dfeee 8147000: VM crashes during initialization trying to print log message
brutisso
parents: 35227
diff changeset
    55
  Thread* thread = Thread::current_or_null();
663c609dfeee 8147000: VM crashes during initialization trying to print log message
brutisso
parents: 35227
diff changeset
    56
  if (thread != NULL && thread->is_Named_thread()) {
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33229
diff changeset
    57
    uint gc_id = current_raw();
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33229
diff changeset
    58
    if (gc_id != undefined()) {
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33229
diff changeset
    59
      int ret = jio_snprintf(buf, len, "GC(%u) ", gc_id);
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33229
diff changeset
    60
      assert(ret > 0, "Failed to print prefix. Log buffer too small?");
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33229
diff changeset
    61
      return (size_t)ret;
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33229
diff changeset
    62
    }
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33229
diff changeset
    63
  }
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33229
diff changeset
    64
  return 0;
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33229
diff changeset
    65
}
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33229
diff changeset
    66
33107
77bf0d2069a3 8134953: Make the GC ID available in a central place
brutisso
parents: 30764
diff changeset
    67
GCIdMark::GCIdMark() : _gc_id(GCId::create()) {
77bf0d2069a3 8134953: Make the GC ID available in a central place
brutisso
parents: 30764
diff changeset
    68
  currentNamedthread()->set_gc_id(_gc_id);
25350
6423a57e5451 8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff changeset
    69
}
33107
77bf0d2069a3 8134953: Make the GC ID available in a central place
brutisso
parents: 30764
diff changeset
    70
77bf0d2069a3 8134953: Make the GC ID available in a central place
brutisso
parents: 30764
diff changeset
    71
GCIdMark::GCIdMark(uint gc_id) : _gc_id(gc_id) {
77bf0d2069a3 8134953: Make the GC ID available in a central place
brutisso
parents: 30764
diff changeset
    72
  currentNamedthread()->set_gc_id(_gc_id);
25350
6423a57e5451 8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff changeset
    73
}
33107
77bf0d2069a3 8134953: Make the GC ID available in a central place
brutisso
parents: 30764
diff changeset
    74
77bf0d2069a3 8134953: Make the GC ID available in a central place
brutisso
parents: 30764
diff changeset
    75
GCIdMark::~GCIdMark() {
77bf0d2069a3 8134953: Make the GC ID available in a central place
brutisso
parents: 30764
diff changeset
    76
  currentNamedthread()->set_gc_id(GCId::undefined());
77bf0d2069a3 8134953: Make the GC ID available in a central place
brutisso
parents: 30764
diff changeset
    77
}
77bf0d2069a3 8134953: Make the GC ID available in a central place
brutisso
parents: 30764
diff changeset
    78
33146
77349b58b4c0 8138717: TestGCEventMixedWithG1ConcurrentMark.java fails
brutisso
parents: 33107
diff changeset
    79
GCIdMarkAndRestore::GCIdMarkAndRestore() : _gc_id(GCId::create()) {
33229
51173444fdd5 8139868: CMSScavengeBeforeRemark broken after JDK-8134953
brutisso
parents: 33152
diff changeset
    80
  _previous_gc_id = GCId::current_raw();
33152
6ad7fe735042 8139293: TestGCEventMixedWithG1ConcurrentMark.java fails after JDK-8134953
brutisso
parents: 33146
diff changeset
    81
  currentNamedthread()->set_gc_id(_gc_id);
6ad7fe735042 8139293: TestGCEventMixedWithG1ConcurrentMark.java fails after JDK-8134953
brutisso
parents: 33146
diff changeset
    82
}
6ad7fe735042 8139293: TestGCEventMixedWithG1ConcurrentMark.java fails after JDK-8134953
brutisso
parents: 33146
diff changeset
    83
6ad7fe735042 8139293: TestGCEventMixedWithG1ConcurrentMark.java fails after JDK-8134953
brutisso
parents: 33146
diff changeset
    84
GCIdMarkAndRestore::GCIdMarkAndRestore(uint gc_id) : _gc_id(gc_id) {
33229
51173444fdd5 8139868: CMSScavengeBeforeRemark broken after JDK-8134953
brutisso
parents: 33152
diff changeset
    85
  _previous_gc_id = GCId::current_raw();
33146
77349b58b4c0 8138717: TestGCEventMixedWithG1ConcurrentMark.java fails
brutisso
parents: 33107
diff changeset
    86
  currentNamedthread()->set_gc_id(_gc_id);
77349b58b4c0 8138717: TestGCEventMixedWithG1ConcurrentMark.java fails
brutisso
parents: 33107
diff changeset
    87
}
77349b58b4c0 8138717: TestGCEventMixedWithG1ConcurrentMark.java fails
brutisso
parents: 33107
diff changeset
    88
77349b58b4c0 8138717: TestGCEventMixedWithG1ConcurrentMark.java fails
brutisso
parents: 33107
diff changeset
    89
GCIdMarkAndRestore::~GCIdMarkAndRestore() {
77349b58b4c0 8138717: TestGCEventMixedWithG1ConcurrentMark.java fails
brutisso
parents: 33107
diff changeset
    90
  currentNamedthread()->set_gc_id(_previous_gc_id);
77349b58b4c0 8138717: TestGCEventMixedWithG1ConcurrentMark.java fails
brutisso
parents: 33107
diff changeset
    91
}