Path: blob/master/test/hotspot/jtreg/compiler/runtime/Test8010927.java
41149 views
/*1* Copyright (c) 2013, 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* @test25* @bug 801092726* @summary Kitchensink crashed with SIGSEGV, Problematic frame: v ~StubRoutines::checkcast_arraycopy27* @library /test/lib28* @modules java.base/jdk.internal.misc:+open29* @build sun.hotspot.WhiteBox30* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox31* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+IgnoreUnrecognizedVMOptions32* -XX:+WhiteBoxAPI -Xbootclasspath/a:. -Xmx128m -XX:NewSize=2097152033* -XX:MaxNewSize=32m -XX:-UseTLAB -XX:-UseAdaptiveSizePolicy34* compiler.runtime.Test801092735*/3637package compiler.runtime;3839import jdk.internal.misc.Unsafe;40import sun.hotspot.WhiteBox;4142import java.lang.reflect.Field;4344/**45* The test creates uncommitted space between oldgen and young gen46* by specifying MaxNewSize bigger than NewSize.47* NewSize = 20971520 = (512*4K) * 10 for 4k pages48* Then it tries to execute arraycopy() with elements type check49* to the array at the end of survive space near unused space.50*/5152public class Test8010927 {5354private static final Unsafe U;5556static {57try {58Field unsafe = Unsafe.class.getDeclaredField("theUnsafe");59unsafe.setAccessible(true);60U = (Unsafe) unsafe.get(null);61} catch (Exception e) {62throw new Error(e);63}64}6566public static Object[] o;6768public static final boolean debug = Boolean.getBoolean("debug");6970// 2 different obect arrays but same element types71static Test8010927[] masterA;72static Object[] masterB;73static final Test8010927 elem = new Test8010927();74static final WhiteBox wb = WhiteBox.getWhiteBox();7576static final int obj_header_size = U.ARRAY_OBJECT_BASE_OFFSET;77static final int heap_oop_size = wb.getHeapOopSize();78static final int card_size = 512;79static final int one_card = (card_size - obj_header_size) / heap_oop_size;8081static final int surv_size = 2112 * 1024;8283// The size is big to not fit into survive space.84static final Object[] cache = new Object[(surv_size / card_size)];8586public static void main(String[] args) {87masterA = new Test8010927[one_card];88masterB = new Object[one_card];89for (int i = 0; i < one_card; ++i) {90masterA[i] = elem;91masterB[i] = elem;92}9394// Move cache[] to the old gen.95long low_limit = wb.getObjectAddress(cache);96System.gc();97// Move 'cache' to oldgen.98long upper_limit = wb.getObjectAddress(cache);99if ((low_limit - upper_limit) > 0) { // substaction works with unsigned values100// OldGen is placed before youngger for ParallelOldGC.101upper_limit = low_limit + 21000000l; // +20971520102}103// Each A[one_card] size is 512 bytes,104// it will take about 40000 allocations to trigger GC.105// cache[] has 8192 elements so GC should happen106// each 5th iteration.107for (long l = 0; l < 20; l++) {108fill_heap();109if (debug) {110System.out.println("test oop_disjoint_arraycopy");111}112testA_arraycopy();113if (debug) {114System.out.println("test checkcast_arraycopy");115}116testB_arraycopy();117// Execute arraycopy to the topmost array in young gen118if (debug) {119int top_index = get_top_address(low_limit, upper_limit);120if (top_index >= 0) {121long addr = wb.getObjectAddress(cache[top_index]);122System.out.println("top_addr: 0x" + Long.toHexString(addr) + ", 0x" + Long.toHexString(addr + 512));123}124}125}126}127128static void fill_heap() {129for (int i = 0; i < cache.length; ++i) {130o = new Test8010927[one_card];131System.arraycopy(masterA, 0, o, 0, masterA.length);132cache[i] = o;133}134for (long j = 0; j < 256; ++j) {135o = new Long[10000]; // to trigger GC136}137}138139static void testA_arraycopy() {140for (int i = 0; i < cache.length; ++i) {141System.arraycopy(masterA, 0, cache[i], 0, masterA.length);142}143}144145static void testB_arraycopy() {146for (int i = 0; i < cache.length; ++i) {147System.arraycopy(masterB, 0, cache[i], 0, masterB.length);148}149}150151static int get_top_address(long min, long max) {152int index = -1;153long addr = min;154for (int i = 0; i < cache.length; ++i) {155long test = wb.getObjectAddress(cache[i]);156if (((test - addr) > 0) && ((max - test) > 0)) { // substaction works with unsigned values157addr = test;158index = i;159}160}161return index;162}163}164165166