1 /* 2 * Copyright (C) 2016 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 19 /// CHECK-START-X86: int Main.p(float) liveness (after) 20 /// CHECK: <<Arg:f\d+>> ParameterValue uses:[<<UseInput:\d+>>] 21 /// CHECK-DAG: <<Five:f\d+>> FloatConstant 5 uses:[<<UseInput>>] 22 /// CHECK-DAG: <<Zero:i\d+>> IntConstant 0 23 /// CHECK-DAG: <<MinusOne:i\d+>> IntConstant -1 uses:[<<UseInput>>] 24 /// CHECK: <<Base:i\d+>> X86ComputeBaseMethodAddress uses:[<<UseInput>>] 25 /// CHECK-NEXT: <<Load:f\d+>> X86LoadFromConstantTable [<<Base>>,<<Five>>] 26 /// CHECK-NEXT: <<Cond:z\d+>> LessThanOrEqual [<<Arg>>,<<Load>>] 27 /// CHECK-NEXT: Select [<<Zero>>,<<MinusOne>>,<<Cond>>] liveness:<<LivSel:\d+>> 28 /// CHECK-EVAL: <<UseInput>> == <<LivSel>> + 1 29 p(float arg)30 public static int p(float arg) { 31 return (arg > 5.0f) ? 0 : -1; 32 } 33 34 /// CHECK-START-{ARM,ARM64}: void Main.testThrowIntoCatchBlock(int, java.lang.Object, int[]) liveness (after) 35 /// CHECK-DAG: <<IntArg:i\d+>> ParameterValue env_uses:[23,25] 36 /// CHECK-DAG: <<RefArg:l\d+>> ParameterValue env_uses:[11,23,25] 37 /// CHECK-DAG: <<Array:l\d+>> ParameterValue env_uses:[11,23,25] 38 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1 env_uses:[23,25] 39 /// CHECK-DAG: SuspendCheck env:[[_,<<IntArg>>,<<RefArg>>,<<Array>>]] liveness:10 40 /// CHECK-DAG: NullCheck env:[[<<Const1>>,<<IntArg>>,<<RefArg>>,<<Array>>]] liveness:20 41 /// CHECK-DAG: ArrayLength liveness:22 42 /// CHECK-DAG: BoundsCheck env:[[<<Const1>>,<<IntArg>>,<<RefArg>>,<<Array>>]] liveness:24 43 /// CHECK-DAG: TryBoundary 44 45 /// CHECK-START-{ARM,ARM64}-DEBUGGABLE: void Main.testThrowIntoCatchBlock(int, java.lang.Object, int[]) liveness (after) 46 /// CHECK-DAG: <<IntArg:i\d+>> ParameterValue env_uses:[11,23,25] 47 /// CHECK-DAG: <<RefArg:l\d+>> ParameterValue env_uses:[11,23,25] 48 /// CHECK-DAG: <<Array:l\d+>> ParameterValue env_uses:[11,23,25] 49 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1 env_uses:[23,25] 50 /// CHECK-DAG: SuspendCheck env:[[_,<<IntArg>>,<<RefArg>>,<<Array>>]] liveness:10 51 /// CHECK-DAG: NullCheck env:[[<<Const1>>,<<IntArg>>,<<RefArg>>,<<Array>>]] liveness:20 52 /// CHECK-DAG: ArrayLength liveness:22 53 /// CHECK-DAG: BoundsCheck env:[[<<Const1>>,<<IntArg>>,<<RefArg>>,<<Array>>]] liveness:24 54 /// CHECK-DAG: TryBoundary 55 56 // X86 and X86_64 generate at use site the ArrayLength, meaning only the BoundsCheck will have environment uses. 57 /// CHECK-START-{X86,X86_64}: void Main.testThrowIntoCatchBlock(int, java.lang.Object, int[]) liveness (after) 58 /// CHECK-DAG: <<IntArg:i\d+>> ParameterValue env_uses:[25,25] 59 /// CHECK-DAG: <<RefArg:l\d+>> ParameterValue env_uses:[11,25,25] 60 /// CHECK-DAG: <<Array:l\d+>> ParameterValue env_uses:[11,25,25] 61 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1 env_uses:[25,25] 62 /// CHECK-DAG: SuspendCheck env:[[_,<<IntArg>>,<<RefArg>>,<<Array>>]] liveness:10 63 /// CHECK-DAG: NullCheck env:[[<<Const1>>,<<IntArg>>,<<RefArg>>,<<Array>>]] liveness:20 64 /// CHECK-DAG: ArrayLength liveness:22 65 /// CHECK-DAG: BoundsCheck env:[[<<Const1>>,<<IntArg>>,<<RefArg>>,<<Array>>]] liveness:24 66 /// CHECK-DAG: TryBoundary 67 68 /// CHECK-START-{X86,X86_64}-DEBUGGABLE: void Main.testThrowIntoCatchBlock(int, java.lang.Object, int[]) liveness (after) 69 /// CHECK-DAG: <<IntArg:i\d+>> ParameterValue env_uses:[11,25,25] 70 /// CHECK-DAG: <<RefArg:l\d+>> ParameterValue env_uses:[11,25,25] 71 /// CHECK-DAG: <<Array:l\d+>> ParameterValue env_uses:[11,25,25] 72 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1 env_uses:[25,25] 73 /// CHECK-DAG: SuspendCheck env:[[_,<<IntArg>>,<<RefArg>>,<<Array>>]] liveness:10 74 /// CHECK-DAG: NullCheck env:[[<<Const1>>,<<IntArg>>,<<RefArg>>,<<Array>>]] liveness:20 75 /// CHECK-DAG: ArrayLength liveness:22 76 /// CHECK-DAG: BoundsCheck env:[[<<Const1>>,<<IntArg>>,<<RefArg>>,<<Array>>]] liveness:24 77 /// CHECK-DAG: TryBoundary 78 79 // 80 // A value live at a throwing instruction in a try block may be copied by 81 // the exception handler to its location at the top of the catch block. testThrowIntoCatchBlock(int x, Object y, int[] a)82 public static void testThrowIntoCatchBlock(int x, Object y, int[] a) { 83 try { 84 a[1] = x; 85 } catch (ArrayIndexOutOfBoundsException exception) { 86 } 87 } 88 89 /// CHECK-START-{ARM,ARM64}: void Main.testBoundsCheck(int, java.lang.Object, int[]) liveness (after) 90 /// CHECK-DAG: <<IntArg:i\d+>> ParameterValue env_uses:[] 91 /// CHECK-DAG: <<RefArg:l\d+>> ParameterValue env_uses:[11,19,21] 92 /// CHECK-DAG: <<Array:l\d+>> ParameterValue env_uses:[11,19,21] 93 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1 env_uses:[] 94 /// CHECK-DAG: SuspendCheck env:[[_,<<IntArg>>,<<RefArg>>,<<Array>>]] liveness:10 95 /// CHECK-DAG: NullCheck env:[[<<Const1>>,<<IntArg>>,<<RefArg>>,<<Array>>]] liveness:16 96 /// CHECK-DAG: ArrayLength liveness:18 97 /// CHECK-DAG: BoundsCheck env:[[<<Const1>>,<<IntArg>>,<<RefArg>>,<<Array>>]] liveness:20 98 99 /// CHECK-START-{ARM,ARM64}-DEBUGGABLE: void Main.testBoundsCheck(int, java.lang.Object, int[]) liveness (after) 100 /// CHECK-DAG: <<IntArg:i\d+>> ParameterValue env_uses:[11,19,21] 101 /// CHECK-DAG: <<RefArg:l\d+>> ParameterValue env_uses:[11,19,21] 102 /// CHECK-DAG: <<Array:l\d+>> ParameterValue env_uses:[11,19,21] 103 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1 env_uses:[19,21] 104 /// CHECK-DAG: SuspendCheck env:[[_,<<IntArg>>,<<RefArg>>,<<Array>>]] liveness:10 105 /// CHECK-DAG: NullCheck env:[[<<Const1>>,<<IntArg>>,<<RefArg>>,<<Array>>]] liveness:16 106 /// CHECK-DAG: ArrayLength liveness:18 107 /// CHECK-DAG: BoundsCheck env:[[<<Const1>>,<<IntArg>>,<<RefArg>>,<<Array>>]] liveness:20 108 109 /// CHECK-START-{X86,X86_64}: void Main.testBoundsCheck(int, java.lang.Object, int[]) liveness (after) 110 /// CHECK-DAG: <<IntArg:i\d+>> ParameterValue env_uses:[] 111 /// CHECK-DAG: <<RefArg:l\d+>> ParameterValue env_uses:[11,21,21] 112 /// CHECK-DAG: <<Array:l\d+>> ParameterValue env_uses:[11,21,21] 113 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1 env_uses:[] 114 /// CHECK-DAG: SuspendCheck env:[[_,<<IntArg>>,<<RefArg>>,<<Array>>]] liveness:10 115 /// CHECK-DAG: NullCheck env:[[<<Const1>>,<<IntArg>>,<<RefArg>>,<<Array>>]] liveness:16 116 /// CHECK-DAG: ArrayLength liveness:18 117 /// CHECK-DAG: BoundsCheck env:[[<<Const1>>,<<IntArg>>,<<RefArg>>,<<Array>>]] liveness:20 118 119 /// CHECK-START-{X86,X86_64}-DEBUGGABLE: void Main.testBoundsCheck(int, java.lang.Object, int[]) liveness (after) 120 /// CHECK-DAG: <<IntArg:i\d+>> ParameterValue env_uses:[11,21,21] 121 /// CHECK-DAG: <<RefArg:l\d+>> ParameterValue env_uses:[11,21,21] 122 /// CHECK-DAG: <<Array:l\d+>> ParameterValue env_uses:[11,21,21] 123 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1 env_uses:[21,21] 124 /// CHECK-DAG: SuspendCheck env:[[_,<<IntArg>>,<<RefArg>>,<<Array>>]] liveness:10 125 /// CHECK-DAG: NullCheck env:[[<<Const1>>,<<IntArg>>,<<RefArg>>,<<Array>>]] liveness:16 126 /// CHECK-DAG: ArrayLength liveness:18 127 /// CHECK-DAG: BoundsCheck env:[[<<Const1>>,<<IntArg>>,<<RefArg>>,<<Array>>]] liveness:20 testBoundsCheck(int x, Object y, int[] a)128 public static void testBoundsCheck(int x, Object y, int[] a) { 129 a[1] = x; 130 } 131 132 /// CHECK-START: void Main.testDeoptimize(int, java.lang.Object, int[]) liveness (after) 133 /// CHECK-DAG: <<IntArg:i\d+>> ParameterValue env_uses:[25] 134 /// CHECK-DAG: <<RefArg:l\d+>> ParameterValue env_uses:[13,21,25] 135 /// CHECK-DAG: <<Array:l\d+>> ParameterValue env_uses:[13,21,25] 136 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0 env_uses:[25] 137 /// CHECK-DAG: SuspendCheck env:[[_,<<IntArg>>,<<RefArg>>,<<Array>>]] liveness:12 138 /// CHECK-DAG: NullCheck env:[[<<Const0>>,<<IntArg>>,<<RefArg>>,<<Array>>]] liveness:18 139 /// CHECK-DAG: ArrayLength liveness:20 140 /// CHECK-DAG: Deoptimize env:[[<<Const0>>,<<IntArg>>,<<RefArg>>,<<Array>>]] liveness:24 141 142 /// CHECK-START-{ARM,ARM64}-DEBUGGABLE: void Main.testDeoptimize(int, java.lang.Object, int[]) liveness (after) 143 /// CHECK-DAG: <<IntArg:i\d+>> ParameterValue env_uses:[13,21,25] 144 /// CHECK-DAG: <<RefArg:l\d+>> ParameterValue env_uses:[13,21,25] 145 /// CHECK-DAG: <<Array:l\d+>> ParameterValue env_uses:[13,21,25] 146 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0 env_uses:[21,25] 147 /// CHECK-DAG: SuspendCheck env:[[_,<<IntArg>>,<<RefArg>>,<<Array>>]] liveness:12 148 /// CHECK-DAG: NullCheck env:[[<<Const0>>,<<IntArg>>,<<RefArg>>,<<Array>>]] liveness:18 149 /// CHECK-DAG: ArrayLength liveness:20 150 /// CHECK-DAG: Deoptimize env:[[<<Const0>>,<<IntArg>>,<<RefArg>>,<<Array>>]] liveness:24 151 152 /// CHECK-START-{X86,X86_64}-DEBUGGABLE: void Main.testDeoptimize(int, java.lang.Object, int[]) liveness (after) 153 /// CHECK-DAG: <<IntArg:i\d+>> ParameterValue env_uses:[13,21,25] 154 /// CHECK-DAG: <<RefArg:l\d+>> ParameterValue env_uses:[13,21,25] 155 /// CHECK-DAG: <<Array:l\d+>> ParameterValue env_uses:[13,21,25] 156 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0 env_uses:[21,25] 157 /// CHECK-DAG: SuspendCheck env:[[_,<<IntArg>>,<<RefArg>>,<<Array>>]] liveness:12 158 /// CHECK-DAG: NullCheck env:[[<<Const0>>,<<IntArg>>,<<RefArg>>,<<Array>>]] liveness:18 159 /// CHECK-DAG: ArrayLength liveness:20 160 /// CHECK-DAG: Deoptimize env:[[<<Const0>>,<<IntArg>>,<<RefArg>>,<<Array>>]] liveness:24 161 // 162 // A value that's not live in compiled code may still be needed in interpreter, 163 // due to code motion, etc. testDeoptimize(int x, Object y, int[] a)164 public static void testDeoptimize(int x, Object y, int[] a) { 165 a[0] = x; 166 a[1] = x; 167 } 168 169 170 /// CHECK-START: void Main.main(java.lang.String[]) liveness (after) 171 /// CHECK: <<X:i\d+>> ArrayLength uses:[<<UseInput:\d+>>] 172 /// CHECK: <<Y:i\d+>> StaticFieldGet uses:[<<UseInput>>] 173 /// CHECK: <<Cond:z\d+>> LessThanOrEqual [<<X>>,<<Y>>] 174 /// CHECK-NEXT: If [<<Cond>>] liveness:<<LivIf:\d+>> 175 /// CHECK-EVAL: <<UseInput>> == <<LivIf>> + 1 176 main(String[] args)177 public static void main(String[] args) { 178 int x = args.length; 179 int y = field; 180 if (x > y) { 181 System.nanoTime(); 182 } 183 184 int val = 14; 185 int[] array = new int[2]; 186 Integer intObj = Integer.valueOf(0); 187 testThrowIntoCatchBlock(val, intObj, array); 188 testBoundsCheck(val, intObj, array); 189 testDeoptimize(val, intObj, array); 190 } 191 192 193 public static int field = 42; 194 } 195