Commit 05a60095 authored by yangguo's avatar yangguo Committed by Commit bot

Simplify IdentityMap.

This removes the requirement for handles as arguments, but also removes
concurrency support, which is not being used at the moment.

Supporting concurrency could be done by introducing a sibling class to
IdentityMap that includes RelocationLock on method calls.

R=bmeurer@chromium.org, ulan@chromium.org

Review URL: https://codereview.chromium.org/1419563004

Cr-Commit-Position: refs/heads/master@{#31510}
parent 70158828
...@@ -620,25 +620,6 @@ class Heap { ...@@ -620,25 +620,6 @@ class Heap {
Heap* heap_; Heap* heap_;
}; };
// An optional version of the above lock that can be used for some critical
// sections on the mutator thread; only safe since the GC currently does not
// do concurrent compaction.
class OptionalRelocationLock {
public:
OptionalRelocationLock(Heap* heap, bool concurrent)
: heap_(heap), concurrent_(concurrent) {
if (concurrent_) heap_->relocation_mutex_.Lock();
}
~OptionalRelocationLock() {
if (concurrent_) heap_->relocation_mutex_.Unlock();
}
private:
Heap* heap_;
bool concurrent_;
};
// Support for partial snapshots. After calling this we have a linear // Support for partial snapshots. After calling this we have a linear
// space to write objects in each space. // space to write objects in each space.
struct Chunk { struct Chunk {
......
...@@ -15,23 +15,18 @@ static const int kInitialIdentityMapSize = 4; ...@@ -15,23 +15,18 @@ static const int kInitialIdentityMapSize = 4;
static const int kResizeFactor = 4; static const int kResizeFactor = 4;
IdentityMapBase::~IdentityMapBase() { IdentityMapBase::~IdentityMapBase() {
if (keys_) { if (keys_) heap_->UnregisterStrongRoots(keys_);
Heap::OptionalRelocationLock lock(heap_, concurrent_);
heap_->UnregisterStrongRoots(keys_);
}
} }
IdentityMapBase::RawEntry IdentityMapBase::Lookup(Handle<Object> key) { IdentityMapBase::RawEntry IdentityMapBase::Lookup(Object* key) {
AllowHandleDereference for_lookup; int index = LookupIndex(key);
int index = LookupIndex(*key);
return index >= 0 ? &values_[index] : nullptr; return index >= 0 ? &values_[index] : nullptr;
} }
IdentityMapBase::RawEntry IdentityMapBase::Insert(Handle<Object> key) { IdentityMapBase::RawEntry IdentityMapBase::Insert(Object* key) {
AllowHandleDereference for_lookup; int index = InsertIndex(key);
int index = InsertIndex(*key);
DCHECK_GE(index, 0); DCHECK_GE(index, 0);
return &values_[index]; return &values_[index];
} }
...@@ -84,8 +79,7 @@ int IdentityMapBase::InsertIndex(Object* address) { ...@@ -84,8 +79,7 @@ int IdentityMapBase::InsertIndex(Object* address) {
// as the identity, returning: // as the identity, returning:
// found => a pointer to the storage location for the value // found => a pointer to the storage location for the value
// not found => a pointer to a new storage location for the value // not found => a pointer to a new storage location for the value
IdentityMapBase::RawEntry IdentityMapBase::GetEntry(Handle<Object> key) { IdentityMapBase::RawEntry IdentityMapBase::GetEntry(Object* key) {
Heap::OptionalRelocationLock lock(heap_, concurrent_);
RawEntry result; RawEntry result;
if (size_ == 0) { if (size_ == 0) {
// Allocate the initial storage for keys and values. // Allocate the initial storage for keys and values.
...@@ -118,10 +112,9 @@ IdentityMapBase::RawEntry IdentityMapBase::GetEntry(Handle<Object> key) { ...@@ -118,10 +112,9 @@ IdentityMapBase::RawEntry IdentityMapBase::GetEntry(Handle<Object> key) {
// as the identity, returning: // as the identity, returning:
// found => a pointer to the storage location for the value // found => a pointer to the storage location for the value
// not found => {nullptr} // not found => {nullptr}
IdentityMapBase::RawEntry IdentityMapBase::FindEntry(Handle<Object> key) { IdentityMapBase::RawEntry IdentityMapBase::FindEntry(Object* key) {
if (size_ == 0) return nullptr; if (size_ == 0) return nullptr;
Heap::OptionalRelocationLock lock(heap_, concurrent_);
RawEntry result = Lookup(key); RawEntry result = Lookup(key);
if (result == nullptr && gc_counter_ != heap_->gc_count()) { if (result == nullptr && gc_counter_ != heap_->gc_count()) {
Rehash(); // Rehash is expensive, so only do it in case of a miss. Rehash(); // Rehash is expensive, so only do it in case of a miss.
......
...@@ -17,11 +17,6 @@ class Zone; ...@@ -17,11 +17,6 @@ class Zone;
// Base class of identity maps contains shared code for all template // Base class of identity maps contains shared code for all template
// instantions. // instantions.
class IdentityMapBase { class IdentityMapBase {
public:
// Enable or disable concurrent mode for this map. Concurrent mode implies
// taking the heap's relocation lock during most operations.
void SetConcurrent(bool concurrent) { concurrent_ = concurrent; }
protected: protected:
// Allow Tester to access internals, including changing the address of objects // Allow Tester to access internals, including changing the address of objects
// within the {keys_} array in order to simulate a moving GC. // within the {keys_} array in order to simulate a moving GC.
...@@ -32,7 +27,6 @@ class IdentityMapBase { ...@@ -32,7 +27,6 @@ class IdentityMapBase {
IdentityMapBase(Heap* heap, Zone* zone) IdentityMapBase(Heap* heap, Zone* zone)
: heap_(heap), : heap_(heap),
zone_(zone), zone_(zone),
concurrent_(false),
gc_counter_(-1), gc_counter_(-1),
size_(0), size_(0),
mask_(0), mask_(0),
...@@ -40,8 +34,8 @@ class IdentityMapBase { ...@@ -40,8 +34,8 @@ class IdentityMapBase {
values_(nullptr) {} values_(nullptr) {}
~IdentityMapBase(); ~IdentityMapBase();
RawEntry GetEntry(Handle<Object> key); RawEntry GetEntry(Object* key);
RawEntry FindEntry(Handle<Object> key); RawEntry FindEntry(Object* key);
private: private:
// Internal implementation should not be called directly by subclasses. // Internal implementation should not be called directly by subclasses.
...@@ -49,13 +43,12 @@ class IdentityMapBase { ...@@ -49,13 +43,12 @@ class IdentityMapBase {
int InsertIndex(Object* address); int InsertIndex(Object* address);
void Rehash(); void Rehash();
void Resize(); void Resize();
RawEntry Lookup(Handle<Object> key); RawEntry Lookup(Object* key);
RawEntry Insert(Handle<Object> key); RawEntry Insert(Object* key);
int Hash(Object* address); int Hash(Object* address);
Heap* heap_; Heap* heap_;
Zone* zone_; Zone* zone_;
bool concurrent_;
int gc_counter_; int gc_counter_;
int size_; int size_;
int mask_; int mask_;
...@@ -79,18 +72,19 @@ class IdentityMap : public IdentityMapBase { ...@@ -79,18 +72,19 @@ class IdentityMap : public IdentityMapBase {
// as the identity, returning: // as the identity, returning:
// found => a pointer to the storage location for the value // found => a pointer to the storage location for the value
// not found => a pointer to a new storage location for the value // not found => a pointer to a new storage location for the value
V* Get(Handle<Object> key) { return reinterpret_cast<V*>(GetEntry(key)); } V* Get(Handle<Object> key) { return Get(*key); }
V* Get(Object* key) { return reinterpret_cast<V*>(GetEntry(key)); }
// Searches this map for the given key using the object's address // Searches this map for the given key using the object's address
// as the identity, returning: // as the identity, returning:
// found => a pointer to the storage location for the value // found => a pointer to the storage location for the value
// not found => {nullptr} // not found => {nullptr}
V* Find(Handle<Object> key) { return reinterpret_cast<V*>(FindEntry(key)); } V* Find(Handle<Object> key) { return Find(*key); }
V* Find(Object* key) { return reinterpret_cast<V*>(FindEntry(key)); }
// Set the value for the given key. // Set the value for the given key.
void Set(Handle<Object> key, V value) { void Set(Handle<Object> key, V v) { Set(*key, v); }
*(reinterpret_cast<V*>(GetEntry(key))) = value; void Set(Object* key, V v) { *(reinterpret_cast<V*>(GetEntry(key))) = v; }
}
}; };
} // namespace internal } // namespace internal
} // namespace v8 } // namespace v8
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment