Nicolas Geoffray | 8d82a0c | 2015-06-20 23:49:01 +0100 | [diff] [blame] | 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 { |
| 18 | public static int[] bar(int[] a) { |
| 19 | a[0] = 0; |
| 20 | a[1] = 0; |
| 21 | a[2] = 0; |
Nicolas Geoffray | a09ff9c | 2015-06-24 10:38:27 +0100 | [diff] [blame] | 22 | // Up to this point, we record that the lower bound (inclusive) is 3. |
Nicolas Geoffray | 8d82a0c | 2015-06-20 23:49:01 +0100 | [diff] [blame] | 23 | // The next instruction will record that the lower bound is 5. |
| 24 | // The deoptimization code used to assume the lower bound has |
Nicolas Geoffray | a09ff9c | 2015-06-24 10:38:27 +0100 | [diff] [blame] | 25 | // to be the one it will add for the deoptimization check (here, it |
| 26 | // would be 3). |
Nicolas Geoffray | 8d82a0c | 2015-06-20 23:49:01 +0100 | [diff] [blame] | 27 | return new int[a.length - 5]; |
| 28 | } |
| 29 | |
Nicolas Geoffray | a09ff9c | 2015-06-24 10:38:27 +0100 | [diff] [blame] | 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 | |
Nicolas Geoffray | 8d82a0c | 2015-06-20 23:49:01 +0100 | [diff] [blame] | 42 | public static void main(String[] args) { |
| 43 | int[] a = new int[5]; |
Nicolas Geoffray | a09ff9c | 2015-06-24 10:38:27 +0100 | [diff] [blame] | 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); |
Nicolas Geoffray | 8d82a0c | 2015-06-20 23:49:01 +0100 | [diff] [blame] | 52 | } |
| 53 | } |
| 54 | } |