1790412959a6413a585f45fc5f77fe7106311a00cNicolas Geoffray/*
26a92a033c33e383541d77607fbe8cd982875d13dRoland Levillain * Copyright (C) 2015 The Android Open Source Project
36a92a033c33e383541d77607fbe8cd982875d13dRoland Levillain *
46a92a033c33e383541d77607fbe8cd982875d13dRoland Levillain * Licensed under the Apache License, Version 2.0 (the "License");
56a92a033c33e383541d77607fbe8cd982875d13dRoland Levillain * you may not use this file except in compliance with the License.
66a92a033c33e383541d77607fbe8cd982875d13dRoland Levillain * You may obtain a copy of the License at
76a92a033c33e383541d77607fbe8cd982875d13dRoland Levillain *
86a92a033c33e383541d77607fbe8cd982875d13dRoland Levillain *      http://www.apache.org/licenses/LICENSE-2.0
96a92a033c33e383541d77607fbe8cd982875d13dRoland Levillain *
106a92a033c33e383541d77607fbe8cd982875d13dRoland Levillain * Unless required by applicable law or agreed to in writing, software
116a92a033c33e383541d77607fbe8cd982875d13dRoland Levillain * distributed under the License is distributed on an "AS IS" BASIS,
126a92a033c33e383541d77607fbe8cd982875d13dRoland Levillain * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
136a92a033c33e383541d77607fbe8cd982875d13dRoland Levillain * See the License for the specific language governing permissions and
146a92a033c33e383541d77607fbe8cd982875d13dRoland Levillain * limitations under the License.
156a92a033c33e383541d77607fbe8cd982875d13dRoland Levillain */
16790412959a6413a585f45fc5f77fe7106311a00cNicolas Geoffray
17790412959a6413a585f45fc5f77fe7106311a00cNicolas Geoffraypublic final class Main {
18790412959a6413a585f45fc5f77fe7106311a00cNicolas Geoffray
19dcdc85bbd569f0ee66c331b4219c19304a616214Jeff Hao  public final static class Helper {
20dcdc85bbd569f0ee66c331b4219c19304a616214Jeff Hao    private int foo = 3;
21dcdc85bbd569f0ee66c331b4219c19304a616214Jeff Hao
22dcdc85bbd569f0ee66c331b4219c19304a616214Jeff Hao    public int getFoo() {
23dcdc85bbd569f0ee66c331b4219c19304a616214Jeff Hao        return foo;
24dcdc85bbd569f0ee66c331b4219c19304a616214Jeff Hao    }
25dcdc85bbd569f0ee66c331b4219c19304a616214Jeff Hao  }
26dcdc85bbd569f0ee66c331b4219c19304a616214Jeff Hao
27790412959a6413a585f45fc5f77fe7106311a00cNicolas Geoffray  public void invokeVirtual() {
28790412959a6413a585f45fc5f77fe7106311a00cNicolas Geoffray  }
29790412959a6413a585f45fc5f77fe7106311a00cNicolas Geoffray
30e523423a053af5cb55837f07ceae9ff2fd581712Nicolas Geoffray  /// CHECK-START: void Main.inlineSharpenInvokeVirtual(Main) builder (after)
31e523423a053af5cb55837f07ceae9ff2fd581712Nicolas Geoffray  /// CHECK-DAG:     <<Invoke:v\d+>>  InvokeVirtual
32a06d66a4ee60926127b9498b7ff0b3e37a24fccfDavid Brazdil  /// CHECK-DAG:                      ReturnVoid
33790412959a6413a585f45fc5f77fe7106311a00cNicolas Geoffray
34a06d66a4ee60926127b9498b7ff0b3e37a24fccfDavid Brazdil  /// CHECK-START: void Main.inlineSharpenInvokeVirtual(Main) inliner (after)
35e523423a053af5cb55837f07ceae9ff2fd581712Nicolas Geoffray  /// CHECK-NOT:                      InvokeVirtual
36a06d66a4ee60926127b9498b7ff0b3e37a24fccfDavid Brazdil  /// CHECK-NOT:                      InvokeStaticOrDirect
37790412959a6413a585f45fc5f77fe7106311a00cNicolas Geoffray
38790412959a6413a585f45fc5f77fe7106311a00cNicolas Geoffray  public static void inlineSharpenInvokeVirtual(Main m) {
39790412959a6413a585f45fc5f77fe7106311a00cNicolas Geoffray    m.invokeVirtual();
40790412959a6413a585f45fc5f77fe7106311a00cNicolas Geoffray  }
41790412959a6413a585f45fc5f77fe7106311a00cNicolas Geoffray
42badd826664896d4a9628a5a89b78016894aa414bDavid Brazdil  /// CHECK-START: int Main.inlineSharpenHelperInvoke() builder (after)
43dcdc85bbd569f0ee66c331b4219c19304a616214Jeff Hao  /// CHECK-DAG:     <<Invoke:i\d+>>  InvokeVirtual {{.*\.getFoo.*}}
44a06d66a4ee60926127b9498b7ff0b3e37a24fccfDavid Brazdil  /// CHECK-DAG:                      Return [<<Invoke>>]
45790412959a6413a585f45fc5f77fe7106311a00cNicolas Geoffray
46dcdc85bbd569f0ee66c331b4219c19304a616214Jeff Hao  /// CHECK-START: int Main.inlineSharpenHelperInvoke() inliner (after)
47dcdc85bbd569f0ee66c331b4219c19304a616214Jeff Hao  /// CHECK-NOT:                      InvokeStaticOrDirect {{.*\.getFoo.*}}
48dcdc85bbd569f0ee66c331b4219c19304a616214Jeff Hao  /// CHECK-NOT:                      InvokeVirtual {{.*\.getFoo.*}}
49790412959a6413a585f45fc5f77fe7106311a00cNicolas Geoffray
50dcdc85bbd569f0ee66c331b4219c19304a616214Jeff Hao  /// CHECK-START: int Main.inlineSharpenHelperInvoke() inliner (after)
51a06d66a4ee60926127b9498b7ff0b3e37a24fccfDavid Brazdil  /// CHECK-DAG:     <<Field:i\d+>>   InstanceFieldGet
52a06d66a4ee60926127b9498b7ff0b3e37a24fccfDavid Brazdil  /// CHECK-DAG:                      Return [<<Field>>]
53790412959a6413a585f45fc5f77fe7106311a00cNicolas Geoffray
54dcdc85bbd569f0ee66c331b4219c19304a616214Jeff Hao  public static int inlineSharpenHelperInvoke() {
55dcdc85bbd569f0ee66c331b4219c19304a616214Jeff Hao    return new Helper().getFoo();
56790412959a6413a585f45fc5f77fe7106311a00cNicolas Geoffray  }
57790412959a6413a585f45fc5f77fe7106311a00cNicolas Geoffray
58790412959a6413a585f45fc5f77fe7106311a00cNicolas Geoffray  public static void main(String[] args) {
59790412959a6413a585f45fc5f77fe7106311a00cNicolas Geoffray    inlineSharpenInvokeVirtual(new Main());
60dcdc85bbd569f0ee66c331b4219c19304a616214Jeff Hao    if (inlineSharpenHelperInvoke() != 3) {
61790412959a6413a585f45fc5f77fe7106311a00cNicolas Geoffray      throw new Error("Expected 3");
62790412959a6413a585f45fc5f77fe7106311a00cNicolas Geoffray    }
63790412959a6413a585f45fc5f77fe7106311a00cNicolas Geoffray  }
64790412959a6413a585f45fc5f77fe7106311a00cNicolas Geoffray}
65