Path: blob/master/test/hotspot/jtreg/gc/epsilon/TestArraycopyCheckcast.java
40942 views
/*1* Copyright (c) 2019, Red Hat, Inc. 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*/2223package gc.epsilon;2425/**26* @test TestArraycopyCheckcast27* @requires vm.gc.Epsilon28* @summary Epsilon is able to handle checkcasted array copies29* @library /test/lib30* @bug 821572431*32* @run main/othervm -Xmx1g -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC gc.epsilon.TestArraycopyCheckcast33* @run main/othervm -Xmx1g -Xint -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC gc.epsilon.TestArraycopyCheckcast34* @run main/othervm -Xmx1g -Xbatch -Xcomp -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC gc.epsilon.TestArraycopyCheckcast35* @run main/othervm -Xmx1g -Xbatch -Xcomp -XX:TieredStopAtLevel=1 -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC gc.epsilon.TestArraycopyCheckcast36* @run main/othervm -Xmx1g -Xbatch -Xcomp -XX:-TieredCompilation -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC gc.epsilon.TestArraycopyCheckcast37*/3839public class TestArraycopyCheckcast {4041static int COUNT = Integer.getInteger("count", 1000);4243public static void main(String[] args) throws Exception {44Object[] src = new Object[COUNT];45Object[] dst = new B[COUNT];4647// Test 1. Copy nulls, should succeed48try {49System.arraycopy(src, 0, dst, 0, COUNT);50} catch (ArrayStoreException e) {51throw new IllegalStateException("Should have completed");52}5354// Test 2. Copying incompatible type, should fail55for (int c = 0; c < COUNT; c++) {56src[c] = new A();57}5859try {60System.arraycopy(src, 0, dst, 0, COUNT);61throw new IllegalStateException("Should have failed with ArrayStoreException");62} catch (ArrayStoreException e) {63// Expected64}6566// Test 3. Copying compatible type, should succeeded67for (int c = 0; c < COUNT; c++) {68src[c] = new C();69}7071try {72System.arraycopy(src, 0, dst, 0, COUNT);73} catch (ArrayStoreException e) {74throw new IllegalStateException("Should have completed");75}7677for (int c = 0; c < COUNT; c++) {78if (src[c] != dst[c]) {79throw new IllegalStateException("Copy failed at index " + c);80}81}82}8384static class A {}85static class B extends A {}86static class C extends B {}87}888990