987
988
989 const char* DefNewGeneration::name() const {
990 return "def new generation";
991 }
992
993 // Moved from inline file as they are not called inline
994 CompactibleSpace* DefNewGeneration::first_compaction_space() const {
995 return eden();
996 }
997
998 HeapWord* DefNewGeneration::allocate(size_t word_size,
999 bool is_tlab) {
1000 // This is the slow-path allocation for the DefNewGeneration.
1001 // Most allocations are fast-path in compiled code.
1002 // We try to allocate from the eden. If that works, we are happy.
1003 // Note that since DefNewGeneration supports lock-free allocation, we
1004 // have to use it here, as well.
1005 HeapWord* result = eden()->par_allocate(word_size);
1006 if (result != NULL) {
1007 return result;
1008 }
1009 do {
1010 HeapWord* old_limit = eden()->soft_end();
1011 if (old_limit < eden()->end()) {
1012 // Tell the next generation we reached a limit.
1013 HeapWord* new_limit =
1014 next_gen()->allocation_limit_reached(eden(), eden()->top(), word_size);
1015 if (new_limit != NULL) {
1016 Atomic::cmpxchg_ptr(new_limit, eden()->soft_end_addr(), old_limit);
1017 } else {
1018 assert(eden()->soft_end() == eden()->end(),
1019 "invalid state after allocation_limit_reached returned null");
1020 }
1021 } else {
1022 // The allocation failed and the soft limit is equal to the hard limit,
1023 // there are no reasons to do an attempt to allocate
1024 assert(old_limit == eden()->end(), "sanity check");
1025 break;
1026 }
1027 // Try to allocate until succeeded or the soft limit can't be adjusted
1028 result = eden()->par_allocate(word_size);
1029 } while (result == NULL);
1030
1031 // If the eden is full and the last collection bailed out, we are running
1032 // out of heap space, and we try to allocate the from-space, too.
1033 // allocate_from_space can't be inlined because that would introduce a
1034 // circular dependency at compile time.
1035 if (result == NULL) {
1036 result = allocate_from_space(word_size);
1037 }
1038 return result;
1039 }
1040
1041 HeapWord* DefNewGeneration::par_allocate(size_t word_size,
1042 bool is_tlab) {
1043 return eden()->par_allocate(word_size);
1044 }
1045
1046 void DefNewGeneration::gc_prologue(bool full) {
1047 // Ensure that _end and _soft_end are the same in eden space.
1048 eden()->set_soft_end(eden()->end());
1049 }
1050
1051 size_t DefNewGeneration::tlab_capacity() const {
1052 return eden()->capacity();
1053 }
1054
1055 size_t DefNewGeneration::unsafe_max_tlab_alloc() const {
1056 return unsafe_max_alloc_nogc();
1057 }
|
987
988
989 const char* DefNewGeneration::name() const {
990 return "def new generation";
991 }
992
993 // Moved from inline file as they are not called inline
994 CompactibleSpace* DefNewGeneration::first_compaction_space() const {
995 return eden();
996 }
997
998 HeapWord* DefNewGeneration::allocate(size_t word_size,
999 bool is_tlab) {
1000 // This is the slow-path allocation for the DefNewGeneration.
1001 // Most allocations are fast-path in compiled code.
1002 // We try to allocate from the eden. If that works, we are happy.
1003 // Note that since DefNewGeneration supports lock-free allocation, we
1004 // have to use it here, as well.
1005 HeapWord* result = eden()->par_allocate(word_size);
1006 if (result != NULL) {
1007 if (CMSEdenChunksRecordAlways && _next_gen != NULL) {
1008 _next_gen->sample_eden_chunk();
1009 }
1010 return result;
1011 }
1012 do {
1013 HeapWord* old_limit = eden()->soft_end();
1014 if (old_limit < eden()->end()) {
1015 // Tell the next generation we reached a limit.
1016 HeapWord* new_limit =
1017 next_gen()->allocation_limit_reached(eden(), eden()->top(), word_size);
1018 if (new_limit != NULL) {
1019 Atomic::cmpxchg_ptr(new_limit, eden()->soft_end_addr(), old_limit);
1020 } else {
1021 assert(eden()->soft_end() == eden()->end(),
1022 "invalid state after allocation_limit_reached returned null");
1023 }
1024 } else {
1025 // The allocation failed and the soft limit is equal to the hard limit,
1026 // there are no reasons to do an attempt to allocate
1027 assert(old_limit == eden()->end(), "sanity check");
1028 break;
1029 }
1030 // Try to allocate until succeeded or the soft limit can't be adjusted
1031 result = eden()->par_allocate(word_size);
1032 } while (result == NULL);
1033
1034 // If the eden is full and the last collection bailed out, we are running
1035 // out of heap space, and we try to allocate the from-space, too.
1036 // allocate_from_space can't be inlined because that would introduce a
1037 // circular dependency at compile time.
1038 if (result == NULL) {
1039 result = allocate_from_space(word_size);
1040 } else if (CMSEdenChunksRecordAlways && _next_gen != NULL) {
1041 _next_gen->sample_eden_chunk();
1042 }
1043 return result;
1044 }
1045
1046 HeapWord* DefNewGeneration::par_allocate(size_t word_size,
1047 bool is_tlab) {
1048 HeapWord* res = eden()->par_allocate(word_size);
1049 if (CMSEdenChunksRecordAlways && _next_gen != NULL) {
1050 _next_gen->sample_eden_chunk();
1051 }
1052 return res;
1053 }
1054
1055 void DefNewGeneration::gc_prologue(bool full) {
1056 // Ensure that _end and _soft_end are the same in eden space.
1057 eden()->set_soft_end(eden()->end());
1058 }
1059
1060 size_t DefNewGeneration::tlab_capacity() const {
1061 return eden()->capacity();
1062 }
1063
1064 size_t DefNewGeneration::unsafe_max_tlab_alloc() const {
1065 return unsafe_max_alloc_nogc();
1066 }
|