1 /* 2 * Copyright (C) 2014 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 main(String[] args)19 public static void main(String[] args) { 20 crash(); 21 npe(); 22 } 23 crash()24 static void crash() { 25 boolean b = baz(); 26 // Create many objects to starve registers. 27 Main foo1 = create(); 28 Main foo2 = create(); 29 Main foo3 = create(); 30 Main foo4 = create(); 31 foo1.otherField = null; 32 // On X86, we would force b to be in a byte register, which 33 // would generate moves. This code exposed a bug in the 34 // register allocator, where an input move was not just before 35 // the instruction itself, and its destination was overridden 36 // by another value. 37 foo1.field = b; 38 foo2.field = b; 39 foo3.field = b; 40 foo4.field = b; 41 foo1.lastField = b; 42 } 43 44 // Similar to `crash` but generated an NPE. npe()45 static void npe() { 46 boolean b = baz(); 47 Main foo1 = create(); 48 Main foo2 = create(); 49 Main foo3 = create(); 50 Main foo4 = create(); 51 foo1.field = b; 52 foo2.field = b; 53 foo3.field = b; 54 foo4.field = b; 55 foo1.lastField = b; 56 } 57 create()58 static Main create() { 59 return new Main(); 60 } 61 baz()62 static boolean baz() { 63 return false; 64 } 65 66 boolean field; 67 Object otherField; 68 boolean lastField; 69 } 70