src/hotspot/share/gc/shared/gcId.cpp
author stefank
Thu, 22 Feb 2018 18:36:32 +0100
changeset 49048 4e8c86b75428
parent 49031 e4a0cc16b050
permissions -rw-r--r--
8198525: Move _size_policy out of GenCollectorPolicy into GenCollectedHeap Reviewed-by: pliden, sjohanss
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
/*
49030
1817d118ff66 8198267: Allow GCId::current_raw() calls from non-NamedThreads
pliden
parents: 47765
diff changeset
     2
 * Copyright (c) 2014, 2018, 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
49031
e4a0cc16b050 8198369: Clean up GCId and GCIdMark
pliden
parents: 49030
diff changeset
    38
uint GCId::create() {
33107
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
49031
e4a0cc16b050 8198369: Clean up GCId and GCIdMark
pliden
parents: 49030
diff changeset
    42
uint GCId::peek() {
35227
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
49031
e4a0cc16b050 8198369: Clean up GCId and GCIdMark
pliden
parents: 49030
diff changeset
    46
uint GCId::current() {
49030
1817d118ff66 8198267: Allow GCId::current_raw() calls from non-NamedThreads
pliden
parents: 47765
diff changeset
    47
  const uint gc_id = currentNamedthread()->gc_id();
1817d118ff66 8198267: Allow GCId::current_raw() calls from non-NamedThreads
pliden
parents: 47765
diff changeset
    48
  assert(gc_id != undefined(), "Using undefined GC id.");
1817d118ff66 8198267: Allow GCId::current_raw() calls from non-NamedThreads
pliden
parents: 47765
diff changeset
    49
  return gc_id;
25350
6423a57e5451 8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff changeset
    50
}
33107
77bf0d2069a3 8134953: Make the GC ID available in a central place
brutisso
parents: 30764
diff changeset
    51
49031
e4a0cc16b050 8198369: Clean up GCId and GCIdMark
pliden
parents: 49030
diff changeset
    52
uint GCId::current_or_undefined() {
49030
1817d118ff66 8198267: Allow GCId::current_raw() calls from non-NamedThreads
pliden
parents: 47765
diff changeset
    53
  return Thread::current()->is_Named_thread() ? currentNamedthread()->gc_id() : undefined();
33107
77bf0d2069a3 8134953: Make the GC ID available in a central place
brutisso
parents: 30764
diff changeset
    54
}
77bf0d2069a3 8134953: Make the GC ID available in a central place
brutisso
parents: 30764
diff changeset
    55
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33229
diff changeset
    56
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
    57
  Thread* thread = Thread::current_or_null();
49030
1817d118ff66 8198267: Allow GCId::current_raw() calls from non-NamedThreads
pliden
parents: 47765
diff changeset
    58
  if (thread != NULL) {
1817d118ff66 8198267: Allow GCId::current_raw() calls from non-NamedThreads
pliden
parents: 47765
diff changeset
    59
    uint gc_id = current_or_undefined();
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33229
diff changeset
    60
    if (gc_id != undefined()) {
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33229
diff changeset
    61
      int ret = jio_snprintf(buf, len, "GC(%u) ", gc_id);
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33229
diff changeset
    62
      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
    63
      return (size_t)ret;
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
  }
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33229
diff changeset
    66
  return 0;
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33229
diff changeset
    67
}
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33229
diff changeset
    68
49031
e4a0cc16b050 8198369: Clean up GCId and GCIdMark
pliden
parents: 49030
diff changeset
    69
GCIdMark::GCIdMark() : _previous_gc_id(currentNamedthread()->gc_id()) {
e4a0cc16b050 8198369: Clean up GCId and GCIdMark
pliden
parents: 49030
diff changeset
    70
  currentNamedthread()->set_gc_id(GCId::create());
25350
6423a57e5451 8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff changeset
    71
}
33107
77bf0d2069a3 8134953: Make the GC ID available in a central place
brutisso
parents: 30764
diff changeset
    72
49031
e4a0cc16b050 8198369: Clean up GCId and GCIdMark
pliden
parents: 49030
diff changeset
    73
GCIdMark::GCIdMark(uint gc_id) : _previous_gc_id(currentNamedthread()->gc_id()) {
e4a0cc16b050 8198369: Clean up GCId and GCIdMark
pliden
parents: 49030
diff changeset
    74
  currentNamedthread()->set_gc_id(gc_id);
25350
6423a57e5451 8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff changeset
    75
}
33107
77bf0d2069a3 8134953: Make the GC ID available in a central place
brutisso
parents: 30764
diff changeset
    76
77bf0d2069a3 8134953: Make the GC ID available in a central place
brutisso
parents: 30764
diff changeset
    77
GCIdMark::~GCIdMark() {
33146
77349b58b4c0 8138717: TestGCEventMixedWithG1ConcurrentMark.java fails
brutisso
parents: 33107
diff changeset
    78
  currentNamedthread()->set_gc_id(_previous_gc_id);
77349b58b4c0 8138717: TestGCEventMixedWithG1ConcurrentMark.java fails
brutisso
parents: 33107
diff changeset
    79
}