| OLD | NEW |
| 1 // Copyright 2006-2010 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2010 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 #include "write-buffer.h" | 34 #include "write-buffer.h" |
| 35 | 35 |
| 36 namespace v8 { | 36 namespace v8 { |
| 37 namespace internal { | 37 namespace internal { |
| 38 | 38 |
| 39 int Heap::MaxObjectSizeInPagedSpace() { | 39 int Heap::MaxObjectSizeInPagedSpace() { |
| 40 return Page::kMaxHeapObjectSize; | 40 return Page::kMaxHeapObjectSize; |
| 41 } | 41 } |
| 42 | 42 |
| 43 | 43 |
| 44 MaybeObject* Heap::AllocateStringFromUtf8(Vector<const char> str, |
| 45 PretenureFlag pretenure) { |
| 46 // Check for ASCII first since this is the common case. |
| 47 if (String::IsAscii(str.start(), str.length())) { |
| 48 // If the string is ASCII, we do not need to convert the characters |
| 49 // since UTF8 is backwards compatible with ASCII. |
| 50 return AllocateStringFromAscii(str, pretenure); |
| 51 } |
| 52 // Non-ASCII and we need to decode. |
| 53 return AllocateStringFromUtf8Slow(str, pretenure); |
| 54 } |
| 55 |
| 56 |
| 44 MaybeObject* Heap::AllocateSymbol(Vector<const char> str, | 57 MaybeObject* Heap::AllocateSymbol(Vector<const char> str, |
| 45 int chars, | 58 int chars, |
| 46 uint32_t hash_field) { | 59 uint32_t hash_field) { |
| 47 unibrow::Utf8InputBuffer<> buffer(str.start(), | 60 unibrow::Utf8InputBuffer<> buffer(str.start(), |
| 48 static_cast<unsigned>(str.length())); | 61 static_cast<unsigned>(str.length())); |
| 49 return AllocateInternalSymbol(&buffer, chars, hash_field); | 62 return AllocateInternalSymbol(&buffer, chars, hash_field); |
| 50 } | 63 } |
| 51 | 64 |
| 52 | 65 |
| 66 MaybeObject* Heap::AllocateAsciiSymbol(Vector<const char> str, |
| 67 uint32_t hash_field) { |
| 68 if (str.length() > SeqAsciiString::kMaxLength) { |
| 69 return Failure::OutOfMemoryException(); |
| 70 } |
| 71 // Compute map and object size. |
| 72 Map* map = ascii_symbol_map(); |
| 73 int size = SeqAsciiString::SizeFor(str.length()); |
| 74 |
| 75 // Allocate string. |
| 76 Object* result; |
| 77 { MaybeObject* maybe_result = (size > MaxObjectSizeInPagedSpace()) |
| 78 ? lo_space_->AllocateRaw(size) |
| 79 : old_data_space_->AllocateRaw(size); |
| 80 if (!maybe_result->ToObject(&result)) return maybe_result; |
| 81 } |
| 82 |
| 83 reinterpret_cast<HeapObject*>(result)->set_map(map); |
| 84 // Set length and hash fields of the allocated string. |
| 85 String* answer = String::cast(result); |
| 86 answer->set_length(str.length()); |
| 87 answer->set_hash_field(hash_field); |
| 88 |
| 89 ASSERT_EQ(size, answer->Size()); |
| 90 |
| 91 // Fill in the characters. |
| 92 memcpy(answer->address() + SeqAsciiString::kHeaderSize, |
| 93 str.start(), str.length()); |
| 94 |
| 95 return answer; |
| 96 } |
| 97 |
| 98 |
| 99 MaybeObject* Heap::AllocateTwoByteSymbol(Vector<const uc16> str, |
| 100 uint32_t hash_field) { |
| 101 if (str.length() > SeqTwoByteString::kMaxLength) { |
| 102 return Failure::OutOfMemoryException(); |
| 103 } |
| 104 // Compute map and object size. |
| 105 Map* map = symbol_map(); |
| 106 int size = SeqTwoByteString::SizeFor(str.length()); |
| 107 |
| 108 // Allocate string. |
| 109 Object* result; |
| 110 { MaybeObject* maybe_result = (size > MaxObjectSizeInPagedSpace()) |
| 111 ? lo_space_->AllocateRaw(size) |
| 112 : old_data_space_->AllocateRaw(size); |
| 113 if (!maybe_result->ToObject(&result)) return maybe_result; |
| 114 } |
| 115 |
| 116 reinterpret_cast<HeapObject*>(result)->set_map(map); |
| 117 // Set length and hash fields of the allocated string. |
| 118 String* answer = String::cast(result); |
| 119 answer->set_length(str.length()); |
| 120 answer->set_hash_field(hash_field); |
| 121 |
| 122 ASSERT_EQ(size, answer->Size()); |
| 123 |
| 124 // Fill in the characters. |
| 125 memcpy(answer->address() + SeqTwoByteString::kHeaderSize, |
| 126 str.start(), str.length() * kUC16Size); |
| 127 |
| 128 return answer; |
| 129 } |
| 130 |
| 53 MaybeObject* Heap::CopyFixedArray(FixedArray* src) { | 131 MaybeObject* Heap::CopyFixedArray(FixedArray* src) { |
| 54 return CopyFixedArrayWithMap(src, src->map()); | 132 return CopyFixedArrayWithMap(src, src->map()); |
| 55 } | 133 } |
| 56 | 134 |
| 57 | 135 |
| 58 MaybeObject* Heap::AllocateRaw(int size_in_bytes, | 136 MaybeObject* Heap::AllocateRaw(int size_in_bytes, |
| 59 AllocationSpace space, | 137 AllocationSpace space, |
| 60 AllocationSpace retry_space) { | 138 AllocationSpace retry_space) { |
| 61 ASSERT(allocation_allowed_ && gc_state_ == NOT_IN_GC); | 139 ASSERT(allocation_allowed_ && gc_state_ == NOT_IN_GC); |
| 62 ASSERT(space != NEW_SPACE || | 140 ASSERT(space != NEW_SPACE || |
| (...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 #define CALL_HEAP_FUNCTION(FUNCTION_CALL, TYPE) \ | 518 #define CALL_HEAP_FUNCTION(FUNCTION_CALL, TYPE) \ |
| 441 CALL_AND_RETRY(FUNCTION_CALL, \ | 519 CALL_AND_RETRY(FUNCTION_CALL, \ |
| 442 return Handle<TYPE>(TYPE::cast(__object__)), \ | 520 return Handle<TYPE>(TYPE::cast(__object__)), \ |
| 443 return Handle<TYPE>()) | 521 return Handle<TYPE>()) |
| 444 | 522 |
| 445 | 523 |
| 446 #define CALL_HEAP_FUNCTION_VOID(FUNCTION_CALL) \ | 524 #define CALL_HEAP_FUNCTION_VOID(FUNCTION_CALL) \ |
| 447 CALL_AND_RETRY(FUNCTION_CALL, return, return) | 525 CALL_AND_RETRY(FUNCTION_CALL, return, return) |
| 448 | 526 |
| 449 | 527 |
| 528 #define CALL_HEAP_FUNCTION_INLINE(FUNCTION_CALL) \ |
| 529 CALL_AND_RETRY(FUNCTION_CALL, break, break) |
| 530 |
| 531 |
| 450 #ifdef DEBUG | 532 #ifdef DEBUG |
| 451 | 533 |
| 452 inline bool Heap::allow_allocation(bool new_state) { | 534 inline bool Heap::allow_allocation(bool new_state) { |
| 453 bool old = allocation_allowed_; | 535 bool old = allocation_allowed_; |
| 454 allocation_allowed_ = new_state; | 536 allocation_allowed_ = new_state; |
| 455 return old; | 537 return old; |
| 456 } | 538 } |
| 457 | 539 |
| 458 #endif | 540 #endif |
| 459 | 541 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 504 | 586 |
| 505 | 587 |
| 506 void ExternalStringTable::ShrinkNewStrings(int position) { | 588 void ExternalStringTable::ShrinkNewStrings(int position) { |
| 507 new_space_strings_.Rewind(position); | 589 new_space_strings_.Rewind(position); |
| 508 Verify(); | 590 Verify(); |
| 509 } | 591 } |
| 510 | 592 |
| 511 } } // namespace v8::internal | 593 } } // namespace v8::internal |
| 512 | 594 |
| 513 #endif // V8_HEAP_INL_H_ | 595 #endif // V8_HEAP_INL_H_ |
| OLD | NEW |