4534N/A/*
4534N/A * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
4534N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4534N/A *
4534N/A * This code is free software; you can redistribute it and/or modify it
4534N/A * under the terms of the GNU General Public License version 2 only, as
4534N/A * published by the Free Software Foundation.
4534N/A *
4534N/A * This code is distributed in the hope that it will be useful, but WITHOUT
4534N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4534N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
4534N/A * version 2 for more details (a copy is included in the LICENSE file that
4534N/A * accompanied this code).
4534N/A *
4534N/A * You should have received a copy of the GNU General Public License version
4534N/A * 2 along with this work; if not, write to the Free Software Foundation,
4534N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4534N/A *
4534N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4534N/A * or visit www.oracle.com if you need additional information or have any
4534N/A * questions.
4534N/A */
4534N/A
4534N/A/*
4534N/A * @test
4534N/A * @bug 8010927
4534N/A * @summary Kitchensink crashed with SIGSEGV, Problematic frame: v ~StubRoutines::checkcast_arraycopy
4534N/A * @library /testlibrary/whitebox /testlibrary
4534N/A * @build Test8010927
4534N/A * @run main ClassFileInstaller sun.hotspot.WhiteBox
4534N/A * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+IgnoreUnrecognizedVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:. -Xmx64m -XX:NewSize=20971520 -XX:MaxNewSize=32m -XX:-UseTLAB -XX:-UseParNewGC -XX:-UseAdaptiveSizePolicy Test8010927
4534N/A */
4534N/A
4534N/Aimport sun.hotspot.WhiteBox;
4534N/Aimport java.lang.reflect.Field;
4534N/Aimport sun.misc.Unsafe;
4534N/A
4534N/A/**
4534N/A * The test creates uncommitted space between oldgen and young gen
4534N/A * by specifying MaxNewSize bigger than NewSize.
4534N/A * NewSize = 20971520 = (512*4K) * 10 for 4k pages
4534N/A * Then it tries to execute arraycopy() with elements type check
4534N/A * to the array at the end of survive space near unused space.
4534N/A */
4534N/A
4534N/Apublic class Test8010927 {
4534N/A
4534N/A private static final Unsafe U;
4534N/A
4534N/A static {
4534N/A try {
4534N/A Field unsafe = Unsafe.class.getDeclaredField("theUnsafe");
4534N/A unsafe.setAccessible(true);
4534N/A U = (Unsafe) unsafe.get(null);
4534N/A } catch (Exception e) {
4534N/A throw new Error(e);
4534N/A }
4534N/A }
4534N/A
4534N/A public static Object[] o;
4534N/A
4534N/A public static final boolean debug = Boolean.getBoolean("debug");
4534N/A
4534N/A // 2 different obect arrays but same element types
4534N/A static Test8010927[] masterA;
4534N/A static Object[] masterB;
4534N/A static final Test8010927 elem = new Test8010927();
4534N/A static final WhiteBox wb = WhiteBox.getWhiteBox();
4534N/A
4534N/A static final int obj_header_size = U.ARRAY_OBJECT_BASE_OFFSET;
4534N/A static final int heap_oop_size = wb.getHeapOopSize();
4534N/A static final int card_size = 512;
4534N/A static final int one_card = (card_size - obj_header_size)/heap_oop_size;
4534N/A
4534N/A static final int surv_size = 2112 * 1024;
4534N/A
4534N/A // The size is big to not fit into survive space.
4534N/A static final Object[] cache = new Object[(surv_size / card_size)];
4534N/A
4534N/A public static void main(String[] args) {
4534N/A masterA = new Test8010927[one_card];
4534N/A masterB = new Object[one_card];
4534N/A for (int i = 0; i < one_card; ++i) {
4534N/A masterA[i] = elem;
4534N/A masterB[i] = elem;
4534N/A }
4534N/A
4534N/A // Move cache[] to the old gen.
4534N/A long low_limit = wb.getObjectAddress(cache);
4534N/A System.gc();
4534N/A // Move 'cache' to oldgen.
4534N/A long upper_limit = wb.getObjectAddress(cache);
4534N/A if ((low_limit - upper_limit) > 0) { // substaction works with unsigned values
4534N/A // OldGen is placed before youngger for ParallelOldGC.
4534N/A upper_limit = low_limit + 21000000l; // +20971520
4534N/A }
4534N/A // Each A[one_card] size is 512 bytes,
4534N/A // it will take about 40000 allocations to trigger GC.
4534N/A // cache[] has 8192 elements so GC should happen
4534N/A // each 5th iteration.
4534N/A for(long l = 0; l < 20; l++) {
4534N/A fill_heap();
4534N/A if (debug) {
4534N/A System.out.println("test oop_disjoint_arraycopy");
4534N/A }
4534N/A testA_arraycopy();
4534N/A if (debug) {
4534N/A System.out.println("test checkcast_arraycopy");
4534N/A }
4534N/A testB_arraycopy();
4534N/A // Execute arraycopy to the topmost array in young gen
4534N/A if (debug) {
4534N/A int top_index = get_top_address(low_limit, upper_limit);
4534N/A if (top_index >= 0) {
4534N/A long addr = wb.getObjectAddress(cache[top_index]);
4534N/A System.out.println("top_addr: 0x" + Long.toHexString(addr) + ", 0x" + Long.toHexString(addr + 512));
4534N/A }
4534N/A }
4534N/A }
4534N/A }
4534N/A static void fill_heap() {
4534N/A for (int i = 0; i < cache.length; ++i) {
4534N/A o = new Test8010927[one_card];
4534N/A System.arraycopy(masterA, 0, o, 0, masterA.length);
4534N/A cache[i] = o;
4534N/A }
4534N/A for (long j = 0; j < 256; ++j) {
4534N/A o = new Long[10000]; // to trigger GC
4534N/A }
4534N/A }
4534N/A static void testA_arraycopy() {
4534N/A for (int i = 0; i < cache.length; ++i) {
4534N/A System.arraycopy(masterA, 0, cache[i], 0, masterA.length);
4534N/A }
4534N/A }
4534N/A static void testB_arraycopy() {
4534N/A for (int i = 0; i < cache.length; ++i) {
4534N/A System.arraycopy(masterB, 0, cache[i], 0, masterB.length);
4534N/A }
4534N/A }
4534N/A static int get_top_address(long min, long max) {
4534N/A int index = -1;
4534N/A long addr = min;
4534N/A for (int i = 0; i < cache.length; ++i) {
4534N/A long test = wb.getObjectAddress(cache[i]);
4534N/A if (((test - addr) > 0) && ((max - test) > 0)) { // substaction works with unsigned values
4534N/A addr = test;
4534N/A index = i;
4534N/A }
4534N/A }
4534N/A return index;
4534N/A }
4534N/A}