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

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

Issue 9958046: 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: move test code, minor formatting and consistency tweaks 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
« 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) 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 7495 matching lines...) Expand 10 before | Expand all | Expand 10 after
8907 } 9106 }
8908 return result.raw(); 9107 return result.raw();
8909 } 9108 }
8910 9109
8911 9110
8912 const char* GrowableObjectArray::ToCString() const { 9111 const char* GrowableObjectArray::ToCString() const {
8913 return "GrowableObjectArray"; 9112 return "GrowableObjectArray";
8914 } 9113 }
8915 9114
8916 9115
8917 intptr_t ByteArray::Length() const { 9116 void ByteArray::Copy(void* dst,
8918 // ByteArray is an abstract class.
8919 UNREACHABLE();
8920 return 0;
8921 }
8922
8923
8924 void ByteArray::Copy(uint8_t* dst,
8925 const ByteArray& src, 9117 const ByteArray& src,
8926 intptr_t src_offset, 9118 intptr_t src_offset,
8927 intptr_t length) { 9119 intptr_t length) {
8928 ASSERT(Utils::RangeCheck(src_offset, length, src.Length())); 9120 ASSERT(Utils::RangeCheck(src_offset, length, src.ByteLength()));
8929 { 9121 {
8930 NoGCScope no_gc; 9122 NoGCScope no_gc;
8931 if (length > 0) { 9123 if (length > 0) {
8932 memmove(dst, src.ByteAddr(src_offset), length); 9124 memmove(dst, src.ByteAddr(src_offset), length);
8933 } 9125 }
8934 } 9126 }
8935 } 9127 }
8936 9128
8937 9129
8938 void ByteArray::Copy(const ByteArray& dst, 9130 void ByteArray::Copy(const ByteArray& dst,
8939 intptr_t dst_offset, 9131 intptr_t dst_offset,
8940 const uint8_t* src, 9132 const void* src,
8941 intptr_t length) { 9133 intptr_t length) {
8942 ASSERT(Utils::RangeCheck(dst_offset, length, dst.Length())); 9134 ASSERT(Utils::RangeCheck(dst_offset, length, dst.ByteLength()));
8943 { 9135 {
8944 NoGCScope no_gc; 9136 NoGCScope no_gc;
8945 if (length > 0) { 9137 if (length > 0) {
8946 memmove(dst.ByteAddr(dst_offset), src, length); 9138 memmove(dst.ByteAddr(dst_offset), src, length);
8947 } 9139 }
8948 } 9140 }
8949 } 9141 }
8950 9142
8951 9143
8952 void ByteArray::Copy(const ByteArray& dst, 9144 void ByteArray::Copy(const ByteArray& dst,
8953 intptr_t dst_offset, 9145 intptr_t dst_offset,
8954 const ByteArray& src, 9146 const ByteArray& src,
8955 intptr_t src_offset, 9147 intptr_t src_offset,
8956 intptr_t length) { 9148 intptr_t length) {
8957 ASSERT(Utils::RangeCheck(src_offset, length, src.Length())); 9149 ASSERT(Utils::RangeCheck(src_offset, length, src.ByteLength()));
8958 ASSERT(Utils::RangeCheck(dst_offset, length, dst.Length())); 9150 ASSERT(Utils::RangeCheck(dst_offset, length, dst.ByteLength()));
8959 { 9151 {
8960 NoGCScope no_gc; 9152 NoGCScope no_gc;
8961 if (length > 0) { 9153 if (length > 0) {
8962 memmove(dst.ByteAddr(dst_offset), src.ByteAddr(src_offset), length); 9154 memmove(dst.ByteAddr(dst_offset), src.ByteAddr(src_offset), length);
8963 } 9155 }
8964 } 9156 }
8965 } 9157 }
8966 9158
8967 9159
9160 template<typename T>
9161 static void ExternalByteArrayFinalize(Dart_Handle handle, void* peer) {
9162 delete reinterpret_cast<ExternalByteArrayData<T>*>(peer);
9163 DeleteWeakPersistentHandle(handle);
9164 }
9165
9166
9167 template<typename HandleT, typename RawT, typename ElementT>
9168 RawT* ByteArray::NewExternalImpl(const Class& cls,
9169 ElementT* data,
9170 intptr_t len,
9171 void* peer,
9172 Dart_PeerFinalizer callback,
9173 Heap::Space space) {
9174 HandleT& result = HandleT::Handle();
9175 ExternalByteArrayData<ElementT>* external_data =
9176 new ExternalByteArrayData<ElementT>(data, peer, callback);
9177 {
9178 RawObject* raw = Object::Allocate(cls, HandleT::InstanceSize(), space);
9179 NoGCScope no_gc;
9180 result ^= raw;
9181 result.SetLength(len);
9182 result.SetExternalData(external_data);
9183 }
9184 AddFinalizer(result, external_data, ExternalByteArrayFinalize<ElementT>);
9185 return result.raw();
9186 }
9187
9188
9189 intptr_t ByteArray::ByteLength() const {
9190 // ByteArray is an abstract class.
9191 UNREACHABLE();
9192 return 0;
9193 }
9194
9195
8968 uint8_t* ByteArray::ByteAddr(intptr_t byte_offset) const { 9196 uint8_t* ByteArray::ByteAddr(intptr_t byte_offset) const {
8969 // ByteArray is an abstract class. 9197 // ByteArray is an abstract class.
8970 UNREACHABLE(); 9198 UNREACHABLE();
8971 return NULL; 9199 return NULL;
8972 } 9200 }
8973 9201
8974 9202
8975 const char* ByteArray::ToCString() const { 9203 const char* ByteArray::ToCString() const {
8976 // ByteArray is an abstract class. 9204 // ByteArray is an abstract class.
8977 UNREACHABLE(); 9205 UNREACHABLE();
8978 return "ByteArray"; 9206 return "ByteArray";
8979 } 9207 }
8980 9208
8981 9209
8982 RawInternalByteArray* InternalByteArray::New(intptr_t len, 9210 template<typename HandleT, typename RawT>
8983 Heap::Space space) { 9211 RawT* ByteArray::NewImpl(const Class& cls, intptr_t len, Heap::Space space) {
8984 Isolate* isolate = Isolate::Current(); 9212 HandleT& result = HandleT::Handle();
8985 const Class& internal_byte_array_class =
8986 Class::Handle(isolate->object_store()->internal_byte_array_class());
8987 InternalByteArray& result = InternalByteArray::Handle();
8988 { 9213 {
8989 RawObject* raw = Object::Allocate(internal_byte_array_class, 9214 RawObject* raw = Object::Allocate(cls, HandleT::InstanceSize(len), space);
8990 InternalByteArray::InstanceSize(len),
8991 space);
8992 NoGCScope no_gc; 9215 NoGCScope no_gc;
8993 result ^= raw; 9216 result ^= raw;
8994 result.SetLength(len); 9217 result.SetLength(len);
8995 if (len > 0) { 9218 if (len > 0) {
8996 memset(result.Addr<uint8_t>(0), 0, len); 9219 memset(result.ByteAddr(0), 0, result.ByteLength());
8997 } 9220 }
8998 } 9221 }
8999 return result.raw(); 9222 return result.raw();
9000 } 9223 }
9001 9224
9002 9225
9003 RawInternalByteArray* InternalByteArray::New(const uint8_t* data, 9226 template<typename HandleT, typename RawT, typename ElementT>
9004 intptr_t len, 9227 RawT* ByteArray::NewImpl(const Class& cls,
9005 Heap::Space space) { 9228 const ElementT* data,
9006 InternalByteArray& result = 9229 intptr_t len,
9007 InternalByteArray::Handle(InternalByteArray::New(len, space)); 9230 Heap::Space space) {
9231 HandleT& result = HandleT::Handle();
9008 { 9232 {
9233 RawObject* raw = Object::Allocate(cls, HandleT::InstanceSize(len), space);
9009 NoGCScope no_gc; 9234 NoGCScope no_gc;
9235 result ^= raw;
9236 result.SetLength(len);
9010 if (len > 0) { 9237 if (len > 0) {
9011 memmove(result.Addr<uint8_t>(0), data, len); 9238 memmove(result.ByteAddr(0), data, result.ByteLength());
9012 } 9239 }
9013 } 9240 }
9014 return result.raw(); 9241 return result.raw();
9015 } 9242 }
9016 9243
9017 9244
9018 const char* InternalByteArray::ToCString() const { 9245 RawInt8Array* Int8Array::New(intptr_t len, Heap::Space space) {
9019 return "_InternalByteArray"; 9246 Isolate* isolate = Isolate::Current();
9020 } 9247 const Class& cls =
9021 9248 Class::Handle(isolate->object_store()->int8_array_class());
9022 9249 return NewImpl<Int8Array, RawInt8Array>(cls, len, space);
9023 void ExternalByteArray::Finalize(Dart_Handle handle, void* peer) { 9250 }
9024 delete reinterpret_cast<ExternalByteArrayData*>(peer); 9251
9025 DeleteWeakPersistentHandle(handle); 9252
9026 } 9253 RawInt8Array* Int8Array::New(const int8_t* data,
9027 9254 intptr_t len,
9028 9255 Heap::Space space) {
9029 RawExternalByteArray* ExternalByteArray::New(uint8_t* data, 9256 Isolate* isolate = Isolate::Current();
9257 const Class& cls =
9258 Class::Handle(isolate->object_store()->int8_array_class());
9259 return NewImpl<Int8Array, RawInt8Array>(cls, data, len, space);
9260 }
9261
9262
9263 const char* Int8Array::ToCString() const {
9264 return "_Int8Array";
9265 }
9266
9267
9268 RawUint8Array* Uint8Array::New(intptr_t len, Heap::Space space) {
9269 Isolate* isolate = Isolate::Current();
9270 const Class& cls =
9271 Class::Handle(isolate->object_store()->uint8_array_class());
9272 return NewImpl<Uint8Array, RawUint8Array>(cls, len, space);
9273 }
9274
9275
9276 RawUint8Array* Uint8Array::New(const uint8_t* data,
9277 intptr_t len,
9278 Heap::Space space) {
9279 Isolate* isolate = Isolate::Current();
9280 const Class& cls =
9281 Class::Handle(isolate->object_store()->uint8_array_class());
9282 return NewImpl<Uint8Array, RawUint8Array>(cls, data, len, space);
9283 }
9284
9285
9286 const char* Uint8Array::ToCString() const {
9287 return "_Uint8Array";
9288 }
9289
9290
9291 RawInt16Array* Int16Array::New(intptr_t len, Heap::Space space) {
9292 Isolate* isolate = Isolate::Current();
9293 const Class& cls =
9294 Class::Handle(isolate->object_store()->int16_array_class());
9295 return NewImpl<Int16Array, RawInt16Array>(cls, len, space);
9296 }
9297
9298
9299 RawInt16Array* Int16Array::New(const int16_t* data,
9300 intptr_t len,
9301 Heap::Space space) {
9302 Isolate* isolate = Isolate::Current();
9303 const Class& cls =
9304 Class::Handle(isolate->object_store()->int16_array_class());
9305 return NewImpl<Int16Array, RawInt16Array>(cls, data, len, space);
9306 }
9307
9308
9309 const char* Int16Array::ToCString() const {
9310 return "_Int16Array";
9311 }
9312
9313
9314 RawUint16Array* Uint16Array::New(intptr_t len, Heap::Space space) {
9315 Isolate* isolate = Isolate::Current();
9316 const Class& cls =
9317 Class::Handle(isolate->object_store()->uint16_array_class());
9318 return NewImpl<Uint16Array, RawUint16Array>(cls, len, space);
9319 }
9320
9321
9322 RawUint16Array* Uint16Array::New(const uint16_t* data,
9323 intptr_t len,
9324 Heap::Space space) {
9325 Isolate* isolate = Isolate::Current();
9326 const Class& cls =
9327 Class::Handle(isolate->object_store()->uint16_array_class());
9328 return NewImpl<Uint16Array, RawUint16Array>(cls, data, len, space);
9329 }
9330
9331
9332 const char* Uint16Array::ToCString() const {
9333 return "_Uint16Array";
9334 }
9335
9336
9337 RawInt32Array* Int32Array::New(intptr_t len, Heap::Space space) {
9338 Isolate* isolate = Isolate::Current();
9339 const Class& cls =
9340 Class::Handle(isolate->object_store()->int32_array_class());
9341 return NewImpl<Int32Array, RawInt32Array>(cls, len, space);
9342 }
9343
9344
9345 RawInt32Array* Int32Array::New(const int32_t* data,
9346 intptr_t len,
9347 Heap::Space space) {
9348 Isolate* isolate = Isolate::Current();
9349 const Class& cls =
9350 Class::Handle(isolate->object_store()->int32_array_class());
9351 return NewImpl<Int32Array, RawInt32Array>(cls, data, len, space);
9352 }
9353
9354
9355 const char* Int32Array::ToCString() const {
9356 return "_Int32Array";
9357 }
9358
9359
9360 RawUint32Array* Uint32Array::New(intptr_t len, Heap::Space space) {
9361 Isolate* isolate = Isolate::Current();
9362 const Class& cls =
9363 Class::Handle(isolate->object_store()->uint32_array_class());
9364 return NewImpl<Uint32Array, RawUint32Array>(cls, len, space);
9365 }
9366
9367
9368 RawUint32Array* Uint32Array::New(const uint32_t* data,
9369 intptr_t len,
9370 Heap::Space space) {
9371 Isolate* isolate = Isolate::Current();
9372 const Class& cls =
9373 Class::Handle(isolate->object_store()->uint32_array_class());
9374 return NewImpl<Uint32Array, RawUint32Array>(cls, data, len, space);
9375 }
9376
9377
9378 const char* Uint32Array::ToCString() const {
9379 return "_Uint32Array";
9380 }
9381
9382
9383 RawInt64Array* Int64Array::New(intptr_t len, Heap::Space space) {
9384 Isolate* isolate = Isolate::Current();
9385 const Class& cls =
9386 Class::Handle(isolate->object_store()->int64_array_class());
9387 return NewImpl<Int64Array, RawInt64Array>(cls, len, space);
9388 }
9389
9390
9391 RawInt64Array* Int64Array::New(const int64_t* data,
9392 intptr_t len,
9393 Heap::Space space) {
9394 Isolate* isolate = Isolate::Current();
9395 const Class& cls =
9396 Class::Handle(isolate->object_store()->int64_array_class());
9397 return NewImpl<Int64Array, RawInt64Array>(cls, data, len, space);
9398 }
9399
9400
9401 const char* Int64Array::ToCString() const {
9402 return "_Int64Array";
9403 }
9404
9405
9406 RawUint64Array* Uint64Array::New(intptr_t len, Heap::Space space) {
9407 Isolate* isolate = Isolate::Current();
9408 const Class& cls =
9409 Class::Handle(isolate->object_store()->uint64_array_class());
9410 return NewImpl<Uint64Array, RawUint64Array>(cls, len, space);
9411 }
9412
9413
9414 RawUint64Array* Uint64Array::New(const uint64_t* data,
9415 intptr_t len,
9416 Heap::Space space) {
9417 Isolate* isolate = Isolate::Current();
9418 const Class& cls =
9419 Class::Handle(isolate->object_store()->uint64_array_class());
9420 return NewImpl<Uint64Array, RawUint64Array>(cls, data, len, space);
9421 }
9422
9423
9424 const char* Uint64Array::ToCString() const {
9425 return "_Uint64Array";
9426 }
9427
9428
9429 RawFloat32Array* Float32Array::New(intptr_t len, Heap::Space space) {
9430 Isolate* isolate = Isolate::Current();
9431 const Class& cls =
9432 Class::Handle(isolate->object_store()->float32_array_class());
9433 return NewImpl<Float32Array, RawFloat32Array>(cls, len, space);
9434 }
9435
9436
9437 RawFloat32Array* Float32Array::New(const float* data,
9438 intptr_t len,
9439 Heap::Space space) {
9440 Isolate* isolate = Isolate::Current();
9441 const Class& cls =
9442 Class::Handle(isolate->object_store()->float32_array_class());
9443 return NewImpl<Float32Array, RawFloat32Array>(cls, data, len, space);
9444 }
9445
9446
9447 const char* Float32Array::ToCString() const {
9448 return "_Float32Array";
9449 }
9450
9451
9452 RawFloat64Array* Float64Array::New(intptr_t len, Heap::Space space) {
9453 Isolate* isolate = Isolate::Current();
9454 const Class& cls =
9455 Class::Handle(isolate->object_store()->float64_array_class());
9456 return NewImpl<Float64Array, RawFloat64Array>(cls, len, space);
9457 }
9458
9459
9460 RawFloat64Array* Float64Array::New(const double* data,
9461 intptr_t len,
9462 Heap::Space space) {
9463 Isolate* isolate = Isolate::Current();
9464 const Class& cls =
9465 Class::Handle(isolate->object_store()->float64_array_class());
9466 return NewImpl<Float64Array, RawFloat64Array>(cls, data, len, space);
9467 }
9468
9469
9470 const char* Float64Array::ToCString() const {
9471 return "_Float64Array";
9472 }
9473
9474
9475 RawExternalInt8Array* ExternalInt8Array::New(int8_t* data,
9030 intptr_t len, 9476 intptr_t len,
9031 void* peer, 9477 void* peer,
9032 Dart_PeerFinalizer callback, 9478 Dart_PeerFinalizer callback,
9033 Heap::Space space) { 9479 Heap::Space space) {
9034 Isolate* isolate = Isolate::Current(); 9480 Isolate* isolate = Isolate::Current();
9035 const Class& external_byte_array_class = 9481 const Class& cls =
9036 Class::Handle(isolate->object_store()->external_byte_array_class()); 9482 Class::Handle(isolate->object_store()->external_int8_array_class());
9037 ExternalByteArray& result = ExternalByteArray::Handle(); 9483 return NewExternalImpl<ExternalInt8Array, RawExternalInt8Array>(
9038 ExternalByteArrayData* external_data = 9484 cls, data, len, peer, callback, space);
9039 new ExternalByteArrayData(data, peer, callback); 9485 }
9040 { 9486
9041 RawObject* raw = Object::Allocate(external_byte_array_class, 9487
9042 ExternalByteArray::InstanceSize(), 9488 const char* ExternalInt8Array::ToCString() const {
9043 space); 9489 return "_ExternalInt8Array";
9044 NoGCScope no_gc; 9490 }
9045 result ^= raw; 9491
9046 result.SetLength(len); 9492
9047 result.SetExternalData(external_data); 9493 RawExternalUint8Array* ExternalUint8Array::New(uint8_t* data,
9048 } 9494 intptr_t len,
9049 AddFinalizer(result, external_data, ExternalByteArray::Finalize); 9495 void* peer,
9050 return result.raw(); 9496 Dart_PeerFinalizer callback,
9051 } 9497 Heap::Space space) {
9052 9498 Isolate* isolate = Isolate::Current();
9053 9499 const Class& cls =
9054 const char* ExternalByteArray::ToCString() const { 9500 Class::Handle(isolate->object_store()->external_uint8_array_class());
9055 return "_ExternalByteArray"; 9501 return NewExternalImpl<ExternalUint8Array, RawExternalUint8Array>(
9056 } 9502 cls, data, len, peer, callback, space);
9503 }
9504
9505
9506 const char* ExternalUint8Array::ToCString() const {
9507 return "_ExternalUint8Array";
9508 }
9509
9510
9511 RawExternalInt16Array* ExternalInt16Array::New(int16_t* data,
9512 intptr_t len,
9513 void* peer,
9514 Dart_PeerFinalizer callback,
9515 Heap::Space space) {
9516 Isolate* isolate = Isolate::Current();
9517 const Class& cls =
9518 Class::Handle(isolate->object_store()->external_int16_array_class());
9519 return NewExternalImpl<ExternalInt16Array, RawExternalInt16Array>(
9520 cls, data, len, peer, callback, space);
9521 }
9522
9523
9524 const char* ExternalInt16Array::ToCString() const {
9525 return "_ExternalInt16Array";
9526 }
9527
9528
9529 RawExternalUint16Array* ExternalUint16Array::New(uint16_t* data,
9530 intptr_t len,
9531 void* peer,
9532 Dart_PeerFinalizer callback,
9533 Heap::Space space) {
9534 Isolate* isolate = Isolate::Current();
9535 const Class& cls =
9536 Class::Handle(isolate->object_store()->external_uint16_array_class());
9537 return NewExternalImpl<ExternalUint16Array, RawExternalUint16Array>(
9538 cls, data, len, peer, callback, space);
9539 }
9540
9541
9542 const char* ExternalUint16Array::ToCString() const {
9543 return "_ExternalUint16Array";
9544 }
9545
9546
9547 RawExternalInt32Array* ExternalInt32Array::New(int32_t* data,
9548 intptr_t len,
9549 void* peer,
9550 Dart_PeerFinalizer callback,
9551 Heap::Space space) {
9552 Isolate* isolate = Isolate::Current();
9553 const Class& cls =
9554 Class::Handle(isolate->object_store()->external_int32_array_class());
9555 return NewExternalImpl<ExternalInt32Array, RawExternalInt32Array>(
9556 cls, data, len, peer, callback, space);
9557 }
9558
9559
9560 const char* ExternalInt32Array::ToCString() const {
9561 return "_ExternalInt32Array";
9562 }
9563
9564
9565 RawExternalUint32Array* ExternalUint32Array::New(uint32_t* data,
9566 intptr_t len,
9567 void* peer,
9568 Dart_PeerFinalizer callback,
9569 Heap::Space space) {
9570 Isolate* isolate = Isolate::Current();
9571 const Class& cls =
9572 Class::Handle(isolate->object_store()->external_uint32_array_class());
9573 return NewExternalImpl<ExternalUint32Array, RawExternalUint32Array>(
9574 cls, data, len, peer, callback, space);
9575 }
9576
9577
9578 const char* ExternalUint32Array::ToCString() const {
9579 return "_ExternalUint32Array";
9580 }
9581
9582
9583 RawExternalInt64Array* ExternalInt64Array::New(int64_t* data,
9584 intptr_t len,
9585 void* peer,
9586 Dart_PeerFinalizer callback,
9587 Heap::Space space) {
9588 Isolate* isolate = Isolate::Current();
9589 const Class& cls =
9590 Class::Handle(isolate->object_store()->external_int64_array_class());
9591 return NewExternalImpl<ExternalInt64Array, RawExternalInt64Array>(
9592 cls, data, len, peer, callback, space);
9593 }
9594
9595
9596 const char* ExternalInt64Array::ToCString() const {
9597 return "_ExternalInt64Array";
9598 }
9599
9600
9601 RawExternalUint64Array* ExternalUint64Array::New(uint64_t* data,
9602 intptr_t len,
9603 void* peer,
9604 Dart_PeerFinalizer callback,
9605 Heap::Space space) {
9606 Isolate* isolate = Isolate::Current();
9607 const Class& cls =
9608 Class::Handle(isolate->object_store()->external_uint64_array_class());
9609 return NewExternalImpl<ExternalUint64Array, RawExternalUint64Array>(
9610 cls, data, len, peer, callback, space);
9611 }
9612
9613
9614 const char* ExternalUint64Array::ToCString() const {
9615 return "_ExternalUint64Array";
9616 }
9617
9618
9619 RawExternalFloat32Array* ExternalFloat32Array::New(float* data,
9620 intptr_t len,
9621 void* peer,
9622 Dart_PeerFinalizer callback,
9623 Heap::Space space) {
9624 Isolate* isolate = Isolate::Current();
9625 const Class& cls =
9626 Class::Handle(isolate->object_store()->external_float32_array_class());
9627 return NewExternalImpl<ExternalFloat32Array, RawExternalFloat32Array>(
9628 cls, data, len, peer, callback, space);
9629 }
9630
9631
9632 const char* ExternalFloat32Array::ToCString() const {
9633 return "_ExternalFloat32Array";
9634 }
9635
9636
9637 RawExternalFloat64Array* ExternalFloat64Array::New(double* data,
9638 intptr_t len,
9639 void* peer,
9640 Dart_PeerFinalizer callback,
9641 Heap::Space space) {
9642 Isolate* isolate = Isolate::Current();
9643 const Class& cls =
9644 Class::Handle(isolate->object_store()->external_float64_array_class());
9645 return NewExternalImpl<ExternalFloat64Array, RawExternalFloat64Array>(
9646 cls, data, len, peer, callback, space);
9647 }
9648
9649
9650 const char* ExternalFloat64Array::ToCString() const {
9651 return "_ExternalFloat64Array";
9652 }
9653
9057 9654
9058 9655
9059 RawClosure* Closure::New(const Function& function, 9656 RawClosure* Closure::New(const Function& function,
9060 const Context& context, 9657 const Context& context,
9061 Heap::Space space) { 9658 Heap::Space space) {
9062 Isolate* isolate = Isolate::Current(); 9659 Isolate* isolate = Isolate::Current();
9063 ASSERT(context.isolate() == isolate); 9660 ASSERT(context.isolate() == isolate);
9064 9661
9065 const Class& cls = Class::Handle(function.signature_class()); 9662 const Class& cls = Class::Handle(function.signature_class());
9066 Closure& result = Closure::Handle(); 9663 Closure& result = Closure::Handle();
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
9368 const String& str = String::Handle(pattern()); 9965 const String& str = String::Handle(pattern());
9369 const char* format = "JSRegExp: pattern=%s flags=%s"; 9966 const char* format = "JSRegExp: pattern=%s flags=%s";
9370 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); 9967 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags());
9371 char* chars = reinterpret_cast<char*>( 9968 char* chars = reinterpret_cast<char*>(
9372 Isolate::Current()->current_zone()->Allocate(len + 1)); 9969 Isolate::Current()->current_zone()->Allocate(len + 1));
9373 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); 9970 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags());
9374 return chars; 9971 return chars;
9375 } 9972 }
9376 9973
9377 } // namespace dart 9974 } // 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