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

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

Issue 10379018: Revert "Revert "Implement {Int,Uint}{8,16,32,64} and Float{32,64} typed arrays."" (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 7 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
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 "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 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 const char* cname, 446 const char* cname,
447 const Script& script, 447 const Script& script,
448 const Library& lib) { 448 const Library& lib) {
449 const String& name = String::Handle(String::NewSymbol(cname)); 449 const String& name = String::Handle(String::NewSymbol(cname));
450 cls.set_name(name); 450 cls.set_name(name);
451 cls.set_script(script); 451 cls.set_script(script);
452 lib.AddClass(cls); 452 lib.AddClass(cls);
453 } 453 }
454 454
455 455
456 void Object::RegisterPrivateClass(const Class& cls,
457 const char* public_class_name,
458 const Script& script,
459 const Library& lib) {
460 String& str = String::Handle();
461 str ^= String::NewSymbol(public_class_name);
462 str ^= lib.PrivateName(str);
463 cls.set_name(str);
464 cls.set_script(script);
465 lib.AddClass(cls);
466 }
467
468
456 RawError* Object::Init(Isolate* isolate) { 469 RawError* Object::Init(Isolate* isolate) {
457 TIMERSCOPE(time_bootstrap); 470 TIMERSCOPE(time_bootstrap);
458 ObjectStore* object_store = isolate->object_store(); 471 ObjectStore* object_store = isolate->object_store();
459 472
460 Class& cls = Class::Handle(); 473 Class& cls = Class::Handle();
461 Type& type = Type::Handle(); 474 Type& type = Type::Handle();
462 Array& array = Array::Handle(); 475 Array& array = Array::Handle();
463 476
464 // All RawArray fields will be initialized to an empty array, therefore 477 // All RawArray fields will be initialized to an empty array, therefore
465 // initialize array class first. 478 // initialize array class first.
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
597 // Super type set below, after Object is allocated. 610 // Super type set below, after Object is allocated.
598 611
599 cls = Class::New<JSRegExp>(); 612 cls = Class::New<JSRegExp>();
600 object_store->set_jsregexp_class(cls); 613 object_store->set_jsregexp_class(cls);
601 RegisterClass(cls, "JSSyntaxRegExp", impl_script, core_impl_lib); 614 RegisterClass(cls, "JSSyntaxRegExp", impl_script, core_impl_lib);
602 pending_classes.Add(cls, Heap::kOld); 615 pending_classes.Add(cls, Heap::kOld);
603 616
604 // Initialize the base interfaces used by the core VM classes. 617 // Initialize the base interfaces used by the core VM classes.
605 const Script& script = Script::Handle(Bootstrap::LoadScript()); 618 const Script& script = Script::Handle(Bootstrap::LoadScript());
606 619
607 // Allocate and initialize the Object class and type. 620 // Allocate and initialize the Object class and type. The Object
608 // The Object and ExternalByteArray classes are the only pre-allocated 621 // class and ByteArray subclasses are the only pre-allocated,
609 // non-interface classes in the core library. 622 // non-interface classes in the core library.
610 cls = Class::New<Instance>(); 623 cls = Class::New<Instance>();
611 object_store->set_object_class(cls); 624 object_store->set_object_class(cls);
612 cls.set_name(String::Handle(String::NewSymbol("Object"))); 625 cls.set_name(String::Handle(String::NewSymbol("Object")));
613 cls.set_script(script); 626 cls.set_script(script);
614 cls.set_class_state(RawClass::kPreFinalized); 627 cls.set_class_state(RawClass::kPreFinalized);
615 core_lib.AddClass(cls); 628 core_lib.AddClass(cls);
616 pending_classes.Add(cls, Heap::kOld); 629 pending_classes.Add(cls, Heap::kOld);
617 type = Type::NewNonParameterizedType(cls); 630 type = Type::NewNonParameterizedType(cls);
618 object_store->set_object_type(type); 631 object_store->set_object_type(type);
619 632
620 cls = Class::New<InternalByteArray>(); 633 cls = Class::New<Int8Array>();
621 object_store->set_internal_byte_array_class(cls); 634 object_store->set_int8_array_class(cls);
622 String& public_class_name = String::Handle(); 635 RegisterPrivateClass(cls, "_Int8Array", script, core_lib);
623 public_class_name = String::New("_InternalByteArray");
624 cls.set_name(String::Handle(core_lib.PrivateName(public_class_name)));
625 cls.set_script(script);
626 core_lib.AddClass(cls);
627 636
628 cls = Class::New<ExternalByteArray>(); 637 cls = Class::New<Uint8Array>();
629 object_store->set_external_byte_array_class(cls); 638 object_store->set_uint8_array_class(cls);
630 public_class_name = String::New("_ExternalByteArray"); 639 RegisterPrivateClass(cls, "_Uint8Array", script, core_lib);
631 cls.set_name(String::Handle(core_lib.PrivateName(public_class_name))); 640
632 cls.set_script(script); 641 cls = Class::New<Int16Array>();
633 core_lib.AddClass(cls); 642 object_store->set_int16_array_class(cls);
643 RegisterPrivateClass(cls, "_Int16Array", script, core_lib);
644
645 cls = Class::New<Uint16Array>();
646 object_store->set_uint16_array_class(cls);
647 RegisterPrivateClass(cls, "_Uint16Array", script, core_lib);
648
649 cls = Class::New<Int32Array>();
650 object_store->set_int32_array_class(cls);
651 RegisterPrivateClass(cls, "_Int32Array", script, core_lib);
652
653 cls = Class::New<Uint32Array>();
654 object_store->set_uint32_array_class(cls);
655 RegisterPrivateClass(cls, "_Uint32Array", script, core_lib);
656
657 cls = Class::New<Int64Array>();
658 object_store->set_int64_array_class(cls);
659 RegisterPrivateClass(cls, "_Int64Array", script, core_lib);
660
661 cls = Class::New<Uint64Array>();
662 object_store->set_uint64_array_class(cls);
663 RegisterPrivateClass(cls, "_Uint64Array", script, core_lib);
664
665 cls = Class::New<Float32Array>();
666 object_store->set_float32_array_class(cls);
667 RegisterPrivateClass(cls, "_Float32Array", script, core_lib);
668
669 cls = Class::New<Float64Array>();
670 object_store->set_float64_array_class(cls);
671 RegisterPrivateClass(cls, "_Float64Array", script, core_lib);
672
673 cls = Class::New<ExternalInt8Array>();
674 object_store->set_external_int8_array_class(cls);
675 RegisterPrivateClass(cls, "_ExternalInt8Array", script, core_lib);
676
677 cls = Class::New<ExternalUint8Array>();
678 object_store->set_external_uint8_array_class(cls);
679 RegisterPrivateClass(cls, "_ExternalUint8Array", script, core_lib);
680
681 cls = Class::New<ExternalInt16Array>();
682 object_store->set_external_int16_array_class(cls);
683 RegisterPrivateClass(cls, "_ExternalInt16Array", script, core_lib);
684
685 cls = Class::New<ExternalUint16Array>();
686 object_store->set_external_uint16_array_class(cls);
687 RegisterPrivateClass(cls, "_ExternalUint16Array", script, core_lib);
688
689 cls = Class::New<ExternalInt32Array>();
690 object_store->set_external_int32_array_class(cls);
691 RegisterPrivateClass(cls, "_ExternalInt32Array", script, core_lib);
692
693 cls = Class::New<ExternalUint32Array>();
694 object_store->set_external_uint32_array_class(cls);
695 RegisterPrivateClass(cls, "_ExternalUint32Array", script, core_lib);
696
697 cls = Class::New<ExternalInt64Array>();
698 object_store->set_external_int64_array_class(cls);
699 RegisterPrivateClass(cls, "_ExternalInt64Array", script, core_lib);
700
701 cls = Class::New<ExternalUint64Array>();
702 object_store->set_external_uint64_array_class(cls);
703 RegisterPrivateClass(cls, "_ExternalUint64Array", script, core_lib);
704
705 cls = Class::New<ExternalFloat32Array>();
706 object_store->set_external_float32_array_class(cls);
707 RegisterPrivateClass(cls, "_ExternalFloat32Array", script, core_lib);
708
709 cls = Class::New<ExternalFloat64Array>();
710 object_store->set_external_float64_array_class(cls);
711 RegisterPrivateClass(cls, "_ExternalFloat64Array", script, core_lib);
634 712
635 // Set the super type of class Stacktrace to Object type so that the 713 // Set the super type of class Stacktrace to Object type so that the
636 // 'toString' method is implemented. 714 // 'toString' method is implemented.
637 cls = object_store->stacktrace_class(); 715 cls = object_store->stacktrace_class();
638 cls.set_super_type(type); 716 cls.set_super_type(type);
639 717
640 cls = CreateAndRegisterInterface("Function", script, core_lib); 718 cls = CreateAndRegisterInterface("Function", script, core_lib);
641 pending_classes.Add(cls, Heap::kOld); 719 pending_classes.Add(cls, Heap::kOld);
642 type = Type::NewNonParameterizedType(cls); 720 type = Type::NewNonParameterizedType(cls);
643 object_store->set_function_interface(type); 721 object_store->set_function_interface(type);
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
764 Array& empty_array = Array::Handle(); 842 Array& empty_array = Array::Handle();
765 empty_array = Array::New(0); 843 empty_array = Array::New(0);
766 object_store->set_empty_array(empty_array); 844 object_store->set_empty_array(empty_array);
767 845
768 cls = Class::New<ImmutableArray>(); 846 cls = Class::New<ImmutableArray>();
769 object_store->set_immutable_array_class(cls); 847 object_store->set_immutable_array_class(cls);
770 848
771 cls = Class::New<GrowableObjectArray>(); 849 cls = Class::New<GrowableObjectArray>();
772 object_store->set_growable_object_array_class(cls); 850 object_store->set_growable_object_array_class(cls);
773 851
774 cls = Class::New<InternalByteArray>(); 852 cls = Class::New<Int8Array>();
775 object_store->set_internal_byte_array_class(cls); 853 object_store->set_int8_array_class(cls);
776 854
777 cls = Class::New<ExternalByteArray>(); 855 cls = Class::New<Uint8Array>();
778 object_store->set_external_byte_array_class(cls); 856 object_store->set_uint8_array_class(cls);
857
858 cls = Class::New<Int16Array>();
859 object_store->set_int16_array_class(cls);
860
861 cls = Class::New<Uint16Array>();
862 object_store->set_uint16_array_class(cls);
863
864 cls = Class::New<Int32Array>();
865 object_store->set_int32_array_class(cls);
866
867 cls = Class::New<Uint32Array>();
868 object_store->set_uint32_array_class(cls);
869
870 cls = Class::New<Int64Array>();
871 object_store->set_int64_array_class(cls);
872
873 cls = Class::New<Uint64Array>();
874 object_store->set_uint64_array_class(cls);
875
876 cls = Class::New<Float32Array>();
877 object_store->set_float32_array_class(cls);
878
879 cls = Class::New<Float64Array>();
880 object_store->set_float64_array_class(cls);
881
882 cls = Class::New<ExternalInt8Array>();
883 object_store->set_external_int8_array_class(cls);
884
885 cls = Class::New<ExternalUint8Array>();
886 object_store->set_external_uint8_array_class(cls);
887
888 cls = Class::New<ExternalInt16Array>();
889 object_store->set_external_int16_array_class(cls);
890
891 cls = Class::New<ExternalUint16Array>();
892 object_store->set_external_uint16_array_class(cls);
893
894 cls = Class::New<ExternalInt32Array>();
895 object_store->set_external_int32_array_class(cls);
896
897 cls = Class::New<ExternalUint32Array>();
898 object_store->set_external_uint32_array_class(cls);
899
900 cls = Class::New<ExternalInt64Array>();
901 object_store->set_external_int64_array_class(cls);
902
903 cls = Class::New<ExternalUint64Array>();
904 object_store->set_external_uint64_array_class(cls);
905
906 cls = Class::New<ExternalFloat32Array>();
907 object_store->set_external_float32_array_class(cls);
908
909 cls = Class::New<ExternalFloat64Array>();
910 object_store->set_external_float64_array_class(cls);
779 911
780 cls = Class::New<Smi>(); 912 cls = Class::New<Smi>();
781 object_store->set_smi_class(cls); 913 object_store->set_smi_class(cls);
782 914
783 cls = Class::New<Mint>(); 915 cls = Class::New<Mint>();
784 object_store->set_mint_class(cls); 916 object_store->set_mint_class(cls);
785 917
786 cls = Class::New<Double>(); 918 cls = Class::New<Double>();
787 object_store->set_double_class(cls); 919 object_store->set_double_class(cls);
788 920
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
956 // TODO(srdjan): Make functions_cache growable and start with a smaller size. 1088 // TODO(srdjan): Make functions_cache growable and start with a smaller size.
957 Array& fcache = 1089 Array& fcache =
958 Array::Handle(Array::New(FunctionsCache::kNumEntries * 32, Heap::kOld)); 1090 Array::Handle(Array::New(FunctionsCache::kNumEntries * 32, Heap::kOld));
959 StorePointer(&raw_ptr()->functions_cache_, fcache.raw()); 1091 StorePointer(&raw_ptr()->functions_cache_, fcache.raw());
960 StorePointer(&raw_ptr()->constants_, empty_array.raw()); 1092 StorePointer(&raw_ptr()->constants_, empty_array.raw());
961 StorePointer(&raw_ptr()->canonical_types_, empty_array.raw()); 1093 StorePointer(&raw_ptr()->canonical_types_, empty_array.raw());
962 StorePointer(&raw_ptr()->functions_, empty_array.raw()); 1094 StorePointer(&raw_ptr()->functions_, empty_array.raw());
963 StorePointer(&raw_ptr()->fields_, empty_array.raw()); 1095 StorePointer(&raw_ptr()->fields_, empty_array.raw());
964 } 1096 }
965 1097
1098
1099 bool Class::HasInstanceFields() const {
1100 const Array& field_array = Array::Handle(fields());
1101 Field& field = Field::Handle();
1102 for (intptr_t i = 0; i < field_array.Length(); ++i) {
1103 field ^= field_array.At(i);
1104 if (!field.is_static()) {
1105 return true;
1106 }
1107 }
1108 return false;
1109 }
1110
966 void Class::SetFunctions(const Array& value) const { 1111 void Class::SetFunctions(const Array& value) const {
967 ASSERT(!value.IsNull()); 1112 ASSERT(!value.IsNull());
968 // Bind all the functions in the array to this class. 1113 // Bind all the functions in the array to this class.
969 Function& func = Function::Handle(); 1114 Function& func = Function::Handle();
970 intptr_t len = value.Length(); 1115 intptr_t len = value.Length();
971 for (intptr_t i = 0; i < len; i++) { 1116 for (intptr_t i = 0; i < len; i++) {
972 func ^= value.At(i); 1117 func ^= value.At(i);
973 func.set_owner(*this); 1118 func.set_owner(*this);
974 } 1119 }
975 StorePointer(&raw_ptr()->functions_, value.raw()); 1120 StorePointer(&raw_ptr()->functions_, value.raw());
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after
1386 return object_store->bool_class(); 1531 return object_store->bool_class();
1387 case kArray: 1532 case kArray:
1388 ASSERT(object_store->array_class() != Class::null()); 1533 ASSERT(object_store->array_class() != Class::null());
1389 return object_store->array_class(); 1534 return object_store->array_class();
1390 case kImmutableArray: 1535 case kImmutableArray:
1391 ASSERT(object_store->immutable_array_class() != Class::null()); 1536 ASSERT(object_store->immutable_array_class() != Class::null());
1392 return object_store->immutable_array_class(); 1537 return object_store->immutable_array_class();
1393 case kGrowableObjectArray: 1538 case kGrowableObjectArray:
1394 ASSERT(object_store->growable_object_array_class() != Class::null()); 1539 ASSERT(object_store->growable_object_array_class() != Class::null());
1395 return object_store->growable_object_array_class(); 1540 return object_store->growable_object_array_class();
1396 case kInternalByteArray: 1541 case kInt8Array:
1397 ASSERT(object_store->internal_byte_array_class() != Class::null()); 1542 ASSERT(object_store->int8_array_class() != Class::null());
1398 return object_store->internal_byte_array_class(); 1543 return object_store->int8_array_class();
1399 case kExternalByteArray: 1544 case kUint8Array:
1400 ASSERT(object_store->external_byte_array_class() != Class::null()); 1545 ASSERT(object_store->uint8_array_class() != Class::null());
1401 return object_store->external_byte_array_class(); 1546 return object_store->uint8_array_class();
1547 case kInt16Array:
1548 ASSERT(object_store->int16_array_class() != Class::null());
1549 return object_store->int16_array_class();
1550 case kUint16Array:
1551 ASSERT(object_store->uint16_array_class() != Class::null());
1552 return object_store->uint16_array_class();
1553 case kInt32Array:
1554 ASSERT(object_store->int32_array_class() != Class::null());
1555 return object_store->int32_array_class();
1556 case kUint32Array:
1557 ASSERT(object_store->uint32_array_class() != Class::null());
1558 return object_store->uint32_array_class();
1559 case kInt64Array:
1560 ASSERT(object_store->int64_array_class() != Class::null());
1561 return object_store->int64_array_class();
1562 case kUint64Array:
1563 ASSERT(object_store->uint64_array_class() != Class::null());
1564 return object_store->uint64_array_class();
1565 case kFloat32Array:
1566 ASSERT(object_store->float32_array_class() != Class::null());
1567 return object_store->float32_array_class();
1568 case kFloat64Array:
1569 ASSERT(object_store->float64_array_class() != Class::null());
1570 return object_store->float64_array_class();
1571 case kExternalInt8Array:
1572 ASSERT(object_store->external_int8_array_class() != Class::null());
1573 return object_store->external_int8_array_class();
1574 case kExternalUint8Array:
1575 ASSERT(object_store->external_uint8_array_class() != Class::null());
1576 return object_store->external_uint8_array_class();
1577 case kExternalInt16Array:
1578 ASSERT(object_store->external_int16_array_class() != Class::null());
1579 return object_store->external_int16_array_class();
1580 case kExternalUint16Array:
1581 ASSERT(object_store->external_uint16_array_class() != Class::null());
1582 return object_store->external_uint16_array_class();
1583 case kExternalInt32Array:
1584 ASSERT(object_store->external_int32_array_class() != Class::null());
1585 return object_store->external_int32_array_class();
1586 case kExternalUint32Array:
1587 ASSERT(object_store->external_uint32_array_class() != Class::null());
1588 return object_store->external_uint32_array_class();
1589 case kExternalInt64Array:
1590 ASSERT(object_store->external_int64_array_class() != Class::null());
1591 return object_store->external_int64_array_class();
1592 case kExternalUint64Array:
1593 ASSERT(object_store->external_uint64_array_class() != Class::null());
1594 return object_store->external_uint64_array_class();
1595 case kExternalFloat32Array:
1596 ASSERT(object_store->external_float32_array_class() != Class::null());
1597 return object_store->external_float32_array_class();
1598 case kExternalFloat64Array:
1599 ASSERT(object_store->external_float64_array_class() != Class::null());
1600 return object_store->external_float64_array_class();
1402 case kStacktrace: 1601 case kStacktrace:
1403 ASSERT(object_store->stacktrace_class() != Class::null()); 1602 ASSERT(object_store->stacktrace_class() != Class::null());
1404 return object_store->stacktrace_class(); 1603 return object_store->stacktrace_class();
1405 case kJSRegExp: 1604 case kJSRegExp:
1406 ASSERT(object_store->jsregexp_class() != Class::null()); 1605 ASSERT(object_store->jsregexp_class() != Class::null());
1407 return object_store->jsregexp_class(); 1606 return object_store->jsregexp_class();
1408 case kClosure: 1607 case kClosure:
1409 return Class::New<Closure>(); 1608 return Class::New<Closure>();
1410 case kInstance: 1609 case kInstance:
1411 return Class::New<Instance>(); 1610 return Class::New<Instance>();
(...skipping 7520 matching lines...) Expand 10 before | Expand all | Expand 10 after
8932 } 9131 }
8933 return result.raw(); 9132 return result.raw();
8934 } 9133 }
8935 9134
8936 9135
8937 const char* GrowableObjectArray::ToCString() const { 9136 const char* GrowableObjectArray::ToCString() const {
8938 return "GrowableObjectArray"; 9137 return "GrowableObjectArray";
8939 } 9138 }
8940 9139
8941 9140
8942 intptr_t ByteArray::Length() const { 9141 void ByteArray::Copy(void* dst,
8943 // ByteArray is an abstract class.
8944 UNREACHABLE();
8945 return 0;
8946 }
8947
8948
8949 void ByteArray::Copy(uint8_t* dst,
8950 const ByteArray& src, 9142 const ByteArray& src,
8951 intptr_t src_offset, 9143 intptr_t src_offset,
8952 intptr_t length) { 9144 intptr_t length) {
8953 ASSERT(Utils::RangeCheck(src_offset, length, src.Length())); 9145 ASSERT(Utils::RangeCheck(src_offset, length, src.ByteLength()));
8954 { 9146 {
8955 NoGCScope no_gc; 9147 NoGCScope no_gc;
8956 if (length > 0) { 9148 if (length > 0) {
8957 memmove(dst, src.ByteAddr(src_offset), length); 9149 memmove(dst, src.ByteAddr(src_offset), length);
8958 } 9150 }
8959 } 9151 }
8960 } 9152 }
8961 9153
8962 9154
8963 void ByteArray::Copy(const ByteArray& dst, 9155 void ByteArray::Copy(const ByteArray& dst,
8964 intptr_t dst_offset, 9156 intptr_t dst_offset,
8965 const uint8_t* src, 9157 const void* src,
8966 intptr_t length) { 9158 intptr_t length) {
8967 ASSERT(Utils::RangeCheck(dst_offset, length, dst.Length())); 9159 ASSERT(Utils::RangeCheck(dst_offset, length, dst.ByteLength()));
8968 { 9160 {
8969 NoGCScope no_gc; 9161 NoGCScope no_gc;
8970 if (length > 0) { 9162 if (length > 0) {
8971 memmove(dst.ByteAddr(dst_offset), src, length); 9163 memmove(dst.ByteAddr(dst_offset), src, length);
8972 } 9164 }
8973 } 9165 }
8974 } 9166 }
8975 9167
8976 9168
8977 void ByteArray::Copy(const ByteArray& dst, 9169 void ByteArray::Copy(const ByteArray& dst,
8978 intptr_t dst_offset, 9170 intptr_t dst_offset,
8979 const ByteArray& src, 9171 const ByteArray& src,
8980 intptr_t src_offset, 9172 intptr_t src_offset,
8981 intptr_t length) { 9173 intptr_t length) {
8982 ASSERT(Utils::RangeCheck(src_offset, length, src.Length())); 9174 ASSERT(Utils::RangeCheck(src_offset, length, src.ByteLength()));
8983 ASSERT(Utils::RangeCheck(dst_offset, length, dst.Length())); 9175 ASSERT(Utils::RangeCheck(dst_offset, length, dst.ByteLength()));
8984 { 9176 {
8985 NoGCScope no_gc; 9177 NoGCScope no_gc;
8986 if (length > 0) { 9178 if (length > 0) {
8987 memmove(dst.ByteAddr(dst_offset), src.ByteAddr(src_offset), length); 9179 memmove(dst.ByteAddr(dst_offset), src.ByteAddr(src_offset), length);
8988 } 9180 }
8989 } 9181 }
8990 } 9182 }
8991 9183
8992 9184
9185 template<typename T>
9186 static void ExternalByteArrayFinalize(Dart_Handle handle, void* peer) {
9187 delete reinterpret_cast<ExternalByteArrayData<T>*>(peer);
9188 DeleteWeakPersistentHandle(handle);
9189 }
9190
9191
9192 template<typename HandleT, typename RawT, typename ElementT>
9193 RawT* ByteArray::NewExternalImpl(const Class& cls,
9194 ElementT* data,
9195 intptr_t len,
9196 void* peer,
9197 Dart_PeerFinalizer callback,
9198 Heap::Space space) {
9199 HandleT& result = HandleT::Handle();
9200 ExternalByteArrayData<ElementT>* external_data =
9201 new ExternalByteArrayData<ElementT>(data, peer, callback);
9202 {
9203 RawObject* raw = Object::Allocate(cls, HandleT::InstanceSize(), space);
9204 NoGCScope no_gc;
9205 result ^= raw;
9206 result.SetLength(len);
9207 result.SetExternalData(external_data);
9208 }
9209 AddFinalizer(result, external_data, ExternalByteArrayFinalize<ElementT>);
9210 return result.raw();
9211 }
9212
9213
9214 intptr_t ByteArray::ByteLength() const {
9215 // ByteArray is an abstract class.
9216 UNREACHABLE();
9217 return 0;
9218 }
9219
9220
8993 uint8_t* ByteArray::ByteAddr(intptr_t byte_offset) const { 9221 uint8_t* ByteArray::ByteAddr(intptr_t byte_offset) const {
8994 // ByteArray is an abstract class. 9222 // ByteArray is an abstract class.
8995 UNREACHABLE(); 9223 UNREACHABLE();
8996 return NULL; 9224 return NULL;
8997 } 9225 }
8998 9226
8999 9227
9000 const char* ByteArray::ToCString() const { 9228 const char* ByteArray::ToCString() const {
9001 // ByteArray is an abstract class. 9229 // ByteArray is an abstract class.
9002 UNREACHABLE(); 9230 UNREACHABLE();
9003 return "ByteArray"; 9231 return "ByteArray";
9004 } 9232 }
9005 9233
9006 9234
9007 RawInternalByteArray* InternalByteArray::New(intptr_t len, 9235 template<typename HandleT, typename RawT>
9008 Heap::Space space) { 9236 RawT* ByteArray::NewImpl(const Class& cls, intptr_t len, Heap::Space space) {
9009 Isolate* isolate = Isolate::Current(); 9237 HandleT& result = HandleT::Handle();
9010 const Class& internal_byte_array_class =
9011 Class::Handle(isolate->object_store()->internal_byte_array_class());
9012 InternalByteArray& result = InternalByteArray::Handle();
9013 { 9238 {
9014 RawObject* raw = Object::Allocate(internal_byte_array_class, 9239 RawObject* raw = Object::Allocate(cls, HandleT::InstanceSize(len), space);
9015 InternalByteArray::InstanceSize(len),
9016 space);
9017 NoGCScope no_gc; 9240 NoGCScope no_gc;
9018 result ^= raw; 9241 result ^= raw;
9019 result.SetLength(len); 9242 result.SetLength(len);
9020 if (len > 0) { 9243 if (len > 0) {
9021 memset(result.Addr<uint8_t>(0), 0, len); 9244 memset(result.ByteAddr(0), 0, result.ByteLength());
9022 } 9245 }
9023 } 9246 }
9024 return result.raw(); 9247 return result.raw();
9025 } 9248 }
9026 9249
9027 9250
9028 RawInternalByteArray* InternalByteArray::New(const uint8_t* data, 9251 template<typename HandleT, typename RawT, typename ElementT>
9029 intptr_t len, 9252 RawT* ByteArray::NewImpl(const Class& cls,
9030 Heap::Space space) { 9253 const ElementT* data,
9031 InternalByteArray& result = 9254 intptr_t len,
9032 InternalByteArray::Handle(InternalByteArray::New(len, space)); 9255 Heap::Space space) {
9256 HandleT& result = HandleT::Handle();
9033 { 9257 {
9258 RawObject* raw = Object::Allocate(cls, HandleT::InstanceSize(len), space);
9034 NoGCScope no_gc; 9259 NoGCScope no_gc;
9260 result ^= raw;
9261 result.SetLength(len);
9035 if (len > 0) { 9262 if (len > 0) {
9036 memmove(result.Addr<uint8_t>(0), data, len); 9263 memmove(result.ByteAddr(0), data, result.ByteLength());
9037 } 9264 }
9038 } 9265 }
9039 return result.raw(); 9266 return result.raw();
9040 } 9267 }
9041 9268
9042 9269
9043 const char* InternalByteArray::ToCString() const { 9270 RawInt8Array* Int8Array::New(intptr_t len, Heap::Space space) {
9044 return "_InternalByteArray"; 9271 Isolate* isolate = Isolate::Current();
9045 } 9272 const Class& cls =
9046 9273 Class::Handle(isolate->object_store()->int8_array_class());
9047 9274 return NewImpl<Int8Array, RawInt8Array>(cls, len, space);
9048 void ExternalByteArray::Finalize(Dart_Handle handle, void* peer) { 9275 }
9049 delete reinterpret_cast<ExternalByteArrayData*>(peer); 9276
9050 DeleteWeakPersistentHandle(handle); 9277
9051 } 9278 RawInt8Array* Int8Array::New(const int8_t* data,
9052 9279 intptr_t len,
9053 9280 Heap::Space space) {
9054 RawExternalByteArray* ExternalByteArray::New(uint8_t* data, 9281 Isolate* isolate = Isolate::Current();
9282 const Class& cls =
9283 Class::Handle(isolate->object_store()->int8_array_class());
9284 return NewImpl<Int8Array, RawInt8Array>(cls, data, len, space);
9285 }
9286
9287
9288 const char* Int8Array::ToCString() const {
9289 return "_Int8Array";
9290 }
9291
9292
9293 RawUint8Array* Uint8Array::New(intptr_t len, Heap::Space space) {
9294 Isolate* isolate = Isolate::Current();
9295 const Class& cls =
9296 Class::Handle(isolate->object_store()->uint8_array_class());
9297 return NewImpl<Uint8Array, RawUint8Array>(cls, len, space);
9298 }
9299
9300
9301 RawUint8Array* Uint8Array::New(const uint8_t* data,
9302 intptr_t len,
9303 Heap::Space space) {
9304 Isolate* isolate = Isolate::Current();
9305 const Class& cls =
9306 Class::Handle(isolate->object_store()->uint8_array_class());
9307 return NewImpl<Uint8Array, RawUint8Array>(cls, data, len, space);
9308 }
9309
9310
9311 const char* Uint8Array::ToCString() const {
9312 return "_Uint8Array";
9313 }
9314
9315
9316 RawInt16Array* Int16Array::New(intptr_t len, Heap::Space space) {
9317 Isolate* isolate = Isolate::Current();
9318 const Class& cls =
9319 Class::Handle(isolate->object_store()->int16_array_class());
9320 return NewImpl<Int16Array, RawInt16Array>(cls, len, space);
9321 }
9322
9323
9324 RawInt16Array* Int16Array::New(const int16_t* data,
9325 intptr_t len,
9326 Heap::Space space) {
9327 Isolate* isolate = Isolate::Current();
9328 const Class& cls =
9329 Class::Handle(isolate->object_store()->int16_array_class());
9330 return NewImpl<Int16Array, RawInt16Array>(cls, data, len, space);
9331 }
9332
9333
9334 const char* Int16Array::ToCString() const {
9335 return "_Int16Array";
9336 }
9337
9338
9339 RawUint16Array* Uint16Array::New(intptr_t len, Heap::Space space) {
9340 Isolate* isolate = Isolate::Current();
9341 const Class& cls =
9342 Class::Handle(isolate->object_store()->uint16_array_class());
9343 return NewImpl<Uint16Array, RawUint16Array>(cls, len, space);
9344 }
9345
9346
9347 RawUint16Array* Uint16Array::New(const uint16_t* data,
9348 intptr_t len,
9349 Heap::Space space) {
9350 Isolate* isolate = Isolate::Current();
9351 const Class& cls =
9352 Class::Handle(isolate->object_store()->uint16_array_class());
9353 return NewImpl<Uint16Array, RawUint16Array>(cls, data, len, space);
9354 }
9355
9356
9357 const char* Uint16Array::ToCString() const {
9358 return "_Uint16Array";
9359 }
9360
9361
9362 RawInt32Array* Int32Array::New(intptr_t len, Heap::Space space) {
9363 Isolate* isolate = Isolate::Current();
9364 const Class& cls =
9365 Class::Handle(isolate->object_store()->int32_array_class());
9366 return NewImpl<Int32Array, RawInt32Array>(cls, len, space);
9367 }
9368
9369
9370 RawInt32Array* Int32Array::New(const int32_t* data,
9371 intptr_t len,
9372 Heap::Space space) {
9373 Isolate* isolate = Isolate::Current();
9374 const Class& cls =
9375 Class::Handle(isolate->object_store()->int32_array_class());
9376 return NewImpl<Int32Array, RawInt32Array>(cls, data, len, space);
9377 }
9378
9379
9380 const char* Int32Array::ToCString() const {
9381 return "_Int32Array";
9382 }
9383
9384
9385 RawUint32Array* Uint32Array::New(intptr_t len, Heap::Space space) {
9386 Isolate* isolate = Isolate::Current();
9387 const Class& cls =
9388 Class::Handle(isolate->object_store()->uint32_array_class());
9389 return NewImpl<Uint32Array, RawUint32Array>(cls, len, space);
9390 }
9391
9392
9393 RawUint32Array* Uint32Array::New(const uint32_t* data,
9394 intptr_t len,
9395 Heap::Space space) {
9396 Isolate* isolate = Isolate::Current();
9397 const Class& cls =
9398 Class::Handle(isolate->object_store()->uint32_array_class());
9399 return NewImpl<Uint32Array, RawUint32Array>(cls, data, len, space);
9400 }
9401
9402
9403 const char* Uint32Array::ToCString() const {
9404 return "_Uint32Array";
9405 }
9406
9407
9408 RawInt64Array* Int64Array::New(intptr_t len, Heap::Space space) {
9409 Isolate* isolate = Isolate::Current();
9410 const Class& cls =
9411 Class::Handle(isolate->object_store()->int64_array_class());
9412 return NewImpl<Int64Array, RawInt64Array>(cls, len, space);
9413 }
9414
9415
9416 RawInt64Array* Int64Array::New(const int64_t* data,
9417 intptr_t len,
9418 Heap::Space space) {
9419 Isolate* isolate = Isolate::Current();
9420 const Class& cls =
9421 Class::Handle(isolate->object_store()->int64_array_class());
9422 return NewImpl<Int64Array, RawInt64Array>(cls, data, len, space);
9423 }
9424
9425
9426 const char* Int64Array::ToCString() const {
9427 return "_Int64Array";
9428 }
9429
9430
9431 RawUint64Array* Uint64Array::New(intptr_t len, Heap::Space space) {
9432 Isolate* isolate = Isolate::Current();
9433 const Class& cls =
9434 Class::Handle(isolate->object_store()->uint64_array_class());
9435 return NewImpl<Uint64Array, RawUint64Array>(cls, len, space);
9436 }
9437
9438
9439 RawUint64Array* Uint64Array::New(const uint64_t* data,
9440 intptr_t len,
9441 Heap::Space space) {
9442 Isolate* isolate = Isolate::Current();
9443 const Class& cls =
9444 Class::Handle(isolate->object_store()->uint64_array_class());
9445 return NewImpl<Uint64Array, RawUint64Array>(cls, data, len, space);
9446 }
9447
9448
9449 const char* Uint64Array::ToCString() const {
9450 return "_Uint64Array";
9451 }
9452
9453
9454 RawFloat32Array* Float32Array::New(intptr_t len, Heap::Space space) {
9455 Isolate* isolate = Isolate::Current();
9456 const Class& cls =
9457 Class::Handle(isolate->object_store()->float32_array_class());
9458 return NewImpl<Float32Array, RawFloat32Array>(cls, len, space);
9459 }
9460
9461
9462 RawFloat32Array* Float32Array::New(const float* data,
9463 intptr_t len,
9464 Heap::Space space) {
9465 Isolate* isolate = Isolate::Current();
9466 const Class& cls =
9467 Class::Handle(isolate->object_store()->float32_array_class());
9468 return NewImpl<Float32Array, RawFloat32Array>(cls, data, len, space);
9469 }
9470
9471
9472 const char* Float32Array::ToCString() const {
9473 return "_Float32Array";
9474 }
9475
9476
9477 RawFloat64Array* Float64Array::New(intptr_t len, Heap::Space space) {
9478 Isolate* isolate = Isolate::Current();
9479 const Class& cls =
9480 Class::Handle(isolate->object_store()->float64_array_class());
9481 return NewImpl<Float64Array, RawFloat64Array>(cls, len, space);
9482 }
9483
9484
9485 RawFloat64Array* Float64Array::New(const double* data,
9486 intptr_t len,
9487 Heap::Space space) {
9488 Isolate* isolate = Isolate::Current();
9489 const Class& cls =
9490 Class::Handle(isolate->object_store()->float64_array_class());
9491 return NewImpl<Float64Array, RawFloat64Array>(cls, data, len, space);
9492 }
9493
9494
9495 const char* Float64Array::ToCString() const {
9496 return "_Float64Array";
9497 }
9498
9499
9500 RawExternalInt8Array* ExternalInt8Array::New(int8_t* data,
9055 intptr_t len, 9501 intptr_t len,
9056 void* peer, 9502 void* peer,
9057 Dart_PeerFinalizer callback, 9503 Dart_PeerFinalizer callback,
9058 Heap::Space space) { 9504 Heap::Space space) {
9059 Isolate* isolate = Isolate::Current(); 9505 Isolate* isolate = Isolate::Current();
9060 const Class& external_byte_array_class = 9506 const Class& cls =
9061 Class::Handle(isolate->object_store()->external_byte_array_class()); 9507 Class::Handle(isolate->object_store()->external_int8_array_class());
9062 ExternalByteArray& result = ExternalByteArray::Handle(); 9508 return NewExternalImpl<ExternalInt8Array, RawExternalInt8Array>(
9063 ExternalByteArrayData* external_data = 9509 cls, data, len, peer, callback, space);
9064 new ExternalByteArrayData(data, peer, callback); 9510 }
9065 { 9511
9066 RawObject* raw = Object::Allocate(external_byte_array_class, 9512
9067 ExternalByteArray::InstanceSize(), 9513 const char* ExternalInt8Array::ToCString() const {
9068 space); 9514 return "_ExternalInt8Array";
9069 NoGCScope no_gc; 9515 }
9070 result ^= raw; 9516
9071 result.SetLength(len); 9517
9072 result.SetExternalData(external_data); 9518 RawExternalUint8Array* ExternalUint8Array::New(uint8_t* data,
9073 } 9519 intptr_t len,
9074 AddFinalizer(result, external_data, ExternalByteArray::Finalize); 9520 void* peer,
9075 return result.raw(); 9521 Dart_PeerFinalizer callback,
9076 } 9522 Heap::Space space) {
9077 9523 Isolate* isolate = Isolate::Current();
9078 9524 const Class& cls =
9079 const char* ExternalByteArray::ToCString() const { 9525 Class::Handle(isolate->object_store()->external_uint8_array_class());
9080 return "_ExternalByteArray"; 9526 return NewExternalImpl<ExternalUint8Array, RawExternalUint8Array>(
9081 } 9527 cls, data, len, peer, callback, space);
9528 }
9529
9530
9531 const char* ExternalUint8Array::ToCString() const {
9532 return "_ExternalUint8Array";
9533 }
9534
9535
9536 RawExternalInt16Array* ExternalInt16Array::New(int16_t* data,
9537 intptr_t len,
9538 void* peer,
9539 Dart_PeerFinalizer callback,
9540 Heap::Space space) {
9541 Isolate* isolate = Isolate::Current();
9542 const Class& cls =
9543 Class::Handle(isolate->object_store()->external_int16_array_class());
9544 return NewExternalImpl<ExternalInt16Array, RawExternalInt16Array>(
9545 cls, data, len, peer, callback, space);
9546 }
9547
9548
9549 const char* ExternalInt16Array::ToCString() const {
9550 return "_ExternalInt16Array";
9551 }
9552
9553
9554 RawExternalUint16Array* ExternalUint16Array::New(uint16_t* data,
9555 intptr_t len,
9556 void* peer,
9557 Dart_PeerFinalizer callback,
9558 Heap::Space space) {
9559 Isolate* isolate = Isolate::Current();
9560 const Class& cls =
9561 Class::Handle(isolate->object_store()->external_uint16_array_class());
9562 return NewExternalImpl<ExternalUint16Array, RawExternalUint16Array>(
9563 cls, data, len, peer, callback, space);
9564 }
9565
9566
9567 const char* ExternalUint16Array::ToCString() const {
9568 return "_ExternalUint16Array";
9569 }
9570
9571
9572 RawExternalInt32Array* ExternalInt32Array::New(int32_t* data,
9573 intptr_t len,
9574 void* peer,
9575 Dart_PeerFinalizer callback,
9576 Heap::Space space) {
9577 Isolate* isolate = Isolate::Current();
9578 const Class& cls =
9579 Class::Handle(isolate->object_store()->external_int32_array_class());
9580 return NewExternalImpl<ExternalInt32Array, RawExternalInt32Array>(
9581 cls, data, len, peer, callback, space);
9582 }
9583
9584
9585 const char* ExternalInt32Array::ToCString() const {
9586 return "_ExternalInt32Array";
9587 }
9588
9589
9590 RawExternalUint32Array* ExternalUint32Array::New(uint32_t* data,
9591 intptr_t len,
9592 void* peer,
9593 Dart_PeerFinalizer callback,
9594 Heap::Space space) {
9595 Isolate* isolate = Isolate::Current();
9596 const Class& cls =
9597 Class::Handle(isolate->object_store()->external_uint32_array_class());
9598 return NewExternalImpl<ExternalUint32Array, RawExternalUint32Array>(
9599 cls, data, len, peer, callback, space);
9600 }
9601
9602
9603 const char* ExternalUint32Array::ToCString() const {
9604 return "_ExternalUint32Array";
9605 }
9606
9607
9608 RawExternalInt64Array* ExternalInt64Array::New(int64_t* data,
9609 intptr_t len,
9610 void* peer,
9611 Dart_PeerFinalizer callback,
9612 Heap::Space space) {
9613 Isolate* isolate = Isolate::Current();
9614 const Class& cls =
9615 Class::Handle(isolate->object_store()->external_int64_array_class());
9616 return NewExternalImpl<ExternalInt64Array, RawExternalInt64Array>(
9617 cls, data, len, peer, callback, space);
9618 }
9619
9620
9621 const char* ExternalInt64Array::ToCString() const {
9622 return "_ExternalInt64Array";
9623 }
9624
9625
9626 RawExternalUint64Array* ExternalUint64Array::New(uint64_t* data,
9627 intptr_t len,
9628 void* peer,
9629 Dart_PeerFinalizer callback,
9630 Heap::Space space) {
9631 Isolate* isolate = Isolate::Current();
9632 const Class& cls =
9633 Class::Handle(isolate->object_store()->external_uint64_array_class());
9634 return NewExternalImpl<ExternalUint64Array, RawExternalUint64Array>(
9635 cls, data, len, peer, callback, space);
9636 }
9637
9638
9639 const char* ExternalUint64Array::ToCString() const {
9640 return "_ExternalUint64Array";
9641 }
9642
9643
9644 RawExternalFloat32Array* ExternalFloat32Array::New(float* data,
9645 intptr_t len,
9646 void* peer,
9647 Dart_PeerFinalizer callback,
9648 Heap::Space space) {
9649 Isolate* isolate = Isolate::Current();
9650 const Class& cls =
9651 Class::Handle(isolate->object_store()->external_float32_array_class());
9652 return NewExternalImpl<ExternalFloat32Array, RawExternalFloat32Array>(
9653 cls, data, len, peer, callback, space);
9654 }
9655
9656
9657 const char* ExternalFloat32Array::ToCString() const {
9658 return "_ExternalFloat32Array";
9659 }
9660
9661
9662 RawExternalFloat64Array* ExternalFloat64Array::New(double* data,
9663 intptr_t len,
9664 void* peer,
9665 Dart_PeerFinalizer callback,
9666 Heap::Space space) {
9667 Isolate* isolate = Isolate::Current();
9668 const Class& cls =
9669 Class::Handle(isolate->object_store()->external_float64_array_class());
9670 return NewExternalImpl<ExternalFloat64Array, RawExternalFloat64Array>(
9671 cls, data, len, peer, callback, space);
9672 }
9673
9674
9675 const char* ExternalFloat64Array::ToCString() const {
9676 return "_ExternalFloat64Array";
9677 }
9678
9082 9679
9083 9680
9084 RawClosure* Closure::New(const Function& function, 9681 RawClosure* Closure::New(const Function& function,
9085 const Context& context, 9682 const Context& context,
9086 Heap::Space space) { 9683 Heap::Space space) {
9087 Isolate* isolate = Isolate::Current(); 9684 Isolate* isolate = Isolate::Current();
9088 ASSERT(context.isolate() == isolate); 9685 ASSERT(context.isolate() == isolate);
9089 9686
9090 const Class& cls = Class::Handle(function.signature_class()); 9687 const Class& cls = Class::Handle(function.signature_class());
9091 Closure& result = Closure::Handle(); 9688 Closure& result = Closure::Handle();
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
9393 const String& str = String::Handle(pattern()); 9990 const String& str = String::Handle(pattern());
9394 const char* format = "JSRegExp: pattern=%s flags=%s"; 9991 const char* format = "JSRegExp: pattern=%s flags=%s";
9395 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); 9992 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags());
9396 char* chars = reinterpret_cast<char*>( 9993 char* chars = reinterpret_cast<char*>(
9397 Isolate::Current()->current_zone()->Allocate(len + 1)); 9994 Isolate::Current()->current_zone()->Allocate(len + 1));
9398 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); 9995 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags());
9399 return chars; 9996 return chars;
9400 } 9997 }
9401 9998
9402 } // namespace dart 9999 } // namespace dart
OLDNEW
« runtime/include/dart_api.h ('K') | « 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