blob: e2b8aa037fb8df19c719b53ecc3d35a156bda0e6 [file] [log] [blame]
Nicolas Geoffraya42363f2015-12-17 14:57:09 +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"
Andreas Gampe542451c2016-07-26 09:02:02 -070018#include "base/enums.h"
Nicolas Geoffraya42363f2015-12-17 14:57:09 +000019#include "jit/jit.h"
20#include "jit/jit_code_cache.h"
Nicolas Geoffray2fa11372016-06-16 14:09:03 +010021#include "jit/profiling_info.h"
Vladimir Markob0b68cf2017-11-14 18:11:50 +000022#include "mirror/class.h"
Nicolas Geoffraya42363f2015-12-17 14:57:09 +000023#include "oat_quick_method_header.h"
Mathieu Chartier0795f232016-09-27 18:43:30 -070024#include "scoped_thread_state_change-inl.h"
Nicolas Geoffraya42363f2015-12-17 14:57:09 +000025#include "stack_map.h"
26
27namespace art {
28
29static void do_checks(jclass cls, const char* method_name) {
30 ScopedObjectAccess soa(Thread::Current());
Mathieu Chartier0795f232016-09-27 18:43:30 -070031 ObjPtr<mirror::Class> klass = soa.Decode<mirror::Class>(cls);
Nicolas Geoffraya42363f2015-12-17 14:57:09 +000032 jit::Jit* jit = Runtime::Current()->GetJit();
33 jit::JitCodeCache* code_cache = jit->GetCodeCache();
Andreas Gampe542451c2016-07-26 09:02:02 -070034 ArtMethod* method = klass->FindDeclaredDirectMethodByName(method_name, kRuntimePointerSize);
Nicolas Geoffraya60e2202016-01-28 18:15:53 +000035
Nicolas Geoffrayc26f1282016-01-29 11:41:25 +000036 OatQuickMethodHeader* header = nullptr;
37 // Infinite loop... Test harness will have its own timeout.
38 while (true) {
Yevgeny Rouband5f56272016-09-28 10:38:25 +070039 const void* pc = method->GetEntryPointFromQuickCompiledCode();
40 if (code_cache->ContainsPc(pc)) {
41 header = OatQuickMethodHeader::FromEntryPoint(pc);
Nicolas Geoffrayc26f1282016-01-29 11:41:25 +000042 break;
43 } else {
Nicolas Geoffray2fa11372016-06-16 14:09:03 +010044 // Sleep to yield to the compiler thread.
45 usleep(1000);
46 // Will either ensure it's compiled or do the compilation itself.
47 jit->CompileMethod(method, soa.Self(), /* osr */ false);
Nicolas Geoffrayc26f1282016-01-29 11:41:25 +000048 }
49 }
Nicolas Geoffraya42363f2015-12-17 14:57:09 +000050
51 CodeInfo info = header->GetOptimizedCodeInfo();
David Srbecky09ed0982016-02-12 21:58:43 +000052 CodeInfoEncoding encoding = info.ExtractEncoding();
53 CHECK(info.HasInlineInfo(encoding));
Nicolas Geoffraya42363f2015-12-17 14:57:09 +000054}
55
Nicolas Geoffray2fa11372016-06-16 14:09:03 +010056static void allocate_profiling_info(jclass cls, const char* method_name) {
57 ScopedObjectAccess soa(Thread::Current());
Mathieu Chartier0795f232016-09-27 18:43:30 -070058 ObjPtr<mirror::Class> klass = soa.Decode<mirror::Class>(cls);
Andreas Gampe542451c2016-07-26 09:02:02 -070059 ArtMethod* method = klass->FindDeclaredDirectMethodByName(method_name, kRuntimePointerSize);
Nicolas Geoffray2fa11372016-06-16 14:09:03 +010060 ProfilingInfo::Create(soa.Self(), method, /* retry_allocation */ true);
61}
62
63extern "C" JNIEXPORT void JNICALL Java_Main_ensureProfilingInfo566(JNIEnv*, jclass cls) {
64 jit::Jit* jit = Runtime::Current()->GetJit();
65 if (jit == nullptr) {
66 return;
67 }
68
69 allocate_profiling_info(cls, "testInvokeVirtual");
70 allocate_profiling_info(cls, "testInvokeInterface");
71 allocate_profiling_info(cls, "$noinline$testInlineToSameTarget");
72}
73
74extern "C" JNIEXPORT void JNICALL Java_Main_ensureJittedAndPolymorphicInline566(JNIEnv*, jclass cls) {
Nicolas Geoffraya42363f2015-12-17 14:57:09 +000075 jit::Jit* jit = Runtime::Current()->GetJit();
76 if (jit == nullptr) {
77 return;
78 }
79
Nicolas Geoffrayc26f1282016-01-29 11:41:25 +000080 if (kIsDebugBuild) {
81 // A debug build might often compile the methods without profiling informations filled.
82 return;
83 }
84
Nicolas Geoffraya42363f2015-12-17 14:57:09 +000085 do_checks(cls, "testInvokeVirtual");
86 do_checks(cls, "testInvokeInterface");
Nicolas Geoffrayff484b92016-07-13 14:13:48 +010087 do_checks(cls, "testInvokeInterface2");
Nicolas Geoffray1be7cbd2016-04-29 13:56:01 +010088 do_checks(cls, "$noinline$testInlineToSameTarget");
Nicolas Geoffraya42363f2015-12-17 14:57:09 +000089}
90
91} // namespace art