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