< prev index next >

test/jdk/jdk/internal/platform/docker/MetricsMemoryTester.java

Print this page
@  rev 57585 : 8231111: Cgroups v2: Rework Metrics in java.base so as to recognize unified hierarchy
|  Reviewed-by: bobv
~

*** 1,7 **** /* ! * Copyright (c) 2018, 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. --- 1,7 ---- /* ! * 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.
*** 63,84 **** --- 63,92 ---- private static void testMemoryFailCount() { long count = Metrics.systemMetrics().getMemoryFailCount(); // Allocate 512M of data byte[][] bytes = new byte[64][]; + boolean atLeastOneAllocationWorked = false; for (int i = 0; i < 64; i++) { try { bytes[i] = new byte[8 * 1024 * 1024]; + atLeastOneAllocationWorked = true; // Break out as soon as we see an increase in failcount // to avoid getting killed by the OOM killer. if (Metrics.systemMetrics().getMemoryFailCount() > count) { break; } } catch (Error e) { // OOM error break; } } + if (!atLeastOneAllocationWorked) { + System.out.println("Allocation failed immediately. Ignoring test!"); + return; + } + // Be sure bytes allocations don't get optimized out + System.out.println("DEBUG: Bytes allocation length 1: " + bytes[0].length); if (Metrics.systemMetrics().getMemoryFailCount() <= count) { throw new RuntimeException("Memory fail count : new : [" + Metrics.systemMetrics().getMemoryFailCount() + "]" + ", old : [" + count + "]"); }
< prev index next >