Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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 | #include "art_method.h" |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 18 | #include "base/enums.h" |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 19 | #include "jit/jit.h" |
| 20 | #include "jit/jit_code_cache.h" |
Nicolas Geoffray | 2fa1137 | 2016-06-16 14:09:03 +0100 | [diff] [blame] | 21 | #include "jit/profiling_info.h" |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 22 | #include "oat_quick_method_header.h" |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 23 | #include "scoped_thread_state_change-inl.h" |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 24 | #include "stack_map.h" |
| 25 | |
| 26 | namespace art { |
| 27 | |
| 28 | static void do_checks(jclass cls, const char* method_name) { |
| 29 | ScopedObjectAccess soa(Thread::Current()); |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 30 | ObjPtr<mirror::Class> klass = soa.Decode<mirror::Class>(cls); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 31 | jit::Jit* jit = Runtime::Current()->GetJit(); |
| 32 | jit::JitCodeCache* code_cache = jit->GetCodeCache(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 33 | ArtMethod* method = klass->FindDeclaredDirectMethodByName(method_name, kRuntimePointerSize); |
Nicolas Geoffray | a60e220 | 2016-01-28 18:15:53 +0000 | [diff] [blame] | 34 | |
Nicolas Geoffray | c26f128 | 2016-01-29 11:41:25 +0000 | [diff] [blame] | 35 | OatQuickMethodHeader* header = nullptr; |
| 36 | // Infinite loop... Test harness will have its own timeout. |
| 37 | while (true) { |
| 38 | header = OatQuickMethodHeader::FromEntryPoint(method->GetEntryPointFromQuickCompiledCode()); |
| 39 | if (code_cache->ContainsPc(header->GetCode())) { |
| 40 | break; |
| 41 | } else { |
Nicolas Geoffray | 2fa1137 | 2016-06-16 14:09:03 +0100 | [diff] [blame] | 42 | // Sleep to yield to the compiler thread. |
| 43 | usleep(1000); |
| 44 | // Will either ensure it's compiled or do the compilation itself. |
| 45 | jit->CompileMethod(method, soa.Self(), /* osr */ false); |
Nicolas Geoffray | c26f128 | 2016-01-29 11:41:25 +0000 | [diff] [blame] | 46 | } |
| 47 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 48 | |
| 49 | CodeInfo info = header->GetOptimizedCodeInfo(); |
David Srbecky | 09ed098 | 2016-02-12 21:58:43 +0000 | [diff] [blame] | 50 | CodeInfoEncoding encoding = info.ExtractEncoding(); |
| 51 | CHECK(info.HasInlineInfo(encoding)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 52 | } |
| 53 | |
Nicolas Geoffray | 2fa1137 | 2016-06-16 14:09:03 +0100 | [diff] [blame] | 54 | static void allocate_profiling_info(jclass cls, const char* method_name) { |
| 55 | ScopedObjectAccess soa(Thread::Current()); |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 56 | ObjPtr<mirror::Class> klass = soa.Decode<mirror::Class>(cls); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 57 | ArtMethod* method = klass->FindDeclaredDirectMethodByName(method_name, kRuntimePointerSize); |
Nicolas Geoffray | 2fa1137 | 2016-06-16 14:09:03 +0100 | [diff] [blame] | 58 | ProfilingInfo::Create(soa.Self(), method, /* retry_allocation */ true); |
| 59 | } |
| 60 | |
| 61 | extern "C" JNIEXPORT void JNICALL Java_Main_ensureProfilingInfo566(JNIEnv*, jclass cls) { |
| 62 | jit::Jit* jit = Runtime::Current()->GetJit(); |
| 63 | if (jit == nullptr) { |
| 64 | return; |
| 65 | } |
| 66 | |
| 67 | allocate_profiling_info(cls, "testInvokeVirtual"); |
| 68 | allocate_profiling_info(cls, "testInvokeInterface"); |
| 69 | allocate_profiling_info(cls, "$noinline$testInlineToSameTarget"); |
| 70 | } |
| 71 | |
| 72 | extern "C" JNIEXPORT void JNICALL Java_Main_ensureJittedAndPolymorphicInline566(JNIEnv*, jclass cls) { |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 73 | jit::Jit* jit = Runtime::Current()->GetJit(); |
| 74 | if (jit == nullptr) { |
| 75 | return; |
| 76 | } |
| 77 | |
Nicolas Geoffray | c26f128 | 2016-01-29 11:41:25 +0000 | [diff] [blame] | 78 | if (kIsDebugBuild) { |
| 79 | // A debug build might often compile the methods without profiling informations filled. |
| 80 | return; |
| 81 | } |
| 82 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 83 | do_checks(cls, "testInvokeVirtual"); |
| 84 | do_checks(cls, "testInvokeInterface"); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 85 | do_checks(cls, "testInvokeInterface2"); |
Nicolas Geoffray | 1be7cbd | 2016-04-29 13:56:01 +0100 | [diff] [blame] | 86 | do_checks(cls, "$noinline$testInlineToSameTarget"); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | } // namespace art |