• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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   int mainField = 42;
19 
main(String[] args)20   public static void main(String[] args) throws Exception {
21     System.loadLibrary(args[0]);
22     ensureJitCompiled(Main.class, "$noinline$callRecursiveMethod");
23     $noinline$callRecursiveMethod(true);
24   }
25 
expectEquals(int expected, int actual)26   public static void expectEquals(int expected, int actual) {
27     if (expected != actual) {
28       throw new Error("Expected " + expected + ", got " + actual);
29     }
30   }
31 
$noinline$callRecursiveMethod(boolean firstEntry)32   public static void $noinline$callRecursiveMethod(boolean firstEntry) throws Exception {
33     Class<?> cls = Class.forName("LoadedLater");
34     Main m = (Main)cls.newInstance();
35     if (firstEntry) {
36       $noinline$callRecursiveMethod(false);
37     } else {
38       expectEquals(0, m.getField());
39     }
40   }
41 
getField()42   public int getField() {
43     return mainField;
44   }
45 
ensureJitCompiled(Class<?> cls, String methodName)46   public static native void ensureJitCompiled(Class<?> cls, String methodName);
47 }
48 
49 class LoadedLater extends Main {
getField()50   public int getField() {
51     return 0;
52   }
53 }
54