--- old/src/java.base/linux/classes/jdk/internal/platform/CgroupMetrics.java 2020-02-18 11:57:29.824712072 +0100 +++ new/src/java.base/linux/classes/jdk/internal/platform/CgroupMetrics.java 2020-02-18 11:57:29.687711821 +0100 @@ -29,7 +29,7 @@ public class CgroupMetrics implements Metrics { - protected final CgroupSubsystem subsystem; + private final CgroupSubsystem subsystem; CgroupMetrics(CgroupSubsystem subsystem) { this.subsystem = Objects.requireNonNull(subsystem); --- old/src/java.base/linux/classes/jdk/internal/platform/CgroupSubsystemFactory.java 2020-02-18 11:57:30.516713341 +0100 +++ new/src/java.base/linux/classes/jdk/internal/platform/CgroupSubsystemFactory.java 2020-02-18 11:57:30.378713088 +0100 @@ -32,12 +32,9 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.stream.Collectors; -import java.util.stream.Stream; import jdk.internal.platform.cgroupv1.CgroupV1Subsystem; import jdk.internal.platform.cgroupv2.CgroupV2Subsystem; -import jdk.internal.platform.cgroupv2.CgroupV2SubsystemController; class CgroupSubsystemFactory { @@ -89,47 +86,16 @@ // in that case if (anyCgroupsV1Controller && anyCgroupsV2Controller) { Logger logger = System.getLogger("jdk.internal.platform"); - logger.log(Level.WARNING, "Mixed cgroupv1 and cgroupv2 not supported. Metrics disabled."); + logger.log(Level.DEBUG, "Mixed cgroupv1 and cgroupv2 not supported. Metrics disabled."); return null; } if (isCgroupsV2) { - // read mountinfo so as to determine root mount path - String mountPath = null; - try (Stream lines = - CgroupUtil.readFilePrivileged(Paths.get("/proc/self/mountinfo"))) { - - String l = lines.filter(line -> line.contains(" - cgroup2 ")) - .collect(Collectors.joining()); - String[] tokens = l.split(" "); - mountPath = tokens[4]; - } catch (IOException e) { - return null; - } - String cgroupPath = null; - try { - List lines = CgroupUtil.readAllLinesPrivileged(Paths.get("/proc/self/cgroup")); - for (String line: lines) { - String[] tokens = line.split(":"); - if (tokens.length != 3) { - return null; // something is not right. - } - if (!"0".equals(tokens[0])) { - // hierarchy must be zero for cgroups v2 - return null; - } - cgroupPath = tokens[2]; - break; - } - } catch (IOException e) { - return null; - } - CgroupSubsystemController unified = new CgroupV2SubsystemController( - mountPath, - cgroupPath); - return new CgroupMetrics(new CgroupV2Subsystem(unified)); + CgroupSubsystem subsystem = CgroupV2Subsystem.getInstance(); + return subsystem != null ? new CgroupMetrics(subsystem) : null; } else { - return new CgroupV1Metrics(CgroupV1Subsystem.getInstance()); + CgroupV1Subsystem subsystem = CgroupV1Subsystem.getInstance(); + return subsystem != null ? new CgroupV1MetricsImpl(subsystem) : null; } } } --- old/src/java.base/linux/classes/jdk/internal/platform/CgroupUtil.java 2020-02-18 11:57:31.201714597 +0100 +++ new/src/java.base/linux/classes/jdk/internal/platform/CgroupUtil.java 2020-02-18 11:57:31.065714348 +0100 @@ -71,7 +71,7 @@ } } - static List readAllLinesPrivileged(Path path) throws IOException { + public static List readAllLinesPrivileged(Path path) throws IOException { try { PrivilegedExceptionAction> pea = () -> Files.readAllLines(path); return AccessController.doPrivileged(pea); --- old/src/java.base/linux/classes/jdk/internal/platform/CgroupV1Metrics.java 2020-02-18 11:57:31.883715848 +0100 +++ new/src/java.base/linux/classes/jdk/internal/platform/CgroupV1Metrics.java 2020-02-18 11:57:31.746715597 +0100 @@ -1,78 +1,168 @@ +/* + * Copyright (c) 2018, 2020, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + package jdk.internal.platform; /** - * Cgroup v1 Metrics extensions + * + * Cgroup v1 extensions to the Metrics interface. Linux, only. * */ -public class CgroupV1Metrics extends CgroupMetrics implements MetricsCgroupV1 { - - CgroupV1Metrics(MetricsCgroupV1 subsystem) { - super((CgroupSubsystem)subsystem); - } - - @Override - public long getMemoryMaxUsage() { - return ((MetricsCgroupV1)subsystem).getMemoryMaxUsage(); - } - - @Override - public long getKernelMemoryFailCount() { - return ((MetricsCgroupV1)subsystem).getKernelMemoryFailCount(); - } - - @Override - public long getKernelMemoryLimit() { - return ((MetricsCgroupV1)subsystem).getKernelMemoryLimit(); - } - - @Override - public long getKernelMemoryMaxUsage() { - return ((MetricsCgroupV1)subsystem).getKernelMemoryMaxUsage(); - } - - @Override - public long getKernelMemoryUsage() { - return ((MetricsCgroupV1)subsystem).getKernelMemoryUsage(); - } - - @Override - public long getTcpMemoryFailCount() { - return ((MetricsCgroupV1)subsystem).getTcpMemoryFailCount(); - } - - @Override - public long getTcpMemoryLimit() { - return ((MetricsCgroupV1)subsystem).getTcpMemoryLimit(); - } - - @Override - public long getTcpMemoryMaxUsage() { - return ((MetricsCgroupV1)subsystem).getTcpMemoryMaxUsage(); - } - - @Override - public long getMemoryAndSwapFailCount() { - return ((MetricsCgroupV1)subsystem).getMemoryAndSwapFailCount(); - } - - @Override - public long getMemoryAndSwapMaxUsage() { - return ((MetricsCgroupV1)subsystem).getMemoryAndSwapMaxUsage(); - } - - @Override - public Boolean isMemoryOOMKillEnabled() { - return ((MetricsCgroupV1)subsystem).isMemoryOOMKillEnabled(); - } - - @Override - public double getCpuSetMemoryPressure() { - return ((MetricsCgroupV1)subsystem).getCpuSetMemoryPressure(); - } - - @Override - public Boolean isCpuSetMemoryPressureEnabled() { - return ((MetricsCgroupV1)subsystem).isCpuSetMemoryPressureEnabled(); - } +public interface CgroupV1Metrics extends Metrics { + /** + * Returns the largest amount of physical memory, in bytes, that + * have been allocated in the Isolation Group. + * + * @return The largest amount of memory in bytes or -1 if this + * metric is not available. Returns -2 if this metric is not + * supported. + * + */ + public long getMemoryMaxUsage(); + + /** + * Returns the number of times that kernel memory requests in the + * Isolation Group have exceeded the kernel memory limit. + * + * @return The number of exceeded requests or -1 if metric + * is not available. + * + */ + public long getKernelMemoryFailCount(); + + /** + * Returns the maximum amount of kernel physical memory, in bytes, that + * can be allocated in the Isolation Group. + * + * @return The maximum amount of memory in bytes or -1 if + * there is no limit set. + * + */ + public long getKernelMemoryLimit(); + + /** + * Returns the largest amount of kernel physical memory, in bytes, that + * have been allocated in the Isolation Group. + * + * @return The largest amount of memory in bytes or -1 if this + * metric is not available. + * + */ + public long getKernelMemoryMaxUsage(); + + /** + * Returns the amount of kernel physical memory, in bytes, that + * is currently allocated in the current Isolation Group. + * + * @return The amount of memory in bytes allocated or -1 if this + * metric is not available. + * + */ + public long getKernelMemoryUsage(); + + /** + * Returns the number of times that networking memory requests in the + * Isolation Group have exceeded the kernel memory limit. + * + * @return The number of exceeded requests or -1 if the metric + * is not available. + * + */ + public long getTcpMemoryFailCount(); + + /** + * Returns the maximum amount of networking physical memory, in bytes, + * that can be allocated in the Isolation Group. + * + * @return The maximum amount of memory in bytes or -1 if + * there is no limit. + * + */ + public long getTcpMemoryLimit(); + + /** + * Returns the largest amount of networking physical memory, in bytes, + * that have been allocated in the Isolation Group. + * + * @return The largest amount of memory in bytes or -1 if this + * metric is not available. + * + */ + public long getTcpMemoryMaxUsage(); + + /** + * Returns the number of times that user memory requests in the + * Isolation Group have exceeded the memory + swap limit. + * + * @return The number of exceeded requests or -1 if the metric + * is not available. + * + */ + public long getMemoryAndSwapFailCount(); + + /** + * Returns the largest amount of physical memory and swap space, + * in bytes, that have been allocated in the Isolation Group. + * + * @return The largest amount of memory in bytes or -1 if this + * metric is not available. + * + */ + public long getMemoryAndSwapMaxUsage(); + + /** + * Returns the state of the Operating System Out of Memory termination + * policy. + * + * @return Returns true if operating system will terminate processes + * in the Isolation Group that exceed the amount of available + * memory, otherwise false. null will be returned if this + * capability is not available on the current operating system. + * + */ + public Boolean isMemoryOOMKillEnabled(); + + /** + * Returns the (attempts per second * 1000), if enabled, that the + * operating system tries to satisfy a memory request for any + * process in the current Isolation Group when no free memory is + * readily available. Use {@link #isCpuSetMemoryPressureEnabled()} to + * determine if this support is enabled. + * + * @return Memory pressure or 0 if not enabled or -1 if metric is not + * available. + * + */ + public double getCpuSetMemoryPressure(); + + /** + * Returns the state of the memory pressure detection support. + * + * @return true if support is available and enabled. false otherwise. + * + */ + public Boolean isCpuSetMemoryPressureEnabled(); } --- old/src/java.base/linux/classes/jdk/internal/platform/cgroupv1/CgroupV1Subsystem.java 2020-02-18 11:57:32.570717108 +0100 +++ new/src/java.base/linux/classes/jdk/internal/platform/cgroupv1/CgroupV1Subsystem.java 2020-02-18 11:57:32.430716851 +0100 @@ -33,9 +33,9 @@ import jdk.internal.platform.CgroupSubsystem; import jdk.internal.platform.CgroupSubsystemController; import jdk.internal.platform.CgroupUtil; -import jdk.internal.platform.MetricsCgroupV1; +import jdk.internal.platform.CgroupV1Metrics; -public class CgroupV1Subsystem implements CgroupSubsystem, MetricsCgroupV1 { +public class CgroupV1Subsystem implements CgroupSubsystem, CgroupV1Metrics { private CgroupV1MemorySubSystemController memory; private CgroupV1SubsystemController cpu; private CgroupV1SubsystemController cpuacct; --- old/src/java.base/linux/classes/jdk/internal/platform/cgroupv2/CgroupV2Subsystem.java 2020-02-18 11:57:33.263718379 +0100 +++ new/src/java.base/linux/classes/jdk/internal/platform/cgroupv2/CgroupV2Subsystem.java 2020-02-18 11:57:33.124718124 +0100 @@ -27,9 +27,11 @@ import java.io.IOException; import java.nio.file.Paths; +import java.util.List; import java.util.concurrent.TimeUnit; import java.util.function.Function; import java.util.stream.Collectors; +import java.util.stream.Stream; import jdk.internal.platform.CgroupSubsystem; import jdk.internal.platform.CgroupSubsystemController; @@ -37,6 +39,7 @@ public class CgroupV2Subsystem implements CgroupSubsystem { + private static final CgroupV2Subsystem INSTANCE = initSubsystem(); private static final long[] LONG_ARRAY_NOT_SUPPORTED = null; private static final int[] INT_ARRAY_UNAVAILABLE = null; private final CgroupSubsystemController unified; @@ -45,7 +48,7 @@ private static final String MAX_VAL = "max"; private static final Object EMPTY_STR = ""; - public CgroupV2Subsystem(CgroupSubsystemController unified) { + private CgroupV2Subsystem(CgroupSubsystemController unified) { this.unified = unified; } @@ -56,6 +59,47 @@ CgroupSubsystem.LONG_RETVAL_UNLIMITED); } + private static CgroupV2Subsystem initSubsystem() { + // read mountinfo so as to determine root mount path + String mountPath = null; + try (Stream lines = + CgroupUtil.readFilePrivileged(Paths.get("/proc/self/mountinfo"))) { + + String l = lines.filter(line -> line.contains(" - cgroup2 ")) + .collect(Collectors.joining()); + String[] tokens = l.split(" "); + mountPath = tokens[4]; + } catch (IOException e) { + return null; + } + String cgroupPath = null; + try { + List lines = CgroupUtil.readAllLinesPrivileged(Paths.get("/proc/self/cgroup")); + for (String line: lines) { + String[] tokens = line.split(":"); + if (tokens.length != 3) { + return null; // something is not right. + } + if (!"0".equals(tokens[0])) { + // hierarchy must be zero for cgroups v2 + return null; + } + cgroupPath = tokens[2]; + break; + } + } catch (IOException e) { + return null; + } + CgroupSubsystemController unified = new CgroupV2SubsystemController( + mountPath, + cgroupPath); + return new CgroupV2Subsystem(unified); + } + + public static CgroupSubsystem getInstance() { + return INSTANCE; + } + @Override public String getProvider() { return PROVIDER_NAME; --- old/src/java.base/share/classes/sun/launcher/LauncherHelper.java 2020-02-18 11:57:33.969719673 +0100 +++ new/src/java.base/share/classes/sun/launcher/LauncherHelper.java 2020-02-18 11:57:33.833719424 +0100 @@ -119,7 +119,7 @@ private static final String defaultBundleName = "sun.launcher.resources.launcher"; - private static final long LONG_RETVAL_NOT_SUPPORTED = -2; + private static class ResourceBundleHolder { private static final ResourceBundle RB = ResourceBundle.getBundle(defaultBundleName); @@ -324,11 +324,13 @@ return; } + final long longRetvalNotSupported = -2; + ostream.println(INDENT + "Provider: " + c.getProvider()); ostream.println(INDENT + "Effective CPU Count: " + c.getEffectiveCpuCount()); - ostream.println(formatCpuVal(c.getCpuPeriod(), INDENT + "CPU Period: ")); - ostream.println(formatCpuVal(c.getCpuQuota(), INDENT + "CPU Quota: ")); - ostream.println(formatCpuVal(c.getCpuShares(), INDENT + "CPU Shares: ")); + ostream.println(formatCpuVal(c.getCpuPeriod(), INDENT + "CPU Period: ", longRetvalNotSupported)); + ostream.println(formatCpuVal(c.getCpuQuota(), INDENT + "CPU Quota: ", longRetvalNotSupported)); + ostream.println(formatCpuVal(c.getCpuShares(), INDENT + "CPU Shares: ", longRetvalNotSupported)); int cpus[] = c.getCpuSetCpus(); if (cpus != null) { @@ -395,45 +397,37 @@ } long limit = c.getMemoryLimit(); - ostream.println(formatLimitString(limit, INDENT + "Memory Limit: ")); + ostream.println(formatLimitString(limit, INDENT + "Memory Limit: ", longRetvalNotSupported)); limit = c.getMemorySoftLimit(); - ostream.println(formatLimitString(limit, INDENT + "Memory Soft Limit: ")); + ostream.println(formatLimitString(limit, INDENT + "Memory Soft Limit: ", longRetvalNotSupported)); limit = c.getMemoryAndSwapLimit(); - ostream.println(formatLimitString(limit, INDENT + "Memory & Swap Limit: ")); + ostream.println(formatLimitString(limit, INDENT + "Memory & Swap Limit: ", longRetvalNotSupported)); ostream.println(""); } - private static String formatLimitString(long limit, String prefix) { + private static String formatLimitString(long limit, String prefix, long unavailable) { if (limit >= 0) { return prefix + SizePrefix.scaleValue(limit); - } else if (limit == LONG_RETVAL_NOT_SUPPORTED) { + } else if (limit == unavailable) { return prefix + "N/A"; } else { return prefix + "Unlimited"; } } - private static String formatCpuVal(long cpuVal, String prefix) { + private static String formatCpuVal(long cpuVal, String prefix, long unavailable) { if (cpuVal >= 0) { return prefix + cpuVal + "us"; - } else if (cpuVal == LONG_RETVAL_NOT_SUPPORTED) { + } else if (cpuVal == unavailable) { return prefix + "N/A"; } else { return prefix + cpuVal; } } - private static String formatBoolean(Boolean value, String prefix) { - if (value != null) { - return prefix + value; - } else { - return prefix + "N/A"; - } - } - private enum SizePrefix { KILO(1024, "K"), --- old/test/jdk/jdk/internal/platform/cgroup/TestCgroupSubsystemController.java 2020-02-18 11:57:34.667720953 +0100 +++ new/test/jdk/jdk/internal/platform/cgroup/TestCgroupSubsystemController.java 2020-02-18 11:57:34.524720691 +0100 @@ -1,22 +1,3 @@ -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.Arrays; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import jdk.internal.platform.CgroupSubsystemController; -import jdk.test.lib.Utils; -import jdk.test.lib.util.FileUtils; - /* * Copyright (c) 2020, Red Hat Inc. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. @@ -40,6 +21,26 @@ * questions. */ + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Arrays; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import jdk.internal.platform.CgroupSubsystemController; +import jdk.test.lib.Utils; +import jdk.test.lib.util.FileUtils; + /* * @test * @requires os.family == "linux" --- old/test/jdk/jdk/internal/platform/docker/MetricsMemoryTester.java 2020-02-18 11:57:35.348722202 +0100 +++ new/test/jdk/jdk/internal/platform/docker/MetricsMemoryTester.java 2020-02-18 11:57:35.209721948 +0100 @@ -24,7 +24,7 @@ import java.util.Arrays; import jdk.internal.platform.Metrics; -import jdk.internal.platform.MetricsCgroupV1; +import jdk.internal.platform.CgroupV1Metrics; public class MetricsMemoryTester { public static void main(String[] args) { @@ -110,8 +110,8 @@ private static void testKernelMemoryLimit(String value) { Metrics m = Metrics.systemMetrics(); - if (m instanceof MetricsCgroupV1) { - MetricsCgroupV1 mCgroupV1 = (MetricsCgroupV1)m; + if (m instanceof CgroupV1Metrics) { + CgroupV1Metrics mCgroupV1 = (CgroupV1Metrics)m; System.out.println("TEST PASSED!!!"); long limit = getMemoryValue(value); long kmemlimit = mCgroupV1.getKernelMemoryLimit(); @@ -155,8 +155,8 @@ private static void testOomKillFlag(boolean oomKillFlag) { Metrics m = Metrics.systemMetrics(); - if (m instanceof MetricsCgroupV1) { - MetricsCgroupV1 mCgroupV1 = (MetricsCgroupV1)m; + if (m instanceof CgroupV1Metrics) { + CgroupV1Metrics mCgroupV1 = (CgroupV1Metrics)m; Boolean expected = Boolean.valueOf(oomKillFlag); Boolean actual = mCgroupV1.isMemoryOOMKillEnabled(); if (!(expected.equals(actual))) { --- old/test/lib/jdk/test/lib/containers/cgroup/CPUSetsReader.java 2020-02-18 11:57:36.034723461 +0100 +++ new/test/lib/jdk/test/lib/containers/cgroup/CPUSetsReader.java 2020-02-18 11:57:35.896723207 +0100 @@ -55,7 +55,7 @@ public static int getNumCpus() { String path = "/proc/cpuinfo"; - try(Stream stream = Files.lines(Paths.get(path))) { + try (Stream stream = Files.lines(Paths.get(path))) { return (int) stream.filter(line -> line.startsWith("processor")).count(); } catch (IOException e) { return 0; --- old/test/lib/jdk/test/lib/containers/cgroup/CgroupMetricsTester.java 2020-02-18 11:57:36.716724711 +0100 +++ new/test/lib/jdk/test/lib/containers/cgroup/CgroupMetricsTester.java 2020-02-18 11:57:36.579724460 +0100 @@ -1,12 +1,10 @@ /* - * Copyright (c) 2019, Red Hat Inc. + * Copyright (c) 2020, Red Hat Inc. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. + * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or --- old/test/lib/jdk/test/lib/containers/cgroup/MetricsTester.java 2020-02-18 11:57:37.409725982 +0100 +++ new/test/lib/jdk/test/lib/containers/cgroup/MetricsTester.java 2020-02-18 11:57:37.268725724 +0100 @@ -1,12 +1,10 @@ /* - * Copyright (c) 2019, Red Hat Inc. + * Copyright (c) 2020, Red Hat Inc. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. + * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or @@ -23,6 +21,7 @@ * questions. */ + package jdk.test.lib.containers.cgroup; import java.util.Objects; --- old/test/lib/jdk/test/lib/containers/cgroup/MetricsTesterCgroupV1.java 2020-02-18 11:57:38.096727242 +0100 +++ new/test/lib/jdk/test/lib/containers/cgroup/MetricsTesterCgroupV1.java 2020-02-18 11:57:37.957726987 +0100 @@ -39,7 +39,7 @@ import java.util.stream.Stream; import jdk.internal.platform.Metrics; -import jdk.internal.platform.MetricsCgroupV1; +import jdk.internal.platform.CgroupV1Metrics; public class MetricsTesterCgroupV1 implements CgroupMetricsTester { @@ -204,7 +204,7 @@ } public void testMemorySubsystem() { - MetricsCgroupV1 metrics = (MetricsCgroupV1)Metrics.systemMetrics(); + CgroupV1Metrics metrics = (CgroupV1Metrics)Metrics.systemMetrics(); // User Memory long oldVal = metrics.getMemoryFailCount(); @@ -328,7 +328,7 @@ } public void testCpuAccounting() { - MetricsCgroupV1 metrics = (MetricsCgroupV1)Metrics.systemMetrics(); + CgroupV1Metrics metrics = (CgroupV1Metrics)Metrics.systemMetrics(); long oldVal = metrics.getCpuUsage(); long newVal = getLongValueFromFile(Controller.CPUACCT, "cpuacct.usage"); @@ -367,7 +367,7 @@ } public void testCpuSchedulingMetrics() { - MetricsCgroupV1 metrics = (MetricsCgroupV1)Metrics.systemMetrics(); + CgroupV1Metrics metrics = (CgroupV1Metrics)Metrics.systemMetrics(); long oldVal = metrics.getCpuPeriod(); long newVal = getLongValueFromFile(Controller.CPUACCT, "cpu.cfs_period_us"); if (!CgroupMetricsTester.compareWithErrorMargin(oldVal, newVal)) { @@ -407,7 +407,7 @@ } public void testCpuSets() { - MetricsCgroupV1 metrics = (MetricsCgroupV1)Metrics.systemMetrics(); + CgroupV1Metrics metrics = (CgroupV1Metrics)Metrics.systemMetrics(); Integer[] oldVal = Arrays.stream(metrics.getCpuSetCpus()).boxed().toArray(Integer[]::new); Arrays.sort(oldVal); @@ -475,7 +475,7 @@ } private void testBlkIO() { - MetricsCgroupV1 metrics = (MetricsCgroupV1)Metrics.systemMetrics(); + CgroupV1Metrics metrics = (CgroupV1Metrics)Metrics.systemMetrics(); long oldVal = metrics.getBlkIOServiceCount(); long newVal = getLongValueFromFile(Controller.BLKIO, "blkio.throttle.io_service_bytes", "Total"); @@ -492,7 +492,7 @@ } public void testCpuConsumption() throws IOException, InterruptedException { - MetricsCgroupV1 metrics = (MetricsCgroupV1)Metrics.systemMetrics(); + CgroupV1Metrics metrics = (CgroupV1Metrics)Metrics.systemMetrics(); // make system call long newSysVal = metrics.getCpuSystemUsage(); long newUserVal = metrics.getCpuUserUsage(); @@ -531,7 +531,7 @@ } public void testMemoryUsage() throws Exception { - MetricsCgroupV1 metrics = (MetricsCgroupV1)Metrics.systemMetrics(); + CgroupV1Metrics metrics = (CgroupV1Metrics)Metrics.systemMetrics(); long memoryMaxUsage = metrics.getMemoryMaxUsage(); long memoryUsage = metrics.getMemoryUsage(); long newMemoryMaxUsage = 0, newMemoryUsage = 0; --- old/test/lib/jdk/test/lib/containers/cgroup/MetricsTesterCgroupV2.java 2020-02-18 11:57:38.808728548 +0100 +++ new/test/lib/jdk/test/lib/containers/cgroup/MetricsTesterCgroupV2.java 2020-02-18 11:57:38.669728293 +0100 @@ -4,9 +4,7 @@ * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. + * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or --- old/src/java.base/linux/classes/jdk/internal/platform/CgroupV1Metrics.java 2020-02-18 11:57:39.590729982 +0100 +++ /dev/null 2020-02-18 07:38:19.571312140 +0100 @@ -1,78 +0,0 @@ -package jdk.internal.platform; - -/** - * Cgroup v1 Metrics extensions - * - */ -public class CgroupV1Metrics extends CgroupMetrics implements MetricsCgroupV1 { - - CgroupV1Metrics(MetricsCgroupV1 subsystem) { - super((CgroupSubsystem)subsystem); - } - - @Override - public long getMemoryMaxUsage() { - return ((MetricsCgroupV1)subsystem).getMemoryMaxUsage(); - } - - @Override - public long getKernelMemoryFailCount() { - return ((MetricsCgroupV1)subsystem).getKernelMemoryFailCount(); - } - - @Override - public long getKernelMemoryLimit() { - return ((MetricsCgroupV1)subsystem).getKernelMemoryLimit(); - } - - @Override - public long getKernelMemoryMaxUsage() { - return ((MetricsCgroupV1)subsystem).getKernelMemoryMaxUsage(); - } - - @Override - public long getKernelMemoryUsage() { - return ((MetricsCgroupV1)subsystem).getKernelMemoryUsage(); - } - - @Override - public long getTcpMemoryFailCount() { - return ((MetricsCgroupV1)subsystem).getTcpMemoryFailCount(); - } - - @Override - public long getTcpMemoryLimit() { - return ((MetricsCgroupV1)subsystem).getTcpMemoryLimit(); - } - - @Override - public long getTcpMemoryMaxUsage() { - return ((MetricsCgroupV1)subsystem).getTcpMemoryMaxUsage(); - } - - @Override - public long getMemoryAndSwapFailCount() { - return ((MetricsCgroupV1)subsystem).getMemoryAndSwapFailCount(); - } - - @Override - public long getMemoryAndSwapMaxUsage() { - return ((MetricsCgroupV1)subsystem).getMemoryAndSwapMaxUsage(); - } - - @Override - public Boolean isMemoryOOMKillEnabled() { - return ((MetricsCgroupV1)subsystem).isMemoryOOMKillEnabled(); - } - - @Override - public double getCpuSetMemoryPressure() { - return ((MetricsCgroupV1)subsystem).getCpuSetMemoryPressure(); - } - - @Override - public Boolean isCpuSetMemoryPressureEnabled() { - return ((MetricsCgroupV1)subsystem).isCpuSetMemoryPressureEnabled(); - } - -} --- /dev/null 2020-02-18 07:38:19.571312140 +0100 +++ new/src/java.base/linux/classes/jdk/internal/platform/CgroupV1MetricsImpl.java 2020-02-18 11:57:39.364729567 +0100 @@ -0,0 +1,106 @@ +/* + * Copyright (c) 2020, Red Hat Inc. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.internal.platform; + +/** + * Cgroup v1 Metrics extensions + * + */ +public class CgroupV1MetricsImpl extends CgroupMetrics implements CgroupV1Metrics { + + private final CgroupV1Metrics metrics; + + CgroupV1MetricsImpl(CgroupV1Metrics metrics) { + super((CgroupSubsystem)metrics); + this.metrics = metrics; + } + + @Override + public long getMemoryMaxUsage() { + return metrics.getMemoryMaxUsage(); + } + + @Override + public long getKernelMemoryFailCount() { + return metrics.getKernelMemoryFailCount(); + } + + @Override + public long getKernelMemoryLimit() { + return metrics.getKernelMemoryLimit(); + } + + @Override + public long getKernelMemoryMaxUsage() { + return metrics.getKernelMemoryMaxUsage(); + } + + @Override + public long getKernelMemoryUsage() { + return metrics.getKernelMemoryUsage(); + } + + @Override + public long getTcpMemoryFailCount() { + return metrics.getTcpMemoryFailCount(); + } + + @Override + public long getTcpMemoryLimit() { + return metrics.getTcpMemoryLimit(); + } + + @Override + public long getTcpMemoryMaxUsage() { + return metrics.getTcpMemoryMaxUsage(); + } + + @Override + public long getMemoryAndSwapFailCount() { + return metrics.getMemoryAndSwapFailCount(); + } + + @Override + public long getMemoryAndSwapMaxUsage() { + return metrics.getMemoryAndSwapMaxUsage(); + } + + @Override + public Boolean isMemoryOOMKillEnabled() { + return metrics.isMemoryOOMKillEnabled(); + } + + @Override + public double getCpuSetMemoryPressure() { + return metrics.getCpuSetMemoryPressure(); + } + + @Override + public Boolean isCpuSetMemoryPressureEnabled() { + return metrics.isCpuSetMemoryPressureEnabled(); + } + +} --- old/src/java.base/share/classes/jdk/internal/platform/MetricsCgroupV1.java 2020-02-18 11:57:40.308731299 +0100 +++ /dev/null 2020-02-18 07:38:19.571312140 +0100 @@ -1,168 +0,0 @@ -/* - * Copyright (c) 2018, 2020, 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 - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package jdk.internal.platform; - -/** - * - * Cgroup v1 extensions to the Metrics interface. - * - */ -public interface MetricsCgroupV1 extends Metrics { - - /** - * Returns the largest amount of physical memory, in bytes, that - * have been allocated in the Isolation Group. - * - * @return The largest amount of memory in bytes or -1 if this - * metric is not available. Returns -2 if this metric is not - * supported. - * - */ - public long getMemoryMaxUsage(); - - /** - * Returns the number of times that kernel memory requests in the - * Isolation Group have exceeded the kernel memory limit. - * - * @return The number of exceeded requests or -1 if metric - * is not available. - * - */ - public long getKernelMemoryFailCount(); - - /** - * Returns the maximum amount of kernel physical memory, in bytes, that - * can be allocated in the Isolation Group. - * - * @return The maximum amount of memory in bytes or -1 if - * there is no limit set. - * - */ - public long getKernelMemoryLimit(); - - /** - * Returns the largest amount of kernel physical memory, in bytes, that - * have been allocated in the Isolation Group. - * - * @return The largest amount of memory in bytes or -1 if this - * metric is not available. - * - */ - public long getKernelMemoryMaxUsage(); - - /** - * Returns the amount of kernel physical memory, in bytes, that - * is currently allocated in the current Isolation Group. - * - * @return The amount of memory in bytes allocated or -1 if this - * metric is not available. - * - */ - public long getKernelMemoryUsage(); - - /** - * Returns the number of times that networking memory requests in the - * Isolation Group have exceeded the kernel memory limit. - * - * @return The number of exceeded requests or -1 if the metric - * is not available. - * - */ - public long getTcpMemoryFailCount(); - - /** - * Returns the maximum amount of networking physical memory, in bytes, - * that can be allocated in the Isolation Group. - * - * @return The maximum amount of memory in bytes or -1 if - * there is no limit. - * - */ - public long getTcpMemoryLimit(); - - /** - * Returns the largest amount of networking physical memory, in bytes, - * that have been allocated in the Isolation Group. - * - * @return The largest amount of memory in bytes or -1 if this - * metric is not available. - * - */ - public long getTcpMemoryMaxUsage(); - - /** - * Returns the number of times that user memory requests in the - * Isolation Group have exceeded the memory + swap limit. - * - * @return The number of exceeded requests or -1 if the metric - * is not available. - * - */ - public long getMemoryAndSwapFailCount(); - - /** - * Returns the largest amount of physical memory and swap space, - * in bytes, that have been allocated in the Isolation Group. - * - * @return The largest amount of memory in bytes or -1 if this - * metric is not available. - * - */ - public long getMemoryAndSwapMaxUsage(); - - /** - * Returns the state of the Operating System Out of Memory termination - * policy. - * - * @return Returns true if operating system will terminate processes - * in the Isolation Group that exceed the amount of available - * memory, otherwise false. null will be returned if this - * capability is not available on the current operating system. - * - */ - public Boolean isMemoryOOMKillEnabled(); - - /** - * Returns the (attempts per second * 1000), if enabled, that the - * operating system tries to satisfy a memory request for any - * process in the current Isolation Group when no free memory is - * readily available. Use {@link #isCpuSetMemoryPressureEnabled()} to - * determine if this support is enabled. - * - * @return Memory pressure or 0 if not enabled or -1 if metric is not - * available. - * - */ - public double getCpuSetMemoryPressure(); - - /** - * Returns the state of the memory pressure detection support. - * - * @return true if support is available and enabled. false otherwise. - * - */ - public Boolean isCpuSetMemoryPressureEnabled(); -}