summaryrefslogtreecommitdiff
path: root/runtime/native/java_lang_Class.cc
diff options
context:
space:
mode:
author David Brazdil <dbrazdil@google.com> 2018-01-31 11:36:39 +0000
committer David Brazdil <dbrazdil@google.com> 2018-02-01 13:47:33 +0000
commita02cb113cd0dd023eec61716d3d1bd0dc1c1453a (patch)
tree8553be51d5f6c2f0ebce20d7e364085ccf0a3206 /runtime/native/java_lang_Class.cc
parentc7e546ff3963a1d51b1f100d308db735bd19f736 (diff)
Move hidden API warnings into resolvers
Checks inserted to maybe warn about accessing a hidden API member are proving too expensive. Move them into the resolvers. Bug: 64382372 Bug: 72649186 Test: art/test.py --host -b -r -t 674-hiddenapi -v Change-Id: I11bceccb8fe647e829c491be38ba0af72f1b3996
Diffstat (limited to 'runtime/native/java_lang_Class.cc')
-rw-r--r--runtime/native/java_lang_Class.cc28
1 files changed, 14 insertions, 14 deletions
diff --git a/runtime/native/java_lang_Class.cc b/runtime/native/java_lang_Class.cc
index 5544275984..1a3867fde7 100644
--- a/runtime/native/java_lang_Class.cc
+++ b/runtime/native/java_lang_Class.cc
@@ -48,12 +48,8 @@
namespace art {
-ALWAYS_INLINE static bool ShouldEnforceHiddenApi(Thread* self)
- REQUIRES_SHARED(Locks::mutator_lock_) {
- if (!Runtime::Current()->AreHiddenApiChecksEnabled()) {
- return false;
- }
-
+// Returns true if the first non-ClassClass caller up the stack is in boot class path.
+static bool IsCallerInBootClassPath(Thread* self) REQUIRES_SHARED(Locks::mutator_lock_) {
// Walk the stack and find the first frame not from java.lang.Class.
// This is very expensive. Save this till the last.
struct FirstNonClassClassCallerVisitor : public StackVisitor {
@@ -84,8 +80,16 @@ ALWAYS_INLINE static bool ShouldEnforceHiddenApi(Thread* self)
FirstNonClassClassCallerVisitor visitor(self);
visitor.WalkStack();
- return visitor.caller == nullptr ||
- !visitor.caller->GetDeclaringClass()->IsBootStrapClassLoaded();
+ return visitor.caller != nullptr &&
+ visitor.caller->GetDeclaringClass()->IsBootStrapClassLoaded();
+}
+
+// Returns true if the first non-ClassClass caller up the stack is not allowed to
+// access hidden APIs. This can be *very* expensive. Never call this in a loop.
+ALWAYS_INLINE static bool ShouldEnforceHiddenApi(Thread* self)
+ REQUIRES_SHARED(Locks::mutator_lock_) {
+ return Runtime::Current()->AreHiddenApiChecksEnabled() &&
+ !IsCallerInBootClassPath(self);
}
// Returns true if the first non-ClassClass caller up the stack should not be
@@ -93,9 +97,7 @@ ALWAYS_INLINE static bool ShouldEnforceHiddenApi(Thread* self)
template<typename T>
ALWAYS_INLINE static bool ShouldBlockAccessToMember(T* member, Thread* self)
REQUIRES_SHARED(Locks::mutator_lock_) {
- DCHECK(member != nullptr);
- return hiddenapi::IsMemberHidden(member->GetAccessFlags()) &&
- ShouldEnforceHiddenApi(self);
+ return hiddenapi::ShouldBlockAccessToMember(member, self, IsCallerInBootClassPath);
}
// Returns true if a class member should be discoverable with reflection given
@@ -109,14 +111,13 @@ ALWAYS_INLINE static bool IsDiscoverable(bool public_only,
return false;
}
- if (enforce_hidden_api && hiddenapi::IsMemberHidden(access_flags)) {
+ if (enforce_hidden_api && hiddenapi::GetMemberAction(access_flags) == hiddenapi::kDeny) {
return false;
}
return true;
}
-
ALWAYS_INLINE static inline ObjPtr<mirror::Class> DecodeClass(
const ScopedFastNativeObjectAccess& soa, jobject java_class)
REQUIRES_SHARED(Locks::mutator_lock_) {
@@ -831,7 +832,6 @@ static jobject Class_newInstance(JNIEnv* env, jobject javaThis) {
return nullptr;
}
}
- hiddenapi::MaybeWarnAboutMemberAccess(constructor, soa.Self(), /* num_frames */ 1);
// Invoke the constructor.
JValue result;
uint32_t args[1] = { static_cast<uint32_t>(reinterpret_cast<uintptr_t>(receiver.Get())) };