Skip to content

Commit b7d483c

Browse files
committed
8255245: C1: Fix output of -XX:+PrintCFGToFile to open it with visualizer
Reviewed-by: kvn, xliu
1 parent 5e0a8cd commit b7d483c

File tree

3 files changed

+36
-14
lines changed

3 files changed

+36
-14
lines changed

src/hotspot/share/c1/c1_CFGPrinter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ void CFGPrinterOutput::print_intervals(IntervalList* intervals, const char* name
325325

326326
for (int i = 0; i < intervals->length(); i++) {
327327
if (intervals->at(i) != NULL) {
328-
intervals->at(i)->print_on(output());
328+
intervals->at(i)->print_on(output(), true);
329329
}
330330
}
331331

src/hotspot/share/c1/c1_LinearScan.cpp

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3212,6 +3212,12 @@ void LinearScan::print_reg_num(outputStream* out, int reg_num) {
32123212
return;
32133213
}
32143214

3215+
LIR_Opr opr = get_operand(reg_num);
3216+
assert(opr->is_valid(), "unknown register");
3217+
opr->print(out);
3218+
}
3219+
3220+
LIR_Opr LinearScan::get_operand(int reg_num) {
32153221
LIR_Opr opr = LIR_OprFact::illegal();
32163222

32173223
#ifdef X86
@@ -3231,9 +3237,9 @@ void LinearScan::print_reg_num(outputStream* out, int reg_num) {
32313237
opr = LIR_OprFact::single_xmm(reg_num - pd_first_xmm_reg);
32323238
#endif
32333239
} else {
3234-
assert(false, "unknown register");
3240+
// reg_num == -1 or a virtual register, return the illegal operand
32353241
}
3236-
opr->print(out);
3242+
return opr;
32373243
}
32383244

32393245
Interval* LinearScan::find_interval_at(int reg_num) const {
@@ -4598,7 +4604,7 @@ bool Interval::intersects_any_children_of(Interval* interval) const {
45984604

45994605

46004606
#ifndef PRODUCT
4601-
void Interval::print_on(outputStream* out) const {
4607+
void Interval::print_on(outputStream* out, bool is_cfg_printer) const {
46024608
const char* SpillState2Name[] = { "no definition", "no spill store", "one spill store", "store at definition", "start in memory", "no optimization" };
46034609
const char* UseKind2Name[] = { "N", "L", "S", "M" };
46044610

@@ -4608,18 +4614,29 @@ void Interval::print_on(outputStream* out) const {
46084614
} else {
46094615
type_name = type2name(type());
46104616
}
4611-
46124617
out->print("%d %s ", reg_num(), type_name);
4613-
if (reg_num() < LIR_OprDesc::vreg_base) {
4614-
LinearScan::print_reg_num(out, assigned_reg());
4615-
} else if (assigned_reg() != -1 && (LinearScan::num_physical_regs(type()) == 1 || assigned_regHi() != -1)) {
4616-
LinearScan::calc_operand_for_interval(this)->print(out);
4618+
4619+
if (is_cfg_printer) {
4620+
// Special version for compatibility with C1 Visualizer.
4621+
LIR_Opr opr = LinearScan::get_operand(reg_num());
4622+
if (opr->is_valid()) {
4623+
out->print("\"");
4624+
opr->print(out);
4625+
out->print("\" ");
4626+
}
46174627
} else {
4618-
// Virtual register that has no assigned register yet.
4619-
out->print("[ANY]");
4628+
// Improved output for normal debugging.
4629+
if (reg_num() < LIR_OprDesc::vreg_base) {
4630+
LinearScan::print_reg_num(out, assigned_reg());
4631+
} else if (assigned_reg() != -1 && (LinearScan::num_physical_regs(type()) == 1 || assigned_regHi() != -1)) {
4632+
LinearScan::calc_operand_for_interval(this)->print(out);
4633+
} else {
4634+
// Virtual register that has no assigned register yet.
4635+
out->print("[ANY]");
4636+
}
4637+
out->print(" ");
46204638
}
4621-
4622-
out->print(" %d %d ", split_parent()->reg_num(), (register_hint(false) != NULL ? register_hint(false)->reg_num() : -1));
4639+
out->print("%d %d ", split_parent()->reg_num(), (register_hint(false) != NULL ? register_hint(false)->reg_num() : -1));
46234640

46244641
// print ranges
46254642
Range* cur = _first;

src/hotspot/share/c1/c1_LinearScan.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ class LinearScan : public CompilationResourceObj {
369369
void print_lir(int level, const char* label, bool hir_valid = true);
370370
static void print_reg_num(int reg_num) { print_reg_num(tty, reg_num); }
371371
static void print_reg_num(outputStream* out, int reg_num);
372+
static LIR_Opr get_operand(int reg_num);
372373
#endif
373374

374375
#ifdef ASSERT
@@ -633,7 +634,11 @@ class Interval : public CompilationResourceObj {
633634
// printing
634635
#ifndef PRODUCT
635636
void print() const { print_on(tty); }
636-
void print_on(outputStream* out) const;
637+
void print_on(outputStream* out) const {
638+
print_on(out, false);
639+
}
640+
// Special version for compatibility with C1 Visualizer.
641+
void print_on(outputStream* out, bool is_cfg_printer) const;
637642

638643
// Used for debugging
639644
void print_parent() const;

0 commit comments

Comments
 (0)