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