1a42363f79832a6e14f348514664dc6dc3edf9da2Nicolas Geoffray/* 2a42363f79832a6e14f348514664dc6dc3edf9da2Nicolas Geoffray * Copyright (C) 2016 The Android Open Source Project 3a42363f79832a6e14f348514664dc6dc3edf9da2Nicolas Geoffray * 4a42363f79832a6e14f348514664dc6dc3edf9da2Nicolas Geoffray * Licensed under the Apache License, Version 2.0 (the "License"); 5a42363f79832a6e14f348514664dc6dc3edf9da2Nicolas Geoffray * you may not use this file except in compliance with the License. 6a42363f79832a6e14f348514664dc6dc3edf9da2Nicolas Geoffray * You may obtain a copy of the License at 7a42363f79832a6e14f348514664dc6dc3edf9da2Nicolas Geoffray * 8a42363f79832a6e14f348514664dc6dc3edf9da2Nicolas Geoffray * http://www.apache.org/licenses/LICENSE-2.0 9a42363f79832a6e14f348514664dc6dc3edf9da2Nicolas Geoffray * 10a42363f79832a6e14f348514664dc6dc3edf9da2Nicolas Geoffray * Unless required by applicable law or agreed to in writing, software 11a42363f79832a6e14f348514664dc6dc3edf9da2Nicolas Geoffray * distributed under the License is distributed on an "AS IS" BASIS, 12a42363f79832a6e14f348514664dc6dc3edf9da2Nicolas Geoffray * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13a42363f79832a6e14f348514664dc6dc3edf9da2Nicolas Geoffray * See the License for the specific language governing permissions and 14a42363f79832a6e14f348514664dc6dc3edf9da2Nicolas Geoffray * limitations under the License. 15a42363f79832a6e14f348514664dc6dc3edf9da2Nicolas Geoffray */ 16a42363f79832a6e14f348514664dc6dc3edf9da2Nicolas Geoffray 17a42363f79832a6e14f348514664dc6dc3edf9da2Nicolas Geoffray#include "art_method.h" 18a42363f79832a6e14f348514664dc6dc3edf9da2Nicolas Geoffray#include "jit/jit.h" 19a42363f79832a6e14f348514664dc6dc3edf9da2Nicolas Geoffray#include "jit/jit_code_cache.h" 20a42363f79832a6e14f348514664dc6dc3edf9da2Nicolas Geoffray#include "oat_quick_method_header.h" 21a42363f79832a6e14f348514664dc6dc3edf9da2Nicolas Geoffray#include "scoped_thread_state_change.h" 22a42363f79832a6e14f348514664dc6dc3edf9da2Nicolas Geoffray#include "stack_map.h" 23a42363f79832a6e14f348514664dc6dc3edf9da2Nicolas Geoffray 24a42363f79832a6e14f348514664dc6dc3edf9da2Nicolas Geoffraynamespace art { 25a42363f79832a6e14f348514664dc6dc3edf9da2Nicolas Geoffray 26a42363f79832a6e14f348514664dc6dc3edf9da2Nicolas Geoffraystatic void do_checks(jclass cls, const char* method_name) { 27a42363f79832a6e14f348514664dc6dc3edf9da2Nicolas Geoffray ScopedObjectAccess soa(Thread::Current()); 28a42363f79832a6e14f348514664dc6dc3edf9da2Nicolas Geoffray mirror::Class* klass = soa.Decode<mirror::Class*>(cls); 29a42363f79832a6e14f348514664dc6dc3edf9da2Nicolas Geoffray jit::Jit* jit = Runtime::Current()->GetJit(); 30a42363f79832a6e14f348514664dc6dc3edf9da2Nicolas Geoffray jit::JitCodeCache* code_cache = jit->GetCodeCache(); 31a42363f79832a6e14f348514664dc6dc3edf9da2Nicolas Geoffray ArtMethod* method = klass->FindDeclaredDirectMethodByName(method_name, sizeof(void*)); 32a60e220d9045409f8a626c6bac1050729b7ccf00Nicolas Geoffray 33c26f1288aaf9141ac4b2150869f0c594d52dbf36Nicolas Geoffray OatQuickMethodHeader* header = nullptr; 34c26f1288aaf9141ac4b2150869f0c594d52dbf36Nicolas Geoffray // Infinite loop... Test harness will have its own timeout. 35c26f1288aaf9141ac4b2150869f0c594d52dbf36Nicolas Geoffray while (true) { 36c26f1288aaf9141ac4b2150869f0c594d52dbf36Nicolas Geoffray header = OatQuickMethodHeader::FromEntryPoint(method->GetEntryPointFromQuickCompiledCode()); 37c26f1288aaf9141ac4b2150869f0c594d52dbf36Nicolas Geoffray if (code_cache->ContainsPc(header->GetCode())) { 38c26f1288aaf9141ac4b2150869f0c594d52dbf36Nicolas Geoffray break; 39c26f1288aaf9141ac4b2150869f0c594d52dbf36Nicolas Geoffray } else { 40c26f1288aaf9141ac4b2150869f0c594d52dbf36Nicolas Geoffray // sleep one second to give time to the JIT compiler. 41c26f1288aaf9141ac4b2150869f0c594d52dbf36Nicolas Geoffray sleep(1); 42c26f1288aaf9141ac4b2150869f0c594d52dbf36Nicolas Geoffray } 43c26f1288aaf9141ac4b2150869f0c594d52dbf36Nicolas Geoffray } 44a42363f79832a6e14f348514664dc6dc3edf9da2Nicolas Geoffray 45a42363f79832a6e14f348514664dc6dc3edf9da2Nicolas Geoffray CodeInfo info = header->GetOptimizedCodeInfo(); 4609ed09866da6d8c7448ef297c148bfa577a247c2David Srbecky CodeInfoEncoding encoding = info.ExtractEncoding(); 4709ed09866da6d8c7448ef297c148bfa577a247c2David Srbecky CHECK(info.HasInlineInfo(encoding)); 48a42363f79832a6e14f348514664dc6dc3edf9da2Nicolas Geoffray} 49a42363f79832a6e14f348514664dc6dc3edf9da2Nicolas Geoffray 50a42363f79832a6e14f348514664dc6dc3edf9da2Nicolas Geoffrayextern "C" JNIEXPORT void JNICALL Java_Main_ensureJittedAndPolymorphicInline(JNIEnv*, jclass cls) { 51a42363f79832a6e14f348514664dc6dc3edf9da2Nicolas Geoffray jit::Jit* jit = Runtime::Current()->GetJit(); 52a42363f79832a6e14f348514664dc6dc3edf9da2Nicolas Geoffray if (jit == nullptr) { 53a42363f79832a6e14f348514664dc6dc3edf9da2Nicolas Geoffray return; 54a42363f79832a6e14f348514664dc6dc3edf9da2Nicolas Geoffray } 55a42363f79832a6e14f348514664dc6dc3edf9da2Nicolas Geoffray 56c26f1288aaf9141ac4b2150869f0c594d52dbf36Nicolas Geoffray if (kIsDebugBuild) { 57c26f1288aaf9141ac4b2150869f0c594d52dbf36Nicolas Geoffray // A debug build might often compile the methods without profiling informations filled. 58c26f1288aaf9141ac4b2150869f0c594d52dbf36Nicolas Geoffray return; 59c26f1288aaf9141ac4b2150869f0c594d52dbf36Nicolas Geoffray } 60c26f1288aaf9141ac4b2150869f0c594d52dbf36Nicolas Geoffray 61a42363f79832a6e14f348514664dc6dc3edf9da2Nicolas Geoffray do_checks(cls, "testInvokeVirtual"); 62a42363f79832a6e14f348514664dc6dc3edf9da2Nicolas Geoffray do_checks(cls, "testInvokeInterface"); 63b3cd84a2fbd4875c605cfa5a4a362864b570f1e6Nicolas Geoffray do_checks(cls, "testInvokeInterface2"); 64366728f70c3bf3598cea3c37fa57c7c9428706faNicolas Geoffray do_checks(cls, "$noinline$testInlineToSameTarget"); 65a42363f79832a6e14f348514664dc6dc3edf9da2Nicolas Geoffray} 66a42363f79832a6e14f348514664dc6dc3edf9da2Nicolas Geoffray 67a42363f79832a6e14f348514664dc6dc3edf9da2Nicolas Geoffray} // namespace art 68