| Nicolas Geoffray | 23ddfe8 | 2017-06-07 14:09:43 +0100 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | public class Main { |
| 18 | public static void main(String[] args) throws Exception { |
| 19 | System.loadLibrary(args[0]); |
| 20 | if (!hasJit()) { |
| 21 | return; |
| 22 | } |
| Nicolas Geoffray | d03e8dd | 2019-04-10 23:13:20 +0100 | [diff] [blame] | 23 | // Force initialization. |
| 24 | Foo.initialize(); |
| Nicolas Geoffray | 23ddfe8 | 2017-06-07 14:09:43 +0100 | [diff] [blame] | 25 | } |
| 26 | |
| Vladimir Marko | 2196c65 | 2017-11-30 16:16:07 +0000 | [diff] [blame] | 27 | public native static boolean hasJitCompiledEntrypoint(Class<?> cls, String methodName); |
| Nicolas Geoffray | 23ddfe8 | 2017-06-07 14:09:43 +0100 | [diff] [blame] | 28 | private native static boolean hasJit(); |
| 29 | } |
| 30 | |
| 31 | class Foo { |
| Nicolas Geoffray | d03e8dd | 2019-04-10 23:13:20 +0100 | [diff] [blame] | 32 | // 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 Geoffray | 23ddfe8 | 2017-06-07 14:09:43 +0100 | [diff] [blame] | 35 | for (int i = 0; i < array.length; ++i) { |
| 36 | array[i] = array; |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | static { |
| 41 | array = new Object[10000]; |
| Vladimir Marko | be0c7cf | 2018-03-19 13:40:56 +0000 | [diff] [blame] | 42 | while (!Main.hasJitCompiledEntrypoint(Foo.class, "$noinline$hotMethod")) { |
| Nicolas Geoffray | d03e8dd | 2019-04-10 23:13:20 +0100 | [diff] [blame] | 43 | new Foo().$noinline$hotMethod(); |
| Nicolas Geoffray | de3a5e9 | 2017-06-07 21:09:38 +0100 | [diff] [blame] | 44 | 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 Geoffray | 23ddfe8 | 2017-06-07 14:09:43 +0100 | [diff] [blame] | 50 | } |
| 51 | } |
| 52 | |
| Nicolas Geoffray | d03e8dd | 2019-04-10 23:13:20 +0100 | [diff] [blame] | 53 | static void initialize() { |
| 54 | } |
| 55 | |
| Nicolas Geoffray | 23ddfe8 | 2017-06-07 14:09:43 +0100 | [diff] [blame] | 56 | static Object[] array; |
| 57 | } |