Resolve race condition with GC in CompilationCacheTable::Put.

The trouble is that the AsHandle method can allocate and thus
invoke GC, which could empty the table while we are updating it.

BUG=chromium:430880
LOG=N
R=verwaest@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#25229}
git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@25229 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
jarin@chromium.org 2014-11-10 05:50:11 +00:00
parent 8977e3d5e4
commit c53fa96773

View File

@ -15014,16 +15014,19 @@ Handle<CompilationCacheTable> CompilationCacheTable::Put(
Handle<SharedFunctionInfo> shared(context->closure()->shared());
StringSharedKey key(src, shared, FLAG_use_strict ? STRICT : SLOPPY,
RelocInfo::kNoPosition);
int entry = cache->FindEntry(&key);
if (entry != kNotFound) {
{
Handle<Object> k = key.AsHandle(isolate);
cache->set(EntryToIndex(entry), *k);
cache->set(EntryToIndex(entry) + 1, *value);
return cache;
DisallowHeapAllocation no_allocation_scope;
int entry = cache->FindEntry(&key);
if (entry != kNotFound) {
cache->set(EntryToIndex(entry), *k);
cache->set(EntryToIndex(entry) + 1, *value);
return cache;
}
}
cache = EnsureCapacity(cache, 1, &key);
entry = cache->FindInsertionEntry(key.Hash());
int entry = cache->FindInsertionEntry(key.Hash());
Handle<Object> k =
isolate->factory()->NewNumber(static_cast<double>(key.Hash()));
cache->set(EntryToIndex(entry), *k);
@ -15039,16 +15042,19 @@ Handle<CompilationCacheTable> CompilationCacheTable::PutEval(
int scope_position) {
Isolate* isolate = cache->GetIsolate();
StringSharedKey key(src, outer_info, value->strict_mode(), scope_position);
int entry = cache->FindEntry(&key);
if (entry != kNotFound) {
{
Handle<Object> k = key.AsHandle(isolate);
cache->set(EntryToIndex(entry), *k);
cache->set(EntryToIndex(entry) + 1, *value);
return cache;
DisallowHeapAllocation no_allocation_scope;
int entry = cache->FindEntry(&key);
if (entry != kNotFound) {
cache->set(EntryToIndex(entry), *k);
cache->set(EntryToIndex(entry) + 1, *value);
return cache;
}
}
cache = EnsureCapacity(cache, 1, &key);
entry = cache->FindInsertionEntry(key.Hash());
int entry = cache->FindInsertionEntry(key.Hash());
Handle<Object> k =
isolate->factory()->NewNumber(static_cast<double>(key.Hash()));
cache->set(EntryToIndex(entry), *k);