Ian Rogers | 8b2c0b9 | 2013-09-19 02:56:49 -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 | |
| 17 | #include "dex_file.h" |
| 18 | #include "mirror/dex_cache.h" |
| 19 | #include "mirror/object-inl.h" |
Ian Rogers | 1eb512d | 2013-10-18 15:42:20 -0700 | [diff] [blame] | 20 | #include "scoped_fast_native_object_access.h" |
Ian Rogers | 8b2c0b9 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 21 | #include "well_known_classes.h" |
| 22 | |
| 23 | namespace art { |
| 24 | |
| 25 | static jobject DexCache_getDexNative(JNIEnv* env, jobject javaDexCache) { |
Ian Rogers | 1eb512d | 2013-10-18 15:42:20 -0700 | [diff] [blame] | 26 | ScopedFastNativeObjectAccess soa(env); |
Ian Rogers | 8b2c0b9 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 27 | mirror::DexCache* dex_cache = soa.Decode<mirror::DexCache*>(javaDexCache); |
| 28 | // Should only be called while holding the lock on the dex cache. |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 29 | DCHECK_EQ(dex_cache->GetLockOwnerThreadId(), soa.Self()->GetThreadId()); |
Ian Rogers | 8b2c0b9 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 30 | const DexFile* dex_file = dex_cache->GetDexFile(); |
| 31 | if (dex_file == NULL) { |
| 32 | return NULL; |
| 33 | } |
| 34 | void* address = const_cast<void*>(reinterpret_cast<const void*>(dex_file->Begin())); |
| 35 | jobject byte_buffer = env->NewDirectByteBuffer(address, dex_file->Size()); |
| 36 | if (byte_buffer == NULL) { |
| 37 | DCHECK(soa.Self()->IsExceptionPending()); |
| 38 | return NULL; |
| 39 | } |
| 40 | |
| 41 | jvalue args[1]; |
| 42 | args[0].l = byte_buffer; |
| 43 | return env->CallStaticObjectMethodA(WellKnownClasses::com_android_dex_Dex, |
| 44 | WellKnownClasses::com_android_dex_Dex_create, |
| 45 | args); |
| 46 | } |
| 47 | |
| 48 | static JNINativeMethod gMethods[] = { |
Ian Rogers | 1eb512d | 2013-10-18 15:42:20 -0700 | [diff] [blame] | 49 | NATIVE_METHOD(DexCache, getDexNative, "!()Lcom/android/dex/Dex;"), |
Ian Rogers | 8b2c0b9 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 50 | }; |
| 51 | |
| 52 | void register_java_lang_DexCache(JNIEnv* env) { |
| 53 | REGISTER_NATIVE_METHODS("java/lang/DexCache"); |
| 54 | } |
| 55 | |
| 56 | } // namespace art |