< prev index next >

src/hotspot/share/gc/shared/collectedHeap.cpp

Print this page
rev 48551 : [mq]: heap8
rev 48552 : [mq]: heap10a
rev 48553 : [mq]: heap14_rebased
rev 48557 : [mq]: heap17
rev 48562 : [mq]: heap23
rev 48563 : [mq]: heap_to_thread
rev 48564 : [mq]: update-spec
rev 48565 : [mq]: event

@@ -36,10 +36,11 @@
 #include "logging/log.hpp"
 #include "memory/metaspace.hpp"
 #include "memory/resourceArea.hpp"
 #include "oops/instanceMirrorKlass.hpp"
 #include "oops/oop.inline.hpp"
+#include "runtime/heapMonitoring.hpp"
 #include "runtime/init.hpp"
 #include "runtime/thread.inline.hpp"
 #include "runtime/threadSMR.hpp"
 #include "services/heapDumper.hpp"
 #include "utilities/align.hpp"

@@ -288,10 +289,21 @@
   }
 }
 #endif
 
 HeapWord* CollectedHeap::allocate_from_tlab_slow(Klass* klass, Thread* thread, size_t size) {
+  HeapWord* obj = NULL;
+
+  if (HeapMonitoring::enabled()) {
+    // Try to allocate the sampled object from TLAB, it is possible a sample
+    // point was put and the TLAB still has space.
+    obj = thread->tlab().allocate_sampled_object(size);
+
+    if (obj != NULL) {
+      return obj;
+    }
+  }
 
   // Retain tlab and allocate object in shared space if
   // the amount free in the tlab is too large to discard.
   if (thread->tlab().free() > thread->tlab().refill_waste_limit()) {
     thread->tlab().record_slow_allocation(size);

@@ -307,11 +319,11 @@
   if (new_tlab_size == 0) {
     return NULL;
   }
 
   // Allocate a new TLAB...
-  HeapWord* obj = Universe::heap()->allocate_new_tlab(new_tlab_size);
+  obj = Universe::heap()->allocate_new_tlab(new_tlab_size);
   if (obj == NULL) {
     return NULL;
   }
 
   AllocTracer::send_allocation_in_new_tlab(klass, obj, new_tlab_size * HeapWordSize, size * HeapWordSize, thread);

@@ -327,10 +339,18 @@
     // any concurrent GC thread.
     size_t hdr_size = oopDesc::header_size();
     Copy::fill_to_words(obj + hdr_size, new_tlab_size - hdr_size, badHeapWordVal);
 #endif // ASSERT
   }
+
+  // Send the thread information about this allocation in case a sample is
+  // requested.
+  if (HeapMonitoring::enabled()) {
+    size_t tlab_bytes_since_last_sample = thread->tlab().bytes_since_last_sample_point();
+    thread->heap_sampler().check_for_sampling(obj, size, tlab_bytes_since_last_sample);
+  }
+
   thread->tlab().fill(obj, obj + size, new_tlab_size);
   return obj;
 }
 
 void CollectedHeap::flush_deferred_store_barrier(JavaThread* thread) {
< prev index next >