OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 2328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2339 { MaybeObject* maybe_obj = StringDictionary::Allocate(Runtime::kNumFunctions); | 2339 { MaybeObject* maybe_obj = StringDictionary::Allocate(Runtime::kNumFunctions); |
2340 if (!maybe_obj->ToObject(&obj)) return false; | 2340 if (!maybe_obj->ToObject(&obj)) return false; |
2341 } | 2341 } |
2342 { MaybeObject* maybe_obj = Runtime::InitializeIntrinsicFunctionNames(this, | 2342 { MaybeObject* maybe_obj = Runtime::InitializeIntrinsicFunctionNames(this, |
2343 obj); | 2343 obj); |
2344 if (!maybe_obj->ToObject(&obj)) return false; | 2344 if (!maybe_obj->ToObject(&obj)) return false; |
2345 } | 2345 } |
2346 set_intrinsic_function_names(StringDictionary::cast(obj)); | 2346 set_intrinsic_function_names(StringDictionary::cast(obj)); |
2347 | 2347 |
2348 if (InitializeNumberStringCache()->IsFailure()) return false; | 2348 if (InitializeNumberStringCache()->IsFailure()) return false; |
| 2349 if (InitializeStringLocks()->IsFailure()) return false; |
2349 | 2350 |
2350 // Allocate cache for single character ASCII strings. | 2351 // Allocate cache for single character ASCII strings. |
2351 { MaybeObject* maybe_obj = | 2352 { MaybeObject* maybe_obj = |
2352 AllocateFixedArray(String::kMaxAsciiCharCode + 1, TENURED); | 2353 AllocateFixedArray(String::kMaxAsciiCharCode + 1, TENURED); |
2353 if (!maybe_obj->ToObject(&obj)) return false; | 2354 if (!maybe_obj->ToObject(&obj)) return false; |
2354 } | 2355 } |
2355 set_single_character_string_cache(FixedArray::cast(obj)); | 2356 set_single_character_string_cache(FixedArray::cast(obj)); |
2356 | 2357 |
2357 // Allocate cache for string split. | 2358 // Allocate cache for string split. |
2358 { MaybeObject* maybe_obj = | 2359 { MaybeObject* maybe_obj = |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2555 | 2556 |
2556 MaybeObject* Heap::Uint32ToString(uint32_t value, | 2557 MaybeObject* Heap::Uint32ToString(uint32_t value, |
2557 bool check_number_string_cache) { | 2558 bool check_number_string_cache) { |
2558 Object* number; | 2559 Object* number; |
2559 MaybeObject* maybe = NumberFromUint32(value); | 2560 MaybeObject* maybe = NumberFromUint32(value); |
2560 if (!maybe->To<Object>(&number)) return maybe; | 2561 if (!maybe->To<Object>(&number)) return maybe; |
2561 return NumberToString(number, check_number_string_cache); | 2562 return NumberToString(number, check_number_string_cache); |
2562 } | 2563 } |
2563 | 2564 |
2564 | 2565 |
| 2566 MaybeObject* Heap::LockString(String* string) { |
| 2567 ASSERT(!string->IsConsString()); |
| 2568 FixedArray* locks = string_locks(); |
| 2569 ASSERT(locks->length() > 1); |
| 2570 int length = locks->length(); |
| 2571 int element_count = Smi::cast(locks->get(0))->value(); |
| 2572 int element_index = element_count + 1; |
| 2573 if (element_index >= length) { |
| 2574 int new_length = length * 2; |
| 2575 MaybeObject* allocation = AllocateFixedArray(new_length); |
| 2576 FixedArray* new_locks = NULL; // Initialized to please compiler. |
| 2577 if (!allocation->To<FixedArray>(&new_locks)) return allocation; |
| 2578 for (int i = 1; i < length; i++) { |
| 2579 new_locks->set(i, locks->get(i)); |
| 2580 } |
| 2581 set_string_locks(new_locks); |
| 2582 locks = new_locks; |
| 2583 } |
| 2584 locks->set(element_index, string); |
| 2585 locks->set(0, Smi::FromInt(element_index)); |
| 2586 return string; |
| 2587 } |
| 2588 |
| 2589 |
| 2590 void Heap::UnlockString(String* string) { |
| 2591 FixedArray* locks = string_locks(); |
| 2592 ASSERT(locks->length() > 1); |
| 2593 int element_count = Smi::cast(locks->get(0))->value(); |
| 2594 ASSERT(element_count > 0); |
| 2595 ASSERT(element_count < locks->length()); |
| 2596 for (int i = 1; i <= element_count; i++) { |
| 2597 String* element = String::cast(locks->get(i)); |
| 2598 if (element == string) { |
| 2599 if (i < element_count) { |
| 2600 locks->set(i, locks->get(element_count)); |
| 2601 } |
| 2602 locks->set_undefined(element_count); |
| 2603 locks->set(0, Smi::FromInt(element_count - 1)); |
| 2604 return; |
| 2605 } |
| 2606 } |
| 2607 // We should have found the string. It's an error to try to unlock |
| 2608 // a string that hasn't been locked. |
| 2609 UNREACHABLE(); |
| 2610 } |
| 2611 |
| 2612 |
| 2613 bool Heap::IsStringLocked(String* string) { |
| 2614 if (string->IsConsString()) return false; |
| 2615 FixedArray* locks = string_locks(); |
| 2616 ASSERT(locks->length() > 1); |
| 2617 int element_count = Smi::cast(locks->get(0))->value(); |
| 2618 for (int i = 1; i <= element_count; i++) { |
| 2619 if (locks->get(i) == string) return true; |
| 2620 } |
| 2621 return false; |
| 2622 } |
| 2623 |
| 2624 |
| 2625 MaybeObject* Heap::InitializeStringLocks() { |
| 2626 const int kInitialSize = 6; |
| 2627 MaybeObject* allocation = AllocateFixedArray(kInitialSize); |
| 2628 if (allocation->IsFailure()) return allocation; |
| 2629 FixedArray* new_array = FixedArray::cast(allocation->ToObjectUnchecked()); |
| 2630 new_array->set(0, Smi::FromInt(0)); |
| 2631 set_string_locks(new_array); |
| 2632 return new_array; |
| 2633 } |
| 2634 |
| 2635 |
2565 Map* Heap::MapForExternalArrayType(ExternalArrayType array_type) { | 2636 Map* Heap::MapForExternalArrayType(ExternalArrayType array_type) { |
2566 return Map::cast(roots_[RootIndexForExternalArrayType(array_type)]); | 2637 return Map::cast(roots_[RootIndexForExternalArrayType(array_type)]); |
2567 } | 2638 } |
2568 | 2639 |
2569 | 2640 |
2570 Heap::RootListIndex Heap::RootIndexForExternalArrayType( | 2641 Heap::RootListIndex Heap::RootIndexForExternalArrayType( |
2571 ExternalArrayType array_type) { | 2642 ExternalArrayType array_type) { |
2572 switch (array_type) { | 2643 switch (array_type) { |
2573 case kExternalByteArray: | 2644 case kExternalByteArray: |
2574 return kExternalByteArrayMapRootIndex; | 2645 return kExternalByteArrayMapRootIndex; |
(...skipping 3826 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6401 } | 6472 } |
6402 isolate_->heap()->store_buffer()->Filter(MemoryChunk::ABOUT_TO_BE_FREED); | 6473 isolate_->heap()->store_buffer()->Filter(MemoryChunk::ABOUT_TO_BE_FREED); |
6403 for (chunk = chunks_queued_for_free_; chunk != NULL; chunk = next) { | 6474 for (chunk = chunks_queued_for_free_; chunk != NULL; chunk = next) { |
6404 next = chunk->next_chunk(); | 6475 next = chunk->next_chunk(); |
6405 isolate_->memory_allocator()->Free(chunk); | 6476 isolate_->memory_allocator()->Free(chunk); |
6406 } | 6477 } |
6407 chunks_queued_for_free_ = NULL; | 6478 chunks_queued_for_free_ = NULL; |
6408 } | 6479 } |
6409 | 6480 |
6410 } } // namespace v8::internal | 6481 } } // namespace v8::internal |
OLD | NEW |