< prev index next >

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

Print this page
rev 49877 : [mq]: rebase

@@ -32,10 +32,11 @@
 #include "memory/universe.hpp"
 #include "oops/arrayOop.hpp"
 #include "oops/oop.inline.hpp"
 #include "prims/jvmtiExport.hpp"
 #include "runtime/sharedRuntime.hpp"
+#include "runtime/handles.inline.hpp"
 #include "runtime/thread.inline.hpp"
 #include "services/lowMemoryDetector.hpp"
 #include "utilities/align.hpp"
 #include "utilities/copy.hpp"
 

@@ -152,14 +153,18 @@
   if (result != NULL) {
     NOT_PRODUCT(Universe::heap()->
       check_for_non_bad_heap_word_value(result, size));
     assert(!HAS_PENDING_EXCEPTION,
            "Unexpected exception, will result in uninitialized storage");
-    THREAD->incr_allocated_bytes(size * HeapWordSize);
+    int size_in_bytes = size * HeapWordSize;
+    THREAD->incr_allocated_bytes(size_in_bytes);
 
-    AllocTracer::send_allocation_outside_tlab(klass, result, size * HeapWordSize, THREAD);
+    AllocTracer::send_allocation_outside_tlab(klass, result, size_in_bytes, THREAD);
 
+    if (ThreadHeapSampler::enabled()) {
+      THREAD->heap_sampler().check_for_sampling(result, size_in_bytes);
+    }
     return result;
   }
 
 
   if (!gc_overhead_limit_was_exceeded) {

@@ -214,54 +219,80 @@
 
 oop CollectedHeap::obj_allocate(Klass* klass, int size, TRAPS) {
   debug_only(check_for_valid_allocation_state());
   assert(!Universe::heap()->is_gc_active(), "Allocation during gc not allowed");
   assert(size >= 0, "int won't convert to size_t");
+
+  HandleMark hm(THREAD);
+  Handle result;
+  {
+    JvmtiSampledObjectAllocEventCollector collector;
   HeapWord* obj = common_mem_allocate_init(klass, size, CHECK_NULL);
   post_allocation_setup_obj(klass, obj, size);
   NOT_PRODUCT(Universe::heap()->check_for_bad_heap_word_value(obj, size));
-  return (oop)obj;
+    result = Handle(THREAD, (oop) obj);
+  }
+  return result();
 }
 
 oop CollectedHeap::class_allocate(Klass* klass, int size, TRAPS) {
   debug_only(check_for_valid_allocation_state());
   assert(!Universe::heap()->is_gc_active(), "Allocation during gc not allowed");
   assert(size >= 0, "int won't convert to size_t");
+
+  // No Sampling collector for classes at this level: there is a risk of
+  // MultiArray and JvmtiThreadState deadlock. Therefore, class allocation
+  // is put on the callers of this method, avoiding the risk of deadlock.
+
   HeapWord* obj = common_mem_allocate_init(klass, size, CHECK_NULL);
   post_allocation_setup_class(klass, obj, size); // set oop_size
   NOT_PRODUCT(Universe::heap()->check_for_bad_heap_word_value(obj, size));
-  return (oop)obj;
+  return (oop) obj;
 }
 
 oop CollectedHeap::array_allocate(Klass* klass,
                                   int size,
                                   int length,
                                   TRAPS) {
   debug_only(check_for_valid_allocation_state());
   assert(!Universe::heap()->is_gc_active(), "Allocation during gc not allowed");
   assert(size >= 0, "int won't convert to size_t");
+
+  HandleMark hm(THREAD);
+  Handle result;
+  {
+    JvmtiSampledObjectAllocEventCollector collector;
   HeapWord* obj = common_mem_allocate_init(klass, size, CHECK_NULL);
   post_allocation_setup_array(klass, obj, length);
   NOT_PRODUCT(Universe::heap()->check_for_bad_heap_word_value(obj, size));
-  return (oop)obj;
+    result = Handle(THREAD, (oop) obj);
+  }
+  return result();
 }
 
 oop CollectedHeap::array_allocate_nozero(Klass* klass,
                                          int size,
                                          int length,
                                          TRAPS) {
   debug_only(check_for_valid_allocation_state());
   assert(!Universe::heap()->is_gc_active(), "Allocation during gc not allowed");
   assert(size >= 0, "int won't convert to size_t");
+
+  HandleMark hm(THREAD);
+  Handle result;
+  {
+    JvmtiSampledObjectAllocEventCollector collector;
   HeapWord* obj = common_mem_allocate_noinit(klass, size, CHECK_NULL);
   ((oop)obj)->set_klass_gap(0);
   post_allocation_setup_array(klass, obj, length);
 #ifndef PRODUCT
   const size_t hs = oopDesc::header_size()+1;
   Universe::heap()->check_for_non_bad_heap_word_value(obj+hs, size-hs);
 #endif
-  return (oop)obj;
+    result = Handle(THREAD, (oop) obj);
+  }
+  return result();
 }
 
 inline HeapWord* CollectedHeap::align_allocation_or_fail(HeapWord* addr,
                                                          HeapWord* end,
                                                          unsigned short alignment_in_bytes) {
< prev index next >