Nicolas Geoffray | 3aaf964 | 2016-06-07 14:14:37 +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" |
| 18 | #include "jit/jit.h" |
| 19 | #include "jit/jit_code_cache.h" |
Nicolas Geoffray | adc61df | 2016-06-09 11:59:31 +0100 | [diff] [blame] | 20 | #include "jit/profiling_info.h" |
Nicolas Geoffray | 3aaf964 | 2016-06-07 14:14:37 +0000 | [diff] [blame] | 21 | #include "oat_quick_method_header.h" |
| 22 | #include "scoped_thread_state_change.h" |
| 23 | #include "ScopedUtfChars.h" |
| 24 | #include "stack_map.h" |
| 25 | |
| 26 | namespace art { |
| 27 | |
| 28 | extern "C" JNIEXPORT void JNICALL Java_Main_waitUntilJitted(JNIEnv* env, |
| 29 | jclass, |
| 30 | jclass itf, |
| 31 | jstring method_name) { |
| 32 | jit::Jit* jit = Runtime::Current()->GetJit(); |
| 33 | if (jit == nullptr) { |
| 34 | return; |
| 35 | } |
| 36 | |
| 37 | ScopedObjectAccess soa(Thread::Current()); |
| 38 | |
| 39 | ScopedUtfChars chars(env, method_name); |
| 40 | CHECK(chars.c_str() != nullptr); |
| 41 | |
| 42 | mirror::Class* klass = soa.Decode<mirror::Class*>(itf); |
| 43 | ArtMethod* method = klass->FindDeclaredDirectMethodByName(chars.c_str(), sizeof(void*)); |
| 44 | |
| 45 | jit::JitCodeCache* code_cache = jit->GetCodeCache(); |
| 46 | OatQuickMethodHeader* header = nullptr; |
Nicolas Geoffray | adc61df | 2016-06-09 11:59:31 +0100 | [diff] [blame] | 47 | // Make sure there is a profiling info, required by the compiler. |
| 48 | ProfilingInfo::Create(soa.Self(), method, /* retry_allocation */ true); |
Nicolas Geoffray | 3aaf964 | 2016-06-07 14:14:37 +0000 | [diff] [blame] | 49 | while (true) { |
| 50 | header = OatQuickMethodHeader::FromEntryPoint(method->GetEntryPointFromQuickCompiledCode()); |
| 51 | if (code_cache->ContainsPc(header->GetCode())) { |
| 52 | break; |
| 53 | } else { |
Nicolas Geoffray | 81d82ff | 2016-06-08 13:37:45 +0100 | [diff] [blame] | 54 | // Sleep to yield to the compiler thread. |
Nicolas Geoffray | 223ac0c | 2016-06-09 09:53:55 +0100 | [diff] [blame] | 55 | usleep(1000); |
Nicolas Geoffray | 1027880 | 2016-06-08 09:18:38 +0100 | [diff] [blame] | 56 | // Will either ensure it's compiled or do the compilation itself. |
Nicolas Geoffray | adc61df | 2016-06-09 11:59:31 +0100 | [diff] [blame] | 57 | jit->CompileMethod(method, soa.Self(), /* osr */ false); |
Nicolas Geoffray | 3aaf964 | 2016-06-07 14:14:37 +0000 | [diff] [blame] | 58 | } |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | } // namespace art |