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 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 532 | 532 |
| 533 cls = Class::New<JSRegExp>(); | 533 cls = Class::New<JSRegExp>(); |
| 534 object_store->set_jsregexp_class(cls); | 534 object_store->set_jsregexp_class(cls); |
| 535 RegisterClass(cls, "JSSyntaxRegExp", impl_script, core_impl_lib); | 535 RegisterClass(cls, "JSSyntaxRegExp", impl_script, core_impl_lib); |
| 536 pending_classes.Add(&Class::ZoneHandle(cls.raw())); | 536 pending_classes.Add(&Class::ZoneHandle(cls.raw())); |
| 537 | 537 |
| 538 // Initialize the base interfaces used by the core VM classes. | 538 // Initialize the base interfaces used by the core VM classes. |
| 539 const Script& script = Script::Handle(Bootstrap::LoadScript()); | 539 const Script& script = Script::Handle(Bootstrap::LoadScript()); |
| 540 | 540 |
| 541 // Allocate and initialize the Object class and type. | 541 // Allocate and initialize the Object class and type. |
| 542 // The Object and ByteBuffer classes are the only pre-allocated | 542 // The Object and ExternalByteArray classes are the only pre-allocated |
| 543 // non-interface classes in the core library. | 543 // non-interface classes in the core library. |
| 544 cls = Class::New<Instance>(); | 544 cls = Class::New<Instance>(); |
| 545 object_store->set_object_class(cls); | 545 object_store->set_object_class(cls); |
| 546 cls.set_name(String::Handle(String::NewSymbol("Object"))); | 546 cls.set_name(String::Handle(String::NewSymbol("Object"))); |
| 547 cls.set_script(script); | 547 cls.set_script(script); |
| 548 core_lib.AddClass(cls); | 548 core_lib.AddClass(cls); |
| 549 pending_classes.Add(&Class::ZoneHandle(cls.raw())); | 549 pending_classes.Add(&Class::ZoneHandle(cls.raw())); |
| 550 type = Type::NewNonParameterizedType(cls); | 550 type = Type::NewNonParameterizedType(cls); |
| 551 object_store->set_object_type(type); | 551 object_store->set_object_type(type); |
| 552 | 552 |
| 553 cls = Class::New<ByteBuffer>(); | 553 cls = Class::New<InternalByteArray>(); |
| 554 object_store->set_byte_buffer_class(cls); | 554 object_store->set_internal_byte_array_class(cls); |
| 555 cls.set_name(String::Handle(String::NewSymbol("ByteBuffer"))); | 555 cls.set_name(String::Handle(String::NewSymbol("InternalByteArray"))); |
| 556 cls.set_script(script); | 556 cls.set_script(script); |
| 557 core_lib.AddClass(cls); | 557 core_lib.AddClass(cls); |
| 558 | 558 |
| 559 cls = Class::New<ExternalByteArray>(); | |
| 560 object_store->set_external_byte_array_class(cls); | |
| 561 cls.set_name(String::Handle(String::NewSymbol("ExternalByteArray"))); | |
| 562 cls.set_script(script); | |
| 563 core_lib.AddClass(cls); | |
| 564 | |
| 559 // Set the super type of class Stacktrace to Object type so that the | 565 // Set the super type of class Stacktrace to Object type so that the |
| 560 // 'toString' method is implemented. | 566 // 'toString' method is implemented. |
| 561 cls = object_store->stacktrace_class(); | 567 cls = object_store->stacktrace_class(); |
| 562 cls.set_super_type(type); | 568 cls.set_super_type(type); |
| 563 | 569 |
| 564 cls = CreateAndRegisterInterface("Function", script, core_lib); | 570 cls = CreateAndRegisterInterface("Function", script, core_lib); |
| 565 pending_classes.Add(&Class::ZoneHandle(cls.raw())); | 571 pending_classes.Add(&Class::ZoneHandle(cls.raw())); |
| 566 type = Type::NewNonParameterizedType(cls); | 572 type = Type::NewNonParameterizedType(cls); |
| 567 object_store->set_function_interface(type); | 573 object_store->set_function_interface(type); |
| 568 | 574 |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 589 cls = CreateAndRegisterInterface("bool", script, core_lib); | 595 cls = CreateAndRegisterInterface("bool", 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_bool_interface(type); | 598 object_store->set_bool_interface(type); |
| 593 | 599 |
| 594 cls = CreateAndRegisterInterface("List", script, core_lib); | 600 cls = CreateAndRegisterInterface("List", script, core_lib); |
| 595 pending_classes.Add(&Class::ZoneHandle(cls.raw())); | 601 pending_classes.Add(&Class::ZoneHandle(cls.raw())); |
| 596 type = Type::NewNonParameterizedType(cls); | 602 type = Type::NewNonParameterizedType(cls); |
| 597 object_store->set_list_interface(type); | 603 object_store->set_list_interface(type); |
| 598 | 604 |
| 605 cls = CreateAndRegisterInterface("ByteArray", script, core_lib); | |
| 606 pending_classes.Add(&Class::ZoneHandle(cls.raw())); | |
| 607 type = Type::NewNonParameterizedType(cls); | |
| 608 object_store->set_byte_array_interface(type); | |
| 609 | |
| 599 // The classes 'Null' and 'void' are not registered in the class dictionary, | 610 // The classes 'Null' and 'void' are not registered in the class dictionary, |
| 600 // because their names are reserved keywords. Their names are not heap | 611 // because their names are reserved keywords. Their names are not heap |
| 601 // allocated, because the classes reside in the VM isolate. | 612 // allocated, because the classes reside in the VM isolate. |
| 602 // The corresponding types are stored in the object store. | 613 // The corresponding types are stored in the object store. |
| 603 cls = null_class_; | 614 cls = null_class_; |
| 604 type = Type::NewNonParameterizedType(cls); | 615 type = Type::NewNonParameterizedType(cls); |
| 605 object_store->set_null_type(type); | 616 object_store->set_null_type(type); |
| 606 | 617 |
| 607 cls = void_class_; | 618 cls = void_class_; |
| 608 type = Type::NewNonParameterizedType(cls); | 619 type = Type::NewNonParameterizedType(cls); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 660 cls = Class::New<Array>(); | 671 cls = Class::New<Array>(); |
| 661 object_store->set_array_class(cls); | 672 object_store->set_array_class(cls); |
| 662 | 673 |
| 663 Array& empty_array = Array::Handle(); | 674 Array& empty_array = Array::Handle(); |
| 664 empty_array = Array::New(0); | 675 empty_array = Array::New(0); |
| 665 object_store->set_empty_array(empty_array); | 676 object_store->set_empty_array(empty_array); |
| 666 | 677 |
| 667 cls = Class::New<ImmutableArray>(); | 678 cls = Class::New<ImmutableArray>(); |
| 668 object_store->set_immutable_array_class(cls); | 679 object_store->set_immutable_array_class(cls); |
| 669 | 680 |
| 670 cls = Class::New<ByteBuffer>(); | 681 cls = Class::New<InternalByteArray>(); |
| 671 object_store->set_byte_buffer_class(cls); | 682 object_store->set_internal_byte_array_class(cls); |
| 683 | |
| 684 cls = Class::New<ExternalByteArray>(); | |
| 685 object_store->set_external_byte_array_class(cls); | |
| 672 | 686 |
| 673 cls = Class::New<Instance>(); | 687 cls = Class::New<Instance>(); |
| 674 object_store->set_object_class(cls); | 688 object_store->set_object_class(cls); |
| 675 | 689 |
| 676 cls = Class::New<Smi>(); | 690 cls = Class::New<Smi>(); |
| 677 object_store->set_smi_class(cls); | 691 object_store->set_smi_class(cls); |
| 678 | 692 |
| 679 cls = Class::New<Mint>(); | 693 cls = Class::New<Mint>(); |
| 680 object_store->set_mint_class(cls); | 694 object_store->set_mint_class(cls); |
| 681 | 695 |
| (...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1219 return object_store->external_four_byte_string_class(); | 1233 return object_store->external_four_byte_string_class(); |
| 1220 case kBool: | 1234 case kBool: |
| 1221 ASSERT(object_store->bool_class() != Class::null()); | 1235 ASSERT(object_store->bool_class() != Class::null()); |
| 1222 return object_store->bool_class(); | 1236 return object_store->bool_class(); |
| 1223 case kArray: | 1237 case kArray: |
| 1224 ASSERT(object_store->array_class() != Class::null()); | 1238 ASSERT(object_store->array_class() != Class::null()); |
| 1225 return object_store->array_class(); | 1239 return object_store->array_class(); |
| 1226 case kImmutableArray: | 1240 case kImmutableArray: |
| 1227 ASSERT(object_store->immutable_array_class() != Class::null()); | 1241 ASSERT(object_store->immutable_array_class() != Class::null()); |
| 1228 return object_store->immutable_array_class(); | 1242 return object_store->immutable_array_class(); |
| 1229 case kByteBuffer: | 1243 case kInternalByteArray: |
| 1230 ASSERT(object_store->byte_buffer_class() != Class::null()); | 1244 ASSERT(object_store->internal_byte_array_class() != Class::null()); |
| 1231 return object_store->byte_buffer_class(); | 1245 return object_store->internal_byte_array_class(); |
| 1246 case kExternalByteArray: | |
| 1247 ASSERT(object_store->external_byte_array_class() != Class::null()); | |
| 1248 return object_store->external_byte_array_class(); | |
| 1232 case kStacktrace: | 1249 case kStacktrace: |
| 1233 ASSERT(object_store->stacktrace_class() != Class::null()); | 1250 ASSERT(object_store->stacktrace_class() != Class::null()); |
| 1234 return object_store->stacktrace_class(); | 1251 return object_store->stacktrace_class(); |
| 1235 case kJSRegExp: | 1252 case kJSRegExp: |
| 1236 ASSERT(object_store->jsregexp_class() != Class::null()); | 1253 ASSERT(object_store->jsregexp_class() != Class::null()); |
| 1237 return object_store->jsregexp_class(); | 1254 return object_store->jsregexp_class(); |
| 1238 case kClosure: | 1255 case kClosure: |
| 1239 return Class::New<Closure>(); | 1256 return Class::New<Closure>(); |
| 1240 case kInstance: | 1257 case kInstance: |
| 1241 return Class::New<Instance>(); | 1258 return Class::New<Instance>(); |
| (...skipping 6184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 7426 Class& cls = Class::Handle(object_store->immutable_array_class()); | 7443 Class& cls = Class::Handle(object_store->immutable_array_class()); |
| 7427 return reinterpret_cast<RawImmutableArray*>(Array::New(cls, len, space)); | 7444 return reinterpret_cast<RawImmutableArray*>(Array::New(cls, len, space)); |
| 7428 } | 7445 } |
| 7429 | 7446 |
| 7430 | 7447 |
| 7431 const char* ImmutableArray::ToCString() const { | 7448 const char* ImmutableArray::ToCString() const { |
| 7432 return "ImmutableArray"; | 7449 return "ImmutableArray"; |
| 7433 } | 7450 } |
| 7434 | 7451 |
| 7435 | 7452 |
| 7436 RawByteBuffer* ByteBuffer::New(uint8_t* data, | 7453 intptr_t ByteArray::Length() const { |
| 7437 intptr_t len, | 7454 // ByteArray is an abstract class. |
| 7438 Heap::Space space) { | 7455 UNREACHABLE(); |
| 7456 return 0; | |
| 7457 } | |
| 7458 | |
| 7459 | |
| 7460 const char* ByteArray::ToCString() const { | |
| 7461 // ByteArray is an abstract class. | |
| 7462 UNREACHABLE(); | |
| 7463 return "ByteArray"; | |
| 7464 } | |
| 7465 | |
| 7466 | |
| 7467 RawInternalByteArray* InternalByteArray::New(intptr_t len, | |
| 7468 Heap::Space space) { | |
| 7439 Isolate* isolate = Isolate::Current(); | 7469 Isolate* isolate = Isolate::Current(); |
| 7440 const Class& byte_buffer_class = | 7470 const Class& internal_byte_array_class = |
| 7441 Class::Handle(isolate->object_store()->byte_buffer_class()); | 7471 Class::Handle(isolate->object_store()->internal_byte_array_class()); |
| 7442 ByteBuffer& result = ByteBuffer::Handle(); | 7472 InternalByteArray& result = InternalByteArray::Handle(); |
| 7443 { | 7473 { |
| 7444 RawObject* raw = Object::Allocate(byte_buffer_class, | 7474 RawObject* raw = Object::Allocate(internal_byte_array_class, |
| 7445 ByteBuffer::InstanceSize(), | 7475 InternalByteArray::InstanceSize(len), |
| 7476 space); | |
| 7477 NoGCScope no_gc; | |
| 7478 result ^= raw; | |
| 7479 result.SetLength(len); | |
|
Ivan Posva
2012/01/25 23:49:57
Not calling bzero here will cause you to leak the
cshapiro
2012/01/26 02:25:42
Right. I assumed we zero initialized. Fixed.
| |
| 7480 } | |
| 7481 return result.raw(); | |
| 7482 } | |
| 7483 | |
| 7484 | |
| 7485 RawInternalByteArray* InternalByteArray::New(const uint8_t* data, | |
| 7486 intptr_t len, | |
| 7487 Heap::Space space) { | |
| 7488 InternalByteArray& result = | |
| 7489 InternalByteArray::Handle(InternalByteArray::New(len, space)); | |
| 7490 { | |
| 7491 NoGCScope no_gc; | |
| 7492 memmove(result.Addr<uint8_t>(0), data, len); | |
| 7493 } | |
| 7494 return result.raw(); | |
| 7495 } | |
| 7496 | |
| 7497 | |
| 7498 const char* InternalByteArray::ToCString() const { | |
| 7499 return "InternalByteArray"; | |
| 7500 } | |
| 7501 | |
| 7502 | |
| 7503 RawExternalByteArray* ExternalByteArray::New(uint8_t* data, | |
| 7504 intptr_t len, | |
| 7505 Heap::Space space) { | |
| 7506 Isolate* isolate = Isolate::Current(); | |
| 7507 const Class& external_byte_array_class = | |
| 7508 Class::Handle(isolate->object_store()->external_byte_array_class()); | |
| 7509 ExternalByteArray& result = ExternalByteArray::Handle(); | |
| 7510 { | |
| 7511 RawObject* raw = Object::Allocate(external_byte_array_class, | |
| 7512 ExternalByteArray::InstanceSize(), | |
| 7446 space); | 7513 space); |
| 7447 NoGCScope no_gc; | 7514 NoGCScope no_gc; |
| 7448 result ^= raw; | 7515 result ^= raw; |
| 7449 result.SetLength(len); | 7516 result.SetLength(len); |
| 7450 result.SetData(data); | 7517 result.SetData(data); |
| 7451 } | 7518 } |
| 7452 return result.raw(); | 7519 return result.raw(); |
| 7453 } | 7520 } |
| 7454 | 7521 |
| 7455 | 7522 |
| 7456 bool ByteBuffer::Equals(const Instance& other) const { | 7523 const char* ExternalByteArray::ToCString() const { |
| 7457 if (this->raw() == other.raw()) { | 7524 return "ExternalByteArray"; |
| 7458 // Both handles point to the same raw instance. | |
| 7459 return true; | |
| 7460 } | |
| 7461 | |
| 7462 if (!other.IsByteBuffer() || other.IsNull()) { | |
| 7463 return false; | |
| 7464 } | |
| 7465 | |
| 7466 ByteBuffer& other_array = ByteBuffer::Handle(); | |
| 7467 other_array ^= other.raw(); | |
| 7468 | |
| 7469 intptr_t len = this->Length(); | |
| 7470 if (len != other_array.Length()) { | |
| 7471 return false; | |
| 7472 } | |
| 7473 | |
| 7474 return memcmp(this->Addr<uint8_t>(0), other_array.Addr<uint8_t>(0), len) == 0; | |
| 7475 } | 7525 } |
| 7476 | 7526 |
| 7477 | 7527 |
| 7478 const char* ByteBuffer::ToCString() const { | |
| 7479 return "ByteBuffer"; | |
| 7480 } | |
| 7481 | |
| 7482 | |
| 7483 RawClosure* Closure::New(const Function& function, | 7528 RawClosure* Closure::New(const Function& function, |
| 7484 const Context& context, | 7529 const Context& context, |
| 7485 Heap::Space space) { | 7530 Heap::Space space) { |
| 7486 Isolate* isolate = Isolate::Current(); | 7531 Isolate* isolate = Isolate::Current(); |
| 7487 ASSERT(context.isolate() == isolate); | 7532 ASSERT(context.isolate() == isolate); |
| 7488 | 7533 |
| 7489 const Class& cls = Class::Handle(function.signature_class()); | 7534 const Class& cls = Class::Handle(function.signature_class()); |
| 7490 Closure& result = Closure::Handle(); | 7535 Closure& result = Closure::Handle(); |
| 7491 { | 7536 { |
| 7492 RawObject* raw = Object::Allocate(cls, Closure::InstanceSize(), space); | 7537 RawObject* raw = Object::Allocate(cls, Closure::InstanceSize(), space); |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 7782 const String& str = String::Handle(pattern()); | 7827 const String& str = String::Handle(pattern()); |
| 7783 const char* format = "JSRegExp: pattern=%s flags=%s"; | 7828 const char* format = "JSRegExp: pattern=%s flags=%s"; |
| 7784 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); | 7829 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); |
| 7785 char* chars = reinterpret_cast<char*>( | 7830 char* chars = reinterpret_cast<char*>( |
| 7786 Isolate::Current()->current_zone()->Allocate(len + 1)); | 7831 Isolate::Current()->current_zone()->Allocate(len + 1)); |
| 7787 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); | 7832 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); |
| 7788 return chars; | 7833 return chars; |
| 7789 } | 7834 } |
| 7790 | 7835 |
| 7791 } // namespace dart | 7836 } // namespace dart |
| OLD | NEW |