From dc17c268e8e73a36a9914924ee5d0c99fb998f0f Mon Sep 17 00:00:00 2001 From: Matthias Baesken Date: Mon, 19 Feb 2024 12:52:35 +0000 Subject: [PATCH] 8325116: Amend jdk.ContainerConfiguration by swap related value Reviewed-by: sgehwolf, lucy, egahlin --- src/hotspot/share/jfr/jni/jfrJniMethod.cpp | 9 +++++++++ src/hotspot/share/jfr/jni/jfrJniMethod.hpp | 2 ++ src/hotspot/share/jfr/jni/jfrJniMethodRegistration.cpp | 1 + .../jdk/jfr/events/ContainerConfigurationEvent.java | 9 +++++++-- src/jdk.jfr/share/classes/jdk/jfr/internal/JVM.java | 6 ++++++ .../classes/jdk/jfr/internal/instrument/JDKEvents.java | 1 + test/hotspot/jtreg/containers/docker/TestJFREvents.java | 3 ++- 7 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/hotspot/share/jfr/jni/jfrJniMethod.cpp b/src/hotspot/share/jfr/jni/jfrJniMethod.cpp index eee46cbbdde..59c770eda29 100644 --- a/src/hotspot/share/jfr/jni/jfrJniMethod.cpp +++ b/src/hotspot/share/jfr/jni/jfrJniMethod.cpp @@ -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 diff --git a/src/hotspot/share/jfr/jni/jfrJniMethod.hpp b/src/hotspot/share/jfr/jni/jfrJniMethod.hpp index c75a4c97219..72351d3e1c1 100644 --- a/src/hotspot/share/jfr/jni/jfrJniMethod.hpp +++ b/src/hotspot/share/jfr/jni/jfrJniMethod.hpp @@ -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); diff --git a/src/hotspot/share/jfr/jni/jfrJniMethodRegistration.cpp b/src/hotspot/share/jfr/jni/jfrJniMethodRegistration.cpp index 338f63fbc4f..7ef831f6282 100644 --- a/src/hotspot/share/jfr/jni/jfrJniMethodRegistration.cpp +++ b/src/hotspot/share/jfr/jni/jfrJniMethodRegistration.cpp @@ -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 diff --git a/src/jdk.jfr/share/classes/jdk/jfr/events/ContainerConfigurationEvent.java b/src/jdk.jfr/share/classes/jdk/jfr/events/ContainerConfigurationEvent.java index 333b734c1c1..cf5a25e5051 100644 --- a/src/jdk.jfr/share/classes/jdk/jfr/events/ContainerConfigurationEvent.java +++ b/src/jdk.jfr/share/classes/jdk/jfr/events/ContainerConfigurationEvent.java @@ -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 @@ -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; } diff --git a/src/jdk.jfr/share/classes/jdk/jfr/internal/JVM.java b/src/jdk.jfr/share/classes/jdk/jfr/internal/JVM.java index 7fcadcddeb0..02edfd1e5ab 100644 --- a/src/jdk.jfr/share/classes/jdk/jfr/internal/JVM.java +++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/JVM.java @@ -627,6 +627,12 @@ public final class JVM { */ 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. * diff --git a/src/jdk.jfr/share/classes/jdk/jfr/internal/instrument/JDKEvents.java b/src/jdk.jfr/share/classes/jdk/jfr/internal/instrument/JDKEvents.java index a7b3c67f2da..10ab2094d5b 100644 --- a/src/jdk.jfr/share/classes/jdk/jfr/internal/instrument/JDKEvents.java +++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/instrument/JDKEvents.java @@ -187,6 +187,7 @@ public final class JDKEvents { t.memoryLimit = containerMetrics.getMemoryLimit(); t.swapMemoryLimit = containerMetrics.getMemoryAndSwapLimit(); t.hostTotalMemory = JVM.hostTotalMemory(); + t.hostTotalSwapMemory = JVM.hostTotalSwapMemory(); t.commit(); } } diff --git a/test/hotspot/jtreg/containers/docker/TestJFREvents.java b/test/hotspot/jtreg/containers/docker/TestJFREvents.java index 682c35bc398..534b580d1fa 100644 --- a/test/hotspot/jtreg/containers/docker/TestJFREvents.java +++ b/test/hotspot/jtreg/containers/docker/TestJFREvents.java @@ -129,7 +129,8 @@ public class TestJFREvents { .shouldContain(cpuSlicePeriodFld + " = " + expectedSlicePeriod) .shouldContain(cpuQuotaFld + " = " + expectedCPUs * expectedSlicePeriod) .shouldContain(memoryLimitFld + " = " + expectedMemoryLimit) - .shouldContain(totalMem + " = " + hostTotalMemory); + .shouldContain(totalMem + " = " + hostTotalMemory) + .shouldContain("hostTotalSwapMemory"); } private static void testCpuUsage() throws Exception {