Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1966)

Unified Diff: runtime/vm/parser.cc

Issue 2126393003: Cache compile-time constants on the script object, sometimes. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Code review Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/parser.h ('k') | runtime/vm/precompiler.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/parser.cc
diff --git a/runtime/vm/parser.cc b/runtime/vm/parser.cc
index b08d7d846fb2586692b5643dc75eeb374b68afce..80493f29a304f8b34530a57165bf39cecde6d6eb 100644
--- a/runtime/vm/parser.cc
+++ b/runtime/vm/parser.cc
@@ -12134,21 +12134,39 @@ bool Parser::IsInstantiatorRequired() const {
}
-void Parser::InsertCachedConstantValue(const String& url,
+void Parser::InsertCachedConstantValue(const Script& script,
TokenPosition token_pos,
const Instance& value) {
ASSERT(Thread::Current()->IsMutatorThread());
- Isolate* isolate = Isolate::Current();
- ConstantPosKey key(url, token_pos);
- if (isolate->object_store()->compile_time_constants() == Array::null()) {
- const intptr_t kInitialConstMapSize = 16;
- isolate->object_store()->set_compile_time_constants(
- Array::Handle(HashTables::New<ConstantsMap>(kInitialConstMapSize,
- Heap::kNew)));
+ const intptr_t kInitialConstMapSize = 16;
+ if (script.InVMHeap()) {
+ // For scripts in the vm heap, their constants are in a shared
+ // per-isolate map.
+ Isolate* isolate = Isolate::Current();
+ const String& url = String::Handle(script.url());
+ UrlAndPosKey key(url, token_pos);
+ if (isolate->object_store()->vm_compile_time_constants() == Array::null()) {
+ isolate->object_store()->set_vm_compile_time_constants(
+ Array::Handle(HashTables::New<VMConstantsMap>(
+ kInitialConstMapSize, Heap::kNew)));
+ }
+ VMConstantsMap constants(
+ isolate->object_store()->vm_compile_time_constants());
+ constants.InsertNewOrGetValue(key, value);
+ isolate->object_store()->set_vm_compile_time_constants(constants.Release());
+ } else {
+ // For scripts which are not in the vm heap, their constants are
+ // stored in the script itself.
+ if (script.compile_time_constants() == Array::null()) {
+ const Array& array =
+ Array::Handle(HashTables::New<ConstantsMap>(kInitialConstMapSize,
+ Heap::kNew));
+ script.set_compile_time_constants(array);
+ }
+ ConstantsMap constants(script.compile_time_constants());
+ constants.InsertNewOrGetValue(token_pos, value);
+ script.set_compile_time_constants(constants.Release());
}
- ConstantsMap constants(isolate->object_store()->compile_time_constants());
- constants.InsertNewOrGetValue(key, value);
- isolate->object_store()->set_compile_time_constants(constants.Release());
}
@@ -12159,28 +12177,40 @@ void Parser::CacheConstantValue(TokenPosition token_pos,
// evaluated only once.
return;
}
- const String& url = String::Handle(Z, script_.url());
- InsertCachedConstantValue(url, token_pos, value);
- if (FLAG_compiler_stats) {
- ConstantsMap constants(isolate()->object_store()->compile_time_constants());
- thread_->compiler_stats()->num_cached_consts = constants.NumOccupied();
- constants.Release();
- }
+ InsertCachedConstantValue(script_, token_pos, value);
}
bool Parser::GetCachedConstant(TokenPosition token_pos, Instance* value) {
- if (isolate()->object_store()->compile_time_constants() == Array::null()) {
- return false;
- }
- ConstantPosKey key(String::Handle(Z, script_.url()), token_pos);
- ConstantsMap constants(isolate()->object_store()->compile_time_constants());
bool is_present = false;
- *value ^= constants.GetOrNull(key, &is_present);
- // Mutator compiler thread may add constants while background compiler
- // is running , and thus change the value of 'compile_time_constants';
- // do not assert that 'compile_time_constants' has not changed.
- constants.Release();
+ if (script_.InVMHeap()) {
+ // For scripts in the vm heap, their constants are in a shared
+ // per-isolate map.
+ if (isolate()->object_store()->vm_compile_time_constants() ==
+ Array::null()) {
+ return false;
+ }
+ UrlAndPosKey key(String::Handle(Z, script_.url()), token_pos);
+ VMConstantsMap constants(
+ isolate()->object_store()->vm_compile_time_constants());
+ *value ^= constants.GetOrNull(key, &is_present);
+ // Mutator compiler thread may add constants while background compiler
+ // is running, and thus change the value of 'vm_compile_time_constants';
+ // do not assert that 'vm_compile_time_constants' has not changed.
+ constants.Release();
+ } else {
+ // For scripts which are not in the vm heap, their constants are
+ // stored in the script itself.
+ if (script_.compile_time_constants() == Array::null()) {
+ return false;
+ }
+ ConstantsMap constants(script_.compile_time_constants());
+ *value ^= constants.GetOrNull(token_pos, &is_present);
+ // Mutator compiler thread may add constants while background compiler
+ // is running, and thus change the value of 'compile_time_constants';
+ // do not assert that 'compile_time_constants' has not changed.
+ constants.Release();
+ }
if (FLAG_compiler_stats && is_present) {
thread_->compiler_stats()->num_const_cache_hits++;
}
@@ -14627,7 +14657,7 @@ ParsedFunction* Parser::ParseStaticFieldInitializer(const Field& field) {
}
-void Parser::InsertCachedConstantValue(const String& url,
+void Parser::InsertCachedConstantValue(const Script& script,
TokenPosition token_pos,
const Instance& value) {
UNREACHABLE();
« no previous file with comments | « runtime/vm/parser.h ('k') | runtime/vm/precompiler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698