blob: c1c6c26047f239319a25c62a1fe95d2819b89f07 [file] [log] [blame]
Ian Rogers8b2c0b92013-09-19 02:56:49 -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
17#include "dex_file.h"
Ian Rogers68d8b422014-07-17 11:09:10 -070018#include "jni_internal.h"
Ian Rogers8b2c0b92013-09-19 02:56:49 -070019#include "mirror/dex_cache.h"
20#include "mirror/object-inl.h"
Ian Rogers1eb512d2013-10-18 15:42:20 -070021#include "scoped_fast_native_object_access.h"
Ian Rogers8b2c0b92013-09-19 02:56:49 -070022#include "well_known_classes.h"
23
24namespace art {
25
26static jobject DexCache_getDexNative(JNIEnv* env, jobject javaDexCache) {
Ian Rogers1eb512d2013-10-18 15:42:20 -070027 ScopedFastNativeObjectAccess soa(env);
Ian Rogers8b2c0b92013-09-19 02:56:49 -070028 mirror::DexCache* dex_cache = soa.Decode<mirror::DexCache*>(javaDexCache);
29 // Should only be called while holding the lock on the dex cache.
Ian Rogersd9c4fc92013-10-01 19:45:43 -070030 DCHECK_EQ(dex_cache->GetLockOwnerThreadId(), soa.Self()->GetThreadId());
Ian Rogers8b2c0b92013-09-19 02:56:49 -070031 const DexFile* dex_file = dex_cache->GetDexFile();
32 if (dex_file == NULL) {
33 return NULL;
34 }
35 void* address = const_cast<void*>(reinterpret_cast<const void*>(dex_file->Begin()));
36 jobject byte_buffer = env->NewDirectByteBuffer(address, dex_file->Size());
37 if (byte_buffer == NULL) {
38 DCHECK(soa.Self()->IsExceptionPending());
39 return NULL;
40 }
41
42 jvalue args[1];
43 args[0].l = byte_buffer;
44 return env->CallStaticObjectMethodA(WellKnownClasses::com_android_dex_Dex,
45 WellKnownClasses::com_android_dex_Dex_create,
46 args);
47}
48
49static JNINativeMethod gMethods[] = {
Ian Rogers1eb512d2013-10-18 15:42:20 -070050 NATIVE_METHOD(DexCache, getDexNative, "!()Lcom/android/dex/Dex;"),
Ian Rogers8b2c0b92013-09-19 02:56:49 -070051};
52
53void register_java_lang_DexCache(JNIEnv* env) {
54 REGISTER_NATIVE_METHODS("java/lang/DexCache");
55}
56
57} // namespace art