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

Side by Side Diff: vm/object.cc

Issue 10782016: Enforce length/size limits for variable size heap object in order to (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 5 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
« vm/object.h ('K') | « vm/object.h ('k') | vm/object_test.cc » ('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 3349 matching lines...) Expand 10 before | Expand all | Expand 10 after
3360 if (!type.IsInstantiated()) { 3360 if (!type.IsInstantiated()) {
3361 type = type.InstantiateFrom(instantiator_type_arguments); 3361 type = type.InstantiateFrom(instantiator_type_arguments);
3362 } 3362 }
3363 instantiated_array.SetTypeAt(i, type); 3363 instantiated_array.SetTypeAt(i, type);
3364 } 3364 }
3365 return instantiated_array.raw(); 3365 return instantiated_array.raw();
3366 } 3366 }
3367 3367
3368 3368
3369 RawTypeArguments* TypeArguments::New(intptr_t len, Heap::Space space) { 3369 RawTypeArguments* TypeArguments::New(intptr_t len, Heap::Space space) {
3370 if ((len < 0) || (len > kMaxTypes)) { 3370 if (len < 0 || len > kMaxElements) {
3371 // TODO(iposva): Should we throw an illegal parameter exception? 3371 // This should be caught before we reach here.
3372 UNIMPLEMENTED(); 3372 FATAL1("Fatal error in TypeArguments::New: invalid len %ld\n", len);
3373 return null();
3374 } 3373 }
3375
3376 const Class& type_arguments_class = 3374 const Class& type_arguments_class =
3377 Class::Handle(Object::type_arguments_class()); 3375 Class::Handle(Object::type_arguments_class());
3378 TypeArguments& result = TypeArguments::Handle(); 3376 TypeArguments& result = TypeArguments::Handle();
3379 { 3377 {
3380 RawObject* raw = Object::Allocate(type_arguments_class, 3378 RawObject* raw = Object::Allocate(type_arguments_class,
3381 TypeArguments::InstanceSize(len), 3379 TypeArguments::InstanceSize(len),
3382 space); 3380 space);
3383 NoGCScope no_gc; 3381 NoGCScope no_gc;
3384 result ^= raw; 3382 result ^= raw;
3385 // Length must be set before we start storing into the array. 3383 // Length must be set before we start storing into the array.
(...skipping 1135 matching lines...) Expand 10 before | Expand all | Expand 10 after
4521 while (index < src_pos && kind != Token::kEOS) { 4519 while (index < src_pos && kind != Token::kEOS) {
4522 iterator.Advance(); 4520 iterator.Advance();
4523 kind = iterator.CurrentTokenKind(); 4521 kind = iterator.CurrentTokenKind();
4524 index += 1; 4522 index += 1;
4525 } 4523 }
4526 return iterator.CurrentPosition(); 4524 return iterator.CurrentPosition();
4527 } 4525 }
4528 4526
4529 4527
4530 RawTokenStream* TokenStream::New(intptr_t len) { 4528 RawTokenStream* TokenStream::New(intptr_t len) {
4529 if (len < 0 || len > kMaxElements) {
4530 // This should be caught before we reach here.
4531 FATAL1("Fatal error in TokenStream::New: invalid len %ld\n", len);
4532 }
4531 const Class& token_stream_class = Class::Handle(Object::token_stream_class()); 4533 const Class& token_stream_class = Class::Handle(Object::token_stream_class());
4532 TokenStream& result = TokenStream::Handle(); 4534 TokenStream& result = TokenStream::Handle();
4533 { 4535 {
4534 RawObject* raw = Object::Allocate(token_stream_class, 4536 RawObject* raw = Object::Allocate(token_stream_class,
4535 TokenStream::InstanceSize(len), 4537 TokenStream::InstanceSize(len),
4536 Heap::kOld); 4538 Heap::kOld);
4537 NoGCScope no_gc; 4539 NoGCScope no_gc;
4538 result ^= raw; 4540 result ^= raw;
4539 result.SetLength(len); 4541 result.SetLength(len);
4540 } 4542 }
(...skipping 1727 matching lines...) Expand 10 before | Expand all | Expand 10 after
6268 if (!error.IsNull()) { 6270 if (!error.IsNull()) {
6269 return error.raw(); 6271 return error.raw();
6270 } 6272 }
6271 } 6273 }
6272 } 6274 }
6273 return error.raw(); 6275 return error.raw();
6274 } 6276 }
6275 6277
6276 6278
6277 RawInstructions* Instructions::New(intptr_t size) { 6279 RawInstructions* Instructions::New(intptr_t size) {
6280 if (size < 0 || size > kMaxElements) {
6281 // This should be caught before we reach here.
6282 FATAL1("Fatal error in Instructions::New: invalid size %ld\n", size);
6283 }
6278 const Class& instructions_class = Class::Handle(Object::instructions_class()); 6284 const Class& instructions_class = Class::Handle(Object::instructions_class());
6279 Instructions& result = Instructions::Handle(); 6285 Instructions& result = Instructions::Handle();
6280 { 6286 {
6281 uword aligned_size = Instructions::InstanceSize(size); 6287 uword aligned_size = Instructions::InstanceSize(size);
6282 RawObject* raw = Object::Allocate(instructions_class, 6288 RawObject* raw = Object::Allocate(instructions_class,
6283 aligned_size, 6289 aligned_size,
6284 Heap::kCode); 6290 Heap::kCode);
6285 NoGCScope no_gc; 6291 NoGCScope no_gc;
6286 // TODO(iposva): Remove premarking once old and code spaces are merged. 6292 // TODO(iposva): Remove premarking once old and code spaces are merged.
6287 raw->SetMarkBit(); 6293 raw->SetMarkBit();
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
6353 return *(EntryAddr(index, kTryIndexEntry)); 6359 return *(EntryAddr(index, kTryIndexEntry));
6354 } 6360 }
6355 6361
6356 6362
6357 void PcDescriptors::SetTryIndex(intptr_t index, intptr_t value) const { 6363 void PcDescriptors::SetTryIndex(intptr_t index, intptr_t value) const {
6358 *(EntryAddr(index, kTryIndexEntry)) = value; 6364 *(EntryAddr(index, kTryIndexEntry)) = value;
6359 } 6365 }
6360 6366
6361 6367
6362 RawPcDescriptors* PcDescriptors::New(intptr_t num_descriptors) { 6368 RawPcDescriptors* PcDescriptors::New(intptr_t num_descriptors) {
6369 if (num_descriptors < 0 || num_descriptors > kMaxElements) {
6370 // This should be caught before we reach here.
6371 FATAL1("Fatal error in PcDescriptors::New: invalid num_descriptors %ld\n",
6372 num_descriptors);
6373 }
6363 const Class& cls = Class::Handle(Object::pc_descriptors_class()); 6374 const Class& cls = Class::Handle(Object::pc_descriptors_class());
6364 PcDescriptors& result = PcDescriptors::Handle(); 6375 PcDescriptors& result = PcDescriptors::Handle();
6365 { 6376 {
6366 uword size = PcDescriptors::InstanceSize(num_descriptors); 6377 uword size = PcDescriptors::InstanceSize(num_descriptors);
6367 RawObject* raw = Object::Allocate(cls, size, Heap::kOld); 6378 RawObject* raw = Object::Allocate(cls, size, Heap::kOld);
6368 NoGCScope no_gc; 6379 NoGCScope no_gc;
6369 result ^= raw; 6380 result ^= raw;
6370 result.SetLength(num_descriptors); 6381 result.SetLength(num_descriptors);
6371 } 6382 }
6372 return result.raw(); 6383 return result.raw();
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
6479 } 6490 }
6480 } 6491 }
6481 6492
6482 6493
6483 RawStackmap* Stackmap::New(uword pc_offset, BitmapBuilder* bmap) { 6494 RawStackmap* Stackmap::New(uword pc_offset, BitmapBuilder* bmap) {
6484 const Class& cls = Class::Handle(Object::stackmap_class()); 6495 const Class& cls = Class::Handle(Object::stackmap_class());
6485 ASSERT(!cls.IsNull()); 6496 ASSERT(!cls.IsNull());
6486 ASSERT(bmap != NULL); 6497 ASSERT(bmap != NULL);
6487 Stackmap& result = Stackmap::Handle(); 6498 Stackmap& result = Stackmap::Handle();
6488 intptr_t size = bmap->SizeInBytes(); 6499 intptr_t size = bmap->SizeInBytes();
6500 if (size < 0 || size > kMaxElements) {
6501 // This should be caught before we reach here.
6502 FATAL1("Fatal error in PcDescriptors::New: invalid size %ld\n", size);
6503 }
6489 { 6504 {
6490 // Stackmap data objects are associated with a code object, allocate them 6505 // Stackmap data objects are associated with a code object, allocate them
6491 // in old generation. 6506 // in old generation.
6492 RawObject* raw = 6507 RawObject* raw =
6493 Object::Allocate(cls, Stackmap::InstanceSize(size), Heap::kOld); 6508 Object::Allocate(cls, Stackmap::InstanceSize(size), Heap::kOld);
6494 NoGCScope no_gc; 6509 NoGCScope no_gc;
6495 result ^= raw; 6510 result ^= raw;
6496 result.set_bitmap_size_in_bytes(size); 6511 result.set_bitmap_size_in_bytes(size);
6497 } 6512 }
6498 result.SetPC(pc_offset); 6513 result.SetPC(pc_offset);
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
6563 } 6578 }
6564 6579
6565 6580
6566 const char* LocalVarDescriptors::ToCString() const { 6581 const char* LocalVarDescriptors::ToCString() const {
6567 UNIMPLEMENTED(); 6582 UNIMPLEMENTED();
6568 return "LocalVarDescriptors"; 6583 return "LocalVarDescriptors";
6569 } 6584 }
6570 6585
6571 6586
6572 RawLocalVarDescriptors* LocalVarDescriptors::New(intptr_t num_variables) { 6587 RawLocalVarDescriptors* LocalVarDescriptors::New(intptr_t num_variables) {
6588 if (num_variables < 0 || num_variables > kMaxElements) {
6589 // This should be caught before we reach here.
6590 FATAL1("Fatal error in LocalVarDescriptors::New: "
6591 "invalid num_variables %ld\n", num_variables);
6592 }
6573 const Class& cls = Class::Handle(Object::var_descriptors_class()); 6593 const Class& cls = Class::Handle(Object::var_descriptors_class());
6574 LocalVarDescriptors& result = LocalVarDescriptors::Handle(); 6594 LocalVarDescriptors& result = LocalVarDescriptors::Handle();
6575 { 6595 {
6576 uword size = LocalVarDescriptors::InstanceSize(num_variables); 6596 uword size = LocalVarDescriptors::InstanceSize(num_variables);
6577 RawObject* raw = Object::Allocate(cls, size, Heap::kOld); 6597 RawObject* raw = Object::Allocate(cls, size, Heap::kOld);
6578 NoGCScope no_gc; 6598 NoGCScope no_gc;
6579 result ^= raw; 6599 result ^= raw;
6580 result.raw_ptr()->length_ = num_variables; 6600 result.raw_ptr()->length_ = num_variables;
6581 } 6601 }
6582 const Array& names = Array::Handle(Array::New(num_variables, Heap::kOld)); 6602 const Array& names = Array::Handle(Array::New(num_variables, Heap::kOld));
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
6617 } 6637 }
6618 6638
6619 6639
6620 void ExceptionHandlers::SetHandlerPC(intptr_t index, 6640 void ExceptionHandlers::SetHandlerPC(intptr_t index,
6621 intptr_t value) const { 6641 intptr_t value) const {
6622 *(EntryAddr(index, kHandlerPcEntry)) = value; 6642 *(EntryAddr(index, kHandlerPcEntry)) = value;
6623 } 6643 }
6624 6644
6625 6645
6626 RawExceptionHandlers* ExceptionHandlers::New(intptr_t num_handlers) { 6646 RawExceptionHandlers* ExceptionHandlers::New(intptr_t num_handlers) {
6647 if (num_handlers < 0 || num_handlers > kMaxElements) {
6648 // This should be caught before we reach here.
6649 FATAL1("Fatal error in ExceptionHandlers::New: invalid num_handlers %ld\n",
6650 num_handlers);
6651 }
6627 const Class& cls = Class::Handle(Object::exception_handlers_class()); 6652 const Class& cls = Class::Handle(Object::exception_handlers_class());
6628 ExceptionHandlers& result = ExceptionHandlers::Handle(); 6653 ExceptionHandlers& result = ExceptionHandlers::Handle();
6629 { 6654 {
6630 uword size = ExceptionHandlers::InstanceSize(num_handlers); 6655 uword size = ExceptionHandlers::InstanceSize(num_handlers);
6631 RawObject* raw = Object::Allocate(cls, size, Heap::kOld); 6656 RawObject* raw = Object::Allocate(cls, size, Heap::kOld);
6632 NoGCScope no_gc; 6657 NoGCScope no_gc;
6633 result ^= raw; 6658 result ^= raw;
6634 result.SetLength(num_handlers); 6659 result.SetLength(num_handlers);
6635 } 6660 }
6636 return result.raw(); 6661 return result.raw();
(...skipping 21 matching lines...) Expand all
6658 "%ld => 0x%x\n", 6683 "%ld => 0x%x\n",
6659 TryIndex(i), 6684 TryIndex(i),
6660 HandlerPC(i)); 6685 HandlerPC(i));
6661 } 6686 }
6662 return buffer; 6687 return buffer;
6663 } 6688 }
6664 6689
6665 6690
6666 Code::Comments& Code::Comments::New(intptr_t count) { 6691 Code::Comments& Code::Comments::New(intptr_t count) {
6667 Comments* comments; 6692 Comments* comments;
6693 if (count < 0 || count > (kIntptrMax / kNumberOfEntries)) {
6694 // This should be caught before we reach here.
6695 FATAL1("Fatal error in Code::Comments::New: invalid count %ld\n", count);
6696 }
6668 if (count == 0) { 6697 if (count == 0) {
6669 comments = new Comments(Array::Empty()); 6698 comments = new Comments(Array::Empty());
6670 } else { 6699 } else {
6671 comments = new Comments(Array::New(count * kNumberOfEntries)); 6700 comments = new Comments(Array::New(count * kNumberOfEntries));
6672 } 6701 }
6673 return *comments; 6702 return *comments;
6674 } 6703 }
6675 6704
6676 6705
6677 intptr_t Code::Comments::Length() const { 6706 intptr_t Code::Comments::Length() const {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
6719 Comments* comments = new Code::Comments(raw_ptr()->comments_); 6748 Comments* comments = new Code::Comments(raw_ptr()->comments_);
6720 return *comments; 6749 return *comments;
6721 } 6750 }
6722 6751
6723 6752
6724 void Code::set_comments(const Code::Comments& comments) const { 6753 void Code::set_comments(const Code::Comments& comments) const {
6725 StorePointer(&raw_ptr()->comments_, comments.comments_.raw()); 6754 StorePointer(&raw_ptr()->comments_, comments.comments_.raw());
6726 } 6755 }
6727 6756
6728 6757
6729 RawCode* Code::New(int pointer_offsets_length) { 6758 RawCode* Code::New(intptr_t pointer_offsets_length) {
6759 if (pointer_offsets_length < 0 || pointer_offsets_length > kMaxElements) {
6760 // This should be caught before we reach here.
6761 FATAL1("Fatal error in Code::New: invalid pointer_offsets_length %ld\n",
6762 pointer_offsets_length);
6763 }
6730 const Class& cls = Class::Handle(Object::code_class()); 6764 const Class& cls = Class::Handle(Object::code_class());
6731 Code& result = Code::Handle(); 6765 Code& result = Code::Handle();
6732 { 6766 {
6733 uword size = Code::InstanceSize(pointer_offsets_length); 6767 uword size = Code::InstanceSize(pointer_offsets_length);
6734 RawObject* raw = Object::Allocate(cls, size, Heap::kOld); 6768 RawObject* raw = Object::Allocate(cls, size, Heap::kOld);
6735 NoGCScope no_gc; 6769 NoGCScope no_gc;
6736 result ^= raw; 6770 result ^= raw;
6737 result.set_pointer_offsets_length(pointer_offsets_length); 6771 result.set_pointer_offsets_length(pointer_offsets_length);
6738 result.set_is_optimized(false); 6772 result.set_is_optimized(false);
6739 result.set_comments(Comments::New(0)); 6773 result.set_comments(Comments::New(0));
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
6947 *map = previous_map; 6981 *map = previous_map;
6948 break; 6982 break;
6949 } 6983 }
6950 previous_map = map->raw(); 6984 previous_map = map->raw();
6951 } 6985 }
6952 return map->raw(); 6986 return map->raw();
6953 } 6987 }
6954 6988
6955 6989
6956 RawContext* Context::New(intptr_t num_variables, Heap::Space space) { 6990 RawContext* Context::New(intptr_t num_variables, Heap::Space space) {
6957 ASSERT(num_variables >= 0); 6991 if (num_variables < 0 || num_variables > kMaxElements) {
6958 6992 // This should be caught before we reach here.
6993 FATAL1("Fatal error in Context::New: invalid num_variables %ld\n",
6994 num_variables);
6995 }
6959 const Class& context_class = Class::Handle(Object::context_class()); 6996 const Class& context_class = Class::Handle(Object::context_class());
6960 Context& result = Context::Handle(); 6997 Context& result = Context::Handle();
6961 { 6998 {
6962 RawObject* raw = Object::Allocate(context_class, 6999 RawObject* raw = Object::Allocate(context_class,
6963 Context::InstanceSize(num_variables), 7000 Context::InstanceSize(num_variables),
6964 space); 7001 space);
6965 NoGCScope no_gc; 7002 NoGCScope no_gc;
6966 result ^= raw; 7003 result ^= raw;
6967 result.set_num_variables(num_variables); 7004 result.set_num_variables(num_variables);
6968 } 7005 }
6969 result.set_isolate(Isolate::Current()); 7006 result.set_isolate(Isolate::Current());
6970 return result.raw(); 7007 return result.raw();
6971 } 7008 }
6972 7009
6973 7010
6974 const char* Context::ToCString() const { 7011 const char* Context::ToCString() const {
6975 return "Context"; 7012 return "Context";
6976 } 7013 }
6977 7014
6978 7015
6979 RawContextScope* ContextScope::New(intptr_t num_variables) { 7016 RawContextScope* ContextScope::New(intptr_t num_variables) {
7017 if (num_variables < 0 || num_variables > kMaxElements) {
7018 // This should be caught before we reach here.
7019 FATAL1("Fatal error in ContextScope::New: invalid num_variables %ld\n",
7020 num_variables);
7021 }
6980 const Class& context_scope_class = 7022 const Class& context_scope_class =
6981 Class::Handle(Object::context_scope_class()); 7023 Class::Handle(Object::context_scope_class());
6982 intptr_t size = ContextScope::InstanceSize(num_variables); 7024 intptr_t size = ContextScope::InstanceSize(num_variables);
6983 ContextScope& result = ContextScope::Handle(); 7025 ContextScope& result = ContextScope::Handle();
6984 { 7026 {
6985 RawObject* raw = Object::Allocate(context_scope_class, size, Heap::kOld); 7027 RawObject* raw = Object::Allocate(context_scope_class, size, Heap::kOld);
6986 NoGCScope no_gc; 7028 NoGCScope no_gc;
6987 result ^= raw; 7029 result ^= raw;
6988 result.set_num_variables(num_variables); 7030 result.set_num_variables(num_variables);
6989 } 7031 }
(...skipping 1149 matching lines...) Expand 10 before | Expand all | Expand 10 after
8139 return BigintOperations::Compare(*this, Bigint::Cast(other)); 8181 return BigintOperations::Compare(*this, Bigint::Cast(other));
8140 } 8182 }
8141 if (this->IsNegative() == other.IsNegative()) { 8183 if (this->IsNegative() == other.IsNegative()) {
8142 return this->IsNegative() ? -1 : 1; 8184 return this->IsNegative() ? -1 : 1;
8143 } 8185 }
8144 return this->IsNegative() ? -1 : 1; 8186 return this->IsNegative() ? -1 : 1;
8145 } 8187 }
8146 8188
8147 8189
8148 RawBigint* Bigint::Allocate(intptr_t length, Heap::Space space) { 8190 RawBigint* Bigint::Allocate(intptr_t length, Heap::Space space) {
8149 ASSERT(length >= 0); 8191 if (length < 0 || length > kMaxElements) {
8192 // This should be caught before we reach here.
8193 FATAL1("Fatal error in Bigint::Allocate: invalid length %ld\n", length);
8194 }
8150 Isolate* isolate = Isolate::Current(); 8195 Isolate* isolate = Isolate::Current();
8151 const Class& cls = Class::Handle(isolate->object_store()->bigint_class()); 8196 const Class& cls = Class::Handle(isolate->object_store()->bigint_class());
8152 Bigint& result = Bigint::Handle(); 8197 Bigint& result = Bigint::Handle();
8153 { 8198 {
8154 RawObject* raw = Object::Allocate(cls, Bigint::InstanceSize(length), space); 8199 RawObject* raw = Object::Allocate(cls, Bigint::InstanceSize(length), space);
8155 NoGCScope no_gc; 8200 NoGCScope no_gc;
8156 result ^= raw; 8201 result ^= raw;
8157 result.raw_ptr()->allocated_length_ = length; // Chunk length allocated. 8202 result.raw_ptr()->allocated_length_ = length; // Chunk length allocated.
8158 result.raw_ptr()->signed_length_ = length; // Chunk length in use. 8203 result.raw_ptr()->signed_length_ = length; // Chunk length in use.
8159 } 8204 }
(...skipping 872 matching lines...) Expand 10 before | Expand all | Expand 10 after
9032 } 9077 }
9033 } 9078 }
9034 return dststr.raw(); 9079 return dststr.raw();
9035 } 9080 }
9036 return OneByteString::null(); 9081 return OneByteString::null();
9037 } 9082 }
9038 9083
9039 9084
9040 RawOneByteString* OneByteString::New(intptr_t len, 9085 RawOneByteString* OneByteString::New(intptr_t len,
9041 Heap::Space space) { 9086 Heap::Space space) {
9087 if (len < 0 || len > kMaxElements) {
9088 // This should be caught before we reach here.
9089 FATAL1("Fatal error in OneByteString::New: invalid len %ld\n", len);
9090 }
9042 Isolate* isolate = Isolate::Current(); 9091 Isolate* isolate = Isolate::Current();
9043 9092
9044 const Class& cls = 9093 const Class& cls =
9045 Class::Handle(isolate->object_store()->one_byte_string_class()); 9094 Class::Handle(isolate->object_store()->one_byte_string_class());
9046 OneByteString& result = OneByteString::Handle(); 9095 OneByteString& result = OneByteString::Handle();
9047 { 9096 {
9048 RawObject* raw = Object::Allocate(cls, 9097 RawObject* raw = Object::Allocate(cls,
9049 OneByteString::InstanceSize(len), 9098 OneByteString::InstanceSize(len),
9050 space); 9099 space);
9051 NoGCScope no_gc; 9100 NoGCScope no_gc;
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
9173 } 9222 }
9174 } 9223 }
9175 return dststr.raw(); 9224 return dststr.raw();
9176 } 9225 }
9177 return TwoByteString::null(); 9226 return TwoByteString::null();
9178 } 9227 }
9179 9228
9180 9229
9181 RawTwoByteString* TwoByteString::New(intptr_t len, 9230 RawTwoByteString* TwoByteString::New(intptr_t len,
9182 Heap::Space space) { 9231 Heap::Space space) {
9232 if (len < 0 || len > kMaxElements) {
9233 // This should be caught before we reach here.
9234 FATAL1("Fatal error in TwoByteString::New: invalid len %ld\n", len);
9235 }
9183 Isolate* isolate = Isolate::Current(); 9236 Isolate* isolate = Isolate::Current();
9184 9237
9185 const Class& cls = 9238 const Class& cls =
9186 Class::Handle(isolate->object_store()->two_byte_string_class()); 9239 Class::Handle(isolate->object_store()->two_byte_string_class());
9187 TwoByteString& result = TwoByteString::Handle(); 9240 TwoByteString& result = TwoByteString::Handle();
9188 { 9241 {
9189 RawObject* raw = Object::Allocate(cls, 9242 RawObject* raw = Object::Allocate(cls,
9190 TwoByteString::InstanceSize(len), 9243 TwoByteString::InstanceSize(len),
9191 space); 9244 space);
9192 NoGCScope no_gc; 9245 NoGCScope no_gc;
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
9304 } 9357 }
9305 } 9358 }
9306 return dststr.raw(); 9359 return dststr.raw();
9307 } 9360 }
9308 return FourByteString::null(); 9361 return FourByteString::null();
9309 } 9362 }
9310 9363
9311 9364
9312 RawFourByteString* FourByteString::New(intptr_t len, 9365 RawFourByteString* FourByteString::New(intptr_t len,
9313 Heap::Space space) { 9366 Heap::Space space) {
9367 if (len < 0 || len > kMaxElements) {
9368 // This should be caught before we reach here.
9369 FATAL1("Fatal error in FourByteString::New: invalid len %ld\n", len);
9370 }
9314 Isolate* isolate = Isolate::Current(); 9371 Isolate* isolate = Isolate::Current();
9315 9372
9316 const Class& cls = 9373 const Class& cls =
9317 Class::Handle(isolate->object_store()->four_byte_string_class()); 9374 Class::Handle(isolate->object_store()->four_byte_string_class());
9318 FourByteString& result = FourByteString::Handle(); 9375 FourByteString& result = FourByteString::Handle();
9319 { 9376 {
9320 RawObject* raw = Object::Allocate(cls, 9377 RawObject* raw = Object::Allocate(cls,
9321 FourByteString::InstanceSize(len), 9378 FourByteString::InstanceSize(len),
9322 space); 9379 space);
9323 NoGCScope no_gc; 9380 NoGCScope no_gc;
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
9414 } 9471 }
9415 9472
9416 9473
9417 RawExternalOneByteString* ExternalOneByteString::New( 9474 RawExternalOneByteString* ExternalOneByteString::New(
9418 const uint8_t* data, 9475 const uint8_t* data,
9419 intptr_t len, 9476 intptr_t len,
9420 void* peer, 9477 void* peer,
9421 Dart_PeerFinalizer callback, 9478 Dart_PeerFinalizer callback,
9422 Heap::Space space) { 9479 Heap::Space space) {
9423 Isolate* isolate = Isolate::Current(); 9480 Isolate* isolate = Isolate::Current();
9481 if (len < 0) {
cshapiro 2012/07/17 22:54:30 This should check against a kMaxElements, preferab
turnidge 2012/07/18 18:17:04 I went further than that. I have made all strings
9482 // This should be caught before we reach here.
9483 //
9484 // Note that we don't have a max length for an external one byte
9485 // string. We can safely compute the offset of all array elements
9486 // without causing overflow.
9487 FATAL1("Fatal error in ExternalOneByteString::New: invalid len %ld\n", len);
9488 }
9424 9489
9425 const Class& cls = 9490 const Class& cls =
9426 Class::Handle(isolate->object_store()->external_one_byte_string_class()); 9491 Class::Handle(isolate->object_store()->external_one_byte_string_class());
9427 ExternalOneByteString& result = ExternalOneByteString::Handle(); 9492 ExternalOneByteString& result = ExternalOneByteString::Handle();
9428 ExternalStringData<uint8_t>* external_data = 9493 ExternalStringData<uint8_t>* external_data =
9429 new ExternalStringData<uint8_t>(data, peer, callback); 9494 new ExternalStringData<uint8_t>(data, peer, callback);
9430 { 9495 {
9431 RawObject* raw = Object::Allocate(cls, 9496 RawObject* raw = Object::Allocate(cls,
9432 ExternalOneByteString::InstanceSize(), 9497 ExternalOneByteString::InstanceSize(),
9433 space); 9498 space);
(...skipping 29 matching lines...) Expand all
9463 } 9528 }
9464 9529
9465 9530
9466 RawExternalTwoByteString* ExternalTwoByteString::New( 9531 RawExternalTwoByteString* ExternalTwoByteString::New(
9467 const uint16_t* data, 9532 const uint16_t* data,
9468 intptr_t len, 9533 intptr_t len,
9469 void* peer, 9534 void* peer,
9470 Dart_PeerFinalizer callback, 9535 Dart_PeerFinalizer callback,
9471 Heap::Space space) { 9536 Heap::Space space) {
9472 Isolate* isolate = Isolate::Current(); 9537 Isolate* isolate = Isolate::Current();
9538 if (len < 0 || len > kMaxElements) {
9539 // This should be caught before we reach here.
9540 FATAL1("Fatal error in ExternalTwoByteString::New: invalid len %ld\n", len);
9541 }
9473 9542
9474 const Class& cls = 9543 const Class& cls =
9475 Class::Handle(isolate->object_store()->external_two_byte_string_class()); 9544 Class::Handle(isolate->object_store()->external_two_byte_string_class());
9476 ExternalTwoByteString& result = ExternalTwoByteString::Handle(); 9545 ExternalTwoByteString& result = ExternalTwoByteString::Handle();
9477 ExternalStringData<uint16_t>* external_data = 9546 ExternalStringData<uint16_t>* external_data =
9478 new ExternalStringData<uint16_t>(data, peer, callback); 9547 new ExternalStringData<uint16_t>(data, peer, callback);
9479 { 9548 {
9480 RawObject* raw = Object::Allocate(cls, 9549 RawObject* raw = Object::Allocate(cls,
9481 ExternalTwoByteString::InstanceSize(), 9550 ExternalTwoByteString::InstanceSize(),
9482 space); 9551 space);
(...skipping 19 matching lines...) Expand all
9502 } 9571 }
9503 9572
9504 9573
9505 RawExternalFourByteString* ExternalFourByteString::New( 9574 RawExternalFourByteString* ExternalFourByteString::New(
9506 const uint32_t* data, 9575 const uint32_t* data,
9507 intptr_t len, 9576 intptr_t len,
9508 void* peer, 9577 void* peer,
9509 Dart_PeerFinalizer callback, 9578 Dart_PeerFinalizer callback,
9510 Heap::Space space) { 9579 Heap::Space space) {
9511 Isolate* isolate = Isolate::Current(); 9580 Isolate* isolate = Isolate::Current();
9581 if (len < 0 || len > kMaxElements) {
9582 // This should be caught before we reach here.
9583 FATAL1("Fatal error in ExternalFourByteString::New: invalid len %ld\n",
9584 len);
9585 }
9512 9586
9513 const Class& cls = 9587 const Class& cls =
9514 Class::Handle(isolate->object_store()->external_four_byte_string_class()); 9588 Class::Handle(isolate->object_store()->external_four_byte_string_class());
9515 ExternalFourByteString& result = ExternalFourByteString::Handle(); 9589 ExternalFourByteString& result = ExternalFourByteString::Handle();
9516 ExternalStringData<uint32_t>* external_data = 9590 ExternalStringData<uint32_t>* external_data =
9517 new ExternalStringData<uint32_t>(data, peer, callback); 9591 new ExternalStringData<uint32_t>(data, peer, callback);
9518 { 9592 {
9519 RawObject* raw = Object::Allocate(cls, 9593 RawObject* raw = Object::Allocate(cls,
9520 ExternalFourByteString::InstanceSize(), 9594 ExternalFourByteString::InstanceSize(),
9521 space); 9595 space);
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
9607 9681
9608 9682
9609 RawArray* Array::New(intptr_t len, Heap::Space space) { 9683 RawArray* Array::New(intptr_t len, Heap::Space space) {
9610 ObjectStore* object_store = Isolate::Current()->object_store(); 9684 ObjectStore* object_store = Isolate::Current()->object_store();
9611 Class& cls = Class::Handle(object_store->array_class()); 9685 Class& cls = Class::Handle(object_store->array_class());
9612 return New(cls, len, space); 9686 return New(cls, len, space);
9613 } 9687 }
9614 9688
9615 9689
9616 RawArray* Array::New(const Class& cls, intptr_t len, Heap::Space space) { 9690 RawArray* Array::New(const Class& cls, intptr_t len, Heap::Space space) {
9617 if ((len < 0) || (len > kMaxArrayElements)) { 9691 if (len < 0 || len > Array::kMaxElements) {
9618 // TODO(srdjan): Verify that illegal argument is the right thing to throw. 9692 // This should be caught before we reach here.
9619 GrowableArray<const Object*> args; 9693 FATAL1("Fatal error in Array::New: invalid len %ld\n", len);
9620 args.Add(&Smi::Handle(Smi::New(len)));
9621 Exceptions::ThrowByType(Exceptions::kIllegalArgument, args);
9622 } 9694 }
9623 Array& result = Array::Handle(); 9695 Array& result = Array::Handle();
9624 { 9696 {
9625 RawObject* raw = Object::Allocate(cls, 9697 RawObject* raw = Object::Allocate(cls,
9626 Array::InstanceSize(len), 9698 Array::InstanceSize(len),
9627 space); 9699 space);
9628 NoGCScope no_gc; 9700 NoGCScope no_gc;
9629 result ^= raw; 9701 result ^= raw;
9630 result.SetLength(len); 9702 result.SetLength(len);
9631 } 9703 }
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
9911 } 9983 }
9912 9984
9913 9985
9914 template<typename HandleT, typename RawT, typename ElementT> 9986 template<typename HandleT, typename RawT, typename ElementT>
9915 RawT* ByteArray::NewExternalImpl(const Class& cls, 9987 RawT* ByteArray::NewExternalImpl(const Class& cls,
9916 ElementT* data, 9988 ElementT* data,
9917 intptr_t len, 9989 intptr_t len,
9918 void* peer, 9990 void* peer,
9919 Dart_PeerFinalizer callback, 9991 Dart_PeerFinalizer callback,
9920 Heap::Space space) { 9992 Heap::Space space) {
9993 if (len < 0) {
cshapiro 2012/07/17 22:54:30 This needs an upper bound, use the non-external on
turnidge 2012/07/18 18:17:04 Done.
9994 // This should be caught before we reach here.
9995 //
9996 // TODO(turnidge): Determine whether we need to check for a max here too.
9997 FATAL1("Fatal error in ByteArray::NewExternalImpl: invalid len %ld\n", len);
9998 }
9921 HandleT& result = HandleT::Handle(); 9999 HandleT& result = HandleT::Handle();
9922 ExternalByteArrayData<ElementT>* external_data = 10000 ExternalByteArrayData<ElementT>* external_data =
9923 new ExternalByteArrayData<ElementT>(data, peer, callback); 10001 new ExternalByteArrayData<ElementT>(data, peer, callback);
9924 { 10002 {
9925 RawObject* raw = Object::Allocate(cls, HandleT::InstanceSize(), space); 10003 RawObject* raw = Object::Allocate(cls, HandleT::InstanceSize(), space);
9926 NoGCScope no_gc; 10004 NoGCScope no_gc;
9927 result ^= raw; 10005 result ^= raw;
9928 result.SetLength(len); 10006 result.SetLength(len);
9929 result.SetExternalData(external_data); 10007 result.SetExternalData(external_data);
9930 } 10008 }
(...skipping 18 matching lines...) Expand all
9949 10027
9950 const char* ByteArray::ToCString() const { 10028 const char* ByteArray::ToCString() const {
9951 // ByteArray is an abstract class. 10029 // ByteArray is an abstract class.
9952 UNREACHABLE(); 10030 UNREACHABLE();
9953 return "ByteArray"; 10031 return "ByteArray";
9954 } 10032 }
9955 10033
9956 10034
9957 template<typename HandleT, typename RawT> 10035 template<typename HandleT, typename RawT>
9958 RawT* ByteArray::NewImpl(const Class& cls, intptr_t len, Heap::Space space) { 10036 RawT* ByteArray::NewImpl(const Class& cls, intptr_t len, Heap::Space space) {
10037 if (len < 0 || len > HandleT::kMaxElements) {
10038 // This should be caught before we reach here.
10039 FATAL1("Fatal error in ByteArray::NewImpl: invalid len %ld\n", len);
10040 }
9959 HandleT& result = HandleT::Handle(); 10041 HandleT& result = HandleT::Handle();
9960 { 10042 {
9961 RawObject* raw = Object::Allocate(cls, HandleT::InstanceSize(len), space); 10043 RawObject* raw = Object::Allocate(cls, HandleT::InstanceSize(len), space);
9962 NoGCScope no_gc; 10044 NoGCScope no_gc;
9963 result ^= raw; 10045 result ^= raw;
9964 result.SetLength(len); 10046 result.SetLength(len);
9965 if (len > 0) { 10047 if (len > 0) {
9966 memset(result.ByteAddr(0), 0, result.ByteLength()); 10048 memset(result.ByteAddr(0), 0, result.ByteLength());
9967 } 10049 }
9968 } 10050 }
9969 return result.raw(); 10051 return result.raw();
9970 } 10052 }
9971 10053
9972 10054
9973 template<typename HandleT, typename RawT, typename ElementT> 10055 template<typename HandleT, typename RawT, typename ElementT>
9974 RawT* ByteArray::NewImpl(const Class& cls, 10056 RawT* ByteArray::NewImpl(const Class& cls,
9975 const ElementT* data, 10057 const ElementT* data,
9976 intptr_t len, 10058 intptr_t len,
9977 Heap::Space space) { 10059 Heap::Space space) {
10060 if (len < 0 || len > HandleT::kMaxElements) {
10061 // This should be caught before we reach here.
10062 FATAL1("Fatal error in ByteArray::NewImpl: invalid len %ld\n", len);
10063 }
9978 HandleT& result = HandleT::Handle(); 10064 HandleT& result = HandleT::Handle();
9979 { 10065 {
9980 RawObject* raw = Object::Allocate(cls, HandleT::InstanceSize(len), space); 10066 RawObject* raw = Object::Allocate(cls, HandleT::InstanceSize(len), space);
9981 NoGCScope no_gc; 10067 NoGCScope no_gc;
9982 result ^= raw; 10068 result ^= raw;
9983 result.SetLength(len); 10069 result.SetLength(len);
9984 if (len > 0) { 10070 if (len > 0) {
9985 memmove(result.ByteAddr(0), data, result.ByteLength()); 10071 memmove(result.ByteAddr(0), data, result.ByteLength());
9986 } 10072 }
9987 } 10073 }
(...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after
10627 StorePointer(&raw_ptr()->pattern_, pattern.raw()); 10713 StorePointer(&raw_ptr()->pattern_, pattern.raw());
10628 } 10714 }
10629 10715
10630 10716
10631 void JSRegExp::set_num_bracket_expressions(intptr_t value) const { 10717 void JSRegExp::set_num_bracket_expressions(intptr_t value) const {
10632 raw_ptr()->num_bracket_expressions_ = Smi::New(value); 10718 raw_ptr()->num_bracket_expressions_ = Smi::New(value);
10633 } 10719 }
10634 10720
10635 10721
10636 RawJSRegExp* JSRegExp::New(intptr_t len, Heap::Space space) { 10722 RawJSRegExp* JSRegExp::New(intptr_t len, Heap::Space space) {
10723 if (len < 0 || len > kMaxElements) {
10724 // This should be caught before we reach here.
10725 FATAL1("Fatal error in JSRegexp::New: invalid len %ld\n", len);
10726 }
10637 const Class& cls = Class::Handle( 10727 const Class& cls = Class::Handle(
10638 Isolate::Current()->object_store()->jsregexp_class()); 10728 Isolate::Current()->object_store()->jsregexp_class());
10639 JSRegExp& result = JSRegExp::Handle(); 10729 JSRegExp& result = JSRegExp::Handle();
10640 { 10730 {
10641 RawObject* raw = Object::Allocate(cls, 10731 RawObject* raw = Object::Allocate(cls,
10642 JSRegExp::InstanceSize(len), 10732 JSRegExp::InstanceSize(len),
10643 space); 10733 space);
10644 NoGCScope no_gc; 10734 NoGCScope no_gc;
10645 result ^= raw; 10735 result ^= raw;
10646 result.set_type(kUnitialized); 10736 result.set_type(kUnitialized);
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
10711 const String& str = String::Handle(pattern()); 10801 const String& str = String::Handle(pattern());
10712 const char* format = "JSRegExp: pattern=%s flags=%s"; 10802 const char* format = "JSRegExp: pattern=%s flags=%s";
10713 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); 10803 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags());
10714 char* chars = reinterpret_cast<char*>( 10804 char* chars = reinterpret_cast<char*>(
10715 Isolate::Current()->current_zone()->Allocate(len + 1)); 10805 Isolate::Current()->current_zone()->Allocate(len + 1));
10716 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); 10806 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags());
10717 return chars; 10807 return chars;
10718 } 10808 }
10719 10809
10720 } // namespace dart 10810 } // namespace dart
OLDNEW
« vm/object.h ('K') | « vm/object.h ('k') | vm/object_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698