Mercurial > hg > truffle
comparison src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp @ 4834:6a78aa6ac1ff
7132311: G1: assert((s == klass->oop_size(this)) || (Universe::heap()->is_gc_active() && ((is_typeArray()...
Summary: Move the check for when to call collect() to before we do a humongous object allocation
Reviewed-by: stefank, tonyp
author | brutisso |
---|---|
date | Mon, 23 Jan 2012 20:36:16 +0100 |
parents | 57025542827f |
children | d30fa85f9994 |
comparison
equal
deleted
inserted
replaced
4833:57025542827f | 4834:6a78aa6ac1ff |
---|---|
1027 | 1027 |
1028 assert_heap_not_locked_and_not_at_safepoint(); | 1028 assert_heap_not_locked_and_not_at_safepoint(); |
1029 assert(isHumongous(word_size), "attempt_allocation_humongous() " | 1029 assert(isHumongous(word_size), "attempt_allocation_humongous() " |
1030 "should only be called for humongous allocations"); | 1030 "should only be called for humongous allocations"); |
1031 | 1031 |
1032 // Humongous objects can exhaust the heap quickly, so we should check if we | |
1033 // need to start a marking cycle at each humongous object allocation. We do | |
1034 // the check before we do the actual allocation. The reason for doing it | |
1035 // before the allocation is that we avoid having to keep track of the newly | |
1036 // allocated memory while we do a GC. | |
1037 if (g1_policy()->need_to_start_conc_mark("concurrent humongous allocation", word_size)) { | |
1038 collect(GCCause::_g1_humongous_allocation); | |
1039 } | |
1040 | |
1032 // We will loop until a) we manage to successfully perform the | 1041 // We will loop until a) we manage to successfully perform the |
1033 // allocation or b) we successfully schedule a collection which | 1042 // allocation or b) we successfully schedule a collection which |
1034 // fails to perform the allocation. b) is the only case when we'll | 1043 // fails to perform the allocation. b) is the only case when we'll |
1035 // return NULL. | 1044 // return NULL. |
1036 HeapWord* result = NULL; | 1045 HeapWord* result = NULL; |
1043 | 1052 |
1044 // Given that humongous objects are not allocated in young | 1053 // Given that humongous objects are not allocated in young |
1045 // regions, we'll first try to do the allocation without doing a | 1054 // regions, we'll first try to do the allocation without doing a |
1046 // collection hoping that there's enough space in the heap. | 1055 // collection hoping that there's enough space in the heap. |
1047 result = humongous_obj_allocate(word_size); | 1056 result = humongous_obj_allocate(word_size); |
1048 | 1057 if (result != NULL) { |
1049 if (result == NULL) { | 1058 return result; |
1050 if (GC_locker::is_active_and_needs_gc()) { | |
1051 should_try_gc = false; | |
1052 } else { | |
1053 // Read the GC count while still holding the Heap_lock. | |
1054 gc_count_before = SharedHeap::heap()->total_collections(); | |
1055 should_try_gc = true; | |
1056 } | |
1057 } | 1059 } |
1058 } | 1060 |
1059 | 1061 if (GC_locker::is_active_and_needs_gc()) { |
1060 if (result != NULL) { | 1062 should_try_gc = false; |
1061 if (g1_policy()->need_to_start_conc_mark("concurrent humongous allocation")) { | 1063 } else { |
1062 // We need to release the Heap_lock before we try to call collect(). | 1064 // Read the GC count while still holding the Heap_lock. |
1063 // The result will not be stored in any object before this method | 1065 gc_count_before = SharedHeap::heap()->total_collections(); |
1064 // returns, so the GC might miss it. Thus, we create a handle to the result | 1066 should_try_gc = true; |
1065 // and fake an object at that place. | |
1066 CollectedHeap::fill_with_object(result, word_size, false); | |
1067 Handle h((oop)result); | |
1068 collect(GCCause::_g1_humongous_allocation); | |
1069 assert(result == (HeapWord*)h(), "Humongous objects should not be moved by collections"); | |
1070 } | 1067 } |
1071 return result; | |
1072 } | 1068 } |
1073 | 1069 |
1074 if (should_try_gc) { | 1070 if (should_try_gc) { |
1075 // If we failed to allocate the humongous object, we should try to | 1071 // If we failed to allocate the humongous object, we should try to |
1076 // do a collection pause (if we're allowed) in case it reclaims | 1072 // do a collection pause (if we're allowed) in case it reclaims |