Home | History | Annotate | Download | only in src
      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 
     19   // This tests a specific situation when condition ends up
     20   // not getting materialized if only used by an environment.
     21 
     22   private static Object obj;
     23 
     24   private static int useValue(boolean value) {
     25     return 42;
     26   }
     27 
     28   private static int runTest(boolean input1) {
     29     boolean negation = !input1;
     30     // Need the negation to appear in front of an If, and
     31     // its condition to disappear. 'javac' will generate
     32     // "if (!input1)" here and GVN will collapse the two
     33     // conditions.
     34     if (input1) {
     35       // Generates an environment use of 'negation'.
     36       obj = new Object();
     37     }
     38     // Uses 'negation' but disappears with inlining.
     39     return useValue(negation);
     40   }
     41 
     42   public static void main(String[] args) throws Exception {
     43     int result = runTest(true);
     44     if (result != 42) {
     45       throw new Error("Expected 42, got " + result);
     46     }
     47   }
     48 }
     49