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 18 public class Main { 19 public int x = 0; 20 Main(Main c)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 willBeInlined()38 private int willBeInlined() { 39 return x; 40 } 41 main(String[] args)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 } 51