Skip to content

Commit 2f19144

Browse files
aamarshVladimir Kozlov
authored andcommitted
8282024: add EscapeAnalysis statistics under PrintOptoStatistics
Reviewed-by: xliu, kvn
1 parent cdb4768 commit 2f19144

5 files changed

Lines changed: 112 additions & 2 deletions

File tree

src/hotspot/share/opto/compile.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,8 @@ void Compile::print_statistics() {
254254
PhaseOutput::print_statistics();
255255
PhasePeephole::print_statistics();
256256
PhaseIdealLoop::print_statistics();
257+
ConnectionGraph::print_statistics();
258+
PhaseMacroExpand::print_statistics();
257259
if (xtty != NULL) xtty->tail("statistics");
258260
}
259261
if (_intrinsic_hist_flags[as_int(vmIntrinsics::_none)] != 0) {

src/hotspot/share/opto/escape.cpp

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ bool ConnectionGraph::compute_escape() {
233233

234234
if (non_escaped_allocs_worklist.length() == 0) {
235235
_collecting = false;
236+
NOT_PRODUCT(escape_state_statistics(java_objects_worklist);)
236237
return false; // Nothing to do.
237238
}
238239
// Add final simple edges to graph.
@@ -262,14 +263,18 @@ bool ConnectionGraph::compute_escape() {
262263
// processing, calls to CI to resolve symbols (types, fields, methods)
263264
// referenced in bytecode. During symbol resolution VM may throw
264265
// an exception which CI cleans and converts to compilation failure.
265-
if (C->failing()) return false;
266+
if (C->failing()) {
267+
NOT_PRODUCT(escape_state_statistics(java_objects_worklist);)
268+
return false;
269+
}
266270

267271
// 2. Finish Graph construction by propagating references to all
268272
// java objects through graph.
269273
if (!complete_connection_graph(ptnodes_worklist, non_escaped_allocs_worklist,
270274
java_objects_worklist, oop_fields_worklist)) {
271275
// All objects escaped or hit time or iterations limits.
272276
_collecting = false;
277+
NOT_PRODUCT(escape_state_statistics(java_objects_worklist);)
273278
return false;
274279
}
275280

@@ -339,7 +344,10 @@ bool ConnectionGraph::compute_escape() {
339344
// Now use the escape information to create unique types for
340345
// scalar replaceable objects.
341346
split_unique_types(alloc_worklist, arraycopy_worklist, mergemem_worklist);
342-
if (C->failing()) return false;
347+
if (C->failing()) {
348+
NOT_PRODUCT(escape_state_statistics(java_objects_worklist);)
349+
return false;
350+
}
343351
C->print_method(PHASE_AFTER_EA, 2);
344352

345353
#ifdef ASSERT
@@ -375,6 +383,7 @@ bool ConnectionGraph::compute_escape() {
375383
}
376384
}
377385

386+
NOT_PRODUCT(escape_state_statistics(java_objects_worklist);)
378387
return has_non_escaping_obj;
379388
}
380389

@@ -3673,6 +3682,10 @@ void ConnectionGraph::split_unique_types(GrowableArray<Node *> &alloc_worklist,
36733682
}
36743683

36753684
#ifndef PRODUCT
3685+
int ConnectionGraph::_no_escape_counter = 0;
3686+
int ConnectionGraph::_arg_escape_counter = 0;
3687+
int ConnectionGraph::_global_escape_counter = 0;
3688+
36763689
static const char *node_type_names[] = {
36773690
"UnknownType",
36783691
"JavaObject",
@@ -3781,6 +3794,30 @@ void ConnectionGraph::dump(GrowableArray<PointsToNode*>& ptnodes_worklist) {
37813794
}
37823795
}
37833796

3797+
void ConnectionGraph::print_statistics() {
3798+
tty->print_cr("No escape = %d, Arg escape = %d, Global escape = %d", Atomic::load(&_no_escape_counter), Atomic::load(&_arg_escape_counter), Atomic::load(&_global_escape_counter));
3799+
}
3800+
3801+
void ConnectionGraph::escape_state_statistics(GrowableArray<JavaObjectNode*>& java_objects_worklist) {
3802+
if (!PrintOptoStatistics || (_invocation > 0)) { // Collect data only for the first invocation
3803+
return;
3804+
}
3805+
for (int next = 0; next < java_objects_worklist.length(); ++next) {
3806+
JavaObjectNode* ptn = java_objects_worklist.at(next);
3807+
if (ptn->ideal_node()->is_Allocate()) {
3808+
if (ptn->escape_state() == PointsToNode::NoEscape) {
3809+
Atomic::inc(&ConnectionGraph::_no_escape_counter);
3810+
} else if (ptn->escape_state() == PointsToNode::ArgEscape) {
3811+
Atomic::inc(&ConnectionGraph::_arg_escape_counter);
3812+
} else if (ptn->escape_state() == PointsToNode::GlobalEscape) {
3813+
Atomic::inc(&ConnectionGraph::_global_escape_counter);
3814+
} else {
3815+
assert(false, "Unexpected Escape State");
3816+
}
3817+
}
3818+
}
3819+
}
3820+
37843821
void ConnectionGraph::trace_es_update_helper(PointsToNode* ptn, PointsToNode::EscapeState es, bool fields, const char* reason) const {
37853822
if (_compile->directive()->TraceEscapeAnalysisOption) {
37863823
assert(ptn != nullptr, "should not be null");

src/hotspot/share/opto/escape.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,12 @@ class ConnectionGraph: public ResourceObj {
636636
bool add_final_edges_unsafe_access(Node* n, uint opcode);
637637

638638
#ifndef PRODUCT
639+
static int _no_escape_counter;
640+
static int _arg_escape_counter;
641+
static int _global_escape_counter;
639642
void dump(GrowableArray<PointsToNode*>& ptnodes_worklist);
643+
static void print_statistics();
644+
void escape_state_statistics(GrowableArray<JavaObjectNode*>& java_objects_worklist);
640645
#endif
641646
};
642647

src/hotspot/share/opto/macro.cpp

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,11 @@ CallNode* PhaseMacroExpand::make_slow_call(CallNode *oldcall, const TypeFunc* sl
160160
void PhaseMacroExpand::eliminate_gc_barrier(Node* p2x) {
161161
BarrierSetC2 *bs = BarrierSet::barrier_set()->barrier_set_c2();
162162
bs->eliminate_gc_barrier(this, p2x);
163+
#ifndef PRODUCT
164+
if (PrintOptoStatistics) {
165+
Atomic::inc(&PhaseMacroExpand::_GC_barriers_removed_counter);
166+
}
167+
#endif
163168
}
164169

165170
// Search for a memory operation for the specified memory slice.
@@ -2339,6 +2344,7 @@ void PhaseMacroExpand::expand_subtypecheck_node(SubTypeCheckNode *check) {
23392344
void PhaseMacroExpand::eliminate_macro_nodes() {
23402345
if (C->macro_count() == 0)
23412346
return;
2347+
NOT_PRODUCT(int membar_before = count_MemBar(C);)
23422348

23432349
// Before elimination may re-mark (change to Nested or NonEscObj)
23442350
// all associated (same box and obj) lock and unlock nodes.
@@ -2364,6 +2370,11 @@ void PhaseMacroExpand::eliminate_macro_nodes() {
23642370
DEBUG_ONLY(int old_macro_count = C->macro_count();)
23652371
if (n->is_AbstractLock()) {
23662372
success = eliminate_locking_node(n->as_AbstractLock());
2373+
#ifndef PRODUCT
2374+
if (success && PrintOptoStatistics) {
2375+
Atomic::inc(&PhaseMacroExpand::_monitor_objects_removed_counter);
2376+
}
2377+
#endif
23672378
}
23682379
assert(success == (C->macro_count() < old_macro_count), "elimination reduces macro count");
23692380
progress = progress || success;
@@ -2382,6 +2393,11 @@ void PhaseMacroExpand::eliminate_macro_nodes() {
23822393
case Node::Class_Allocate:
23832394
case Node::Class_AllocateArray:
23842395
success = eliminate_allocate_node(n->as_Allocate());
2396+
#ifndef PRODUCT
2397+
if (success && PrintOptoStatistics) {
2398+
Atomic::inc(&PhaseMacroExpand::_objs_scalar_replaced_counter);
2399+
}
2400+
#endif
23852401
break;
23862402
case Node::Class_CallStaticJava:
23872403
success = eliminate_boxing_node(n->as_CallStaticJava());
@@ -2411,6 +2427,12 @@ void PhaseMacroExpand::eliminate_macro_nodes() {
24112427
progress = progress || success;
24122428
}
24132429
}
2430+
#ifndef PRODUCT
2431+
if (PrintOptoStatistics) {
2432+
int membar_after = count_MemBar(C);
2433+
Atomic::add(&PhaseMacroExpand::_memory_barriers_removed_counter, membar_before - membar_after);
2434+
}
2435+
#endif
24142436
}
24152437

24162438
//------------------------------expand_macro_nodes----------------------
@@ -2599,3 +2621,38 @@ bool PhaseMacroExpand::expand_macro_nodes() {
25992621
_igvn.set_delay_transform(false);
26002622
return false;
26012623
}
2624+
2625+
#ifndef PRODUCT
2626+
int PhaseMacroExpand::_objs_scalar_replaced_counter = 0;
2627+
int PhaseMacroExpand::_monitor_objects_removed_counter = 0;
2628+
int PhaseMacroExpand::_GC_barriers_removed_counter = 0;
2629+
int PhaseMacroExpand::_memory_barriers_removed_counter = 0;
2630+
2631+
void PhaseMacroExpand::print_statistics() {
2632+
tty->print("Objects scalar replaced = %d, ", Atomic::load(&_objs_scalar_replaced_counter));
2633+
tty->print("Monitor objects removed = %d, ", Atomic::load(&_monitor_objects_removed_counter));
2634+
tty->print("GC barriers removed = %d, ", Atomic::load(&_GC_barriers_removed_counter));
2635+
tty->print_cr("Memory barriers removed = %d", Atomic::load(&_memory_barriers_removed_counter));
2636+
}
2637+
2638+
int PhaseMacroExpand::count_MemBar(Compile *C) {
2639+
if (!PrintOptoStatistics) {
2640+
return 0;
2641+
}
2642+
Unique_Node_List ideal_nodes;
2643+
int total = 0;
2644+
ideal_nodes.map(C->live_nodes(), NULL);
2645+
ideal_nodes.push(C->root());
2646+
for (uint next = 0; next < ideal_nodes.size(); ++next) {
2647+
Node* n = ideal_nodes.at(next);
2648+
if (n->is_MemBar()) {
2649+
total++;
2650+
}
2651+
for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) {
2652+
Node* m = n->fast_out(i);
2653+
ideal_nodes.push(m);
2654+
}
2655+
}
2656+
return total;
2657+
}
2658+
#endif

src/hotspot/share/opto/macro.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,15 @@ class PhaseMacroExpand : public Phase {
208208

209209
PhaseIterGVN &igvn() const { return _igvn; }
210210

211+
#ifndef PRODUCT
212+
static int _objs_scalar_replaced_counter;
213+
static int _monitor_objects_removed_counter;
214+
static int _GC_barriers_removed_counter;
215+
static int _memory_barriers_removed_counter;
216+
static void print_statistics();
217+
static int count_MemBar(Compile *C);
218+
#endif
219+
211220
// Members accessed from BarrierSetC2
212221
void replace_node(Node* source, Node* target) { _igvn.replace_node(source, target); }
213222
Node* intcon(jint con) const { return _igvn.intcon(con); }

0 commit comments

Comments
 (0)