blob: 3236bde5a2dcc49051f8d6d511d357b9e3ebf303 [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"
Vladimir Marko97d7e1c2016-10-04 14:44:28 +010022#include "oat_file.h"
Alex Light22cbec42015-09-18 17:09:43 -070023#include "runtime.h"
Mathieu Chartier0795f232016-09-27 18:43:30 -070024#include "scoped_thread_state_change-inl.h"
Alex Light9dcc4572014-08-14 14:16:26 -070025#include "thread.h"
26
27namespace art {
28
29class NoPatchoatTest {
30 public:
Igor Murashkin96e83932014-10-29 19:45:42 -070031 static const OatFile::OatDexFile* getOatDexFile(jclass cls) {
Alex Light9dcc4572014-08-14 14:16:26 -070032 ScopedObjectAccess soa(Thread::Current());
Mathieu Chartier0795f232016-09-27 18:43:30 -070033 ObjPtr<mirror::Class> klass = soa.Decode<mirror::Class>(cls);
Alex Light9dcc4572014-08-14 14:16:26 -070034 const DexFile& dex_file = klass->GetDexFile();
Richard Uhler07b3c232015-03-31 15:57:54 -070035 return dex_file.GetOatDexFile();
Igor Murashkin96e83932014-10-29 19:45:42 -070036 }
37
Alex Light22cbec42015-09-18 17:09:43 -070038 static bool isRelocationDeltaZero() {
Jeff Haodcdc85b2015-12-04 14:06:18 -080039 std::vector<gc::space::ImageSpace*> spaces =
40 Runtime::Current()->GetHeap()->GetBootImageSpaces();
41 return !spaces.empty() && spaces[0]->GetImageHeader().GetPatchDelta() == 0;
Alex Light22cbec42015-09-18 17:09:43 -070042 }
43
Igor Murashkin96e83932014-10-29 19:45:42 -070044 static bool hasExecutableOat(jclass cls) {
45 const OatFile::OatDexFile* oat_dex_file = getOatDexFile(cls);
46
Vladimir Markoaa4497d2014-09-05 14:01:17 +010047 return oat_dex_file != nullptr && oat_dex_file->GetOatFile()->IsExecutable();
Alex Light9dcc4572014-08-14 14:16:26 -070048 }
Igor Murashkin96e83932014-10-29 19:45:42 -070049
David Brazdil1ed44492016-02-01 18:00:06 +000050 static bool needsRelocation(jclass cls) {
Igor Murashkin96e83932014-10-29 19:45:42 -070051 const OatFile::OatDexFile* oat_dex_file = getOatDexFile(cls);
52
53 if (oat_dex_file == nullptr) {
54 return false;
55 }
56
57 const OatFile* oat_file = oat_dex_file->GetOatFile();
Andreas Gampe7bcfcb82016-03-23 15:31:51 +000058 return !oat_file->IsPic()
Vladimir Marko8c185bf2016-05-23 15:32:42 +010059 && CompilerFilter::IsBytecodeCompilationEnabled(oat_file->GetCompilerFilter());
Igor Murashkin96e83932014-10-29 19:45:42 -070060 }
Alex Light9dcc4572014-08-14 14:16:26 -070061};
62
Alex Light22cbec42015-09-18 17:09:43 -070063extern "C" JNIEXPORT jboolean JNICALL Java_Main_isRelocationDeltaZero(JNIEnv*, jclass) {
64 return NoPatchoatTest::isRelocationDeltaZero();
65}
66
Alex Light9dcc4572014-08-14 14:16:26 -070067extern "C" JNIEXPORT jboolean JNICALL Java_Main_hasExecutableOat(JNIEnv*, jclass cls) {
68 return NoPatchoatTest::hasExecutableOat(cls);
69}
70
David Brazdil1ed44492016-02-01 18:00:06 +000071extern "C" JNIEXPORT jboolean JNICALL Java_Main_needsRelocation(JNIEnv*, jclass cls) {
72 return NoPatchoatTest::needsRelocation(cls);
Igor Murashkin96e83932014-10-29 19:45:42 -070073}
74
Alex Light9dcc4572014-08-14 14:16:26 -070075} // namespace art