src/hotspot/share/gc/shared/gcId.cpp
author coleenp
Tue, 31 Oct 2017 11:55:09 -0400
changeset 47765 b7c7428eaab9
parent 47216 71c04702a3d5
child 49030 1817d118ff66
permissions -rw-r--r--
8189610: Reconcile jvm.h and all jvm_md.h between java.base and hotspot Summary: Removed hotspot version of jvm*h and jni*h files. Reviewed-by: ihse, mchung, 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
/*
46560
388aa8d67c80 8181449: Fix debug.hpp / globalDefinitions.hpp dependency inversion
kbarrett
parents: 35491
diff changeset
     2
 * Copyright (c) 2014, 2017, 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"
47765
b7c7428eaab9 8189610: Reconcile jvm.h and all jvm_md.h between java.base and hotspot
coleenp
parents: 47216
diff changeset
    26
#include "jvm.h"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 25350
diff changeset
    27
#include "gc/shared/gcId.hpp"
25350
6423a57e5451 8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff changeset
    28
#include "runtime/safepoint.hpp"
33107
77bf0d2069a3 8134953: Make the GC ID available in a central place
brutisso
parents: 30764
diff changeset
    29
#include "runtime/thread.inline.hpp"
25350
6423a57e5451 8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff changeset
    30
6423a57e5451 8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff changeset
    31
uint GCId::_next_id = 0;
6423a57e5451 8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff changeset
    32
33107
77bf0d2069a3 8134953: Make the GC ID available in a central place
brutisso
parents: 30764
diff changeset
    33
NamedThread* currentNamedthread() {
77bf0d2069a3 8134953: Make the GC ID available in a central place
brutisso
parents: 30764
diff changeset
    34
  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
    35
  return (NamedThread*)Thread::current();
25350
6423a57e5451 8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff changeset
    36
}
33107
77bf0d2069a3 8134953: Make the GC ID available in a central place
brutisso
parents: 30764
diff changeset
    37
77bf0d2069a3 8134953: Make the GC ID available in a central place
brutisso
parents: 30764
diff changeset
    38
const uint GCId::create() {
77bf0d2069a3 8134953: Make the GC ID available in a central place
brutisso
parents: 30764
diff changeset
    39
  return _next_id++;
77bf0d2069a3 8134953: Make the GC ID available in a central place
brutisso
parents: 30764
diff changeset
    40
}
77bf0d2069a3 8134953: Make the GC ID available in a central place
brutisso
parents: 30764
diff changeset
    41
35227
176e593eb364 8065331: Add trace events for failed allocations
mlarsson
parents: 35061
diff changeset
    42
const uint GCId::peek() {
176e593eb364 8065331: Add trace events for failed allocations
mlarsson
parents: 35061
diff changeset
    43
  return _next_id;
176e593eb364 8065331: Add trace events for failed allocations
mlarsson
parents: 35061
diff changeset
    44
}
176e593eb364 8065331: Add trace events for failed allocations
mlarsson
parents: 35061
diff changeset
    45
33107
77bf0d2069a3 8134953: Make the GC ID available in a central place
brutisso
parents: 30764
diff changeset
    46
const uint GCId::current() {
77bf0d2069a3 8134953: Make the GC ID available in a central place
brutisso
parents: 30764
diff changeset
    47
  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
    48
  return current_raw();
25350
6423a57e5451 8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff changeset
    49
}
33107
77bf0d2069a3 8134953: Make the GC ID available in a central place
brutisso
parents: 30764
diff changeset
    50
77bf0d2069a3 8134953: Make the GC ID available in a central place
brutisso
parents: 30764
diff changeset
    51
const uint GCId::current_raw() {
77bf0d2069a3 8134953: Make the GC ID available in a central place
brutisso
parents: 30764
diff changeset
    52
  return currentNamedthread()->gc_id();
77bf0d2069a3 8134953: Make the GC ID available in a central place
brutisso
parents: 30764
diff changeset
    53
}
77bf0d2069a3 8134953: Make the GC ID available in a central place
brutisso
parents: 30764
diff changeset
    54
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33229
diff changeset
    55
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
    56
  Thread* thread = Thread::current_or_null();
663c609dfeee 8147000: VM crashes during initialization trying to print log message
brutisso
parents: 35227
diff changeset
    57
  if (thread != NULL && thread->is_Named_thread()) {
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33229
diff changeset
    58
    uint gc_id = current_raw();
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33229
diff changeset
    59
    if (gc_id != undefined()) {
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33229
diff changeset
    60
      int ret = jio_snprintf(buf, len, "GC(%u) ", gc_id);
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33229
diff changeset
    61
      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
    62
      return (size_t)ret;
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
  }
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33229
diff changeset
    65
  return 0;
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33229
diff changeset
    66
}
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33229
diff changeset
    67
33107
77bf0d2069a3 8134953: Make the GC ID available in a central place
brutisso
parents: 30764
diff changeset
    68
GCIdMark::GCIdMark() : _gc_id(GCId::create()) {
77bf0d2069a3 8134953: Make the GC ID available in a central place
brutisso
parents: 30764
diff changeset
    69
  currentNamedthread()->set_gc_id(_gc_id);
25350
6423a57e5451 8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff changeset
    70
}
33107
77bf0d2069a3 8134953: Make the GC ID available in a central place
brutisso
parents: 30764
diff changeset
    71
77bf0d2069a3 8134953: Make the GC ID available in a central place
brutisso
parents: 30764
diff changeset
    72
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
    73
  currentNamedthread()->set_gc_id(_gc_id);
25350
6423a57e5451 8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff changeset
    74
}
33107
77bf0d2069a3 8134953: Make the GC ID available in a central place
brutisso
parents: 30764
diff changeset
    75
77bf0d2069a3 8134953: Make the GC ID available in a central place
brutisso
parents: 30764
diff changeset
    76
GCIdMark::~GCIdMark() {
77bf0d2069a3 8134953: Make the GC ID available in a central place
brutisso
parents: 30764
diff changeset
    77
  currentNamedthread()->set_gc_id(GCId::undefined());
77bf0d2069a3 8134953: Make the GC ID available in a central place
brutisso
parents: 30764
diff changeset
    78
}
77bf0d2069a3 8134953: Make the GC ID available in a central place
brutisso
parents: 30764
diff changeset
    79
33146
77349b58b4c0 8138717: TestGCEventMixedWithG1ConcurrentMark.java fails
brutisso
parents: 33107
diff changeset
    80
GCIdMarkAndRestore::GCIdMarkAndRestore() : _gc_id(GCId::create()) {
33229
51173444fdd5 8139868: CMSScavengeBeforeRemark broken after JDK-8134953
brutisso
parents: 33152
diff changeset
    81
  _previous_gc_id = GCId::current_raw();
33152
6ad7fe735042 8139293: TestGCEventMixedWithG1ConcurrentMark.java fails after JDK-8134953
brutisso
parents: 33146
diff changeset
    82
  currentNamedthread()->set_gc_id(_gc_id);
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
6ad7fe735042 8139293: TestGCEventMixedWithG1ConcurrentMark.java fails after JDK-8134953
brutisso
parents: 33146
diff changeset
    85
GCIdMarkAndRestore::GCIdMarkAndRestore(uint gc_id) : _gc_id(gc_id) {
33229
51173444fdd5 8139868: CMSScavengeBeforeRemark broken after JDK-8134953
brutisso
parents: 33152
diff changeset
    86
  _previous_gc_id = GCId::current_raw();
33146
77349b58b4c0 8138717: TestGCEventMixedWithG1ConcurrentMark.java fails
brutisso
parents: 33107
diff changeset
    87
  currentNamedthread()->set_gc_id(_gc_id);
77349b58b4c0 8138717: TestGCEventMixedWithG1ConcurrentMark.java fails
brutisso
parents: 33107
diff changeset
    88
}
77349b58b4c0 8138717: TestGCEventMixedWithG1ConcurrentMark.java fails
brutisso
parents: 33107
diff changeset
    89
77349b58b4c0 8138717: TestGCEventMixedWithG1ConcurrentMark.java fails
brutisso
parents: 33107
diff changeset
    90
GCIdMarkAndRestore::~GCIdMarkAndRestore() {
77349b58b4c0 8138717: TestGCEventMixedWithG1ConcurrentMark.java fails
brutisso
parents: 33107
diff changeset
    91
  currentNamedthread()->set_gc_id(_previous_gc_id);
77349b58b4c0 8138717: TestGCEventMixedWithG1ConcurrentMark.java fails
brutisso
parents: 33107
diff changeset
    92
}