Path: blob/master/test/hotspot/jtreg/compiler/arraycopy/TestArrayCopyOverflowArguments.java
41152 views
/*1* Copyright (c) 2015 SAP SE. 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* @summary Test that overflowed integers passed to arraycopy don't do any harm. This might26* be the case on platforms where C-code expects that ints passed to a call27* are properly sign extended to 64 bit (e.g., PPC64, s390x). This can fail28* if slow_arraycopy_C() is commpiled by the C compiler without any imlicit29* casts (as spill stores to the stack that are done with 4-byte instruction).30*31* @run main/othervm -XX:-BackgroundCompilation -XX:-UseOnStackReplacement32* compiler.arraycopy.TestArrayCopyOverflowArguments33*/3435package compiler.arraycopy;3637public class TestArrayCopyOverflowArguments {3839// Without volatile the overflowing computation was moved up and then40// spilled to the stack. The 32-bit spill store caused proper rounding.41static volatile int mod = Integer.MAX_VALUE;4243public static int[] m1(Object src) {44if (src == null) return null;45int[] dest = new int[10];46try {47// PPC C calling conventions require that ints are properly expanded48// to longs when passed to a function.49int pos = 8 + mod + mod; // = 0x1_0000_0006.50int start = 2 + mod + mod; // = 0x1_0000_0000.51int len = 12 + mod + mod; // = 0x1_0000_0010.52// This is supposed to call SharedRuntime::slow_arraycopy_C().53System.arraycopy(src, pos, dest, 0, 10);54} catch (ArrayStoreException npe) {55}56return dest;57}5859static public void main(String[] args) throws Exception {60int[] src = new int[20];6162for (int i = 0; i < 20; ++i) {63src[i] = i * (i-1);64}6566for (int i = 0; i < 20000; i++) {67m1(src);68}69}70}71727374