blob: 5ee4d550f88839f187ada79a2a670fdccb59054b [file] [log] [blame]
Nicolas Geoffray8d82a0c2015-06-20 23:49:01 +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
17public class Main {
18 public static int[] bar(int[] a) {
19 a[0] = 0;
20 a[1] = 0;
21 a[2] = 0;
Nicolas Geoffraya09ff9c2015-06-24 10:38:27 +010022 // Up to this point, we record that the lower bound (inclusive) is 3.
Nicolas Geoffray8d82a0c2015-06-20 23:49:01 +010023 // The next instruction will record that the lower bound is 5.
24 // The deoptimization code used to assume the lower bound has
Nicolas Geoffraya09ff9c2015-06-24 10:38:27 +010025 // to be the one it will add for the deoptimization check (here, it
26 // would be 3).
Nicolas Geoffray8d82a0c2015-06-20 23:49:01 +010027 return new int[a.length - 5];
28 }
29
Nicolas Geoffraya09ff9c2015-06-24 10:38:27 +010030 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
Nicolas Geoffray8d82a0c2015-06-20 23:49:01 +010042 public static void main(String[] args) {
43 int[] a = new int[5];
Nicolas Geoffraya09ff9c2015-06-24 10:38:27 +010044 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);
Nicolas Geoffray8d82a0c2015-06-20 23:49:01 +010052 }
53 }
54}