OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_HEAP_HEAP_INL_H_ | 5 #ifndef V8_HEAP_HEAP_INL_H_ |
6 #define V8_HEAP_HEAP_INL_H_ | 6 #define V8_HEAP_HEAP_INL_H_ |
7 | 7 |
8 #include <cmath> | 8 #include <cmath> |
9 | 9 |
10 #include "src/base/platform/platform.h" | 10 #include "src/base/platform/platform.h" |
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
536 } | 536 } |
537 | 537 |
538 | 538 |
539 Isolate* Heap::isolate() { | 539 Isolate* Heap::isolate() { |
540 return reinterpret_cast<Isolate*>( | 540 return reinterpret_cast<Isolate*>( |
541 reinterpret_cast<intptr_t>(this) - | 541 reinterpret_cast<intptr_t>(this) - |
542 reinterpret_cast<size_t>(reinterpret_cast<Isolate*>(16)->heap()) + 16); | 542 reinterpret_cast<size_t>(reinterpret_cast<Isolate*>(16)->heap()) + 16); |
543 } | 543 } |
544 | 544 |
545 | 545 |
546 // Calls the FUNCTION_CALL function and retries it up to three times | |
547 // to guarantee that any allocations performed during the call will | |
548 // succeed if there's enough memory. | |
549 // | |
550 // Warning: Do not use the identifiers __object__, __maybe_object__, | |
551 // __allocation__ or __scope__ in a call to this macro. | |
552 | |
553 #define RETURN_OBJECT_UNLESS_RETRY(ISOLATE, TYPE) \ | |
554 if (__allocation__.To(&__object__)) { \ | |
555 DCHECK(__object__ != (ISOLATE)->heap()->exception()); \ | |
556 return Handle<TYPE>(TYPE::cast(__object__), ISOLATE); \ | |
557 } | |
558 | |
559 #define CALL_HEAP_FUNCTION(ISOLATE, FUNCTION_CALL, TYPE) \ | |
560 do { \ | |
561 AllocationResult __allocation__ = FUNCTION_CALL; \ | |
562 Object* __object__ = NULL; \ | |
563 RETURN_OBJECT_UNLESS_RETRY(ISOLATE, TYPE) \ | |
564 /* Two GCs before panicking. In newspace will almost always succeed. */ \ | |
565 for (int __i__ = 0; __i__ < 2; __i__++) { \ | |
566 (ISOLATE)->heap()->CollectGarbage(__allocation__.RetrySpace(), \ | |
567 "allocation failure"); \ | |
568 __allocation__ = FUNCTION_CALL; \ | |
569 RETURN_OBJECT_UNLESS_RETRY(ISOLATE, TYPE) \ | |
570 } \ | |
571 (ISOLATE)->counters()->gc_last_resort_from_handles()->Increment(); \ | |
572 (ISOLATE)->heap()->CollectAllAvailableGarbage("last resort gc"); \ | |
573 { \ | |
574 AlwaysAllocateScope __scope__(ISOLATE); \ | |
575 __allocation__ = FUNCTION_CALL; \ | |
576 } \ | |
577 RETURN_OBJECT_UNLESS_RETRY(ISOLATE, TYPE) \ | |
578 /* TODO(1181417): Fix this. */ \ | |
579 v8::internal::Heap::FatalProcessOutOfMemory("CALL_AND_RETRY_LAST", true); \ | |
580 return Handle<TYPE>(); \ | |
581 } while (false) | |
582 | |
583 | |
584 void Heap::ExternalStringTable::AddString(String* string) { | 546 void Heap::ExternalStringTable::AddString(String* string) { |
585 DCHECK(string->IsExternalString()); | 547 DCHECK(string->IsExternalString()); |
586 if (heap_->InNewSpace(string)) { | 548 if (heap_->InNewSpace(string)) { |
587 new_space_strings_.Add(string); | 549 new_space_strings_.Add(string); |
588 } else { | 550 } else { |
589 old_space_strings_.Add(string); | 551 old_space_strings_.Add(string); |
590 } | 552 } |
591 } | 553 } |
592 | 554 |
593 | 555 |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
742 | 704 |
743 void VerifySmisVisitor::VisitPointers(Object** start, Object** end) { | 705 void VerifySmisVisitor::VisitPointers(Object** start, Object** end) { |
744 for (Object** current = start; current < end; current++) { | 706 for (Object** current = start; current < end; current++) { |
745 CHECK((*current)->IsSmi()); | 707 CHECK((*current)->IsSmi()); |
746 } | 708 } |
747 } | 709 } |
748 } | 710 } |
749 } // namespace v8::internal | 711 } // namespace v8::internal |
750 | 712 |
751 #endif // V8_HEAP_HEAP_INL_H_ | 713 #endif // V8_HEAP_HEAP_INL_H_ |
OLD | NEW |