Skip to content

Commit

Permalink
8325116: Amend jdk.ContainerConfiguration by swap related value
Browse files Browse the repository at this point in the history
Reviewed-by: sgehwolf, lucy, egahlin
  • Loading branch information
MBaesken committed Feb 19, 2024
1 parent b366492 commit dc17c26
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 3 deletions.
9 changes: 9 additions & 0 deletions src/hotspot/share/jfr/jni/jfrJniMethod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,15 @@ JVM_ENTRY_NO_ENV(jlong, jfr_host_total_memory(JNIEnv* env, jclass jvm))
#endif
JVM_END

JVM_ENTRY_NO_ENV(jlong, jfr_host_total_swap_memory(JNIEnv* env, jclass jvm))
#ifdef LINUX
// We want the host swap memory, not the container value.
return os::Linux::host_swap();
#else
return os::total_swap_space();
#endif
JVM_END

JVM_ENTRY_NO_ENV(void, jfr_emit_data_loss(JNIEnv* env, jclass jvm, jlong bytes))
EventDataLoss::commit(bytes, min_jlong);
JVM_END
Expand Down
2 changes: 2 additions & 0 deletions src/hotspot/share/jfr/jni/jfrJniMethod.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ jboolean JNICALL jfr_is_containerized(JNIEnv* env, jclass jvm);

jlong JNICALL jfr_host_total_memory(JNIEnv* env, jclass jvm);

jlong JNICALL jfr_host_total_swap_memory(JNIEnv* env, jclass jvm);

void JNICALL jfr_emit_data_loss(JNIEnv* env, jclass jvm, jlong bytes);

jlong JNICALL jfr_register_stack_filter(JNIEnv* env, jobject classes, jobject methods);
Expand Down
1 change: 1 addition & 0 deletions src/hotspot/share/jfr/jni/jfrJniMethodRegistration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ JfrJniMethodRegistration::JfrJniMethodRegistration(JNIEnv* env) {
(char*)"isInstrumented", (char*)"(Ljava/lang/Class;)Z", (void*) jfr_is_class_instrumented,
(char*)"isContainerized", (char*)"()Z", (void*) jfr_is_containerized,
(char*)"hostTotalMemory", (char*)"()J", (void*) jfr_host_total_memory,
(char*)"hostTotalSwapMemory", (char*)"()J", (void*) jfr_host_total_swap_memory,
(char*)"emitDataLoss", (char*)"(J)V", (void*)jfr_emit_data_loss,
(char*)"registerStackFilter", (char*)"([Ljava/lang/String;[Ljava/lang/String;)J", (void*)jfr_register_stack_filter,
(char*)"unregisterStackFilter", (char*)"(J)V", (void*)jfr_unregister_stack_filter
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, DataDog. All rights reserved.
* Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2024, DataDog. 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
Expand Down Expand Up @@ -80,4 +80,9 @@ public final class ContainerConfigurationEvent extends AbstractPeriodicEvent {
@Description("Total memory of the host running the container")
@DataAmount
public long hostTotalMemory;

@Label("Container Host Total Swap Memory")
@Description("Total swap memory of the host running the container")
@DataAmount
public long hostTotalSwapMemory;
}
6 changes: 6 additions & 0 deletions src/jdk.jfr/share/classes/jdk/jfr/internal/JVM.java
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,12 @@ private static class ChunkRotationMonitor {}
*/
public static native long hostTotalMemory();

/**
* Returns the total amount of swap memory of the host system whether or not this
* JVM runs in a container.
*/
public static native long hostTotalSwapMemory();

/**
* Emit a jdk.DataLoss event for the specified amount of bytes.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ private static void emitContainerConfiguration() {
t.memoryLimit = containerMetrics.getMemoryLimit();
t.swapMemoryLimit = containerMetrics.getMemoryAndSwapLimit();
t.hostTotalMemory = JVM.hostTotalMemory();
t.hostTotalSwapMemory = JVM.hostTotalSwapMemory();
t.commit();
}
}
Expand Down
3 changes: 2 additions & 1 deletion test/hotspot/jtreg/containers/docker/TestJFREvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ private static void testContainerInfo(int expectedCPUs, int expectedMemoryMB, lo
.shouldContain(cpuSlicePeriodFld + " = " + expectedSlicePeriod)
.shouldContain(cpuQuotaFld + " = " + expectedCPUs * expectedSlicePeriod)
.shouldContain(memoryLimitFld + " = " + expectedMemoryLimit)
.shouldContain(totalMem + " = " + hostTotalMemory);
.shouldContain(totalMem + " = " + hostTotalMemory)
.shouldContain("hostTotalSwapMemory");
}

private static void testCpuUsage() throws Exception {
Expand Down

1 comment on commit dc17c26

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.