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