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