annotate src/hotspot/share/gc/shared/gcId.cpp @ 49210:e4a0cc16b050

8198369: Clean up GCId and GCIdMark Reviewed-by: stefank, eosterlund
author pliden
date Wed, 21 Feb 2018 07:50:33 +0100
parents 1817d118ff66
children
rev   line source
brutisso@25350 1 /*
pliden@49209 2 * Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
brutisso@25350 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
brutisso@25350 4 *
brutisso@25350 5 * This code is free software; you can redistribute it and/or modify it
brutisso@25350 6 * under the terms of the GNU General Public License version 2 only, as
brutisso@25350 7 * published by the Free Software Foundation.
brutisso@25350 8 *
brutisso@25350 9 * This code is distributed in the hope that it will be useful, but WITHOUT
brutisso@25350 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
brutisso@25350 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
brutisso@25350 12 * version 2 for more details (a copy is included in the LICENSE file that
brutisso@25350 13 * accompanied this code).
brutisso@25350 14 *
brutisso@25350 15 * You should have received a copy of the GNU General Public License version
brutisso@25350 16 * 2 along with this work; if not, write to the Free Software Foundation,
brutisso@25350 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
brutisso@25350 18 *
brutisso@25350 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
brutisso@25350 20 * or visit www.oracle.com if you need additional information or have any
brutisso@25350 21 * questions.
brutisso@25350 22 *
brutisso@25350 23 */
brutisso@25350 24
brutisso@25350 25 #include "precompiled.hpp"
coleenp@47827 26 #include "jvm.h"
pliden@30764 27 #include "gc/shared/gcId.hpp"
brutisso@25350 28 #include "runtime/safepoint.hpp"
brutisso@33107 29 #include "runtime/thread.inline.hpp"
brutisso@25350 30
brutisso@25350 31 uint GCId::_next_id = 0;
brutisso@25350 32
brutisso@33107 33 NamedThread* currentNamedthread() {
brutisso@33107 34 assert(Thread::current()->is_Named_thread(), "This thread must be NamedThread");
brutisso@33107 35 return (NamedThread*)Thread::current();
brutisso@25350 36 }
brutisso@33107 37
pliden@49210 38 uint GCId::create() {
brutisso@33107 39 return _next_id++;
brutisso@25350 40 }
brutisso@33107 41
pliden@49210 42 uint GCId::peek() {
mlarsson@35227 43 return _next_id;
mlarsson@35227 44 }
mlarsson@35227 45
pliden@49210 46 uint GCId::current() {
pliden@49209 47 const uint gc_id = currentNamedthread()->gc_id();
pliden@49209 48 assert(gc_id != undefined(), "Using undefined GC id.");
pliden@49209 49 return gc_id;
brutisso@25350 50 }
brutisso@33107 51
pliden@49210 52 uint GCId::current_or_undefined() {
pliden@49209 53 return Thread::current()->is_Named_thread() ? currentNamedthread()->gc_id() : undefined();
brutisso@25350 54 }
brutisso@33107 55
brutisso@35061 56 size_t GCId::print_prefix(char* buf, size_t len) {
brutisso@35491 57 Thread* thread = Thread::current_or_null();
pliden@49209 58 if (thread != NULL) {
pliden@49209 59 uint gc_id = current_or_undefined();
brutisso@35061 60 if (gc_id != undefined()) {
brutisso@35061 61 int ret = jio_snprintf(buf, len, "GC(%u) ", gc_id);
brutisso@35061 62 assert(ret > 0, "Failed to print prefix. Log buffer too small?");
brutisso@35061 63 return (size_t)ret;
brutisso@35061 64 }
brutisso@35061 65 }
brutisso@35061 66 return 0;
brutisso@35061 67 }
brutisso@35061 68
pliden@49210 69 GCIdMark::GCIdMark() : _previous_gc_id(currentNamedthread()->gc_id()) {
pliden@49210 70 currentNamedthread()->set_gc_id(GCId::create());
brutisso@33107 71 }
brutisso@33107 72
pliden@49210 73 GCIdMark::GCIdMark(uint gc_id) : _previous_gc_id(currentNamedthread()->gc_id()) {
pliden@49210 74 currentNamedthread()->set_gc_id(gc_id);
brutisso@33107 75 }
brutisso@33107 76
brutisso@33107 77 GCIdMark::~GCIdMark() {
brutisso@33146 78 currentNamedthread()->set_gc_id(_previous_gc_id);
brutisso@33146 79 }