Home | History | Annotate | Download | only in 596-app-images
      1 /*
      2  * Copyright 2016 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 <iostream>
     18 #include <pthread.h>
     19 #include <stdio.h>
     20 #include <vector>
     21 
     22 #include "gc/heap.h"
     23 #include "gc/space/image_space.h"
     24 #include "gc/space/space-inl.h"
     25 #include "image.h"
     26 #include "jni.h"
     27 #include "mirror/class.h"
     28 #include "runtime.h"
     29 #include "scoped_thread_state_change-inl.h"
     30 
     31 namespace art {
     32 
     33 namespace {
     34 
     35 extern "C" JNIEXPORT jboolean JNICALL Java_Main_checkAppImageLoaded(JNIEnv*, jclass) {
     36   ScopedObjectAccess soa(Thread::Current());
     37   for (auto* space : Runtime::Current()->GetHeap()->GetContinuousSpaces()) {
     38     if (space->IsImageSpace()) {
     39       auto* image_space = space->AsImageSpace();
     40       const auto& image_header = image_space->GetImageHeader();
     41       if (image_header.IsAppImage()) {
     42         return JNI_TRUE;
     43       }
     44     }
     45   }
     46   return JNI_FALSE;
     47 }
     48 
     49 extern "C" JNIEXPORT jboolean JNICALL Java_Main_checkAppImageContains(JNIEnv*, jclass, jclass c) {
     50   ScopedObjectAccess soa(Thread::Current());
     51   ObjPtr<mirror::Class> klass_ptr = soa.Decode<mirror::Class>(c);
     52   for (auto* space : Runtime::Current()->GetHeap()->GetContinuousSpaces()) {
     53     if (space->IsImageSpace()) {
     54       auto* image_space = space->AsImageSpace();
     55       const auto& image_header = image_space->GetImageHeader();
     56       if (image_header.IsAppImage()) {
     57         if (image_space->HasAddress(klass_ptr.Ptr())) {
     58           return JNI_TRUE;
     59         }
     60       }
     61     }
     62   }
     63   return JNI_FALSE;
     64 }
     65 
     66 }  // namespace
     67 
     68 }  // namespace art
     69