Path: blob/master/test/hotspot/jtreg/gc/arguments/HeapRegionUsageTool.java
40943 views
/*1* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223package gc.arguments;2425import java.lang.management.ManagementFactory;26import java.lang.management.MemoryPoolMXBean;27import java.lang.management.MemoryUsage;2829/**30* Utility class used by tests to get heap region usage.31*/32public final class HeapRegionUsageTool {3334/**35* Get MemoryUsage from MemoryPoolMXBean which name matches passed string.36*37* @param name38* @return MemoryUsage39*/40private static MemoryUsage getUsage(String name){41for (MemoryPoolMXBean pool : ManagementFactory.getMemoryPoolMXBeans()) {42if (pool.getName().matches(name)) {43return pool.getUsage();44}45}46return null;47}4849/**50* Get MemoryUsage of Eden space.51*52* @return MemoryUsage53*/54public static MemoryUsage getEdenUsage() {55return getUsage(".*Eden.*");56}5758/**59* Get MemoryUsage of Survivor space.60*61* @return MemoryUsage62*/63public static MemoryUsage getSurvivorUsage() {64return getUsage(".*Survivor.*");65}6667/**68* Get memory usage of Tenured space69*70* @return MemoryUsage71*/72public static MemoryUsage getOldUsage() {73return getUsage(".*(Old|Tenured).*");74}7576/**77* Get heap usage.78*79* @return MemoryUsage80*/81public static MemoryUsage getHeapUsage() {82return ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();83}8485/**86* Helper function to align up.87*88* @param value89* @param alignment90* @return aligned value91*/92public static long alignUp(long value, long alignment) {93return (value + alignment - 1) & ~(alignment - 1);94}9596/**97* Helper function to align down.98*99* @param value100* @param alignment101* @return aligned value102*/103public static long alignDown(long value, long alignment) {104return value & ~(alignment - 1);105}106}107108109