blob: 005ba7fbc2644a657662cf1c1bd77010f782a034 [file] [log] [blame]
Calin Juravle641547a2015-04-21 22:08:51 +01001/*
Roland Levillain6a92a032015-07-23 12:15:01 +01002 * 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 */
Calin Juravle641547a2015-04-21 22:08:51 +010016
17
18public class Main {
19 public int x = 0;
20
21 public Main(Main c) {
22 // After inlining the graph will look like:
23 // NullCheck c
24 // InstanceFieldGet c
25 // InstanceFieldSet this 3
26 // The dead code will eliminate the InstanceFieldGet and we'll end up with:
27 // NullCheck c
28 // InstanceFieldSet this 3
29 // At codegen, when verifying if we can move the null check to the user,
30 // we should check that we actually have the same user (not only that the
31 // next instruction can do implicit null checks).
32 // In this case we should generate code for the NullCheck since the next
33 // instruction checks a different object.
34 c.willBeInlined();
35 x = 3;
36 }
37
38 private int willBeInlined() {
39 return x;
40 }
41
42 public static void main(String[] args) {
43 try {
44 new Main(null);
45 throw new RuntimeException("Failed to throw NullPointerException");
46 } catch (NullPointerException e) {
47 // expected
48 }
49 }
50}