summaryrefslogtreecommitdiff
path: root/runtime/native/java_lang_Class.cc
diff options
context:
space:
mode:
author Treehugger Robot <treehugger-gerrit@google.com> 2018-02-01 15:54:46 +0000
committer Gerrit Code Review <noreply-gerritcodereview@google.com> 2018-02-01 15:54:46 +0000
commit70e88d6df6cc97163fa8b2bdd756a6e910bc9aa5 (patch)
tree3801c976e92f02247042e4c124f6b7dc00d4e435 /runtime/native/java_lang_Class.cc
parentcf026fec63bea5056988452a6c014df75bf13e19 (diff)
parenta02cb113cd0dd023eec61716d3d1bd0dc1c1453a (diff)
Merge "Move hidden API warnings into resolvers"
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 a1f23bdfb8..2091a27ffd 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())) };