blob: 498ea1d6064c8044f9ee5e1cff0ea6d8922820f6 [file] [log] [blame]
Alex Light2e960a02016-05-03 15:01:06 -07001/*
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
Alex Light2e960a02016-05-03 15:01:06 -070017#include <pthread.h>
Andreas Gampe8cf9cb32017-07-19 09:28:38 -070018
19#include <cstdio>
20#include <iostream>
Alex Light2e960a02016-05-03 15:01:06 -070021#include <vector>
22
Andreas Gampe8cf9cb32017-07-19 09:28:38 -070023#include "jni.h"
24
Alex Light2e960a02016-05-03 15:01:06 -070025#include "gc/heap.h"
26#include "gc/space/image_space.h"
27#include "gc/space/space-inl.h"
28#include "image.h"
Alex Light2e960a02016-05-03 15:01:06 -070029#include "mirror/class.h"
30#include "runtime.h"
Mathieu Chartier0795f232016-09-27 18:43:30 -070031#include "scoped_thread_state_change-inl.h"
Alex Light2e960a02016-05-03 15:01:06 -070032
33namespace art {
34
35namespace {
36
37extern "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
51extern "C" JNIEXPORT jboolean JNICALL Java_Main_checkAppImageContains(JNIEnv*, jclass, jclass c) {
52 ScopedObjectAccess soa(Thread::Current());
Mathieu Chartier0795f232016-09-27 18:43:30 -070053 ObjPtr<mirror::Class> klass_ptr = soa.Decode<mirror::Class>(c);
Alex Light2e960a02016-05-03 15:01:06 -070054 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()) {
Mathieu Chartier1cc62e42016-10-03 18:01:28 -070059 if (image_space->HasAddress(klass_ptr.Ptr())) {
Alex Light2e960a02016-05-03 15:01:06 -070060 return JNI_TRUE;
61 }
62 }
63 }
64 }
65 return JNI_FALSE;
66}
67
Mathieu Chartierf1dd69a2017-06-08 23:30:15 +000068extern "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
Alex Light2e960a02016-05-03 15:01:06 -070074} // namespace
75
76} // namespace art