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

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

Issue 10824209: - Allow patching of top-level methods and accessors. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/parser.h » ('j') | 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) 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/object.h" 5 #include "vm/object.h"
6 6
7 #include "include/dart_api.h" 7 #include "include/dart_api.h"
8 #include "platform/assert.h" 8 #include "platform/assert.h"
9 #include "vm/assembler.h" 9 #include "vm/assembler.h"
10 #include "vm/bigint_operations.h" 10 #include "vm/bigint_operations.h"
(...skipping 4127 matching lines...) Expand 10 before | Expand all | Expand 10 after
4138 intptr_t token_pos) { 4138 intptr_t token_pos) {
4139 ASSERT(name.IsOneByteString()); 4139 ASSERT(name.IsOneByteString());
4140 ASSERT(!owner.IsNull()); 4140 ASSERT(!owner.IsNull());
4141 const Function& result = Function::Handle(Function::New()); 4141 const Function& result = Function::Handle(Function::New());
4142 result.set_parameter_types(Array::Handle(Array::Empty())); 4142 result.set_parameter_types(Array::Handle(Array::Empty()));
4143 result.set_parameter_names(Array::Handle(Array::Empty())); 4143 result.set_parameter_names(Array::Handle(Array::Empty()));
4144 result.set_name(name); 4144 result.set_name(name);
4145 result.set_kind(kind); 4145 result.set_kind(kind);
4146 result.set_is_static(is_static); 4146 result.set_is_static(is_static);
4147 result.set_is_const(is_const); 4147 result.set_is_const(is_const);
4148 result.set_is_abstract(is_abstract);
4148 result.set_is_external(is_external); 4149 result.set_is_external(is_external);
4149 result.set_owner(owner); 4150 result.set_owner(owner);
4150 result.set_token_pos(token_pos); 4151 result.set_token_pos(token_pos);
4151 result.set_end_token_pos(token_pos); 4152 result.set_end_token_pos(token_pos);
4152 result.set_num_fixed_parameters(0); 4153 result.set_num_fixed_parameters(0);
4153 result.set_num_optional_parameters(0); 4154 result.set_num_optional_parameters(0);
4154 result.set_usage_counter(0); 4155 result.set_usage_counter(0);
4155 result.set_deoptimization_counter(0); 4156 result.set_deoptimization_counter(0);
4156 result.set_is_optimizable(true); 4157 result.set_is_optimizable(true);
4157 result.set_has_finally(false); 4158 result.set_has_finally(false);
4158 result.set_is_native(false); 4159 result.set_is_native(false);
4159 result.set_is_abstract(is_abstract);
4160 return result.raw(); 4160 return result.raw();
4161 } 4161 }
4162 4162
4163 4163
4164 RawFunction* Function::NewClosureFunction(const String& name, 4164 RawFunction* Function::NewClosureFunction(const String& name,
4165 const Function& parent, 4165 const Function& parent,
4166 intptr_t token_pos) { 4166 intptr_t token_pos) {
4167 ASSERT(name.IsOneByteString()); 4167 ASSERT(name.IsOneByteString());
4168 ASSERT(!parent.IsNull()); 4168 ASSERT(!parent.IsNull());
4169 const Class& parent_class = Class::Handle(parent.owner()); 4169 const Class& parent_class = Class::Handle(parent.owner());
(...skipping 1278 matching lines...) Expand 10 before | Expand all | Expand 10 after
5448 GrowDictionary(dict, dict_size); 5448 GrowDictionary(dict, dict_size);
5449 } 5449 }
5450 5450
5451 // Invalidate the cache of loaded scripts. 5451 // Invalidate the cache of loaded scripts.
5452 if (loaded_scripts() != Array::null()) { 5452 if (loaded_scripts() != Array::null()) {
5453 StorePointer(&raw_ptr()->loaded_scripts_, Array::null()); 5453 StorePointer(&raw_ptr()->loaded_scripts_, Array::null());
5454 } 5454 }
5455 } 5455 }
5456 5456
5457 5457
5458 RawObject* Library::LookupEntry(const String& name, intptr_t *index) const {
5459 Isolate* isolate = Isolate::Current();
5460 const Array& dict = Array::Handle(isolate, dictionary());
5461 intptr_t dict_size = dict.Length() - 1;
5462 *index = name.Hash() % dict_size;
5463
5464 Object& entry = Object::Handle(isolate);
5465 Class& cls = Class::Handle(isolate);
5466 Function& func = Function::Handle(isolate);
5467 Field& field = Field::Handle(isolate);
5468 LibraryPrefix& library_prefix = LibraryPrefix::Handle(isolate);
5469 String& entry_name = String::Handle(isolate);
5470 entry = dict.At(*index);
5471 // Search the entry in the hash set.
5472 while (!entry.IsNull()) {
5473 // TODO(hausner): find a better way to handle this polymorphism.
5474 // Either introduce a common base class for Class, Function, Field
5475 // and LibraryPrefix or make the name() function virtual in Object.
5476 if (entry.IsClass()) {
5477 cls ^= entry.raw();
5478 entry_name = cls.Name();
5479 } else if (entry.IsFunction()) {
5480 func ^= entry.raw();
5481 entry_name = func.name();
5482 } else if (entry.IsField()) {
5483 field ^= entry.raw();
5484 entry_name = field.name();
5485 } else if (entry.IsLibraryPrefix()) {
5486 library_prefix ^= entry.raw();
5487 entry_name = library_prefix.name();
5488 } else {
5489 UNREACHABLE();
5490 }
5491 if (entry_name.Equals(name)) {
5492 return entry.raw();
5493 }
5494 *index = (*index + 1) % dict_size;
5495 entry = dict.At(*index);
5496 }
5497 return Object::null();
5498 }
5499
5500
5501 void Library::ReplaceObject(const Object& obj, const String& name) const {
5502 ASSERT(obj.IsClass() || obj.IsFunction() || obj.IsField());
5503 ASSERT(LookupLocalObject(name) != Object::null());
5504
5505 intptr_t index;
5506 LookupEntry(name, &index);
5507 // The value is guaranteed to be found.
5508 const Array& dict = Array::Handle(dictionary());
5509 dict.SetAt(index, obj);
5510 }
5511
5512
5458 void Library::AddClass(const Class& cls) const { 5513 void Library::AddClass(const Class& cls) const {
5459 AddObject(cls, String::Handle(cls.Name())); 5514 AddObject(cls, String::Handle(cls.Name()));
5460 // Link class to this library. 5515 // Link class to this library.
5461 cls.set_library(*this); 5516 cls.set_library(*this);
5462 } 5517 }
5463 5518
5464 5519
5465 RawArray* Library::LoadedScripts() const { 5520 RawArray* Library::LoadedScripts() const {
5466 // We compute the list of loaded scripts lazily. The result is 5521 // We compute the list of loaded scripts lazily. The result is
5467 // cached in loaded_scripts_. 5522 // cached in loaded_scripts_.
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
5577 if (!func.IsNull()) { 5632 if (!func.IsNull()) {
5578 return func.raw(); 5633 return func.raw();
5579 } 5634 }
5580 } 5635 }
5581 } 5636 }
5582 return Function::null(); 5637 return Function::null();
5583 } 5638 }
5584 5639
5585 5640
5586 RawObject* Library::LookupLocalObject(const String& name) const { 5641 RawObject* Library::LookupLocalObject(const String& name) const {
5587 Isolate* isolate = Isolate::Current(); 5642 intptr_t index;
5588 const Array& dict = Array::Handle(isolate, dictionary()); 5643 return LookupEntry(name, &index);
5589 intptr_t dict_size = dict.Length() - 1;
5590 intptr_t index = name.Hash() % dict_size;
5591
5592 Object& entry = Object::Handle(isolate, Object::null());
5593 Class& cls = Class::Handle(isolate, Class::null());
5594 Function& func = Function::Handle(isolate, Function::null());
5595 Field& field = Field::Handle(isolate, Field::null());
5596 LibraryPrefix& library_prefix = LibraryPrefix::Handle(isolate,
5597 LibraryPrefix::null());
5598 String& entry_name = String::Handle(isolate, String::null());
5599 entry = dict.At(index);
5600 // Search the entry in the hash set.
5601 while (!entry.IsNull()) {
5602 // TODO(hausner): find a better way to handle this polymorphism.
5603 // Either introduce a common base class for Class, Function, Field
5604 // and LibraryPrefix or make the name() function virtual in Object.
5605 if (entry.IsClass()) {
5606 cls ^= entry.raw();
5607 entry_name = cls.Name();
5608 } else if (entry.IsFunction()) {
5609 func ^= entry.raw();
5610 entry_name = func.name();
5611 } else if (entry.IsField()) {
5612 field ^= entry.raw();
5613 entry_name = field.name();
5614 } else if (entry.IsLibraryPrefix()) {
5615 library_prefix ^= entry.raw();
5616 entry_name = library_prefix.name();
5617 } else {
5618 UNREACHABLE();
5619 }
5620 if (entry_name.Equals(name)) {
5621 return entry.raw();
5622 }
5623 index = (index + 1) % dict_size;
5624 entry = dict.At(index);
5625 }
5626 return Class::null();
5627 } 5644 }
5628 5645
5629 5646
5630 static bool ShouldBePrivate(const String& name) { 5647 static bool ShouldBePrivate(const String& name) {
5631 return 5648 return
5632 (name.Length() >= 1 && 5649 (name.Length() >= 1 &&
5633 name.CharAt(0) == '_') || 5650 name.CharAt(0) == '_') ||
5634 (name.Length() >= 5 && 5651 (name.Length() >= 5 &&
5635 (name.CharAt(4) == '_' && 5652 (name.CharAt(4) == '_' &&
5636 (name.CharAt(0) == 'g' || name.CharAt(0) == 's') && 5653 (name.CharAt(0) == 'g' || name.CharAt(0) == 's') &&
(...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after
6195 lib ^= libs.At(i); 6212 lib ^= libs.At(i);
6196 error_message = lib.FindDuplicateDefinition(); 6213 error_message = lib.FindDuplicateDefinition();
6197 if (!error_message.IsNull()) { 6214 if (!error_message.IsNull()) {
6198 return error_message.raw(); 6215 return error_message.raw();
6199 } 6216 }
6200 } 6217 }
6201 return String::null(); 6218 return String::null();
6202 } 6219 }
6203 6220
6204 6221
6222 RawError* Library::Patch(const String& url, const String& source) const {
6223 const Script& script = Script::Handle(
6224 Script::New(url, source, RawScript::kPatchTag));
6225 return Compiler::Compile(*this, script);
6226 }
6227
6228
6205 bool Library::IsKeyUsed(intptr_t key) { 6229 bool Library::IsKeyUsed(intptr_t key) {
6206 intptr_t lib_key; 6230 intptr_t lib_key;
6207 const GrowableObjectArray& libs = GrowableObjectArray::Handle( 6231 const GrowableObjectArray& libs = GrowableObjectArray::Handle(
6208 Isolate::Current()->object_store()->libraries()); 6232 Isolate::Current()->object_store()->libraries());
6209 Library& lib = Library::Handle(); 6233 Library& lib = Library::Handle();
6210 String& lib_url = String::Handle(); 6234 String& lib_url = String::Handle();
6211 for (int i = 0; i < libs.Length(); i++) { 6235 for (int i = 0; i < libs.Length(); i++) {
6212 lib ^= libs.At(i); 6236 lib ^= libs.At(i);
6213 lib_url ^= lib.url(); 6237 lib_url ^= lib.url();
6214 lib_key = lib_url.Hash(); 6238 lib_key = lib_url.Hash();
(...skipping 4840 matching lines...) Expand 10 before | Expand all | Expand 10 after
11055 const char* JSRegExp::ToCString() const { 11079 const char* JSRegExp::ToCString() const {
11056 const String& str = String::Handle(pattern()); 11080 const String& str = String::Handle(pattern());
11057 const char* format = "JSRegExp: pattern=%s flags=%s"; 11081 const char* format = "JSRegExp: pattern=%s flags=%s";
11058 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); 11082 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags());
11059 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len + 1); 11083 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len + 1);
11060 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); 11084 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags());
11061 return chars; 11085 return chars;
11062 } 11086 }
11063 11087
11064 } // namespace dart 11088 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/parser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698