blob: 51cd5b80d5715f63e2d74d9449b118d5da423121 [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"
18#include "mirror/dex_cache.h"
19#include "mirror/object-inl.h"
Ian Rogers1eb512d2013-10-18 15:42:20 -070020#include "scoped_fast_native_object_access.h"
Ian Rogers8b2c0b92013-09-19 02:56:49 -070021#include "well_known_classes.h"
22
23namespace art {
24
25static jobject DexCache_getDexNative(JNIEnv* env, jobject javaDexCache) {
Ian Rogers1eb512d2013-10-18 15:42:20 -070026 ScopedFastNativeObjectAccess soa(env);
Ian Rogers8b2c0b92013-09-19 02:56:49 -070027 mirror::DexCache* dex_cache = soa.Decode<mirror::DexCache*>(javaDexCache);
28 // Should only be called while holding the lock on the dex cache.
Ian Rogersd9c4fc92013-10-01 19:45:43 -070029 DCHECK_EQ(dex_cache->GetLockOwnerThreadId(), soa.Self()->GetThreadId());
Ian Rogers8b2c0b92013-09-19 02:56:49 -070030 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
48static JNINativeMethod gMethods[] = {
Ian Rogers1eb512d2013-10-18 15:42:20 -070049 NATIVE_METHOD(DexCache, getDexNative, "!()Lcom/android/dex/Dex;"),
Ian Rogers8b2c0b92013-09-19 02:56:49 -070050};
51
52void register_java_lang_DexCache(JNIEnv* env) {
53 REGISTER_NATIVE_METHODS("java/lang/DexCache");
54}
55
56} // namespace art