Commit 5c6e003e authored by Toon Verwaest's avatar Toon Verwaest Committed by Commit Bot

[runtime] Flatten cons strings before accessing compilation cache

We'd flatten upon compile anyway; and hashing the cons string also
creates a local flattened version that's not cached.

Change-Id: Ib5c82385ab009464b45bf1ceb289d04caaa77fcf
Reviewed-on: https://chromium-review.googlesource.com/c/1309827Reviewed-by: 's avatarIgor Sheludko <ishell@chromium.org>
Commit-Queue: Maya Lekova <mslekova@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57182}
parent ebd070ec
......@@ -137,8 +137,8 @@ MaybeHandle<SharedFunctionInfo> CompilationCacheScript::Lookup(
const int generation = 0;
DCHECK_EQ(generations(), 1);
Handle<CompilationCacheTable> table = GetTable(generation);
MaybeHandle<SharedFunctionInfo> probe =
table->LookupScript(source, native_context, language_mode);
MaybeHandle<SharedFunctionInfo> probe = CompilationCacheTable::LookupScript(
table, source, native_context, language_mode);
Handle<SharedFunctionInfo> function_info;
if (probe.ToHandle(&function_info)) {
// Break when we've found a suitable shared function info that
......@@ -192,8 +192,8 @@ InfoCellPair CompilationCacheEval::Lookup(Handle<String> source,
const int generation = 0;
DCHECK_EQ(generations(), 1);
Handle<CompilationCacheTable> table = GetTable(generation);
result = table->LookupEval(source, outer_info, native_context, language_mode,
position);
result = CompilationCacheTable::LookupEval(
table, source, outer_info, native_context, language_mode, position);
if (result.has_shared()) {
isolate()->counters()->compilation_cache_hits()->Increment();
} else {
......
......@@ -17547,20 +17547,24 @@ FeedbackCell* SearchLiteralsMap(CompilationCacheTable* cache, int cache_entry,
} // namespace
MaybeHandle<SharedFunctionInfo> CompilationCacheTable::LookupScript(
Handle<String> src, Handle<Context> native_context,
LanguageMode language_mode) {
Handle<CompilationCacheTable> table, Handle<String> src,
Handle<Context> native_context, LanguageMode language_mode) {
// We use the empty function SFI as part of the key. Although the
// empty_function is native context dependent, the SFI is de-duped on
// snapshot builds by the PartialSnapshotCache, and so this does not prevent
// reuse of scripts in the compilation cache across native contexts.
Handle<SharedFunctionInfo> shared(native_context->empty_function()->shared(),
native_context->GetIsolate());
Isolate* isolate = native_context->GetIsolate();
src = String::Flatten(isolate, src);
StringSharedKey key(src, shared, language_mode, kNoSourcePosition);
int entry = FindEntry(GetIsolate(), &key);
int entry = table->FindEntry(isolate, &key);
if (entry == kNotFound) return MaybeHandle<SharedFunctionInfo>();
int index = EntryToIndex(entry);
if (!get(index)->IsFixedArray()) return MaybeHandle<SharedFunctionInfo>();
Object* obj = get(index + 1);
if (!table->get(index)->IsFixedArray()) {
return MaybeHandle<SharedFunctionInfo>();
}
Object* obj = table->get(index + 1);
if (obj->IsSharedFunctionInfo()) {
return handle(SharedFunctionInfo::cast(obj), native_context->GetIsolate());
}
......@@ -17568,18 +17572,21 @@ MaybeHandle<SharedFunctionInfo> CompilationCacheTable::LookupScript(
}
InfoCellPair CompilationCacheTable::LookupEval(
Handle<String> src, Handle<SharedFunctionInfo> outer_info,
Handle<Context> native_context, LanguageMode language_mode, int position) {
Handle<CompilationCacheTable> table, Handle<String> src,
Handle<SharedFunctionInfo> outer_info, Handle<Context> native_context,
LanguageMode language_mode, int position) {
InfoCellPair empty_result;
Isolate* isolate = native_context->GetIsolate();
src = String::Flatten(isolate, src);
StringSharedKey key(src, outer_info, language_mode, position);
int entry = FindEntry(GetIsolate(), &key);
int entry = table->FindEntry(isolate, &key);
if (entry == kNotFound) return empty_result;
int index = EntryToIndex(entry);
if (!get(index)->IsFixedArray()) return empty_result;
Object* obj = get(EntryToIndex(entry) + 1);
if (!table->get(index)->IsFixedArray()) return empty_result;
Object* obj = table->get(EntryToIndex(entry) + 1);
if (obj->IsSharedFunctionInfo()) {
FeedbackCell* feedback_cell =
SearchLiteralsMap(this, EntryToIndex(entry) + 2, *native_context);
SearchLiteralsMap(*table, EntryToIndex(entry) + 2, *native_context);
return InfoCellPair(SharedFunctionInfo::cast(obj), feedback_cell);
}
return empty_result;
......@@ -17606,6 +17613,7 @@ Handle<CompilationCacheTable> CompilationCacheTable::PutScript(
// reuse of scripts in the compilation cache across native contexts.
Handle<SharedFunctionInfo> shared(native_context->empty_function()->shared(),
isolate);
src = String::Flatten(isolate, src);
StringSharedKey key(src, shared, language_mode, kNoSourcePosition);
Handle<Object> k = key.AsHandle(isolate);
cache = EnsureCapacity(isolate, cache, 1);
......@@ -17622,6 +17630,7 @@ Handle<CompilationCacheTable> CompilationCacheTable::PutEval(
Handle<Context> native_context, Handle<FeedbackCell> feedback_cell,
int position) {
Isolate* isolate = native_context->GetIsolate();
src = String::Flatten(isolate, src);
StringSharedKey key(src, outer_info, value->language_mode(), position);
{
Handle<Object> k = key.AsHandle(isolate);
......
......@@ -69,12 +69,14 @@ class CompilationCacheTable
: public HashTable<CompilationCacheTable, CompilationCacheShape>,
public NeverReadOnlySpaceObject {
public:
MaybeHandle<SharedFunctionInfo> LookupScript(Handle<String> src,
Handle<Context> native_context,
LanguageMode language_mode);
InfoCellPair LookupEval(Handle<String> src, Handle<SharedFunctionInfo> shared,
Handle<Context> native_context,
LanguageMode language_mode, int position);
static MaybeHandle<SharedFunctionInfo> LookupScript(
Handle<CompilationCacheTable> table, Handle<String> src,
Handle<Context> native_context, LanguageMode language_mode);
static InfoCellPair LookupEval(Handle<CompilationCacheTable> table,
Handle<String> src,
Handle<SharedFunctionInfo> shared,
Handle<Context> native_context,
LanguageMode language_mode, int position);
Handle<Object> LookupRegExp(Handle<String> source, JSRegExp::Flags flags);
static Handle<CompilationCacheTable> PutScript(
Handle<CompilationCacheTable> cache, Handle<String> src,
......
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