blob: 42211f7548ffa0580529fea5f317bfdcf6552bec [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 <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"
Mathieu Chartier0795f232016-09-27 18:43:30 -070029#include "scoped_thread_state_change-inl.h"
Alex Light2e960a02016-05-03 15:01:06 -070030
31namespace art {
32
33namespace {
34
35extern "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
49extern "C" JNIEXPORT jboolean JNICALL Java_Main_checkAppImageContains(JNIEnv*, jclass, jclass c) {
50 ScopedObjectAccess soa(Thread::Current());
Mathieu Chartier0795f232016-09-27 18:43:30 -070051 ObjPtr<mirror::Class> klass_ptr = soa.Decode<mirror::Class>(c);
Alex Light2e960a02016-05-03 15:01:06 -070052 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()) {
Mathieu Chartier1cc62e42016-10-03 18:01:28 -070057 if (image_space->HasAddress(klass_ptr.Ptr())) {
Alex Light2e960a02016-05-03 15:01:06 -070058 return JNI_TRUE;
59 }
60 }
61 }
62 }
63 return JNI_FALSE;
64}
65
66} // namespace
67
68} // namespace art