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 559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
570 #define GC_GREEDY_CHECK() { } | 570 #define GC_GREEDY_CHECK() { } |
571 #endif | 571 #endif |
572 | 572 |
573 // Calls the FUNCTION_CALL function and retries it up to three times | 573 // Calls the FUNCTION_CALL function and retries it up to three times |
574 // to guarantee that any allocations performed during the call will | 574 // to guarantee that any allocations performed during the call will |
575 // succeed if there's enough memory. | 575 // succeed if there's enough memory. |
576 | 576 |
577 // Warning: Do not use the identifiers __object__, __maybe_object__ or | 577 // Warning: Do not use the identifiers __object__, __maybe_object__ or |
578 // __scope__ in a call to this macro. | 578 // __scope__ in a call to this macro. |
579 | 579 |
580 #define CALL_AND_RETRY(ISOLATE, FUNCTION_CALL, RETURN_VALUE, RETURN_EMPTY)\ | 580 #define CALL_AND_RETRY(ISOLATE, FUNCTION_CALL, RETURN_VALUE, RETURN_EMPTY, OOM)\ |
581 do { \ | 581 do { \ |
582 GC_GREEDY_CHECK(); \ | 582 GC_GREEDY_CHECK(); \ |
583 MaybeObject* __maybe_object__ = FUNCTION_CALL; \ | 583 MaybeObject* __maybe_object__ = FUNCTION_CALL; \ |
584 Object* __object__ = NULL; \ | 584 Object* __object__ = NULL; \ |
585 if (__maybe_object__->ToObject(&__object__)) RETURN_VALUE; \ | 585 if (__maybe_object__->ToObject(&__object__)) RETURN_VALUE; \ |
586 if (__maybe_object__->IsOutOfMemory()) { \ | 586 if (__maybe_object__->IsOutOfMemory()) { \ |
587 v8::internal::V8::FatalProcessOutOfMemory("CALL_AND_RETRY_0", true);\ | 587 OOM; \ |
588 } \ | 588 } \ |
589 if (!__maybe_object__->IsRetryAfterGC()) RETURN_EMPTY; \ | 589 if (!__maybe_object__->IsRetryAfterGC()) RETURN_EMPTY; \ |
590 ISOLATE->heap()->CollectGarbage(Failure::cast(__maybe_object__)-> \ | 590 ISOLATE->heap()->CollectGarbage(Failure::cast(__maybe_object__)-> \ |
591 allocation_space(), \ | 591 allocation_space(), \ |
592 "allocation failure"); \ | 592 "allocation failure"); \ |
593 __maybe_object__ = FUNCTION_CALL; \ | 593 __maybe_object__ = FUNCTION_CALL; \ |
594 if (__maybe_object__->ToObject(&__object__)) RETURN_VALUE; \ | 594 if (__maybe_object__->ToObject(&__object__)) RETURN_VALUE; \ |
595 if (__maybe_object__->IsOutOfMemory()) { \ | 595 if (__maybe_object__->IsOutOfMemory()) { \ |
596 v8::internal::V8::FatalProcessOutOfMemory("CALL_AND_RETRY_1", true);\ | 596 OOM; \ |
597 } \ | 597 } \ |
598 if (!__maybe_object__->IsRetryAfterGC()) RETURN_EMPTY; \ | 598 if (!__maybe_object__->IsRetryAfterGC()) RETURN_EMPTY; \ |
599 ISOLATE->counters()->gc_last_resort_from_handles()->Increment(); \ | 599 ISOLATE->counters()->gc_last_resort_from_handles()->Increment(); \ |
600 ISOLATE->heap()->CollectAllAvailableGarbage("last resort gc"); \ | 600 ISOLATE->heap()->CollectAllAvailableGarbage("last resort gc"); \ |
601 { \ | 601 { \ |
602 AlwaysAllocateScope __scope__; \ | 602 AlwaysAllocateScope __scope__; \ |
603 __maybe_object__ = FUNCTION_CALL; \ | 603 __maybe_object__ = FUNCTION_CALL; \ |
604 } \ | 604 } \ |
605 if (__maybe_object__->ToObject(&__object__)) RETURN_VALUE; \ | 605 if (__maybe_object__->ToObject(&__object__)) RETURN_VALUE; \ |
606 if (__maybe_object__->IsOutOfMemory() || \ | 606 if (__maybe_object__->IsOutOfMemory()) { \ |
607 __maybe_object__->IsRetryAfterGC()) { \ | 607 OOM; \ |
608 /* TODO(1181417): Fix this. */ \ | 608 } \ |
609 v8::internal::V8::FatalProcessOutOfMemory("CALL_AND_RETRY_2", true);\ | 609 if (__maybe_object__->IsRetryAfterGC()) { \ |
610 } \ | 610 /* TODO(1181417): Fix this. */ \ |
611 RETURN_EMPTY; \ | 611 v8::internal::V8::FatalProcessOutOfMemory("CALL_AND_RETRY_LAST", true); \ |
| 612 } \ |
| 613 RETURN_EMPTY; \ |
612 } while (false) | 614 } while (false) |
613 | 615 |
| 616 #define CALL_AND_RETRY_OR_DIE( \ |
| 617 ISOLATE, FUNCTION_CALL, RETURN_VALUE, RETURN_EMPTY) \ |
| 618 CALL_AND_RETRY( \ |
| 619 ISOLATE, \ |
| 620 FUNCTION_CALL, \ |
| 621 RETURN_VALUE, \ |
| 622 RETURN_EMPTY, \ |
| 623 v8::internal::V8::FatalProcessOutOfMemory("CALL_AND_RETRY", true)) |
614 | 624 |
615 #define CALL_HEAP_FUNCTION(ISOLATE, FUNCTION_CALL, TYPE) \ | 625 #define CALL_HEAP_FUNCTION(ISOLATE, FUNCTION_CALL, TYPE) \ |
616 CALL_AND_RETRY(ISOLATE, \ | 626 CALL_AND_RETRY_OR_DIE(ISOLATE, \ |
617 FUNCTION_CALL, \ | 627 FUNCTION_CALL, \ |
618 return Handle<TYPE>(TYPE::cast(__object__), ISOLATE), \ | 628 return Handle<TYPE>(TYPE::cast(__object__), ISOLATE), \ |
619 return Handle<TYPE>()) | 629 return Handle<TYPE>()) \ |
620 | 630 |
621 | 631 |
622 #define CALL_HEAP_FUNCTION_VOID(ISOLATE, FUNCTION_CALL) \ | 632 #define CALL_HEAP_FUNCTION_VOID(ISOLATE, FUNCTION_CALL) \ |
623 CALL_AND_RETRY(ISOLATE, FUNCTION_CALL, return, return) | 633 CALL_AND_RETRY_OR_DIE(ISOLATE, FUNCTION_CALL, return, return) |
624 | 634 |
625 | 635 |
626 #define CALL_HEAP_FUNCTION_PASS_EXCEPTION(ISOLATE, FUNCTION_CALL) \ | 636 #define CALL_HEAP_FUNCTION_PASS_EXCEPTION(ISOLATE, FUNCTION_CALL) \ |
627 CALL_AND_RETRY(ISOLATE, \ | 637 CALL_AND_RETRY(ISOLATE, \ |
628 FUNCTION_CALL, \ | 638 FUNCTION_CALL, \ |
629 return __object__, \ | 639 return __object__, \ |
| 640 return __maybe_object__, \ |
630 return __maybe_object__) | 641 return __maybe_object__) |
631 | 642 |
632 | 643 |
633 #ifdef DEBUG | 644 #ifdef DEBUG |
634 | 645 |
635 inline bool Heap::allow_allocation(bool new_state) { | 646 inline bool Heap::allow_allocation(bool new_state) { |
636 bool old = allocation_allowed_; | 647 bool old = allocation_allowed_; |
637 allocation_allowed_ = new_state; | 648 allocation_allowed_ = new_state; |
638 return old; | 649 return old; |
639 } | 650 } |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
885 AssertNoAllocation::~AssertNoAllocation() { } | 896 AssertNoAllocation::~AssertNoAllocation() { } |
886 DisableAssertNoAllocation::DisableAssertNoAllocation() { } | 897 DisableAssertNoAllocation::DisableAssertNoAllocation() { } |
887 DisableAssertNoAllocation::~DisableAssertNoAllocation() { } | 898 DisableAssertNoAllocation::~DisableAssertNoAllocation() { } |
888 | 899 |
889 #endif | 900 #endif |
890 | 901 |
891 | 902 |
892 } } // namespace v8::internal | 903 } } // namespace v8::internal |
893 | 904 |
894 #endif // V8_HEAP_INL_H_ | 905 #endif // V8_HEAP_INL_H_ |
OLD | NEW |