1 /*
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 public class Main {
bar(int[] a)18   public static int[] bar(int[] a) {
19     a[0] = 0;
20     a[1] = 0;
21     a[2] = 0;
22     // Up to this point, we record that the lower bound (inclusive) is 3.
23     // The next instruction will record that the lower bound is 5.
24     // The deoptimization code used to assume the lower bound has
25     // to be the one it will add for the deoptimization check (here, it
26     // would be 3).
27     return new int[a.length - 5];
28   }
29 
foo(int[] a)30   public static int[] foo(int[] a) {
31     a[0] = 0;
32     a[1] = 0;
33     a[2] = 0;
34     // Up to this point, we record that the lower bound (inclusive) is 3.
35     // The next instruction will record that the lower bound is 1.
36     // The deoptimization code used to assume the lower bound has
37     // to be the one it will add for the deoptimization check (here, it
38     // would be 3).
39     return new int[a.length - 1];
40   }
41 
main(String[] args)42   public static void main(String[] args) {
43     int[] a = new int[5];
44     int[] result = bar(a);
45     if (result.length != 0) {
46       throw new Error("Expected 0, got " + result.length);
47     }
48 
49     result = foo(a);
50     if (result.length != 4) {
51       throw new Error("Expected 5, got " + result.length);
52     }
53   }
54 }
55