Calin Juravle | 27e17fd | 2015-11-25 15:59:14 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 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 | |
| 19 | #include "jit/offline_profiling_info.h" |
| 20 | #include "jni.h" |
| 21 | #include "mirror/class-inl.h" |
| 22 | #include "oat_file_assistant.h" |
| 23 | #include "oat_file_manager.h" |
| 24 | #include "scoped_thread_state_change.h" |
| 25 | #include "thread.h" |
| 26 | |
| 27 | namespace art { |
| 28 | namespace { |
| 29 | |
| 30 | extern "C" JNIEXPORT jstring JNICALL Java_Main_getProfileInfoDump( |
| 31 | JNIEnv* env, jclass, jstring filename, jclass cls_from_primary, jclass cls_from_secondary) { |
| 32 | // Note: |
| 33 | // Ideally we would get the dex list from the primary oat file. |
| 34 | // e.g. |
| 35 | // oat_file = Runtime::Current()->GetOatFileManager().GetPrimaryOatFile(); |
| 36 | // dex_files = OatFileAssistant::LoadDexFiles(*oat_file, dex_location.c_str()); |
| 37 | // However the ownership of the pointers is complicated since the primary file |
| 38 | // already exists and the test crashed sporadically because some data changes under |
| 39 | // our feet. |
| 40 | // To simplify things get the dex files from the classes passed as arguments. |
| 41 | const DexFile* dex_primary; |
| 42 | const DexFile* dex_secondary; |
| 43 | { |
| 44 | ScopedObjectAccess soa(Thread::Current()); |
| 45 | dex_primary = soa.Decode<mirror::Class*>(cls_from_primary)->GetDexCache()->GetDexFile(); |
| 46 | dex_secondary = soa.Decode<mirror::Class*>(cls_from_secondary)->GetDexCache()->GetDexFile(); |
| 47 | } |
| 48 | |
| 49 | std::vector<const DexFile*> dex_files; |
| 50 | dex_files.push_back(dex_primary); |
| 51 | dex_files.push_back(dex_secondary); |
| 52 | |
| 53 | const char* filename_chars = env->GetStringUTFChars(filename, nullptr); |
| 54 | ProfileCompilationInfo info(filename_chars); |
| 55 | const char* result = info.Load(dex_files) |
| 56 | ? info.DumpInfo(/*print_full_dex_location*/false).c_str() |
| 57 | : nullptr; |
| 58 | env->ReleaseStringUTFChars(filename, filename_chars); |
| 59 | return env->NewStringUTF(result); |
| 60 | } |
| 61 | |
| 62 | } // namespace |
| 63 | } // namespace art |