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 | |
Brian Carlstrom | 1d9f52b | 2011-10-13 10:50:45 -0700 | [diff] [blame] | 17 | #include <unistd.h> |
| 18 | |
Elliott Hughes | 07ed66b | 2012-12-12 18:34:25 -0800 | [diff] [blame] | 19 | #include "base/logging.h" |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 20 | #include "class_linker.h" |
Elliott Hughes | eac7667 | 2012-05-24 21:56:51 -0700 | [diff] [blame] | 21 | #include "class_loader.h" |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 22 | #include "dex_file.h" |
Elliott Hughes | 07ed66b | 2012-12-12 18:34:25 -0800 | [diff] [blame] | 23 | #include "gc/space.h" |
Brian Carlstrom | 81f3ca1 | 2012-03-17 00:27:35 -0700 | [diff] [blame] | 24 | #include "image.h" |
Elliott Hughes | eac7667 | 2012-05-24 21:56:51 -0700 | [diff] [blame] | 25 | #include "jni_internal.h" |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame^] | 26 | #include "oat.h" |
Brian Carlstrom | 1d9f52b | 2011-10-13 10:50:45 -0700 | [diff] [blame] | 27 | #include "os.h" |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 28 | #include "runtime.h" |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 29 | #include "scoped_thread_state_change.h" |
Ian Rogers | c981848 | 2012-01-11 08:52:51 -0800 | [diff] [blame] | 30 | #include "ScopedLocalRef.h" |
Brian Carlstrom | f91c8c3 | 2011-09-21 17:30:34 -0700 | [diff] [blame] | 31 | #include "ScopedUtfChars.h" |
Elliott Hughes | eac7667 | 2012-05-24 21:56:51 -0700 | [diff] [blame] | 32 | #include "toStringArray.h" |
| 33 | #include "zip_archive.h" |
Brian Carlstrom | f91c8c3 | 2011-09-21 17:30:34 -0700 | [diff] [blame] | 34 | |
| 35 | namespace art { |
| 36 | |
Brian Carlstrom | f91c8c3 | 2011-09-21 17:30:34 -0700 | [diff] [blame] | 37 | // A smart pointer that provides read-only access to a Java string's UTF chars. |
| 38 | // Unlike libcore's NullableScopedUtfChars, this will *not* throw NullPointerException if |
| 39 | // passed a null jstring. The correct idiom is: |
| 40 | // |
| 41 | // NullableScopedUtfChars name(env, javaName); |
Brian Carlstrom | c252c3e | 2011-10-16 23:21:02 -0700 | [diff] [blame] | 42 | // if (env->ExceptionCheck()) { |
Brian Carlstrom | f91c8c3 | 2011-09-21 17:30:34 -0700 | [diff] [blame] | 43 | // return NULL; |
| 44 | // } |
| 45 | // // ... use name.c_str() |
| 46 | // |
| 47 | // TODO: rewrite to get rid of this, or change ScopedUtfChars to offer this option. |
| 48 | class NullableScopedUtfChars { |
Elliott Hughes | ba8eee1 | 2012-01-24 20:25:24 -0800 | [diff] [blame] | 49 | public: |
| 50 | NullableScopedUtfChars(JNIEnv* env, jstring s) : mEnv(env), mString(s) { |
| 51 | mUtfChars = (s != NULL) ? env->GetStringUTFChars(s, NULL) : NULL; |
| 52 | } |
| 53 | |
| 54 | ~NullableScopedUtfChars() { |
| 55 | if (mUtfChars) { |
| 56 | mEnv->ReleaseStringUTFChars(mString, mUtfChars); |
Brian Carlstrom | f91c8c3 | 2011-09-21 17:30:34 -0700 | [diff] [blame] | 57 | } |
Elliott Hughes | ba8eee1 | 2012-01-24 20:25:24 -0800 | [diff] [blame] | 58 | } |
Brian Carlstrom | f91c8c3 | 2011-09-21 17:30:34 -0700 | [diff] [blame] | 59 | |
Elliott Hughes | ba8eee1 | 2012-01-24 20:25:24 -0800 | [diff] [blame] | 60 | const char* c_str() const { |
| 61 | return mUtfChars; |
| 62 | } |
Brian Carlstrom | f91c8c3 | 2011-09-21 17:30:34 -0700 | [diff] [blame] | 63 | |
Elliott Hughes | ba8eee1 | 2012-01-24 20:25:24 -0800 | [diff] [blame] | 64 | size_t size() const { |
| 65 | return strlen(mUtfChars); |
| 66 | } |
Brian Carlstrom | f91c8c3 | 2011-09-21 17:30:34 -0700 | [diff] [blame] | 67 | |
Elliott Hughes | ba8eee1 | 2012-01-24 20:25:24 -0800 | [diff] [blame] | 68 | // Element access. |
| 69 | const char& operator[](size_t n) const { |
| 70 | return mUtfChars[n]; |
| 71 | } |
Brian Carlstrom | f91c8c3 | 2011-09-21 17:30:34 -0700 | [diff] [blame] | 72 | |
Elliott Hughes | ba8eee1 | 2012-01-24 20:25:24 -0800 | [diff] [blame] | 73 | private: |
| 74 | JNIEnv* mEnv; |
| 75 | jstring mString; |
| 76 | const char* mUtfChars; |
Brian Carlstrom | f91c8c3 | 2011-09-21 17:30:34 -0700 | [diff] [blame] | 77 | |
Elliott Hughes | ba8eee1 | 2012-01-24 20:25:24 -0800 | [diff] [blame] | 78 | // Disallow copy and assignment. |
| 79 | NullableScopedUtfChars(const NullableScopedUtfChars&); |
| 80 | void operator=(const NullableScopedUtfChars&); |
Brian Carlstrom | f91c8c3 | 2011-09-21 17:30:34 -0700 | [diff] [blame] | 81 | }; |
| 82 | |
jeffhao | c393a4f | 2011-10-19 13:46:09 -0700 | [diff] [blame] | 83 | static jint DexFile_openDexFile(JNIEnv* env, jclass, jstring javaSourceName, jstring javaOutputName, jint) { |
Brian Carlstrom | f91c8c3 | 2011-09-21 17:30:34 -0700 | [diff] [blame] | 84 | ScopedUtfChars sourceName(env, javaSourceName); |
| 85 | if (sourceName.c_str() == NULL) { |
| 86 | return 0; |
| 87 | } |
Brian Carlstrom | 5b332c8 | 2012-02-01 15:02:31 -0800 | [diff] [blame] | 88 | std::string source(sourceName.c_str()); |
Brian Carlstrom | f91c8c3 | 2011-09-21 17:30:34 -0700 | [diff] [blame] | 89 | NullableScopedUtfChars outputName(env, javaOutputName); |
Brian Carlstrom | c252c3e | 2011-10-16 23:21:02 -0700 | [diff] [blame] | 90 | if (env->ExceptionCheck()) { |
Brian Carlstrom | f91c8c3 | 2011-09-21 17:30:34 -0700 | [diff] [blame] | 91 | return 0; |
| 92 | } |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 93 | ScopedObjectAccess soa(env); |
jeffhao | c393a4f | 2011-10-19 13:46:09 -0700 | [diff] [blame] | 94 | const DexFile* dex_file; |
| 95 | if (outputName.c_str() == NULL) { |
Brian Carlstrom | 5b332c8 | 2012-02-01 15:02:31 -0800 | [diff] [blame] | 96 | dex_file = Runtime::Current()->GetClassLinker()->FindDexFileInOatFileFromDexLocation(source); |
jeffhao | c393a4f | 2011-10-19 13:46:09 -0700 | [diff] [blame] | 97 | } else { |
Brian Carlstrom | 5b332c8 | 2012-02-01 15:02:31 -0800 | [diff] [blame] | 98 | std::string output(outputName.c_str()); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 99 | dex_file = |
| 100 | Runtime::Current()->GetClassLinker()->FindOrCreateOatFileForDexLocation(source, output); |
jeffhao | c393a4f | 2011-10-19 13:46:09 -0700 | [diff] [blame] | 101 | } |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 102 | if (dex_file == NULL) { |
Brian Carlstrom | 5b332c8 | 2012-02-01 15:02:31 -0800 | [diff] [blame] | 103 | LOG(WARNING) << "Failed to open dex file: " << source; |
Elliott Hughes | eac7667 | 2012-05-24 21:56:51 -0700 | [diff] [blame] | 104 | Thread::Current()->ThrowNewExceptionF("Ljava/io/IOException;", "Unable to open dex file: %s", |
| 105 | source.c_str()); |
jeffhao | c393a4f | 2011-10-19 13:46:09 -0700 | [diff] [blame] | 106 | return 0; |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 107 | } |
| 108 | return static_cast<jint>(reinterpret_cast<uintptr_t>(dex_file)); |
| 109 | } |
| 110 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 111 | static const DexFile* toDexFile(int dex_file_address) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 112 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 113 | const DexFile* dex_file = reinterpret_cast<const DexFile*>(static_cast<uintptr_t>(dex_file_address)); |
Elliott Hughes | b3e66df | 2012-01-12 14:49:18 -0800 | [diff] [blame] | 114 | if (dex_file == NULL) { |
Elliott Hughes | eac7667 | 2012-05-24 21:56:51 -0700 | [diff] [blame] | 115 | Thread::Current()->ThrowNewExceptionF("Ljava/lang/NullPointerException;", "dex_file == null"); |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 116 | } |
| 117 | return dex_file; |
Brian Carlstrom | f91c8c3 | 2011-09-21 17:30:34 -0700 | [diff] [blame] | 118 | } |
| 119 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 120 | static void DexFile_closeDexFile(JNIEnv* env, jclass, jint cookie) { |
| 121 | const DexFile* dex_file; |
| 122 | { |
| 123 | ScopedObjectAccess soa(env); |
| 124 | dex_file = toDexFile(cookie); |
| 125 | } |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 126 | if (dex_file == NULL) { |
| 127 | return; |
| 128 | } |
| 129 | if (Runtime::Current()->GetClassLinker()->IsDexFileRegistered(*dex_file)) { |
| 130 | return; |
| 131 | } |
| 132 | delete dex_file; |
Brian Carlstrom | f91c8c3 | 2011-09-21 17:30:34 -0700 | [diff] [blame] | 133 | } |
| 134 | |
Elliott Hughes | 0512f02 | 2012-03-15 22:10:52 -0700 | [diff] [blame] | 135 | static jclass DexFile_defineClassNative(JNIEnv* env, jclass, jstring javaName, jobject javaLoader, |
| 136 | jint cookie) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 137 | ScopedObjectAccess soa(env); |
Elliott Hughes | eac7667 | 2012-05-24 21:56:51 -0700 | [diff] [blame] | 138 | const DexFile* dex_file = toDexFile(cookie); |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 139 | if (dex_file == NULL) { |
| 140 | return NULL; |
| 141 | } |
Brian Carlstrom | df14324 | 2011-10-10 18:05:34 -0700 | [diff] [blame] | 142 | ScopedUtfChars class_name(env, javaName); |
| 143 | if (class_name.c_str() == NULL) { |
| 144 | return NULL; |
| 145 | } |
Elliott Hughes | 9557241 | 2011-12-13 18:14:20 -0800 | [diff] [blame] | 146 | const std::string descriptor(DotToDescriptor(class_name.c_str())); |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 147 | const DexFile::ClassDef* dex_class_def = dex_file->FindClassDef(descriptor); |
| 148 | if (dex_class_def == NULL) { |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 149 | return NULL; |
| 150 | } |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 151 | ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); |
| 152 | class_linker->RegisterDexFile(*dex_file); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 153 | Object* class_loader_object = soa.Decode<Object*>(javaLoader); |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 154 | ClassLoader* class_loader = down_cast<ClassLoader*>(class_loader_object); |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 155 | Class* result = class_linker->DefineClass(descriptor, class_loader, *dex_file, *dex_class_def); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 156 | return soa.AddLocalReference<jclass>(result); |
Brian Carlstrom | f91c8c3 | 2011-09-21 17:30:34 -0700 | [diff] [blame] | 157 | } |
| 158 | |
Elliott Hughes | 0512f02 | 2012-03-15 22:10:52 -0700 | [diff] [blame] | 159 | static jobjectArray DexFile_getClassNameList(JNIEnv* env, jclass, jint cookie) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 160 | const DexFile* dex_file; |
| 161 | { |
| 162 | ScopedObjectAccess soa(env); |
| 163 | dex_file = toDexFile(cookie); |
| 164 | } |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 165 | if (dex_file == NULL) { |
| 166 | return NULL; |
| 167 | } |
Brian Carlstrom | 03a20ba | 2011-10-13 10:24:13 -0700 | [diff] [blame] | 168 | |
| 169 | std::vector<std::string> class_names; |
| 170 | for (size_t i = 0; i < dex_file->NumClassDefs(); ++i) { |
| 171 | const DexFile::ClassDef& class_def = dex_file->GetClassDef(i); |
| 172 | const char* descriptor = dex_file->GetClassDescriptor(class_def); |
| 173 | class_names.push_back(DescriptorToDot(descriptor)); |
| 174 | } |
| 175 | return toStringArray(env, class_names); |
Brian Carlstrom | f91c8c3 | 2011-09-21 17:30:34 -0700 | [diff] [blame] | 176 | } |
| 177 | |
Elliott Hughes | 0512f02 | 2012-03-15 22:10:52 -0700 | [diff] [blame] | 178 | static jboolean DexFile_isDexOptNeeded(JNIEnv* env, jclass, jstring javaFilename) { |
Brian Carlstrom | bf2cb16 | 2012-02-27 17:49:19 -0800 | [diff] [blame] | 179 | bool debug_logging = false; |
| 180 | |
Brian Carlstrom | 03a20ba | 2011-10-13 10:24:13 -0700 | [diff] [blame] | 181 | ScopedUtfChars filename(env, javaFilename); |
| 182 | if (filename.c_str() == NULL) { |
Brian Carlstrom | bf2cb16 | 2012-02-27 17:49:19 -0800 | [diff] [blame] | 183 | LOG(ERROR) << "DexFile_isDexOptNeeded null filename"; |
Brian Carlstrom | 1d9f52b | 2011-10-13 10:50:45 -0700 | [diff] [blame] | 184 | return JNI_TRUE; |
Brian Carlstrom | 03a20ba | 2011-10-13 10:24:13 -0700 | [diff] [blame] | 185 | } |
Brian Carlstrom | 1d9f52b | 2011-10-13 10:50:45 -0700 | [diff] [blame] | 186 | |
| 187 | if (!OS::FileExists(filename.c_str())) { |
Brian Carlstrom | bf2cb16 | 2012-02-27 17:49:19 -0800 | [diff] [blame] | 188 | LOG(ERROR) << "DexFile_isDexOptNeeded file '" << filename.c_str() << "' does not exist"; |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 189 | ScopedObjectAccess soa(env); |
Elliott Hughes | eac7667 | 2012-05-24 21:56:51 -0700 | [diff] [blame] | 190 | Thread::Current()->ThrowNewExceptionF("Ljava/io/FileNotFoundException;", "%s", filename.c_str()); |
Brian Carlstrom | 1d9f52b | 2011-10-13 10:50:45 -0700 | [diff] [blame] | 191 | return JNI_TRUE; |
| 192 | } |
| 193 | |
| 194 | // Always treat elements of the bootclasspath as up-to-date. The |
| 195 | // fact that code is running at all means that this should be true. |
Brian Carlstrom | 81f3ca1 | 2012-03-17 00:27:35 -0700 | [diff] [blame] | 196 | Runtime* runtime = Runtime::Current(); |
| 197 | ClassLinker* class_linker = runtime->GetClassLinker(); |
Brian Carlstrom | 1d9f52b | 2011-10-13 10:50:45 -0700 | [diff] [blame] | 198 | const std::vector<const DexFile*>& boot_class_path = class_linker->GetBootClassPath(); |
| 199 | for (size_t i = 0; i < boot_class_path.size(); i++) { |
| 200 | if (boot_class_path[i]->GetLocation() == filename.c_str()) { |
Brian Carlstrom | bf2cb16 | 2012-02-27 17:49:19 -0800 | [diff] [blame] | 201 | if (debug_logging) { |
| 202 | LOG(INFO) << "DexFile_isDexOptNeeded ignoring boot class path file: " << filename.c_str(); |
| 203 | } |
Brian Carlstrom | 1d9f52b | 2011-10-13 10:50:45 -0700 | [diff] [blame] | 204 | return JNI_FALSE; |
| 205 | } |
| 206 | } |
| 207 | |
Brian Carlstrom | afe2551 | 2012-06-27 17:02:58 -0700 | [diff] [blame] | 208 | // Check if we have an oat file next to the dex file. |
Brian Carlstrom | a004aa9 | 2012-02-08 18:05:09 -0800 | [diff] [blame] | 209 | std::string oat_filename(OatFile::DexFilenameToOatFilename(filename.c_str())); |
Brian Carlstrom | 1cac343 | 2012-12-12 10:56:22 -0800 | [diff] [blame] | 210 | UniquePtr<const OatFile> oat_file(OatFile::Open(oat_filename, oat_filename, NULL)); |
Brian Carlstrom | 58cbbc2 | 2012-03-29 17:52:00 -0700 | [diff] [blame] | 211 | if (oat_file.get() != NULL && oat_file->GetOatDexFile(filename.c_str()) != NULL) { |
Brian Carlstrom | afe2551 | 2012-06-27 17:02:58 -0700 | [diff] [blame] | 212 | uint32_t location_checksum; |
| 213 | // If we have no classes.dex checksum such as in a user build, assume up-to-date. |
| 214 | if (!DexFile::GetChecksum(filename.c_str(), location_checksum)) { |
| 215 | if (debug_logging) { |
| 216 | LOG(INFO) << "DexFile_isDexOptNeeded ignoring precompiled stripped file: " << filename.c_str(); |
| 217 | } |
| 218 | return JNI_FALSE; |
Brian Carlstrom | bf2cb16 | 2012-02-27 17:49:19 -0800 | [diff] [blame] | 219 | } |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 220 | ScopedObjectAccess soa(env); |
Brian Carlstrom | afe2551 | 2012-06-27 17:02:58 -0700 | [diff] [blame] | 221 | if (ClassLinker::VerifyOatFileChecksums(oat_file.get(), filename.c_str(), location_checksum)) { |
| 222 | if (debug_logging) { |
| 223 | LOG(INFO) << "DexFile_isDexOptNeeded precompiled file " << oat_filename |
| 224 | << " is up-to-date checksum compared to " << filename.c_str(); |
| 225 | } |
| 226 | return JNI_FALSE; |
| 227 | } |
Brian Carlstrom | fad7143 | 2011-10-16 20:25:10 -0700 | [diff] [blame] | 228 | } |
Brian Carlstrom | 5b332c8 | 2012-02-01 15:02:31 -0800 | [diff] [blame] | 229 | |
Brian Carlstrom | a004aa9 | 2012-02-08 18:05:09 -0800 | [diff] [blame] | 230 | // Check if we have an oat file in the cache |
| 231 | std::string cache_location(GetArtCacheFilenameOrDie(oat_filename)); |
Brian Carlstrom | 1cac343 | 2012-12-12 10:56:22 -0800 | [diff] [blame] | 232 | oat_file.reset(OatFile::Open(cache_location, oat_filename, NULL)); |
Brian Carlstrom | 58cbbc2 | 2012-03-29 17:52:00 -0700 | [diff] [blame] | 233 | if (oat_file.get() == NULL) { |
Brian Carlstrom | bf2cb16 | 2012-02-27 17:49:19 -0800 | [diff] [blame] | 234 | LOG(INFO) << "DexFile_isDexOptNeeded cache file " << cache_location |
| 235 | << " does not exist for " << filename.c_str(); |
Brian Carlstrom | 5b332c8 | 2012-02-01 15:02:31 -0800 | [diff] [blame] | 236 | return JNI_TRUE; |
| 237 | } |
| 238 | |
Mathieu Chartier | b062fdd | 2012-07-03 09:51:48 -0700 | [diff] [blame] | 239 | Heap* heap = runtime->GetHeap(); |
| 240 | const Spaces& spaces = heap->GetSpaces(); |
| 241 | // TODO: C++0x auto |
| 242 | for (Spaces::const_iterator cur = spaces.begin(); cur != spaces.end(); ++cur) { |
| 243 | if ((*cur)->IsImageSpace()) { |
| 244 | // TODO: Ensure this works with multiple image spaces. |
| 245 | const ImageHeader& image_header = (*cur)->AsImageSpace()->GetImageHeader(); |
Brian Carlstrom | 28db012 | 2012-10-18 16:20:41 -0700 | [diff] [blame] | 246 | if (oat_file->GetOatHeader().GetImageFileLocationOatChecksum() != image_header.GetOatChecksum()) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 247 | ScopedObjectAccess soa(env); |
Mathieu Chartier | b062fdd | 2012-07-03 09:51:48 -0700 | [diff] [blame] | 248 | LOG(INFO) << "DexFile_isDexOptNeeded cache file " << cache_location |
Brian Carlstrom | 28db012 | 2012-10-18 16:20:41 -0700 | [diff] [blame] | 249 | << " has out-of-date oat checksum compared to " |
| 250 | << image_header.GetImageRoot(ImageHeader::kOatLocation)->AsString()->ToModifiedUtf8(); |
| 251 | return JNI_TRUE; |
| 252 | } |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame^] | 253 | if (oat_file->GetOatHeader().GetImageFileLocationOatDataBegin() |
| 254 | != reinterpret_cast<uint32_t>(image_header.GetOatDataBegin())) { |
Brian Carlstrom | 28db012 | 2012-10-18 16:20:41 -0700 | [diff] [blame] | 255 | ScopedObjectAccess soa(env); |
| 256 | LOG(INFO) << "DexFile_isDexOptNeeded cache file " << cache_location |
| 257 | << " has out-of-date oat begin compared to " |
Mathieu Chartier | b062fdd | 2012-07-03 09:51:48 -0700 | [diff] [blame] | 258 | << image_header.GetImageRoot(ImageHeader::kOatLocation)->AsString()->ToModifiedUtf8(); |
| 259 | return JNI_TRUE; |
| 260 | } |
| 261 | } |
Brian Carlstrom | 81f3ca1 | 2012-03-17 00:27:35 -0700 | [diff] [blame] | 262 | } |
| 263 | |
Brian Carlstrom | a004aa9 | 2012-02-08 18:05:09 -0800 | [diff] [blame] | 264 | uint32_t location_checksum; |
| 265 | if (!DexFile::GetChecksum(filename.c_str(), location_checksum)) { |
Brian Carlstrom | bf2cb16 | 2012-02-27 17:49:19 -0800 | [diff] [blame] | 266 | LOG(ERROR) << "DexFile_isDexOptNeeded failed to compute checksum of " << filename.c_str(); |
Brian Carlstrom | a004aa9 | 2012-02-08 18:05:09 -0800 | [diff] [blame] | 267 | return JNI_TRUE; |
| 268 | } |
| 269 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 270 | ScopedObjectAccess soa(env); |
Brian Carlstrom | afe2551 | 2012-06-27 17:02:58 -0700 | [diff] [blame] | 271 | if (!ClassLinker::VerifyOatFileChecksums(oat_file.get(), filename.c_str(), location_checksum)) { |
Brian Carlstrom | bf2cb16 | 2012-02-27 17:49:19 -0800 | [diff] [blame] | 272 | LOG(INFO) << "DexFile_isDexOptNeeded cache file " << cache_location |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 273 | << " has out-of-date checksum compared to " << filename.c_str(); |
Brian Carlstrom | 5b332c8 | 2012-02-01 15:02:31 -0800 | [diff] [blame] | 274 | return JNI_TRUE; |
| 275 | } |
| 276 | |
Brian Carlstrom | bf2cb16 | 2012-02-27 17:49:19 -0800 | [diff] [blame] | 277 | if (debug_logging) { |
| 278 | LOG(INFO) << "DexFile_isDexOptNeeded cache file " << cache_location |
| 279 | << " is up-to-date for " << filename.c_str(); |
| 280 | } |
Brian Carlstrom | f91c8c3 | 2011-09-21 17:30:34 -0700 | [diff] [blame] | 281 | return JNI_FALSE; |
| 282 | } |
| 283 | |
| 284 | static JNINativeMethod gMethods[] = { |
| 285 | NATIVE_METHOD(DexFile, closeDexFile, "(I)V"), |
Ian Rogers | 66a556f | 2012-02-14 00:05:38 -0800 | [diff] [blame] | 286 | NATIVE_METHOD(DexFile, defineClassNative, "(Ljava/lang/String;Ljava/lang/ClassLoader;I)Ljava/lang/Class;"), |
Brian Carlstrom | f91c8c3 | 2011-09-21 17:30:34 -0700 | [diff] [blame] | 287 | NATIVE_METHOD(DexFile, getClassNameList, "(I)[Ljava/lang/String;"), |
| 288 | NATIVE_METHOD(DexFile, isDexOptNeeded, "(Ljava/lang/String;)Z"), |
| 289 | NATIVE_METHOD(DexFile, openDexFile, "(Ljava/lang/String;Ljava/lang/String;I)I"), |
| 290 | }; |
| 291 | |
Brian Carlstrom | f91c8c3 | 2011-09-21 17:30:34 -0700 | [diff] [blame] | 292 | void register_dalvik_system_DexFile(JNIEnv* env) { |
Elliott Hughes | eac7667 | 2012-05-24 21:56:51 -0700 | [diff] [blame] | 293 | REGISTER_NATIVE_METHODS("dalvik/system/DexFile"); |
Brian Carlstrom | f91c8c3 | 2011-09-21 17:30:34 -0700 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | } // namespace art |