We should refactor the usage of streamIndentor and StreamAutoIndentor and combine them into a single StreamIndentor class to make it easier to apply indentation. JDK-8354362 introduced a partial solution for this, by being able to add indentation with a StreamAutoIndentor.
To use indentation, you currently need to do two separate things: 1) increment indentation and 2) apply indentation when printing. The indentation level can be incremented by using one of: streamIndentor, inc() or inc(int n), and automatic indentation can be enabled by using one of: StreamAutoIndentor, indent(), cr_indent().
streamIndentor and StreamAutoIndentor should be combined into a new class, maybe called StreamIndentor. StreamIndentor should have the functionality of both streamIndentor and StreamAutoIndentor, that is, enabling automatic indentation and also applying an optional amount of indentation. This means you only need to do one thing to make sure that indentation is incremented and applied, making it easier to use indentation.
There are currently four (4) ways that indentation is applied in HotSpot:
1) The new method of enabling automatic indentation and applying indentation simultaneously (partially implemented already).
Only in GC printing code via CollectedHeap.
2) Initially use a StreamAutoIndentor, then use streamIndentor to temporarily increment indentation. Indentation is automatically applied when printing.
nmt/memReporter uses this principle, by having a StreamAutoIndentor as a member variable and applying indentation via streamIndentor when needed.
3) Use a streamIndentor and manually call indent() (or cr_indent()).
Commonly used pattern. No need to manually apply indentation if automatically applied.
4) Increment/decrement indentation (using inc() and/or dec()) and manually call indent().
Only C1's CFGPrinterOutput does this.
In the third case, there is a possibility that there are cases where applying indentation automatically is undesirable. This should be investigated further to see that any changes do not break printing.
To use indentation, you currently need to do two separate things: 1) increment indentation and 2) apply indentation when printing. The indentation level can be incremented by using one of: streamIndentor, inc() or inc(int n), and automatic indentation can be enabled by using one of: StreamAutoIndentor, indent(), cr_indent().
streamIndentor and StreamAutoIndentor should be combined into a new class, maybe called StreamIndentor. StreamIndentor should have the functionality of both streamIndentor and StreamAutoIndentor, that is, enabling automatic indentation and also applying an optional amount of indentation. This means you only need to do one thing to make sure that indentation is incremented and applied, making it easier to use indentation.
There are currently four (4) ways that indentation is applied in HotSpot:
1) The new method of enabling automatic indentation and applying indentation simultaneously (partially implemented already).
Only in GC printing code via CollectedHeap.
2) Initially use a StreamAutoIndentor, then use streamIndentor to temporarily increment indentation. Indentation is automatically applied when printing.
nmt/memReporter uses this principle, by having a StreamAutoIndentor as a member variable and applying indentation via streamIndentor when needed.
3) Use a streamIndentor and manually call indent() (or cr_indent()).
Commonly used pattern. No need to manually apply indentation if automatically applied.
4) Increment/decrement indentation (using inc() and/or dec()) and manually call indent().
Only C1's CFGPrinterOutput does this.
In the third case, there is a possibility that there are cases where applying indentation automatically is undesirable. This should be investigated further to see that any changes do not break printing.
- links to
-
Review(master) openjdk/jdk/24917