blob: dc16a84928bd24088d4b1662cd9e91dd295aaa0c [file] [log] [blame]
Mathieu Chartier00fbe4f2019-01-02 16:52:38 -08001/*
2 * Copyright 2019 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 "jni.h"
18
19#include "gc/heap.h"
20#include "gc/space/image_space.h"
21#include "gc/space/space-inl.h"
22#include "gc/space/region_space.h"
23#include "image.h"
24#include "mirror/class.h"
25#include "runtime.h"
26#include "scoped_thread_state_change-inl.h"
27
28namespace art {
29
30namespace {
31
32extern "C" JNIEXPORT jint JNICALL Java_Main_getRegionSize(JNIEnv*, jclass) {
33 return gc::space::RegionSpace::kRegionSize;
34}
35
36extern "C" JNIEXPORT jint JNICALL Java_Main_checkAppImageSectionSize(JNIEnv*, jclass, jclass c) {
37 ScopedObjectAccess soa(Thread::Current());
38 ObjPtr<mirror::Class> klass_ptr = soa.Decode<mirror::Class>(c);
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() && image_space->HasAddress(klass_ptr.Ptr())) {
44 return image_header.GetObjectsSection().Size();
45 }
46 }
47 }
48 return 0;
49}
50
51} // namespace
52
53} // namespace art