hotspot/src/share/vm/gc/shared/gcId.cpp
author brutisso
Thu, 10 Dec 2015 14:57:55 +0100
changeset 35061 be6025ebffea
parent 33229 51173444fdd5
child 35227 176e593eb364
permissions -rw-r--r--
8145092: Use Unified Logging for the GC logging Summary: JEP-271. VM changes contributed by brutisso, test changes contributed by david. Reviewed-by: sjohanss, david, brutisso Contributed-by: bengt.rutisson@oracle.com, david.lindholm@oralce.com
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"
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33229
diff changeset
    29
#include "runtime/threadLocalStorage.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
77bf0d2069a3 8134953: Make the GC ID available in a central place
brutisso
parents: 30764
diff changeset
    42
const uint GCId::current() {
77bf0d2069a3 8134953: Make the GC ID available in a central place
brutisso
parents: 30764
diff changeset
    43
  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
    44
  return current_raw();
25350
6423a57e5451 8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff changeset
    45
}
33107
77bf0d2069a3 8134953: Make the GC ID available in a central place
brutisso
parents: 30764
diff changeset
    46
77bf0d2069a3 8134953: Make the GC ID available in a central place
brutisso
parents: 30764
diff changeset
    47
const uint GCId::current_raw() {
77bf0d2069a3 8134953: Make the GC ID available in a central place
brutisso
parents: 30764
diff changeset
    48
  return currentNamedthread()->gc_id();
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
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33229
diff changeset
    51
size_t GCId::print_prefix(char* buf, size_t len) {
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33229
diff changeset
    52
  if (ThreadLocalStorage::is_initialized() && ThreadLocalStorage::thread()->is_Named_thread()) {
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33229
diff changeset
    53
    uint gc_id = current_raw();
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33229
diff changeset
    54
    if (gc_id != undefined()) {
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33229
diff changeset
    55
      int ret = jio_snprintf(buf, len, "GC(%u) ", gc_id);
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33229
diff changeset
    56
      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
    57
      return (size_t)ret;
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33229
diff changeset
    58
    }
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33229
diff changeset
    59
  }
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33229
diff changeset
    60
  return 0;
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33229
diff changeset
    61
}
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33229
diff changeset
    62
33107
77bf0d2069a3 8134953: Make the GC ID available in a central place
brutisso
parents: 30764
diff changeset
    63
GCIdMark::GCIdMark() : _gc_id(GCId::create()) {
77bf0d2069a3 8134953: Make the GC ID available in a central place
brutisso
parents: 30764
diff changeset
    64
  currentNamedthread()->set_gc_id(_gc_id);
25350
6423a57e5451 8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff changeset
    65
}
33107
77bf0d2069a3 8134953: Make the GC ID available in a central place
brutisso
parents: 30764
diff changeset
    66
77bf0d2069a3 8134953: Make the GC ID available in a central place
brutisso
parents: 30764
diff changeset
    67
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
    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() {
77bf0d2069a3 8134953: Make the GC ID available in a central place
brutisso
parents: 30764
diff changeset
    72
  currentNamedthread()->set_gc_id(GCId::undefined());
77bf0d2069a3 8134953: Make the GC ID available in a central place
brutisso
parents: 30764
diff changeset
    73
}
77bf0d2069a3 8134953: Make the GC ID available in a central place
brutisso
parents: 30764
diff changeset
    74
33146
77349b58b4c0 8138717: TestGCEventMixedWithG1ConcurrentMark.java fails
brutisso
parents: 33107
diff changeset
    75
GCIdMarkAndRestore::GCIdMarkAndRestore() : _gc_id(GCId::create()) {
33229
51173444fdd5 8139868: CMSScavengeBeforeRemark broken after JDK-8134953
brutisso
parents: 33152
diff changeset
    76
  _previous_gc_id = GCId::current_raw();
33152
6ad7fe735042 8139293: TestGCEventMixedWithG1ConcurrentMark.java fails after JDK-8134953
brutisso
parents: 33146
diff changeset
    77
  currentNamedthread()->set_gc_id(_gc_id);
6ad7fe735042 8139293: TestGCEventMixedWithG1ConcurrentMark.java fails after JDK-8134953
brutisso
parents: 33146
diff changeset
    78
}
6ad7fe735042 8139293: TestGCEventMixedWithG1ConcurrentMark.java fails after JDK-8134953
brutisso
parents: 33146
diff changeset
    79
6ad7fe735042 8139293: TestGCEventMixedWithG1ConcurrentMark.java fails after JDK-8134953
brutisso
parents: 33146
diff changeset
    80
GCIdMarkAndRestore::GCIdMarkAndRestore(uint gc_id) : _gc_id(gc_id) {
33229
51173444fdd5 8139868: CMSScavengeBeforeRemark broken after JDK-8134953
brutisso
parents: 33152
diff changeset
    81
  _previous_gc_id = GCId::current_raw();
33146
77349b58b4c0 8138717: TestGCEventMixedWithG1ConcurrentMark.java fails
brutisso
parents: 33107
diff changeset
    82
  currentNamedthread()->set_gc_id(_gc_id);
77349b58b4c0 8138717: TestGCEventMixedWithG1ConcurrentMark.java fails
brutisso
parents: 33107
diff changeset
    83
}
77349b58b4c0 8138717: TestGCEventMixedWithG1ConcurrentMark.java fails
brutisso
parents: 33107
diff changeset
    84
77349b58b4c0 8138717: TestGCEventMixedWithG1ConcurrentMark.java fails
brutisso
parents: 33107
diff changeset
    85
GCIdMarkAndRestore::~GCIdMarkAndRestore() {
77349b58b4c0 8138717: TestGCEventMixedWithG1ConcurrentMark.java fails
brutisso
parents: 33107
diff changeset
    86
  currentNamedthread()->set_gc_id(_previous_gc_id);
77349b58b4c0 8138717: TestGCEventMixedWithG1ConcurrentMark.java fails
brutisso
parents: 33107
diff changeset
    87
}