| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 | 77 |
| 78 // semispace_size_ should be a power of 2 and old_generation_size_ should be | 78 // semispace_size_ should be a power of 2 and old_generation_size_ should be |
| 79 // a multiple of Page::kPageSize. | 79 // a multiple of Page::kPageSize. |
| 80 int Heap::semispace_size_ = 2*MB; | 80 int Heap::semispace_size_ = 2*MB; |
| 81 int Heap::old_generation_size_ = 512*MB; | 81 int Heap::old_generation_size_ = 512*MB; |
| 82 int Heap::initial_semispace_size_ = 256*KB; | 82 int Heap::initial_semispace_size_ = 256*KB; |
| 83 | 83 |
| 84 GCCallback Heap::global_gc_prologue_callback_ = NULL; | 84 GCCallback Heap::global_gc_prologue_callback_ = NULL; |
| 85 GCCallback Heap::global_gc_epilogue_callback_ = NULL; | 85 GCCallback Heap::global_gc_epilogue_callback_ = NULL; |
| 86 | 86 |
| 87 ExternalSymbolCallback Heap::global_external_symbol_callback_ = NULL; |
| 88 |
| 87 // Variables set based on semispace_size_ and old_generation_size_ in | 89 // Variables set based on semispace_size_ and old_generation_size_ in |
| 88 // ConfigureHeap. | 90 // ConfigureHeap. |
| 89 int Heap::young_generation_size_ = 0; // Will be 2 * semispace_size_. | 91 int Heap::young_generation_size_ = 0; // Will be 2 * semispace_size_. |
| 90 | 92 |
| 91 // Double the new space after this many scavenge collections. | 93 // Double the new space after this many scavenge collections. |
| 92 int Heap::new_space_growth_limit_ = 8; | 94 int Heap::new_space_growth_limit_ = 8; |
| 93 int Heap::scavenge_count_ = 0; | 95 int Heap::scavenge_count_ = 0; |
| 94 Heap::HeapState Heap::gc_state_ = NOT_IN_GC; | 96 Heap::HeapState Heap::gc_state_ = NOT_IN_GC; |
| 95 | 97 |
| 96 int Heap::mc_count_ = 0; | 98 int Heap::mc_count_ = 0; |
| (...skipping 1438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1535 if (result->IsFailure()) return result; | 1537 if (result->IsFailure()) return result; |
| 1536 | 1538 |
| 1537 ExternalTwoByteString* external_string = ExternalTwoByteString::cast(result); | 1539 ExternalTwoByteString* external_string = ExternalTwoByteString::cast(result); |
| 1538 external_string->set_length(length); | 1540 external_string->set_length(length); |
| 1539 external_string->set_resource(resource); | 1541 external_string->set_resource(resource); |
| 1540 | 1542 |
| 1541 return result; | 1543 return result; |
| 1542 } | 1544 } |
| 1543 | 1545 |
| 1544 | 1546 |
| 1547 Object* Heap::AllocateExternalSymbolFromTwoByte( |
| 1548 ExternalTwoByteString::Resource* resource) { |
| 1549 Map* map; |
| 1550 int length = resource->length(); |
| 1551 if (length <= String::kMaxShortStringSize) { |
| 1552 map = short_external_symbol_map(); |
| 1553 } else if (length <= String::kMaxMediumStringSize) { |
| 1554 map = medium_external_symbol_map(); |
| 1555 } else { |
| 1556 map = long_external_symbol_map(); |
| 1557 } |
| 1558 |
| 1559 Object* result = Allocate(map, OLD_DATA_SPACE); |
| 1560 if (result->IsFailure()) return result; |
| 1561 |
| 1562 ExternalTwoByteString* external_string = ExternalTwoByteString::cast(result); |
| 1563 external_string->set_length(length); |
| 1564 external_string->set_resource(resource); |
| 1565 |
| 1566 return result; |
| 1567 } |
| 1568 |
| 1569 |
| 1545 Object* Heap::LookupSingleCharacterStringFromCode(uint16_t code) { | 1570 Object* Heap::LookupSingleCharacterStringFromCode(uint16_t code) { |
| 1546 if (code <= String::kMaxAsciiCharCode) { | 1571 if (code <= String::kMaxAsciiCharCode) { |
| 1547 Object* value = Heap::single_character_string_cache()->get(code); | 1572 Object* value = Heap::single_character_string_cache()->get(code); |
| 1548 if (value != Heap::undefined_value()) return value; | 1573 if (value != Heap::undefined_value()) return value; |
| 1549 | 1574 |
| 1550 char buffer[1]; | 1575 char buffer[1]; |
| 1551 buffer[0] = static_cast<char>(code); | 1576 buffer[0] = static_cast<char>(code); |
| 1552 Object* result = LookupSymbol(Vector<const char>(buffer, 1)); | 1577 Object* result = LookupSymbol(Vector<const char>(buffer, 1)); |
| 1553 | 1578 |
| 1554 if (result->IsFailure()) return result; | 1579 if (result->IsFailure()) return result; |
| (...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2046 } | 2071 } |
| 2047 if (map == long_external_ascii_string_map()) { | 2072 if (map == long_external_ascii_string_map()) { |
| 2048 return long_external_ascii_string_map(); | 2073 return long_external_ascii_string_map(); |
| 2049 } | 2074 } |
| 2050 | 2075 |
| 2051 // No match found. | 2076 // No match found. |
| 2052 return NULL; | 2077 return NULL; |
| 2053 } | 2078 } |
| 2054 | 2079 |
| 2055 | 2080 |
| 2056 Object* Heap::AllocateSymbol(unibrow::CharacterStream* buffer, | 2081 Object* Heap::AllocateInternalSymbol(unibrow::CharacterStream* buffer, |
| 2057 int chars, | 2082 int chars, |
| 2058 uint32_t length_field) { | 2083 uint32_t length_field) { |
| 2059 // Ensure the chars matches the number of characters in the buffer. | 2084 // Ensure the chars matches the number of characters in the buffer. |
| 2060 ASSERT(static_cast<unsigned>(chars) == buffer->Length()); | 2085 ASSERT(static_cast<unsigned>(chars) == buffer->Length()); |
| 2061 // Determine whether the string is ascii. | 2086 // Determine whether the string is ascii. |
| 2062 bool is_ascii = true; | 2087 bool is_ascii = true; |
| 2063 while (buffer->has_more()) { | 2088 while (buffer->has_more()) { |
| 2064 if (buffer->GetNext() > unibrow::Utf8::kMaxOneByteChar) is_ascii = false; | 2089 if (buffer->GetNext() > unibrow::Utf8::kMaxOneByteChar) is_ascii = false; |
| 2065 } | 2090 } |
| 2066 buffer->Rewind(); | 2091 buffer->Rewind(); |
| 2067 | 2092 |
| 2068 // Compute map and object size. | 2093 // Compute map and object size. |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2104 ASSERT_EQ(size, answer->Size()); | 2129 ASSERT_EQ(size, answer->Size()); |
| 2105 | 2130 |
| 2106 // Fill in the characters. | 2131 // Fill in the characters. |
| 2107 for (int i = 0; i < chars; i++) { | 2132 for (int i = 0; i < chars; i++) { |
| 2108 answer->Set(answer_shape, i, buffer->GetNext()); | 2133 answer->Set(answer_shape, i, buffer->GetNext()); |
| 2109 } | 2134 } |
| 2110 return answer; | 2135 return answer; |
| 2111 } | 2136 } |
| 2112 | 2137 |
| 2113 | 2138 |
| 2139 // External string resource that only contains a length field. These |
| 2140 // are used temporarily when allocating external symbols. |
| 2141 class DummyExternalStringResource |
| 2142 : public v8::String::ExternalStringResource { |
| 2143 public: |
| 2144 explicit DummyExternalStringResource(size_t length) : length_(length) { } |
| 2145 |
| 2146 virtual const uint16_t* data() const { |
| 2147 UNREACHABLE(); |
| 2148 return NULL; |
| 2149 } |
| 2150 |
| 2151 virtual size_t length() const { return length_; } |
| 2152 private: |
| 2153 size_t length_; |
| 2154 }; |
| 2155 |
| 2156 |
| 2157 Object* Heap::AllocateExternalSymbol(Vector<const char> string, int chars) { |
| 2158 // Attempt to allocate the resulting external string first. Use a |
| 2159 // dummy string resource that has the correct length so that we only |
| 2160 // have to patch the external string resource after the callback. |
| 2161 DummyExternalStringResource dummy_resource(chars); |
| 2162 Object* obj = AllocateExternalSymbolFromTwoByte(&dummy_resource); |
| 2163 if (obj->IsFailure()) return obj; |
| 2164 // Perform callback. |
| 2165 v8::String::ExternalStringResource* resource = |
| 2166 global_external_symbol_callback_(string.start(), string.length()); |
| 2167 // Patch the resource pointer of the result. |
| 2168 ExternalTwoByteString* result = ExternalTwoByteString::cast(obj); |
| 2169 result->set_resource(resource); |
| 2170 // Force hash code to be computed. |
| 2171 result->Hash(); |
| 2172 ASSERT(result->IsEqualTo(string)); |
| 2173 return result; |
| 2174 } |
| 2175 |
| 2176 |
| 2114 Object* Heap::AllocateRawAsciiString(int length, PretenureFlag pretenure) { | 2177 Object* Heap::AllocateRawAsciiString(int length, PretenureFlag pretenure) { |
| 2115 AllocationSpace space = (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE; | 2178 AllocationSpace space = (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE; |
| 2116 int size = SeqAsciiString::SizeFor(length); | 2179 int size = SeqAsciiString::SizeFor(length); |
| 2117 if (size > MaxHeapObjectSize()) { | 2180 if (size > MaxHeapObjectSize()) { |
| 2118 space = LO_SPACE; | 2181 space = LO_SPACE; |
| 2119 } | 2182 } |
| 2120 | 2183 |
| 2121 // Use AllocateRaw rather than Allocate because the object's size cannot be | 2184 // Use AllocateRaw rather than Allocate because the object's size cannot be |
| 2122 // determined from the map. | 2185 // determined from the map. |
| 2123 Object* result = AllocateRaw(size, space, OLD_DATA_SPACE); | 2186 Object* result = AllocateRaw(size, space, OLD_DATA_SPACE); |
| (...skipping 1152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3276 #ifdef DEBUG | 3339 #ifdef DEBUG |
| 3277 bool Heap::GarbageCollectionGreedyCheck() { | 3340 bool Heap::GarbageCollectionGreedyCheck() { |
| 3278 ASSERT(FLAG_gc_greedy); | 3341 ASSERT(FLAG_gc_greedy); |
| 3279 if (Bootstrapper::IsActive()) return true; | 3342 if (Bootstrapper::IsActive()) return true; |
| 3280 if (disallow_allocation_failure()) return true; | 3343 if (disallow_allocation_failure()) return true; |
| 3281 return CollectGarbage(0, NEW_SPACE); | 3344 return CollectGarbage(0, NEW_SPACE); |
| 3282 } | 3345 } |
| 3283 #endif | 3346 #endif |
| 3284 | 3347 |
| 3285 } } // namespace v8::internal | 3348 } } // namespace v8::internal |
| OLD | NEW |