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 "base/enums.h"
19 #include "jit/jit.h"
20 #include "jit/jit_code_cache.h"
21 #include "jit/profiling_info.h"
22 #include "mirror/class.h"
23 #include "oat_quick_method_header.h"
24 #include "scoped_thread_state_change-inl.h"
25 #include "stack_map.h"
26
27 namespace art {
28
do_checks(jclass cls,const char * method_name)29 static void do_checks(jclass cls, const char* method_name) {
30 ScopedObjectAccess soa(Thread::Current());
31 ObjPtr<mirror::Class> klass = soa.Decode<mirror::Class>(cls);
32 jit::Jit* jit = Runtime::Current()->GetJit();
33 jit::JitCodeCache* code_cache = jit->GetCodeCache();
34 ArtMethod* method = klass->FindDeclaredDirectMethodByName(method_name, kRuntimePointerSize);
35
36 OatQuickMethodHeader* header = nullptr;
37 // Infinite loop... Test harness will have its own timeout.
38 while (true) {
39 const void* pc = method->GetEntryPointFromQuickCompiledCode();
40 if (code_cache->ContainsPc(pc)) {
41 header = OatQuickMethodHeader::FromEntryPoint(pc);
42 break;
43 } else {
44 ScopedThreadSuspension sts(soa.Self(), kSuspended);
45 // Sleep to yield to the compiler thread.
46 usleep(1000);
47 }
48 // Will either ensure it's compiled or do the compilation itself.
49 jit->CompileMethod(method, soa.Self(), /*baseline=*/ false, /*osr=*/ false, /*prejit=*/ false);
50 }
51
52 CodeInfo info(header);
53 CHECK(info.HasInlineInfo()) << method->PrettyMethod();
54 }
55
allocate_profiling_info(jclass cls,const char * method_name)56 static void allocate_profiling_info(jclass cls, const char* method_name) {
57 ScopedObjectAccess soa(Thread::Current());
58 ObjPtr<mirror::Class> klass = soa.Decode<mirror::Class>(cls);
59 ArtMethod* method = klass->FindDeclaredDirectMethodByName(method_name, kRuntimePointerSize);
60 ProfilingInfo::Create(soa.Self(), method, /* retry_allocation */ true);
61 }
62
Java_Main_ensureProfilingInfo566(JNIEnv *,jclass cls)63 extern "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, "$noinline$testInvokeVirtual");
70 allocate_profiling_info(cls, "$noinline$testInvokeInterface");
71 allocate_profiling_info(cls, "$noinline$testInlineToSameTarget");
72 }
73
Java_Main_ensureJittedAndPolymorphicInline566(JNIEnv *,jclass cls)74 extern "C" JNIEXPORT void JNICALL Java_Main_ensureJittedAndPolymorphicInline566(JNIEnv*, jclass cls) {
75 jit::Jit* jit = Runtime::Current()->GetJit();
76 if (jit == nullptr) {
77 return;
78 }
79
80 if (kIsDebugBuild) {
81 // A debug build might often compile the methods without profiling informations filled.
82 return;
83 }
84
85 do_checks(cls, "$noinline$testInvokeVirtual");
86 do_checks(cls, "$noinline$testInvokeInterface");
87 do_checks(cls, "$noinline$testInvokeInterface2");
88 do_checks(cls, "$noinline$testInlineToSameTarget");
89 }
90
91 } // namespace art
92