Chromium Code Reviews| 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/object.h" | 5 #include "vm/object.h" |
| 6 | 6 |
| 7 #include "platform/assert.h" | 7 #include "platform/assert.h" |
| 8 #include "vm/assembler.h" | 8 #include "vm/assembler.h" |
| 9 #include "vm/bigint_operations.h" | 9 #include "vm/bigint_operations.h" |
| 10 #include "vm/bootstrap.h" | 10 #include "vm/bootstrap.h" |
| (...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 527 | 527 |
| 528 cls = Class::New<JSRegExp>(); | 528 cls = Class::New<JSRegExp>(); |
| 529 object_store->set_jsregexp_class(cls); | 529 object_store->set_jsregexp_class(cls); |
| 530 RegisterClass(cls, "JSSyntaxRegExp", impl_script, core_impl_lib); | 530 RegisterClass(cls, "JSSyntaxRegExp", impl_script, core_impl_lib); |
| 531 pending_classes.Add(&Class::ZoneHandle(cls.raw())); | 531 pending_classes.Add(&Class::ZoneHandle(cls.raw())); |
| 532 | 532 |
| 533 // Initialize the base interfaces used by the core VM classes. | 533 // Initialize the base interfaces used by the core VM classes. |
| 534 const Script& script = Script::Handle(Bootstrap::LoadScript()); | 534 const Script& script = Script::Handle(Bootstrap::LoadScript()); |
| 535 | 535 |
| 536 // Allocate and initialize the Object class and type. | 536 // Allocate and initialize the Object class and type. |
| 537 // The Object and ByteBuffer classes are the only pre-allocated | 537 // The Object and ExternalByteArray classes are the only pre-allocated |
| 538 // non-interface classes in the core library. | 538 // non-interface classes in the core library. |
| 539 cls = Class::New<Instance>(); | 539 cls = Class::New<Instance>(); |
| 540 object_store->set_object_class(cls); | 540 object_store->set_object_class(cls); |
| 541 cls.set_name(String::Handle(String::NewSymbol("Object"))); | 541 cls.set_name(String::Handle(String::NewSymbol("Object"))); |
| 542 cls.set_script(script); | 542 cls.set_script(script); |
| 543 core_lib.AddClass(cls); | 543 core_lib.AddClass(cls); |
| 544 pending_classes.Add(&Class::ZoneHandle(cls.raw())); | 544 pending_classes.Add(&Class::ZoneHandle(cls.raw())); |
| 545 type = Type::NewNonParameterizedType(cls); | 545 type = Type::NewNonParameterizedType(cls); |
| 546 object_store->set_object_type(type); | 546 object_store->set_object_type(type); |
| 547 | 547 |
| 548 cls = Class::New<ByteBuffer>(); | 548 cls = Class::New<InternalByteArray>(); |
| 549 object_store->set_byte_buffer_class(cls); | 549 object_store->set_internal_byte_array_class(cls); |
| 550 cls.set_name(String::Handle(String::NewSymbol("ByteBuffer"))); | 550 cls.set_name(String::Handle(String::NewSymbol("InternalByteArray"))); |
| 551 cls.set_script(script); | 551 cls.set_script(script); |
| 552 core_lib.AddClass(cls); | 552 core_lib.AddClass(cls); |
| 553 | 553 |
| 554 cls = Class::New<ExternalByteArray>(); | |
| 555 object_store->set_external_byte_array_class(cls); | |
| 556 cls.set_name(String::Handle(String::NewSymbol("ExternalByteArray"))); | |
| 557 cls.set_script(script); | |
| 558 core_lib.AddClass(cls); | |
| 559 | |
| 554 // Set the super type of class Stacktrace to Object type so that the | 560 // Set the super type of class Stacktrace to Object type so that the |
| 555 // 'toString' method is implemented. | 561 // 'toString' method is implemented. |
| 556 cls = object_store->stacktrace_class(); | 562 cls = object_store->stacktrace_class(); |
| 557 cls.set_super_type(type); | 563 cls.set_super_type(type); |
| 558 | 564 |
| 559 cls = CreateAndRegisterInterface("Function", script, core_lib); | 565 cls = CreateAndRegisterInterface("Function", script, core_lib); |
| 560 pending_classes.Add(&Class::ZoneHandle(cls.raw())); | 566 pending_classes.Add(&Class::ZoneHandle(cls.raw())); |
| 561 type = Type::NewNonParameterizedType(cls); | 567 type = Type::NewNonParameterizedType(cls); |
| 562 object_store->set_function_interface(type); | 568 object_store->set_function_interface(type); |
| 563 | 569 |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 584 cls = CreateAndRegisterInterface("bool", script, core_lib); | 590 cls = CreateAndRegisterInterface("bool", script, core_lib); |
| 585 pending_classes.Add(&Class::ZoneHandle(cls.raw())); | 591 pending_classes.Add(&Class::ZoneHandle(cls.raw())); |
| 586 type = Type::NewNonParameterizedType(cls); | 592 type = Type::NewNonParameterizedType(cls); |
| 587 object_store->set_bool_interface(type); | 593 object_store->set_bool_interface(type); |
| 588 | 594 |
| 589 cls = CreateAndRegisterInterface("List", script, core_lib); | 595 cls = CreateAndRegisterInterface("List", script, core_lib); |
| 590 pending_classes.Add(&Class::ZoneHandle(cls.raw())); | 596 pending_classes.Add(&Class::ZoneHandle(cls.raw())); |
| 591 type = Type::NewNonParameterizedType(cls); | 597 type = Type::NewNonParameterizedType(cls); |
| 592 object_store->set_list_interface(type); | 598 object_store->set_list_interface(type); |
| 593 | 599 |
| 600 cls = CreateAndRegisterInterface("ByteArray", script, core_lib); | |
| 601 pending_classes.Add(&Class::ZoneHandle(cls.raw())); | |
| 602 type = Type::NewNonParameterizedType(cls); | |
| 603 object_store->set_byte_array_interface(type); | |
| 604 | |
| 594 // The classes 'Null' and 'void' are not registered in the class dictionary, | 605 // The classes 'Null' and 'void' are not registered in the class dictionary, |
| 595 // because their names are reserved keywords. Their names are not heap | 606 // because their names are reserved keywords. Their names are not heap |
| 596 // allocated, because the classes reside in the VM isolate. | 607 // allocated, because the classes reside in the VM isolate. |
| 597 // The corresponding types are stored in the object store. | 608 // The corresponding types are stored in the object store. |
| 598 cls = null_class_; | 609 cls = null_class_; |
| 599 type = Type::NewNonParameterizedType(cls); | 610 type = Type::NewNonParameterizedType(cls); |
| 600 object_store->set_null_type(type); | 611 object_store->set_null_type(type); |
| 601 | 612 |
| 602 cls = void_class_; | 613 cls = void_class_; |
| 603 type = Type::NewNonParameterizedType(cls); | 614 type = Type::NewNonParameterizedType(cls); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 655 cls = Class::New<Array>(); | 666 cls = Class::New<Array>(); |
| 656 object_store->set_array_class(cls); | 667 object_store->set_array_class(cls); |
| 657 | 668 |
| 658 Array& empty_array = Array::Handle(); | 669 Array& empty_array = Array::Handle(); |
| 659 empty_array = Array::New(0); | 670 empty_array = Array::New(0); |
| 660 object_store->set_empty_array(empty_array); | 671 object_store->set_empty_array(empty_array); |
| 661 | 672 |
| 662 cls = Class::New<ImmutableArray>(); | 673 cls = Class::New<ImmutableArray>(); |
| 663 object_store->set_immutable_array_class(cls); | 674 object_store->set_immutable_array_class(cls); |
| 664 | 675 |
| 665 cls = Class::New<ByteBuffer>(); | 676 cls = Class::New<InternalByteArray>(); |
| 666 object_store->set_byte_buffer_class(cls); | 677 object_store->set_internal_byte_array_class(cls); |
| 678 | |
| 679 cls = Class::New<ExternalByteArray>(); | |
| 680 object_store->set_external_byte_array_class(cls); | |
| 667 | 681 |
| 668 cls = Class::New<Instance>(); | 682 cls = Class::New<Instance>(); |
| 669 object_store->set_object_class(cls); | 683 object_store->set_object_class(cls); |
| 670 | 684 |
| 671 cls = Class::New<Smi>(); | 685 cls = Class::New<Smi>(); |
| 672 object_store->set_smi_class(cls); | 686 object_store->set_smi_class(cls); |
| 673 | 687 |
| 674 cls = Class::New<Mint>(); | 688 cls = Class::New<Mint>(); |
| 675 object_store->set_mint_class(cls); | 689 object_store->set_mint_class(cls); |
| 676 | 690 |
| (...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1214 return object_store->external_four_byte_string_class(); | 1228 return object_store->external_four_byte_string_class(); |
| 1215 case kBool: | 1229 case kBool: |
| 1216 ASSERT(object_store->bool_class() != Class::null()); | 1230 ASSERT(object_store->bool_class() != Class::null()); |
| 1217 return object_store->bool_class(); | 1231 return object_store->bool_class(); |
| 1218 case kArray: | 1232 case kArray: |
| 1219 ASSERT(object_store->array_class() != Class::null()); | 1233 ASSERT(object_store->array_class() != Class::null()); |
| 1220 return object_store->array_class(); | 1234 return object_store->array_class(); |
| 1221 case kImmutableArray: | 1235 case kImmutableArray: |
| 1222 ASSERT(object_store->immutable_array_class() != Class::null()); | 1236 ASSERT(object_store->immutable_array_class() != Class::null()); |
| 1223 return object_store->immutable_array_class(); | 1237 return object_store->immutable_array_class(); |
| 1224 case kByteBuffer: | 1238 case kInternalByteArray: |
| 1225 ASSERT(object_store->byte_buffer_class() != Class::null()); | 1239 ASSERT(object_store->internal_byte_array_class() != Class::null()); |
| 1226 return object_store->byte_buffer_class(); | 1240 return object_store->internal_byte_array_class(); |
| 1241 case kExternalByteArray: | |
| 1242 ASSERT(object_store->external_byte_array_class() != Class::null()); | |
| 1243 return object_store->external_byte_array_class(); | |
| 1227 case kStacktrace: | 1244 case kStacktrace: |
| 1228 ASSERT(object_store->stacktrace_class() != Class::null()); | 1245 ASSERT(object_store->stacktrace_class() != Class::null()); |
| 1229 return object_store->stacktrace_class(); | 1246 return object_store->stacktrace_class(); |
| 1230 case kJSRegExp: | 1247 case kJSRegExp: |
| 1231 ASSERT(object_store->jsregexp_class() != Class::null()); | 1248 ASSERT(object_store->jsregexp_class() != Class::null()); |
| 1232 return object_store->jsregexp_class(); | 1249 return object_store->jsregexp_class(); |
| 1233 case kClosure: | 1250 case kClosure: |
| 1234 return Class::New<Closure>(); | 1251 return Class::New<Closure>(); |
| 1235 case kInstance: | 1252 case kInstance: |
| 1236 return Class::New<Instance>(); | 1253 return Class::New<Instance>(); |
| (...skipping 6115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 7352 Class& cls = Class::Handle(object_store->immutable_array_class()); | 7369 Class& cls = Class::Handle(object_store->immutable_array_class()); |
| 7353 return reinterpret_cast<RawImmutableArray*>(Array::New(cls, len, space)); | 7370 return reinterpret_cast<RawImmutableArray*>(Array::New(cls, len, space)); |
| 7354 } | 7371 } |
| 7355 | 7372 |
| 7356 | 7373 |
| 7357 const char* ImmutableArray::ToCString() const { | 7374 const char* ImmutableArray::ToCString() const { |
| 7358 return "ImmutableArray"; | 7375 return "ImmutableArray"; |
| 7359 } | 7376 } |
| 7360 | 7377 |
| 7361 | 7378 |
| 7362 RawByteBuffer* ByteBuffer::New(uint8_t* data, | 7379 intptr_t ByteArray::Length() const { |
| 7363 intptr_t len, | 7380 // ByteArray is an abstract class. |
| 7364 Heap::Space space) { | 7381 UNREACHABLE(); |
| 7382 return 0; | |
| 7383 } | |
| 7384 | |
| 7385 | |
| 7386 const char* ByteArray::ToCString() const { | |
| 7387 // ByteArray is an abstract class. | |
| 7388 UNREACHABLE(); | |
| 7389 return "ByteArray"; | |
| 7390 } | |
| 7391 | |
| 7392 | |
| 7393 bool InternalByteArray::Equals(const Instance& that) const { | |
| 7394 if (this->raw() == that.raw()) { | |
| 7395 // Both handles point to the same raw instance. | |
| 7396 return true; | |
| 7397 } | |
| 7398 if (!that.IsInternalByteArray() || that.IsNull()) { | |
| 7399 return false; | |
|
siva
2012/01/20 22:51:04
So we can't check if an internal byte array is equ
cshapiro
2012/01/24 02:14:23
I have removed the equality checks. They do not m
| |
| 7400 } | |
| 7401 InternalByteArray& that_array = InternalByteArray::Handle(); | |
| 7402 that_array ^= that.raw(); | |
| 7403 intptr_t len = this->Length(); | |
| 7404 if (len != that_array.Length()) { | |
| 7405 return false; | |
| 7406 } | |
| 7407 return memcmp(this->Addr<uint8_t>(0), that_array.Addr<uint8_t>(0), len) == 0; | |
| 7408 } | |
| 7409 | |
| 7410 | |
| 7411 RawInternalByteArray* InternalByteArray::New(intptr_t len, | |
| 7412 Heap::Space space) { | |
| 7365 Isolate* isolate = Isolate::Current(); | 7413 Isolate* isolate = Isolate::Current(); |
| 7366 const Class& byte_buffer_class = | 7414 const Class& internal_byte_array_class = |
| 7367 Class::Handle(isolate->object_store()->byte_buffer_class()); | 7415 Class::Handle(isolate->object_store()->internal_byte_array_class()); |
| 7368 ByteBuffer& result = ByteBuffer::Handle(); | 7416 InternalByteArray& result = InternalByteArray::Handle(); |
| 7369 { | 7417 { |
| 7370 RawObject* raw = Object::Allocate(byte_buffer_class, | 7418 RawObject* raw = Object::Allocate(internal_byte_array_class, |
| 7371 ByteBuffer::InstanceSize(), | 7419 InternalByteArray::InstanceSize(len), |
| 7372 space); | 7420 space); |
| 7373 NoGCScope no_gc; | 7421 NoGCScope no_gc; |
| 7374 result ^= raw; | 7422 result ^= raw; |
| 7423 result.SetLength(len); | |
| 7424 } | |
| 7425 return result.raw(); | |
| 7426 } | |
| 7427 | |
| 7428 | |
| 7429 RawInternalByteArray* InternalByteArray::New(const uint8_t* data, | |
| 7430 intptr_t len, | |
| 7431 Heap::Space space) { | |
| 7432 InternalByteArray& result = | |
| 7433 InternalByteArray::Handle(InternalByteArray::New(len, space)); | |
| 7434 { | |
| 7435 NoGCScope no_gc; | |
| 7436 memmove(result.Addr<uint8_t>(0), data, len); | |
| 7437 } | |
| 7438 return result.raw(); | |
| 7439 } | |
| 7440 | |
| 7441 | |
| 7442 const char* InternalByteArray::ToCString() const { | |
| 7443 return "InternalByteArray"; | |
| 7444 } | |
| 7445 | |
| 7446 | |
| 7447 RawExternalByteArray* ExternalByteArray::New(uint8_t* data, | |
| 7448 intptr_t len, | |
| 7449 Heap::Space space) { | |
| 7450 Isolate* isolate = Isolate::Current(); | |
| 7451 const Class& external_byte_array_class = | |
| 7452 Class::Handle(isolate->object_store()->external_byte_array_class()); | |
| 7453 ExternalByteArray& result = ExternalByteArray::Handle(); | |
| 7454 { | |
| 7455 RawObject* raw = Object::Allocate(external_byte_array_class, | |
| 7456 ExternalByteArray::InstanceSize(), | |
| 7457 space); | |
| 7458 NoGCScope no_gc; | |
| 7459 result ^= raw; | |
| 7375 result.SetLength(len); | 7460 result.SetLength(len); |
| 7376 result.SetData(data); | 7461 result.SetData(data); |
| 7377 } | 7462 } |
| 7378 return result.raw(); | 7463 return result.raw(); |
| 7379 } | 7464 } |
| 7380 | 7465 |
| 7381 | 7466 |
| 7382 bool ByteBuffer::Equals(const Instance& other) const { | 7467 bool ExternalByteArray::Equals(const Instance& other) const { |
| 7383 if (this->raw() == other.raw()) { | 7468 if (this->raw() == other.raw()) { |
| 7384 // Both handles point to the same raw instance. | 7469 // Both handles point to the same raw instance. |
| 7385 return true; | 7470 return true; |
| 7386 } | 7471 } |
| 7387 | 7472 |
| 7388 if (!other.IsByteBuffer() || other.IsNull()) { | 7473 if (!other.IsExternalByteArray() || other.IsNull()) { |
| 7389 return false; | 7474 return false; |
| 7390 } | 7475 } |
|
siva
2012/01/20 22:51:04
Ditto comment about comparing with an internal byt
cshapiro
2012/01/24 02:14:23
Same here. Gone.
| |
| 7391 | 7476 |
| 7392 ByteBuffer& other_array = ByteBuffer::Handle(); | 7477 ExternalByteArray& other_array = ExternalByteArray::Handle(); |
| 7393 other_array ^= other.raw(); | 7478 other_array ^= other.raw(); |
| 7394 | 7479 |
| 7395 intptr_t len = this->Length(); | 7480 intptr_t len = this->Length(); |
| 7396 if (len != other_array.Length()) { | 7481 if (len != other_array.Length()) { |
| 7397 return false; | 7482 return false; |
| 7398 } | 7483 } |
| 7399 | 7484 |
| 7400 return memcmp(this->Addr<uint8_t>(0), other_array.Addr<uint8_t>(0), len) == 0; | 7485 return memcmp(this->Addr<uint8_t>(0), other_array.Addr<uint8_t>(0), len) == 0; |
| 7401 } | 7486 } |
| 7402 | 7487 |
| 7403 | 7488 |
| 7404 const char* ByteBuffer::ToCString() const { | 7489 const char* ExternalByteArray::ToCString() const { |
| 7405 return "ByteBuffer"; | 7490 return "ExternalByteArray"; |
| 7406 } | 7491 } |
| 7407 | 7492 |
| 7408 | 7493 |
| 7409 RawClosure* Closure::New(const Function& function, | 7494 RawClosure* Closure::New(const Function& function, |
| 7410 const Context& context, | 7495 const Context& context, |
| 7411 Heap::Space space) { | 7496 Heap::Space space) { |
| 7412 Isolate* isolate = Isolate::Current(); | 7497 Isolate* isolate = Isolate::Current(); |
| 7413 ASSERT(context.isolate() == isolate); | 7498 ASSERT(context.isolate() == isolate); |
| 7414 | 7499 |
| 7415 const Class& cls = Class::Handle(function.signature_class()); | 7500 const Class& cls = Class::Handle(function.signature_class()); |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 7708 const String& str = String::Handle(pattern()); | 7793 const String& str = String::Handle(pattern()); |
| 7709 const char* format = "JSRegExp: pattern=%s flags=%s"; | 7794 const char* format = "JSRegExp: pattern=%s flags=%s"; |
| 7710 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); | 7795 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); |
| 7711 char* chars = reinterpret_cast<char*>( | 7796 char* chars = reinterpret_cast<char*>( |
| 7712 Isolate::Current()->current_zone()->Allocate(len + 1)); | 7797 Isolate::Current()->current_zone()->Allocate(len + 1)); |
| 7713 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); | 7798 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); |
| 7714 return chars; | 7799 return chars; |
| 7715 } | 7800 } |
| 7716 | 7801 |
| 7717 } // namespace dart | 7802 } // namespace dart |
| OLD | NEW |