--- old/test/jdk/java/lang/management/MemoryMXBean/MemoryManagement.java 2018-10-08 18:33:43.000000000 -0400 +++ new/test/jdk/java/lang/management/MemoryMXBean/MemoryManagement.java 2018-10-08 18:33:43.000000000 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 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 @@ -82,21 +82,35 @@ MemoryUtil.printMemoryManagers(managers); } - // Find the Old generation which supports low memory detection + // Find a pool which which supports low memory detection ListIterator iter = pools.listIterator(); while (iter.hasNext()) { MemoryPoolMXBean p = (MemoryPoolMXBean) iter.next(); if (p.getType() == MemoryType.HEAP && p.isUsageThresholdSupported()) { - mpool = p; - if (trace) { - System.out.println("Selected memory pool for low memory " + - "detection."); - MemoryUtil.printMemoryPool(mpool); + if (!p.getName().equals("G1 Old Space")) { + // In G1, humongous objects are tracked in the old space only in + // legacy monitoring mode. In default mode, G1 tracks humongous + // objects in the humongous space, which latter also supports a + // usage threshold. Since we're allocating humongous objects in + // this test, in default mode the old space doesn't change. For + // this test, we use the old space in legacy mode (it's called + // "G1 Old Gen" and the humongous space in default mode. If we + // used "G1 Old Space" in default mode, notification would never + // happen. + mpool = p; + if (trace) { + System.out.println("Selected memory pool for low memory " + + "detection."); + MemoryUtil.printMemoryPool(mpool); + } + break; } - break; } } + if (mpool == null) { + throw new RuntimeException("TEST FAILED: No heap pool found"); + } SensorListener listener = new SensorListener(); NotificationEmitter emitter = (NotificationEmitter) mm;