| 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 12127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12138 } | 12138 } |
| 12139 return current_class().IsGeneric(); | 12139 return current_class().IsGeneric(); |
| 12140 } | 12140 } |
| 12141 | 12141 |
| 12142 | 12142 |
| 12143 void Parser::InsertCachedConstantValue(const Script& script, | 12143 void Parser::InsertCachedConstantValue(const Script& script, |
| 12144 TokenPosition token_pos, | 12144 TokenPosition token_pos, |
| 12145 const Instance& value) { | 12145 const Instance& value) { |
| 12146 ASSERT(Thread::Current()->IsMutatorThread()); | 12146 ASSERT(Thread::Current()->IsMutatorThread()); |
| 12147 const intptr_t kInitialConstMapSize = 16; | 12147 const intptr_t kInitialConstMapSize = 16; |
| 12148 if (script.InVMHeap()) { | 12148 ASSERT(!script.InVMHeap()); |
| 12149 // For scripts in the vm heap, their constants are in a shared | 12149 if (script.compile_time_constants() == Array::null()) { |
| 12150 // per-isolate map. | 12150 const Array& array = |
| 12151 Isolate* isolate = Isolate::Current(); | 12151 Array::Handle(HashTables::New<ConstantsMap>(kInitialConstMapSize, |
| 12152 const String& url = String::Handle(script.url()); | 12152 Heap::kNew)); |
| 12153 UrlAndPosKey key(url, token_pos); | 12153 script.set_compile_time_constants(array); |
| 12154 if (isolate->object_store()->vm_compile_time_constants() == Array::null()) { | |
| 12155 isolate->object_store()->set_vm_compile_time_constants( | |
| 12156 Array::Handle(HashTables::New<VMConstantsMap>( | |
| 12157 kInitialConstMapSize, Heap::kNew))); | |
| 12158 } | |
| 12159 VMConstantsMap constants( | |
| 12160 isolate->object_store()->vm_compile_time_constants()); | |
| 12161 constants.InsertNewOrGetValue(key, value); | |
| 12162 isolate->object_store()->set_vm_compile_time_constants(constants.Release()); | |
| 12163 } else { | |
| 12164 // For scripts which are not in the vm heap, their constants are | |
| 12165 // stored in the script itself. | |
| 12166 if (script.compile_time_constants() == Array::null()) { | |
| 12167 const Array& array = | |
| 12168 Array::Handle(HashTables::New<ConstantsMap>(kInitialConstMapSize, | |
| 12169 Heap::kNew)); | |
| 12170 script.set_compile_time_constants(array); | |
| 12171 } | |
| 12172 ConstantsMap constants(script.compile_time_constants()); | |
| 12173 constants.InsertNewOrGetValue(token_pos, value); | |
| 12174 script.set_compile_time_constants(constants.Release()); | |
| 12175 } | 12154 } |
| 12155 ConstantsMap constants(script.compile_time_constants()); |
| 12156 constants.InsertNewOrGetValue(token_pos, value); |
| 12157 script.set_compile_time_constants(constants.Release()); |
| 12176 } | 12158 } |
| 12177 | 12159 |
| 12178 | 12160 |
| 12179 void Parser::CacheConstantValue(TokenPosition token_pos, | 12161 void Parser::CacheConstantValue(TokenPosition token_pos, |
| 12180 const Instance& value) { | 12162 const Instance& value) { |
| 12181 if (current_function().kind() == RawFunction::kImplicitStaticFinalGetter) { | 12163 if (current_function().kind() == RawFunction::kImplicitStaticFinalGetter) { |
| 12182 // Don't cache constants in initializer expressions. They get | 12164 // Don't cache constants in initializer expressions. They get |
| 12183 // evaluated only once. | 12165 // evaluated only once. |
| 12184 return; | 12166 return; |
| 12185 } | 12167 } |
| 12186 InsertCachedConstantValue(script_, token_pos, value); | 12168 InsertCachedConstantValue(script_, token_pos, value); |
| 12187 } | 12169 } |
| 12188 | 12170 |
| 12189 | 12171 |
| 12190 bool Parser::GetCachedConstant(TokenPosition token_pos, Instance* value) { | 12172 bool Parser::GetCachedConstant(TokenPosition token_pos, Instance* value) { |
| 12191 bool is_present = false; | 12173 bool is_present = false; |
| 12192 if (script_.InVMHeap()) { | 12174 ASSERT(!script_.InVMHeap()); |
| 12193 // For scripts in the vm heap, their constants are in a shared | 12175 if (script_.compile_time_constants() == Array::null()) { |
| 12194 // per-isolate map. | 12176 return false; |
| 12195 if (isolate()->object_store()->vm_compile_time_constants() == | |
| 12196 Array::null()) { | |
| 12197 return false; | |
| 12198 } | |
| 12199 UrlAndPosKey key(String::Handle(Z, script_.url()), token_pos); | |
| 12200 VMConstantsMap constants( | |
| 12201 isolate()->object_store()->vm_compile_time_constants()); | |
| 12202 *value ^= constants.GetOrNull(key, &is_present); | |
| 12203 // Mutator compiler thread may add constants while background compiler | |
| 12204 // is running, and thus change the value of 'vm_compile_time_constants'; | |
| 12205 // do not assert that 'vm_compile_time_constants' has not changed. | |
| 12206 constants.Release(); | |
| 12207 } else { | |
| 12208 // For scripts which are not in the vm heap, their constants are | |
| 12209 // stored in the script itself. | |
| 12210 if (script_.compile_time_constants() == Array::null()) { | |
| 12211 return false; | |
| 12212 } | |
| 12213 ConstantsMap constants(script_.compile_time_constants()); | |
| 12214 *value ^= constants.GetOrNull(token_pos, &is_present); | |
| 12215 // Mutator compiler thread may add constants while background compiler | |
| 12216 // is running, and thus change the value of 'compile_time_constants'; | |
| 12217 // do not assert that 'compile_time_constants' has not changed. | |
| 12218 constants.Release(); | |
| 12219 } | 12177 } |
| 12178 ConstantsMap constants(script_.compile_time_constants()); |
| 12179 *value ^= constants.GetOrNull(token_pos, &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(); |
| 12220 if (FLAG_compiler_stats && is_present) { | 12184 if (FLAG_compiler_stats && is_present) { |
| 12221 thread_->compiler_stats()->num_const_cache_hits++; | 12185 thread_->compiler_stats()->num_const_cache_hits++; |
| 12222 } | 12186 } |
| 12223 return is_present; | 12187 return is_present; |
| 12224 } | 12188 } |
| 12225 | 12189 |
| 12226 | 12190 |
| 12227 RawInstance* Parser::TryCanonicalize(const Instance& instance, | 12191 RawInstance* Parser::TryCanonicalize(const Instance& instance, |
| 12228 TokenPosition token_pos) { | 12192 TokenPosition token_pos) { |
| 12229 if (instance.IsNull()) { | 12193 if (instance.IsNull()) { |
| (...skipping 2446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14676 const ArgumentListNode& function_args, | 14640 const ArgumentListNode& function_args, |
| 14677 const LocalVariable* temp_for_last_arg, | 14641 const LocalVariable* temp_for_last_arg, |
| 14678 bool is_super_invocation) { | 14642 bool is_super_invocation) { |
| 14679 UNREACHABLE(); | 14643 UNREACHABLE(); |
| 14680 return NULL; | 14644 return NULL; |
| 14681 } | 14645 } |
| 14682 | 14646 |
| 14683 } // namespace dart | 14647 } // namespace dart |
| 14684 | 14648 |
| 14685 #endif // DART_PRECOMPILED_RUNTIME | 14649 #endif // DART_PRECOMPILED_RUNTIME |
| OLD | NEW |