Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 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_file.h" |
| 18 | |
Mathieu Chartier | 48b2b3e | 2016-05-05 15:31:12 -0700 | [diff] [blame] | 19 | #include "art_method-inl.h" |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 20 | #include "jit/offline_profiling_info.h" |
| 21 | #include "jit/profile_saver.h" |
| 22 | #include "jni.h" |
| 23 | #include "method_reference.h" |
| 24 | #include "mirror/class-inl.h" |
| 25 | #include "oat_file_assistant.h" |
| 26 | #include "oat_file_manager.h" |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 27 | #include "scoped_thread_state_change-inl.h" |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 28 | #include "ScopedUtfChars.h" |
| 29 | #include "thread.h" |
| 30 | |
| 31 | namespace art { |
| 32 | namespace { |
| 33 | |
| 34 | class CreateProfilingInfoVisitor : public StackVisitor { |
| 35 | public: |
| 36 | explicit CreateProfilingInfoVisitor(Thread* thread, const char* method_name) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 37 | REQUIRES_SHARED(Locks::mutator_lock_) |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 38 | : StackVisitor(thread, nullptr, StackVisitor::StackWalkKind::kIncludeInlinedFrames), |
| 39 | method_name_(method_name) {} |
| 40 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 41 | bool VisitFrame() REQUIRES_SHARED(Locks::mutator_lock_) { |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 42 | ArtMethod* m = GetMethod(); |
| 43 | std::string m_name(m->GetName()); |
| 44 | |
| 45 | if (m_name.compare(method_name_) == 0) { |
| 46 | ProfilingInfo::Create(Thread::Current(), m, /* retry_allocation */ true); |
| 47 | method_index_ = m->GetDexMethodIndex(); |
| 48 | return false; |
| 49 | } |
| 50 | return true; |
| 51 | } |
| 52 | |
| 53 | int method_index_ = -1; |
| 54 | const char* const method_name_; |
| 55 | }; |
| 56 | |
| 57 | extern "C" JNIEXPORT jint JNICALL Java_Main_ensureProfilingInfo(JNIEnv* env, |
| 58 | jclass, |
| 59 | jstring method_name) { |
| 60 | ScopedUtfChars chars(env, method_name); |
| 61 | CHECK(chars.c_str() != nullptr); |
| 62 | ScopedObjectAccess soa(Thread::Current()); |
| 63 | CreateProfilingInfoVisitor visitor(soa.Self(), chars.c_str()); |
| 64 | visitor.WalkStack(); |
| 65 | return visitor.method_index_; |
| 66 | } |
| 67 | |
| 68 | extern "C" JNIEXPORT void JNICALL Java_Main_ensureProfileProcessing(JNIEnv*, jclass) { |
| 69 | ProfileSaver::ForceProcessProfiles(); |
| 70 | } |
| 71 | |
| 72 | extern "C" JNIEXPORT jboolean JNICALL Java_Main_presentInProfile( |
| 73 | JNIEnv* env, jclass cls, jstring filename, jint method_index) { |
| 74 | ScopedUtfChars filename_chars(env, filename); |
| 75 | CHECK(filename_chars.c_str() != nullptr); |
| 76 | ScopedObjectAccess soa(Thread::Current()); |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 77 | const DexFile* dex_file = soa.Decode<mirror::Class>(cls)->GetDexCache()->GetDexFile(); |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 78 | return ProfileSaver::HasSeenMethod(std::string(filename_chars.c_str()), |
| 79 | dex_file, |
| 80 | static_cast<uint16_t>(method_index)); |
| 81 | } |
| 82 | |
| 83 | } // namespace |
| 84 | } // namespace art |