blob: a992b5cb5bb884098979eebf5ac4dd50862b3fa3 [file] [log] [blame]
Brian Carlstromf91c8c32011-09-21 17:30:34 -07001/*
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 Gampe277ccbd2014-11-03 21:36:10 -080017#include "dalvik_system_DexFile.h"
18
Narayan Kamath8943c1d2016-05-02 13:14:48 +010019#include <sstream>
20
Andreas Gampe46ee31b2016-12-14 10:11:49 -080021#include "android-base/stringprintf.h"
22
David Sehr891a50e2017-10-27 17:01:07 -070023#include "base/file_utils.h"
Elliott Hughes07ed66b2012-12-12 18:34:25 -080024#include "base/logging.h"
Andreas Gampe833a4852014-05-21 18:46:59 -070025#include "base/stl_util.h"
Brian Carlstromaded5f72011-10-07 17:15:04 -070026#include "class_linker.h"
Calin Juravle20c46442017-09-12 00:54:26 -070027#include <class_loader_context.h>
Ian Rogers62d6c772013-02-27 08:32:07 -080028#include "common_throws.h"
Andreas Gampec38be812016-03-23 15:03:46 -070029#include "compiler_filter.h"
David Sehr9e734c72018-01-04 17:56:19 -080030#include "dex/dex_file-inl.h"
31#include "dex/dex_file_loader.h"
Elliott Hugheseac76672012-05-24 21:56:51 -070032#include "jni_internal.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080033#include "mirror/class_loader.h"
Ian Rogers05f30572013-02-20 12:13:11 -080034#include "mirror/object-inl.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080035#include "mirror/string.h"
Andreas Gampe87583b32017-05-25 11:22:18 -070036#include "native_util.h"
Steven Morelande431e272017-07-18 16:53:49 -070037#include "nativehelper/jni_macros.h"
Andreas Gampe373a9b52017-10-18 09:01:57 -070038#include "nativehelper/scoped_local_ref.h"
39#include "nativehelper/scoped_utf_chars.h"
Narayan Kamath8943c1d2016-05-02 13:14:48 +010040#include "oat_file.h"
Richard Uhler66d874d2015-01-15 09:37:19 -080041#include "oat_file_assistant.h"
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -070042#include "oat_file_manager.h"
Brian Carlstrom1d9f52b2011-10-13 10:50:45 -070043#include "os.h"
Brian Carlstromaded5f72011-10-07 17:15:04 -070044#include "runtime.h"
Mathieu Chartier0795f232016-09-27 18:43:30 -070045#include "scoped_thread_state_change-inl.h"
Calin Juravlebb0b53f2014-05-23 17:33:29 +010046#include "utils.h"
Ian Rogersdd157d72014-05-15 14:47:50 -070047#include "well_known_classes.h"
Elliott Hugheseac76672012-05-24 21:56:51 -070048#include "zip_archive.h"
Brian Carlstromf91c8c32011-09-21 17:30:34 -070049
50namespace art {
51
Andreas Gampe46ee31b2016-12-14 10:11:49 -080052using android::base::StringPrintf;
53
Mathieu Chartiere58991b2015-10-13 07:59:34 -070054static bool ConvertJavaArrayToDexFiles(
55 JNIEnv* env,
56 jobject arrayObject,
57 /*out*/ std::vector<const DexFile*>& dex_files,
58 /*out*/ const OatFile*& oat_file) {
Andreas Gampe324b9bb2015-02-23 16:33:22 -080059 jarray array = reinterpret_cast<jarray>(arrayObject);
60
61 jsize array_size = env->GetArrayLength(array);
62 if (env->ExceptionCheck() == JNI_TRUE) {
Mathieu Chartiere58991b2015-10-13 07:59:34 -070063 return false;
Andreas Gampe324b9bb2015-02-23 16:33:22 -080064 }
65
66 // TODO: Optimize. On 32bit we can use an int array.
67 jboolean is_long_data_copied;
68 jlong* long_data = env->GetLongArrayElements(reinterpret_cast<jlongArray>(array),
69 &is_long_data_copied);
70 if (env->ExceptionCheck() == JNI_TRUE) {
Mathieu Chartiere58991b2015-10-13 07:59:34 -070071 return false;
Andreas Gampe324b9bb2015-02-23 16:33:22 -080072 }
73
Mathieu Chartiere58991b2015-10-13 07:59:34 -070074 oat_file = reinterpret_cast<const OatFile*>(static_cast<uintptr_t>(long_data[kOatFileIndex]));
75 dex_files.reserve(array_size - 1);
76 for (jsize i = kDexFileIndexStart; i < array_size; ++i) {
77 dex_files.push_back(reinterpret_cast<const DexFile*>(static_cast<uintptr_t>(long_data[i])));
Andreas Gampe324b9bb2015-02-23 16:33:22 -080078 }
79
80 env->ReleaseLongArrayElements(reinterpret_cast<jlongArray>(array), long_data, JNI_ABORT);
Mathieu Chartiere58991b2015-10-13 07:59:34 -070081 return env->ExceptionCheck() != JNI_TRUE;
Andreas Gampe324b9bb2015-02-23 16:33:22 -080082}
83
Mathieu Chartiere58991b2015-10-13 07:59:34 -070084static jlongArray ConvertDexFilesToJavaArray(JNIEnv* env,
85 const OatFile* oat_file,
86 std::vector<std::unique_ptr<const DexFile>>& vec) {
87 // Add one for the oat file.
Mathieu Chartier80b37b72015-10-12 18:13:39 -070088 jlongArray long_array = env->NewLongArray(static_cast<jsize>(kDexFileIndexStart + vec.size()));
Andreas Gampe324b9bb2015-02-23 16:33:22 -080089 if (env->ExceptionCheck() == JNI_TRUE) {
90 return nullptr;
91 }
92
93 jboolean is_long_data_copied;
94 jlong* long_data = env->GetLongArrayElements(long_array, &is_long_data_copied);
95 if (env->ExceptionCheck() == JNI_TRUE) {
96 return nullptr;
97 }
98
Mathieu Chartiere58991b2015-10-13 07:59:34 -070099 long_data[kOatFileIndex] = reinterpret_cast<uintptr_t>(oat_file);
100 for (size_t i = 0; i < vec.size(); ++i) {
101 long_data[kDexFileIndexStart + i] = reinterpret_cast<uintptr_t>(vec[i].get());
Andreas Gampe324b9bb2015-02-23 16:33:22 -0800102 }
103
104 env->ReleaseLongArrayElements(long_array, long_data, 0);
105 if (env->ExceptionCheck() == JNI_TRUE) {
106 return nullptr;
107 }
108
109 // Now release all the unique_ptrs.
110 for (auto& dex_file : vec) {
111 dex_file.release();
112 }
113
114 return long_array;
115}
116
Brian Carlstromf91c8c32011-09-21 17:30:34 -0700117// A smart pointer that provides read-only access to a Java string's UTF chars.
118// Unlike libcore's NullableScopedUtfChars, this will *not* throw NullPointerException if
119// passed a null jstring. The correct idiom is:
120//
121// NullableScopedUtfChars name(env, javaName);
Brian Carlstromc252c3e2011-10-16 23:21:02 -0700122// if (env->ExceptionCheck()) {
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700123// return null;
Brian Carlstromf91c8c32011-09-21 17:30:34 -0700124// }
125// // ... use name.c_str()
126//
127// TODO: rewrite to get rid of this, or change ScopedUtfChars to offer this option.
128class NullableScopedUtfChars {
Elliott Hughesba8eee12012-01-24 20:25:24 -0800129 public:
130 NullableScopedUtfChars(JNIEnv* env, jstring s) : mEnv(env), mString(s) {
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700131 mUtfChars = (s != nullptr) ? env->GetStringUTFChars(s, nullptr) : nullptr;
Elliott Hughesba8eee12012-01-24 20:25:24 -0800132 }
133
134 ~NullableScopedUtfChars() {
135 if (mUtfChars) {
136 mEnv->ReleaseStringUTFChars(mString, mUtfChars);
Brian Carlstromf91c8c32011-09-21 17:30:34 -0700137 }
Elliott Hughesba8eee12012-01-24 20:25:24 -0800138 }
Brian Carlstromf91c8c32011-09-21 17:30:34 -0700139
Elliott Hughesba8eee12012-01-24 20:25:24 -0800140 const char* c_str() const {
141 return mUtfChars;
142 }
Brian Carlstromf91c8c32011-09-21 17:30:34 -0700143
Elliott Hughesba8eee12012-01-24 20:25:24 -0800144 size_t size() const {
145 return strlen(mUtfChars);
146 }
Brian Carlstromf91c8c32011-09-21 17:30:34 -0700147
Elliott Hughesba8eee12012-01-24 20:25:24 -0800148 // Element access.
149 const char& operator[](size_t n) const {
150 return mUtfChars[n];
151 }
Brian Carlstromf91c8c32011-09-21 17:30:34 -0700152
Elliott Hughesba8eee12012-01-24 20:25:24 -0800153 private:
154 JNIEnv* mEnv;
155 jstring mString;
156 const char* mUtfChars;
Brian Carlstromf91c8c32011-09-21 17:30:34 -0700157
Elliott Hughesba8eee12012-01-24 20:25:24 -0800158 // Disallow copy and assignment.
159 NullableScopedUtfChars(const NullableScopedUtfChars&);
160 void operator=(const NullableScopedUtfChars&);
Brian Carlstromf91c8c32011-09-21 17:30:34 -0700161};
162
Alex Lightea9465e2017-02-16 15:38:35 -0800163static std::unique_ptr<MemMap> AllocateDexMemoryMap(JNIEnv* env, jint start, jint end) {
164 if (end <= start) {
165 ScopedObjectAccess soa(env);
166 ThrowWrappedIOException("Bad range");
167 return nullptr;
168 }
169
170 std::string error_message;
171 size_t length = static_cast<size_t>(end - start);
172 std::unique_ptr<MemMap> dex_mem_map(MemMap::MapAnonymous("DEX data",
173 nullptr,
174 length,
175 PROT_READ | PROT_WRITE,
176 /* low_4gb */ false,
177 /* reuse */ false,
178 &error_message));
179 if (dex_mem_map == nullptr) {
180 ScopedObjectAccess soa(env);
181 ThrowWrappedIOException("%s", error_message.c_str());
182 }
183 return dex_mem_map;
184}
185
186static const DexFile* CreateDexFile(JNIEnv* env, std::unique_ptr<MemMap> dex_mem_map) {
187 std::string location = StringPrintf("Anonymous-DexFile@%p-%p",
188 dex_mem_map->Begin(),
189 dex_mem_map->End());
190 std::string error_message;
Mathieu Chartier79c87da2017-10-10 11:54:29 -0700191 std::unique_ptr<const DexFile> dex_file(DexFileLoader::Open(location,
192 0,
193 std::move(dex_mem_map),
194 /* verify */ true,
195 /* verify_location */ true,
196 &error_message));
Alex Lightea9465e2017-02-16 15:38:35 -0800197 if (dex_file == nullptr) {
198 ScopedObjectAccess soa(env);
199 ThrowWrappedIOException("%s", error_message.c_str());
200 return nullptr;
201 }
202
203 if (!dex_file->DisableWrite()) {
204 ScopedObjectAccess soa(env);
205 ThrowWrappedIOException("Failed to make dex file read-only");
206 return nullptr;
207 }
208
209 return dex_file.release();
210}
211
212static jobject CreateSingleDexFileCookie(JNIEnv* env, std::unique_ptr<MemMap> data) {
213 std::unique_ptr<const DexFile> dex_file(CreateDexFile(env, std::move(data)));
214 if (dex_file.get() == nullptr) {
215 DCHECK(env->ExceptionCheck());
216 return nullptr;
217 }
218 std::vector<std::unique_ptr<const DexFile>> dex_files;
219 dex_files.push_back(std::move(dex_file));
220 return ConvertDexFilesToJavaArray(env, nullptr, dex_files);
221}
222
223static jobject DexFile_createCookieWithDirectBuffer(JNIEnv* env,
224 jclass,
225 jobject buffer,
226 jint start,
227 jint end) {
228 uint8_t* base_address = reinterpret_cast<uint8_t*>(env->GetDirectBufferAddress(buffer));
229 if (base_address == nullptr) {
230 ScopedObjectAccess soa(env);
231 ThrowWrappedIOException("dexFileBuffer not direct");
232 return 0;
233 }
234
235 std::unique_ptr<MemMap> dex_mem_map(AllocateDexMemoryMap(env, start, end));
236 if (dex_mem_map == nullptr) {
237 DCHECK(Thread::Current()->IsExceptionPending());
238 return 0;
239 }
240
241 size_t length = static_cast<size_t>(end - start);
242 memcpy(dex_mem_map->Begin(), base_address, length);
243 return CreateSingleDexFileCookie(env, std::move(dex_mem_map));
244}
245
246static jobject DexFile_createCookieWithArray(JNIEnv* env,
247 jclass,
248 jbyteArray buffer,
249 jint start,
250 jint end) {
251 std::unique_ptr<MemMap> dex_mem_map(AllocateDexMemoryMap(env, start, end));
252 if (dex_mem_map == nullptr) {
253 DCHECK(Thread::Current()->IsExceptionPending());
254 return 0;
255 }
256
257 auto destination = reinterpret_cast<jbyte*>(dex_mem_map.get()->Begin());
258 env->GetByteArrayRegion(buffer, start, end - start, destination);
259 return CreateSingleDexFileCookie(env, std::move(dex_mem_map));
260}
261
Calin Juravle1f7079b2017-04-18 21:25:37 -0700262// TODO(calin): clean up the unused parameters (here and in libcore).
Mathieu Chartierb190d942015-11-12 10:00:58 -0800263static jobject DexFile_openDexFileNative(JNIEnv* env,
264 jclass,
265 jstring javaSourceName,
Calin Juravle1f7079b2017-04-18 21:25:37 -0700266 jstring javaOutputName ATTRIBUTE_UNUSED,
Mathieu Chartierb190d942015-11-12 10:00:58 -0800267 jint flags ATTRIBUTE_UNUSED,
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800268 jobject class_loader,
269 jobjectArray dex_elements) {
Brian Carlstromf91c8c32011-09-21 17:30:34 -0700270 ScopedUtfChars sourceName(env, javaSourceName);
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700271 if (sourceName.c_str() == nullptr) {
Brian Carlstromf91c8c32011-09-21 17:30:34 -0700272 return 0;
273 }
Calin Juravle1f7079b2017-04-18 21:25:37 -0700274
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700275 Runtime* const runtime = Runtime::Current();
276 ClassLinker* linker = runtime->GetClassLinker();
Andreas Gampe324b9bb2015-02-23 16:33:22 -0800277 std::vector<std::unique_ptr<const DexFile>> dex_files;
Andreas Gampe833a4852014-05-21 18:46:59 -0700278 std::vector<std::string> error_msgs;
Mathieu Chartiere58991b2015-10-13 07:59:34 -0700279 const OatFile* oat_file = nullptr;
Andreas Gampe833a4852014-05-21 18:46:59 -0700280
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700281 dex_files = runtime->GetOatFileManager().OpenDexFilesFromOat(sourceName.c_str(),
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800282 class_loader,
283 dex_elements,
Mathieu Chartiere58991b2015-10-13 07:59:34 -0700284 /*out*/ &oat_file,
285 /*out*/ &error_msgs);
Andreas Gampe833a4852014-05-21 18:46:59 -0700286
Richard Uhler66d874d2015-01-15 09:37:19 -0800287 if (!dex_files.empty()) {
Mathieu Chartiere58991b2015-10-13 07:59:34 -0700288 jlongArray array = ConvertDexFilesToJavaArray(env, oat_file, dex_files);
Andreas Gampe324b9bb2015-02-23 16:33:22 -0800289 if (array == nullptr) {
290 ScopedObjectAccess soa(env);
291 for (auto& dex_file : dex_files) {
Vladimir Markocd556b02017-02-03 11:47:34 +0000292 if (linker->IsDexFileRegistered(soa.Self(), *dex_file)) {
Andreas Gampe324b9bb2015-02-23 16:33:22 -0800293 dex_file.release();
294 }
295 }
296 }
297 return array;
Brian Carlstrom756ee4e2013-10-03 15:46:12 -0700298 } else {
Vladimir Marko60836d52014-01-16 15:53:38 +0000299 ScopedObjectAccess soa(env);
Andreas Gampe329d1882014-04-08 10:32:19 -0700300 CHECK(!error_msgs.empty());
301 // The most important message is at the end. So set up nesting by going forward, which will
302 // wrap the existing exception as a cause for the following one.
303 auto it = error_msgs.begin();
304 auto itEnd = error_msgs.end();
305 for ( ; it != itEnd; ++it) {
306 ThrowWrappedIOException("%s", it->c_str());
307 }
308
Andreas Gampe324b9bb2015-02-23 16:33:22 -0800309 return nullptr;
Brian Carlstromaded5f72011-10-07 17:15:04 -0700310 }
Brian Carlstromaded5f72011-10-07 17:15:04 -0700311}
312
Mathieu Chartier1d7d7f12015-09-25 16:48:57 -0700313static jboolean DexFile_closeDexFile(JNIEnv* env, jclass, jobject cookie) {
Mathieu Chartiere58991b2015-10-13 07:59:34 -0700314 std::vector<const DexFile*> dex_files;
315 const OatFile* oat_file;
316 if (!ConvertJavaArrayToDexFiles(env, cookie, dex_files, oat_file)) {
317 Thread::Current()->AssertPendingException();
Mathieu Chartier1d7d7f12015-09-25 16:48:57 -0700318 return JNI_FALSE;
319 }
Mathieu Chartiere58991b2015-10-13 07:59:34 -0700320 Runtime* const runtime = Runtime::Current();
Mathieu Chartier1d7d7f12015-09-25 16:48:57 -0700321 bool all_deleted = true;
Mathieu Chartiere58991b2015-10-13 07:59:34 -0700322 {
323 ScopedObjectAccess soa(env);
Mathieu Chartier0795f232016-09-27 18:43:30 -0700324 ObjPtr<mirror::Object> dex_files_object = soa.Decode<mirror::Object>(cookie);
Mathieu Chartierbc5a7952016-10-17 15:46:31 -0700325 ObjPtr<mirror::LongArray> long_dex_files = dex_files_object->AsLongArray();
Mathieu Chartiere58991b2015-10-13 07:59:34 -0700326 // Delete dex files associated with this dalvik.system.DexFile since there should not be running
327 // code using it. dex_files is a vector due to multidex.
328 ClassLinker* const class_linker = runtime->GetClassLinker();
329 int32_t i = kDexFileIndexStart; // Oat file is at index 0.
330 for (const DexFile* dex_file : dex_files) {
331 if (dex_file != nullptr) {
332 // Only delete the dex file if the dex cache is not found to prevent runtime crashes if there
333 // are calls to DexFile.close while the ART DexFile is still in use.
Vladimir Markocd556b02017-02-03 11:47:34 +0000334 if (!class_linker->IsDexFileRegistered(soa.Self(), *dex_file)) {
Mathieu Chartiere58991b2015-10-13 07:59:34 -0700335 // Clear the element in the array so that we can call close again.
336 long_dex_files->Set(i, 0);
337 delete dex_file;
338 } else {
339 all_deleted = false;
340 }
341 }
342 ++i;
Andreas Gampe833a4852014-05-21 18:46:59 -0700343 }
Brian Carlstromaded5f72011-10-07 17:15:04 -0700344 }
Mathieu Chartier1d7d7f12015-09-25 16:48:57 -0700345
Mathieu Chartierfdccbd42015-10-14 10:58:41 -0700346 // oat_file can be null if we are running without dex2oat.
347 if (all_deleted && oat_file != nullptr) {
Mathieu Chartiere58991b2015-10-13 07:59:34 -0700348 // If all of the dex files are no longer in use we can unmap the corresponding oat file.
349 VLOG(class_linker) << "Unregistering " << oat_file;
350 runtime->GetOatFileManager().UnRegisterAndDeleteOatFile(oat_file);
351 }
Mathieu Chartier1d7d7f12015-09-25 16:48:57 -0700352 return all_deleted ? JNI_TRUE : JNI_FALSE;
Brian Carlstromf91c8c32011-09-21 17:30:34 -0700353}
354
Mathieu Chartiere58991b2015-10-13 07:59:34 -0700355static jclass DexFile_defineClassNative(JNIEnv* env,
356 jclass,
357 jstring javaName,
358 jobject javaLoader,
Mathieu Chartier00310e02015-10-17 12:46:42 -0700359 jobject cookie,
360 jobject dexFile) {
Mathieu Chartiere58991b2015-10-13 07:59:34 -0700361 std::vector<const DexFile*> dex_files;
362 const OatFile* oat_file;
363 if (!ConvertJavaArrayToDexFiles(env, cookie, /*out*/ dex_files, /*out*/ oat_file)) {
Brian Carlstrom7571e8b2013-08-12 17:04:14 -0700364 VLOG(class_linker) << "Failed to find dex_file";
Andreas Gampe324b9bb2015-02-23 16:33:22 -0800365 DCHECK(env->ExceptionCheck());
366 return nullptr;
Brian Carlstromaded5f72011-10-07 17:15:04 -0700367 }
Andreas Gampe324b9bb2015-02-23 16:33:22 -0800368
Brian Carlstromdf143242011-10-10 18:05:34 -0700369 ScopedUtfChars class_name(env, javaName);
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700370 if (class_name.c_str() == nullptr) {
Brian Carlstrom2e450bf2013-09-06 15:39:46 -0700371 VLOG(class_linker) << "Failed to find class_name";
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700372 return nullptr;
Brian Carlstromdf143242011-10-10 18:05:34 -0700373 }
Elliott Hughes95572412011-12-13 18:14:20 -0800374 const std::string descriptor(DotToDescriptor(class_name.c_str()));
Mathieu Chartiere7c9a8c2014-11-06 16:35:45 -0800375 const size_t hash(ComputeModifiedUtf8Hash(descriptor.c_str()));
Mathieu Chartiere58991b2015-10-13 07:59:34 -0700376 for (auto& dex_file : dex_files) {
David Sehr9aa352e2016-09-15 18:13:52 -0700377 const DexFile::ClassDef* dex_class_def =
378 OatDexFile::FindClassDef(*dex_file, descriptor.c_str(), hash);
Andreas Gampe833a4852014-05-21 18:46:59 -0700379 if (dex_class_def != nullptr) {
380 ScopedObjectAccess soa(env);
381 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
Andreas Gampe833a4852014-05-21 18:46:59 -0700382 StackHandleScope<1> hs(soa.Self());
383 Handle<mirror::ClassLoader> class_loader(
Mathieu Chartier0795f232016-09-27 18:43:30 -0700384 hs.NewHandle(soa.Decode<mirror::ClassLoader>(javaLoader)));
Vladimir Markocd556b02017-02-03 11:47:34 +0000385 ObjPtr<mirror::DexCache> dex_cache =
386 class_linker->RegisterDexFile(*dex_file, class_loader.Get());
387 if (dex_cache == nullptr) {
388 // OOME or InternalError (dexFile already registered with a different class loader).
389 soa.Self()->AssertPendingException();
390 return nullptr;
391 }
Mathieu Chartierbc5a7952016-10-17 15:46:31 -0700392 ObjPtr<mirror::Class> result = class_linker->DefineClass(soa.Self(),
393 descriptor.c_str(),
394 hash,
395 class_loader,
396 *dex_file,
397 *dex_class_def);
Mathieu Chartier00310e02015-10-17 12:46:42 -0700398 // Add the used dex file. This only required for the DexFile.loadClass API since normal
399 // class loaders already keep their dex files live.
Mathieu Chartierbc5a7952016-10-17 15:46:31 -0700400 class_linker->InsertDexFileInToClassLoader(soa.Decode<mirror::Object>(dexFile),
Mathieu Chartier00310e02015-10-17 12:46:42 -0700401 class_loader.Get());
Andreas Gampe833a4852014-05-21 18:46:59 -0700402 if (result != nullptr) {
Brian Carlstrom667ab7c2014-10-16 19:12:28 -0700403 VLOG(class_linker) << "DexFile_defineClassNative returning " << result
404 << " for " << class_name.c_str();
Andreas Gampe833a4852014-05-21 18:46:59 -0700405 return soa.AddLocalReference<jclass>(result);
406 }
407 }
Brian Carlstromaded5f72011-10-07 17:15:04 -0700408 }
Brian Carlstrom667ab7c2014-10-16 19:12:28 -0700409 VLOG(class_linker) << "Failed to find dex_class_def " << class_name.c_str();
Andreas Gampe833a4852014-05-21 18:46:59 -0700410 return nullptr;
Brian Carlstromf91c8c32011-09-21 17:30:34 -0700411}
412
Andreas Gampe833a4852014-05-21 18:46:59 -0700413// Needed as a compare functor for sets of const char
414struct CharPointerComparator {
415 bool operator()(const char *str1, const char *str2) const {
416 return strcmp(str1, str2) < 0;
417 }
418};
419
420// Note: this can be an expensive call, as we sort out duplicates in MultiDex files.
Andreas Gampe324b9bb2015-02-23 16:33:22 -0800421static jobjectArray DexFile_getClassNameList(JNIEnv* env, jclass, jobject cookie) {
Mathieu Chartiere58991b2015-10-13 07:59:34 -0700422 const OatFile* oat_file = nullptr;
423 std::vector<const DexFile*> dex_files;
424 if (!ConvertJavaArrayToDexFiles(env, cookie, /*out */ dex_files, /* out */ oat_file)) {
Andreas Gampe324b9bb2015-02-23 16:33:22 -0800425 DCHECK(env->ExceptionCheck());
426 return nullptr;
427 }
Andreas Gampe833a4852014-05-21 18:46:59 -0700428
Andreas Gampe324b9bb2015-02-23 16:33:22 -0800429 // Push all class descriptors into a set. Use set instead of unordered_set as we want to
430 // retrieve all in the end.
431 std::set<const char*, CharPointerComparator> descriptors;
Mathieu Chartiere58991b2015-10-13 07:59:34 -0700432 for (auto& dex_file : dex_files) {
Andreas Gampe324b9bb2015-02-23 16:33:22 -0800433 for (size_t i = 0; i < dex_file->NumClassDefs(); ++i) {
434 const DexFile::ClassDef& class_def = dex_file->GetClassDef(i);
435 const char* descriptor = dex_file->GetClassDescriptor(class_def);
436 descriptors.insert(descriptor);
Andreas Gampe833a4852014-05-21 18:46:59 -0700437 }
Andreas Gampe324b9bb2015-02-23 16:33:22 -0800438 }
Andreas Gampe833a4852014-05-21 18:46:59 -0700439
Andreas Gampe324b9bb2015-02-23 16:33:22 -0800440 // Now create output array and copy the set into it.
Mathieu Chartiere58991b2015-10-13 07:59:34 -0700441 jobjectArray result = env->NewObjectArray(descriptors.size(),
442 WellKnownClasses::java_lang_String,
Andreas Gampe324b9bb2015-02-23 16:33:22 -0800443 nullptr);
444 if (result != nullptr) {
445 auto it = descriptors.begin();
446 auto it_end = descriptors.end();
447 jsize i = 0;
448 for (; it != it_end; it++, ++i) {
449 std::string descriptor(DescriptorToDot(*it));
450 ScopedLocalRef<jstring> jdescriptor(env, env->NewStringUTF(descriptor.c_str()));
451 if (jdescriptor.get() == nullptr) {
452 return nullptr;
Ian Rogersdd157d72014-05-15 14:47:50 -0700453 }
Andreas Gampe324b9bb2015-02-23 16:33:22 -0800454 env->SetObjectArrayElement(result, i, jdescriptor.get());
Ian Rogersdd157d72014-05-15 14:47:50 -0700455 }
Brian Carlstromaded5f72011-10-07 17:15:04 -0700456 }
Ian Rogersdd157d72014-05-15 14:47:50 -0700457 return result;
Brian Carlstromf91c8c32011-09-21 17:30:34 -0700458}
459
Mathieu Chartiere58991b2015-10-13 07:59:34 -0700460static jint GetDexOptNeeded(JNIEnv* env,
461 const char* filename,
Mathieu Chartiere58991b2015-10-13 07:59:34 -0700462 const char* instruction_set,
Andreas Gampe29d38e72016-03-23 15:31:51 +0000463 const char* compiler_filter_name,
Calin Juravle20c46442017-09-12 00:54:26 -0700464 const char* class_loader_context,
Shubham Ajmerae4e812a2017-05-25 20:09:58 -0700465 bool profile_changed,
466 bool downgrade) {
Narayan Kamath11d9f062014-04-23 20:24:57 +0100467 if ((filename == nullptr) || !OS::FileExists(filename)) {
Richard Uhler95abd042015-03-24 09:51:28 -0700468 LOG(ERROR) << "DexFile_getDexOptNeeded file '" << filename << "' does not exist";
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700469 ScopedLocalRef<jclass> fnfe(env, env->FindClass("java/io/FileNotFoundException"));
Narayan Kamath11d9f062014-04-23 20:24:57 +0100470 const char* message = (filename == nullptr) ? "<empty file name>" : filename;
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700471 env->ThrowNew(fnfe.get(), message);
Calin Juravleb077e152016-02-18 18:47:37 +0000472 return -1;
Brian Carlstrom1d9f52b2011-10-13 10:50:45 -0700473 }
474
Alex Light6e183f22014-07-18 14:57:04 -0700475 const InstructionSet target_instruction_set = GetInstructionSetFromString(instruction_set);
Vladimir Marko33bff252017-11-01 14:35:42 +0000476 if (target_instruction_set == InstructionSet::kNone) {
Andreas Gampe20c89302014-08-19 17:28:06 -0700477 ScopedLocalRef<jclass> iae(env, env->FindClass("java/lang/IllegalArgumentException"));
478 std::string message(StringPrintf("Instruction set %s is invalid.", instruction_set));
479 env->ThrowNew(iae.get(), message.c_str());
Calin Juravleb077e152016-02-18 18:47:37 +0000480 return -1;
Andreas Gampe20c89302014-08-19 17:28:06 -0700481 }
Alex Light6e183f22014-07-18 14:57:04 -0700482
Andreas Gampe29d38e72016-03-23 15:31:51 +0000483 CompilerFilter::Filter filter;
484 if (!CompilerFilter::ParseCompilerFilter(compiler_filter_name, &filter)) {
485 ScopedLocalRef<jclass> iae(env, env->FindClass("java/lang/IllegalArgumentException"));
486 std::string message(StringPrintf("Compiler filter %s is invalid.", compiler_filter_name));
487 env->ThrowNew(iae.get(), message.c_str());
488 return -1;
489 }
490
Calin Juravle20c46442017-09-12 00:54:26 -0700491 std::unique_ptr<ClassLoaderContext> context = nullptr;
492 if (class_loader_context != nullptr) {
493 context = ClassLoaderContext::Create(class_loader_context);
494
495 if (context == nullptr) {
496 ScopedLocalRef<jclass> iae(env, env->FindClass("java/lang/IllegalArgumentException"));
497 std::string message(StringPrintf("Class loader context '%s' is invalid.",
498 class_loader_context));
499 env->ThrowNew(iae.get(), message.c_str());
500 return -1;
501 }
502 }
503
Richard Uhler66d874d2015-01-15 09:37:19 -0800504 // TODO: Verify the dex location is well formed, and throw an IOException if
505 // not?
Andreas Gampe29d38e72016-03-23 15:31:51 +0000506
Richard Uhlerd1472a22016-04-15 15:18:56 -0700507 OatFileAssistant oat_file_assistant(filename, target_instruction_set, false);
Richard Uhler66d874d2015-01-15 09:37:19 -0800508
509 // Always treat elements of the bootclasspath as up-to-date.
510 if (oat_file_assistant.IsInBootClassPath()) {
Richard Uhler95abd042015-03-24 09:51:28 -0700511 return OatFileAssistant::kNoDexOptNeeded;
Richard Uhler66d874d2015-01-15 09:37:19 -0800512 }
Calin Juravle44e5efa2017-09-12 00:54:26 -0700513
Calin Juravle20c46442017-09-12 00:54:26 -0700514 return oat_file_assistant.GetDexOptNeeded(filter,
515 profile_changed,
516 downgrade,
517 context.get());
Brian Carlstromf91c8c32011-09-21 17:30:34 -0700518}
519
Narayan Kamath8943c1d2016-05-02 13:14:48 +0100520static jstring DexFile_getDexFileStatus(JNIEnv* env,
521 jclass,
522 jstring javaFilename,
523 jstring javaInstructionSet) {
524 ScopedUtfChars filename(env, javaFilename);
525 if (env->ExceptionCheck()) {
526 return nullptr;
527 }
528
529 ScopedUtfChars instruction_set(env, javaInstructionSet);
530 if (env->ExceptionCheck()) {
531 return nullptr;
532 }
533
534 const InstructionSet target_instruction_set = GetInstructionSetFromString(
535 instruction_set.c_str());
Vladimir Marko33bff252017-11-01 14:35:42 +0000536 if (target_instruction_set == InstructionSet::kNone) {
Narayan Kamath8943c1d2016-05-02 13:14:48 +0100537 ScopedLocalRef<jclass> iae(env, env->FindClass("java/lang/IllegalArgumentException"));
538 std::string message(StringPrintf("Instruction set %s is invalid.", instruction_set.c_str()));
539 env->ThrowNew(iae.get(), message.c_str());
540 return nullptr;
541 }
542
543 OatFileAssistant oat_file_assistant(filename.c_str(), target_instruction_set,
Narayan Kamath8943c1d2016-05-02 13:14:48 +0100544 false /* load_executable */);
Richard Uhler46cc64f2016-11-14 14:53:55 +0000545 return env->NewStringUTF(oat_file_assistant.GetStatusDump().c_str());
Narayan Kamath8943c1d2016-05-02 13:14:48 +0100546}
547
Mathieu Chartiere58991b2015-10-13 07:59:34 -0700548static jint DexFile_getDexOptNeeded(JNIEnv* env,
549 jclass,
550 jstring javaFilename,
Mathieu Chartiere58991b2015-10-13 07:59:34 -0700551 jstring javaInstructionSet,
Andreas Gampec38be812016-03-23 15:03:46 -0700552 jstring javaTargetCompilerFilter,
Calin Juravle20c46442017-09-12 00:54:26 -0700553 jstring javaClassLoaderContext,
Shubham Ajmerae4e812a2017-05-25 20:09:58 -0700554 jboolean newProfile,
555 jboolean downgrade) {
Narayan Kamath11d9f062014-04-23 20:24:57 +0100556 ScopedUtfChars filename(env, javaFilename);
Andreas Gampe20c89302014-08-19 17:28:06 -0700557 if (env->ExceptionCheck()) {
Calin Juravleb077e152016-02-18 18:47:37 +0000558 return -1;
Andreas Gampe20c89302014-08-19 17:28:06 -0700559 }
560
Narayan Kamath11d9f062014-04-23 20:24:57 +0100561 ScopedUtfChars instruction_set(env, javaInstructionSet);
Andreas Gampe20c89302014-08-19 17:28:06 -0700562 if (env->ExceptionCheck()) {
Calin Juravleb077e152016-02-18 18:47:37 +0000563 return -1;
Andreas Gampe20c89302014-08-19 17:28:06 -0700564 }
Narayan Kamath11d9f062014-04-23 20:24:57 +0100565
Andreas Gampec38be812016-03-23 15:03:46 -0700566 ScopedUtfChars target_compiler_filter(env, javaTargetCompilerFilter);
567 if (env->ExceptionCheck()) {
568 return -1;
Andreas Gampe29d38e72016-03-23 15:31:51 +0000569 }
Andreas Gampec38be812016-03-23 15:03:46 -0700570
Calin Juravle20c46442017-09-12 00:54:26 -0700571 NullableScopedUtfChars class_loader_context(env, javaClassLoaderContext);
572 if (env->ExceptionCheck()) {
573 return -1;
574 }
575
Mathieu Chartiere58991b2015-10-13 07:59:34 -0700576 return GetDexOptNeeded(env,
577 filename.c_str(),
Mathieu Chartiere58991b2015-10-13 07:59:34 -0700578 instruction_set.c_str(),
Andreas Gampec38be812016-03-23 15:03:46 -0700579 target_compiler_filter.c_str(),
Calin Juravle20c46442017-09-12 00:54:26 -0700580 class_loader_context.c_str(),
Shubham Ajmerae4e812a2017-05-25 20:09:58 -0700581 newProfile == JNI_TRUE,
582 downgrade == JNI_TRUE);
Narayan Kamath11d9f062014-04-23 20:24:57 +0100583}
584
Calin Juravleb077e152016-02-18 18:47:37 +0000585// public API
Narayan Kamath11d9f062014-04-23 20:24:57 +0100586static jboolean DexFile_isDexOptNeeded(JNIEnv* env, jclass, jstring javaFilename) {
Richard Uhler06e3f4f2016-05-24 15:42:37 -0700587 ScopedUtfChars filename_utf(env, javaFilename);
588 if (env->ExceptionCheck()) {
589 return JNI_FALSE;
590 }
591
592 const char* filename = filename_utf.c_str();
593 if ((filename == nullptr) || !OS::FileExists(filename)) {
594 LOG(ERROR) << "DexFile_isDexOptNeeded file '" << filename << "' does not exist";
595 ScopedLocalRef<jclass> fnfe(env, env->FindClass("java/io/FileNotFoundException"));
596 const char* message = (filename == nullptr) ? "<empty file name>" : filename;
597 env->ThrowNew(fnfe.get(), message);
598 return JNI_FALSE;
599 }
600
Richard Uhlerd1472a22016-04-15 15:18:56 -0700601 OatFileAssistant oat_file_assistant(filename, kRuntimeISA, false);
Richard Uhler06e3f4f2016-05-24 15:42:37 -0700602 return oat_file_assistant.IsUpToDate() ? JNI_FALSE : JNI_TRUE;
Dave Allison39c3bfb2014-01-28 18:33:52 -0800603}
604
Andreas Gampec38be812016-03-23 15:03:46 -0700605static jboolean DexFile_isValidCompilerFilter(JNIEnv* env,
606 jclass javeDexFileClass ATTRIBUTE_UNUSED,
607 jstring javaCompilerFilter) {
608 ScopedUtfChars compiler_filter(env, javaCompilerFilter);
609 if (env->ExceptionCheck()) {
610 return -1;
611 }
612
613 CompilerFilter::Filter filter;
614 return CompilerFilter::ParseCompilerFilter(compiler_filter.c_str(), &filter)
615 ? JNI_TRUE : JNI_FALSE;
616}
617
618static jboolean DexFile_isProfileGuidedCompilerFilter(JNIEnv* env,
619 jclass javeDexFileClass ATTRIBUTE_UNUSED,
620 jstring javaCompilerFilter) {
621 ScopedUtfChars compiler_filter(env, javaCompilerFilter);
622 if (env->ExceptionCheck()) {
623 return -1;
624 }
625
626 CompilerFilter::Filter filter;
627 if (!CompilerFilter::ParseCompilerFilter(compiler_filter.c_str(), &filter)) {
628 return JNI_FALSE;
629 }
630 return CompilerFilter::DependsOnProfile(filter) ? JNI_TRUE : JNI_FALSE;
631}
632
Andreas Gampe86a785d2016-03-30 17:19:48 -0700633static jstring DexFile_getNonProfileGuidedCompilerFilter(JNIEnv* env,
634 jclass javeDexFileClass ATTRIBUTE_UNUSED,
635 jstring javaCompilerFilter) {
636 ScopedUtfChars compiler_filter(env, javaCompilerFilter);
637 if (env->ExceptionCheck()) {
638 return nullptr;
639 }
640
641 CompilerFilter::Filter filter;
642 if (!CompilerFilter::ParseCompilerFilter(compiler_filter.c_str(), &filter)) {
643 return javaCompilerFilter;
644 }
645
646 CompilerFilter::Filter new_filter = CompilerFilter::GetNonProfileDependentFilterFrom(filter);
647
648 // Filter stayed the same, return input.
649 if (filter == new_filter) {
650 return javaCompilerFilter;
651 }
652
653 // Create a new string object and return.
654 std::string new_filter_str = CompilerFilter::NameOfFilter(new_filter);
655 return env->NewStringUTF(new_filter_str.c_str());
656}
657
Nicolas Geoffray741d4262017-05-03 13:08:36 +0100658static jstring DexFile_getSafeModeCompilerFilter(JNIEnv* env,
659 jclass javeDexFileClass ATTRIBUTE_UNUSED,
660 jstring javaCompilerFilter) {
661 ScopedUtfChars compiler_filter(env, javaCompilerFilter);
662 if (env->ExceptionCheck()) {
663 return nullptr;
664 }
665
666 CompilerFilter::Filter filter;
667 if (!CompilerFilter::ParseCompilerFilter(compiler_filter.c_str(), &filter)) {
668 return javaCompilerFilter;
669 }
670
671 CompilerFilter::Filter new_filter = CompilerFilter::GetSafeModeFilterFrom(filter);
672
673 // Filter stayed the same, return input.
674 if (filter == new_filter) {
675 return javaCompilerFilter;
676 }
677
678 // Create a new string object and return.
679 std::string new_filter_str = CompilerFilter::NameOfFilter(new_filter);
680 return env->NewStringUTF(new_filter_str.c_str());
681}
682
Jeff Hao90671be2016-04-22 14:00:06 -0700683static jboolean DexFile_isBackedByOatFile(JNIEnv* env, jclass, jobject cookie) {
684 const OatFile* oat_file = nullptr;
685 std::vector<const DexFile*> dex_files;
686 if (!ConvertJavaArrayToDexFiles(env, cookie, /*out */ dex_files, /* out */ oat_file)) {
687 DCHECK(env->ExceptionCheck());
688 return false;
689 }
690 return oat_file != nullptr;
691}
692
Calin Juravle367b9d82017-05-15 18:18:39 -0700693static jobjectArray DexFile_getDexFileOutputPaths(JNIEnv* env,
Philip Cuadrab55ad7c2016-07-12 16:37:40 -0700694 jclass,
695 jstring javaFilename,
696 jstring javaInstructionSet) {
697 ScopedUtfChars filename(env, javaFilename);
698 if (env->ExceptionCheck()) {
699 return nullptr;
700 }
701
702 ScopedUtfChars instruction_set(env, javaInstructionSet);
703 if (env->ExceptionCheck()) {
704 return nullptr;
705 }
706
707 const InstructionSet target_instruction_set = GetInstructionSetFromString(
708 instruction_set.c_str());
Vladimir Marko33bff252017-11-01 14:35:42 +0000709 if (target_instruction_set == InstructionSet::kNone) {
Philip Cuadrab55ad7c2016-07-12 16:37:40 -0700710 ScopedLocalRef<jclass> iae(env, env->FindClass("java/lang/IllegalArgumentException"));
711 std::string message(StringPrintf("Instruction set %s is invalid.", instruction_set.c_str()));
712 env->ThrowNew(iae.get(), message.c_str());
713 return nullptr;
714 }
715
716 OatFileAssistant oat_file_assistant(filename.c_str(),
717 target_instruction_set,
Philip Cuadrab55ad7c2016-07-12 16:37:40 -0700718 false /* load_executable */);
719
720 std::unique_ptr<OatFile> best_oat_file = oat_file_assistant.GetBestOatFile();
721 if (best_oat_file == nullptr) {
722 return nullptr;
723 }
724
Calin Juravle367b9d82017-05-15 18:18:39 -0700725 std::string oat_filename = best_oat_file->GetLocation();
726 std::string vdex_filename = GetVdexFilename(best_oat_file->GetLocation());
727
728 ScopedLocalRef<jstring> jvdexFilename(env, env->NewStringUTF(vdex_filename.c_str()));
729 if (jvdexFilename.get() == nullptr) {
730 return nullptr;
731 }
732 ScopedLocalRef<jstring> joatFilename(env, env->NewStringUTF(oat_filename.c_str()));
733 if (joatFilename.get() == nullptr) {
734 return nullptr;
735 }
736
737 // Now create output array and copy the set into it.
738 jobjectArray result = env->NewObjectArray(2,
739 WellKnownClasses::java_lang_String,
740 nullptr);
741 env->SetObjectArrayElement(result, 0, jvdexFilename.get());
742 env->SetObjectArrayElement(result, 1, joatFilename.get());
743
744 return result;
Philip Cuadrab55ad7c2016-07-12 16:37:40 -0700745}
746
Richard Uhler24ed94f2017-11-16 11:54:29 +0000747static jlong DexFile_getStaticSizeOfDexFile(JNIEnv* env, jclass, jobject cookie) {
748 const OatFile* oat_file = nullptr;
749 std::vector<const DexFile*> dex_files;
750 if (!ConvertJavaArrayToDexFiles(env, cookie, /*out */ dex_files, /* out */ oat_file)) {
751 DCHECK(env->ExceptionCheck());
752 return 0;
753 }
754
755 uint64_t file_size = 0;
756 for (auto& dex_file : dex_files) {
757 if (dex_file) {
758 file_size += dex_file->GetHeader().file_size_;
759 }
760 }
761 return static_cast<jlong>(file_size);
762}
763
Brian Carlstromf91c8c32011-09-21 17:30:34 -0700764static JNINativeMethod gMethods[] = {
Mathieu Chartier1d7d7f12015-09-25 16:48:57 -0700765 NATIVE_METHOD(DexFile, closeDexFile, "(Ljava/lang/Object;)Z"),
Mathieu Chartier00310e02015-10-17 12:46:42 -0700766 NATIVE_METHOD(DexFile,
767 defineClassNative,
768 "(Ljava/lang/String;"
769 "Ljava/lang/ClassLoader;"
770 "Ljava/lang/Object;"
771 "Ldalvik/system/DexFile;"
772 ")Ljava/lang/Class;"),
Andreas Gampe324b9bb2015-02-23 16:33:22 -0800773 NATIVE_METHOD(DexFile, getClassNameList, "(Ljava/lang/Object;)[Ljava/lang/String;"),
Brian Carlstromf91c8c32011-09-21 17:30:34 -0700774 NATIVE_METHOD(DexFile, isDexOptNeeded, "(Ljava/lang/String;)Z"),
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700775 NATIVE_METHOD(DexFile, getDexOptNeeded,
Calin Juravle20c46442017-09-12 00:54:26 -0700776 "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ZZ)I"),
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700777 NATIVE_METHOD(DexFile, openDexFileNative,
Mathieu Chartier689a7002015-11-20 10:29:42 -0800778 "(Ljava/lang/String;"
779 "Ljava/lang/String;"
780 "I"
781 "Ljava/lang/ClassLoader;"
782 "[Ldalvik/system/DexPathList$Element;"
783 ")Ljava/lang/Object;"),
Alex Lightea9465e2017-02-16 15:38:35 -0800784 NATIVE_METHOD(DexFile, createCookieWithDirectBuffer,
785 "(Ljava/nio/ByteBuffer;II)Ljava/lang/Object;"),
786 NATIVE_METHOD(DexFile, createCookieWithArray, "([BII)Ljava/lang/Object;"),
Andreas Gampec38be812016-03-23 15:03:46 -0700787 NATIVE_METHOD(DexFile, isValidCompilerFilter, "(Ljava/lang/String;)Z"),
788 NATIVE_METHOD(DexFile, isProfileGuidedCompilerFilter, "(Ljava/lang/String;)Z"),
Andreas Gampe86a785d2016-03-30 17:19:48 -0700789 NATIVE_METHOD(DexFile,
790 getNonProfileGuidedCompilerFilter,
791 "(Ljava/lang/String;)Ljava/lang/String;"),
Nicolas Geoffray741d4262017-05-03 13:08:36 +0100792 NATIVE_METHOD(DexFile,
793 getSafeModeCompilerFilter,
794 "(Ljava/lang/String;)Ljava/lang/String;"),
Jeff Hao90671be2016-04-22 14:00:06 -0700795 NATIVE_METHOD(DexFile, isBackedByOatFile, "(Ljava/lang/Object;)Z"),
Narayan Kamath8943c1d2016-05-02 13:14:48 +0100796 NATIVE_METHOD(DexFile, getDexFileStatus,
Philip Cuadrab55ad7c2016-07-12 16:37:40 -0700797 "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;"),
Calin Juravle367b9d82017-05-15 18:18:39 -0700798 NATIVE_METHOD(DexFile, getDexFileOutputPaths,
Richard Uhler24ed94f2017-11-16 11:54:29 +0000799 "(Ljava/lang/String;Ljava/lang/String;)[Ljava/lang/String;"),
800 NATIVE_METHOD(DexFile, getStaticSizeOfDexFile, "(Ljava/lang/Object;)J")
Brian Carlstromf91c8c32011-09-21 17:30:34 -0700801};
802
Brian Carlstromf91c8c32011-09-21 17:30:34 -0700803void register_dalvik_system_DexFile(JNIEnv* env) {
Elliott Hugheseac76672012-05-24 21:56:51 -0700804 REGISTER_NATIVE_METHODS("dalvik/system/DexFile");
Brian Carlstromf91c8c32011-09-21 17:30:34 -0700805}
806
807} // namespace art