Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/test/runtime/NMT/MallocSiteHashOverflow.java
32284 views
/*1* Copyright (c) 2014, 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*/2223/*24* @test25* @summary Test corner case that overflows malloc site hashtable bucket26* @requires sun.arch.data.model == "32"27* @key nmt jcmd stress28* @library /testlibrary /testlibrary/whitebox29* @build MallocSiteHashOverflow30* @run main ClassFileInstaller sun.hotspot.WhiteBox31* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:NativeMemoryTracking=detail MallocSiteHashOverflow32*/3334import com.oracle.java.testlibrary.*;35import sun.hotspot.WhiteBox;3637public class MallocSiteHashOverflow {3839public static void main(String args[]) throws Exception {4041// Size of entries based on malloc tracking header defined in mallocTracker.hpp42// For 32-bit systems, create 257 malloc sites with the same hash bucket to overflow a hash bucket43long entries = 257;4445OutputAnalyzer output;46WhiteBox wb = WhiteBox.getWhiteBox();47int MAX_HASH_SIZE = wb.NMTGetHashSize();4849// Grab my own PID50String pid = Integer.toString(ProcessTools.getProcessId());51ProcessBuilder pb = new ProcessBuilder();5253// Verify that current tracking level is "detail"54pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "statistics"});55output = new OutputAnalyzer(pb.start());56output.shouldContain("Native Memory Tracking Statistics");5758// Attempt to cause NMT to downgrade tracking level by allocating small amounts59// of memory with random pseudo call stack60int pc = 1;61for (int i = 0; i < entries; i++) {62long addr = wb.NMTMallocWithPseudoStack(1, pc);63if (addr == 0) {64throw new RuntimeException("NMTMallocWithPseudoStack: out of memory");65}66// We free memory here since it doesn't affect pseudo malloc alloc site hash table entries67wb.NMTFree(addr);68pc += MAX_HASH_SIZE;69if (i == entries) {70// Verify that tracking has been downgraded71pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "statistics"});72output = new OutputAnalyzer(pb.start());73output.shouldContain("Tracking level has been downgraded due to lack of resources");74}75}76}77}787980