Path: blob/master/src/hotspot/share/logging/logPrefix.hpp
40930 views
/*1* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/23#ifndef SHARE_LOGGING_LOGPREFIX_HPP24#define SHARE_LOGGING_LOGPREFIX_HPP2526#include "gc/shared/gcId.hpp"27#include "logging/logTag.hpp"2829// Prefixes prepend each log message for a specified tagset with a given prefix.30// These prefixes are written before the log message but after the log decorations.31//32// A prefix is defined as a function that takes a buffer (with some size) as argument.33// This function will be called for each log message, and should write the prefix34// to the given buffer. The function should return how many characters it wrote,35// which should never exceed the given size.36//37// List of prefixes for specific tags and/or tagsets.38// Syntax: LOG_PREFIX(<name of prefixer function>, LOG_TAGS(<chosen log tags>))39// Where the prefixer function matches the following signature: size_t (*)(char*, size_t)4041// Prefix function for internal vm test42DEBUG_ONLY(size_t Test_log_prefix_prefixer(char* buf, size_t len);)4344#define LOG_PREFIX_LIST \45LOG_PREFIX(GCId::print_prefix, LOG_TAGS(gc)) \46LOG_PREFIX(GCId::print_prefix, LOG_TAGS(gc, age)) \47LOG_PREFIX(GCId::print_prefix, LOG_TAGS(gc, alloc)) \48LOG_PREFIX(GCId::print_prefix, LOG_TAGS(gc, alloc, region)) \49LOG_PREFIX(GCId::print_prefix, LOG_TAGS(gc, barrier)) \50LOG_PREFIX(GCId::print_prefix, LOG_TAGS(gc, breakpoint)) \51LOG_PREFIX(GCId::print_prefix, LOG_TAGS(gc, classhisto)) \52LOG_PREFIX(GCId::print_prefix, LOG_TAGS(gc, compaction)) \53LOG_PREFIX(GCId::print_prefix, LOG_TAGS(gc, cpu)) \54LOG_PREFIX(GCId::print_prefix, LOG_TAGS(gc, ergo)) \55LOG_PREFIX(GCId::print_prefix, LOG_TAGS(gc, ergo, cset)) \56LOG_PREFIX(GCId::print_prefix, LOG_TAGS(gc, ergo, heap)) \57LOG_PREFIX(GCId::print_prefix, LOG_TAGS(gc, ergo, ihop)) \58LOG_PREFIX(GCId::print_prefix, LOG_TAGS(gc, ergo, refine)) \59LOG_PREFIX(GCId::print_prefix, LOG_TAGS(gc, heap)) \60LOG_PREFIX(GCId::print_prefix, LOG_TAGS(gc, heap, numa)) \61LOG_PREFIX(GCId::print_prefix, LOG_TAGS(gc, heap, region)) \62LOG_PREFIX(GCId::print_prefix, LOG_TAGS(gc, freelist)) \63LOG_PREFIX(GCId::print_prefix, LOG_TAGS(gc, humongous)) \64LOG_PREFIX(GCId::print_prefix, LOG_TAGS(gc, ihop)) \65LOG_PREFIX(GCId::print_prefix, LOG_TAGS(gc, liveness)) \66LOG_PREFIX(GCId::print_prefix, LOG_TAGS(gc, load)) \67LOG_PREFIX(GCId::print_prefix, LOG_TAGS(gc, marking)) \68LOG_PREFIX(GCId::print_prefix, LOG_TAGS(gc, metaspace)) \69LOG_PREFIX(GCId::print_prefix, LOG_TAGS(gc, mmu)) \70LOG_PREFIX(GCId::print_prefix, LOG_TAGS(gc, nmethod)) \71LOG_PREFIX(GCId::print_prefix, LOG_TAGS(gc, phases)) \72LOG_PREFIX(GCId::print_prefix, LOG_TAGS(gc, phases, ref)) \73LOG_PREFIX(GCId::print_prefix, LOG_TAGS(gc, phases, start)) \74LOG_PREFIX(GCId::print_prefix, LOG_TAGS(gc, phases, task)) \75LOG_PREFIX(GCId::print_prefix, LOG_TAGS(gc, phases, verify)) \76LOG_PREFIX(GCId::print_prefix, LOG_TAGS(gc, phases, verify, start)) \77LOG_PREFIX(GCId::print_prefix, LOG_TAGS(gc, plab)) \78LOG_PREFIX(GCId::print_prefix, LOG_TAGS(gc, promotion)) \79LOG_PREFIX(GCId::print_prefix, LOG_TAGS(gc, region)) \80LOG_PREFIX(GCId::print_prefix, LOG_TAGS(gc, remset)) \81LOG_PREFIX(GCId::print_prefix, LOG_TAGS(gc, remset, tracking)) \82LOG_PREFIX(GCId::print_prefix, LOG_TAGS(gc, ref)) \83LOG_PREFIX(GCId::print_prefix, LOG_TAGS(gc, ref, start)) \84LOG_PREFIX(GCId::print_prefix, LOG_TAGS(gc, refine, stats)) \85LOG_PREFIX(GCId::print_prefix, LOG_TAGS(gc, reloc)) \86LOG_PREFIX(GCId::print_prefix, LOG_TAGS(gc, start)) \87LOG_PREFIX(GCId::print_prefix, LOG_TAGS(gc, symboltable)) \88LOG_PREFIX(GCId::print_prefix, LOG_TAGS(gc, sweep)) \89LOG_PREFIX(GCId::print_prefix, LOG_TAGS(gc, task)) \90LOG_PREFIX(GCId::print_prefix, LOG_TAGS(gc, task, start)) \91LOG_PREFIX(GCId::print_prefix, LOG_TAGS(gc, task, stats)) \92LOG_PREFIX(GCId::print_prefix, LOG_TAGS(gc, task, time)) \93DEBUG_ONLY(LOG_PREFIX(Test_log_prefix_prefixer, LOG_TAGS(logging, test))) \94LOG_PREFIX(GCId::print_prefix, LOG_TAGS(gc, tlab)) \95LOG_PREFIX(GCId::print_prefix, LOG_TAGS(gc, verify)) \96LOG_PREFIX(GCId::print_prefix, LOG_TAGS(gc, verify, start)) \97LOG_PREFIX(GCId::print_prefix, LOG_TAGS(gc, workgang))9899100// The empty prefix, used when there's no prefix defined.101template <LogTagType T0, LogTagType T1, LogTagType T2, LogTagType T3, LogTagType T4, LogTagType GuardTag = LogTag::__NO_TAG>102struct LogPrefix : public AllStatic {103STATIC_ASSERT(GuardTag == LogTag::__NO_TAG);104static size_t prefix(char* buf, size_t len) {105return 0;106}107};108109#define LOG_PREFIX(fn, ...) \110template <> struct LogPrefix<__VA_ARGS__> { \111static size_t prefix(char* buf, size_t len) { \112size_t ret = fn(buf, len); \113/* Either prefix did fit (strlen(buf) == ret && ret < len) */ \114/* or the prefix didn't fit in buffer (ret > len && strlen(buf) < len) */ \115assert(ret == 0 || strlen(buf) < len, \116"Buffer overrun by prefix function."); \117assert(ret == 0 || strlen(buf) == ret || ret >= len, \118"Prefix function should return length of prefix written," \119" or the intended length of prefix if the buffer was too small."); \120return ret; \121} \122};123LOG_PREFIX_LIST124#undef LOG_PREFIX125126#endif // SHARE_LOGGING_LOGPREFIX_HPP127128129