1 /* 2 * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 * @test 26 * @bug 8010927 27 * @summary Kitchensink crashed with SIGSEGV, Problematic frame: v ~StubRoutines::checkcast_arraycopy 28 * @library /../../test/lib /testlibrary 29 * @modules java.base/sun.misc 30 * @build Test8010927 31 * @run main ClassFileInstaller sun.hotspot.WhiteBox 32 * sun.hotspot.WhiteBox$WhiteBoxPermission 33 * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+IgnoreUnrecognizedVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:. -Xmx64m -XX:NewSize=20971520 -XX:MaxNewSize=32m -XX:-UseTLAB -XX:-UseAdaptiveSizePolicy Test8010927 34 */ 35 36 import sun.hotspot.WhiteBox; 37 import java.lang.reflect.Field; 38 import sun.misc.Unsafe; 39 40 /** 41 * The test creates uncommitted space between oldgen and young gen 42 * by specifying MaxNewSize bigger than NewSize. 43 * NewSize = 20971520 = (512*4K) * 10 for 4k pages 44 * Then it tries to execute arraycopy() with elements type check 45 * to the array at the end of survive space near unused space. 46 */ 47 48 public class Test8010927 { 49 50 private static final Unsafe U; 51 52 static { 53 try { 54 Field unsafe = Unsafe.class.getDeclaredField("theUnsafe"); 55 unsafe.setAccessible(true); 56 U = (Unsafe) unsafe.get(null); 57 } catch (Exception e) { 58 throw new Error(e); 59 } 60 } 61 62 public static Object[] o; 63 64 public static final boolean debug = Boolean.getBoolean("debug"); 65 66 // 2 different obect arrays but same element types 67 static Test8010927[] masterA; 68 static Object[] masterB; 69 static final Test8010927 elem = new Test8010927(); 70 static final WhiteBox wb = WhiteBox.getWhiteBox(); 71 72 static final int obj_header_size = U.ARRAY_OBJECT_BASE_OFFSET; 73 static final int heap_oop_size = wb.getHeapOopSize(); 74 static final int card_size = 512; 75 static final int one_card = (card_size - obj_header_size)/heap_oop_size; 76 77 static final int surv_size = 2112 * 1024; 78 79 // The size is big to not fit into survive space. 80 static final Object[] cache = new Object[(surv_size / card_size)]; 81 82 public static void main(String[] args) { 83 masterA = new Test8010927[one_card]; 84 masterB = new Object[one_card]; 85 for (int i = 0; i < one_card; ++i) { 86 masterA[i] = elem; 87 masterB[i] = elem; 88 } 89 90 // Move cache[] to the old gen. 91 long low_limit = wb.getObjectAddress(cache); 92 System.gc(); 93 // Move 'cache' to oldgen. 94 long upper_limit = wb.getObjectAddress(cache); 95 if ((low_limit - upper_limit) > 0) { // substaction works with unsigned values 96 // OldGen is placed before youngger for ParallelOldGC. 97 upper_limit = low_limit + 21000000l; // +20971520 98 } 99 // Each A[one_card] size is 512 bytes, 100 // it will take about 40000 allocations to trigger GC. 101 // cache[] has 8192 elements so GC should happen 102 // each 5th iteration. 103 for(long l = 0; l < 20; l++) { 104 fill_heap(); 105 if (debug) { 106 System.out.println("test oop_disjoint_arraycopy"); 107 } 108 testA_arraycopy(); 109 if (debug) { 110 System.out.println("test checkcast_arraycopy"); 111 } 112 testB_arraycopy(); 113 // Execute arraycopy to the topmost array in young gen 114 if (debug) { 115 int top_index = get_top_address(low_limit, upper_limit); 116 if (top_index >= 0) { 117 long addr = wb.getObjectAddress(cache[top_index]); 118 System.out.println("top_addr: 0x" + Long.toHexString(addr) + ", 0x" + Long.toHexString(addr + 512)); 119 } 120 } 121 } 122 } 123 static void fill_heap() { 124 for (int i = 0; i < cache.length; ++i) { 125 o = new Test8010927[one_card]; 126 System.arraycopy(masterA, 0, o, 0, masterA.length); 127 cache[i] = o; 128 } 129 for (long j = 0; j < 256; ++j) { 130 o = new Long[10000]; // to trigger GC 131 } 132 } 133 static void testA_arraycopy() { 134 for (int i = 0; i < cache.length; ++i) { 135 System.arraycopy(masterA, 0, cache[i], 0, masterA.length); 136 } 137 } 138 static void testB_arraycopy() { 139 for (int i = 0; i < cache.length; ++i) { 140 System.arraycopy(masterB, 0, cache[i], 0, masterB.length); 141 } 142 } 143 static int get_top_address(long min, long max) { 144 int index = -1; 145 long addr = min; 146 for (int i = 0; i < cache.length; ++i) { 147 long test = wb.getObjectAddress(cache[i]); 148 if (((test - addr) > 0) && ((max - test) > 0)) { // substaction works with unsigned values 149 addr = test; 150 index = i; 151 } 152 } 153 return index; 154 } 155 }