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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 | 55 |
56 MaybeObject* Heap::AllocateSymbol(Vector<const char> str, | 56 MaybeObject* Heap::AllocateSymbol(Vector<const char> str, |
57 int chars, | 57 int chars, |
58 uint32_t hash_field) { | 58 uint32_t hash_field) { |
59 unibrow::Utf8InputBuffer<> buffer(str.start(), | 59 unibrow::Utf8InputBuffer<> buffer(str.start(), |
60 static_cast<unsigned>(str.length())); | 60 static_cast<unsigned>(str.length())); |
61 return AllocateInternalSymbol(&buffer, chars, hash_field); | 61 return AllocateInternalSymbol(&buffer, chars, hash_field); |
62 } | 62 } |
63 | 63 |
64 | 64 |
| 65 MaybeObject* Heap::AllocateAsciiSymbol(Vector<const char> str, |
| 66 uint32_t hash_field) { |
| 67 if (str.length() > SeqAsciiString::kMaxLength) { |
| 68 return Failure::OutOfMemoryException(); |
| 69 } |
| 70 // Compute map and object size. |
| 71 Map* map = ascii_symbol_map(); |
| 72 int size = SeqAsciiString::SizeFor(str.length()); |
| 73 |
| 74 // Allocate string. |
| 75 Object* result; |
| 76 { MaybeObject* maybe_result = (size > MaxObjectSizeInPagedSpace()) |
| 77 ? lo_space_->AllocateRaw(size) |
| 78 : old_data_space_->AllocateRaw(size); |
| 79 if (!maybe_result->ToObject(&result)) return maybe_result; |
| 80 } |
| 81 |
| 82 reinterpret_cast<HeapObject*>(result)->set_map(map); |
| 83 // Set length and hash fields of the allocated string. |
| 84 String* answer = String::cast(result); |
| 85 answer->set_length(str.length()); |
| 86 answer->set_hash_field(hash_field); |
| 87 |
| 88 ASSERT_EQ(size, answer->Size()); |
| 89 |
| 90 // Fill in the characters. |
| 91 memcpy(answer->address() + SeqAsciiString::kHeaderSize, |
| 92 str.start(), str.length()); |
| 93 |
| 94 return answer; |
| 95 } |
| 96 |
| 97 |
| 98 MaybeObject* Heap::AllocateTwoByteSymbol(Vector<const uc16> str, |
| 99 uint32_t hash_field) { |
| 100 if (str.length() > SeqTwoByteString::kMaxLength) { |
| 101 return Failure::OutOfMemoryException(); |
| 102 } |
| 103 // Compute map and object size. |
| 104 Map* map = symbol_map(); |
| 105 int size = SeqTwoByteString::SizeFor(str.length()); |
| 106 |
| 107 // Allocate string. |
| 108 Object* result; |
| 109 { MaybeObject* maybe_result = (size > MaxObjectSizeInPagedSpace()) |
| 110 ? lo_space_->AllocateRaw(size) |
| 111 : old_data_space_->AllocateRaw(size); |
| 112 if (!maybe_result->ToObject(&result)) return maybe_result; |
| 113 } |
| 114 |
| 115 reinterpret_cast<HeapObject*>(result)->set_map(map); |
| 116 // Set length and hash fields of the allocated string. |
| 117 String* answer = String::cast(result); |
| 118 answer->set_length(str.length()); |
| 119 answer->set_hash_field(hash_field); |
| 120 |
| 121 ASSERT_EQ(size, answer->Size()); |
| 122 |
| 123 // Fill in the characters. |
| 124 memcpy(answer->address() + SeqTwoByteString::kHeaderSize, |
| 125 str.start(), str.length() * kUC16Size); |
| 126 |
| 127 return answer; |
| 128 } |
| 129 |
65 MaybeObject* Heap::CopyFixedArray(FixedArray* src) { | 130 MaybeObject* Heap::CopyFixedArray(FixedArray* src) { |
66 return CopyFixedArrayWithMap(src, src->map()); | 131 return CopyFixedArrayWithMap(src, src->map()); |
67 } | 132 } |
68 | 133 |
69 | 134 |
70 MaybeObject* Heap::AllocateRaw(int size_in_bytes, | 135 MaybeObject* Heap::AllocateRaw(int size_in_bytes, |
71 AllocationSpace space, | 136 AllocationSpace space, |
72 AllocationSpace retry_space) { | 137 AllocationSpace retry_space) { |
73 ASSERT(allocation_allowed_ && gc_state_ == NOT_IN_GC); | 138 ASSERT(allocation_allowed_ && gc_state_ == NOT_IN_GC); |
74 ASSERT(space != NEW_SPACE || | 139 ASSERT(space != NEW_SPACE || |
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
513 | 578 |
514 | 579 |
515 void ExternalStringTable::ShrinkNewStrings(int position) { | 580 void ExternalStringTable::ShrinkNewStrings(int position) { |
516 new_space_strings_.Rewind(position); | 581 new_space_strings_.Rewind(position); |
517 Verify(); | 582 Verify(); |
518 } | 583 } |
519 | 584 |
520 } } // namespace v8::internal | 585 } } // namespace v8::internal |
521 | 586 |
522 #endif // V8_HEAP_INL_H_ | 587 #endif // V8_HEAP_INL_H_ |
OLD | NEW |