diff options
| -rw-r--r-- | dex2oat/dex2oat.cc | 20 | ||||
| -rw-r--r-- | runtime/art_method-inl.h | 91 | ||||
| -rw-r--r-- | runtime/art_method.h | 7 | ||||
| -rw-r--r-- | runtime/compiler_callbacks.h | 10 | ||||
| -rw-r--r-- | runtime/hidden_api.cc | 2 | ||||
| -rw-r--r-- | runtime/hidden_api.h | 6 |
6 files changed, 102 insertions, 34 deletions
diff --git a/dex2oat/dex2oat.cc b/dex2oat/dex2oat.cc index 1e4ed58c8c..40d97a882b 100644 --- a/dex2oat/dex2oat.cc +++ b/dex2oat/dex2oat.cc @@ -1517,10 +1517,15 @@ class Dex2Oat FINAL { // Verification results are null since we don't know if we will need them yet as the compler // filter may change. - callbacks_.reset(new QuickCompilerCallbacks( - IsBootImage() ? - CompilerCallbacks::CallbackMode::kCompileBootImage : - CompilerCallbacks::CallbackMode::kCompileApp)); + CompilerCallbacks::CallbackMode callback_mode = CompilerCallbacks::CallbackMode::kCompileApp; + if (IsBootImage()) { + if (IsCoreImage()) { + callback_mode = CompilerCallbacks::CallbackMode::kCompileCoreImage; + } else { + callback_mode = CompilerCallbacks::CallbackMode::kCompileBootImage; + } + } + callbacks_.reset(new QuickCompilerCallbacks(callback_mode)); RuntimeArgumentMap runtime_options; if (!PrepareRuntimeOptions(&runtime_options, callbacks_.get())) { @@ -2268,14 +2273,21 @@ class Dex2Oat FINAL { return IsAppImage() || IsBootImage(); } + // Returns true if we are compiling an app image. bool IsAppImage() const { return compiler_options_->IsAppImage(); } + // Returns true if we are compiling a boot image. bool IsBootImage() const { return compiler_options_->IsBootImage(); } + // Returns true if we are compiling a core image (a minimal boot image for testing). + bool IsCoreImage() const { + return compiler_options_->IsCoreImage(); + } + bool IsHost() const { return is_host_; } diff --git a/runtime/art_method-inl.h b/runtime/art_method-inl.h index 1565644380..191d502782 100644 --- a/runtime/art_method-inl.h +++ b/runtime/art_method-inl.h @@ -24,6 +24,7 @@ #include "base/utils.h" #include "class_linker-inl.h" #include "common_throws.h" +#include "compiler_callbacks.h" #include "dex/code_item_accessors-inl.h" #include "dex/dex_file-inl.h" #include "dex/dex_file_annotations.h" @@ -31,6 +32,7 @@ #include "dex/invoke_type.h" #include "dex/primitive.h" #include "gc_root-inl.h" +#include "hidden_api.h" #include "intrinsics_enum.h" #include "jit/profiling_info.h" #include "mirror/class-inl.h" @@ -384,19 +386,72 @@ inline bool ArtMethod::HasSingleImplementation() { return (GetAccessFlags<kReadBarrierOption>() & kAccSingleImplementation) != 0; } -inline bool ArtMethod::IsHiddenIntrinsic(uint32_t ordinal) { - switch (static_cast<Intrinsics>(ordinal)) { - case Intrinsics::kReferenceGetReferent: - case Intrinsics::kSystemArrayCopyChar: - case Intrinsics::kStringGetCharsNoCheck: - case Intrinsics::kVarHandleFullFence: - case Intrinsics::kVarHandleAcquireFence: - case Intrinsics::kVarHandleReleaseFence: - case Intrinsics::kVarHandleLoadLoadFence: - case Intrinsics::kVarHandleStoreStoreFence: - return true; - default: - return false; +inline HiddenApiAccessFlags::ApiList ArtMethod::GetHiddenApiAccessFlags() { + if (UNLIKELY(IsIntrinsic())) { + switch (static_cast<Intrinsics>(GetIntrinsic())) { + case Intrinsics::kSystemArrayCopyChar: + case Intrinsics::kStringGetCharsNoCheck: + case Intrinsics::kReferenceGetReferent: + return HiddenApiAccessFlags::kLightGreylist; + case Intrinsics::kVarHandleCompareAndExchange: + case Intrinsics::kVarHandleCompareAndExchangeAcquire: + case Intrinsics::kVarHandleCompareAndExchangeRelease: + case Intrinsics::kVarHandleCompareAndSet: + case Intrinsics::kVarHandleGet: + case Intrinsics::kVarHandleGetAcquire: + case Intrinsics::kVarHandleGetAndAdd: + case Intrinsics::kVarHandleGetAndAddAcquire: + case Intrinsics::kVarHandleGetAndAddRelease: + case Intrinsics::kVarHandleGetAndBitwiseAnd: + case Intrinsics::kVarHandleGetAndBitwiseAndAcquire: + case Intrinsics::kVarHandleGetAndBitwiseAndRelease: + case Intrinsics::kVarHandleGetAndBitwiseOr: + case Intrinsics::kVarHandleGetAndBitwiseOrAcquire: + case Intrinsics::kVarHandleGetAndBitwiseOrRelease: + case Intrinsics::kVarHandleGetAndBitwiseXor: + case Intrinsics::kVarHandleGetAndBitwiseXorAcquire: + case Intrinsics::kVarHandleGetAndBitwiseXorRelease: + case Intrinsics::kVarHandleGetAndSet: + case Intrinsics::kVarHandleGetAndSetAcquire: + case Intrinsics::kVarHandleGetAndSetRelease: + case Intrinsics::kVarHandleGetOpaque: + case Intrinsics::kVarHandleGetVolatile: + case Intrinsics::kVarHandleSet: + case Intrinsics::kVarHandleSetOpaque: + case Intrinsics::kVarHandleSetRelease: + case Intrinsics::kVarHandleSetVolatile: + case Intrinsics::kVarHandleWeakCompareAndSet: + case Intrinsics::kVarHandleWeakCompareAndSetAcquire: + case Intrinsics::kVarHandleWeakCompareAndSetPlain: + case Intrinsics::kVarHandleWeakCompareAndSetRelease: + case Intrinsics::kVarHandleFullFence: + case Intrinsics::kVarHandleAcquireFence: + case Intrinsics::kVarHandleReleaseFence: + case Intrinsics::kVarHandleLoadLoadFence: + case Intrinsics::kVarHandleStoreStoreFence: + return HiddenApiAccessFlags::kBlacklist; + default: + return HiddenApiAccessFlags::kWhitelist; + } + } else { + return HiddenApiAccessFlags::DecodeFromRuntime(GetAccessFlags()); + } +} + +// This is a temporary workaround for the fact that core image does not have +// hidden API access flags. This function will return true if we know that the +// process (or its forks) will not enforce the flags. (b/77733081). +inline bool WillIgnoreHiddenApiAccessFlags() { + Runtime* runtime = Runtime::Current(); + + if (runtime->IsAotCompiler() && runtime->GetCompilerCallbacks()->IsBootImage()) { + // Do not ignore when compiling the regular boot image, only the core image. + return runtime->GetCompilerCallbacks()->IsCoreImage(); + } else { + // Ignore if this runtime was started with disabled enforcement and + // will not fork into other processes. + return runtime->GetHiddenApiEnforcementPolicy() == hiddenapi::EnforcementPolicy::kNoChecks && + !runtime->IsZygote(); } } @@ -436,14 +491,8 @@ inline void ArtMethod::SetIntrinsic(uint32_t intrinsic) { DCHECK_EQ(is_default_conflict, IsDefaultConflicting()); DCHECK_EQ(is_compilable, IsCompilable()); DCHECK_EQ(must_count_locks, MustCountLocks()); - if (kIsDebugBuild) { - if (IsHiddenIntrinsic(intrinsic)) { - // Special case some of our intrinsics because the access flags clash - // with the intrinsics ordinal. - DCHECK_EQ(HiddenApiAccessFlags::kWhitelist, GetHiddenApiAccessFlags()); - } else { - DCHECK_EQ(hidden_api_list, GetHiddenApiAccessFlags()); - } + if (!WillIgnoreHiddenApiAccessFlags()) { + DCHECK_EQ(hidden_api_list, GetHiddenApiAccessFlags()); } } else { SetAccessFlags(new_value); diff --git a/runtime/art_method.h b/runtime/art_method.h index 64d293200f..ae13d86934 100644 --- a/runtime/art_method.h +++ b/runtime/art_method.h @@ -341,9 +341,7 @@ class ArtMethod FINAL { AddAccessFlags(kAccMustCountLocks); } - HiddenApiAccessFlags::ApiList GetHiddenApiAccessFlags() { - return HiddenApiAccessFlags::DecodeFromRuntime(GetAccessFlags()); - } + HiddenApiAccessFlags::ApiList GetHiddenApiAccessFlags(); // Returns true if this method could be overridden by a default method. bool IsOverridableByDefaultMethod() REQUIRES_SHARED(Locks::mutator_lock_); @@ -873,9 +871,6 @@ class ArtMethod FINAL { } while (!access_flags_.compare_exchange_weak(old_access_flags, new_access_flags)); } - // Returns true if the given intrinsic is considered hidden. - bool IsHiddenIntrinsic(uint32_t ordinal); - DISALLOW_COPY_AND_ASSIGN(ArtMethod); // Need to use CopyFrom to deal with 32 vs 64 bits. }; diff --git a/runtime/compiler_callbacks.h b/runtime/compiler_callbacks.h index 6855dcdb2b..279d5ab764 100644 --- a/runtime/compiler_callbacks.h +++ b/runtime/compiler_callbacks.h @@ -42,6 +42,7 @@ class CompilerCallbacks { public: enum class CallbackMode { // private kCompileBootImage, + kCompileCoreImage, kCompileApp }; @@ -67,8 +68,15 @@ class CompilerCallbacks { virtual void SetDoesClassUnloading(bool does_class_unloading ATTRIBUTE_UNUSED, CompilerDriver* compiler_driver ATTRIBUTE_UNUSED) {} + // Returns true if the compiler is compiling a boot image. + // Note that core image (a minimal boot image for testing) is also considered a boot image. bool IsBootImage() { - return mode_ == CallbackMode::kCompileBootImage; + return mode_ == CallbackMode::kCompileBootImage || mode_ == CallbackMode::kCompileCoreImage; + } + + // Returns true if the compiler is compiling a core image (a minimal boot image for testing). + bool IsCoreImage() { + return mode_ == CallbackMode::kCompileCoreImage; } virtual void UpdateClassState(ClassReference ref ATTRIBUTE_UNUSED, diff --git a/runtime/hidden_api.cc b/runtime/hidden_api.cc index c5d09cfa77..d758737638 100644 --- a/runtime/hidden_api.cc +++ b/runtime/hidden_api.cc @@ -20,6 +20,8 @@ #include <nativehelper/scoped_local_ref.h> +#include "art_field-inl.h" +#include "art_method-inl.h" #include "base/dumpable.h" #include "thread-current-inl.h" #include "well_known_classes.h" diff --git a/runtime/hidden_api.h b/runtime/hidden_api.h index 4325496ca3..6b40dea86c 100644 --- a/runtime/hidden_api.h +++ b/runtime/hidden_api.h @@ -17,8 +17,6 @@ #ifndef ART_RUNTIME_HIDDEN_API_H_ #define ART_RUNTIME_HIDDEN_API_H_ -#include "art_field-inl.h" -#include "art_method-inl.h" #include "base/mutex.h" #include "dex/hidden_api_access_flags.h" #include "mirror/class-inl.h" @@ -26,6 +24,10 @@ #include "runtime.h" namespace art { + +class ArtField; +class ArtMethod; + namespace hiddenapi { // Hidden API enforcement policy |