Commit eecde44f authored by rossberg's avatar rossberg Committed by Commit bot

Properly thread language mode to compilation cache

Fixes the TSAN issue.

R=mstarzinger@chromium.org
NOTRY=true
BUG=

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

Cr-Commit-Position: refs/heads/master@{#26623}
parent 1291400f
...@@ -1366,14 +1366,7 @@ bool Genesis::CompileExperimentalBuiltin(Isolate* isolate, int index) { ...@@ -1366,14 +1366,7 @@ bool Genesis::CompileExperimentalBuiltin(Isolate* isolate, int index) {
isolate, source_code, isolate, source_code,
factory->NewStringFromAscii(ExperimentalNatives::GetScriptSource(index)), factory->NewStringFromAscii(ExperimentalNatives::GetScriptSource(index)),
false); false);
return CompileNative(isolate, name, source_code);
// TODO(rossberg): The natives do not yet obey strong mode rules
// (for example, some macros use '==').
bool use_strong = FLAG_use_strong;
FLAG_use_strong = false;
bool result = CompileNative(isolate, name, source_code);
FLAG_use_strong = use_strong;
return result;
} }
......
...@@ -147,7 +147,8 @@ bool CompilationCacheScript::HasOrigin(Handle<SharedFunctionInfo> function_info, ...@@ -147,7 +147,8 @@ bool CompilationCacheScript::HasOrigin(Handle<SharedFunctionInfo> function_info,
Handle<SharedFunctionInfo> CompilationCacheScript::Lookup( Handle<SharedFunctionInfo> CompilationCacheScript::Lookup(
Handle<String> source, Handle<Object> name, int line_offset, Handle<String> source, Handle<Object> name, int line_offset,
int column_offset, bool is_embedder_debug_script, int column_offset, bool is_embedder_debug_script,
bool is_shared_cross_origin, Handle<Context> context) { bool is_shared_cross_origin, Handle<Context> context,
LanguageMode language_mode) {
Object* result = NULL; Object* result = NULL;
int generation; int generation;
...@@ -156,7 +157,7 @@ Handle<SharedFunctionInfo> CompilationCacheScript::Lookup( ...@@ -156,7 +157,7 @@ Handle<SharedFunctionInfo> CompilationCacheScript::Lookup(
{ HandleScope scope(isolate()); { HandleScope scope(isolate());
for (generation = 0; generation < generations(); generation++) { for (generation = 0; generation < generations(); generation++) {
Handle<CompilationCacheTable> table = GetTable(generation); Handle<CompilationCacheTable> table = GetTable(generation);
Handle<Object> probe = table->Lookup(source, context); Handle<Object> probe = table->Lookup(source, context, language_mode);
if (probe->IsSharedFunctionInfo()) { if (probe->IsSharedFunctionInfo()) {
Handle<SharedFunctionInfo> function_info = Handle<SharedFunctionInfo> function_info =
Handle<SharedFunctionInfo>::cast(probe); Handle<SharedFunctionInfo>::cast(probe);
...@@ -181,7 +182,7 @@ Handle<SharedFunctionInfo> CompilationCacheScript::Lookup( ...@@ -181,7 +182,7 @@ Handle<SharedFunctionInfo> CompilationCacheScript::Lookup(
is_embedder_debug_script, is_shared_cross_origin)); is_embedder_debug_script, is_shared_cross_origin));
// If the script was found in a later generation, we promote it to // If the script was found in a later generation, we promote it to
// the first generation to let it survive longer in the cache. // the first generation to let it survive longer in the cache.
if (generation != 0) Put(source, context, shared); if (generation != 0) Put(source, context, language_mode, shared);
isolate()->counters()->compilation_cache_hits()->Increment(); isolate()->counters()->compilation_cache_hits()->Increment();
return shared; return shared;
} else { } else {
...@@ -193,11 +194,12 @@ Handle<SharedFunctionInfo> CompilationCacheScript::Lookup( ...@@ -193,11 +194,12 @@ Handle<SharedFunctionInfo> CompilationCacheScript::Lookup(
void CompilationCacheScript::Put(Handle<String> source, void CompilationCacheScript::Put(Handle<String> source,
Handle<Context> context, Handle<Context> context,
LanguageMode language_mode,
Handle<SharedFunctionInfo> function_info) { Handle<SharedFunctionInfo> function_info) {
HandleScope scope(isolate()); HandleScope scope(isolate());
Handle<CompilationCacheTable> table = GetFirstTable(); Handle<CompilationCacheTable> table = GetFirstTable();
SetFirstTable( SetFirstTable(CompilationCacheTable::Put(table, source, context,
CompilationCacheTable::Put(table, source, context, function_info)); language_mode, function_info));
} }
...@@ -292,12 +294,13 @@ void CompilationCache::Remove(Handle<SharedFunctionInfo> function_info) { ...@@ -292,12 +294,13 @@ void CompilationCache::Remove(Handle<SharedFunctionInfo> function_info) {
MaybeHandle<SharedFunctionInfo> CompilationCache::LookupScript( MaybeHandle<SharedFunctionInfo> CompilationCache::LookupScript(
Handle<String> source, Handle<Object> name, int line_offset, Handle<String> source, Handle<Object> name, int line_offset,
int column_offset, bool is_embedder_debug_script, int column_offset, bool is_embedder_debug_script,
bool is_shared_cross_origin, Handle<Context> context) { bool is_shared_cross_origin, Handle<Context> context,
LanguageMode language_mode) {
if (!IsEnabled()) return MaybeHandle<SharedFunctionInfo>(); if (!IsEnabled()) return MaybeHandle<SharedFunctionInfo>();
return script_.Lookup(source, name, line_offset, column_offset, return script_.Lookup(source, name, line_offset, column_offset,
is_embedder_debug_script, is_shared_cross_origin, is_embedder_debug_script, is_shared_cross_origin,
context); context, language_mode);
} }
...@@ -329,10 +332,11 @@ MaybeHandle<FixedArray> CompilationCache::LookupRegExp(Handle<String> source, ...@@ -329,10 +332,11 @@ MaybeHandle<FixedArray> CompilationCache::LookupRegExp(Handle<String> source,
void CompilationCache::PutScript(Handle<String> source, void CompilationCache::PutScript(Handle<String> source,
Handle<Context> context, Handle<Context> context,
LanguageMode language_mode,
Handle<SharedFunctionInfo> function_info) { Handle<SharedFunctionInfo> function_info) {
if (!IsEnabled()) return; if (!IsEnabled()) return;
script_.Put(source, context, function_info); script_.Put(source, context, language_mode, function_info);
} }
......
...@@ -76,9 +76,11 @@ class CompilationCacheScript : public CompilationSubCache { ...@@ -76,9 +76,11 @@ class CompilationCacheScript : public CompilationSubCache {
int line_offset, int column_offset, int line_offset, int column_offset,
bool is_embedder_debug_script, bool is_embedder_debug_script,
bool is_shared_cross_origin, bool is_shared_cross_origin,
Handle<Context> context); Handle<Context> context,
LanguageMode language_mode);
void Put(Handle<String> source, void Put(Handle<String> source,
Handle<Context> context, Handle<Context> context,
LanguageMode language_mode,
Handle<SharedFunctionInfo> function_info); Handle<SharedFunctionInfo> function_info);
private: private:
...@@ -148,7 +150,8 @@ class CompilationCache { ...@@ -148,7 +150,8 @@ class CompilationCache {
MaybeHandle<SharedFunctionInfo> LookupScript( MaybeHandle<SharedFunctionInfo> LookupScript(
Handle<String> source, Handle<Object> name, int line_offset, Handle<String> source, Handle<Object> name, int line_offset,
int column_offset, bool is_embedder_debug_script, int column_offset, bool is_embedder_debug_script,
bool is_shared_cross_origin, Handle<Context> context); bool is_shared_cross_origin, Handle<Context> context,
LanguageMode language_mode);
// Finds the shared function info for a source string for eval in a // Finds the shared function info for a source string for eval in a
// given context. Returns an empty handle if the cache doesn't // given context. Returns an empty handle if the cache doesn't
...@@ -166,6 +169,7 @@ class CompilationCache { ...@@ -166,6 +169,7 @@ class CompilationCache {
// info. This may overwrite an existing mapping. // info. This may overwrite an existing mapping.
void PutScript(Handle<String> source, void PutScript(Handle<String> source,
Handle<Context> context, Handle<Context> context,
LanguageMode language_mode,
Handle<SharedFunctionInfo> function_info); Handle<SharedFunctionInfo> function_info);
// Associate the (source, context->closure()->shared(), kind) triple // Associate the (source, context->closure()->shared(), kind) triple
......
...@@ -1263,6 +1263,12 @@ Handle<SharedFunctionInfo> Compiler::CompileScript( ...@@ -1263,6 +1263,12 @@ Handle<SharedFunctionInfo> Compiler::CompileScript(
isolate->counters()->total_load_size()->Increment(source_length); isolate->counters()->total_load_size()->Increment(source_length);
isolate->counters()->total_compile_size()->Increment(source_length); isolate->counters()->total_compile_size()->Increment(source_length);
// TODO(rossberg): The natives do not yet obey strong mode rules
// (for example, some macros use '==').
bool use_strong = FLAG_use_strong && !isolate->bootstrapper()->IsActive();
LanguageMode language_mode =
construct_language_mode(FLAG_use_strict, use_strong);
CompilationCache* compilation_cache = isolate->compilation_cache(); CompilationCache* compilation_cache = isolate->compilation_cache();
// Do a lookup in the compilation cache but not for extensions. // Do a lookup in the compilation cache but not for extensions.
...@@ -1271,7 +1277,8 @@ Handle<SharedFunctionInfo> Compiler::CompileScript( ...@@ -1271,7 +1277,8 @@ Handle<SharedFunctionInfo> Compiler::CompileScript(
if (extension == NULL) { if (extension == NULL) {
maybe_result = compilation_cache->LookupScript( maybe_result = compilation_cache->LookupScript(
source, script_name, line_offset, column_offset, source, script_name, line_offset, column_offset,
is_embedder_debug_script, is_shared_cross_origin, context); is_embedder_debug_script, is_shared_cross_origin, context,
language_mode);
if (maybe_result.is_null() && FLAG_serialize_toplevel && if (maybe_result.is_null() && FLAG_serialize_toplevel &&
compile_options == ScriptCompiler::kConsumeCodeCache && compile_options == ScriptCompiler::kConsumeCodeCache &&
!isolate->debug()->is_loaded()) { !isolate->debug()->is_loaded()) {
...@@ -1322,14 +1329,11 @@ Handle<SharedFunctionInfo> Compiler::CompileScript( ...@@ -1322,14 +1329,11 @@ Handle<SharedFunctionInfo> Compiler::CompileScript(
info.PrepareForSerializing(); info.PrepareForSerializing();
} }
LanguageMode language_mode =
construct_language_mode(FLAG_use_strict, FLAG_use_strong);
info.SetLanguageMode( info.SetLanguageMode(
static_cast<LanguageMode>(info.language_mode() | language_mode)); static_cast<LanguageMode>(info.language_mode() | language_mode));
result = CompileToplevel(&info); result = CompileToplevel(&info);
if (extension == NULL && !result.is_null() && !result->dont_cache()) { if (extension == NULL && !result.is_null() && !result->dont_cache()) {
compilation_cache->PutScript(source, context, result); compilation_cache->PutScript(source, context, language_mode, result);
if (FLAG_serialize_toplevel && if (FLAG_serialize_toplevel &&
compile_options == ScriptCompiler::kProduceCodeCache) { compile_options == ScriptCompiler::kProduceCodeCache) {
HistogramTimerScope histogram_timer( HistogramTimerScope histogram_timer(
......
...@@ -840,10 +840,6 @@ void Shell::AddHistogramSample(void* histogram, int sample) { ...@@ -840,10 +840,6 @@ void Shell::AddHistogramSample(void* histogram, int sample) {
void Shell::InstallUtilityScript(Isolate* isolate) { void Shell::InstallUtilityScript(Isolate* isolate) {
HandleScope scope(isolate); HandleScope scope(isolate);
// TODO(rossberg): Utility scripts do not yet obey strong mode rules.
bool use_strong = i::FLAG_use_strong;
i::FLAG_use_strong = false;
// If we use the utility context, we have to set the security tokens so that // If we use the utility context, we have to set the security tokens so that
// utility, evaluation and debug context can all access each other. // utility, evaluation and debug context can all access each other.
v8::Local<v8::Context> utility_context = v8::Local<v8::Context> utility_context =
...@@ -893,8 +889,6 @@ void Shell::InstallUtilityScript(Isolate* isolate) { ...@@ -893,8 +889,6 @@ void Shell::InstallUtilityScript(Isolate* isolate) {
// Start the in-process debugger if requested. // Start the in-process debugger if requested.
if (i::FLAG_debugger) v8::Debug::SetDebugEventListener(HandleDebugEvent); if (i::FLAG_debugger) v8::Debug::SetDebugEventListener(HandleDebugEvent);
i::FLAG_use_strong = use_strong;
} }
#endif // !V8_SHARED #endif // !V8_SHARED
......
...@@ -15354,11 +15354,11 @@ Handle<String> StringTable::LookupKey(Isolate* isolate, HashTableKey* key) { ...@@ -15354,11 +15354,11 @@ Handle<String> StringTable::LookupKey(Isolate* isolate, HashTableKey* key) {
Handle<Object> CompilationCacheTable::Lookup(Handle<String> src, Handle<Object> CompilationCacheTable::Lookup(Handle<String> src,
Handle<Context> context) { Handle<Context> context,
LanguageMode language_mode) {
Isolate* isolate = GetIsolate(); Isolate* isolate = GetIsolate();
Handle<SharedFunctionInfo> shared(context->closure()->shared()); Handle<SharedFunctionInfo> shared(context->closure()->shared());
LanguageMode mode = construct_language_mode(FLAG_use_strict, FLAG_use_strong); StringSharedKey key(src, shared, language_mode, RelocInfo::kNoPosition);
StringSharedKey key(src, shared, mode, RelocInfo::kNoPosition);
int entry = FindEntry(&key); int entry = FindEntry(&key);
if (entry == kNotFound) return isolate->factory()->undefined_value(); if (entry == kNotFound) return isolate->factory()->undefined_value();
int index = EntryToIndex(entry); int index = EntryToIndex(entry);
...@@ -15395,11 +15395,10 @@ Handle<Object> CompilationCacheTable::LookupRegExp(Handle<String> src, ...@@ -15395,11 +15395,10 @@ Handle<Object> CompilationCacheTable::LookupRegExp(Handle<String> src,
Handle<CompilationCacheTable> CompilationCacheTable::Put( Handle<CompilationCacheTable> CompilationCacheTable::Put(
Handle<CompilationCacheTable> cache, Handle<String> src, Handle<CompilationCacheTable> cache, Handle<String> src,
Handle<Context> context, Handle<Object> value) { Handle<Context> context, LanguageMode language_mode, Handle<Object> value) {
Isolate* isolate = cache->GetIsolate(); Isolate* isolate = cache->GetIsolate();
Handle<SharedFunctionInfo> shared(context->closure()->shared()); Handle<SharedFunctionInfo> shared(context->closure()->shared());
LanguageMode mode = construct_language_mode(FLAG_use_strict, FLAG_use_strong); StringSharedKey key(src, shared, language_mode, RelocInfo::kNoPosition);
StringSharedKey key(src, shared, mode, RelocInfo::kNoPosition);
{ {
Handle<Object> k = key.AsHandle(isolate); Handle<Object> k = key.AsHandle(isolate);
DisallowHeapAllocation no_allocation_scope; DisallowHeapAllocation no_allocation_scope;
......
...@@ -8077,14 +8077,16 @@ class CompilationCacheTable: public HashTable<CompilationCacheTable, ...@@ -8077,14 +8077,16 @@ class CompilationCacheTable: public HashTable<CompilationCacheTable,
HashTableKey*> { HashTableKey*> {
public: public:
// Find cached value for a string key, otherwise return null. // Find cached value for a string key, otherwise return null.
Handle<Object> Lookup(Handle<String> src, Handle<Context> context); Handle<Object> Lookup(
Handle<Object> LookupEval(Handle<String> src, Handle<String> src, Handle<Context> context, LanguageMode language_mode);
Handle<SharedFunctionInfo> shared, Handle<Object> LookupEval(
Handle<String> src, Handle<SharedFunctionInfo> shared,
LanguageMode language_mode, int scope_position); LanguageMode language_mode, int scope_position);
Handle<Object> LookupRegExp(Handle<String> source, JSRegExp::Flags flags); Handle<Object> LookupRegExp(Handle<String> source, JSRegExp::Flags flags);
static Handle<CompilationCacheTable> Put( static Handle<CompilationCacheTable> Put(
Handle<CompilationCacheTable> cache, Handle<String> src, Handle<CompilationCacheTable> cache, Handle<String> src,
Handle<Context> context, Handle<Object> value); Handle<Context> context, LanguageMode language_mode,
Handle<Object> value);
static Handle<CompilationCacheTable> PutEval( static Handle<CompilationCacheTable> PutEval(
Handle<CompilationCacheTable> cache, Handle<String> src, Handle<CompilationCacheTable> cache, Handle<String> src,
Handle<SharedFunctionInfo> context, Handle<SharedFunctionInfo> value, Handle<SharedFunctionInfo> context, Handle<SharedFunctionInfo> value,
......
...@@ -1387,6 +1387,8 @@ TEST(CompilationCacheCachingBehavior) { ...@@ -1387,6 +1387,8 @@ TEST(CompilationCacheCachingBehavior) {
Factory* factory = isolate->factory(); Factory* factory = isolate->factory();
Heap* heap = isolate->heap(); Heap* heap = isolate->heap();
CompilationCache* compilation_cache = isolate->compilation_cache(); CompilationCache* compilation_cache = isolate->compilation_cache();
LanguageMode language_mode =
construct_language_mode(FLAG_use_strict, FLAG_use_strong);
v8::HandleScope scope(CcTest::isolate()); v8::HandleScope scope(CcTest::isolate());
const char* raw_source = const char* raw_source =
...@@ -1407,7 +1409,8 @@ TEST(CompilationCacheCachingBehavior) { ...@@ -1407,7 +1409,8 @@ TEST(CompilationCacheCachingBehavior) {
// On first compilation, only a hash is inserted in the code cache. We can't // On first compilation, only a hash is inserted in the code cache. We can't
// find that value. // find that value.
MaybeHandle<SharedFunctionInfo> info = compilation_cache->LookupScript( MaybeHandle<SharedFunctionInfo> info = compilation_cache->LookupScript(
source, Handle<Object>(), 0, 0, false, true, native_context); source, Handle<Object>(), 0, 0, false, true, native_context,
language_mode);
CHECK(info.is_null()); CHECK(info.is_null());
{ {
...@@ -1418,7 +1421,7 @@ TEST(CompilationCacheCachingBehavior) { ...@@ -1418,7 +1421,7 @@ TEST(CompilationCacheCachingBehavior) {
// On second compilation, the hash is replaced by a real cache entry mapping // On second compilation, the hash is replaced by a real cache entry mapping
// the source to the shared function info containing the code. // the source to the shared function info containing the code.
info = compilation_cache->LookupScript(source, Handle<Object>(), 0, 0, false, info = compilation_cache->LookupScript(source, Handle<Object>(), 0, 0, false,
true, native_context); true, native_context, language_mode);
CHECK(!info.is_null()); CHECK(!info.is_null());
heap->CollectAllGarbage(Heap::kNoGCFlags); heap->CollectAllGarbage(Heap::kNoGCFlags);
...@@ -1426,7 +1429,7 @@ TEST(CompilationCacheCachingBehavior) { ...@@ -1426,7 +1429,7 @@ TEST(CompilationCacheCachingBehavior) {
// On second compilation, the hash is replaced by a real cache entry mapping // On second compilation, the hash is replaced by a real cache entry mapping
// the source to the shared function info containing the code. // the source to the shared function info containing the code.
info = compilation_cache->LookupScript(source, Handle<Object>(), 0, 0, false, info = compilation_cache->LookupScript(source, Handle<Object>(), 0, 0, false,
true, native_context); true, native_context, language_mode);
CHECK(!info.is_null()); CHECK(!info.is_null());
while (!info.ToHandleChecked()->code()->IsOld()) { while (!info.ToHandleChecked()->code()->IsOld()) {
...@@ -1436,7 +1439,7 @@ TEST(CompilationCacheCachingBehavior) { ...@@ -1436,7 +1439,7 @@ TEST(CompilationCacheCachingBehavior) {
heap->CollectAllGarbage(Heap::kNoGCFlags); heap->CollectAllGarbage(Heap::kNoGCFlags);
// Ensure code aging cleared the entry from the cache. // Ensure code aging cleared the entry from the cache.
info = compilation_cache->LookupScript(source, Handle<Object>(), 0, 0, false, info = compilation_cache->LookupScript(source, Handle<Object>(), 0, 0, false,
true, native_context); true, native_context, language_mode);
CHECK(info.is_null()); CHECK(info.is_null());
{ {
...@@ -1447,7 +1450,7 @@ TEST(CompilationCacheCachingBehavior) { ...@@ -1447,7 +1450,7 @@ TEST(CompilationCacheCachingBehavior) {
// On first compilation, only a hash is inserted in the code cache. We can't // On first compilation, only a hash is inserted in the code cache. We can't
// find that value. // find that value.
info = compilation_cache->LookupScript(source, Handle<Object>(), 0, 0, false, info = compilation_cache->LookupScript(source, Handle<Object>(), 0, 0, false,
true, native_context); true, native_context, language_mode);
CHECK(info.is_null()); CHECK(info.is_null());
for (int i = 0; i < CompilationCacheTable::kHashGenerations; i++) { for (int i = 0; i < CompilationCacheTable::kHashGenerations; i++) {
...@@ -1462,7 +1465,7 @@ TEST(CompilationCacheCachingBehavior) { ...@@ -1462,7 +1465,7 @@ TEST(CompilationCacheCachingBehavior) {
// If we aged the cache before caching the script, ensure that we didn't cache // If we aged the cache before caching the script, ensure that we didn't cache
// on next compilation. // on next compilation.
info = compilation_cache->LookupScript(source, Handle<Object>(), 0, 0, false, info = compilation_cache->LookupScript(source, Handle<Object>(), 0, 0, false,
true, native_context); true, native_context, language_mode);
CHECK(info.is_null()); CHECK(info.is_null());
} }
......
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