< prev index next >
src/share/vm/gc/shared/collectedHeap.cpp
Print this page
@@ -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 "services/heapDumper.hpp"
@@ -294,10 +295,31 @@
}
}
#endif
HeapWord* CollectedHeap::allocate_from_tlab_slow(Klass* klass, Thread* thread, size_t size) {
+ // We can come here for three reasons:
+ // - We either really did fill the tlab.
+ // - We pretended to everyone we did and we want to sample.
+ // - Both of the above reasons are true at the same time.
+ if (HeapMonitoring::enabled()) {
+ if (thread->tlab().should_sample()) {
+ // The tlab could still have space after this sample.
+ thread->tlab().set_back_actual_end();
+
+ // Try to allocate again: it could work now.
+ HeapWord* obj = thread->tlab().allocate(size);
+ if (obj != NULL) {
+ // Object got allocated, sample it now.
+ HeapMonitoring::object_alloc_do_sample(thread,
+ reinterpret_cast<oopDesc*>(obj),
+ size);
+ thread->tlab().pick_next_sample();
+ 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);
@@ -334,10 +356,20 @@
size_t hdr_size = oopDesc::header_size();
Copy::fill_to_words(obj + hdr_size, new_tlab_size - hdr_size, badHeapWordVal);
#endif // ASSERT
}
thread->tlab().fill(obj, obj + size, new_tlab_size);
+
+ if (HeapMonitoring::enabled()) {
+ if (thread->tlab().should_sample()) {
+ HeapMonitoring::object_alloc_do_sample(thread,
+ reinterpret_cast<oopDesc*>(obj),
+ size);
+ }
+ // Always pick a next sample here.
+ thread->tlab().pick_next_sample();
+ }
return obj;
}
void CollectedHeap::flush_deferred_store_barrier(JavaThread* thread) {
MemRegion deferred = thread->deferred_card_mark();
< prev index next >