| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 #endif | 229 #endif |
| 230 | 230 |
| 231 HeapObject* object; | 231 HeapObject* object; |
| 232 MaybeObject* result; | 232 MaybeObject* result; |
| 233 if (NEW_SPACE == space) { | 233 if (NEW_SPACE == space) { |
| 234 result = new_space_.AllocateRaw(size_in_bytes); | 234 result = new_space_.AllocateRaw(size_in_bytes); |
| 235 if (always_allocate() && result->IsFailure() && retry_space != NEW_SPACE) { | 235 if (always_allocate() && result->IsFailure() && retry_space != NEW_SPACE) { |
| 236 space = retry_space; | 236 space = retry_space; |
| 237 } else { | 237 } else { |
| 238 if (profiler->is_tracking_allocations() && result->To(&object)) { | 238 if (profiler->is_tracking_allocations() && result->To(&object)) { |
| 239 profiler->NewObjectEvent(object->address(), size_in_bytes); | 239 profiler->AllocationEvent(object->address(), size_in_bytes); |
| 240 } | 240 } |
| 241 return result; | 241 return result; |
| 242 } | 242 } |
| 243 } | 243 } |
| 244 | 244 |
| 245 if (OLD_POINTER_SPACE == space) { | 245 if (OLD_POINTER_SPACE == space) { |
| 246 result = old_pointer_space_->AllocateRaw(size_in_bytes); | 246 result = old_pointer_space_->AllocateRaw(size_in_bytes); |
| 247 } else if (OLD_DATA_SPACE == space) { | 247 } else if (OLD_DATA_SPACE == space) { |
| 248 result = old_data_space_->AllocateRaw(size_in_bytes); | 248 result = old_data_space_->AllocateRaw(size_in_bytes); |
| 249 } else if (CODE_SPACE == space) { | 249 } else if (CODE_SPACE == space) { |
| 250 result = code_space_->AllocateRaw(size_in_bytes); | 250 result = code_space_->AllocateRaw(size_in_bytes); |
| 251 } else if (LO_SPACE == space) { | 251 } else if (LO_SPACE == space) { |
| 252 result = lo_space_->AllocateRaw(size_in_bytes, NOT_EXECUTABLE); | 252 result = lo_space_->AllocateRaw(size_in_bytes, NOT_EXECUTABLE); |
| 253 } else if (CELL_SPACE == space) { | 253 } else if (CELL_SPACE == space) { |
| 254 result = cell_space_->AllocateRaw(size_in_bytes); | 254 result = cell_space_->AllocateRaw(size_in_bytes); |
| 255 } else if (PROPERTY_CELL_SPACE == space) { | 255 } else if (PROPERTY_CELL_SPACE == space) { |
| 256 result = property_cell_space_->AllocateRaw(size_in_bytes); | 256 result = property_cell_space_->AllocateRaw(size_in_bytes); |
| 257 } else { | 257 } else { |
| 258 ASSERT(MAP_SPACE == space); | 258 ASSERT(MAP_SPACE == space); |
| 259 result = map_space_->AllocateRaw(size_in_bytes); | 259 result = map_space_->AllocateRaw(size_in_bytes); |
| 260 } | 260 } |
| 261 if (result->IsFailure()) old_gen_exhausted_ = true; | 261 if (result->IsFailure()) old_gen_exhausted_ = true; |
| 262 if (profiler->is_tracking_allocations() && result->To(&object)) { | 262 if (profiler->is_tracking_allocations() && result->To(&object)) { |
| 263 profiler->NewObjectEvent(object->address(), size_in_bytes); | 263 profiler->AllocationEvent(object->address(), size_in_bytes); |
| 264 } | 264 } |
| 265 return result; | 265 return result; |
| 266 } | 266 } |
| 267 | 267 |
| 268 | 268 |
| 269 MaybeObject* Heap::NumberFromInt32( | 269 MaybeObject* Heap::NumberFromInt32( |
| 270 int32_t value, PretenureFlag pretenure) { | 270 int32_t value, PretenureFlag pretenure) { |
| 271 if (Smi::IsValid(value)) return Smi::FromInt(value); | 271 if (Smi::IsValid(value)) return Smi::FromInt(value); |
| 272 // Bypass NumberFromDouble to avoid various redundant checks. | 272 // Bypass NumberFromDouble to avoid various redundant checks. |
| 273 return AllocateHeapNumber(FastI2D(value), pretenure); | 273 return AllocateHeapNumber(FastI2D(value), pretenure); |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 OS::MemMove(dst, src, static_cast<size_t>(byte_size)); | 476 OS::MemMove(dst, src, static_cast<size_t>(byte_size)); |
| 477 } | 477 } |
| 478 } | 478 } |
| 479 | 479 |
| 480 | 480 |
| 481 void Heap::ScavengePointer(HeapObject** p) { | 481 void Heap::ScavengePointer(HeapObject** p) { |
| 482 ScavengeObject(p, *p); | 482 ScavengeObject(p, *p); |
| 483 } | 483 } |
| 484 | 484 |
| 485 | 485 |
| 486 void Heap::UpdateAllocationSiteFeedback(HeapObject* object) { |
| 487 if (FLAG_allocation_site_pretenuring && object->IsJSObject()) { |
| 488 AllocationMemento* memento = AllocationMemento::FindForJSObject( |
| 489 JSObject::cast(object), true); |
| 490 if (memento != NULL) { |
| 491 ASSERT(memento->IsValid()); |
| 492 memento->GetAllocationSite()->IncrementMementoFoundCount(); |
| 493 } |
| 494 } |
| 495 } |
| 496 |
| 497 |
| 486 void Heap::ScavengeObject(HeapObject** p, HeapObject* object) { | 498 void Heap::ScavengeObject(HeapObject** p, HeapObject* object) { |
| 487 ASSERT(object->GetIsolate()->heap()->InFromSpace(object)); | 499 ASSERT(object->GetIsolate()->heap()->InFromSpace(object)); |
| 488 | 500 |
| 489 // We use the first word (where the map pointer usually is) of a heap | 501 // We use the first word (where the map pointer usually is) of a heap |
| 490 // object to record the forwarding pointer. A forwarding pointer can | 502 // object to record the forwarding pointer. A forwarding pointer can |
| 491 // point to an old space, the code space, or the to space of the new | 503 // point to an old space, the code space, or the to space of the new |
| 492 // generation. | 504 // generation. |
| 493 MapWord first_word = object->map_word(); | 505 MapWord first_word = object->map_word(); |
| 494 | 506 |
| 495 // If the first word is a forwarding address, the object has already been | 507 // If the first word is a forwarding address, the object has already been |
| 496 // copied. | 508 // copied. |
| 497 if (first_word.IsForwardingAddress()) { | 509 if (first_word.IsForwardingAddress()) { |
| 498 HeapObject* dest = first_word.ToForwardingAddress(); | 510 HeapObject* dest = first_word.ToForwardingAddress(); |
| 499 ASSERT(object->GetIsolate()->heap()->InFromSpace(*p)); | 511 ASSERT(object->GetIsolate()->heap()->InFromSpace(*p)); |
| 500 *p = dest; | 512 *p = dest; |
| 501 return; | 513 return; |
| 502 } | 514 } |
| 503 | 515 |
| 504 if (FLAG_trace_track_allocation_sites && object->IsJSObject()) { | 516 UpdateAllocationSiteFeedback(object); |
| 505 if (AllocationMemento::FindForJSObject(JSObject::cast(object), true) != | |
| 506 NULL) { | |
| 507 object->GetIsolate()->heap()->allocation_mementos_found_++; | |
| 508 } | |
| 509 } | |
| 510 | 517 |
| 511 // AllocationMementos are unrooted and shouldn't survive a scavenge | 518 // AllocationMementos are unrooted and shouldn't survive a scavenge |
| 512 ASSERT(object->map() != object->GetHeap()->allocation_memento_map()); | 519 ASSERT(object->map() != object->GetHeap()->allocation_memento_map()); |
| 513 // Call the slow part of scavenge object. | 520 // Call the slow part of scavenge object. |
| 514 return ScavengeObjectSlow(p, object); | 521 return ScavengeObjectSlow(p, object); |
| 515 } | 522 } |
| 516 | 523 |
| 517 | 524 |
| 518 bool Heap::CollectGarbage(AllocationSpace space, const char* gc_reason) { | 525 bool Heap::CollectGarbage(AllocationSpace space, const char* gc_reason) { |
| 519 const char* collector_reason = NULL; | 526 const char* collector_reason = NULL; |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 749 } | 756 } |
| 750 | 757 |
| 751 | 758 |
| 752 Address TranscendentalCache::cache_array_address() { | 759 Address TranscendentalCache::cache_array_address() { |
| 753 return reinterpret_cast<Address>(caches_); | 760 return reinterpret_cast<Address>(caches_); |
| 754 } | 761 } |
| 755 | 762 |
| 756 | 763 |
| 757 double TranscendentalCache::SubCache::Calculate(double input) { | 764 double TranscendentalCache::SubCache::Calculate(double input) { |
| 758 switch (type_) { | 765 switch (type_) { |
| 759 case ACOS: | |
| 760 return acos(input); | |
| 761 case ASIN: | |
| 762 return asin(input); | |
| 763 case ATAN: | |
| 764 return atan(input); | |
| 765 case COS: | |
| 766 return fast_cos(input); | |
| 767 case EXP: | |
| 768 return exp(input); | |
| 769 case LOG: | 766 case LOG: |
| 770 return fast_log(input); | 767 return fast_log(input); |
| 771 case SIN: | |
| 772 return fast_sin(input); | |
| 773 case TAN: | |
| 774 return fast_tan(input); | |
| 775 default: | 768 default: |
| 769 UNREACHABLE(); |
| 776 return 0.0; // Never happens. | 770 return 0.0; // Never happens. |
| 777 } | 771 } |
| 778 } | 772 } |
| 779 | 773 |
| 780 | 774 |
| 781 MaybeObject* TranscendentalCache::SubCache::Get(double input) { | 775 MaybeObject* TranscendentalCache::SubCache::Get(double input) { |
| 782 Converter c; | 776 Converter c; |
| 783 c.dbl = input; | 777 c.dbl = input; |
| 784 int hash = Hash(c); | 778 int hash = Hash(c); |
| 785 Element e = elements_[hash]; | 779 Element e = elements_[hash]; |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 864 #ifdef DEBUG | 858 #ifdef DEBUG |
| 865 Isolate* isolate = Isolate::Current(); | 859 Isolate* isolate = Isolate::Current(); |
| 866 isolate->heap()->disallow_allocation_failure_ = old_state_; | 860 isolate->heap()->disallow_allocation_failure_ = old_state_; |
| 867 #endif | 861 #endif |
| 868 } | 862 } |
| 869 | 863 |
| 870 | 864 |
| 871 } } // namespace v8::internal | 865 } } // namespace v8::internal |
| 872 | 866 |
| 873 #endif // V8_HEAP_INL_H_ | 867 #endif // V8_HEAP_INL_H_ |
| OLD | NEW |