blob: 30ccc56b806203c271768262c521166ca4f07c98 [file] [log] [blame]
Nicolas Geoffrayee3cf072015-10-06 11:45:02 +01001/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17
18public class Main {
19 public static void main(String[] args) {
20 arraycopy();
21 try {
22 arraycopy(new Object());
23 throw new Error("Should not be here");
24 } catch (ArrayStoreException ase) {
25 // Ignore.
26 }
27 try {
28 arraycopy(null);
29 throw new Error("Should not be here");
30 } catch (NullPointerException npe) {
31 // Ignore.
32 }
33
34 try {
35 arraycopy(new Object[1]);
36 throw new Error("Should not be here");
37 } catch (ArrayIndexOutOfBoundsException aiooe) {
38 // Ignore.
39 }
40
41 arraycopy(new Object[2]);
42 arraycopy(new Object[2], 0);
43
44 try {
45 arraycopy(new Object[1], 1);
46 throw new Error("Should not be here");
47 } catch (ArrayIndexOutOfBoundsException aiooe) {
48 // Ignore.
49 }
50 }
51
52 /// CHECK-START-X86_64: void Main.arraycopy() disassembly (after)
53 /// CHECK: InvokeStaticOrDirect
54 /// CHECK-NOT: test
55 /// CHECK-NOT: call
56 /// CHECK: ReturnVoid
57 // Checks that the call is intrinsified and that there is no test instruction
58 // when we know the source and destination are not null.
59 public static void arraycopy() {
60 Object[] obj = new Object[4];
61 System.arraycopy(obj, 1, obj, 0, 1);
62 }
63
64 public static void arraycopy(Object obj) {
65 System.arraycopy(obj, 1, obj, 0, 1);
66 }
67
68 public static void arraycopy(Object[] obj, int pos) {
69 System.arraycopy(obj, pos, obj, 0, obj.length);
70 }
71}