1 /* 2 * Copyright (C) 2024 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 class WithStatic { 18 public static int field = 42; 19 } 20 21 // `CallStatic` being part of the profile, the compiler used to think it will be in the app image. 22 // However, given it implements `Itf` which is from a different dex file from a different class 23 // loader, we cannot encode `CallStatic` in the image. We used to find that information too late in 24 // the compilation stage and were therefore wrongly assuming we could inline methods from 25 // `CallStatic` without the need for resolving it. 26 // 27 // Note that to trigger the crash, we needed an interface from a different dex file. We were 28 // correctly pruning the class if the superclass was from a different dex file. 29 class CallStatic implements Itf { $inline$foo()30 public static int $inline$foo() { 31 // Access a static field to make sure we invoke the runtime, which will then walk the call 32 // stack. 33 return WithStatic.field; 34 } 35 } 36 37 public class Test { callInstance()38 public static int callInstance() { 39 // Call a method from `CallStatic` which will be inlined. If the compiler thinks `CallStatic` 40 // will be in the image, it will skip the slow path of resolving it. 41 return CallStatic.$inline$foo(); 42 } 43 } 44