| 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();
|
|
|