| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "vm/parser.h" | 5 #include "vm/parser.h" |
| 6 #include "vm/flags.h" | 6 #include "vm/flags.h" |
| 7 | 7 |
| 8 #ifndef DART_PRECOMPILED_RUNTIME | 8 #ifndef DART_PRECOMPILED_RUNTIME |
| 9 | 9 |
| 10 #include "lib/invocation_mirror.h" | 10 #include "lib/invocation_mirror.h" |
| (...skipping 12116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12127 bool Parser::IsInstantiatorRequired() const { | 12127 bool Parser::IsInstantiatorRequired() const { |
| 12128 ASSERT(!current_function().IsNull()); | 12128 ASSERT(!current_function().IsNull()); |
| 12129 if (current_function().is_static() && | 12129 if (current_function().is_static() && |
| 12130 !current_function().IsInFactoryScope()) { | 12130 !current_function().IsInFactoryScope()) { |
| 12131 return false; | 12131 return false; |
| 12132 } | 12132 } |
| 12133 return current_class().IsGeneric(); | 12133 return current_class().IsGeneric(); |
| 12134 } | 12134 } |
| 12135 | 12135 |
| 12136 | 12136 |
| 12137 void Parser::InsertCachedConstantValue(const String& url, | 12137 void Parser::InsertCachedConstantValue(const Script& script, |
| 12138 TokenPosition token_pos, | 12138 TokenPosition token_pos, |
| 12139 const Instance& value) { | 12139 const Instance& value) { |
| 12140 ASSERT(Thread::Current()->IsMutatorThread()); | 12140 ASSERT(Thread::Current()->IsMutatorThread()); |
| 12141 Isolate* isolate = Isolate::Current(); | 12141 const intptr_t kInitialConstMapSize = 16; |
| 12142 ConstantPosKey key(url, token_pos); | 12142 if (script.InVMHeap()) { |
| 12143 if (isolate->object_store()->compile_time_constants() == Array::null()) { | 12143 // For scripts in the vm heap, their constants are in a shared |
| 12144 const intptr_t kInitialConstMapSize = 16; | 12144 // per-isolate map. |
| 12145 isolate->object_store()->set_compile_time_constants( | 12145 Isolate* isolate = Isolate::Current(); |
| 12146 Array::Handle(HashTables::New<ConstantsMap>(kInitialConstMapSize, | 12146 const String& url = String::Handle(script.url()); |
| 12147 Heap::kNew))); | 12147 UrlAndPosKey key(url, token_pos); |
| 12148 if (isolate->object_store()->vm_compile_time_constants() == Array::null()) { |
| 12149 isolate->object_store()->set_vm_compile_time_constants( |
| 12150 Array::Handle(HashTables::New<VMConstantsMap>( |
| 12151 kInitialConstMapSize, Heap::kNew))); |
| 12152 } |
| 12153 VMConstantsMap constants( |
| 12154 isolate->object_store()->vm_compile_time_constants()); |
| 12155 constants.InsertNewOrGetValue(key, value); |
| 12156 isolate->object_store()->set_vm_compile_time_constants(constants.Release()); |
| 12157 } else { |
| 12158 // For scripts which are not in the vm heap, their constants are |
| 12159 // stored in the script itself. |
| 12160 if (script.compile_time_constants() == Array::null()) { |
| 12161 const Array& array = |
| 12162 Array::Handle(HashTables::New<ConstantsMap>(kInitialConstMapSize, |
| 12163 Heap::kNew)); |
| 12164 script.set_compile_time_constants(array); |
| 12165 } |
| 12166 ConstantsMap constants(script.compile_time_constants()); |
| 12167 constants.InsertNewOrGetValue(token_pos, value); |
| 12168 script.set_compile_time_constants(constants.Release()); |
| 12148 } | 12169 } |
| 12149 ConstantsMap constants(isolate->object_store()->compile_time_constants()); | |
| 12150 constants.InsertNewOrGetValue(key, value); | |
| 12151 isolate->object_store()->set_compile_time_constants(constants.Release()); | |
| 12152 } | 12170 } |
| 12153 | 12171 |
| 12154 | 12172 |
| 12155 void Parser::CacheConstantValue(TokenPosition token_pos, | 12173 void Parser::CacheConstantValue(TokenPosition token_pos, |
| 12156 const Instance& value) { | 12174 const Instance& value) { |
| 12157 if (current_function().kind() == RawFunction::kImplicitStaticFinalGetter) { | 12175 if (current_function().kind() == RawFunction::kImplicitStaticFinalGetter) { |
| 12158 // Don't cache constants in initializer expressions. They get | 12176 // Don't cache constants in initializer expressions. They get |
| 12159 // evaluated only once. | 12177 // evaluated only once. |
| 12160 return; | 12178 return; |
| 12161 } | 12179 } |
| 12162 const String& url = String::Handle(Z, script_.url()); | 12180 InsertCachedConstantValue(script_, token_pos, value); |
| 12163 InsertCachedConstantValue(url, token_pos, value); | |
| 12164 if (FLAG_compiler_stats) { | |
| 12165 ConstantsMap constants(isolate()->object_store()->compile_time_constants()); | |
| 12166 thread_->compiler_stats()->num_cached_consts = constants.NumOccupied(); | |
| 12167 constants.Release(); | |
| 12168 } | |
| 12169 } | 12181 } |
| 12170 | 12182 |
| 12171 | 12183 |
| 12172 bool Parser::GetCachedConstant(TokenPosition token_pos, Instance* value) { | 12184 bool Parser::GetCachedConstant(TokenPosition token_pos, Instance* value) { |
| 12173 if (isolate()->object_store()->compile_time_constants() == Array::null()) { | 12185 bool is_present = false; |
| 12174 return false; | 12186 if (script_.InVMHeap()) { |
| 12187 // For scripts in the vm heap, their constants are in a shared |
| 12188 // per-isolate map. |
| 12189 if (isolate()->object_store()->vm_compile_time_constants() == |
| 12190 Array::null()) { |
| 12191 return false; |
| 12192 } |
| 12193 UrlAndPosKey key(String::Handle(Z, script_.url()), token_pos); |
| 12194 VMConstantsMap constants( |
| 12195 isolate()->object_store()->vm_compile_time_constants()); |
| 12196 *value ^= constants.GetOrNull(key, &is_present); |
| 12197 // Mutator compiler thread may add constants while background compiler |
| 12198 // is running, and thus change the value of 'vm_compile_time_constants'; |
| 12199 // do not assert that 'vm_compile_time_constants' has not changed. |
| 12200 constants.Release(); |
| 12201 } else { |
| 12202 // For scripts which are not in the vm heap, their constants are |
| 12203 // stored in the script itself. |
| 12204 if (script_.compile_time_constants() == Array::null()) { |
| 12205 return false; |
| 12206 } |
| 12207 ConstantsMap constants(script_.compile_time_constants()); |
| 12208 *value ^= constants.GetOrNull(token_pos, &is_present); |
| 12209 // Mutator compiler thread may add constants while background compiler |
| 12210 // is running, and thus change the value of 'compile_time_constants'; |
| 12211 // do not assert that 'compile_time_constants' has not changed. |
| 12212 constants.Release(); |
| 12175 } | 12213 } |
| 12176 ConstantPosKey key(String::Handle(Z, script_.url()), token_pos); | |
| 12177 ConstantsMap constants(isolate()->object_store()->compile_time_constants()); | |
| 12178 bool is_present = false; | |
| 12179 *value ^= constants.GetOrNull(key, &is_present); | |
| 12180 // Mutator compiler thread may add constants while background compiler | |
| 12181 // is running , and thus change the value of 'compile_time_constants'; | |
| 12182 // do not assert that 'compile_time_constants' has not changed. | |
| 12183 constants.Release(); | |
| 12184 if (FLAG_compiler_stats && is_present) { | 12214 if (FLAG_compiler_stats && is_present) { |
| 12185 thread_->compiler_stats()->num_const_cache_hits++; | 12215 thread_->compiler_stats()->num_const_cache_hits++; |
| 12186 } | 12216 } |
| 12187 return is_present; | 12217 return is_present; |
| 12188 } | 12218 } |
| 12189 | 12219 |
| 12190 | 12220 |
| 12191 RawInstance* Parser::TryCanonicalize(const Instance& instance, | 12221 RawInstance* Parser::TryCanonicalize(const Instance& instance, |
| 12192 TokenPosition token_pos) { | 12222 TokenPosition token_pos) { |
| 12193 if (instance.IsNull()) { | 12223 if (instance.IsNull()) { |
| (...skipping 2426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14620 return Object::null(); | 14650 return Object::null(); |
| 14621 } | 14651 } |
| 14622 | 14652 |
| 14623 | 14653 |
| 14624 ParsedFunction* Parser::ParseStaticFieldInitializer(const Field& field) { | 14654 ParsedFunction* Parser::ParseStaticFieldInitializer(const Field& field) { |
| 14625 UNREACHABLE(); | 14655 UNREACHABLE(); |
| 14626 return NULL; | 14656 return NULL; |
| 14627 } | 14657 } |
| 14628 | 14658 |
| 14629 | 14659 |
| 14630 void Parser::InsertCachedConstantValue(const String& url, | 14660 void Parser::InsertCachedConstantValue(const Script& script, |
| 14631 TokenPosition token_pos, | 14661 TokenPosition token_pos, |
| 14632 const Instance& value) { | 14662 const Instance& value) { |
| 14633 UNREACHABLE(); | 14663 UNREACHABLE(); |
| 14634 } | 14664 } |
| 14635 | 14665 |
| 14636 | 14666 |
| 14637 ArgumentListNode* Parser::BuildNoSuchMethodArguments( | 14667 ArgumentListNode* Parser::BuildNoSuchMethodArguments( |
| 14638 TokenPosition call_pos, | 14668 TokenPosition call_pos, |
| 14639 const String& function_name, | 14669 const String& function_name, |
| 14640 const ArgumentListNode& function_args, | 14670 const ArgumentListNode& function_args, |
| 14641 const LocalVariable* temp_for_last_arg, | 14671 const LocalVariable* temp_for_last_arg, |
| 14642 bool is_super_invocation) { | 14672 bool is_super_invocation) { |
| 14643 UNREACHABLE(); | 14673 UNREACHABLE(); |
| 14644 return NULL; | 14674 return NULL; |
| 14645 } | 14675 } |
| 14646 | 14676 |
| 14647 } // namespace dart | 14677 } // namespace dart |
| 14648 | 14678 |
| 14649 #endif // DART_PRECOMPILED_RUNTIME | 14679 #endif // DART_PRECOMPILED_RUNTIME |
| OLD | NEW |