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