blob: 475a11d3515ea36abdf99138f8cc241c32da5f70 [file] [log] [blame]
Nicolas Geoffray3aaf9642016-06-07 14:14:37 +00001/*
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 Geoffrayadc61df2016-06-09 11:59:31 +010020#include "jit/profiling_info.h"
Nicolas Geoffray3aaf9642016-06-07 14:14:37 +000021#include "oat_quick_method_header.h"
22#include "scoped_thread_state_change.h"
23#include "ScopedUtfChars.h"
24#include "stack_map.h"
25
26namespace art {
27
28extern "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 Geoffrayadc61df2016-06-09 11:59:31 +010047 // Make sure there is a profiling info, required by the compiler.
48 ProfilingInfo::Create(soa.Self(), method, /* retry_allocation */ true);
Nicolas Geoffray3aaf9642016-06-07 14:14:37 +000049 while (true) {
50 header = OatQuickMethodHeader::FromEntryPoint(method->GetEntryPointFromQuickCompiledCode());
51 if (code_cache->ContainsPc(header->GetCode())) {
52 break;
53 } else {
Nicolas Geoffray81d82ff2016-06-08 13:37:45 +010054 // Sleep to yield to the compiler thread.
Nicolas Geoffray223ac0c2016-06-09 09:53:55 +010055 usleep(1000);
Nicolas Geoffray10278802016-06-08 09:18:38 +010056 // Will either ensure it's compiled or do the compilation itself.
Nicolas Geoffrayadc61df2016-06-09 11:59:31 +010057 jit->CompileMethod(method, soa.Self(), /* osr */ false);
Nicolas Geoffray3aaf9642016-06-07 14:14:37 +000058 }
59 }
60}
61
62} // namespace art