blob: 9c51ca60ab666ad3b584aed7375d863cc9864de7 [file] [log] [blame]
Nicolas Geoffray2dc77ec2016-06-02 15:55:48 +01001/*
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
25namespace art {
26
27extern "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();
53 }
54 }
55}
56
57} // namespace art