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

Side by Side Diff: runtime/vm/kernel_reader.cc

Issue 2967593002: [kernel] Cache patch-classes. (Closed)
Patch Set: Created 3 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 unified diff | Download patch
« no previous file with comments | « runtime/vm/kernel_reader.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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/kernel_reader.h" 5 #include "vm/kernel_reader.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 8
9 #include "vm/dart_api_impl.h" 9 #include "vm/dart_api_impl.h"
10 #include "vm/kernel_binary.h" 10 #include "vm/kernel_binary.h"
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 return reader_->LookupClass(klass).raw(); 119 return reader_->LookupClass(klass).raw();
120 } 120 }
121 121
122 122
123 KernelReader::KernelReader(Program* program) 123 KernelReader::KernelReader(Program* program)
124 : program_(program), 124 : program_(program),
125 thread_(dart::Thread::Current()), 125 thread_(dart::Thread::Current()),
126 zone_(thread_->zone()), 126 zone_(thread_->zone()),
127 isolate_(thread_->isolate()), 127 isolate_(thread_->isolate()),
128 scripts_(Array::ZoneHandle(zone_)), 128 scripts_(Array::ZoneHandle(zone_)),
129 patch_classes_(Array::ZoneHandle(zone_)),
129 translation_helper_(this, thread_), 130 translation_helper_(this, thread_),
130 builder_(&translation_helper_, 131 builder_(&translation_helper_,
131 zone_, 132 zone_,
132 program_->kernel_data(), 133 program_->kernel_data(),
133 program_->kernel_data_size()) { 134 program_->kernel_data_size()) {
134 T.active_class_ = &active_class_; 135 T.active_class_ = &active_class_;
135 T.finalize_ = false; 136 T.finalize_ = false;
136 137
137 scripts_ = Array::New(builder_.SourceTableSize(), Heap::kOld); 138 scripts_ = Array::New(builder_.SourceTableSize(), Heap::kOld);
139 patch_classes_ = Array::New(builder_.SourceTableSize(), Heap::kOld);
138 140
139 // Copy the Kernel string offsets out of the binary and into the VM's heap. 141 // Copy the Kernel string offsets out of the binary and into the VM's heap.
140 ASSERT(program->string_table_offset() >= 0); 142 ASSERT(program->string_table_offset() >= 0);
141 Reader reader(program->kernel_data(), program->kernel_data_size()); 143 Reader reader(program->kernel_data(), program->kernel_data_size());
142 reader.set_offset(program->string_table_offset()); 144 reader.set_offset(program->string_table_offset());
143 intptr_t count = reader.ReadUInt() + 1; 145 intptr_t count = reader.ReadUInt() + 1;
144 TypedData& offsets = TypedData::Handle( 146 TypedData& offsets = TypedData::Handle(
145 Z, TypedData::New(kTypedDataUint32ArrayCid, count, Heap::kOld)); 147 Z, TypedData::New(kTypedDataUint32ArrayCid, count, Heap::kOld));
146 offsets.SetUint32(0, 0); 148 offsets.SetUint32(0, 0);
147 intptr_t end_offset = 0; 149 intptr_t end_offset = 0;
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after
673 procedure_offset); 675 procedure_offset);
674 } 676 }
675 677
676 procedure_helper.ReadUntilExcluding(ProcedureHelper::kEnd); 678 procedure_helper.ReadUntilExcluding(ProcedureHelper::kEnd);
677 } 679 }
678 680
679 const Object& KernelReader::ClassForScriptAt(const dart::Class& klass, 681 const Object& KernelReader::ClassForScriptAt(const dart::Class& klass,
680 intptr_t source_uri_index) { 682 intptr_t source_uri_index) {
681 Script& correct_script = ScriptAt(source_uri_index); 683 Script& correct_script = ScriptAt(source_uri_index);
682 if (klass.script() != correct_script.raw()) { 684 if (klass.script() != correct_script.raw()) {
683 // TODO(jensj): We could probably cache this so we don't create 685 // Use cache for patch classes. This works best for in-order usages.
684 // new PatchClasses all the time 686 PatchClass& patch_class = PatchClass::ZoneHandle(Z);
685 return PatchClass::ZoneHandle(Z, PatchClass::New(klass, correct_script)); 687 patch_class ^= patch_classes_.At(source_uri_index);
688 if (patch_class.IsNull() || patch_class.origin_class() != klass.raw()) {
689 patch_class = PatchClass::New(klass, correct_script);
690 patch_classes_.SetAt(source_uri_index, patch_class);
691 }
692 return patch_class;
686 } 693 }
687 return klass; 694 return klass;
688 } 695 }
689 696
690 Script& KernelReader::ScriptAt(intptr_t index, StringIndex import_uri) { 697 Script& KernelReader::ScriptAt(intptr_t index, StringIndex import_uri) {
691 Script& script = Script::ZoneHandle(Z); 698 Script& script = Script::ZoneHandle(Z);
692 script ^= scripts_.At(index); 699 script ^= scripts_.At(index);
693 if (script.IsNull()) { 700 if (script.IsNull()) {
694 // Create script with correct uri(s). 701 // Create script with correct uri(s).
695 dart::String& uri_string = builder_.SourceTableUriFor(index); 702 dart::String& uri_string = builder_.SourceTableUriFor(index);
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
906 initializer_fun.set_is_debuggable(false); 913 initializer_fun.set_is_debuggable(false);
907 initializer_fun.set_is_reflectable(false); 914 initializer_fun.set_is_reflectable(false);
908 initializer_fun.set_is_inlinable(false); 915 initializer_fun.set_is_inlinable(false);
909 return new (zone) ParsedFunction(thread, initializer_fun); 916 return new (zone) ParsedFunction(thread, initializer_fun);
910 } 917 }
911 918
912 919
913 } // namespace kernel 920 } // namespace kernel
914 } // namespace dart 921 } // namespace dart
915 #endif // !defined(DART_PRECOMPILED_RUNTIME) 922 #endif // !defined(DART_PRECOMPILED_RUNTIME)
OLDNEW
« no previous file with comments | « runtime/vm/kernel_reader.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698