blob: 3e533ad62ecc8e3bd193b79bf00b666ec0ba7e66 [file] [log] [blame]
Alex Light9dcc4572014-08-14 14:16:26 -07001/*
2 * Copyright (C) 2014 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 "class_linker.h"
18#include "dex_file-inl.h"
Alex Light22cbec42015-09-18 17:09:43 -070019#include "gc/heap.h"
20#include "gc/space/image_space.h"
Alex Light9dcc4572014-08-14 14:16:26 -070021#include "mirror/class-inl.h"
Alex Light22cbec42015-09-18 17:09:43 -070022#include "runtime.h"
Alex Light9dcc4572014-08-14 14:16:26 -070023#include "scoped_thread_state_change.h"
24#include "thread.h"
25
26namespace art {
27
28class NoPatchoatTest {
29 public:
Igor Murashkin96e83932014-10-29 19:45:42 -070030 static const OatFile::OatDexFile* getOatDexFile(jclass cls) {
Alex Light9dcc4572014-08-14 14:16:26 -070031 ScopedObjectAccess soa(Thread::Current());
32 mirror::Class* klass = soa.Decode<mirror::Class*>(cls);
33 const DexFile& dex_file = klass->GetDexFile();
Richard Uhler07b3c232015-03-31 15:57:54 -070034 return dex_file.GetOatDexFile();
Igor Murashkin96e83932014-10-29 19:45:42 -070035 }
36
Alex Light22cbec42015-09-18 17:09:43 -070037 static bool isRelocationDeltaZero() {
38 gc::space::ImageSpace* space = Runtime::Current()->GetHeap()->GetImageSpace();
39 return space != nullptr && space->GetImageHeader().GetPatchDelta() == 0;
40 }
41
Igor Murashkin96e83932014-10-29 19:45:42 -070042 static bool hasExecutableOat(jclass cls) {
43 const OatFile::OatDexFile* oat_dex_file = getOatDexFile(cls);
44
Vladimir Markoaa4497d2014-09-05 14:01:17 +010045 return oat_dex_file != nullptr && oat_dex_file->GetOatFile()->IsExecutable();
Alex Light9dcc4572014-08-14 14:16:26 -070046 }
Igor Murashkin96e83932014-10-29 19:45:42 -070047
48 static bool isPic(jclass cls) {
49 const OatFile::OatDexFile* oat_dex_file = getOatDexFile(cls);
50
51 if (oat_dex_file == nullptr) {
52 return false;
53 }
54
55 const OatFile* oat_file = oat_dex_file->GetOatFile();
56 return oat_file->IsPic();
57 }
Alex Light9dcc4572014-08-14 14:16:26 -070058};
59
Alex Light22cbec42015-09-18 17:09:43 -070060extern "C" JNIEXPORT jboolean JNICALL Java_Main_isRelocationDeltaZero(JNIEnv*, jclass) {
61 return NoPatchoatTest::isRelocationDeltaZero();
62}
63
Alex Light9dcc4572014-08-14 14:16:26 -070064extern "C" JNIEXPORT jboolean JNICALL Java_Main_hasExecutableOat(JNIEnv*, jclass cls) {
65 return NoPatchoatTest::hasExecutableOat(cls);
66}
67
Igor Murashkin96e83932014-10-29 19:45:42 -070068extern "C" JNIEXPORT jboolean JNICALL Java_Main_isPic(JNIEnv*, jclass cls) {
69 return NoPatchoatTest::isPic(cls);
70}
71
Alex Light9dcc4572014-08-14 14:16:26 -070072} // namespace art