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

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

Issue 8429027: Add an external array type to support typed arrays. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address final review comments Created 9 years, 1 month 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/object_store.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) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 "vm/assembler.h" 7 #include "vm/assembler.h"
8 #include "vm/assert.h" 8 #include "vm/assert.h"
9 #include "vm/bigint_operations.h" 9 #include "vm/bigint_operations.h"
10 #include "vm/bootstrap.h" 10 #include "vm/bootstrap.h"
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 478
479 cls = Class::New<JSRegExp>(); 479 cls = Class::New<JSRegExp>();
480 object_store->set_jsregexp_class(cls); 480 object_store->set_jsregexp_class(cls);
481 RegisterClass(cls, "JSSyntaxRegExp", impl_script, core_impl_lib); 481 RegisterClass(cls, "JSSyntaxRegExp", impl_script, core_impl_lib);
482 pending_classes.Add(&Class::ZoneHandle(cls.raw())); 482 pending_classes.Add(&Class::ZoneHandle(cls.raw()));
483 483
484 // Initialize the base interfaces used by the core VM classes. 484 // Initialize the base interfaces used by the core VM classes.
485 const Script& script = Script::Handle(Bootstrap::LoadScript()); 485 const Script& script = Script::Handle(Bootstrap::LoadScript());
486 486
487 // Allocate and initialize the Object class and type. 487 // Allocate and initialize the Object class and type.
488 // Object class is the only pre-allocated non-interface in the core library. 488 // The Object and ByteBuffer classes are the only pre-allocated
489 // non-interface classes in the core library.
489 cls = Class::New<Instance>(); 490 cls = Class::New<Instance>();
490 object_store->set_object_class(cls); 491 object_store->set_object_class(cls);
491 cls.set_name(String::Handle(String::NewSymbol("Object"))); 492 cls.set_name(String::Handle(String::NewSymbol("Object")));
492 cls.set_script(script); 493 cls.set_script(script);
493 core_lib.AddClass(cls); 494 core_lib.AddClass(cls);
494 pending_classes.Add(&Class::ZoneHandle(cls.raw())); 495 pending_classes.Add(&Class::ZoneHandle(cls.raw()));
495 type = Type::NewNonParameterizedType(cls); 496 type = Type::NewNonParameterizedType(cls);
496 object_store->set_object_type(type); 497 object_store->set_object_type(type);
497 498
499 cls = Class::New<ByteBuffer>();
500 object_store->set_byte_buffer_class(cls);
501 cls.set_name(String::Handle(String::NewSymbol("ByteBuffer")));
502 cls.set_script(script);
503 core_lib.AddClass(cls);
504
498 // Set the super type of class Stacktrace to Object type so that the 505 // Set the super type of class Stacktrace to Object type so that the
499 // 'toString' method is implemented. 506 // 'toString' method is implemented.
500 cls = object_store->stacktrace_class(); 507 cls = object_store->stacktrace_class();
501 cls.set_super_type(type); 508 cls.set_super_type(type);
502 509
503 cls = CreateAndRegisterInterface("Function", script, core_lib); 510 cls = CreateAndRegisterInterface("Function", script, core_lib);
504 pending_classes.Add(&Class::ZoneHandle(cls.raw())); 511 pending_classes.Add(&Class::ZoneHandle(cls.raw()));
505 type = Type::NewNonParameterizedType(cls); 512 type = Type::NewNonParameterizedType(cls);
506 object_store->set_function_interface(type); 513 object_store->set_function_interface(type);
507 514
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
594 cls = Class::New<Array>(); 601 cls = Class::New<Array>();
595 object_store->set_array_class(cls); 602 object_store->set_array_class(cls);
596 603
597 Array& empty_array = Array::Handle(); 604 Array& empty_array = Array::Handle();
598 empty_array = Array::New(0); 605 empty_array = Array::New(0);
599 object_store->set_empty_array(empty_array); 606 object_store->set_empty_array(empty_array);
600 607
601 cls = Class::New<ImmutableArray>(); 608 cls = Class::New<ImmutableArray>();
602 object_store->set_immutable_array_class(cls); 609 object_store->set_immutable_array_class(cls);
603 610
611 cls = Class::New<ByteBuffer>();
612 object_store->set_byte_buffer_class(cls);
613
604 cls = Class::New<Instance>(); 614 cls = Class::New<Instance>();
605 object_store->set_object_class(cls); 615 object_store->set_object_class(cls);
606 616
607 cls = Class::New<Smi>(); 617 cls = Class::New<Smi>();
608 object_store->set_smi_class(cls); 618 object_store->set_smi_class(cls);
609 619
610 cls = Class::New<Mint>(); 620 cls = Class::New<Mint>();
611 object_store->set_mint_class(cls); 621 object_store->set_mint_class(cls);
612 622
613 cls = Class::New<Double>(); 623 cls = Class::New<Double>();
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after
1105 return object_store->four_byte_string_class(); 1115 return object_store->four_byte_string_class();
1106 case kBool: 1116 case kBool:
1107 ASSERT(object_store->bool_class() != Class::null()); 1117 ASSERT(object_store->bool_class() != Class::null());
1108 return object_store->bool_class(); 1118 return object_store->bool_class();
1109 case kArray: 1119 case kArray:
1110 ASSERT(object_store->array_class() != Class::null()); 1120 ASSERT(object_store->array_class() != Class::null());
1111 return object_store->array_class(); 1121 return object_store->array_class();
1112 case kImmutableArray: 1122 case kImmutableArray:
1113 ASSERT(object_store->immutable_array_class() != Class::null()); 1123 ASSERT(object_store->immutable_array_class() != Class::null());
1114 return object_store->immutable_array_class(); 1124 return object_store->immutable_array_class();
1125 case kByteBuffer:
1126 ASSERT(object_store->byte_buffer_class() != Class::null());
1127 return object_store->byte_buffer_class();
1115 case kStacktrace: 1128 case kStacktrace:
1116 ASSERT(object_store->stacktrace_class() != Class::null()); 1129 ASSERT(object_store->stacktrace_class() != Class::null());
1117 return object_store->stacktrace_class(); 1130 return object_store->stacktrace_class();
1118 case kJSRegExp: 1131 case kJSRegExp:
1119 ASSERT(object_store->jsregexp_class() != Class::null()); 1132 ASSERT(object_store->jsregexp_class() != Class::null());
1120 return object_store->jsregexp_class(); 1133 return object_store->jsregexp_class();
1121 case kClosure: 1134 case kClosure:
1122 return Class::New<Closure>(); 1135 return Class::New<Closure>();
1123 case kInstance: 1136 case kInstance:
1124 return Class::New<Instance>(); 1137 return Class::New<Instance>();
(...skipping 5566 matching lines...) Expand 10 before | Expand all | Expand 10 after
6691 RawArray* Array::Empty() { 6704 RawArray* Array::Empty() {
6692 return Isolate::Current()->object_store()->empty_array(); 6705 return Isolate::Current()->object_store()->empty_array();
6693 } 6706 }
6694 6707
6695 6708
6696 const char* ImmutableArray::ToCString() const { 6709 const char* ImmutableArray::ToCString() const {
6697 return "ImmutableArray"; 6710 return "ImmutableArray";
6698 } 6711 }
6699 6712
6700 6713
6714 RawByteBuffer* ByteBuffer::New(uint8_t* data,
6715 intptr_t len,
6716 Heap::Space space) {
6717 Isolate* isolate = Isolate::Current();
6718 const Class& byte_buffer_class =
6719 Class::Handle(isolate->object_store()->byte_buffer_class());
6720 ByteBuffer& result = ByteBuffer::Handle();
6721 {
6722 RawObject* raw = Object::Allocate(byte_buffer_class,
6723 ByteBuffer::InstanceSize(),
6724 space);
6725 NoGCScope no_gc;
6726 result ^= raw;
6727 result.SetLength(len);
6728 result.SetData(data);
6729 }
6730 return result.raw();
6731 }
6732
6733
6734 bool ByteBuffer::Equals(const Instance& other) const {
6735 if (this->raw() == other.raw()) {
6736 // Both handles point to the same raw instance.
6737 return true;
6738 }
6739
6740 if (!other.IsByteBuffer() || other.IsNull()) {
6741 return false;
6742 }
6743
6744 ByteBuffer& other_array = ByteBuffer::Handle();
6745 other_array ^= other.raw();
6746
6747 intptr_t len = this->Length();
6748 if (len != other_array.Length()) {
6749 return false;
6750 }
6751
6752 return memcmp(this->Addr<uint8_t>(0), other_array.Addr<uint8_t>(0), len) == 0;
6753 }
6754
6755
6756 const char* ByteBuffer::ToCString() const {
6757 return "ByteBuffer";
6758 }
6759
6760
6701 RawClosure* Closure::New(const Function& function, 6761 RawClosure* Closure::New(const Function& function,
6702 const Context& context, 6762 const Context& context,
6703 Heap::Space space) { 6763 Heap::Space space) {
6704 Isolate* isolate = Isolate::Current(); 6764 Isolate* isolate = Isolate::Current();
6705 ASSERT(context.isolate() == isolate); 6765 ASSERT(context.isolate() == isolate);
6706 6766
6707 const Class& cls = Class::Handle(function.signature_class()); 6767 const Class& cls = Class::Handle(function.signature_class());
6708 Closure& result = Closure::Handle(); 6768 Closure& result = Closure::Handle();
6709 { 6769 {
6710 RawObject* raw = Object::Allocate(cls, Closure::InstanceSize(), space); 6770 RawObject* raw = Object::Allocate(cls, Closure::InstanceSize(), space);
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
7000 const String& str = String::Handle(pattern()); 7060 const String& str = String::Handle(pattern());
7001 const char* format = "JSRegExp: pattern=%s flags=%s"; 7061 const char* format = "JSRegExp: pattern=%s flags=%s";
7002 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); 7062 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags());
7003 char* chars = reinterpret_cast<char*>( 7063 char* chars = reinterpret_cast<char*>(
7004 Isolate::Current()->current_zone()->Allocate(len + 1)); 7064 Isolate::Current()->current_zone()->Allocate(len + 1));
7005 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); 7065 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags());
7006 return chars; 7066 return chars;
7007 } 7067 }
7008 7068
7009 } // namespace dart 7069 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/object_store.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698