| 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/cpu.h" | 10 #include "vm/cpu.h" |
| (...skipping 1669 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1680 } | 1680 } |
| 1681 } | 1681 } |
| 1682 #endif | 1682 #endif |
| 1683 } | 1683 } |
| 1684 | 1684 |
| 1685 | 1685 |
| 1686 RawObject* Object::Allocate(intptr_t cls_id, | 1686 RawObject* Object::Allocate(intptr_t cls_id, |
| 1687 intptr_t size, | 1687 intptr_t size, |
| 1688 Heap::Space space) { | 1688 Heap::Space space) { |
| 1689 ASSERT(Utils::IsAligned(size, kObjectAlignment)); | 1689 ASSERT(Utils::IsAligned(size, kObjectAlignment)); |
| 1690 Isolate* isolate = Isolate::Current(); | 1690 Thread* thread = Thread::Current(); |
| 1691 Isolate* isolate = thread->isolate(); |
| 1691 ASSERT(isolate->no_callback_scope_depth() == 0); | 1692 ASSERT(isolate->no_callback_scope_depth() == 0); |
| 1692 Heap* heap = isolate->heap(); | 1693 Heap* heap = isolate->heap(); |
| 1693 | 1694 |
| 1694 uword address = heap->Allocate(size, space); | 1695 uword address = heap->Allocate(size, space); |
| 1695 if (address == 0) { | 1696 if (address == 0) { |
| 1696 // Use the preallocated out of memory exception to avoid calling | 1697 // Use the preallocated out of memory exception to avoid calling |
| 1697 // into dart code or allocating any code. | 1698 // into dart code or allocating any code. |
| 1698 const Instance& exception = | 1699 const Instance& exception = |
| 1699 Instance::Handle(isolate->object_store()->out_of_memory()); | 1700 Instance::Handle(isolate->object_store()->out_of_memory()); |
| 1700 Exceptions::Throw(isolate, exception); | 1701 Exceptions::Throw(thread, exception); |
| 1701 UNREACHABLE(); | 1702 UNREACHABLE(); |
| 1702 } | 1703 } |
| 1703 if (space == Heap::kNew) { | 1704 if (space == Heap::kNew) { |
| 1704 isolate->class_table()->UpdateAllocatedNew(cls_id, size); | 1705 isolate->class_table()->UpdateAllocatedNew(cls_id, size); |
| 1705 } else { | 1706 } else { |
| 1706 isolate->class_table()->UpdateAllocatedOld(cls_id, size); | 1707 isolate->class_table()->UpdateAllocatedOld(cls_id, size); |
| 1707 } | 1708 } |
| 1708 NoSafepointScope no_safepoint; | 1709 NoSafepointScope no_safepoint; |
| 1709 InitializeObject(address, cls_id, size); | 1710 InitializeObject(address, cls_id, size); |
| 1710 RawObject* raw_obj = reinterpret_cast<RawObject*>(address + kHeapObjectTag); | 1711 RawObject* raw_obj = reinterpret_cast<RawObject*>(address + kHeapObjectTag); |
| (...skipping 15582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 17293 | 17294 |
| 17294 | 17295 |
| 17295 const char* Bigint::ToDecCString(uword (*allocator)(intptr_t size)) const { | 17296 const char* Bigint::ToDecCString(uword (*allocator)(intptr_t size)) const { |
| 17296 // log10(2) ~= 0.30102999566398114. | 17297 // log10(2) ~= 0.30102999566398114. |
| 17297 const intptr_t kLog2Dividend = 30103; | 17298 const intptr_t kLog2Dividend = 30103; |
| 17298 const intptr_t kLog2Divisor = 100000; | 17299 const intptr_t kLog2Divisor = 100000; |
| 17299 intptr_t used = Used(); | 17300 intptr_t used = Used(); |
| 17300 const intptr_t kMaxUsed = | 17301 const intptr_t kMaxUsed = |
| 17301 kIntptrMax / kBitsPerDigit / kLog2Dividend * kLog2Divisor; | 17302 kIntptrMax / kBitsPerDigit / kLog2Dividend * kLog2Divisor; |
| 17302 if (used > kMaxUsed) { | 17303 if (used > kMaxUsed) { |
| 17303 // Throw out of memory exception. | 17304 Exceptions::ThrowOOM(); |
| 17304 Isolate* isolate = Isolate::Current(); | |
| 17305 const Instance& exception = | |
| 17306 Instance::Handle(isolate->object_store()->out_of_memory()); | |
| 17307 Exceptions::Throw(isolate, exception); | |
| 17308 UNREACHABLE(); | 17305 UNREACHABLE(); |
| 17309 } | 17306 } |
| 17310 const int64_t bit_len = used * kBitsPerDigit; | 17307 const int64_t bit_len = used * kBitsPerDigit; |
| 17311 const int64_t dec_len = (bit_len * kLog2Dividend / kLog2Divisor) + 1; | 17308 const int64_t dec_len = (bit_len * kLog2Dividend / kLog2Divisor) + 1; |
| 17312 // Add one byte for the minus sign and for the trailing \0 character. | 17309 // Add one byte for the minus sign and for the trailing \0 character. |
| 17313 const int64_t len = (Neg() ? 1 : 0) + dec_len + 1; | 17310 const int64_t len = (Neg() ? 1 : 0) + dec_len + 1; |
| 17314 char* chars = reinterpret_cast<char*>(allocator(len)); | 17311 char* chars = reinterpret_cast<char*>(allocator(len)); |
| 17315 intptr_t pos = 0; | 17312 intptr_t pos = 0; |
| 17316 const intptr_t kDivisor = 100000000; | 17313 const intptr_t kDivisor = 100000000; |
| 17317 const intptr_t kDigits = 8; | 17314 const intptr_t kDigits = 8; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 17375 const char* zero = "0x0"; | 17372 const char* zero = "0x0"; |
| 17376 const size_t len = strlen(zero) + 1; | 17373 const size_t len = strlen(zero) + 1; |
| 17377 char* chars = reinterpret_cast<char*>(allocator(len)); | 17374 char* chars = reinterpret_cast<char*>(allocator(len)); |
| 17378 strncpy(chars, zero, len); | 17375 strncpy(chars, zero, len); |
| 17379 return chars; | 17376 return chars; |
| 17380 } | 17377 } |
| 17381 const int kBitsPerHexDigit = 4; | 17378 const int kBitsPerHexDigit = 4; |
| 17382 const int kHexDigitsPerDigit = 8; | 17379 const int kHexDigitsPerDigit = 8; |
| 17383 const intptr_t kMaxUsed = (kIntptrMax - 4) / kHexDigitsPerDigit; | 17380 const intptr_t kMaxUsed = (kIntptrMax - 4) / kHexDigitsPerDigit; |
| 17384 if (used > kMaxUsed) { | 17381 if (used > kMaxUsed) { |
| 17385 // Throw out of memory exception. | 17382 Exceptions::ThrowOOM(); |
| 17386 Isolate* isolate = Isolate::Current(); | |
| 17387 const Instance& exception = | |
| 17388 Instance::Handle(isolate->object_store()->out_of_memory()); | |
| 17389 Exceptions::Throw(isolate, exception); | |
| 17390 UNREACHABLE(); | 17383 UNREACHABLE(); |
| 17391 } | 17384 } |
| 17392 intptr_t hex_len = (used - 1) * kHexDigitsPerDigit; | 17385 intptr_t hex_len = (used - 1) * kHexDigitsPerDigit; |
| 17393 // The most significant digit may use fewer than kHexDigitsPerDigit digits. | 17386 // The most significant digit may use fewer than kHexDigitsPerDigit digits. |
| 17394 uint32_t digit = DigitAt(used - 1); | 17387 uint32_t digit = DigitAt(used - 1); |
| 17395 ASSERT(digit != 0); // Value must be clamped. | 17388 ASSERT(digit != 0); // Value must be clamped. |
| 17396 while (digit != 0) { | 17389 while (digit != 0) { |
| 17397 hex_len++; | 17390 hex_len++; |
| 17398 digit >>= kBitsPerHexDigit; | 17391 digit >>= kBitsPerHexDigit; |
| 17399 } | 17392 } |
| (...skipping 752 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 18152 ASSERT(start >= 0); | 18145 ASSERT(start >= 0); |
| 18153 ASSERT(end <= strings.Length()); | 18146 ASSERT(end <= strings.Length()); |
| 18154 intptr_t result_len = 0; | 18147 intptr_t result_len = 0; |
| 18155 String& str = String::Handle(); | 18148 String& str = String::Handle(); |
| 18156 intptr_t char_size = kOneByteChar; | 18149 intptr_t char_size = kOneByteChar; |
| 18157 // Compute 'char_size' and 'result_len'. | 18150 // Compute 'char_size' and 'result_len'. |
| 18158 for (intptr_t i = start; i < end; i++) { | 18151 for (intptr_t i = start; i < end; i++) { |
| 18159 str ^= strings.At(i); | 18152 str ^= strings.At(i); |
| 18160 const intptr_t str_len = str.Length(); | 18153 const intptr_t str_len = str.Length(); |
| 18161 if ((kMaxElements - result_len) < str_len) { | 18154 if ((kMaxElements - result_len) < str_len) { |
| 18162 Isolate* isolate = Isolate::Current(); | 18155 Exceptions::ThrowOOM(); |
| 18163 const Instance& exception = | |
| 18164 Instance::Handle(isolate->object_store()->out_of_memory()); | |
| 18165 Exceptions::Throw(isolate, exception); | |
| 18166 UNREACHABLE(); | 18156 UNREACHABLE(); |
| 18167 } | 18157 } |
| 18168 result_len += str_len; | 18158 result_len += str_len; |
| 18169 char_size = Utils::Maximum(char_size, str.CharSize()); | 18159 char_size = Utils::Maximum(char_size, str.CharSize()); |
| 18170 } | 18160 } |
| 18171 if (char_size == kOneByteChar) { | 18161 if (char_size == kOneByteChar) { |
| 18172 return OneByteString::ConcatAll(strings, start, end, result_len, space); | 18162 return OneByteString::ConcatAll(strings, start, end, result_len, space); |
| 18173 } | 18163 } |
| 18174 ASSERT(char_size == kTwoByteChar); | 18164 ASSERT(char_size == kTwoByteChar); |
| 18175 return TwoByteString::ConcatAll(strings, start, end, result_len, space); | 18165 return TwoByteString::ConcatAll(strings, start, end, result_len, space); |
| (...skipping 1243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 19419 return reinterpret_cast<RawImmutableArray*>(Array::New(kClassId, len, space)); | 19409 return reinterpret_cast<RawImmutableArray*>(Array::New(kClassId, len, space)); |
| 19420 } | 19410 } |
| 19421 | 19411 |
| 19422 | 19412 |
| 19423 void GrowableObjectArray::Add(const Object& value, Heap::Space space) const { | 19413 void GrowableObjectArray::Add(const Object& value, Heap::Space space) const { |
| 19424 ASSERT(!IsNull()); | 19414 ASSERT(!IsNull()); |
| 19425 if (Length() == Capacity()) { | 19415 if (Length() == Capacity()) { |
| 19426 // TODO(Issue 2500): Need a better growth strategy. | 19416 // TODO(Issue 2500): Need a better growth strategy. |
| 19427 intptr_t new_capacity = (Capacity() == 0) ? 4 : Capacity() * 2; | 19417 intptr_t new_capacity = (Capacity() == 0) ? 4 : Capacity() * 2; |
| 19428 if (new_capacity <= Capacity()) { | 19418 if (new_capacity <= Capacity()) { |
| 19429 // Use the preallocated out of memory exception to avoid calling | 19419 Exceptions::ThrowOOM(); |
| 19430 // into dart code or allocating any code. | |
| 19431 Isolate* isolate = Isolate::Current(); | |
| 19432 const Instance& exception = | |
| 19433 Instance::Handle(isolate->object_store()->out_of_memory()); | |
| 19434 Exceptions::Throw(isolate, exception); | |
| 19435 UNREACHABLE(); | 19420 UNREACHABLE(); |
| 19436 } | 19421 } |
| 19437 Grow(new_capacity, space); | 19422 Grow(new_capacity, space); |
| 19438 } | 19423 } |
| 19439 ASSERT(Length() < Capacity()); | 19424 ASSERT(Length() < Capacity()); |
| 19440 intptr_t index = Length(); | 19425 intptr_t index = Length(); |
| 19441 SetLength(index + 1); | 19426 SetLength(index + 1); |
| 19442 SetAt(index, value); | 19427 SetAt(index, value); |
| 19443 } | 19428 } |
| 19444 | 19429 |
| (...skipping 1356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 20801 return tag_label.ToCString(); | 20786 return tag_label.ToCString(); |
| 20802 } | 20787 } |
| 20803 | 20788 |
| 20804 | 20789 |
| 20805 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { | 20790 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { |
| 20806 Instance::PrintJSONImpl(stream, ref); | 20791 Instance::PrintJSONImpl(stream, ref); |
| 20807 } | 20792 } |
| 20808 | 20793 |
| 20809 | 20794 |
| 20810 } // namespace dart | 20795 } // namespace dart |
| OLD | NEW |