summaryrefslogtreecommitdiffstats
path: root/runtime/monitor.h
diff options
context:
space:
mode:
authorMathieu Chartier <mathieuc@google.com>2013-10-31 10:35:05 -0700
committerMathieu Chartier <mathieuc@google.com>2013-10-31 13:33:51 -0700
commit4e6a31eb97f22f4480827474b30b9e64f396eace (patch)
tree3afe222c60314a22be8bb8de61cb245e1af2dc92 /runtime/monitor.h
parent1b8cb967143d5c46db1db8ac940a73d111be3628 (diff)
downloadart-4e6a31eb97f22f4480827474b30b9e64f396eace.tar.gz
art-4e6a31eb97f22f4480827474b30b9e64f396eace.tar.bz2
art-4e6a31eb97f22f4480827474b30b9e64f396eace.zip
Lazily compute object identity hash codes.
Before, we computed identity hashcodes whenever we inflated a monitor. This caused issues since it meant that we would have all of these hash codes in the image, causing locks to excessively inflate during application run time. This change makes it so that we lazily compute hash codes. When a thin lock gets inflated, we assign a hash code of 0 assigned to it. This value signifies no hash code. When we try to get the identity hash code of an object with an inflated monitor, it gets computed if it is 0. Change-Id: Iae6acd1960515a36e74644e5b1323ff336731806
Diffstat (limited to 'runtime/monitor.h')
-rw-r--r--runtime/monitor.h15
1 files changed, 9 insertions, 6 deletions
diff --git a/runtime/monitor.h b/runtime/monitor.h
index c464400f46..09cfafa042 100644
--- a/runtime/monitor.h
+++ b/runtime/monitor.h
@@ -24,6 +24,7 @@
#include <list>
#include <vector>
+#include "atomic_integer.h"
#include "base/mutex.h"
#include "root_visitor.h"
#include "thread_state.h"
@@ -98,17 +99,19 @@ class Monitor {
return owner_;
}
- int32_t GetHashCode() const {
- return hash_code_;
- }
+ int32_t GetHashCode();
bool IsLocked() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
+ bool HasHashCode() const {
+ return hash_code_.load() != 0;
+ }
+
static void InflateThinLocked(Thread* self, mirror::Object* obj, LockWord lock_word,
uint32_t hash_code) NO_THREAD_SAFETY_ANALYSIS;
private:
- explicit Monitor(Thread* owner, mirror::Object* obj, uint32_t hash_code)
+ explicit Monitor(Thread* owner, mirror::Object* obj, int32_t hash_code)
SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
// Install the monitor into its object, may fail if another thread installs a different monitor
@@ -179,8 +182,8 @@ class Monitor {
// Threads currently waiting on this monitor.
Thread* wait_set_ GUARDED_BY(monitor_lock_);
- // Stored object hash code, always generated.
- const uint32_t hash_code_;
+ // Stored object hash code, generated lazily by GetHashCode.
+ AtomicInteger hash_code_;
// Method and dex pc where the lock owner acquired the lock, used when lock
// sampling is enabled. locking_method_ may be null if the lock is currently