Alex Light | 2e960a0 | 2016-05-03 15:01:06 -0700 | [diff] [blame] | 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 | |
Alex Light | 2e960a0 | 2016-05-03 15:01:06 -0700 | [diff] [blame] | 17 | #include <pthread.h> |
Andreas Gampe | 8cf9cb3 | 2017-07-19 09:28:38 -0700 | [diff] [blame^] | 18 | |
| 19 | #include <cstdio> |
| 20 | #include <iostream> |
Alex Light | 2e960a0 | 2016-05-03 15:01:06 -0700 | [diff] [blame] | 21 | #include <vector> |
| 22 | |
Andreas Gampe | 8cf9cb3 | 2017-07-19 09:28:38 -0700 | [diff] [blame^] | 23 | #include "jni.h" |
| 24 | |
Alex Light | 2e960a0 | 2016-05-03 15:01:06 -0700 | [diff] [blame] | 25 | #include "gc/heap.h" |
| 26 | #include "gc/space/image_space.h" |
| 27 | #include "gc/space/space-inl.h" |
| 28 | #include "image.h" |
Alex Light | 2e960a0 | 2016-05-03 15:01:06 -0700 | [diff] [blame] | 29 | #include "mirror/class.h" |
| 30 | #include "runtime.h" |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 31 | #include "scoped_thread_state_change-inl.h" |
Alex Light | 2e960a0 | 2016-05-03 15:01:06 -0700 | [diff] [blame] | 32 | |
| 33 | namespace art { |
| 34 | |
| 35 | namespace { |
| 36 | |
| 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 | |
| 51 | extern "C" JNIEXPORT jboolean JNICALL Java_Main_checkAppImageContains(JNIEnv*, jclass, jclass c) { |
| 52 | ScopedObjectAccess soa(Thread::Current()); |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 53 | ObjPtr<mirror::Class> klass_ptr = soa.Decode<mirror::Class>(c); |
Alex Light | 2e960a0 | 2016-05-03 15:01:06 -0700 | [diff] [blame] | 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()) { |
Mathieu Chartier | 1cc62e4 | 2016-10-03 18:01:28 -0700 | [diff] [blame] | 59 | if (image_space->HasAddress(klass_ptr.Ptr())) { |
Alex Light | 2e960a0 | 2016-05-03 15:01:06 -0700 | [diff] [blame] | 60 | return JNI_TRUE; |
| 61 | } |
| 62 | } |
| 63 | } |
| 64 | } |
| 65 | return JNI_FALSE; |
| 66 | } |
| 67 | |
Mathieu Chartier | f1dd69a | 2017-06-08 23:30:15 +0000 | [diff] [blame] | 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 | |
Alex Light | 2e960a0 | 2016-05-03 15:01:06 -0700 | [diff] [blame] | 74 | } // namespace |
| 75 | |
| 76 | } // namespace art |