RFR: 8349835: C2: simplify IGV property printing

Johan Sjölen jsjolen at openjdk.org
Mon Sep 22 14:37:56 UTC 2025


On Fri, 22 Aug 2025 13:28:22 GMT, Saranya Natarajan <snatarajan at openjdk.org> wrote:

> The code that prints node properties and live range properties is very verbose and repetitive and could be simplified by applying a refactoring suggested [here](https://github.com/openjdk/jdk/pull/23558#discussion_r1950785708).
> 
> ### Fix 
> Implemented the suggested refactoring. 
> 
> ### Testing 
> Github Actions, Tier 1-3

Hi,

I'd change the data structure to have a tagged union with separate constructors to make the struct understandable.

src/hotspot/share/opto/idealGraphPrinter.cpp line 534:

> 532:         {((flags & Node::Flag_has_call) != 0), "has_call", "true"},
> 533:         {((flags & Node::Flag_has_swapped_edges) != 0), "has_swapped_edges", "true"}
> 534:       };

This code desperately needs a utility to check the corresponding bits in `flags` :-).

src/hotspot/share/opto/idealGraphPrinter.hpp line 123:

> 121:     const char *_svalue = nullptr;
> 122:     int _ivalue = -1;
> 123:   };

Get rid of optionals and explicit condition checking by introducing a tagged union.

```c++
struct IdealGraphPrintRecord {
  enum class State {
    False, String, Integer
  };
  State _state;
  const char* _name;
  union {
    const char* _svalue;
    int _ivalue;
  };
  IdealGraphPrintRecord(bool cond, const char* name, int value)
  : _state( cond ? State::Integer : State::False ), _name(name), _ivalue(value) {}
  IdealGraphPrintRecord(bool cond, const char* name, const char* value)
  : _state( cond ? State::String : State::False ), _name(name), _svalue(value) {}

  bool has_string() { return _state == State::String; }
  bool has_int() { return _state == State::Integer; }
  const char* string_value() { return _svalue; }
  const char* key() { ... }
  int int_value() { ... }
};

-------------

PR Review: https://git.openjdk.org/jdk/pull/26902#pullrequestreview-3253147647
PR Review Comment: https://git.openjdk.org/jdk/pull/26902#discussion_r2368702964
PR Review Comment: https://git.openjdk.org/jdk/pull/26902#discussion_r2368689760


More information about the hotspot-compiler-dev mailing list