8325116: Amend jdk.ContainerConfiguration by swap related value

Reviewed-by: sgehwolf, lucy, egahlin
This commit is contained in:
Matthias Baesken 2024-02-19 12:52:35 +00:00
parent b366492761
commit dc17c268e8
7 changed files with 28 additions and 3 deletions

View File

@ -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

View File

@ -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);

View File

@ -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

View File

@ -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;
}

View File

@ -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.
*

View File

@ -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();
}
}

View File

@ -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 {