< prev index next >

src/share/vm/gc/shared/collectedHeap.inline.hpp

Print this page
rev 11777 : [mq]: gcinterface.patch


 132 
 133   // Clear unhandled oops for memory allocation.  Memory allocation might
 134   // not take out a lock if from tlab, so clear here.
 135   CHECK_UNHANDLED_OOPS_ONLY(THREAD->clear_unhandled_oops();)
 136 
 137   if (HAS_PENDING_EXCEPTION) {
 138     NOT_PRODUCT(guarantee(false, "Should not allocate with exception pending"));
 139     return NULL;  // caller does a CHECK_0 too
 140   }
 141 
 142   HeapWord* result = NULL;
 143   if (UseTLAB) {
 144     result = allocate_from_tlab(klass, THREAD, size);
 145     if (result != NULL) {
 146       assert(!HAS_PENDING_EXCEPTION,
 147              "Unexpected exception, will result in uninitialized storage");
 148       return result;
 149     }
 150   }
 151   bool gc_overhead_limit_was_exceeded = false;
 152   result = Universe::heap()->mem_allocate(size,
 153                                           &gc_overhead_limit_was_exceeded);
 154   if (result != NULL) {
 155     NOT_PRODUCT(Universe::heap()->
 156       check_for_non_bad_heap_word_value(result, size));
 157     assert(!HAS_PENDING_EXCEPTION,
 158            "Unexpected exception, will result in uninitialized storage");
 159     THREAD->incr_allocated_bytes(size * HeapWordSize);
 160 
 161     AllocTracer::send_allocation_outside_tlab_event(klass, size * HeapWordSize);
 162 
 163     return result;
 164   }
 165 
 166 
 167   if (!gc_overhead_limit_was_exceeded) {
 168     // -XX:+HeapDumpOnOutOfMemoryError and -XX:OnOutOfMemoryError support
 169     report_java_out_of_memory("Java heap space");
 170 
 171     if (JvmtiExport::should_post_resource_exhausted()) {
 172       JvmtiExport::post_resource_exhausted(
 173         JVMTI_RESOURCE_EXHAUSTED_OOM_ERROR | JVMTI_RESOURCE_EXHAUSTED_JAVA_HEAP,
 174         "Java heap space");
 175     }


 199   assert(UseTLAB, "should use UseTLAB");
 200 
 201   HeapWord* obj = thread->tlab().allocate(size);
 202   if (obj != NULL) {
 203     return obj;
 204   }
 205   // Otherwise...
 206   return allocate_from_tlab_slow(klass, thread, size);
 207 }
 208 
 209 void CollectedHeap::init_obj(HeapWord* obj, size_t size) {
 210   assert(obj != NULL, "cannot initialize NULL object");
 211   const size_t hs = oopDesc::header_size();
 212   assert(size >= hs, "unexpected object size");
 213   ((oop)obj)->set_klass_gap(0);
 214   Copy::fill_to_aligned_words(obj + hs, size - hs);
 215 }
 216 
 217 oop CollectedHeap::obj_allocate(KlassHandle klass, int size, TRAPS) {
 218   debug_only(check_for_valid_allocation_state());
 219   assert(!Universe::heap()->is_gc_active(), "Allocation during gc not allowed");
 220   assert(size >= 0, "int won't convert to size_t");
 221   HeapWord* obj = common_mem_allocate_init(klass, size, CHECK_NULL);
 222   post_allocation_setup_obj(klass, obj, size);
 223   NOT_PRODUCT(Universe::heap()->check_for_bad_heap_word_value(obj, size));
 224   return (oop)obj;
 225 }
 226 
 227 oop CollectedHeap::class_allocate(KlassHandle klass, int size, TRAPS) {
 228   debug_only(check_for_valid_allocation_state());
 229   assert(!Universe::heap()->is_gc_active(), "Allocation during gc not allowed");
 230   assert(size >= 0, "int won't convert to size_t");
 231   HeapWord* obj = common_mem_allocate_init(klass, size, CHECK_NULL);
 232   post_allocation_setup_class(klass, obj, size); // set oop_size
 233   NOT_PRODUCT(Universe::heap()->check_for_bad_heap_word_value(obj, size));
 234   return (oop)obj;
 235 }
 236 
 237 oop CollectedHeap::array_allocate(KlassHandle klass,
 238                                   int size,
 239                                   int length,
 240                                   TRAPS) {
 241   debug_only(check_for_valid_allocation_state());
 242   assert(!Universe::heap()->is_gc_active(), "Allocation during gc not allowed");
 243   assert(size >= 0, "int won't convert to size_t");
 244   HeapWord* obj = common_mem_allocate_init(klass, size, CHECK_NULL);
 245   post_allocation_setup_array(klass, obj, length);
 246   NOT_PRODUCT(Universe::heap()->check_for_bad_heap_word_value(obj, size));
 247   return (oop)obj;
 248 }
 249 
 250 oop CollectedHeap::array_allocate_nozero(KlassHandle klass,
 251                                          int size,
 252                                          int length,
 253                                          TRAPS) {
 254   debug_only(check_for_valid_allocation_state());
 255   assert(!Universe::heap()->is_gc_active(), "Allocation during gc not allowed");
 256   assert(size >= 0, "int won't convert to size_t");
 257   HeapWord* obj = common_mem_allocate_noinit(klass, size, CHECK_NULL);
 258   ((oop)obj)->set_klass_gap(0);
 259   post_allocation_setup_array(klass, obj, length);
 260 #ifndef PRODUCT
 261   const size_t hs = oopDesc::header_size()+1;
 262   Universe::heap()->check_for_non_bad_heap_word_value(obj+hs, size-hs);
 263 #endif
 264   return (oop)obj;
 265 }
 266 
 267 inline HeapWord* CollectedHeap::align_allocation_or_fail(HeapWord* addr,
 268                                                          HeapWord* end,
 269                                                          unsigned short alignment_in_bytes) {
 270   if (alignment_in_bytes <= ObjectAlignmentInBytes) {
 271     return addr;
 272   }
 273 
 274   assert(is_ptr_aligned(addr, HeapWordSize),
 275          "Address " PTR_FORMAT " is not properly aligned.", p2i(addr));
 276   assert(is_size_aligned(alignment_in_bytes, HeapWordSize),
 277          "Alignment size %u is incorrect.", alignment_in_bytes);
 278 
 279   HeapWord* new_addr = (HeapWord*) align_ptr_up(addr, alignment_in_bytes);
 280   size_t padding = pointer_delta(new_addr, addr);
 281 
 282   if (padding == 0) {




 132 
 133   // Clear unhandled oops for memory allocation.  Memory allocation might
 134   // not take out a lock if from tlab, so clear here.
 135   CHECK_UNHANDLED_OOPS_ONLY(THREAD->clear_unhandled_oops();)
 136 
 137   if (HAS_PENDING_EXCEPTION) {
 138     NOT_PRODUCT(guarantee(false, "Should not allocate with exception pending"));
 139     return NULL;  // caller does a CHECK_0 too
 140   }
 141 
 142   HeapWord* result = NULL;
 143   if (UseTLAB) {
 144     result = allocate_from_tlab(klass, THREAD, size);
 145     if (result != NULL) {
 146       assert(!HAS_PENDING_EXCEPTION,
 147              "Unexpected exception, will result in uninitialized storage");
 148       return result;
 149     }
 150   }
 151   bool gc_overhead_limit_was_exceeded = false;
 152   result = GC::gc()->heap()->mem_allocate(size,
 153                                           &gc_overhead_limit_was_exceeded);
 154   if (result != NULL) {
 155     NOT_PRODUCT(GC::gc()->heap()->
 156       check_for_non_bad_heap_word_value(result, size));
 157     assert(!HAS_PENDING_EXCEPTION,
 158            "Unexpected exception, will result in uninitialized storage");
 159     THREAD->incr_allocated_bytes(size * HeapWordSize);
 160 
 161     AllocTracer::send_allocation_outside_tlab_event(klass, size * HeapWordSize);
 162 
 163     return result;
 164   }
 165 
 166 
 167   if (!gc_overhead_limit_was_exceeded) {
 168     // -XX:+HeapDumpOnOutOfMemoryError and -XX:OnOutOfMemoryError support
 169     report_java_out_of_memory("Java heap space");
 170 
 171     if (JvmtiExport::should_post_resource_exhausted()) {
 172       JvmtiExport::post_resource_exhausted(
 173         JVMTI_RESOURCE_EXHAUSTED_OOM_ERROR | JVMTI_RESOURCE_EXHAUSTED_JAVA_HEAP,
 174         "Java heap space");
 175     }


 199   assert(UseTLAB, "should use UseTLAB");
 200 
 201   HeapWord* obj = thread->tlab().allocate(size);
 202   if (obj != NULL) {
 203     return obj;
 204   }
 205   // Otherwise...
 206   return allocate_from_tlab_slow(klass, thread, size);
 207 }
 208 
 209 void CollectedHeap::init_obj(HeapWord* obj, size_t size) {
 210   assert(obj != NULL, "cannot initialize NULL object");
 211   const size_t hs = oopDesc::header_size();
 212   assert(size >= hs, "unexpected object size");
 213   ((oop)obj)->set_klass_gap(0);
 214   Copy::fill_to_aligned_words(obj + hs, size - hs);
 215 }
 216 
 217 oop CollectedHeap::obj_allocate(KlassHandle klass, int size, TRAPS) {
 218   debug_only(check_for_valid_allocation_state());
 219   assert(!GC::gc()->heap()->is_gc_active(), "Allocation during gc not allowed");
 220   assert(size >= 0, "int won't convert to size_t");
 221   HeapWord* obj = common_mem_allocate_init(klass, size, CHECK_NULL);
 222   post_allocation_setup_obj(klass, obj, size);
 223   NOT_PRODUCT(GC::gc()->heap()->check_for_bad_heap_word_value(obj, size));
 224   return (oop)obj;
 225 }
 226 
 227 oop CollectedHeap::class_allocate(KlassHandle klass, int size, TRAPS) {
 228   debug_only(check_for_valid_allocation_state());
 229   assert(!GC::gc()->heap()->is_gc_active(), "Allocation during gc not allowed");
 230   assert(size >= 0, "int won't convert to size_t");
 231   HeapWord* obj = common_mem_allocate_init(klass, size, CHECK_NULL);
 232   post_allocation_setup_class(klass, obj, size); // set oop_size
 233   NOT_PRODUCT(GC::gc()->heap()->check_for_bad_heap_word_value(obj, size));
 234   return (oop)obj;
 235 }
 236 
 237 oop CollectedHeap::array_allocate(KlassHandle klass,
 238                                   int size,
 239                                   int length,
 240                                   TRAPS) {
 241   debug_only(check_for_valid_allocation_state());
 242   assert(!GC::gc()->heap()->is_gc_active(), "Allocation during gc not allowed");
 243   assert(size >= 0, "int won't convert to size_t");
 244   HeapWord* obj = common_mem_allocate_init(klass, size, CHECK_NULL);
 245   post_allocation_setup_array(klass, obj, length);
 246   NOT_PRODUCT(GC::gc()->heap()->check_for_bad_heap_word_value(obj, size));
 247   return (oop)obj;
 248 }
 249 
 250 oop CollectedHeap::array_allocate_nozero(KlassHandle klass,
 251                                          int size,
 252                                          int length,
 253                                          TRAPS) {
 254   debug_only(check_for_valid_allocation_state());
 255   assert(!GC::gc()->heap()->is_gc_active(), "Allocation during gc not allowed");
 256   assert(size >= 0, "int won't convert to size_t");
 257   HeapWord* obj = common_mem_allocate_noinit(klass, size, CHECK_NULL);
 258   ((oop)obj)->set_klass_gap(0);
 259   post_allocation_setup_array(klass, obj, length);
 260 #ifndef PRODUCT
 261   const size_t hs = oopDesc::header_size()+1;
 262   GC::gc()->heap()->check_for_non_bad_heap_word_value(obj+hs, size-hs);
 263 #endif
 264   return (oop)obj;
 265 }
 266 
 267 inline HeapWord* CollectedHeap::align_allocation_or_fail(HeapWord* addr,
 268                                                          HeapWord* end,
 269                                                          unsigned short alignment_in_bytes) {
 270   if (alignment_in_bytes <= ObjectAlignmentInBytes) {
 271     return addr;
 272   }
 273 
 274   assert(is_ptr_aligned(addr, HeapWordSize),
 275          "Address " PTR_FORMAT " is not properly aligned.", p2i(addr));
 276   assert(is_size_aligned(alignment_in_bytes, HeapWordSize),
 277          "Alignment size %u is incorrect.", alignment_in_bytes);
 278 
 279   HeapWord* new_addr = (HeapWord*) align_ptr_up(addr, alignment_in_bytes);
 280   size_t padding = pointer_delta(new_addr, addr);
 281 
 282   if (padding == 0) {


< prev index next >