8298278: JFR: Turn MEMFLAGS into a type for use with the NativeMemoryUsage events

Reviewed-by: sjohanss
This commit is contained in:
Erik Gahlin 2023-02-14 15:02:58 +00:00
parent 77519e5f4f
commit 8933c2d06a
6 changed files with 33 additions and 10 deletions
src/hotspot/share

@ -723,7 +723,7 @@
<Event name="NativeMemoryUsage" category="Java Virtual Machine, Memory" label="Native Memory Usage Per Type"
description="Native memory usage for a given memory type in the JVM" period="everyChunk">
<Field type="string" name="type" label="Memory Type" description="Type used for the native memory allocation" />
<Field type="NMTType" name="type" label="Memory Type" description="Type used for the native memory allocation" />
<Field type="ulong" contentType="bytes" name="reserved" label="Reserved Memory" description="Reserved bytes for this type" />
<Field type="ulong" contentType="bytes" name="committed" label="Committed Memory" description="Committed bytes for this type" />
</Event>
@ -1378,6 +1378,10 @@
<Field type="byte" array="true" name="payload" label="Payload" />
</Type>
<Type name="NMTType" label="Native Memory Tracking Type">
<Field type="string" name="name" label="Name" />
</Type>
<Relation name="JavaMonitorAddress"/>
<Relation name="SafepointId"/>
<Relation name="GcId"/>

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -53,6 +53,7 @@
#include "runtime/safepoint.hpp"
#include "runtime/synchronizer.hpp"
#include "runtime/vmOperations.hpp"
#include "services/nmtCommon.hpp"
#ifdef COMPILER2
#include "opto/compile.hpp"
#include "opto/node.hpp"
@ -321,3 +322,12 @@ void CompilerTypeConstant::serialize(JfrCheckpointWriter& writer) {
writer.write(compilertype2name((CompilerType)i));
}
}
void NMTTypeConstant::serialize(JfrCheckpointWriter& writer) {
writer.write_count(mt_number_of_types);
for (int i = 0; i < mt_number_of_types; ++i) {
writer.write_key(i);
MEMFLAGS flag = NMTUtil::index_to_flag(i);
writer.write(NMTUtil::flag_to_name(flag));
}
}

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -123,4 +123,9 @@ class CompilerTypeConstant : public JfrSerializer {
void serialize(JfrCheckpointWriter& writer);
};
class NMTTypeConstant : public JfrSerializer {
public:
void serialize(JfrCheckpointWriter& writer);
};
#endif // SHARE_JFR_RECORDER_CHECKPOINT_TYPES_JFRTYPE_HPP

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -37,6 +37,7 @@
#include "runtime/javaThread.hpp"
#include "runtime/semaphore.hpp"
#include "runtime/thread.inline.hpp"
#include "services/memTracker.hpp"
#include "utilities/macros.hpp"
class JfrSerializerRegistration : public JfrCHeapObj {
@ -237,6 +238,9 @@ bool JfrTypeManager::initialize() {
register_static_type(TYPE_THREADSTATE, true, new ThreadStateConstant());
register_static_type(TYPE_BYTECODE, true, new BytecodeConstant());
register_static_type(TYPE_COMPILERTYPE, true, new CompilerTypeConstant());
if (MemTracker::enabled()) {
register_static_type(TYPE_NMTTYPE, true, new NMTTypeConstant());
}
return load_thread_constants(JavaThread::current());
}

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2022, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -85,10 +85,10 @@ void MemJFRReporter::send_total_event() {
event.commit();
}
void MemJFRReporter::send_type_event(const Ticks& starttime, const char* type, size_t reserved, size_t committed) {
void MemJFRReporter::send_type_event(const Ticks& starttime, MEMFLAGS flag, size_t reserved, size_t committed) {
EventNativeMemoryUsage event(UNTIMED);
event.set_starttime(starttime);
event.set_type(type);
event.set_type(NMTUtil::flag_to_index(flag));
event.set_reserved(reserved);
event.set_committed(committed);
event.commit();
@ -108,6 +108,6 @@ void MemJFRReporter::send_type_events() {
// Skip mtNone since it is not really used.
continue;
}
send_type_event(timestamp, NMTUtil::flag_to_name(flag), usage->reserved(flag), usage->committed(flag));
send_type_event(timestamp, flag, usage->reserved(flag), usage->committed(flag));
}
}

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2022, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -35,7 +35,7 @@
// so no more synchronization is needed.
class MemJFRReporter : public AllStatic {
private:
static void send_type_event(const Ticks& starttime, const char* tag, size_t reserved, size_t committed);
static void send_type_event(const Ticks& starttime, MEMFLAGS flag, size_t reserved, size_t committed);
public:
static void send_total_event();
static void send_type_events();