Skip to content

Commit 381021a

Browse files
committed
Merge
2 parents 2c3ae19 + afc4441 commit 381021a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+721
-231
lines changed

src/hotspot/share/c1/c1_Runtime1.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,20 @@ JRT_ENTRY_NO_ASYNC(static address, exception_handler_for_pc_helper(JavaThread* t
539539
}
540540
#endif
541541

542+
// debugging support
543+
// tracing
544+
if (log_is_enabled(Info, exceptions)) {
545+
ResourceMark rm;
546+
stringStream tempst;
547+
assert(nm->method() != NULL, "Unexpected NULL method()");
548+
tempst.print("C1 compiled method <%s>\n"
549+
" at PC" INTPTR_FORMAT " for thread " INTPTR_FORMAT,
550+
nm->method()->print_value_string(), p2i(pc), p2i(thread));
551+
Exceptions::log_exception(exception, tempst.as_string());
552+
}
553+
// for AbortVMOnException flag
554+
Exceptions::debug_check_abort(exception);
555+
542556
// Check the stack guard pages and reenable them if necessary and there is
543557
// enough space on the stack to do so. Use fast exceptions only if the guard
544558
// pages are enabled.
@@ -585,20 +599,6 @@ JRT_ENTRY_NO_ASYNC(static address, exception_handler_for_pc_helper(JavaThread* t
585599
// New exception handling mechanism can support inlined methods
586600
// with exception handlers since the mappings are from PC to PC
587601

588-
// debugging support
589-
// tracing
590-
if (log_is_enabled(Info, exceptions)) {
591-
ResourceMark rm;
592-
stringStream tempst;
593-
assert(nm->method() != NULL, "Unexpected NULL method()");
594-
tempst.print("compiled method <%s>\n"
595-
" at PC" INTPTR_FORMAT " for thread " INTPTR_FORMAT,
596-
nm->method()->print_value_string(), p2i(pc), p2i(thread));
597-
Exceptions::log_exception(exception, tempst.as_string());
598-
}
599-
// for AbortVMOnException flag
600-
Exceptions::debug_check_abort(exception);
601-
602602
// Clear out the exception oop and pc since looking up an
603603
// exception handler can cause class loading, which might throw an
604604
// exception and those fields are expected to be clear during

src/hotspot/share/ci/ciMethodData.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ ciMethodData::ciMethodData(MethodData* md)
4747
_saw_free_extra_data(false),
4848
// Initialize the escape information (to "don't know.");
4949
_eflags(0), _arg_local(0), _arg_stack(0), _arg_returned(0),
50+
_creation_mileage(0),
5051
_current_mileage(0),
5152
_invocation_counter(0),
5253
_backedge_counter(0),
@@ -242,6 +243,7 @@ void ciMethodData::load_data() {
242243
load_remaining_extra_data();
243244

244245
// Note: Extra data are all BitData, and do not need translation.
246+
_creation_mileage = mdo->creation_mileage();
245247
_current_mileage = MethodData::mileage_of(mdo->method());
246248
_invocation_counter = mdo->invocation_count();
247249
_backedge_counter = mdo->backedge_count();

src/hotspot/share/ci/ciMethodData.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,8 @@ class ciMethodData : public ciMetadata {
395395
intx _arg_stack; // bit set of stack-allocatable arguments
396396
intx _arg_returned; // bit set of returned arguments
397397

398+
int _creation_mileage; // method mileage at MDO creation
399+
398400
// Maturity of the oop when the snapshot is taken.
399401
int _current_mileage;
400402

@@ -475,7 +477,7 @@ class ciMethodData : public ciMetadata {
475477
bool is_empty() { return _state == empty_state; }
476478
bool is_mature() { return _state == mature_state; }
477479

478-
int creation_mileage() { return _orig.creation_mileage(); }
480+
int creation_mileage() { return _creation_mileage; }
479481
int current_mileage() { return _current_mileage; }
480482

481483
int invocation_count() { return _invocation_counter; }

src/hotspot/share/gc/g1/g1HeapVerifier.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,7 @@ bool G1HeapVerifier::should_verify(G1VerifyType type) {
472472

473473
void G1HeapVerifier::verify(VerifyOption vo) {
474474
assert_at_safepoint_on_vm_thread();
475+
assert(Heap_lock->is_locked(), "heap must be locked");
475476

476477
log_debug(gc, verify)("Roots");
477478
VerifyRootsClosure rootsCl(vo);

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

Lines changed: 2 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -24,111 +24,32 @@
2424

2525
#include "precompiled.hpp"
2626
#include "gc/shared/allocTracer.hpp"
27-
#include "gc/shared/threadLocalAllocBuffer.inline.hpp"
2827
#include "jfr/jfrEvents.hpp"
2928
#include "utilities/globalDefinitions.hpp"
3029
#include "utilities/macros.hpp"
3130
#if INCLUDE_JFR
3231
#include "jfr/support/jfrAllocationTracer.hpp"
3332
#endif
3433

35-
static THREAD_LOCAL int64_t _last_allocated_bytes = 0;
36-
37-
inline void send_allocation_sample(const Klass* klass, int64_t allocated_bytes) {
38-
assert(allocated_bytes > 0, "invariant");
39-
EventObjectAllocationSample event;
40-
if (event.should_commit()) {
41-
const size_t weight = allocated_bytes - _last_allocated_bytes;
42-
assert(weight > 0, "invariant");
43-
event.set_objectClass(klass);
44-
event.set_weight(weight);
45-
event.commit();
46-
_last_allocated_bytes = allocated_bytes;
47-
}
48-
}
49-
50-
inline bool send_allocation_sample_with_result(const Klass* klass, int64_t allocated_bytes) {
51-
assert(allocated_bytes > 0, "invariant");
52-
EventObjectAllocationSample event;
53-
if (event.should_commit()) {
54-
const size_t weight = allocated_bytes - _last_allocated_bytes;
55-
assert(weight > 0, "invariant");
56-
event.set_objectClass(klass);
57-
event.set_weight(weight);
58-
event.commit();
59-
_last_allocated_bytes = allocated_bytes;
60-
return true;
61-
}
62-
return false;
63-
}
64-
65-
inline intptr_t estimate_tlab_size_bytes(Thread* thread) {
66-
assert(thread != NULL, "invariant");
67-
const size_t desired_tlab_size_bytes = thread->tlab().desired_size() * HeapWordSize;
68-
const size_t alignment_reserve_bytes = thread->tlab().alignment_reserve_in_bytes();
69-
assert(desired_tlab_size_bytes > alignment_reserve_bytes, "invariant");
70-
return static_cast<intptr_t>(desired_tlab_size_bytes - alignment_reserve_bytes);
71-
}
72-
73-
inline int64_t load_allocated_bytes(Thread* thread) {
74-
const int64_t allocated_bytes = thread->allocated_bytes();
75-
if (allocated_bytes < _last_allocated_bytes) {
76-
// A hw thread can detach and reattach to the VM, and when it does,
77-
// it gets a new JavaThread representation. The thread local variable
78-
// tracking _last_allocated_bytes is mapped to the existing hw thread,
79-
// so it needs to be reset.
80-
_last_allocated_bytes = 0;
81-
}
82-
return allocated_bytes == _last_allocated_bytes ? 0 : allocated_bytes;
83-
}
84-
85-
// To avoid large objects from being undersampled compared to the regular TLAB samples,
86-
// the data amount is normalized as if it was a TLAB, giving a number of TLAB sampling attempts to the large object.
87-
static void normalize_as_tlab_and_send_allocation_samples(Klass* klass, intptr_t obj_alloc_size_bytes, Thread* thread) {
88-
const int64_t allocated_bytes = load_allocated_bytes(thread);
89-
assert(allocated_bytes > 0, "invariant"); // obj_alloc_size_bytes is already attributed to allocated_bytes at this point.
90-
if (!UseTLAB) {
91-
send_allocation_sample(klass, allocated_bytes);
92-
return;
93-
}
94-
const intptr_t tlab_size_bytes = estimate_tlab_size_bytes(thread);
95-
if (allocated_bytes - _last_allocated_bytes < tlab_size_bytes) {
96-
return;
97-
}
98-
assert(obj_alloc_size_bytes > 0, "invariant");
99-
do {
100-
if (send_allocation_sample_with_result(klass, allocated_bytes)) {
101-
return;
102-
}
103-
obj_alloc_size_bytes -= tlab_size_bytes;
104-
} while (obj_alloc_size_bytes > 0);
105-
}
106-
10734
void AllocTracer::send_allocation_outside_tlab(Klass* klass, HeapWord* obj, size_t alloc_size, Thread* thread) {
108-
JFR_ONLY(JfrAllocationTracer tracer(obj, alloc_size, thread);)
35+
JFR_ONLY(JfrAllocationTracer tracer(klass, obj, alloc_size, true, thread);)
10936
EventObjectAllocationOutsideTLAB event;
11037
if (event.should_commit()) {
11138
event.set_objectClass(klass);
11239
event.set_allocationSize(alloc_size);
11340
event.commit();
11441
}
115-
normalize_as_tlab_and_send_allocation_samples(klass, static_cast<intptr_t>(alloc_size), thread);
11642
}
11743

11844
void AllocTracer::send_allocation_in_new_tlab(Klass* klass, HeapWord* obj, size_t tlab_size, size_t alloc_size, Thread* thread) {
119-
JFR_ONLY(JfrAllocationTracer tracer(obj, alloc_size, thread);)
45+
JFR_ONLY(JfrAllocationTracer tracer(klass, obj, alloc_size, false, thread);)
12046
EventObjectAllocationInNewTLAB event;
12147
if (event.should_commit()) {
12248
event.set_objectClass(klass);
12349
event.set_allocationSize(alloc_size);
12450
event.set_tlabSize(tlab_size);
12551
event.commit();
12652
}
127-
const int64_t allocated_bytes = load_allocated_bytes(thread);
128-
if (allocated_bytes == 0) {
129-
return;
130-
}
131-
send_allocation_sample(klass, allocated_bytes);
13253
}
13354

13455
void AllocTracer::send_allocation_requiring_gc_event(size_t size, uint gcId) {

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,20 @@
4646
#include "gc/g1/g1Policy.hpp"
4747
#endif // INCLUDE_G1GC
4848

49+
bool VM_GC_Sync_Operation::doit_prologue() {
50+
Heap_lock->lock();
51+
return true;
52+
}
53+
54+
void VM_GC_Sync_Operation::doit_epilogue() {
55+
Heap_lock->unlock();
56+
}
57+
58+
void VM_Verify::doit() {
59+
Universe::heap()->prepare_for_verify();
60+
Universe::verify();
61+
}
62+
4963
VM_GC_Operation::~VM_GC_Operation() {
5064
CollectedHeap* ch = Universe::heap();
5165
ch->soft_ref_policy()->set_all_soft_refs_clear(false);
@@ -94,8 +108,7 @@ bool VM_GC_Operation::doit_prologue() {
94108
proper_unit_for_byte_size(NewSize)));
95109
}
96110

97-
// If the GC count has changed someone beat us to the collection
98-
Heap_lock->lock();
111+
VM_GC_Sync_Operation::doit_prologue();
99112

100113
// Check invocations
101114
if (skip_operation()) {
@@ -116,7 +129,7 @@ void VM_GC_Operation::doit_epilogue() {
116129
if (Universe::has_reference_pending_list()) {
117130
Heap_lock->notify_all();
118131
}
119-
Heap_lock->unlock();
132+
VM_GC_Sync_Operation::doit_epilogue();
120133
}
121134

122135
bool VM_GC_HeapInspection::skip_operation() const {

src/hotspot/share/gc/shared/gcVMOperations.hpp

Lines changed: 52 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,27 @@
3939
// a set of operations (VM_Operation) related to GC.
4040
//
4141
// VM_Operation
42+
// VM_GC_Sync_Operation
4243
// VM_GC_Operation
43-
// VM_GC_HeapInspection
44-
// VM_GenCollectFull
45-
// VM_GenCollectFullConcurrent
46-
// VM_ParallelGCSystemGC
47-
// VM_CollectForAllocation
48-
// VM_GenCollectForAllocation
49-
// VM_ParallelGCFailedAllocation
44+
// VM_GC_HeapInspection
45+
// VM_PopulateDynamicDumpSharedSpace
46+
// VM_GenCollectFull
47+
// VM_GenCollectFullConcurrent
48+
// VM_ParallelGCSystemGC
49+
// VM_CollectForAllocation
50+
// VM_GenCollectForAllocation
51+
// VM_ParallelGCFailedAllocation
52+
// VM_Verify
53+
// VM_PopulateDumpSharedSpace
54+
//
55+
// VM_GC_Sync_Operation
56+
// - implements only synchronization with other VM operations of the
57+
// same kind using the Heap_lock, not actually doing a GC.
58+
//
5059
// VM_GC_Operation
51-
// - implements methods common to all classes in the hierarchy:
52-
// prevents multiple gc requests and manages lock on heap;
60+
// - implements methods common to all operations that perform garbage collections,
61+
// checking that the VM is in a state to do GC and preventing multiple GC
62+
// requests.
5363
//
5464
// VM_GC_HeapInspection
5565
// - prints class histogram on SIGBREAK if PrintClassHistogram
@@ -68,11 +78,37 @@
6878
// - these operations preform full collection of heaps of
6979
// different kind
7080
//
81+
// VM_Verify
82+
// - verifies the heap
83+
//
84+
// VM_PopulateDynamicDumpSharedSpace
85+
// - populates the CDS archive area with the information from the archive file.
86+
//
87+
// VM_PopulateDumpSharedSpace
88+
// - creates the CDS archive
89+
//
90+
91+
class VM_GC_Sync_Operation : public VM_Operation {
92+
public:
93+
94+
VM_GC_Sync_Operation() : VM_Operation() { }
95+
96+
// Acquires the Heap_lock.
97+
virtual bool doit_prologue();
98+
// Releases the Heap_lock.
99+
virtual void doit_epilogue();
100+
};
101+
102+
class VM_Verify : public VM_GC_Sync_Operation {
103+
public:
104+
VMOp_Type type() const { return VMOp_Verify; }
105+
void doit();
106+
};
71107

72-
class VM_GC_Operation: public VM_Operation {
108+
class VM_GC_Operation: public VM_GC_Sync_Operation {
73109
protected:
74-
uint _gc_count_before; // gc count before acquiring PLL
75-
uint _full_gc_count_before; // full gc count before acquiring PLL
110+
uint _gc_count_before; // gc count before acquiring the Heap_lock
111+
uint _full_gc_count_before; // full gc count before acquiring the Heap_lock
76112
bool _full; // whether a "full" collection
77113
bool _prologue_succeeded; // whether doit_prologue succeeded
78114
GCCause::Cause _gc_cause; // the putative cause for this gc op
@@ -84,7 +120,7 @@ class VM_GC_Operation: public VM_Operation {
84120
VM_GC_Operation(uint gc_count_before,
85121
GCCause::Cause _cause,
86122
uint full_gc_count_before = 0,
87-
bool full = false) {
123+
bool full = false) : VM_GC_Sync_Operation() {
88124
_full = full;
89125
_prologue_succeeded = false;
90126
_gc_count_before = gc_count_before;
@@ -106,9 +142,10 @@ class VM_GC_Operation: public VM_Operation {
106142
}
107143
~VM_GC_Operation();
108144

109-
// Acquire the reference synchronization lock
145+
// Acquire the Heap_lock and determine if this VM operation should be executed
146+
// (i.e. not skipped). Return this result, and also store it in _prologue_succeeded.
110147
virtual bool doit_prologue();
111-
// Do notifyAll (if needed) and release held lock
148+
// Notify the Heap_lock if needed and release it.
112149
virtual void doit_epilogue();
113150

114151
virtual bool allow_nested_vm_operations() const { return true; }

src/hotspot/share/gc/z/zDriver.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "precompiled.hpp"
2525
#include "gc/shared/gcId.hpp"
2626
#include "gc/shared/gcLocker.hpp"
27+
#include "gc/shared/gcVMOperations.hpp"
2728
#include "gc/shared/isGCActiveMark.hpp"
2829
#include "gc/z/zBreakpoint.hpp"
2930
#include "gc/z/zCollectedHeap.hpp"

src/hotspot/share/jfr/support/jfrAllocationTracer.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@
2525
#include "precompiled.hpp"
2626
#include "jfr/leakprofiler/leakProfiler.hpp"
2727
#include "jfr/support/jfrAllocationTracer.hpp"
28+
#include "jfr/support/jfrObjectAllocationSample.hpp"
2829
#include "jfr/support/jfrThreadLocal.hpp"
2930
#include "runtime/thread.hpp"
3031

31-
JfrAllocationTracer::JfrAllocationTracer(HeapWord* obj, size_t alloc_size, Thread* thread) : _tl(NULL) {
32+
JfrAllocationTracer::JfrAllocationTracer(const Klass* klass, HeapWord* obj, size_t alloc_size, bool outside_tlab, Thread* thread) : _tl(NULL) {
33+
JfrObjectAllocationSample::send_event(klass, alloc_size, outside_tlab, thread);
3234
if (LeakProfiler::is_running()) {
3335
_tl = thread->jfr_thread_local();
3436
LeakProfiler::sample(obj, alloc_size, thread->as_Java_thread());

src/hotspot/share/jfr/support/jfrAllocationTracer.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,15 @@
2727

2828
#include "memory/allocation.hpp"
2929

30+
class Klass;
3031
class JfrThreadLocal;
32+
class Thread;
3133

3234
class JfrAllocationTracer : public StackObj {
3335
private:
3436
JfrThreadLocal* _tl;
3537
public:
36-
JfrAllocationTracer(HeapWord* obj, size_t alloc_size, Thread* thread);
38+
JfrAllocationTracer(const Klass* klass, HeapWord* obj, size_t alloc_size, bool outside_tlab, Thread* thread);
3739
~JfrAllocationTracer();
3840
};
3941

0 commit comments

Comments
 (0)