Commit 96e5434b authored by ishell@chromium.org's avatar ishell@chromium.org

WeakHashTable::Put() and callers handlified.

R=yangguo@chromium.org

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20959 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 6d477530
......@@ -5672,20 +5672,20 @@ void Heap::RemoveGCEpilogueCallback(v8::Isolate::GCEpilogueCallback callback) {
}
MaybeObject* Heap::AddWeakObjectToCodeDependency(Object* obj,
DependentCode* dep) {
ASSERT(!InNewSpace(obj));
ASSERT(!InNewSpace(dep));
MaybeObject* maybe_obj =
WeakHashTable::cast(weak_object_to_code_table_)->Put(obj, dep);
WeakHashTable* table;
if (!maybe_obj->To(&table)) return maybe_obj;
if (ShouldZapGarbage() && weak_object_to_code_table_ != table) {
// TODO(ishell): Find a better place for this.
void Heap::AddWeakObjectToCodeDependency(Handle<Object> obj,
Handle<DependentCode> dep) {
ASSERT(!InNewSpace(*obj));
ASSERT(!InNewSpace(*dep));
Handle<WeakHashTable> table(WeakHashTable::cast(weak_object_to_code_table_),
isolate());
table = WeakHashTable::Put(table, obj, dep);
if (ShouldZapGarbage() && weak_object_to_code_table_ != *table) {
WeakHashTable::cast(weak_object_to_code_table_)->Zap(the_hole_value());
}
set_weak_object_to_code_table(table);
ASSERT_EQ(dep, WeakHashTable::cast(weak_object_to_code_table_)->Lookup(obj));
return weak_object_to_code_table_;
set_weak_object_to_code_table(*table);
ASSERT_EQ(*dep, table->Lookup(*obj));
}
......
......@@ -1703,7 +1703,8 @@ class Heap {
Heap* heap_;
};
MaybeObject* AddWeakObjectToCodeDependency(Object* obj, DependentCode* dep);
void AddWeakObjectToCodeDependency(Handle<Object> obj,
Handle<DependentCode> dep);
DependentCode* LookupWeakObjectToCodeDependency(Object* obj);
......
......@@ -180,8 +180,7 @@ static void AddWeakObjectToCodeDependency(Isolate* isolate,
heap->EnsureWeakObjectToCodeTable();
Handle<DependentCode> dep(heap->LookupWeakObjectToCodeDependency(*object));
dep = DependentCode::Insert(dep, DependentCode::kWeakCodeGroup, code);
CALL_HEAP_FUNCTION_VOID(isolate,
heap->AddWeakObjectToCodeDependency(*object, *dep));
heap->AddWeakObjectToCodeDependency(object, dep);
}
......
......@@ -16246,29 +16246,31 @@ Object* WeakHashTable::Lookup(Object* key) {
}
MaybeObject* WeakHashTable::Put(Object* key, Object* value) {
ASSERT(IsKey(key));
int entry = FindEntry(key);
Handle<WeakHashTable> WeakHashTable::Put(Handle<WeakHashTable> table,
Handle<Object> key,
Handle<Object> value) {
ASSERT(table->IsKey(*key));
int entry = table->FindEntry(*key);
// Key is already in table, just overwrite value.
if (entry != kNotFound) {
set(EntryToValueIndex(entry), value);
return this;
table->set(EntryToValueIndex(entry), *value);
return table;
}
// Check whether the hash table should be extended.
Object* obj;
{ MaybeObject* maybe_obj = EnsureCapacity(1, key, TENURED);
if (!maybe_obj->ToObject(&obj)) return maybe_obj;
}
WeakHashTable* table = WeakHashTable::cast(obj);
table->AddEntry(table->FindInsertionEntry(Hash(key)), key, value);
table = EnsureCapacity(table, 1, *key, TENURED);
table->AddEntry(table->FindInsertionEntry(table->Hash(*key)), key, value);
return table;
}
void WeakHashTable::AddEntry(int entry, Object* key, Object* value) {
set(EntryToIndex(entry), key);
set(EntryToValueIndex(entry), value);
void WeakHashTable::AddEntry(int entry,
Handle<Object> key,
Handle<Object> value) {
DisallowHeapAllocation no_allocation;
set(EntryToIndex(entry), *key);
set(EntryToValueIndex(entry), *value);
ElementAdded();
}
......
......@@ -4524,7 +4524,9 @@ class WeakHashTable: public HashTable<WeakHashTable,
// Adds (or overwrites) the value associated with the given key. Mapping a
// key to the hole value causes removal of the whole entry.
MUST_USE_RESULT MaybeObject* Put(Object* key, Object* value);
MUST_USE_RESULT static Handle<WeakHashTable> Put(Handle<WeakHashTable> table,
Handle<Object> key,
Handle<Object> value);
// This function is called when heap verification is turned on.
void Zap(Object* value) {
......@@ -4538,7 +4540,7 @@ class WeakHashTable: public HashTable<WeakHashTable,
private:
friend class MarkCompactCollector;
void AddEntry(int entry, Object* key, Object* value);
void AddEntry(int entry, Handle<Object> key, Handle<Object> value);
// Returns the index to the value of an entry.
static inline int EntryToValueIndex(int entry) {
......
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