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 "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 8308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8319 // that it can be traversed over successfully during garbage collection. | 8319 // that it can be traversed over successfully during garbage collection. |
8320 if (capacity_size != used_size) { | 8320 if (capacity_size != used_size) { |
8321 NoGCScope no_gc; | 8321 NoGCScope no_gc; |
8322 ASSERT(capacity_len > used_len); | 8322 ASSERT(capacity_len > used_len); |
8323 intptr_t leftover_size = capacity_size - used_size; | 8323 intptr_t leftover_size = capacity_size - used_size; |
8324 | 8324 |
8325 uword addr = RawObject::ToAddr(array.raw()) + used_size; | 8325 uword addr = RawObject::ToAddr(array.raw()) + used_size; |
8326 if (leftover_size >= Array::InstanceSize(0)) { | 8326 if (leftover_size >= Array::InstanceSize(0)) { |
8327 // As we have enough space to use an array object, update the leftover | 8327 // As we have enough space to use an array object, update the leftover |
8328 // space as an Array object. | 8328 // space as an Array object. |
8329 new_array.raw_ = reinterpret_cast<RawArray*>(RawObject::FromAddr(addr)); | 8329 RawArray* raw = reinterpret_cast<RawArray*>(RawObject::FromAddr(addr)); |
8330 new_array.raw_ptr()->class_ = isolate->object_store()->array_class(); | 8330 raw->ptr()->class_ = isolate->object_store()->array_class(); |
8331 tags = RawObject::SizeTag::update(leftover_size, tags); | 8331 tags = RawObject::SizeTag::update(leftover_size, tags); |
8332 new_array.raw_ptr()->tags_ = tags; | 8332 raw->ptr()->tags_ = tags; |
8333 intptr_t leftover_len = | 8333 intptr_t leftover_len = |
8334 ((leftover_size - Array::InstanceSize(0)) / kWordSize); | 8334 ((leftover_size - Array::InstanceSize(0)) / kWordSize); |
8335 new_array.SetLength(leftover_len); | 8335 raw->ptr()->tags_ = tags; |
| 8336 raw->ptr()->length_ = Smi::New(leftover_len); |
8336 } else { | 8337 } else { |
8337 // Update the leftover space as a basic object. | 8338 // Update the leftover space as a basic object. |
8338 ASSERT(leftover_size == Object::InstanceSize()); | 8339 ASSERT(leftover_size == Object::InstanceSize()); |
8339 Object& new_object = Object::Handle(isolate, RawObject::FromAddr(addr)); | 8340 RawObject* raw = reinterpret_cast<RawObject*>(RawObject::FromAddr(addr)); |
8340 new_object.raw()->ptr()->class_ = isolate->object_store()->object_class(); | 8341 raw->ptr()->class_ = isolate->object_store()->object_class(); |
8341 tags = RawObject::SizeTag::update(leftover_size, tags); | 8342 tags = RawObject::SizeTag::update(leftover_size, tags); |
8342 new_object.raw()->ptr()->tags_ = tags; | 8343 raw->ptr()->tags_ = tags; |
8343 } | 8344 } |
8344 } | 8345 } |
8345 return array.raw(); | 8346 return array.raw(); |
8346 } | 8347 } |
8347 | 8348 |
8348 | 8349 |
8349 RawImmutableArray* ImmutableArray::New(intptr_t len, | 8350 RawImmutableArray* ImmutableArray::New(intptr_t len, |
8350 Heap::Space space) { | 8351 Heap::Space space) { |
8351 ObjectStore* object_store = Isolate::Current()->object_store(); | 8352 ObjectStore* object_store = Isolate::Current()->object_store(); |
8352 Class& cls = Class::Handle(object_store->immutable_array_class()); | 8353 Class& cls = Class::Handle(object_store->immutable_array_class()); |
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8902 const String& str = String::Handle(pattern()); | 8903 const String& str = String::Handle(pattern()); |
8903 const char* format = "JSRegExp: pattern=%s flags=%s"; | 8904 const char* format = "JSRegExp: pattern=%s flags=%s"; |
8904 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); | 8905 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); |
8905 char* chars = reinterpret_cast<char*>( | 8906 char* chars = reinterpret_cast<char*>( |
8906 Isolate::Current()->current_zone()->Allocate(len + 1)); | 8907 Isolate::Current()->current_zone()->Allocate(len + 1)); |
8907 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); | 8908 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); |
8908 return chars; | 8909 return chars; |
8909 } | 8910 } |
8910 | 8911 |
8911 } // namespace dart | 8912 } // namespace dart |
OLD | NEW |