Revert "Update hidden API membership of intrinsics"

This reverts commit e1954f30cbf70ed4430b9ca7b85b5d52fdc42251.

Reason for revert: Breaks all internal tests.

Bug: 64382372
Bug: 77733081
Bug: 72430785
Change-Id: If6138ee1a3d73059b20c582c0dfd388ff07507a2
diff --git a/dex2oat/dex2oat.cc b/dex2oat/dex2oat.cc
index 40d97a8..1e4ed58 100644
--- a/dex2oat/dex2oat.cc
+++ b/dex2oat/dex2oat.cc
@@ -1517,15 +1517,10 @@
 
     // Verification results are null since we don't know if we will need them yet as the compler
     // filter may change.
-    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));
+    callbacks_.reset(new QuickCompilerCallbacks(
+        IsBootImage() ?
+            CompilerCallbacks::CallbackMode::kCompileBootImage :
+            CompilerCallbacks::CallbackMode::kCompileApp));
 
     RuntimeArgumentMap runtime_options;
     if (!PrepareRuntimeOptions(&runtime_options, callbacks_.get())) {
@@ -2273,21 +2268,14 @@
     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 191d502..1565644 100644
--- a/runtime/art_method-inl.h
+++ b/runtime/art_method-inl.h
@@ -24,7 +24,6 @@
 #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"
@@ -32,7 +31,6 @@
 #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"
@@ -386,72 +384,19 @@
   return (GetAccessFlags<kReadBarrierOption>() & kAccSingleImplementation) != 0;
 }
 
-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();
+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;
   }
 }
 
@@ -491,8 +436,14 @@
     DCHECK_EQ(is_default_conflict, IsDefaultConflicting());
     DCHECK_EQ(is_compilable, IsCompilable());
     DCHECK_EQ(must_count_locks, MustCountLocks());
-    if (!WillIgnoreHiddenApiAccessFlags()) {
-      DCHECK_EQ(hidden_api_list, GetHiddenApiAccessFlags());
+    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());
+      }
     }
   } else {
     SetAccessFlags(new_value);
diff --git a/runtime/art_method.h b/runtime/art_method.h
index ae13d86..64d2932 100644
--- a/runtime/art_method.h
+++ b/runtime/art_method.h
@@ -341,7 +341,9 @@
     AddAccessFlags(kAccMustCountLocks);
   }
 
-  HiddenApiAccessFlags::ApiList GetHiddenApiAccessFlags();
+  HiddenApiAccessFlags::ApiList GetHiddenApiAccessFlags() {
+    return HiddenApiAccessFlags::DecodeFromRuntime(GetAccessFlags());
+  }
 
   // Returns true if this method could be overridden by a default method.
   bool IsOverridableByDefaultMethod() REQUIRES_SHARED(Locks::mutator_lock_);
@@ -871,6 +873,9 @@
     } 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 279d5ab..6855dcd 100644
--- a/runtime/compiler_callbacks.h
+++ b/runtime/compiler_callbacks.h
@@ -42,7 +42,6 @@
  public:
   enum class CallbackMode {  // private
     kCompileBootImage,
-    kCompileCoreImage,
     kCompileApp
   };
 
@@ -68,15 +67,8 @@
   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 || 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;
+    return mode_ == CallbackMode::kCompileBootImage;
   }
 
   virtual void UpdateClassState(ClassReference ref ATTRIBUTE_UNUSED,
diff --git a/runtime/hidden_api.cc b/runtime/hidden_api.cc
index 5655f71..98feb4d 100644
--- a/runtime/hidden_api.cc
+++ b/runtime/hidden_api.cc
@@ -18,8 +18,6 @@
 
 #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 49b4c89..d2c71a7 100644
--- a/runtime/hidden_api.h
+++ b/runtime/hidden_api.h
@@ -17,6 +17,8 @@
 #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"
@@ -24,10 +26,6 @@
 #include "runtime.h"
 
 namespace art {
-
-class ArtField;
-class ArtMethod;
-
 namespace hiddenapi {
 
 // Hidden API enforcement policy