src/share/vm/memory/defNewGeneration.cpp

Print this page




 993 
 994 
 995 const char* DefNewGeneration::name() const {
 996   return "def new generation";
 997 }
 998 
 999 // Moved from inline file as they are not called inline
1000 CompactibleSpace* DefNewGeneration::first_compaction_space() const {
1001   return eden();
1002 }
1003 
1004 HeapWord* DefNewGeneration::allocate(size_t word_size,
1005                                      bool is_tlab) {
1006   // This is the slow-path allocation for the DefNewGeneration.
1007   // Most allocations are fast-path in compiled code.
1008   // We try to allocate from the eden.  If that works, we are happy.
1009   // Note that since DefNewGeneration supports lock-free allocation, we
1010   // have to use it here, as well.
1011   HeapWord* result = eden()->par_allocate(word_size);
1012   if (result != NULL) {



1013     return result;
1014   }
1015   do {
1016     HeapWord* old_limit = eden()->soft_end();
1017     if (old_limit < eden()->end()) {
1018       // Tell the next generation we reached a limit.
1019       HeapWord* new_limit =
1020         next_gen()->allocation_limit_reached(eden(), eden()->top(), word_size);
1021       if (new_limit != NULL) {
1022         Atomic::cmpxchg_ptr(new_limit, eden()->soft_end_addr(), old_limit);
1023       } else {
1024         assert(eden()->soft_end() == eden()->end(),
1025                "invalid state after allocation_limit_reached returned null");
1026       }
1027     } else {
1028       // The allocation failed and the soft limit is equal to the hard limit,
1029       // there are no reasons to do an attempt to allocate
1030       assert(old_limit == eden()->end(), "sanity check");
1031       break;
1032     }
1033     // Try to allocate until succeeded or the soft limit can't be adjusted
1034     result = eden()->par_allocate(word_size);
1035   } while (result == NULL);
1036 
1037   // If the eden is full and the last collection bailed out, we are running
1038   // out of heap space, and we try to allocate the from-space, too.
1039   // allocate_from_space can't be inlined because that would introduce a
1040   // circular dependency at compile time.
1041   if (result == NULL) {
1042     result = allocate_from_space(word_size);


1043   }
1044   return result;
1045 }
1046 
1047 HeapWord* DefNewGeneration::par_allocate(size_t word_size,
1048                                          bool is_tlab) {
1049   return eden()->par_allocate(word_size);




1050 }
1051 
1052 void DefNewGeneration::gc_prologue(bool full) {
1053   // Ensure that _end and _soft_end are the same in eden space.
1054   eden()->set_soft_end(eden()->end());
1055 }
1056 
1057 size_t DefNewGeneration::tlab_capacity() const {
1058   return eden()->capacity();
1059 }
1060 
1061 size_t DefNewGeneration::unsafe_max_tlab_alloc() const {
1062   return unsafe_max_alloc_nogc();
1063 }


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