Alex Light | 9dcc457 | 2014-08-14 14:16:26 -0700 | [diff] [blame] | 1 | /* |
| 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 Light | 22cbec4 | 2015-09-18 17:09:43 -0700 | [diff] [blame] | 19 | #include "gc/heap.h" |
| 20 | #include "gc/space/image_space.h" |
Alex Light | 9dcc457 | 2014-08-14 14:16:26 -0700 | [diff] [blame] | 21 | #include "mirror/class-inl.h" |
Vladimir Marko | 97d7e1c | 2016-10-04 14:44:28 +0100 | [diff] [blame] | 22 | #include "oat_file.h" |
Alex Light | 22cbec4 | 2015-09-18 17:09:43 -0700 | [diff] [blame] | 23 | #include "runtime.h" |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 24 | #include "scoped_thread_state_change-inl.h" |
Alex Light | 9dcc457 | 2014-08-14 14:16:26 -0700 | [diff] [blame] | 25 | #include "thread.h" |
| 26 | |
| 27 | namespace art { |
| 28 | |
| 29 | class NoPatchoatTest { |
| 30 | public: |
Igor Murashkin | 96e8393 | 2014-10-29 19:45:42 -0700 | [diff] [blame] | 31 | static const OatFile::OatDexFile* getOatDexFile(jclass cls) { |
Alex Light | 9dcc457 | 2014-08-14 14:16:26 -0700 | [diff] [blame] | 32 | ScopedObjectAccess soa(Thread::Current()); |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 33 | ObjPtr<mirror::Class> klass = soa.Decode<mirror::Class>(cls); |
Alex Light | 9dcc457 | 2014-08-14 14:16:26 -0700 | [diff] [blame] | 34 | const DexFile& dex_file = klass->GetDexFile(); |
Richard Uhler | 07b3c23 | 2015-03-31 15:57:54 -0700 | [diff] [blame] | 35 | return dex_file.GetOatDexFile(); |
Igor Murashkin | 96e8393 | 2014-10-29 19:45:42 -0700 | [diff] [blame] | 36 | } |
| 37 | |
Alex Light | 22cbec4 | 2015-09-18 17:09:43 -0700 | [diff] [blame] | 38 | static bool isRelocationDeltaZero() { |
Jeff Hao | dcdc85b | 2015-12-04 14:06:18 -0800 | [diff] [blame] | 39 | std::vector<gc::space::ImageSpace*> spaces = |
| 40 | Runtime::Current()->GetHeap()->GetBootImageSpaces(); |
| 41 | return !spaces.empty() && spaces[0]->GetImageHeader().GetPatchDelta() == 0; |
Alex Light | 22cbec4 | 2015-09-18 17:09:43 -0700 | [diff] [blame] | 42 | } |
| 43 | |
Igor Murashkin | 96e8393 | 2014-10-29 19:45:42 -0700 | [diff] [blame] | 44 | static bool hasExecutableOat(jclass cls) { |
| 45 | const OatFile::OatDexFile* oat_dex_file = getOatDexFile(cls); |
| 46 | |
Vladimir Marko | aa4497d | 2014-09-05 14:01:17 +0100 | [diff] [blame] | 47 | return oat_dex_file != nullptr && oat_dex_file->GetOatFile()->IsExecutable(); |
Alex Light | 9dcc457 | 2014-08-14 14:16:26 -0700 | [diff] [blame] | 48 | } |
Igor Murashkin | 96e8393 | 2014-10-29 19:45:42 -0700 | [diff] [blame] | 49 | |
David Brazdil | 1ed4449 | 2016-02-01 18:00:06 +0000 | [diff] [blame] | 50 | static bool needsRelocation(jclass cls) { |
Igor Murashkin | 96e8393 | 2014-10-29 19:45:42 -0700 | [diff] [blame] | 51 | 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 Gampe | 7bcfcb8 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 58 | return !oat_file->IsPic() |
Vladimir Marko | 8c185bf | 2016-05-23 15:32:42 +0100 | [diff] [blame] | 59 | && CompilerFilter::IsBytecodeCompilationEnabled(oat_file->GetCompilerFilter()); |
Igor Murashkin | 96e8393 | 2014-10-29 19:45:42 -0700 | [diff] [blame] | 60 | } |
Alex Light | 9dcc457 | 2014-08-14 14:16:26 -0700 | [diff] [blame] | 61 | }; |
| 62 | |
Alex Light | 22cbec4 | 2015-09-18 17:09:43 -0700 | [diff] [blame] | 63 | extern "C" JNIEXPORT jboolean JNICALL Java_Main_isRelocationDeltaZero(JNIEnv*, jclass) { |
| 64 | return NoPatchoatTest::isRelocationDeltaZero(); |
| 65 | } |
| 66 | |
Alex Light | 9dcc457 | 2014-08-14 14:16:26 -0700 | [diff] [blame] | 67 | extern "C" JNIEXPORT jboolean JNICALL Java_Main_hasExecutableOat(JNIEnv*, jclass cls) { |
| 68 | return NoPatchoatTest::hasExecutableOat(cls); |
| 69 | } |
| 70 | |
David Brazdil | 1ed4449 | 2016-02-01 18:00:06 +0000 | [diff] [blame] | 71 | extern "C" JNIEXPORT jboolean JNICALL Java_Main_needsRelocation(JNIEnv*, jclass cls) { |
| 72 | return NoPatchoatTest::needsRelocation(cls); |
Igor Murashkin | 96e8393 | 2014-10-29 19:45:42 -0700 | [diff] [blame] | 73 | } |
| 74 | |
Alex Light | 9dcc457 | 2014-08-14 14:16:26 -0700 | [diff] [blame] | 75 | } // namespace art |