| Brian Carlstrom | f91c8c3 | 2011-09-21 17:30:34 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 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 | |
| Andreas Gampe | 277ccbd | 2014-11-03 21:36:10 -0800 | [diff] [blame] | 17 | #include "dalvik_system_DexFile.h" |
| 18 | |
| Narayan Kamath | 8943c1d | 2016-05-02 13:14:48 +0100 | [diff] [blame] | 19 | #include <sstream> |
| 20 | |
| Andreas Gampe | 46ee31b | 2016-12-14 10:11:49 -0800 | [diff] [blame] | 21 | #include "android-base/stringprintf.h" |
| 22 | |
| Vladimir Marko | 78baed5 | 2018-10-11 10:44:58 +0100 | [diff] [blame] | 23 | #include "base/casts.h" |
| David Sehr | 891a50e | 2017-10-27 17:01:07 -0700 | [diff] [blame] | 24 | #include "base/file_utils.h" |
| Elliott Hughes | 07ed66b | 2012-12-12 18:34:25 -0800 | [diff] [blame] | 25 | #include "base/logging.h" |
| David Sehr | c431b9d | 2018-03-02 12:01:51 -0800 | [diff] [blame] | 26 | #include "base/os.h" |
| Andreas Gampe | 833a485 | 2014-05-21 18:46:59 -0700 | [diff] [blame] | 27 | #include "base/stl_util.h" |
| David Sehr | c431b9d | 2018-03-02 12:01:51 -0800 | [diff] [blame] | 28 | #include "base/utils.h" |
| David Sehr | 79e2607 | 2018-04-06 17:58:50 -0700 | [diff] [blame] | 29 | #include "base/zip_archive.h" |
| Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 30 | #include "class_linker.h" |
| David Brazdil | 7458291 | 2019-03-01 11:18:19 +0000 | [diff] [blame^] | 31 | #include "class_loader_context.h" |
| Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 32 | #include "common_throws.h" |
| Andreas Gampe | c38be81 | 2016-03-23 15:03:46 -0700 | [diff] [blame] | 33 | #include "compiler_filter.h" |
| David Sehr | 013fd80 | 2018-01-11 22:55:24 -0800 | [diff] [blame] | 34 | #include "dex/art_dex_file_loader.h" |
| David Sehr | b2ec9f5 | 2018-02-21 13:20:31 -0800 | [diff] [blame] | 35 | #include "dex/descriptors_names.h" |
| David Sehr | 9e734c7 | 2018-01-04 17:56:19 -0800 | [diff] [blame] | 36 | #include "dex/dex_file-inl.h" |
| 37 | #include "dex/dex_file_loader.h" |
| Andreas Gampe | 88dbad3 | 2018-06-26 19:54:12 -0700 | [diff] [blame] | 38 | #include "handle_scope-inl.h" |
| David Srbecky | fb3de3d | 2018-01-29 16:11:49 +0000 | [diff] [blame] | 39 | #include "jit/debugger_interface.h" |
| Vladimir Marko | a3ad0cd | 2018-05-04 10:06:38 +0100 | [diff] [blame] | 40 | #include "jni/jni_internal.h" |
| Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 41 | #include "mirror/class_loader.h" |
| Ian Rogers | 05f3057 | 2013-02-20 12:13:11 -0800 | [diff] [blame] | 42 | #include "mirror/object-inl.h" |
| Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 43 | #include "mirror/string.h" |
| Andreas Gampe | 87583b3 | 2017-05-25 11:22:18 -0700 | [diff] [blame] | 44 | #include "native_util.h" |
| Steven Moreland | e431e27 | 2017-07-18 16:53:49 -0700 | [diff] [blame] | 45 | #include "nativehelper/jni_macros.h" |
| Andreas Gampe | 373a9b5 | 2017-10-18 09:01:57 -0700 | [diff] [blame] | 46 | #include "nativehelper/scoped_local_ref.h" |
| 47 | #include "nativehelper/scoped_utf_chars.h" |
| Narayan Kamath | 8943c1d | 2016-05-02 13:14:48 +0100 | [diff] [blame] | 48 | #include "oat_file.h" |
| Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 49 | #include "oat_file_assistant.h" |
| Mathieu Chartier | f9c6fc6 | 2015-10-07 11:44:05 -0700 | [diff] [blame] | 50 | #include "oat_file_manager.h" |
| Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 51 | #include "runtime.h" |
| Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 52 | #include "scoped_thread_state_change-inl.h" |
| Ian Rogers | dd157d7 | 2014-05-15 14:47:50 -0700 | [diff] [blame] | 53 | #include "well_known_classes.h" |
| Brian Carlstrom | f91c8c3 | 2011-09-21 17:30:34 -0700 | [diff] [blame] | 54 | |
| 55 | namespace art { |
| 56 | |
| Andreas Gampe | 46ee31b | 2016-12-14 10:11:49 -0800 | [diff] [blame] | 57 | using android::base::StringPrintf; |
| 58 | |
| Mathieu Chartier | e58991b | 2015-10-13 07:59:34 -0700 | [diff] [blame] | 59 | static bool ConvertJavaArrayToDexFiles( |
| 60 | JNIEnv* env, |
| 61 | jobject arrayObject, |
| 62 | /*out*/ std::vector<const DexFile*>& dex_files, |
| 63 | /*out*/ const OatFile*& oat_file) { |
| Andreas Gampe | 324b9bb | 2015-02-23 16:33:22 -0800 | [diff] [blame] | 64 | jarray array = reinterpret_cast<jarray>(arrayObject); |
| 65 | |
| 66 | jsize array_size = env->GetArrayLength(array); |
| 67 | if (env->ExceptionCheck() == JNI_TRUE) { |
| Mathieu Chartier | e58991b | 2015-10-13 07:59:34 -0700 | [diff] [blame] | 68 | return false; |
| Andreas Gampe | 324b9bb | 2015-02-23 16:33:22 -0800 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | // TODO: Optimize. On 32bit we can use an int array. |
| 72 | jboolean is_long_data_copied; |
| 73 | jlong* long_data = env->GetLongArrayElements(reinterpret_cast<jlongArray>(array), |
| 74 | &is_long_data_copied); |
| 75 | if (env->ExceptionCheck() == JNI_TRUE) { |
| Mathieu Chartier | e58991b | 2015-10-13 07:59:34 -0700 | [diff] [blame] | 76 | return false; |
| Andreas Gampe | 324b9bb | 2015-02-23 16:33:22 -0800 | [diff] [blame] | 77 | } |
| 78 | |
| Vladimir Marko | 78baed5 | 2018-10-11 10:44:58 +0100 | [diff] [blame] | 79 | oat_file = reinterpret_cast64<const OatFile*>(long_data[kOatFileIndex]); |
| Mathieu Chartier | e58991b | 2015-10-13 07:59:34 -0700 | [diff] [blame] | 80 | dex_files.reserve(array_size - 1); |
| 81 | for (jsize i = kDexFileIndexStart; i < array_size; ++i) { |
| Vladimir Marko | 78baed5 | 2018-10-11 10:44:58 +0100 | [diff] [blame] | 82 | dex_files.push_back(reinterpret_cast64<const DexFile*>(long_data[i])); |
| Andreas Gampe | 324b9bb | 2015-02-23 16:33:22 -0800 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | env->ReleaseLongArrayElements(reinterpret_cast<jlongArray>(array), long_data, JNI_ABORT); |
| Mathieu Chartier | e58991b | 2015-10-13 07:59:34 -0700 | [diff] [blame] | 86 | return env->ExceptionCheck() != JNI_TRUE; |
| Andreas Gampe | 324b9bb | 2015-02-23 16:33:22 -0800 | [diff] [blame] | 87 | } |
| 88 | |
| Mathieu Chartier | e58991b | 2015-10-13 07:59:34 -0700 | [diff] [blame] | 89 | static jlongArray ConvertDexFilesToJavaArray(JNIEnv* env, |
| 90 | const OatFile* oat_file, |
| 91 | std::vector<std::unique_ptr<const DexFile>>& vec) { |
| 92 | // Add one for the oat file. |
| Mathieu Chartier | 80b37b7 | 2015-10-12 18:13:39 -0700 | [diff] [blame] | 93 | jlongArray long_array = env->NewLongArray(static_cast<jsize>(kDexFileIndexStart + vec.size())); |
| Andreas Gampe | 324b9bb | 2015-02-23 16:33:22 -0800 | [diff] [blame] | 94 | if (env->ExceptionCheck() == JNI_TRUE) { |
| 95 | return nullptr; |
| 96 | } |
| 97 | |
| 98 | jboolean is_long_data_copied; |
| 99 | jlong* long_data = env->GetLongArrayElements(long_array, &is_long_data_copied); |
| 100 | if (env->ExceptionCheck() == JNI_TRUE) { |
| 101 | return nullptr; |
| 102 | } |
| 103 | |
| Vladimir Marko | 78baed5 | 2018-10-11 10:44:58 +0100 | [diff] [blame] | 104 | long_data[kOatFileIndex] = reinterpret_cast64<jlong>(oat_file); |
| Mathieu Chartier | e58991b | 2015-10-13 07:59:34 -0700 | [diff] [blame] | 105 | for (size_t i = 0; i < vec.size(); ++i) { |
| Vladimir Marko | 78baed5 | 2018-10-11 10:44:58 +0100 | [diff] [blame] | 106 | long_data[kDexFileIndexStart + i] = reinterpret_cast64<jlong>(vec[i].get()); |
| Andreas Gampe | 324b9bb | 2015-02-23 16:33:22 -0800 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | env->ReleaseLongArrayElements(long_array, long_data, 0); |
| 110 | if (env->ExceptionCheck() == JNI_TRUE) { |
| 111 | return nullptr; |
| 112 | } |
| 113 | |
| 114 | // Now release all the unique_ptrs. |
| 115 | for (auto& dex_file : vec) { |
| Andreas Gampe | afaf7f8 | 2018-10-16 11:32:38 -0700 | [diff] [blame] | 116 | dex_file.release(); // NOLINT |
| Andreas Gampe | 324b9bb | 2015-02-23 16:33:22 -0800 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | return long_array; |
| 120 | } |
| 121 | |
| Brian Carlstrom | f91c8c3 | 2011-09-21 17:30:34 -0700 | [diff] [blame] | 122 | // A smart pointer that provides read-only access to a Java string's UTF chars. |
| 123 | // Unlike libcore's NullableScopedUtfChars, this will *not* throw NullPointerException if |
| 124 | // passed a null jstring. The correct idiom is: |
| 125 | // |
| 126 | // NullableScopedUtfChars name(env, javaName); |
| Brian Carlstrom | c252c3e | 2011-10-16 23:21:02 -0700 | [diff] [blame] | 127 | // if (env->ExceptionCheck()) { |
| Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 128 | // return null; |
| Brian Carlstrom | f91c8c3 | 2011-09-21 17:30:34 -0700 | [diff] [blame] | 129 | // } |
| 130 | // // ... use name.c_str() |
| 131 | // |
| 132 | // TODO: rewrite to get rid of this, or change ScopedUtfChars to offer this option. |
| 133 | class NullableScopedUtfChars { |
| Elliott Hughes | ba8eee1 | 2012-01-24 20:25:24 -0800 | [diff] [blame] | 134 | public: |
| 135 | NullableScopedUtfChars(JNIEnv* env, jstring s) : mEnv(env), mString(s) { |
| Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 136 | mUtfChars = (s != nullptr) ? env->GetStringUTFChars(s, nullptr) : nullptr; |
| Elliott Hughes | ba8eee1 | 2012-01-24 20:25:24 -0800 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | ~NullableScopedUtfChars() { |
| 140 | if (mUtfChars) { |
| 141 | mEnv->ReleaseStringUTFChars(mString, mUtfChars); |
| Brian Carlstrom | f91c8c3 | 2011-09-21 17:30:34 -0700 | [diff] [blame] | 142 | } |
| Elliott Hughes | ba8eee1 | 2012-01-24 20:25:24 -0800 | [diff] [blame] | 143 | } |
| Brian Carlstrom | f91c8c3 | 2011-09-21 17:30:34 -0700 | [diff] [blame] | 144 | |
| Elliott Hughes | ba8eee1 | 2012-01-24 20:25:24 -0800 | [diff] [blame] | 145 | const char* c_str() const { |
| 146 | return mUtfChars; |
| 147 | } |
| Brian Carlstrom | f91c8c3 | 2011-09-21 17:30:34 -0700 | [diff] [blame] | 148 | |
| Elliott Hughes | ba8eee1 | 2012-01-24 20:25:24 -0800 | [diff] [blame] | 149 | size_t size() const { |
| 150 | return strlen(mUtfChars); |
| 151 | } |
| Brian Carlstrom | f91c8c3 | 2011-09-21 17:30:34 -0700 | [diff] [blame] | 152 | |
| Elliott Hughes | ba8eee1 | 2012-01-24 20:25:24 -0800 | [diff] [blame] | 153 | // Element access. |
| 154 | const char& operator[](size_t n) const { |
| 155 | return mUtfChars[n]; |
| 156 | } |
| Brian Carlstrom | f91c8c3 | 2011-09-21 17:30:34 -0700 | [diff] [blame] | 157 | |
| Elliott Hughes | ba8eee1 | 2012-01-24 20:25:24 -0800 | [diff] [blame] | 158 | private: |
| 159 | JNIEnv* mEnv; |
| 160 | jstring mString; |
| 161 | const char* mUtfChars; |
| Brian Carlstrom | f91c8c3 | 2011-09-21 17:30:34 -0700 | [diff] [blame] | 162 | |
| Elliott Hughes | ba8eee1 | 2012-01-24 20:25:24 -0800 | [diff] [blame] | 163 | // Disallow copy and assignment. |
| 164 | NullableScopedUtfChars(const NullableScopedUtfChars&); |
| 165 | void operator=(const NullableScopedUtfChars&); |
| Brian Carlstrom | f91c8c3 | 2011-09-21 17:30:34 -0700 | [diff] [blame] | 166 | }; |
| 167 | |
| Vladimir Marko | c34bebf | 2018-08-16 16:12:49 +0100 | [diff] [blame] | 168 | static MemMap AllocateDexMemoryMap(JNIEnv* env, jint start, jint end) { |
| Alex Light | ea9465e | 2017-02-16 15:38:35 -0800 | [diff] [blame] | 169 | if (end <= start) { |
| 170 | ScopedObjectAccess soa(env); |
| 171 | ThrowWrappedIOException("Bad range"); |
| Vladimir Marko | c34bebf | 2018-08-16 16:12:49 +0100 | [diff] [blame] | 172 | return MemMap::Invalid(); |
| Alex Light | ea9465e | 2017-02-16 15:38:35 -0800 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | std::string error_message; |
| 176 | size_t length = static_cast<size_t>(end - start); |
| Vladimir Marko | c34bebf | 2018-08-16 16:12:49 +0100 | [diff] [blame] | 177 | MemMap dex_mem_map = MemMap::MapAnonymous("DEX data", |
| Vladimir Marko | c34bebf | 2018-08-16 16:12:49 +0100 | [diff] [blame] | 178 | length, |
| 179 | PROT_READ | PROT_WRITE, |
| Vladimir Marko | 1130659 | 2018-10-26 14:22:59 +0100 | [diff] [blame] | 180 | /*low_4gb=*/ false, |
| Vladimir Marko | c34bebf | 2018-08-16 16:12:49 +0100 | [diff] [blame] | 181 | &error_message); |
| 182 | if (!dex_mem_map.IsValid()) { |
| Alex Light | ea9465e | 2017-02-16 15:38:35 -0800 | [diff] [blame] | 183 | ScopedObjectAccess soa(env); |
| 184 | ThrowWrappedIOException("%s", error_message.c_str()); |
| Vladimir Marko | c34bebf | 2018-08-16 16:12:49 +0100 | [diff] [blame] | 185 | return MemMap::Invalid(); |
| Alex Light | ea9465e | 2017-02-16 15:38:35 -0800 | [diff] [blame] | 186 | } |
| 187 | return dex_mem_map; |
| 188 | } |
| 189 | |
| Vladimir Marko | c34bebf | 2018-08-16 16:12:49 +0100 | [diff] [blame] | 190 | static const DexFile* CreateDexFile(JNIEnv* env, MemMap&& dex_mem_map) { |
| Alex Light | ea9465e | 2017-02-16 15:38:35 -0800 | [diff] [blame] | 191 | std::string location = StringPrintf("Anonymous-DexFile@%p-%p", |
| Vladimir Marko | c34bebf | 2018-08-16 16:12:49 +0100 | [diff] [blame] | 192 | dex_mem_map.Begin(), |
| 193 | dex_mem_map.End()); |
| Alex Light | ea9465e | 2017-02-16 15:38:35 -0800 | [diff] [blame] | 194 | std::string error_message; |
| David Sehr | 013fd80 | 2018-01-11 22:55:24 -0800 | [diff] [blame] | 195 | const ArtDexFileLoader dex_file_loader; |
| 196 | std::unique_ptr<const DexFile> dex_file(dex_file_loader.Open(location, |
| 197 | 0, |
| 198 | std::move(dex_mem_map), |
| Andreas Gampe | 98ea9d9 | 2018-10-19 14:06:15 -0700 | [diff] [blame] | 199 | /* verify= */ true, |
| 200 | /* verify_checksum= */ true, |
| David Sehr | 013fd80 | 2018-01-11 22:55:24 -0800 | [diff] [blame] | 201 | &error_message)); |
| Alex Light | ea9465e | 2017-02-16 15:38:35 -0800 | [diff] [blame] | 202 | if (dex_file == nullptr) { |
| 203 | ScopedObjectAccess soa(env); |
| 204 | ThrowWrappedIOException("%s", error_message.c_str()); |
| 205 | return nullptr; |
| 206 | } |
| 207 | |
| 208 | if (!dex_file->DisableWrite()) { |
| 209 | ScopedObjectAccess soa(env); |
| 210 | ThrowWrappedIOException("Failed to make dex file read-only"); |
| 211 | return nullptr; |
| 212 | } |
| 213 | |
| 214 | return dex_file.release(); |
| 215 | } |
| 216 | |
| David Brazdil | 7458291 | 2019-03-01 11:18:19 +0000 | [diff] [blame^] | 217 | struct ScopedIntArrayAccessor { |
| 218 | public: |
| 219 | ScopedIntArrayAccessor(JNIEnv* env, jintArray arr) : env_(env), array_(arr) { |
| 220 | elements_ = env_->GetIntArrayElements(array_, /* isCopy= */ nullptr); |
| 221 | CHECK(elements_ != nullptr); |
| Alex Light | ea9465e | 2017-02-16 15:38:35 -0800 | [diff] [blame] | 222 | } |
| David Brazdil | 7458291 | 2019-03-01 11:18:19 +0000 | [diff] [blame^] | 223 | |
| 224 | ~ScopedIntArrayAccessor() { |
| 225 | env_->ReleaseIntArrayElements(array_, elements_, JNI_ABORT); |
| 226 | } |
| 227 | |
| 228 | jint Get(jsize index) const { return elements_[index]; } |
| 229 | |
| 230 | private: |
| 231 | JNIEnv* env_; |
| 232 | jintArray array_; |
| 233 | jint* elements_; |
| 234 | }; |
| 235 | |
| 236 | static jobject DexFile_openInMemoryDexFilesNative(JNIEnv* env, |
| 237 | jclass, |
| 238 | jobjectArray buffers, |
| 239 | jobjectArray arrays, |
| 240 | jintArray jstarts, |
| 241 | jintArray jends) { |
| 242 | jsize buffers_length = env->GetArrayLength(buffers); |
| 243 | CHECK_EQ(buffers_length, env->GetArrayLength(arrays)); |
| 244 | CHECK_EQ(buffers_length, env->GetArrayLength(jstarts)); |
| 245 | CHECK_EQ(buffers_length, env->GetArrayLength(jends)); |
| 246 | |
| 247 | ScopedIntArrayAccessor starts(env, jstarts); |
| 248 | ScopedIntArrayAccessor ends(env, jends); |
| 249 | |
| 250 | // Allocate memory for dex files and copy data from ByteBuffers. |
| Alex Light | ea9465e | 2017-02-16 15:38:35 -0800 | [diff] [blame] | 251 | std::vector<std::unique_ptr<const DexFile>> dex_files; |
| David Brazdil | 7458291 | 2019-03-01 11:18:19 +0000 | [diff] [blame^] | 252 | dex_files.reserve(buffers_length); |
| 253 | for (jsize i = 0; i < buffers_length; ++i) { |
| 254 | jobject buffer = env->GetObjectArrayElement(buffers, i); |
| 255 | jbyteArray array = reinterpret_cast<jbyteArray>(env->GetObjectArrayElement(arrays, i)); |
| 256 | jint start = starts.Get(i); |
| 257 | jint end = ends.Get(i); |
| Alex Light | ea9465e | 2017-02-16 15:38:35 -0800 | [diff] [blame] | 258 | |
| David Brazdil | 7458291 | 2019-03-01 11:18:19 +0000 | [diff] [blame^] | 259 | MemMap dex_data = AllocateDexMemoryMap(env, start, end); |
| 260 | if (!dex_data.IsValid()) { |
| 261 | DCHECK(Thread::Current()->IsExceptionPending()); |
| 262 | return nullptr; |
| 263 | } |
| 264 | |
| 265 | if (array == nullptr) { |
| 266 | // Direct ByteBuffer |
| 267 | uint8_t* base_address = reinterpret_cast<uint8_t*>(env->GetDirectBufferAddress(buffer)); |
| 268 | if (base_address == nullptr) { |
| 269 | ScopedObjectAccess soa(env); |
| 270 | ThrowWrappedIOException("dexFileBuffer not direct"); |
| 271 | return nullptr; |
| 272 | } |
| 273 | size_t length = static_cast<size_t>(end - start); |
| 274 | memcpy(dex_data.Begin(), base_address + start, length); |
| 275 | } else { |
| 276 | // ByteBuffer backed by a byte array |
| 277 | jbyte* destination = reinterpret_cast<jbyte*>(dex_data.Begin()); |
| 278 | env->GetByteArrayRegion(array, start, end - start, destination); |
| 279 | } |
| 280 | |
| 281 | std::unique_ptr<const DexFile> dex_file(CreateDexFile(env, std::move(dex_data))); |
| 282 | if (dex_file == nullptr) { |
| 283 | DCHECK(env->ExceptionCheck()); |
| 284 | return nullptr; |
| 285 | } |
| 286 | dex_files.push_back(std::move(dex_file)); |
| Alex Light | ea9465e | 2017-02-16 15:38:35 -0800 | [diff] [blame] | 287 | } |
| 288 | |
| David Brazdil | 7458291 | 2019-03-01 11:18:19 +0000 | [diff] [blame^] | 289 | return ConvertDexFilesToJavaArray(env, /* oat_file= */ nullptr, dex_files); |
| Alex Light | ea9465e | 2017-02-16 15:38:35 -0800 | [diff] [blame] | 290 | } |
| 291 | |
| Calin Juravle | 1f7079b | 2017-04-18 21:25:37 -0700 | [diff] [blame] | 292 | // TODO(calin): clean up the unused parameters (here and in libcore). |
| Mathieu Chartier | b190d94 | 2015-11-12 10:00:58 -0800 | [diff] [blame] | 293 | static jobject DexFile_openDexFileNative(JNIEnv* env, |
| 294 | jclass, |
| 295 | jstring javaSourceName, |
| Calin Juravle | 1f7079b | 2017-04-18 21:25:37 -0700 | [diff] [blame] | 296 | jstring javaOutputName ATTRIBUTE_UNUSED, |
| Mathieu Chartier | b190d94 | 2015-11-12 10:00:58 -0800 | [diff] [blame] | 297 | jint flags ATTRIBUTE_UNUSED, |
| Mathieu Chartier | fbc3108 | 2016-01-24 11:59:56 -0800 | [diff] [blame] | 298 | jobject class_loader, |
| 299 | jobjectArray dex_elements) { |
| Brian Carlstrom | f91c8c3 | 2011-09-21 17:30:34 -0700 | [diff] [blame] | 300 | ScopedUtfChars sourceName(env, javaSourceName); |
| Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 301 | if (sourceName.c_str() == nullptr) { |
| Yi Kong | 4b22b34 | 2018-08-02 14:43:21 -0700 | [diff] [blame] | 302 | return nullptr; |
| Brian Carlstrom | f91c8c3 | 2011-09-21 17:30:34 -0700 | [diff] [blame] | 303 | } |
| Calin Juravle | 1f7079b | 2017-04-18 21:25:37 -0700 | [diff] [blame] | 304 | |
| Mathieu Chartier | f9c6fc6 | 2015-10-07 11:44:05 -0700 | [diff] [blame] | 305 | Runtime* const runtime = Runtime::Current(); |
| 306 | ClassLinker* linker = runtime->GetClassLinker(); |
| Andreas Gampe | 324b9bb | 2015-02-23 16:33:22 -0800 | [diff] [blame] | 307 | std::vector<std::unique_ptr<const DexFile>> dex_files; |
| Andreas Gampe | 833a485 | 2014-05-21 18:46:59 -0700 | [diff] [blame] | 308 | std::vector<std::string> error_msgs; |
| Mathieu Chartier | e58991b | 2015-10-13 07:59:34 -0700 | [diff] [blame] | 309 | const OatFile* oat_file = nullptr; |
| Andreas Gampe | 833a485 | 2014-05-21 18:46:59 -0700 | [diff] [blame] | 310 | |
| Mathieu Chartier | f9c6fc6 | 2015-10-07 11:44:05 -0700 | [diff] [blame] | 311 | dex_files = runtime->GetOatFileManager().OpenDexFilesFromOat(sourceName.c_str(), |
| Mathieu Chartier | fbc3108 | 2016-01-24 11:59:56 -0800 | [diff] [blame] | 312 | class_loader, |
| 313 | dex_elements, |
| Mathieu Chartier | e58991b | 2015-10-13 07:59:34 -0700 | [diff] [blame] | 314 | /*out*/ &oat_file, |
| 315 | /*out*/ &error_msgs); |
| Andreas Gampe | 833a485 | 2014-05-21 18:46:59 -0700 | [diff] [blame] | 316 | |
| Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 317 | if (!dex_files.empty()) { |
| Mathieu Chartier | e58991b | 2015-10-13 07:59:34 -0700 | [diff] [blame] | 318 | jlongArray array = ConvertDexFilesToJavaArray(env, oat_file, dex_files); |
| Andreas Gampe | 324b9bb | 2015-02-23 16:33:22 -0800 | [diff] [blame] | 319 | if (array == nullptr) { |
| 320 | ScopedObjectAccess soa(env); |
| 321 | for (auto& dex_file : dex_files) { |
| Vladimir Marko | cd556b0 | 2017-02-03 11:47:34 +0000 | [diff] [blame] | 322 | if (linker->IsDexFileRegistered(soa.Self(), *dex_file)) { |
| Andreas Gampe | afaf7f8 | 2018-10-16 11:32:38 -0700 | [diff] [blame] | 323 | dex_file.release(); // NOLINT |
| Andreas Gampe | 324b9bb | 2015-02-23 16:33:22 -0800 | [diff] [blame] | 324 | } |
| 325 | } |
| 326 | } |
| 327 | return array; |
| Brian Carlstrom | 756ee4e | 2013-10-03 15:46:12 -0700 | [diff] [blame] | 328 | } else { |
| Vladimir Marko | 60836d5 | 2014-01-16 15:53:38 +0000 | [diff] [blame] | 329 | ScopedObjectAccess soa(env); |
| Andreas Gampe | 329d188 | 2014-04-08 10:32:19 -0700 | [diff] [blame] | 330 | CHECK(!error_msgs.empty()); |
| 331 | // The most important message is at the end. So set up nesting by going forward, which will |
| 332 | // wrap the existing exception as a cause for the following one. |
| 333 | auto it = error_msgs.begin(); |
| 334 | auto itEnd = error_msgs.end(); |
| 335 | for ( ; it != itEnd; ++it) { |
| 336 | ThrowWrappedIOException("%s", it->c_str()); |
| 337 | } |
| 338 | |
| Andreas Gampe | 324b9bb | 2015-02-23 16:33:22 -0800 | [diff] [blame] | 339 | return nullptr; |
| Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 340 | } |
| Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 341 | } |
| 342 | |
| Mathieu Chartier | 1d7d7f1 | 2015-09-25 16:48:57 -0700 | [diff] [blame] | 343 | static jboolean DexFile_closeDexFile(JNIEnv* env, jclass, jobject cookie) { |
| Mathieu Chartier | e58991b | 2015-10-13 07:59:34 -0700 | [diff] [blame] | 344 | std::vector<const DexFile*> dex_files; |
| 345 | const OatFile* oat_file; |
| 346 | if (!ConvertJavaArrayToDexFiles(env, cookie, dex_files, oat_file)) { |
| 347 | Thread::Current()->AssertPendingException(); |
| Mathieu Chartier | 1d7d7f1 | 2015-09-25 16:48:57 -0700 | [diff] [blame] | 348 | return JNI_FALSE; |
| 349 | } |
| Mathieu Chartier | e58991b | 2015-10-13 07:59:34 -0700 | [diff] [blame] | 350 | Runtime* const runtime = Runtime::Current(); |
| Mathieu Chartier | 1d7d7f1 | 2015-09-25 16:48:57 -0700 | [diff] [blame] | 351 | bool all_deleted = true; |
| David Srbecky | 912f36c | 2018-09-08 12:22:58 +0100 | [diff] [blame] | 352 | // We need to clear the caches since they may contain pointers to the dex instructions. |
| 353 | // Different dex file can be loaded at the same memory location later by chance. |
| 354 | Thread::ClearAllInterpreterCaches(); |
| Mathieu Chartier | e58991b | 2015-10-13 07:59:34 -0700 | [diff] [blame] | 355 | { |
| 356 | ScopedObjectAccess soa(env); |
| Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 357 | ObjPtr<mirror::Object> dex_files_object = soa.Decode<mirror::Object>(cookie); |
| Mathieu Chartier | bc5a795 | 2016-10-17 15:46:31 -0700 | [diff] [blame] | 358 | ObjPtr<mirror::LongArray> long_dex_files = dex_files_object->AsLongArray(); |
| Mathieu Chartier | e58991b | 2015-10-13 07:59:34 -0700 | [diff] [blame] | 359 | // Delete dex files associated with this dalvik.system.DexFile since there should not be running |
| 360 | // code using it. dex_files is a vector due to multidex. |
| 361 | ClassLinker* const class_linker = runtime->GetClassLinker(); |
| 362 | int32_t i = kDexFileIndexStart; // Oat file is at index 0. |
| 363 | for (const DexFile* dex_file : dex_files) { |
| 364 | if (dex_file != nullptr) { |
| David Srbecky | afc60cd | 2018-12-05 11:59:31 +0000 | [diff] [blame] | 365 | RemoveNativeDebugInfoForDex(soa.Self(), dex_file); |
| David Brazdil | 7458291 | 2019-03-01 11:18:19 +0000 | [diff] [blame^] | 366 | // Only delete the dex file if the dex cache is not found to prevent runtime crashes |
| 367 | // if there are calls to DexFile.close while the ART DexFile is still in use. |
| Vladimir Marko | cd556b0 | 2017-02-03 11:47:34 +0000 | [diff] [blame] | 368 | if (!class_linker->IsDexFileRegistered(soa.Self(), *dex_file)) { |
| Mathieu Chartier | e58991b | 2015-10-13 07:59:34 -0700 | [diff] [blame] | 369 | // Clear the element in the array so that we can call close again. |
| 370 | long_dex_files->Set(i, 0); |
| 371 | delete dex_file; |
| 372 | } else { |
| 373 | all_deleted = false; |
| 374 | } |
| 375 | } |
| 376 | ++i; |
| Andreas Gampe | 833a485 | 2014-05-21 18:46:59 -0700 | [diff] [blame] | 377 | } |
| Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 378 | } |
| Mathieu Chartier | 1d7d7f1 | 2015-09-25 16:48:57 -0700 | [diff] [blame] | 379 | |
| Mathieu Chartier | fdccbd4 | 2015-10-14 10:58:41 -0700 | [diff] [blame] | 380 | // oat_file can be null if we are running without dex2oat. |
| 381 | if (all_deleted && oat_file != nullptr) { |
| Mathieu Chartier | e58991b | 2015-10-13 07:59:34 -0700 | [diff] [blame] | 382 | // If all of the dex files are no longer in use we can unmap the corresponding oat file. |
| 383 | VLOG(class_linker) << "Unregistering " << oat_file; |
| 384 | runtime->GetOatFileManager().UnRegisterAndDeleteOatFile(oat_file); |
| 385 | } |
| Mathieu Chartier | 1d7d7f1 | 2015-09-25 16:48:57 -0700 | [diff] [blame] | 386 | return all_deleted ? JNI_TRUE : JNI_FALSE; |
| Brian Carlstrom | f91c8c3 | 2011-09-21 17:30:34 -0700 | [diff] [blame] | 387 | } |
| 388 | |
| Mathieu Chartier | e58991b | 2015-10-13 07:59:34 -0700 | [diff] [blame] | 389 | static jclass DexFile_defineClassNative(JNIEnv* env, |
| 390 | jclass, |
| 391 | jstring javaName, |
| 392 | jobject javaLoader, |
| Mathieu Chartier | 00310e0 | 2015-10-17 12:46:42 -0700 | [diff] [blame] | 393 | jobject cookie, |
| 394 | jobject dexFile) { |
| Mathieu Chartier | e58991b | 2015-10-13 07:59:34 -0700 | [diff] [blame] | 395 | std::vector<const DexFile*> dex_files; |
| 396 | const OatFile* oat_file; |
| 397 | if (!ConvertJavaArrayToDexFiles(env, cookie, /*out*/ dex_files, /*out*/ oat_file)) { |
| Brian Carlstrom | 7571e8b | 2013-08-12 17:04:14 -0700 | [diff] [blame] | 398 | VLOG(class_linker) << "Failed to find dex_file"; |
| Andreas Gampe | 324b9bb | 2015-02-23 16:33:22 -0800 | [diff] [blame] | 399 | DCHECK(env->ExceptionCheck()); |
| 400 | return nullptr; |
| Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 401 | } |
| Andreas Gampe | 324b9bb | 2015-02-23 16:33:22 -0800 | [diff] [blame] | 402 | |
| Brian Carlstrom | df14324 | 2011-10-10 18:05:34 -0700 | [diff] [blame] | 403 | ScopedUtfChars class_name(env, javaName); |
| Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 404 | if (class_name.c_str() == nullptr) { |
| Brian Carlstrom | 2e450bf | 2013-09-06 15:39:46 -0700 | [diff] [blame] | 405 | VLOG(class_linker) << "Failed to find class_name"; |
| Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 406 | return nullptr; |
| Brian Carlstrom | df14324 | 2011-10-10 18:05:34 -0700 | [diff] [blame] | 407 | } |
| Elliott Hughes | 9557241 | 2011-12-13 18:14:20 -0800 | [diff] [blame] | 408 | const std::string descriptor(DotToDescriptor(class_name.c_str())); |
| Mathieu Chartier | e7c9a8c | 2014-11-06 16:35:45 -0800 | [diff] [blame] | 409 | const size_t hash(ComputeModifiedUtf8Hash(descriptor.c_str())); |
| Mathieu Chartier | e58991b | 2015-10-13 07:59:34 -0700 | [diff] [blame] | 410 | for (auto& dex_file : dex_files) { |
| Andreas Gampe | 3f1dcd3 | 2018-12-28 09:39:56 -0800 | [diff] [blame] | 411 | const dex::ClassDef* dex_class_def = |
| David Sehr | 9aa352e | 2016-09-15 18:13:52 -0700 | [diff] [blame] | 412 | OatDexFile::FindClassDef(*dex_file, descriptor.c_str(), hash); |
| Andreas Gampe | 833a485 | 2014-05-21 18:46:59 -0700 | [diff] [blame] | 413 | if (dex_class_def != nullptr) { |
| 414 | ScopedObjectAccess soa(env); |
| 415 | ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); |
| Andreas Gampe | 833a485 | 2014-05-21 18:46:59 -0700 | [diff] [blame] | 416 | StackHandleScope<1> hs(soa.Self()); |
| 417 | Handle<mirror::ClassLoader> class_loader( |
| Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 418 | hs.NewHandle(soa.Decode<mirror::ClassLoader>(javaLoader))); |
| Vladimir Marko | cd556b0 | 2017-02-03 11:47:34 +0000 | [diff] [blame] | 419 | ObjPtr<mirror::DexCache> dex_cache = |
| 420 | class_linker->RegisterDexFile(*dex_file, class_loader.Get()); |
| 421 | if (dex_cache == nullptr) { |
| 422 | // OOME or InternalError (dexFile already registered with a different class loader). |
| 423 | soa.Self()->AssertPendingException(); |
| 424 | return nullptr; |
| 425 | } |
| Mathieu Chartier | bc5a795 | 2016-10-17 15:46:31 -0700 | [diff] [blame] | 426 | ObjPtr<mirror::Class> result = class_linker->DefineClass(soa.Self(), |
| 427 | descriptor.c_str(), |
| 428 | hash, |
| 429 | class_loader, |
| 430 | *dex_file, |
| 431 | *dex_class_def); |
| Mathieu Chartier | 00310e0 | 2015-10-17 12:46:42 -0700 | [diff] [blame] | 432 | // Add the used dex file. This only required for the DexFile.loadClass API since normal |
| 433 | // class loaders already keep their dex files live. |
| Mathieu Chartier | bc5a795 | 2016-10-17 15:46:31 -0700 | [diff] [blame] | 434 | class_linker->InsertDexFileInToClassLoader(soa.Decode<mirror::Object>(dexFile), |
| Mathieu Chartier | 00310e0 | 2015-10-17 12:46:42 -0700 | [diff] [blame] | 435 | class_loader.Get()); |
| Andreas Gampe | 833a485 | 2014-05-21 18:46:59 -0700 | [diff] [blame] | 436 | if (result != nullptr) { |
| Brian Carlstrom | 667ab7c | 2014-10-16 19:12:28 -0700 | [diff] [blame] | 437 | VLOG(class_linker) << "DexFile_defineClassNative returning " << result |
| 438 | << " for " << class_name.c_str(); |
| Andreas Gampe | 833a485 | 2014-05-21 18:46:59 -0700 | [diff] [blame] | 439 | return soa.AddLocalReference<jclass>(result); |
| 440 | } |
| 441 | } |
| Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 442 | } |
| Brian Carlstrom | 667ab7c | 2014-10-16 19:12:28 -0700 | [diff] [blame] | 443 | VLOG(class_linker) << "Failed to find dex_class_def " << class_name.c_str(); |
| Andreas Gampe | 833a485 | 2014-05-21 18:46:59 -0700 | [diff] [blame] | 444 | return nullptr; |
| Brian Carlstrom | f91c8c3 | 2011-09-21 17:30:34 -0700 | [diff] [blame] | 445 | } |
| 446 | |
| Andreas Gampe | 833a485 | 2014-05-21 18:46:59 -0700 | [diff] [blame] | 447 | // Needed as a compare functor for sets of const char |
| 448 | struct CharPointerComparator { |
| 449 | bool operator()(const char *str1, const char *str2) const { |
| 450 | return strcmp(str1, str2) < 0; |
| 451 | } |
| 452 | }; |
| 453 | |
| 454 | // Note: this can be an expensive call, as we sort out duplicates in MultiDex files. |
| Andreas Gampe | 324b9bb | 2015-02-23 16:33:22 -0800 | [diff] [blame] | 455 | static jobjectArray DexFile_getClassNameList(JNIEnv* env, jclass, jobject cookie) { |
| Mathieu Chartier | e58991b | 2015-10-13 07:59:34 -0700 | [diff] [blame] | 456 | const OatFile* oat_file = nullptr; |
| 457 | std::vector<const DexFile*> dex_files; |
| 458 | if (!ConvertJavaArrayToDexFiles(env, cookie, /*out */ dex_files, /* out */ oat_file)) { |
| Andreas Gampe | 324b9bb | 2015-02-23 16:33:22 -0800 | [diff] [blame] | 459 | DCHECK(env->ExceptionCheck()); |
| 460 | return nullptr; |
| 461 | } |
| Andreas Gampe | 833a485 | 2014-05-21 18:46:59 -0700 | [diff] [blame] | 462 | |
| Andreas Gampe | 324b9bb | 2015-02-23 16:33:22 -0800 | [diff] [blame] | 463 | // Push all class descriptors into a set. Use set instead of unordered_set as we want to |
| 464 | // retrieve all in the end. |
| 465 | std::set<const char*, CharPointerComparator> descriptors; |
| Mathieu Chartier | e58991b | 2015-10-13 07:59:34 -0700 | [diff] [blame] | 466 | for (auto& dex_file : dex_files) { |
| Andreas Gampe | 324b9bb | 2015-02-23 16:33:22 -0800 | [diff] [blame] | 467 | for (size_t i = 0; i < dex_file->NumClassDefs(); ++i) { |
| Andreas Gampe | 3f1dcd3 | 2018-12-28 09:39:56 -0800 | [diff] [blame] | 468 | const dex::ClassDef& class_def = dex_file->GetClassDef(i); |
| Andreas Gampe | 324b9bb | 2015-02-23 16:33:22 -0800 | [diff] [blame] | 469 | const char* descriptor = dex_file->GetClassDescriptor(class_def); |
| 470 | descriptors.insert(descriptor); |
| Andreas Gampe | 833a485 | 2014-05-21 18:46:59 -0700 | [diff] [blame] | 471 | } |
| Andreas Gampe | 324b9bb | 2015-02-23 16:33:22 -0800 | [diff] [blame] | 472 | } |
| Andreas Gampe | 833a485 | 2014-05-21 18:46:59 -0700 | [diff] [blame] | 473 | |
| Andreas Gampe | 324b9bb | 2015-02-23 16:33:22 -0800 | [diff] [blame] | 474 | // Now create output array and copy the set into it. |
| Mathieu Chartier | e58991b | 2015-10-13 07:59:34 -0700 | [diff] [blame] | 475 | jobjectArray result = env->NewObjectArray(descriptors.size(), |
| 476 | WellKnownClasses::java_lang_String, |
| Andreas Gampe | 324b9bb | 2015-02-23 16:33:22 -0800 | [diff] [blame] | 477 | nullptr); |
| 478 | if (result != nullptr) { |
| 479 | auto it = descriptors.begin(); |
| 480 | auto it_end = descriptors.end(); |
| 481 | jsize i = 0; |
| 482 | for (; it != it_end; it++, ++i) { |
| 483 | std::string descriptor(DescriptorToDot(*it)); |
| 484 | ScopedLocalRef<jstring> jdescriptor(env, env->NewStringUTF(descriptor.c_str())); |
| 485 | if (jdescriptor.get() == nullptr) { |
| 486 | return nullptr; |
| Ian Rogers | dd157d7 | 2014-05-15 14:47:50 -0700 | [diff] [blame] | 487 | } |
| Andreas Gampe | 324b9bb | 2015-02-23 16:33:22 -0800 | [diff] [blame] | 488 | env->SetObjectArrayElement(result, i, jdescriptor.get()); |
| Ian Rogers | dd157d7 | 2014-05-15 14:47:50 -0700 | [diff] [blame] | 489 | } |
| Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 490 | } |
| Ian Rogers | dd157d7 | 2014-05-15 14:47:50 -0700 | [diff] [blame] | 491 | return result; |
| Brian Carlstrom | f91c8c3 | 2011-09-21 17:30:34 -0700 | [diff] [blame] | 492 | } |
| 493 | |
| Mathieu Chartier | e58991b | 2015-10-13 07:59:34 -0700 | [diff] [blame] | 494 | static jint GetDexOptNeeded(JNIEnv* env, |
| 495 | const char* filename, |
| Mathieu Chartier | e58991b | 2015-10-13 07:59:34 -0700 | [diff] [blame] | 496 | const char* instruction_set, |
| Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 497 | const char* compiler_filter_name, |
| Calin Juravle | 20c4644 | 2017-09-12 00:54:26 -0700 | [diff] [blame] | 498 | const char* class_loader_context, |
| Shubham Ajmera | e4e812a | 2017-05-25 20:09:58 -0700 | [diff] [blame] | 499 | bool profile_changed, |
| 500 | bool downgrade) { |
| Narayan Kamath | 11d9f06 | 2014-04-23 20:24:57 +0100 | [diff] [blame] | 501 | if ((filename == nullptr) || !OS::FileExists(filename)) { |
| Richard Uhler | 95abd04 | 2015-03-24 09:51:28 -0700 | [diff] [blame] | 502 | LOG(ERROR) << "DexFile_getDexOptNeeded file '" << filename << "' does not exist"; |
| Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 503 | ScopedLocalRef<jclass> fnfe(env, env->FindClass("java/io/FileNotFoundException")); |
| Narayan Kamath | 11d9f06 | 2014-04-23 20:24:57 +0100 | [diff] [blame] | 504 | const char* message = (filename == nullptr) ? "<empty file name>" : filename; |
| Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 505 | env->ThrowNew(fnfe.get(), message); |
| Calin Juravle | b077e15 | 2016-02-18 18:47:37 +0000 | [diff] [blame] | 506 | return -1; |
| Brian Carlstrom | 1d9f52b | 2011-10-13 10:50:45 -0700 | [diff] [blame] | 507 | } |
| 508 | |
| Alex Light | 6e183f2 | 2014-07-18 14:57:04 -0700 | [diff] [blame] | 509 | const InstructionSet target_instruction_set = GetInstructionSetFromString(instruction_set); |
| Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 510 | if (target_instruction_set == InstructionSet::kNone) { |
| Andreas Gampe | 20c8930 | 2014-08-19 17:28:06 -0700 | [diff] [blame] | 511 | ScopedLocalRef<jclass> iae(env, env->FindClass("java/lang/IllegalArgumentException")); |
| 512 | std::string message(StringPrintf("Instruction set %s is invalid.", instruction_set)); |
| 513 | env->ThrowNew(iae.get(), message.c_str()); |
| Calin Juravle | b077e15 | 2016-02-18 18:47:37 +0000 | [diff] [blame] | 514 | return -1; |
| Andreas Gampe | 20c8930 | 2014-08-19 17:28:06 -0700 | [diff] [blame] | 515 | } |
| Alex Light | 6e183f2 | 2014-07-18 14:57:04 -0700 | [diff] [blame] | 516 | |
| Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 517 | CompilerFilter::Filter filter; |
| 518 | if (!CompilerFilter::ParseCompilerFilter(compiler_filter_name, &filter)) { |
| 519 | ScopedLocalRef<jclass> iae(env, env->FindClass("java/lang/IllegalArgumentException")); |
| 520 | std::string message(StringPrintf("Compiler filter %s is invalid.", compiler_filter_name)); |
| 521 | env->ThrowNew(iae.get(), message.c_str()); |
| 522 | return -1; |
| 523 | } |
| 524 | |
| Calin Juravle | 20c4644 | 2017-09-12 00:54:26 -0700 | [diff] [blame] | 525 | std::unique_ptr<ClassLoaderContext> context = nullptr; |
| 526 | if (class_loader_context != nullptr) { |
| 527 | context = ClassLoaderContext::Create(class_loader_context); |
| 528 | |
| 529 | if (context == nullptr) { |
| 530 | ScopedLocalRef<jclass> iae(env, env->FindClass("java/lang/IllegalArgumentException")); |
| 531 | std::string message(StringPrintf("Class loader context '%s' is invalid.", |
| 532 | class_loader_context)); |
| 533 | env->ThrowNew(iae.get(), message.c_str()); |
| 534 | return -1; |
| 535 | } |
| 536 | } |
| 537 | |
| Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 538 | // TODO: Verify the dex location is well formed, and throw an IOException if |
| 539 | // not? |
| Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 540 | |
| Richard Uhler | d1472a2 | 2016-04-15 15:18:56 -0700 | [diff] [blame] | 541 | OatFileAssistant oat_file_assistant(filename, target_instruction_set, false); |
| Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 542 | |
| 543 | // Always treat elements of the bootclasspath as up-to-date. |
| 544 | if (oat_file_assistant.IsInBootClassPath()) { |
| Richard Uhler | 95abd04 | 2015-03-24 09:51:28 -0700 | [diff] [blame] | 545 | return OatFileAssistant::kNoDexOptNeeded; |
| Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 546 | } |
| Calin Juravle | 44e5efa | 2017-09-12 00:54:26 -0700 | [diff] [blame] | 547 | |
| Calin Juravle | 20c4644 | 2017-09-12 00:54:26 -0700 | [diff] [blame] | 548 | return oat_file_assistant.GetDexOptNeeded(filter, |
| 549 | profile_changed, |
| 550 | downgrade, |
| 551 | context.get()); |
| Brian Carlstrom | f91c8c3 | 2011-09-21 17:30:34 -0700 | [diff] [blame] | 552 | } |
| 553 | |
| Narayan Kamath | 8943c1d | 2016-05-02 13:14:48 +0100 | [diff] [blame] | 554 | static jstring DexFile_getDexFileStatus(JNIEnv* env, |
| 555 | jclass, |
| 556 | jstring javaFilename, |
| 557 | jstring javaInstructionSet) { |
| 558 | ScopedUtfChars filename(env, javaFilename); |
| 559 | if (env->ExceptionCheck()) { |
| 560 | return nullptr; |
| 561 | } |
| 562 | |
| 563 | ScopedUtfChars instruction_set(env, javaInstructionSet); |
| 564 | if (env->ExceptionCheck()) { |
| 565 | return nullptr; |
| 566 | } |
| 567 | |
| 568 | const InstructionSet target_instruction_set = GetInstructionSetFromString( |
| 569 | instruction_set.c_str()); |
| Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 570 | if (target_instruction_set == InstructionSet::kNone) { |
| Narayan Kamath | 8943c1d | 2016-05-02 13:14:48 +0100 | [diff] [blame] | 571 | ScopedLocalRef<jclass> iae(env, env->FindClass("java/lang/IllegalArgumentException")); |
| 572 | std::string message(StringPrintf("Instruction set %s is invalid.", instruction_set.c_str())); |
| 573 | env->ThrowNew(iae.get(), message.c_str()); |
| 574 | return nullptr; |
| 575 | } |
| 576 | |
| 577 | OatFileAssistant oat_file_assistant(filename.c_str(), target_instruction_set, |
| Andreas Gampe | 98ea9d9 | 2018-10-19 14:06:15 -0700 | [diff] [blame] | 578 | /* load_executable= */ false); |
| Richard Uhler | 46cc64f | 2016-11-14 14:53:55 +0000 | [diff] [blame] | 579 | return env->NewStringUTF(oat_file_assistant.GetStatusDump().c_str()); |
| Narayan Kamath | 8943c1d | 2016-05-02 13:14:48 +0100 | [diff] [blame] | 580 | } |
| 581 | |
| Calin Juravle | 5f9a801 | 2018-02-12 20:27:46 -0800 | [diff] [blame] | 582 | // Return an array specifying the optimization status of the given file. |
| 583 | // The array specification is [compiler_filter, compiler_reason]. |
| 584 | static jobjectArray DexFile_getDexFileOptimizationStatus(JNIEnv* env, |
| 585 | jclass, |
| 586 | jstring javaFilename, |
| 587 | jstring javaInstructionSet) { |
| 588 | ScopedUtfChars filename(env, javaFilename); |
| 589 | if (env->ExceptionCheck()) { |
| 590 | return nullptr; |
| 591 | } |
| 592 | |
| 593 | ScopedUtfChars instruction_set(env, javaInstructionSet); |
| 594 | if (env->ExceptionCheck()) { |
| 595 | return nullptr; |
| 596 | } |
| 597 | |
| 598 | const InstructionSet target_instruction_set = GetInstructionSetFromString( |
| 599 | instruction_set.c_str()); |
| 600 | if (target_instruction_set == InstructionSet::kNone) { |
| 601 | ScopedLocalRef<jclass> iae(env, env->FindClass("java/lang/IllegalArgumentException")); |
| 602 | std::string message(StringPrintf("Instruction set %s is invalid.", instruction_set.c_str())); |
| 603 | env->ThrowNew(iae.get(), message.c_str()); |
| 604 | return nullptr; |
| 605 | } |
| 606 | |
| 607 | std::string compilation_filter; |
| 608 | std::string compilation_reason; |
| 609 | OatFileAssistant::GetOptimizationStatus( |
| 610 | filename.c_str(), target_instruction_set, &compilation_filter, &compilation_reason); |
| 611 | |
| 612 | ScopedLocalRef<jstring> j_compilation_filter(env, env->NewStringUTF(compilation_filter.c_str())); |
| 613 | if (j_compilation_filter.get() == nullptr) { |
| 614 | return nullptr; |
| 615 | } |
| 616 | ScopedLocalRef<jstring> j_compilation_reason(env, env->NewStringUTF(compilation_reason.c_str())); |
| 617 | if (j_compilation_reason.get() == nullptr) { |
| 618 | return nullptr; |
| 619 | } |
| 620 | |
| 621 | // Now create output array and copy the set into it. |
| 622 | jobjectArray result = env->NewObjectArray(2, |
| 623 | WellKnownClasses::java_lang_String, |
| 624 | nullptr); |
| 625 | env->SetObjectArrayElement(result, 0, j_compilation_filter.get()); |
| 626 | env->SetObjectArrayElement(result, 1, j_compilation_reason.get()); |
| 627 | |
| 628 | return result; |
| 629 | } |
| 630 | |
| Mathieu Chartier | e58991b | 2015-10-13 07:59:34 -0700 | [diff] [blame] | 631 | static jint DexFile_getDexOptNeeded(JNIEnv* env, |
| 632 | jclass, |
| 633 | jstring javaFilename, |
| Mathieu Chartier | e58991b | 2015-10-13 07:59:34 -0700 | [diff] [blame] | 634 | jstring javaInstructionSet, |
| Andreas Gampe | c38be81 | 2016-03-23 15:03:46 -0700 | [diff] [blame] | 635 | jstring javaTargetCompilerFilter, |
| Calin Juravle | 20c4644 | 2017-09-12 00:54:26 -0700 | [diff] [blame] | 636 | jstring javaClassLoaderContext, |
| Shubham Ajmera | e4e812a | 2017-05-25 20:09:58 -0700 | [diff] [blame] | 637 | jboolean newProfile, |
| 638 | jboolean downgrade) { |
| Narayan Kamath | 11d9f06 | 2014-04-23 20:24:57 +0100 | [diff] [blame] | 639 | ScopedUtfChars filename(env, javaFilename); |
| Andreas Gampe | 20c8930 | 2014-08-19 17:28:06 -0700 | [diff] [blame] | 640 | if (env->ExceptionCheck()) { |
| Calin Juravle | b077e15 | 2016-02-18 18:47:37 +0000 | [diff] [blame] | 641 | return -1; |
| Andreas Gampe | 20c8930 | 2014-08-19 17:28:06 -0700 | [diff] [blame] | 642 | } |
| 643 | |
| Narayan Kamath | 11d9f06 | 2014-04-23 20:24:57 +0100 | [diff] [blame] | 644 | ScopedUtfChars instruction_set(env, javaInstructionSet); |
| Andreas Gampe | 20c8930 | 2014-08-19 17:28:06 -0700 | [diff] [blame] | 645 | if (env->ExceptionCheck()) { |
| Calin Juravle | b077e15 | 2016-02-18 18:47:37 +0000 | [diff] [blame] | 646 | return -1; |
| Andreas Gampe | 20c8930 | 2014-08-19 17:28:06 -0700 | [diff] [blame] | 647 | } |
| Narayan Kamath | 11d9f06 | 2014-04-23 20:24:57 +0100 | [diff] [blame] | 648 | |
| Andreas Gampe | c38be81 | 2016-03-23 15:03:46 -0700 | [diff] [blame] | 649 | ScopedUtfChars target_compiler_filter(env, javaTargetCompilerFilter); |
| 650 | if (env->ExceptionCheck()) { |
| 651 | return -1; |
| Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 652 | } |
| Andreas Gampe | c38be81 | 2016-03-23 15:03:46 -0700 | [diff] [blame] | 653 | |
| Calin Juravle | 20c4644 | 2017-09-12 00:54:26 -0700 | [diff] [blame] | 654 | NullableScopedUtfChars class_loader_context(env, javaClassLoaderContext); |
| 655 | if (env->ExceptionCheck()) { |
| 656 | return -1; |
| 657 | } |
| 658 | |
| Mathieu Chartier | e58991b | 2015-10-13 07:59:34 -0700 | [diff] [blame] | 659 | return GetDexOptNeeded(env, |
| 660 | filename.c_str(), |
| Mathieu Chartier | e58991b | 2015-10-13 07:59:34 -0700 | [diff] [blame] | 661 | instruction_set.c_str(), |
| Andreas Gampe | c38be81 | 2016-03-23 15:03:46 -0700 | [diff] [blame] | 662 | target_compiler_filter.c_str(), |
| Calin Juravle | 20c4644 | 2017-09-12 00:54:26 -0700 | [diff] [blame] | 663 | class_loader_context.c_str(), |
| Shubham Ajmera | e4e812a | 2017-05-25 20:09:58 -0700 | [diff] [blame] | 664 | newProfile == JNI_TRUE, |
| 665 | downgrade == JNI_TRUE); |
| Narayan Kamath | 11d9f06 | 2014-04-23 20:24:57 +0100 | [diff] [blame] | 666 | } |
| 667 | |
| Calin Juravle | b077e15 | 2016-02-18 18:47:37 +0000 | [diff] [blame] | 668 | // public API |
| Narayan Kamath | 11d9f06 | 2014-04-23 20:24:57 +0100 | [diff] [blame] | 669 | static jboolean DexFile_isDexOptNeeded(JNIEnv* env, jclass, jstring javaFilename) { |
| Richard Uhler | 06e3f4f | 2016-05-24 15:42:37 -0700 | [diff] [blame] | 670 | ScopedUtfChars filename_utf(env, javaFilename); |
| 671 | if (env->ExceptionCheck()) { |
| 672 | return JNI_FALSE; |
| 673 | } |
| 674 | |
| 675 | const char* filename = filename_utf.c_str(); |
| 676 | if ((filename == nullptr) || !OS::FileExists(filename)) { |
| 677 | LOG(ERROR) << "DexFile_isDexOptNeeded file '" << filename << "' does not exist"; |
| 678 | ScopedLocalRef<jclass> fnfe(env, env->FindClass("java/io/FileNotFoundException")); |
| 679 | const char* message = (filename == nullptr) ? "<empty file name>" : filename; |
| 680 | env->ThrowNew(fnfe.get(), message); |
| 681 | return JNI_FALSE; |
| 682 | } |
| 683 | |
| Richard Uhler | d1472a2 | 2016-04-15 15:18:56 -0700 | [diff] [blame] | 684 | OatFileAssistant oat_file_assistant(filename, kRuntimeISA, false); |
| Richard Uhler | 06e3f4f | 2016-05-24 15:42:37 -0700 | [diff] [blame] | 685 | return oat_file_assistant.IsUpToDate() ? JNI_FALSE : JNI_TRUE; |
| Dave Allison | 39c3bfb | 2014-01-28 18:33:52 -0800 | [diff] [blame] | 686 | } |
| 687 | |
| Andreas Gampe | c38be81 | 2016-03-23 15:03:46 -0700 | [diff] [blame] | 688 | static jboolean DexFile_isValidCompilerFilter(JNIEnv* env, |
| 689 | jclass javeDexFileClass ATTRIBUTE_UNUSED, |
| 690 | jstring javaCompilerFilter) { |
| 691 | ScopedUtfChars compiler_filter(env, javaCompilerFilter); |
| 692 | if (env->ExceptionCheck()) { |
| 693 | return -1; |
| 694 | } |
| 695 | |
| 696 | CompilerFilter::Filter filter; |
| 697 | return CompilerFilter::ParseCompilerFilter(compiler_filter.c_str(), &filter) |
| 698 | ? JNI_TRUE : JNI_FALSE; |
| 699 | } |
| 700 | |
| 701 | static jboolean DexFile_isProfileGuidedCompilerFilter(JNIEnv* env, |
| 702 | jclass javeDexFileClass ATTRIBUTE_UNUSED, |
| 703 | jstring javaCompilerFilter) { |
| 704 | ScopedUtfChars compiler_filter(env, javaCompilerFilter); |
| 705 | if (env->ExceptionCheck()) { |
| 706 | return -1; |
| 707 | } |
| 708 | |
| 709 | CompilerFilter::Filter filter; |
| 710 | if (!CompilerFilter::ParseCompilerFilter(compiler_filter.c_str(), &filter)) { |
| 711 | return JNI_FALSE; |
| 712 | } |
| 713 | return CompilerFilter::DependsOnProfile(filter) ? JNI_TRUE : JNI_FALSE; |
| 714 | } |
| 715 | |
| Andreas Gampe | 86a785d | 2016-03-30 17:19:48 -0700 | [diff] [blame] | 716 | static jstring DexFile_getNonProfileGuidedCompilerFilter(JNIEnv* env, |
| 717 | jclass javeDexFileClass ATTRIBUTE_UNUSED, |
| 718 | jstring javaCompilerFilter) { |
| 719 | ScopedUtfChars compiler_filter(env, javaCompilerFilter); |
| 720 | if (env->ExceptionCheck()) { |
| 721 | return nullptr; |
| 722 | } |
| 723 | |
| 724 | CompilerFilter::Filter filter; |
| 725 | if (!CompilerFilter::ParseCompilerFilter(compiler_filter.c_str(), &filter)) { |
| 726 | return javaCompilerFilter; |
| 727 | } |
| 728 | |
| 729 | CompilerFilter::Filter new_filter = CompilerFilter::GetNonProfileDependentFilterFrom(filter); |
| 730 | |
| 731 | // Filter stayed the same, return input. |
| 732 | if (filter == new_filter) { |
| 733 | return javaCompilerFilter; |
| 734 | } |
| 735 | |
| 736 | // Create a new string object and return. |
| 737 | std::string new_filter_str = CompilerFilter::NameOfFilter(new_filter); |
| 738 | return env->NewStringUTF(new_filter_str.c_str()); |
| 739 | } |
| 740 | |
| Nicolas Geoffray | 741d426 | 2017-05-03 13:08:36 +0100 | [diff] [blame] | 741 | static jstring DexFile_getSafeModeCompilerFilter(JNIEnv* env, |
| 742 | jclass javeDexFileClass ATTRIBUTE_UNUSED, |
| 743 | jstring javaCompilerFilter) { |
| 744 | ScopedUtfChars compiler_filter(env, javaCompilerFilter); |
| 745 | if (env->ExceptionCheck()) { |
| 746 | return nullptr; |
| 747 | } |
| 748 | |
| 749 | CompilerFilter::Filter filter; |
| 750 | if (!CompilerFilter::ParseCompilerFilter(compiler_filter.c_str(), &filter)) { |
| 751 | return javaCompilerFilter; |
| 752 | } |
| 753 | |
| 754 | CompilerFilter::Filter new_filter = CompilerFilter::GetSafeModeFilterFrom(filter); |
| 755 | |
| 756 | // Filter stayed the same, return input. |
| 757 | if (filter == new_filter) { |
| 758 | return javaCompilerFilter; |
| 759 | } |
| 760 | |
| 761 | // Create a new string object and return. |
| 762 | std::string new_filter_str = CompilerFilter::NameOfFilter(new_filter); |
| 763 | return env->NewStringUTF(new_filter_str.c_str()); |
| 764 | } |
| 765 | |
| Jeff Hao | 90671be | 2016-04-22 14:00:06 -0700 | [diff] [blame] | 766 | static jboolean DexFile_isBackedByOatFile(JNIEnv* env, jclass, jobject cookie) { |
| 767 | const OatFile* oat_file = nullptr; |
| 768 | std::vector<const DexFile*> dex_files; |
| 769 | if (!ConvertJavaArrayToDexFiles(env, cookie, /*out */ dex_files, /* out */ oat_file)) { |
| 770 | DCHECK(env->ExceptionCheck()); |
| 771 | return false; |
| 772 | } |
| 773 | return oat_file != nullptr; |
| 774 | } |
| 775 | |
| Calin Juravle | 367b9d8 | 2017-05-15 18:18:39 -0700 | [diff] [blame] | 776 | static jobjectArray DexFile_getDexFileOutputPaths(JNIEnv* env, |
| Philip Cuadra | b55ad7c | 2016-07-12 16:37:40 -0700 | [diff] [blame] | 777 | jclass, |
| 778 | jstring javaFilename, |
| 779 | jstring javaInstructionSet) { |
| 780 | ScopedUtfChars filename(env, javaFilename); |
| 781 | if (env->ExceptionCheck()) { |
| 782 | return nullptr; |
| 783 | } |
| 784 | |
| 785 | ScopedUtfChars instruction_set(env, javaInstructionSet); |
| 786 | if (env->ExceptionCheck()) { |
| 787 | return nullptr; |
| 788 | } |
| 789 | |
| 790 | const InstructionSet target_instruction_set = GetInstructionSetFromString( |
| 791 | instruction_set.c_str()); |
| Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 792 | if (target_instruction_set == InstructionSet::kNone) { |
| Philip Cuadra | b55ad7c | 2016-07-12 16:37:40 -0700 | [diff] [blame] | 793 | ScopedLocalRef<jclass> iae(env, env->FindClass("java/lang/IllegalArgumentException")); |
| 794 | std::string message(StringPrintf("Instruction set %s is invalid.", instruction_set.c_str())); |
| 795 | env->ThrowNew(iae.get(), message.c_str()); |
| 796 | return nullptr; |
| 797 | } |
| 798 | |
| 799 | OatFileAssistant oat_file_assistant(filename.c_str(), |
| 800 | target_instruction_set, |
| Andreas Gampe | 98ea9d9 | 2018-10-19 14:06:15 -0700 | [diff] [blame] | 801 | /* load_executable= */ false); |
| Philip Cuadra | b55ad7c | 2016-07-12 16:37:40 -0700 | [diff] [blame] | 802 | |
| 803 | std::unique_ptr<OatFile> best_oat_file = oat_file_assistant.GetBestOatFile(); |
| 804 | if (best_oat_file == nullptr) { |
| 805 | return nullptr; |
| 806 | } |
| 807 | |
| Calin Juravle | 367b9d8 | 2017-05-15 18:18:39 -0700 | [diff] [blame] | 808 | std::string oat_filename = best_oat_file->GetLocation(); |
| 809 | std::string vdex_filename = GetVdexFilename(best_oat_file->GetLocation()); |
| 810 | |
| 811 | ScopedLocalRef<jstring> jvdexFilename(env, env->NewStringUTF(vdex_filename.c_str())); |
| 812 | if (jvdexFilename.get() == nullptr) { |
| 813 | return nullptr; |
| 814 | } |
| 815 | ScopedLocalRef<jstring> joatFilename(env, env->NewStringUTF(oat_filename.c_str())); |
| 816 | if (joatFilename.get() == nullptr) { |
| 817 | return nullptr; |
| 818 | } |
| 819 | |
| 820 | // Now create output array and copy the set into it. |
| 821 | jobjectArray result = env->NewObjectArray(2, |
| 822 | WellKnownClasses::java_lang_String, |
| 823 | nullptr); |
| 824 | env->SetObjectArrayElement(result, 0, jvdexFilename.get()); |
| 825 | env->SetObjectArrayElement(result, 1, joatFilename.get()); |
| 826 | |
| 827 | return result; |
| Philip Cuadra | b55ad7c | 2016-07-12 16:37:40 -0700 | [diff] [blame] | 828 | } |
| 829 | |
| Richard Uhler | 24ed94f | 2017-11-16 11:54:29 +0000 | [diff] [blame] | 830 | static jlong DexFile_getStaticSizeOfDexFile(JNIEnv* env, jclass, jobject cookie) { |
| 831 | const OatFile* oat_file = nullptr; |
| 832 | std::vector<const DexFile*> dex_files; |
| 833 | if (!ConvertJavaArrayToDexFiles(env, cookie, /*out */ dex_files, /* out */ oat_file)) { |
| 834 | DCHECK(env->ExceptionCheck()); |
| 835 | return 0; |
| 836 | } |
| 837 | |
| 838 | uint64_t file_size = 0; |
| 839 | for (auto& dex_file : dex_files) { |
| 840 | if (dex_file) { |
| 841 | file_size += dex_file->GetHeader().file_size_; |
| 842 | } |
| 843 | } |
| 844 | return static_cast<jlong>(file_size); |
| 845 | } |
| 846 | |
| Nicolas Geoffray | 35a4f48 | 2018-05-09 14:49:54 +0100 | [diff] [blame] | 847 | static void DexFile_setTrusted(JNIEnv* env, jclass, jobject j_cookie) { |
| 848 | Runtime* runtime = Runtime::Current(); |
| 849 | ScopedObjectAccess soa(env); |
| 850 | |
| 851 | // Currently only allow this for debuggable apps. |
| 852 | if (!runtime->IsJavaDebuggable()) { |
| 853 | ThrowSecurityException("Can't exempt class, process is not debuggable."); |
| 854 | return; |
| 855 | } |
| 856 | |
| 857 | std::vector<const DexFile*> dex_files; |
| 858 | const OatFile* oat_file; |
| 859 | if (!ConvertJavaArrayToDexFiles(env, j_cookie, dex_files, oat_file)) { |
| 860 | Thread::Current()->AssertPendingException(); |
| 861 | return; |
| 862 | } |
| 863 | |
| David Brazdil | e768182 | 2018-12-14 16:25:33 +0000 | [diff] [blame] | 864 | // Assign core platform domain as the dex files are allowed to access all the other domains. |
| Nicolas Geoffray | 35a4f48 | 2018-05-09 14:49:54 +0100 | [diff] [blame] | 865 | for (const DexFile* dex_file : dex_files) { |
| David Brazdil | e768182 | 2018-12-14 16:25:33 +0000 | [diff] [blame] | 866 | const_cast<DexFile*>(dex_file)->SetHiddenapiDomain(hiddenapi::Domain::kCorePlatform); |
| Nicolas Geoffray | 35a4f48 | 2018-05-09 14:49:54 +0100 | [diff] [blame] | 867 | } |
| 868 | } |
| 869 | |
| Brian Carlstrom | f91c8c3 | 2011-09-21 17:30:34 -0700 | [diff] [blame] | 870 | static JNINativeMethod gMethods[] = { |
| Mathieu Chartier | 1d7d7f1 | 2015-09-25 16:48:57 -0700 | [diff] [blame] | 871 | NATIVE_METHOD(DexFile, closeDexFile, "(Ljava/lang/Object;)Z"), |
| Mathieu Chartier | 00310e0 | 2015-10-17 12:46:42 -0700 | [diff] [blame] | 872 | NATIVE_METHOD(DexFile, |
| 873 | defineClassNative, |
| 874 | "(Ljava/lang/String;" |
| 875 | "Ljava/lang/ClassLoader;" |
| 876 | "Ljava/lang/Object;" |
| 877 | "Ldalvik/system/DexFile;" |
| 878 | ")Ljava/lang/Class;"), |
| Andreas Gampe | 324b9bb | 2015-02-23 16:33:22 -0800 | [diff] [blame] | 879 | NATIVE_METHOD(DexFile, getClassNameList, "(Ljava/lang/Object;)[Ljava/lang/String;"), |
| Brian Carlstrom | f91c8c3 | 2011-09-21 17:30:34 -0700 | [diff] [blame] | 880 | NATIVE_METHOD(DexFile, isDexOptNeeded, "(Ljava/lang/String;)Z"), |
| Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 881 | NATIVE_METHOD(DexFile, getDexOptNeeded, |
| Calin Juravle | 20c4644 | 2017-09-12 00:54:26 -0700 | [diff] [blame] | 882 | "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ZZ)I"), |
| Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 883 | NATIVE_METHOD(DexFile, openDexFileNative, |
| Mathieu Chartier | 689a700 | 2015-11-20 10:29:42 -0800 | [diff] [blame] | 884 | "(Ljava/lang/String;" |
| 885 | "Ljava/lang/String;" |
| 886 | "I" |
| 887 | "Ljava/lang/ClassLoader;" |
| 888 | "[Ldalvik/system/DexPathList$Element;" |
| 889 | ")Ljava/lang/Object;"), |
| David Brazdil | 7458291 | 2019-03-01 11:18:19 +0000 | [diff] [blame^] | 890 | NATIVE_METHOD(DexFile, openInMemoryDexFilesNative, |
| 891 | "([Ljava/nio/ByteBuffer;" |
| 892 | "[[B" |
| 893 | "[I" |
| 894 | "[I" |
| 895 | ")Ljava/lang/Object;"), |
| Andreas Gampe | c38be81 | 2016-03-23 15:03:46 -0700 | [diff] [blame] | 896 | NATIVE_METHOD(DexFile, isValidCompilerFilter, "(Ljava/lang/String;)Z"), |
| 897 | NATIVE_METHOD(DexFile, isProfileGuidedCompilerFilter, "(Ljava/lang/String;)Z"), |
| Andreas Gampe | 86a785d | 2016-03-30 17:19:48 -0700 | [diff] [blame] | 898 | NATIVE_METHOD(DexFile, |
| 899 | getNonProfileGuidedCompilerFilter, |
| 900 | "(Ljava/lang/String;)Ljava/lang/String;"), |
| Nicolas Geoffray | 741d426 | 2017-05-03 13:08:36 +0100 | [diff] [blame] | 901 | NATIVE_METHOD(DexFile, |
| 902 | getSafeModeCompilerFilter, |
| 903 | "(Ljava/lang/String;)Ljava/lang/String;"), |
| Jeff Hao | 90671be | 2016-04-22 14:00:06 -0700 | [diff] [blame] | 904 | NATIVE_METHOD(DexFile, isBackedByOatFile, "(Ljava/lang/Object;)Z"), |
| Narayan Kamath | 8943c1d | 2016-05-02 13:14:48 +0100 | [diff] [blame] | 905 | NATIVE_METHOD(DexFile, getDexFileStatus, |
| Philip Cuadra | b55ad7c | 2016-07-12 16:37:40 -0700 | [diff] [blame] | 906 | "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;"), |
| Calin Juravle | 367b9d8 | 2017-05-15 18:18:39 -0700 | [diff] [blame] | 907 | NATIVE_METHOD(DexFile, getDexFileOutputPaths, |
| Richard Uhler | 24ed94f | 2017-11-16 11:54:29 +0000 | [diff] [blame] | 908 | "(Ljava/lang/String;Ljava/lang/String;)[Ljava/lang/String;"), |
| Calin Juravle | 5f9a801 | 2018-02-12 20:27:46 -0800 | [diff] [blame] | 909 | NATIVE_METHOD(DexFile, getStaticSizeOfDexFile, "(Ljava/lang/Object;)J"), |
| 910 | NATIVE_METHOD(DexFile, getDexFileOptimizationStatus, |
| Nicolas Geoffray | 35a4f48 | 2018-05-09 14:49:54 +0100 | [diff] [blame] | 911 | "(Ljava/lang/String;Ljava/lang/String;)[Ljava/lang/String;"), |
| 912 | NATIVE_METHOD(DexFile, setTrusted, "(Ljava/lang/Object;)V") |
| Brian Carlstrom | f91c8c3 | 2011-09-21 17:30:34 -0700 | [diff] [blame] | 913 | }; |
| 914 | |
| Brian Carlstrom | f91c8c3 | 2011-09-21 17:30:34 -0700 | [diff] [blame] | 915 | void register_dalvik_system_DexFile(JNIEnv* env) { |
| Elliott Hughes | eac7667 | 2012-05-24 21:56:51 -0700 | [diff] [blame] | 916 | REGISTER_NATIVE_METHODS("dalvik/system/DexFile"); |
| Brian Carlstrom | f91c8c3 | 2011-09-21 17:30:34 -0700 | [diff] [blame] | 917 | } |
| 918 | |
| 919 | } // namespace art |