Add intrinsic for Reference.get()
Added an intrinsic function for Reference.get(). Return immediately
without going through JNI if the slow path is not currently in use.
Otherwise, branch off to the the existing JNI function.
Approximately 47x speedup for cases where slow path is not enabled.
Change-Id: I13ad65a356fe4e104d8d83980694dc2740d7d039
diff --git a/runtime/mirror/reference.h b/runtime/mirror/reference.h
index 9c9d87b..15e0145 100644
--- a/runtime/mirror/reference.h
+++ b/runtime/mirror/reference.h
@@ -17,7 +17,10 @@
#ifndef ART_RUNTIME_MIRROR_REFERENCE_H_
#define ART_RUNTIME_MIRROR_REFERENCE_H_
+#include "class.h"
#include "object.h"
+#include "object_callbacks.h"
+#include "thread.h"
namespace art {
@@ -29,9 +32,11 @@
} // namespace gc
struct ReferenceOffsets;
+struct ReferenceClassOffsets;
struct FinalizerReferenceOffsets;
namespace mirror {
+class ReferenceClass;
// C++ mirror of java.lang.ref.Reference
class MANAGED Reference : public Object {
@@ -80,6 +85,15 @@
bool IsEnqueuable() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
+ static ReferenceClass* GetJavaLangRefReference() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
+ CHECK(java_lang_ref_Reference_ != nullptr);
+ return ReadBarrier::BarrierForRoot<mirror::ReferenceClass, kWithReadBarrier>(
+ &java_lang_ref_Reference_);
+ }
+ static void SetClass(ReferenceClass* klass);
+ static void ResetClass(void);
+ static void VisitRoots(RootCallback* callback, void* arg);
+
private:
// Note: This avoids a read barrier, it should only be used by the GC.
HeapReference<Object>* GetReferentReferenceAddr() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
@@ -92,12 +106,46 @@
HeapReference<Reference> queue_next_; // Note this is Java volatile:
HeapReference<Object> referent_; // Note this is Java volatile:
+ static ReferenceClass* java_lang_ref_Reference_;
+
friend struct art::ReferenceOffsets; // for verifying offset information
friend class gc::ReferenceProcessor;
friend class gc::ReferenceQueue;
DISALLOW_IMPLICIT_CONSTRUCTORS(Reference);
};
+// Tightly coupled with the ReferenceProcessor to provide switch for slow/fast path. Consistency
+// is maintained by ReferenceProcessor.
+class MANAGED ReferenceClass : public Class {
+ public:
+ static MemberOffset DisableIntrinsicOffset() {
+ return OFFSET_OF_OBJECT_MEMBER(ReferenceClass, disable_intrinsic_);
+ }
+ static MemberOffset SlowPathEnabledOffset() {
+ return OFFSET_OF_OBJECT_MEMBER(ReferenceClass, slow_path_enabled_);
+ }
+
+ void Init() {
+ disable_intrinsic_ = false;
+ slow_path_enabled_ = false;
+ }
+
+ bool GetSlowPathEnabled() const {
+ return slow_path_enabled_;
+ }
+ void SetSlowPathEnabled(bool enabled) {
+ slow_path_enabled_ = enabled;
+ }
+
+ private:
+ int32_t disable_intrinsic_;
+ int32_t slow_path_enabled_;
+ // allows runtime to safely enable/disable intrinsics fast path for benchmarking
+
+ friend struct art::ReferenceClassOffsets; // for verifying offset information
+ DISALLOW_IMPLICIT_CONSTRUCTORS(ReferenceClass);
+};
+
// C++ mirror of java.lang.ref.FinalizerReference
class MANAGED FinalizerReference : public Reference {
public: