Home | History | Annotate | Download | only in native
      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"
     20 #include "scoped_thread_state_change.h"
     21 #include "well_known_classes.h"
     22 
     23 namespace art {
     24 
     25 static jobject DexCache_getDexNative(JNIEnv* env, jobject javaDexCache) {
     26   ScopedObjectAccess soa(env);
     27   mirror::DexCache* dex_cache = soa.Decode<mirror::DexCache*>(javaDexCache);
     28   // Should only be called while holding the lock on the dex cache.
     29   DCHECK_EQ(dex_cache->GetThinLockId(), soa.Self()->GetThinLockId());
     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[] = {
     49   NATIVE_METHOD(DexCache, getDexNative, "()Lcom/android/dex/Dex;"),
     50 };
     51 
     52 void register_java_lang_DexCache(JNIEnv* env) {
     53   REGISTER_NATIVE_METHODS("java/lang/DexCache");
     54 }
     55 
     56 }  // namespace art
     57