• 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 
main(String[] args)19   public static void main(String[] args) {
20     System.loadLibrary(args[0]);
21     ensureJitCompiled(Main.class, "staticMethod");
22     int a = staticMethod(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
23     assertEquals(42, a);
24 
25     ensureJitCompiled(Main.class, "staticMethodNonRange");
26     a = staticMethodNonRange(1, 2, 3, 4, 5);
27     assertEquals(42, a);
28 
29     staticMain = new Main();
30     ensureJitCompiled(Main.class, "instanceMethod");
31     a = staticMain.instanceMethod(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
32     assertEquals(42, a);
33 
34     ensureJitCompiled(Main.class, "instanceMethodNonRange");
35     a = staticMain.instanceMethodNonRange(1, 2, 3, 4);
36     assertEquals(42, a);
37   }
38 
staticMethod( int a, int b, int c, int d, int e, int f, int g, int h, int i, int j)39   public static int staticMethod(
40       int a, int b, int c, int d, int e, int f, int g, int h, int i, int j) {
41     assertEquals(10, j);
42     assertEquals(9, i);
43     assertEquals(8, h);
44     assertEquals(7, g);
45     assertEquals(6, f);
46     assertEquals(5, e);
47     assertEquals(4, d);
48     assertEquals(3, c);
49     assertEquals(2, b);
50     assertEquals(1, a);
51     return 42;
52   }
53 
instanceMethod(int a, int b, int c, int d, int e, int f, int g, int h, int i, int j)54   public int instanceMethod(int a, int b, int c, int d, int e, int f, int g, int h, int i, int j) {
55     assertEquals(10, j);
56     assertEquals(9, i);
57     assertEquals(8, h);
58     assertEquals(7, g);
59     assertEquals(6, f);
60     assertEquals(5, e);
61     assertEquals(4, d);
62     assertEquals(3, c);
63     assertEquals(2, b);
64     assertEquals(1, a);
65     assertEquals(staticMain, this);
66     return 42;
67   }
68 
staticMethodNonRange(int a, int b, int c, int d, int e)69   public static int staticMethodNonRange(int a, int b, int c, int d, int e) {
70     assertEquals(5, e);
71     assertEquals(4, d);
72     assertEquals(3, c);
73     assertEquals(2, b);
74     assertEquals(1, a);
75     return 42;
76   }
77 
instanceMethodNonRange(int a, int b, int c, int d)78   public int instanceMethodNonRange(int a, int b, int c, int d) {
79     assertEquals(4, d);
80     assertEquals(3, c);
81     assertEquals(2, b);
82     assertEquals(1, a);
83     assertEquals(staticMain, this);
84     return 42;
85   }
86 
87   static Main staticMain;
88 
assertEquals(int expected, int actual)89   public static void assertEquals(int expected, int actual) {
90     if (expected != actual) {
91       throw new Error("Expected " + expected + ", got " + actual);
92     }
93   }
94 
assertEquals(Object expected, Object actual)95   public static void assertEquals(Object expected, Object actual) {
96     if (expected != actual) {
97       throw new Error("Expected " + expected + ", got " + actual);
98     }
99   }
100 
ensureJitCompiled(Class<?> cls, String methodName)101   public static native void ensureJitCompiled(Class<?> cls, String methodName);
102 }
103