Revision: 20578
Author: [email protected]
Date: Tue Apr 8 12:33:08 2014 UTC
Log: Handlify CompilationCache.
BUG=
[email protected]
Review URL: https://codereview.chromium.org/224733022
http://code.google.com/p/v8/source/detail?r=20578
Modified:
/branches/bleeding_edge/src/compilation-cache.cc
/branches/bleeding_edge/src/compilation-cache.h
/branches/bleeding_edge/src/compiler.cc
/branches/bleeding_edge/src/jsregexp.cc
/branches/bleeding_edge/src/objects.cc
/branches/bleeding_edge/src/objects.h
=======================================
--- /branches/bleeding_edge/src/compilation-cache.cc Tue Mar 11 14:41:22
2014 UTC
+++ /branches/bleeding_edge/src/compilation-cache.cc Tue Apr 8 12:33:08
2014 UTC
@@ -184,7 +184,7 @@
{ HandleScope scope(isolate());
for (generation = 0; generation < generations(); generation++) {
Handle<CompilationCacheTable> table = GetTable(generation);
- Handle<Object> probe(table->Lookup(*source, *context), isolate());
+ Handle<Object> probe = table->Lookup(source, context);
if (probe->IsSharedFunctionInfo()) {
Handle<SharedFunctionInfo> function_info =
Handle<SharedFunctionInfo>::cast(probe);
@@ -237,36 +237,19 @@
return Handle<SharedFunctionInfo>::null();
}
}
-
-
-MaybeObject* CompilationCacheScript::TryTablePut(
- Handle<String> source,
- Handle<Context> context,
- Handle<SharedFunctionInfo> function_info) {
- Handle<CompilationCacheTable> table = GetFirstTable();
- return table->Put(*source, *context, *function_info);
-}
-
-
-Handle<CompilationCacheTable> CompilationCacheScript::TablePut(
- Handle<String> source,
- Handle<Context> context,
- Handle<SharedFunctionInfo> function_info) {
- CALL_HEAP_FUNCTION(isolate(),
- TryTablePut(source, context, function_info),
- CompilationCacheTable);
-}
void CompilationCacheScript::Put(Handle<String> source,
Handle<Context> context,
Handle<SharedFunctionInfo> function_info)
{
HandleScope scope(isolate());
- SetFirstTable(TablePut(source, context, function_info));
+ Handle<CompilationCacheTable> table = GetFirstTable();
+ SetFirstTable(
+ CompilationCacheTable::Put(table, source, context, function_info));
}
-Handle<SharedFunctionInfo> CompilationCacheEval::Lookup(
+MaybeHandle<SharedFunctionInfo> CompilationCacheEval::Lookup(
Handle<String> source,
Handle<Context> context,
StrictMode strict_mode,
@@ -274,21 +257,20 @@
// Make sure not to leak the table into the surrounding handle
// scope. Otherwise, we risk keeping old tables around even after
// having cleared the cache.
- Object* result = NULL;
+ Handle<Object> result = isolate()->factory()->undefined_value();
int generation;
{ HandleScope scope(isolate());
+ Handle<Object> temp = result;
for (generation = 0; generation < generations(); generation++) {
Handle<CompilationCacheTable> table = GetTable(generation);
- result = table->LookupEval(
- *source, *context, strict_mode, scope_position);
- if (result->IsSharedFunctionInfo()) {
- break;
- }
+ temp = table->LookupEval(source, context, strict_mode,
scope_position);
+ if (temp->IsSharedFunctionInfo()) break;
}
+ if (temp->IsSharedFunctionInfo()) result = scope.CloseAndEscape(temp);
}
if (result->IsSharedFunctionInfo()) {
- Handle<SharedFunctionInfo>
- function_info(SharedFunctionInfo::cast(result), isolate());
+ Handle<SharedFunctionInfo> function_info =
+ Handle<SharedFunctionInfo>::cast(result);
if (generation != 0) {
Put(source, context, function_info, scope_position);
}
@@ -296,31 +278,9 @@
return function_info;
} else {
isolate()->counters()->compilation_cache_misses()->Increment();
- return Handle<SharedFunctionInfo>::null();
+ return MaybeHandle<SharedFunctionInfo>();
}
}
-
-
-MaybeObject* CompilationCacheEval::TryTablePut(
- Handle<String> source,
- Handle<Context> context,
- Handle<SharedFunctionInfo> function_info,
- int scope_position) {
- Handle<CompilationCacheTable> table = GetFirstTable();
- return table->PutEval(*source, *context, *function_info, scope_position);
-}
-
-
-Handle<CompilationCacheTable> CompilationCacheEval::TablePut(
- Handle<String> source,
- Handle<Context> context,
- Handle<SharedFunctionInfo> function_info,
- int scope_position) {
- CALL_HEAP_FUNCTION(isolate(),
- TryTablePut(
- source, context, function_info, scope_position),
- CompilationCacheTable);
-}
void CompilationCacheEval::Put(Handle<String> source,
@@ -328,28 +288,34 @@
Handle<SharedFunctionInfo> function_info,
int scope_position) {
HandleScope scope(isolate());
- SetFirstTable(TablePut(source, context, function_info, scope_position));
+ Handle<CompilationCacheTable> table = GetFirstTable();
+ table = CompilationCacheTable::PutEval(table, source, context,
+ function_info, scope_position);
+ SetFirstTable(table);
}
-Handle<FixedArray> CompilationCacheRegExp::Lookup(Handle<String> source,
- JSRegExp::Flags flags) {
+MaybeHandle<FixedArray> CompilationCacheRegExp::Lookup(
+ Handle<String> source,
+ JSRegExp::Flags flags) {
// Make sure not to leak the table into the surrounding handle
// scope. Otherwise, we risk keeping old tables around even after
// having cleared the cache.
- Object* result = NULL;
+ Handle<Object> result = isolate()->factory()->undefined_value();
int generation;
{ HandleScope scope(isolate());
+ Handle<Object> temp = result;
for (generation = 0; generation < generations(); generation++) {
Handle<CompilationCacheTable> table = GetTable(generation);
- result = table->LookupRegExp(*source, flags);
- if (result->IsFixedArray()) {
+ temp = table->LookupRegExp(source, flags);
+ if (temp->IsFixedArray()) {
break;
}
}
+ if (temp->IsSharedFunctionInfo()) result = scope.CloseAndEscape(temp);
}
if (result->IsFixedArray()) {
- Handle<FixedArray> data(FixedArray::cast(result), isolate());
+ Handle<FixedArray> data = Handle<FixedArray>::cast(result);
if (generation != 0) {
Put(source, flags, data);
}
@@ -357,35 +323,17 @@
return data;
} else {
isolate()->counters()->compilation_cache_misses()->Increment();
- return Handle<FixedArray>::null();
+ return MaybeHandle<FixedArray>();
}
}
-
-
-MaybeObject* CompilationCacheRegExp::TryTablePut(
- Handle<String> source,
- JSRegExp::Flags flags,
- Handle<FixedArray> data) {
- Handle<CompilationCacheTable> table = GetFirstTable();
- return table->PutRegExp(*source, flags, *data);
-}
-
-
-Handle<CompilationCacheTable> CompilationCacheRegExp::TablePut(
- Handle<String> source,
- JSRegExp::Flags flags,
- Handle<FixedArray> data) {
- CALL_HEAP_FUNCTION(isolate(),
- TryTablePut(source, flags, data),
- CompilationCacheTable);
-}
void CompilationCacheRegExp::Put(Handle<String> source,
JSRegExp::Flags flags,
Handle<FixedArray> data) {
HandleScope scope(isolate());
- SetFirstTable(TablePut(source, flags, data));
+ Handle<CompilationCacheTable> table = GetFirstTable();
+ SetFirstTable(CompilationCacheTable::PutRegExp(table, source, flags,
data));
}
@@ -398,36 +346,28 @@
}
-Handle<SharedFunctionInfo> CompilationCache::LookupScript(
+MaybeHandle<SharedFunctionInfo> CompilationCache::LookupScript(
Handle<String> source,
Handle<Object> name,
int line_offset,
int column_offset,
bool is_shared_cross_origin,
Handle<Context> context) {
- if (!IsEnabled()) {
- return Handle<SharedFunctionInfo>::null();
- }
+ if (!IsEnabled()) return MaybeHandle<SharedFunctionInfo>();
- return script_.Lookup(source,
- name,
- line_offset,
- column_offset,
- is_shared_cross_origin,
- context);
+ return script_.Lookup(source, name, line_offset, column_offset,
+ is_shared_cross_origin, context);
}
-Handle<SharedFunctionInfo> CompilationCache::LookupEval(
+MaybeHandle<SharedFunctionInfo> CompilationCache::LookupEval(
Handle<String> source,
Handle<Context> context,
StrictMode strict_mode,
int scope_position) {
- if (!IsEnabled()) {
- return Handle<SharedFunctionInfo>::null();
- }
+ if (!IsEnabled()) return MaybeHandle<SharedFunctionInfo>();
- Handle<SharedFunctionInfo> result;
+ MaybeHandle<SharedFunctionInfo> result;
if (context->IsNativeContext()) {
result = eval_global_.Lookup(
source, context, strict_mode, scope_position);
@@ -440,11 +380,9 @@
}
-Handle<FixedArray> CompilationCache::LookupRegExp(Handle<String> source,
+MaybeHandle<FixedArray> CompilationCache::LookupRegExp(Handle<String>
source,
JSRegExp::Flags flags) {
- if (!IsEnabled()) {
- return Handle<FixedArray>::null();
- }
+ if (!IsEnabled()) return MaybeHandle<FixedArray>();
return reg_exp_.Lookup(source, flags);
}
=======================================
--- /branches/bleeding_edge/src/compilation-cache.h Tue Mar 11 14:41:22
2014 UTC
+++ /branches/bleeding_edge/src/compilation-cache.h Tue Apr 8 12:33:08
2014 UTC
@@ -106,17 +106,6 @@
Handle<SharedFunctionInfo> function_info);
private:
- MUST_USE_RESULT MaybeObject* TryTablePut(
- Handle<String> source,
- Handle<Context> context,
- Handle<SharedFunctionInfo> function_info);
-
- // Note: Returns a new hash table if operation results in expansion.
- Handle<CompilationCacheTable> TablePut(
- Handle<String> source,
- Handle<Context> context,
- Handle<SharedFunctionInfo> function_info);
-
bool HasOrigin(Handle<SharedFunctionInfo> function_info,
Handle<Object> name,
int line_offset,
@@ -147,10 +136,10 @@
CompilationCacheEval(Isolate* isolate, int generations)
: CompilationSubCache(isolate, generations) { }
- Handle<SharedFunctionInfo> Lookup(Handle<String> source,
- Handle<Context> context,
- StrictMode strict_mode,
- int scope_position);
+ MaybeHandle<SharedFunctionInfo> Lookup(Handle<String> source,
+ Handle<Context> context,
+ StrictMode strict_mode,
+ int scope_position);
void Put(Handle<String> source,
Handle<Context> context,
@@ -158,19 +147,6 @@
int scope_position);
private:
- MUST_USE_RESULT MaybeObject* TryTablePut(
- Handle<String> source,
- Handle<Context> context,
- Handle<SharedFunctionInfo> function_info,
- int scope_position);
-
- // Note: Returns a new hash table if operation results in expansion.
- Handle<CompilationCacheTable> TablePut(
- Handle<String> source,
- Handle<Context> context,
- Handle<SharedFunctionInfo> function_info,
- int scope_position);
-
DISALLOW_IMPLICIT_CONSTRUCTORS(CompilationCacheEval);
};
@@ -181,21 +157,12 @@
CompilationCacheRegExp(Isolate* isolate, int generations)
: CompilationSubCache(isolate, generations) { }
- Handle<FixedArray> Lookup(Handle<String> source, JSRegExp::Flags flags);
+ MaybeHandle<FixedArray> Lookup(Handle<String> source, JSRegExp::Flags
flags);
void Put(Handle<String> source,
JSRegExp::Flags flags,
Handle<FixedArray> data);
private:
- MUST_USE_RESULT MaybeObject* TryTablePut(Handle<String> source,
- JSRegExp::Flags flags,
- Handle<FixedArray> data);
-
- // Note: Returns a new hash table if operation results in expansion.
- Handle<CompilationCacheTable> TablePut(Handle<String> source,
- JSRegExp::Flags flags,
- Handle<FixedArray> data);
-
DISALLOW_IMPLICIT_CONSTRUCTORS(CompilationCacheRegExp);
};
@@ -209,25 +176,21 @@
// Finds the script shared function info for a source
// string. Returns an empty handle if the cache doesn't contain a
// script for the given source string with the right origin.
- Handle<SharedFunctionInfo> LookupScript(Handle<String> source,
- Handle<Object> name,
- int line_offset,
- int column_offset,
- bool is_shared_cross_origin,
- Handle<Context> context);
+ MaybeHandle<SharedFunctionInfo> LookupScript(
+ Handle<String> source, Handle<Object> name, int line_offset,
+ int column_offset, bool is_shared_cross_origin, Handle<Context>
context);
// Finds the shared function info for a source string for eval in a
// given context. Returns an empty handle if the cache doesn't
// contain a script for the given source string.
- Handle<SharedFunctionInfo> LookupEval(Handle<String> source,
- Handle<Context> context,
- StrictMode strict_mode,
- int scope_position);
+ MaybeHandle<SharedFunctionInfo> LookupEval(
+ Handle<String> source, Handle<Context> context, StrictMode
strict_mode,
+ int scope_position);
// Returns the regexp data associated with the given regexp if it
// is in cache, otherwise an empty handle.
- Handle<FixedArray> LookupRegExp(Handle<String> source,
- JSRegExp::Flags flags);
+ MaybeHandle<FixedArray> LookupRegExp(
+ Handle<String> source, JSRegExp::Flags flags);
// Associate the (source, kind) pair to the shared function
// info. This may overwrite an existing mapping.
=======================================
--- /branches/bleeding_edge/src/compiler.cc Mon Apr 7 07:40:18 2014 UTC
+++ /branches/bleeding_edge/src/compiler.cc Tue Apr 8 12:33:08 2014 UTC
@@ -877,10 +877,12 @@
isolate->counters()->total_compile_size()->Increment(source_length);
CompilationCache* compilation_cache = isolate->compilation_cache();
- Handle<SharedFunctionInfo> shared_info = compilation_cache->LookupEval(
- source, context, strict_mode, scope_position);
+ MaybeHandle<SharedFunctionInfo> maybe_shared_info =
+ compilation_cache->LookupEval(source, context, strict_mode,
+ scope_position);
+ Handle<SharedFunctionInfo> shared_info;
- if (shared_info.is_null()) {
+ if (!maybe_shared_info.ToHandle(&shared_info)) {
Handle<Script> script = isolate->factory()->NewScript(source);
CompilationInfoWithZone info(script);
info.MarkAsEval();
@@ -945,17 +947,15 @@
CompilationCache* compilation_cache = isolate->compilation_cache();
// Do a lookup in the compilation cache but not for extensions.
+ MaybeHandle<SharedFunctionInfo> maybe_result;
Handle<SharedFunctionInfo> result;
if (extension == NULL) {
- result = compilation_cache->LookupScript(source,
- script_name,
- line_offset,
- column_offset,
- is_shared_cross_origin,
- context);
+ maybe_result = compilation_cache->LookupScript(
+ source, script_name, line_offset, column_offset,
+ is_shared_cross_origin, context);
}
- if (result.is_null()) {
+ if (!maybe_result.ToHandle(&result)) {
// No cache entry found. Compile the script.
// Create a script object describing the script to be compiled.
@@ -981,11 +981,10 @@
if (extension == NULL && !result.is_null() && !result->dont_cache()) {
compilation_cache->PutScript(source, context, result);
}
+ if (result.is_null()) isolate->ReportPendingMessages();
} else if (result->ic_age() != isolate->heap()->global_ic_age()) {
result->ResetForNewContext(isolate->heap()->global_ic_age());
}
-
- if (result.is_null()) isolate->ReportPendingMessages();
return result;
}
=======================================
--- /branches/bleeding_edge/src/jsregexp.cc Tue Apr 8 09:49:49 2014 UTC
+++ /branches/bleeding_edge/src/jsregexp.cc Tue Apr 8 12:33:08 2014 UTC
@@ -175,8 +175,10 @@
Zone zone(isolate);
JSRegExp::Flags flags = RegExpFlagsFromString(flag_str);
CompilationCache* compilation_cache = isolate->compilation_cache();
- Handle<FixedArray> cached = compilation_cache->LookupRegExp(pattern,
flags);
- bool in_cache = !cached.is_null();
+ MaybeHandle<FixedArray> maybe_cached =
+ compilation_cache->LookupRegExp(pattern, flags);
+ Handle<FixedArray> cached;
+ bool in_cache = maybe_cached.ToHandle(&cached);
LOG(isolate, RegExpCompileEvent(re, in_cache));
Handle<Object> result;
=======================================
--- /branches/bleeding_edge/src/objects.cc Tue Apr 8 09:49:49 2014 UTC
+++ /branches/bleeding_edge/src/objects.cc Tue Apr 8 12:33:08 2014 UTC
@@ -13742,8 +13742,8 @@
// StringSharedKeys are used as keys in the eval cache.
class StringSharedKey : public HashTableKey {
public:
- StringSharedKey(String* source,
- SharedFunctionInfo* shared,
+ StringSharedKey(Handle<String> source,
+ Handle<SharedFunctionInfo> shared,
StrictMode strict_mode,
int scope_position)
: source_(source),
@@ -13752,10 +13752,11 @@
scope_position_(scope_position) { }
bool IsMatch(Object* other) {
+ DisallowHeapAllocation no_allocation;
if (!other->IsFixedArray()) return false;
FixedArray* other_array = FixedArray::cast(other);
SharedFunctionInfo* shared =
SharedFunctionInfo::cast(other_array->get(0));
- if (shared != shared_) return false;
+ if (shared != *shared_) return false;
int strict_unchecked = Smi::cast(other_array->get(2))->value();
ASSERT(strict_unchecked == SLOPPY || strict_unchecked == STRICT);
StrictMode strict_mode = static_cast<StrictMode>(strict_unchecked);
@@ -13763,7 +13764,7 @@
int scope_position = Smi::cast(other_array->get(3))->value();
if (scope_position != scope_position_) return false;
String* source = String::cast(other_array->get(1));
- return source->Equals(source_);
+ return source->Equals(*source_);
}
static uint32_t StringSharedHashHelper(String* source,
@@ -13777,7 +13778,7 @@
// script source code and the start position of the calling scope.
// We do this to ensure that the cache entries can survive garbage
// collection.
- Script* script = Script::cast(shared->script());
+ Script* script(Script::cast(shared->script()));
hash ^= String::cast(script->source())->Hash();
if (strict_mode == STRICT) hash ^= 0x8000;
hash += scope_position;
@@ -13786,11 +13787,12 @@
}
uint32_t Hash() {
- return StringSharedHashHelper(
- source_, shared_, strict_mode_, scope_position_);
+ return StringSharedHashHelper(*source_, *shared_, strict_mode_,
+ scope_position_);
}
uint32_t HashForObject(Object* obj) {
+ DisallowHeapAllocation no_allocation;
FixedArray* other_array = FixedArray::cast(obj);
SharedFunctionInfo* shared =
SharedFunctionInfo::cast(other_array->get(0));
String* source = String::cast(other_array->get(1));
@@ -13802,22 +13804,25 @@
source, shared, strict_mode, scope_position);
}
- MUST_USE_RESULT MaybeObject* AsObject(Heap* heap) {
- Object* obj;
- { MaybeObject* maybe_obj = heap->AllocateFixedArray(4);
- if (!maybe_obj->ToObject(&obj)) return maybe_obj;
- }
- FixedArray* other_array = FixedArray::cast(obj);
- other_array->set(0, shared_);
- other_array->set(1, source_);
- other_array->set(2, Smi::FromInt(strict_mode_));
- other_array->set(3, Smi::FromInt(scope_position_));
- return other_array;
+
+ Object* AsObject(Heap* heap) {
+ UNREACHABLE();
+ return NULL;
+ }
+
+
+ Handle<Object> AsObject(Factory* factory) {
+ Handle<FixedArray> array = factory->NewFixedArray(4);
+ array->set(0, *shared_);
+ array->set(1, *source_);
+ array->set(2, Smi::FromInt(strict_mode_));
+ array->set(3, Smi::FromInt(scope_position_));
+ return array;
}
private:
- String* source_;
- SharedFunctionInfo* shared_;
+ Handle<String> source_;
+ Handle<SharedFunctionInfo> shared_;
StrictMode strict_mode_;
int scope_position_;
};
@@ -15014,116 +15019,101 @@
}
-Object* CompilationCacheTable::Lookup(String* src, Context* context) {
- SharedFunctionInfo* shared = context->closure()->shared();
- StringSharedKey key(src,
- shared,
- FLAG_use_strict ? STRICT : SLOPPY,
+Handle<Object> CompilationCacheTable::Lookup(Handle<String> src,
+ Handle<Context> context) {
+ Isolate* isolate = GetIsolate();
+ Handle<SharedFunctionInfo> shared(context->closure()->shared());
+ StringSharedKey key(src, shared, FLAG_use_strict ? STRICT : SLOPPY,
RelocInfo::kNoPosition);
int entry = FindEntry(&key);
- if (entry == kNotFound) return GetHeap()->undefined_value();
- return get(EntryToIndex(entry) + 1);
+ if (entry == kNotFound) return isolate->factory()->undefined_value();
+ return Handle<Object>(get(EntryToIndex(entry) + 1), isolate);
}
-Object* CompilationCacheTable::LookupEval(String* src,
- Context* context,
- StrictMode strict_mode,
- int scope_position) {
- StringSharedKey key(src,
- context->closure()->shared(),
- strict_mode,
- scope_position);
+Handle<Object> CompilationCacheTable::LookupEval(Handle<String> src,
+ Handle<Context> context,
+ StrictMode strict_mode,
+ int scope_position) {
+ Isolate* isolate = GetIsolate();
+ Handle<SharedFunctionInfo> shared(context->closure()->shared());
+ StringSharedKey key(src, shared, strict_mode, scope_position);
int entry = FindEntry(&key);
- if (entry == kNotFound) return GetHeap()->undefined_value();
- return get(EntryToIndex(entry) + 1);
+ if (entry == kNotFound) return isolate->factory()->undefined_value();
+ return Handle<Object>(get(EntryToIndex(entry) + 1), isolate);
}
-Object* CompilationCacheTable::LookupRegExp(String* src,
- JSRegExp::Flags flags) {
- RegExpKey key(src, flags);
+Handle<Object> CompilationCacheTable::LookupRegExp(Handle<String> src,
+ JSRegExp::Flags flags) {
+ Isolate* isolate = GetIsolate();
+ DisallowHeapAllocation no_allocation;
+ RegExpKey key(*src, flags);
int entry = FindEntry(&key);
- if (entry == kNotFound) return GetHeap()->undefined_value();
- return get(EntryToIndex(entry) + 1);
+ if (entry == kNotFound) return isolate->factory()->undefined_value();
+ return Handle<Object>(get(EntryToIndex(entry) + 1), isolate);
}
-MaybeObject* CompilationCacheTable::Put(String* src,
- Context* context,
- Object* value) {
- SharedFunctionInfo* shared = context->closure()->shared();
- StringSharedKey key(src,
- shared,
- FLAG_use_strict ? STRICT : SLOPPY,
+Handle<CompilationCacheTable> CompilationCacheTable::Put(
+ Handle<CompilationCacheTable> cache, Handle<String> src,
+ Handle<Context> context, Handle<Object> value) {
+ Isolate* isolate = cache->GetIsolate();
+ Handle<SharedFunctionInfo> shared(context->closure()->shared());
+ StringSharedKey key(src, shared, FLAG_use_strict ? STRICT : SLOPPY,
RelocInfo::kNoPosition);
- CompilationCacheTable* cache;
- MaybeObject* maybe_cache = EnsureCapacity(1, &key);
- if (!maybe_cache->To(&cache)) return maybe_cache;
-
- Object* k;
- MaybeObject* maybe_k = key.AsObject(GetHeap());
- if (!maybe_k->To(&k)) return maybe_k;
-
+ cache = EnsureCapacityFor(cache, 1, &key);
+ Handle<Object> k = key.AsObject(isolate->factory());
int entry = cache->FindInsertionEntry(key.Hash());
- cache->set(EntryToIndex(entry), k);
- cache->set(EntryToIndex(entry) + 1, value);
+ cache->set(EntryToIndex(entry), *k);
+ cache->set(EntryToIndex(entry) + 1, *value);
cache->ElementAdded();
return cache;
}
-MaybeObject* CompilationCacheTable::PutEval(String* src,
- Context* context,
- SharedFunctionInfo* value,
- int scope_position) {
- StringSharedKey key(src,
- context->closure()->shared(),
- value->strict_mode(),
- scope_position);
- Object* obj;
- { MaybeObject* maybe_obj = EnsureCapacity(1, &key);
- if (!maybe_obj->ToObject(&obj)) return maybe_obj;
- }
-
- CompilationCacheTable* cache =
- reinterpret_cast<CompilationCacheTable*>(obj);
+Handle<CompilationCacheTable> CompilationCacheTable::PutEval(
+ Handle<CompilationCacheTable> cache, Handle<String> src,
+ Handle<Context> context, Handle<SharedFunctionInfo> value,
+ int scope_position) {
+ Isolate* isolate = cache->GetIsolate();
+ Handle<SharedFunctionInfo> shared(context->closure()->shared());
+ StringSharedKey key(src, shared, value->strict_mode(), scope_position);
+ cache = EnsureCapacityFor(cache, 1, &key);
+ Handle<Object> k = key.AsObject(isolate->factory());
int entry = cache->FindInsertionEntry(key.Hash());
-
- Object* k;
- { MaybeObject* maybe_k = key.AsObject(GetHeap());
- if (!maybe_k->ToObject(&k)) return maybe_k;
- }
-
- cache->set(EntryToIndex(entry), k);
- cache->set(EntryToIndex(entry) + 1, value);
+ cache->set(EntryToIndex(entry), *k);
+ cache->set(EntryToIndex(entry) + 1, *value);
cache->ElementAdded();
return cache;
}
-
-MaybeObject* CompilationCacheTable::PutRegExp(String* src,
- JSRegExp::Flags flags,
- FixedArray* value) {
- RegExpKey key(src, flags);
- Object* obj;
- { MaybeObject* maybe_obj = EnsureCapacity(1, &key);
- if (!maybe_obj->ToObject(&obj)) return maybe_obj;
- }
- CompilationCacheTable* cache =
- reinterpret_cast<CompilationCacheTable*>(obj);
+Handle<CompilationCacheTable> CompilationCacheTable::PutRegExp(
+ Handle<CompilationCacheTable> cache, Handle<String> src,
+ JSRegExp::Flags flags, Handle<FixedArray> value) {
+ RegExpKey key(*src, flags);
+ cache = EnsureCapacityFor(cache, 1, &key);
int entry = cache->FindInsertionEntry(key.Hash());
// We store the value in the key slot, and compare the search key
// to the stored value with a custon IsMatch function during lookups.
- cache->set(EntryToIndex(entry), value);
- cache->set(EntryToIndex(entry) + 1, value);
+ cache->set(EntryToIndex(entry), *value);
+ cache->set(EntryToIndex(entry) + 1, *value);
cache->ElementAdded();
return cache;
}
+
+
+Handle<CompilationCacheTable> CompilationCacheTable::EnsureCapacityFor(
+ Handle<CompilationCacheTable> cache, int n, HashTableKey* key) {
+ CALL_HEAP_FUNCTION(cache->GetIsolate(),
+ cache->EnsureCapacity(n, key),
+ CompilationCacheTable);
+}
void CompilationCacheTable::Remove(Object* value) {
+ DisallowHeapAllocation no_allocation;
Object* the_hole_value = GetHeap()->the_hole_value();
for (int entry = 0, size = Capacity(); entry < size; entry++) {
int entry_index = EntryToIndex(entry);
=======================================
--- /branches/bleeding_edge/src/objects.h Tue Apr 8 10:00:57 2014 UTC
+++ /branches/bleeding_edge/src/objects.h Tue Apr 8 12:33:08 2014 UTC
@@ -8200,24 +8200,22 @@
HashTableKey*> {
public:
// Find cached value for a string key, otherwise return null.
- Object* Lookup(String* src, Context* context);
- Object* LookupEval(String* src,
- Context* context,
- StrictMode strict_mode,
- int scope_position);
- Object* LookupRegExp(String* source, JSRegExp::Flags flags);
- MUST_USE_RESULT MaybeObject* Put(String* src,
- Context* context,
- Object* value);
- MUST_USE_RESULT MaybeObject* PutEval(String* src,
- Context* context,
- SharedFunctionInfo* value,
- int scope_position);
- MUST_USE_RESULT MaybeObject* PutRegExp(String* src,
- JSRegExp::Flags flags,
- FixedArray* value);
-
- // Remove given value from cache.
+ Handle<Object> Lookup(Handle<String> src, Handle<Context> context);
+ Handle<Object> LookupEval(Handle<String> src, Handle<Context> context,
+ StrictMode strict_mode, int scope_position);
+ Handle<Object> LookupRegExp(Handle<String> source, JSRegExp::Flags
flags);
+ static Handle<CompilationCacheTable> Put(
+ Handle<CompilationCacheTable> cache, Handle<String> src,
+ Handle<Context> context, Handle<Object> value);
+ static Handle<CompilationCacheTable> PutEval(
+ Handle<CompilationCacheTable> cache, Handle<String> src,
+ Handle<Context> context, Handle<SharedFunctionInfo> value,
+ int scope_position);
+ static Handle<CompilationCacheTable> PutRegExp(
+ Handle<CompilationCacheTable> cache, Handle<String> src,
+ JSRegExp::Flags flags, Handle<FixedArray> value);
+ static Handle<CompilationCacheTable> EnsureCapacityFor(
+ Handle<CompilationCacheTable> cache, int n, HashTableKey* key);
void Remove(Object* value);
static inline CompilationCacheTable* cast(Object* obj);
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.