1*795d594fSAndroid Build Coastguard Worker /* 2*795d594fSAndroid Build Coastguard Worker * Copyright (C) 2017 The Android Open Source Project 3*795d594fSAndroid Build Coastguard Worker * 4*795d594fSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 5*795d594fSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 6*795d594fSAndroid Build Coastguard Worker * You may obtain a copy of the License at 7*795d594fSAndroid Build Coastguard Worker * 8*795d594fSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 9*795d594fSAndroid Build Coastguard Worker * 10*795d594fSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 11*795d594fSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 12*795d594fSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*795d594fSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 14*795d594fSAndroid Build Coastguard Worker * limitations under the License. 15*795d594fSAndroid Build Coastguard Worker */ 16*795d594fSAndroid Build Coastguard Worker 17*795d594fSAndroid Build Coastguard Worker public class Main { 18*795d594fSAndroid Build Coastguard Worker 19*795d594fSAndroid Build Coastguard Worker // Note that this is testing we haven't intrinsified the byte[] arraycopy version. 20*795d594fSAndroid Build Coastguard Worker // Once we eventually start doing it, we will need to re-adjust this test. 21*795d594fSAndroid Build Coastguard Worker 22*795d594fSAndroid Build Coastguard Worker /// CHECK-START-X86: void Main.typedCopy(java.lang.Object, byte[]) disassembly (after) 23*795d594fSAndroid Build Coastguard Worker /// CHECK: InvokeStaticOrDirect method_name:java.lang.System.arraycopy intrinsic:SystemArrayCopy 24*795d594fSAndroid Build Coastguard Worker /// CHECK-NOT: call 25*795d594fSAndroid Build Coastguard Worker /// CHECK: InvokeStaticOrDirect method_name:java.lang.System.arraycopy intrinsic:SystemArrayCopyByte 26*795d594fSAndroid Build Coastguard Worker /// CHECK-NOT: call 27*795d594fSAndroid Build Coastguard Worker /// CHECK: ReturnVoid typedCopy(Object o, byte[] foo)28*795d594fSAndroid Build Coastguard Worker public static void typedCopy(Object o, byte[] foo) { 29*795d594fSAndroid Build Coastguard Worker System.arraycopy(o, 1, o, 0, 1); 30*795d594fSAndroid Build Coastguard Worker System.arraycopy((Object)foo, 1, (Object)foo, 0, 1); // Don't use the @hide byte[] overload. 31*795d594fSAndroid Build Coastguard Worker } 32*795d594fSAndroid Build Coastguard Worker untypedCopy(Object o, Object foo)33*795d594fSAndroid Build Coastguard Worker public static void untypedCopy(Object o, Object foo) { 34*795d594fSAndroid Build Coastguard Worker System.arraycopy(o, 1, o, 0, 1); 35*795d594fSAndroid Build Coastguard Worker System.arraycopy(foo, 1, foo, 0, 1); 36*795d594fSAndroid Build Coastguard Worker } 37*795d594fSAndroid Build Coastguard Worker 38*795d594fSAndroid Build Coastguard Worker // Test that we still do the optimization after inlining. 39*795d594fSAndroid Build Coastguard Worker 40*795d594fSAndroid Build Coastguard Worker /// CHECK-START-X86: void Main.untypedCopyCaller(java.lang.Object, byte[]) disassembly (after) 41*795d594fSAndroid Build Coastguard Worker /// CHECK: InvokeStaticOrDirect method_name:java.lang.System.arraycopy intrinsic:SystemArrayCopy 42*795d594fSAndroid Build Coastguard Worker /// CHECK-NOT: call 43*795d594fSAndroid Build Coastguard Worker /// CHECK: InvokeStaticOrDirect method_name:java.lang.System.arraycopy intrinsic:SystemArrayCopyByte 44*795d594fSAndroid Build Coastguard Worker /// CHECK-NOT: call 45*795d594fSAndroid Build Coastguard Worker /// CHECK: ReturnVoid untypedCopyCaller(Object o, byte[] array)46*795d594fSAndroid Build Coastguard Worker public static void untypedCopyCaller(Object o, byte[] array) { 47*795d594fSAndroid Build Coastguard Worker untypedCopy(o, array); 48*795d594fSAndroid Build Coastguard Worker } 49*795d594fSAndroid Build Coastguard Worker assertEquals(Object one, Object two)50*795d594fSAndroid Build Coastguard Worker public static void assertEquals(Object one, Object two) { 51*795d594fSAndroid Build Coastguard Worker if (one != two) { 52*795d594fSAndroid Build Coastguard Worker throw new Error("Expected " + one + ", got " + two); 53*795d594fSAndroid Build Coastguard Worker } 54*795d594fSAndroid Build Coastguard Worker } 55*795d594fSAndroid Build Coastguard Worker main(String[] args)56*795d594fSAndroid Build Coastguard Worker public static void main(String[] args) { 57*795d594fSAndroid Build Coastguard Worker // Simple checks. 58*795d594fSAndroid Build Coastguard Worker byte[] a = new byte[2]; 59*795d594fSAndroid Build Coastguard Worker Object[] o = new Object[2]; 60*795d594fSAndroid Build Coastguard Worker 61*795d594fSAndroid Build Coastguard Worker o[0] = a; 62*795d594fSAndroid Build Coastguard Worker o[1] = o; 63*795d594fSAndroid Build Coastguard Worker a[0] = 1; 64*795d594fSAndroid Build Coastguard Worker a[1] = 2; 65*795d594fSAndroid Build Coastguard Worker 66*795d594fSAndroid Build Coastguard Worker untypedCopyCaller(o, a); 67*795d594fSAndroid Build Coastguard Worker assertEquals(o[0], o); 68*795d594fSAndroid Build Coastguard Worker assertEquals(o[1], o); 69*795d594fSAndroid Build Coastguard Worker assertEquals(a[0], (byte)2); 70*795d594fSAndroid Build Coastguard Worker assertEquals(a[1], (byte)2); 71*795d594fSAndroid Build Coastguard Worker 72*795d594fSAndroid Build Coastguard Worker o[0] = a; 73*795d594fSAndroid Build Coastguard Worker o[1] = o; 74*795d594fSAndroid Build Coastguard Worker a[0] = 1; 75*795d594fSAndroid Build Coastguard Worker a[1] = 2; 76*795d594fSAndroid Build Coastguard Worker 77*795d594fSAndroid Build Coastguard Worker typedCopy(o, a); 78*795d594fSAndroid Build Coastguard Worker assertEquals(o[0], o); 79*795d594fSAndroid Build Coastguard Worker assertEquals(o[1], o); 80*795d594fSAndroid Build Coastguard Worker assertEquals(a[0], (byte)2); 81*795d594fSAndroid Build Coastguard Worker assertEquals(a[1], (byte)2); 82*795d594fSAndroid Build Coastguard Worker } 83*795d594fSAndroid Build Coastguard Worker } 84