blob: 9f4c6c91f8c32948c0e1e6d89778d427dc36a6d2 [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"
18#include "jit/jit.h"
19#include "jit/jit_code_cache.h"
Nicolas Geoffray2fa11372016-06-16 14:09:03 +010020#include "jit/profiling_info.h"
Nicolas Geoffraya42363f2015-12-17 14:57:09 +000021#include "oat_quick_method_header.h"
22#include "scoped_thread_state_change.h"
23#include "stack_map.h"
24
25namespace art {
26
27static void do_checks(jclass cls, const char* method_name) {
28 ScopedObjectAccess soa(Thread::Current());
29 mirror::Class* klass = soa.Decode<mirror::Class*>(cls);
30 jit::Jit* jit = Runtime::Current()->GetJit();
31 jit::JitCodeCache* code_cache = jit->GetCodeCache();
32 ArtMethod* method = klass->FindDeclaredDirectMethodByName(method_name, sizeof(void*));
Nicolas Geoffraya60e2202016-01-28 18:15:53 +000033
Nicolas Geoffrayc26f1282016-01-29 11:41:25 +000034 OatQuickMethodHeader* header = nullptr;
35 // Infinite loop... Test harness will have its own timeout.
36 while (true) {
37 header = OatQuickMethodHeader::FromEntryPoint(method->GetEntryPointFromQuickCompiledCode());
38 if (code_cache->ContainsPc(header->GetCode())) {
39 break;
40 } else {
Nicolas Geoffray2fa11372016-06-16 14:09:03 +010041 // Sleep to yield to the compiler thread.
42 usleep(1000);
43 // Will either ensure it's compiled or do the compilation itself.
44 jit->CompileMethod(method, soa.Self(), /* osr */ false);
Nicolas Geoffrayc26f1282016-01-29 11:41:25 +000045 }
46 }
Nicolas Geoffraya42363f2015-12-17 14:57:09 +000047
48 CodeInfo info = header->GetOptimizedCodeInfo();
David Srbecky09ed0982016-02-12 21:58:43 +000049 CodeInfoEncoding encoding = info.ExtractEncoding();
50 CHECK(info.HasInlineInfo(encoding));
Nicolas Geoffraya42363f2015-12-17 14:57:09 +000051}
52
Nicolas Geoffray2fa11372016-06-16 14:09:03 +010053static void allocate_profiling_info(jclass cls, const char* method_name) {
54 ScopedObjectAccess soa(Thread::Current());
55 mirror::Class* klass = soa.Decode<mirror::Class*>(cls);
56 ArtMethod* method = klass->FindDeclaredDirectMethodByName(method_name, sizeof(void*));
57 ProfilingInfo::Create(soa.Self(), method, /* retry_allocation */ true);
58}
59
60extern "C" JNIEXPORT void JNICALL Java_Main_ensureProfilingInfo566(JNIEnv*, jclass cls) {
61 jit::Jit* jit = Runtime::Current()->GetJit();
62 if (jit == nullptr) {
63 return;
64 }
65
66 allocate_profiling_info(cls, "testInvokeVirtual");
67 allocate_profiling_info(cls, "testInvokeInterface");
68 allocate_profiling_info(cls, "$noinline$testInlineToSameTarget");
69}
70
71extern "C" JNIEXPORT void JNICALL Java_Main_ensureJittedAndPolymorphicInline566(JNIEnv*, jclass cls) {
Nicolas Geoffraya42363f2015-12-17 14:57:09 +000072 jit::Jit* jit = Runtime::Current()->GetJit();
73 if (jit == nullptr) {
74 return;
75 }
76
Nicolas Geoffrayc26f1282016-01-29 11:41:25 +000077 if (kIsDebugBuild) {
78 // A debug build might often compile the methods without profiling informations filled.
79 return;
80 }
81
Nicolas Geoffraya42363f2015-12-17 14:57:09 +000082 do_checks(cls, "testInvokeVirtual");
83 do_checks(cls, "testInvokeInterface");
Nicolas Geoffrayff484b92016-07-13 14:13:48 +010084 do_checks(cls, "testInvokeInterface2");
Nicolas Geoffray1be7cbd2016-04-29 13:56:01 +010085 do_checks(cls, "$noinline$testInlineToSameTarget");
Nicolas Geoffraya42363f2015-12-17 14:57:09 +000086}
87
88} // namespace art