19dcc4572949f6a8231a1b4ed859676ba6f411726Alex Light/* 29dcc4572949f6a8231a1b4ed859676ba6f411726Alex Light * Copyright (C) 2014 The Android Open Source Project 39dcc4572949f6a8231a1b4ed859676ba6f411726Alex Light * 49dcc4572949f6a8231a1b4ed859676ba6f411726Alex Light * Licensed under the Apache License, Version 2.0 (the "License"); 59dcc4572949f6a8231a1b4ed859676ba6f411726Alex Light * you may not use this file except in compliance with the License. 69dcc4572949f6a8231a1b4ed859676ba6f411726Alex Light * You may obtain a copy of the License at 79dcc4572949f6a8231a1b4ed859676ba6f411726Alex Light * 89dcc4572949f6a8231a1b4ed859676ba6f411726Alex Light * http://www.apache.org/licenses/LICENSE-2.0 99dcc4572949f6a8231a1b4ed859676ba6f411726Alex Light * 109dcc4572949f6a8231a1b4ed859676ba6f411726Alex Light * Unless required by applicable law or agreed to in writing, software 119dcc4572949f6a8231a1b4ed859676ba6f411726Alex Light * distributed under the License is distributed on an "AS IS" BASIS, 129dcc4572949f6a8231a1b4ed859676ba6f411726Alex Light * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 139dcc4572949f6a8231a1b4ed859676ba6f411726Alex Light * See the License for the specific language governing permissions and 149dcc4572949f6a8231a1b4ed859676ba6f411726Alex Light * limitations under the License. 159dcc4572949f6a8231a1b4ed859676ba6f411726Alex Light */ 169dcc4572949f6a8231a1b4ed859676ba6f411726Alex Light 179dcc4572949f6a8231a1b4ed859676ba6f411726Alex Light#include "class_linker.h" 189dcc4572949f6a8231a1b4ed859676ba6f411726Alex Light#include "dex_file-inl.h" 1922cbec48e2a325fa1b7ffca694128f61839284feAlex Light#include "gc/heap.h" 2022cbec48e2a325fa1b7ffca694128f61839284feAlex Light#include "gc/space/image_space.h" 219dcc4572949f6a8231a1b4ed859676ba6f411726Alex Light#include "mirror/class-inl.h" 2222cbec48e2a325fa1b7ffca694128f61839284feAlex Light#include "runtime.h" 239dcc4572949f6a8231a1b4ed859676ba6f411726Alex Light#include "scoped_thread_state_change.h" 249dcc4572949f6a8231a1b4ed859676ba6f411726Alex Light#include "thread.h" 259dcc4572949f6a8231a1b4ed859676ba6f411726Alex Light 269dcc4572949f6a8231a1b4ed859676ba6f411726Alex Lightnamespace art { 279dcc4572949f6a8231a1b4ed859676ba6f411726Alex Light 289dcc4572949f6a8231a1b4ed859676ba6f411726Alex Lightclass NoPatchoatTest { 299dcc4572949f6a8231a1b4ed859676ba6f411726Alex Light public: 3096e83930f35544872228be209d3704f60c2c485cIgor Murashkin static const OatFile::OatDexFile* getOatDexFile(jclass cls) { 319dcc4572949f6a8231a1b4ed859676ba6f411726Alex Light ScopedObjectAccess soa(Thread::Current()); 329dcc4572949f6a8231a1b4ed859676ba6f411726Alex Light mirror::Class* klass = soa.Decode<mirror::Class*>(cls); 339dcc4572949f6a8231a1b4ed859676ba6f411726Alex Light const DexFile& dex_file = klass->GetDexFile(); 3407b3c2351bb527ea91c084dc19434600af9ae66bRichard Uhler return dex_file.GetOatDexFile(); 3596e83930f35544872228be209d3704f60c2c485cIgor Murashkin } 3696e83930f35544872228be209d3704f60c2c485cIgor Murashkin 3722cbec48e2a325fa1b7ffca694128f61839284feAlex Light static bool isRelocationDeltaZero() { 38dcdc85bbd569f0ee66c331b4219c19304a616214Jeff Hao std::vector<gc::space::ImageSpace*> spaces = 39dcdc85bbd569f0ee66c331b4219c19304a616214Jeff Hao Runtime::Current()->GetHeap()->GetBootImageSpaces(); 40dcdc85bbd569f0ee66c331b4219c19304a616214Jeff Hao return !spaces.empty() && spaces[0]->GetImageHeader().GetPatchDelta() == 0; 4122cbec48e2a325fa1b7ffca694128f61839284feAlex Light } 4222cbec48e2a325fa1b7ffca694128f61839284feAlex Light 4396e83930f35544872228be209d3704f60c2c485cIgor Murashkin static bool hasExecutableOat(jclass cls) { 4496e83930f35544872228be209d3704f60c2c485cIgor Murashkin const OatFile::OatDexFile* oat_dex_file = getOatDexFile(cls); 4596e83930f35544872228be209d3704f60c2c485cIgor Murashkin 46aa4497db59f1eeec954f2ba5da6d458fcdf9b3a4Vladimir Marko return oat_dex_file != nullptr && oat_dex_file->GetOatFile()->IsExecutable(); 479dcc4572949f6a8231a1b4ed859676ba6f411726Alex Light } 4896e83930f35544872228be209d3704f60c2c485cIgor Murashkin 491ed44491dfccc0520d698c8ed0ce3225a6cf8582David Brazdil static bool needsRelocation(jclass cls) { 5096e83930f35544872228be209d3704f60c2c485cIgor Murashkin const OatFile::OatDexFile* oat_dex_file = getOatDexFile(cls); 5196e83930f35544872228be209d3704f60c2c485cIgor Murashkin 5296e83930f35544872228be209d3704f60c2c485cIgor Murashkin if (oat_dex_file == nullptr) { 5396e83930f35544872228be209d3704f60c2c485cIgor Murashkin return false; 5496e83930f35544872228be209d3704f60c2c485cIgor Murashkin } 5596e83930f35544872228be209d3704f60c2c485cIgor Murashkin 5696e83930f35544872228be209d3704f60c2c485cIgor Murashkin const OatFile* oat_file = oat_dex_file->GetOatFile(); 577bcfcb80a31f57a84d754e00bca8698829365208Andreas Gampe return !oat_file->IsPic() 588c185bf0c6f18a5349bc87a7e3751ba06d90f461Vladimir Marko && CompilerFilter::IsBytecodeCompilationEnabled(oat_file->GetCompilerFilter()); 5996e83930f35544872228be209d3704f60c2c485cIgor Murashkin } 609dcc4572949f6a8231a1b4ed859676ba6f411726Alex Light}; 619dcc4572949f6a8231a1b4ed859676ba6f411726Alex Light 6222cbec48e2a325fa1b7ffca694128f61839284feAlex Lightextern "C" JNIEXPORT jboolean JNICALL Java_Main_isRelocationDeltaZero(JNIEnv*, jclass) { 6322cbec48e2a325fa1b7ffca694128f61839284feAlex Light return NoPatchoatTest::isRelocationDeltaZero(); 6422cbec48e2a325fa1b7ffca694128f61839284feAlex Light} 6522cbec48e2a325fa1b7ffca694128f61839284feAlex Light 669dcc4572949f6a8231a1b4ed859676ba6f411726Alex Lightextern "C" JNIEXPORT jboolean JNICALL Java_Main_hasExecutableOat(JNIEnv*, jclass cls) { 679dcc4572949f6a8231a1b4ed859676ba6f411726Alex Light return NoPatchoatTest::hasExecutableOat(cls); 689dcc4572949f6a8231a1b4ed859676ba6f411726Alex Light} 699dcc4572949f6a8231a1b4ed859676ba6f411726Alex Light 701ed44491dfccc0520d698c8ed0ce3225a6cf8582David Brazdilextern "C" JNIEXPORT jboolean JNICALL Java_Main_needsRelocation(JNIEnv*, jclass cls) { 711ed44491dfccc0520d698c8ed0ce3225a6cf8582David Brazdil return NoPatchoatTest::needsRelocation(cls); 7296e83930f35544872228be209d3704f60c2c485cIgor Murashkin} 7396e83930f35544872228be209d3704f60c2c485cIgor Murashkin 749dcc4572949f6a8231a1b4ed859676ba6f411726Alex Light} // namespace art 75