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 "dex/dex_file.h" 18 19 #include "art_method-inl.h" 20 #include "dex/method_reference.h" 21 #include "jit/profile_compilation_info.h" 22 #include "jit/profile_saver.h" 23 #include "jni.h" 24 #include "mirror/class-inl.h" 25 #include "mirror/executable.h" 26 #include "nativehelper/ScopedUtfChars.h" 27 #include "oat_file_assistant.h" 28 #include "oat_file_manager.h" 29 #include "scoped_thread_state_change-inl.h" 30 #include "thread.h" 31 32 namespace art { 33 namespace { 34 35 extern "C" JNIEXPORT void JNICALL Java_Main_ensureProfilingInfo(JNIEnv* env, 36 jclass, 37 jobject method) { 38 CHECK(method != nullptr); 39 ScopedObjectAccess soa(env); 40 ObjPtr<mirror::Executable> exec = soa.Decode<mirror::Executable>(method); 41 ArtMethod* art_method = exec->GetArtMethod(); 42 if (!ProfilingInfo::Create(soa.Self(), art_method, /* retry_allocation */ true)) { 43 LOG(ERROR) << "Failed to create profiling info for method " << art_method->PrettyMethod(); 44 } 45 } 46 47 extern "C" JNIEXPORT void JNICALL Java_Main_ensureProfileProcessing(JNIEnv*, jclass) { 48 ProfileSaver::ForceProcessProfiles(); 49 } 50 51 extern "C" JNIEXPORT jboolean JNICALL Java_Main_presentInProfile(JNIEnv* env, 52 jclass, 53 jstring filename, 54 jobject method) { 55 ScopedUtfChars filename_chars(env, filename); 56 CHECK(filename_chars.c_str() != nullptr); 57 ScopedObjectAccess soa(env); 58 ObjPtr<mirror::Executable> exec = soa.Decode<mirror::Executable>(method); 59 ArtMethod* art_method = exec->GetArtMethod(); 60 return ProfileSaver::HasSeenMethod(std::string(filename_chars.c_str()), 61 /*hot*/ true, 62 MethodReference(art_method->GetDexFile(), 63 art_method->GetDexMethodIndex())); 64 } 65 66 } // namespace 67 } // namespace art 68