| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "vm/object.h" | 5 #include "vm/object.h" |
| 6 | 6 |
| 7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
| 8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
| 9 #include "vm/assembler.h" | 9 #include "vm/assembler.h" |
| 10 #include "vm/bigint_operations.h" | 10 #include "vm/bigint_operations.h" |
| (...skipping 3440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3451 if (!type.IsInstantiated()) { | 3451 if (!type.IsInstantiated()) { |
| 3452 type = type.InstantiateFrom(instantiator_type_arguments); | 3452 type = type.InstantiateFrom(instantiator_type_arguments); |
| 3453 } | 3453 } |
| 3454 instantiated_array.SetTypeAt(i, type); | 3454 instantiated_array.SetTypeAt(i, type); |
| 3455 } | 3455 } |
| 3456 return instantiated_array.raw(); | 3456 return instantiated_array.raw(); |
| 3457 } | 3457 } |
| 3458 | 3458 |
| 3459 | 3459 |
| 3460 RawTypeArguments* TypeArguments::New(intptr_t len, Heap::Space space) { | 3460 RawTypeArguments* TypeArguments::New(intptr_t len, Heap::Space space) { |
| 3461 if ((len < 0) || (len > kMaxTypes)) { | 3461 if (len < 0 || len > kMaxElements) { |
| 3462 // TODO(iposva): Should we throw an illegal parameter exception? | 3462 // This should be caught before we reach here. |
| 3463 UNIMPLEMENTED(); | 3463 FATAL1("Fatal error in TypeArguments::New: invalid len %ld\n", len); |
| 3464 return null(); | |
| 3465 } | 3464 } |
| 3466 | |
| 3467 TypeArguments& result = TypeArguments::Handle(); | 3465 TypeArguments& result = TypeArguments::Handle(); |
| 3468 { | 3466 { |
| 3469 RawObject* raw = Object::Allocate(TypeArguments::kInstanceKind, | 3467 RawObject* raw = Object::Allocate(TypeArguments::kInstanceKind, |
| 3470 TypeArguments::InstanceSize(len), | 3468 TypeArguments::InstanceSize(len), |
| 3471 space); | 3469 space); |
| 3472 NoGCScope no_gc; | 3470 NoGCScope no_gc; |
| 3473 result ^= raw; | 3471 result ^= raw; |
| 3474 // Length must be set before we start storing into the array. | 3472 // Length must be set before we start storing into the array. |
| 3475 result.SetLength(len); | 3473 result.SetLength(len); |
| 3476 } | 3474 } |
| (...skipping 1235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4712 iterator.Advance(); | 4710 iterator.Advance(); |
| 4713 kind = iterator.CurrentTokenKind(); | 4711 kind = iterator.CurrentTokenKind(); |
| 4714 index += 1; | 4712 index += 1; |
| 4715 } | 4713 } |
| 4716 return iterator.CurrentPosition(); | 4714 return iterator.CurrentPosition(); |
| 4717 } | 4715 } |
| 4718 | 4716 |
| 4719 | 4717 |
| 4720 RawTokenStream* TokenStream::New(intptr_t len) { | 4718 RawTokenStream* TokenStream::New(intptr_t len) { |
| 4721 ASSERT(Object::token_stream_class() != Class::null()); | 4719 ASSERT(Object::token_stream_class() != Class::null()); |
| 4720 if (len < 0 || len > kMaxElements) { |
| 4721 // This should be caught before we reach here. |
| 4722 FATAL1("Fatal error in TokenStream::New: invalid len %ld\n", len); |
| 4723 } |
| 4722 TokenStream& result = TokenStream::Handle(); | 4724 TokenStream& result = TokenStream::Handle(); |
| 4723 { | 4725 { |
| 4724 RawObject* raw = Object::Allocate(TokenStream::kInstanceKind, | 4726 RawObject* raw = Object::Allocate(TokenStream::kInstanceKind, |
| 4725 TokenStream::InstanceSize(len), | 4727 TokenStream::InstanceSize(len), |
| 4726 Heap::kOld); | 4728 Heap::kOld); |
| 4727 NoGCScope no_gc; | 4729 NoGCScope no_gc; |
| 4728 result ^= raw; | 4730 result ^= raw; |
| 4729 result.SetLength(len); | 4731 result.SetLength(len); |
| 4730 } | 4732 } |
| 4731 return result.raw(); | 4733 return result.raw(); |
| (...skipping 1734 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6466 return error.raw(); | 6468 return error.raw(); |
| 6467 } | 6469 } |
| 6468 } | 6470 } |
| 6469 } | 6471 } |
| 6470 return error.raw(); | 6472 return error.raw(); |
| 6471 } | 6473 } |
| 6472 | 6474 |
| 6473 | 6475 |
| 6474 RawInstructions* Instructions::New(intptr_t size) { | 6476 RawInstructions* Instructions::New(intptr_t size) { |
| 6475 ASSERT(Object::instructions_class() != Class::null()); | 6477 ASSERT(Object::instructions_class() != Class::null()); |
| 6478 if (size < 0 || size > kMaxElements) { |
| 6479 // This should be caught before we reach here. |
| 6480 FATAL1("Fatal error in Instructions::New: invalid size %ld\n", size); |
| 6481 } |
| 6476 Instructions& result = Instructions::Handle(); | 6482 Instructions& result = Instructions::Handle(); |
| 6477 { | 6483 { |
| 6478 uword aligned_size = Instructions::InstanceSize(size); | 6484 uword aligned_size = Instructions::InstanceSize(size); |
| 6479 RawObject* raw = Object::Allocate(Instructions::kInstanceKind, | 6485 RawObject* raw = Object::Allocate(Instructions::kInstanceKind, |
| 6480 aligned_size, | 6486 aligned_size, |
| 6481 Heap::kCode); | 6487 Heap::kCode); |
| 6482 NoGCScope no_gc; | 6488 NoGCScope no_gc; |
| 6483 // TODO(iposva): Remove premarking once old and code spaces are merged. | 6489 // TODO(iposva): Remove premarking once old and code spaces are merged. |
| 6484 raw->SetMarkBit(); | 6490 raw->SetMarkBit(); |
| 6485 result ^= raw; | 6491 result ^= raw; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6551 } | 6557 } |
| 6552 | 6558 |
| 6553 | 6559 |
| 6554 void PcDescriptors::SetTryIndex(intptr_t index, intptr_t value) const { | 6560 void PcDescriptors::SetTryIndex(intptr_t index, intptr_t value) const { |
| 6555 *(EntryAddr(index, kTryIndexEntry)) = value; | 6561 *(EntryAddr(index, kTryIndexEntry)) = value; |
| 6556 } | 6562 } |
| 6557 | 6563 |
| 6558 | 6564 |
| 6559 RawPcDescriptors* PcDescriptors::New(intptr_t num_descriptors) { | 6565 RawPcDescriptors* PcDescriptors::New(intptr_t num_descriptors) { |
| 6560 ASSERT(Object::pc_descriptors_class() != Class::null()); | 6566 ASSERT(Object::pc_descriptors_class() != Class::null()); |
| 6567 if (num_descriptors < 0 || num_descriptors > kMaxElements) { |
| 6568 // This should be caught before we reach here. |
| 6569 FATAL1("Fatal error in PcDescriptors::New: invalid num_descriptors %ld\n", |
| 6570 num_descriptors); |
| 6571 } |
| 6561 PcDescriptors& result = PcDescriptors::Handle(); | 6572 PcDescriptors& result = PcDescriptors::Handle(); |
| 6562 { | 6573 { |
| 6563 uword size = PcDescriptors::InstanceSize(num_descriptors); | 6574 uword size = PcDescriptors::InstanceSize(num_descriptors); |
| 6564 RawObject* raw = Object::Allocate(PcDescriptors::kInstanceKind, | 6575 RawObject* raw = Object::Allocate(PcDescriptors::kInstanceKind, |
| 6565 size, | 6576 size, |
| 6566 Heap::kOld); | 6577 Heap::kOld); |
| 6567 NoGCScope no_gc; | 6578 NoGCScope no_gc; |
| 6568 result ^= raw; | 6579 result ^= raw; |
| 6569 result.SetLength(num_descriptors); | 6580 result.SetLength(num_descriptors); |
| 6570 } | 6581 } |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6677 *byte_addr &= ~byte_mask; | 6688 *byte_addr &= ~byte_mask; |
| 6678 } | 6689 } |
| 6679 } | 6690 } |
| 6680 | 6691 |
| 6681 | 6692 |
| 6682 RawStackmap* Stackmap::New(uword pc_offset, BitmapBuilder* bmap) { | 6693 RawStackmap* Stackmap::New(uword pc_offset, BitmapBuilder* bmap) { |
| 6683 ASSERT(Object::stackmap_class() != Class::null()); | 6694 ASSERT(Object::stackmap_class() != Class::null()); |
| 6684 ASSERT(bmap != NULL); | 6695 ASSERT(bmap != NULL); |
| 6685 Stackmap& result = Stackmap::Handle(); | 6696 Stackmap& result = Stackmap::Handle(); |
| 6686 intptr_t size = bmap->SizeInBytes(); | 6697 intptr_t size = bmap->SizeInBytes(); |
| 6698 if (size < 0 || size > kMaxElements) { |
| 6699 // This should be caught before we reach here. |
| 6700 FATAL1("Fatal error in PcDescriptors::New: invalid size %ld\n", size); |
| 6701 } |
| 6687 { | 6702 { |
| 6688 // Stackmap data objects are associated with a code object, allocate them | 6703 // Stackmap data objects are associated with a code object, allocate them |
| 6689 // in old generation. | 6704 // in old generation. |
| 6690 RawObject* raw = Object::Allocate(Stackmap::kInstanceKind, | 6705 RawObject* raw = Object::Allocate(Stackmap::kInstanceKind, |
| 6691 Stackmap::InstanceSize(size), | 6706 Stackmap::InstanceSize(size), |
| 6692 Heap::kOld); | 6707 Heap::kOld); |
| 6693 NoGCScope no_gc; | 6708 NoGCScope no_gc; |
| 6694 result ^= raw; | 6709 result ^= raw; |
| 6695 result.set_bitmap_size_in_bytes(size); | 6710 result.set_bitmap_size_in_bytes(size); |
| 6696 } | 6711 } |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6763 | 6778 |
| 6764 | 6779 |
| 6765 const char* LocalVarDescriptors::ToCString() const { | 6780 const char* LocalVarDescriptors::ToCString() const { |
| 6766 UNIMPLEMENTED(); | 6781 UNIMPLEMENTED(); |
| 6767 return "LocalVarDescriptors"; | 6782 return "LocalVarDescriptors"; |
| 6768 } | 6783 } |
| 6769 | 6784 |
| 6770 | 6785 |
| 6771 RawLocalVarDescriptors* LocalVarDescriptors::New(intptr_t num_variables) { | 6786 RawLocalVarDescriptors* LocalVarDescriptors::New(intptr_t num_variables) { |
| 6772 ASSERT(Object::var_descriptors_class() != Class::null()); | 6787 ASSERT(Object::var_descriptors_class() != Class::null()); |
| 6788 if (num_variables < 0 || num_variables > kMaxElements) { |
| 6789 // This should be caught before we reach here. |
| 6790 FATAL1("Fatal error in LocalVarDescriptors::New: " |
| 6791 "invalid num_variables %ld\n", num_variables); |
| 6792 } |
| 6773 LocalVarDescriptors& result = LocalVarDescriptors::Handle(); | 6793 LocalVarDescriptors& result = LocalVarDescriptors::Handle(); |
| 6774 { | 6794 { |
| 6775 uword size = LocalVarDescriptors::InstanceSize(num_variables); | 6795 uword size = LocalVarDescriptors::InstanceSize(num_variables); |
| 6776 RawObject* raw = Object::Allocate(LocalVarDescriptors::kInstanceKind, | 6796 RawObject* raw = Object::Allocate(LocalVarDescriptors::kInstanceKind, |
| 6777 size, | 6797 size, |
| 6778 Heap::kOld); | 6798 Heap::kOld); |
| 6779 NoGCScope no_gc; | 6799 NoGCScope no_gc; |
| 6780 result ^= raw; | 6800 result ^= raw; |
| 6781 result.raw_ptr()->length_ = num_variables; | 6801 result.raw_ptr()->length_ = num_variables; |
| 6782 } | 6802 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6819 | 6839 |
| 6820 | 6840 |
| 6821 void ExceptionHandlers::SetHandlerPC(intptr_t index, | 6841 void ExceptionHandlers::SetHandlerPC(intptr_t index, |
| 6822 intptr_t value) const { | 6842 intptr_t value) const { |
| 6823 *(EntryAddr(index, kHandlerPcEntry)) = value; | 6843 *(EntryAddr(index, kHandlerPcEntry)) = value; |
| 6824 } | 6844 } |
| 6825 | 6845 |
| 6826 | 6846 |
| 6827 RawExceptionHandlers* ExceptionHandlers::New(intptr_t num_handlers) { | 6847 RawExceptionHandlers* ExceptionHandlers::New(intptr_t num_handlers) { |
| 6828 ASSERT(Object::exception_handlers_class() != Class::null()); | 6848 ASSERT(Object::exception_handlers_class() != Class::null()); |
| 6849 if (num_handlers < 0 || num_handlers > kMaxElements) { |
| 6850 // This should be caught before we reach here. |
| 6851 FATAL1("Fatal error in ExceptionHandlers::New: invalid num_handlers %ld\n", |
| 6852 num_handlers); |
| 6853 } |
| 6829 ExceptionHandlers& result = ExceptionHandlers::Handle(); | 6854 ExceptionHandlers& result = ExceptionHandlers::Handle(); |
| 6830 { | 6855 { |
| 6831 uword size = ExceptionHandlers::InstanceSize(num_handlers); | 6856 uword size = ExceptionHandlers::InstanceSize(num_handlers); |
| 6832 RawObject* raw = Object::Allocate(ExceptionHandlers::kInstanceKind, | 6857 RawObject* raw = Object::Allocate(ExceptionHandlers::kInstanceKind, |
| 6833 size, | 6858 size, |
| 6834 Heap::kOld); | 6859 Heap::kOld); |
| 6835 NoGCScope no_gc; | 6860 NoGCScope no_gc; |
| 6836 result ^= raw; | 6861 result ^= raw; |
| 6837 result.SetLength(num_handlers); | 6862 result.SetLength(num_handlers); |
| 6838 } | 6863 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 6861 "%ld => 0x%x\n", | 6886 "%ld => 0x%x\n", |
| 6862 TryIndex(i), | 6887 TryIndex(i), |
| 6863 HandlerPC(i)); | 6888 HandlerPC(i)); |
| 6864 } | 6889 } |
| 6865 return buffer; | 6890 return buffer; |
| 6866 } | 6891 } |
| 6867 | 6892 |
| 6868 | 6893 |
| 6869 Code::Comments& Code::Comments::New(intptr_t count) { | 6894 Code::Comments& Code::Comments::New(intptr_t count) { |
| 6870 Comments* comments; | 6895 Comments* comments; |
| 6896 if (count < 0 || count > (kIntptrMax / kNumberOfEntries)) { |
| 6897 // This should be caught before we reach here. |
| 6898 FATAL1("Fatal error in Code::Comments::New: invalid count %ld\n", count); |
| 6899 } |
| 6871 if (count == 0) { | 6900 if (count == 0) { |
| 6872 comments = new Comments(Array::Empty()); | 6901 comments = new Comments(Array::Empty()); |
| 6873 } else { | 6902 } else { |
| 6874 comments = new Comments(Array::New(count * kNumberOfEntries)); | 6903 comments = new Comments(Array::New(count * kNumberOfEntries)); |
| 6875 } | 6904 } |
| 6876 return *comments; | 6905 return *comments; |
| 6877 } | 6906 } |
| 6878 | 6907 |
| 6879 | 6908 |
| 6880 intptr_t Code::Comments::Length() const { | 6909 intptr_t Code::Comments::Length() const { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6922 Comments* comments = new Code::Comments(raw_ptr()->comments_); | 6951 Comments* comments = new Code::Comments(raw_ptr()->comments_); |
| 6923 return *comments; | 6952 return *comments; |
| 6924 } | 6953 } |
| 6925 | 6954 |
| 6926 | 6955 |
| 6927 void Code::set_comments(const Code::Comments& comments) const { | 6956 void Code::set_comments(const Code::Comments& comments) const { |
| 6928 StorePointer(&raw_ptr()->comments_, comments.comments_.raw()); | 6957 StorePointer(&raw_ptr()->comments_, comments.comments_.raw()); |
| 6929 } | 6958 } |
| 6930 | 6959 |
| 6931 | 6960 |
| 6932 RawCode* Code::New(int pointer_offsets_length) { | 6961 RawCode* Code::New(intptr_t pointer_offsets_length) { |
| 6962 if (pointer_offsets_length < 0 || pointer_offsets_length > kMaxElements) { |
| 6963 // This should be caught before we reach here. |
| 6964 FATAL1("Fatal error in Code::New: invalid pointer_offsets_length %ld\n", |
| 6965 pointer_offsets_length); |
| 6966 } |
| 6933 ASSERT(Object::code_class() != Class::null()); | 6967 ASSERT(Object::code_class() != Class::null()); |
| 6934 Code& result = Code::Handle(); | 6968 Code& result = Code::Handle(); |
| 6935 { | 6969 { |
| 6936 uword size = Code::InstanceSize(pointer_offsets_length); | 6970 uword size = Code::InstanceSize(pointer_offsets_length); |
| 6937 RawObject* raw = Object::Allocate(Code::kInstanceKind, size, Heap::kOld); | 6971 RawObject* raw = Object::Allocate(Code::kInstanceKind, size, Heap::kOld); |
| 6938 NoGCScope no_gc; | 6972 NoGCScope no_gc; |
| 6939 result ^= raw; | 6973 result ^= raw; |
| 6940 result.set_pointer_offsets_length(pointer_offsets_length); | 6974 result.set_pointer_offsets_length(pointer_offsets_length); |
| 6941 result.set_is_optimized(false); | 6975 result.set_is_optimized(false); |
| 6942 result.set_comments(Comments::New(0)); | 6976 result.set_comments(Comments::New(0)); |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7160 // If the code has stackmaps, it must have them for all safepoints. | 7194 // If the code has stackmaps, it must have them for all safepoints. |
| 7161 UNREACHABLE(); | 7195 UNREACHABLE(); |
| 7162 return Stackmap::null(); | 7196 return Stackmap::null(); |
| 7163 } | 7197 } |
| 7164 | 7198 |
| 7165 | 7199 |
| 7166 RawContext* Context::New(intptr_t num_variables, Heap::Space space) { | 7200 RawContext* Context::New(intptr_t num_variables, Heap::Space space) { |
| 7167 ASSERT(num_variables >= 0); | 7201 ASSERT(num_variables >= 0); |
| 7168 ASSERT(Object::context_class() != Class::null()); | 7202 ASSERT(Object::context_class() != Class::null()); |
| 7169 | 7203 |
| 7204 if (num_variables < 0 || num_variables > kMaxElements) { |
| 7205 // This should be caught before we reach here. |
| 7206 FATAL1("Fatal error in Context::New: invalid num_variables %ld\n", |
| 7207 num_variables); |
| 7208 } |
| 7170 Context& result = Context::Handle(); | 7209 Context& result = Context::Handle(); |
| 7171 { | 7210 { |
| 7172 RawObject* raw = Object::Allocate(Context::kInstanceKind, | 7211 RawObject* raw = Object::Allocate(Context::kInstanceKind, |
| 7173 Context::InstanceSize(num_variables), | 7212 Context::InstanceSize(num_variables), |
| 7174 space); | 7213 space); |
| 7175 NoGCScope no_gc; | 7214 NoGCScope no_gc; |
| 7176 result ^= raw; | 7215 result ^= raw; |
| 7177 result.set_num_variables(num_variables); | 7216 result.set_num_variables(num_variables); |
| 7178 } | 7217 } |
| 7179 result.set_isolate(Isolate::Current()); | 7218 result.set_isolate(Isolate::Current()); |
| 7180 return result.raw(); | 7219 return result.raw(); |
| 7181 } | 7220 } |
| 7182 | 7221 |
| 7183 | 7222 |
| 7184 const char* Context::ToCString() const { | 7223 const char* Context::ToCString() const { |
| 7185 return "Context"; | 7224 return "Context"; |
| 7186 } | 7225 } |
| 7187 | 7226 |
| 7188 | 7227 |
| 7189 RawContextScope* ContextScope::New(intptr_t num_variables) { | 7228 RawContextScope* ContextScope::New(intptr_t num_variables) { |
| 7190 ASSERT(Object::context_scope_class() != Class::null()); | 7229 ASSERT(Object::context_scope_class() != Class::null()); |
| 7230 if (num_variables < 0 || num_variables > kMaxElements) { |
| 7231 // This should be caught before we reach here. |
| 7232 FATAL1("Fatal error in ContextScope::New: invalid num_variables %ld\n", |
| 7233 num_variables); |
| 7234 } |
| 7191 intptr_t size = ContextScope::InstanceSize(num_variables); | 7235 intptr_t size = ContextScope::InstanceSize(num_variables); |
| 7192 ContextScope& result = ContextScope::Handle(); | 7236 ContextScope& result = ContextScope::Handle(); |
| 7193 { | 7237 { |
| 7194 RawObject* raw = Object::Allocate(ContextScope::kInstanceKind, | 7238 RawObject* raw = Object::Allocate(ContextScope::kInstanceKind, |
| 7195 size, | 7239 size, |
| 7196 Heap::kOld); | 7240 Heap::kOld); |
| 7197 NoGCScope no_gc; | 7241 NoGCScope no_gc; |
| 7198 result ^= raw; | 7242 result ^= raw; |
| 7199 result.set_num_variables(num_variables); | 7243 result.set_num_variables(num_variables); |
| 7200 } | 7244 } |
| (...skipping 1205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8406 return BigintOperations::Compare(*this, Bigint::Cast(other)); | 8450 return BigintOperations::Compare(*this, Bigint::Cast(other)); |
| 8407 } | 8451 } |
| 8408 if (this->IsNegative() == other.IsNegative()) { | 8452 if (this->IsNegative() == other.IsNegative()) { |
| 8409 return this->IsNegative() ? -1 : 1; | 8453 return this->IsNegative() ? -1 : 1; |
| 8410 } | 8454 } |
| 8411 return this->IsNegative() ? -1 : 1; | 8455 return this->IsNegative() ? -1 : 1; |
| 8412 } | 8456 } |
| 8413 | 8457 |
| 8414 | 8458 |
| 8415 RawBigint* Bigint::Allocate(intptr_t length, Heap::Space space) { | 8459 RawBigint* Bigint::Allocate(intptr_t length, Heap::Space space) { |
| 8416 ASSERT(length >= 0); | 8460 if (length < 0 || length > kMaxElements) { |
| 8461 // This should be caught before we reach here. |
| 8462 FATAL1("Fatal error in Bigint::Allocate: invalid length %ld\n", length); |
| 8463 } |
| 8417 ASSERT(Isolate::Current()->object_store()->bigint_class() != Class::null()); | 8464 ASSERT(Isolate::Current()->object_store()->bigint_class() != Class::null()); |
| 8418 Bigint& result = Bigint::Handle(); | 8465 Bigint& result = Bigint::Handle(); |
| 8419 { | 8466 { |
| 8420 RawObject* raw = Object::Allocate(Bigint::kInstanceKind, | 8467 RawObject* raw = Object::Allocate(Bigint::kInstanceKind, |
| 8421 Bigint::InstanceSize(length), | 8468 Bigint::InstanceSize(length), |
| 8422 space); | 8469 space); |
| 8423 NoGCScope no_gc; | 8470 NoGCScope no_gc; |
| 8424 result ^= raw; | 8471 result ^= raw; |
| 8425 result.raw_ptr()->allocated_length_ = length; // Chunk length allocated. | 8472 result.raw_ptr()->allocated_length_ = length; // Chunk length allocated. |
| 8426 result.raw_ptr()->signed_length_ = length; // Chunk length in use. | 8473 result.raw_ptr()->signed_length_ = length; // Chunk length in use. |
| (...skipping 740 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9167 ASSERT(pos == len); | 9214 ASSERT(pos == len); |
| 9168 return (name_pos == name_len); | 9215 return (name_pos == name_len); |
| 9169 } | 9216 } |
| 9170 | 9217 |
| 9171 | 9218 |
| 9172 RawOneByteString* OneByteString::New(intptr_t len, | 9219 RawOneByteString* OneByteString::New(intptr_t len, |
| 9173 Heap::Space space) { | 9220 Heap::Space space) { |
| 9174 ASSERT(Isolate::Current() == Dart::vm_isolate() || | 9221 ASSERT(Isolate::Current() == Dart::vm_isolate() || |
| 9175 Isolate::Current()->object_store()->one_byte_string_class() != | 9222 Isolate::Current()->object_store()->one_byte_string_class() != |
| 9176 Class::null()); | 9223 Class::null()); |
| 9224 if (len < 0 || len > kMaxElements) { |
| 9225 // This should be caught before we reach here. |
| 9226 FATAL1("Fatal error in OneByteString::New: invalid len %ld\n", len); |
| 9227 } |
| 9177 OneByteString& result = OneByteString::Handle(); | 9228 OneByteString& result = OneByteString::Handle(); |
| 9178 { | 9229 { |
| 9179 RawObject* raw = Object::Allocate(OneByteString::kInstanceKind, | 9230 RawObject* raw = Object::Allocate(OneByteString::kInstanceKind, |
| 9180 OneByteString::InstanceSize(len), | 9231 OneByteString::InstanceSize(len), |
| 9181 space); | 9232 space); |
| 9182 NoGCScope no_gc; | 9233 NoGCScope no_gc; |
| 9183 result ^= raw; | 9234 result ^= raw; |
| 9184 result.SetLength(len); | 9235 result.SetLength(len); |
| 9185 result.SetHash(0); | 9236 result.SetHash(0); |
| 9186 } | 9237 } |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9305 } | 9356 } |
| 9306 return dststr.raw(); | 9357 return dststr.raw(); |
| 9307 } | 9358 } |
| 9308 return TwoByteString::null(); | 9359 return TwoByteString::null(); |
| 9309 } | 9360 } |
| 9310 | 9361 |
| 9311 | 9362 |
| 9312 RawTwoByteString* TwoByteString::New(intptr_t len, | 9363 RawTwoByteString* TwoByteString::New(intptr_t len, |
| 9313 Heap::Space space) { | 9364 Heap::Space space) { |
| 9314 ASSERT(Isolate::Current()->object_store()->two_byte_string_class()); | 9365 ASSERT(Isolate::Current()->object_store()->two_byte_string_class()); |
| 9366 if (len < 0 || len > kMaxElements) { |
| 9367 // This should be caught before we reach here. |
| 9368 FATAL1("Fatal error in TwoByteString::New: invalid len %ld\n", len); |
| 9369 } |
| 9315 TwoByteString& result = TwoByteString::Handle(); | 9370 TwoByteString& result = TwoByteString::Handle(); |
| 9316 { | 9371 { |
| 9317 RawObject* raw = Object::Allocate(TwoByteString::kInstanceKind, | 9372 RawObject* raw = Object::Allocate(TwoByteString::kInstanceKind, |
| 9318 TwoByteString::InstanceSize(len), | 9373 TwoByteString::InstanceSize(len), |
| 9319 space); | 9374 space); |
| 9320 NoGCScope no_gc; | 9375 NoGCScope no_gc; |
| 9321 result ^= raw; | 9376 result ^= raw; |
| 9322 result.SetLength(len); | 9377 result.SetLength(len); |
| 9323 result.SetHash(0); | 9378 result.SetHash(0); |
| 9324 } | 9379 } |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9434 return dststr.raw(); | 9489 return dststr.raw(); |
| 9435 } | 9490 } |
| 9436 return FourByteString::null(); | 9491 return FourByteString::null(); |
| 9437 } | 9492 } |
| 9438 | 9493 |
| 9439 | 9494 |
| 9440 RawFourByteString* FourByteString::New(intptr_t len, | 9495 RawFourByteString* FourByteString::New(intptr_t len, |
| 9441 Heap::Space space) { | 9496 Heap::Space space) { |
| 9442 ASSERT(Isolate::Current()->object_store()->four_byte_string_class() != | 9497 ASSERT(Isolate::Current()->object_store()->four_byte_string_class() != |
| 9443 Class::null()); | 9498 Class::null()); |
| 9499 if (len < 0 || len > kMaxElements) { |
| 9500 // This should be caught before we reach here. |
| 9501 FATAL1("Fatal error in FourByteString::New: invalid len %ld\n", len); |
| 9502 } |
| 9444 FourByteString& result = FourByteString::Handle(); | 9503 FourByteString& result = FourByteString::Handle(); |
| 9445 { | 9504 { |
| 9446 RawObject* raw = Object::Allocate(FourByteString::kInstanceKind, | 9505 RawObject* raw = Object::Allocate(FourByteString::kInstanceKind, |
| 9447 FourByteString::InstanceSize(len), | 9506 FourByteString::InstanceSize(len), |
| 9448 space); | 9507 space); |
| 9449 NoGCScope no_gc; | 9508 NoGCScope no_gc; |
| 9450 result ^= raw; | 9509 result ^= raw; |
| 9451 result.SetLength(len); | 9510 result.SetLength(len); |
| 9452 result.SetHash(0); | 9511 result.SetHash(0); |
| 9453 } | 9512 } |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9541 | 9600 |
| 9542 | 9601 |
| 9543 RawExternalOneByteString* ExternalOneByteString::New( | 9602 RawExternalOneByteString* ExternalOneByteString::New( |
| 9544 const uint8_t* data, | 9603 const uint8_t* data, |
| 9545 intptr_t len, | 9604 intptr_t len, |
| 9546 void* peer, | 9605 void* peer, |
| 9547 Dart_PeerFinalizer callback, | 9606 Dart_PeerFinalizer callback, |
| 9548 Heap::Space space) { | 9607 Heap::Space space) { |
| 9549 ASSERT(Isolate::Current()->object_store()->external_one_byte_string_class() != | 9608 ASSERT(Isolate::Current()->object_store()->external_one_byte_string_class() != |
| 9550 Class::null()); | 9609 Class::null()); |
| 9610 if (len < 0 || len > kMaxElements) { |
| 9611 // This should be caught before we reach here. |
| 9612 FATAL1("Fatal error in ExternalOneByteString::New: invalid len %ld\n", len); |
| 9613 } |
| 9551 ExternalOneByteString& result = ExternalOneByteString::Handle(); | 9614 ExternalOneByteString& result = ExternalOneByteString::Handle(); |
| 9552 ExternalStringData<uint8_t>* external_data = | 9615 ExternalStringData<uint8_t>* external_data = |
| 9553 new ExternalStringData<uint8_t>(data, peer, callback); | 9616 new ExternalStringData<uint8_t>(data, peer, callback); |
| 9554 { | 9617 { |
| 9555 RawObject* raw = Object::Allocate(ExternalOneByteString::kInstanceKind, | 9618 RawObject* raw = Object::Allocate(ExternalOneByteString::kInstanceKind, |
| 9556 ExternalOneByteString::InstanceSize(), | 9619 ExternalOneByteString::InstanceSize(), |
| 9557 space); | 9620 space); |
| 9558 NoGCScope no_gc; | 9621 NoGCScope no_gc; |
| 9559 result ^= raw; | 9622 result ^= raw; |
| 9560 result.SetLength(len); | 9623 result.SetLength(len); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 9588 | 9651 |
| 9589 | 9652 |
| 9590 RawExternalTwoByteString* ExternalTwoByteString::New( | 9653 RawExternalTwoByteString* ExternalTwoByteString::New( |
| 9591 const uint16_t* data, | 9654 const uint16_t* data, |
| 9592 intptr_t len, | 9655 intptr_t len, |
| 9593 void* peer, | 9656 void* peer, |
| 9594 Dart_PeerFinalizer callback, | 9657 Dart_PeerFinalizer callback, |
| 9595 Heap::Space space) { | 9658 Heap::Space space) { |
| 9596 ASSERT(Isolate::Current()->object_store()->external_two_byte_string_class() != | 9659 ASSERT(Isolate::Current()->object_store()->external_two_byte_string_class() != |
| 9597 Class::null()); | 9660 Class::null()); |
| 9661 if (len < 0 || len > kMaxElements) { |
| 9662 // This should be caught before we reach here. |
| 9663 FATAL1("Fatal error in ExternalTwoByteString::New: invalid len %ld\n", len); |
| 9664 } |
| 9598 ExternalTwoByteString& result = ExternalTwoByteString::Handle(); | 9665 ExternalTwoByteString& result = ExternalTwoByteString::Handle(); |
| 9599 ExternalStringData<uint16_t>* external_data = | 9666 ExternalStringData<uint16_t>* external_data = |
| 9600 new ExternalStringData<uint16_t>(data, peer, callback); | 9667 new ExternalStringData<uint16_t>(data, peer, callback); |
| 9601 { | 9668 { |
| 9602 RawObject* raw = Object::Allocate(ExternalTwoByteString::kInstanceKind, | 9669 RawObject* raw = Object::Allocate(ExternalTwoByteString::kInstanceKind, |
| 9603 ExternalTwoByteString::InstanceSize(), | 9670 ExternalTwoByteString::InstanceSize(), |
| 9604 space); | 9671 space); |
| 9605 NoGCScope no_gc; | 9672 NoGCScope no_gc; |
| 9606 result ^= raw; | 9673 result ^= raw; |
| 9607 result.SetLength(len); | 9674 result.SetLength(len); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 9625 | 9692 |
| 9626 | 9693 |
| 9627 RawExternalFourByteString* ExternalFourByteString::New( | 9694 RawExternalFourByteString* ExternalFourByteString::New( |
| 9628 const uint32_t* data, | 9695 const uint32_t* data, |
| 9629 intptr_t len, | 9696 intptr_t len, |
| 9630 void* peer, | 9697 void* peer, |
| 9631 Dart_PeerFinalizer callback, | 9698 Dart_PeerFinalizer callback, |
| 9632 Heap::Space space) { | 9699 Heap::Space space) { |
| 9633 ASSERT(Isolate::Current()->object_store()-> | 9700 ASSERT(Isolate::Current()->object_store()-> |
| 9634 external_four_byte_string_class() != Class::null()); | 9701 external_four_byte_string_class() != Class::null()); |
| 9702 if (len < 0 || len > kMaxElements) { |
| 9703 // This should be caught before we reach here. |
| 9704 FATAL1("Fatal error in ExternalFourByteString::New: invalid len %ld\n", |
| 9705 len); |
| 9706 } |
| 9635 ExternalFourByteString& result = ExternalFourByteString::Handle(); | 9707 ExternalFourByteString& result = ExternalFourByteString::Handle(); |
| 9636 ExternalStringData<uint32_t>* external_data = | 9708 ExternalStringData<uint32_t>* external_data = |
| 9637 new ExternalStringData<uint32_t>(data, peer, callback); | 9709 new ExternalStringData<uint32_t>(data, peer, callback); |
| 9638 { | 9710 { |
| 9639 RawObject* raw = Object::Allocate(ExternalFourByteString::kInstanceKind, | 9711 RawObject* raw = Object::Allocate(ExternalFourByteString::kInstanceKind, |
| 9640 ExternalFourByteString::InstanceSize(), | 9712 ExternalFourByteString::InstanceSize(), |
| 9641 space); | 9713 space); |
| 9642 NoGCScope no_gc; | 9714 NoGCScope no_gc; |
| 9643 result ^= raw; | 9715 result ^= raw; |
| 9644 result.SetLength(len); | 9716 result.SetLength(len); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9728 | 9800 |
| 9729 RawArray* Array::New(intptr_t len, Heap::Space space) { | 9801 RawArray* Array::New(intptr_t len, Heap::Space space) { |
| 9730 ObjectStore* object_store = Isolate::Current()->object_store(); | 9802 ObjectStore* object_store = Isolate::Current()->object_store(); |
| 9731 ASSERT(object_store->array_class() != Class::null()); | 9803 ASSERT(object_store->array_class() != Class::null()); |
| 9732 Class& cls = Class::Handle(object_store->array_class()); | 9804 Class& cls = Class::Handle(object_store->array_class()); |
| 9733 return New(cls, len, space); | 9805 return New(cls, len, space); |
| 9734 } | 9806 } |
| 9735 | 9807 |
| 9736 | 9808 |
| 9737 RawArray* Array::New(const Class& cls, intptr_t len, Heap::Space space) { | 9809 RawArray* Array::New(const Class& cls, intptr_t len, Heap::Space space) { |
| 9738 if ((len < 0) || (len > kMaxArrayElements)) { | 9810 if (len < 0 || len > Array::kMaxElements) { |
| 9739 // TODO(srdjan): Verify that illegal argument is the right thing to throw. | 9811 // This should be caught before we reach here. |
| 9740 GrowableArray<const Object*> args; | 9812 FATAL1("Fatal error in Array::New: invalid len %ld\n", len); |
| 9741 args.Add(&Smi::Handle(Smi::New(len))); | |
| 9742 Exceptions::ThrowByType(Exceptions::kIllegalArgument, args); | |
| 9743 } | 9813 } |
| 9744 Array& result = Array::Handle(); | 9814 Array& result = Array::Handle(); |
| 9745 { | 9815 { |
| 9746 RawObject* raw = Object::Allocate(cls.id(), | 9816 RawObject* raw = Object::Allocate(cls.id(), |
| 9747 Array::InstanceSize(len), | 9817 Array::InstanceSize(len), |
| 9748 space); | 9818 space); |
| 9749 NoGCScope no_gc; | 9819 NoGCScope no_gc; |
| 9750 result ^= raw; | 9820 result ^= raw; |
| 9751 result.SetLength(len); | 9821 result.SetLength(len); |
| 9752 } | 9822 } |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10033 } | 10103 } |
| 10034 | 10104 |
| 10035 | 10105 |
| 10036 template<typename HandleT, typename RawT, typename ElementT> | 10106 template<typename HandleT, typename RawT, typename ElementT> |
| 10037 RawT* ByteArray::NewExternalImpl(const Class& cls, | 10107 RawT* ByteArray::NewExternalImpl(const Class& cls, |
| 10038 ElementT* data, | 10108 ElementT* data, |
| 10039 intptr_t len, | 10109 intptr_t len, |
| 10040 void* peer, | 10110 void* peer, |
| 10041 Dart_PeerFinalizer callback, | 10111 Dart_PeerFinalizer callback, |
| 10042 Heap::Space space) { | 10112 Heap::Space space) { |
| 10113 if (len < 0 || len > HandleT::kMaxElements) { |
| 10114 // This should be caught before we reach here. |
| 10115 FATAL1("Fatal error in ByteArray::NewExternalImpl: invalid len %ld\n", len); |
| 10116 } |
| 10043 HandleT& result = HandleT::Handle(); | 10117 HandleT& result = HandleT::Handle(); |
| 10044 ExternalByteArrayData<ElementT>* external_data = | 10118 ExternalByteArrayData<ElementT>* external_data = |
| 10045 new ExternalByteArrayData<ElementT>(data, peer, callback); | 10119 new ExternalByteArrayData<ElementT>(data, peer, callback); |
| 10046 { | 10120 { |
| 10047 RawObject* raw = Object::Allocate(cls.id(), HandleT::InstanceSize(), space); | 10121 RawObject* raw = Object::Allocate(cls.id(), HandleT::InstanceSize(), space); |
| 10048 NoGCScope no_gc; | 10122 NoGCScope no_gc; |
| 10049 result ^= raw; | 10123 result ^= raw; |
| 10050 result.SetLength(len); | 10124 result.SetLength(len); |
| 10051 result.SetExternalData(external_data); | 10125 result.SetExternalData(external_data); |
| 10052 } | 10126 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 10071 | 10145 |
| 10072 const char* ByteArray::ToCString() const { | 10146 const char* ByteArray::ToCString() const { |
| 10073 // ByteArray is an abstract class. | 10147 // ByteArray is an abstract class. |
| 10074 UNREACHABLE(); | 10148 UNREACHABLE(); |
| 10075 return "ByteArray"; | 10149 return "ByteArray"; |
| 10076 } | 10150 } |
| 10077 | 10151 |
| 10078 | 10152 |
| 10079 template<typename HandleT, typename RawT> | 10153 template<typename HandleT, typename RawT> |
| 10080 RawT* ByteArray::NewImpl(const Class& cls, intptr_t len, Heap::Space space) { | 10154 RawT* ByteArray::NewImpl(const Class& cls, intptr_t len, Heap::Space space) { |
| 10155 if (len < 0 || len > HandleT::kMaxElements) { |
| 10156 // This should be caught before we reach here. |
| 10157 FATAL1("Fatal error in ByteArray::NewImpl: invalid len %ld\n", len); |
| 10158 } |
| 10081 HandleT& result = HandleT::Handle(); | 10159 HandleT& result = HandleT::Handle(); |
| 10082 { | 10160 { |
| 10083 RawObject* raw = Object::Allocate(cls.id(), | 10161 RawObject* raw = Object::Allocate(cls.id(), |
| 10084 HandleT::InstanceSize(len), | 10162 HandleT::InstanceSize(len), |
| 10085 space); | 10163 space); |
| 10086 NoGCScope no_gc; | 10164 NoGCScope no_gc; |
| 10087 result ^= raw; | 10165 result ^= raw; |
| 10088 result.SetLength(len); | 10166 result.SetLength(len); |
| 10089 if (len > 0) { | 10167 if (len > 0) { |
| 10090 memset(result.ByteAddr(0), 0, result.ByteLength()); | 10168 memset(result.ByteAddr(0), 0, result.ByteLength()); |
| 10091 } | 10169 } |
| 10092 } | 10170 } |
| 10093 return result.raw(); | 10171 return result.raw(); |
| 10094 } | 10172 } |
| 10095 | 10173 |
| 10096 | 10174 |
| 10097 template<typename HandleT, typename RawT, typename ElementT> | 10175 template<typename HandleT, typename RawT, typename ElementT> |
| 10098 RawT* ByteArray::NewImpl(const Class& cls, | 10176 RawT* ByteArray::NewImpl(const Class& cls, |
| 10099 const ElementT* data, | 10177 const ElementT* data, |
| 10100 intptr_t len, | 10178 intptr_t len, |
| 10101 Heap::Space space) { | 10179 Heap::Space space) { |
| 10180 if (len < 0 || len > HandleT::kMaxElements) { |
| 10181 // This should be caught before we reach here. |
| 10182 FATAL1("Fatal error in ByteArray::NewImpl: invalid len %ld\n", len); |
| 10183 } |
| 10102 HandleT& result = HandleT::Handle(); | 10184 HandleT& result = HandleT::Handle(); |
| 10103 { | 10185 { |
| 10104 RawObject* raw = Object::Allocate(cls.id(), | 10186 RawObject* raw = Object::Allocate(cls.id(), |
| 10105 HandleT::InstanceSize(len), | 10187 HandleT::InstanceSize(len), |
| 10106 space); | 10188 space); |
| 10107 NoGCScope no_gc; | 10189 NoGCScope no_gc; |
| 10108 result ^= raw; | 10190 result ^= raw; |
| 10109 result.SetLength(len); | 10191 result.SetLength(len); |
| 10110 if (len > 0) { | 10192 if (len > 0) { |
| 10111 memmove(result.ByteAddr(0), data, result.ByteLength()); | 10193 memmove(result.ByteAddr(0), data, result.ByteLength()); |
| (...skipping 682 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10794 | 10876 |
| 10795 | 10877 |
| 10796 void JSRegExp::set_num_bracket_expressions(intptr_t value) const { | 10878 void JSRegExp::set_num_bracket_expressions(intptr_t value) const { |
| 10797 raw_ptr()->num_bracket_expressions_ = Smi::New(value); | 10879 raw_ptr()->num_bracket_expressions_ = Smi::New(value); |
| 10798 } | 10880 } |
| 10799 | 10881 |
| 10800 | 10882 |
| 10801 RawJSRegExp* JSRegExp::New(intptr_t len, Heap::Space space) { | 10883 RawJSRegExp* JSRegExp::New(intptr_t len, Heap::Space space) { |
| 10802 ASSERT(Isolate::Current()->object_store()->jsregexp_class() != | 10884 ASSERT(Isolate::Current()->object_store()->jsregexp_class() != |
| 10803 Class::null()); | 10885 Class::null()); |
| 10886 if (len < 0 || len > kMaxElements) { |
| 10887 // This should be caught before we reach here. |
| 10888 FATAL1("Fatal error in JSRegexp::New: invalid len %ld\n", len); |
| 10889 } |
| 10804 JSRegExp& result = JSRegExp::Handle(); | 10890 JSRegExp& result = JSRegExp::Handle(); |
| 10805 { | 10891 { |
| 10806 RawObject* raw = Object::Allocate(JSRegExp::kInstanceKind, | 10892 RawObject* raw = Object::Allocate(JSRegExp::kInstanceKind, |
| 10807 JSRegExp::InstanceSize(len), | 10893 JSRegExp::InstanceSize(len), |
| 10808 space); | 10894 space); |
| 10809 NoGCScope no_gc; | 10895 NoGCScope no_gc; |
| 10810 result ^= raw; | 10896 result ^= raw; |
| 10811 result.set_type(kUnitialized); | 10897 result.set_type(kUnitialized); |
| 10812 result.set_flags(0); | 10898 result.set_flags(0); |
| 10813 result.SetLength(len); | 10899 result.SetLength(len); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10876 const String& str = String::Handle(pattern()); | 10962 const String& str = String::Handle(pattern()); |
| 10877 const char* format = "JSRegExp: pattern=%s flags=%s"; | 10963 const char* format = "JSRegExp: pattern=%s flags=%s"; |
| 10878 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); | 10964 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); |
| 10879 char* chars = reinterpret_cast<char*>( | 10965 char* chars = reinterpret_cast<char*>( |
| 10880 Isolate::Current()->current_zone()->Allocate(len + 1)); | 10966 Isolate::Current()->current_zone()->Allocate(len + 1)); |
| 10881 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); | 10967 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); |
| 10882 return chars; | 10968 return chars; |
| 10883 } | 10969 } |
| 10884 | 10970 |
| 10885 } // namespace dart | 10971 } // namespace dart |
| OLD | NEW |