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 final class Main {
     18 
     19   public final static class Helper {
     20     private int foo = 3;
     21 
     22     public int getFoo() {
     23         return foo;
     24     }
     25   }
     26 
     27   public void invokeVirtual() {
     28   }
     29 
     30   /// CHECK-START: void Main.inlineSharpenInvokeVirtual(Main) builder (after)
     31   /// CHECK-DAG:     <<Invoke:v\d+>>  InvokeVirtual
     32   /// CHECK-DAG:                      ReturnVoid
     33 
     34   /// CHECK-START: void Main.inlineSharpenInvokeVirtual(Main) inliner (after)
     35   /// CHECK-NOT:                      InvokeVirtual
     36   /// CHECK-NOT:                      InvokeStaticOrDirect
     37 
     38   public static void inlineSharpenInvokeVirtual(Main m) {
     39     m.invokeVirtual();
     40   }
     41 
     42   /// CHECK-START: int Main.inlineSharpenHelperInvoke() builder (after)
     43   /// CHECK-DAG:     <<Invoke:i\d+>>  InvokeVirtual {{.*\.getFoo.*}}
     44   /// CHECK-DAG:                      Return [<<Invoke>>]
     45 
     46   /// CHECK-START: int Main.inlineSharpenHelperInvoke() inliner (after)
     47   /// CHECK-NOT:                      InvokeStaticOrDirect {{.*\.getFoo.*}}
     48   /// CHECK-NOT:                      InvokeVirtual {{.*\.getFoo.*}}
     49 
     50   /// CHECK-START: int Main.inlineSharpenHelperInvoke() inliner (after)
     51   /// CHECK-DAG:     <<Field:i\d+>>   InstanceFieldGet
     52   /// CHECK-DAG:                      Return [<<Field>>]
     53 
     54   public static int inlineSharpenHelperInvoke() {
     55     return new Helper().getFoo();
     56   }
     57 
     58   public static void main(String[] args) {
     59     inlineSharpenInvokeVirtual(new Main());
     60     if (inlineSharpenHelperInvoke() != 3) {
     61       throw new Error("Expected 3");
     62     }
     63   }
     64 }
     65