blob: 2d43a39d35ced73fab2698aeaa5f1105e7f1aa13 [file] [log] [blame]
Nicolas Geoffray23ddfe82017-06-07 14:09:43 +01001/*
2 * Copyright (C) 2017 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
17public class Main {
18 public static void main(String[] args) throws Exception {
19 System.loadLibrary(args[0]);
20 if (!hasJit()) {
21 return;
22 }
Nicolas Geoffrayd03e8dd2019-04-10 23:13:20 +010023 // Force initialization.
24 Foo.initialize();
Nicolas Geoffray23ddfe82017-06-07 14:09:43 +010025 }
26
Vladimir Marko2196c652017-11-30 16:16:07 +000027 public native static boolean hasJitCompiledEntrypoint(Class<?> cls, String methodName);
Nicolas Geoffray23ddfe82017-06-07 14:09:43 +010028 private native static boolean hasJit();
29}
30
31class Foo {
Nicolas Geoffrayd03e8dd2019-04-10 23:13:20 +010032 // This method needs to be virtual for the test. Otherwise if it's a static method,
33 // the JIT compiler won't compile while its entrypoint is the resolution stub.
34 void $noinline$hotMethod() {
Nicolas Geoffray23ddfe82017-06-07 14:09:43 +010035 for (int i = 0; i < array.length; ++i) {
36 array[i] = array;
37 }
38 }
39
40 static {
41 array = new Object[10000];
Vladimir Markobe0c7cf2018-03-19 13:40:56 +000042 while (!Main.hasJitCompiledEntrypoint(Foo.class, "$noinline$hotMethod")) {
Nicolas Geoffrayd03e8dd2019-04-10 23:13:20 +010043 new Foo().$noinline$hotMethod();
Nicolas Geoffrayde3a5e92017-06-07 21:09:38 +010044 try {
45 // Sleep to give a chance for the JIT to compile `hotMethod`.
46 Thread.sleep(100);
47 } catch (Exception e) {
48 // Ignore
49 }
Nicolas Geoffray23ddfe82017-06-07 14:09:43 +010050 }
51 }
52
Nicolas Geoffrayd03e8dd2019-04-10 23:13:20 +010053 static void initialize() {
54 }
55
Nicolas Geoffray23ddfe82017-06-07 14:09:43 +010056 static Object[] array;
57}