Home | History | Annotate | Download | only in 661-oat-writer-layout
      1 /*
      2  * Copyright (C) 2017 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 "jni.h"
     18 
     19 #include "art_method.h"
     20 #include "class_linker.h"
     21 #include "mirror/class-inl.h"
     22 #include "mirror/dex_cache.h"
     23 #include "mirror/executable.h"
     24 #include "mirror/object-inl.h"
     25 #include "obj_ptr.h"
     26 #include "oat_file.h"
     27 #include "runtime.h"
     28 #include "scoped_thread_state_change-inl.h"
     29 #include "thread.h"
     30 
     31 namespace art {
     32 namespace {
     33 
     34 extern "C" JNIEXPORT jlong JNICALL Java_Main_getOatMethodQuickCode(JNIEnv* env,
     35                                                                    jclass,
     36                                                                    jobject method) {
     37   CHECK(method != nullptr);
     38   ScopedObjectAccess soa(env);
     39   ObjPtr<mirror::Executable> exec = soa.Decode<mirror::Executable>(method);
     40   ArtMethod* art_method = exec->GetArtMethod();
     41 
     42   const void* quick_code =
     43     art_method->GetOatMethodQuickCode(Runtime::Current()->GetClassLinker()->GetImagePointerSize());
     44 
     45   return static_cast<jlong>(reinterpret_cast<uintptr_t>(quick_code));
     46 }
     47 
     48 extern "C" JNIEXPORT jboolean JNICALL Java_Main_hasOatCompiledCode(JNIEnv* env,
     49                                                                    jclass,
     50                                                                    jclass kls) {
     51   CHECK(kls != nullptr);
     52   ScopedObjectAccess soa(env);
     53   Thread* self = Thread::Current();
     54 
     55   ObjPtr<mirror::Class> klass_ptr = self->DecodeJObject(kls)->AsClass();
     56 
     57   bool found = false;
     58   OatFile::OatClass oat_class = OatFile::FindOatClass(*klass_ptr->GetDexCache()->GetDexFile(),
     59                                                       klass_ptr->GetDexClassDefIndex(),
     60                                                       /* out */ &found);
     61 
     62   if (!found) {
     63     return false;
     64   }
     65 
     66   OatClassType type = oat_class.GetType();
     67   switch (type) {
     68     case kOatClassAllCompiled:
     69     case kOatClassSomeCompiled:
     70       return true;
     71 
     72     case kOatClassNoneCompiled:
     73     case kOatClassMax:
     74       return false;
     75   }
     76 
     77   LOG(FATAL) << "unhandled switch statement";
     78   UNREACHABLE();
     79 }
     80 
     81 }  // namespace
     82 }  // namespace art
     83