Path: blob/master/test/hotspot/jtreg/compiler/codecache/OverflowCodeCacheTest.java
41152 views
/*1* Copyright (c) 2014, 2021, 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* @test OverflowCodeCacheTest25* @bug 805955026* @summary testing of code cache segments overflow27* @library /test/lib28* @modules java.base/jdk.internal.misc29* java.management30*31* @build sun.hotspot.WhiteBox32* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox33* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions34* -XX:+WhiteBoxAPI -XX:CompileCommand=compileonly,null::*35* -XX:-SegmentedCodeCache36* compiler.codecache.OverflowCodeCacheTest37* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions38* -XX:+WhiteBoxAPI -XX:CompileCommand=compileonly,null::*39* -XX:+SegmentedCodeCache40* compiler.codecache.OverflowCodeCacheTest41*/4243package compiler.codecache;4445import jdk.test.lib.Asserts;46import sun.hotspot.WhiteBox;47import sun.hotspot.code.BlobType;48import sun.hotspot.code.CodeBlob;4950import java.lang.management.MemoryPoolMXBean;51import java.util.ArrayList;52import java.util.EnumSet;5354public class OverflowCodeCacheTest {55private static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();5657public static void main(String[] args) {58EnumSet<BlobType> blobTypes = BlobType.getAvailable();59for (BlobType type : blobTypes) {60new OverflowCodeCacheTest(type).test();61}62}6364private final BlobType type;65private final MemoryPoolMXBean bean;66private OverflowCodeCacheTest(BlobType type) {67this.type = type;68this.bean = type.getMemoryPool();69}7071private void test() {72System.out.printf("type %s%n", type);73System.out.println("allocating till possible...");74ArrayList<Long> blobs = new ArrayList<>();75int compilationActivityMode = -1;76try {77long addr;78int size = (int) (getHeapSize() >> 7);79while ((addr = WHITE_BOX.allocateCodeBlob(size, type.id)) != 0) {80blobs.add(addr);8182BlobType actualType = CodeBlob.getCodeBlob(addr).code_blob_type;83if (actualType != type) {84// check we got allowed overflow handling85Asserts.assertTrue(type.allowTypeWhenOverflow(actualType),86type + " doesn't allow using " + actualType + " when overflow");87}88}89/* now, remember compilationActivityMode to check it later, after freeing, since we90possibly have no free cache for futher work */91compilationActivityMode = WHITE_BOX.getCompilationActivityMode();92} finally {93for (Long blob : blobs) {94WHITE_BOX.freeCodeBlob(blob);95}96}97Asserts.assertNotEquals(compilationActivityMode, 1 /* run_compilation*/,98"Compilation must be disabled when CodeCache(CodeHeap) overflows");99}100101private long getHeapSize() {102return bean.getUsage().getMax();103}104105}106107108