diff --git a/.github/workflows/jreleaser.yml b/.github/workflows/jreleaser.yml index d1796166..d3990572 100644 --- a/.github/workflows/jreleaser.yml +++ b/.github/workflows/jreleaser.yml @@ -25,7 +25,7 @@ jobs: - name: Setup Java JDK uses: actions/setup-java@1bcf9fb12cf4aa7d266a90ae39939e61372fe520 # v5.4.0 with: - java-version: '11' + java-version: '25' distribution: 'microsoft' server-id: ossrh server-username: MAVEN_USERNAME diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index c1693cd9..9dd6ff73 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -25,7 +25,7 @@ jobs: - name: Setup Java JDK uses: actions/setup-java@1bcf9fb12cf4aa7d266a90ae39939e61372fe520 # v5.4.0 with: - java-version: '11' + java-version: '25' distribution: 'microsoft' server-id: ossrh server-username: MAVEN_USERNAME diff --git a/.github/workflows/release_to_github.yml b/.github/workflows/release_to_github.yml index f51557fc..46ba9623 100644 --- a/.github/workflows/release_to_github.yml +++ b/.github/workflows/release_to_github.yml @@ -27,7 +27,7 @@ jobs: - name: Setup Java JDK uses: actions/setup-java@1bcf9fb12cf4aa7d266a90ae39939e61372fe520 # v5.4.0 with: - java-version: '11' + java-version: '25' distribution: 'microsoft' - name: Version diff --git a/IT/pom.xml b/IT/pom.xml index 7c9112b2..eb8b3c72 100644 --- a/IT/pom.xml +++ b/IT/pom.xml @@ -31,6 +31,10 @@ com.microsoft.gctoolkit gctoolkit-vertx + + org.jspecify + jspecify + org.junit.jupiter junit-jupiter-api diff --git a/IT/src/main/java/com/microsoft/gctoolkit/integration/aggregation/CollectionCycleCountsSummary.java b/IT/src/main/java/com/microsoft/gctoolkit/integration/aggregation/CollectionCycleCountsSummary.java index fcf1b8d1..3640ee06 100644 --- a/IT/src/main/java/com/microsoft/gctoolkit/integration/aggregation/CollectionCycleCountsSummary.java +++ b/IT/src/main/java/com/microsoft/gctoolkit/integration/aggregation/CollectionCycleCountsSummary.java @@ -4,13 +4,14 @@ import java.io.PrintStream; import java.util.HashMap; +import java.util.Map; public class CollectionCycleCountsSummary extends CollectionCycleCountsAggregation { - private HashMap collectionCycleCounts = new HashMap<>(); + private Map collectionCycleCounts = new HashMap<>(); @Override public void count(GarbageCollectionTypes gcType) { - collectionCycleCounts.compute(gcType, (key, value) -> value == null ? 1 : ++value); + collectionCycleCounts.compute(gcType, (_, value) -> value == null ? 1 : ++value); } private String format = "%s : %s\n"; diff --git a/IT/src/main/java/com/microsoft/gctoolkit/integration/aggregation/HeapOccupancyAfterCollectionSummary.java b/IT/src/main/java/com/microsoft/gctoolkit/integration/aggregation/HeapOccupancyAfterCollectionSummary.java index 2a6ae73f..973acd73 100644 --- a/IT/src/main/java/com/microsoft/gctoolkit/integration/aggregation/HeapOccupancyAfterCollectionSummary.java +++ b/IT/src/main/java/com/microsoft/gctoolkit/integration/aggregation/HeapOccupancyAfterCollectionSummary.java @@ -13,8 +13,9 @@ public class HeapOccupancyAfterCollectionSummary extends HeapOccupancyAfterColle private final Map aggregations = new ConcurrentHashMap<>(); + @Override public void addDataPoint(GarbageCollectionTypes gcType, DateTimeStamp timeStamp, long heapOccupancy) { - aggregations.computeIfAbsent(gcType, key -> new XYDataSet()).add(timeStamp.getTimeStamp(),heapOccupancy); + aggregations.computeIfAbsent(gcType, _ -> new XYDataSet()).add(timeStamp.getTimeStamp(),heapOccupancy); } public Map get() { diff --git a/IT/src/main/java/com/microsoft/gctoolkit/integration/aggregation/PauseTimeAggregation.java b/IT/src/main/java/com/microsoft/gctoolkit/integration/aggregation/PauseTimeAggregation.java index a6bc8480..6ff5dae6 100644 --- a/IT/src/main/java/com/microsoft/gctoolkit/integration/aggregation/PauseTimeAggregation.java +++ b/IT/src/main/java/com/microsoft/gctoolkit/integration/aggregation/PauseTimeAggregation.java @@ -3,16 +3,12 @@ import com.microsoft.gctoolkit.aggregator.Aggregation; import com.microsoft.gctoolkit.aggregator.Collates; -/** - * API for an Aggregation that records pause time duration. A - * PauseTimeAggregation gets its data from a PauseTimeAggregator. - */ +/// API for an Aggregation that records pause time duration. A +/// PauseTimeAggregation gets its data from a PauseTimeAggregator. @Collates(PauseTimeAggregator.class) public abstract class PauseTimeAggregation extends Aggregation { - /** - * Record the duration of a pause event. This method is called from PauseTimeAggregator. - * @param duration The duration (in decimal seconds) of a GC pause. - */ + /// Record the duration of a pause event. This method is called from PauseTimeAggregator. + /// @param duration The duration (in decimal seconds) of a GC pause. public abstract void recordPauseDuration(double duration); } diff --git a/IT/src/main/java/com/microsoft/gctoolkit/integration/aggregation/PauseTimeAggregator.java b/IT/src/main/java/com/microsoft/gctoolkit/integration/aggregation/PauseTimeAggregator.java index 18e236fe..0728a999 100644 --- a/IT/src/main/java/com/microsoft/gctoolkit/integration/aggregation/PauseTimeAggregator.java +++ b/IT/src/main/java/com/microsoft/gctoolkit/integration/aggregation/PauseTimeAggregator.java @@ -6,9 +6,7 @@ import com.microsoft.gctoolkit.event.g1gc.G1RealPause; import com.microsoft.gctoolkit.event.generational.GenerationalGCPauseEvent; -/** - * An Aggregator that extracts pause time. - */ +/// An Aggregator that extracts pause time. @Aggregates({EventSource.G1GC, EventSource.GENERATIONAL}) public class PauseTimeAggregator extends Aggregator { diff --git a/IT/src/main/java/com/microsoft/gctoolkit/integration/aggregation/PauseTimeSummary.java b/IT/src/main/java/com/microsoft/gctoolkit/integration/aggregation/PauseTimeSummary.java index 2431d440..96fc7a56 100644 --- a/IT/src/main/java/com/microsoft/gctoolkit/integration/aggregation/PauseTimeSummary.java +++ b/IT/src/main/java/com/microsoft/gctoolkit/integration/aggregation/PauseTimeSummary.java @@ -1,11 +1,9 @@ package com.microsoft.gctoolkit.integration.aggregation; -/** - * An implementation of PauseTimeAggregation which simply accumulates pause times, and - * provides methods for getting the total pause time and the percentage of time the - * application was paused. This is an instance of RuntimeAggregation, which gives us - * the run time represented by the GC log. - */ +/// An implementation of PauseTimeAggregation which simply accumulates pause times, and +/// provides methods for getting the total pause time and the percentage of time the +/// application was paused. This is an instance of RuntimeAggregation, which gives us +/// the run time represented by the GC log. public class PauseTimeSummary extends PauseTimeAggregation { private double totalPauseTime; @@ -25,18 +23,14 @@ public void recordPauseDuration(double duration) { totalPauseTime += duration; } - /** - * Get the total amount of time the application was paused for garbage collection. - * @return The total pause time. - */ + /// Get the total amount of time the application was paused for garbage collection. + /// @return The total pause time. public double getTotalPauseTime() { return totalPauseTime; } - /** - * Get the amount of time the application was paused as a percentage of total runtime. - * @return The percentage of time the application was paused. - */ + /// Get the amount of time the application was paused as a percentage of total runtime. + /// @return The percentage of time the application was paused. public double getPercentPaused() { return (totalPauseTime / super.estimatedRuntime()) * 100.0D; } diff --git a/IT/src/main/java/com/microsoft/gctoolkit/integration/collections/XYDataSet.java b/IT/src/main/java/com/microsoft/gctoolkit/integration/collections/XYDataSet.java index ffd01479..4e6c8082 100644 --- a/IT/src/main/java/com/microsoft/gctoolkit/integration/collections/XYDataSet.java +++ b/IT/src/main/java/com/microsoft/gctoolkit/integration/collections/XYDataSet.java @@ -32,25 +32,21 @@ public boolean isEmpty() { return dataSeries.isEmpty(); } - /** - * Returns an immutable List of the items in this DataSet. - */ + /// Returns an immutable List of the items in this DataSet. public List getItems() { return List.copyOf(dataSeries); } public com.microsoft.gctoolkit.integration.collections.XYDataSet scaleSeries(double scaleFactor) { - com.microsoft.gctoolkit.integration.collections.XYDataSet scaled = new com.microsoft.gctoolkit.integration.collections.XYDataSet(); + var scaled = new com.microsoft.gctoolkit.integration.collections.XYDataSet(); for (com.microsoft.gctoolkit.integration.collections.XYDataSet.Point item : dataSeries) { scaled.add(item.getX(), item.getY().doubleValue() * scaleFactor); } return scaled; } - /** - * Returns the largest Y value in the XYDataSet as an OptionalDouble, - * with an empty optional if the dataset is empty. - */ + /// Returns the largest Y value in the XYDataSet as an OptionalDouble, + /// with an empty optional if the dataset is empty. public OptionalDouble maxOfY() { return dataSeries.stream() .map(com.microsoft.gctoolkit.integration.collections.XYDataSet.Point::getY) @@ -59,9 +55,9 @@ public OptionalDouble maxOfY() { } public com.microsoft.gctoolkit.integration.collections.XYDataSet scaleAndTranslateXAxis(double scale, double offset) { - com.microsoft.gctoolkit.integration.collections.XYDataSet translatedSeries = new com.microsoft.gctoolkit.integration.collections.XYDataSet(); + var translatedSeries = new com.microsoft.gctoolkit.integration.collections.XYDataSet(); for (com.microsoft.gctoolkit.integration.collections.XYDataSet.Point dataPoint : dataSeries) { - double scaledXCoordinate = (scale * dataPoint.getX().doubleValue()) + offset; + var scaledXCoordinate = (scale * dataPoint.getX().doubleValue()) + offset; translatedSeries.add(scaledXCoordinate, dataPoint.getY()); } return translatedSeries; diff --git a/IT/src/main/java/com/microsoft/gctoolkit/integration/shared/OneRuntimeAggregator.java b/IT/src/main/java/com/microsoft/gctoolkit/integration/shared/OneRuntimeAggregator.java index 194f9a16..386cbbb8 100644 --- a/IT/src/main/java/com/microsoft/gctoolkit/integration/shared/OneRuntimeAggregator.java +++ b/IT/src/main/java/com/microsoft/gctoolkit/integration/shared/OneRuntimeAggregator.java @@ -6,11 +6,9 @@ @Aggregates({EventSource.G1GC,EventSource.GENERATIONAL,EventSource.SHENANDOAH,EventSource.ZGC}) public class OneRuntimeAggregator extends Aggregator { - /** - * Subclass only. - * - * @param aggregation The Aggregation that {@literal @}Collates this Aggregator - */ + /// Subclass only. + /// + /// @param aggregation The Aggregation that `@`Collates this Aggregator public OneRuntimeAggregator(OneRuntimeReport aggregation) { super(aggregation); } diff --git a/IT/src/main/java/com/microsoft/gctoolkit/integration/shared/TwoRuntimeAggregator.java b/IT/src/main/java/com/microsoft/gctoolkit/integration/shared/TwoRuntimeAggregator.java index afd109d8..a80cefbe 100644 --- a/IT/src/main/java/com/microsoft/gctoolkit/integration/shared/TwoRuntimeAggregator.java +++ b/IT/src/main/java/com/microsoft/gctoolkit/integration/shared/TwoRuntimeAggregator.java @@ -6,11 +6,9 @@ @Aggregates({EventSource.G1GC,EventSource.GENERATIONAL,EventSource.SHENANDOAH,EventSource.ZGC}) public class TwoRuntimeAggregator extends Aggregator { - /** - * Subclass only. - * - * @param aggregation The Aggregation that {@literal @}Collates this Aggregator - */ + /// Subclass only. + /// + /// @param aggregation The Aggregation that `@`Collates this Aggregator public TwoRuntimeAggregator(TwoRuntimeReport aggregation) { super(aggregation); } diff --git a/IT/src/main/java/module-info.java b/IT/src/main/java/module-info.java index 20cd6df0..5c2d32e6 100644 --- a/IT/src/main/java/module-info.java +++ b/IT/src/main/java/module-info.java @@ -8,6 +8,7 @@ requires com.microsoft.gctoolkit.api; requires java.logging; + requires transitive org.jspecify; exports com.microsoft.gctoolkit.integration.aggregation to com.microsoft.gctoolkit.api; diff --git a/IT/src/test/java/com/microsoft/gctoolkit/integration/CMSEventsTest.java b/IT/src/test/java/com/microsoft/gctoolkit/integration/CMSEventsTest.java index ba5af07a..6b49252c 100644 --- a/IT/src/test/java/com/microsoft/gctoolkit/integration/CMSEventsTest.java +++ b/IT/src/test/java/com/microsoft/gctoolkit/integration/CMSEventsTest.java @@ -30,7 +30,7 @@ public void analyze(String gcLogFile) { * The log files can be either in text, zip, or gzip format. */ GCLogFile logFile = new SingleGCLogFile(Path.of(gcLogFile)); - GCToolKit gcToolKit = new GCToolKit(); + var gcToolKit = new GCToolKit(); /** * This call will load all implementations of Aggregator that have been declared in module-info.java. diff --git a/IT/src/test/java/com/microsoft/gctoolkit/integration/CaptureJVMTerminationEventTest.java b/IT/src/test/java/com/microsoft/gctoolkit/integration/CaptureJVMTerminationEventTest.java index 6955bb1a..ffed33c0 100644 --- a/IT/src/test/java/com/microsoft/gctoolkit/integration/CaptureJVMTerminationEventTest.java +++ b/IT/src/test/java/com/microsoft/gctoolkit/integration/CaptureJVMTerminationEventTest.java @@ -38,7 +38,7 @@ public void analyze(String gcLogFile) { * The log files can be either in text, zip, or gzip format. */ GCLogFile logFile = new SingleGCLogFile(Path.of(gcLogFile)); - GCToolKit gcToolKit = new GCToolKit(); + var gcToolKit = new GCToolKit(); /** * This call will load all implementations of Aggregator that have been declared in module-info.java. diff --git a/IT/src/test/java/com/microsoft/gctoolkit/integration/EndToEndIntegrationTest.java b/IT/src/test/java/com/microsoft/gctoolkit/integration/EndToEndIntegrationTest.java index 3cf81c25..4db13f23 100644 --- a/IT/src/test/java/com/microsoft/gctoolkit/integration/EndToEndIntegrationTest.java +++ b/IT/src/test/java/com/microsoft/gctoolkit/integration/EndToEndIntegrationTest.java @@ -37,7 +37,7 @@ public void analyze(String gcLogFile) { * The log files can be either in text, zip, or gzip format. */ GCLogFile logFile = new SingleGCLogFile(Path.of(gcLogFile)); - GCToolKit gcToolKit = new GCToolKit(); + var gcToolKit = new GCToolKit(); /** * This call will load all implementations of Aggregator that have been declared in module-info.java. @@ -57,10 +57,10 @@ public void analyze(String gcLogFile) { } // Retrieves the Aggregation for HeapOccupancyAfterCollectionSummary. This is a time-series aggregation. - String message = "The XYDataSet for %s contains %s items.\n"; + var message = "The XYDataSet for %s contains %s items.\n"; machine.getAggregation(HeapOccupancyAfterCollectionSummary.class) .map(HeapOccupancyAfterCollectionSummary::get) - .ifPresent(summary -> { + .ifPresent(summary -> summary.forEach((gcType, dataSet) -> { switch (gcType) { case DefNew: @@ -76,13 +76,12 @@ public void analyze(String gcLogFile) { Assertions.assertEquals(26,remarkCount,"Remark count"); break; default: - System.out.println(gcType + " not managed"); + IO.println(gcType + " not managed"); break; } - }); - }); + })); - Optional summary = machine.getAggregation(CollectionCycleCountsSummary.class); + var summary = machine.getAggregation(CollectionCycleCountsSummary.class); // Retrieves the Aggregation for PauseTimeSummary. This is a com.microsoft.gctoolkit.sample.aggregation.RuntimeAggregation. machine.getAggregation(PauseTimeSummary.class).ifPresent(pauseTimeSummary -> { Assertions.assertEquals( 208.922, pauseTimeSummary.getTotalPauseTime(), 0.001d, "Total Pause Time"); diff --git a/IT/src/test/java/com/microsoft/gctoolkit/integration/MissingAnnotationTest.java b/IT/src/test/java/com/microsoft/gctoolkit/integration/MissingAnnotationTest.java index 19a6d2ec..acb9e34f 100644 --- a/IT/src/test/java/com/microsoft/gctoolkit/integration/MissingAnnotationTest.java +++ b/IT/src/test/java/com/microsoft/gctoolkit/integration/MissingAnnotationTest.java @@ -22,7 +22,7 @@ public class MissingAnnotationTest { @SuppressWarnings("unchecked") private void workFlow(Aggregation aggregation, Class clazz) { - GCToolKit gcToolKit = new GCToolKit(); + var gcToolKit = new GCToolKit(); // Load our test aggregation instead of calling GCToolKit::loadAggregationsFromServiceLoader gcToolKit.loadAggregation(aggregation); JavaVirtualMachine machine = null; @@ -46,7 +46,7 @@ void testSuppliedAggregation() { workFlow(new MissingEventSource(), MissingAnnotationTest.MissingEventSource.class); } - /************* Aggregator/Aggregation with missing Collates annotation */ + /// *********** Aggregator/Aggregation with missing Collates annotation public static class MissingAnnotationAggregation extends Aggregation { @Override @@ -68,7 +68,7 @@ protected TestAggregator(MissingAnnotationAggregation aggregation) { } } - /************* Aggregator/Aggregation with missing Aggregates annotation */ + /// *********** Aggregator/Aggregation with missing Aggregates annotation @Collates(MissingAnnotationAggregator.class) public static class MissingEventSource extends Aggregation { @Override diff --git a/IT/src/test/java/com/microsoft/gctoolkit/integration/NoModuleIntegrationTest.java b/IT/src/test/java/com/microsoft/gctoolkit/integration/NoModuleIntegrationTest.java index 2a55520b..2c601f6d 100644 --- a/IT/src/test/java/com/microsoft/gctoolkit/integration/NoModuleIntegrationTest.java +++ b/IT/src/test/java/com/microsoft/gctoolkit/integration/NoModuleIntegrationTest.java @@ -41,7 +41,7 @@ public void analyze(String gcLogFile) { * The log files can be either in text, zip, or gzip format. */ GCLogFile logFile = new SingleGCLogFile(Path.of(gcLogFile)); - GCToolKit gcToolKit = new GCToolKit(); + var gcToolKit = new GCToolKit(); gcToolKit.loadDataSourceChannel(new VertxDataSourceChannel()); gcToolKit.loadJVMEventChannel(new VertxJVMEventChannel()); @@ -63,10 +63,10 @@ public void analyze(String gcLogFile) { } // Retrieves the Aggregation for HeapOccupancyAfterCollectionSummary. This is a time-series aggregation. - String message = "The XYDataSet for %s contains %s items.\n"; + var message = "The XYDataSet for %s contains %s items.\n"; machine.getAggregation(HeapOccupancyAfterCollectionSummary.class) .map(HeapOccupancyAfterCollectionSummary::get) - .ifPresent(summary -> { + .ifPresent(summary -> summary.forEach((gcType, dataSet) -> { System.out.printf(message, gcType, dataSet.size()); switch (gcType) { @@ -83,13 +83,12 @@ public void analyze(String gcLogFile) { Assertions.assertEquals(26,remarkCount,"Remark count"); break; default: - System.out.println(gcType + " not managed"); + IO.println(gcType + " not managed"); break; } - }); - }); + })); - Optional summary = machine.getAggregation(CollectionCycleCountsSummary.class); + var summary = machine.getAggregation(CollectionCycleCountsSummary.class); // Retrieves the Aggregation for PauseTimeSummary. This is a com.microsoft.gctoolkit.sample.aggregation.RuntimeAggregation. machine.getAggregation(PauseTimeSummary.class).ifPresent(pauseTimeSummary -> { Assertions.assertEquals( 208.922, pauseTimeSummary.getTotalPauseTime(), 0.001d, "Total Pause Time"); diff --git a/IT/src/test/java/com/microsoft/gctoolkit/integration/TestSharedAggregators.java b/IT/src/test/java/com/microsoft/gctoolkit/integration/TestSharedAggregators.java index 8506505c..34273d2f 100644 --- a/IT/src/test/java/com/microsoft/gctoolkit/integration/TestSharedAggregators.java +++ b/IT/src/test/java/com/microsoft/gctoolkit/integration/TestSharedAggregators.java @@ -21,10 +21,10 @@ public class TestSharedAggregators { @Test public void compareRuntimeDurations() { - TestLogFile logFile = new TestLogFile(testLog); + var logFile = new TestLogFile(testLog); Path gcLogFile = logFile.getFile().toPath(); GCLogFile log = new SingleGCLogFile(gcLogFile); - GCToolKit toolKit = new GCToolKit(); + var toolKit = new GCToolKit(); toolKit.loadAggregationsFromServiceLoader(); JavaVirtualMachine jvm = null; try { diff --git a/IT/src/test/java/com/microsoft/gctoolkit/integration/XYDataSetTest.java b/IT/src/test/java/com/microsoft/gctoolkit/integration/XYDataSetTest.java index eee075fc..fa507e1e 100644 --- a/IT/src/test/java/com/microsoft/gctoolkit/integration/XYDataSetTest.java +++ b/IT/src/test/java/com/microsoft/gctoolkit/integration/XYDataSetTest.java @@ -16,8 +16,8 @@ public void shouldScaleOnlyY_AxisDataSet() { var xyDataSet = new XYDataSet(); xyDataSet.add(new Point(50, 100)); XYDataSet scaledPoint = xyDataSet.scaleSeries(2); - Assertions.assertEquals(50, scaledPoint.getItems().get(0).getX()); - Assertions.assertEquals(200.0, scaledPoint.getItems().get(0).getY()); + Assertions.assertEquals(50, scaledPoint.getItems().getFirst().getX()); + Assertions.assertEquals(200.0, scaledPoint.getItems().getFirst().getY()); } @Test @@ -36,8 +36,8 @@ public void shouldReturnScaledAndTranslatedX_AxisDataSet() { var xyDataSet = new XYDataSet(); xyDataSet.add(new Point(50, 100)); var translated = xyDataSet.scaleAndTranslateXAxis(2, 20); - Assertions.assertEquals(120.0, translated.getItems().get(0).getX()); - Assertions.assertEquals(100, translated.getItems().get(0).getY()); + Assertions.assertEquals(120.0, translated.getItems().getFirst().getX()); + Assertions.assertEquals(100, translated.getItems().getFirst().getY()); } @Test diff --git a/IT/src/test/java/com/microsoft/gctoolkit/integration/ZeroAggregationTest.java b/IT/src/test/java/com/microsoft/gctoolkit/integration/ZeroAggregationTest.java index 2c2dc8f8..3b2e2779 100644 --- a/IT/src/test/java/com/microsoft/gctoolkit/integration/ZeroAggregationTest.java +++ b/IT/src/test/java/com/microsoft/gctoolkit/integration/ZeroAggregationTest.java @@ -33,7 +33,7 @@ public void testNoAggregationRegistered() { * The log files can be either in text, zip, or gzip format. */ GCLogFile logFile = new SingleGCLogFile(path); - GCToolKit gcToolKit = new GCToolKit(); + var gcToolKit = new GCToolKit(); // Do not call GCToolKit::loadAggregationsFromServiceLoader JavaVirtualMachine machine = null; try { @@ -52,7 +52,7 @@ public void testNoAggregationRegistered() { public void testSuppliedAggregation() { Path path = new TestLogFile("cms/defnew/details/defnew.log").getFile().toPath(); GCLogFile logFile = new SingleGCLogFile(path); - GCToolKit gcToolKit = new GCToolKit(); + var gcToolKit = new GCToolKit(); // Load our local Aggregation that will not be registered for the given log file gcToolKit.loadAggregation(new ZeroAggregationTest.TestAggregation()); JavaVirtualMachine machine = null; @@ -84,13 +84,11 @@ public boolean isEmpty() { @Aggregates(EventSource.G1GC) public static class TestAggregator extends Aggregator { - /** - * Subclass only. - * - * @param aggregation The Aggregation that {@literal @}Collates this Aggregator - * @see Collates - * @see Aggregation - */ + /// Subclass only. + /// + /// @param aggregation The Aggregation that `@`Collates this Aggregator + /// @see Collates + /// @see Aggregation protected TestAggregator(TestAggregation aggregation) { super(aggregation); } diff --git a/IT/src/test/java/com/microsoft/gctoolkit/integration/core/PreunifiedJavaVirtualMachineConfigurationTest.java b/IT/src/test/java/com/microsoft/gctoolkit/integration/core/PreunifiedJavaVirtualMachineConfigurationTest.java index 5397b846..d7ed8fbd 100644 --- a/IT/src/test/java/com/microsoft/gctoolkit/integration/core/PreunifiedJavaVirtualMachineConfigurationTest.java +++ b/IT/src/test/java/com/microsoft/gctoolkit/integration/core/PreunifiedJavaVirtualMachineConfigurationTest.java @@ -26,14 +26,14 @@ public class PreunifiedJavaVirtualMachineConfigurationTest { @Tag("modulePath") @Test public void testSingle() { - TestLogFile log = new TestLogFile(logFile); + var log = new TestLogFile(logFile); smokeTest(new SingleGCLogFile(log.getFile().toPath()), times); } private void smokeTest(GCLogFile log, int[] endStartTimes ) { - GCToolKit gcToolKit = new GCToolKit(); + var gcToolKit = new GCToolKit(); gcToolKit.loadAggregationsFromServiceLoader(); - TestTimeAggregation aggregation = new TestTimeAggregation(); + var aggregation = new TestTimeAggregation(); gcToolKit.loadAggregation(aggregation); JavaVirtualMachine machine = null; try { @@ -61,13 +61,11 @@ private void smokeTest(GCLogFile log, int[] endStartTimes ) { @Aggregates({EventSource.G1GC,EventSource.GENERATIONAL,EventSource.ZGC,EventSource.SHENANDOAH}) public static class TestTimeAggregator extends Aggregator { - /** - * Subclass only. - * - * @param aggregation The Aggregation that {@literal @}Collates this Aggregator - * @see Collates - * @see Aggregation - */ + /// Subclass only. + /// + /// @param aggregation The Aggregation that `@`Collates this Aggregator + /// @see Collates + /// @see Aggregation public TestTimeAggregator(TestTimeAggregation aggregation) { super(aggregation); } diff --git a/IT/src/test/java/com/microsoft/gctoolkit/integration/core/UnifiedJavaVirtualMachineConfigurationTest.java b/IT/src/test/java/com/microsoft/gctoolkit/integration/core/UnifiedJavaVirtualMachineConfigurationTest.java index d02d54f7..b2656cc9 100644 --- a/IT/src/test/java/com/microsoft/gctoolkit/integration/core/UnifiedJavaVirtualMachineConfigurationTest.java +++ b/IT/src/test/java/com/microsoft/gctoolkit/integration/core/UnifiedJavaVirtualMachineConfigurationTest.java @@ -22,19 +22,19 @@ public class UnifiedJavaVirtualMachineConfigurationTest { @Tag("modulePath") @Test public void testRotating() { - TestLogFile log = new TestLogFile(logFile); + var log = new TestLogFile(logFile); test(new RotatingGCLogFile(log.getFile().toPath()), times[0]); } @Tag("modulePath") @Test public void testSingle() { - TestLogFile log = new TestLogFile(logFile); + var log = new TestLogFile(logFile); test(new SingleGCLogFile(log.getFile().toPath()), times[1]); } private void test(GCLogFile log, int[] endStartTimes ) { - GCToolKit gcToolKit = new GCToolKit(); + var gcToolKit = new GCToolKit(); gcToolKit.loadAggregationsFromServiceLoader(); JavaVirtualMachine machine = null; try { diff --git a/IT/src/test/java/com/microsoft/gctoolkit/integration/io/RotatingGarbageCollectionLogFileTest.java b/IT/src/test/java/com/microsoft/gctoolkit/integration/io/RotatingGarbageCollectionLogFileTest.java index a09583c8..a734f267 100644 --- a/IT/src/test/java/com/microsoft/gctoolkit/integration/io/RotatingGarbageCollectionLogFileTest.java +++ b/IT/src/test/java/com/microsoft/gctoolkit/integration/io/RotatingGarbageCollectionLogFileTest.java @@ -51,11 +51,11 @@ public class RotatingGarbageCollectionLogFileTest { public void getOrderedGarbageCollectionLogFiles() { for(String[] data : expected) { try { - TestLogFile logFile = new TestLogFile(data[0]); - RotatingGCLogFile garbageCollectionLogFile = new RotatingGCLogFile(logFile.getFile().toPath()); + var logFile = new TestLogFile(data[0]); + var garbageCollectionLogFile = new RotatingGCLogFile(logFile.getFile().toPath()); List segments = garbageCollectionLogFile.getOrderedGarbageCollectionLogFiles(); assertEquals(data.length - 1, segments.size()); - for (int n = 1; n < data.length; n++) { + for (var n = 1; n < data.length; n++) { assertEquals(data[n], segments.get(n - 1).getPath().getFileName().toString()); } } catch (Throwable e) { @@ -66,15 +66,15 @@ public void getOrderedGarbageCollectionLogFiles() { private void runRollingLogOrderingTest(Path path, List expectedOrdering, long lineCount) { try { - RotatingGCLogFile rotatingGCLogFile = new RotatingGCLogFile(path); - List actual = + var rotatingGCLogFile = new RotatingGCLogFile(path); + var actual = rotatingGCLogFile .getOrderedGarbageCollectionLogFiles() .stream() - .map(segment -> segment.getSegmentName()) + .map(LogFileSegment::getSegmentName) .collect(Collectors.toList()); assertEquals(expectedOrdering, actual); - long count = rotatingGCLogFile.stream().count(); + var count = rotatingGCLogFile.stream().count(); assertEquals(246733,count,"Unequal line counts"); } catch (Exception badTestData) { fail(badTestData); @@ -84,7 +84,7 @@ private void runRollingLogOrderingTest(Path path, List expectedOrdering, @Test public void testRollingLogOrderUsage() { Path path = new TestLogFile("rolling/jdk14/rollinglogs/rollover.log").getFile().toPath(); - List expected = Arrays.asList( + var expected = Arrays.asList( "rollover.log.3", "rollover.log.4", "rollover.log.0", "rollover.log.1", "rollover.log.2", "rollover.log" ); runRollingLogOrderingTest(path, expected, 246732); @@ -93,7 +93,7 @@ public void testRollingLogOrderUsage() { @Test public void testRollingInZip() { Path path = new TestLogFile("rolling/jdk14/rollinglogs/zip/rollover.zip").getFile().toPath(); - List expected = Arrays.asList( + var expected = Arrays.asList( "rollover.log.3", "rollover.log.4", "rollover.log.0", "rollover.log.1", "rollover.log.2", "rollover.log" ); runRollingLogOrderingTest(path,expected, 246733); @@ -102,7 +102,7 @@ public void testRollingInZip() { @Test public void testRollingInDirInZip() { Path path = new TestLogFile("rolling/jdk14/rollinglogs/zip/rolloverdir.zip").getFile().toPath(); - List expected = Arrays.asList( + var expected = Arrays.asList( "rollover/rollover.log.3", "rollover/rollover.log.4", "rollover/rollover.log.0", "rollover/rollover.log.1", "rollover/rollover.log.2", "rollover/rollover.log" ); runRollingLogOrderingTest(path,expected, 246733); diff --git a/IT/src/test/java/com/microsoft/gctoolkit/integration/io/SingleGarbageCollectionLogFileTest.java b/IT/src/test/java/com/microsoft/gctoolkit/integration/io/SingleGarbageCollectionLogFileTest.java index f9c16834..bdbf2745 100644 --- a/IT/src/test/java/com/microsoft/gctoolkit/integration/io/SingleGarbageCollectionLogFileTest.java +++ b/IT/src/test/java/com/microsoft/gctoolkit/integration/io/SingleGarbageCollectionLogFileTest.java @@ -21,13 +21,13 @@ public class SingleGarbageCollectionLogFileTest { @Test public void unifiedLog() { - for (int index = 0; index < unifiedLogs.length; index++) + for (var index = 0; index < unifiedLogs.length; index++) logStreamingTest(unifiedLogs[index], logIsUnified[index], logIsZipped[index], logIsGZipped[index]); } private void logStreamingTest(String log, boolean unified, boolean zipped, boolean gzipped) { Path path = new TestLogFile(log).getFile().toPath(); - SingleGCLogFile gcLogFile = new SingleGCLogFile(path); + var gcLogFile = new SingleGCLogFile(path); assertEquals(unified, gcLogFile.isUnified(), "Expected unified but failed"); try { assertEquals(1, gcLogFile.getMetaData().getNumberOfFiles(), "Expected 1 but found " + gcLogFile.getMetaData().getNumberOfFiles()); diff --git a/IT/src/test/java/com/microsoft/gctoolkit/integration/query/MissingTimeStampTest.java b/IT/src/test/java/com/microsoft/gctoolkit/integration/query/MissingTimeStampTest.java index 2161b691..96a0adf5 100644 --- a/IT/src/test/java/com/microsoft/gctoolkit/integration/query/MissingTimeStampTest.java +++ b/IT/src/test/java/com/microsoft/gctoolkit/integration/query/MissingTimeStampTest.java @@ -30,7 +30,7 @@ public void analyze(String gcLogFile) { * The log files can be either in text, zip, or gzip format. */ GCLogFile logFile = new SingleGCLogFile(Path.of(gcLogFile)); - GCToolKit gcToolKit = new GCToolKit(); + var gcToolKit = new GCToolKit(); /* * This call will load all implementations of Aggregator that have been declared in module-info.java. @@ -57,7 +57,7 @@ public void analyze(String gcLogFile) { fail("getPercentPaused failed", t); } - double pauseTimePercentage = 0.0d; + var pauseTimePercentage = 0.0d; try { pauseTimePercentage = machine.getAggregation(PauseTimeSummary.class).get().getPercentPaused(); diff --git a/api/pom.xml b/api/pom.xml index 2836ee42..30cac4f1 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -15,6 +15,10 @@ ${project.parent.url} + + org.jspecify + jspecify + org.junit.jupiter junit-jupiter-api @@ -24,6 +28,6 @@ org.junit.jupiter junit-jupiter-engine test - + diff --git a/api/src/main/java/com/microsoft/gctoolkit/GCToolKit.java b/api/src/main/java/com/microsoft/gctoolkit/GCToolKit.java index 6c258dcb..9357c5cf 100644 --- a/api/src/main/java/com/microsoft/gctoolkit/GCToolKit.java +++ b/api/src/main/java/com/microsoft/gctoolkit/GCToolKit.java @@ -14,6 +14,7 @@ import com.microsoft.gctoolkit.message.DataSourceChannel; import com.microsoft.gctoolkit.message.DataSourceParser; import com.microsoft.gctoolkit.message.JVMEventChannel; +import org.jspecify.annotations.Nullable; import java.io.IOException; import java.lang.reflect.Constructor; @@ -34,9 +35,7 @@ import static java.lang.Class.forName; -/** - * The primary API for analyzing Java Garbage Collection (GC) logs. - */ +/// The primary API for analyzing Java Garbage Collection (GC) logs. public class GCToolKit { private static final Logger LOGGER = Logger.getLogger(GCToolKit.class.getName()); @@ -52,59 +51,53 @@ private static boolean isDebugging(String className) { && !GCTOOLKIT_DEBUG.contains("-" + className))); } - /** - * Print a debug message to System.out if gctoolkit.debug is empty, is set to "all", - * or contains "className" but does not contain "-className". - * For example, to enable debug logging for all classes except UnifiedG1GCParser: - * -Dgctoolkit.debug=all,-com.microsoft.gctoolkit.parser.UnifiedG1GCParser - * - * @param message Supplies the message to log. If null, nothing will be logged. - */ - public static void LOG_DEBUG_MESSAGE(Supplier message) { + /// Print a debug message to System.out if gctoolkit.debug is empty, is set to "all", + /// or contains "className" but does not contain "-className". + /// For example, to enable debug logging for all classes except UnifiedG1GCParser: + /// `-Dgctoolkit.debug=all,-com.microsoft.gctoolkit.parser.UnifiedG1GCParser` + /// + /// @param message Supplies the message to log. If null, nothing will be logged. + public static void LOG_DEBUG_MESSAGE(@Nullable Supplier message) { if (DEBUGGING && message != null) { StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace(); String methodName = stackTrace[2].getMethodName(); String className = stackTrace[2].getClassName(); String fileName = stackTrace[2].getFileName(); - int lineNumber = stackTrace[2].getLineNumber(); + var lineNumber = stackTrace[2].getLineNumber(); if (isDebugging(className)) { - System.out.println(String.format("DEBUG: %s.%s(%s:%d): %s", className, methodName, fileName, lineNumber, message.get())); + IO.println("DEBUG: %s.%s(%s:%d): %s".formatted(className, methodName, fileName, lineNumber, message.get())); } } } - private final HashSet registeredDataSourceParsers = new HashSet<>(); + private final Set registeredDataSourceParsers = new HashSet<>(); private List registeredAggregations; private JVMEventChannel jvmEventChannel = null; private DataSourceChannel dataSourceChannel = null; - /** - * Instantiate a GCToolKit object. The same GCToolKit object can be used to analyze - * more than one GC log. It is not necessary to create a GCToolKit object for - * each GC log to be analyzed. Please note, however, that GCToolKit API is not - * thread safe. - */ + /// Instantiate a GCToolKit object. The same GCToolKit object can be used to analyze + /// more than one GC log. It is not necessary to create a GCToolKit object for + /// each GC log to be analyzed. Please note, however, that GCToolKit API is not + /// thread safe. public GCToolKit() { // Allow for adding aggregations from source code, // but don't corrupt the ones loaded by the service loader this.registeredAggregations = new ArrayList<>(); } - /** - * Loads all Aggregations defined in the application module through - * the java.util.ServiceLoader model. To register a class that - * provides the {@link Aggregation} API, define the following - * in {@code module-info.java}: - *
-     * import com.microsoft.gctoolkit.aggregator.Aggregation;
-     * import com.microsoft.gctoolkit.sample.aggregation.HeapOccupancyAfterCollectionSummary;
-     * 
-     * module com.microsoft.gctoolkit.sample {
-     *     ...
-     *     provides Aggregation with HeapOccupancyAfterCollectionSummary;
-     * }
-     * 
- */ + /// Loads all Aggregations defined in the application module through + /// the java.util.ServiceLoader model. To register a class that + /// provides the [Aggregation] API, define the following + /// in `module-info.java`: + /// ``` + /// import com.microsoft.gctoolkit.aggregator.Aggregation; + /// import com.microsoft.gctoolkit.sample.aggregation.HeapOccupancyAfterCollectionSummary; + /// + /// module com.microsoft.gctoolkit.sample { + /// ... + /// provides Aggregation with HeapOccupancyAfterCollectionSummary; + /// } + /// ``` public void loadAggregationsFromServiceLoader() { try { ServiceLoader.load(Aggregation.class) @@ -120,29 +113,25 @@ public void loadAggregationsFromServiceLoader() { } } - /** - * Registers an {@code Aggregation} class which can be used to perform analysis - * on {@code JVMEvent}s. GCToolKit will instantiate the Aggregation when needed. - *

- * The {@link JavaVirtualMachine#getAggregation(Class)} - * API will return an Aggregation that was used in the log analysis. Even though - * an Aggregation was registered, the {@code getAggregation} method will return - * null if the Aggregation was not used in the analysis. - * - * @param aggregation the Aggregation class to register. - * @see Aggregation - * @see JavaVirtualMachine - */ + /// Registers an `Aggregation` class which can be used to perform analysis + /// on `JVMEvent`s. GCToolKit will instantiate the Aggregation when needed. + /// + /// The [JavaVirtualMachine#getAggregation(Class)] + /// API will return an Aggregation that was used in the log analysis. Even though + /// an Aggregation was registered, the `getAggregation` method will return + /// null if the Aggregation was not used in the analysis. + /// + /// @param aggregation the Aggregation class to register. + /// @see Aggregation + /// @see JavaVirtualMachine public void loadAggregation(Aggregation aggregation) { registeredAggregations.add(aggregation); } - /** - * Load the first implementation of JavaVirtualMachine that can process - * the supplied DataSource, GCLog in this instance. - * @param logFile GCLogFile DataSource - * @return JavaVirtualMachine implementation. - */ + /// Load the first implementation of JavaVirtualMachine that can process + /// the supplied DataSource, GCLog in this instance. + /// @param logFile GCLogFile DataSource + /// @return JavaVirtualMachine implementation. private JavaVirtualMachine loadJavaVirtualMachine(GCLogFile logFile) { return logFile.getJavaVirtualMachine(); } @@ -154,7 +143,7 @@ public void loadDataSourceChannel(DataSourceChannel channel) { private void loadDataSourceChannel() { if ( dataSourceChannel == null) { - ServiceLoader serviceLoader = ServiceLoader.load(DataSourceChannel.class); + var serviceLoader = ServiceLoader.load(DataSourceChannel.class); if (serviceLoader.findFirst().isPresent()) { loadDataSourceChannel(serviceLoader .stream() @@ -165,7 +154,7 @@ private void loadDataSourceChannel() { try { Class clazz = forName("com.microsoft.gctoolkit.vertx.VertxDataSourceChannel", true, Thread.currentThread().getContextClassLoader()); loadDataSourceChannel((DataSourceChannel) clazz.getConstructors()[0].newInstance()); - } catch (Exception e) { + } catch (Exception _) { throw new ServiceConfigurationError("Unable to find a suitable DataSourceChannel provider"); } } @@ -179,7 +168,7 @@ public void loadJVMEventChannel(JVMEventChannel channel) { private void loadJVMEventChannel() { if ( jvmEventChannel == null) { - ServiceLoader serviceLoader = ServiceLoader.load(JVMEventChannel.class); + var serviceLoader = ServiceLoader.load(JVMEventChannel.class); if (serviceLoader.findFirst().isPresent()) { loadJVMEventChannel(ServiceLoader.load(JVMEventChannel.class) .stream() @@ -190,34 +179,30 @@ private void loadJVMEventChannel() { try { Class clazz = forName("com.microsoft.gctoolkit.vertx.VertxJVMEventChannel", true, Thread.currentThread().getContextClassLoader()); loadJVMEventChannel((JVMEventChannel) clazz.getConstructors()[0].newInstance()); - } catch (Exception e) { + } catch (Exception _) { throw new ServiceConfigurationError("Unable to find a suitable provider to create a JVMEventChannel"); } } } } - /** - * This method allows full control over which DataSourceParsers are used to parse the DataSource. - * This method should be called before the {@link #analyze(DataSource)} method. - * DataSourceParsers loaded by this method are used in place of those that are ordinarily loaded via - * the service provider interface. - * Use the {@link #addDataSourceParser(DataSourceParser)} method to load a DataSourceParser in addition - * to those loaded by the service provider interface. - * @param dataSourceParser An implementation of DataSourceParser that will be used to parse the DataSource. - */ + /// This method allows full control over which DataSourceParsers are used to parse the DataSource. + /// This method should be called before the [#analyze(DataSource)] method. + /// DataSourceParsers loaded by this method are used in place of those that are ordinarily loaded via + /// the service provider interface. + /// Use the [#addDataSourceParser(DataSourceParser)] method to load a DataSourceParser in addition + /// to those loaded by the service provider interface. + /// @param dataSourceParser An implementation of DataSourceParser that will be used to parse the DataSource. public void loadDataSourceParser(DataSourceParser dataSourceParser) { registeredDataSourceParsers.add(dataSourceParser); } private List additiveParsers = new ArrayList<>(); - /** - * Add a DataSourceParser to be used to parse a DataSource. The DataSourceParser will be used in addition - * to those loaded by the service provider interface. This method should be called before the - * {@link #analyze(DataSource)} method. - * @param dataSourceParser An implementation of DataSourceParser that will be used to parse the DataSource. - */ + /// Add a DataSourceParser to be used to parse a DataSource. The DataSourceParser will be used in addition + /// to those loaded by the service provider interface. This method should be called before the + /// [#analyze(DataSource)] method. + /// @param dataSourceParser An implementation of DataSourceParser that will be used to parse the DataSource. public void addDataSourceParser(DataSourceParser dataSourceParser) { additiveParsers.add(dataSourceParser); } @@ -256,12 +241,12 @@ private Set loadDataSourceParsers(Diary diary) { dataSourceParsers = Arrays.stream(parsers) .map(parserName -> { try { - Class clazz = forName(parserName, true, Thread.currentThread().getContextClassLoader()); + var clazz = forName(parserName, true, Thread.currentThread().getContextClassLoader()); return Optional.of(clazz.getConstructors()[0].newInstance()); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException - | InvocationTargetException e) { + | InvocationTargetException _) { return Optional.empty(); } }) @@ -291,25 +276,23 @@ private Set loadDataSourceParsers(Diary diary) { .collect(HashSet::new, Set::addAll, Set::addAll); } - /** - * Perform an analysis on a GC log file. The analysis will use the Aggregations - * that were {@link #loadAggregation(Aggregation) registered}, if appropriate for - * the GC log file. - * - * @param dataSource The log to analyze, typically a - * {@link SingleGCLogFile} or - * {@link RotatingGCLogFile}. - * @return a representation of the state of the Java Virtual Machine resulting - * from the analysis of the GC log file. - * @throws IOException when something goes wrong reading the data source - */ + /// Perform an analysis on a GC log file. The analysis will use the Aggregations + /// that were [registered][#loadAggregation(Aggregation)], if appropriate for + /// the GC log file. + /// + /// @param dataSource The log to analyze, typically a + /// [SingleGCLogFile] or + /// [RotatingGCLogFile]. + /// @return a representation of the state of the Java Virtual Machine resulting + /// from the analysis of the GC log file. + /// @throws IOException when something goes wrong reading the data source public JavaVirtualMachine analyze(DataSource dataSource) throws IOException { - GCLogFile logFile = (GCLogFile)dataSource; - Set events = loadDataSourceParsers(logFile.diary()); + var logFile = (GCLogFile)dataSource; + var events = loadDataSourceParsers(logFile.diary()); JavaVirtualMachine javaVirtualMachine = loadJavaVirtualMachine(logFile); try { - List> filteredAggregators = filterAggregations(events); - long start = System.currentTimeMillis(); + var filteredAggregators = filterAggregations(events); + var start = System.currentTimeMillis(); javaVirtualMachine.analyze(filteredAggregators, jvmEventChannel, dataSourceChannel); LOGGER.log(Level.FINE,() -> "Analysis completed in " + (System.currentTimeMillis() - start) + "ms"); } catch(Throwable t) { @@ -322,7 +305,7 @@ private List> filterAggregations(Set> aggregators = new ArrayList<>(); for (Aggregation aggregation : registeredAggregations) { LOG_DEBUG_MESSAGE(() -> "Evaluating: " + aggregation.getClass().getName()); - Constructor> constructor = constructor(aggregation); + var constructor = constructor(aggregation); if (constructor == null) { LOGGER.log(Level.WARNING, "Cannot find one of: default constructor or @Collates annotation for " + aggregation.getClass().getName()); continue; diff --git a/api/src/main/java/com/microsoft/gctoolkit/aggregator/Aggregates.java b/api/src/main/java/com/microsoft/gctoolkit/aggregator/Aggregates.java index c57d708c..42eff5ba 100644 --- a/api/src/main/java/com/microsoft/gctoolkit/aggregator/Aggregates.java +++ b/api/src/main/java/com/microsoft/gctoolkit/aggregator/Aggregates.java @@ -7,11 +7,9 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -/** - * This annotation is used by implementations of {@link Aggregator} to indicate - * the source of the events being aggregated. An {@code Aggregator} must include - * this annotation in order to receive JVM events from the parser. - */ +/// This annotation is used by implementations of [Aggregator] to indicate +/// the source of the events being aggregated. An `Aggregator` must include +/// this annotation in order to receive JVM events from the parser. @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) /** @@ -19,9 +17,7 @@ * the source of the events being aggregated. */ public @interface Aggregates { - /** - * Indicate the source of events being aggregated by an Aggregator. - * @return An array of EventSource - */ + /// Indicate the source of events being aggregated by an Aggregator. + /// @return An array of EventSource EventSource[] value(); } diff --git a/api/src/main/java/com/microsoft/gctoolkit/aggregator/Aggregation.java b/api/src/main/java/com/microsoft/gctoolkit/aggregator/Aggregation.java index b053af96..7a486083 100644 --- a/api/src/main/java/com/microsoft/gctoolkit/aggregator/Aggregation.java +++ b/api/src/main/java/com/microsoft/gctoolkit/aggregator/Aggregation.java @@ -3,91 +3,89 @@ package com.microsoft.gctoolkit.aggregator; import com.microsoft.gctoolkit.event.jvm.JVMEvent; -import com.microsoft.gctoolkit.jvm.JavaVirtualMachine; import com.microsoft.gctoolkit.online.statistics.WelfordVarianceCalculator; import com.microsoft.gctoolkit.time.DateTimeStamp; -/** - * An {@code Aggregation} collates data from an {@link Aggregator} and may be thought of as a view - * of the data. An {@code Aggregation} might collate data into a time series for plotting, or it might - * summarize the data. Separating the capture of the data, which is the job of the {@code Aggregator} - * from how the data is aggregated, which is the job of the {@code Aggregation}, allows for multiple - * views of the data to be built for the same {@code Aggregator}. - *

- * The {@link Collates} annotation is used to indicate which {@code Aggregator} an {@code Aggregation} - * works with. If an {@code Aggregation} does not have the {@code Collates} annotation, the {@code Aggregation} - * will not be used. - *

- * An implementation of Aggregation must have a public, no-arg constructor. - *

- * Best practice for creating an {@code Aggregation} is to create an interface for the methods the - * {@code Aggregator} will call. When a GC log is analyzed, {@code JVMEvents} are captured by the - * {@code Aggregators}. An {@code Aggregator} extracts data from the JVMEvent and calls the - * {@code Aggregation} API to collate the data. - *

- * As an example, say one wants to record the pause times of full GCs. An {@code Aggregation} - * could present an API that takes the date/time of the event, the cause of the full GC, and - * the duration of the full GC. The {@code Aggregator} could capture G1FullGC events and - * FullGC events. Which event is actually sent to the {@code Aggregator} depends on the - * what kind of GC log file is being parsed. - *

- * The example FullGCAggregator is annotated with the {@code @Aggregates} annotation, giving - * the G1GC and Generational as the event source. This lets GCToolKit know that this Aggregator - * is capturing events from those sources. Notice also that the constructor of FullGCAggregator - * registers the JVMEvent types that it is interested in, and gives the method to call for that - * event type. Lastly, the process method extracts the data from the event and calls the - * FullGCAggregation API. - *

- * The implementation of FullGCAggregation can collate the data however desired. MaxFullGCPauseTime is - * just one example. Notice that the method to get the maximum pause time is defined in MaxFullGCPauseTime, - * not in FullGCAggregation. This keeps the FullGCAggregation interface from imposing API that some - * other view (some other Aggregation) of the data might not want or need. - * - *


- * {@literal @}Collates(FullGCAggregator.class)
- * public interface FullGCAggregation extends Aggregation {
- *      void recordFullGC(DateTimeStamp timeStamp, GCCause cause, double pauseTime);
- * }
- *
- * {@literal @}Aggregates({EventSource.G1GC, EventSource.Generational})
- * public class FullGCAggregator implements Aggregator{@literal <}FullGCAggregation{@literal >} {
- *
- *     public FullGCAggregator(FullGCAggregation aggregation) {
- *         super(aggregation);
- *         register(G1FullGC.class, this::process);
- *         register(FullGC.class, this::process);
- *     }
- *
- *      private void process(GCEvent event) {
- *          aggregation().recordFullGC(event.getDateTimeStamp(), event.getGCCause(), event.getDuration());
- *      }
- * }
- *
- * public class MaxFullGCPauseTime implements FullGCAggregation {
- *     Map{@literal <}GCCause, Double{@literal >} maxPauseTime = new HashMap();
- *
- *     public MaxFullGCPauseTime() {}
- *
- *     {@literal @}Override
- *     public void recordFullGC(DateTimeStamp timeStamp, GCCause cause, double pauseTime) {
- *         maxPauseTime.compute(cause, (k, v) -{@literal >} (v == null) ? pauseTime : Math.max(v, pauseTime));
- *     }
- *
- *     public double getMaxPauseTime(GCCause cause) {
- *         return maxPauseTime.get(cause);
- *     }
- *
- *     {@literal @}Override
- *     public boolean hasWarning() { return false; }
- *
- *     {@literal @}Override
- *     public boolean isEmpty() { return maxPauseTime.isEmpty(); }
- * }
- * 
- * - * @see JavaVirtualMachine#getAggregation(Class) - * @see Collates - */ +/// An `Aggregation` collates data from an [Aggregator] and may be thought of as a view +/// of the data. An `Aggregation` might collate data into a time series for plotting, or it might +/// summarize the data. Separating the capture of the data, which is the job of the `Aggregator` +/// from how the data is aggregated, which is the job of the `Aggregation`, allows for multiple +/// views of the data to be built for the same `Aggregator`. +/// +/// The [Collates] annotation is used to indicate which `Aggregator` an `Aggregation` +/// works with. If an `Aggregation` does not have the `Collates` annotation, the `Aggregation` +/// will not be used. +/// +/// An implementation of Aggregation must have a public, no-arg constructor. +/// +/// Best practice for creating an `Aggregation` is to create an interface for the methods the +/// `Aggregator` will call. When a GC log is analyzed, `JVMEvents` are captured by the +/// `Aggregators`. An `Aggregator` extracts data from the JVMEvent and calls the +/// `Aggregation` API to collate the data. +/// +/// As an example, say one wants to record the pause times of full GCs. An `Aggregation` +/// could present an API that takes the date/time of the event, the cause of the full GC, and +/// the duration of the full GC. The `Aggregator` could capture G1FullGC events and +/// FullGC events. Which event is actually sent to the `Aggregator` depends on the +/// what kind of GC log file is being parsed. +/// +/// The example FullGCAggregator is annotated with the `@Aggregates` annotation, giving +/// the G1GC and Generational as the event source. This lets GCToolKit know that this Aggregator +/// is capturing events from those sources. Notice also that the constructor of FullGCAggregator +/// registers the JVMEvent types that it is interested in, and gives the method to call for that +/// event type. Lastly, the process method extracts the data from the event and calls the +/// FullGCAggregation API. +/// +/// The implementation of FullGCAggregation can collate the data however desired. MaxFullGCPauseTime is +/// just one example. Notice that the method to get the maximum pause time is defined in MaxFullGCPauseTime, +/// not in FullGCAggregation. This keeps the FullGCAggregation interface from imposing API that some +/// other view (some other Aggregation) of the data might not want or need. +/// +/// ``` +/// +/// `@`Collates(FullGCAggregator.class) +/// public interface FullGCAggregation extends Aggregation { +/// void recordFullGC(DateTimeStamp timeStamp, GCCause cause, double pauseTime); +/// } +/// +/// `@`Aggregates({EventSource.G1GC, EventSource.Generational}) +/// public class FullGCAggregator implements Aggregator`<`FullGCAggregation`>` { +/// +/// public FullGCAggregator(FullGCAggregation aggregation) { +/// super(aggregation); +/// register(G1FullGC.class, this::process); +/// register(FullGC.class, this::process); +/// } +/// +/// private void process(GCEvent event) { +/// aggregation().recordFullGC(event.getDateTimeStamp(), event.getGCCause(), event.getDuration()); +/// } +/// } +/// +/// public class MaxFullGCPauseTime implements FullGCAggregation { +/// Map`<`GCCause, Double`>` maxPauseTime = new HashMap(); +/// +/// public MaxFullGCPauseTime() {} +/// +/// `@`Override +/// public void recordFullGC(DateTimeStamp timeStamp, GCCause cause, double pauseTime) { +/// maxPauseTime.compute(cause, (k, v) -`>` (v == null) ? pauseTime : Math.max(v, pauseTime)); +/// } +/// +/// public double getMaxPauseTime(GCCause cause) { +/// return maxPauseTime.get(cause); +/// } +/// +/// `@`Override +/// public boolean hasWarning() { return false; } +/// +/// `@`Override +/// public boolean isEmpty() { return maxPauseTime.isEmpty(); } +/// } +/// ``` +/// +/// @see JavaVirtualMachine#getAggregation(Class) +/// @see Collates public abstract class Aggregation { private DateTimeStamp timeOfFirstEvent = null; @@ -95,53 +93,41 @@ public abstract class Aggregation { private final WelfordVarianceCalculator varianceCalculator = new WelfordVarianceCalculator(); private DateTimeStamp timeOfLastSeenEvent = null; - /** - * Constructor for the module SPI - */ + /// Constructor for the module SPI protected Aggregation() {} - /** - * @param eventTime of first event seen - */ + /// @param eventTime of first event seen public void timeOfFirstEvent(DateTimeStamp eventTime) { this.timeOfFirstEvent = eventTime; } - /** - * @return time of first event seen - */ + /// @return time of first event seen public DateTimeStamp timeOfFirstEvent() { return this.timeOfFirstEvent; } - /** - * Interface to record the time span of the log - * Estimate based on information carried in the JVMTermination event. - * @param eventTime - estimate start time of the log. - */ + /// Interface to record the time span of the log + /// Estimate based on information carried in the JVMTermination event. + /// @param eventTime - estimate start time of the log. public void timeOfTerminationEvent(DateTimeStamp eventTime) { this.timeOfTermination = eventTime; } - /** - * @return the timestamp reported by the JVM termination record if present otherwise the end of the last event. - */ + /// @return the timestamp reported by the JVM termination record if present otherwise the end of the last event. public DateTimeStamp timeOfTerminationEvent() { return this.timeOfTermination; } - /** - * Estimates the start time of the log based on the available data. - *

- * If the first event does not have a timestamp, the method returns the time of the first event minus the variance of GC frequency. - *

- * If the timestamp is present and the timestamp of the first event is greater than the variance, the method returns the timestamp minus the variance. - * However, if the resulting timestamp is negative, the method returns the time of the first event instead, since a negative timestamp is not possible. - * - * @return The estimated start time of the log based on the available data - */ + /// Estimates the start time of the log based on the available data. + /// + /// If the first event does not have a timestamp, the method returns the time of the first event minus the variance of GC frequency. + /// + /// If the timestamp is present and the timestamp of the first event is greater than the variance, the method returns the timestamp minus the variance. + /// However, if the resulting timestamp is negative, the method returns the time of the first event instead, since a negative timestamp is not possible. + /// + /// @return The estimated start time of the log based on the available data public DateTimeStamp estimatedStartTime() { - double sd = Math.sqrt(varianceCalculator.getValue()); + var sd = Math.sqrt(varianceCalculator.getValue()); if (!timeOfFirstEvent.hasTimeStamp()) { return timeOfFirstEvent.minus(sd); } @@ -154,30 +140,22 @@ public DateTimeStamp estimatedStartTime() { } } - /** - * @return estimate time span represented by the data presented. - */ + /// @return estimate time span represented by the data presented. public double estimatedRuntime() { return timeOfTermination.minus(estimatedStartTime()); } - /** - * Return true if the Aggregation contains a warning. For example, an Aggregation that - * looks at GC Cause might return {@code true} if it finds a System.gc() call. - * @return {@code true} if the Aggregation contains a warning. - */ + /// Return true if the Aggregation contains a warning. For example, an Aggregation that + /// looks at GC Cause might return `true` if it finds a System.gc() call. + /// @return `true` if the Aggregation contains a warning. abstract public boolean hasWarning(); - /** - * Return {@code true} if there is no data in the Aggregation. - * @return {@code true} if there is no data in the Aggregation. - */ + /// Return `true` if there is no data in the Aggregation. + /// @return `true` if there is no data in the Aggregation. abstract public boolean isEmpty(); - /** - * Sort if a given Aggregator collates for this aggregation. - * @return aggregator - */ + /// Sort if a given Aggregator collates for this aggregation. + /// @return aggregator public Class> collates() { return collates(getClass()); } @@ -188,15 +166,13 @@ public void updateEventFrequency(JVMEvent event) { timeOfLastSeenEvent = dateTimeStamp; return; } - double timeSpan = dateTimeStamp.minus(timeOfLastSeenEvent); + var timeSpan = dateTimeStamp.minus(timeOfLastSeenEvent); varianceCalculator.update(timeSpan); } - /** - * Calculates the aggregator for this aggregation. - * @param clazz this Aggregation - * @return the Aggregator - */ + /// Calculates the aggregator for this aggregation. + /// @param clazz this Aggregation + /// @return the Aggregator private Class> collates(Class clazz) { Class> target; if (clazz != null && clazz != Aggregation.class) { diff --git a/api/src/main/java/com/microsoft/gctoolkit/aggregator/Aggregator.java b/api/src/main/java/com/microsoft/gctoolkit/aggregator/Aggregator.java index 5a7bc7fe..120f14d4 100644 --- a/api/src/main/java/com/microsoft/gctoolkit/aggregator/Aggregator.java +++ b/api/src/main/java/com/microsoft/gctoolkit/aggregator/Aggregator.java @@ -10,55 +10,53 @@ import java.util.concurrent.Executors; import java.util.function.Consumer; -/** - * An Aggregator consumes a JVMEvent, extracts data from the event, and calls on an - * Aggregation which collates the data. - * An Aggregators uses the {@literal @}Aggregates annotation to declare the - * EventSource(s) of the JVMEvents it handles. - * The constructor of an Aggregator must call {@link #register(Class, Consumer)} - * to register the consumer methods of JVMEvents the Aggregator consumes. - *

- * This example Aggregator aggregates events from the G1GC event source. It consumes - * and processes four different events. The {@code Consumer} method for each event extracts - * the cause of the collection and calls the GCCauseAggregation {@code record} method. - * - *


- *
- * {@literal @}Collates(GCCauseAggregator)
- * public interface GCCauseAggregation extends Aggregation {
- *     publish(GarbageCollectionType type, GCCause cause);
- * }
- *
- * {@literal @}Aggregates(EventSource.G1GC)
- * public class GCCauseAggregator extends Aggregator{@literal <}GCCauseAggregation{@literal >} {
- *
- *     public GCCauseAggregator(GCCauseAggregation aggregation) {
- *         super(aggregation);
- *         register(G1Young.class, this::process);
- *         register(G1Mixed.class, this::process);
- *         register(G1YoungInitialMark.class, this::process);
- *         register(G1FullGC.class, this::process);
- *     }
- *
- *     private void process(G1Young collection) {
- *         aggregation().publish(GarbageCollectionTypes.Young, collection.getGCCause());
- *     }
- *
- *     private void process(G1Mixed collection) {
- *         aggregation().publish(GarbageCollectionTypes.Mixed, collection.getGCCause());
- *     }
- *
- *     private void process(G1YoungInitialMark collection) {
- *         aggregation().publish(GarbageCollectionTypes.G1GCYoungInitialMark, collection.getGCCause());
- *     }
- *
- *     private void process(G1FullGC collection) {
- *         aggregation().publish(GarbageCollectionTypes.FullGC, collection.getGCCause());
- *     }
- * }
- * 
- * @param The type of Aggregation - */ +/// An Aggregator consumes a JVMEvent, extracts data from the event, and calls on an +/// Aggregation which collates the data. +/// An Aggregators uses the ``@`Aggregates` annotation to declare the +/// EventSource(s) of the JVMEvents it handles. +/// The constructor of an Aggregator must call [#register(Class, Consumer)] +/// to register the consumer methods of JVMEvents the Aggregator consumes. +/// +/// This example Aggregator aggregates events from the G1GC event source. It consumes +/// and processes four different events. The `Consumer` method for each event extracts +/// the cause of the collection and calls the GCCauseAggregation `record` method. +/// +/// ``` +/// +/// `@`Collates(GCCauseAggregator) +/// public interface GCCauseAggregation extends Aggregation { +/// publish(GarbageCollectionType type, GCCause cause); +/// } +/// +/// `@`Aggregates(EventSource.G1GC) +/// public class GCCauseAggregator extends Aggregator`<`GCCauseAggregation`>` { +/// +/// public GCCauseAggregator(GCCauseAggregation aggregation) { +/// super(aggregation); +/// register(G1Young.class, this::process); +/// register(G1Mixed.class, this::process); +/// register(G1YoungInitialMark.class, this::process); +/// register(G1FullGC.class, this::process); +/// } +/// +/// private void process(G1Young collection) { +/// aggregation().publish(GarbageCollectionTypes.Young, collection.getGCCause()); +/// } +/// +/// private void process(G1Mixed collection) { +/// aggregation().publish(GarbageCollectionTypes.Mixed, collection.getGCCause()); +/// } +/// +/// private void process(G1YoungInitialMark collection) { +/// aggregation().publish(GarbageCollectionTypes.G1GCYoungInitialMark, collection.getGCCause()); +/// } +/// +/// private void process(G1FullGC collection) { +/// aggregation().publish(GarbageCollectionTypes.FullGC, collection.getGCCause()); +/// } +/// } +/// ``` +/// @param A The type of Aggregation public abstract class Aggregator { private final A aggregation; @@ -67,53 +65,51 @@ public abstract class Aggregator { /// JVMEventDispatcher manages all the registered events and event consumers private final JVMEventDispatcher jvmEventDispatcher = new JVMEventDispatcher(); - /** - * Subclass only. - * @param aggregation The Aggregation that {@literal @}Collates this Aggregator - * @see Collates - * @see Aggregation - */ + /// Subclass only. + /// @param aggregation The Aggregation that `@`Collates this Aggregator + /// @see Collates + /// @see Aggregation protected Aggregator(A aggregation) { this.aggregation = aggregation; } - /** - * This method returns the {@link Aggregation} that collates the data - * which is collected by this {@code Aggregator}. - * @return The Aggregator's corresponding Aggregation - */ + /// This method returns the [Aggregation] that collates the data + /// which is collected by this `Aggregator`. + /// @return The Aggregator's corresponding Aggregation public A aggregation() { return aggregation; } - /** - * Register a JVMEvent class and the method in the Aggregator sub-class that handles it. - * If the JVMEvent class is a super-class of other event types, then the Consumer is called - * for all sub-classes of that JVMEvent class, unless a Consumer for a more specific event class - * is registered. - *

- * The typical pattern is to call this method from the constructor of the Aggregator sub-class. - *

{@code
-     *     register(G1Young.class, this::process);
-     * }
- * The {@code Consumer} for this example would be coded as: - *
{@code
-     *     private void process(G1Young collection) {...}
-     * }
- * Where the body of the method would pull the relevant data from the event - * and pass the data on to the Aggregation. - * @param eventClass the Class of the JVMEvent type to register. - * @param process the handler which processes the event - * @param the type of JVMEvent - */ + /// Register a JVMEvent class and the method in the Aggregator sub-class that handles it. + /// If the JVMEvent class is a super-class of other event types, then the Consumer is called + /// for all sub-classes of that JVMEvent class, unless a Consumer for a more specific event class + /// is registered. + /// + /// The typical pattern is to call this method from the constructor of the Aggregator sub-class. + /// `````` + /// + /// register(G1Young.class, this::process); + /// + /// ``` + /// ``` + /// The `Consumer` for this example would be coded as: + /// `````` + /// + /// private void process(G1Young collection) {...} + /// + /// ``` + /// ``` + /// Where the body of the method would pull the relevant data from the event + /// and pass the data on to the Aggregation. + /// @param eventClass the Class of the JVMEvent type to register. + /// @param process the handler which processes the event + /// @param E the type of JVMEvent protected void register(Class eventClass, Consumer process) { jvmEventDispatcher.register(eventClass, process); } - /** - * Call back to be run when the JVMTermination event has been - * @param task to be executed - */ + /// Call back to be run when the JVMTermination event has been + /// @param task to be executed public void onCompletion(Runnable task) { this.completionTask = task; } @@ -127,26 +123,22 @@ public void onCompletion(Runnable task) { } ); - /** - * Call a callback when aggregation is completed. - */ + /// Call a callback when aggregation is completed. private void complete() { if (completionTask != null) { executorService.execute(completionTask); } } - /** - * This method consumes a JVMEvent and dispatches it to the - * {@link #register(Class, Consumer) registered consumer}. - * @param event an event to be processed - */ + /// This method consumes a JVMEvent and dispatches it to the + /// [registered consumer][#register(Class, Consumer)]. + /// @param event an event to be processed public void receive(JVMEvent event) { aggregation().updateEventFrequency(event); - if (event instanceof JVMTermination) { - aggregation().timeOfTerminationEvent(((JVMTermination) event).getTimeOfTerminationEvent()); - aggregation().timeOfFirstEvent(((JVMTermination)event).getTimeOfFirstEvent()); + if (event instanceof JVMTermination termination) { + aggregation().timeOfTerminationEvent(termination.getTimeOfTerminationEvent()); + aggregation().timeOfFirstEvent(termination.getTimeOfFirstEvent()); } jvmEventDispatcher.dispatch(event); if (event instanceof JVMTermination) { @@ -154,21 +146,17 @@ public void receive(JVMEvent event) { } } - /** - * Calculates if this Aggregator aggregates the given event source - * @param eventSource to be checked. - * @return true is the aggregator aggregates the event source - */ + /// Calculates if this Aggregator aggregates the given event source + /// @param eventSource to be checked. + /// @return true is the aggregator aggregates the event source public boolean aggregates(EventSource eventSource) { return (eventSource != null) && aggregates(getClass(), eventSource); } - /** - * Calculates if this Aggregator aggregates the given event source. - * @param clazz the aggregator - * @param targetEventSource the event source to check - * @return true is the aggregator aggregates the event source - */ + /// Calculates if this Aggregator aggregates the given event source. + /// @param clazz the aggregator + /// @param targetEventSource the event source to check + /// @return true is the aggregator aggregates the event source private boolean aggregates(Class clazz, EventSource targetEventSource) { if (clazz != null && clazz != Aggregator.class) { diff --git a/api/src/main/java/com/microsoft/gctoolkit/aggregator/Collates.java b/api/src/main/java/com/microsoft/gctoolkit/aggregator/Collates.java index 89be8cd2..46f55c8c 100644 --- a/api/src/main/java/com/microsoft/gctoolkit/aggregator/Collates.java +++ b/api/src/main/java/com/microsoft/gctoolkit/aggregator/Collates.java @@ -7,44 +7,40 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -/** - * An implementation of an Aggregation collates data from an Aggregator. - * This annotation is used on an Aggregation to tell GCToolKit which - * Aggregator produces the data the Aggregation collates. - *

- * In this example, there is a PauseTimeAggegator which receives pause time events - * from GCToolKit. The PauseTimeAggregator extracts the cause, the time the event - * occurred, and the duration of the event and calls the PauseTimeAggregation method. - *

- * An implementation of PauseTimeAggregation is able to collate the data in a way - * that makes sense for how the data is to be viewed. For example: one may want to - * summarize the data as a histogram, or one may want to collect a series of data - * for plotting. - *


- * {@literal @}Aggregates({EventSource.G1GC. EventSource.Generational, EventSource.ZGC, EventSource.Shenandoah})
- * public class PauseTimeAggregator extends Aggregator{@literal <}PauseTimeAggregation{@literal >} {
- *     ...
- * }
- * {@literal @}Collates(PauseTimeAggregator.class)
- * public interface PauseTimeAggregation extends Aggregation {
- *     ...
- * }
- *
- * public class PauseTimeSummary implements PauseTimeAggregation {
- *     ...
- * }
- *
- * public class PauseTimeGraph implements PauseTimeAggregation {
- *     ...
- * }
- * 
- */ +/// An implementation of an Aggregation collates data from an Aggregator. +/// This annotation is used on an Aggregation to tell GCToolKit which +/// Aggregator produces the data the Aggregation collates. +/// +/// In this example, there is a PauseTimeAggegator which receives pause time events +/// from GCToolKit. The PauseTimeAggregator extracts the cause, the time the event +/// occurred, and the duration of the event and calls the PauseTimeAggregation method. +/// +/// An implementation of PauseTimeAggregation is able to collate the data in a way +/// that makes sense for how the data is to be viewed. For example: one may want to +/// summarize the data as a histogram, or one may want to collect a series of data +/// for plotting. +/// ``` +/// +/// `@`Aggregates({EventSource.G1GC. EventSource.Generational, EventSource.ZGC, EventSource.Shenandoah}) +/// public class PauseTimeAggregator extends Aggregator`<`PauseTimeAggregation`>` { +/// ... +/// } +/// `@`Collates(PauseTimeAggregator.class) +/// public interface PauseTimeAggregation extends Aggregation { +/// ... +/// } +/// +/// public class PauseTimeSummary implements PauseTimeAggregation { +/// ... +/// } +/// +/// public class PauseTimeGraph implements PauseTimeAggregation { +/// ... +/// } +/// ``` @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) public @interface Collates { - /** - * - * @return the Aggregator that collates. - */ + /// @return the Aggregator that collates. Class> value(); } diff --git a/api/src/main/java/com/microsoft/gctoolkit/aggregator/EventSource.java b/api/src/main/java/com/microsoft/gctoolkit/aggregator/EventSource.java index 2a0cb55c..593bab7b 100644 --- a/api/src/main/java/com/microsoft/gctoolkit/aggregator/EventSource.java +++ b/api/src/main/java/com/microsoft/gctoolkit/aggregator/EventSource.java @@ -6,51 +6,31 @@ import static com.microsoft.gctoolkit.message.ChannelName.*; -/** - * EventSource indicates to the source of the GC events - * that an Aggregator is meant to process. - * @see Aggregates - */ +/// EventSource indicates to the source of the GC events +/// that an Aggregator is meant to process. +/// @see Aggregates public enum EventSource { - /** - * Event come from CMS, Parallel or Serial collectors. - */ + /// Event come from CMS, Parallel or Serial collectors. GENERATIONAL(GENERATIONAL_HEAP_PARSER_OUTBOX), CMS_UNIFIED(GENERATIONAL_HEAP_PARSER_OUTBOX), - /** - * Events that come from the CMS collection cycles - * @deprecated use the GENERATIONAL event source instead. - */ + /// Events that come from the CMS collection cycles + /// @deprecated use the GENERATIONAL event source instead. @Deprecated(since="3.0.8", forRemoval=true) CMS_PREUNIFIED(CMS_TENURED_POOL_PARSER_OUTBOX), - /** - * Events come from the G1 collector. - */ + /// Events come from the G1 collector. G1GC(G1GC_PARSER_OUTBOX), - /** - * Events come from the Shenandoah collector. - */ + /// Events come from the Shenandoah collector. SHENANDOAH(SHENANDOAH_PARSER_OUTBOX), - /** - * Events come from the ZGC collector. - */ + /// Events come from the ZGC collector. ZGC(ZGC_PARSER_OUTBOX), - /** - * Events come from the safe points in the GC log, or from a separate safepoint log. - */ + /// Events come from the safe points in the GC log, or from a separate safepoint log. SAFEPOINT(JVM_EVENT_PARSER_OUTBOX), - /** - * Events come from the survivor space. - */ + /// Events come from the survivor space. SURVIVOR(SURVIVOR_MEMORY_POOL_PARSER_OUTBOX), - /** - * Events come from the tenured space. - */ + /// Events come from the tenured space. TENURED(GENERATIONAL_HEAP_PARSER_OUTBOX), - /** - * Events that come from all sources - */ + /// Events that come from all sources JVM(JVM_EVENT_PARSER_OUTBOX); ChannelName channel; diff --git a/api/src/main/java/com/microsoft/gctoolkit/aggregator/JVMEventDispatcher.java b/api/src/main/java/com/microsoft/gctoolkit/aggregator/JVMEventDispatcher.java index 8c259e04..42de944d 100644 --- a/api/src/main/java/com/microsoft/gctoolkit/aggregator/JVMEventDispatcher.java +++ b/api/src/main/java/com/microsoft/gctoolkit/aggregator/JVMEventDispatcher.java @@ -8,14 +8,12 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.function.Consumer; -/** - * This is a utility class that supports the {@link Aggregator#register(Class, Consumer)} method. - */ +/// This is a utility class that supports the [Aggregator#register(Class, Consumer)] method. public class JVMEventDispatcher { private final Map, Consumer> eventConsumers = new ConcurrentHashMap<>(); - private final Consumer nopConsumer = (evt) -> {}; + private final Consumer nopConsumer = _ -> {}; @SuppressWarnings("unchecked") private Consumer getConsumerForClass(Class eventClass) { @@ -56,24 +54,20 @@ private Consumer getConsumerForClass(Clas return nopConsumer; } - /** - * Called from {@link Aggregator#register(Class, Consumer)} - * @param eventClass A JVMEvent class that the Aggregator captures - * @param process A method to call back when an event of type {@code eventClass} is captured. - * @param A type of JVMEvent - */ + /// Called from [Aggregator#register(Class, Consumer)] + /// @param eventClass A JVMEvent class that the Aggregator captures + /// @param process A method to call back when an event of type `eventClass` is captured. + /// @param R A type of JVMEvent @SuppressWarnings("unchecked") public void register(Class eventClass, Consumer process) { eventConsumers.put(eventClass, (Consumer)process); } - /** - * todo: fix comment for the link below. - * Called from {@link Aggregator#receive(JVMEvent)}, this invokes the process method that was - * {@link #register(Class, Consumer) registered}. - * @param event An event from the parser. - * @param the type of JVMEvent. - */ + /// todo: fix comment for the link below. + /// Called from [Aggregator#receive(JVMEvent)], this invokes the process method that was + /// [registered][#register(Class, Consumer)]. + /// @param event An event from the parser. + /// @param R the type of JVMEvent. public void dispatch(R event) { getConsumerForClass(event.getClass()).accept(event); } diff --git a/api/src/main/java/com/microsoft/gctoolkit/event/CPUSummary.java b/api/src/main/java/com/microsoft/gctoolkit/event/CPUSummary.java index dc43ee39..b3242f5d 100644 --- a/api/src/main/java/com/microsoft/gctoolkit/event/CPUSummary.java +++ b/api/src/main/java/com/microsoft/gctoolkit/event/CPUSummary.java @@ -2,58 +2,44 @@ // Licensed under the MIT License. package com.microsoft.gctoolkit.event; -/** - * Breakout of the CPU summary to contain gc thread time in the - * kernel - * total time for all threads executing GC code - * wall clock time or pause time of GC cycle. - */ +/// Breakout of the CPU summary to contain gc thread time in the +/// kernel +/// total time for all threads executing GC code +/// wall clock time or pause time of GC cycle. public class CPUSummary { private final double user; private final double kernel; private final double wallClock; - /** - * - * @param user time - * @param kernel time - * @param wallClock time - */ + /// @param user time + /// @param kernel time + /// @param wallClock time public CPUSummary(double user, double kernel, double wallClock) { this.user = user; this.kernel = kernel; this.wallClock = wallClock; } - /** - * - * @return user time in seconds. - */ + /// @return user time in seconds. public double getUser() { return this.user; } - /**qq - * - * @return kernel time in seconds. - */ + /// qq + /// + /// @return kernel time in seconds. public double getKernel() { return this.kernel; } - /** - * - * @return real time in seconds. - */ + /// @return real time in seconds. public double getWallClock() { return this.wallClock; } - /** - * - * @return string representation of the data. - */ + /// @return string representation of the data. + @Override public String toString() { return "[Times: user=" + user + " sys=" + kernel + ", real=" + wallClock + " secs]"; } diff --git a/api/src/main/java/com/microsoft/gctoolkit/event/GCCause.java b/api/src/main/java/com/microsoft/gctoolkit/event/GCCause.java index 3de5781a..e79c515d 100644 --- a/api/src/main/java/com/microsoft/gctoolkit/event/GCCause.java +++ b/api/src/main/java/com/microsoft/gctoolkit/event/GCCause.java @@ -2,10 +2,8 @@ // Licensed under the MIT License. package com.microsoft.gctoolkit.event; -/** - * There are causes for Garbage Collection, this is a representation of the - * causes that a GC log file can hold. - */ +/// There are causes for Garbage Collection, this is a representation of the +/// causes that a GC log file can hold. public enum GCCause { JAVA_LANG_SYSTEM("System.gc()"), DIAGNOSTIC_COMMAND("Diagnostic Command"), diff --git a/api/src/main/java/com/microsoft/gctoolkit/event/GCCauses.java b/api/src/main/java/com/microsoft/gctoolkit/event/GCCauses.java index 96e0bb4f..1708e304 100644 --- a/api/src/main/java/com/microsoft/gctoolkit/event/GCCauses.java +++ b/api/src/main/java/com/microsoft/gctoolkit/event/GCCauses.java @@ -2,6 +2,8 @@ // Licensed under the MIT License. package com.microsoft.gctoolkit.event; +import org.jspecify.annotations.Nullable; + import java.util.Arrays; import java.util.Map; import java.util.function.Function; @@ -16,7 +18,7 @@ public class GCCauses { GC_CAUSES.put("System", GCCause.JAVA_LANG_SYSTEM); } - public static GCCause get(String gcCauseName) { + public static GCCause get(@Nullable String gcCauseName) { GCCause cause; if (gcCauseName == null) { cause = GCCause.GCCAUSE_NOT_SET; diff --git a/api/src/main/java/com/microsoft/gctoolkit/event/GCEvent.java b/api/src/main/java/com/microsoft/gctoolkit/event/GCEvent.java index 9e1dd398..5bb4f382 100644 --- a/api/src/main/java/com/microsoft/gctoolkit/event/GCEvent.java +++ b/api/src/main/java/com/microsoft/gctoolkit/event/GCEvent.java @@ -7,114 +7,83 @@ import java.util.Objects; -/** - * A GCEvent is something that happens in the GC sub system that is captured in - * the log, e.g. a Full GC - *

- * A GCEvent has meta data which it expects to be overridden, e.g. whether or - * not it was a young collection - */ +/// A GCEvent is something that happens in the GC sub system that is captured in +/// the log, e.g. a Full GC +/// +/// A GCEvent has meta data which it expects to be overridden, e.g. whether or +/// not it was a young collection public abstract class GCEvent extends JVMEvent { static final double TIMESTAMP_THRESHOLD = 1.0E-6; private final GarbageCollectionTypes gcType; private GCCause cause; - /** - * - * @param timeStamp for event - * @param gcType for event - * @param cause of event - * @param duration of event - */ + /// @param timeStamp for event + /// @param gcType for event + /// @param cause of event + /// @param duration of event protected GCEvent(DateTimeStamp timeStamp, GarbageCollectionTypes gcType, GCCause cause, double duration) { super(timeStamp, duration); this.gcType = gcType; this.cause = cause; } - /** - * - * @param timeStamp for event - * @param duration of event - */ + /// @param timeStamp for event + /// @param duration of event protected GCEvent(DateTimeStamp timeStamp, double duration) { this(timeStamp, GarbageCollectionTypes.Unknown, GCCause.UNKNOWN_GCCAUSE, duration); } - /** - * - * @param timeStamp for event - * @param cause that triggered the event - * @param duration of event - */ + /// @param timeStamp for event + /// @param cause that triggered the event + /// @param duration of event protected GCEvent(DateTimeStamp timeStamp, GCCause cause, double duration) { this(timeStamp, GarbageCollectionTypes.Unknown, cause, duration); } - /** - * - * @param timeStamp for event - * @param gcType of the event - * @param duration of the event - */ + /// @param timeStamp for event + /// @param gcType of the event + /// @param duration of the event protected GCEvent(DateTimeStamp timeStamp, GarbageCollectionTypes gcType, double duration) { this(timeStamp, gcType, GCCause.UNKNOWN_GCCAUSE, duration); } - /** - * - * @param cause of the event - */ + /// @param cause of the event public void setGCCause(GCCause cause) { this.cause = cause; } - /** - * - * @return the cause of the event. - */ + /// @return the cause of the event. public GCCause getGCCause() { return this.cause; } - /** - * - * @return the type of collection this event represents - */ + /// @return the type of collection this event represents public GarbageCollectionTypes getGarbageCollectionType() { return gcType; } - /** - * - * Is the distance between x and y larger than the provided threshold. - * @param x is a value - * @param y is a value - * @return boolean is diff is greater than threshold - */ + /// Is the distance between x and y larger than the provided threshold. + /// @param x is a value + /// @param y is a value + /// @return boolean is diff is greater than threshold private boolean withinThreshold(final double x, final double y) { return TIMESTAMP_THRESHOLD > Math.abs(x - y); } - /** - * - * @return hashCode - */ + /// @return hashCode @Override public int hashCode() { return Objects.hash(gcType.getLabel(),getDateTimeStamp().getTimeStamp(),getDuration()); } - /** - * - * @param o the object to compare to. - * @return true is this equals o. - */ + /// @param o the object to compare to. + /// @return true is this equals o. + @Override public boolean equals(Object o) { if (o == this) return true; if (o == null || getClass() != o.getClass()) return false; - GCEvent gcEvent = (GCEvent) o; + var gcEvent = (GCEvent) o; return gcType.getLabel().equals(gcEvent.gcType.getLabel()) && withinThreshold(getDateTimeStamp().getTimeStamp(), gcEvent.getDateTimeStamp().getTimeStamp()) && withinThreshold(getDuration(), gcEvent.getDuration()); diff --git a/api/src/main/java/com/microsoft/gctoolkit/event/GarbageCollectionTypes.java b/api/src/main/java/com/microsoft/gctoolkit/event/GarbageCollectionTypes.java index 68634474..6cdfa80f 100644 --- a/api/src/main/java/com/microsoft/gctoolkit/event/GarbageCollectionTypes.java +++ b/api/src/main/java/com/microsoft/gctoolkit/event/GarbageCollectionTypes.java @@ -2,9 +2,7 @@ // Licensed under the MIT License. package com.microsoft.gctoolkit.event; -/** - * Representation of GC Collection Events - */ +/// Representation of GC Collection Events public enum GarbageCollectionTypes implements LabelledGCEventType { GC("GC"), @@ -71,6 +69,7 @@ public static GarbageCollectionTypes fromLabel(String label) { return LabelledGCEventType.fromLabel(GarbageCollectionTypes.class, label); } + @Override public String getLabel() { return label; } diff --git a/api/src/main/java/com/microsoft/gctoolkit/event/LabelledGCEventType.java b/api/src/main/java/com/microsoft/gctoolkit/event/LabelledGCEventType.java index 3bb540d9..4dc8df36 100644 --- a/api/src/main/java/com/microsoft/gctoolkit/event/LabelledGCEventType.java +++ b/api/src/main/java/com/microsoft/gctoolkit/event/LabelledGCEventType.java @@ -4,9 +4,7 @@ import java.util.Arrays; -/** - * Representation of GC Collection Events - */ +/// Representation of GC Collection Events public interface LabelledGCEventType { static & LabelledGCEventType> E fromLabel(Class type, String label) { diff --git a/api/src/main/java/com/microsoft/gctoolkit/event/MemoryPoolSummary.java b/api/src/main/java/com/microsoft/gctoolkit/event/MemoryPoolSummary.java index c7de3ec1..68bbe402 100644 --- a/api/src/main/java/com/microsoft/gctoolkit/event/MemoryPoolSummary.java +++ b/api/src/main/java/com/microsoft/gctoolkit/event/MemoryPoolSummary.java @@ -50,13 +50,13 @@ public MemoryPoolSummary add(MemoryPoolSummary memoryPoolSummary) { } public long kBytesRecovered() { - long kBytesRecovered = kByteDelta(); - return (kBytesRecovered > 0) ? kBytesRecovered : 0L; + var kBytesRecovered = kByteDelta(); + return kBytesRecovered > 0 ? kBytesRecovered : 0L; } public long kBytesAllocated(MemoryPoolSummary previousHeapState) { - long kBytesAllocated = occupancyBeforeCollection - previousHeapState.getOccupancyAfterCollection(); - return (kBytesAllocated > 0) ? kBytesAllocated : 0L; + var kBytesAllocated = occupancyBeforeCollection - previousHeapState.getOccupancyAfterCollection(); + return kBytesAllocated > 0 ? kBytesAllocated : 0L; } // Will be positive if data is copied into the pool and negative if the pool has been GC'ed @@ -68,6 +68,7 @@ public boolean isValid() { return sizeAfterCollection != -1; } + @Override public String toString() { return occupancyBeforeCollection + "K(" + sizeBeforeCollection + "K)->" + occupancyAfterCollection + "K(" + sizeAfterCollection + "K)"; } diff --git a/api/src/main/java/com/microsoft/gctoolkit/event/ReferenceGCSummary.java b/api/src/main/java/com/microsoft/gctoolkit/event/ReferenceGCSummary.java index bf60958b..b2e2bdf8 100644 --- a/api/src/main/java/com/microsoft/gctoolkit/event/ReferenceGCSummary.java +++ b/api/src/main/java/com/microsoft/gctoolkit/event/ReferenceGCSummary.java @@ -4,10 +4,8 @@ import com.microsoft.gctoolkit.time.DateTimeStamp; -/** - * Exemplar - * 11906.844: [GC pause (young)11906.881: [SoftReference, 0 refs, 0.0000060 secs]11906.881: [WeakReference, 0 refs, 0.0000020 secs]11906.881: [FinalReference, 0 refs, 0.0000010 secs]11906.881: [PhantomReference, 0 refs, 0.0000020 secs]11906.881: [JNI Weak Reference, 0.0002710 secs], 0.03831600 secs] - */ +/// Exemplar +/// 11906.844: [GC pause (young)11906.881: [SoftReference, 0 refs, 0.0000060 secs]11906.881: [WeakReference, 0 refs, 0.0000020 secs]11906.881: [FinalReference, 0 refs, 0.0000010 secs]11906.881: [PhantomReference, 0 refs, 0.0000020 secs]11906.881: [JNI Weak Reference, 0.0002710 secs], 0.03831600 secs] public class ReferenceGCSummary { private DateTimeStamp softReferenceDateTimeStamp; diff --git a/api/src/main/java/com/microsoft/gctoolkit/event/TLABSummary.java b/api/src/main/java/com/microsoft/gctoolkit/event/TLABSummary.java index 16449883..162790b5 100644 --- a/api/src/main/java/com/microsoft/gctoolkit/event/TLABSummary.java +++ b/api/src/main/java/com/microsoft/gctoolkit/event/TLABSummary.java @@ -2,12 +2,11 @@ // Licensed under the MIT License. package com.microsoft.gctoolkit.event; - -import java.util.ArrayList; +import java.util.List; public class TLABSummary { - private ArrayList tlabRecords; + private List tlabRecords; public TLABSummary() { } diff --git a/api/src/main/java/com/microsoft/gctoolkit/event/g1gc/ConcurrentCleanupForNextMark.java b/api/src/main/java/com/microsoft/gctoolkit/event/g1gc/ConcurrentCleanupForNextMark.java index 94753495..b0d54de9 100644 --- a/api/src/main/java/com/microsoft/gctoolkit/event/g1gc/ConcurrentCleanupForNextMark.java +++ b/api/src/main/java/com/microsoft/gctoolkit/event/g1gc/ConcurrentCleanupForNextMark.java @@ -6,26 +6,19 @@ import com.microsoft.gctoolkit.event.GarbageCollectionTypes; import com.microsoft.gctoolkit.time.DateTimeStamp; -/** - * Concurrent cleanup for next mark - */ +/// Concurrent cleanup for next mark public class ConcurrentCleanupForNextMark extends G1GCConcurrentEvent { - /** - * @param timeStamp start of event - * @param duration event duration - */ + /// @param timeStamp start of event + /// @param duration event duration public ConcurrentCleanupForNextMark(DateTimeStamp timeStamp, double duration) { super(timeStamp, GarbageCollectionTypes.ConcurrentCleanupForNextMark, GCCause.UNKNOWN_GCCAUSE, duration); } - /** - * - * @param timeStamp start of event - * @param cause trigger for the event - * @param duration event duration - */ + /// @param timeStamp start of event + /// @param cause trigger for the event + /// @param duration event duration public ConcurrentCleanupForNextMark(DateTimeStamp timeStamp, GCCause cause, double duration) { super(timeStamp, GarbageCollectionTypes.ConcurrentCleanupForNextMark, cause, duration); } diff --git a/api/src/main/java/com/microsoft/gctoolkit/event/g1gc/ConcurrentClearClaimedMarks.java b/api/src/main/java/com/microsoft/gctoolkit/event/g1gc/ConcurrentClearClaimedMarks.java index 18f8850f..069de374 100644 --- a/api/src/main/java/com/microsoft/gctoolkit/event/g1gc/ConcurrentClearClaimedMarks.java +++ b/api/src/main/java/com/microsoft/gctoolkit/event/g1gc/ConcurrentClearClaimedMarks.java @@ -6,17 +6,12 @@ import com.microsoft.gctoolkit.event.GarbageCollectionTypes; import com.microsoft.gctoolkit.time.DateTimeStamp; -/** - * Concurrent phase, Clear claimed marks - */ +/// Concurrent phase, Clear claimed marks public class ConcurrentClearClaimedMarks extends G1GCConcurrentEvent { - /** - * - * @param timeStamp time of event - * @param duration duration of event - */ + /// @param timeStamp time of event + /// @param duration duration of event public ConcurrentClearClaimedMarks(DateTimeStamp timeStamp, double duration) { super(timeStamp, GarbageCollectionTypes.ConcurrentClearClaimedMarks, GCCause.UNKNOWN_GCCAUSE, duration); } diff --git a/api/src/main/java/com/microsoft/gctoolkit/event/g1gc/ConcurrentCompleteCleanup.java b/api/src/main/java/com/microsoft/gctoolkit/event/g1gc/ConcurrentCompleteCleanup.java index 1817d871..37ad91d9 100644 --- a/api/src/main/java/com/microsoft/gctoolkit/event/g1gc/ConcurrentCompleteCleanup.java +++ b/api/src/main/java/com/microsoft/gctoolkit/event/g1gc/ConcurrentCompleteCleanup.java @@ -6,26 +6,19 @@ import com.microsoft.gctoolkit.event.GarbageCollectionTypes; import com.microsoft.gctoolkit.time.DateTimeStamp; -/** - * Concurrent phase, complete cleanup at end of G1GC Concurrent cycle - */ +/// Concurrent phase, complete cleanup at end of G1GC Concurrent cycle public class ConcurrentCompleteCleanup extends G1GCConcurrentEvent { - /** - * @param timeStamp time of event - * @param duration duration of event - */ + /// @param timeStamp time of event + /// @param duration duration of event public ConcurrentCompleteCleanup(DateTimeStamp timeStamp, double duration) { super(timeStamp, GarbageCollectionTypes.ConcurrentCompleteCleanup, GCCause.UNKNOWN_GCCAUSE, duration); } - /** - * - * @param timeStamp time of event - * @param cause reason for triggering this event - * @param duration duration of event - */ + /// @param timeStamp time of event + /// @param cause reason for triggering this event + /// @param duration duration of event public ConcurrentCompleteCleanup(DateTimeStamp timeStamp, GCCause cause, double duration) { super(timeStamp, GarbageCollectionTypes.ConcurrentCompleteCleanup, cause, duration); } diff --git a/api/src/main/java/com/microsoft/gctoolkit/event/g1gc/ConcurrentCreateLiveData.java b/api/src/main/java/com/microsoft/gctoolkit/event/g1gc/ConcurrentCreateLiveData.java index 4086ef13..6b8e4353 100644 --- a/api/src/main/java/com/microsoft/gctoolkit/event/g1gc/ConcurrentCreateLiveData.java +++ b/api/src/main/java/com/microsoft/gctoolkit/event/g1gc/ConcurrentCreateLiveData.java @@ -6,25 +6,19 @@ import com.microsoft.gctoolkit.event.GarbageCollectionTypes; import com.microsoft.gctoolkit.time.DateTimeStamp; -/** - * Concurrent phase: Create Live Data - */ +/// Concurrent phase: Create Live Data public class ConcurrentCreateLiveData extends G1GCConcurrentEvent { - /** - * @param timeStamp time of the event - * @param duration duration of the event - */ + /// @param timeStamp time of the event + /// @param duration duration of the event public ConcurrentCreateLiveData(DateTimeStamp timeStamp, double duration) { super(timeStamp, GarbageCollectionTypes.ConcurrentCreateLiveData, GCCause.UNKNOWN_GCCAUSE, duration); } - /** - * @param timeStamp time of the event - * @param cause reason to trigger the event - * @param duration duration of the event - */ + /// @param timeStamp time of the event + /// @param cause reason to trigger the event + /// @param duration duration of the event public ConcurrentCreateLiveData(DateTimeStamp timeStamp, GCCause cause, double duration) { super(timeStamp, GarbageCollectionTypes.ConcurrentCreateLiveData, cause, duration); } diff --git a/api/src/main/java/com/microsoft/gctoolkit/event/g1gc/ConcurrentScanRootRegion.java b/api/src/main/java/com/microsoft/gctoolkit/event/g1gc/ConcurrentScanRootRegion.java index c0cb1953..384e0671 100644 --- a/api/src/main/java/com/microsoft/gctoolkit/event/g1gc/ConcurrentScanRootRegion.java +++ b/api/src/main/java/com/microsoft/gctoolkit/event/g1gc/ConcurrentScanRootRegion.java @@ -6,25 +6,19 @@ import com.microsoft.gctoolkit.event.GarbageCollectionTypes; import com.microsoft.gctoolkit.time.DateTimeStamp; -/** - * Concurrent phase - */ +/// Concurrent phase public class ConcurrentScanRootRegion extends G1GCConcurrentEvent { - /** - * @param timeStamp time of the event - * @param duration duration of the event - */ + /// @param timeStamp time of the event + /// @param duration duration of the event public ConcurrentScanRootRegion(DateTimeStamp timeStamp, double duration) { super(timeStamp, GarbageCollectionTypes.ConcurrentRootRegionScan, GCCause.UNKNOWN_GCCAUSE, duration); } - /** - * @param timeStamp time of the event - * @param cause reason to trigger the event - * @param duration duration of the event - */ + /// @param timeStamp time of the event + /// @param cause reason to trigger the event + /// @param duration duration of the event public ConcurrentScanRootRegion(DateTimeStamp timeStamp, GCCause cause, double duration) { super(timeStamp, GarbageCollectionTypes.ConcurrentRootRegionScan, cause, duration); } diff --git a/api/src/main/java/com/microsoft/gctoolkit/event/g1gc/G1Cleanup.java b/api/src/main/java/com/microsoft/gctoolkit/event/g1gc/G1Cleanup.java index 56864bce..1fbc75e9 100644 --- a/api/src/main/java/com/microsoft/gctoolkit/event/g1gc/G1Cleanup.java +++ b/api/src/main/java/com/microsoft/gctoolkit/event/g1gc/G1Cleanup.java @@ -6,15 +6,11 @@ import com.microsoft.gctoolkit.event.GarbageCollectionTypes; import com.microsoft.gctoolkit.time.DateTimeStamp; -/** - * Pause phase - */ +/// Pause phase public class G1Cleanup extends G1RealPause { - /** - * @param timeStamp time of the event - * @param duration duration of the event - */ + /// @param timeStamp time of the event + /// @param duration duration of the event public G1Cleanup(DateTimeStamp timeStamp, double duration) { super(timeStamp, GarbageCollectionTypes.G1GCCleanup, GCCause.GCCAUSE_NOT_SET, duration); } diff --git a/api/src/main/java/com/microsoft/gctoolkit/event/g1gc/G1ConcurrentCleanup.java b/api/src/main/java/com/microsoft/gctoolkit/event/g1gc/G1ConcurrentCleanup.java index f467451e..2e936ecb 100644 --- a/api/src/main/java/com/microsoft/gctoolkit/event/g1gc/G1ConcurrentCleanup.java +++ b/api/src/main/java/com/microsoft/gctoolkit/event/g1gc/G1ConcurrentCleanup.java @@ -6,25 +6,19 @@ import com.microsoft.gctoolkit.event.GarbageCollectionTypes; import com.microsoft.gctoolkit.time.DateTimeStamp; -/** - * Concurrent phase - */ +/// Concurrent phase public class G1ConcurrentCleanup extends G1GCConcurrentEvent { - /** - * @param timeStamp time of the event - * @param duration duration of the event - */ + /// @param timeStamp time of the event + /// @param duration duration of the event public G1ConcurrentCleanup(DateTimeStamp timeStamp, double duration) { super(timeStamp, GarbageCollectionTypes.G1GCConcurrentCleanup, GCCause.GCCAUSE_NOT_SET, duration); } - /** - * @param timeStamp time of the event - * @param cause reason to trigger the event - * @param duration duration of the event - */ + /// @param timeStamp time of the event + /// @param cause reason to trigger the event + /// @param duration duration of the event public G1ConcurrentCleanup(DateTimeStamp timeStamp, GCCause cause, double duration) { super(timeStamp, GarbageCollectionTypes.G1GCConcurrentCleanup, cause, duration); } diff --git a/api/src/main/java/com/microsoft/gctoolkit/event/g1gc/G1ConcurrentMark.java b/api/src/main/java/com/microsoft/gctoolkit/event/g1gc/G1ConcurrentMark.java index 9f100804..b8f81c29 100644 --- a/api/src/main/java/com/microsoft/gctoolkit/event/g1gc/G1ConcurrentMark.java +++ b/api/src/main/java/com/microsoft/gctoolkit/event/g1gc/G1ConcurrentMark.java @@ -6,10 +6,7 @@ import com.microsoft.gctoolkit.event.GarbageCollectionTypes; import com.microsoft.gctoolkit.time.DateTimeStamp; -/** - * Concurrent phase - * - */ +/// Concurrent phase public class G1ConcurrentMark extends G1GCConcurrentEvent { @@ -19,89 +16,65 @@ public class G1ConcurrentMark extends G1GCConcurrentEvent { private double precleanDuration = -1.0d; private boolean aborted = false; - /** - * @param timeStamp time of the event - * @param duration duration of the event - */ + /// @param timeStamp time of the event + /// @param duration duration of the event public G1ConcurrentMark(DateTimeStamp timeStamp, double duration) { super(timeStamp, GarbageCollectionTypes.G1GCConcurrentMark, GCCause.GCCAUSE_NOT_SET, duration); } - /** - * @param timeStamp time of the event - * @param cause reason to trigger the event - * @param duration duration of the event - */ + /// @param timeStamp time of the event + /// @param cause reason to trigger the event + /// @param duration duration of the event public G1ConcurrentMark(DateTimeStamp timeStamp, GCCause cause, double duration) { super(timeStamp, GarbageCollectionTypes.G1GCConcurrentMark, cause, duration); } - /** - * @param duration for the mark from roots step - */ + /// @param duration for the mark from roots step public void setMarkFromRootsDuration(double duration) { this.markFromRootsDuration = duration; } - /** - * @return mark from roots duration - */ + /// @return mark from roots duration public double getMarkFromRootsDuration() { return markFromRootsDuration; } - /** - * @return number of active workers - */ + /// @return number of active workers public int getActiveWorkerThreads() { return activeWorkerThreads; } - /** - * @param activeWorkerThreads number of active workers - */ + /// @param activeWorkerThreads number of active workers public void setActiveWorkerThreads(int activeWorkerThreads) { this.activeWorkerThreads = activeWorkerThreads; } - /** - * @return size of worker pool - */ + /// @return size of worker pool public int getAvailableWorkerThreads() { return availableWorkerThreads; } - /** - * @param availableWorkerThreads set the work pool size - */ + /// @param availableWorkerThreads set the work pool size public void setAvailableWorkerThreads(int availableWorkerThreads) { this.availableWorkerThreads = availableWorkerThreads; } - /** - * @return preclean duration - */ + /// @return preclean duration public double getPrecleanDuration() { return precleanDuration; } - /** - * @param duration set preclean duration - */ + /// @param duration set preclean duration public void setPrecleanDuration(double duration) { this.precleanDuration = duration; } - /** - * was preclean aborted due to occupancy threshold - */ + /// was preclean aborted due to occupancy threshold public void abort() { this.aborted = true; } - /** - * @return if preclean was aborted due to occupancy threshold - */ + /// @return if preclean was aborted due to occupancy threshold public boolean isAborted() { return this.aborted; } diff --git a/api/src/main/java/com/microsoft/gctoolkit/event/g1gc/G1ConcurrentStringDeduplication.java b/api/src/main/java/com/microsoft/gctoolkit/event/g1gc/G1ConcurrentStringDeduplication.java index 423b0bb0..cc5218fe 100644 --- a/api/src/main/java/com/microsoft/gctoolkit/event/g1gc/G1ConcurrentStringDeduplication.java +++ b/api/src/main/java/com/microsoft/gctoolkit/event/g1gc/G1ConcurrentStringDeduplication.java @@ -6,9 +6,7 @@ import com.microsoft.gctoolkit.event.GarbageCollectionTypes; import com.microsoft.gctoolkit.time.DateTimeStamp; -/** - * 2015-10-17T21:10:23.673-0400: 3993.137: [GC concurrent-string-deduplication, 79.3K->792.0B(78.6K), avg 96.2%, 0.0024351 secs] - */ +/// 2015-10-17T21:10:23.673-0400: 3993.137: [GC concurrent-string-deduplication, 79.3K->792.0B(78.6K), avg 96.2%, 0.0024351 secs] public class G1ConcurrentStringDeduplication extends G1GCConcurrentEvent { diff --git a/api/src/main/java/com/microsoft/gctoolkit/event/g1gc/G1FullGCNES.java b/api/src/main/java/com/microsoft/gctoolkit/event/g1gc/G1FullGCNES.java index b47745ba..50424eff 100644 --- a/api/src/main/java/com/microsoft/gctoolkit/event/g1gc/G1FullGCNES.java +++ b/api/src/main/java/com/microsoft/gctoolkit/event/g1gc/G1FullGCNES.java @@ -6,9 +6,7 @@ import com.microsoft.gctoolkit.event.GarbageCollectionTypes; import com.microsoft.gctoolkit.time.DateTimeStamp; -/** - * full GC not elsewhere specified on the G1 garbage collector - */ +/// full GC not elsewhere specified on the G1 garbage collector public class G1FullGCNES extends G1FullGC { public G1FullGCNES(DateTimeStamp timeStamp, GCCause cause, double pauseTime) { this(timeStamp, GarbageCollectionTypes.Full, cause, pauseTime); diff --git a/api/src/main/java/com/microsoft/gctoolkit/event/g1gc/G1GCPauseEvent.java b/api/src/main/java/com/microsoft/gctoolkit/event/g1gc/G1GCPauseEvent.java index 1a390859..ea907362 100644 --- a/api/src/main/java/com/microsoft/gctoolkit/event/g1gc/G1GCPauseEvent.java +++ b/api/src/main/java/com/microsoft/gctoolkit/event/g1gc/G1GCPauseEvent.java @@ -136,9 +136,9 @@ public MemoryPoolSummary getTenured() { return getHeap().minus(getEden()); } else { final RegionSummary summary = getArchiveRegionSummary(); - final long archiveRegionByteBefore = summary.getBefore() * heapRegionSize * 1024L; - final long archiveRegionByteAfter = summary.getAfter() * heapRegionSize * 1024L; - final long archiveRegionByteAssigned = summary.getAssigned() * heapRegionSize * 1024L; + final var archiveRegionByteBefore = summary.getBefore() * heapRegionSize * 1024L; + final var archiveRegionByteAfter = summary.getAfter() * heapRegionSize * 1024L; + final var archiveRegionByteAssigned = summary.getAssigned() * heapRegionSize * 1024L; return new MemoryPoolSummary(getHeap().getOccupancyBeforeCollection() - this.getEden().getOccupancyBeforeCollection() - getSurvivor().getOccupancyBeforeCollection() - archiveRegionByteAssigned, getHeap().getSizeBeforeCollection() - getEden().getSizeBeforeCollection() - getSurvivor().getOccupancyBeforeCollection() - archiveRegionByteBefore, diff --git a/api/src/main/java/com/microsoft/gctoolkit/event/g1gc/G1RealPause.java b/api/src/main/java/com/microsoft/gctoolkit/event/g1gc/G1RealPause.java index 3a25c5a6..7efbb818 100644 --- a/api/src/main/java/com/microsoft/gctoolkit/event/g1gc/G1RealPause.java +++ b/api/src/main/java/com/microsoft/gctoolkit/event/g1gc/G1RealPause.java @@ -6,9 +6,7 @@ import com.microsoft.gctoolkit.event.GarbageCollectionTypes; import com.microsoft.gctoolkit.time.DateTimeStamp; -/** - * not a trap - */ +/// not a trap public abstract class G1RealPause extends G1GCPauseEvent { public G1RealPause(DateTimeStamp timeStamp, GarbageCollectionTypes type, GCCause cause, double duration) { super(timeStamp, type, cause, duration); diff --git a/api/src/main/java/com/microsoft/gctoolkit/event/g1gc/G1Trap.java b/api/src/main/java/com/microsoft/gctoolkit/event/g1gc/G1Trap.java index af59b3a7..aa86c302 100644 --- a/api/src/main/java/com/microsoft/gctoolkit/event/g1gc/G1Trap.java +++ b/api/src/main/java/com/microsoft/gctoolkit/event/g1gc/G1Trap.java @@ -13,9 +13,7 @@ import java.util.logging.Level; import java.util.logging.Logger; -/** - * G1 Event to capture parser errors - */ +/// G1 Event to capture parser errors public class G1Trap extends G1GCPauseEvent { @@ -24,7 +22,10 @@ public class G1Trap extends G1GCPauseEvent { private static final String message = "Internal EventSource Error @ "; public G1Trap() { - super(new DateTimeStamp(0.0d), GarbageCollectionTypes.G1Trap, GCCause.UNKNOWN_GCCAUSE, 0.0d); + DateTimeStamp timeStamp = new DateTimeStamp(0.0d); + GarbageCollectionTypes type = GarbageCollectionTypes.G1Trap; + GCCause cause1 = GCCause.UNKNOWN_GCCAUSE; + super(timeStamp, type, cause1, 0.0d); } private int errorCount = 0; diff --git a/api/src/main/java/com/microsoft/gctoolkit/event/g1gc/G1Young.java b/api/src/main/java/com/microsoft/gctoolkit/event/g1gc/G1Young.java index a44d9e18..a2db6279 100644 --- a/api/src/main/java/com/microsoft/gctoolkit/event/g1gc/G1Young.java +++ b/api/src/main/java/com/microsoft/gctoolkit/event/g1gc/G1Young.java @@ -8,6 +8,7 @@ import com.microsoft.gctoolkit.event.UnifiedStatisticalSummary; import com.microsoft.gctoolkit.event.jvm.SurvivorRecord; import com.microsoft.gctoolkit.time.DateTimeStamp; +import org.jspecify.annotations.Nullable; import java.util.Iterator; import java.util.Map; @@ -234,7 +235,7 @@ public Iterator parallelPhaseNames() { return parallelPhaseSummaries.keySet().iterator(); } - public StatisticalSummary parallelPhaseSummaryFor(String phaseName) { + public @Nullable StatisticalSummary parallelPhaseSummaryFor(String phaseName) { return parallelPhaseSummaries.get(phaseName); } @@ -270,7 +271,7 @@ public Stream evacuateCSetPhaseNames() { return evacuateCSetPhase.keySet().stream(); } - public StatisticalSummary evacuateCSetPhaseDuration(String name) { + public @Nullable StatisticalSummary evacuateCSetPhaseDuration(String name) { return evacuateCSetPhase.get(name); } diff --git a/api/src/main/java/com/microsoft/gctoolkit/event/generational/AbortablePreClean.java b/api/src/main/java/com/microsoft/gctoolkit/event/generational/AbortablePreClean.java index fba624f9..b84edf63 100644 --- a/api/src/main/java/com/microsoft/gctoolkit/event/generational/AbortablePreClean.java +++ b/api/src/main/java/com/microsoft/gctoolkit/event/generational/AbortablePreClean.java @@ -6,30 +6,23 @@ import com.microsoft.gctoolkit.event.GarbageCollectionTypes; import com.microsoft.gctoolkit.time.DateTimeStamp; -/** - * CMS phase to put time between the InitialMark and the Remark phase. Abortable when time or space thresholds are met. - */ +/// CMS phase to put time between the InitialMark and the Remark phase. Abortable when time or space thresholds are met. public class AbortablePreClean extends CMSConcurrentEvent { private final boolean abortedDueToTime; - /** - * - * @param timeStamp time of event start - * @param duration how long the event lasted - * @param cpuTime CPU consumption time - * @param wallClockTime real time - * @param abortDueToTime was this phase aborted due to time - */ + /// @param timeStamp time of event start + /// @param duration how long the event lasted + /// @param cpuTime CPU consumption time + /// @param wallClockTime real time + /// @param abortDueToTime was this phase aborted due to time public AbortablePreClean(DateTimeStamp timeStamp, double duration, double cpuTime, double wallClockTime, boolean abortDueToTime) { super(timeStamp, GarbageCollectionTypes.Abortable_Preclean, GCCause.UNKNOWN_GCCAUSE, duration, cpuTime, wallClockTime); this.abortedDueToTime = abortDueToTime; } - /** - * Was the event aborted due to a timeout - * @return true is event was aborted due to a timeout (2 minutes by default). - */ + /// Was the event aborted due to a timeout + /// @return true is event was aborted due to a timeout (2 minutes by default). public boolean isAbortedDueToTime() { return this.abortedDueToTime; } diff --git a/api/src/main/java/com/microsoft/gctoolkit/event/generational/ConcurrentMark.java b/api/src/main/java/com/microsoft/gctoolkit/event/generational/ConcurrentMark.java index 77e5eb6c..9cb679fd 100644 --- a/api/src/main/java/com/microsoft/gctoolkit/event/generational/ConcurrentMark.java +++ b/api/src/main/java/com/microsoft/gctoolkit/event/generational/ConcurrentMark.java @@ -6,18 +6,13 @@ import com.microsoft.gctoolkit.event.GarbageCollectionTypes; import com.microsoft.gctoolkit.time.DateTimeStamp; -/** - * CMS concurrent mark phase - */ +/// CMS concurrent mark phase public class ConcurrentMark extends CMSConcurrentEvent { - /** - * - * @param timeStamp start of event - * @param duration duration of event - * @param cpuTime amount of CPU time consumes - * @param wallClockTime duration real time (hints at level of parallelize) - */ + /// @param timeStamp start of event + /// @param duration duration of event + /// @param cpuTime amount of CPU time consumes + /// @param wallClockTime duration real time (hints at level of parallelize) public ConcurrentMark(DateTimeStamp timeStamp, double duration, double cpuTime, double wallClockTime) { super(timeStamp, GarbageCollectionTypes.ConcurrentMark, GCCause.UNKNOWN_GCCAUSE, duration, cpuTime, wallClockTime); } diff --git a/api/src/main/java/com/microsoft/gctoolkit/event/generational/InitialMark.java b/api/src/main/java/com/microsoft/gctoolkit/event/generational/InitialMark.java index c58ba1c5..8e6a32e6 100644 --- a/api/src/main/java/com/microsoft/gctoolkit/event/generational/InitialMark.java +++ b/api/src/main/java/com/microsoft/gctoolkit/event/generational/InitialMark.java @@ -17,6 +17,7 @@ public InitialMark(DateTimeStamp timeStamp, double duration) { this(timeStamp, GCCause.UNKNOWN_GCCAUSE, duration); } + @Override public void add(MemoryPoolSummary tenured, MemoryPoolSummary heap) { this.add(heap.minus(tenured), tenured, heap); } diff --git a/api/src/main/java/com/microsoft/gctoolkit/event/jvm/ApplicationConcurrentTime.java b/api/src/main/java/com/microsoft/gctoolkit/event/jvm/ApplicationConcurrentTime.java index 8e0a9c13..fa87742d 100644 --- a/api/src/main/java/com/microsoft/gctoolkit/event/jvm/ApplicationConcurrentTime.java +++ b/api/src/main/java/com/microsoft/gctoolkit/event/jvm/ApplicationConcurrentTime.java @@ -4,15 +4,11 @@ import com.microsoft.gctoolkit.time.DateTimeStamp; -/** - * Event to report on time application is running with the collector - */ +/// Event to report on time application is running with the collector public class ApplicationConcurrentTime extends JVMEvent { - /** - * @param timeStamp start of event - * @param duration duration of the event - */ + /// @param timeStamp start of event + /// @param duration duration of the event public ApplicationConcurrentTime(DateTimeStamp timeStamp, double duration) { super(timeStamp, duration); } diff --git a/api/src/main/java/com/microsoft/gctoolkit/event/jvm/ApplicationRunTime.java b/api/src/main/java/com/microsoft/gctoolkit/event/jvm/ApplicationRunTime.java index 4ca1ea02..488f340d 100644 --- a/api/src/main/java/com/microsoft/gctoolkit/event/jvm/ApplicationRunTime.java +++ b/api/src/main/java/com/microsoft/gctoolkit/event/jvm/ApplicationRunTime.java @@ -4,15 +4,11 @@ import com.microsoft.gctoolkit.time.DateTimeStamp; -/** - * Application run time between safepoint events. - */ +/// Application run time between safepoint events. public class ApplicationRunTime extends JVMEvent { - /** - * @param timeStamp start of event - * @param duration duration of the event - */ + /// @param timeStamp start of event + /// @param duration duration of the event public ApplicationRunTime(DateTimeStamp timeStamp, double duration) { super(timeStamp, duration); } diff --git a/api/src/main/java/com/microsoft/gctoolkit/event/jvm/ApplicationStoppedTime.java b/api/src/main/java/com/microsoft/gctoolkit/event/jvm/ApplicationStoppedTime.java index 2176708f..d8262072 100644 --- a/api/src/main/java/com/microsoft/gctoolkit/event/jvm/ApplicationStoppedTime.java +++ b/api/src/main/java/com/microsoft/gctoolkit/event/jvm/ApplicationStoppedTime.java @@ -13,7 +13,8 @@ public class ApplicationStoppedTime extends JVMEvent { public ApplicationStoppedTime(DateTimeStamp timeStamp, double duration, double timeToStopThreads, VMOperations safePointReason) { - this(timeStamp, duration, timeToStopThreads, safePointReason, safePointReason.isCollection()); + var gcPause1 = safePointReason.isCollection(); + this(timeStamp, duration, timeToStopThreads, safePointReason, gcPause1); } public ApplicationStoppedTime(DateTimeStamp timeStamp, double duration, boolean gcPause) { diff --git a/api/src/main/java/com/microsoft/gctoolkit/event/jvm/JVMEvent.java b/api/src/main/java/com/microsoft/gctoolkit/event/jvm/JVMEvent.java index 080853ed..26fa27c8 100644 --- a/api/src/main/java/com/microsoft/gctoolkit/event/jvm/JVMEvent.java +++ b/api/src/main/java/com/microsoft/gctoolkit/event/jvm/JVMEvent.java @@ -4,36 +4,28 @@ import com.microsoft.gctoolkit.time.DateTimeStamp; -/** - * This is the base class for all JVM events created by the parser. - */ +/// This is the base class for all JVM events created by the parser. public abstract class JVMEvent { private final DateTimeStamp timeStamp; private final double duration; - /** - * All events have a date/time stamp of when the event occurred, and a duration. - * @param timeStamp The date/time stamp of when the event occurred. - * @param duration The duration of the event in decimal seconds. - */ + /// All events have a date/time stamp of when the event occurred, and a duration. + /// @param timeStamp The date/time stamp of when the event occurred. + /// @param duration The duration of the event in decimal seconds. public JVMEvent(DateTimeStamp timeStamp, double duration) { this.timeStamp = timeStamp; this.duration = duration; } - /** - * Get the date/time stamp of when the event occurred. - * @return The date/time stamp of when the event occurred. - */ + /// Get the date/time stamp of when the event occurred. + /// @return The date/time stamp of when the event occurred. public DateTimeStamp getDateTimeStamp() { return timeStamp; } - /** - * Get the duration of the event. - * @return The duration of the event in decimal seconds. - */ + /// Get the duration of the event. + /// @return The duration of the event in decimal seconds. public double getDuration() { return duration; } diff --git a/api/src/main/java/com/microsoft/gctoolkit/event/jvm/JVMTermination.java b/api/src/main/java/com/microsoft/gctoolkit/event/jvm/JVMTermination.java index 39a964b2..e7494cec 100644 --- a/api/src/main/java/com/microsoft/gctoolkit/event/jvm/JVMTermination.java +++ b/api/src/main/java/com/microsoft/gctoolkit/event/jvm/JVMTermination.java @@ -8,18 +8,16 @@ public class JVMTermination extends JVMEvent { private DateTimeStamp timeOfFirstEvent; - /** - * estimatedTimeOfJVMTermination is the time JVM terminated or the last JVMEvent was seen. For the last - * JVMEvent, any pause time will have been added to timeStamp. The duration normally means the duration - * of the event. In this case duration doesn't refer to the time the JVM took to shutdown but instead - * refers to the total running time of the JVM. This is a recognized change in the definition of duration. - * - * The start variable is the timeOfFirstEvent on the first event seen in the data source. - * Not starting from 0.000 secs should not add much noise to any of the subsequent calculations. - * - * @param estimatedTimeOfJVMTermination time of JVM termination message or end of last event seen - * @param timeOfFirstEvent time of first message in the GC log. - */ + /// estimatedTimeOfJVMTermination is the time JVM terminated or the last JVMEvent was seen. For the last + /// JVMEvent, any pause time will have been added to timeStamp. The duration normally means the duration + /// of the event. In this case duration doesn't refer to the time the JVM took to shutdown but instead + /// refers to the total running time of the JVM. This is a recognized change in the definition of duration. + /// + /// The start variable is the timeOfFirstEvent on the first event seen in the data source. + /// Not starting from 0.000 secs should not add much noise to any of the subsequent calculations. + /// + /// @param estimatedTimeOfJVMTermination time of JVM termination message or end of last event seen + /// @param timeOfFirstEvent time of first message in the GC log. public JVMTermination(DateTimeStamp estimatedTimeOfJVMTermination, DateTimeStamp timeOfFirstEvent) { super(estimatedTimeOfJVMTermination, 0.0d); this.timeOfFirstEvent = timeOfFirstEvent; diff --git a/api/src/main/java/com/microsoft/gctoolkit/event/jvm/SurvivorRecord.java b/api/src/main/java/com/microsoft/gctoolkit/event/jvm/SurvivorRecord.java index cf9bb054..313ba212 100644 --- a/api/src/main/java/com/microsoft/gctoolkit/event/jvm/SurvivorRecord.java +++ b/api/src/main/java/com/microsoft/gctoolkit/event/jvm/SurvivorRecord.java @@ -4,8 +4,6 @@ import com.microsoft.gctoolkit.time.DateTimeStamp; -import java.util.ArrayList; - public class SurvivorRecord extends JVMEvent { diff --git a/api/src/main/java/com/microsoft/gctoolkit/event/shenandoah/ShenandoahCycle.java b/api/src/main/java/com/microsoft/gctoolkit/event/shenandoah/ShenandoahCycle.java index 4123a842..ae295fc3 100644 --- a/api/src/main/java/com/microsoft/gctoolkit/event/shenandoah/ShenandoahCycle.java +++ b/api/src/main/java/com/microsoft/gctoolkit/event/shenandoah/ShenandoahCycle.java @@ -11,78 +11,59 @@ public class ShenandoahCycle extends GCEvent { private ERGO ergonomics; - /** - * @param timeStamp time of event - * @param gcType type of event - * @param cause reason for triggering event - * @param duration duration of the event - */ + /// @param timeStamp time of event + /// @param gcType type of event + /// @param cause reason for triggering event + /// @param duration duration of the event public ShenandoahCycle(DateTimeStamp timeStamp, GarbageCollectionTypes gcType, GCCause cause, double duration) { super(timeStamp, gcType, cause, duration); } - /** - * - * @param timeStamp time of event - * @param duration duration of the event - */ + /// @param timeStamp time of event + /// @param duration duration of the event public ShenandoahCycle(DateTimeStamp timeStamp, double duration) { super(timeStamp, duration); } - /** - * - * @param timeStamp time of event - * @param cause reason for triggering event - * @param duration duration of the event - */ + /// @param timeStamp time of event + /// @param cause reason for triggering event + /// @param duration duration of the event public ShenandoahCycle(DateTimeStamp timeStamp, GCCause cause, double duration) { super(timeStamp, cause, duration); } - /** - * - * @param timeStamp time of event - * @param gcType type of event - * @param duration duration of the event - */ + /// @param timeStamp time of event + /// @param gcType type of event + /// @param duration duration of the event public ShenandoahCycle(DateTimeStamp timeStamp, GarbageCollectionTypes gcType, double duration) { super(timeStamp, gcType, duration); } - /** - * - * @deprecated use setErgonomics(...) instead - * @param free memory after collection - * @param maxFree max free memory - * @param humongous allocations - * @param fragExternal fragmented memory outside of heap - * @param fragInternal fragmented memory inside heap - * @param reserve currently reserved memory - * @param maxReserve max reserved memory - */ + /// @deprecated use setErgonomics(...) instead + /// @param free memory after collection + /// @param maxFree max free memory + /// @param humongous allocations + /// @param fragExternal fragmented memory outside of heap + /// @param fragInternal fragmented memory inside heap + /// @param reserve currently reserved memory + /// @param maxReserve max reserved memory @Deprecated(forRemoval = true) public void addErgonomics(int free, int maxFree, int humongous, double fragExternal, double fragInternal, int reserve, int maxReserve) { setErgonomics(free, maxFree, humongous, fragExternal, fragInternal, reserve, maxReserve); } - /** - * - * @param free memory after collection - * @param maxFree max free memory - * @param humongous allocations - * @param fragExternal fragmented memory outside of heap - * @param fragInternal fragmented memory inside heap - * @param reserve currently reserved memory - * @param maxReserve max reserved memory - */ + /// @param free memory after collection + /// @param maxFree max free memory + /// @param humongous allocations + /// @param fragExternal fragmented memory outside of heap + /// @param fragInternal fragmented memory inside heap + /// @param reserve currently reserved memory + /// @param maxReserve max reserved memory public void setErgonomics(int free, int maxFree, int humongous, double fragExternal, double fragInternal, int reserve, int maxReserve) { this.ergonomics = new ERGO(free, maxFree, humongous, fragExternal, fragInternal, reserve, maxReserve); } - /** - * @return the ergonomics - */ + /// @return the ergonomics ERGO getErgonomics() { return ergonomics; } @@ -92,7 +73,7 @@ enum Phases { Concurrent_Marking, Concurrent_precleaning, Pause_Final_Mark, Concurrent_cleanup, Concurrent_evacuation, Pause_Init_Update_Refs, - Concurrent_update_references, Pause_Final_Update_Refs; + Concurrent_update_references, Pause_Final_Update_Refs } @@ -116,16 +97,13 @@ class ERGO { private final int reserve; private final int maxReserve; - /** - * - * @param free memory after collection - * @param maxFree max free memory - * @param humongous allocations - * @param fragExternal fragmented memory outside of heap - * @param fragInternal fragmented memory inside heap - * @param reserve currently reserved memory - * @param maxReserve max reserved memory - */ + /// @param free memory after collection + /// @param maxFree max free memory + /// @param humongous allocations + /// @param fragExternal fragmented memory outside of heap + /// @param fragInternal fragmented memory inside heap + /// @param reserve currently reserved memory + /// @param maxReserve max reserved memory public ERGO(int free, int maxFree, int humongous, double fragExternal, double fragInternal, int reserve, int maxReserve) { this.free = free; this.maxFree = maxFree; @@ -136,58 +114,37 @@ public ERGO(int free, int maxFree, int humongous, double fragExternal, double fr this.maxReserve = maxReserve; } - /** - * - * @return free - */ + /// @return free public int getFree() { return free; } - /** - * - * @return max free - */ + /// @return max free public int getMaxFree() { return maxFree; } - /** - * - * @return humongous count - */ + /// @return humongous count public int getHumongous() { return humongous; } - /** - * - * @return external fragmentation - */ + /// @return external fragmentation public double getFragExternal() { return fragExternal; } - /** - * - * @return internal fragmentation - */ + /// @return internal fragmentation public double getFragInternal() { return fragInternal; } - /** - * - * @return reserve - */ + /// @return reserve public int getReserve() { return reserve; } - /** - * - * @return return max reserve - */ + /// @return return max reserve public int getMaxReserve() { return maxReserve; } diff --git a/api/src/main/java/com/microsoft/gctoolkit/event/zgc/ZGCCollection.java b/api/src/main/java/com/microsoft/gctoolkit/event/zgc/ZGCCollection.java index 8938a7ca..9d9ac7c4 100644 --- a/api/src/main/java/com/microsoft/gctoolkit/event/zgc/ZGCCollection.java +++ b/api/src/main/java/com/microsoft/gctoolkit/event/zgc/ZGCCollection.java @@ -333,16 +333,12 @@ public void setLoadAverages(double[] load) { } public double getLoadAverageAt(int time) { - switch (time) { - case 1: - return load[0]; - case 5: - return load[1]; - case 15: - return load[2]; - default: - return 0.0d; - } + return switch (time) { + case 1 -> load[0]; + case 5 -> load[1]; + case 15 -> load[2]; + default -> 0.0d; + }; } public void setMMU(double[] mmu) { @@ -350,22 +346,15 @@ public void setMMU(double[] mmu) { } public double getMMU(int percentage) { - switch (percentage) { - case 2: - return mmu[0]; - case 5: - return mmu[1]; - case 10: - return mmu[2]; - case 20: - return mmu[3]; - case 50: - return mmu[4]; - case 100: - return mmu[5]; - default: - return 0.0d; - } + return switch (percentage) { + case 2 -> mmu[0]; + case 5 -> mmu[1]; + case 10 -> mmu[2]; + case 20 -> mmu[3]; + case 50 -> mmu[4]; + case 100 -> mmu[5]; + default -> 0.0d; + }; } public void setConcurrentRemapRoots(DateTimeStamp remapRootsStart, double remapRootsDuration) { diff --git a/api/src/main/java/com/microsoft/gctoolkit/event/zgc/ZGCConcurrentPhases.java b/api/src/main/java/com/microsoft/gctoolkit/event/zgc/ZGCConcurrentPhases.java index cf208a00..4a78e598 100644 --- a/api/src/main/java/com/microsoft/gctoolkit/event/zgc/ZGCConcurrentPhases.java +++ b/api/src/main/java/com/microsoft/gctoolkit/event/zgc/ZGCConcurrentPhases.java @@ -21,6 +21,7 @@ public static ZGCConcurrentPhases fromLabel(String label) { return LabelledGCEventType.fromLabel(ZGCConcurrentPhases.class, label); } + @Override public String getLabel() { return label; } diff --git a/api/src/main/java/com/microsoft/gctoolkit/event/zgc/ZGCCycleType.java b/api/src/main/java/com/microsoft/gctoolkit/event/zgc/ZGCCycleType.java index 945e8d6a..cdfd7de3 100644 --- a/api/src/main/java/com/microsoft/gctoolkit/event/zgc/ZGCCycleType.java +++ b/api/src/main/java/com/microsoft/gctoolkit/event/zgc/ZGCCycleType.java @@ -29,7 +29,7 @@ public static ZGCCycleType fromPhase(ZGCPhase phase){ } else if (phase == ZGCPhase.MINOR_YOUNG){ return ZGCCycleType.MINOR; } else { - throw new IllegalArgumentException(String.format("Unknown ZGCPhase: %s", phase)); + throw new IllegalArgumentException("Unknown ZGCPhase: %s".formatted(phase)); } } } diff --git a/api/src/main/java/com/microsoft/gctoolkit/event/zgc/ZGCPauseTypes.java b/api/src/main/java/com/microsoft/gctoolkit/event/zgc/ZGCPauseTypes.java index c1ad24b8..6040af20 100644 --- a/api/src/main/java/com/microsoft/gctoolkit/event/zgc/ZGCPauseTypes.java +++ b/api/src/main/java/com/microsoft/gctoolkit/event/zgc/ZGCPauseTypes.java @@ -20,6 +20,7 @@ public static ZGCPauseTypes fromLabel(String label) { return LabelledGCEventType.fromLabel(ZGCPauseTypes.class, label); } + @Override public String getLabel() { return label; } diff --git a/api/src/main/java/com/microsoft/gctoolkit/event/zgc/ZGCReclaimedSummary.java b/api/src/main/java/com/microsoft/gctoolkit/event/zgc/ZGCReclaimedSummary.java index 3e8462c7..a7a5008f 100644 --- a/api/src/main/java/com/microsoft/gctoolkit/event/zgc/ZGCReclaimedSummary.java +++ b/api/src/main/java/com/microsoft/gctoolkit/event/zgc/ZGCReclaimedSummary.java @@ -2,6 +2,8 @@ // Licensed under the MIT License. package com.microsoft.gctoolkit.event.zgc; +import org.jspecify.annotations.Nullable; + public class ZGCReclaimedSummary { private final long relocateStart; @@ -20,7 +22,7 @@ public long getRelocateEnd() { return relocateEnd; } - public ZGCReclaimedSummary sum(ZGCReclaimedSummary other) { + public ZGCReclaimedSummary sum(@Nullable ZGCReclaimedSummary other) { if (other == null) { return this; } diff --git a/api/src/main/java/com/microsoft/gctoolkit/event/zgc/ZGCUsedSummary.java b/api/src/main/java/com/microsoft/gctoolkit/event/zgc/ZGCUsedSummary.java index 52de2d97..6c730836 100644 --- a/api/src/main/java/com/microsoft/gctoolkit/event/zgc/ZGCUsedSummary.java +++ b/api/src/main/java/com/microsoft/gctoolkit/event/zgc/ZGCUsedSummary.java @@ -2,6 +2,8 @@ // Licensed under the MIT License. package com.microsoft.gctoolkit.event.zgc; +import org.jspecify.annotations.Nullable; + public class ZGCUsedSummary { private final long markStart; private final long markEnd; @@ -31,7 +33,7 @@ public long getMarkStart() { return markStart; } - public ZGCUsedSummary sum(ZGCUsedSummary other) { + public ZGCUsedSummary sum(@Nullable ZGCUsedSummary other) { if (other == null) { return this; } diff --git a/api/src/main/java/com/microsoft/gctoolkit/io/DataSource.java b/api/src/main/java/com/microsoft/gctoolkit/io/DataSource.java index de193bc9..2ec9a659 100644 --- a/api/src/main/java/com/microsoft/gctoolkit/io/DataSource.java +++ b/api/src/main/java/com/microsoft/gctoolkit/io/DataSource.java @@ -7,30 +7,22 @@ import java.io.IOException; import java.util.stream.Stream; -/** - * A source of data which may be streamed. - * @param The type of data returned in the stream. - */ +/// A source of data which may be streamed. +/// @param T The type of data returned in the stream. public interface DataSource { - /** - * Return meta data for the data source - * @return diary contains log file metadata - * @throws IOException if there is an issue generating the diary - */ + /// Return meta data for the data source + /// @return diary contains log file metadata + /// @throws IOException if there is an issue generating the diary Diary diary() throws IOException; - /** - * Return a stream of the data. - * @return A stream of the data. - * @throws IOException Thrown if the data cannot be streamed, - * or an IOException is raised while streaming. - */ + /// Return a stream of the data. + /// @return A stream of the data. + /// @throws IOException Thrown if the data cannot be streamed, + /// or an IOException is raised while streaming. Stream stream() throws IOException; - /** - * Return a sentinel value marking the end of the data. - * @return A value used as a sentinel to mark the end of data. - */ + /// Return a sentinel value marking the end of the data. + /// @return A value used as a sentinel to mark the end of data. T endOfData(); } diff --git a/api/src/main/java/com/microsoft/gctoolkit/io/FileDataSource.java b/api/src/main/java/com/microsoft/gctoolkit/io/FileDataSource.java index 044490df..74a38832 100644 --- a/api/src/main/java/com/microsoft/gctoolkit/io/FileDataSource.java +++ b/api/src/main/java/com/microsoft/gctoolkit/io/FileDataSource.java @@ -7,48 +7,37 @@ import java.io.IOException; import java.nio.file.Path; -/** - * A DataSource rooted in a file system. - * @param The type of data returned from the DataSource - */ +/// A DataSource rooted in a file system. +/// @param T The type of data returned from the DataSource public abstract class FileDataSource implements DataSource { protected final Path path; - /** - * Subclass only. - * @param path The path to the file in the file system. - */ + /// Subclass only. + /// @param path The path to the file in the file system. protected FileDataSource(Path path) { this.path = path; } - /** - * The Diary contains a summary of important properties of the log that will be used in orchestrating the - * setup and configuration of the internal components of GCToolkit. - * @return a diary. - */ + /// The Diary contains a summary of important properties of the log that will be used in orchestrating the + /// setup and configuration of the internal components of GCToolkit. + /// @return a diary. + @Override abstract public Diary diary() throws IOException; - /** - * Return the path to the file in the file system. - * @return The path to the file in the file system. - */ + /// Return the path to the file in the file system. + /// @return The path to the file in the file system. public Path getPath() { return path; } - /** - * Return meta data about the file. - * @return Meta data about the file. - * @throws IOException when there is an issue generating the diary - */ + /// Return meta data about the file. + /// @return Meta data about the file. + /// @throws IOException when there is an issue generating the diary public abstract LogFileMetadata getMetaData() throws IOException; - /** - * {@inheritDoc} - * @return Returns {@code this.getPath().toString();} - */ + /// {@inheritDoc} + /// @return Returns `this.getPath().toString();` @Override public String toString() { return path.toString(); diff --git a/api/src/main/java/com/microsoft/gctoolkit/io/GCLogFile.java b/api/src/main/java/com/microsoft/gctoolkit/io/GCLogFile.java index cf0e7e63..1ca4e921 100644 --- a/api/src/main/java/com/microsoft/gctoolkit/io/GCLogFile.java +++ b/api/src/main/java/com/microsoft/gctoolkit/io/GCLogFile.java @@ -14,7 +14,6 @@ import java.nio.file.Path; import java.util.Objects; import java.util.ServiceConfigurationError; -import java.util.ServiceLoader; import java.util.logging.Level; import java.util.logging.Logger; import java.util.regex.Matcher; @@ -25,44 +24,34 @@ import static java.util.ServiceLoader.load; -/** - * Represents a GC log file, which may be a {@link SingleGCLogFile} or a {@link RotatingGCLogFile}. - */ +/// Represents a GC log file, which may be a [SingleGCLogFile] or a [RotatingGCLogFile]. public abstract class GCLogFile extends FileDataSource { private static final Logger LOGGER = Logger.getLogger(FileDataSource.class.getName()); - /** - * The value used for the implementation of {@link #endOfData()}. - */ + /// The value used for the implementation of [#endOfData()]. public static final String END_OF_DATA_SENTINEL = "END_OF_DATA_SENTINEL"; private Diary diary; private TripleState unifiedFormat = TripleState.UNKNOWN; private JavaVirtualMachine jvm = null; - /** - * Subclass only. - * @param path The path to the GCLogFile or, in the case of rotating log files, the parent directory. - */ + /// Subclass only. + /// @param path The path to the GCLogFile or, in the case of rotating log files, the parent directory. protected GCLogFile(Path path) { super(path); } - /** - * Return the relevant JavaVirtualMachine implementation - */ + /// Return the relevant JavaVirtualMachine implementation public JavaVirtualMachine getJavaVirtualMachine() { if ( jvm == null) - jvm = (isUnified()) ? new UnifiedJavaVirtualMachine() : new PreUnifiedJavaVirtualMachine(); + jvm = isUnified() ? new UnifiedJavaVirtualMachine() : new PreUnifiedJavaVirtualMachine(); jvm.accepts(this); return jvm; } - /** - * Returns {@code true} if this GCLogFile is written in unified logging (JEP 158) format. - * @return {@code true} if the log file is in unified logging format. - */ + /// Returns `true` if this GCLogFile is written in unified logging (JEP 158) format. + /// @return `true` if the log file is in unified logging format. public boolean isUnified() { if ( ! unifiedFormat.isKnown()) unifiedFormat = discoverFormat(); @@ -70,7 +59,7 @@ public boolean isUnified() { } private Diarizer diarizer() { - ServiceLoader serviceLoader = load(Diarizer.class); + var serviceLoader = load(Diarizer.class); if (serviceLoader.findFirst().isPresent()) { return serviceLoader .stream() @@ -80,19 +69,17 @@ private Diarizer diarizer() { .orElseThrow(() -> new ServiceConfigurationError("Unable to find a suitable provider to create a diary")); } else { try { - String clazzName = (isUnified()) ? "com.microsoft.gctoolkit.parser.jvm.UnifiedDiarizer" : "com.microsoft.gctoolkit.parser.jvm.PreUnifiedDiarizer"; + String clazzName = isUnified() ? "com.microsoft.gctoolkit.parser.jvm.UnifiedDiarizer" : "com.microsoft.gctoolkit.parser.jvm.PreUnifiedDiarizer"; Class clazz = Class.forName(clazzName, true, Thread.currentThread().getContextClassLoader()); return (Diarizer) clazz.getConstructors()[0].newInstance(); - } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | InvocationTargetException e) { + } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | InvocationTargetException _) { throw new ServiceConfigurationError("Unable to find a suitable provider to create a diary"); } } } - /** - * - * @return the computed diary - */ + /// @return the computed diary + @Override public Diary diary() throws IOException { if ( diary == null) { Diarizer diarizer = diarizer(); @@ -119,16 +106,14 @@ public final String endOfData() { private static final Pattern LINE_STARTS_WITH_DECORATOR = Pattern.compile("^\\[\\d.+?\\]"); private static final int SHOULD_HAVE_SEEN_A_UNIFIED_DECORATOR_BY_THIS_LINE_IN_THE_LOG = 25; - /** - * This method is used to determine whether or not the log file uses the unified log format - * by looking for lines starting with the unified logging decorator. This method is called from - * the constructors of the subclasses. - * @return {@code true} if the file uses the unified log format. - * @throws IOException Thrown from reading the stream. - */ + /// This method is used to determine whether or not the log file uses the unified log format + /// by looking for lines starting with the unified logging decorator. This method is called from + /// the constructors of the subclasses. + /// @return `true` if the file uses the unified log format. + /// @throws IOException Thrown from reading the stream. private TripleState discoverFormat() { try (Stream stream = stream()) { // contribution from MansuyDavid @github - boolean isUnified = firstNLines(stream, SHOULD_HAVE_SEEN_A_UNIFIED_DECORATOR_BY_THIS_LINE_IN_THE_LOG) + var isUnified = firstNLines(stream, SHOULD_HAVE_SEEN_A_UNIFIED_DECORATOR_BY_THIS_LINE_IN_THE_LOG) .map(LINE_STARTS_WITH_DECORATOR::matcher) .anyMatch(Matcher::find); return TripleState.valueOf(isUnified); diff --git a/api/src/main/java/com/microsoft/gctoolkit/io/GCLogFileSegment.java b/api/src/main/java/com/microsoft/gctoolkit/io/GCLogFileSegment.java index b52f6cbb..a91eb604 100644 --- a/api/src/main/java/com/microsoft/gctoolkit/io/GCLogFileSegment.java +++ b/api/src/main/java/com/microsoft/gctoolkit/io/GCLogFileSegment.java @@ -3,6 +3,7 @@ package com.microsoft.gctoolkit.io; import com.microsoft.gctoolkit.time.DateTimeStamp; +import org.jspecify.annotations.Nullable; import java.io.IOException; import java.io.RandomAccessFile; @@ -10,16 +11,15 @@ import java.nio.file.Path; import java.util.ArrayList; import java.util.Comparator; +import java.util.List; import java.util.regex.Matcher; import java.util.stream.Stream; -/** - * A {@link RotatingGCLogFile} is made up of {@code GarbageCollectionLogFileSegment}s. Creating - * a {@code GarbageCollectionLogFileSegment} is not necessary when the - * {@link RotatingGCLogFile#RotatingGCLogFile(Path)} constructor is used. - * The { @ link RotatingGCLogFile # RotatingGCLogFile(Path, List) } constructor allows the user to - * provide a list of discrete {@code GarbageCollectionLogFileSegement}s for a {@code RotatingGCLogFile}. - */ +/// A [RotatingGCLogFile] is made up of `GarbageCollectionLogFileSegment`s. Creating +/// a `GarbageCollectionLogFileSegment` is not necessary when the +/// [RotatingGCLogFile#RotatingGCLogFile(Path)] constructor is used. +/// The { @ link RotatingGCLogFile # RotatingGCLogFile(Path, List) } constructor allows the user to +/// provide a list of discrete `GarbageCollectionLogFileSegement`s for a `RotatingGCLogFile`. public class GCLogFileSegment implements LogFileSegment { private final Path path; @@ -28,10 +28,8 @@ public class GCLogFileSegment implements LogFileSegment { private DateTimeStamp endTime = null; private DateTimeStamp startTime = null; - /** - * The constructor attempts to extract the segment index from the file name. - * @param path The path to the file. - */ + /// The constructor attempts to extract the segment index from the file name. + /// @param path The path to the file. public GCLogFileSegment(Path path) { this.path = path; @@ -47,70 +45,63 @@ public GCLogFileSegment(Path path) { } } - /** - * Return the path to the file. - * @return The path to the file. - */ + /// Return the path to the file. + /// @return The path to the file. + @Override public Path getPath() { return path; } + @Override public String getSegmentName() { return getPath().toFile().getName(); } - /** - * return some comparable value for the first time found in the log. - * If isn't found, then return min value. This combined with the end - * time being a max value implies the log covers an impossible amount - * of time. The sorting logic in the Metadata classes should filter - * out these types of segments. - * @return double representing either the age of the JVM or time - * from epoch if only a date stamp is found at the beginning of the log file - */ + /// return some comparable value for the first time found in the log. + /// If isn't found, then return min value. This combined with the end + /// time being a max value implies the log covers an impossible amount + /// of time. The sorting logic in the Metadata classes should filter + /// out these types of segments. + /// @return double representing either the age of the JVM or time + /// from epoch if only a date stamp is found at the beginning of the log file @Override public double getStartTime() { try { ageOfJVMAtLogStart(); return startTime.getTimeStamp(); - } catch (NullPointerException ex) { + } catch (NullPointerException _) { return Double.MAX_VALUE; } } - /** - * return some comparable value for the last time found in the log. - * If isn't found, then return max value. This combined with the start - * time implies the log covers an impossible amount of time. The - * sorting logic in the Metadata classes should filter out these - * types of segments. - * @return double representing either the age of the JVM or time - * from epoch if only a date stamp is found at the end of the log file - */ + /// return some comparable value for the last time found in the log. + /// If isn't found, then return max value. This combined with the start + /// time implies the log covers an impossible amount of time. The + /// sorting logic in the Metadata classes should filter out these + /// types of segments. + /// @return double representing either the age of the JVM or time + /// from epoch if only a date stamp is found at the end of the log file @Override public double getEndTime() { try { ageOfJVMAtLogEnd(); return endTime.getTimeStamp(); - } catch (NullPointerException|IOException ex) { + } catch (NullPointerException|IOException _) { return Double.MIN_VALUE; } } - /** - * The segment index is the integer appended to the file name. If the file name does not - * have a segment index, then {@code Integer.MAX_VALUE} is returned. - * @return The segment index, or {@code Integer.MAX_VALUE} if the file does not have a segment index. - */ + /// The segment index is the integer appended to the file name. If the file name does not + /// have a segment index, then `Integer.MAX_VALUE` is returned. + /// @return The segment index, or `Integer.MAX_VALUE` if the file does not have a segment index. public int getSegmentIndex() { return segmentIndex; } - /** - * Stream the file, one line at a time. - * @return A stream of lines from the file. - */ - public Stream stream() { + /// Stream the file, one line at a time. + /// @return A stream of lines from the file. + @Override + public @Nullable Stream stream() { try { return Files.lines(path); } catch (IOException e) { @@ -119,10 +110,8 @@ public Stream stream() { return null; } - /** - * Return {@code true} if the log file segment was the file being written to. - * @return {@code true} if the log file segment was the current file. - */ + /// Return `true` if the log file segment was the file being written to. + /// @return `true` if the log file segment was the current file. public boolean isCurrent() { return current; } @@ -149,10 +138,8 @@ private DateTimeStamp ageOfJVMAtLogEnd() throws IOException { return endTime; } - /** - * {@inheritDoc} - * @return Returns {@code this.getName(); } - */ + /// {@inheritDoc} + /// @return Returns `this.getName(); ` @Override public String toString() { return getSegmentName(); @@ -163,19 +150,19 @@ public String toString() { // https://codereview.stackexchange.com/questions/79039/get-the-tail-of-a-file-the-last-10-lines // Tail is not a class, it's a method so the solution in stackoverflow isn't correct but the core // could be used here as it's cleaner - private ArrayList tail(int numberOfLines) throws IOException { + private List tail(int numberOfLines) throws IOException { - char LF = '\n'; - char CR = '\r'; - boolean foundEOL = false; - char eol = 0; - RandomAccessFile randomAccessFile = new RandomAccessFile(path.toFile(), "r"); - long currentPosition = randomAccessFile.length() - 1; - int linesFound = 0; + var LF = '\n'; + var CR = '\r'; + var foundEOL = false; + var eol = 0; + var randomAccessFile = new RandomAccessFile(path.toFile(), "r"); + var currentPosition = randomAccessFile.length() - 1; + var linesFound = 0; while (currentPosition > 0 && !foundEOL) { randomAccessFile.seek(currentPosition); - char character = (char) randomAccessFile.readByte(); + var character = (char) randomAccessFile.readByte(); if (character == LF) { eol = LF; randomAccessFile.seek(currentPosition - 1); @@ -194,12 +181,12 @@ private ArrayList tail(int numberOfLines) throws IOException { while (currentPosition > 0 && linesFound < numberOfLines) { randomAccessFile.seek(--currentPosition); - char character = (char) randomAccessFile.readByte(); + var character = (char) randomAccessFile.readByte(); if (eol == character) linesFound++; } - ArrayList lines = new ArrayList<>(); + var lines = new ArrayList(); if (linesFound > 0) { String line; while ((line = randomAccessFile.readLine()) != null) { diff --git a/api/src/main/java/com/microsoft/gctoolkit/io/GCLogFileZipSegment.java b/api/src/main/java/com/microsoft/gctoolkit/io/GCLogFileZipSegment.java index 8ffd0c09..ba50286b 100644 --- a/api/src/main/java/com/microsoft/gctoolkit/io/GCLogFileZipSegment.java +++ b/api/src/main/java/com/microsoft/gctoolkit/io/GCLogFileZipSegment.java @@ -18,13 +18,11 @@ import java.util.zip.ZipEntry; import java.util.zip.ZipFile; -/** - * A {@link RotatingGCLogFile} is made up of {@code GarbageCollectionLogFileSegment}s. Creating - * a {@code GarbageCollectionLogFileSegment} is not necessary when the - * {@link RotatingGCLogFile#RotatingGCLogFile(Path)} constructor is used. - * The {@link RotatingGCLogFile#RotatingGCLogFile(Path)} constructor allows the user to - * provide a list of discrete {@code GarbageCollectionLogFileSegement}s for a {@code RotatingGCLogFile}. - */ +/// A [RotatingGCLogFile] is made up of `GarbageCollectionLogFileSegment`s. Creating +/// a `GarbageCollectionLogFileSegment` is not necessary when the +/// [RotatingGCLogFile#RotatingGCLogFile(Path)] constructor is used. +/// The [RotatingGCLogFile#RotatingGCLogFile(Path)] constructor allows the user to +/// provide a list of discrete `GarbageCollectionLogFileSegement`s for a `RotatingGCLogFile`. public class GCLogFileZipSegment implements LogFileSegment { private final Path path; @@ -32,24 +30,22 @@ public class GCLogFileZipSegment implements LogFileSegment { private DateTimeStamp endTime = null; private DateTimeStamp startTime = null; - /** - * The constructor attempts to extract the segment index from the file name. - * @param path The path to the file. - * @param segmentName name of first segment in zip file - */ + /// The constructor attempts to extract the segment index from the file name. + /// @param path The path to the file. + /// @param segmentName name of first segment in zip file public GCLogFileZipSegment(Path path, String segmentName) { this.path = path; this.segmentName = segmentName; } - /** - * Return the path to the file. - * @return The path to the file. - */ + /// Return the path to the file. + /// @return The path to the file. + @Override public Path getPath() { return path; } + @Override public String getSegmentName() { return this.segmentName; } @@ -67,7 +63,7 @@ private void ageOfJVMAtLogStart() { private DateTimeStamp ageOfJVMAtLogEnd() { if (endTime == null) { - List tail = stream(). + var tail = stream(). collect(tail(100)); endTime = tail.stream() .filter(line -> ! line.contains("Saved as")) @@ -102,7 +98,7 @@ else if ( startTime.hasDateStamp()) return startTime.toEpochInMillis(); else return Double.MAX_VALUE; - } catch (NullPointerException ex) { + } catch (NullPointerException _) { return Double.MIN_VALUE; } } @@ -117,18 +113,17 @@ else if ( endTime.hasDateStamp()) return endTime.toEpochInMillis(); else return Double.MAX_VALUE; - } catch (NullPointerException ex) { + } catch (NullPointerException _) { return Double.MIN_VALUE; } } - /** - * Stream the file, one line at a time. - * @return A stream of lines from the file. - */ + /// Stream the file, one line at a time. + /// @return A stream of lines from the file. + @Override public Stream stream() { try { - ZipFile file = new ZipFile(path.toFile()); + var file = new ZipFile(path.toFile()); ZipEntry entry = file.getEntry(this.segmentName); return new BufferedReader(new InputStreamReader(file.getInputStream(entry))).lines(); } catch (IOException e) { @@ -137,10 +132,8 @@ public Stream stream() { return new ArrayList().stream(); } - /** - * {@inheritDoc} - * @return Returns {@code this.getPath().toString(); } - */ + /// {@inheritDoc} + /// @return Returns `this.getPath().toString(); ` @Override public String toString() { return getSegmentName(); diff --git a/api/src/main/java/com/microsoft/gctoolkit/io/LogFileMetadata.java b/api/src/main/java/com/microsoft/gctoolkit/io/LogFileMetadata.java index 97c4bba7..5c63af63 100644 --- a/api/src/main/java/com/microsoft/gctoolkit/io/LogFileMetadata.java +++ b/api/src/main/java/com/microsoft/gctoolkit/io/LogFileMetadata.java @@ -8,9 +8,7 @@ import java.util.logging.Logger; import java.util.stream.Stream; -/** - * Meta-data about a {@link FileDataSource}. - */ +/// Meta-data about a [FileDataSource]. public abstract class LogFileMetadata { private static final Logger LOG = Logger.getLogger(LogFileMetadata.class.getName()); @@ -34,9 +32,9 @@ public Path getPath() { } boolean magic(int field1, int field2) { - try (FileInputStream magicByteReader = new FileInputStream(path.toFile())) { - int magicByte1 = magicByteReader.read(); - int magicByte2 = magicByteReader.read(); + try (var magicByteReader = new FileInputStream(path.toFile())) { + var magicByte1 = magicByteReader.read(); + var magicByte2 = magicByteReader.read(); return magicByte1 == field1 && magicByte2 == field2; } catch (IOException ioe) { LOG.warning(ioe.getMessage()); @@ -57,41 +55,31 @@ else if ( magic(ZIP_MAGIC1, ZIP_MAGIC2)) fileFormat = FileFormat.PLAINTEXT; } - /** - * Return the number of files. Useful if the file is a compressed file which may - * contain multiple entries. - * @return The number of files in the file. - */ + /// Return the number of files. Useful if the file is a compressed file which may + /// contain multiple entries. + /// @return The number of files in the file. public abstract int getNumberOfFiles(); - /** - * {@code true} if the file is a Zip compressed file. - * @return {@code true} if the file is a Zip compressed file. - */ + /// `true` if the file is a Zip compressed file. + /// @return `true` if the file is a Zip compressed file. public boolean isZip() { return fileFormat == FileFormat.ZIP; } - /** - * {@code true} if the file is a GZip compressed file. - * @return {@code true} if the file is a GZip compressed file. - */ + /// `true` if the file is a GZip compressed file. + /// @return `true` if the file is a GZip compressed file. public boolean isGZip() { return fileFormat == FileFormat.GZIP; } - /** - * {@code true} if the file is a regular file. - * @return {@code true} if the file is a regular file. - */ + /// `true` if the file is a regular file. + /// @return `true` if the file is a regular file. public boolean isPlainText() { return fileFormat == FileFormat.PLAINTEXT; } - /** - * {@code true} if the file is a directory. - * @return {@code true} if the file is a directory. - */ + /// `true` if the file is a directory. + /// @return `true` if the file is a directory. public boolean isDirectory() { return fileFormat == FileFormat.DIRECTORY; } diff --git a/api/src/main/java/com/microsoft/gctoolkit/io/RotatingGCLogFile.java b/api/src/main/java/com/microsoft/gctoolkit/io/RotatingGCLogFile.java index 6155cd1f..e23fe24e 100644 --- a/api/src/main/java/com/microsoft/gctoolkit/io/RotatingGCLogFile.java +++ b/api/src/main/java/com/microsoft/gctoolkit/io/RotatingGCLogFile.java @@ -17,28 +17,24 @@ import java.util.logging.Logger; import java.util.stream.Collectors; import java.util.stream.Stream; -import java.util.zip.ZipEntry; import java.util.zip.ZipFile; -/** - * A collection of rotating GC log files. The collection will contain only those files that can be - * considered contiguous. The log file segments are ordered, with the current or newest file first. - */ +/// A collection of rotating GC log files. The collection will contain only those files that can be +/// considered contiguous. The log file segments are ordered, with the current or newest file first. public class RotatingGCLogFile extends GCLogFile { private static final Logger LOGGER = Logger.getLogger(RotatingGCLogFile.class.getName()); - /** - * Use the given path to find rotating log files. If the path is a file, the file name is used to match - * other files in the directory. If the path is a directory, all files in the directory are considered. - * @param path the path to a rotating log file, or to a directory containing rotating log files. - */ + /// Use the given path to find rotating log files. If the path is a file, the file name is used to match + /// other files in the directory. If the path is a directory, all files in the directory are considered. + /// @param path the path to a rotating log file, or to a directory containing rotating log files. public RotatingGCLogFile(Path path) { super(path); } private RotatingLogFileMetadata metaData; + @Override public LogFileMetadata getMetaData() throws IOException { if ( metaData == null) metaData = new RotatingLogFileMetadata(getPath()); @@ -70,8 +66,8 @@ private Stream stream(LogFileMetadata metadata, LinkedList copySegments = new LinkedList<>(segments); - Stream allSegments = Stream.concat(copySegments.removeFirst().stream(), copySegments.removeFirst().stream()); + var copySegments = new LinkedList(segments); + var allSegments = Stream.concat(copySegments.removeFirst().stream(), copySegments.removeFirst().stream()); while (!copySegments.isEmpty()) allSegments = Stream.concat(allSegments, copySegments.removeFirst().stream()); return allSegments; @@ -86,9 +82,9 @@ private Stream stream(LogFileMetadata metadata, LinkedList streamZipFile() throws IOException { - ZipFile zipFile = new ZipFile(path.toFile()); - List entries = zipFile.stream().filter(entry -> !entry.isDirectory()).collect(Collectors.toList()); - Vector streams = new Vector<>(); + var zipFile = new ZipFile(path.toFile()); + var entries = zipFile.stream().filter(entry -> !entry.isDirectory()).collect(Collectors.toList()); + var streams = new Vector(); try { entries @@ -106,18 +102,16 @@ private Stream streamZipFile() throws IOException { throw uioe.getCause(); } - SequenceInputStream sequenceInputStream = new SequenceInputStream(streams.elements()); + var sequenceInputStream = new SequenceInputStream(streams.elements()); return new BufferedReader(new InputStreamReader(sequenceInputStream)).lines(); } - /** - * The {@link GCLogFileSegment}s in rotating order. Note that only the contiguous - * log file segments are included. Therefore, the number of log file segments may be less than - * the files that match the rotating pattern. - * @return The log file segments in rotating order. - * @throws IOException when there is an IO exception - */ + /// The [GCLogFileSegment]s in rotating order. Note that only the contiguous + /// log file segments are included. Therefore, the number of log file segments may be less than + /// the files that match the rotating pattern. + /// @return The log file segments in rotating order. + /// @throws IOException when there is an IO exception public List getOrderedGarbageCollectionLogFiles() throws IOException { return getMetaData().logFiles().collect(Collectors.toList()); } diff --git a/api/src/main/java/com/microsoft/gctoolkit/io/RotatingLogFileMetadata.java b/api/src/main/java/com/microsoft/gctoolkit/io/RotatingLogFileMetadata.java index d5215160..c9c61d93 100644 --- a/api/src/main/java/com/microsoft/gctoolkit/io/RotatingLogFileMetadata.java +++ b/api/src/main/java/com/microsoft/gctoolkit/io/RotatingLogFileMetadata.java @@ -17,9 +17,7 @@ import static java.util.stream.Collectors.toList; -/** - * Meta-data about a {@link FileDataSource}. - */ +/// Meta-data about a [FileDataSource]. public class RotatingLogFileMetadata extends LogFileMetadata { private static final Logger LOG = Logger.getLogger(RotatingLogFileMetadata.class.getName()); @@ -30,6 +28,7 @@ public RotatingLogFileMetadata(Path path) throws IOException { super(path); } + @Override public Stream logFiles() { if ( segments == null) { if ( isPlainText() || isDirectory()) @@ -57,11 +56,10 @@ private void findZIPSegments() { orderSegments(); } - /** - * Return the number of files. Useful if the file is a compressed file which may - * contain multiple entries. - * @return The number of files in the file. - */ + /// Return the number of files. Useful if the file is a compressed file which may + /// contain multiple entries. + /// @return The number of files in the file. + @Override public int getNumberOfFiles() { if ( this.segments == null) if ( isZip()) @@ -71,21 +69,19 @@ public int getNumberOfFiles() { return this.segments.size(); } - /** - * Root for the pattern for the file currently being written to... has - * a . suffix for unified - * a .current suffix for pre-unified. - * - * The possible parameters here along with the actions - * 1) directory - * 2) the file currently being written to - * 3) a file not currently being written to. - * - * In all cases we want to find the file currently being written to and - * use that to reverse engineer the root. - * - * @return String representing the pattern for the root of the rotating log name - */ + /// Root for the pattern for the file currently being written to... has + /// a . suffix for unified + /// a .current suffix for pre-unified. + /// + /// The possible parameters here along with the actions + /// 1) directory + /// 2) the file currently being written to + /// 3) a file not currently being written to. + /// + /// In all cases we want to find the file currently being written to and + /// use that to reverse engineer the root. + /// + /// @return String representing the pattern for the root of the rotating log name private String getRootPattern() { // at this point we only have the path, not a segment... it maybe that we have to save the chosen segment @@ -99,12 +95,12 @@ private String getRootPattern() { .get() .getSegmentName().split("\\."); } else if ( isZip()) { - bits = segments.get(0).getSegmentName().split("\\."); + bits = segments.getFirst().getSegmentName().split("\\."); } else { bits = getPath().getFileName().toString().split("\\."); } - int baseLength = 0; + var baseLength = 0; if ( "current".equals(bits[bits.length - 1])) baseLength = bits.length - 2; else if ( bits[bits.length - 1].matches("\\d+$")) @@ -112,8 +108,8 @@ else if ( bits[bits.length - 1].matches("\\d+$")) else baseLength = bits.length; - StringBuilder base = new StringBuilder(bits[0]); - for ( int i = 1; i < baseLength; i++) + var base = new StringBuilder(bits[0]); + for ( var i = 1; i < baseLength; i++) base.append(".").append(bits[i]); return base.toString(); } @@ -127,7 +123,7 @@ private void findSegments() { else { Files.list(getPath().getParent()) .filter(file -> file.getFileName().toString().startsWith(getRootPattern())) - .map(p -> new GCLogFileSegment(p)).forEach(segments::add); + .map(GCLogFileSegment::new).forEach(segments::add); } } catch (IOException ioe) { LOG.log(Level.WARNING,"Unable to find log segments.", ioe); @@ -139,7 +135,7 @@ private void orderSegments() { if (segments.size() < 2) return; - LinkedList orderedList = new LinkedList<>(); + var orderedList = new LinkedList(); List workingList = new ArrayList<>(); workingList.addAll(segments); diff --git a/api/src/main/java/com/microsoft/gctoolkit/io/SingleGCLogFile.java b/api/src/main/java/com/microsoft/gctoolkit/io/SingleGCLogFile.java index b3020b33..77e88486 100644 --- a/api/src/main/java/com/microsoft/gctoolkit/io/SingleGCLogFile.java +++ b/api/src/main/java/com/microsoft/gctoolkit/io/SingleGCLogFile.java @@ -15,18 +15,14 @@ import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; -/** - * A single GC log file. If the file is a zip or gzip file, - * then the first entry is the file of interest. - */ +/// A single GC log file. If the file is a zip or gzip file, +/// then the first entry is the file of interest. public class SingleGCLogFile extends GCLogFile { private static final Logger LOGGER = Logger.getLogger(SingleGCLogFile.class.getName()); - /** - * Constructor for a single, GC log file. - * @param path The path to the log file. - */ + /// Constructor for a single, GC log file. + /// @param path The path to the log file. private SingleLogFileMetadata metadata = null; @@ -68,7 +64,7 @@ private Stream stream(LogFileMetadata metadata) throws IOException { } private static Stream streamZipFile(Path path) throws IOException { - ZipInputStream zipStream = new ZipInputStream(Files.newInputStream(path)); + var zipStream = new ZipInputStream(Files.newInputStream(path)); ZipEntry entry; do { entry = zipStream.getNextEntry(); @@ -77,7 +73,7 @@ private static Stream streamZipFile(Path path) throws IOException { } private static Stream streamGZipFile(Path path) throws IOException { - GZIPInputStream gzipStream = new GZIPInputStream(Files.newInputStream(path)); + var gzipStream = new GZIPInputStream(Files.newInputStream(path)); return new BufferedReader(new InputStreamReader(new BufferedInputStream(gzipStream))).lines(); } diff --git a/api/src/main/java/com/microsoft/gctoolkit/io/SingleLogFileMetadata.java b/api/src/main/java/com/microsoft/gctoolkit/io/SingleLogFileMetadata.java index 7f65cfd6..f653ae13 100644 --- a/api/src/main/java/com/microsoft/gctoolkit/io/SingleLogFileMetadata.java +++ b/api/src/main/java/com/microsoft/gctoolkit/io/SingleLogFileMetadata.java @@ -8,9 +8,7 @@ import java.util.logging.Logger; import java.util.stream.Stream; -/** - * Meta-data about a {@link FileDataSource}. - */ +/// Meta-data about a [FileDataSource]. public class SingleLogFileMetadata extends LogFileMetadata { private static final Logger LOG = Logger.getLogger(SingleLogFileMetadata.class.getName()); @@ -22,12 +20,14 @@ public SingleLogFileMetadata(Path path) throws IOException { this.logFile = new GCLogFileSegment(path); } + @Override public Stream logFiles() { return List.of(logFile).stream(); } + @Override public int getNumberOfFiles() { - return ( logFile != null) ? 1 : 0; + return logFile != null ? 1 : 0; } } diff --git a/api/src/main/java/com/microsoft/gctoolkit/jvm/AbstractJavaVirtualMachine.java b/api/src/main/java/com/microsoft/gctoolkit/jvm/AbstractJavaVirtualMachine.java index bd7db30f..30901f2e 100644 --- a/api/src/main/java/com/microsoft/gctoolkit/jvm/AbstractJavaVirtualMachine.java +++ b/api/src/main/java/com/microsoft/gctoolkit/jvm/AbstractJavaVirtualMachine.java @@ -24,10 +24,8 @@ import java.util.logging.Level; import java.util.logging.Logger; -/** - * The base implementation of JavaVirtualMachine that uses the message API to feed - * lines to the parser(s) and post events to the aggregators. - */ +/// The base implementation of JavaVirtualMachine that uses the message API to feed +/// lines to the parser(s) and post events to the aggregators. public abstract class AbstractJavaVirtualMachine implements JavaVirtualMachine { private static final Logger LOGGER = Logger.getLogger(AbstractJavaVirtualMachine.class.getName()); @@ -40,11 +38,9 @@ public abstract class AbstractJavaVirtualMachine implements JavaVirtualMachine { private double logDuration = -1.0d; private final Map, Aggregation> aggregatedData = new ConcurrentHashMap<>(); - /** - * Sets the data source - * @param logFile is the source of GC logging data - * @throws IOException if there is any issues reading from the data source. - */ + /// Sets the data source + /// @param logFile is the source of GC logging data + /// @throws IOException if there is any issues reading from the data source. public void setDataSource(DataSource logFile) throws IOException { this.dataSource = (GCLogFile) logFile; this.diary = logFile.diary(); @@ -85,19 +81,18 @@ public String getCommandLine() { return ""; //todo: extract from diary... jvmConfigurationFromParser.getCommandLine(); } + @Override public DateTimeStamp getTimeOfFirstEvent() { return diary.getTimeOfFirstEvent(); } - /** - * If the first event is significantly distant from zero in relation to the time intervals between the - * of the next N events, where N maybe 1, then this is likely a log fragment and not the start of the run. - *

- * Try to estimate the time at which the JVM started. For log fragments, this will be the time - * of the first event in the log. Otherwise it will be 0.000 seconds. - * - * @return DateTimeStamp as estimated start time. - */ + /// If the first event is significantly distant from zero in relation to the time intervals between the + /// of the next N events, where N maybe 1, then this is likely a log fragment and not the start of the run. + /// + /// Try to estimate the time at which the JVM started. For log fragments, this will be the time + /// of the first event in the log. Otherwise it will be 0.000 seconds. + /// + /// @return DateTimeStamp as estimated start time. @Override public DateTimeStamp getEstimatedJVMStartTime() { DateTimeStamp startTime = diary.getTimeOfFirstEvent(); @@ -110,20 +105,16 @@ public DateTimeStamp getEstimatedJVMStartTime() { } } - /** - * Sets the estimated start time as calculated by the Aggregation class - * @param estimatedStartTime as calculated from observations of the event timing in the gc log. - */ + /// Sets the estimated start time as calculated by the Aggregation class + /// @param estimatedStartTime as calculated from observations of the event timing in the gc log. public void setEstimatedJVMStartTime(DateTimeStamp estimatedStartTime) { this.estimatedStartTime = estimatedStartTime; } - /** - * JVM termination time will be one of either, the time stamp in the termination event if present or, the - * time of the last event + that events duration. - * - * @return DateTimeStamp - */ + /// JVM termination time will be one of either, the time stamp in the termination event if present or, the + /// time of the last event + that events duration. + /// + /// @return DateTimeStamp @Override public DateTimeStamp getJVMTerminationTime() { return timeOfLastEvent; @@ -148,21 +139,19 @@ public Optional getAggregation(Class aggregationCl return Optional.ofNullable((T) aggregatedData.get(aggregationClass)); } - /** - * Orchestrate the analysis of a GC log. Step wise - * 1. find the aggregators that aggregate events generated by the gc log - * 2. Register the aggregators with the message bus. Setup a callback so the message framework. - * 3. Stream the data to a publisher - * 4. Wait until all the aggregators have completed - * 5. Set the start and end times - * 6. Return to the caller - * @param registeredAggregators all of the aggregations loaded by the module SPI - * @param eventBus the bus to publish events on - * @param dataSourceBus the bus that raw log lines are published on - */ + /// Orchestrate the analysis of a GC log. Step wise + /// 1. find the aggregators that aggregate events generated by the gc log + /// 2. Register the aggregators with the message bus. Setup a callback so the message framework. + /// 3. Stream the data to a publisher + /// 4. Wait until all the aggregators have completed + /// 5. Set the start and end times + /// 6. Return to the caller + /// @param registeredAggregators all of the aggregations loaded by the module SPI + /// @param eventBus the bus to publish events on + /// @param dataSourceBus the bus that raw log lines are published on @Override public void analyze(List> registeredAggregators, JVMEventChannel eventBus, DataSourceChannel dataSourceBus) { - Phaser finishLine = new Phaser(); + var finishLine = new Phaser(); Set generatedEvents = diary.generatesEvents(); for (Aggregator aggregator : registeredAggregators) { Aggregation aggregation = aggregator.aggregation(); @@ -171,7 +160,7 @@ public void analyze(List> registeredAggregator GCToolKit.LOG_DEBUG_MESSAGE(() -> "Registering " + aggregator.getClass().getName() + " with " + eventSource.toChannel()); finishLine.register(); aggregator.onCompletion(finishLine::arriveAndDeregister); - JVMEventChannelAggregator eventChannelAggregator = new JVMEventChannelAggregator(eventSource.toChannel(), aggregator); + var eventChannelAggregator = new JVMEventChannelAggregator(eventSource.toChannel(), aggregator); eventBus.registerListener(eventChannelAggregator); }); } diff --git a/api/src/main/java/com/microsoft/gctoolkit/jvm/Diarizer.java b/api/src/main/java/com/microsoft/gctoolkit/jvm/Diarizer.java index 10d1c8e0..0d199e87 100644 --- a/api/src/main/java/com/microsoft/gctoolkit/jvm/Diarizer.java +++ b/api/src/main/java/com/microsoft/gctoolkit/jvm/Diarizer.java @@ -4,10 +4,8 @@ import com.microsoft.gctoolkit.time.DateTimeStamp; -/** - * Examines GC log input to infer the JVM logging format, collector configuration, - * command-line flags, and related diary information used by parsers. - */ +/// Examines GC log input to infer the JVM logging format, collector configuration, +/// command-line flags, and related diary information used by parsers. public interface Diarizer { int MAXIMUM_LINES_TO_EXAMINE = 10_000; diff --git a/api/src/main/java/com/microsoft/gctoolkit/jvm/Diary.java b/api/src/main/java/com/microsoft/gctoolkit/jvm/Diary.java index 02a5322c..046c38eb 100644 --- a/api/src/main/java/com/microsoft/gctoolkit/jvm/Diary.java +++ b/api/src/main/java/com/microsoft/gctoolkit/jvm/Diary.java @@ -54,13 +54,11 @@ GENERATIONAL_ZGC // 29 */ -/** - * Records discovered GC log feature states while a log is being diarized. - * - *

Each {@link SupportedFlags} entry is tracked as true, false, or unknown so - * parser selection and event-source discovery can defer decisions until enough - * log evidence has been observed.

- */ +/// Records discovered GC log feature states while a log is being diarized. +/// +/// Each [SupportedFlags] entry is tracked as true, false, or unknown so +/// parser selection and event-source discovery can defer decisions until enough +/// log evidence has been observed. public class Diary { private final TripleState[] states; @@ -68,7 +66,7 @@ public class Diary { public Diary() { states = new TripleState[SupportedFlags.values().length]; - for (int i = 0; i < states.length; i++) states[i] = TripleState.UNKNOWN; + for (var i = 0; i < states.length; i++) states[i] = TripleState.UNKNOWN; } public void setTrue(SupportedFlags flag) { @@ -96,7 +94,7 @@ public boolean isStateKnown(SupportedFlags flag) { } public boolean isStateKnown(SupportedFlags... flags) { - boolean value = true; + var value = true; for (SupportedFlags flag : flags) { value &= states[flag.ordinal()].isTrue(); } @@ -104,7 +102,7 @@ public boolean isStateKnown(SupportedFlags... flags) { } public void setState(SupportedFlags flag, boolean flagTurnedOn) { - if ((flagTurnedOn)) { + if (flagTurnedOn) { setTrue(flag); } else { setFalse(flag); @@ -117,8 +115,8 @@ public boolean isTrue(SupportedFlags flag) { @Override public String toString() { - StringBuilder buffer = new StringBuilder("LoggingDiary{"); - boolean first = true; + var buffer = new StringBuilder("LoggingDiary{"); + var first = true; for(SupportedFlags flag : SupportedFlags.values()) { if (!first || (first = false)) { buffer.append(", "); @@ -423,7 +421,7 @@ private void evaluate(Set events, SupportedFlags flag, EventSource events.add(eventSource); } public Set generatesEvents() { - Set generatedEvents = new TreeSet<>(); + var generatedEvents = new TreeSet(); evaluate(generatedEvents, APPLICATION_STOPPED_TIME, SAFEPOINT); evaluate(generatedEvents, APPLICATION_CONCURRENT_TIME, SAFEPOINT); evaluate(generatedEvents, DEFNEW, EventSource.GENERATIONAL); diff --git a/api/src/main/java/com/microsoft/gctoolkit/jvm/JavaVirtualMachine.java b/api/src/main/java/com/microsoft/gctoolkit/jvm/JavaVirtualMachine.java index 882f95be..0ad35dd9 100644 --- a/api/src/main/java/com/microsoft/gctoolkit/jvm/JavaVirtualMachine.java +++ b/api/src/main/java/com/microsoft/gctoolkit/jvm/JavaVirtualMachine.java @@ -3,7 +3,6 @@ package com.microsoft.gctoolkit.jvm; -import com.microsoft.gctoolkit.GCToolKit; import com.microsoft.gctoolkit.aggregator.Aggregation; import com.microsoft.gctoolkit.aggregator.Aggregator; import com.microsoft.gctoolkit.io.DataSource; @@ -14,114 +13,82 @@ import java.util.List; import java.util.Optional; -/** - * JavaVirtualMachine is a representation of the JVM state obtained by analyzing a GC log file. - * An instance of JavaVirtualMachine is created by calling {@link GCToolKit#analyze(DataSource)} - */ +/// JavaVirtualMachine is a representation of the JVM state obtained by analyzing a GC log file. +/// An instance of JavaVirtualMachine is created by calling [GCToolKit#analyze(DataSource)] public interface JavaVirtualMachine { - /** - * @param dataSource the log to be considered. - * Return {@code true} if the JavaVirtualMachine implementation can work with the GC log. - * @return {@code true} if the JavaVirtualMachine implementation can work with the GC Log. - */ + /// @param dataSource the log to be considered. + /// Return `true` if the JavaVirtualMachine implementation can work with the GC log. + /// @return `true` if the JavaVirtualMachine implementation can work with the GC Log. boolean accepts(DataSource dataSource); - /** - * True if the log is unified or false for preunified - * @return true is the log is from JDK 9+ - */ + /// True if the log is unified or false for preunified + /// @return true is the log is from JDK 9+ boolean isUnifiedLogging(); - /** - * Return {@code true} if the JVM was using G1GC. - * @return {@code true} if the GC is G1GC. - */ + /// Return `true` if the JVM was using G1GC. + /// @return `true` if the GC is G1GC. boolean isG1GC(); - /** - * Return {@code true} if the JVM was using ZGC. - * @return {@code true} if the GC is ZGC. - */ + /// Return `true` if the JVM was using ZGC. + /// @return `true` if the GC is ZGC. boolean isZGC(); - /** - * Return {@code true} if the JVM was using Shenandoah. - * @return {@code true} if the GC is Shenandoah. - */ + /// Return `true` if the JVM was using Shenandoah. + /// @return `true` if the GC is Shenandoah. boolean isShenandoah(); - /** - * Return {@code true} if the JVM was using Parallel GC. - * @return {@code true} if the GC is Parallel GC. - */ + /// Return `true` if the JVM was using Parallel GC. + /// @return `true` if the GC is Parallel GC. boolean isParallel() ; - /** - * Return {@code true} if the JVM was using Serial GC. - * @return {@code true} if the GC is Serial GC. - */ + /// Return `true` if the JVM was using Serial GC. + /// @return `true` if the GC is Serial GC. boolean isSerial(); - /** - * Return {@code true} if the JVM was using CMS GC. - * @return {@code true} if the GC is CMS GC. - */ + /// Return `true` if the JVM was using CMS GC. + /// @return `true` if the GC is CMS GC. boolean isCMS(); - /** - * Return the command line used to run the JVM, if available. - * @return The command line used to run the JVM, or {@code null} - */ + /// Return the command line used to run the JVM, if available. + /// @return The command line used to run the JVM, or `null` String getCommandLine(); - /** - * Return the time of the first event in the GC log file. - * @return The time of the last event. - */ + /// Return the time of the first event in the GC log file. + /// @return The time of the last event. DateTimeStamp getTimeOfFirstEvent(); - /** - * Estimates the initial start time of the log in the case that the log - * is determined to be a fragment. Otherwise, return a start time of 0.000 seconds - * @return The time of the first event. - */ + /// Estimates the initial start time of the log in the case that the log + /// is determined to be a fragment. Otherwise, return a start time of 0.000 seconds + /// @return The time of the first event. DateTimeStamp getEstimatedJVMStartTime(); - /** - * Return the time of the last event in the GC log file. - * @return The time of the last event. - */ + /// Return the time of the last event in the GC log file. + /// @return The time of the last event. DateTimeStamp getJVMTerminationTime(); - /** - * Return the runtime duration. This is not necessarily the difference - * between the first and last event. Rather, this calculation considers - * the duration of the events. - * @return The runtime duration that the GC log represents. - */ + /// Return the runtime duration. This is not necessarily the difference + /// between the first and last event. Rather, this calculation considers + /// the duration of the events. + /// @return The runtime duration that the GC log represents. double getRuntimeDuration(); - /** - * Return the {@code Aggregation} that was used in the analysis of the GC log file - * that is the same class as {@code aggregationClass}. In other words, {@code aggregationClass} - * is a key used to look up an instance of the {@code Aggregation}. The return value - * may be {@code null} if the {@code Aggregation} was not used in the analysis. Which - * {@code Aggregation}s are used depends on the GC. - * @param aggregationClass The class of the Aggregation to be returned. - * @param type cast for the Aggregation class type. - * @return an {@code Aggregation} whose {@code getClass() == aggregationClass}, or {@code null} - * if given aggregationClass is not available. - */ + /// Return the `Aggregation` that was used in the analysis of the GC log file + /// that is the same class as `aggregationClass`. In other words, `aggregationClass` + /// is a key used to look up an instance of the `Aggregation`. The return value + /// may be `null` if the `Aggregation` was not used in the analysis. Which + /// `Aggregation`s are used depends on the GC. + /// @param aggregationClass The class of the Aggregation to be returned. + /// @param T type cast for the Aggregation class type. + /// @return an `Aggregation` whose `getClass() == aggregationClass`, or `null` + /// if given aggregationClass is not available. Optional getAggregation(Class aggregationClass); - /** - * Interface to trigger the analysis of a gc log. - * @param registeredAggregations all aggregations supplied by the module SPI - * @param eventChannel JVMEvent message channel - * @param dataSourceChannel GC logging data channel - */ + /// Interface to trigger the analysis of a gc log. + /// @param registeredAggregations all aggregations supplied by the module SPI + /// @param eventChannel JVMEvent message channel + /// @param dataSourceChannel GC logging data channel void analyze(List> registeredAggregations, JVMEventChannel eventChannel, DataSourceChannel dataSourceChannel); } \ No newline at end of file diff --git a/api/src/main/java/com/microsoft/gctoolkit/jvm/PreUnifiedJavaVirtualMachine.java b/api/src/main/java/com/microsoft/gctoolkit/jvm/PreUnifiedJavaVirtualMachine.java index d5b04a0b..36280404 100644 --- a/api/src/main/java/com/microsoft/gctoolkit/jvm/PreUnifiedJavaVirtualMachine.java +++ b/api/src/main/java/com/microsoft/gctoolkit/jvm/PreUnifiedJavaVirtualMachine.java @@ -9,13 +9,11 @@ import java.util.logging.Level; import java.util.logging.Logger; -/** - * An implementation of JavaVirtualMachine that uses io.vertx verticles to feed - * lines to the parser(s) and post events to the aggregators. This implementation - * is here in the vertx module so that the api and parser modules can exist without - * having to import io.vertx. In the api module, the class GCToolKit uses the classloader - * to load required JavaVirtualMachine. - */ +/// An implementation of JavaVirtualMachine that uses io.vertx verticles to feed +/// lines to the parser(s) and post events to the aggregators. This implementation +/// is here in the vertx module so that the api and parser modules can exist without +/// having to import io.vertx. In the api module, the class GCToolKit uses the classloader +/// to load required JavaVirtualMachine. public class PreUnifiedJavaVirtualMachine extends AbstractJavaVirtualMachine { private static final Logger LOGGER = Logger.getLogger(PreUnifiedJavaVirtualMachine.class.getName()); @@ -24,8 +22,8 @@ public class PreUnifiedJavaVirtualMachine extends AbstractJavaVirtualMachine { @Override public boolean accepts(DataSource logFile) { try { - if (logFile instanceof GCLogFile) { - if (!((GCLogFile) logFile).isUnified()) { + if (logFile instanceof GCLogFile file) { + if (!file.isUnified()) { super.setDataSource(logFile); return true; } diff --git a/api/src/main/java/com/microsoft/gctoolkit/jvm/SupportedFlags.java b/api/src/main/java/com/microsoft/gctoolkit/jvm/SupportedFlags.java index bcec8d2b..3875363c 100644 --- a/api/src/main/java/com/microsoft/gctoolkit/jvm/SupportedFlags.java +++ b/api/src/main/java/com/microsoft/gctoolkit/jvm/SupportedFlags.java @@ -2,10 +2,8 @@ // Licensed under the MIT License. package com.microsoft.gctoolkit.jvm; -/** - * Flags that describe JVM, collector, and log-detail features discovered while - * diarizing a GC log. - */ +/// Flags that describe JVM, collector, and log-detail features discovered while +/// diarizing a GC log. public enum SupportedFlags { APPLICATION_STOPPED_TIME, // 0 APPLICATION_CONCURRENT_TIME, // 1 diff --git a/api/src/main/java/com/microsoft/gctoolkit/jvm/UnifiedJavaVirtualMachine.java b/api/src/main/java/com/microsoft/gctoolkit/jvm/UnifiedJavaVirtualMachine.java index b982f439..7dfb1399 100644 --- a/api/src/main/java/com/microsoft/gctoolkit/jvm/UnifiedJavaVirtualMachine.java +++ b/api/src/main/java/com/microsoft/gctoolkit/jvm/UnifiedJavaVirtualMachine.java @@ -9,13 +9,11 @@ import java.util.logging.Level; import java.util.logging.Logger; -/** - * An implementation of JavaVirtualMachine that uses io.vertx verticles to feed - * lines to the parser(s) and post events to the aggregators. This implementation - * is here in the vertx module so that the api and parser modules can exist without - * having to import io.vertx. In the api module, the class GCToolKit uses the classloader - * to load UnifiedJavaVirtualMachine. - */ +/// An implementation of JavaVirtualMachine that uses io.vertx verticles to feed +/// lines to the parser(s) and post events to the aggregators. This implementation +/// is here in the vertx module so that the api and parser modules can exist without +/// having to import io.vertx. In the api module, the class GCToolKit uses the classloader +/// to load UnifiedJavaVirtualMachine. public class UnifiedJavaVirtualMachine extends AbstractJavaVirtualMachine { private static final Logger LOGGER = Logger.getLogger(UnifiedJavaVirtualMachine.class.getName()); diff --git a/api/src/main/java/com/microsoft/gctoolkit/message/ChannelName.java b/api/src/main/java/com/microsoft/gctoolkit/message/ChannelName.java index 9c57edf6..0ad32499 100644 --- a/api/src/main/java/com/microsoft/gctoolkit/message/ChannelName.java +++ b/api/src/main/java/com/microsoft/gctoolkit/message/ChannelName.java @@ -1,8 +1,6 @@ package com.microsoft.gctoolkit.message; -/** - * A list of all of the channel names that are available for publishing on. - */ +/// A list of all of the channel names that are available for publishing on. public enum ChannelName { DATA_SOURCE("DataSource"), @@ -25,6 +23,7 @@ public String getName() { return name; } + @Override public String toString() { return getName(); } diff --git a/api/src/main/java/com/microsoft/gctoolkit/message/DataSourceChannel.java b/api/src/main/java/com/microsoft/gctoolkit/message/DataSourceChannel.java index 08166d1b..93c0cf75 100644 --- a/api/src/main/java/com/microsoft/gctoolkit/message/DataSourceChannel.java +++ b/api/src/main/java/com/microsoft/gctoolkit/message/DataSourceChannel.java @@ -1,7 +1,5 @@ package com.microsoft.gctoolkit.message; -/** - * Interface defining the DataSource Channel. This must be implemented by a provider - * and made available via the module service provider API. - */ +/// Interface defining the DataSource Channel. This must be implemented by a provider +/// and made available via the module service provider API. public interface DataSourceChannel extends Channel {} diff --git a/api/src/main/java/com/microsoft/gctoolkit/online/statistics/OnlineMeanCalculator.java b/api/src/main/java/com/microsoft/gctoolkit/online/statistics/OnlineMeanCalculator.java index cb716537..6c208326 100644 --- a/api/src/main/java/com/microsoft/gctoolkit/online/statistics/OnlineMeanCalculator.java +++ b/api/src/main/java/com/microsoft/gctoolkit/online/statistics/OnlineMeanCalculator.java @@ -4,6 +4,7 @@ public class OnlineMeanCalculator implements OnlineStatisticsCalculator { private int numSamples = 0; private double mean = 0.0; + @Override public void update(double sampleValue) { numSamples++; mean += (sampleValue - mean) / numSamples; diff --git a/api/src/main/java/com/microsoft/gctoolkit/online/statistics/OnlineStatisticsCalculator.java b/api/src/main/java/com/microsoft/gctoolkit/online/statistics/OnlineStatisticsCalculator.java index 796dd15d..17136695 100644 --- a/api/src/main/java/com/microsoft/gctoolkit/online/statistics/OnlineStatisticsCalculator.java +++ b/api/src/main/java/com/microsoft/gctoolkit/online/statistics/OnlineStatisticsCalculator.java @@ -3,17 +3,13 @@ public interface OnlineStatisticsCalculator { - /** - * Updates the statistics calculation with the given value. - *

- * For example, if the statistics calculation is a mean, this method would update the mean with the given value. - * - * @param sampleValue the value to be added to the statistics calculation - */ + /// Updates the statistics calculation with the given value. + /// + /// For example, if the statistics calculation is a mean, this method would update the mean with the given value. + /// + /// @param sampleValue the value to be added to the statistics calculation void update(double sampleValue); - /** - * @return the value of the statistics calculation - */ + /// @return the value of the statistics calculation double getValue(); } diff --git a/api/src/main/java/com/microsoft/gctoolkit/online/statistics/WelfordVarianceCalculator.java b/api/src/main/java/com/microsoft/gctoolkit/online/statistics/WelfordVarianceCalculator.java index 0600af4a..023517a9 100644 --- a/api/src/main/java/com/microsoft/gctoolkit/online/statistics/WelfordVarianceCalculator.java +++ b/api/src/main/java/com/microsoft/gctoolkit/online/statistics/WelfordVarianceCalculator.java @@ -7,12 +7,12 @@ public class WelfordVarianceCalculator implements OnlineStatisticsCalculator { @Override public void update(double sampleValue) { - double oldMean = onlineMeanCalculator.getValue(); + var oldMean = onlineMeanCalculator.getValue(); onlineMeanCalculator.update(sampleValue); numSamples++; - double newMean = onlineMeanCalculator.getValue(); + var newMean = onlineMeanCalculator.getValue(); m2 += (sampleValue - oldMean) * (sampleValue - newMean); } diff --git a/api/src/main/java/com/microsoft/gctoolkit/parser/datatype/TripleState.java b/api/src/main/java/com/microsoft/gctoolkit/parser/datatype/TripleState.java index e197b1ce..b71819e9 100644 --- a/api/src/main/java/com/microsoft/gctoolkit/parser/datatype/TripleState.java +++ b/api/src/main/java/com/microsoft/gctoolkit/parser/datatype/TripleState.java @@ -4,44 +4,35 @@ import java.util.Locale; -/** - * When a boolean just won't do. Parsing a log file is a process of discovery. Nothing is known until it is known. - */ +/// When a boolean just won't do. Parsing a log file is a process of discovery. Nothing is known until it is known. public enum TripleState { UNKNOWN, TRUE, FALSE; - /** - * Transform boolean to it's corresponding TripleState - * @param value boolean - * @return - */ + /// Transform boolean to it's corresponding TripleState + /// @param value boolean + /// @return public static TripleState valueOf(boolean value) { - return (value) ? TRUE : FALSE; + return value ? TRUE : FALSE; } - /** - * @return {@code true} if {@code this != TripleState.UNKOWN} - */ + /// @return `true` if `this != TripleState.UNKOWN` public boolean isKnown() { return this != UNKNOWN; } - /** - * @return {@code true} if {@code this == TripleState.TRUE} - */ + /// @return `true` if `this == TripleState.TRUE` public boolean isTrue() { return this == TRUE; } - /** - * @return {@code true} if {@code this == TripleState.FALSE} - */ + /// @return `true` if `this == TripleState.FALSE` public boolean isFalse() { return this == FALSE; } + @Override public String toString() { return this.name().toLowerCase(Locale.ROOT); } diff --git a/api/src/main/java/com/microsoft/gctoolkit/time/DateTimeStamp.java b/api/src/main/java/com/microsoft/gctoolkit/time/DateTimeStamp.java index 3666f254..089c9210 100644 --- a/api/src/main/java/com/microsoft/gctoolkit/time/DateTimeStamp.java +++ b/api/src/main/java/com/microsoft/gctoolkit/time/DateTimeStamp.java @@ -2,6 +2,8 @@ // Licensed under the MIT License. package com.microsoft.gctoolkit.time; +import org.jspecify.annotations.Nullable; + import java.time.Instant; import java.time.ZoneId; import java.time.ZonedDateTime; @@ -16,14 +18,12 @@ import static java.util.Comparator.*; -/** - * A date and time. Both date and time come from reading the GC log. In cases where - * the GC log has no date or time stamp, a DateTimeStamp is synthesized from the information - * available in the log (event durations, for example). - *

- * Instance of DateTimeStamp are created by the parser. The constructors match what might be - * found for dates and time stamps in a GC log file. - */ +/// A date and time. Both date and time come from reading the GC log. In cases where +/// the GC log has no date or time stamp, a DateTimeStamp is synthesized from the information +/// available in the log (event durations, for example). +/// +/// Instance of DateTimeStamp are created by the parser. The constructors match what might be +/// found for dates and time stamps in a GC log file. public class DateTimeStamp implements Comparable { // Represents the time from Epoch @@ -99,57 +99,47 @@ public static DateTimeStamp fromGCLogLine(String line) { return EMPTY_DATE; } - /** - * Provides a minimal date. - * @return a minimal date - */ + /// Provides a minimal date. + /// @return a minimal date public static DateTimeStamp baseDate() { return new DateTimeStamp(EPOC, 0.0d); } - /** - * Create a DateTimeStamp by parsing an ISO 8601 date/time string. - * @param iso8601DateTime A String in ISO 8601 format. - */ + /// Create a DateTimeStamp by parsing an ISO 8601 date/time string. + /// @param iso8601DateTime A String in ISO 8601 format. public DateTimeStamp(String iso8601DateTime) { - this(dateFromString(iso8601DateTime)); + ZonedDateTime dateTime1 = dateFromString(iso8601DateTime); + this(dateTime1); } - /** - * Create a DateTimeStamp from a ZonedDateTime. - * @param dateTime A ZonedDateTime - */ + /// Create a DateTimeStamp from a ZonedDateTime. + /// @param dateTime A ZonedDateTime public DateTimeStamp(ZonedDateTime dateTime) { this(dateTime,Double.NaN); } - /** - * Create a DateTimeStamp from an IOS 8601 date/time string and - * a time stamp. The time stamp represents decimal seconds. - * @param iso8601DateTime A String in ISO 8601 format. - * @param timeStamp A time stamp in decimal seconds. - */ + /// Create a DateTimeStamp from an IOS 8601 date/time string and + /// a time stamp. The time stamp represents decimal seconds. + /// @param iso8601DateTime A String in ISO 8601 format. + /// @param timeStamp A time stamp in decimal seconds. public DateTimeStamp(String iso8601DateTime, double timeStamp) { - this(dateFromString(iso8601DateTime), timeStamp); + ZonedDateTime dateTime1 = dateFromString(iso8601DateTime); + this(dateTime1, timeStamp); } - /** - * Create a DateTimeStamp from a time stamp. - * @param timeStamp A time stamp in decimal seconds. - */ + /// Create a DateTimeStamp from a time stamp. + /// @param timeStamp A time stamp in decimal seconds. public DateTimeStamp(double timeStamp) { this((ZonedDateTime) null,timeStamp); } - /** - * Create a DateTimeStamp from a ZonedDateTime and a timestamp. - * All other constructors end up here. If timeStamp is - * {@code NaN} or less than zero, then the time stamp is extracted - * from the ZonedDateTime. - * @param dateTime A ZonedDateTime, which may be {@code null}. - * @param timeStamp A time stamp in decimal seconds, - * which should be greater than or equal to zero. - */ + /// Create a DateTimeStamp from a ZonedDateTime and a timestamp. + /// All other constructors end up here. If timeStamp is + /// `NaN` or less than zero, then the time stamp is extracted + /// from the ZonedDateTime. + /// @param dateTime A ZonedDateTime, which may be `null`. + /// @param timeStamp A time stamp in decimal seconds, + /// which should be greater than or equal to zero. public DateTimeStamp(ZonedDateTime dateTime, double timeStamp) { this.dateTime = dateTime; if ( (timeStamp < 0.00d) || Double.isNaN(timeStamp)) @@ -159,10 +149,8 @@ public DateTimeStamp(ZonedDateTime dateTime, double timeStamp) { this.timeStamp = Math.round(timeStamp * 1000.0d) / 1000.0d; } - /** - * Return the time stamp value. Allows a consistent time stamp be available to all calculations. - * @return The time stamp value, in decimal seconds. - */ + /// Return the time stamp value. Allows a consistent time stamp be available to all calculations. + /// @return The time stamp value, in decimal seconds. @Deprecated public double getTimeStamp() { if (!hasTimeStamp()) @@ -180,19 +168,15 @@ public double toSeconds() { return toMilliseconds() / 1000.0d; } - /** - * Return the date stamp. - * @return The date stamp, which may be {@code null} - */ + /// Return the date stamp. + /// @return The date stamp, which may be `null` public ZonedDateTime getDateTime() { return dateTime; } - /** - * Return {@code true} if the date stamp is not {@code null}. - * It is possible to have two DateTimeStamps from the same GC log, one with a DateStamp and one without. - * @return {@code true} if the date stamp is not {@code null}. - */ + /// Return `true` if the date stamp is not `null`. + /// It is possible to have two DateTimeStamps from the same GC log, one with a DateStamp and one without. + /// @return `true` if the date stamp is not `null`. public boolean hasDateStamp() { return ! (getDateTime() == null || EPOC.equals(getDateTime())); } @@ -203,8 +187,7 @@ public boolean hasTimeStamp() { @Override public boolean equals(Object obj) { - if (obj instanceof DateTimeStamp) { - DateTimeStamp other = (DateTimeStamp) obj; + if (obj instanceof DateTimeStamp other) { if (this.hasDateStamp()) return this.getDateTime().equals(other.getDateTime()) && (this.getTimeStamp() == other.getTimeStamp()); @@ -221,7 +204,7 @@ public int hashCode() { @Override public String toString() { - StringBuilder buffer = new StringBuilder(); + var buffer = new StringBuilder(); if (hasDateStamp()) buffer.append(getDateTime().toString()); if (hasTimeStamp()) @@ -229,33 +212,27 @@ public String toString() { return buffer.toString(); } - /** - * Return {@code true} if this DateTimeStamp comes before the other. - * @param other The other DateTimeStamp. - * @return {@code true} if this time stamp is less than the other. - */ + /// Return `true` if this DateTimeStamp comes before the other. + /// @param other The other DateTimeStamp. + /// @return `true` if this time stamp is less than the other. public boolean before(DateTimeStamp other) { return compareTo(other) < 0; } - /** - * Return {@code true} if this DateTimeStamp comes after the other. - * @param other The other DateTimeStamp. - * @return {@code true} if this time stamp is less than the other. - */ + /// Return `true` if this DateTimeStamp comes after the other. + /// @param other The other DateTimeStamp. + /// @return `true` if this time stamp is less than the other. public boolean after(DateTimeStamp other) { return compareTo(other) > 0; } - /** - * Return {@code 1} if this date is after than the other, - * {@code -1} if this date is before the other, - * or {@code 0} if this date is the same as the other. - * @param otherDate The other date. - * @return {@code 1}, {@code 0}, {@code -1} if this date is - * after, the same as, or before the other. - */ - public int compare(ZonedDateTime otherDate) { + /// Return `1` if this date is after than the other, + /// `-1` if this date is before the other, + /// or `0` if this date is the same as the other. + /// @param otherDate The other date. + /// @return `1`, `0`, `-1` if this date is + /// after, the same as, or before the other. + public int compare(@Nullable ZonedDateTime otherDate) { if (hasDateStamp() && otherDate != null) { if (getDateTime().isAfter(otherDate)) return 1; if (getDateTime().isBefore(otherDate)) return -1; @@ -265,76 +242,66 @@ public int compare(ZonedDateTime otherDate) { } } - /** - * Return a new {@code DateTimeStamp} resulting from adding the - * decimal second offset to this. - * @param offsetInDecimalSeconds An offset, in decimal seconds. - * @return A new {@code DateTimeStamp}, {@code offsetInDecimalSeconds} from this. - */ + /// Return a new `DateTimeStamp` resulting from adding the + /// decimal second offset to this. + /// @param offsetInDecimalSeconds An offset, in decimal seconds. + /// @return A new `DateTimeStamp`, `offsetInDecimalSeconds` from this. public DateTimeStamp add(double offsetInDecimalSeconds) { if (Double.isNaN(offsetInDecimalSeconds)) throw new IllegalArgumentException("Cannot add " + Double.NaN); - double adjustedTimeStamp = Double.NaN; + var adjustedTimeStamp = Double.NaN; ZonedDateTime adjustedDateStamp = null; if ( hasTimeStamp()) { adjustedTimeStamp = getTimeStamp() + offsetInDecimalSeconds; } if (hasDateStamp()) { - double offset = (Double.isNaN(offsetInDecimalSeconds)) ? 0.000d : offsetInDecimalSeconds; - int seconds = (int) offset; - long nanos = ((long) ((offset % 1) * 1_000L)) * 1_000_000L; + double offset = Double.isNaN(offsetInDecimalSeconds) ? 0.000d : offsetInDecimalSeconds; + var seconds = (int) offset; + var nanos = ((long) ((offset % 1) * 1_000L)) * 1_000_000L; adjustedDateStamp = dateTime.plusSeconds(seconds).plusNanos(nanos); } return new DateTimeStamp(adjustedDateStamp, adjustedTimeStamp); } - /** - * Return a new {@code DateTimeStamp} resulting from subtracting the - * decimal second offset from this. - * @param offsetInDecimalSeconds An offset, in decimal seconds. - * @return A new {@code DateTimeStamp}, {@code offsetInDecimalSeconds} from this. - */ + /// Return a new `DateTimeStamp` resulting from subtracting the + /// decimal second offset from this. + /// @param offsetInDecimalSeconds An offset, in decimal seconds. + /// @return A new `DateTimeStamp`, `offsetInDecimalSeconds` from this. public DateTimeStamp minus(double offsetInDecimalSeconds) { return add(-offsetInDecimalSeconds); } - /** - * Return the difference between this time stamp, and the time stamp of - * the other DateTimeStamp. - * @param other The other {@code DateTimeStamp} - * @return The difference between this time stamp, and the time stamp - * of the other DateTimeStamp. - */ + /// Return the difference between this time stamp, and the time stamp of + /// the other DateTimeStamp. + /// @param other The other `DateTimeStamp` + /// @return The difference between this time stamp, and the time stamp + /// of the other DateTimeStamp. public double minus(DateTimeStamp other) { if (hasTimeStamp() && other.hasTimeStamp()) return getTimeStamp() - other.getTimeStamp(); if (hasDateStamp() && other.hasDateStamp()) { - double thisInSeconds = (double)getDateTime().toEpochSecond() + ((double)(getDateTime().getNano() / 1_000_000)) / 1000.0d; - double otherInSeconds = (double)other.getDateTime().toEpochSecond() + ((double)(other.getDateTime().getNano() / 1_000_000)) / 1000.0d; + var thisInSeconds = (double)getDateTime().toEpochSecond() + ((double)(getDateTime().getNano() / 1_000_000)) / 1000.0d; + var otherInSeconds = (double)other.getDateTime().toEpochSecond() + ((double)(other.getDateTime().getNano() / 1_000_000)) / 1000.0d; return thisInSeconds - otherInSeconds; } return Double.NaN; } - /** - * Return the difference between time stamps, converted to minutes. - * This is a convenience method for {@code this.minus(dateTimeStamp) / 60.0}. - * @param dateTimeStamp The other {@code DateTimeStamp} - * @return The difference between time stamps, converted to minutes. - */ + /// Return the difference between time stamps, converted to minutes. + /// This is a convenience method for `this.minus(dateTimeStamp) / 60.0`. + /// @param dateTimeStamp The other `DateTimeStamp` + /// @return The difference between time stamps, converted to minutes. public double timeSpanInMinutes(DateTimeStamp dateTimeStamp) { return this.minus(dateTimeStamp) / 60.0d; } - /** - * It will compare date time first, if both are equals then compare timestamp value, - * For Null date time considered to be last entry. - * @param dateTimeStamp - other object to compared - * @return a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object - */ + /// It will compare date time first, if both are equals then compare timestamp value, + /// For Null date time considered to be last entry. + /// @param dateTimeStamp - other object to compared + /// @return a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object @Override public int compareTo(DateTimeStamp dateTimeStamp) { return comparator.compare(this,dateTimeStamp); @@ -344,7 +311,7 @@ private static Comparator getComparator(){ // compare with dateTime field, if null then it will go to last // need a check to make sure these are comparable return nullsLast((o1, o2) -> { - Comparator dateTimeStampComparator = compareDateTimeStamp(o1, o2); + var dateTimeStampComparator = compareDateTimeStamp(o1, o2); return dateTimeStampComparator.compare(o1,o2); }); } diff --git a/api/src/main/java/module-info.java b/api/src/main/java/module-info.java index 8afa6d46..5c1a5653 100644 --- a/api/src/main/java/module-info.java +++ b/api/src/main/java/module-info.java @@ -31,6 +31,7 @@ */ module com.microsoft.gctoolkit.api { requires java.logging; + requires org.jspecify; exports com.microsoft.gctoolkit; exports com.microsoft.gctoolkit.aggregator; diff --git a/api/src/test/java/com/microsoft/gctoolkit/io/RotatingGCLogTest.java b/api/src/test/java/com/microsoft/gctoolkit/io/RotatingGCLogTest.java index b59a6c8c..e7ef54cb 100644 --- a/api/src/test/java/com/microsoft/gctoolkit/io/RotatingGCLogTest.java +++ b/api/src/test/java/com/microsoft/gctoolkit/io/RotatingGCLogTest.java @@ -15,7 +15,7 @@ public class RotatingGCLogTest { void orderRotatingLogsTest() { Path path = new TestLogFile("G1-80-16gbps2.log").getFile().toPath(); try { - RotatingGCLogFile file = new RotatingGCLogFile(path); + var file = new RotatingGCLogFile(path); assertEquals(2, file.getMetaData().getNumberOfFiles()); assertEquals(2, file.getMetaData().logFiles().map(LogFileSegment::getPath).map(Path::toFile).map(File::getName).filter(s -> s.startsWith("G1-80-16gbps2")).count()); file.getMetaData().logFiles().map(LogFileSegment::getEndTime).forEach(System.out::println); diff --git a/api/src/test/java/com/microsoft/gctoolkit/online/statistics/WelfordVarianceCalculatorTest.java b/api/src/test/java/com/microsoft/gctoolkit/online/statistics/WelfordVarianceCalculatorTest.java index ca60294f..f1690aef 100644 --- a/api/src/test/java/com/microsoft/gctoolkit/online/statistics/WelfordVarianceCalculatorTest.java +++ b/api/src/test/java/com/microsoft/gctoolkit/online/statistics/WelfordVarianceCalculatorTest.java @@ -2,20 +2,21 @@ import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; class WelfordVarianceCalculatorTest { @Test void insufficientSamples() { - WelfordVarianceCalculator calculator = new WelfordVarianceCalculator(); + var calculator = new WelfordVarianceCalculator(); calculator.update(1.23d); assertThrows(NotEnoughSampleException.class, calculator::getValue); } @Test void getVariance() { - WelfordVarianceCalculator calculator = new WelfordVarianceCalculator(); + var calculator = new WelfordVarianceCalculator(); calculator.update(1421.23); calculator.update(2897.34); calculator.update(3907.45); @@ -24,7 +25,7 @@ void getVariance() { @Test void getVarianceWithSmallDifference() { - WelfordVarianceCalculator calculator = new WelfordVarianceCalculator(); + var calculator = new WelfordVarianceCalculator(); calculator.update(71899123.1273789); calculator.update(71899123.1378323); calculator.update(71899123.1478654); diff --git a/api/src/test/java/com/microsoft/gctoolkit/time/DateTimeStampTest.java b/api/src/test/java/com/microsoft/gctoolkit/time/DateTimeStampTest.java index ebf0b56e..7da3a864 100644 --- a/api/src/test/java/com/microsoft/gctoolkit/time/DateTimeStampTest.java +++ b/api/src/test/java/com/microsoft/gctoolkit/time/DateTimeStampTest.java @@ -16,7 +16,7 @@ public class DateTimeStampTest { @Test void getTimeStamp() { - DateTimeStamp dateTimeStamp = new DateTimeStamp(.586); + var dateTimeStamp = new DateTimeStamp(.586); assertEquals(.586, dateTimeStamp.getTimeStamp(), 0.0001); dateTimeStamp = new DateTimeStamp("2018-04-04T09:10:00.586-0100"); @@ -28,7 +28,7 @@ void getTimeStamp() { @Test void getDateStampAsString() { - DateTimeStamp dateTimeStamp = new DateTimeStamp(.586); + var dateTimeStamp = new DateTimeStamp(.586); assertEquals("@0.586", dateTimeStamp.toString()); dateTimeStamp = new DateTimeStamp("2018-04-04T09:10:00.586-0100"); @@ -40,7 +40,7 @@ void getDateStampAsString() { @Test void getDateTime() { - DateTimeStamp dateTimeStamp = new DateTimeStamp(.586); + var dateTimeStamp = new DateTimeStamp(.586); assertNull(dateTimeStamp.getDateTime()); dateTimeStamp = new DateTimeStamp("2018-04-04T09:10:00.586-0100"); @@ -52,7 +52,7 @@ void getDateTime() { @Test void hasDateStamp() { - DateTimeStamp dateTimeStamp = new DateTimeStamp(.586); + var dateTimeStamp = new DateTimeStamp(.586); assertFalse(dateTimeStamp.hasDateStamp()); dateTimeStamp = new DateTimeStamp("2018-04-04T09:10:00.586-0100"); @@ -64,8 +64,8 @@ void hasDateStamp() { @Test void testHash() { - DateTimeStamp a = new DateTimeStamp(.586); - DateTimeStamp b = new DateTimeStamp(.587); + var a = new DateTimeStamp(.586); + var b = new DateTimeStamp(.587); assertNotEquals(a.hashCode(), b.hashCode()); a = new DateTimeStamp("2018-04-04T09:10:00.586-0100"); @@ -100,8 +100,8 @@ void testHash() { @Test void testEquals() { - DateTimeStamp a = new DateTimeStamp(0.586d); - DateTimeStamp b = new DateTimeStamp(0.586d); + var a = new DateTimeStamp(0.586d); + var b = new DateTimeStamp(0.586d); assertEquals(a,b); assertEquals(b,a); b = new DateTimeStamp(.587); @@ -216,8 +216,8 @@ void testAfter() { @Test void compare() { - DateTimeStamp a = new DateTimeStamp("2018-04-04T09:10:00.586-0100"); - DateTimeStamp b = new DateTimeStamp("2018-04-04T09:10:00.587-0100"); + var a = new DateTimeStamp("2018-04-04T09:10:00.586-0100"); + var b = new DateTimeStamp("2018-04-04T09:10:00.587-0100"); assertTrue(a.compare(b.getDateTime()) < 0); assertTrue(b.compare(a.getDateTime()) > 0); assertEquals(0, a.compare(new DateTimeStamp("2018-04-04T09:10:00.586-0100").getDateTime())); @@ -237,10 +237,10 @@ void compare() { @Test void add() { - DateTimeStamp a = new DateTimeStamp(.586); - double a_ts = a.getTimeStamp(); + var a = new DateTimeStamp(.586); + var a_ts = a.getTimeStamp(); ZonedDateTime a_dt = a.getDateTime(); - DateTimeStamp b = new DateTimeStamp(.586 + .587); + var b = new DateTimeStamp(.586 + .587); assertEquals(b.getTimeStamp(), a.add(.587).getTimeStamp(), .001); assertEquals(a_ts, a.getTimeStamp(), .001); // test that a is unmodified assertEquals(a_dt, a.getDateTime()); // test that a is unmodified @@ -267,10 +267,10 @@ void add() { @Test void minus() { - DateTimeStamp a = new DateTimeStamp(.586); - double a_ts = a.getTimeStamp(); + var a = new DateTimeStamp(.586); + var a_ts = a.getTimeStamp(); ZonedDateTime a_dt = a.getDateTime(); - DateTimeStamp b = new DateTimeStamp(.586 - .587); + var b = new DateTimeStamp(.586 - .587); assertEquals(b.getTimeStamp(), a.minus(.587).getTimeStamp(), .001); assertEquals(a_ts, a.getTimeStamp(), .001); // test that a is unmodified assertEquals(a_dt, a.getDateTime()); // test that a is unmodified @@ -297,15 +297,15 @@ void minus() { @Test void testMinus() { - DateTimeStamp a = new DateTimeStamp(.586); - DateTimeStamp b = new DateTimeStamp(.587); - double diff = a.minus(b); + var a = new DateTimeStamp(.586); + var b = new DateTimeStamp(.587); + var diff = a.minus(b); assertEquals(.586 - .587, diff, .001); a = new DateTimeStamp("2018-04-04T09:10:00.586-0100"); b = new DateTimeStamp("2018-04-04T09:10:00.587-0100"); diff = a.minus(b); - double expected = -0.001d; + var expected = -0.001d; assertEquals(expected, diff, 0.001); a = new DateTimeStamp("2018-04-04T09:10:00.586-0100", .18); @@ -317,9 +317,9 @@ void testMinus() { @Test void timeSpanInMinutes() { - DateTimeStamp a = new DateTimeStamp(.586); - DateTimeStamp b = new DateTimeStamp(.587); - double diff = b.timeSpanInMinutes(a); + var a = new DateTimeStamp(.586); + var b = new DateTimeStamp(.587); + var diff = b.timeSpanInMinutes(a); assertEquals( 0.001d / 60.0d, diff, .001); a = new DateTimeStamp("2018-04-04T09:10:00.586-0100"); @@ -335,70 +335,70 @@ void timeSpanInMinutes() { @Test void testCompareLessThan() { - DateTimeStamp smaller = new DateTimeStamp("2018-04-04T09:10:00.586-0100"); - DateTimeStamp greater = new DateTimeStamp("2018-04-04T10:10:00.587-0100"); + var smaller = new DateTimeStamp("2018-04-04T09:10:00.586-0100"); + var greater = new DateTimeStamp("2018-04-04T10:10:00.587-0100"); assertEquals(-1, smaller.compareTo(greater)); } @Test void testCompareGreaterThan() { - DateTimeStamp smaller = new DateTimeStamp("2018-04-04T09:10:00.586-0100"); - DateTimeStamp greater = new DateTimeStamp("2018-04-04T10:10:00.587-0100"); + var smaller = new DateTimeStamp("2018-04-04T09:10:00.586-0100"); + var greater = new DateTimeStamp("2018-04-04T10:10:00.587-0100"); assertEquals(1, greater.compareTo(smaller)); } @Test void testCompareEquals() { - DateTimeStamp object1 = new DateTimeStamp("2018-04-04T10:10:00.586-0100"); - DateTimeStamp object2 = new DateTimeStamp("2018-04-04T10:10:00.586-0100"); + var object1 = new DateTimeStamp("2018-04-04T10:10:00.586-0100"); + var object2 = new DateTimeStamp("2018-04-04T10:10:00.586-0100"); assertEquals(0, object1.compareTo(object2)); } @Test void testCompareEqualsTimeStamp() { - DateTimeStamp object1 = new DateTimeStamp("2018-04-04T10:10:00.586-0100", 123); - DateTimeStamp object2 = new DateTimeStamp("2018-04-04T10:10:00.586-0100", 123); + var object1 = new DateTimeStamp("2018-04-04T10:10:00.586-0100", 123); + var object2 = new DateTimeStamp("2018-04-04T10:10:00.586-0100", 123); assertEquals(0, object2.compareTo(object1)); } @Test void testCompareGreaterTimeStamp() { - DateTimeStamp smaller = new DateTimeStamp("2018-04-04T10:10:00.586-0100", 122); - DateTimeStamp greater = new DateTimeStamp("2018-04-04T10:10:00.586-0100", 123); + var smaller = new DateTimeStamp("2018-04-04T10:10:00.586-0100", 122); + var greater = new DateTimeStamp("2018-04-04T10:10:00.586-0100", 123); assertEquals(1, greater.compareTo(smaller)); } @Test void testCompareSmallerTimeStamp() { - DateTimeStamp smaller = new DateTimeStamp("2018-04-04T10:10:00.586-0100", 123); - DateTimeStamp greater = new DateTimeStamp("2018-04-04T10:10:00.586-0100", 124); + var smaller = new DateTimeStamp("2018-04-04T10:10:00.586-0100", 123); + var greater = new DateTimeStamp("2018-04-04T10:10:00.586-0100", 124); assertEquals(-1, smaller.compareTo(greater)); } @Test void testCompareNullValue() { - DateTimeStamp smaller = new DateTimeStamp("2018-04-04T09:10:00.586-0100"); + var smaller = new DateTimeStamp("2018-04-04T09:10:00.586-0100"); assertEquals(-1, smaller.compareTo(null)); } @Test void testCompareEqualsTimeStampWithoutDateTime() { - DateTimeStamp object1 = new DateTimeStamp(123); - DateTimeStamp object2 = new DateTimeStamp(123); + var object1 = new DateTimeStamp(123); + var object2 = new DateTimeStamp(123); assertEquals(0, object2.compareTo(object1)); } @Test void testCompareGreaterTimeStampWithoutDateTime() { - DateTimeStamp smaller = new DateTimeStamp(122); - DateTimeStamp greater = new DateTimeStamp(124); + var smaller = new DateTimeStamp(122); + var greater = new DateTimeStamp(124); assertEquals(1, greater.compareTo(smaller)); } @Test void testCompareSmallerTimeStampWithoutDateTime() { - DateTimeStamp smaller = new DateTimeStamp(123); - DateTimeStamp greater = new DateTimeStamp(124); + var smaller = new DateTimeStamp(123); + var greater = new DateTimeStamp(124); assertEquals(-1, smaller.compareTo(greater)); } @@ -418,15 +418,15 @@ void testNanWithMinusNonZero() { @Test void testNanWithMinus() { - DateTimeStamp dateTimeStamp = new DateTimeStamp("2018-04-04T10:09:59.586-0100"); + var dateTimeStamp = new DateTimeStamp("2018-04-04T10:09:59.586-0100"); DateTimeStamp forComparing = new DateTimeStamp("2018-04-04T10:10:00.586-0100").minus(1.0d); assertEquals(dateTimeStamp, forComparing); } @Test void testNanWithConstructor() { - DateTimeStamp dateTimeStamp = new DateTimeStamp((String) null,Double.NaN); - DateTimeStamp forComparing = new DateTimeStamp(0.0); + var dateTimeStamp = new DateTimeStamp((String) null,Double.NaN); + var forComparing = new DateTimeStamp(0.0); assertNotEquals(dateTimeStamp, forComparing); } @@ -436,8 +436,8 @@ void testNanWithConstructor() { @Test void compareWithNANValue(){ // This is an illegal state which is unlikely to happen in the context of a single GC log. - DateTimeStamp dateTimeStamp = new DateTimeStamp(12d); - DateTimeStamp dateTimeStampCompare = new DateTimeStamp(Double.NaN); + var dateTimeStamp = new DateTimeStamp(12d); + var dateTimeStampCompare = new DateTimeStamp(Double.NaN); assertThrows(IllegalStateException.class, () -> { dateTimeStamp.compareTo(dateTimeStampCompare); }, "IllegalStateException Not Thrown"); @@ -446,9 +446,9 @@ void compareWithNANValue(){ @Test void compareWithNullDates() { - DateTimeStamp stamp1 = new DateTimeStamp((String)null, 100); - DateTimeStamp stamp2 = new DateTimeStamp((String)null, 200); - DateTimeStamp stamp3 = new DateTimeStamp((String)null, 100); + var stamp1 = new DateTimeStamp((String)null, 100); + var stamp2 = new DateTimeStamp((String)null, 200); + var stamp3 = new DateTimeStamp((String)null, 100); assertTrue(stamp1.compareTo(stamp2) < 0); assertTrue(stamp1.compareTo(stamp3) == 0); assertTrue(stamp2.compareTo(stamp3) > 0); @@ -456,9 +456,9 @@ void compareWithNullDates() { @Test void compareToTransitivity() { - DateTimeStamp stamp1 = new DateTimeStamp("2021-09-01T11:12:13.111-0100", 100); - DateTimeStamp stamp2 = new DateTimeStamp((String)null, 200); - DateTimeStamp stamp3 = new DateTimeStamp("2021-08-31T11:12:13.111-0100", 300); + var stamp1 = new DateTimeStamp("2021-09-01T11:12:13.111-0100", 100); + var stamp2 = new DateTimeStamp((String)null, 200); + var stamp3 = new DateTimeStamp("2021-08-31T11:12:13.111-0100", 300); assertTrue(stamp1.compareTo(stamp2) < 0); assertTrue(stamp2.compareTo(stamp3) < 0); assertTrue(stamp1.compareTo(stamp3) < 0); @@ -466,26 +466,26 @@ void compareToTransitivity() { @Test void compareToTransitivityWithEqualTimeStamps() { - DateTimeStamp stamp1 = new DateTimeStamp("2021-09-01T11:12:13.111-0100", 100); - DateTimeStamp stamp2 = new DateTimeStamp((String)null, 100); - DateTimeStamp stamp3 = new DateTimeStamp("2021-08-31T11:12:13.111-0100", 100); - int comp1To2 = stamp1.compareTo(stamp2); - int comp2To3 = stamp2.compareTo(stamp3); + var stamp1 = new DateTimeStamp("2021-09-01T11:12:13.111-0100", 100); + var stamp2 = new DateTimeStamp((String)null, 100); + var stamp3 = new DateTimeStamp("2021-08-31T11:12:13.111-0100", 100); + var comp1To2 = stamp1.compareTo(stamp2); + var comp2To3 = stamp2.compareTo(stamp3); assertEquals(comp1To2, comp2To3); - int comp1To3 = stamp1.compareTo(stamp3); + var comp1To3 = stamp1.compareTo(stamp3); assertEquals(comp1To2, comp1To3, "compareTo() is not transitive"); } @Test void malformedDateTimeStampThrowsException() { - final DateTimeStamp onlyDate = new DateTimeStamp("2021-09-01T11:12:13.111-0100"); - final DateTimeStamp onlyTime = new DateTimeStamp(1.0D); + final var onlyDate = new DateTimeStamp("2021-09-01T11:12:13.111-0100"); + final var onlyTime = new DateTimeStamp(1.0D); assertThrows(IllegalStateException.class, () -> onlyDate.after(onlyTime)); } @Test void shouldParseGCLogLineWithBrackets() { - final String dateTimeString = "2025-05-08T11:07:55.681+0530"; + final var dateTimeString = "2025-05-08T11:07:55.681+0530"; final String gcLogLine = "[" + dateTimeString + "][gc,phases ] GC(4) Other: 0.2ms"; final DateTimeStamp dateTimeStamp = DateTimeStamp.fromGCLogLine(gcLogLine); final ZonedDateTime expected = ZonedDateTime.from(formatter.parse(dateTimeString)); diff --git a/parser/pom.xml b/parser/pom.xml index 44e603a9..52edb498 100644 --- a/parser/pom.xml +++ b/parser/pom.xml @@ -18,6 +18,10 @@ com.microsoft.gctoolkit gctoolkit-api + + org.jspecify + jspecify + org.junit.jupiter junit-jupiter-api diff --git a/parser/src/main/java/com/microsoft/gctoolkit/parser/AbstractLogTrace.java b/parser/src/main/java/com/microsoft/gctoolkit/parser/AbstractLogTrace.java index b702af83..c6102f1b 100644 --- a/parser/src/main/java/com/microsoft/gctoolkit/parser/AbstractLogTrace.java +++ b/parser/src/main/java/com/microsoft/gctoolkit/parser/AbstractLogTrace.java @@ -3,6 +3,7 @@ package com.microsoft.gctoolkit.parser; import com.microsoft.gctoolkit.time.DateTimeStamp; +import org.jspecify.annotations.Nullable; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -67,7 +68,7 @@ public double getTimeStamp() { return convertToDouble(matcher.group(1)); } - public String getDateStamp() { + public @Nullable String getDateStamp() { if (trace.find()) { return trace.group(4); } else { @@ -75,37 +76,32 @@ public String getDateStamp() { } } - /** - * - * @return the date timestamp paring found at the beginning of the GC log line. - */ + /// @return the date timestamp paring found at the beginning of the GC log line. public DateTimeStamp getDateTimeStamp() { return getDateTimeStamp(1); } - /** - * If a line contains multiple date timestamp group pairing then return the nth pair. - * The following example contains 3 different date timestamps. index of 1 yields 57724.218 - * whereas index 3 yields 2010-04-21T10:45:33.367+0100@57724.319 - * - * 57724.218: [Full GC 57724.218: [CMS2010-04-21T10:45:33.367+0100: 57724.319: [CMS-concurrent-mark: 2.519/2.587 secs] - * - * one time stamp or a date timestamp pairing - * @param nth is date timestamp field pair to be returned - * @return the nth date timestamp pairing - */ + /// If a line contains multiple date timestamp group pairing then return the nth pair. + /// The following example contains 3 different date timestamps. index of 1 yields 57724.218 + /// whereas index 3 yields 2010-04-21T10:45:33.367+0100@57724.319 + /// ` + /// 57724.218: [Full GC 57724.218: [CMS2010-04-21T10:45:33.367+0100: 57724.319: [CMS-concurrent-mark: 2.519/2.587 secs] + /// ` + /// one time stamp or a date timestamp pairing + /// @param nth is date timestamp field pair to be returned + /// @return the nth date timestamp pairing public DateTimeStamp getDateTimeStamp(int nth) { Matcher matcher; if ( nth > 1) { matcher = DATE_TIME_STAMP_RULE.matcher(trace.group(0)); - for (int i = 0; i < nth; i++) + for (var i = 0; i < nth; i++) if (!matcher.find()) break; } else matcher = trace; - String timeStamp = ( matcher.group(3) == null) ? matcher.group(4) : matcher.group(3); - String dateStamp = ( matcher.group(2) == null) ? matcher.group(5) : matcher.group(2); + String timeStamp = matcher.group(3) == null ? matcher.group(4) : matcher.group(3); + String dateStamp = matcher.group(2) == null ? matcher.group(5) : matcher.group(2); if (timeStamp != null) { return new DateTimeStamp(dateStamp, convertToDouble(timeStamp)); } else if ( dateStamp != null) @@ -113,7 +109,7 @@ public DateTimeStamp getDateTimeStamp(int nth) { return new DateTimeStamp(MISSING_TIMESTAMP_SENTINEL); } - public GCLogTrace next() { + public @Nullable GCLogTrace next() { if (trace.find()) return new GCLogTrace(trace); return null; diff --git a/parser/src/main/java/com/microsoft/gctoolkit/parser/CMSPatterns.java b/parser/src/main/java/com/microsoft/gctoolkit/parser/CMSPatterns.java index 927f8ab6..e7f5ff7e 100644 --- a/parser/src/main/java/com/microsoft/gctoolkit/parser/CMSPatterns.java +++ b/parser/src/main/java/com/microsoft/gctoolkit/parser/CMSPatterns.java @@ -2,13 +2,11 @@ // Licensed under the MIT License. package com.microsoft.gctoolkit.parser; -/** - * Patterns in the GC log associated with the Concurrent Mark and Sweep (CMS) - * Collector. - *

- * TODO The patterns could be split into separate files, e.g. ParNew, CMF and - * so on - */ +/// Patterns in the GC log associated with the Concurrent Mark and Sweep (CMS) +/// Collector. +/// +/// TODO The patterns could be split into separate files, e.g. ParNew, CMF and +/// so on public interface CMSPatterns extends SharedPatterns { //[Rescan (non-parallel) 139439.229: @@ -33,12 +31,12 @@ public interface CMSPatterns extends SharedPatterns { String CARD_SUMMARY = TIMESTAMP + "\\[CMS \\(cardTable: " + COUNTER + " cards, re-scanned " + COUNTER + " cards, " + COUNTER + " iterations\\)"; String FLS_LARGE_BLOCK_BODY = "CMS: Large block " + MEMORY_ADDRESS; - /****** Current working set *************/ + /// **** Current working set ************ GCParseRule REMARK_CLAUSE = new GCParseRule("REMARK_CLAUSE", REMARK_BLOCK); GCParseRule POOL_OCCUPANCY_HEAP_OCCUPANCY_BLOCK = new GCParseRule("POOL_OCCUPANCY_HEAP_OCCUPANCY_BLOCK", BEFORE_AFTER_CONFIGURED_PAUSE + "\\] " + BEFORE_AFTER_CONFIGURED + ", "); - /********** CMS Phase records **********/ + /// ******** CMS Phase records ********* //3.307: [GC [1 CMS-initial-mark: 0K(18874368K)] 302009K(20761856K), 0.0994470 secs] [Times: user=0.20 sys=0.00, real=0.10 secs] //12.986: [GC[1 CMS-initial-mark: 33532K(62656K)] 49652K(81280K), 0.0014191 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] //40.971: [GC (CMS Initial Mark) [1 CMS-initial-mark: 2692K(5376K)] 38078K(354944K), 0.0147940 secs] [Times: user=0.01 sys=0.00, real=0.02 secs] @@ -52,7 +50,7 @@ public interface CMSPatterns extends SharedPatterns { GCParseRule CONCURRENT_PHASE_END_BLOCK = new GCParseRule("CONCURRENT_PHASE_END_BLOCK", CMS_PHASE_END + " " + CPU_SUMMARY); GCParseRule ABORT_PRECLEAN_DUE_TO_TIME_CLAUSE = new GCParseRule("ABORT_PRECLEAN_DUE_TO_TIME_CLAUSE", "^" + ABORT_PRECLEAN_DUE_TO_TIME_BLOCK); - /********** Remark statements **********/ + /// ******** Remark statements ********* //, 0.0404150 secs]204737.599: [weak refs processing, 0.0112190 secs] [1 CMS-remark: 30259925K(60327552K)] 30338613K(60768448K), 0.0528880 secs] String REMARK_DETAILS_BLOCK = ", " + PAUSE_TIME + "\\]" + WEAK_REF_BLOCK + "(?:" + STRING_TABLE_SCRUB_BLOCK + ")? " + REMARK_BLOCK; GCParseRule REMARK_DETAILS = new GCParseRule("REMARK_DETAILS", "^" + REMARK_DETAILS_BLOCK); @@ -101,7 +99,7 @@ public interface CMSPatterns extends SharedPatterns { //11.980: [Rescan (parallel) , 0.0085120 secs]11.988: [weak refs processing, 0.0000210 secs]11.988: [class unloading, 0.0097120 secs]11.998: [scrub symbol & string tables, 0.0073130 secs] [1 CMS-remark: 0K(18874368K)] 28278K(20761856K), 0.0462600 secs] GCParseRule PARALLEL_RESCAN_WEAK_CLASS_SCRUB = new GCParseRule("PARALLEL_RESCAN_WEAK_CLASS_SCRUB", "^" + DATE_TIMESTAMP + "\\[Rescan \\(parallel\\) , " + PAUSE_TIME + "\\]" + WEAK_REF_BLOCK + CLASS_UNLOADING_BLOCK + STRING_AND_SYMBOL_SCRUB_BLOCK + " " + REMARK_BLOCK); - /********** ParNew records **********/ + /// ******** ParNew records ********* //48.021: [GC48.021: [ParNew: 306686K->34046K(306688K), 0.3196120 secs] 1341473K->1125818K(8669952K), 0.3197540 secs] GCParseRule PARNEW = new GCParseRule("PARNEW", "^(" + GC_PREFIX + ")?" + PARNEW_BLOCK + " " + BEFORE_AFTER_CONFIGURED_PAUSE + "\\]"); @@ -153,7 +151,7 @@ public interface CMSPatterns extends SharedPatterns { //(concurrent mode failure)10.103: [SoftReference, 0 refs, 0.0000148 secs]10.103: [WeakReference, 130 refs, 0.0000052 secs]10.103: [FinalReference, 848 refs, 0.0000175 secs]10.103: [PhantomReference, 0 refs, 0 refs, 0.0000029 secs]10.103: [JNI Weak Reference, 0.0000052 secs]: 172902K->6834K(174784K), 0.0106416 secs] 244864K->6834K(253440K), [Metaspace: 11290K->11290K(1058816K)], 0.0116373 secs] [Times: user=0.01 sys=0.01, real=0.01 secs] GCParseRule CONCURRENT_MODE_FAILURE_REFERENCE = new GCParseRule("CONCURRENT_MODE_FAILURE_REFERENCE", "^\\(concurrent mode failure\\)" + REFERENCE_RECORDS + ": " + BEFORE_AFTER_CONFIGURED_PAUSE + "\\] " + BEFORE_AFTER_CONFIGURED + ", " + PERM_RECORD + ", " + PAUSE_TIME + "\\]"); - /********** Concurrent Mode Failures (CMF) *********/ + /// ******** Concurrent Mode Failures (CMF) ******** //12525.344: [Full GC 12525.344: [ParNew GCParseRule FULL_PARNEW_START = new GCParseRule("FULL_PARNEW_START", FULL_GC_PREFIX + TIMESTAMP + "\\[ParNew$"); @@ -274,9 +272,9 @@ public interface CMSPatterns extends SharedPatterns { //2016-04-01T14:25:57.870-0700: 8761.336: [Full GC (GCLocker Initiated GC)2016-04-01T14:25:57.871-0700: 8761.336: [CMS (concurrent mode failure)2016-04-01T14:25:59.160-0700: 8762.626: [SoftReference, 541 refs, 0.0001800 secs]2016-04-01T14:25:59.160-0700: 8762.626: [WeakReference, 21658 refs, 0.0024960 secs]2016-04-01T14:25:59.163-0700: 8762.628: [FinalReference, 4142 refs, 0.0033170 secs]2016-04-01T14:25:59.166-0700: 8762.632: [PhantomReference, 194 refs, 0.0000550 secs]2016-04-01T14:25:59.166-0700: 8762.632: [JNI Weak Reference, 0.0000220 secs]: 4186495K->665385K(4218880K), 3.8356980 secs] 4448832K->665385K(5946048K), [CMS Perm : 417612K->417612K(1048576K)], 3.8379940 secs] [Times: user=3.84 sys=0.02, real=3.83 secs] GCParseRule FULL_GC_REFERENCE_CMF = new GCParseRule("FULL_GC_REFERENCE_CMF", FULL_GC_PREFIX + DATE_TIMESTAMP + "\\[CMS \\(concurrent mode failure\\)" + REFERENCE_RECORDS + ": " + BEFORE_AFTER_CONFIGURED_PAUSE + "\\] " + BEFORE_AFTER_CONFIGURED + ", " + PERM_RECORD + ", " + PAUSE_TIME); - /********** - * Record with debug information - * *********/ + /// ******** + /// Record with debug information + /// ******** String CMS_SCANNING = TIMESTAMP + "\\[(?:CMS|Tenured)( \\(concurrent mode failure\\))?Finished (generational|perm) space scanning in " + INTEGER + "th thread: " + PAUSE_TIME; //257.311: [GC 257.311: [ParNew (promotion failed): 1887488K->1887488K(1887488K), 20.7438090 secs]26278.055: [CMSFinished generational space scanning in 0th thread: 50.866 sec diff --git a/parser/src/main/java/com/microsoft/gctoolkit/parser/CMSTenuredPoolParser.java b/parser/src/main/java/com/microsoft/gctoolkit/parser/CMSTenuredPoolParser.java index a5f6dd59..0a47cc3a 100644 --- a/parser/src/main/java/com/microsoft/gctoolkit/parser/CMSTenuredPoolParser.java +++ b/parser/src/main/java/com/microsoft/gctoolkit/parser/CMSTenuredPoolParser.java @@ -36,6 +36,7 @@ public Set eventsProduced() { return Set.of(EventSource.CMS_PREUNIFIED); } + @Override public String getName() { return ChannelName.CMS_TENURED_POOL_PARSER_OUTBOX.toString(); } @@ -67,13 +68,11 @@ else if ((trace = EndOfFile.parse(line)) != null) { } } - /** - * 12.986: [GC[1 CMS-initial-mark: 33532K(62656K)] 49652K(81280K), 0.0014191 secs] - * null,12.986,null,null,null,null,33532,K,62656,K,null,null,null,49652,K,81280,K,0.0014191 - * first 6 is the date. - */ + /// 12.986: [GC[1 CMS-initial-mark: 33532K(62656K)] 49652K(81280K), 0.0014191 secs] + /// null,12.986,null,null,null,null,33532,K,62656,K,null,null,null,49652,K,81280,K,0.0014191 + /// first 6 is the date. private void initialMark(GCLogTrace trace) { - InitialMark initialMark = new InitialMark(trace.getDateTimeStamp(), GCCause.UNKNOWN_GCCAUSE, trace.getDoubleGroup(trace.groupCount())); + var initialMark = new InitialMark(trace.getDateTimeStamp(), GCCause.UNKNOWN_GCCAUSE, trace.getDoubleGroup(trace.groupCount())); MemoryPoolSummary tenured = trace.getOccupancyWithMemoryPoolSizeSummary(7); MemoryPoolSummary heap = trace.getOccupancyWithMemoryPoolSizeSummary(11); initialMark.add(heap.minus(tenured), tenured, heap); @@ -93,16 +92,16 @@ private void endOfConcurrentPhase(GCLogTrace trace) { private void endConcurrentPrecleanWithReferenceProcessing(GCLogTrace trace) { try { publish(new ConcurrentPreClean(startOfPhase, trace.getDoubleGroup(14) - startOfPhase.getTimeStamp(), trace.getDoubleGroup(16), trace.getDoubleGroup(17))); - } catch (Throwable t) { + } catch (Throwable _) { LOG.warning("concurrent phase choked on " + trace.toString()); } } private void endOfConcurrentPhase(GCLogTrace trace, DateTimeStamp timeStamp) { String phase = trace.getGroup(6); - double cpuTime = trace.getDoubleGroup(7); - double wallTime = trace.getDoubleGroup(8); - double duration = timeStamp.getTimeStamp() - startOfPhase.getTimeStamp(); + var cpuTime = trace.getDoubleGroup(7); + var wallTime = trace.getDoubleGroup(8); + var duration = timeStamp.getTimeStamp() - startOfPhase.getTimeStamp(); if ("mark".equals(phase)) publish(new ConcurrentMark(startOfPhase, duration, cpuTime, wallTime)); else if ("preclean".equals(phase)) @@ -119,10 +118,10 @@ else if ("reset".equals(phase)) private void abortPrecleanDueToTime(GCLogTrace trace) { try { - double cpuTime = trace.getDoubleGroup(7); - double wallClock = trace.getDoubleGroup(8); + var cpuTime = trace.getDoubleGroup(7); + var wallClock = trace.getDoubleGroup(8); publish(new AbortablePreClean(startOfPhase, trace.getDateTimeStamp().getTimeStamp() - startOfPhase.getTimeStamp(), cpuTime, wallClock, true)); - } catch (Exception e) { + } catch (Exception _) { LOG.warning("concurrent phase end choked on " + trace); } } @@ -148,7 +147,7 @@ private CMSRemark extractRemark(GCLogTrace trace, String line) { gcCause = GCCause.CMS_FINAL_REMARK; } - CMSRemark remark = new CMSRemark(startOfPhase, gcCause, trace.getDoubleGroup(trace.groupCount())); + var remark = new CMSRemark(startOfPhase, gcCause, trace.getDoubleGroup(trace.groupCount())); try { MemoryPoolSummary tenured = trace.getOccupancyWithMemoryPoolSizeSummary(1); @@ -156,7 +155,7 @@ private CMSRemark extractRemark(GCLogTrace trace, String line) { remark.add(heap.minus(tenured), tenured, heap); recordRescanStepTimes(remark, line); remark.add(extractPrintReferenceGC(line)); - } catch (Exception e) { + } catch (Exception _) { LOG.warning("Unable to properly extract data from " + trace); } return remark; diff --git a/parser/src/main/java/com/microsoft/gctoolkit/parser/ForwardReference.java b/parser/src/main/java/com/microsoft/gctoolkit/parser/ForwardReference.java index 3969d219..45f7b0dc 100644 --- a/parser/src/main/java/com/microsoft/gctoolkit/parser/ForwardReference.java +++ b/parser/src/main/java/com/microsoft/gctoolkit/parser/ForwardReference.java @@ -64,9 +64,7 @@ public void add(CPUSummary cpuSummary) { this.cpuSummary = cpuSummary; } - /** - * @return the decorators - */ + /// @return the decorators Decorators getDecorators() { return decorators; } diff --git a/parser/src/main/java/com/microsoft/gctoolkit/parser/G1GCForwardReference.java b/parser/src/main/java/com/microsoft/gctoolkit/parser/G1GCForwardReference.java index dd3a1b29..f07a4f4b 100644 --- a/parser/src/main/java/com/microsoft/gctoolkit/parser/G1GCForwardReference.java +++ b/parser/src/main/java/com/microsoft/gctoolkit/parser/G1GCForwardReference.java @@ -113,9 +113,7 @@ GarbageCollectionTypes getConcurrentPhase() { } - /** - * memory pool statistics - */ + /// memory pool statistics private static final int HEAP_OCCUPANCY_BEFORE_COLLECTION = 0; private static final int HEAP_OCCUPANCY_AFTER_COLLECTION = 1; private static final int HEAP_SIZE_BEFORE_COLLECTION = 2; @@ -386,7 +384,7 @@ private boolean hasReferenceGCSummary() { } private ReferenceGCSummary generateReferenceGCSummary() { - ReferenceGCSummary summary = new ReferenceGCSummary(); + var summary = new ReferenceGCSummary(); summary.addSoftReferences(getStartTime(), referenceCounts[SOFT_REFERENCE], referenceProcessingDuarations[SOFT_REFERENCE]); summary.addWeakReferences(getStartTime(), referenceCounts[WEAK_REFERENCE], referenceProcessingDuarations[WEAK_REFERENCE]); summary.addPhantomReferences(getStartTime(), referenceCounts[PHANTOM_REFERENCE], referenceProcessingDuarations[PHANTOM_REFERENCE]); @@ -532,7 +530,7 @@ private MemoryPoolSummary getMemoryPoolSummary(int offset) { if (memoryPoolMeasurment[offset + OCCUPANCY_BEFORE_OFFSET] == -1L) //do we have recorded values return null; //do we know the size of the memory pool prior to the collection - long sizeBeforeCollection = (memoryPoolMeasurment[offset + SIZE_BEFORE_OFFSET] > -1L) ? memoryPoolMeasurment[offset + SIZE_BEFORE_OFFSET] : memoryPoolMeasurment[offset + SIZE_AFTER_OFFSET]; + long sizeBeforeCollection = memoryPoolMeasurment[offset + SIZE_BEFORE_OFFSET] > -1L ? memoryPoolMeasurment[offset + SIZE_BEFORE_OFFSET] : memoryPoolMeasurment[offset + SIZE_AFTER_OFFSET]; return new MemoryPoolSummary(memoryPoolMeasurment[offset + OCCUPANCY_BEFORE_OFFSET], sizeBeforeCollection, memoryPoolMeasurment[offset + OCCUPANCY_AFTER_OFFSET], memoryPoolMeasurment[offset + SIZE_AFTER_OFFSET]); } @@ -570,7 +568,7 @@ enum REGIONS { SURVIVOR, OLD, HUMONGOUS, - ARCHIVE; + ARCHIVE } private final RegionSummary[] regionSummaries = new RegionSummary[REGIONS.values().length]; @@ -636,7 +634,7 @@ private void fillInRegionSummary(G1GCPauseEvent collection) { } private void fullInInternalPhases(G1FullGC collection) { - int index = 0; + var index = 0; String key; while ((key = fullGCInternalPhaseOrder.get(++index)) != null) { collection.addInternalPhase(key, fullGCInternalPhases.get(key)); @@ -733,10 +731,8 @@ G1GCConcurrentEvent buildConcurrentUndoCycleEvent() { return new G1ConcurrentUndoCycle(getConcurrentCycleStartTime(), getDuration()); } - /** - * gcType == null -> likely an incomplete record. - * @return - */ + /// gcType == null -> likely an incomplete record. + /// @return G1GCPauseEvent buildEvent() throws MalformedEvent { if (gcType == null ) { throw new MalformedEvent("G1GC Event type is undefined (null): " + this.toString()); @@ -799,7 +795,7 @@ private G1Mixed buildMixed() { private G1ConcurrentMark buildConcurrentMark() { - G1ConcurrentMark concurrentMark = new G1ConcurrentMark(getStartTime(), getDuration()); + var concurrentMark = new G1ConcurrentMark(getStartTime(), getDuration()); if (aborted) concurrentMark.abort(); if (markFromRootsDuration > -1.0d) { @@ -815,7 +811,7 @@ private G1ConcurrentMark buildConcurrentMark() { } private G1Remark buildRemark() { - G1Remark remark = new G1Remark(pausePhaseDuringConcurrentCycleTime, 0.0d, pausePhaseDuringConcurrentCycleDuration); + var remark = new G1Remark(pausePhaseDuringConcurrentCycleTime, 0.0d, pausePhaseDuringConcurrentCycleDuration); if (hasReferenceGCSummary()) remark.add(generateReferenceGCSummary()); fillInMemoryPoolStats(remark); @@ -824,7 +820,7 @@ private G1Remark buildRemark() { } private G1Cleanup buildCleanup() { - G1Cleanup cleanup = new G1Cleanup(pausePhaseDuringConcurrentCycleTime, pausePhaseDuringConcurrentCycleDuration); + var cleanup = new G1Cleanup(pausePhaseDuringConcurrentCycleTime, pausePhaseDuringConcurrentCycleDuration); fillInMemoryPoolStats(cleanup); cleanup.addCPUSummary(getCPUSummary()); return cleanup; @@ -870,13 +866,12 @@ void fullPhase(int integerGroup, String fullGCInternalPhase, double duration) { fullGCInternalPhases.put(fullGCInternalPhase, duration); } - /** - * Not that this value will be printed but having toString() defined is useful for debugging. The issue is - * null values for gctype and gcCause will cause IDE debuggers to NPE. Capture and set to null. - * @return String rep of this forward reference. - */ + /// Not that this value will be printed but having toString() defined is useful for debugging. The issue is + /// null values for gctype and gcCause will cause IDE debuggers to NPE. Capture and set to null. + /// @return String rep of this forward reference. + @Override public String toString() { - return getStartTime().toString() + " : " + ((gcType == null) ? "null" : gcType.toString()) + " : " + ((getGCCause() == null) ? "null" : getGCCause().toString()) + " : " + getDuration(); + return getStartTime().toString() + " : " + (gcType == null ? "null" : gcType.toString()) + " : " + (getGCCause() == null ? "null" : getGCCause().toString()) + " : " + getDuration(); } boolean setArchiveOccupancyBeforeCollection(int value) { diff --git a/parser/src/main/java/com/microsoft/gctoolkit/parser/G1GCPatterns.java b/parser/src/main/java/com/microsoft/gctoolkit/parser/G1GCPatterns.java index a981ff59..e126b01c 100644 --- a/parser/src/main/java/com/microsoft/gctoolkit/parser/G1GCPatterns.java +++ b/parser/src/main/java/com/microsoft/gctoolkit/parser/G1GCPatterns.java @@ -2,15 +2,13 @@ // Licensed under the MIT License. package com.microsoft.gctoolkit.parser; -/** - * Supported flags - * -XX:+PrintGCDateStamps - * -XX:+PrintGCDetails - * -XX:+PrintTenuringDistribution - * -XX:+PrintAdaptiveSizePolicy - * -XX:+PrintReferenceGC - * -XX:+G1SummarizeRSetStats -XX:+G1SumerizeRsetStatsPeriod=1 - */ +/// Supported flags +/// -XX:+PrintGCDateStamps +/// -XX:+PrintGCDetails +/// -XX:+PrintTenuringDistribution +/// -XX:+PrintAdaptiveSizePolicy +/// -XX:+PrintReferenceGC +/// -XX:+G1SummarizeRSetStats -XX:+G1SumerizeRsetStatsPeriod=1 public interface G1GCPatterns extends G1GCTokens { diff --git a/parser/src/main/java/com/microsoft/gctoolkit/parser/GCLogParser.java b/parser/src/main/java/com/microsoft/gctoolkit/parser/GCLogParser.java index 6dcd1078..8b5ade0d 100644 --- a/parser/src/main/java/com/microsoft/gctoolkit/parser/GCLogParser.java +++ b/parser/src/main/java/com/microsoft/gctoolkit/parser/GCLogParser.java @@ -18,81 +18,59 @@ import java.util.logging.Level; import java.util.logging.Logger; -/** - * Abstract class representing a parser for GC log files. - * Implements the DataSourceParser and SharedPatterns interfaces. - */ +/// Abstract class representing a parser for GC log files. +/// Implements the DataSourceParser and SharedPatterns interfaces. public abstract class GCLogParser implements DataSourceParser, SharedPatterns { private static final Logger LOGGER = Logger.getLogger(GCLogParser.class.getName()); - /** - * Special string to indicate the end of the data in the GC log. - */ + /// Special string to indicate the end of the data in the GC log. public static final String END_OF_DATA_SENTINEL = GCLogFile.END_OF_DATA_SENTINEL; // TODO: GCID_COUNTER should be in SharedPatterns, not here. - /** - * Rule for parsing the GCID counter. - */ + /// Rule for parsing the GCID counter. public static final GCParseRule GCID_COUNTER = new GCParseRule("GCID_COUNTER", " GC\\((\\d+)\\) "); private JVMEventChannel consumer; protected Diary diary; private DateTimeStamp clock = new DateTimeStamp(DateTimeStamp.EPOC, 0.0d); private double lastDuration = 0.0d; - /** - * Default constructor. - */ + /// Default constructor. public GCLogParser() {} - /** - * Sets the diary and initializes the clock to the time of the first event in the GC log. - * @param diary summary of the GC log. - */ + /// Sets the diary and initializes the clock to the time of the first event in the GC log. + /// @param diary summary of the GC log. @Override public void diary(Diary diary) { this.diary = diary; this.clock = diary.getTimeOfFirstEvent(); } - /** - * Gets the current clock time. - * @return the current DateTimeStamp. - */ + /// Gets the current clock time. + /// @return the current DateTimeStamp. public DateTimeStamp getClock() { return clock; } - /** - * Sets the clock to a new value. - * @param newValue the new DateTimeStamp value. - */ + /// Sets the clock to a new value. + /// @param newValue the new DateTimeStamp value. public void setClock(DateTimeStamp newValue) { this.clock = newValue; } - /** - * Abstract method to get the name of the parser. - * @return the name of the parser. - */ + /// Abstract method to get the name of the parser. + /// @return the name of the parser. public abstract String getName(); - /** - * Abstract method to process a trace line from the GC log. - * @param trace the trace line to process. - */ + /// Abstract method to process a trace line from the GC log. + /// @param trace the trace line to process. protected abstract void process(String trace); - /** - * Abstract method to advance the clock based on a record. - * @param record the record to use for advancing the clock. - */ + /// Abstract method to advance the clock based on a record. + /// @param record the record to use for advancing the clock. abstract void advanceClock(String record); - /** - * Advances the clock to the specified time. - * @param now the new DateTimeStamp. - */ + /// Advances the clock to the specified time. + /// @param now the new DateTimeStamp. protected final void advanceClock(DateTimeStamp now) { if (now == null) return; @@ -102,81 +80,66 @@ else if (now.before(getClock())) { setClock(now); } - /** - * Publishes a JVM event to the specified channel. - * @param channel the channel to publish to. - * @param event the event to be published. - */ + /// Publishes a JVM event to the specified channel. + /// @param channel the channel to publish to. + /// @param event the event to be published. public void publish(ChannelName channel, JVMEvent event) { lastDuration = event.getDuration(); consumer.publish(channel, event); } - /** - * Receives a trace line and processes it. - * @param trace the trace line to process. - */ + /// Receives a trace line and processes it. + /// @param trace the trace line to process. + @Override public void receive(String trace) { - if (!trace.equals(END_OF_DATA_SENTINEL)) + if (!END_OF_DATA_SENTINEL.equals(trace)) advanceClock(trace); else advanceClock(getClock().add(lastDuration)); process(trace); } - /** - * Checks if the diary indicates a pre-JDK 1.7.0_40 version. - * @return true if pre-JDK 1.7.0_40, false otherwise. - */ + /// Checks if the diary indicates a pre-JDK 1.7.0_40 version. + /// @return true if pre-JDK 1.7.0_40, false otherwise. boolean isPreJDK17040() { return diary.isPre70_40(); } - /** - * Checks if the diary has PrintGCDetails enabled. - * @return true if PrintGCDetails is enabled, false otherwise. - */ + /// Checks if the diary has PrintGCDetails enabled. + /// @return true if PrintGCDetails is enabled, false otherwise. boolean hasPrintGCDetails() { return diary.isPrintGCDetails(); } - /** - * Extracts a MemoryPoolSummary from a GCLogTrace. - * @param trace the GCLogTrace to extract from. - * @param offset the offset to use. - * @return the extracted MemoryPoolSummary. - */ + /// Extracts a MemoryPoolSummary from a GCLogTrace. + /// @param trace the GCLogTrace to extract from. + /// @param offset the offset to use. + /// @return the extracted MemoryPoolSummary. MemoryPoolSummary getTotalOccupancyBeforeAfterWithTotalHeapPoolSizeSummary(GCLogTrace trace, int offset) { return trace.getOccupancyBeforeAfterWithMemoryPoolSizeSummary(offset); } - /** - * Extracts a MemoryPoolSummary from a GCLogTrace. - * @param trace the GCLogTrace to extract from. - * @param offset the offset to use. - * @return the extracted MemoryPoolSummary. - */ + /// Extracts a MemoryPoolSummary from a GCLogTrace. + /// @param trace the GCLogTrace to extract from. + /// @param offset the offset to use. + /// @return the extracted MemoryPoolSummary. MemoryPoolSummary getTotalOccupancyWithTotalHeapSizeSummary(GCLogTrace trace, int offset) { return trace.getOccupancyWithMemoryPoolSizeSummary(offset); } - /** - * Extracts a GCLogTrace from a line using a specified GCParseRule. - * @param line the line to parse. - * @param rule the GCParseRule to use. - * @return the extracted GCLogTrace. - */ + /// Extracts a GCLogTrace from a line using a specified GCParseRule. + /// @param line the line to parse. + /// @param rule the GCParseRule to use. + /// @return the extracted GCLogTrace. GCLogTrace extractReferenceBlock(String line, GCParseRule rule) { return rule.parse(line); } - /** - * Extracts a ReferenceGCSummary from a line. - * @param line the line to parse. - * @return the extracted ReferenceGCSummary. - */ + /// Extracts a ReferenceGCSummary from a line. + /// @param line the line to parse. + /// @return the extracted ReferenceGCSummary. ReferenceGCSummary extractPrintReferenceGC(String line) { - ReferenceGCSummary summary = new ReferenceGCSummary(); + var summary = new ReferenceGCSummary(); GCLogTrace trace; if ((trace = extractReferenceBlock(line, SOFT_REFERENCE)) != null) summary.addSoftReferences(trace.getDateTimeStamp(), trace.getIntegerGroup(6), trace.getDuration()); @@ -199,11 +162,9 @@ ReferenceGCSummary extractPrintReferenceGC(String line) { return summary; } - /** - * Extracts a MemoryPoolSummary from a line representing PermGen or Metaspace records. - * @param line the line to parse. - * @return the extracted MemoryPoolSummary. - */ + /// Extracts a MemoryPoolSummary from a line representing PermGen or Metaspace records. + /// @param line the line to parse. + /// @return the extracted MemoryPoolSummary. MemoryPoolSummary extractPermOrMetaspaceRecord(String line) { GCLogTrace trace; MemoryPoolSummary metaDataPool = null; @@ -225,37 +186,31 @@ MemoryPoolSummary extractPermOrMetaspaceRecord(String line) { break; } } else if ((trace = META_SPACE_RECORD.parse(line)) != null) { - int index = (trace.getGroup(1) == null) ? 1 : 3; + int index = trace.getGroup(1) == null ? 1 : 3; metaDataPool = new MetaspaceRecord(trace.toKBytes(index), trace.toKBytes(3), trace.toKBytes(5)); } return metaDataPool; } - /** - * Extracts a PermGenSummary from a GCLogTrace. - * @param trace the GCLogTrace to extract from. - * @return the extracted PermGenSummary. - */ + /// Extracts a PermGenSummary from a GCLogTrace. + /// @param trace the GCLogTrace to extract from. + /// @return the extracted PermGenSummary. MemoryPoolSummary extractPermGenRecord(GCLogTrace trace) { - int index = (trace.getGroup(2) == null) ? 2 : 4; + int index = trace.getGroup(2) == null ? 2 : 4; return new PermGenSummary(trace.getLongGroup(index), trace.getLongGroup(4), trace.getLongGroup(6)); } - /** - * Extracts the GCID from a line. - * @param line the line to parse. - * @return the extracted GCID, or -1 if not found. - */ + /// Extracts the GCID from a line. + /// @param line the line to parse. + /// @return the extracted GCID, or -1 if not found. int extractGCID(String line) { GCLogTrace trace = GCID_COUNTER.parse(line); - return (trace != null) ? trace.getIntegerGroup(1) : -1; + return trace != null ? trace.getIntegerGroup(1) : -1; } - /** - * Extracts a CPUSummary from a line. - * @param line the line to parse. - * @return the extracted CPUSummary, or null if not found. - */ + /// Extracts a CPUSummary from a line. + /// @param line the line to parse. + /// @return the extracted CPUSummary, or null if not found. CPUSummary extractCPUSummary(String line) { GCLogTrace trace; if ((trace = CPU_BREAKDOWN.parse(line)) != null) { @@ -264,19 +219,15 @@ CPUSummary extractCPUSummary(String line) { return null; } - /** - * Sets the JVMEventChannel to publish to. - * @param channel the channel to publish to. - */ + /// Sets the JVMEventChannel to publish to. + /// @param channel the channel to publish to. @Override public void publishTo(JVMEventChannel channel) { this.consumer = channel; } - /** - * Gets the channel name. - * @return the channel name. - */ + /// Gets the channel name. + /// @return the channel name. @Override public ChannelName channel() { return ChannelName.DATA_SOURCE; diff --git a/parser/src/main/java/com/microsoft/gctoolkit/parser/GCLogTrace.java b/parser/src/main/java/com/microsoft/gctoolkit/parser/GCLogTrace.java index 40f210f2..df37fb8c 100644 --- a/parser/src/main/java/com/microsoft/gctoolkit/parser/GCLogTrace.java +++ b/parser/src/main/java/com/microsoft/gctoolkit/parser/GCLogTrace.java @@ -12,15 +12,14 @@ import com.microsoft.gctoolkit.event.jvm.MetaspaceRecord; import com.microsoft.gctoolkit.event.jvm.PermGenSummary; import com.microsoft.gctoolkit.event.zgc.ZGCPhase; +import org.jspecify.annotations.Nullable; import java.util.logging.Level; import java.util.logging.Logger; import java.util.regex.Matcher; -/** - * Class that represents a chunk of GC log that we are attempting to match to a - * known GC log pattern - */ +/// Class that represents a chunk of GC log that we are attempting to match to a +/// known GC log pattern public class GCLogTrace extends AbstractLogTrace { private static final Logger LOGGER = Logger.getLogger(GCLogTrace.class.getName()); @@ -31,18 +30,22 @@ public GCLogTrace(Matcher matcher) { super(matcher); } + @Override public int groupCount() { return trace.groupCount(); } + @Override public boolean groupNotNull(int index) { return getGroup(index) != null; } + @Override public long getLongGroup(int index) { return Long.parseLong(trace.group(index)); } + @Override public int getIntegerGroup(int index) { return Integer.parseInt(trace.group(index)); } @@ -77,28 +80,22 @@ public double getDurationInSeconds() { return getDuration() / 1000.00d; } - /** - * Annoyingly we're assuming the field actually is ms instead of confirming - * @param index Index of the capture group. - * @return The capture group parsed to a double. - */ + /// Annoyingly we're assuming the field actually is ms instead of confirming + /// @param index Index of the capture group. + /// @return The capture group parsed to a double. public double getMilliseconds(int index) { return getDoubleGroup(index); } - /** - * Annoyingly we're assuming the field actually is s instead of confirming - * @param index Index of the capture group. - * @return The capture group parsed to a double. - */ + /// Annoyingly we're assuming the field actually is s instead of confirming + /// @param index Index of the capture group. + /// @return The capture group parsed to a double. public double getSeconds(int index) { return getDoubleGroup(index); } - /** - * Assumed to be the last capture group - * @return The last capture group parsed to a double. - */ + /// Assumed to be the last capture group + /// @return The last capture group parsed to a double. public double getMilliseconds() { return getMilliseconds(groupCount()); } @@ -120,7 +117,7 @@ public String toString() { } public boolean hasNext() { - return (trace.find()); + return trace.find(); } public int end() { @@ -136,7 +133,7 @@ public long doubleToKBytes(int offset) { } private double toKBytes(double value, String units) { - double returnValue = value; + var returnValue = value; switch (Character.toUpperCase(units.codePointAt(0))) { case 'G': returnValue *= 1024.0D; @@ -154,7 +151,7 @@ private double toKBytes(double value, String units) { } public long toKBytes(long value, String units) { - long returnValue = value; + var returnValue = value; switch (Character.toUpperCase(units.codePointAt(0))) { case 'G': returnValue *= 1024L; @@ -172,26 +169,26 @@ public long toKBytes(long value, String units) { return returnValue; } - public PermGenSummary getMetaspaceSummary(int offset) { + public @Nullable PermGenSummary getMetaspaceSummary(int offset) { try { - long before = toKBytes(offset); - long after = toKBytes(offset + 2); - long size = toKBytes(offset + 4); + var before = toKBytes(offset); + var after = toKBytes(offset + 2); + var size = toKBytes(offset + 4); return new PermGenSummary(before, after, size); - } catch (NumberFormatException numberFormatException) { + } catch (NumberFormatException _) { LOGGER.fine("Unable to calculate Metaspace summary."); notYetImplemented(); } return null; } - public MemoryPoolSummary getOccupancyBeforeAfterWithMemoryPoolSizeSummary(int offset) { + public @Nullable MemoryPoolSummary getOccupancyBeforeAfterWithMemoryPoolSizeSummary(int offset) { try { - long before = toKBytes(offset); - long after = toKBytes(offset + 2); - long size = toKBytes(offset + 4); + var before = toKBytes(offset); + var after = toKBytes(offset + 2); + var size = toKBytes(offset + 4); return new MemoryPoolSummary(before, size, after, size); - } catch (NumberFormatException numberFormatException) { + } catch (NumberFormatException _) { LOGGER.warning("Unable to calculate generational memory pool summary."); notYetImplemented(); } @@ -199,13 +196,13 @@ public MemoryPoolSummary getOccupancyBeforeAfterWithMemoryPoolSizeSummary(int of return null; } - public MemoryPoolSummary getOccupancyWithMemoryPoolSizeSummary(int offset) { + public @Nullable MemoryPoolSummary getOccupancyWithMemoryPoolSizeSummary(int offset) { try { - long occupancy = toKBytes(offset); - long size = toKBytes(offset + 2); + var occupancy = toKBytes(offset); + var size = toKBytes(offset + 2); return new MemoryPoolSummary(occupancy, size, occupancy, size); - } catch (NumberFormatException numberFormatException) { + } catch (NumberFormatException _) { LOGGER.fine("Unable to calculate generational memory pool occupancy summary."); notYetImplemented(); } @@ -213,13 +210,13 @@ public MemoryPoolSummary getOccupancyWithMemoryPoolSizeSummary(int offset) { return null; } - public MemoryPoolSummary getOccupancyWithMemoryPoolSizeSummary() { + public @Nullable MemoryPoolSummary getOccupancyWithMemoryPoolSizeSummary() { try { - long occupancy = toKBytes(1); - long size = toKBytes(3); + var occupancy = toKBytes(1); + var size = toKBytes(3); return new MemoryPoolSummary(occupancy, size, occupancy, size); - } catch (NumberFormatException numberFormatException) { + } catch (NumberFormatException _) { LOGGER.fine("Unable to calculate generational memory pool occupancy summary."); notYetImplemented(); } @@ -227,40 +224,40 @@ public MemoryPoolSummary getOccupancyWithMemoryPoolSizeSummary() { return null; } - public MetaspaceRecord getMetaSpaceRecord(int offset) { + public @Nullable MetaspaceRecord getMetaSpaceRecord(int offset) { try { - long before = toKBytes(offset); - long after = toKBytes(offset + 2); - long size = toKBytes(offset + 4); + var before = toKBytes(offset); + var after = toKBytes(offset + 2); + var size = toKBytes(offset + 4); return new MetaspaceRecord(before, after, size); - } catch (NumberFormatException numberFormatException) { + } catch (NumberFormatException _) { LOGGER.fine("Unable to calculate Metaspace summary."); notYetImplemented(); } return null; } - public MetaspaceRecord getEnlargedMemoryPoolRecord(int offset) { + public @Nullable MetaspaceRecord getEnlargedMemoryPoolRecord(int offset) { try { - long before = toKBytes(offset); - long after = toKBytes(offset + 4); - long size = toKBytes(offset + 6); + var before = toKBytes(offset); + var after = toKBytes(offset + 4); + var size = toKBytes(offset + 6); return new MetaspaceRecord(before, after, size); - } catch (NumberFormatException numberFormatException) { + } catch (NumberFormatException _) { LOGGER.fine("Unable to calculate Metaspace summary."); notYetImplemented(); } return null; } - public MetaspaceRecord getEnlargedMetaSpaceRecord(int offset) { + public @Nullable MetaspaceRecord getEnlargedMetaSpaceRecord(int offset) { try { - long before = toKBytes(offset); - long sizeBefore = toKBytes(offset + 2); - long after = toKBytes(offset + 4); - long size = toKBytes(offset + 6); + var before = toKBytes(offset); + var sizeBefore = toKBytes(offset + 2); + var after = toKBytes(offset + 4); + var size = toKBytes(offset + 6); return new MetaspaceRecord(before, sizeBefore, after, size); - } catch (NumberFormatException numberFormatException) { + } catch (NumberFormatException _) { LOGGER.fine("Unable to calculate Metaspace summary."); notYetImplemented(); } @@ -278,22 +275,22 @@ public UnifiedCountSummary countSummary() { public RegionSummary regionSummary() { return new RegionSummary(getIntegerGroup(2), getIntegerGroup(3), - (trace.group(4) != null) ? getIntegerGroup(4) : getIntegerGroup(3)); + trace.group(4) != null ? getIntegerGroup(4) : getIntegerGroup(3)); } // Debugging support **PLEASE DO NOT REMOVE** public void notYetImplemented() { String threadName = Thread.currentThread().getName(); LOGGER.log(Level.FINE, "{0}, not implemented: {1}", new Object[]{threadName, getGroup(0)}); - for (int i = 1; i < groupCount() + 1; i++) { + for (var i = 1; i < groupCount() + 1; i++) { LOGGER.log(Level.FINE, "{0} : {1}", new Object[]{i, getGroup(i)}); } LOGGER.fine("-----------------------------------------"); //IntelliJ Eats this log output, so it's displayed to stdout GCToolKit.LOG_DEBUG_MESSAGE(() -> { - StringBuilder debugMessage = new StringBuilder(); + var debugMessage = new StringBuilder(); debugMessage.append(threadName).append(", not implemented: ").append(getGroup(0)).append(System.lineSeparator()); - for (int i = 1; i < groupCount() + 1; i++) { + for (var i = 1; i < groupCount() + 1; i++) { debugMessage.append(i).append(": ").append(getGroup(i)).append(System.lineSeparator()); } debugMessage.append("-----------------------------------------"); diff --git a/parser/src/main/java/com/microsoft/gctoolkit/parser/GCParseRule.java b/parser/src/main/java/com/microsoft/gctoolkit/parser/GCParseRule.java index 37d8ba0f..97310c3e 100644 --- a/parser/src/main/java/com/microsoft/gctoolkit/parser/GCParseRule.java +++ b/parser/src/main/java/com/microsoft/gctoolkit/parser/GCParseRule.java @@ -2,13 +2,13 @@ // Licensed under the MIT License. package com.microsoft.gctoolkit.parser; +import org.jspecify.annotations.Nullable; + import java.util.regex.Matcher; import java.util.regex.Pattern; -/** - * Class that tracks whether a log entry was parsed successfully (hit), or not - * (miss) and captures the origin of that hit or miss. - */ +/// Class that tracks whether a log entry was parsed successfully (hit), or not +/// (miss) and captures the origin of that hit or miss. public class GCParseRule { private final String name; @@ -19,15 +19,13 @@ public GCParseRule(String name, String pattern) { this.pattern = Pattern.compile(pattern); } - /** - * TODO This painful pattern of returning a null which gets checked by - * the caller could be replaced by use of Optional - * todo: for some reason the matcher is getting corrupted, synchronized helps! Need to sort out corruption - * - * @param trace The trace to match against the pattern - * @return A trace with a valid matcher or null - */ - public GCLogTrace parse(String trace) { + /// TODO This painful pattern of returning a null which gets checked by + /// the caller could be replaced by use of Optional + /// todo: for some reason the matcher is getting corrupted, synchronized helps! Need to sort out corruption + /// + /// @param trace The trace to match against the pattern + /// @return A trace with a valid matcher or null + public @Nullable GCLogTrace parse(String trace) { Matcher matcher = pattern.matcher(trace); if (matcher.find()) { return new GCLogTrace(matcher); diff --git a/parser/src/main/java/com/microsoft/gctoolkit/parser/GenerationalHeapParser.java b/parser/src/main/java/com/microsoft/gctoolkit/parser/GenerationalHeapParser.java index 04edccc7..e65c7307 100644 --- a/parser/src/main/java/com/microsoft/gctoolkit/parser/GenerationalHeapParser.java +++ b/parser/src/main/java/com/microsoft/gctoolkit/parser/GenerationalHeapParser.java @@ -2,7 +2,6 @@ // Licensed under the MIT License. package com.microsoft.gctoolkit.parser; -import com.microsoft.gctoolkit.GCToolKit; import com.microsoft.gctoolkit.aggregator.EventSource; import com.microsoft.gctoolkit.event.CPUSummary; import com.microsoft.gctoolkit.event.GCCause; @@ -39,6 +38,7 @@ import java.util.AbstractMap; import java.util.ArrayList; +import java.util.List; import java.util.Optional; import java.util.Set; import java.util.function.BiConsumer; @@ -49,17 +49,15 @@ import static com.microsoft.gctoolkit.parser.unified.UnifiedG1GCPatterns.WEAK_PROCESSING; -/** - * Time of GC - * GCType - * Collect total heap values - * Heap before collection - * Heap after collection - * Heap configured size - * total pause time - * CMS failures - * System.gc() calls - */ +/// Time of GC +/// GCType +/// Collect total heap values +/// Heap before collection +/// Heap after collection +/// Heap configured size +/// total pause time +/// CMS failures +/// System.gc() calls public class GenerationalHeapParser extends PreUnifiedGCLogParser implements SimplePatterns, ICMSPatterns, SerialPatterns, ParallelPatterns { private static final Logger LOGGER = Logger.getLogger(GenerationalHeapParser.class.getName()); @@ -335,7 +333,7 @@ private boolean ignoreFrequentButUnwantedEntries(String line) { if (line.startsWith("{Heap before")) { return true; } - if (line.equals("}")) { + if ("}".equals(line)) { return true; } @@ -369,7 +367,7 @@ public void endOfFile(GCLogTrace trace, String line) { } public void defNew(GCLogTrace trace, String line) { - DefNew defNew = new DefNew(getClock(), trace.gcCause(), trace.getDuration()); + var defNew = new DefNew(getClock(), trace.gcCause(), trace.getDuration()); defNew.add(trace.getOccupancyBeforeAfterWithMemoryPoolSizeSummary(13), this.getTotalOccupancyBeforeAfterWithTotalHeapPoolSizeSummary(trace, 20)); defNew.add(extractCPUSummary(line)); publish(defNew); @@ -377,7 +375,7 @@ public void defNew(GCLogTrace trace, String line) { //2019-10-22T23:41:21.852+0000: 21.912: [GC (GCLocker Initiated GC) 2019-10-22T23:41:21.853+0000: 21.912: [DefNew2019-10-22T23:41:21.914+0000: 21.974: [SoftReference, 0 refs, 0.0000842 secs]2019-10-22T23:41:21.914+0000: 21.974: [WeakReference, 76 refs, 0.0000513 secs]2019-10-22T23:41:21.914+0000: 21.974: [FinalReference, 91635 refs, 0.0396861 secs]2019-10-22T23:41:21.954+0000: 22.014: [PhantomReference, 0 refs, 3 refs, 0.0000444 secs]2019-10-22T23:41:21.954+0000: 22.014: [JNI Weak Reference, 0.0000281 secs]: 419520K->19563K(471936K), 0.1019514 secs] 502104K->102148K(2044800K), 0.1020469 secs] [Times: user=0.09 sys=0.01, real=0.10 secs] public void defNewDetails(GCLogTrace trace, String line) { - DefNew defNew = new DefNew(getClock(), trace.gcCause(), trace.getDuration()); + var defNew = new DefNew(getClock(), trace.gcCause(), trace.getDuration()); MemoryPoolSummary heap = this.getTotalOccupancyBeforeAfterWithTotalHeapPoolSizeSummary(trace, 58); MemoryPoolSummary young = trace.getOccupancyBeforeAfterWithMemoryPoolSizeSummary(51); defNew.add(young, heap.minus(young), heap); @@ -393,7 +391,7 @@ public void defNewWithTenuring(GCLogTrace trace, String line) { //3.299: [Full GC (Metadata GC Threshold) 3.299: [Tenured: 21006K->20933K(21888K), 0.0230475 secs] 29003K->20933K(31680K), [Metapace: 12111K->12111K(12672K)], 0.0231557 secs] public void serialFull(GCLogTrace trace, String line) { - FullGC collection = new FullGC(getClock(), trace.gcCause(), trace.getDuration()); + var collection = new FullGC(getClock(), trace.gcCause(), trace.getDuration()); MemoryPoolSummary tenured = trace.getOccupancyBeforeAfterWithMemoryPoolSizeSummary(5); MemoryPoolSummary heap = this.getTotalOccupancyBeforeAfterWithTotalHeapPoolSizeSummary(trace, 12); collection.add(heap.minus(tenured), tenured, heap); @@ -405,7 +403,7 @@ public void serialFull(GCLogTrace trace, String line) { //62.616: [GC 62.616: [ParNew: 5033216K->129451K(5662336K), 0.2536590 secs] 5097075K->193310K(24536704K), 0.2538510 secs] //48.021: [GC48.021: [ParNew: 306686K->34046K(306688K), 0.3196120 secs] 1341473K->1125818K(8669952K), 0.3197540 secs] public void parNew(GCLogTrace trace, String line) { - ParNew collection = new ParNew(getClock(), trace.gcCause(1), trace.getDuration()); + var collection = new ParNew(getClock(), trace.gcCause(1), trace.getDuration()); collection.add(trace.getOccupancyBeforeAfterWithMemoryPoolSizeSummary(13), getTotalOccupancyBeforeAfterWithTotalHeapPoolSizeSummary(trace, 20)); collection.add(extractCPUSummary(line)); publish(collection); @@ -454,26 +452,26 @@ private void parNewConcurrentModeFailureFLSAfter(GCLogTrace trace, String line) private void parNewFLSTime(GCLogTrace trace, String line) { if (garbageCollectionTypeForwardReference == GarbageCollectionTypes.ParNewPromotionFailed) { - ParNewPromotionFailed parNew = new ParNewPromotionFailed(getClock(), gcCauseForwardReference, scavengeDurationForwardReference); - MemoryPoolSummary heap = new MemoryPoolSummary(heapForwardReference.getOccupancyBeforeCollection(), heapForwardReference.getOccupancyBeforeCollection(), heapForwardReference.getSizeAfterCollection()); + var parNew = new ParNewPromotionFailed(getClock(), gcCauseForwardReference, scavengeDurationForwardReference); + var heap = new MemoryPoolSummary(heapForwardReference.getOccupancyBeforeCollection(), heapForwardReference.getOccupancyBeforeCollection(), heapForwardReference.getSizeAfterCollection()); parNew.add(youngMemoryPoolSummaryForwardReference, heap); parNew.add(scavengeCPUSummaryForwardReference); - ConcurrentModeFailure cmf = new ConcurrentModeFailure(getClock().add(scavengeDurationForwardReference), GCCause.CMS_FAILURE, trace.getDuration()); + var cmf = new ConcurrentModeFailure(getClock().add(scavengeDurationForwardReference), GCCause.CMS_FAILURE, trace.getDuration()); cmf.add(heapForwardReference.minus(tenuredForwardReference), tenuredForwardReference, heapForwardReference); cmf.add(extractCPUSummary(line)); cmf.addBinaryTreeDictionary(new BinaryTreeDictionary(totalFreeSpaceForwardReference, maxChunkSizeForwardReference, numberOfBlocksForwardReference, averageBlockSizeForwardReference, treeHeightForwardReference)); publish(parNew); publish(cmf); } else if (garbageCollectionTypeForwardReference == GarbageCollectionTypes.ParNew) { - ParNew collection = new ParNew(scavengeTimeStamp, gcCauseForwardReference, trace.getPauseTime()); + var collection = new ParNew(scavengeTimeStamp, gcCauseForwardReference, trace.getPauseTime()); collection.add(youngMemoryPoolSummaryForwardReference, heapForwardReference); collection.add(extractCPUSummary(line)); collection.addBinaryTreeDictionary(new BinaryTreeDictionary(totalFreeSpaceForwardReference, maxChunkSizeForwardReference, numberOfBlocksForwardReference, averageBlockSizeForwardReference, treeHeightForwardReference)); publish(collection); } else if (garbageCollectionTypeForwardReference == GarbageCollectionTypes.ConcurrentModeFailure) { - MemoryPoolSummary heap = new MemoryPoolSummary(heapForwardReference.getOccupancyBeforeCollection(), heapForwardReference.getSizeAfterCollection(), heapForwardReference.getOccupancyBeforeCollection(), heapForwardReference.getSizeAfterCollection()); - double portionOfPauseToSubtract = ( parNewForwardReference == null) ? 0.0d : parNewForwardReference.getDuration(); - ConcurrentModeFailure concurrentModeFailure = new ConcurrentModeFailure(fullGCTimeStamp, gcCauseForwardReference, trace.getPauseTime() - portionOfPauseToSubtract); + var heap = new MemoryPoolSummary(heapForwardReference.getOccupancyBeforeCollection(), heapForwardReference.getSizeAfterCollection(), heapForwardReference.getOccupancyBeforeCollection(), heapForwardReference.getSizeAfterCollection()); + double portionOfPauseToSubtract = parNewForwardReference == null ? 0.0d : parNewForwardReference.getDuration(); + var concurrentModeFailure = new ConcurrentModeFailure(fullGCTimeStamp, gcCauseForwardReference, trace.getPauseTime() - portionOfPauseToSubtract); concurrentModeFailure.add(heapForwardReference.minus(tenuredForwardReference), tenuredForwardReference, heapForwardReference); concurrentModeFailure.add(extractCPUSummary(line)); concurrentModeFailure.add(metaSpaceForwardReference); @@ -485,8 +483,8 @@ private void parNewFLSTime(GCLogTrace trace, String line) { } publish(concurrentModeFailure); } else if (garbageCollectionTypeForwardReference == GarbageCollectionTypes.FullGC) { - MemoryPoolSummary heap = new MemoryPoolSummary(heapForwardReference.getOccupancyBeforeCollection(), heapForwardReference.getSizeAfterCollection(), heapForwardReference.getOccupancyBeforeCollection(), heapForwardReference.getSizeAfterCollection()); - FullGC fullGc = new FullGC(fullGCTimeStamp, gcCauseForwardReference, trace.getDuration()); + var heap = new MemoryPoolSummary(heapForwardReference.getOccupancyBeforeCollection(), heapForwardReference.getSizeAfterCollection(), heapForwardReference.getOccupancyBeforeCollection(), heapForwardReference.getSizeAfterCollection()); + var fullGc = new FullGC(fullGCTimeStamp, gcCauseForwardReference, trace.getDuration()); fullGc.add(heap); fullGc.add(extractCPUSummary(line)); publish(fullGc); @@ -553,7 +551,7 @@ public void parNewCardTable(GCLogTrace trace, String line) { //11.675: [GC 11.675: [ParNew: 3782K->402K(3904K), 0.0012156 secs]11.676: [Tenured: 8673K->6751K(8840K), 0.1268332 secs] 12373K->6751K(12744K), [Perm : 10729K->10675K(21248K)], 0.1281985 secs] //89.260: [GC 89.260: [ParNew: 19135K->19135K(19136K), 0.0000156 secs]89.260: [CMS: 105875K->107775K(107776K), 0.5703972 secs] 125011K->116886K(126912K), [CMS Perm : 15589K->15584K(28412K)], 0.5705219 secs] public void parNewToConcurrentModeFailure(GCLogTrace trace, String line) { - ConcurrentModeFailure collection = new ConcurrentModeFailure(getClock(), trace.gcCause(), trace.getDoubleGroup(trace.groupCount())); + var collection = new ConcurrentModeFailure(getClock(), trace.gcCause(), trace.getDoubleGroup(trace.groupCount())); collection.add(trace.getOccupancyBeforeAfterWithMemoryPoolSizeSummary(12), trace.getOccupancyBeforeAfterWithMemoryPoolSizeSummary(24), getTotalOccupancyBeforeAfterWithTotalHeapPoolSizeSummary(trace, 31)); collection.addPermOrMetaSpaceRecord(extractPermOrMetaspaceRecord(line)); collection.add(extractCPUSummary(line)); @@ -562,7 +560,7 @@ public void parNewToConcurrentModeFailure(GCLogTrace trace, String line) { //Very rare occurrence where ParNew suffers from a promotion failure during the reset. This is, and isn't a CMF but will be treated as one. public void parNewToPsudoConcurrentModeFailure(GCLogTrace trace, String line) { - ConcurrentModeFailure collection = new ConcurrentModeFailure(scavengeTimeStamp, GCCause.PROMOTION_FAILED, trace.getDoubleGroup(trace.groupCount())); + var collection = new ConcurrentModeFailure(scavengeTimeStamp, GCCause.PROMOTION_FAILED, trace.getDoubleGroup(trace.groupCount())); MemoryPoolSummary tenured = trace.getOccupancyBeforeAfterWithMemoryPoolSizeSummary(1); MemoryPoolSummary heap = getTotalOccupancyBeforeAfterWithTotalHeapPoolSizeSummary(trace, 8); collection.add(heap.minus(tenured), tenured, heap); @@ -573,7 +571,7 @@ public void parNewToPsudoConcurrentModeFailure(GCLogTrace trace, String line) { } public void parNewReference(GCLogTrace trace, String line) { - ParNew gcEvent = new ParNew(trace.getDateTimeStamp(), trace.gcCause(), trace.getDuration()); + var gcEvent = new ParNew(trace.getDateTimeStamp(), trace.gcCause(), trace.getDuration()); MemoryPoolSummary young = trace.getOccupancyBeforeAfterWithMemoryPoolSizeSummary(51); MemoryPoolSummary heap = trace.getOccupancyBeforeAfterWithMemoryPoolSizeSummary(58); gcEvent.add(young, heap.minus(young), heap); @@ -612,7 +610,7 @@ public void defNewReference(GCLogTrace trace, String line) { //GenerationalHeapParser, not implemented: 2015-07-06T15:18:19.465-0700: 483260.591: [GC (Allocation Failure) 483260.592: [ParNew (promotion failed): 2146944K->2146944K(2146944K), 0.9972460 secs] 20182045K->20340243K(20732992K), 0.9975730 secs public void parNewPromotionFailed(GCLogTrace trace, String line) { - ParNewPromotionFailed collection = new ParNewPromotionFailed(getClock(), GCCause.PROMOTION_FAILED, trace.getDuration()); + var collection = new ParNewPromotionFailed(getClock(), GCCause.PROMOTION_FAILED, trace.getDuration()); MemoryPoolSummary young = trace.getOccupancyBeforeAfterWithMemoryPoolSizeSummary(12); MemoryPoolSummary heap = getTotalOccupancyBeforeAfterWithTotalHeapPoolSizeSummary(trace, 19); collection.add(young, heap); @@ -624,13 +622,13 @@ public void parNewPromotionFailedDetails(GCLogTrace trace, String line) { scavengeTimeStamp = getClock(); garbageCollectionTypeForwardReference = GarbageCollectionTypes.ParNewPromotionFailed; gcCauseForwardReference = GCCause.PROMOTION_FAILED; - ArrayList blocks = new ArrayList<>(); + var blocks = new ArrayList(); GCLogTrace block = PARNEW_PROMOTION_FAILURE_SIZE_BLOCK.parse(line); do { blocks.add(block.getIntegerGroup(1)); } while (block.hasNext()); promotionFailureSizesForwardReference = new int[blocks.size()]; - for (int index = 0; index < blocks.size(); index++) + for (var index = 0; index < blocks.size(); index++) promotionFailureSizesForwardReference[index] = blocks.get(index); GCLogTrace memorySummary = BEFORE_AFTER_CONFIGURED_PAUSE_RULE.parse(line); youngMemoryPoolSummaryForwardReference = memorySummary.getOccupancyBeforeAfterWithMemoryPoolSizeSummary(1); @@ -659,15 +657,13 @@ public void parNewPromotionFailedTenuring(GCLogTrace trace, String line) { //ParNew followed by a concurrent mode failure. Set the time of the CMF to be the beginning of the aborted CMS phase //not completely correct but good enough. - /** - * This rule is linked to 2 similar but not identical rules. - * The group count for 1 rule is 18 and the group count for the other rule is 16. - * @param trace The chunk of GC log that we are attempting to match to a known GC log pattern - * @param line The GC log line being parsed - */ + /// This rule is linked to 2 similar but not identical rules. + /// The group count for 1 rule is 18 and the group count for the other rule is 16. + /// @param trace The chunk of GC log that we are attempting to match to a known GC log pattern + /// @param line The GC log line being parsed public void parNewPromotionFailedInConcurrentMarkSweepPhase(GCLogTrace trace, String line) { concurrentPhaseEnd(trace,line,15); - int offset = (trace.groupCount() == 23) ? 0 : 2; + int offset = trace.groupCount() == 23 ? 0 : 2; scavengeTimeStamp = getClock(); garbageCollectionTypeForwardReference = GarbageCollectionTypes.ParNewPromotionFailed; gcCauseForwardReference = GCCause.PROMOTION_FAILED; @@ -695,8 +691,8 @@ public void concurrentMarkSweepBailingToForeground(GCLogTrace trace, String line //14921.473: [GC14921.473: [ParNew (promotion failed): 609300K->606029K(629120K), 0.1794470 secs]14921.652: [CMS: 1224499K->1100531K(1398144K), 3.4546330 secs] 1829953K->1100531K(2027264K), [CMS Perm : 148729K->148710K(262144K)], 3.6342950 secs] //84.977: [GC 84.977: [ParNew (promotion failed): 17024K->19136K(19136K), 0.0389515 secs]85.016: [CMS: 107077K->107775K(107776K), 0.2868956 secs] 109258K->107895K(126912K), [CMS Perm : 10680K->10674K(21248K)], 0.3260017 secs] [Times: user=0.37 sys=0.00, real=0.32 secs] public void promotionFailedToFull(GCLogTrace trace, String line) { - double youngDuration = trace.getDoubleGroup(18); - ParNewPromotionFailed youngCollection = new ParNewPromotionFailed(getClock(), GCCause.PROMOTION_FAILED, youngDuration); + var youngDuration = trace.getDoubleGroup(18); + var youngCollection = new ParNewPromotionFailed(getClock(), GCCause.PROMOTION_FAILED, youngDuration); MemoryPoolSummary youngGen = trace.getOccupancyBeforeAfterWithMemoryPoolSizeSummary(12); MemoryPoolSummary tenured = trace.getOccupancyBeforeAfterWithMemoryPoolSizeSummary(24); MemoryPoolSummary totalHeap = this.getTotalOccupancyBeforeAfterWithTotalHeapPoolSizeSummary(trace, 31); @@ -710,7 +706,7 @@ public void promotionFailedToFull(GCLogTrace trace, String line) { FullGC collection; DateTimeStamp fullStart = trace.getDateTimeStamp(3); - double duration = trace.getDuration() - youngDuration; + var duration = trace.getDuration() - youngDuration; collection = new FullGC(fullStart, GCCause.PROMOTION_FAILED, duration); collection.add(totalHeap.minus(tenured), tenured, totalHeap); collection.addPermOrMetaSpaceRecord(extractPermOrMetaspaceRecord(line)); @@ -766,15 +762,15 @@ public void corruptedParNewConcurrentPhase(GCLogTrace trace, String line) { //(promotion failed): 118016K->118016K(118016K), 0.0288030 secs]17740.440: [CMS (concurrent mode failure): 914159K->311550K(917504K), 0.5495730 secs] 985384K->311550K(1035520K), // [CMS Perm : 65977K->65950K(131072K)], 0.5785090 secs] [Times: user=0.67 sys=0.01, real=0.58 secs] public void corruptedParNewBody(GCLogTrace trace, String line) { - ParNewPromotionFailed parNewPromotionFailed = new ParNewPromotionFailed(scavengeTimeStamp, GCCause.PROMOTION_FAILED, trace.getPauseTime() - trace.getDoubleGroup(16)); + var parNewPromotionFailed = new ParNewPromotionFailed(scavengeTimeStamp, GCCause.PROMOTION_FAILED, trace.getPauseTime() - trace.getDoubleGroup(16)); MemoryPoolSummary heap = getTotalOccupancyBeforeAfterWithTotalHeapPoolSizeSummary(trace, 20); MemoryPoolSummary tenured = trace.getOccupancyBeforeAfterWithMemoryPoolSizeSummary(13); MemoryPoolSummary young = trace.getOccupancyBeforeAfterWithMemoryPoolSizeSummary(1); - MemoryPoolSummary parNewHeap = new MemoryPoolSummary(heap.getOccupancyBeforeCollection(), heap.getSizeAfterCollection(), heap.getOccupancyBeforeCollection(), heap.getSizeAfterCollection()); + var parNewHeap = new MemoryPoolSummary(heap.getOccupancyBeforeCollection(), heap.getSizeAfterCollection(), heap.getOccupancyBeforeCollection(), heap.getSizeAfterCollection()); parNewPromotionFailed.add(young, parNewHeap.minus(young), parNewHeap); - ConcurrentModeFailure concurrentModeFailure = new ConcurrentModeFailure(scavengeTimeStamp.add(trace.getDoubleGroup(9) - scavengeTimeStamp.getTimeStamp()), GCCause.LAST_GC_CAUSE, trace.getDoubleGroup(16)); + var concurrentModeFailure = new ConcurrentModeFailure(scavengeTimeStamp.add(trace.getDoubleGroup(9) - scavengeTimeStamp.getTimeStamp()), GCCause.LAST_GC_CAUSE, trace.getDoubleGroup(16)); concurrentModeFailure.add(heap.minus(tenured), tenured, heap); concurrentModeFailure.addPermOrMetaSpaceRecord(extractPermOrMetaspaceRecord(line)); concurrentModeFailure.add(extractCPUSummary(line)); @@ -794,8 +790,8 @@ public void concurrentPhaseEnd(GCLogTrace trace, String line) { public void concurrentPhaseEnd(GCLogTrace trace, String line, int offset) { try { - double cpuTime = trace.getDoubleGroup(7 + offset); - double wallClock = trace.getDoubleGroup(8 + offset); + var cpuTime = trace.getDoubleGroup(7 + offset); + var wallClock = trace.getDoubleGroup(8 + offset); switch (trace.getGroup(6 + offset)) { case "mark": publish(new ConcurrentMark(startOfConcurrentPhase, wallClock, cpuTime, wallClock)); @@ -823,7 +819,7 @@ public void concurrentPhaseEnd(GCLogTrace trace, String line, int offset) { //12.986: [GC[1 CMS-initial-mark: 33532K(62656K)] 49652K(81280K), 0.0014191 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] //todo: Initial-mark rule maybe too greedy??? public void initialMark(GCLogTrace trace, String line) { - InitialMark initialMark = new InitialMark(getClock(), trace.gcCause(), trace.getDoubleGroup(trace.groupCount())); + var initialMark = new InitialMark(getClock(), trace.gcCause(), trace.getDoubleGroup(trace.groupCount())); initialMark.add(trace.getOccupancyWithMemoryPoolSizeSummary(7), getTotalOccupancyWithTotalHeapSizeSummary(trace, 11)); initialMark.add(extractCPUSummary(line)); publish(initialMark); @@ -833,7 +829,7 @@ public void initialMark(GCLogTrace trace, String line) { //4981160.497: [GC[YG occupancy: 77784 K (153344 K)]4981160.498: [Rescan (parallel) , 0.1474240 secs]2014-06-10T17:50:11.873-0700: 4981160.645: [weak refs processing, 0.0000430 secs]2014-06-10T17:50:11.873-0700: 4981160.645: [scrub string table, 0.0009790 secs] [1 CMS-remark: 1897500K(1926784K)] 1975285K(2080128K), 0.1486260 secs] [Times: user=0.29 sys=0.00, real=0.15 secs] public void scavengeBeforeRemark(GCLogTrace trace, String line) { DateTimeStamp parNewStart = trace.getDateTimeStamp(2); - ParNew parNew = new ParNew(parNewStart, GCCause.UNKNOWN_GCCAUSE, trace.getDuration()); + var parNew = new ParNew(parNewStart, GCCause.UNKNOWN_GCCAUSE, trace.getDuration()); MemoryPoolSummary young = trace.getOccupancyBeforeAfterWithMemoryPoolSizeSummary(20); MemoryPoolSummary tenured = getTotalOccupancyBeforeAfterWithTotalHeapPoolSizeSummary(trace, 27); parNew.add(young, tenured.minus(young), tenured); @@ -875,9 +871,9 @@ public void parallelRescan(GCLogTrace trace, String line) { } public void rescanWeakClassSymbolString(GCLogTrace trace, String line) { - CMSRemark remark = new CMSRemark(getClock(), GCCause.CMS_FINAL_REMARK, trace.getDuration()); - MemoryPoolSummary tenured = new MemoryPoolSummary(trace.toKBytes(20), trace.toKBytes(22), trace.toKBytes(20), trace.toKBytes(22)); - MemoryPoolSummary heap = new MemoryPoolSummary(trace.toKBytes(24), trace.toKBytes(26), trace.toKBytes(24), trace.toKBytes(26)); + var remark = new CMSRemark(getClock(), GCCause.CMS_FINAL_REMARK, trace.getDuration()); + var tenured = new MemoryPoolSummary(trace.toKBytes(20), trace.toKBytes(22), trace.toKBytes(20), trace.toKBytes(22)); + var heap = new MemoryPoolSummary(trace.toKBytes(24), trace.toKBytes(26), trace.toKBytes(24), trace.toKBytes(26)); remark.add(youngMemoryPoolSummaryForwardReference, tenured, heap); recordRescanStepTimes(remark, line); remark.add(extractCPUSummary(line)); @@ -889,7 +885,7 @@ public void recordRemark(GCLogTrace trace, String line) { } public void remarkParNewPromotionFailed(GCLogTrace trace, String line) { - ParNewPromotionFailed parNewPromotionFailed = new ParNewPromotionFailed(getClock(), GCCause.PROMOTION_FAILED, trace.getDoubleGroup(trace.groupCount())); + var parNewPromotionFailed = new ParNewPromotionFailed(getClock(), GCCause.PROMOTION_FAILED, trace.getDoubleGroup(trace.groupCount())); MemoryPoolSummary young = trace.getOccupancyBeforeAfterWithMemoryPoolSizeSummary(11); MemoryPoolSummary tenured = getTotalOccupancyBeforeAfterWithTotalHeapPoolSizeSummary(trace, 18); parNewPromotionFailed.add(young, tenured.minus(young), tenured); @@ -902,13 +898,13 @@ public void tenuringDetails(GCLogTrace trace, String line) { MemoryPoolSummary young = trace.getOccupancyBeforeAfterWithMemoryPoolSizeSummary(1); MemoryPoolSummary heap = getTotalOccupancyBeforeAfterWithTotalHeapPoolSizeSummary(trace, 8); if (garbageCollectionTypeForwardReference == GarbageCollectionTypes.ParNew) { - ParNew collection = new ParNew(scavengeTimeStamp, gcCauseForwardReference, trace.getDuration()); + var collection = new ParNew(scavengeTimeStamp, gcCauseForwardReference, trace.getDuration()); collection.add(young, heap); collection.add(referenceGCForwardReference); collection.add(extractCPUSummary(line)); publish(collection); } else if (garbageCollectionTypeForwardReference == GarbageCollectionTypes.DefNew) { - DefNew collection = new DefNew(scavengeTimeStamp, gcCauseForwardReference, trace.getDoubleGroup(14)); + var collection = new DefNew(scavengeTimeStamp, gcCauseForwardReference, trace.getDoubleGroup(14)); collection.add(young, heap); collection.add(referenceGCForwardReference); collection.add(extractCPUSummary(line)); @@ -924,7 +920,7 @@ public void concurrentModeFailureDetails(GCLogTrace trace, String line) { MemoryPoolSummary heapSummary = getTotalOccupancyBeforeAfterWithTotalHeapPoolSizeSummary(trace, 8); //Must be preceded by a young gen collection if (garbageCollectionTypeForwardReference == GarbageCollectionTypes.ParNew) { - ParNew collection = new ParNew(scavengeTimeStamp, gcCauseForwardReference, scavengeDurationForwardReference); + var collection = new ParNew(scavengeTimeStamp, gcCauseForwardReference, scavengeDurationForwardReference); collection.add(youngMemoryPoolSummaryForwardReference, new MemoryPoolSummary(tenuredPoolSummary.getOccupancyBeforeCollection(), tenuredPoolSummary.getSizeBeforeCollection(), tenuredPoolSummary.getOccupancyBeforeCollection(), tenuredPoolSummary.getSizeAfterCollection()), new MemoryPoolSummary(heapSummary.getOccupancyBeforeCollection(), heapSummary.getSizeBeforeCollection(), heapSummary.getOccupancyBeforeCollection(), heapSummary.getSizeAfterCollection())); @@ -933,7 +929,7 @@ public void concurrentModeFailureDetails(GCLogTrace trace, String line) { failure = new ConcurrentModeFailure(getClock(), gcCauseForwardReference, trace.getDoubleGroup(trace.groupCount())); youngMemoryPoolSummaryForwardReference = heapSummary.minus(tenuredPoolSummary); } else if (garbageCollectionTypeForwardReference == GarbageCollectionTypes.DefNew) { - DefNew collection = new DefNew(scavengeTimeStamp, gcCauseForwardReference, scavengeDurationForwardReference); + var collection = new DefNew(scavengeTimeStamp, gcCauseForwardReference, scavengeDurationForwardReference); collection.add(youngMemoryPoolSummaryForwardReference, new MemoryPoolSummary(tenuredPoolSummary.getOccupancyBeforeCollection(), tenuredPoolSummary.getSizeBeforeCollection(), tenuredPoolSummary.getOccupancyBeforeCollection(), tenuredPoolSummary.getSizeAfterCollection()), new MemoryPoolSummary(heapSummary.getOccupancyBeforeCollection(), heapSummary.getSizeBeforeCollection(), heapSummary.getOccupancyBeforeCollection(), heapSummary.getSizeAfterCollection())); @@ -942,7 +938,7 @@ public void concurrentModeFailureDetails(GCLogTrace trace, String line) { failure = new ConcurrentModeFailure(getClock(), gcCauseForwardReference, trace.getDoubleGroup(trace.groupCount())); youngMemoryPoolSummaryForwardReference = heapSummary.minus(tenuredPoolSummary); } else if (garbageCollectionTypeForwardReference == GarbageCollectionTypes.ParNewPromotionFailed) { - ParNewPromotionFailed collection = new ParNewPromotionFailed(scavengeTimeStamp, gcCauseForwardReference, scavengeDurationForwardReference); + var collection = new ParNewPromotionFailed(scavengeTimeStamp, gcCauseForwardReference, scavengeDurationForwardReference); collection.add(youngMemoryPoolSummaryForwardReference, new MemoryPoolSummary(tenuredPoolSummary.getOccupancyBeforeCollection(), tenuredPoolSummary.getSizeBeforeCollection(), tenuredPoolSummary.getOccupancyBeforeCollection(), tenuredPoolSummary.getSizeAfterCollection()), new MemoryPoolSummary(heapSummary.getOccupancyBeforeCollection(), heapSummary.getSizeBeforeCollection(), heapSummary.getOccupancyBeforeCollection(), heapSummary.getSizeAfterCollection())); @@ -975,21 +971,18 @@ public void concurrentModeFailureDetails(GCLogTrace trace, String line) { //: 189422K->15827K(471872K), 0.1282129 secs]131348.814: [CMS (concurrent mode failure): 927657K->279012K(1572864K), 23.8067389 secs] 1116483K->279012K(2044736K), [CMS Perm : 131071K->27250K(131072K)], 23.9363976 secs] //this one is tricky, the GC is caused by CMS Perm filling up. Take heap before GC as heap after GC for the ParNew - /** - * Internal memory pools have to be derived for the ParNew. - * The following calculations were used to derive all pool sizes for the log entry below - * : 189422K->15827K(471872K), 0.1282129 secs]131348.814: [CMS (concurrent mode failure): 927657K->279012K(1572864K), 23.8067389 secs] 1116483K->279012K(2044736K), [CMS Perm : 131071K->27250K(131072K)], 23.9363976 secs] - * total heap for young = 189422K + 927657K -> 1116483K (2044736K), @ indexes 1 + 13 -> 20 (24) - * total heap for CMF = 1116483K->279012K(2044736K) 20 -> 22 (24) - * tenured for CMF = 927657K->279012K(1572864K) 13 -> 15 (17) - * young for CMF = 15827K -> 0K (471872K) 3 -> 0K (5) - * @param trace representing the log line - * @param line the text for the log line (can be extracted from the trace using trace.group(0); - * - */ + /// Internal memory pools have to be derived for the ParNew. + /// The following calculations were used to derive all pool sizes for the log entry below + /// : 189422K->15827K(471872K), 0.1282129 secs]131348.814: [CMS (concurrent mode failure): 927657K->279012K(1572864K), 23.8067389 secs] 1116483K->279012K(2044736K), [CMS Perm : 131071K->27250K(131072K)], 23.9363976 secs] + /// total heap for young = 189422K + 927657K -> 1116483K (2044736K), @ indexes 1 + 13 -> 20 (24) + /// total heap for CMF = 1116483K->279012K(2044736K) 20 -> 22 (24) + /// tenured for CMF = 927657K->279012K(1572864K) 13 -> 15 (17) + /// young for CMF = 15827K -> 0K (471872K) 3 -> 0K (5) + /// @param trace representing the log line + /// @param line the text for the log line (can be extracted from the trace using trace.group(0); public void parNewDetailsConcurrentModeFailure(GCLogTrace trace, String line) { - ParNew parNew = new ParNew(scavengeTimeStamp, GCCause.UNKNOWN_GCCAUSE, trace.getDoubleGroup(7)); - MemoryPoolSummary heap = new MemoryPoolSummary(trace.toKBytes(1) + trace.toKBytes(13), trace.toKBytes(24), trace.toKBytes(20), trace.toKBytes(24)); + var parNew = new ParNew(scavengeTimeStamp, GCCause.UNKNOWN_GCCAUSE, trace.getDoubleGroup(7)); + var heap = new MemoryPoolSummary(trace.toKBytes(1) + trace.toKBytes(13), trace.toKBytes(24), trace.toKBytes(20), trace.toKBytes(24)); MemoryPoolSummary young = trace.getOccupancyBeforeAfterWithMemoryPoolSizeSummary(1); parNew.add(young, heap); parNew.add(extractCPUSummary(line)); @@ -999,7 +992,7 @@ public void parNewDetailsConcurrentModeFailure(GCLogTrace trace, String line) { LOGGER.warning("concurrent phase not closed"); } - ConcurrentModeFailure collection = new ConcurrentModeFailure(fullGCTimeStamp, gcCauseForwardReference, trace.getDuration()); + var collection = new ConcurrentModeFailure(fullGCTimeStamp, gcCauseForwardReference, trace.getDuration()); collection.add( new MemoryPoolSummary( trace.toKBytes(3), trace.toKBytes(5), 0L, trace.toKBytes(5)), @@ -1029,15 +1022,15 @@ public void parNewDetailsPromotionFailedWithConcurrentMarkSweepPhase(GCLogTrace //: 19134K->19136K(19136K), 0.0493809 secs]236.955: [CMS: 107351K->79265K(107776K), 0.2540576 secs] 119733K->79265K(126912K), [CMS Perm : 14256K->14256K(24092K)], 0.3036551 secs] //: 2368K->319K(2368K), 0.0063634 secs]5.353: [Tenured: 5443K->5196K(5504K), 0.0830293 secs] 7325K->5196K(7872K), [Perm : 10606K->10606K(21248K)], 0.0895957 secs] public void parNewDetailsWithConcurrentModeFailure(GCLogTrace trace, String line) { - ParNewPromotionFailed collection = new ParNewPromotionFailed(scavengeTimeStamp, gcCauseForwardReference, trace.getDoubleGroup(7)); + var collection = new ParNewPromotionFailed(scavengeTimeStamp, gcCauseForwardReference, trace.getDoubleGroup(7)); MemoryPoolSummary young = trace.getOccupancyBeforeAfterWithMemoryPoolSizeSummary(1); - MemoryPoolSummary heap = new MemoryPoolSummary(trace.toKBytes(20), trace.toKBytes(24), trace.toKBytes(20), trace.toKBytes(24)); + var heap = new MemoryPoolSummary(trace.toKBytes(20), trace.toKBytes(24), trace.toKBytes(20), trace.toKBytes(24)); MemoryPoolSummary tenured = heap.minus(young); collection.add(young, tenured, heap); collection.add(extractCPUSummary(line)); publish(collection, false); - ConcurrentModeFailure fullCollection = new ConcurrentModeFailure(getClock(), gcCauseForwardReference, trace.getDoubleGroup(trace.groupCount())); + var fullCollection = new ConcurrentModeFailure(getClock(), gcCauseForwardReference, trace.getDoubleGroup(trace.groupCount())); tenured = trace.getOccupancyBeforeAfterWithMemoryPoolSizeSummary(13); heap = getTotalOccupancyBeforeAfterWithTotalHeapPoolSizeSummary(trace, 20); young = heap.minus(tenured); @@ -1056,7 +1049,7 @@ public void concurrentModeFailureReference(GCLogTrace trace, String line) { if (fullGCTimeStamp == null) { fullGCTimeStamp = getClock().add(parNewForwardReference.getDuration()); //need to estimate the pool occupancies and sizes for the ParNew - MemoryPoolSummary parNewHeap = new MemoryPoolSummary(heap.getOccupancyBeforeCollection(), heap.getSizeAfterCollection(), heap.getOccupancyBeforeCollection(), heap.getSizeAfterCollection()); + var parNewHeap = new MemoryPoolSummary(heap.getOccupancyBeforeCollection(), heap.getSizeAfterCollection(), heap.getOccupancyBeforeCollection(), heap.getSizeAfterCollection()); MemoryPoolSummary parNewTenured = parNewHeap.minus(youngMemoryPoolSummaryForwardReference); parNewForwardReference.add(youngMemoryPoolSummaryForwardReference, parNewTenured, parNewHeap); publish(parNewForwardReference, false); @@ -1075,10 +1068,10 @@ public void concurrentModeFailureReference(GCLogTrace trace, String line) { public void iCMSConcurrentModeFailureDuringParNewDefNewTenuringDetails(GCLogTrace trace, String line) { MemoryPoolSummary young = trace.getOccupancyBeforeAfterWithMemoryPoolSizeSummary(1); MemoryPoolSummary heap = getTotalOccupancyBeforeAfterWithTotalHeapPoolSizeSummary(trace, 8); - int dutyCycle = trace.getIntegerGroup(14); + var dutyCycle = trace.getIntegerGroup(14); if (garbageCollectionTypeForwardReference == GarbageCollectionTypes.ParNew) { - ParNew collection = new ParNew(scavengeTimeStamp, gcCauseForwardReference, trace.getDoubleGroup(trace.groupCount())); + var collection = new ParNew(scavengeTimeStamp, gcCauseForwardReference, trace.getDoubleGroup(trace.groupCount())); collection.add(young, heap.minus(young), heap); collection.recordDutyCycle(dutyCycle); collection.addPermOrMetaSpaceRecord(extractPermOrMetaspaceRecord(line)); @@ -1093,13 +1086,13 @@ public void iCMSConcurrentModeFailureDuringParNewDefNewTenuringDetails(GCLogTrac : 214K->0K(81856K), 0.0211649 secs] 1423543K->1423340K(2097088K) icms_dc=39 , 0.0218647 secs] */ else if (garbageCollectionTypeForwardReference == GarbageCollectionTypes.FullGC) { - SystemGC collection = new SystemGC(fullGCTimeStamp, GCCause.JAVA_LANG_SYSTEM, trace.getDoubleGroup(trace.groupCount())); + var collection = new SystemGC(fullGCTimeStamp, GCCause.JAVA_LANG_SYSTEM, trace.getDoubleGroup(trace.groupCount())); collection.add(young, heap.minus(young), heap); collection.recordDutyCycle(dutyCycle); collection.add(extractCPUSummary(line)); publish(collection); } else if (garbageCollectionTypeForwardReference == GarbageCollectionTypes.ParNewPromotionFailed) { - ParNewPromotionFailed collection = new ParNewPromotionFailed(scavengeTimeStamp, GCCause.PROMOTION_FAILED, trace.getDoubleGroup(trace.groupCount())); + var collection = new ParNewPromotionFailed(scavengeTimeStamp, GCCause.PROMOTION_FAILED, trace.getDoubleGroup(trace.groupCount())); collection.add(young, heap.minus(young), heap); collection.recordDutyCycle(dutyCycle); collection.add(extractCPUSummary(line)); @@ -1112,7 +1105,7 @@ else if (garbageCollectionTypeForwardReference == GarbageCollectionTypes.FullGC) //(concurrent mode failure): 1696350K->613432K(2015232K), 22.0030939 secs] 1772267K->613432K(2097088K) icms_dc=100 , 22.3467890 secs] public void iCMSConcurrentModeFailure(GCLogTrace trace, String line) { if (garbageCollectionTypeForwardReference == GarbageCollectionTypes.FullGC || garbageCollectionTypeForwardReference == GarbageCollectionTypes.ConcurrentModeFailure) { - ConcurrentModeFailure failure = new ConcurrentModeFailure(fullGCTimeStamp, GCCause.UNKNOWN_GCCAUSE, trace.getDuration()); + var failure = new ConcurrentModeFailure(fullGCTimeStamp, GCCause.UNKNOWN_GCCAUSE, trace.getDuration()); failure.add(getTotalOccupancyBeforeAfterWithTotalHeapPoolSizeSummary(trace, 8)); failure.recordDutyCycle(trace.getIntegerGroup(21)); failure.add(extractCPUSummary(line)); @@ -1130,7 +1123,7 @@ public void iCMSConcurrentModeFailure(GCLogTrace trace, String line) { if (fullGCTimeStamp == null) { fullGCTimeStamp = scavengeTimeStamp.add(trace.getDoubleGroup(7)); } - ConcurrentModeFailure failure = new ConcurrentModeFailure(fullGCTimeStamp, gcCauseForwardReference, trace.getDoubleGroup(7)); + var failure = new ConcurrentModeFailure(fullGCTimeStamp, gcCauseForwardReference, trace.getDoubleGroup(7)); MemoryPoolSummary heap = getTotalOccupancyBeforeAfterWithTotalHeapPoolSizeSummary(trace, 8); MemoryPoolSummary tenured = trace.getOccupancyBeforeAfterWithMemoryPoolSizeSummary(1); failure.add(heap.minus(tenured), tenured, heap); @@ -1150,16 +1143,16 @@ public void iCMSConcurrentModeFailure(GCLogTrace trace, String line) { */ public void iCMSConcurrentModeFailureDuringParNewDefNewDetails(GCLogTrace trace, String line) { { - ParNewPromotionFailed collection = new ParNewPromotionFailed(scavengeTimeStamp, trace.getDoubleGroup(7)); + var collection = new ParNewPromotionFailed(scavengeTimeStamp, trace.getDoubleGroup(7)); MemoryPoolSummary young = trace.getOccupancyBeforeAfterWithMemoryPoolSizeSummary(1); - MemoryPoolSummary heap = new MemoryPoolSummary(trace.toKBytes(20), trace.toKBytes(24), trace.toKBytes(20), trace.toKBytes(24)); + var heap = new MemoryPoolSummary(trace.toKBytes(20), trace.toKBytes(24), trace.toKBytes(20), trace.toKBytes(24)); collection.add(young, heap.minus(young), heap); collection.add(extractCPUSummary(line)); publish(collection); } { - ConcurrentModeFailure collection = new ConcurrentModeFailure(getClock(), GCCause.CMS_FAILURE, trace.getDuration()); + var collection = new ConcurrentModeFailure(getClock(), GCCause.CMS_FAILURE, trace.getDuration()); MemoryPoolSummary tenured = trace.getOccupancyBeforeAfterWithMemoryPoolSizeSummary(13); MemoryPoolSummary heap = getTotalOccupancyBeforeAfterWithTotalHeapPoolSizeSummary(trace, 20); collection.add(heap.minus(tenured), tenured, heap); @@ -1178,7 +1171,7 @@ public void fullGCInterruptsConcurrentPhase(GCLogTrace trace, String line) { } public void fullGCReferenceConcurrentModeFailure(GCLogTrace trace, String line) { - ConcurrentModeFailure collection = new ConcurrentModeFailure(getClock(), trace.gcCause(), trace.getDoubleGroup(trace.groupCount())); + var collection = new ConcurrentModeFailure(getClock(), trace.gcCause(), trace.getDoubleGroup(trace.groupCount())); GCLogTrace memorySummary = MEMORY_SUMMARY_RULE.parse(line); MemoryPoolSummary tenured = memorySummary.getOccupancyBeforeAfterWithMemoryPoolSizeSummary(1); getTotalOccupancyBeforeAfterWithTotalHeapPoolSizeSummary(memorySummary.next(), 1); @@ -1199,8 +1192,8 @@ public void fullParNewStart(GCLogTrace trace, String line) { } public void iCMSParNew(GCLogTrace trace, String line) { - int offset = TIME_DATE_OFFSET * 2; - ParNew parNew = new ParNew(getClock(), trace.gcCause(), trace.getDuration()); + var offset = TIME_DATE_OFFSET * 2; + var parNew = new ParNew(getClock(), trace.gcCause(), trace.getDuration()); parNew.add(trace.getOccupancyBeforeAfterWithMemoryPoolSizeSummary(offset), getTotalOccupancyBeforeAfterWithTotalHeapPoolSizeSummary(trace, offset + 7)); parNew.recordDutyCycle(trace.getIntegerGroup(trace.groupCount() - 1)); parNew.add(extractCPUSummary(line)); @@ -1210,8 +1203,8 @@ public void iCMSParNew(GCLogTrace trace, String line) { //Full GC with ParNew promotion failed. //"445909.040: [GC 445909.040: [ParNew (1: promotion failure size = 4629668) (promotion failed): 460096K->460096K(460096K), 0.8467130 secs]445909.887: [CMS: 6252252K->2709964K(7877440K), 23.9213270 secs] 6637399K->2709964K(8337536K), [CMS Perm : 1201406K->68157K(2097152K)] icms_dc=0 , 24.7685320 secs] public void iCMSParNewPromotionFailureRecord(GCLogTrace trace, String line) { - ParNewPromotionFailed parNewPromotionFailed = new ParNewPromotionFailed(getClock(), GCCause.PROMOTION_FAILED, trace.getDoubleGroup(19)); - MemoryPoolSummary heap = new MemoryPoolSummary(trace.toKBytes(32), trace.toKBytes(36), trace.toKBytes(32), trace.toKBytes(36)); + var parNewPromotionFailed = new ParNewPromotionFailed(getClock(), GCCause.PROMOTION_FAILED, trace.getDoubleGroup(19)); + var heap = new MemoryPoolSummary(trace.toKBytes(32), trace.toKBytes(36), trace.toKBytes(32), trace.toKBytes(36)); MemoryPoolSummary young = trace.getOccupancyBeforeAfterWithMemoryPoolSizeSummary(13); MemoryPoolSummary tenured = heap.minus(young); parNewPromotionFailed.add(young, tenured, heap); @@ -1220,7 +1213,7 @@ public void iCMSParNewPromotionFailureRecord(GCLogTrace trace, String line) { //Synthesis a Full GC DateTimeStamp fullGCStart = trace.getDateTimeStamp(3); fullGCStart = getClock().add(fullGCStart.getTimeStamp() - getClock().getTimeStamp()); - FullGC fullGC = new FullGC(fullGCStart, GCCause.PROMOTION_FAILED, trace.getDoubleGroup(31)); + var fullGC = new FullGC(fullGCStart, GCCause.PROMOTION_FAILED, trace.getDoubleGroup(31)); heap = getTotalOccupancyBeforeAfterWithTotalHeapPoolSizeSummary(trace, 32); tenured = trace.getOccupancyBeforeAfterWithMemoryPoolSizeSummary(25); young = new MemoryPoolSummary(0L, trace.toKBytes(17), 0L, trace.toKBytes(17)); @@ -1231,8 +1224,8 @@ public void iCMSParNewPromotionFailureRecord(GCLogTrace trace, String line) { } public void iCMSParNewPromotionFailure(GCLogTrace trace, String line) { - double parnewDuration = trace.getDoubleGroup((2 * TIME_DATE_OFFSET) + 6); - ParNewPromotionFailed parNewPromotionFailed = new ParNewPromotionFailed(getClock(), GCCause.PROMOTION_FAILED, parnewDuration); + var parnewDuration = trace.getDoubleGroup((2 * TIME_DATE_OFFSET) + 6); + var parNewPromotionFailed = new ParNewPromotionFailed(getClock(), GCCause.PROMOTION_FAILED, parnewDuration); MemoryPoolSummary heap = trace.getOccupancyBeforeAfterWithMemoryPoolSizeSummary((3 * TIME_DATE_OFFSET) + 13); MemoryPoolSummary young = trace.getOccupancyBeforeAfterWithMemoryPoolSizeSummary(2 * TIME_DATE_OFFSET); MemoryPoolSummary tenured = heap.minus(young); @@ -1242,7 +1235,7 @@ public void iCMSParNewPromotionFailure(GCLogTrace trace, String line) { //Synthesis a Full GC DateTimeStamp fullGCStart = trace.getDateTimeStamp(3); - ConcurrentModeFailure fullGC = new ConcurrentModeFailure(fullGCStart, GCCause.PROMOTION_FAILED, trace.getDuration() - parnewDuration); + var fullGC = new ConcurrentModeFailure(fullGCStart, GCCause.PROMOTION_FAILED, trace.getDuration() - parnewDuration); tenured = trace.getOccupancyBeforeAfterWithMemoryPoolSizeSummary((3 * TIME_DATE_OFFSET) + 6); young = new MemoryPoolSummary(young.getOccupancyBeforeCollection(), young.getSizeBeforeCollection(), 0L, young.getSizeAfterCollection()); fullGC.add(young, tenured, heap); @@ -1260,7 +1253,7 @@ public void fullGCiCMS(GCLogTrace trace, String line) { else collection = new FullGC(getClock(), trace.gcCause(), trace.getDuration()); MemoryPoolSummary tenured = trace.getOccupancyBeforeAfterWithMemoryPoolSizeSummary(2 + TIME_DATE_OFFSET); - MemoryPoolSummary heap = getTotalOccupancyBeforeAfterWithTotalHeapPoolSizeSummary(trace, (TIME_DATE_OFFSET) + 9); + MemoryPoolSummary heap = getTotalOccupancyBeforeAfterWithTotalHeapPoolSizeSummary(trace, TIME_DATE_OFFSET + 9); collection.add(heap.minus(tenured), tenured, heap); collection.recordDutyCycle(trace.getIntegerGroup(trace.groupCount() - 1)); collection.addPermOrMetaSpaceRecord(extractPermOrMetaspaceRecord(line)); @@ -1271,20 +1264,20 @@ public void fullGCiCMS(GCLogTrace trace, String line) { //: 81792K->0K(81856K), 0.0431036 secs] 90187K->11671K(2097088K) icms_dc=5 , 0.0435503 secs] public void iCMSParNewDefNewTenuringDetails(GCLogTrace trace, String line) { if (GarbageCollectionTypes.ParNew == garbageCollectionTypeForwardReference) { - ParNew collection = new ParNew(scavengeTimeStamp, gcCauseForwardReference, trace.getDuration()); + var collection = new ParNew(scavengeTimeStamp, gcCauseForwardReference, trace.getDuration()); collection.add(trace.getOccupancyBeforeAfterWithMemoryPoolSizeSummary(1), getTotalOccupancyBeforeAfterWithTotalHeapPoolSizeSummary(trace, 8)); collection.recordDutyCycle(trace.getIntegerGroup(14)); collection.add(extractCPUSummary(line)); publish(collection); } else if (GarbageCollectionTypes.ParNewPromotionFailed == garbageCollectionTypeForwardReference) { - ParNewPromotionFailed collection = new ParNewPromotionFailed(scavengeTimeStamp, gcCauseForwardReference, trace.getDuration()); + var collection = new ParNewPromotionFailed(scavengeTimeStamp, gcCauseForwardReference, trace.getDuration()); MemoryPoolSummary young = trace.getOccupancyBeforeAfterWithMemoryPoolSizeSummary(1); MemoryPoolSummary heap = getTotalOccupancyBeforeAfterWithTotalHeapPoolSizeSummary(trace, 8); collection.add(young, heap.minus(young), heap); collection.recordDutyCycle(trace.getIntegerGroup(trace.groupCount() - 1)); publish(collection); } else if (GarbageCollectionTypes.FullGC == garbageCollectionTypeForwardReference) { - FullGC collection = new FullGC(fullGCTimeStamp, gcCauseForwardReference, trace.getDuration()); + var collection = new FullGC(fullGCTimeStamp, gcCauseForwardReference, trace.getDuration()); MemoryPoolSummary young = trace.getOccupancyBeforeAfterWithMemoryPoolSizeSummary(1); MemoryPoolSummary heap = getTotalOccupancyBeforeAfterWithTotalHeapPoolSizeSummary(trace, 8); collection.add(young, heap.minus(young), heap); @@ -1299,7 +1292,7 @@ public void iCMSParNewDefNewTenuringDetails(GCLogTrace trace, String line) { //35305.590: [GC 35305.590: [ParNew (promotion failed): 10973K->3147K(153344K), 0.0295730 secs] 1763339K->1763817K(2080128K) icms_dc=32 , 0.0297680 secs] public void iCMSPromotionFailed(GCLogTrace trace, String line) { - ParNewPromotionFailed collection = new ParNewPromotionFailed(getClock(), trace.getDuration()); + var collection = new ParNewPromotionFailed(getClock(), trace.getDuration()); MemoryPoolSummary young = trace.getOccupancyBeforeAfterWithMemoryPoolSizeSummary(TIME_DATE_OFFSET + 2); MemoryPoolSummary heap = getTotalOccupancyBeforeAfterWithTotalHeapPoolSizeSummary(trace, TIME_DATE_OFFSET + 9); collection.add(young, heap.minus(young), heap); @@ -1330,8 +1323,8 @@ else if ((cause == GCCause.UNKNOWN_GCCAUSE) || (cause == GCCause.GCCAUSE_NOT_SET //91057.643: [GC 91057.643: [ParNew: 153344K->153344K(153344K), 0.0000250 secs]91057.643: [CMS: 1895319K->1754894K(1926784K), 9.6910090 secs] 2048663K->1754894K(2080128K), [CMS Perm : 135228K->134975K(230652K)] icms_dc=65 , 9.6912470 secs] public void iCMSMislabeledFull(GCLogTrace trace, String line) { - double parNewDuration = trace.getDoubleGroup((TIME_DATE_OFFSET * 2) + 6); - ParNew parNew = new ParNew(trace.getDateTimeStamp(2), trace.gcCause(), parNewDuration); + var parNewDuration = trace.getDoubleGroup((TIME_DATE_OFFSET * 2) + 6); + var parNew = new ParNew(trace.getDateTimeStamp(2), trace.gcCause(), parNewDuration); MemoryPoolSummary young = trace.getOccupancyBeforeAfterWithMemoryPoolSizeSummary(TIME_DATE_OFFSET * 2); MemoryPoolSummary tenured = trace.getOccupancyBeforeAfterWithMemoryPoolSizeSummary((TIME_DATE_OFFSET * 2) + 12); MemoryPoolSummary heap = getTotalOccupancyBeforeAfterWithTotalHeapPoolSizeSummary(trace, (TIME_DATE_OFFSET * 2) + 19); @@ -1340,7 +1333,7 @@ public void iCMSMislabeledFull(GCLogTrace trace, String line) { new MemoryPoolSummary(heap.getOccupancyBeforeCollection(), heap.getSizeAfterCollection(), heap.getOccupancyBeforeCollection(), heap.getSizeAfterCollection())); publish(parNew); - FullGC full = new FullGC(trace.getDateTimeStamp(3), trace.gcCause(), trace.getDuration()); + var full = new FullGC(trace.getDateTimeStamp(3), trace.gcCause(), trace.getDuration()); full.add(heap.minus(tenured), tenured, heap); full.recordDutyCycle(trace.getIntegerGroup(trace.groupCount() - 1)); full.addPermOrMetaSpaceRecord(extractPermOrMetaspaceRecord(line)); @@ -1350,7 +1343,7 @@ public void iCMSMislabeledFull(GCLogTrace trace, String line) { //10110.232: [Full GC 10110.232: [CMS (concurrent mode failure): 2715839K->1659203K(2752512K), 39.3188254 secs] 2740830K->1659203K(3106432K), [CMS Perm : 206079K->204904K(402264K)] icms_dc=100 , 39.3199631 secs] [Times: user=39.37 sys=0.02, real=39.32 secs] public void iCMSFullAfterConcurrentModeFailure(GCLogTrace trace, String line) { - ConcurrentModeFailure failure = new ConcurrentModeFailure(getClock(), GCCause.UNKNOWN_GCCAUSE, trace.getDuration()); + var failure = new ConcurrentModeFailure(getClock(), GCCause.UNKNOWN_GCCAUSE, trace.getDuration()); failure.add(trace.getOccupancyBeforeAfterWithMemoryPoolSizeSummary(TIME_DATE_OFFSET * 2), getTotalOccupancyBeforeAfterWithTotalHeapPoolSizeSummary(trace, (TIME_DATE_OFFSET * 2) + 7)); failure.recordDutyCycle(trace.getIntegerGroup(trace.groupCount() - 1)); failure.addPermOrMetaSpaceRecord(extractPermOrMetaspaceRecord(line)); @@ -1365,7 +1358,7 @@ public void iCMSConcurrentModeInterrupted(GCLogTrace trace, String line) { fullGCTimeStamp = getClock(); logMissedFirstRecordForEvent(line); } - ConcurrentModeInterrupted collection = new ConcurrentModeInterrupted(fullGCTimeStamp, garbageCollectionTypeForwardReference, gcCauseForwardReference, trace.getDoubleGroup(trace.groupCount())); + var collection = new ConcurrentModeInterrupted(fullGCTimeStamp, garbageCollectionTypeForwardReference, gcCauseForwardReference, trace.getDoubleGroup(trace.groupCount())); MemoryPoolSummary tenured = trace.getOccupancyBeforeAfterWithMemoryPoolSizeSummary(1); MemoryPoolSummary heap = getTotalOccupancyBeforeAfterWithTotalHeapPoolSizeSummary(trace, 8); collection.add(heap.minus(tenured), tenured, heap); @@ -1392,7 +1385,7 @@ public void psFullGCMeta(GCLogTrace trace, String line) { //1.147: [Full GC (System) 1.147: [Tenured: 1636K->1765K(5312K), 0.0488106 secs] 2894K->1765K(7616K), [Perm : 10112K->10112K(21248K)], 0.0488934 secs] public void psFullGCV2Meta(GCLogTrace trace, String line) { - SystemGC collection = new SystemGC(getClock(), trace.getDoubleGroup(trace.groupCount())); + var collection = new SystemGC(getClock(), trace.getDoubleGroup(trace.groupCount())); MemoryPoolSummary tenured = trace.getOccupancyBeforeAfterWithMemoryPoolSizeSummary(5); MemoryPoolSummary heap = getTotalOccupancyBeforeAfterWithTotalHeapPoolSizeSummary(trace, 12); collection.add(heap.minus(tenured), tenured, heap); @@ -1402,18 +1395,18 @@ public void psFullGCV2Meta(GCLogTrace trace, String line) { } public void parNewConcurrentModeFailurePerm(GCLogTrace trace, String line) { - double concurrentModeFailurePause = trace.getDoubleGroup(26); - double parNewPause = trace.getDoubleGroup(18); - double startTimeGap = trace.getDoubleGroup(13) - getClock().getTimeStamp(); + var concurrentModeFailurePause = trace.getDoubleGroup(26); + var parNewPause = trace.getDoubleGroup(18); + var startTimeGap = trace.getDoubleGroup(13) - getClock().getTimeStamp(); - ParNewPromotionFailed parNewPromotionFailed = new ParNewPromotionFailed(getClock(), trace.gcCause(), parNewPause); - MemoryPoolSummary heap = new MemoryPoolSummary(trace.toKBytes(27), trace.toKBytes(31), trace.toKBytes(27), trace.toKBytes(31)); + var parNewPromotionFailed = new ParNewPromotionFailed(getClock(), trace.gcCause(), parNewPause); + var heap = new MemoryPoolSummary(trace.toKBytes(27), trace.toKBytes(31), trace.toKBytes(27), trace.toKBytes(31)); MemoryPoolSummary young = trace.getOccupancyBeforeAfterWithMemoryPoolSizeSummary(12); parNewPromotionFailed.add(young, heap.minus(young), heap); publish(parNewPromotionFailed); - ConcurrentModeFailure concurrentModeFailure = new ConcurrentModeFailure(getClock().add(startTimeGap), GCCause.PROMOTION_FAILED, concurrentModeFailurePause); + var concurrentModeFailure = new ConcurrentModeFailure(getClock().add(startTimeGap), GCCause.PROMOTION_FAILED, concurrentModeFailurePause); heap = getTotalOccupancyBeforeAfterWithTotalHeapPoolSizeSummary(trace, 27); young = new MemoryPoolSummary( trace.toKBytes(14), trace.toKBytes(16), 0, trace.toKBytes(16)); @@ -1447,7 +1440,7 @@ public void fullParNewConcurrentModeFailureMeta(GCLogTrace trace, String line) { //1.147: [Full GC (System) 1.147: [Tenured: 1636K->1765K(5312K), 0.0488106 secs] 2894K->1765K(7616K), [Perm : 10112K->10112K(21248K)], 0.0488934 secs] public void psFullGCV2Perm(GCLogTrace trace, String line) { - SystemGC collection = new SystemGC(getClock(), trace.getDoubleGroup(trace.groupCount())); + var collection = new SystemGC(getClock(), trace.getDoubleGroup(trace.groupCount())); MemoryPoolSummary tenured = trace.getOccupancyBeforeAfterWithMemoryPoolSizeSummary(5); MemoryPoolSummary heap = getTotalOccupancyBeforeAfterWithTotalHeapPoolSizeSummary(trace, 12); collection.add(heap.minus(tenured), tenured, heap); @@ -1499,14 +1492,14 @@ public void cmsFullPermOrMeta(GCLogTrace trace, String line) { //285.945: [ParNew 173250K->163849K(190460K), 0.0044482 secs] public void parNewNoDetails(GCLogTrace trace, String line) { - ParNew parNew = new ParNew(getClock(), GarbageCollectionTypes.Young, GCCause.UNKNOWN_GCCAUSE, trace.getDoubleGroup(trace.groupCount())); + var parNew = new ParNew(getClock(), GarbageCollectionTypes.Young, GCCause.UNKNOWN_GCCAUSE, trace.getDoubleGroup(trace.groupCount())); parNew.add(getTotalOccupancyBeforeAfterWithTotalHeapPoolSizeSummary(trace, 3)); parNew.add(extractCPUSummary(line)); publish(parNew); } public void youngNoDetails(GCLogTrace trace, String line) { - YoungGC youngGC = new YoungGC(getClock(), GarbageCollectionTypes.Young, GCCause.UNKNOWN_GCCAUSE, trace.getDuration()); + var youngGC = new YoungGC(getClock(), GarbageCollectionTypes.Young, GCCause.UNKNOWN_GCCAUSE, trace.getDuration()); youngGC.add(getTotalOccupancyBeforeAfterWithTotalHeapPoolSizeSummary(trace, 6)); youngGC.add(extractCPUSummary(line)); publish(youngGC); @@ -1515,13 +1508,13 @@ public void youngNoDetails(GCLogTrace trace, String line) { public void cmsNoDetails(GCLogTrace trace, String line) { if (expectRemark) { expectRemark = false; - CMSRemark remark = new CMSRemark(getClock(), trace.getDoubleGroup(trace.groupCount())); + var remark = new CMSRemark(getClock(), trace.getDoubleGroup(trace.groupCount())); remark.add(getTotalOccupancyWithTotalHeapSizeSummary(trace, 6)); remark.add(extractCPUSummary(line)); publish(remark); } else { expectRemark = true; - InitialMark initialMark = new InitialMark(getClock(), trace.getDoubleGroup(trace.groupCount())); + var initialMark = new InitialMark(getClock(), trace.getDoubleGroup(trace.groupCount())); initialMark.add(getTotalOccupancyWithTotalHeapSizeSummary(trace, 6)); initialMark.add(extractCPUSummary(line)); publish(initialMark); @@ -1531,7 +1524,7 @@ public void cmsNoDetails(GCLogTrace trace, String line) { // 29.975: [Full GC 155252K->44872K(205568K), 0.3398460 secs] public void fullNoGCDetails(GCLogTrace trace, String line) { expectRemark = false; - FullGC fullGC = new FullGC(getClock(), GCCause.UNKNOWN_GCCAUSE, trace.getDuration()); + var fullGC = new FullGC(getClock(), GCCause.UNKNOWN_GCCAUSE, trace.getDuration()); fullGC.add(getTotalOccupancyBeforeAfterWithTotalHeapPoolSizeSummary(trace, 6)); publish(fullGC); } @@ -1555,12 +1548,12 @@ public void gcStart(GCLogTrace trace, String line) { public void youngSplitNoDetails(GCLogTrace trace, String line) { if (garbageCollectionTypeForwardReference == GarbageCollectionTypes.ParNew) { - ParNew parNew = new ParNew(scavengeTimeStamp, GarbageCollectionTypes.ParNew, GCCause.UNKNOWN_GCCAUSE, trace.getDoubleGroup(trace.groupCount())); + var parNew = new ParNew(scavengeTimeStamp, GarbageCollectionTypes.ParNew, GCCause.UNKNOWN_GCCAUSE, trace.getDoubleGroup(trace.groupCount())); parNew.add(getTotalOccupancyBeforeAfterWithTotalHeapPoolSizeSummary(trace, 1)); parNew.add(extractCPUSummary(line)); publish(parNew); } else if (garbageCollectionTypeForwardReference == GarbageCollectionTypes.Young) { - YoungGC youngGC = new YoungGC(scavengeTimeStamp, GarbageCollectionTypes.Young, GCCause.UNKNOWN_GCCAUSE, trace.getDoubleGroup(trace.groupCount())); + var youngGC = new YoungGC(scavengeTimeStamp, GarbageCollectionTypes.Young, GCCause.UNKNOWN_GCCAUSE, trace.getDoubleGroup(trace.groupCount())); youngGC.add(getTotalOccupancyBeforeAfterWithTotalHeapPoolSizeSummary(trace, 1)); youngGC.add(extractCPUSummary(line)); publish(youngGC); @@ -1570,14 +1563,14 @@ public void youngSplitNoDetails(GCLogTrace trace, String line) { //134883.104: [GC-- 2411642K->2456159K(2500288K), 0.1478340 secs] //rarely seen! public void cmfSimple(GCLogTrace trace, String line) { - ConcurrentModeFailure concurrentModeFailure = new ConcurrentModeFailure(getClock(), trace.gcCause(), trace.getDoubleGroup(trace.groupCount())); + var concurrentModeFailure = new ConcurrentModeFailure(getClock(), trace.gcCause(), trace.getDoubleGroup(trace.groupCount())); concurrentModeFailure.add(extractCPUSummary(line)); publish(concurrentModeFailure); } //939.183: [GC [PSYoungGen: 523744K->844K(547584K)] 657668K->135357K(1035008K), 0.0157986 secs] [Times: user=0.30 sys=0.01, real=0.02 secs] public void psYoungGen(GCLogTrace trace, String line) { - PSYoungGen collection = new PSYoungGen(getClock(), trace.gcCause(), trace.getDoubleGroup(trace.groupCount())); + var collection = new PSYoungGen(getClock(), trace.gcCause(), trace.getDoubleGroup(trace.groupCount())); collection.add(trace.getOccupancyBeforeAfterWithMemoryPoolSizeSummary(8), getTotalOccupancyBeforeAfterWithTotalHeapPoolSizeSummary(trace, 14)); collection.add(extractCPUSummary(line)); publish(collection); @@ -1602,11 +1595,11 @@ public void psFull(GCLogTrace trace, String line) { public void psYoungNoDetails(GCLogTrace trace, String line) { GCCause cause = trace.gcCause(); if (GCCause.JAVA_LANG_SYSTEM == cause) { // bug in 1.8.0_121 makes Full System.gc() look like a young collection - SystemGC collection = new SystemGC(trace.getDateTimeStamp(), GCCause.JAVA_LANG_SYSTEM, trace.getDuration()); + var collection = new SystemGC(trace.getDateTimeStamp(), GCCause.JAVA_LANG_SYSTEM, trace.getDuration()); collection.add(trace.getOccupancyBeforeAfterWithMemoryPoolSizeSummary(7)); publish(collection); } else { - PSYoungGen collection = new PSYoungGen(trace.getDateTimeStamp(), cause, trace.getDuration()); + var collection = new PSYoungGen(trace.getDateTimeStamp(), cause, trace.getDuration()); collection.add(trace.getOccupancyBeforeAfterWithMemoryPoolSizeSummary(7)); publish(collection); } @@ -1619,7 +1612,7 @@ public void psYoungGenReferenceProcessingSplit(GCLogTrace trace, String line) { } public void psYoungGenReferenceProcessing(GCLogTrace trace, String line) { - PSYoungGen collection = new PSYoungGen(getClock(), trace.gcCause(), trace.getDuration()); + var collection = new PSYoungGen(getClock(), trace.gcCause(), trace.getDuration()); referenceGCForwardReference = extractPrintReferenceGC(line); collection.add(trace.getOccupancyBeforeAfterWithMemoryPoolSizeSummary(28), getTotalOccupancyBeforeAfterWithTotalHeapPoolSizeSummary(trace, 34)); collection.add(extractCPUSummary(line)); @@ -1672,7 +1665,7 @@ public void psFullReference(GCLogTrace trace, String line) { //47047.534: [Full GC (System.gc()) 47047.534: [Tenured: 292298K->278286K(699072K), 0.7450752 secs] 350258K->278286K(1013824K), [Metaspace: 99239K->99239K(1140736K)], 0.7451777 secs] [Times: user=0.74 sys=0.00, real=0.75 secs] public void psFullReferenceJDK8(GCLogTrace trace, String line) { - FullGC fullGC = new FullGC(getClock(), GarbageCollectionTypes.FullGC, trace.gcCause(), trace.getDuration()); + var fullGC = new FullGC(getClock(), GarbageCollectionTypes.FullGC, trace.gcCause(), trace.getDuration()); MemoryPoolSummary tenured = trace.getOccupancyBeforeAfterWithMemoryPoolSizeSummary(30); MemoryPoolSummary heap = trace.getOccupancyBeforeAfterWithMemoryPoolSizeSummary(37); fullGC.add(heap.minus(tenured), tenured, heap); @@ -1683,10 +1676,10 @@ public void psFullReferenceJDK8(GCLogTrace trace, String line) { } public void serialFullReference(GCLogTrace trace, String line) { - FullGC collection = (trace.gcCause().equals(GCCause.JAVA_LANG_SYSTEM)) ? new SystemGC(trace.getDateTimeStamp(), trace.gcCause(), trace.getDuration()) : new FullGC(trace.getDateTimeStamp(), trace.gcCause(), trace.getDuration()); + FullGC collection = trace.gcCause() == GCCause.JAVA_LANG_SYSTEM ? new SystemGC(trace.getDateTimeStamp(), trace.gcCause(), trace.getDuration()) : new FullGC(trace.getDateTimeStamp(), trace.gcCause(), trace.getDuration()); MemoryPoolSummary tenured = trace.getOccupancyBeforeAfterWithMemoryPoolSizeSummary(30); MemoryPoolSummary heap = trace.getOccupancyBeforeAfterWithMemoryPoolSizeSummary(37); - MemoryPoolSummary young = new MemoryPoolSummary(heap.getOccupancyBeforeCollection() - tenured.getOccupancyBeforeCollection(), 0L, heap.getSizeAfterCollection() - tenured.getSizeAfterCollection()); + var young = new MemoryPoolSummary(heap.getOccupancyBeforeCollection() - tenured.getOccupancyBeforeCollection(), 0L, heap.getSizeAfterCollection() - tenured.getSizeAfterCollection()); collection.add(young, tenured, heap); collection.add(extractPrintReferenceGC(line)); collection.add(extractCPUSummary(line)); @@ -1697,7 +1690,7 @@ public void serialFullReference(GCLogTrace trace, String line) { public void psFullErgonomicsPhases(GCLogTrace trace, String line) { fullGCTimeStamp = getClock(); gcCauseForwardReference = trace.gcCause(); - garbageCollectionTypeForwardReference = (gcCauseForwardReference != GCCause.JAVA_LANG_SYSTEM) ? GarbageCollectionTypes.FullGC : GarbageCollectionTypes.SystemGC; + garbageCollectionTypeForwardReference = gcCauseForwardReference != GCCause.JAVA_LANG_SYSTEM ? GarbageCollectionTypes.FullGC : GarbageCollectionTypes.SystemGC; } public void psFullReferencePhase(GCLogTrace trace, String line) { @@ -1705,7 +1698,7 @@ public void psFullReferencePhase(GCLogTrace trace, String line) { } public void psDetailsWithTenuring(GCLogTrace trace, String line) { - PSYoungGen collection = new PSYoungGen(scavengeTimeStamp, gcCauseForwardReference, trace.getDuration()); + var collection = new PSYoungGen(scavengeTimeStamp, gcCauseForwardReference, trace.getDuration()); collection.add(trace.getOccupancyBeforeAfterWithMemoryPoolSizeSummary(2), getTotalOccupancyBeforeAfterWithTotalHeapPoolSizeSummary(trace, 8)); if (referenceGCForwardReference != null) collection.add(referenceGCForwardReference); @@ -1716,7 +1709,7 @@ public void psDetailsWithTenuring(GCLogTrace trace, String line) { //13.056: [GC-- [PSYoungGen: 4194240K->4194240K(4194240K)] 4280449K->4360823K(4361088K), 0.4589570 secs] //GC-- indicated a promotion failed public void psFailure(GCLogTrace trace, String line) { - PSYoungGen collection = new PSYoungGen(getClock(), GCCause.PROMOTION_FAILED, trace.getDoubleGroup(trace.groupCount())); + var collection = new PSYoungGen(getClock(), GCCause.PROMOTION_FAILED, trace.getDoubleGroup(trace.groupCount())); collection.add(trace.getOccupancyBeforeAfterWithMemoryPoolSizeSummary(8), getTotalOccupancyBeforeAfterWithTotalHeapPoolSizeSummary(trace, 14)); } @@ -1735,7 +1728,7 @@ public void psFullAdaptiveSizePolicy(GCLogTrace trace, String line) { } public void psYoungDetailsFloating(GCLogTrace trace, String line) { - PSYoungGen collection = new PSYoungGen(scavengeTimeStamp, gcCauseForwardReference, trace.getDoubleGroup(trace.groupCount())); + var collection = new PSYoungGen(scavengeTimeStamp, gcCauseForwardReference, trace.getDoubleGroup(trace.groupCount())); collection.add(trace.getOccupancyBeforeAfterWithMemoryPoolSizeSummary(1), getTotalOccupancyBeforeAfterWithTotalHeapPoolSizeSummary(trace, 7)); publish(collection); } @@ -1771,24 +1764,24 @@ public void psFullReferenceAdaptiveSize(GCLogTrace trace, String line) { public void psPromotionFailed(GCLogTrace trace, String line) { if (GarbageCollectionTypes.DefNew == garbageCollectionTypeForwardReference) { - DefNew youngGC = new DefNew(scavengeTimeStamp, gcCauseForwardReference, trace.getDoubleGroup(7)); + var youngGC = new DefNew(scavengeTimeStamp, gcCauseForwardReference, trace.getDoubleGroup(7)); MemoryPoolSummary young = trace.getOccupancyBeforeAfterWithMemoryPoolSizeSummary(1); - MemoryPoolSummary heap = new MemoryPoolSummary(young.getOccupancyBeforeCollection() + trace.toKBytes(9), trace.toKBytes(20), trace.toKBytes(16), trace.toKBytes(20)); + var heap = new MemoryPoolSummary(young.getOccupancyBeforeCollection() + trace.toKBytes(9), trace.toKBytes(20), trace.toKBytes(16), trace.toKBytes(20)); youngGC.add(young, heap); - double cpuBreakDownRatio = trace.getDoubleGroup(7) / trace.getDoubleGroup(trace.groupCount()); + var cpuBreakDownRatio = trace.getDoubleGroup(7) / trace.getDoubleGroup(trace.groupCount()); CPUSummary cpuSummary = extractCPUSummary(line); if (cpuSummary != null) { - double user = cpuSummary.getUser(); - double kernel = cpuSummary.getKernel(); - double real = cpuSummary.getWallClock(); + var user = cpuSummary.getUser(); + var kernel = cpuSummary.getKernel(); + var real = cpuSummary.getWallClock(); youngGC.add(new CPUSummary(user * cpuBreakDownRatio, kernel * cpuBreakDownRatio, real * cpuBreakDownRatio)); cpuBreakDownRatio = 1.0d - cpuBreakDownRatio; cpuSummary = new CPUSummary(user * cpuBreakDownRatio, kernel * cpuBreakDownRatio, real * cpuBreakDownRatio); } publish(youngGC, false); - DateTimeStamp timeOfFullCollection = new DateTimeStamp(trace.getDoubleGroup(8)); //todo: adjust date to match and add it in. - FullGC fullGC = new FullGC(timeOfFullCollection, gcCauseForwardReference, trace.getDoubleGroup(trace.groupCount()) - trace.getDoubleGroup(7)); + var timeOfFullCollection = new DateTimeStamp(trace.getDoubleGroup(8)); //todo: adjust date to match and add it in. + var fullGC = new FullGC(timeOfFullCollection, gcCauseForwardReference, trace.getDoubleGroup(trace.groupCount()) - trace.getDoubleGroup(7)); //young young = new MemoryPoolSummary(young.getOccupancyAfterCollection(), young.getSizeAfterCollection(), 0L, young.getSizeAfterCollection()); fullGC.add(young, trace.getOccupancyBeforeAfterWithMemoryPoolSizeSummary(16)); @@ -1841,8 +1834,8 @@ private void adaptivePolicySizeBody(GCLogTrace trace, String line) { } public void remarkSplitByDebug(GCLogTrace trace, String line) { - long youngOccupancy = trace.getLongGroup(7); - long youngConfiguredSize = trace.getLongGroup(8); + var youngOccupancy = trace.getLongGroup(7); + var youngConfiguredSize = trace.getLongGroup(8); youngMemoryPoolSummaryForwardReference = new MemoryPoolSummary(youngOccupancy, youngConfiguredSize, youngOccupancy, youngConfiguredSize); } @@ -1885,7 +1878,7 @@ public void scavengeBeforeRemarkPrintHeapAtGC(GCLogTrace trace, String line) { // 22.729: [scrub symbol table, 0.0038738 secs]22.733: [scrub string table, 0.0046405 secs] // [1 CMS-remark: 243393K(9378240K)] 310268K(10375040K), 0.2151395 secs] [Times: user=1.12 sys=0.09, real=0.21 secs] public void splitRemarkReference(GCLogTrace trace, String line) { - CMSRemark remark = new CMSRemark(getClock(), gcCauseForwardReference, trace.getPauseTime()); + var remark = new CMSRemark(getClock(), gcCauseForwardReference, trace.getPauseTime()); GCLogTrace remarkClause = REMARK_CLAUSE.parse(line); MemoryPoolSummary tenured = getTotalOccupancyWithTotalHeapSizeSummary(remarkClause, 1); MemoryPoolSummary heap = getTotalOccupancyWithTotalHeapSizeSummary(remarkClause, 5); @@ -1900,30 +1893,28 @@ public void splitRemarkReference(GCLogTrace trace, String line) { //Bug: weak reference processing record is fragmented. private final GCParseRule weakReferenceFragmentRule = new GCParseRule("weakReferenceFragmentRule", "\\], " + PAUSE_TIME); - /** - * public void remarkWithReferenceAndScavenge(GCLogTrace trace, String line) { - * CMSRemark remark = new CMSRemark(getClock(), trace.getDoubleGroup(trace.groupCount() - 3)); - * GCLogTrace remarkClause = REMARK_CLAUSE.parse(line); - * MemoryPoolSummary tenured = getTotalOccupancyWithTotalHeapSizeSummary(remarkClause, 1); - * MemoryPoolSummary heap = getTotalOccupancyWithTotalHeapSizeSummary(remarkClause, 5); - * remark.add(heap.minus(tenured), tenured, heap); - * recordRescanStepTimes(remark, line); - * remark.addReferenceGCSummary(extractPrintReferenceGC(line)); - * remark.add(extractCPUSummary(line)); - * publish(remark); - * } - * @param trace The chunk of GC log that we are attempting to match to a known GC log pattern - * @param line The GC log line being parsed - */ + /// public void remarkWithReferenceAndScavenge(GCLogTrace trace, String line) { + /// CMSRemark remark = new CMSRemark(getClock(), trace.getDoubleGroup(trace.groupCount() - 3)); + /// GCLogTrace remarkClause = REMARK_CLAUSE.parse(line); + /// MemoryPoolSummary tenured = getTotalOccupancyWithTotalHeapSizeSummary(remarkClause, 1); + /// MemoryPoolSummary heap = getTotalOccupancyWithTotalHeapSizeSummary(remarkClause, 5); + /// remark.add(heap.minus(tenured), tenured, heap); + /// recordRescanStepTimes(remark, line); + /// remark.addReferenceGCSummary(extractPrintReferenceGC(line)); + /// remark.add(extractCPUSummary(line)); + /// publish(remark); + /// } + /// @param trace The chunk of GC log that we are attempting to match to a known GC log pattern + /// @param line The GC log line being parsed public void splitRemarkReferenceWithWeakReferenceSplitBug(GCLogTrace trace, String line) { GCLogTrace remarkTrace = REMARK_CLAUSE.parse(line); Pattern durationGroupPattern = Pattern.compile(".* " + PAUSE_TIME); Matcher matcher = durationGroupPattern.matcher(line); - double duration = 0.0d; + var duration = 0.0d; if (matcher.find()) { duration = Double.parseDouble(matcher.group(matcher.groupCount())); } - CMSRemark collection = new CMSRemark(getClock(), GCCause.CMS_FINAL_REMARK, duration); + var collection = new CMSRemark(getClock(), GCCause.CMS_FINAL_REMARK, duration); MemoryPoolSummary tenured = getTotalOccupancyWithTotalHeapSizeSummary(remarkTrace, 1); MemoryPoolSummary heap = getTotalOccupancyWithTotalHeapSizeSummary(remarkTrace, 5); collection.add(heap.minus(tenured), tenured, heap); @@ -1947,7 +1938,7 @@ public void adaptiveSizePolicyStop(GCLogTrace trace, String line) { private final GCParseRule cmsRemarkBlockRule = new GCParseRule("CMS_REMARK_BLOCK", REMARK_BLOCK); private void recordRemark(GCLogTrace trace, String line, GCCause gcCause) { - CMSRemark collection = (gcCause == GCCause.UNKNOWN_GCCAUSE) + CMSRemark collection = gcCause == GCCause.UNKNOWN_GCCAUSE ? new CMSRemark(getClock(), trace.getDuration()) : new CMSRemark(getClock(), gcCause, trace.getDuration()); @@ -2037,22 +2028,22 @@ private void log(String line) { //this rule must be evaluated before CONCURRENT_PHASE_END_BLOCK private void abortPrecleanDueToTime(GCLogTrace trace, String line) { try { - double cpuTime = trace.getDoubleGroup(7); - double wallClock = trace.getDoubleGroup(8); + var cpuTime = trace.getDoubleGroup(7); + var wallClock = trace.getDoubleGroup(8); publish(new AbortablePreClean(startOfConcurrentPhase, wallClock, cpuTime, wallClock, true)); abortPrecleanDueToTime = false; - } catch (Exception e) { + } catch (Exception _) { LOGGER.warning("concurrent phase end choked on " + trace); } } private void abortPrecleanWithCards(GCLogTrace trace, String line) { try { - double cpuTime = trace.getDoubleGroup(10); - double wallClock = trace.getDoubleGroup(11); + var cpuTime = trace.getDoubleGroup(10); + var wallClock = trace.getDoubleGroup(11); publish(new AbortablePreClean(startOfConcurrentPhase, wallClock, cpuTime, wallClock, false)); abortPrecleanDueToTime = false; - } catch (Exception e) { + } catch (Exception _) { LOGGER.warning("concurrent phase end choked on " + trace); } } @@ -2069,16 +2060,16 @@ private void endConcurrentPrecleanWithReferenceProcessing(GCLogTrace trace, Stri GCLogTrace concurrentBlock = CONCURRENT_PHASE_END_BLOCK.parse(line); try { publish(new ConcurrentPreClean(startOfConcurrentPhase, concurrentBlock.getDoubleGroup(11), concurrentBlock.getDoubleGroup(7), concurrentBlock.getDoubleGroup(8))); - } catch (Throwable t) { + } catch (Throwable _) { LOGGER.warning("Unable to extract data from " + trace.toString()); } } private void endOfConcurrentPhase(GCLogTrace trace, DateTimeStamp timeStamp, int offset) { String phase = trace.getGroup(6 + offset); - double cpuTime = trace.getDoubleGroup(7 + offset); - double wallTime = trace.getDoubleGroup(8 + offset); - double duration = timeStamp.toSeconds() - startOfConcurrentPhase.toSeconds(); + var cpuTime = trace.getDoubleGroup(7 + offset); + var wallTime = trace.getDoubleGroup(8 + offset); + var duration = timeStamp.toSeconds() - startOfConcurrentPhase.toSeconds(); switch (phase) { case "mark": @@ -2139,7 +2130,7 @@ public void publish(JVMEvent event, boolean clear) { super.publish(ChannelName.GENERATIONAL_HEAP_PARSER_OUTBOX, event); } - final private ArrayList queue = new ArrayList<>(); + final private List queue = new ArrayList<>(); public void publish(GenerationalGCPauseEvent event) { if ( inConcurrentPhase) { queue.add(event); diff --git a/parser/src/main/java/com/microsoft/gctoolkit/parser/ICMSPatterns.java b/parser/src/main/java/com/microsoft/gctoolkit/parser/ICMSPatterns.java index f65f0cca..7ee9d016 100644 --- a/parser/src/main/java/com/microsoft/gctoolkit/parser/ICMSPatterns.java +++ b/parser/src/main/java/com/microsoft/gctoolkit/parser/ICMSPatterns.java @@ -2,14 +2,12 @@ // Licensed under the MIT License. package com.microsoft.gctoolkit.parser; -/** - * Patterns for the incremental Concurrent Mark and Sweep (iCMS) collector - */ +/// Patterns for the incremental Concurrent Mark and Sweep (iCMS) collector public interface ICMSPatterns extends CMSPatterns { String ICMS_DC = " icms_dc=(\\d+) "; - /***** iCMS records ******/ + /// *** iCMS records ***** //Greedy: 263204.684: [GC263204.684: [ParNew (promotion failed): 153342K->153343K(153344K), 0.0910130 secs]263204.776: [CMS: 1752518K->1636004K(1926784K), 8.9443330 secs] 1889511K->1636004K(2080128K), [CMS Perm : 137004K->135442K(233916K)] icms_dc=75 , 9.0355990 secs] //Greedy: 410971.012: [GC 410971.012: [ParNew (promotion failed): 153068K->153068K(153344K), 0.1683040 secs]410971.180: [CMS: 1414041K->1301153K(1926784K), 7.3235580 secs] 1543745K->1301153K(2080128K), [CMS Perm : 137698K->135751K(235644K)] icms_dc=19 , 7.4921120 secs] //Missed: 357305.590: [GC 357305.590: [ParNew (promotion failed): 10973K->3147K(153344K), 0.0295730 secs] 1763339K->1763817K(2080128K) icms_dc=32 , 0.0297680 secs] diff --git a/parser/src/main/java/com/microsoft/gctoolkit/parser/JHiccupTrace.java b/parser/src/main/java/com/microsoft/gctoolkit/parser/JHiccupTrace.java index 1ade84df..a1e4374d 100644 --- a/parser/src/main/java/com/microsoft/gctoolkit/parser/JHiccupTrace.java +++ b/parser/src/main/java/com/microsoft/gctoolkit/parser/JHiccupTrace.java @@ -2,12 +2,12 @@ // Licensed under the MIT License. package com.microsoft.gctoolkit.parser; +import org.jspecify.annotations.Nullable; + import java.util.regex.Matcher; import java.util.regex.Pattern; -/** - * Class that represents a chunk of a jHiccup log that we are attempting to match to a - */ +/// Class that represents a chunk of a jHiccup log that we are attempting to match to a public class JHiccupTrace { //0.124,1.004,2.408,HIST @@ -21,9 +21,9 @@ public class JHiccupTrace { private final Matcher trace; - public static JHiccupTrace toTrace(String line) { + public static @Nullable JHiccupTrace toTrace(String line) { Matcher m = JHICCUP_LOG_ENTRY.matcher(line); - return (m == null) ? null : new JHiccupTrace(m); + return m == null ? null : new JHiccupTrace(m); } protected JHiccupTrace(Matcher matcher) { diff --git a/parser/src/main/java/com/microsoft/gctoolkit/parser/JVMEventParser.java b/parser/src/main/java/com/microsoft/gctoolkit/parser/JVMEventParser.java index d08181de..b405dc1b 100644 --- a/parser/src/main/java/com/microsoft/gctoolkit/parser/JVMEventParser.java +++ b/parser/src/main/java/com/microsoft/gctoolkit/parser/JVMEventParser.java @@ -34,16 +34,15 @@ public Set eventsProduced() { return Set.of(EventSource.JVM); } + @Override public String getName() { return "JVMEventParser"; } - /** - * Application stopped time records prior to 7.0 are not timestamped. - * In those cases one can use Application Run time to reconstruct the timings - * If Application run time is missing, collect records and estimate run times - * based on a change in the value of getClock(); - */ + /// Application stopped time records prior to 7.0 are not timestamped. + /// In those cases one can use Application Run time to reconstruct the timings + /// If Application run time is missing, collect records and estimate run times + /// based on a change in the value of getClock(); @Override protected void process(String line) { @@ -54,7 +53,7 @@ protected void process(String line) { if ((trace = APPLICATION_STOP_TIME.parse(line)) != null) { if (lastEventWasGC) { // can estimate TTSP - double duration = trace.getDoubleGroup(3); + var duration = trace.getDoubleGroup(3); publish(new ApplicationStoppedTime(trace.getDateTimeStamp(), duration, duration - gcPauseTime, lastEventWasGC)); lastEventWasGC = false; gcPauseTime = GCPAUSE_TIME_NOT_SET; @@ -81,7 +80,7 @@ protected void process(String line) { extractTLAB(trace, 0); } else if ((trace = TLAB_TOTALS.parse(line)) != null) { extractTLABSummary(trace); - } else if (line.equals(END_OF_DATA_SENTINEL)) { + } else if (END_OF_DATA_SENTINEL.equals(line)) { // TODO: #154 else if (line.equals(END_OF_DATA_SENTINEL)|| (JVM_EXIT.parse(line) != null)) { // if we see "^heap" then we're at the end of the log // at issue is if logs have been concatenated then we're not at the end and we @@ -93,7 +92,7 @@ protected void process(String line) { timeStamp = getClock(); } - } catch (Throwable t) { + } catch (Throwable _) { LOGGER.log(Level.FINE, "Missed: {0}", line); } } @@ -105,23 +104,23 @@ private void extractTLABSummary(GCLogTrace trace) { @SuppressWarnings("unused") private void extractTLAB(GCLogTrace trace, int offset) { String gcThreadId = trace.getGroup(1 + offset); - int id = trace.getIntegerGroup(2 + offset); - int desiredSize = trace.getIntegerGroup(3 + offset); - int slowAllocs = trace.getIntegerGroup(4 + offset); - int refillWaste = trace.getIntegerGroup(5 + offset); - double allocFraction = trace.getDoubleGroup(6 + offset); - int unknownKBField = trace.getIntegerGroup(7 + offset); - int refills = trace.getIntegerGroup(8 + offset); - double wastePercent = trace.getDoubleGroup(9 + offset); - int gcUknownField = trace.getIntegerGroup(10 + offset); - int slowUnknown = trace.getIntegerGroup(11 + offset); - int fastUnknown = trace.getIntegerGroup(12 + offset); + var id = trace.getIntegerGroup(2 + offset); + var desiredSize = trace.getIntegerGroup(3 + offset); + var slowAllocs = trace.getIntegerGroup(4 + offset); + var refillWaste = trace.getIntegerGroup(5 + offset); + var allocFraction = trace.getDoubleGroup(6 + offset); + var unknownKBField = trace.getIntegerGroup(7 + offset); + var refills = trace.getIntegerGroup(8 + offset); + var wastePercent = trace.getDoubleGroup(9 + offset); + var gcUknownField = trace.getIntegerGroup(10 + offset); + var slowUnknown = trace.getIntegerGroup(11 + offset); + var fastUnknown = trace.getIntegerGroup(12 + offset); } //todo: should actually use the timings in the log but this is ok for now. private void drainSafePoints() { - double interval = (getClock().getTimeStamp() - (timeStamp.getTimeStamp())) / (safePoints.size() + 1); - double timeValue = getClock().getTimeStamp() + interval; + var interval = (getClock().getTimeStamp() - (timeStamp.getTimeStamp())) / (safePoints.size() + 1); + var timeValue = getClock().getTimeStamp() + interval; for (SafePointData safePointData : safePoints) { publish(safePointData.complete(new DateTimeStamp(timeValue))); timeValue += interval; @@ -145,6 +144,7 @@ private static class StoppedTime extends SafePointData { gcInduced = gc; } + @Override JVMEvent complete(DateTimeStamp dateTimeStamp) { return new ApplicationStoppedTime(dateTimeStamp, duration, gcInduced); } @@ -156,6 +156,7 @@ private static class ConcurrentTime extends SafePointData { duration = timing; } + @Override JVMEvent complete(DateTimeStamp dateTimeStamp) { return new ApplicationConcurrentTime(dateTimeStamp, duration); } diff --git a/parser/src/main/java/com/microsoft/gctoolkit/parser/PreUnifiedG1GCParser.java b/parser/src/main/java/com/microsoft/gctoolkit/parser/PreUnifiedG1GCParser.java index c53a8ce4..1c79797a 100644 --- a/parser/src/main/java/com/microsoft/gctoolkit/parser/PreUnifiedG1GCParser.java +++ b/parser/src/main/java/com/microsoft/gctoolkit/parser/PreUnifiedG1GCParser.java @@ -35,21 +35,20 @@ import com.microsoft.gctoolkit.time.DateTimeStamp; import java.util.AbstractMap; +import java.util.Queue; import java.util.Set; import java.util.concurrent.ConcurrentLinkedQueue; import java.util.function.BiConsumer; import java.util.logging.Level; import java.util.logging.Logger; -/** - * TODO No reports or views generated from this data yet. - *

- * Result - * -0 on when GC started - * - type of GC triggered - * - from, to, configured - * - pause time if it is reported or can be calculated - */ +/// TODO No reports or views generated from this data yet. +/// +/// Result +/// -0 on when GC started +/// - type of GC triggered +/// - from, to, configured +/// - pause time if it is reported or can be calculated public class PreUnifiedG1GCParser extends PreUnifiedGCLogParser implements G1GCPatterns { private static final Logger LOGGER = Logger.getLogger(PreUnifiedG1GCParser.class.getName()); @@ -74,7 +73,7 @@ public class PreUnifiedG1GCParser extends PreUnifiedGCLogParser implements G1GCP private DateTimeStamp concurrentPhaseStartTimeStamp; private GarbageCollectionTypes concurrentCollectionTypeForwardReference; - private final ConcurrentLinkedQueue backlog = new ConcurrentLinkedQueue<>(); + private final Queue backlog = new ConcurrentLinkedQueue<>(); private final MRUQueue> parseRules; @@ -246,6 +245,7 @@ public Set eventsProduced() { return Set.of(EventSource.G1GC); } + @Override public String getName() { return "PreUnifiedG1GCParser"; } @@ -290,9 +290,7 @@ void g1FullAdaptiveSizing(GCLogTrace trace, String line) { collectionTypeForwardReference = GarbageCollectionTypes.Full; } - /** - * Convert if-else blocks to method calls to model GenerationalHeapParser implementation - */ + /// Convert if-else blocks to method calls to model GenerationalHeapParser implementation private void g1YoungSplitStart(GCLogTrace trace, String line) { timeStampForwardReference = getClock(); @@ -317,13 +315,11 @@ private void recordTableFixup(GCLogTrace trace, String line) { ((G1Young) forwardReference).tableFixupStatistics(summary); } - /** - * Quick failure for lines that commonly appear that aren't interesting for this - * parser. - * - * @param line log line - * @return boolean true is the line should be ignored. - */ + /// Quick failure for lines that commonly appear that aren't interesting for this + /// parser. + /// + /// @param line log line + /// @return boolean true is the line should be ignored. private final GCParseRule corruptedApplicationTime = new GCParseRule("corruptedApplicationTime", DATE_TIMESTAMP + TIMESTAMP); private boolean ignoreFrequentlySeenButUnwantedLines(String line) { @@ -343,19 +339,17 @@ private boolean ignoreFrequentlySeenButUnwantedLines(String line) { if (line.startsWith("No shared spaces configured.")) return true; if (line.startsWith("Heap after GC invocations=")) return true; if (line.startsWith("OpenJDK")) return true; - if (line.equals("}")) return true; + if ("}".equals(line)) return true; if (line.startsWith("Java HotSpot(TM)")) return true; if (line.startsWith("CommandLine")) return true; if (line.startsWith("Memory: ")) return true; return line.contains("Allocation failed. Thread"); } - /** - * Ignore rules we don't need to deriveConfiguration. - * - * @param trace GCLogTrace that hits this log line - * @param line Log line. - */ + /// Ignore rules we don't need to deriveConfiguration. + /// + /// @param trace GCLogTrace that hits this log line + /// @param line Log line. private void ignore(GCLogTrace trace, String line) { return; } @@ -368,8 +362,8 @@ private void ignore(GCLogTrace trace, String line) { //115.421: [GC pause (G1 Evacuation Pause) (young) (initial-mark) (to-space exhausted), 0.0476190 secs] //2025-03-23T03:57:20.841+0000: 661.878: [GC pause (System.gc()) (young) (initial-mark), 0.0502295 secs] private void processYoungGenCollection(GCLogTrace trace, String line) { - boolean initialMark = trace.contains(8, "initial-mark"); - boolean tospaceExhausted = trace.contains(trace.groupCount() - 2, "to-space"); + var initialMark = trace.contains(8, "initial-mark"); + var tospaceExhausted = trace.contains(trace.groupCount() - 2, "to-space"); if (trace.contains(7, "young")) { if (initialMark) @@ -451,7 +445,7 @@ private void processNoDetailsMemorySummary(GCLogTrace trace, String line) { publish(forwardReference); } } else if (collectionTypeForwardReference == GarbageCollectionTypes.G1GCCleanup) { - G1Cleanup cleanup = new G1Cleanup(timeStampForwardReference, trace.getDuration()); + var cleanup = new G1Cleanup(timeStampForwardReference, trace.getDuration()); cleanup.addMemorySummary(summary); publish(cleanup); } else @@ -463,7 +457,7 @@ private void processParallelPhaseSummary(GCLogTrace trace, String line) { } private void processParallelPhase(GCLogTrace trace, String line) { - double count = trace.getDoubleGroup(2); + var count = trace.getDoubleGroup(2); ((G1Young) forwardReference).addParallelPhaseSummary(trace.getGroup(1), new StatisticalSummary(count, count, count, 0.0d, count)); } @@ -507,8 +501,8 @@ else if (line.contains("End")) } private void solarisWorkerParallelBlock(GCLogTrace trace, String line) { - double time = trace.getDoubleGroup(2); - StatisticalSummary summary = new StatisticalSummary(time, time, time, 0.0d, time); + var time = trace.getDoubleGroup(2); + var summary = new StatisticalSummary(time, time, time, 0.0d, time); if (line.contains("Start")) ((G1Young) forwardReference).setWorkersStart(summary); else if (line.contains("End")) @@ -520,7 +514,7 @@ private void processedBuffers(GCLogTrace trace, String line) { } private void processedBuffer(GCLogTrace trace, String line) { - int count = trace.getIntegerGroup(1); + var count = trace.getIntegerGroup(1); ((G1Young) forwardReference).addProcessedBuffersSummary(new StatisticalSummary(count, count, count, 0.0d, count)); } @@ -748,7 +742,7 @@ private void youngSplitAtTimestamp(GCLogTrace trace, String line) { } private void freeFloatingYoungBlock(GCLogTrace trace, String line) { - boolean initialMark = false; + var initialMark = false; if (trace.getGroup(3) != null) initialMark = trace.contains(3, "initial-mark"); if (trace.contains(2, "young")) @@ -830,10 +824,10 @@ private void g1ConcurrentStart(GCLogTrace trace, String line) { } private void concurrentStringDedup(GCLogTrace trace, String line) { - double startingStringVolume = trace.toKBytes(4); - double endingStringValue = trace.toKBytes(6); - double reduction = trace.toKBytes(8); - double percentReduction = trace.getDoubleGroup(10); + var startingStringVolume = trace.toKBytes(4); + var endingStringValue = trace.toKBytes(6); + var reduction = trace.toKBytes(8); + var percentReduction = trace.getDoubleGroup(10); publish(new G1ConcurrentStringDeduplication(getClock(), trace.gcCause(), startingStringVolume, endingStringValue, reduction, percentReduction, trace.getDoubleGroup(trace.groupCount()))); } @@ -841,18 +835,18 @@ private void concurrentStringDedup(GCLogTrace trace, String line) { //6.298: [GC remark 6.298: [GC ref-proc, 0.0000570 secs], 0.0010940 secs] //2014-02-21T16:04:24.321-0100: 7.852: [GC remark 2014-02-21T16:04:24.322-0100: 7.853: [GC ref-proc, 0.0000640 secs], 0.0013310 secs] private void g1Remark(GCLogTrace trace, String line) { - publish(new G1Remark(trace.getDateTimeStamp(), (trace.getGroup(13) != null) ? trace.getDoubleGroup(13) : 0.0d, trace.getDoubleGroup(trace.groupCount()))); + publish(new G1Remark(trace.getDateTimeStamp(), trace.getGroup(13) != null ? trace.getDoubleGroup(13) : 0.0d, trace.getDoubleGroup(trace.groupCount()))); } //2015-04-09T14:28:44.235+0100: 6.597: [GC remark 6.597: [Finalize Marking, 0.0091510 secs] 6.606: [GC ref-proc, 0.0014102 secs] 6.608: [Unloading, 0.0044869 secs], 0.0153351 secs] //public G1Remark( DateTimeStamp timeStamp, double referenceProcessingTimes, double finalizeMarking, double unloading, double duration) private void g1180Remark(GCLogTrace trace, String line) { - G1Remark remark = new G1Remark(trace.getDateTimeStamp(), trace.getDoubleGroup(17), trace.getDoubleGroup(11), trace.getDoubleGroup(23), trace.getDoubleGroup(trace.groupCount())); + var remark = new G1Remark(trace.getDateTimeStamp(), trace.getDoubleGroup(17), trace.getDoubleGroup(11), trace.getDoubleGroup(23), trace.getDoubleGroup(trace.groupCount())); publish(remark); } private void g1180RemarkRefDetails(GCLogTrace trace, String line) { - G1Remark remark = new G1Remark(trace.getDateTimeStamp(), trace.getDoubleGroup(56), trace.getDoubleGroup(11), trace.getDoubleGroup(trace.groupCount() - 1), trace.getDuration()); + var remark = new G1Remark(trace.getDateTimeStamp(), trace.getDoubleGroup(56), trace.getDoubleGroup(11), trace.getDoubleGroup(trace.groupCount() - 1), trace.getDuration()); remark.add(extractPrintReferenceGC(line)); publish(remark); } @@ -860,13 +854,13 @@ private void g1180RemarkRefDetails(GCLogTrace trace, String line) { //549.253: [GC cleanup 7826K->7826K(13M), 0.0004750 secs] //todo: capture memory summary private void g1Cleanup(GCLogTrace trace, String line) { - G1Cleanup cleanup = new G1Cleanup(trace.getDateTimeStamp(), trace.getPauseTime()); + var cleanup = new G1Cleanup(trace.getDateTimeStamp(), trace.getPauseTime()); cleanup.addMemorySummary(getTotalOccupancyBeforeAfterWithTotalHeapPoolSizeSummary(trace, 7)); publish(cleanup); } private void g1CleanupNoMemory(GCLogTrace trace, String line) { - G1Cleanup cleanup = new G1Cleanup(trace.getDateTimeStamp(), trace.getPauseTime()); + var cleanup = new G1Cleanup(trace.getDateTimeStamp(), trace.getPauseTime()); publish(cleanup); } @@ -878,7 +872,7 @@ private void splitCleanup(GCLogTrace trace, String line) { //511.628: [GC concurrent-mark-abort] private void g1ConcurrentAbort(GCLogTrace trace, String line) { if (concurrentPhaseStartTimeStamp != null) { - G1ConcurrentMark concurrentMark = new G1ConcurrentMark(concurrentPhaseStartTimeStamp, trace.gcCause(), trace.getTimeStamp() - concurrentPhaseStartTimeStamp.getTimeStamp()); + var concurrentMark = new G1ConcurrentMark(concurrentPhaseStartTimeStamp, trace.gcCause(), trace.getTimeStamp() - concurrentPhaseStartTimeStamp.getTimeStamp()); concurrentMark.abort(); publish(concurrentMark); } @@ -922,7 +916,7 @@ public void g1FloatingConcurrentPhaseStart(GCLogTrace trace, String line) { /***********************************/ /* Reference processing */ - /***********************************/ + /// ******************************** private void g1DetailsReferenceGC(GCLogTrace trace, String line) { @@ -934,8 +928,8 @@ private void g1DetailsReferenceGC(GCLogTrace trace, String line) { private void g1RemarkReferenceGC(GCLogTrace trace, String line) { ReferenceGCSummary summary = extractPrintReferenceGC(line); - double totalReferenceProcessingTime = summary.getSoftReferencePauseTime() + summary.getWeakReferencePauseTime() + summary.getFinalReferencePauseTime() + summary.getPhantomReferencePauseTime() + summary.getJniWeakReferencePauseTime(); - G1Remark remark = new G1Remark(getClock(), totalReferenceProcessingTime, trace.getPauseTime()); + var totalReferenceProcessingTime = summary.getSoftReferencePauseTime() + summary.getWeakReferencePauseTime() + summary.getFinalReferencePauseTime() + summary.getPhantomReferencePauseTime() + summary.getJniWeakReferencePauseTime(); + var remark = new G1Remark(getClock(), totalReferenceProcessingTime, trace.getPauseTime()); remark.add(summary); publish(remark); } @@ -1024,7 +1018,7 @@ private void g1FullInterruptsConcurrentWithReferences(GCLogTrace trace, String l private void g1FullMemorySplitByConcurrent(GCLogTrace trace, String line) { if (collectionTypeForwardReference == GarbageCollectionTypes.Full) { - G1FullGCNES full = new G1FullGCNES(timeStampForwardReference, gcCauseForwardReference, trace.getPauseTime()); + var full = new G1FullGCNES(timeStampForwardReference, gcCauseForwardReference, trace.getPauseTime()); full.addMemorySummary(trace.getOccupancyBeforeAfterWithMemoryPoolSizeSummary(1)); publish(full); } else @@ -1034,7 +1028,7 @@ private void g1FullMemorySplitByConcurrent(GCLogTrace trace, String line) { /***********************************/ /* Adaptive Sizing */ - /***********************************/ + /// ******************************** private void youngSplitByG1Ergonomics(GCLogTrace trace, String line) { timeStampForwardReference = getClock(); @@ -1061,7 +1055,7 @@ else if ("mixed".equals(trace.getGroup(4))) /***********************************/ /* Heap Summary */ - /***********************************/ + /// ******************************** //We have found this section. If PrintHeapAtGC does not interfere // this method should consume all remaining lines @@ -1091,7 +1085,7 @@ private void classspaceFinal(GCLogTrace trace, String line) { /* Pre 170_40 rules */ /* Very old and should not be used */ - /***********************************/ + /// ******************************** @SuppressWarnings("unused") private void g1Pre17040Summary(GCLogTrace trace, String line) { @@ -1109,7 +1103,7 @@ private void g1Pre17040Summary(GCLogTrace trace, String line) { /*************************/ /* Support Methods */ - /*************************/ + /// ********************** private void g1ConcurrentEnd(GCLogTrace trace, String line) { //If concurrentPhaseStartTimeStamp is null, something went wrong in the parsing. @@ -1156,23 +1150,21 @@ private StatisticalSummary extractCounterSummary(GCLogTrace trace, int offset) { } private MemoryPoolSummary extractPoolSummary(GCLogTrace trace, int offset) { - long occupancyBefore = trace.doubleToKBytes(offset); - long sizeBefore = trace.doubleToKBytes(offset + 2); - long occupancyAfter = trace.doubleToKBytes(offset + 4); - long size = trace.doubleToKBytes(offset + 6); + var occupancyBefore = trace.doubleToKBytes(offset); + var sizeBefore = trace.doubleToKBytes(offset + 2); + var occupancyAfter = trace.doubleToKBytes(offset + 4); + var size = trace.doubleToKBytes(offset + 6); return new MemoryPoolSummary(occupancyBefore, sizeBefore, occupancyAfter, size); } private SurvivorMemoryPoolSummary extractSurvivorPoolSummary(GCLogTrace trace, int offset) { - long occupancyBefore = trace.doubleToKBytes(offset); - long occupancyAfter = trace.doubleToKBytes(offset + 2); + var occupancyBefore = trace.doubleToKBytes(offset); + var occupancyAfter = trace.doubleToKBytes(offset + 2); return new SurvivorMemoryPoolSummary(occupancyBefore, occupancyAfter); } - /** - * Maintain time ordering of records. Concurrent phases are recorded at start time and thus - * other phases may mix in. - */ + /// Maintain time ordering of records. Concurrent phases are recorded at start time and thus + /// other phases may mix in. private void drainBacklog() { if (backlog.size() > 0) for (JVMEvent event : backlog) diff --git a/parser/src/main/java/com/microsoft/gctoolkit/parser/PreUnifiedGCLogParser.java b/parser/src/main/java/com/microsoft/gctoolkit/parser/PreUnifiedGCLogParser.java index 4e5dfb3c..dfe5281e 100644 --- a/parser/src/main/java/com/microsoft/gctoolkit/parser/PreUnifiedGCLogParser.java +++ b/parser/src/main/java/com/microsoft/gctoolkit/parser/PreUnifiedGCLogParser.java @@ -15,6 +15,7 @@ public abstract class PreUnifiedGCLogParser extends GCLogParser { public PreUnifiedGCLogParser() {} + @Override void advanceClock(String record) { try { GCLogTrace trace = TIMESTAMP_BLOCK.parse(record); diff --git a/parser/src/main/java/com/microsoft/gctoolkit/parser/PreUnifiedTokens.java b/parser/src/main/java/com/microsoft/gctoolkit/parser/PreUnifiedTokens.java index 856bbae3..987e29c3 100644 --- a/parser/src/main/java/com/microsoft/gctoolkit/parser/PreUnifiedTokens.java +++ b/parser/src/main/java/com/microsoft/gctoolkit/parser/PreUnifiedTokens.java @@ -2,11 +2,9 @@ // Licensed under the MIT License. package com.microsoft.gctoolkit.parser; -/** - * Interface that contains String and ParseRule representations of common - * data types within GC Log data.These tokens are used in Regular Expressions - * Pattern matching in the GC Log parser(s) - */ +/// Interface that contains String and ParseRule representations of common +/// data types within GC Log data.These tokens are used in Regular Expressions +/// Pattern matching in the GC Log parser(s) public interface PreUnifiedTokens extends GenericTokens { // Time values diff --git a/parser/src/main/java/com/microsoft/gctoolkit/parser/SafepointParseRule.java b/parser/src/main/java/com/microsoft/gctoolkit/parser/SafepointParseRule.java index 11be6836..3d79e226 100644 --- a/parser/src/main/java/com/microsoft/gctoolkit/parser/SafepointParseRule.java +++ b/parser/src/main/java/com/microsoft/gctoolkit/parser/SafepointParseRule.java @@ -3,6 +3,7 @@ package com.microsoft.gctoolkit.parser; import com.microsoft.gctoolkit.parser.vmops.SafepointTrace; +import org.jspecify.annotations.Nullable; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; @@ -10,10 +11,8 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -/** - * Class that tracks whether a log entry was parsed successfully (hit), or not - * (miss) and captures the origin of that hit or miss. - */ +/// Class that tracks whether a log entry was parsed successfully (hit), or not +/// (miss) and captures the origin of that hit or miss. public class SafepointParseRule { private static final ConcurrentMap hits = new ConcurrentHashMap<>(); @@ -24,19 +23,17 @@ public class SafepointParseRule { public SafepointParseRule(String pattern) { this.pattern = Pattern.compile(pattern); - Throwable throwable = new Throwable(); + var throwable = new Throwable(); throwable = throwable.fillInStackTrace(); origin.put(this, throwable); } - /** - * TODO #155 This painful pattern of returning a null which gets checked by - * the caller could be replaced by use of Optional - * - * @param trace The trace to match against the pattern - * @return A trace with a valid matcher or null - */ - public SafepointTrace parse(String trace) { + /// TODO #155 This painful pattern of returning a null which gets checked by + /// the caller could be replaced by use of Optional + /// + /// @param trace The trace to match against the pattern + /// @return A trace with a valid matcher or null + public @Nullable SafepointTrace parse(String trace) { Matcher matcher = pattern.matcher(trace); if (matcher.find()) { hits(); diff --git a/parser/src/main/java/com/microsoft/gctoolkit/parser/SharedPatterns.java b/parser/src/main/java/com/microsoft/gctoolkit/parser/SharedPatterns.java index f653960a..c2fe5907 100644 --- a/parser/src/main/java/com/microsoft/gctoolkit/parser/SharedPatterns.java +++ b/parser/src/main/java/com/microsoft/gctoolkit/parser/SharedPatterns.java @@ -2,11 +2,9 @@ // Licensed under the MIT License. package com.microsoft.gctoolkit.parser; -/** - * TODO: #157 There needs to be a clearer separation of what is a Token vs what is a SharedPattern - *

- * Shared generational rules - */ +/// TODO: #157 There needs to be a clearer separation of what is a Token vs what is a SharedPattern +/// +/// Shared generational rules public interface SharedPatterns extends PreUnifiedTokens { String WEAK_REF_BLOCK = DATE_TIMESTAMP + "\\[weak refs processing, " + PAUSE_TIME + "\\]"; diff --git a/parser/src/main/java/com/microsoft/gctoolkit/parser/ShenandoahParser.java b/parser/src/main/java/com/microsoft/gctoolkit/parser/ShenandoahParser.java index fb957810..7e7d6743 100644 --- a/parser/src/main/java/com/microsoft/gctoolkit/parser/ShenandoahParser.java +++ b/parser/src/main/java/com/microsoft/gctoolkit/parser/ShenandoahParser.java @@ -19,17 +19,15 @@ import java.util.logging.Level; import java.util.logging.Logger; -/** - * Time of GC - * GCType - * Collect total heap values - * Heap before collection - * Heap after collection - * Heap configured size - * total pause time - * CMS failures - * System.gc() calls - */ +/// Time of GC +/// GCType +/// Collect total heap values +/// Heap before collection +/// Heap after collection +/// Heap configured size +/// total pause time +/// CMS failures +/// System.gc() calls public class ShenandoahParser extends UnifiedGCLogParser implements ShenandoahPatterns { diff --git a/parser/src/main/java/com/microsoft/gctoolkit/parser/SurvivorMemoryPoolParser.java b/parser/src/main/java/com/microsoft/gctoolkit/parser/SurvivorMemoryPoolParser.java index 4fbbd9d6..998d4a97 100644 --- a/parser/src/main/java/com/microsoft/gctoolkit/parser/SurvivorMemoryPoolParser.java +++ b/parser/src/main/java/com/microsoft/gctoolkit/parser/SurvivorMemoryPoolParser.java @@ -24,17 +24,16 @@ public Set eventsProduced() { return Set.of(EventSource.SURVIVOR); } + @Override public String getName() { return "SurvivorMemoryPoolParser"; } - /** - * 61.572: [GC 61.572: [ParNew - * Desired survivor size 1343488 bytes, new threshold 4 (max 4) - * - age 1: 25176 bytes, 25176 total - * - * @param entry : GC log entry to deriveConfiguration - */ + /// 61.572: [GC 61.572: [ParNew + /// Desired survivor size 1343488 bytes, new threshold 4 (max 4) + /// - age 1: 25176 bytes, 25176 total + /// + /// @param entry : GC log entry to deriveConfiguration @Override protected void process(String entry) { GCLogTrace trace; @@ -43,7 +42,7 @@ protected void process(String entry) { forwardReference = new SurvivorRecord(getClock(), trace.getLongGroup(1), trace.getIntegerGroup(2), trace.getIntegerGroup(3)); } else if ((trace = TENURING_AGE_BREAKDOWN.parse(entry)) != null) { forwardReference.add(trace.getIntegerGroup(1), trace.getLongGroup(2)); - } else if (entry.equals(END_OF_DATA_SENTINEL) || (JVM_EXIT.parse(entry) != null)) { + } else if (END_OF_DATA_SENTINEL.equals(entry) || (JVM_EXIT.parse(entry) != null)) { if (forwardReference != null) super.publish(ChannelName.SURVIVOR_MEMORY_POOL_PARSER_OUTBOX, forwardReference); super.publish(ChannelName.SURVIVOR_MEMORY_POOL_PARSER_OUTBOX, new JVMTermination(getClock(),diary.getTimeOfFirstEvent())); diff --git a/parser/src/main/java/com/microsoft/gctoolkit/parser/Tokens.java b/parser/src/main/java/com/microsoft/gctoolkit/parser/Tokens.java index 5d2aea9e..fe39739e 100644 --- a/parser/src/main/java/com/microsoft/gctoolkit/parser/Tokens.java +++ b/parser/src/main/java/com/microsoft/gctoolkit/parser/Tokens.java @@ -2,11 +2,9 @@ // Licensed under the MIT License. package com.microsoft.gctoolkit.parser; -/** - * Interface that contains String and ParseRule representations of common - * data types within GC Log data.These tokens are used in Regular Expressions - * Pattern matching in the GC Log parser(s) - */ +/// Interface that contains String and ParseRule representations of common +/// data types within GC Log data.These tokens are used in Regular Expressions +/// Pattern matching in the GC Log parser(s) public interface Tokens { // Primitives @@ -77,7 +75,7 @@ public interface Tokens { // Reference processing block // 11906.881: [SoftReference, 0 refs, 0.0000060 secs] // 11906.881: [WeakReference, 0 refs, 0.0000020 secs] - // 11906.881: [FinalReference, 0 refs, 0.0000010 secs] + // 11906.881: [FinalReference, 0 refs, 0.0000010 ßsecs] // 11906.881: [PhantomReference, 0 refs, 0.0000020 secs] String REFERENCE_PROCESSING = DATE_TIMESTAMP + "\\[(Soft|Weak|Final)Reference, " + COUNTER + " refs, " + PAUSE_TIME + "\\]"; GCParseRule SOFT_REFERENCE = new GCParseRule("SOFT_REFERENCE", DATE_TIMESTAMP + "\\[SoftReference, " + COUNTER + " refs, " + PAUSE_TIME + "\\]"); diff --git a/parser/src/main/java/com/microsoft/gctoolkit/parser/UnifiedG1GCParser.java b/parser/src/main/java/com/microsoft/gctoolkit/parser/UnifiedG1GCParser.java index 015d2f89..0d5d6463 100644 --- a/parser/src/main/java/com/microsoft/gctoolkit/parser/UnifiedG1GCParser.java +++ b/parser/src/main/java/com/microsoft/gctoolkit/parser/UnifiedG1GCParser.java @@ -38,16 +38,14 @@ import static com.microsoft.gctoolkit.event.GarbageCollectionTypes.fromLabel; -/** - * TODO No reports or views generated from this data yet. - *

- * Result on - * - when GC started - * - type of GC triggered - * - from, to, configured - * - pause time if it is reported or can be calculated - * todo: me - */ +/// TODO No reports or views generated from this data yet. +/// +/// Result on +/// - when GC started +/// - type of GC triggered +/// - from, to, configured +/// - pause time if it is reported or can be calculated +/// todo: me public class UnifiedG1GCParser extends UnifiedGCLogParser implements UnifiedG1GCPatterns, TenuredPatterns { private static final Logger LOGGER = Logger.getLogger(UnifiedG1GCParser.class.getName()); @@ -167,6 +165,7 @@ public Set eventsProduced() { return Set.of(EventSource.G1GC); } + @Override public String getName() { return "UnifiedG1GCParser"; } @@ -220,7 +219,7 @@ private void applyRule(GCParseRule ruleToApply, GCLogTrace trace, String line) { private void setForwardReference(int gcid, String line) { if (gcid != -1) { - forwardReference = collectionsUnderway.computeIfAbsent(gcid, k -> new G1GCForwardReference(new Decorators(line), gcid)); + forwardReference = collectionsUnderway.computeIfAbsent(gcid, _ -> new G1GCForwardReference(new Decorators(line), gcid)); forwardReference.setHeapRegionSize(regionSize); forwardReference.setMaxHeapSize(maxHeapSize); forwardReference.setMinHeapSize(minHeapSize); @@ -234,13 +233,12 @@ private void removeForwardReference(G1GCForwardReference forwardReference) { private void noop(GCLogTrace trace, String line) {} - /************* - * - * Data Extraction methods - */ + /// *********** + /// + /// Data Extraction methods private void cpuBreakout(GCLogTrace trace, String line) { - CPUSummary cpuSummary = new CPUSummary(trace.getDoubleGroup(1), trace.getDoubleGroup(2), trace.getDoubleGroup(3)); + var cpuSummary = new CPUSummary(trace.getDoubleGroup(1), trace.getDoubleGroup(2), trace.getDoubleGroup(3)); forwardReference.setCPUSummary(cpuSummary); try { publishPauseEvent(forwardReference.buildEvent()); @@ -252,15 +250,13 @@ private void cpuBreakout(GCLogTrace trace, String line) { // todo: need to drain the queues before terminating... // Just in case there isn't a JVM termination event in the log. public void endOfFile(GCLogTrace trace, String line) { - publish(new JVMTermination((jvmTerminationEventTime.hasTimeStamp()) ? jvmTerminationEventTime : getClock(),diary.getTimeOfFirstEvent())); + publish(new JVMTermination(jvmTerminationEventTime.hasTimeStamp() ? jvmTerminationEventTime : getClock(),diary.getTimeOfFirstEvent())); } - /** - * following records describe heap before the collection - * - * @param trace - * @param line - */ + /// following records describe heap before the collection + /// + /// @param trace + /// @param line private void heapBeforeAfterGCInvocationCount(GCLogTrace trace, String line) { if ("before".equals(trace.getGroup(1))) { before = true; @@ -318,18 +314,16 @@ private void youngRegionAllotment(GCLogTrace trace, String line) { } } - /** - * @param trace - * @param line - */ + /// @param trace + /// @param line private void metaClassSpace(GCLogTrace trace, String line) { if (before) { - if (trace.getGroup(1).equals("Metaspace")) { + if ("Metaspace".equals(trace.getGroup(1))) { forwardReference.setMetaspaceOccupancyBeforeCollection(trace.getLongGroup(2)); forwardReference.setMetaspaceSizeBeforeCollection(trace.getLongGroup(3)); forwardReference.setMetaspaceCommittedBeforeCollection(trace.getLongGroup(4)); forwardReference.setMetaspaceReservedBeforeCollection(trace.getLongGroup(5)); - } else if (trace.getGroup(1).equals("class space")) { + } else if ("class space".equals(trace.getGroup(1))) { forwardReference.setClassspaceOccupancyBeforeCollection(trace.getLongGroup(2)); forwardReference.setClassspaceSizeBeforeCollection(trace.getLongGroup(3)); forwardReference.setClassspaceCommittedBeforeCollection(trace.getLongGroup(4)); @@ -337,12 +331,12 @@ private void metaClassSpace(GCLogTrace trace, String line) { } else trace.notYetImplemented(); } else { - if (trace.getGroup(1).equals("Metaspace")) { + if ("Metaspace".equals(trace.getGroup(1))) { forwardReference.setMetaspaceOccupancyAfterCollection(trace.getLongGroup(2)); forwardReference.setMetaspaceSizeAfterCollection(trace.getLongGroup(3)); forwardReference.setMetaspaceCommittedAfterCollection(trace.getLongGroup(4)); forwardReference.setMetaspaceReservedAfterCollection(trace.getLongGroup(5)); - } else if (trace.getGroup(1).equals("class space")) { + } else if ("class space".equals(trace.getGroup(1))) { forwardReference.setClassspaceOccupancyAfterCollection(trace.getLongGroup(2)); forwardReference.setClassspaceSizeAfterCollection(trace.getLongGroup(3)); forwardReference.setClassspaceCommittedAfterCollection(trace.getLongGroup(4)); @@ -474,12 +468,10 @@ public void parallelCount(GCLogTrace trace, String line) { } } - /** - * The trace indicates number of active regions before and after the collection. This is then used to provide an - * extremely coarse estimate of the amount of live data. - * @param trace A chunk of GC log that we are attempting to match to a known GC log pattern - * @param line The log line corresponding to the trace - */ + /// The trace indicates number of active regions before and after the collection. This is then used to provide an + /// extremely coarse estimate of the amount of live data. + /// @param trace A chunk of GC log that we are attempting to match to a known GC log pattern + /// @param line The log line corresponding to the trace public void regionSummary(GCLogTrace trace, String line) { RegionSummary summary = trace.regionSummary(); switch (trace.getGroup(1)) { @@ -535,13 +527,11 @@ public void youngDetails(GCLogTrace trace, String line) { } } - /** - * Record contains Metaspace broken out to class and non-class space. Since - * Metaspace = class space + non-class space, we can ignore the non-class space information (for now) - * The space size before the collection can be determined by inspecting the previous record (ignore for now) - * @param trace A chunk of GC log that we are attempting to match to a known GC log pattern - * @param line The log line corresponding to the trace - */ + /// Record contains Metaspace broken out to class and non-class space. Since + /// Metaspace = class space + non-class space, we can ignore the non-class space information (for now) + /// The space size before the collection can be determined by inspecting the previous record (ignore for now) + /// @param trace A chunk of GC log that we are attempting to match to a known GC log pattern + /// @param line The log line corresponding to the trace public void metaNonClassClassSpace(GCLogTrace trace, String line) { MemoryPoolSummary metaspace = trace.getEnlargedMetaSpaceRecord(1); forwardReference.setMetaspaceOccupancyBeforeCollection(metaspace.getOccupancyBeforeCollection()); @@ -555,12 +545,10 @@ public void metaNonClassClassSpace(GCLogTrace trace, String line) { //Concurrent Mark - /** - * Start of concurrent phases which can be ignored (for now??) - * - * @param trace - * @param line - */ + /// Start of concurrent phases which can be ignored (for now??) + /// + /// @param trace + /// @param line private void concurrentCycleStart(GCLogTrace trace, String line) { forwardReference.setConcurrentCycleStartTime(getClock()); @@ -600,11 +588,9 @@ private void concurrentPhaseDuration(GCLogTrace trace, String line) { publishConcurrentEvent(forwardReference.buildConcurrentPhaseEvent()); } - /** - * this is the start of the records, nothing to be captured. - * @param trace - * @param line - */ + /// this is the start of the records, nothing to be captured. + /// @param trace + /// @param line private void concurrentMarkInternalPhases(GCLogTrace trace, String line) { } @@ -673,50 +659,40 @@ private void fullPhase(GCLogTrace trace, String line) { forwardReference.fullPhase(trace.getIntegerGroup(1), trace.getGroup(2), trace.getDurationInSeconds()); } - /** - * todo: need to process and view this captured data - * @param trace - * @param line - */ + /// todo: need to process and view this captured data + /// @param trace + /// @param line private void fullClassUnloading(GCLogTrace trace, String line) { //forwardReference.fullClassUnloadingDuration(trace.getMillisecondDurationInSeconds()); } - /** - * todo: need to capture StringTable data (part of remark at debug level) - * @param trace - * @param line - */ + /// todo: need to capture StringTable data (part of remark at debug level) + /// @param trace + /// @param line private void fullStringSymbolTable(GCLogTrace trace, String line) { // forwardReference.scrubStringSymbolTableDuration(trace.getMillisecondDurationInSeconds()); } - /** - * Capture logged tenuring summary data - * @param trace - * @param line - */ + /// Capture logged tenuring summary data + /// @param trace + /// @param line private void tenuringSummary(GCLogTrace trace, String line) { forwardReference.survivorRecord(new SurvivorRecord(getClock(), trace.getLongGroup(1), trace.getIntegerGroup(2), trace.getIntegerGroup(3))); } - /** - * Capture logged age table data - * @param trace - * @param line - */ + /// Capture logged age table data + /// @param trace + /// @param line private void tenuringAgeBreakout(GCLogTrace trace, String line) { notYetImplemented(trace,line); forwardReference.addAgeBreakout(trace.getIntegerGroup(1), trace.getLongGroup(2)); } - /** - * records a concurrent phase of a concurrent cycle. After the event has been recorded, all other events - * that occurred during the concurrent event will be recorded. - * The exception is the Concurrent Undo cycle which causes all concurrent phases to be queued until the - * undo cycle ends. - * @param event - */ + /// records a concurrent phase of a concurrent cycle. After the event has been recorded, all other events + /// that occurred during the concurrent event will be recorded. + /// The exception is the Concurrent Undo cycle which causes all concurrent phases to be queued until the + /// undo cycle ends. + /// @param event private void publishConcurrentEvent(G1GCConcurrentEvent event) { if ( event == null) return; @@ -739,12 +715,10 @@ private void publishUndoCycle(G1ConcurrentUndoCycle cycle) { private final Queue eventQueue = new LinkedList<>(); - /** - * Events are published in the start time order. If a concurrent cycle has started and it's in a concurrent - * phase, the pause event is queued. It will be published when the concurrent phase completes. As each event is - * published, it corresponding forward reference is released. - * @param event - */ + /// Events are published in the start time order. If a concurrent cycle has started and it's in a concurrent + /// phase, the pause event is queued. It will be published when the concurrent phase completes. As each event is + /// published, it corresponding forward reference is released. + /// @param event private void publishPauseEvent(G1GCPauseEvent event) { if (event == null) return; if ( concurrentPhaseActive) { @@ -777,12 +751,10 @@ private boolean ignoreFrequentlySeenButUnwantedLines(String line) { return false; } - /** - * Ignore rules we don't need to process. - * - * @param trace GCLogTrace that hits this log line - * @param line Log line. - */ + /// Ignore rules we don't need to process. + /// + /// @param trace GCLogTrace that hits this log line + /// @param line Log line. private void ignore(GCLogTrace trace, String line) { return; } diff --git a/parser/src/main/java/com/microsoft/gctoolkit/parser/UnifiedGCLogParser.java b/parser/src/main/java/com/microsoft/gctoolkit/parser/UnifiedGCLogParser.java index ee3e5369..13315349 100644 --- a/parser/src/main/java/com/microsoft/gctoolkit/parser/UnifiedGCLogParser.java +++ b/parser/src/main/java/com/microsoft/gctoolkit/parser/UnifiedGCLogParser.java @@ -15,6 +15,7 @@ abstract class UnifiedGCLogParser extends GCLogParser { public UnifiedGCLogParser() {} + @Override void advanceClock(String record) { try { DateTimeStamp now = new Decorators(record).getDateTimeStamp(); @@ -28,11 +29,9 @@ void notYetImplemented(GCLogTrace trace, String line) { trace.notYetImplemented(); } - /** - * Some log entries require no actions - */ + /// Some log entries require no actions void noop() { if (DEBUG) - System.out.println("noop"); + IO.println("noop"); } } diff --git a/parser/src/main/java/com/microsoft/gctoolkit/parser/UnifiedGenerationalParser.java b/parser/src/main/java/com/microsoft/gctoolkit/parser/UnifiedGenerationalParser.java index e96b556a..aac4d467 100644 --- a/parser/src/main/java/com/microsoft/gctoolkit/parser/UnifiedGenerationalParser.java +++ b/parser/src/main/java/com/microsoft/gctoolkit/parser/UnifiedGenerationalParser.java @@ -35,6 +35,7 @@ import java.util.AbstractMap; import java.util.ArrayList; +import java.util.List; import java.util.Map; import java.util.Set; import java.util.function.BiConsumer; @@ -55,15 +56,13 @@ import static com.microsoft.gctoolkit.event.GarbageCollectionTypes.ParNew; import static com.microsoft.gctoolkit.event.GarbageCollectionTypes.Remark; -/** - * TODO No reports or views generated from this data yet. - *

- * Result on - * - when GC started - * - type of GC triggered - * - from, to, configured - * - pause time if it is reported or can be calculated - */ +/// TODO No reports or views generated from this data yet. +/// +/// Result on +/// - when GC started +/// - type of GC triggered +/// - from, to, configured +/// - pause time if it is reported or can be calculated public class UnifiedGenerationalParser extends UnifiedGCLogParser implements UnifiedGenerationalPatterns, TenuredPatterns { private static final Logger LOGGER = Logger.getLogger(UnifiedGenerationalParser.class.getName()); @@ -122,6 +121,7 @@ public Set eventsProduced() { return Set.of(EventSource.GENERATIONAL); } + @Override public String getName() { return "UnifiedGenerationalParser"; } @@ -137,9 +137,8 @@ protected void process(String line) { .filter(tuple -> tuple.getValue() != null) .findAny() .ifPresentOrElse( - tuple -> { - applyRule(tuple.getKey(), tuple.getValue(), line); - }, + tuple -> + applyRule(tuple.getKey(), tuple.getValue(), line), () -> LOGGER.log(Level.FINE, "Missed: {0}", line) ); } @@ -153,10 +152,9 @@ private void applyRule(GCParseRule ruleToApply, GCLogTrace trace, String line) { } } - /************* - * - * Data Extraction methods - */ + /// *********** + /// + /// Data Extraction methods private GenerationalForwardReference pauseEvent = null; private GenerationalForwardReference concurrentCyclePauseEvent = null; private GenerationalForwardReference concurrentEvent = null; @@ -230,8 +228,8 @@ private void metaSpaceDetails(GCLogTrace trace, String line) { } private void youngDetails(GCLogTrace trace, String line) { - boolean isNoDetailsEvent = false; - int gcid = GCLogParser.GCID_COUNTER.parse(line).getIntegerGroup(1); + var isNoDetailsEvent = false; + var gcid = GCLogParser.GCID_COUNTER.parse(line).getIntegerGroup(1); if (pauseEvent == null && gcid > currentGcId) { // #457 - Unified-Parallel file without details doesn't trigger youngHeader(). @@ -258,32 +256,26 @@ private void youngDetails(GCLogTrace trace, String line) { } } - /** - * Capture logged tenuring summary data - * @param trace - * @param line - */ + /// Capture logged tenuring summary data + /// @param trace + /// @param line private void tenuringSummary(GCLogTrace trace, String line) { if ( pauseEvent != null) pauseEvent.survivorRecord(new SurvivorRecord(getClock(), trace.getLongGroup(1), trace.getIntegerGroup(2), trace.getIntegerGroup(3))); } - /** - * Capture logged age table data - * @param trace - * @param line - */ + /// Capture logged age table data + /// @param trace + /// @param line private void tenuringAgeBreakout(GCLogTrace trace, String line) { if (pauseEvent != null) pauseEvent.addAgeBreakout(trace.getIntegerGroup(1), trace.getLongGroup(2)); } - /** - * If the concurrentCyclePauseEvent has not been recorded, something has gone wrong and it's likely - * that it doesn't have a consistent state. The default action is to lose it. - * @param trace - * @param line - */ + /// If the concurrentCyclePauseEvent has not been recorded, something has gone wrong and it's likely + /// that it doesn't have a consistent state. The default action is to lose it. + /// @param trace + /// @param line private void initialMark(GCLogTrace trace, String line) { if (concurrentCyclePauseEvent != null) LOGGER.warning("Pause event not completely recorded: " + pauseEvent.getGcID()); @@ -317,11 +309,9 @@ private void workerThreads(GCLogTrace trace, String line) { notYetImplemented(trace, line); } - /** - * If the forward reference has not been recorded, assume it's state is corrupted so over-write it. - * @param trace - * @param line - */ + /// If the forward reference has not been recorded, assume it's state is corrupted so over-write it. + /// @param trace + /// @param line private void remark(GCLogTrace trace, String line) { if (concurrentCyclePauseEvent != null) LOGGER.warning("Pause event not recorded and is about to be lost: " + pauseEvent.getGcID()); @@ -373,8 +363,8 @@ private void fullGC(GCLogTrace trace, String line) { } private void fullGCSummary(GCLogTrace trace, String line) { - boolean isNoDetailsEvent = false; - int gcid = GCLogParser.GCID_COUNTER.parse(line).getIntegerGroup(1); + var isNoDetailsEvent = false; + var gcid = GCLogParser.GCID_COUNTER.parse(line).getIntegerGroup(1); if (pauseEvent == null && gcid > currentGcId) { // #457 - Unified-Parallel file doesn't trigger fullGC() to create pauseEvent. @@ -427,19 +417,16 @@ private void jvmExit(GCLogTrace trace, String line) { super.publish(ChannelName.GENERATIONAL_HEAP_PARSER_OUTBOX, new JVMTermination(getClock(),diary.getTimeOfFirstEvent())); } - /** - * - * By convention, events are emitted iini the order that they started. For CMS, it's possible to have a ParNew - * intermixed with a concurrent cycle. To cover these cases, the young gen collection is cached, the concurrent - * event is completed and then the cached event is emitted. - */ - private ArrayList cache = new ArrayList<>(); + /// By convention, events are emitted iini the order that they started. For CMS, it's possible to have a ParNew + /// intermixed with a concurrent cycle. To cover these cases, the young gen collection is cached, the concurrent + /// event is completed and then the cached event is emitted. + private List cache = new ArrayList<>(); private void cpuBreakout(GCLogTrace trace, String line) { GCLogTrace gcidTrace = GCID_COUNTER.parse(line); if (gcidTrace != null) { - CPUSummary cpuSummary = new CPUSummary(trace.getDoubleGroup(1), trace.getDoubleGroup(2), trace.getDoubleGroup(3)); - int gcid = gcidTrace.getIntegerGroup(1); + var cpuSummary = new CPUSummary(trace.getDoubleGroup(1), trace.getDoubleGroup(2), trace.getDoubleGroup(3)); + var gcid = gcidTrace.getIntegerGroup(1); // There are 3 cases to consider. // - pause event outside of a concurrent cycle // - pause event that is part of the concurrent cycle @@ -451,7 +438,7 @@ private void cpuBreakout(GCLogTrace trace, String line) { if (pauseEvent != null && pauseEvent.getGcID() == gcid) { pauseEvent.add(cpuSummary); if (inConcurrentPhase) { - cache.add(buildPauseEvent((pauseEvent))); + cache.add(buildPauseEvent(pauseEvent)); } else { publish(buildPauseEvent(pauseEvent)); } @@ -481,10 +468,10 @@ private void fillOutMetaspaceData(GenerationalGCPauseEvent event, GenerationalFo } private void fillOutMemoryPoolData(GenerationalGCPauseEvent event, GenerationalForwardReference values) { - int map = 0; - map |= (values.getHeap() != null) ? 1 : 0; - map |= (values.getYoung() != null) ? 2 : 0; - map |= (values.getTenured() != null) ? 4 : 0; + var map = 0; + map |= values.getHeap() != null ? 1 : 0; + map |= values.getYoung() != null ? 2 : 0; + map |= values.getTenured() != null ? 4 : 0; switch (map) { default: case 0: // none, error @@ -536,14 +523,14 @@ private GenerationalGCPauseEvent buildYoungEvent(GenerationalForwardReference fo } public InitialMark buildInitialMark(GenerationalForwardReference values) { - InitialMark collection = new InitialMark(values.getStartTime(), values.getGCCause(), values.getDuration()); + var collection = new InitialMark(values.getStartTime(), values.getGCCause(), values.getDuration()); collection.add(values.getHeap()); collection.add(values.getCPUSummary()); return collection; } private CMSRemark buildRemark(GenerationalForwardReference values) { - CMSRemark remark = new CMSRemark(values.getStartTime(), values.getGCCause(), values.getDuration()); + var remark = new CMSRemark(values.getStartTime(), values.getGCCause(), values.getDuration()); remark.add(values.getHeap()); //add in all the other work remark.add(values.getCPUSummary()); @@ -562,14 +549,14 @@ private FullGC buildFullGC(GenerationalForwardReference forwardReference) { FullGC gc; switch (forwardReference.getGarbageCollectionType()) { case PSFull: - if ( forwardReference.getGCCause().equals(GCCause.JAVA_LANG_SYSTEM)) + if ( forwardReference.getGCCause() == GCCause.JAVA_LANG_SYSTEM) gc = new SystemGC(forwardReference.getStartTime(), forwardReference.getGCCause(), forwardReference.getDuration()); else gc = new PSFullGC(forwardReference.getStartTime(), forwardReference.getGCCause(), forwardReference.getDuration()); return fillOutFullGC(gc, forwardReference); case FullGC: case Full: - if ( forwardReference.getGCCause().equals(GCCause.JAVA_LANG_SYSTEM)) + if ( forwardReference.getGCCause() == GCCause.JAVA_LANG_SYSTEM) gc = new SystemGC(forwardReference.getStartTime(), forwardReference.getGCCause(), forwardReference.getDuration()); else gc = new FullGC(forwardReference.getStartTime(), forwardReference.getGCCause(), forwardReference.getDuration()); diff --git a/parser/src/main/java/com/microsoft/gctoolkit/parser/UnifiedJVMEventParser.java b/parser/src/main/java/com/microsoft/gctoolkit/parser/UnifiedJVMEventParser.java index 26f3e759..ad395cbb 100644 --- a/parser/src/main/java/com/microsoft/gctoolkit/parser/UnifiedJVMEventParser.java +++ b/parser/src/main/java/com/microsoft/gctoolkit/parser/UnifiedJVMEventParser.java @@ -32,6 +32,7 @@ public Set eventsProduced() { return Set.of(EventSource.JVM); } + @Override public String getName() { return "JavaEventParser"; } @@ -60,23 +61,23 @@ protected void process(String line) { else if ((trace = UNIFIED_LOGGING_APPLICATION_TIME.parse(line)) != null) { publish(new ApplicationConcurrentTime(getClock(), trace.getDoubleGroup(1))); - } else if (line.equals(END_OF_DATA_SENTINEL) || (JVM_EXIT.parse(line) != null)) { + } else if (END_OF_DATA_SENTINEL.equals(line) || (JVM_EXIT.parse(line) != null)) { publish(new JVMTermination(getClock(),diary.getTimeOfFirstEvent())); } else if (getClock().getTimeStamp() > timeStamp.getTimeStamp()) { if (isGCPause(line)) gcPause = true; timeStamp = getClock(); } - } catch (Throwable t) { + } catch (Throwable _) { LOGGER.log(Level.FINE, "Missed: {0}", line); } } private boolean isGCPause(String line) { - return ((line.contains(" Pause Initial Mark")) || + return (line.contains(" Pause Initial Mark")) || (line.contains(" Remark ")) || (line.contains(" Pause Young ")) || - (line.contains(" Full "))); + (line.contains(" Full ")); } @Override diff --git a/parser/src/main/java/com/microsoft/gctoolkit/parser/UnifiedSurvivorMemoryPoolParser.java b/parser/src/main/java/com/microsoft/gctoolkit/parser/UnifiedSurvivorMemoryPoolParser.java index 4d0e9df6..874b3810 100644 --- a/parser/src/main/java/com/microsoft/gctoolkit/parser/UnifiedSurvivorMemoryPoolParser.java +++ b/parser/src/main/java/com/microsoft/gctoolkit/parser/UnifiedSurvivorMemoryPoolParser.java @@ -18,13 +18,11 @@ public class UnifiedSurvivorMemoryPoolParser extends UnifiedGCLogParser implements TenuredPatterns { - /** - * [16.962s][debug][gc,age ] GC(14) Desired survivor size 10485760 bytes, new threshold 15 (max threshold 15) - * [16.973s][trace][gc,age ] GC(14) Age table with threshold 15 (max threshold 15) - * [16.973s][trace][gc,age ] GC(14) - age 1: 768744 bytes, 768744 total - * ... - * [16.974s][trace][gc,age ] GC(14) - age 14: 542328 bytes, 8307008 total - */ + /// [16.962s][debug][gc,age ] GC(14) Desired survivor size 10485760 bytes, new threshold 15 (max threshold 15) + /// [16.973s][trace][gc,age ] GC(14) Age table with threshold 15 (max threshold 15) + /// [16.973s][trace][gc,age ] GC(14) - age 1: 768744 bytes, 768744 total + /// ... + /// [16.974s][trace][gc,age ] GC(14) - age 14: 542328 bytes, 8307008 total private GCParseRule DESIRED_SURVIVOR_SIZE = new GCParseRule("DESIRED_SURVIVOR_SIZE", "Desired survivor size " + COUNTER + " bytes, new threshold " + COUNTER + " \\(max threshold " + COUNTER + "\\)"); private GCParseRule AGE_TABLE_HEADER = new GCParseRule("AGE_TABLE_HEADER", "Age table with threshold " + COUNTER + " \\(max threshold " + COUNTER + "\\)"); private GCParseRule AGE_RECORD = new GCParseRule("AGE_RECORD", "- age\\s+" + COUNTER + ":\\s+" + COUNTER + " bytes,\\s+" + COUNTER + " total"); @@ -39,6 +37,7 @@ public Set eventsProduced() { return Set.of(EventSource.SURVIVOR); } + @Override public String getName() { return "SurvivorMemoryPoolParser"; } @@ -56,7 +55,7 @@ protected void process(String entry) { forwardReference.add(trace.getIntegerGroup(1), trace.getLongGroup(2)); ageDataCollected = true; } - } else if (entry.equals(END_OF_DATA_SENTINEL) || (JVM_EXIT.parse(entry) != null)) { + } else if (END_OF_DATA_SENTINEL.equals(entry) || (JVM_EXIT.parse(entry) != null)) { if (forwardReference != null) publish(forwardReference); publish(new JVMTermination(getClock(),diary.getTimeOfFirstEvent())); diff --git a/parser/src/main/java/com/microsoft/gctoolkit/parser/ZGCMemoryScope.java b/parser/src/main/java/com/microsoft/gctoolkit/parser/ZGCMemoryScope.java index 046dfc00..405416f6 100644 --- a/parser/src/main/java/com/microsoft/gctoolkit/parser/ZGCMemoryScope.java +++ b/parser/src/main/java/com/microsoft/gctoolkit/parser/ZGCMemoryScope.java @@ -5,5 +5,5 @@ public enum ZGCMemoryScope { ALL, YOUNG_GENERATION, - OLD_GENERATION; + OLD_GENERATION } diff --git a/parser/src/main/java/com/microsoft/gctoolkit/parser/ZGCParser.java b/parser/src/main/java/com/microsoft/gctoolkit/parser/ZGCParser.java index 395da1ef..ec0230fc 100644 --- a/parser/src/main/java/com/microsoft/gctoolkit/parser/ZGCParser.java +++ b/parser/src/main/java/com/microsoft/gctoolkit/parser/ZGCParser.java @@ -42,6 +42,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Map; import java.util.Optional; import java.util.Set; import java.util.HashMap; @@ -49,17 +50,15 @@ import java.util.logging.Level; import java.util.logging.Logger; -/** - * Time of GC - * GCType - * Collect total heap values - * Heap before collection - * Heap after collection - * Heap configured size - * total pause time - * CMS failures - * System.gc() calls - */ +/// Time of GC +/// GCType +/// Collect total heap values +/// Heap before collection +/// Heap after collection +/// Heap configured size +/// total pause time +/// CMS failures +/// System.gc() calls public class ZGCParser extends UnifiedGCLogParser implements ZGCPatterns { private static final Logger LOGGER = Logger.getLogger(ZGCParser.class.getName()); @@ -68,7 +67,7 @@ public class ZGCParser extends UnifiedGCLogParser implements ZGCPatterns { private final boolean develop = Boolean.getBoolean("microsoft.develop"); private final ZGCForwardReference[] forwardReferences = new ZGCForwardReference[3]; - private final HashMap gcCauseMap = new HashMap<>(2); + private final Map gcCauseMap = new HashMap<>(2); private final long[] heapCapacity = new long[3]; @@ -115,10 +114,8 @@ public Set eventsProduced() { return Set.of(EventSource.ZGC); } - /** - * This marks the phase we're in for memory stats. Generation ZGC will provide heap capacity - * as well as old and young gen capacities. This enables the Young gen phase - */ + /// This marks the phase we're in for memory stats. Generation ZGC will provide heap capacity + /// as well as old and young gen capacities. This enables the Young gen phase private void markGenHeapStats(GCLogTrace gcLogTrace, String s) { this.genHeapStats = true; } @@ -199,11 +196,11 @@ private void cycleStart(GCLogTrace trace, String s) { // cycleStart ends up being called for ZGC logging with no details, but did not handle this situation. // It is not clear if there is any differentiation between Young/Old Phases in no-details logging, so I've made // an assumption here that we're strictly dealing with Young collections until we have sample logging otherwise. - if (ZGCCycleType.MAJOR.equals(type)) { + if (ZGCCycleType.MAJOR == type) { setForwardRefForPhase( ZGCPhase.MAJOR_YOUNG, new ZGCForwardReference(getClock(), trace.getLongGroup(1), trace.gcCause(3,0), type, ZGCPhase.MAJOR_YOUNG)); - } else if (ZGCCycleType.MINOR.equals(type)) { + } else if (ZGCCycleType.MINOR == type) { setForwardRefForPhase( ZGCPhase.MINOR_YOUNG, new ZGCForwardReference(getClock(), trace.getLongGroup(1), trace.gcCause(3,0), type, ZGCPhase.MINOR_YOUNG)); @@ -229,9 +226,9 @@ private void generationStart(GCLogTrace trace, String line){ return; } ZGCPhase phase = ZGCPhase.get(trace.getGroup(2)); - long gcId = trace.getLongGroup(1); + var gcId = trace.getLongGroup(1); GCCause gcCause = gcCauseMap.getOrDefault(gcId, GCCause.UNKNOWN_GCCAUSE); - ZGCForwardReference forwardReference = new ZGCForwardReference(getClock(), gcId, gcCause, ZGCCycleType.fromPhase(phase), phase); + var forwardReference = new ZGCForwardReference(getClock(), gcId, gcCause, ZGCCycleType.fromPhase(phase), phase); setForwardRefForPhase( phase, forwardReference @@ -311,7 +308,7 @@ private void concurrentPhase(GCLogTrace trace, String s) { private void pageSummary(GCLogTrace trace, String s) { ZGCForwardReference ref = getForwardRefForPhase(trace.getZCollectionPhase()); - ZGCPageSummary summary = new ZGCPageSummary( + var summary = new ZGCPageSummary( trace.getLongGroup(3), trace.getLongGroup(4), trace.getLongGroup(5), @@ -336,7 +333,7 @@ private void forwardingUsage(GCLogTrace trace, String s) { private void ageTable(GCLogTrace trace, String s) { ZGCForwardReference ref = getForwardRefForPhase(trace.getZCollectionPhase()); - ZGCPageAgeSummary summary = new ZGCPageAgeSummary( + var summary = new ZGCPageAgeSummary( trace.getGroup(2), trace.toKBytes(3), trace.getIntegerGroup(5), @@ -402,7 +399,7 @@ private void relocationSummary(GCLogTrace trace, String s) { private void nMethods(GCLogTrace trace, String s) { ZGCForwardReference ref = getForwardRefForPhase(trace.getZCollectionPhase()); - ZGCNMethodSummary summary = new ZGCNMethodSummary( + var summary = new ZGCNMethodSummary( trace.getLongGroup(2), trace.getLongGroup(3)); ref.setNMethodSummary(summary); @@ -411,7 +408,7 @@ private void nMethods(GCLogTrace trace, String s) { private void metaspace(GCLogTrace trace, String s) { ZGCForwardReference ref = getForwardRefForPhase(trace.getZCollectionPhase()); - ZGCMetaspaceSummary summary = new ZGCMetaspaceSummary( + var summary = new ZGCMetaspaceSummary( trace.toKBytes(2), trace.toKBytes(4), trace.toKBytes(6)); @@ -425,7 +422,7 @@ private void referenceProcessing(GCLogTrace trace, String s) { private void referenceProcessingGen(GCLogTrace trace, String s) { ZGCForwardReference ref = getForwardRefForPhase(trace.getZCollectionPhase()); - ZGCReferenceSummary summary = new ZGCReferenceSummary(trace.getLongGroup(3), trace.getLongGroup(4), trace.getLongGroup(5)); + var summary = new ZGCReferenceSummary(trace.getLongGroup(3), trace.getLongGroup(4), trace.getLongGroup(5)); if ("Soft".equals(trace.getGroup(2))){ ref.setSoftRefSummary(summary); } else if ("Weak".equals(trace.getGroup(2))) { @@ -463,7 +460,7 @@ private void sizeEntry(GCLogTrace trace, String s) { if (genHeapStats) { if ("Used".equals(trace.getGroup(2))){ - ZGCUsedSummary summary = new ZGCUsedSummary( + var summary = new ZGCUsedSummary( trace.toKBytes(3), trace.toKBytes(6), trace.toKBytes(9), @@ -566,7 +563,7 @@ private void generationEnd(GCLogTrace trace, String s) { private void memorySummary(GCLogTrace trace, String s) { if (diary.isGenerationalZGC()) { - long gcId = trace.getLongGroup(1); + var gcId = trace.getLongGroup(1); if (gcCauseMap.containsKey(gcId)) { gcCauseMap.remove(gcId); @@ -604,7 +601,7 @@ private void publishIfMemorySummaryMissing(GCLogTrace trace) { // We use the lack of a MemorySummary in the forwardReference as a sign // that we need to publish a Generational no-details event. ZGCCycleType cycleType = ZGCCycleType.get(trace.getGroup(2)); - ZGCForwardReference forwardReference = ZGCCycleType.MAJOR.equals(cycleType) ? + ZGCForwardReference forwardReference = ZGCCycleType.MAJOR == cycleType ? getForwardRefForPhase(ZGCPhase.MAJOR_YOUNG) : getForwardRefForPhase(ZGCPhase.MINOR_YOUNG); @@ -758,7 +755,7 @@ public ZGCForwardReference(DateTimeStamp dateTimeStamp, long gcId, GCCause cause public GCEvent getGCEVent(DateTimeStamp endTime) { ZGCCollection cycle; - double duration = (gcDuration != null) ? gcDuration : endTime.minus(startTimeStamp); + double duration = gcDuration != null ? gcDuration : endTime.minus(startTimeStamp); switch (phase) { case FULL: diff --git a/parser/src/main/java/com/microsoft/gctoolkit/parser/collection/MRUQueue.java b/parser/src/main/java/com/microsoft/gctoolkit/parser/collection/MRUQueue.java index cc4a7d28..cef8a5ea 100644 --- a/parser/src/main/java/com/microsoft/gctoolkit/parser/collection/MRUQueue.java +++ b/parser/src/main/java/com/microsoft/gctoolkit/parser/collection/MRUQueue.java @@ -2,6 +2,8 @@ // Licensed under the MIT License. package com.microsoft.gctoolkit.parser.collection; +import org.jspecify.annotations.Nullable; + import java.util.Collection; import java.util.HashMap; import java.util.Iterator; @@ -22,7 +24,7 @@ public MRUQueue() { @Override @SuppressWarnings("unchecked") - public V get(Object key) { + public @Nullable V get(Object key) { keys.remove(key); if (key != null) { keys.offerFirst((K)key); // unchecked cast @@ -59,7 +61,7 @@ public V put(K key, V value) { } @Override - public V remove(Object key) { + public @Nullable V remove(Object key) { return null; } diff --git a/parser/src/main/java/com/microsoft/gctoolkit/parser/collection/RuleSet.java b/parser/src/main/java/com/microsoft/gctoolkit/parser/collection/RuleSet.java index dc89ce68..bb065888 100644 --- a/parser/src/main/java/com/microsoft/gctoolkit/parser/collection/RuleSet.java +++ b/parser/src/main/java/com/microsoft/gctoolkit/parser/collection/RuleSet.java @@ -2,6 +2,8 @@ // Licensed under the MIT License. package com.microsoft.gctoolkit.parser.collection; +import org.jspecify.annotations.Nullable; + import java.util.AbstractMap; import java.util.Collection; import java.util.HashMap; @@ -31,15 +33,16 @@ public Node(K key, V value) { // the list in O(1) time, instead of O(n) time. private Node head; - private final HashMap> entries; + private final Map> entries; public RuleSet() { entries = new HashMap<>(); } - public V get(Object key) { + @Override + public @Nullable V get(Object key) { if (key != null) { - Node node = entries.get(key); + var node = entries.get(key); return node.getValue(); } return null; @@ -67,7 +70,7 @@ public boolean containsValue(Object value) { @Override public V put(K key, V value) { - Node node = new Node<>(key, value); + var node = new Node(key, value); if (head == null) { head = node; } else { @@ -80,7 +83,7 @@ public V put(K key, V value) { } @Override - public V remove(Object key) { + public @Nullable V remove(Object key) { return null; } @@ -101,7 +104,7 @@ public Set keySet() { @Override public Collection values() { - Collection values = new LinkedList<>(); + var values = new LinkedList(); for (Node node = head; node != null; node = node.next) { values.add(node.getValue()); } @@ -110,7 +113,7 @@ public Collection values() { @Override public Set> entrySet() { - Set> entrySet = new HashSet<>(); + var entrySet = new HashSet>(); for (Node node = head; node != null; node = node.next) { entrySet.add(node); } diff --git a/parser/src/main/java/com/microsoft/gctoolkit/parser/io/LogLineFilter.java b/parser/src/main/java/com/microsoft/gctoolkit/parser/io/LogLineFilter.java index 7a322591..46ee502e 100644 --- a/parser/src/main/java/com/microsoft/gctoolkit/parser/io/LogLineFilter.java +++ b/parser/src/main/java/com/microsoft/gctoolkit/parser/io/LogLineFilter.java @@ -35,12 +35,10 @@ public LogLineFilter() { } } - /** - * Some clients store logs with a prefix. Filter the prefix out of the log entry prior to parsing - * - * @param line A line from the GC log file. - * @return The same line without the prefix. - */ + /// Some clients store logs with a prefix. Filter the prefix out of the log entry prior to parsing + /// + /// @param line A line from the GC log file. + /// @return The same line without the prefix. public String prefixFilter(String line) { if (verbose) LOGGER.fine(line); diff --git a/parser/src/main/java/com/microsoft/gctoolkit/parser/io/SafepointLogFile.java b/parser/src/main/java/com/microsoft/gctoolkit/parser/io/SafepointLogFile.java index f8a77458..2a6a244e 100644 --- a/parser/src/main/java/com/microsoft/gctoolkit/parser/io/SafepointLogFile.java +++ b/parser/src/main/java/com/microsoft/gctoolkit/parser/io/SafepointLogFile.java @@ -28,10 +28,9 @@ public SafepointLogFile(Path path) { this.path = path; } - /** - * todo: for the moment this diary is empty. - * @return a diary - */ + /// todo: for the moment this diary is empty. + /// @return a diary + @Override public Diary diary() { return new Diary(); } @@ -43,6 +42,7 @@ public String endOfData() { public Path getPath() { return path; } + @Override public Stream stream() throws IOException { if (metadata.isPlainText()) { return Files.lines(path); @@ -55,7 +55,7 @@ public Stream stream() throws IOException { } Stream streamZipFile() throws IOException { - ZipInputStream zipStream = new ZipInputStream(Files.newInputStream(path)); + var zipStream = new ZipInputStream(Files.newInputStream(path)); ZipEntry entry; do { entry = zipStream.getNextEntry(); @@ -64,7 +64,7 @@ Stream streamZipFile() throws IOException { } Stream streamGZipFile() throws IOException { - GZIPInputStream gzipStream = new GZIPInputStream(Files.newInputStream(path)); + var gzipStream = new GZIPInputStream(Files.newInputStream(path)); return new BufferedReader(new InputStreamReader(new BufferedInputStream(gzipStream))).lines(); } diff --git a/parser/src/main/java/com/microsoft/gctoolkit/parser/jvm/CommandLineFlag.java b/parser/src/main/java/com/microsoft/gctoolkit/parser/jvm/CommandLineFlag.java index 64cc2539..3d6ec039 100644 --- a/parser/src/main/java/com/microsoft/gctoolkit/parser/jvm/CommandLineFlag.java +++ b/parser/src/main/java/com/microsoft/gctoolkit/parser/jvm/CommandLineFlag.java @@ -2,6 +2,8 @@ // Licensed under the MIT License. package com.microsoft.gctoolkit.parser.jvm; +import org.jspecify.annotations.Nullable; + public enum CommandLineFlag { PrintGCApplicationStoppedTime("PrintGCApplicationStoppedTime"), @@ -20,15 +22,15 @@ public enum CommandLineFlag { PrintPromotionFailure("PrintPromotionFailure"), PrintFLSStatistics("PrintFLSStatistics"); - public static CommandLineFlag getEnumFromString(String string) { + public static @Nullable CommandLineFlag getEnumFromString(String string) { try { return Enum.valueOf(CommandLineFlag.class, string.trim()); - } catch (IllegalArgumentException ex) { + } catch (IllegalArgumentException _) { } return null; } - public static CommandLineFlag fromString(String name) { + public static @Nullable CommandLineFlag fromString(String name) { return getEnumFromString(name); } diff --git a/parser/src/main/java/com/microsoft/gctoolkit/parser/jvm/Decorators.java b/parser/src/main/java/com/microsoft/gctoolkit/parser/jvm/Decorators.java index 11659c39..c3c6aa4d 100644 --- a/parser/src/main/java/com/microsoft/gctoolkit/parser/jvm/Decorators.java +++ b/parser/src/main/java/com/microsoft/gctoolkit/parser/jvm/Decorators.java @@ -5,6 +5,7 @@ import com.microsoft.gctoolkit.parser.unified.UnifiedLoggingLevel; import com.microsoft.gctoolkit.parser.unified.UnifiedLoggingTokens; import com.microsoft.gctoolkit.time.DateTimeStamp; +import org.jspecify.annotations.Nullable; import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; @@ -17,46 +18,44 @@ public class Decorators { - /** - * This class represents the decorators found in the log line as defined by JEP 158 (https://openjdk.java.net/jeps/158). - * The list, taken from that document is as: - * time -- Current time and date in ISO-8601 format - * uptime -- Time since the start of the JVM in seconds and milliseconds (e.g., 6.567s) - * timemillis -- The same value as generated by System.currentTimeMillis() - * uptimemillis -- Milliseconds since the JVM started - * timenanos -- The same value as generated by System.nanoTime() - * uptimenanos -- Nanoseconds since the JVM started - * pid -- The process identifier - * tid -- The thread identifier - * level -- The level associated with the log message - * tags -- The tag-set associated with the log message - * - * This implementation takes advantage of the property that the ordering of tags is stable. For example, - * -Xlog:*::pid,time produces the identical ordering as -Xlog:*::time,pid. Moreover, the list of decorators - * is dedupped implying that the second decorator in -Xlog:*::time,time is ignored. - * - * The default decorators (as of the time of authoring JDK 9-21) include [uptime][level][tags]. - * For example, [1.361s][info][gc,heap]. This reads uptime of 1.361 seconds. The tag for the log record - * is gc.heap at the info level. - * - * At issue is that uptime and timemillis are, on the surface, indistinguishable. The same is true with - * timenanos and uptimenanos as well as with pid and tid. The following logic can be used to help differentiate - * indistinguishable decorators. - * - * 1) If both decorators are present then order can be used to differentiate - * 2) If ms time value - 20 years > 0, then timemillis can be assumed. Otherwise uptime is assumed. The reasoning - * is, unified logging didn't exist that long ago. The value of 20 has been arbitrarily chosen. - * 3) There is no reliable way to differentiate the nanosecond timings if only 1 is present. However this may not - * matter as GCToolKit would only use these values to create a baseline measure to align date/time with uptime. - * This technique is designed to work-around the cases where logs do not contain the uptime decorator. - * 4) There is no known way to reliably differentiate between PID and TID. At this time, GCToolKit ignores these - * decorators. - * - * Todo: GCToolkit captures time in the DateTimeStamp class. That class will capture uptime or time or both. If both - * are missing, GCToolkit JVMEvents will have no sense of time. It is possible that the other timing fields could fill - * in cases where both the time and uptime decorators were missing. - * @param line - */ + /// This class represents the decorators found in the log line as defined by JEP 158 (https://openjdk.java.net/jeps/158). + /// The list, taken from that document is as: + /// time -- Current time and date in ISO-8601 format + /// uptime -- Time since the start of the JVM in seconds and milliseconds (e.g., 6.567s) + /// timemillis -- The same value as generated by System.currentTimeMillis() + /// uptimemillis -- Milliseconds since the JVM started + /// timenanos -- The same value as generated by System.nanoTime() + /// uptimenanos -- Nanoseconds since the JVM started + /// pid -- The process identifier + /// tid -- The thread identifier + /// level -- The level associated with the log message + /// tags -- The tag-set associated with the log message + /// + /// This implementation takes advantage of the property that the ordering of tags is stable. For example, + /// -Xlog:*::pid,time produces the identical ordering as -Xlog:*::time,pid. Moreover, the list of decorators + /// is dedupped implying that the second decorator in -Xlog:*::time,time is ignored. + /// + /// The default decorators (as of the time of authoring JDK 9-21) include [uptime][level][tags]. + /// For example, [1.361s][info][gc,heap]. This reads uptime of 1.361 seconds. The tag for the log record + /// is gc.heap at the info level. + /// + /// At issue is that uptime and timemillis are, on the surface, indistinguishable. The same is true with + /// timenanos and uptimenanos as well as with pid and tid. The following logic can be used to help differentiate + /// indistinguishable decorators. + /// + /// 1) If both decorators are present then order can be used to differentiate + /// 2) If ms time value - 20 years > 0, then timemillis can be assumed. Otherwise uptime is assumed. The reasoning + /// is, unified logging didn't exist that long ago. The value of 20 has been arbitrarily chosen. + /// 3) There is no reliable way to differentiate the nanosecond timings if only 1 is present. However this may not + /// matter as GCToolKit would only use these values to create a baseline measure to align date/time with uptime. + /// This technique is designed to work-around the cases where logs do not contain the uptime decorator. + /// 4) There is no known way to reliably differentiate between PID and TID. At this time, GCToolKit ignores these + /// decorators. + /// + /// Todo: GCToolkit captures time in the DateTimeStamp class. That class will capture uptime or time or both. If both + /// are missing, GCToolkit JVMEvents will have no sense of time. It is possible that the other timing fields could fill + /// in cases where both the time and uptime decorators were missing. + /// @param line private static final Logger LOGGER = Logger.getLogger(Decorators.class.getName()); @@ -96,7 +95,7 @@ private void extractValues(String line) { // Retrieving a group from a matcher calls substring each time // Store all the groups in an array ahead of time to avoid paying this cost unnecessarily decoratorGroups = new String[decoratorMatcher.groupCount()]; - for (int i = 1; i <= decoratorMatcher.groupCount(); i++) { + for (var i = 1; i <= decoratorMatcher.groupCount(); i++) { String group = decoratorMatcher.group(i); decoratorGroups[i-1] = group; if (group != null) @@ -107,7 +106,7 @@ private void extractValues(String line) { // For some reason, ISO_DATE_TIME doesn't like that time-zone is -0100. It wants -01:00. private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); - public ZonedDateTime getDateStamp() { + public @Nullable ZonedDateTime getDateStamp() { try { String value = decoratorGroups[DATE_STAMP_GROUP]; if (value != null) { @@ -130,7 +129,7 @@ public double getUpTime() { } private long extractClock(int groupIndex, long threshold) { - long clockReading = -1L; + var clockReading = -1L; String stringValue = decoratorGroups[groupIndex]; if (stringValue != null) { clockReading = Long.parseLong(unboxValue(stringValue, 2)); @@ -151,7 +150,7 @@ public long getUptimeMillis() { value = decoratorGroups[TIME_MILLIS_OR_MAYBE_UPTIME_MILLIS_GROUP]; } if (value != null) { - long longValue = Long.parseLong(unboxValue(value, 2)); + var longValue = Long.parseLong(unboxValue(value, 2)); if (longValue < TWENTY_YEARS_IN_MILLIS) return longValue; } @@ -168,7 +167,7 @@ public long getUptimeNano() { value = decoratorGroups[TIME_NANOS_OR_MAYBE_UPTIME_NANOS_GROUP]; } if (value != null) { - long longValue = Long.parseLong(unboxValue(value, 2)); + var longValue = Long.parseLong(unboxValue(value, 2)); if (longValue < TWENTY_YEARS_IN_NANO) return longValue; } diff --git a/parser/src/main/java/com/microsoft/gctoolkit/parser/jvm/GarbageCollectorAlgorithm.java b/parser/src/main/java/com/microsoft/gctoolkit/parser/jvm/GarbageCollectorAlgorithm.java index 2e85cb4c..49d80e42 100644 --- a/parser/src/main/java/com/microsoft/gctoolkit/parser/jvm/GarbageCollectorAlgorithm.java +++ b/parser/src/main/java/com/microsoft/gctoolkit/parser/jvm/GarbageCollectorAlgorithm.java @@ -3,24 +3,24 @@ package com.microsoft.gctoolkit.parser.jvm; public enum GarbageCollectorAlgorithm { - /** -XX:+UseConcMarkSweepGC */ + /// -XX:+UseConcMarkSweepGC DEFNEW, // 1 - /** -XX:+UseConcMarkSweepGC -XX:+UseParNew */ + /// -XX:+UseConcMarkSweepGC -XX:+UseParNew PARNEW, // 2 - /** -XX:+UseConcMarkSweepGC */ + /// -XX:+UseConcMarkSweepGC CMS, // 3 - /** -XX:+UseConcMarkSweepGC -XX:+CMSIncrementalMode */ + /// -XX:+UseConcMarkSweepGC -XX:+CMSIncrementalMode ICMS, // 4 - /** -XX:+UseParallelGC */ + /// -XX:+UseParallelGC PARALLELGC, // 5 - /** -XX:+UseParallelGC -XX:+UseParallelOldGC
-XX:+UseParallelOldGC */ + /// -XX:+UseParallelGC -XX:+UseParallelOldGC
-XX:+UseParallelOldGC PARALLELOLDGC, // 6 - /** -XX:+UseSerialGC */ + /// -XX:+UseSerialGC SERIAL, // 7 - /** -XX:+UseSerialGC */ + /// -XX:+UseSerialGC G1GC, // 8 - /** -XX:+UseZGC */ + /// -XX:+UseZGC ZGC, // 9 - /** -XX:+UseShenandoahGC */ + /// -XX:+UseShenandoahGC SHENANDOAH // 10 } diff --git a/parser/src/main/java/com/microsoft/gctoolkit/parser/jvm/GarbageCollectorFlag.java b/parser/src/main/java/com/microsoft/gctoolkit/parser/jvm/GarbageCollectorFlag.java index 7190abd6..648ee23e 100644 --- a/parser/src/main/java/com/microsoft/gctoolkit/parser/jvm/GarbageCollectorFlag.java +++ b/parser/src/main/java/com/microsoft/gctoolkit/parser/jvm/GarbageCollectorFlag.java @@ -2,6 +2,8 @@ // Licensed under the MIT License. package com.microsoft.gctoolkit.parser.jvm; +import org.jspecify.annotations.Nullable; + public enum GarbageCollectorFlag { @@ -13,15 +15,15 @@ public enum GarbageCollectorFlag { UseSerialGC("UseSerialGC"), CMSIncrementialMode("CMSIncrementalMode"); - public static GarbageCollectorFlag getEnumFromString(String string) { + public static @Nullable GarbageCollectorFlag getEnumFromString(String string) { try { return Enum.valueOf(GarbageCollectorFlag.class, string.trim()); - } catch (IllegalArgumentException ex) { + } catch (IllegalArgumentException _) { } return null; } - public static GarbageCollectorFlag fromString(String name) { + public static @Nullable GarbageCollectorFlag fromString(String name) { return getEnumFromString(name); } diff --git a/parser/src/main/java/com/microsoft/gctoolkit/parser/jvm/PreUnifiedDiarizer.java b/parser/src/main/java/com/microsoft/gctoolkit/parser/jvm/PreUnifiedDiarizer.java index 1bf6beb6..d48c3b03 100644 --- a/parser/src/main/java/com/microsoft/gctoolkit/parser/jvm/PreUnifiedDiarizer.java +++ b/parser/src/main/java/com/microsoft/gctoolkit/parser/jvm/PreUnifiedDiarizer.java @@ -29,64 +29,62 @@ import static com.microsoft.gctoolkit.parser.SharedPatterns.MEMORY_SUMMARY_RULE; import static com.microsoft.gctoolkit.parser.SharedPatterns.META_SPACE_RECORD; -/** - * Class to answer 3 questions about the GC log; - * - which collector combination is being used - * - which JVM version - * - which flags are being used - *

- * Collectors - * - Unknown (no details) - * - Serial - * - ParNew/CMS - * - iCMS - * - PSYoungGen/PSFull - * - G1GC - *

- * Version breaks - * Can be known precisely if header is present in GC log. - * prior to 1.7.0_45 - * 1.7.0_45 has the System.gc() regression - * 1.8.0_05 anything after this version will include G1 Metaspace clause - * 1.9.0 unknown how to determine this via deriveConfiguration. - *

- * Are these flags set - * PrintGCDetails - * PrintTenuringDistrubtion - * PrintGCApplicationStoppedTime - * PrintGCApplicationConcurrentTime - *

- * Log file characteristics - *

- * pre 7.0_45 - * - Permspace - * - (System) - *

- * 7.0_45+ - * - (System.gc()) - * - Permspace - *

- * 8.0 - * - Metaspace - *

- * 8.0_20 - * - G1 prints Metaspace clause - *

- * Collector clues - * iCMS - * - CMS cycle starts early but once completed all further records will contain "icms_dc=" - *

- * ParNew/CMS - * - ParNew - * - initial-mark - *

- * PSYoung/PSFull - * - PSYoungGen - * - PSFull - *

- * Serial - * - DefNew - */ +/// Class to answer 3 questions about the GC log; +/// - which collector combination is being used +/// - which JVM version +/// - which flags are being used +/// +/// Collectors +/// - Unknown (no details) +/// - Serial +/// - ParNew/CMS +/// - iCMS +/// - PSYoungGen/PSFull +/// - G1GC +/// +/// Version breaks +/// Can be known precisely if header is present in GC log. +/// prior to 1.7.0_45 +/// 1.7.0_45 has the System.gc() regression +/// 1.8.0_05 anything after this version will include G1 Metaspace clause +/// 1.9.0 unknown how to determine this via deriveConfiguration. +/// +/// Are these flags set +/// PrintGCDetails +/// PrintTenuringDistrubtion +/// PrintGCApplicationStoppedTime +/// PrintGCApplicationConcurrentTime +/// +/// Log file characteristics +/// +/// pre 7.0_45 +/// - Permspace +/// - (System) +/// +/// 7.0_45+ +/// - (System.gc()) +/// - Permspace +/// +/// 8.0 +/// - Metaspace +/// +/// 8.0_20 +/// - G1 prints Metaspace clause +/// +/// Collector clues +/// iCMS +/// - CMS cycle starts early but once completed all further records will contain "icms_dc=" +/// +/// ParNew/CMS +/// - ParNew +/// - initial-mark +/// +/// PSYoung/PSFull +/// - PSYoungGen +/// - PSFull +/// +/// Serial +/// - DefNew //SimplePatterns, CMSPatterns, ParallelPatterns, G1GCPatterns, public class PreUnifiedDiarizer implements Diarizer { @@ -198,10 +196,8 @@ else if (simpleParallelOrParNewDetected) { diary.setFalse(SupportedFlags.MAX_TENURING_THRESHOLD_VIOLATION, SupportedFlags.PRINT_PROMOTION_FAILURE, SupportedFlags.PRINT_FLS_STATISTICS); } - /** - * Attempt to diarize the GC Log line that's come. That is, if we collect enough details about - * this log in oder to categorize it by collector and collector features then we return true - */ + /// Attempt to diarize the GC Log line that's come. That is, if we collect enough details about + /// this log in oder to categorize it by collector and collector features then we return true @Override public boolean diarize(String line) { @@ -761,7 +757,7 @@ else if (collectionCount > 1) private void evaluateCommandLineFlags(String[] commandLineFlags) { for (String rawFlag : commandLineFlags) { String flag = processRawFlag(rawFlag); - boolean flagTurnedOn = isSetToTrue(rawFlag); + var flagTurnedOn = isSetToTrue(rawFlag); CommandLineFlag supportedFlag = CommandLineFlag.fromString(flag); if (supportedFlag != null) { switch (supportedFlag) { @@ -817,31 +813,31 @@ private void evaluateCommandLineFlags(String[] commandLineFlags) { if (gcFlag != null) { switch (gcFlag) { case UseSerialGC: - setGCFlags |= (flagTurnedOn) ? 0x1 : 0x100; + setGCFlags |= flagTurnedOn ? 0x1 : 0x100; break; case UseParallelGC: - setGCFlags |= (flagTurnedOn) ? 0x2 : 0x200; + setGCFlags |= flagTurnedOn ? 0x2 : 0x200; break; case UseParallelOldGC: - setGCFlags |= (flagTurnedOn) ? 0x4 : 0x400; + setGCFlags |= flagTurnedOn ? 0x4 : 0x400; break; case UseParNewGC: - setGCFlags |= (flagTurnedOn) ? 0x8 : 0x800; + setGCFlags |= flagTurnedOn ? 0x8 : 0x800; break; case UseConcMarkSweepGC: - setGCFlags |= (flagTurnedOn) ? 0x10 : 0x1000; + setGCFlags |= flagTurnedOn ? 0x10 : 0x1000; break; case CMSIncrementialMode: - setGCFlags |= (flagTurnedOn) ? 0x20 : 0; + setGCFlags |= flagTurnedOn ? 0x20 : 0; break; case UseG1GC: - setGCFlags |= (flagTurnedOn) ? 0x40 : 0x4000; + setGCFlags |= flagTurnedOn ? 0x40 : 0x4000; break; default: @@ -859,13 +855,13 @@ private void evaluateCommandLineFlags(String[] commandLineFlags) { private String processRawFlag(String rawFlag) { - String processedFlag = ""; + var processedFlag = ""; if (rawFlag.startsWith("-XX:")) { if (rawFlag.charAt(4) == '+' || rawFlag.charAt(4) == '-') processedFlag = rawFlag.substring(5); else processedFlag = rawFlag.substring(4); - int equalsPosition = processedFlag.indexOf("="); + var equalsPosition = processedFlag.indexOf("="); if (equalsPosition > 0) processedFlag = processedFlag.substring(0, equalsPosition); } @@ -874,7 +870,7 @@ private String processRawFlag(String rawFlag) { } private boolean isSetToTrue(String flag) { - return (flag.startsWith("-XX:+")); + return flag.startsWith("-XX:+"); } //"Java HotSpot(TM) 64-Bit Server VM (25.40-b25) for bsd-amd64 JRE (1.8.0_40-b25), built on Feb 10 2015 21:07:25 by \"java_re\" with gcc 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)", @@ -890,12 +886,12 @@ private void parseJVMVersion(String versionString) { if (matcher.group(3) == null) diary.setTrue(SupportedFlags.PRE_JDK70_40); try { - int minorVersion = Integer.parseInt(matcher.group(3).substring(1)); + var minorVersion = Integer.parseInt(matcher.group(3).substring(1)); if (minorVersion < 41) diary.setTrue(SupportedFlags.PRE_JDK70_40); else diary.setFalse(SupportedFlags.PRE_JDK70_40); - } catch (NumberFormatException nfe) { + } catch (NumberFormatException _) { diary.setTrue(SupportedFlags.PRE_JDK70_40); } break; diff --git a/parser/src/main/java/com/microsoft/gctoolkit/parser/jvm/UnifiedDiarizer.java b/parser/src/main/java/com/microsoft/gctoolkit/parser/jvm/UnifiedDiarizer.java index 30743a07..94238733 100644 --- a/parser/src/main/java/com/microsoft/gctoolkit/parser/jvm/UnifiedDiarizer.java +++ b/parser/src/main/java/com/microsoft/gctoolkit/parser/jvm/UnifiedDiarizer.java @@ -4,20 +4,20 @@ import com.microsoft.gctoolkit.jvm.Diarizer; import com.microsoft.gctoolkit.jvm.Diary; +import com.microsoft.gctoolkit.jvm.SupportedFlags; import com.microsoft.gctoolkit.parser.unified.UnifiedLoggingLevel; import com.microsoft.gctoolkit.time.DateTimeStamp; +import java.util.Set; import java.util.TreeSet; -import static com.microsoft.gctoolkit.jvm.SupportedFlags.GC_CAUSE; -import static com.microsoft.gctoolkit.jvm.SupportedFlags.*; +import com.microsoft.gctoolkit.jvm.SupportedFlags; import static com.microsoft.gctoolkit.parser.unified.ShenandoahPatterns.SHENANDOAH_TAG; import static com.microsoft.gctoolkit.parser.unified.UnifiedG1GCPatterns.G1_COLLECTION; import static com.microsoft.gctoolkit.parser.unified.UnifiedG1GCPatterns.G1_TAG; import static com.microsoft.gctoolkit.parser.unified.UnifiedGenerationalPatterns.*; import static com.microsoft.gctoolkit.parser.unified.UnifiedPatterns.CPU_BREAKOUT; import static com.microsoft.gctoolkit.parser.unified.ZGCPatterns.CYCLE_START; -import static com.microsoft.gctoolkit.parser.unified.ZGCPatterns.ZGC_TAG; //ShenandoahPatterns, ZGCPatterns, UnifiedG1GCPatterns, UnifiedGenerationalPatterns, public class UnifiedDiarizer implements Diarizer { @@ -28,18 +28,19 @@ public class UnifiedDiarizer implements Diarizer { private int lineCount = MAXIMUM_LINES_TO_EXAMINE; private final Diary diary; - private final TreeSet tagsAndLevels = new TreeSet<>(); + private final Set tagsAndLevels = new TreeSet<>(); private int stopTheWorldEvents = 0; { diary = new Diary(); - diary.setTrue(UNIFIED_LOGGING); - diary.setFalse(ICMS, PRE_JDK70_40, JDK70, PRE_JDK70_40, JDK80, MAX_TENURING_THRESHOLD_VIOLATION); + diary.setTrue(SupportedFlags.UNIFIED_LOGGING); + diary.setFalse(SupportedFlags.ICMS, SupportedFlags.PRE_JDK70_40, SupportedFlags.JDK70, SupportedFlags.PRE_JDK70_40, SupportedFlags.JDK80, SupportedFlags.MAX_TENURING_THRESHOLD_VIOLATION); } public UnifiedDiarizer() {} + @Override public Diary getDiary() { fillInKnowns(); return diary; @@ -70,7 +71,7 @@ public boolean hasJVMEvents() { } private void fillInKnowns() { - diary.setFalse(ADAPTIVE_SIZING); + diary.setFalse(SupportedFlags.ADAPTIVE_SIZING); } @Override @@ -97,56 +98,54 @@ public boolean diarize(String line) { return this.completed(); } - /** - * Extract decorators (from a GC log line tag) and set the corresponding diary flags accordingly - * - * @param line GC log line - */ + /// Extract decorators (from a GC log line tag) and set the corresponding diary flags accordingly + /// + /// @param line GC log line private void extractDecorators(String line) { - Decorators decorators = new Decorators(line); + var decorators = new Decorators(line); timeOfFirstEvent(decorators); extractTagsAndLevels(decorators); // -Xlog:gc*,gc+ref=debug,gc+phases=debug,gc+age=trace,safepoint if (decorators.getLogLevel().isPresent()) { UnifiedLoggingLevel logLevel = decorators.getLogLevel().get(); if (decorators.tagsContain("gc,age")) - diary.setTrue(TENURING_DISTRIBUTION); + diary.setTrue(SupportedFlags.TENURING_DISTRIBUTION); else if (decorators.tagsContain("ref") && logLevel.isGreaterThanOrEqualTo(UnifiedLoggingLevel.debug)) - diary.setTrue(PRINT_REFERENCE_GC); + diary.setTrue(SupportedFlags.PRINT_REFERENCE_GC); else if (decorators.tagsContain("gc,phases") && logLevel.isGreaterThanOrEqualTo(UnifiedLoggingLevel.debug)) - diary.setTrue(GC_DETAILS); + diary.setTrue(SupportedFlags.GC_DETAILS); else if ( decorators.tagsContain("gc,ergo")) - diary.setTrue(ADAPTIVE_SIZING); + diary.setTrue(SupportedFlags.ADAPTIVE_SIZING); else if (decorators.tagsContain("gc,cpu")) - diary.setTrue(PRINT_CPU_TIMES); + diary.setTrue(SupportedFlags.PRINT_CPU_TIMES); if (decorators.tagsContain("safepoint")) - diary.setTrue(APPLICATION_STOPPED_TIME, APPLICATION_CONCURRENT_TIME); + diary.setTrue(SupportedFlags.APPLICATION_STOPPED_TIME, SupportedFlags.APPLICATION_CONCURRENT_TIME); if (diary.isZGC()) { if (decorators.tagsContain("task")) - diary.setTrue(GC_DETAILS); + diary.setTrue(SupportedFlags.GC_DETAILS); else if (decorators.tagsContain("heap")) - diary.setTrue(PRINT_HEAP_AT_GC); + diary.setTrue(SupportedFlags.PRINT_HEAP_AT_GC); else if (decorators.tagsContain("tlab")) - diary.setTrue(TLAB_DATA); + diary.setTrue(SupportedFlags.TLAB_DATA); else if (decorators.tagsContain("gc,start") && line.contains("Garbage Collection (")) - diary.setTrue(GC_CAUSE); + diary.setTrue(SupportedFlags.GC_CAUSE); else if (decorators.tagsContain("gc,heap")) { if (line.contains("Heap before GC")) - diary.setTrue(PRINT_HEAP_AT_GC); - diary.setTrue(GC_DETAILS); + diary.setTrue(SupportedFlags.PRINT_HEAP_AT_GC); + diary.setTrue(SupportedFlags.GC_DETAILS); } else if (decorators.tagsContain("gc,ref")) - diary.setTrue(PRINT_REFERENCE_GC); + diary.setTrue(SupportedFlags.PRINT_REFERENCE_GC); else if (decorators.tagsContain("gc,heap") && decorators.getLogLevel().get() == UnifiedLoggingLevel.debug) - diary.setTrue(PRINT_HEAP_AT_GC); + diary.setTrue(SupportedFlags.PRINT_HEAP_AT_GC); } else if (diary.isShenandoah()) { if (decorators.tagsContain("gc,task") || decorators.tagsContain("gc,start")) - diary.setTrue(GC_DETAILS); + diary.setTrue(SupportedFlags.GC_DETAILS); else if (decorators.tagsContain("gc,ergo")) - diary.setTrue(ADAPTIVE_SIZING); + diary.setTrue(SupportedFlags.ADAPTIVE_SIZING); else if (decorators.tagsContain("gc") && line.contains("Trigger")) - diary.setTrue(GC_CAUSE); + diary.setTrue(SupportedFlags.GC_CAUSE); } } } @@ -175,72 +174,69 @@ private void discoverCollector(String line) { if (CYCLE_START.parse(line) != null) { String cycleType = CYCLE_START.parse(line).getGroup(2); - diary.setTrue(ZGC); - if(cycleType.equals("Minor") || cycleType.equals("Major")) - diary.setTrue(GENERATIONAL_ZGC); + diary.setTrue(SupportedFlags.ZGC); + if("Minor".equals(cycleType) || "Major".equals(cycleType)) + diary.setTrue(SupportedFlags.GENERATIONAL_ZGC); else - diary.setFalse(GENERATIONAL_ZGC); - diary.setFalse(DEFNEW, SERIAL, PARALLELGC, PARALLELOLDGC, PARNEW, CMS, ICMS, G1GC, RSET_STATS, SHENANDOAH, CMS_DEBUG_LEVEL_1, PRE_JDK70_40, JDK70, JDK80, TENURING_DISTRIBUTION, MAX_TENURING_THRESHOLD_VIOLATION, TLAB_DATA, PRINT_PROMOTION_FAILURE, PRINT_FLS_STATISTICS, ADAPTIVE_SIZING); + diary.setFalse(SupportedFlags.GENERATIONAL_ZGC); + diary.setFalse(SupportedFlags.DEFNEW, SupportedFlags.SERIAL, SupportedFlags.PARALLELGC, SupportedFlags.PARALLELOLDGC, SupportedFlags.PARNEW, SupportedFlags.CMS, SupportedFlags.ICMS, SupportedFlags.G1GC, SupportedFlags.RSET_STATS, SupportedFlags.SHENANDOAH, SupportedFlags.CMS_DEBUG_LEVEL_1, SupportedFlags.PRE_JDK70_40, SupportedFlags.JDK70, SupportedFlags.JDK80, SupportedFlags.TENURING_DISTRIBUTION, SupportedFlags.MAX_TENURING_THRESHOLD_VIOLATION, SupportedFlags.TLAB_DATA, SupportedFlags.PRINT_PROMOTION_FAILURE, SupportedFlags.PRINT_FLS_STATISTICS, SupportedFlags.ADAPTIVE_SIZING); return; } if ( SHENANDOAH_TAG.parse(line) != null) { - diary.setTrue(SHENANDOAH); - diary.setFalse(DEFNEW, SERIAL, PARALLELGC, PARALLELOLDGC, PARNEW, CMS, ICMS, G1GC, RSET_STATS, ZGC, CMS_DEBUG_LEVEL_1, PRE_JDK70_40, JDK70, JDK80, TENURING_DISTRIBUTION, MAX_TENURING_THRESHOLD_VIOLATION, TLAB_DATA, PRINT_PROMOTION_FAILURE, PRINT_FLS_STATISTICS, PRINT_HEAP_AT_GC, GENERATIONAL_ZGC); + diary.setTrue(SupportedFlags.SHENANDOAH); + diary.setFalse(SupportedFlags.DEFNEW, SupportedFlags.SERIAL, SupportedFlags.PARALLELGC, SupportedFlags.PARALLELOLDGC, SupportedFlags.PARNEW, SupportedFlags.CMS, SupportedFlags.ICMS, SupportedFlags.G1GC, SupportedFlags.RSET_STATS, SupportedFlags.ZGC, SupportedFlags.CMS_DEBUG_LEVEL_1, SupportedFlags.PRE_JDK70_40, SupportedFlags.JDK70, SupportedFlags.JDK80, SupportedFlags.TENURING_DISTRIBUTION, SupportedFlags.MAX_TENURING_THRESHOLD_VIOLATION, SupportedFlags.TLAB_DATA, SupportedFlags.PRINT_PROMOTION_FAILURE, SupportedFlags.PRINT_FLS_STATISTICS, SupportedFlags.PRINT_HEAP_AT_GC, SupportedFlags.GENERATIONAL_ZGC); return; } if (G1_TAG.parse(line) != null || line.contains("G1 Evacuation Pause") || (line.contains("Humongous regions: "))) { - diary.setTrue(G1GC); - diary.setFalse(DEFNEW, SERIAL, PARALLELGC, PARALLELOLDGC, PARNEW, CMS, ICMS, ZGC, SHENANDOAH, CMS_DEBUG_LEVEL_1, PRE_JDK70_40, JDK70, JDK80, TLAB_DATA, PRINT_PROMOTION_FAILURE, PRINT_FLS_STATISTICS, GENERATIONAL_ZGC); + diary.setTrue(SupportedFlags.G1GC); + diary.setFalse(SupportedFlags.DEFNEW, SupportedFlags.SERIAL, SupportedFlags.PARALLELGC, SupportedFlags.PARALLELOLDGC, SupportedFlags.PARNEW, SupportedFlags.CMS, SupportedFlags.ICMS, SupportedFlags.ZGC, SupportedFlags.SHENANDOAH, SupportedFlags.CMS_DEBUG_LEVEL_1, SupportedFlags.PRE_JDK70_40, SupportedFlags.JDK70, SupportedFlags.JDK80, SupportedFlags.TLAB_DATA, SupportedFlags.PRINT_PROMOTION_FAILURE, SupportedFlags.PRINT_FLS_STATISTICS, SupportedFlags.GENERATIONAL_ZGC); return; } if (CMS_TAG.parse(line) != null || PARNEW_TAG.parse(line) != null || line.contains("ParNew")) { - diary.setTrue(PARNEW, CMS); - diary.setFalse(DEFNEW, SERIAL, PARALLELGC, PARALLELOLDGC, ICMS, CMS_DEBUG_LEVEL_1, G1GC, ZGC, SHENANDOAH, PRE_JDK70_40, JDK70, JDK80, RSET_STATS, GENERATIONAL_ZGC); + diary.setTrue(SupportedFlags.PARNEW, SupportedFlags.CMS); + diary.setFalse(SupportedFlags.DEFNEW, SupportedFlags.SERIAL, SupportedFlags.PARALLELGC, SupportedFlags.PARALLELOLDGC, SupportedFlags.ICMS, SupportedFlags.CMS_DEBUG_LEVEL_1, SupportedFlags.G1GC, SupportedFlags.ZGC, SupportedFlags.SHENANDOAH, SupportedFlags.PRE_JDK70_40, SupportedFlags.JDK70, SupportedFlags.JDK80, SupportedFlags.RSET_STATS, SupportedFlags.GENERATIONAL_ZGC); return; } if (PARALLEL_TAG.parse(line) != null || line.contains("ParOldGen") || line.contains("PSYoungGen")) { - diary.setTrue(PARALLELGC, PARALLELOLDGC, GC_CAUSE); - diary.setFalse(DEFNEW, SERIAL, PARNEW, CMS, ICMS, CMS_DEBUG_LEVEL_1, G1GC, ZGC, SHENANDOAH, PRE_JDK70_40, JDK70, JDK80, RSET_STATS, GENERATIONAL_ZGC); + diary.setTrue(SupportedFlags.PARALLELGC, SupportedFlags.PARALLELOLDGC, SupportedFlags.GC_CAUSE); + diary.setFalse(SupportedFlags.DEFNEW, SupportedFlags.SERIAL, SupportedFlags.PARNEW, SupportedFlags.CMS, SupportedFlags.ICMS, SupportedFlags.CMS_DEBUG_LEVEL_1, SupportedFlags.G1GC, SupportedFlags.ZGC, SupportedFlags.SHENANDOAH, SupportedFlags.PRE_JDK70_40, SupportedFlags.JDK70, SupportedFlags.JDK80, SupportedFlags.RSET_STATS, SupportedFlags.GENERATIONAL_ZGC); return; } if (SERIAL_TAG.parse(line) != null || line.contains("DefNew")) { - diary.setTrue(DEFNEW, SERIAL, GC_CAUSE); - diary.setFalse(PARALLELGC, PARALLELOLDGC, PARNEW, CMS, ICMS, CMS_DEBUG_LEVEL_1, G1GC, ZGC, SHENANDOAH, PRE_JDK70_40, JDK70, JDK80, RSET_STATS, GENERATIONAL_ZGC); + diary.setTrue(SupportedFlags.DEFNEW, SupportedFlags.SERIAL, SupportedFlags.GC_CAUSE); + diary.setFalse(SupportedFlags.PARALLELGC, SupportedFlags.PARALLELOLDGC, SupportedFlags.PARNEW, SupportedFlags.CMS, SupportedFlags.ICMS, SupportedFlags.CMS_DEBUG_LEVEL_1, SupportedFlags.G1GC, SupportedFlags.ZGC, SupportedFlags.SHENANDOAH, SupportedFlags.PRE_JDK70_40, SupportedFlags.JDK70, SupportedFlags.JDK80, SupportedFlags.RSET_STATS, SupportedFlags.GENERATIONAL_ZGC); return; } } - /** - * - * @param line - */ + /// @param line private void discoverDetails(String line) { //todo: RSET_STATS for G1 not looked for... if (G1_COLLECTION.parse(line) != null) { - diary.setTrue(GC_CAUSE); + diary.setTrue(SupportedFlags.GC_CAUSE); } else if (CYCLE_START.parse(line) != null) { - diary.setTrue(GC_CAUSE); + diary.setTrue(SupportedFlags.GC_CAUSE); } if (stopTheWorldEvents > CYCLES_TO_EXAMINE_BEFORE_GIVING_UP) - diary.setFalse(ADAPTIVE_SIZING, GC_CAUSE, TLAB_DATA, PRINT_REFERENCE_GC, PRINT_PROMOTION_FAILURE, PRINT_FLS_STATISTICS, RSET_STATS, PRINT_HEAP_AT_GC); + diary.setFalse(SupportedFlags.ADAPTIVE_SIZING, SupportedFlags.GC_CAUSE, SupportedFlags.TLAB_DATA, SupportedFlags.PRINT_REFERENCE_GC, SupportedFlags.PRINT_PROMOTION_FAILURE, SupportedFlags.PRINT_FLS_STATISTICS, SupportedFlags.RSET_STATS, SupportedFlags.PRINT_HEAP_AT_GC); } private void discoverJVMEvents(String line) { if (stopTheWorldEvents > CYCLES_TO_EXAMINE_FOR_SAFEPOINT) { - diary.setFalse(APPLICATION_STOPPED_TIME, APPLICATION_CONCURRENT_TIME); + diary.setFalse(SupportedFlags.APPLICATION_STOPPED_TIME, SupportedFlags.APPLICATION_CONCURRENT_TIME); } } diff --git a/parser/src/main/java/com/microsoft/gctoolkit/parser/unified/UnifiedLoggingLevel.java b/parser/src/main/java/com/microsoft/gctoolkit/parser/unified/UnifiedLoggingLevel.java index b0f3d0a2..6270769f 100644 --- a/parser/src/main/java/com/microsoft/gctoolkit/parser/unified/UnifiedLoggingLevel.java +++ b/parser/src/main/java/com/microsoft/gctoolkit/parser/unified/UnifiedLoggingLevel.java @@ -20,19 +20,15 @@ public String getLabel() { return label; } - /** - * @param other logging level to compare this one to - * @return whether this logging level is lesser or equal to the other one - */ + /// @param other logging level to compare this one to + /// @return whether this logging level is lesser or equal to the other one public boolean isLessThanOrEqualTo(UnifiedLoggingLevel other) { return this.compareTo(other) <= 0; } - /** - * @param other logging level to compare this one to - * @return whether this logging level is greater or equal to the other one - */ + /// @param other logging level to compare this one to + /// @return whether this logging level is greater or equal to the other one public boolean isGreaterThanOrEqualTo(UnifiedLoggingLevel other) { return this.compareTo(other) >= 0; } diff --git a/parser/src/main/java/com/microsoft/gctoolkit/parser/vmops/SafepointParser.java b/parser/src/main/java/com/microsoft/gctoolkit/parser/vmops/SafepointParser.java index 51170261..d03f7e54 100644 --- a/parser/src/main/java/com/microsoft/gctoolkit/parser/vmops/SafepointParser.java +++ b/parser/src/main/java/com/microsoft/gctoolkit/parser/vmops/SafepointParser.java @@ -21,6 +21,7 @@ public Set eventsProduced() { return Set.of(EventSource.SAFEPOINT); } + @Override public String getName() { return "SafepointParser"; } @@ -30,7 +31,7 @@ protected void process(String line) { if ((trace = TRACE.parse(line)) != null) { Safepoint safepoint = trace.toSafepoint(); super.publish(ChannelName.JVM_EVENT_PARSER_OUTBOX, safepoint); - } else if (line.equals(END_OF_DATA_SENTINEL)) + } else if (END_OF_DATA_SENTINEL.equals(line)) super.publish( ChannelName.JVM_EVENT_PARSER_OUTBOX, new JVMTermination(getClock(),diary.getTimeOfFirstEvent())); } diff --git a/parser/src/main/java/com/microsoft/gctoolkit/parser/vmops/SafepointPatterns.java b/parser/src/main/java/com/microsoft/gctoolkit/parser/vmops/SafepointPatterns.java index 2b056583..3d99c33f 100644 --- a/parser/src/main/java/com/microsoft/gctoolkit/parser/vmops/SafepointPatterns.java +++ b/parser/src/main/java/com/microsoft/gctoolkit/parser/vmops/SafepointPatterns.java @@ -6,10 +6,8 @@ import com.microsoft.gctoolkit.parser.PreUnifiedTokens; import com.microsoft.gctoolkit.parser.SafepointParseRule; -/** - * General format is; - * vmop [threads: total initially_running wait_to_block] [time: spin block sync cleanup vmop] page_trap_count - */ +/// General format is; +/// vmop [threads: total initially_running wait_to_block] [time: spin block sync cleanup vmop] page_trap_count public interface SafepointPatterns extends PreUnifiedTokens { String VMOP = "(Deoptimize|no vm operation|EnableBiasedLocking|GenCollectForAllocation|RevokeBias|BulkRevokeBias|ThreadDump|FindDeadlocks|Exit)"; diff --git a/parser/src/main/java/com/microsoft/gctoolkit/parser/vmops/SafepointTrace.java b/parser/src/main/java/com/microsoft/gctoolkit/parser/vmops/SafepointTrace.java index c042f19c..0fbd6e5b 100644 --- a/parser/src/main/java/com/microsoft/gctoolkit/parser/vmops/SafepointTrace.java +++ b/parser/src/main/java/com/microsoft/gctoolkit/parser/vmops/SafepointTrace.java @@ -16,7 +16,7 @@ public SafepointTrace(Matcher matcher) { } public Safepoint toSafepoint() { - Safepoint safepoint = new Safepoint(getVMOP(), getDateTimeStamp(), getDuration()); + var safepoint = new Safepoint(getVMOP(), getDateTimeStamp(), getDuration()); safepoint.recordThreadCounts(totalThreads(), initiallyRunningThreads(), waitingToBlockThreads()); safepoint.recordDurations(spinTime(), blockTime(), syncTime(), cleanupTime(), vmopTime()); safepoint.recordPageTrapCount(getTrapCount()); @@ -27,6 +27,7 @@ public String getVMOP() { return super.getGroup(VMOP); } + @Override public DateTimeStamp getDateTimeStamp() { return new DateTimeStamp(getTimeStampGroup()); } diff --git a/parser/src/main/java/module-info.java b/parser/src/main/java/module-info.java index 4ea91c2a..ff265217 100644 --- a/parser/src/main/java/module-info.java +++ b/parser/src/main/java/module-info.java @@ -7,6 +7,7 @@ module com.microsoft.gctoolkit.parser { requires com.microsoft.gctoolkit.api; requires java.logging; + requires transitive org.jspecify; exports com.microsoft.gctoolkit.parser to com.microsoft.gctoolkit.api; diff --git a/parser/src/test/java/com/microsoft/gctoolkit/parser/ConcurrentMarkSweepParserRulesTest.java b/parser/src/test/java/com/microsoft/gctoolkit/parser/ConcurrentMarkSweepParserRulesTest.java index 363be7c7..dfce4a3c 100644 --- a/parser/src/test/java/com/microsoft/gctoolkit/parser/ConcurrentMarkSweepParserRulesTest.java +++ b/parser/src/test/java/com/microsoft/gctoolkit/parser/ConcurrentMarkSweepParserRulesTest.java @@ -5,23 +5,19 @@ import com.microsoft.gctoolkit.GCToolKit; import org.junit.jupiter.api.Test; -import java.util.StringJoiner; - import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; public class ConcurrentMarkSweepParserRulesTest implements CMSPatterns { - /** - * Run all rules over all log entries looking for both misses and greedy rules. - */ + /// Run all rules over all log entries looking for both misses and greedy rules. @Test public void testCMSParseRules() { assertEquals(rules.length, lines.length, "Number of rules differs from the numbers of log entries"); - for (int i = 0; i < rules.length; i++) { - for (int j = 0; j < lines.length; j++) { - int captured = CommonTestHelper.captureTest(rules[i], lines[j]); + for (var i = 0; i < rules.length; i++) { + for (var j = 0; j < lines.length; j++) { + var captured = CommonTestHelper.captureTest(rules[i], lines[j]); if (i == j) { assertEquals(captured, lines[j].length, i + " failed to captured it's lines"); } else { @@ -37,7 +33,7 @@ public void testCMSParseRules() { //@Test //@Ignore("Not a real test, only for debugging") public void testDebugCMSParseRule() { - int index = rules.length-1; // awesome fix from David.. thanks :-) + var index = rules.length-1; // awesome fix from David.. thanks :-) index = 43; GCParseRule rule = rules[index]; evaluate(rule, lines[index][0]); @@ -49,9 +45,9 @@ private void evaluate(GCParseRule rule, String string) { assertNotNull(trace); // Enable debugging by setting gctoolkit.debug to true GCToolKit.LOG_DEBUG_MESSAGE(() -> { - StringBuilder sb = new StringBuilder("matches groups " + trace.groupCount()); - for (int i = 0; i <= trace.groupCount(); i++) { - sb.append(String.format("%n%d : %s", i, trace.getGroup(i))) ; + var sb = new StringBuilder("matches groups " + trace.groupCount()); + for (var i = 0; i <= trace.groupCount(); i++) { + sb.append("%n%d : %s".formatted(i, trace.getGroup(i))) ; } return sb.toString(); }); diff --git a/parser/src/test/java/com/microsoft/gctoolkit/parser/ConcurrentMarkSweepPhaseParserRulesTest.java b/parser/src/test/java/com/microsoft/gctoolkit/parser/ConcurrentMarkSweepPhaseParserRulesTest.java index 1bcf7b02..a518664a 100644 --- a/parser/src/test/java/com/microsoft/gctoolkit/parser/ConcurrentMarkSweepPhaseParserRulesTest.java +++ b/parser/src/test/java/com/microsoft/gctoolkit/parser/ConcurrentMarkSweepPhaseParserRulesTest.java @@ -20,9 +20,9 @@ public class ConcurrentMarkSweepPhaseParserRulesTest implements CMSPatterns { @Test public void testCMSParseRules() { assertEquals(rules.length,lines.length, "rules length != # of groups of lines to be test"); - for (int i = 0; i < rules.length; i++) { - for (int j = 0; j < lines.length; j++) { - int captured = captureTest(rules[i], lines[j]); + for (var i = 0; i < rules.length; i++) { + for (var j = 0; j < lines.length; j++) { + var captured = captureTest(rules[i], lines[j]); if (i == j) { assertEquals(captured, lines[j].length, i + " failed to captured it's lines"); } else { @@ -39,7 +39,7 @@ public void testCMSParseRules() { //@Test public void testDebugCMSParseRules() { - int index = 8; + var index = 8; for (String line : lines[index]) evaluate(rules[index], line); } @@ -52,9 +52,9 @@ private void evaluate(GCParseRule rule, String string) { trace.notYetImplemented(); // Enable debugging by setting gctoolkit.debug to true GCToolKit.LOG_DEBUG_MESSAGE(() -> { - StringBuilder sb = new StringBuilder("matches groups " + trace.groupCount()); - for (int i = 0; i <= trace.groupCount(); i++) { - sb.append(String.format("%n%d : %s", i, trace.getGroup(i))) ; + var sb = new StringBuilder("matches groups " + trace.groupCount()); + for (var i = 0; i <= trace.groupCount(); i++) { + sb.append("%n%d : %s".formatted(i, trace.getGroup(i))) ; } return sb.toString(); }); diff --git a/parser/src/test/java/com/microsoft/gctoolkit/parser/G1GCParserRulesTest.java b/parser/src/test/java/com/microsoft/gctoolkit/parser/G1GCParserRulesTest.java index f36e0571..14121153 100644 --- a/parser/src/test/java/com/microsoft/gctoolkit/parser/G1GCParserRulesTest.java +++ b/parser/src/test/java/com/microsoft/gctoolkit/parser/G1GCParserRulesTest.java @@ -14,9 +14,9 @@ public class G1GCParserRulesTest implements G1GCPatterns { @Test public void testG1GCParseRules() { - for (int i = 0; i < rules.length; i++) - for (int j = 0; j < lines.length; j++) { - int captured = CommonTestHelper.captureTest(rules[i], lines[j]); + for (var i = 0; i < rules.length; i++) + for (var j = 0; j < lines.length; j++) { + var captured = CommonTestHelper.captureTest(rules[i], lines[j]); if (i == j) { assertEquals(lines[j].length, captured, i + " failed to captured it's lines"); } else { @@ -29,7 +29,7 @@ public void testG1GCParseRules() { // test for debugging only... @Test public void testSingeRule() { - int index = 35; + var index = 35; assertEquals(1, CommonTestHelper.captureTest(rules[index], lines[index])); } @@ -40,7 +40,7 @@ private void evaluate(GCParseRule rule, String string, boolean dump) { assertNotNull(trace); if (dump) { LOGGER.fine("matches groups " + trace.groupCount()); - for (int i = 0; i <= trace.groupCount(); i++) { + for (var i = 0; i <= trace.groupCount(); i++) { LOGGER.fine(i + ": " + trace.getGroup(i)); } } diff --git a/parser/src/test/java/com/microsoft/gctoolkit/parser/G1GCUnifiedParserRulesTest.java b/parser/src/test/java/com/microsoft/gctoolkit/parser/G1GCUnifiedParserRulesTest.java index 03af8906..d82ad37b 100644 --- a/parser/src/test/java/com/microsoft/gctoolkit/parser/G1GCUnifiedParserRulesTest.java +++ b/parser/src/test/java/com/microsoft/gctoolkit/parser/G1GCUnifiedParserRulesTest.java @@ -14,22 +14,20 @@ public class G1GCUnifiedParserRulesTest implements UnifiedG1GCPatterns, TenuredPatterns { - /** - * The rules are; - * A pattern should capture the lines for which it is intended to capture - * A pattern should not capture any other lines. - * - * This testing is designed to run all patterns against all lines - */ + /// The rules are; + /// A pattern should capture the lines for which it is intended to capture + /// A pattern should not capture any other lines. + /// + /// This testing is designed to run all patterns against all lines private static final Logger LOGGER = Logger.getLogger(G1GCUnifiedParserRulesTest.class.getName()); @Test public void testG1GCParseRules() { assertEquals(lines.length,rules.length, "Rules and data dont't match"); - for (int i = 0; i < rules.length; i++) - for (int j = 0; j < lines.length; j++) { - int captured = captureTest(rules[i], lines[j]); + for (var i = 0; i < rules.length; i++) + for (var j = 0; j < lines.length; j++) { + var captured = captureTest(rules[i], lines[j]); if (i == j) { assertEquals(lines[j].length, captured,rules[i].getName() + " failed to capture"); } else { @@ -43,21 +41,21 @@ public void testG1GCParseRules() { @Test public void testUnifiedLoggingDecorators() { for (String decoratorLine : decoratorLines) { - Decorators decorators = new Decorators(decoratorLine); + var decorators = new Decorators(decoratorLine); assertTrue(decorators.getNumberOfDecorators() != 0); } } @Test @Disabled("used for debug testing") public void testSingeRuleCapture() { - int index = 6; + var index = 6; assertEquals(lines[index].length, captureTest(rules[index], lines[index]), "Miss for " + rules[index].getName()); } // for debugging @Test public void testSingleRuleMisses() { - int index = 10; - for (int i = 0; i < rules.length; i++) + var index = 10; + for (var i = 0; i < rules.length; i++) if ( index != i) assertEquals(0, captureTest(rules[index], lines[i]), rules[index].getName() + " hits on lines for " + rules[i].getName()); } @@ -75,7 +73,7 @@ private void evaluate(GCParseRule rule, String string, boolean dump) { assertNotNull(trace); if (dump) { LOGGER.fine("matches groups " + trace.groupCount()); - for (int i = 0; i <= trace.groupCount(); i++) { + for (var i = 0; i <= trace.groupCount(); i++) { LOGGER.fine(i + ": " + trace.getGroup(i)); } } diff --git a/parser/src/test/java/com/microsoft/gctoolkit/parser/GenerationalHeapParserRulesTest.java b/parser/src/test/java/com/microsoft/gctoolkit/parser/GenerationalHeapParserRulesTest.java index ce3146da..2428a687 100644 --- a/parser/src/test/java/com/microsoft/gctoolkit/parser/GenerationalHeapParserRulesTest.java +++ b/parser/src/test/java/com/microsoft/gctoolkit/parser/GenerationalHeapParserRulesTest.java @@ -16,10 +16,10 @@ public class GenerationalHeapParserRulesTest implements SimplePatterns, SerialPa @Test public void testGenerationalRules() { assertEquals(rules.length,lines.length); - for (int i = 0; i < rules.length; i++) - for (int j = 0; j < lines.length; j++) { + for (var i = 0; i < rules.length; i++) + for (var j = 0; j < lines.length; j++) { assertTrue(lines[j].length > 0, "No lines to test for index " + j); - int captured = captureTest(rules[i], lines[j]); + var captured = captureTest(rules[i], lines[j]); if (i == j) { assertEquals(captured, lines[j].length, i + " failed to captured it's lines"); } else { @@ -32,7 +32,7 @@ public void testGenerationalRules() { // @Test public void testDebugGenerationalRules() { - int index = 4; + var index = 4; GCParseRule rule = rules[index]; //evaluate( rule, lines[index][0], debugging); evaluate(rule, lines[index][1], true); diff --git a/parser/src/test/java/com/microsoft/gctoolkit/parser/GenerationalHeapParserTest.java b/parser/src/test/java/com/microsoft/gctoolkit/parser/GenerationalHeapParserTest.java index 60638008..52f21b46 100644 --- a/parser/src/test/java/com/microsoft/gctoolkit/parser/GenerationalHeapParserTest.java +++ b/parser/src/test/java/com/microsoft/gctoolkit/parser/GenerationalHeapParserTest.java @@ -17,8 +17,6 @@ import com.microsoft.gctoolkit.event.generational.ParNew; import com.microsoft.gctoolkit.event.generational.SystemGC; import com.microsoft.gctoolkit.event.generational.YoungGC; -import com.microsoft.gctoolkit.event.jvm.JVMEvent; -import com.microsoft.gctoolkit.event.jvm.SurvivorRecord; import com.microsoft.gctoolkit.jvm.Diarizer; import com.microsoft.gctoolkit.parser.jvm.PreUnifiedDiarizer; import com.microsoft.gctoolkit.time.DateTimeStamp; @@ -26,8 +24,6 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -import java.util.List; - import static org.junit.jupiter.api.Assertions.*; public class GenerationalHeapParserTest extends ParserTest { @@ -57,10 +53,10 @@ public void canParseLFSFullGC() { ", 1.9094806 secs] [Times: user=1.91 sys=0.00, real=1.91 secs]" }; - List jvmEvents = feedParser(lines); + var jvmEvents = feedParser(lines); try { - FullGC fgc = (FullGC) jvmEvents.get(0); + var fgc = (FullGC) jvmEvents.getFirst(); Assertions.assertEquals(1.9094806d, fgc.getDuration()); Assertions.assertEquals(4063232, fgc.getHeap().getSizeAfterCollection()); } catch(Throwable t) { @@ -88,13 +84,13 @@ public void testConcurrentModeFailure() { GCLogParser.END_OF_DATA_SENTINEL }; - List jvmEvents = feedParser(lines); + var jvmEvents = feedParser(lines); try { - InitialMark initialMark = (InitialMark) jvmEvents.get(0); - ConcurrentMark concurrentMark = (ConcurrentMark) jvmEvents.get(1); - ConcurrentPreClean concurrentPreClean = (ConcurrentPreClean) jvmEvents.get(2); - AbortablePreClean abortablePreClean = (AbortablePreClean) jvmEvents.get(3); + var initialMark = (InitialMark) jvmEvents.getFirst(); + var concurrentMark = (ConcurrentMark) jvmEvents.get(1); + var concurrentPreClean = (ConcurrentPreClean) jvmEvents.get(2); + var abortablePreClean = (AbortablePreClean) jvmEvents.get(3); } catch (ClassCastException cce) { fail(cce.getMessage()); } @@ -118,16 +114,16 @@ public void testReferenceProcessingInConcurrentCycle() { "2016-04-01T15:03:48.139-0700: 11031.605: [CMS-concurrent-reset: 0.027/0.027 secs] [Times: user=0.02 sys=0.00, real=0.03 secs]" }; - List jvmEvents = feedParser(lines); + var jvmEvents = feedParser(lines); try { - InitialMark initialMark = (InitialMark) jvmEvents.get(0); - ConcurrentMark concurrentMark = (ConcurrentMark) jvmEvents.get(1); - ConcurrentPreClean concurrentPreClean = (ConcurrentPreClean) jvmEvents.get(2); - AbortablePreClean abortablePreClean = (AbortablePreClean) jvmEvents.get(3); - CMSRemark remark = (CMSRemark) jvmEvents.get(4); - ConcurrentSweep sweep = (ConcurrentSweep) jvmEvents.get(5); - ConcurrentReset reset = (ConcurrentReset) jvmEvents.get(6); + var initialMark = (InitialMark) jvmEvents.getFirst(); + var concurrentMark = (ConcurrentMark) jvmEvents.get(1); + var concurrentPreClean = (ConcurrentPreClean) jvmEvents.get(2); + var abortablePreClean = (AbortablePreClean) jvmEvents.get(3); + var remark = (CMSRemark) jvmEvents.get(4); + var sweep = (ConcurrentSweep) jvmEvents.get(5); + var reset = (ConcurrentReset) jvmEvents.get(6); } catch (ClassCastException cce) { fail(cce.getMessage()); } @@ -157,10 +153,10 @@ public void testThat2CMFDoNotHappen() { {InitialMark.class, ConcurrentMark.class, ConcurrentModeFailure.class} }; - for (int i = 0; i < lines.length; i++) { - List jvmEvents = feedParser(lines[i]); + for (var i = 0; i < lines.length; i++) { + var jvmEvents = feedParser(lines[i]); - for (int j = 0; j < eventTypes[i].length; j++) { + for (var j = 0; j < eventTypes[i].length; j++) { assertEquals(jvmEvents.get(j).getClass(), eventTypes[i][j]); } jvmEvents.clear(); @@ -196,7 +192,7 @@ public void basicLogTest() { "84.129: [GC 39935K->23835K(2095040K), 0.0203206 secs" }; - List jvmEvents = feedParser(lines); + var jvmEvents = feedParser(lines); assertEquals(24, jvmEvents.size()); assertEquals(9.089,getParser().diary.getTimeOfFirstEvent().toSeconds()); } @@ -215,7 +211,7 @@ public void parallelYoungGenTest() { "132380.027: [Full GC [PSYoungGen: 388637K->0K(581376K)] [PSOldGen: 1707204K->1099190K(1708032K)] 2095842K->1099190K(2289408K) [PSPermGen: 103975K->103975K(122880K)], 25.3055946 secs]" }; - List jvmEvents = feedParser(lines); + var jvmEvents = feedParser(lines); assertEquals(7, jvmEvents.size()); assertEquals(103.387, getParser().diary.getTimeOfFirstEvent().toSeconds()); } @@ -228,12 +224,12 @@ public void psYoungNoDetailsTest() { "13.563: [GC (Allocation Failure) 886080K->31608K(1986432K), 0.0392109 secs]", }; - List jvmEvents = feedParser(lines); + var jvmEvents = feedParser(lines); assertEquals(1, jvmEvents.size()); - assertTrue(jvmEvents.get(0) instanceof PSYoungGen); + assertTrue(jvmEvents.getFirst() instanceof PSYoungGen); - PSYoungGen evt = (PSYoungGen) jvmEvents.get(0); + var evt = (PSYoungGen) jvmEvents.getFirst(); assertMemoryPoolValues(evt.getHeap(), 886080, 1986432, 31608, 1986432); } @@ -250,28 +246,28 @@ void testGenerationalNoDetailsLines() { "25293.283: [GC 2548071K(3028408K), 0.0743383 secs]" }; - int expectedEventCount = 3; + var expectedEventCount = 3; - List jvmEvents = feedParser(lines); + var jvmEvents = feedParser(lines); assertEquals(jvmEvents.size(), expectedEventCount); // 0 - YoungGC - assertTrue(jvmEvents.get(0) instanceof YoungGC); - YoungGC evt0 = ((YoungGC) jvmEvents.get(0)); + assertTrue(jvmEvents.getFirst() instanceof YoungGC); + var evt0 = (YoungGC) jvmEvents.getFirst(); assertEquals(evt0.getDateTimeStamp(), new DateTimeStamp(75.240)); assertMemoryPoolValues(evt0.getHeap(), 525312, 2013696, 16552, 2013696); assertDoubleEquals(evt0.getDuration(), 0.1105640); // 1 - FullGC assertTrue(jvmEvents.get(1) instanceof FullGC); - FullGC evt1 = ((FullGC) jvmEvents.get(1)); + var evt1 = (FullGC) jvmEvents.get(1); assertEquals(evt1.getDateTimeStamp(), new DateTimeStamp(8357.379)); assertMemoryPoolValues(evt1.getHeap(), 1379524, 2787392, 1236761, 2787392); assertDoubleEquals(evt1.getDuration(), 43.3665438); // 2 - InitialMark assertTrue(jvmEvents.get(2) instanceof InitialMark); - InitialMark evt2 = ((InitialMark) jvmEvents.get(2)); + var evt2 = (InitialMark) jvmEvents.get(2); assertEquals(evt2.getDateTimeStamp(), new DateTimeStamp(25293.283)); assertMemoryPoolValues(evt2.getHeap(), 2548071, 3028408, 2548071, 3028408); assertDoubleEquals(evt2.getDuration(), 0.0743383); @@ -288,21 +284,21 @@ void testCMSGenerationalNoDetailsLines() { //"15.423: [GC (CMS Final Remark) 168951K(1986432K), 0.0388223 secs]" }; - int expectedEventCount = 2; + var expectedEventCount = 2; - List jvmEvents = feedParser(lines); + var jvmEvents = feedParser(lines); assertEquals(jvmEvents.size(), expectedEventCount); // 0 - PSYoungGen - assertTrue(jvmEvents.get(0) instanceof PSYoungGen); - PSYoungGen evt0 = ((PSYoungGen) jvmEvents.get(0)); + assertTrue(jvmEvents.getFirst() instanceof PSYoungGen); + var evt0 = (PSYoungGen) jvmEvents.getFirst(); assertEquals(evt0.getDateTimeStamp(), new DateTimeStamp(13.563)); assertMemoryPoolValues(evt0.getHeap(), 886080, 1986432, 31608, 1986432); assertDoubleEquals(evt0.getDuration(), 0.0392109); // 1 - PSFullGC assertTrue(jvmEvents.get(1) instanceof FullGC); - FullGC evt1 = ((FullGC) jvmEvents.get(1)); + var evt1 = (FullGC) jvmEvents.get(1); assertEquals(evt1.getDateTimeStamp(), new DateTimeStamp(23.331)); assertMemoryPoolValues(evt1.getHeap(), 17386, 415232, 16928, 415232); assertDoubleEquals(evt1.getDuration(), 0.0498462); @@ -330,14 +326,14 @@ void testGenerationalDetailsLines() { "2021-12-17T14:58:05.098+0000: 5002.059: [Full GC (Ergonomics) [PSYoungGen: 60759K->0K(414208K)] [ParOldGen: 974100K->1024865K(1086976K)] 1034860K->1024865K(1501184K), [Metaspace: 154915K->154915K(1187840K)], 0.7945447 secs] [Times: user=0.68 sys=0.06, real=0.79 secs] " }; - int expectedEventCount = 6; + var expectedEventCount = 6; - List jvmEvents = feedParser(lines); + var jvmEvents = feedParser(lines); assertEquals(jvmEvents.size(), expectedEventCount); // 0 - PSFullGC - assertTrue(jvmEvents.get(0) instanceof PSFullGC); - PSFullGC evt0 = ((PSFullGC) jvmEvents.get(0)); + assertTrue(jvmEvents.getFirst() instanceof PSFullGC); + var evt0 = (PSFullGC) jvmEvents.getFirst(); assertEquals(evt0.getDateTimeStamp(), new DateTimeStamp("2021-12-17T13:34:54.484+0000", 11.445)); assertEquals(evt0.getGCCause(), GCCause.METADATA_GENERATION_THRESHOLD); // Memory Pools @@ -350,7 +346,7 @@ void testGenerationalDetailsLines() { // 1 - PSYoungGen assertTrue(jvmEvents.get(1) instanceof PSYoungGen); - PSYoungGen evt1 = ((PSYoungGen) jvmEvents.get(1)); + var evt1 = (PSYoungGen) jvmEvents.get(1); assertEquals(evt1.getDateTimeStamp(), new DateTimeStamp("2021-12-17T13:35:02.874+0000", 19.835)); assertEquals(evt1.getGCCause(), GCCause.METADATA_GENERATION_THRESHOLD); // Memory Pools @@ -361,7 +357,7 @@ void testGenerationalDetailsLines() { // 2 - PSYoungGen assertTrue(jvmEvents.get(2) instanceof PSYoungGen); - PSYoungGen evt2 = ((PSYoungGen) jvmEvents.get(2)); + var evt2 = (PSYoungGen) jvmEvents.get(2); assertEquals(evt2.getDateTimeStamp(), new DateTimeStamp("2021-12-17T13:35:24.328+0000", 41.289)); assertEquals(evt2.getGCCause(), GCCause.ALLOCATION_FAILURE); // Memory Pools @@ -372,7 +368,7 @@ void testGenerationalDetailsLines() { // 3 - PSYoungGen (SystemGC) assertTrue(jvmEvents.get(3) instanceof PSYoungGen); - PSYoungGen evt3 = ((PSYoungGen) jvmEvents.get(3)); + var evt3 = (PSYoungGen) jvmEvents.get(3); assertEquals(evt3.getDateTimeStamp(), new DateTimeStamp("2021-12-17T13:36:02.418+0000", 79.379)); assertEquals(evt3.getGCCause(), GCCause.JAVA_LANG_SYSTEM); // Memory Pools @@ -383,7 +379,7 @@ void testGenerationalDetailsLines() { // 4 - PSFullGC (SystemGC) assertTrue(jvmEvents.get(4) instanceof SystemGC); - SystemGC evt4 = ((SystemGC) jvmEvents.get(4)); + var evt4 = (SystemGC) jvmEvents.get(4); assertEquals(evt4.getDateTimeStamp(), new DateTimeStamp("2021-12-17T13:36:02.583+0000", 79.544)); assertEquals(evt4.getGCCause(), GCCause.JAVA_LANG_SYSTEM); // Memory Pools @@ -396,7 +392,7 @@ void testGenerationalDetailsLines() { // 5 - PSFullGC (Ergonomics) assertTrue(jvmEvents.get(5) instanceof PSFullGC); - PSFullGC evt5 = ((PSFullGC) jvmEvents.get(5)); + var evt5 = (PSFullGC) jvmEvents.get(5); assertEquals(evt5.getDateTimeStamp(), new DateTimeStamp("2021-12-17T14:58:05.098+0000", 5002.059)); assertEquals(evt5.getGCCause(), GCCause.ADAPTIVE_SIZE_POLICY); // Memory Pools diff --git a/parser/src/test/java/com/microsoft/gctoolkit/parser/GenerationalZGCParserTest.java b/parser/src/test/java/com/microsoft/gctoolkit/parser/GenerationalZGCParserTest.java index 9d036b8d..e53322a7 100644 --- a/parser/src/test/java/com/microsoft/gctoolkit/parser/GenerationalZGCParserTest.java +++ b/parser/src/test/java/com/microsoft/gctoolkit/parser/GenerationalZGCParserTest.java @@ -3,17 +3,13 @@ package com.microsoft.gctoolkit.parser; import com.microsoft.gctoolkit.event.GarbageCollectionTypes; -import com.microsoft.gctoolkit.event.jvm.JVMEvent; import com.microsoft.gctoolkit.event.zgc.*; import com.microsoft.gctoolkit.jvm.Diarizer; import com.microsoft.gctoolkit.parser.jvm.UnifiedDiarizer; import com.microsoft.gctoolkit.time.DateTimeStamp; import org.junit.jupiter.api.Test; -import java.util.List; - import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; @@ -25,6 +21,7 @@ protected Diarizer diarizer() { return new UnifiedDiarizer(); } + @Override protected GCLogParser parser() { return new ZGCParser(); } @@ -123,11 +120,11 @@ public void testZgcMajorCycle() { }; - List singleYoungSingleOld = feedParser(eventLogEntries); + var singleYoungSingleOld = feedParser(eventLogEntries); try { assertEquals(2, singleYoungSingleOld.size()); - ZGCYoungCollection young = (ZGCYoungCollection) singleYoungSingleOld.get(0); + var young = (ZGCYoungCollection) singleYoungSingleOld.getFirst(); assertEquals(young.getGcId(), 1L); assertEquals(toInt(0.075d, 1000), toInt(young.getDuration(),1000)); @@ -183,7 +180,7 @@ public void testZgcMajorCycle() { assertTrue(checkPageSummary(young.getLargePageSummary(), 1,0,0,8,0,0)); assertEquals(2, young.getAgeTableSummary().size()); - assertTrue(checkPageAgeSummary(young.getAgeTableSummary().get(0), "Eden", 8, 0, 223, 1, 100, 78, 1, 0, 0,0)); + assertTrue(checkPageAgeSummary(young.getAgeTableSummary().getFirst(), "Eden", 8, 0, 223, 1, 100, 78, 1, 0, 0,0)); assertTrue(checkPageAgeSummary(young.getAgeTableSummary().get(1), "Survivor 1", 16, 0 , 47, 0, 12, 7, 1, 0, 1, 0)); assertEquals(3 * 1024, young.getForwardingUsage()); @@ -204,7 +201,7 @@ public void testZgcMajorCycle() { /* * Old Phase Checks */ - ZGCOldCollection old = (ZGCOldCollection) singleYoungSingleOld.get(1); + var old = (ZGCOldCollection) singleYoungSingleOld.get(1); assertEquals(old.getGcId(), 1L); assertEquals(toInt(0.029d, 1000), toInt(old.getDuration(),1000)); @@ -335,10 +332,10 @@ public void testZgcMinorCycle() { }; - List singleCycle = feedParser(eventLogEntries); + var singleCycle = feedParser(eventLogEntries); try { assertEquals(1, singleCycle.size()); - ZGCYoungCollection young = (ZGCYoungCollection) singleCycle.get(0); + var young = (ZGCYoungCollection) singleCycle.getFirst(); assertEquals(young.getGcId(), 7L); @@ -394,7 +391,7 @@ public void testZgcMinorCycle() { assertEquals(36 * 1024, young.getForwardingUsage()); assertEquals(3, young.getAgeTableSummary().size()); - assertTrue(checkPageAgeSummary(young.getAgeTableSummary().get(0), "Eden", 79, 0 , 13800, 37, 6940, 5622, 0, 0, 0, 0)); + assertTrue(checkPageAgeSummary(young.getAgeTableSummary().getFirst(), "Eden", 79, 0 , 13800, 37, 6940, 5622, 0, 0, 0, 0)); assertTrue(checkPageAgeSummary(young.getAgeTableSummary().get(1), "Survivor 1", 25, 0, 132, 0, 79, 61, 0, 0, 0, 0)); assertTrue(checkPageAgeSummary(young.getAgeTableSummary().get(2), "Survivor 2", 15, 0, 78, 0, 47, 37, 0, 0, 0, 0)); @@ -612,23 +609,23 @@ public void testMultipleConcurrentCycles() { "[2024-11-19T09:48:57.431-0600][info ][gc,phases ] GC(3) O: Old Generation 13310M(81%)->15900M(97%) 9.540s", "[2024-11-19T09:48:57.431-0600][info ][gc ] GC(3) Major Collection (Warmup) 8960M(55%)->13184M(80%) 14.923s", }; - List events = feedParser(eventLogEntries); + var events = feedParser(eventLogEntries); assertEquals(4, events.size()); - ZGCYoungCollection majorYoung = (ZGCYoungCollection) events.get(0); + var majorYoung = (ZGCYoungCollection) events.getFirst(); assertEquals(3L, majorYoung.getGcId()); assertEquals(GarbageCollectionTypes.ZGCMajorYoung, majorYoung.getGarbageCollectionType()); - ZGCYoungCollection minorYoungA = (ZGCYoungCollection) events.get(1); + var minorYoungA = (ZGCYoungCollection) events.get(1); assertEquals(4L, minorYoungA.getGcId()); assertEquals(GarbageCollectionTypes.ZGCMinorYoung, minorYoungA.getGarbageCollectionType()); - ZGCYoungCollection minorYoungB = (ZGCYoungCollection) events.get(2); + var minorYoungB = (ZGCYoungCollection) events.get(2); assertEquals(5L, minorYoungB.getGcId()); assertEquals(GarbageCollectionTypes.ZGCMinorYoung, minorYoungB.getGarbageCollectionType()); - ZGCOldCollection majorOld = (ZGCOldCollection) events.get(3); + var majorOld = (ZGCOldCollection) events.get(3); assertEquals(3L, majorOld.getGcId()); assertEquals(GarbageCollectionTypes.ZGCMajorOld, majorOld.getGarbageCollectionType()); diff --git a/parser/src/test/java/com/microsoft/gctoolkit/parser/IncrementialConcurrentMarkSweepParserRulesTest.java b/parser/src/test/java/com/microsoft/gctoolkit/parser/IncrementialConcurrentMarkSweepParserRulesTest.java index 55ed526d..3f09313d 100644 --- a/parser/src/test/java/com/microsoft/gctoolkit/parser/IncrementialConcurrentMarkSweepParserRulesTest.java +++ b/parser/src/test/java/com/microsoft/gctoolkit/parser/IncrementialConcurrentMarkSweepParserRulesTest.java @@ -37,9 +37,9 @@ public class IncrementialConcurrentMarkSweepParserRulesTest implements ICMSPatte @Test public void testiCMSParseRules() { - for (int i = 0; i < rules.length; i++) - for (int j = 0; j < lines.length; j++) { - for (int k = 0; k < lines[j].length; k++) { + for (var i = 0; i < rules.length; i++) + for (var j = 0; j < lines.length; j++) { + for (var k = 0; k < lines[j].length; k++) { GCLogTrace trace = rules[i].parse(lines[j][k]); if (trace != null) { assertEquals(i, j, "rule @" + i + " matched record @" + j + ":" + k); @@ -56,7 +56,7 @@ private void evaluate(GCParseRule rule, String string, boolean debugging) { assertNotNull(trace); if (debugging) { LOGGER.fine("matches groups " + trace.groupCount()); - for (int i = 0; i <= trace.groupCount(); i++) { + for (var i = 0; i <= trace.groupCount(); i++) { LOGGER.fine(i + ": " + trace.getGroup(i)); } } diff --git a/parser/src/test/java/com/microsoft/gctoolkit/parser/ParallelParserRulesTest.java b/parser/src/test/java/com/microsoft/gctoolkit/parser/ParallelParserRulesTest.java index 43bef54e..a6718108 100644 --- a/parser/src/test/java/com/microsoft/gctoolkit/parser/ParallelParserRulesTest.java +++ b/parser/src/test/java/com/microsoft/gctoolkit/parser/ParallelParserRulesTest.java @@ -16,9 +16,9 @@ public class ParallelParserRulesTest implements ParallelPatterns { @Test public void testParallelParseRules() { - for (int i = 0; i < rules.length; i++) - for (int j = 0; j < lines.length; j++) { - int captured = captureTest(rules[i], lines[j]); + for (var i = 0; i < rules.length; i++) + for (var j = 0; j < lines.length; j++) { + var captured = captureTest(rules[i], lines[j]); if (i == j) { assertEquals(captured, lines[j].length, i + " failed to captured it's lines"); } else { @@ -31,7 +31,7 @@ public void testParallelParseRules() { // @Test public void testDebugParallelParseRules() { - int index = 4; + var index = 4; GCParseRule rule = rules[index]; //evaluate( rule, lines[index][0], debugging); evaluate(rule, lines[index][1], true); diff --git a/parser/src/test/java/com/microsoft/gctoolkit/parser/ParserTest.java b/parser/src/test/java/com/microsoft/gctoolkit/parser/ParserTest.java index 34d1bd8f..b853afad 100644 --- a/parser/src/test/java/com/microsoft/gctoolkit/parser/ParserTest.java +++ b/parser/src/test/java/com/microsoft/gctoolkit/parser/ParserTest.java @@ -35,28 +35,22 @@ public void setUp() { parser.publishTo(channel); } - /** - * The test provides an instance of a Diarizer appropriate to the gc log or lines being parsed. - * @return A Diarizer appropriate to the gc log or lines being parsed - */ + /// The test provides an instance of a Diarizer appropriate to the gc log or lines being parsed. + /// @return A Diarizer appropriate to the gc log or lines being parsed protected abstract Diarizer diarizer(); - /** - * The test provides an instance of a GCLogParser appropriate to the gc log or lines being parsed. - * @return A GCLogParser appropriate to the gc log or lines being parsed - */ + /// The test provides an instance of a GCLogParser appropriate to the gc log or lines being parsed. + /// @return A GCLogParser appropriate to the gc log or lines being parsed protected abstract GCLogParser parser(); GCLogParser getParser() { return this.parser; } - /** - * Parser runs in its own thread so start one for it and then feed it the lines to be parsed - * - * @param lines The GC log lines to be fed to the parser. - * @return The list of JVMEvents from the parsed lines. - */ + /// Parser runs in its own thread so start one for it and then feed it the lines to be parsed + /// + /// @param lines The GC log lines to be fed to the parser. + /// @return The list of JVMEvents from the parsed lines. protected List feedParser(String[] lines) { Arrays.stream(lines).forEach(diarizer::diarize); parser.diary(diarizer.getDiary()); @@ -64,15 +58,13 @@ protected List feedParser(String[] lines) { return channel.events(); } - /** - * Common check for all GC events that report on memory. - * - * @param summary - * @param occupancyAtStartOfCollection - * @param sizeAtStartOfCollection - * @param occupancyAfterCollection - * @param sizeAfterCollection - */ + /// Common check for all GC events that report on memory. + /// + /// @param summary + /// @param occupancyAtStartOfCollection + /// @param sizeAtStartOfCollection + /// @param occupancyAfterCollection + /// @param sizeAfterCollection protected void assertMemoryPoolValues(MemoryPoolSummary summary, long occupancyAtStartOfCollection, long sizeAtStartOfCollection, long occupancyAfterCollection, long sizeAfterCollection) { assertEquals(summary.getOccupancyBeforeCollection(), occupancyAtStartOfCollection); assertEquals(summary.getSizeBeforeCollection(), sizeAtStartOfCollection); @@ -80,28 +72,24 @@ protected void assertMemoryPoolValues(MemoryPoolSummary summary, long occupancyA assertEquals(summary.getSizeAfterCollection(), sizeAfterCollection); } - /** - * Common check for GC events that report on Survivor memory. - * - * @param summary - * @param occupancyAtStartOfCollection - * @param sizeAtStartOfCollection - * @param occupancyAfterCollection - * @param sizeAfterCollection - */ + /// Common check for GC events that report on Survivor memory. + /// + /// @param summary + /// @param occupancyAtStartOfCollection + /// @param sizeAtStartOfCollection + /// @param occupancyAfterCollection + /// @param sizeAfterCollection protected void assertSurvivorMemoryPoolValues(SurvivorMemoryPoolSummary summary, long occupancyAtStartOfCollection, long occupancyAfterCollection) { assertEquals(summary.getOccupancyBeforeCollection(), occupancyAtStartOfCollection); assertEquals(summary.getOccupancyAfterCollection(), occupancyAfterCollection); } - /** - * Common check for GC events that report on CPU usage - * - * @param summary - * @param user - * @param sys (kernel) - * @param real (wallClock) - */ + /// Common check for GC events that report on CPU usage + /// + /// @param summary + /// @param user + /// @param sys (kernel) + /// @param real (wallClock) protected void assertCPUSummaryValues(CPUSummary summary, double user, double sys, double real) { assertNotNull(summary); assertDoubleEquals(summary.getUser(), user); @@ -109,25 +97,21 @@ protected void assertCPUSummaryValues(CPUSummary summary, double user, double sy assertDoubleEquals(summary.getWallClock(), real); } - /** - * Compare doubles using a default epsilon value of 0.0000001, which should be - * sufficient for most duration representations. - * - * @param d1 - * @param d2 - */ + /// Compare doubles using a default epsilon value of 0.0000001, which should be + /// sufficient for most duration representations. + /// + /// @param d1 + /// @param d2 protected void assertDoubleEquals(double d1, double d2) { - double defaultEpsilon = 0.0000001d; + var defaultEpsilon = 0.0000001d; assertDoubleEquals(d1, d2, defaultEpsilon); } - /** - * Compare doubles without worrying about binary representation discrepancies - * - * @param d1 - * @param d2 - * @param epsilon - */ + /// Compare doubles without worrying about binary representation discrepancies + /// + /// @param d1 + /// @param d2 + /// @param epsilon protected void assertDoubleEquals(double d1, double d2, double epsilon) { assertTrue(Math.abs(d1-d2) < epsilon); } @@ -147,9 +131,7 @@ public void publish(ChannelName channel, JVMEvent message) { events.add(message); } - /** - * Unfortunately needs to be implemented but doesn't need to do anything - */ + /// Unfortunately needs to be implemented but doesn't need to do anything @Override public void close() { diff --git a/parser/src/test/java/com/microsoft/gctoolkit/parser/PreUnifiedCMSTenuredParserTest.java b/parser/src/test/java/com/microsoft/gctoolkit/parser/PreUnifiedCMSTenuredParserTest.java index 0f5d6142..09769e79 100644 --- a/parser/src/test/java/com/microsoft/gctoolkit/parser/PreUnifiedCMSTenuredParserTest.java +++ b/parser/src/test/java/com/microsoft/gctoolkit/parser/PreUnifiedCMSTenuredParserTest.java @@ -10,18 +10,16 @@ import com.microsoft.gctoolkit.event.generational.ConcurrentReset; import com.microsoft.gctoolkit.event.generational.ConcurrentSweep; import com.microsoft.gctoolkit.event.generational.InitialMark; -import com.microsoft.gctoolkit.event.jvm.JVMEvent; import com.microsoft.gctoolkit.jvm.Diarizer; import com.microsoft.gctoolkit.parser.jvm.PreUnifiedDiarizer; import org.junit.jupiter.api.Test; -import java.util.List; - import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; public class PreUnifiedCMSTenuredParserTest extends ParserTest { - + + @Override protected Diarizer diarizer() { return new PreUnifiedDiarizer(); } @@ -51,13 +49,13 @@ public void testConcurrentModeFailure() { GCLogParser.END_OF_DATA_SENTINEL }; - List jvmEvents = feedParser(lines); + var jvmEvents = feedParser(lines); try { - InitialMark initialMark = (InitialMark) jvmEvents.get(0); - ConcurrentMark concurrentMark = (ConcurrentMark) jvmEvents.get(1); - ConcurrentPreClean concurrentPreClean = (ConcurrentPreClean) jvmEvents.get(2); - AbortablePreClean abortablePreClean = (AbortablePreClean) jvmEvents.get(3); + var initialMark = (InitialMark) jvmEvents.getFirst(); + var concurrentMark = (ConcurrentMark) jvmEvents.get(1); + var concurrentPreClean = (ConcurrentPreClean) jvmEvents.get(2); + var abortablePreClean = (AbortablePreClean) jvmEvents.get(3); } catch (ClassCastException cce) { fail(cce.getMessage()); } @@ -82,16 +80,16 @@ public void test70_40CMSDetailsCause() { GCLogParser.END_OF_DATA_SENTINEL }; - List jvmEvents = feedParser(lines); + var jvmEvents = feedParser(lines); try { - InitialMark initialMark = (InitialMark) jvmEvents.get(0); - ConcurrentMark concurrentMark = (ConcurrentMark) jvmEvents.get(1); - ConcurrentPreClean concurrentPreClean = (ConcurrentPreClean) jvmEvents.get(2); - AbortablePreClean abortablePreClean = (AbortablePreClean) jvmEvents.get(3); - CMSRemark cmsRemark = (CMSRemark) jvmEvents.get(4); - ConcurrentSweep concurrentSweep = (ConcurrentSweep) jvmEvents.get(5); - ConcurrentReset concurrentReset = (ConcurrentReset) jvmEvents.get(6); + var initialMark = (InitialMark) jvmEvents.getFirst(); + var concurrentMark = (ConcurrentMark) jvmEvents.get(1); + var concurrentPreClean = (ConcurrentPreClean) jvmEvents.get(2); + var abortablePreClean = (AbortablePreClean) jvmEvents.get(3); + var cmsRemark = (CMSRemark) jvmEvents.get(4); + var concurrentSweep = (ConcurrentSweep) jvmEvents.get(5); + var concurrentReset = (ConcurrentReset) jvmEvents.get(6); } catch (ClassCastException cce) { fail(cce.getMessage()); } @@ -118,16 +116,16 @@ public void test70CMSDetailsNoCauseDateStamps() { GCLogParser.END_OF_DATA_SENTINEL }; - List jvmEvents = feedParser(lines); + var jvmEvents = feedParser(lines); try { - InitialMark initialMark = (InitialMark) jvmEvents.get(0); - ConcurrentMark concurrentMark = (ConcurrentMark) jvmEvents.get(1); - ConcurrentPreClean concurrentPreClean = (ConcurrentPreClean) jvmEvents.get(2); - AbortablePreClean abortablePreClean = (AbortablePreClean) jvmEvents.get(3); - CMSRemark cmsRemark = (CMSRemark) jvmEvents.get(4); - ConcurrentSweep concurrentSweep = (ConcurrentSweep) jvmEvents.get(5); - ConcurrentReset concurrentReset = (ConcurrentReset) jvmEvents.get(6); + var initialMark = (InitialMark) jvmEvents.getFirst(); + var concurrentMark = (ConcurrentMark) jvmEvents.get(1); + var concurrentPreClean = (ConcurrentPreClean) jvmEvents.get(2); + var abortablePreClean = (AbortablePreClean) jvmEvents.get(3); + var cmsRemark = (CMSRemark) jvmEvents.get(4); + var concurrentSweep = (ConcurrentSweep) jvmEvents.get(5); + var concurrentReset = (ConcurrentReset) jvmEvents.get(6); } catch (ClassCastException cce) { fail(cce.getMessage()); } @@ -160,12 +158,12 @@ public void testPreCleanReferenceWithParNew() { "2020-03-27T17:40:46.829+0000: 62609.842: [CMS-concurrent-abortable-preclean: 2.855/3.180 secs] [Times: user=25.14 sys=1.51, real=3.18 secs] " }; - List jvmEvents = feedParser(lines); + var jvmEvents = feedParser(lines); try { - ConcurrentMark concurrentMark = (ConcurrentMark) jvmEvents.get(0); - ConcurrentPreClean concurrentPreClean = (ConcurrentPreClean) jvmEvents.get(1); - AbortablePreClean abortablePreClean = (AbortablePreClean) jvmEvents.get(2); + var concurrentMark = (ConcurrentMark) jvmEvents.getFirst(); + var concurrentPreClean = (ConcurrentPreClean) jvmEvents.get(1); + var abortablePreClean = (AbortablePreClean) jvmEvents.get(2); } catch (ClassCastException cce) { fail(cce.getMessage()); } diff --git a/parser/src/test/java/com/microsoft/gctoolkit/parser/PreUnifiedG1GCParserTest.java b/parser/src/test/java/com/microsoft/gctoolkit/parser/PreUnifiedG1GCParserTest.java index d7f6df56..7d03bb30 100644 --- a/parser/src/test/java/com/microsoft/gctoolkit/parser/PreUnifiedG1GCParserTest.java +++ b/parser/src/test/java/com/microsoft/gctoolkit/parser/PreUnifiedG1GCParserTest.java @@ -3,8 +3,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; -import java.util.List; - import org.junit.jupiter.api.Test; import com.microsoft.gctoolkit.event.GCCause; @@ -16,7 +14,6 @@ import com.microsoft.gctoolkit.event.g1gc.G1Remark; import com.microsoft.gctoolkit.event.g1gc.G1Young; import com.microsoft.gctoolkit.event.g1gc.G1YoungInitialMark; -import com.microsoft.gctoolkit.event.jvm.JVMEvent; import com.microsoft.gctoolkit.jvm.Diarizer; import com.microsoft.gctoolkit.parser.jvm.PreUnifiedDiarizer; import com.microsoft.gctoolkit.time.DateTimeStamp; @@ -25,20 +22,18 @@ public class PreUnifiedG1GCParserTest extends ParserTest { protected long M = 1024; protected long G = 1024*1024; - + + @Override protected Diarizer diarizer() { return new PreUnifiedDiarizer(); - }; + } + @Override protected GCLogParser parser() { return new PreUnifiedG1GCParser(); - }; - - /** - * jlittle-ptc: Collection of different pre-unified events found in a log generated without -XX:+PrintGCDetails enabled. - * - * Tests to ensure all events are parsed correctly. - */ + }/// jlittle-ptc: Collection of different pre-unified events found in a log generated without -XX:+PrintGCDetails enabled. +/// +/// Tests to ensure all events are parsed correctly. @Test void testPreUnifiedG1GCLinesNoDetails() { String[] lines = { @@ -75,14 +70,14 @@ void testPreUnifiedG1GCLinesNoDetails() { }; - int expectedEventCount = 8; + var expectedEventCount = 8; - List jvmEvents = feedParser(lines); + var jvmEvents = feedParser(lines); assertEquals(jvmEvents.size(), expectedEventCount); // 0 - G1Young - assertTrue(jvmEvents.get(0) instanceof G1Young); - G1Young evt0 = ((G1Young) jvmEvents.get(0)); + assertTrue(jvmEvents.getFirst() instanceof G1Young); + var evt0 = (G1Young) jvmEvents.getFirst(); assertEquals(evt0.getDateTimeStamp(), new DateTimeStamp(1.303)); assertEquals(evt0.getGCCause(), GCCause.G1_EVACUATION_PAUSE); assertMemoryPoolValues(evt0.getHeap(), 57260, 1024*M, 14150, 1024*M); @@ -90,45 +85,45 @@ void testPreUnifiedG1GCLinesNoDetails() { // 1 - ConcurrentScanRootRegion - Duration/Timestamp only. assertTrue(jvmEvents.get(1) instanceof ConcurrentScanRootRegion); - ConcurrentScanRootRegion evt1 = ((ConcurrentScanRootRegion) jvmEvents.get(1)); + var evt1 = (ConcurrentScanRootRegion) jvmEvents.get(1); assertEquals(evt1.getDateTimeStamp(), new DateTimeStamp(1.496)); assertDoubleEquals(evt1.getDuration(), 0.0033801); // 2 - G1ConcurrentMark - Duration/Timestamp only assertTrue(jvmEvents.get(2) instanceof G1ConcurrentMark); - G1ConcurrentMark evt2 = ((G1ConcurrentMark) jvmEvents.get(2)); + var evt2 = (G1ConcurrentMark) jvmEvents.get(2); assertEquals(evt2.getDateTimeStamp(), new DateTimeStamp(1.499)); assertDoubleEquals(evt2.getDuration(), 0.0096200); // 3 - G1Remark - Duration/Timestamp only assertTrue(jvmEvents.get(3) instanceof G1Remark); - G1Remark evt3 = ((G1Remark) jvmEvents.get(3)); + var evt3 = (G1Remark) jvmEvents.get(3); assertEquals(evt3.getDateTimeStamp(), new DateTimeStamp(1.509)); assertDoubleEquals(evt3.getDuration(), 0.0045439); // 4 - G1Cleanup assertTrue(jvmEvents.get(4) instanceof G1Cleanup); - G1Cleanup evt4 = ((G1Cleanup) jvmEvents.get(4)); + var evt4 = (G1Cleanup) jvmEvents.get(4); assertEquals(evt4.getDateTimeStamp(), new DateTimeStamp(1.513)); assertMemoryPoolValues(evt4.getHeap(), 15686, 1024*M, 13638, 1024*M); assertDoubleEquals(evt4.getDuration(), 0.0014924); // 5 - G1ConcurrentCleanup - Duration/Timestamp only assertTrue(jvmEvents.get(5) instanceof G1ConcurrentCleanup); - G1ConcurrentCleanup evt5 = ((G1ConcurrentCleanup) jvmEvents.get(5)); + var evt5 = (G1ConcurrentCleanup) jvmEvents.get(5); assertEquals(evt5.getDateTimeStamp(), new DateTimeStamp(1.515)); assertDoubleEquals(evt5.getDuration(), 0.0000053); // 6 - G1Mixed assertTrue(jvmEvents.get(6) instanceof G1Mixed); - G1Mixed evt6 = ((G1Mixed) jvmEvents.get(6)); + var evt6 = (G1Mixed) jvmEvents.get(6); assertEquals(evt6.getDateTimeStamp(), new DateTimeStamp(24.383)); assertMemoryPoolValues(evt6.getHeap(), 269*M, 1149*M, 153*M, 1149*M); assertDoubleEquals(evt6.getDuration(), 0.0457592); // 7 - G1Mixed assertTrue(jvmEvents.get(7) instanceof G1Mixed); - G1Mixed evt7 = ((G1Mixed) jvmEvents.get(7)); + var evt7 = (G1Mixed) jvmEvents.get(7); assertEquals(evt7.getDateTimeStamp(), new DateTimeStamp(1566.108)); assertMemoryPoolValues(evt7.getHeap(), 7521, 13*M, 5701, 13*M); assertDoubleEquals(evt7.getDuration(), 0.0030090); @@ -172,14 +167,14 @@ void testG1DetailedEvacuationPauseEvent() { " [Times: user=0.27 sys=0.01, real=0.05 secs] " }; - int expectedEventCount = 1; + var expectedEventCount = 1; - List jvmEvents = feedParser(lines); + var jvmEvents = feedParser(lines); assertEquals(expectedEventCount, jvmEvents.size()); // 0 - G1Young - assertTrue(jvmEvents.get(0) instanceof G1Young); - G1Young evt0 = ((G1Young) jvmEvents.get(0)); + assertTrue(jvmEvents.getFirst() instanceof G1Young); + var evt0 = (G1Young) jvmEvents.getFirst(); assertEquals(evt0.getDateTimeStamp(), new DateTimeStamp("2025-03-23T03:46:46.582+0000", 27.619)); assertEquals(evt0.getGCCause(), GCCause.G1_EVACUATION_PAUSE); // Memory Pools @@ -222,14 +217,14 @@ void testG1DetailedYoungMetadataGCThresholdPauseEvent() { " [Times: user=0.07 sys=0.02, real=0.03 secs]" }; - int expectedEventCount = 1; + var expectedEventCount = 1; - List jvmEvents = feedParser(lines); + var jvmEvents = feedParser(lines); assertEquals(expectedEventCount, jvmEvents.size()); // 0 - G1YoungInitialMark - assertTrue(jvmEvents.get(0) instanceof G1YoungInitialMark); - G1YoungInitialMark evt0 = ((G1YoungInitialMark) jvmEvents.get(0)); + assertTrue(jvmEvents.getFirst() instanceof G1YoungInitialMark); + var evt0 = (G1YoungInitialMark) jvmEvents.getFirst(); assertEquals(evt0.getDateTimeStamp(), new DateTimeStamp("2025-03-23T03:46:27.139+0000", 8.176)); assertEquals(evt0.getGCCause(), GCCause.METADATA_GENERATION_THRESHOLD); // Memory Pools @@ -272,14 +267,14 @@ void testG1DetailedSystemGCYoung() { " [Times: user=0.03 sys=0.00, real=0.01 secs]" }; - int expectedEventCount = 1; + var expectedEventCount = 1; - List jvmEvents = feedParser(lines); + var jvmEvents = feedParser(lines); assertEquals(expectedEventCount, jvmEvents.size()); // 0 - G1YoungInitialMark - assertTrue(jvmEvents.get(0) instanceof G1YoungInitialMark); - G1YoungInitialMark evt0 = ((G1YoungInitialMark) jvmEvents.get(0)); + assertTrue(jvmEvents.getFirst() instanceof G1YoungInitialMark); + var evt0 = (G1YoungInitialMark) jvmEvents.getFirst(); assertEquals(evt0.getDateTimeStamp(), new DateTimeStamp("2025-04-18T20:35:53.067+0000", 2306974.104)); assertEquals(evt0.getGCCause(), GCCause.JAVA_LANG_SYSTEM); // Memory Pools @@ -322,14 +317,14 @@ void testG1DetailedGCLockerInitiatedPauseEvent() { " [Times: user=0.59 sys=0.05, real=0.13 secs] " }; - int expectedEventCount = 1; + var expectedEventCount = 1; - List jvmEvents = feedParser(lines); + var jvmEvents = feedParser(lines); assertEquals(expectedEventCount, jvmEvents.size()); // 0 - G1YoungInitialMark - assertTrue(jvmEvents.get(0) instanceof G1Young); - G1Young evt0 = ((G1Young) jvmEvents.get(0)); + assertTrue(jvmEvents.getFirst() instanceof G1Young); + var evt0 = (G1Young) jvmEvents.getFirst(); assertEquals(evt0.getDateTimeStamp(), new DateTimeStamp("2025-03-23T03:47:20.309+0000", 61.346)); assertEquals(evt0.getGCCause(), GCCause.GC_LOCKER); // Memory Pools @@ -372,14 +367,14 @@ void testG1DetailedMixedPauseEvent() { " [Times: user=0.27 sys=0.00, real=0.03 secs]" }; - int expectedEventCount = 1; + var expectedEventCount = 1; - List jvmEvents = feedParser(lines); + var jvmEvents = feedParser(lines); assertEquals(expectedEventCount, jvmEvents.size()); // 0 - G1Mixed - assertTrue(jvmEvents.get(0) instanceof G1Mixed); - G1Mixed evt0 = ((G1Mixed) jvmEvents.get(0)); + assertTrue(jvmEvents.getFirst() instanceof G1Mixed); + var evt0 = (G1Mixed) jvmEvents.getFirst(); assertEquals(evt0.getDateTimeStamp(), new DateTimeStamp(879630.318)); assertEquals(evt0.getGCCause(), GCCause.G1_EVACUATION_PAUSE); // Memory Pools diff --git a/parser/src/test/java/com/microsoft/gctoolkit/parser/PreUnifiedGenerationalParserTest.java b/parser/src/test/java/com/microsoft/gctoolkit/parser/PreUnifiedGenerationalParserTest.java index a7139019..f165eac3 100644 --- a/parser/src/test/java/com/microsoft/gctoolkit/parser/PreUnifiedGenerationalParserTest.java +++ b/parser/src/test/java/com/microsoft/gctoolkit/parser/PreUnifiedGenerationalParserTest.java @@ -17,14 +17,11 @@ import com.microsoft.gctoolkit.event.generational.ParNew; import com.microsoft.gctoolkit.event.generational.ParNewPromotionFailed; import com.microsoft.gctoolkit.event.generational.SystemGC; -import com.microsoft.gctoolkit.event.jvm.JVMEvent; import com.microsoft.gctoolkit.io.GCLogFile; import com.microsoft.gctoolkit.jvm.Diarizer; import com.microsoft.gctoolkit.parser.jvm.PreUnifiedDiarizer; import org.junit.jupiter.api.Test; -import java.util.List; - import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertSame; @@ -32,13 +29,15 @@ public class PreUnifiedGenerationalParserTest extends ParserTest { private static final String END_OF_DATA_SENTINEL = GCLogFile.END_OF_DATA_SENTINEL; + @Override protected Diarizer diarizer() { return new PreUnifiedDiarizer(); - }; + } + @Override protected GCLogParser parser() { return new GenerationalHeapParser(); - }; + } @Test public void testDefNewDetails() { @@ -48,9 +47,9 @@ public void testDefNewDetails() { END_OF_DATA_SENTINEL }; - List jvmEvents = feedParser(lines); + var jvmEvents = feedParser(lines); - DefNew defNew = (DefNew) jvmEvents.get(0); + var defNew = (DefNew) jvmEvents.getFirst(); // occupancy before(size before)->occupancy after(size) assertMemoryPoolValues(defNew.getHeap(), 502104, 2044800, 102148, 2044800); @@ -79,15 +78,15 @@ public void testParNewCMSWithDetailsTenuringAndSystemGC() { END_OF_DATA_SENTINEL }; - List jvmEvents = feedParser(lines); + var jvmEvents = feedParser(lines); - ParNew parNew = (ParNew) jvmEvents.get(0); + var parNew = (ParNew) jvmEvents.getFirst(); assertMemoryPoolValues(parNew.getHeap(), 16000, 81280, 1725, 81280); assertMemoryPoolValues(parNew.getYoung(), 16000, 18624, 1725, 18624); assertMemoryPoolValues(parNew.getTenured(), 0, 81280 - 18624, 0, 81280 - 18624); assertEquals(0.0167922, parNew.getDuration()); - SystemGC full = (SystemGC) jvmEvents.get(1); + var full = (SystemGC) jvmEvents.get(1); assertMemoryPoolValues(full.getHeap(), 4654, 81280, 1602, 81280); assertMemoryPoolValues(full.getYoung(), 4654, 81280 - 62656, 0, 81280 - 62656); assertMemoryPoolValues(full.getTenured(), 0, 81280 - 18624, 1602, 62656); @@ -121,13 +120,13 @@ public void testConcurrentModeFailure() { }; - List jvmEvents = feedParser(lines); + var jvmEvents = feedParser(lines); - InitialMark initialMark = (InitialMark) jvmEvents.get(0); + var initialMark = (InitialMark) jvmEvents.getFirst(); assertEquals(0.0008727d, initialMark.getDuration()); - ParNewPromotionFailed parNewPromotionFailed = (ParNewPromotionFailed) jvmEvents.get(4); + var parNewPromotionFailed = (ParNewPromotionFailed) jvmEvents.get(4); assertEquals(0.0023005d, parNewPromotionFailed.getDuration()); - ConcurrentModeFailure concurrentModeFailure = (ConcurrentModeFailure) jvmEvents.get(5); + var concurrentModeFailure = (ConcurrentModeFailure) jvmEvents.get(5); assertEquals(0.095695d, concurrentModeFailure.getDuration()); } @@ -141,16 +140,16 @@ public void test80ParallelGC() { END_OF_DATA_SENTINEL }; - List jvmEvents = feedParser(lines); + var jvmEvents = feedParser(lines); - PSYoungGen psYoungGen = (PSYoungGen) jvmEvents.get(0); + var psYoungGen = (PSYoungGen) jvmEvents.getFirst(); assertSame(psYoungGen.getGCCause(), GCCause.ALLOCATION_FAILURE); assertEquals(0.0485326, psYoungGen.getDuration()); assertMemoryPoolValues(psYoungGen.getHeap(), 610571, 819712, 581588, 819712); assertMemoryPoolValues(psYoungGen.getTenured(), 610571 - 232960, 819712 - 232960, 581588 - 116224, 819712 - 232960); assertMemoryPoolValues(psYoungGen.getYoung(), 232960, 232960, 116224, 232960); - FullGC fullGC = (FullGC) jvmEvents.get(1); + var fullGC = (FullGC) jvmEvents.get(1); assertSame(fullGC.getGCCause(), GCCause.ADAPTIVE_SIZE_POLICY); assertEquals(0.0449697, fullGC.getDuration()); // todo: value of heap size before collection is 808448 should be 819712. @@ -179,28 +178,28 @@ public void test70_40CMSDetailsCause() { END_OF_DATA_SENTINEL }; - List jvmEvents = feedParser(lines); + var jvmEvents = feedParser(lines); - ParNew parNew = (ParNew) jvmEvents.get(0); + var parNew = (ParNew) jvmEvents.getFirst(); assertSame(parNew.getGCCause(), GCCause.GC_LOCKER); assertMemoryPoolValues(parNew.getHeap(), 35230, 354944, 38078, 354944); assertMemoryPoolValues(parNew.getYoung(), 32671, 349568, 35386, 349568); assertMemoryPoolValues(parNew.getTenured(), 35230 - 32671, 354944 - 349568, 38078 - 35386, 354944 - 349568); assertEquals(0.0082790, parNew.getDuration()); - InitialMark initialMark = (InitialMark) jvmEvents.get(1); + var initialMark = (InitialMark) jvmEvents.get(1); assertEquals(0.014794d, initialMark.getDuration()); - ConcurrentMark concurrentPhase = (ConcurrentMark) jvmEvents.get(2); + var concurrentPhase = (ConcurrentMark) jvmEvents.get(2); assertEquals(0.005d, concurrentPhase.getDuration()); - ConcurrentPreClean preClean = (ConcurrentPreClean) jvmEvents.get(3); + var preClean = (ConcurrentPreClean) jvmEvents.get(3); assertEquals(0.0d, preClean.getDuration()); - AbortablePreClean abortablePreClean = (AbortablePreClean) jvmEvents.get(4); + var abortablePreClean = (AbortablePreClean) jvmEvents.get(4); assertEquals(0.349d, abortablePreClean.getDuration()); - CMSRemark cmsRemark = (CMSRemark) jvmEvents.get(5); + var cmsRemark = (CMSRemark) jvmEvents.get(5); assertEquals(0.069964d, cmsRemark.getDuration()); - ConcurrentSweep concurrentSweep = (ConcurrentSweep) jvmEvents.get(6); + var concurrentSweep = (ConcurrentSweep) jvmEvents.get(6); assertEquals(0.001d, concurrentSweep.getDuration()); - ConcurrentReset reset = (ConcurrentReset) jvmEvents.get(7); + var reset = (ConcurrentReset) jvmEvents.get(7); assertEquals(0.005d, reset.getDuration()); } @@ -223,18 +222,18 @@ public void test70CMSDetailsNoCauseDateStamps() { END_OF_DATA_SENTINEL }; - List jvmEvents = feedParser(lines); + var jvmEvents = feedParser(lines); - ParNew parNew = (ParNew) jvmEvents.get(0); + var parNew = (ParNew) jvmEvents.getFirst(); assertMemoryPoolValues(parNew.getHeap(), 1856305, 1965056, 851287, 1965056); assertMemoryPoolValues(parNew.getYoung(), 1143174, 1188864, 132096, 1188864); assertMemoryPoolValues(parNew.getTenured(), 1856305 - 1143174, 1965056 - 1188864, 851287 - 132096, 1965056 - 1188864); assertEquals(0.1554100, parNew.getDuration()); - InitialMark initialMark = (InitialMark) jvmEvents.get(1); + var initialMark = (InitialMark) jvmEvents.get(1); assertEquals(0.1976100, initialMark.getDuration()); - CMSRemark cmsRemark = (CMSRemark) jvmEvents.get(5); + var cmsRemark = (CMSRemark) jvmEvents.get(5); assertEquals(0.6306470, cmsRemark.getDuration()); } } diff --git a/parser/src/test/java/com/microsoft/gctoolkit/parser/ShenandoahParserRulesTest.java b/parser/src/test/java/com/microsoft/gctoolkit/parser/ShenandoahParserRulesTest.java index e169abe0..0298a14f 100644 --- a/parser/src/test/java/com/microsoft/gctoolkit/parser/ShenandoahParserRulesTest.java +++ b/parser/src/test/java/com/microsoft/gctoolkit/parser/ShenandoahParserRulesTest.java @@ -15,9 +15,9 @@ public class ShenandoahParserRulesTest implements ShenandoahPatterns { @Test public void testParseRules() { - for (int i = 0; i < rules.length; i++) - for (int j = 0; j < lines.length; j++) { - int captured = captureTest(rules[i], lines[j]); + for (var i = 0; i < rules.length; i++) + for (var j = 0; j < lines.length; j++) { + var captured = captureTest(rules[i], lines[j]); if (i == j) { assertEquals(captured, lines[j].length, i + " failed to captured it's lines"); } else { @@ -29,7 +29,7 @@ public void testParseRules() { } private int captureTest(GCParseRule rule, String[] lines) { - int captureCount = 0; + var captureCount = 0; for (String line : lines) { GCLogTrace trace = rule.parse(line); if (rule.parse(line) != null) { @@ -42,7 +42,7 @@ private int captureTest(GCParseRule rule, String[] lines) { // Convenience test for debugging single rules // @Test public void testSingeRule() { - int index = 9; + var index = 9; assertEquals(captureTest(rules[index], lines[index]), lines[index].length); } @@ -53,7 +53,7 @@ private void evaluate(GCParseRule rule, String string, boolean dump) { assertNotNull(trace); if (dump) { LOGGER.fine("matches groups " + trace.groupCount()); - for (int i = 0; i <= trace.groupCount(); i++) { + for (var i = 0; i <= trace.groupCount(); i++) { LOGGER.fine(i + ": " + trace.getGroup(i)); } } diff --git a/parser/src/test/java/com/microsoft/gctoolkit/parser/ShenandoahParserTest.java b/parser/src/test/java/com/microsoft/gctoolkit/parser/ShenandoahParserTest.java index 785c0734..4229908b 100644 --- a/parser/src/test/java/com/microsoft/gctoolkit/parser/ShenandoahParserTest.java +++ b/parser/src/test/java/com/microsoft/gctoolkit/parser/ShenandoahParserTest.java @@ -2,14 +2,11 @@ // Licensed under the MIT License. package com.microsoft.gctoolkit.parser; -import com.microsoft.gctoolkit.event.jvm.JVMEvent; import com.microsoft.gctoolkit.event.shenandoah.ShenandoahCycle; import com.microsoft.gctoolkit.jvm.Diarizer; import com.microsoft.gctoolkit.parser.jvm.UnifiedDiarizer; import org.junit.jupiter.api.Assertions; -import java.util.List; - public class ShenandoahParserTest extends ParserTest { @Override @@ -75,10 +72,10 @@ public void infoLevelShenandoahCycle() { "[0.896s][info][gc,ergo ] Pacer for Idle. Initial: 163M, Alloc Tax Rate: 1.0x" }; - List singleCycle = feedParser(eventLogEntries); + var singleCycle = feedParser(eventLogEntries); try { Assertions.assertTrue(singleCycle.size() == 1); - ShenandoahCycle sc = (ShenandoahCycle) singleCycle.get(0); + var sc = (ShenandoahCycle) singleCycle.getFirst(); // todo: Put in checks for values //Memory diff --git a/parser/src/test/java/com/microsoft/gctoolkit/parser/UnifiedG1GCParserFragmentTest.java b/parser/src/test/java/com/microsoft/gctoolkit/parser/UnifiedG1GCParserFragmentTest.java index db0b162f..304e8d2d 100644 --- a/parser/src/test/java/com/microsoft/gctoolkit/parser/UnifiedG1GCParserFragmentTest.java +++ b/parser/src/test/java/com/microsoft/gctoolkit/parser/UnifiedG1GCParserFragmentTest.java @@ -6,19 +6,12 @@ import com.microsoft.gctoolkit.event.GCCause; import com.microsoft.gctoolkit.event.MemoryPoolSummary; import com.microsoft.gctoolkit.event.g1gc.G1Young; -import com.microsoft.gctoolkit.event.jvm.JVMEvent; import com.microsoft.gctoolkit.event.jvm.SurvivorRecord; import com.microsoft.gctoolkit.jvm.Diarizer; -import com.microsoft.gctoolkit.parser.diary.TestLogFile; import com.microsoft.gctoolkit.parser.jvm.UnifiedDiarizer; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -import java.io.IOException; -import java.nio.file.Path; -import java.util.Iterator; -import java.util.List; - import static org.junit.jupiter.api.Assertions.fail; public class UnifiedG1GCParserFragmentTest extends ParserTest { @@ -88,11 +81,11 @@ public void testNewDecoratorCombination() { "[2023-12-06T07:32:54.701+0000][613ms] GC(1) User=0.00s Sys=0.00s Real=0.00s" }; - List jvmEvents = feedParser(lines); + var jvmEvents = feedParser(lines); try { Assertions.assertEquals(2, jvmEvents.size()); - Assertions.assertEquals(G1Young.class, jvmEvents.get(0).getClass()); + Assertions.assertEquals(G1Young.class, jvmEvents.getFirst().getClass()); Assertions.assertEquals(G1Young.class, jvmEvents.get(1).getClass()); } catch(Throwable t) { fail(t); @@ -103,8 +96,9 @@ public void testNewDecoratorCombination() { public void testSurvivorRecord() { String[] lines = {"[0.016s][info][gc,heap] Heap region size: 1M", "[0.018s][info][gc ] Using G1", - "[0.018s][info][gc,heap,coops] Heap address: 0x00000007fc000000, size: 64 MB, Compressed Oops mode: Zero based, Oop shift amount: 3\n" + - "[10.749s][info][gc,start ] GC(0) Pause Young (Normal) (G1 Evacuation Pause)", + """ + [0.018s][info][gc,heap,coops] Heap address: 0x00000007fc000000, size: 64 MB, Compressed Oops mode: Zero based, Oop shift amount: 3 + [10.749s][info][gc,start ] GC(0) Pause Young (Normal) (G1 Evacuation Pause)""", "[10.749s][info][gc,task ] GC(0) Using 8 workers of 8 for evacuation", "[10.749s][debug][gc,age ] GC(0) Desired survivor size 1572864 bytes, new threshold 15 (max threshold 15)", "[10.753s][trace][gc,age ] GC(0) Age table with threshold 15 (max threshold 15)", @@ -153,12 +147,12 @@ public void testSurvivorRecord() { "[10.754s][info ][gc ] GC(0) Pause Young (Normal) (G1 Evacuation Pause) 23M->5M(64M) 5.662ms", "[10.754s][info ][gc,cpu ] GC(0) User=0.03s Sys=0.01s Real=0.00s" }; - List jvmEvents = feedParser(lines); + var jvmEvents = feedParser(lines); try { Assertions.assertEquals(1, jvmEvents.size()); - Assertions.assertEquals(G1Young.class, jvmEvents.get(0).getClass()); - G1Young cycle = (G1Young) jvmEvents.get(0); + Assertions.assertEquals(G1Young.class, jvmEvents.getFirst().getClass()); + var cycle = (G1Young) jvmEvents.getFirst(); SurvivorRecord survivorRecord = cycle.getSurvivorRecord(); Assertions.assertEquals(1572864, survivorRecord.getDesiredOccupancyAfterCollection()); Assertions.assertEquals(15, survivorRecord.getMaxTenuringThreshold()); diff --git a/parser/src/test/java/com/microsoft/gctoolkit/parser/UnifiedGenerationalEventsTest.java b/parser/src/test/java/com/microsoft/gctoolkit/parser/UnifiedGenerationalEventsTest.java index 6308c28f..274fbeb0 100644 --- a/parser/src/test/java/com/microsoft/gctoolkit/parser/UnifiedGenerationalEventsTest.java +++ b/parser/src/test/java/com/microsoft/gctoolkit/parser/UnifiedGenerationalEventsTest.java @@ -17,14 +17,11 @@ import com.microsoft.gctoolkit.event.generational.PSFullGC; import com.microsoft.gctoolkit.event.generational.PSYoungGen; import com.microsoft.gctoolkit.event.generational.ParNew; -import com.microsoft.gctoolkit.event.jvm.JVMEvent; import com.microsoft.gctoolkit.event.jvm.SurvivorRecord; import com.microsoft.gctoolkit.jvm.Diarizer; import com.microsoft.gctoolkit.parser.jvm.UnifiedDiarizer; import org.junit.jupiter.api.Test; -import java.util.List; - import static org.junit.jupiter.api.Assertions.*; @@ -55,10 +52,10 @@ public void testParallelYoungCollection() { "[10.026s][info ][gc ] GC(0) Pause Young (Allocation Failure) 16M->4M(61M) 5.423ms", "[10.026s][info ][gc,cpu ] GC(0) User=0.02s Sys=0.01s Real=0.00s", }; - List jvmEvents = feedParser(lines); + var jvmEvents = feedParser(lines); try { assertEquals(1, jvmEvents.size(), "Should be 1 event... "); - PSYoungGen youngGen = (PSYoungGen) jvmEvents.get(0); + var youngGen = (PSYoungGen) jvmEvents.getFirst(); MemoryPoolSummary poolSummary = youngGen.getHeap(); assertEquals(poolSummary.getOccupancyBeforeCollection(), 16 * 1024); assertEquals(poolSummary.getOccupancyAfterCollection(), 4 * 1024); @@ -98,13 +95,13 @@ public void testParallelNoDetails() { "[6529.878s][info][gc] GC(121) Pause Young (GCLocker Initiated GC) 9210M->7586M(12157M) 34.814ms" }; - List jvmEvents = feedParser(lines); + var jvmEvents = feedParser(lines); assertEquals(5, jvmEvents.size()); try { // Event 0 - PSYoungGen - PSYoungGen evt0 = (PSYoungGen) jvmEvents.get(0); + var evt0 = (PSYoungGen) jvmEvents.getFirst(); assertEquals(GCCause.METADATA_GENERATION_THRESHOLD, evt0.getGCCause()); MemoryPoolSummary heapSummary = evt0.getHeap(); assertEquals(516*1024, heapSummary.getOccupancyBeforeCollection()); @@ -112,7 +109,7 @@ public void testParallelNoDetails() { assertEquals(7065*1024, heapSummary.getSizeAfterCollection()); // Event 1 - FullGC - FullGC evt1 = (FullGC) jvmEvents.get(1); + var evt1 = (FullGC) jvmEvents.get(1); assertEquals(GCCause.METADATA_GENERATION_THRESHOLD, evt1.getGCCause()); heapSummary = evt1.getHeap(); assertEquals(42*1024, heapSummary.getOccupancyBeforeCollection()); @@ -120,7 +117,7 @@ public void testParallelNoDetails() { assertEquals(7065*1024, heapSummary.getSizeAfterCollection()); // Event 2 - PSYoungGen - PSYoungGen evt2 = (PSYoungGen) jvmEvents.get(2); + var evt2 = (PSYoungGen) jvmEvents.get(2); assertEquals(GCCause.ALLOCATION_FAILURE, evt2.getGCCause()); heapSummary = evt2.getHeap(); assertEquals(1914*1024, heapSummary.getOccupancyBeforeCollection()); @@ -128,7 +125,7 @@ public void testParallelNoDetails() { assertEquals(7065*1024, heapSummary.getSizeAfterCollection()); // Event 3 - FullGC - FullGC evt3 = (FullGC) jvmEvents.get(3); + var evt3 = (FullGC) jvmEvents.get(3); assertEquals(GCCause.ADAPTIVE_SIZE_POLICY, evt3.getGCCause()); heapSummary = evt3.getHeap(); assertEquals(5282*1024, heapSummary.getOccupancyBeforeCollection()); @@ -136,7 +133,7 @@ public void testParallelNoDetails() { assertEquals(12150*1024, heapSummary.getSizeAfterCollection()); // Event 4 - PSYoungGen - PSYoungGen evt4 = (PSYoungGen) jvmEvents.get(4); + var evt4 = (PSYoungGen) jvmEvents.get(4); assertEquals(GCCause.GC_LOCKER, evt4.getGCCause()); heapSummary = evt4.getHeap(); assertEquals(9210*1024, heapSummary.getOccupancyBeforeCollection()); @@ -178,10 +175,10 @@ public void testParallelFUllCollection() { "[10.130s][info ][gc ] GC(25) Pause Full (Ergonomics) 55M->7M(42M) 14.092ms", "[10.130s][info ][gc,cpu ] GC(25) User=0.04s Sys=0.00s Real=0.02s" }; - List jvmEvents = feedParser(lines); + var jvmEvents = feedParser(lines); try { assertEquals(1, jvmEvents.size(), "Should be 1 event... "); - PSFullGC full = (PSFullGC) jvmEvents.get(0); + var full = (PSFullGC) jvmEvents.getFirst(); assertEquals(full.getHeap().getOccupancyBeforeCollection(), 55 * 1024); assertEquals(full.getHeap().getOccupancyAfterCollection(), 7 * 1024); assertEquals(full.getHeap().getSizeAfterCollection(), 42 * 1024); @@ -206,10 +203,10 @@ public void testParNewCollection() { "[31.193s][info ][gc,cpu ] GC(17) User=0.01s Sys=0.00s Real=0.00s" }; - List jvmEvents = feedParser(lines); + var jvmEvents = feedParser(lines); try { assertEquals(1, jvmEvents.size()); - ParNew collection = (ParNew) jvmEvents.get(0); + var collection = (ParNew) jvmEvents.getFirst(); assertEquals(31 * 1024, collection.getHeap().getOccupancyBeforeCollection()); assertEquals(15 * 1024, collection.getHeap().getOccupancyAfterCollection()); assertEquals(61 * 1024, collection.getHeap().getSizeAfterCollection()); @@ -270,31 +267,31 @@ public void testCMSCycleCollection() { "[31.276s][info ][gc ] GC(29) Concurrent Reset 2.716ms", "[31.276s][info ][gc,cpu ] GC(29) User=0.01s Sys=0.00s Real=0.00s" }; - List jvmEvents = feedParser(lines); + var jvmEvents = feedParser(lines); try { assertEquals(7, jvmEvents.size()); - InitialMark initialMark = (InitialMark) jvmEvents.get(0); + var initialMark = (InitialMark) jvmEvents.getFirst(); assertEquals(24 * 1024, initialMark.getHeap().getOccupancyBeforeCollection()); assertEquals(24 * 1024, initialMark.getHeap().getOccupancyAfterCollection()); assertEquals(61 * 1024, initialMark.getHeap().getSizeAfterCollection()); assertEquals(240, Math.round(initialMark.getDuration() * 1000000.0d)); - ConcurrentMark concurrentMark = (ConcurrentMark) jvmEvents.get(1); + var concurrentMark = (ConcurrentMark) jvmEvents.get(1); assertEquals(30285, Math.round(concurrentMark.getDuration() * 1000000.0d)); - ConcurrentPreClean preClean = (ConcurrentPreClean) jvmEvents.get(2); + var preClean = (ConcurrentPreClean) jvmEvents.get(2); assertEquals(2368, Math.round(preClean.getDuration() * 1000000.0d)); - AbortablePreClean abortablePreClean = (AbortablePreClean) jvmEvents.get(3); + var abortablePreClean = (AbortablePreClean) jvmEvents.get(3); assertEquals(2394, Math.round(abortablePreClean.getDuration() * 1000000.0d)); - CMSRemark remark = (CMSRemark) jvmEvents.get(4); + var remark = (CMSRemark) jvmEvents.get(4); assertEquals(26 * 1024, remark.getHeap().getOccupancyBeforeCollection()); assertEquals(26 * 1024, remark.getHeap().getOccupancyAfterCollection()); assertEquals(61 * 1024, remark.getHeap().getSizeAfterCollection()); assertEquals(2919, (int) (remark.getDuration() * 1000000.0d)); - ConcurrentSweep sweep = (ConcurrentSweep) jvmEvents.get(5); + var sweep = (ConcurrentSweep) jvmEvents.get(5); assertEquals(4130, Math.round(sweep.getDuration() * 1000000.0d)); - ConcurrentReset reset = (ConcurrentReset) jvmEvents.get(6); + var reset = (ConcurrentReset) jvmEvents.get(6); assertEquals(2716, Math.round(reset.getDuration() * 1000000.0d)); } catch (ClassCastException cce) { fail(cce.getMessage()); @@ -312,10 +309,10 @@ public void testDefNewCollection() { "[11.910s][info ][gc ] GC(0) Pause Young (Allocation Failure) 16M->3M(61M) 10.585ms", "[11.910s][info ][gc,cpu ] GC(0) User=0.01s Sys=0.00s Real=0.01s" }; - List jvmEvents = feedParser(lines); + var jvmEvents = feedParser(lines); try { assertEquals(1, jvmEvents.size()); - DefNew collection = (DefNew) jvmEvents.get(0); + var collection = (DefNew) jvmEvents.getFirst(); assertEquals(16 * 1024, collection.getHeap().getOccupancyBeforeCollection()); assertEquals(3 * 1024, collection.getHeap().getOccupancyAfterCollection()); assertEquals(61 * 1024, collection.getHeap().getSizeAfterCollection()); @@ -368,10 +365,10 @@ public void testSerialFullCollection() { "[12.199s][info ][gc ] GC(112) Pause Young (Allocation Failure) 61M->6M(61M) 10.878ms", "[12.199s][info ][gc,cpu ] GC(112) User=0.02s Sys=0.00s Real=0.01s" }; - List jvmEvents = feedParser(lines); + var jvmEvents = feedParser(lines); try { assertEquals(1, jvmEvents.size()); - FullGC collection = (FullGC) jvmEvents.get(0); + var collection = (FullGC) jvmEvents.getFirst(); assertEquals(61 * 1024, collection.getHeap().getOccupancyBeforeCollection()); assertEquals(6 * 1024, collection.getHeap().getOccupancyAfterCollection()); assertEquals(61 * 1024, collection.getHeap().getSizeAfterCollection()); @@ -391,10 +388,10 @@ public void testEnhancedMetaspaceRecord() { "[0.694s][info][gc ] GC(2) Pause Young (Allocation Failure) 116M->115M(171M) 131.613ms", "[0.694s][info][gc,cpu ] GC(2) User=0.33s Sys=0.02s Real=0.13s" }; - List jvmEvents = feedParser(lines); + var jvmEvents = feedParser(lines); try { assertEquals(1, jvmEvents.size()); - PSYoungGen collection = (PSYoungGen) jvmEvents.get(0); + var collection = (PSYoungGen) jvmEvents.getFirst(); assertEquals(53228, collection.getYoung().getOccupancyBeforeCollection()); assertEquals(7148, collection.getYoung().getOccupancyAfterCollection()); assertEquals(53248, collection.getYoung().getSizeAfterCollection()); @@ -435,9 +432,9 @@ public void parallelWithSurvivorRecordsTest() { "[9.371s][info ][gc,cpu ] GC(18) User=0.01s Sys=0.00s Real=0.00s" }; - List jvmEvents = feedParser(lines); + var jvmEvents = feedParser(lines); assertEquals(1, jvmEvents.size()); - PSYoungGen collection = (PSYoungGen) jvmEvents.get(0); + var collection = (PSYoungGen) jvmEvents.getFirst(); assertEquals(9.371, collection.getDateTimeStamp().toSeconds()); SurvivorRecord record = collection.getSurvivorRecord(); assertNotNull(record); @@ -464,9 +461,9 @@ public void serialWithSurvivorRecordsTest() { "[8.727s][info ][gc,cpu ] GC(9) User=0.00s Sys=0.00s Real=0.00s" }; - List jvmEvents = feedParser(lines); + var jvmEvents = feedParser(lines); assertEquals(1, jvmEvents.size()); - DefNew collection = (DefNew) jvmEvents.get(0); + var collection = (DefNew) jvmEvents.getFirst(); assertEquals(8.726, collection.getDateTimeStamp().toSeconds()); SurvivorRecord record = collection.getSurvivorRecord(); assertNotNull(record); @@ -475,7 +472,7 @@ public void serialWithSurvivorRecordsTest() { assertEquals(8945664, record.getDesiredOccupancyAfterCollection()); assertEquals(16, record.getBytesAtEachAge().length); int[] bytesAtAge = {0, 400368, 0, 304, 0, 0, 0, 0, 32, 554176, 0, 0, 0, 0, 0, 0}; - for (int i = 1; i < bytesAtAge.length; i++) { + for (var i = 1; i < bytesAtAge.length; i++) { assertEquals(bytesAtAge[i], record.getBytesAtAge(i)); } assertThrows(IndexOutOfBoundsException.class, () -> record.getBytesAtAge(16)); @@ -496,9 +493,9 @@ public void cmsWithSurvivorRecordsTest() { "[11.634s][info ][gc ] GC(12) Pause Young (Allocation Failure) 140M->3M(495M) 0.430ms", "[11.634s][info ][gc,cpu ] GC(12) User=0.00s Sys=0.00s Real=0.00s", }; - List jvmEvents = feedParser(lines); + var jvmEvents = feedParser(lines); assertEquals(1, jvmEvents.size()); - ParNew collection = (ParNew) jvmEvents.get(0); + var collection = (ParNew) jvmEvents.getFirst(); assertEquals(11.633, collection.getDateTimeStamp().toSeconds()); SurvivorRecord record = collection.getSurvivorRecord(); @@ -508,7 +505,7 @@ public void cmsWithSurvivorRecordsTest() { assertEquals(8945664, record.getDesiredOccupancyAfterCollection()); assertEquals(7, record.getBytesAtEachAge().length); int[] bytesAtAge = {0, 400208, 0, 0, 0, 0, 304}; - for (int i = 1; i < bytesAtAge.length; i++) { + for (var i = 1; i < bytesAtAge.length; i++) { assertEquals(bytesAtAge[i], record.getBytesAtAge(i)); } assertThrows(IndexOutOfBoundsException.class, () -> record.getBytesAtAge(7)); diff --git a/parser/src/test/java/com/microsoft/gctoolkit/parser/UnifiedGenerationalParserRulesTest.java b/parser/src/test/java/com/microsoft/gctoolkit/parser/UnifiedGenerationalParserRulesTest.java index b0856bfb..8be334e7 100644 --- a/parser/src/test/java/com/microsoft/gctoolkit/parser/UnifiedGenerationalParserRulesTest.java +++ b/parser/src/test/java/com/microsoft/gctoolkit/parser/UnifiedGenerationalParserRulesTest.java @@ -17,9 +17,9 @@ public class UnifiedGenerationalParserRulesTest implements UnifiedGenerationalPa @Test public void testGenerationalParseRules() { - for (int i = 0; i < rules.length; i++) - for (int j = 0; j < lines.length; j++) { - int captured = captureTest(rules[i], lines[j]); + for (var i = 0; i < rules.length; i++) + for (var j = 0; j < lines.length; j++) { + var captured = captureTest(rules[i], lines[j]); if (i == j) { assertEquals(captured, lines[j].length, i + " failed to captured it's lines"); } else { @@ -33,7 +33,7 @@ public void testGenerationalParseRules() { @Test public void testUnifiedLoggingDecorators() { for (String decoratorLine : decoratorLines) { - Decorators decorators = new Decorators(decoratorLine); + var decorators = new Decorators(decoratorLine); assertTrue(decorators.getNumberOfDecorators() != 0); } } @@ -41,7 +41,7 @@ public void testUnifiedLoggingDecorators() { // Convenience test for debugging single rules // @Test public void testSingeRule() { - int index = 0; + var index = 0; assertEquals(4, captureTest(rules[index], lines[index])); } @@ -52,7 +52,7 @@ private void evaluate(GCParseRule rule, String string, boolean dump) { assertNotNull(trace); if (dump) { LOGGER.fine("matches groups " + trace.groupCount()); - for (int i = 0; i <= trace.groupCount(); i++) { + for (var i = 0; i <= trace.groupCount(); i++) { LOGGER.fine(i + ": " + trace.getGroup(i)); } } diff --git a/parser/src/test/java/com/microsoft/gctoolkit/parser/ZGCParserRulesTest.java b/parser/src/test/java/com/microsoft/gctoolkit/parser/ZGCParserRulesTest.java index e4f83fee..d2c75f04 100644 --- a/parser/src/test/java/com/microsoft/gctoolkit/parser/ZGCParserRulesTest.java +++ b/parser/src/test/java/com/microsoft/gctoolkit/parser/ZGCParserRulesTest.java @@ -16,9 +16,9 @@ public class ZGCParserRulesTest implements ZGCPatterns { @Test public void testZGCParseRules() { - for (int i = 0; i < rules.length; i++) - for (int j = 0; j < lines.length; j++) { - int captured = captureTest(rules[i], lines[j]); + for (var i = 0; i < rules.length; i++) + for (var j = 0; j < lines.length; j++) { + var captured = captureTest(rules[i], lines[j]); if (i == j) { assertEquals(captured, lines[j].length, i + " failed to captured it's lines"); } else { @@ -32,13 +32,13 @@ public void testZGCParseRules() { @Test public void testUnifiedLoggingDecorators() { for (String decoratorLine : decoratorLines) { - Decorators decorators = new Decorators(decoratorLine); + var decorators = new Decorators(decoratorLine); assertTrue(decorators.getNumberOfDecorators() != 0); } } private int captureTest(GCParseRule rule, String[] lines) { - int captureCount = 0; + var captureCount = 0; for (String line : lines) { GCLogTrace trace = rule.parse(line); if (trace != null) { @@ -51,7 +51,7 @@ private int captureTest(GCParseRule rule, String[] lines) { // Convenience test for debugging single rules // @Test public void testSingeRule() { - int index = 14; + var index = 14; assertEquals(captureTest(rules[index], lines[index]), lines[index].length); } @@ -62,7 +62,7 @@ private void evaluate(GCParseRule rule, String string, boolean dump) { assertNotNull(trace); if (dump) { LOGGER.fine("matches groups " + trace.groupCount()); - for (int i = 0; i <= trace.groupCount(); i++) { + for (var i = 0; i <= trace.groupCount(); i++) { LOGGER.fine(i + ": " + trace.getGroup(i)); } } diff --git a/parser/src/test/java/com/microsoft/gctoolkit/parser/ZGCParserTest.java b/parser/src/test/java/com/microsoft/gctoolkit/parser/ZGCParserTest.java index 0e26cf67..4958b0c5 100644 --- a/parser/src/test/java/com/microsoft/gctoolkit/parser/ZGCParserTest.java +++ b/parser/src/test/java/com/microsoft/gctoolkit/parser/ZGCParserTest.java @@ -3,7 +3,6 @@ package com.microsoft.gctoolkit.parser; import com.microsoft.gctoolkit.event.GCCause; -import com.microsoft.gctoolkit.event.jvm.JVMEvent; import com.microsoft.gctoolkit.event.zgc.ZGCAllocatedSummary; import com.microsoft.gctoolkit.event.zgc.ZGCFullCollection; import com.microsoft.gctoolkit.event.zgc.ZGCGarbageSummary; @@ -21,8 +20,6 @@ import org.junit.jupiter.api.Test; -import java.util.List; - import static org.junit.jupiter.api.Assertions.*; public class ZGCParserTest extends ParserTest { @@ -34,6 +31,7 @@ protected Diarizer diarizer() { return new UnifiedDiarizer(); } + @Override protected GCLogParser parser() { return new ZGCParser(); } @@ -80,10 +78,10 @@ public void infoLevelZGCCycle() { }; - List singleCycle = feedParser(eventLogEntries); + var singleCycle = feedParser(eventLogEntries); try { assertEquals(1, singleCycle.size()); - ZGCFullCollection zgc = (ZGCFullCollection) singleCycle.get(0); + var zgc = (ZGCFullCollection) singleCycle.getFirst(); assertEquals(zgc.getGcId(), 2L); @@ -152,21 +150,21 @@ void testLegacyZGCNoDetailsLines() { "[23.507s][info][gc] GC(3) Garbage Collection (Warmup) 826M(10%)->168M(2%)" }; - int expectedEventCount = 2; + var expectedEventCount = 2; - List jvmEvents = feedParser(lines); + var jvmEvents = feedParser(lines); assertEquals(expectedEventCount, jvmEvents.size()); // 0 - ZGCFullCollection - assertTrue(jvmEvents.get(0) instanceof ZGCFullCollection); - ZGCFullCollection evt0 = (ZGCFullCollection) jvmEvents.get(0); + assertTrue(jvmEvents.getFirst() instanceof ZGCFullCollection); + var evt0 = (ZGCFullCollection) jvmEvents.getFirst(); assertEquals(evt0.getDateTimeStamp(), new DateTimeStamp(1.295)); assertEquals(evt0.getGCCause(), GCCause.METADATA_GENERATION_THRESHOLD); assertZGCMemorySummary(evt0.getMemorySummary(), 90*M, 58*M); // 1 - ZGCFullCollection assertTrue(jvmEvents.get(1) instanceof ZGCFullCollection); - ZGCFullCollection evt1 = (ZGCFullCollection) jvmEvents.get(1); + var evt1 = (ZGCFullCollection) jvmEvents.get(1); assertEquals(new DateTimeStamp(23.507), evt1.getDateTimeStamp()); assertEquals(GCCause.WARMUP, evt1.getGCCause()); assertZGCMemorySummary(evt1.getMemorySummary(), 826*M, 168*M); @@ -214,16 +212,16 @@ void testLegacyDetailedEvent() { "[1.664s][info][gc ] GC(0) Garbage Collection (Metadata GC Threshold) 124M(2%)->66M(1%)" }; - int expectedEventCount = 1; + var expectedEventCount = 1; - List jvmEvents = feedParser(lines); + var jvmEvents = feedParser(lines); assertEquals(expectedEventCount, jvmEvents.size()); // 0 - ZGCFullCollection // Note: this is just a light-weight check of the event object at this time to make sure there is no confusion between // Legacy ZGC logging and Generational ZGC events with some of the changes added to support no-detail logging. - assertTrue(jvmEvents.get(0) instanceof ZGCFullCollection); - ZGCFullCollection evt0 = (ZGCFullCollection) jvmEvents.get(0); + assertTrue(jvmEvents.getFirst() instanceof ZGCFullCollection); + var evt0 = (ZGCFullCollection) jvmEvents.getFirst(); assertEquals(new DateTimeStamp(1.641), evt0.getDateTimeStamp()); assertEquals(GCCause.METADATA_GENERATION_THRESHOLD, evt0.getGCCause()); assertEquals(ZGCPhase.FULL, evt0.getPhase()); @@ -244,14 +242,14 @@ void testGenerationalZGCNoDetailsLines() { "[36.423s][info][gc] GC(3) Major Collection (Warmup) 730M(9%)->258M(3%) 0.097s" }; - int expectedEventCount = 2; + var expectedEventCount = 2; - List jvmEvents = feedParser(lines); + var jvmEvents = feedParser(lines); assertEquals(jvmEvents.size(), expectedEventCount); // 0 - ZGCYoungCollection - assertTrue(jvmEvents.get(0) instanceof ZGCYoungCollection); - ZGCYoungCollection evt0 = (ZGCYoungCollection) jvmEvents.get(0); + assertTrue(jvmEvents.getFirst() instanceof ZGCYoungCollection); + var evt0 = (ZGCYoungCollection) jvmEvents.getFirst(); assertEquals(new DateTimeStamp(4.252), evt0.getDateTimeStamp()); assertEquals(GCCause.METADATA_GENERATION_THRESHOLD, evt0.getGCCause()); assertEquals(ZGCPhase.MAJOR_YOUNG, evt0.getPhase()); @@ -260,7 +258,7 @@ void testGenerationalZGCNoDetailsLines() { // 1 - ZGCYoungCollection(Major) assertTrue(jvmEvents.get(1) instanceof ZGCYoungCollection); - ZGCYoungCollection evt1 = (ZGCYoungCollection) jvmEvents.get(1); + var evt1 = (ZGCYoungCollection) jvmEvents.get(1); assertEquals(new DateTimeStamp(36.326), evt1.getDateTimeStamp()); assertEquals(GCCause.WARMUP, evt1.getGCCause()); assertEquals(ZGCPhase.MAJOR_YOUNG, evt1.getPhase()); @@ -366,16 +364,16 @@ void testMajorGenerationalDetailedEvent() { "[1.062s][info][gc ] GC(0) Major Collection (Metadata GC Threshold) 86M(1%)->56M(1%) 0.073s", }; - int expectedEventCount = 2; + var expectedEventCount = 2; - List jvmEvents = feedParser(lines); + var jvmEvents = feedParser(lines); assertEquals(jvmEvents.size(), expectedEventCount); // TODO: Only basic testing to make sure no extra events were being created by fixes for no-details logs. // 0 - ZGCYoungCollection - assertTrue(jvmEvents.get(0) instanceof ZGCYoungCollection); - ZGCYoungCollection evt0 = (ZGCYoungCollection) jvmEvents.get(0); + assertTrue(jvmEvents.getFirst() instanceof ZGCYoungCollection); + var evt0 = (ZGCYoungCollection) jvmEvents.getFirst(); assertEquals(new DateTimeStamp(0.990), evt0.getDateTimeStamp()); assertEquals(GCCause.METADATA_GENERATION_THRESHOLD, evt0.getGCCause()); assertEquals(ZGCPhase.MAJOR_YOUNG, evt0.getPhase()); @@ -384,7 +382,7 @@ void testMajorGenerationalDetailedEvent() { // 1 - ZGCOldCollection(Major) assertTrue(jvmEvents.get(1) instanceof ZGCOldCollection); - ZGCOldCollection evt1 = (ZGCOldCollection) jvmEvents.get(1); + var evt1 = (ZGCOldCollection) jvmEvents.get(1); assertEquals(new DateTimeStamp(1.012), evt1.getDateTimeStamp()); assertEquals(GCCause.METADATA_GENERATION_THRESHOLD, evt1.getGCCause()); assertEquals(ZGCPhase.MAJOR_OLD, evt1.getPhase()); diff --git a/parser/src/test/java/com/microsoft/gctoolkit/parser/collection/MRUQueueTest.java b/parser/src/test/java/com/microsoft/gctoolkit/parser/collection/MRUQueueTest.java index 030e8889..a684da68 100644 --- a/parser/src/test/java/com/microsoft/gctoolkit/parser/collection/MRUQueueTest.java +++ b/parser/src/test/java/com/microsoft/gctoolkit/parser/collection/MRUQueueTest.java @@ -16,13 +16,13 @@ public void testMRUQueueOrdering() { String[] afterA = {"A", "B", "C"}; String[] afterC = {"C", "A", "B"}; - MRUQueue queue = new MRUQueue<>(); + var queue = new MRUQueue(); queue.put("B", "E"); queue.put("A", "D"); queue.put("C", "F"); assertEquals(3, queue.size()); - int i = 0; + var i = 0; for (String key : queue.keys()) { assertEquals(key, original[i++]); } diff --git a/parser/src/test/java/com/microsoft/gctoolkit/parser/diary/CMSDefNewLogDiaryTest.java b/parser/src/test/java/com/microsoft/gctoolkit/parser/diary/CMSDefNewLogDiaryTest.java index 9d2521c1..40b501e2 100644 --- a/parser/src/test/java/com/microsoft/gctoolkit/parser/diary/CMSDefNewLogDiaryTest.java +++ b/parser/src/test/java/com/microsoft/gctoolkit/parser/diary/CMSDefNewLogDiaryTest.java @@ -12,9 +12,9 @@ public class CMSDefNewLogDiaryTest extends LogDiaryTest { @Test public void testForCMSDefNewDetails() { - int i = 0; + var i = 0; for (String name : cmsDefNewDetails) { - TestLogFile logFile = new TestLogFile(name); + var logFile = new TestLogFile(name); Diarizer diary = null; try { diary = getJVMConfiguration(new SingleGCLogFile(logFile.getFile().toPath())); diff --git a/parser/src/test/java/com/microsoft/gctoolkit/parser/diary/CMSLogDiaryTest.java b/parser/src/test/java/com/microsoft/gctoolkit/parser/diary/CMSLogDiaryTest.java index b0a59bef..3619fd75 100644 --- a/parser/src/test/java/com/microsoft/gctoolkit/parser/diary/CMSLogDiaryTest.java +++ b/parser/src/test/java/com/microsoft/gctoolkit/parser/diary/CMSLogDiaryTest.java @@ -14,9 +14,9 @@ public class CMSLogDiaryTest extends LogDiaryTest { @Test public void testForCMS() { - int i = 0; + var i = 0; for (String name : cms) { - TestLogFile logFile = new TestLogFile("cms/" + name); + var logFile = new TestLogFile("cms/" + name); Diarizer diary = null; try { diary = getJVMConfiguration(new SingleGCLogFile(logFile.getFile().toPath())); diff --git a/parser/src/test/java/com/microsoft/gctoolkit/parser/diary/CMSParNewLogDiaryTest.java b/parser/src/test/java/com/microsoft/gctoolkit/parser/diary/CMSParNewLogDiaryTest.java index 4134ef3a..75fdc9fa 100644 --- a/parser/src/test/java/com/microsoft/gctoolkit/parser/diary/CMSParNewLogDiaryTest.java +++ b/parser/src/test/java/com/microsoft/gctoolkit/parser/diary/CMSParNewLogDiaryTest.java @@ -9,7 +9,7 @@ public class CMSParNewLogDiaryTest extends LogDiaryTest { @Test public void testForCMSParNewDetails() { - int i = 0; + var i = 0; for (String name : cmsParNewDetails) { testWith(new TestLogFile("cms/parnew/details/" + name).getFile(), name, cmsParNewDetailsDiary[i], cmsParNewDetailsUnknown[i], cmsParNewDetailsKnown[i++]); } @@ -17,7 +17,7 @@ public void testForCMSParNewDetails() { @Test public void testForCMSParNewDetailsTenuring() { - int i = 0; + var i = 0; for (String name : cmsParNewDetailsTenuring) { testWith(new TestLogFile("cms/parnew/details/tenuring/" + name).getFile(), name, cmsParNewDetailsTenuringDiary[i], cmsParNewDetailsTenuringUnknown[i], cmsParNewDetailsTenuringKnown[i++]); } @@ -25,7 +25,7 @@ public void testForCMSParNewDetailsTenuring() { @Test public void testForCMS() { - int i = 0; + var i = 0; for (String name : cms) { testWith(new TestLogFile("cms/" + name).getFile(), name, cmsDiary[i], cmsUnknown[i], cmsKnown[i++]); } @@ -33,7 +33,7 @@ public void testForCMS() { @Test public void testForCMSParNewDetailsGCCause170() { - int i = 0; + var i = 0; for (String name : cmsParNewDetailsGCCause170) { testWith(new TestLogFile("cms/parnew/details/gccause/170/" + name).getFile(), name, cmsParNewDetailsGCCause170Diary[i], cmsParNewDetailsGCCause170Unknown[i], cmsParNewDetailsGCCause170Known[i++]); } diff --git a/parser/src/test/java/com/microsoft/gctoolkit/parser/diary/G1DiarizerTest.java b/parser/src/test/java/com/microsoft/gctoolkit/parser/diary/G1DiarizerTest.java index 7c88d6d7..d4ed85c8 100644 --- a/parser/src/test/java/com/microsoft/gctoolkit/parser/diary/G1DiarizerTest.java +++ b/parser/src/test/java/com/microsoft/gctoolkit/parser/diary/G1DiarizerTest.java @@ -31,7 +31,7 @@ public class G1DiarizerTest extends LogDiaryTest { @Test public void testForDetails() { - int i = 0; + var i = 0; for (String name : details) { testWith(new TestLogFile("g1gc/details/" + name).getFile(), name, detailsDiary[i], detailsUnknown[i], detailsKnown[i++]); } @@ -71,7 +71,7 @@ public void testForDetails() { @Test public void testForDetailsTenuring() { - int i = 0; + var i = 0; for (String name : detailsTenuring) { testWith(new TestLogFile("g1gc/details/tenuring/" + name).getFile(), name, detailsTenuringDiary[i], detailsTenuringUnknown[i], detailsTenuringKnown[i++]); } @@ -99,7 +99,7 @@ public void testForDetailsTenuring() { @Test public void testForDetailsTenuringRolling17040() { - int i = 0; + var i = 0; for (String name : detailsTenuringRolling17040) { testWith(new TestLogFile("g1gc/details/tenuring/170_45/rolling/" + name).getFile(), name, detailsTenuringRolling17040Diary[i], detailsTenuringRolling17040Unknown[i], detailsTenuringRolling17040Known[i++]); } @@ -131,7 +131,7 @@ public void testForDetailsTenuringRolling17040() { @Test public void testForDetailsTenuring80() { - int i = 0; + var i = 0; for (String name : detailsTenuring80) { testWith(new TestLogFile("g1gc/details/tenuring/180/" + name).getFile(), name, detailsTenuring80Diary[i], detailsTenuring80Unknown[i], detailsTenuring80Known[i++]); } @@ -159,7 +159,7 @@ public void testForDetailsTenuring80() { @Test public void testForDetailsPrintReferenceGC() { - int i = 0; + var i = 0; for (String name : detailsPrintReferenceGC) { testWith(new TestLogFile("g1gc/details/reference/" + name).getFile(), name, detailsPrintReferenceGCDiary[i], detailsPrintReferenceGCUnknown[i], detailsPrintReferenceGCKnown[i++]); } @@ -186,7 +186,7 @@ public void testForDetailsPrintReferenceGC() { @Test public void testForDetailsAdaptiveSizeRSet() { - int i = 0; + var i = 0; for (String name : detailsAdaptiveSizeRSet) { testWith(new TestLogFile("g1gc/details/adaptivesize/rset/" + name).getFile(), name, detailsAdaptiveSizeRSetDiary[i], detailsAdaptiveSizeRSetUnknown[i], detailsAdaptiveSizeRSetKnown[i++]); } @@ -194,7 +194,7 @@ public void testForDetailsAdaptiveSizeRSet() { @Test public void testUnifiedG1GC() { - int i = 0; + var i = 0; for (String name : unifiedLogs) { testWith(new TestLogFile("unified/g1gc/" + name).getFile(), name, unifiedDiary[i], unifiedUnknown[i], unifiedKnown[i++]); } diff --git a/parser/src/test/java/com/microsoft/gctoolkit/parser/diary/LogDiaryTest.java b/parser/src/test/java/com/microsoft/gctoolkit/parser/diary/LogDiaryTest.java index 5fd05ab9..d1b81831 100644 --- a/parser/src/test/java/com/microsoft/gctoolkit/parser/diary/LogDiaryTest.java +++ b/parser/src/test/java/com/microsoft/gctoolkit/parser/diary/LogDiaryTest.java @@ -35,14 +35,12 @@ protected Diarizer getJVMConfiguration(GCLogFile gcLogFile) throws IOException { return jvmConfiguration; } - /** - * Convenience method to avoid changing test that rely on the other form of this method signature. - * - * @param name test log file name - * @param expectedDiaryResults expected diary results - * @param expectedDetailsUnKnown expected unknown details - * @param expectedDetailsKnown expected known details - */ + /// Convenience method to avoid changing test that rely on the other form of this method signature. + /// + /// @param name test log file name + /// @param expectedDiaryResults expected diary results + /// @param expectedDetailsUnKnown expected unknown details + /// @param expectedDetailsKnown expected known details void testWith(String name, boolean[] expectedDiaryResults, int[] expectedDetailsUnKnown, int[] expectedDetailsKnown) { testWith(new TestLogFile(name).getFile(), name, expectedDiaryResults, expectedDetailsUnKnown, expectedDetailsKnown); } @@ -64,10 +62,8 @@ void performCheck(String name, boolean calculated, boolean expected) { org.junit.jupiter.api.Assertions.assertTrue(calculated == expected, name + ", calculated: " + calculated + ", expected: " + expected); } - /** - * What the deriveConfiguration should look like. Unknown == false so there is a separate test to determine - * if something is truly false when it should be false - */ + /// What the deriveConfiguration should look like. Unknown == false so there is a separate test to determine + /// if something is truly false when it should be false void interrogateDiary(Diarizer jvmConfiguration, String name, boolean[] expected) { Diary diary = jvmConfiguration.getDiary(); performCheck(name, diary.isApplicationStoppedTime(), expected[SupportedFlags.APPLICATION_STOPPED_TIME.ordinal()]); @@ -97,9 +93,7 @@ void interrogateDiary(Diarizer jvmConfiguration, String name, boolean[] expected performCheck(name, diary.isMaxTenuringThresholdViolation(), expected[SupportedFlags.MAX_TENURING_THRESHOLD_VIOLATION.ordinal()]); } - /** - * Things we shouldn't know - */ + /// Things we shouldn't know void lookForUnknowns(Diarizer jvmConfiguration, String name, int[] unknowns) { Diary diary = jvmConfiguration.getDiary(); for (int unknown : unknowns) { @@ -193,11 +187,9 @@ void lookForUnknowns(Diarizer jvmConfiguration, String name, int[] unknowns) { } } - /** - * Things we should know. Since unknown == false this is primarily to test for things that should be false. - * IOWs, if the primary test passes, this is a secondary to cover cases where the value should be false and - * not unknown. - */ + /// Things we should know. Since unknown == false this is primarily to test for things that should be false. + /// IOWs, if the primary test passes, this is a secondary to cover cases where the value should be false and + /// not unknown. void lookForKnowns(Diarizer jvmConfiguration, String name, int[] knowns) { Diary diary = jvmConfiguration.getDiary(); for (int known : knowns) { diff --git a/parser/src/test/java/com/microsoft/gctoolkit/parser/diary/ParallelDiarizerTest.java b/parser/src/test/java/com/microsoft/gctoolkit/parser/diary/ParallelDiarizerTest.java index d4b98f25..14eda3ba 100644 --- a/parser/src/test/java/com/microsoft/gctoolkit/parser/diary/ParallelDiarizerTest.java +++ b/parser/src/test/java/com/microsoft/gctoolkit/parser/diary/ParallelDiarizerTest.java @@ -8,7 +8,7 @@ public class ParallelDiarizerTest extends LogDiaryTest { @Test public void testForDetails() { - int i = 0; + var i = 0; for (String name : details) { testWith(name, detailsDiary[i], detailsUnknown[i], detailsKnown[i++]); } @@ -16,7 +16,7 @@ public void testForDetails() { @Test public void testFor170GCCause() { - int i = 0; + var i = 0; for (String name : a170gcCause) { testWith("ps/details/gccause/170/" + name, a170gcCauseDiary[i], a170gcCauseUnknown[i], a170CauseKnown[i++]); } @@ -24,7 +24,7 @@ public void testFor170GCCause() { @Test public void testFor180GCCause() { - int i = 0; + var i = 0; for (String name : a180gcCause) { testWith("ps/details/gccause/180/" + name, a180gcCauseDiary[i], a180gcCauseUnknown[i], a180gcCauseKnown[i++]); } @@ -32,7 +32,7 @@ public void testFor180GCCause() { @Test public void testForDetailsTenuring() { - int i = 0; + var i = 0; for (String name : detailsTenuring) { testWith(name, detailsTenuringDiary[i], detailsTenuringUnknown[i], detailsTenuringKnown[i++]); } @@ -40,7 +40,7 @@ public void testForDetailsTenuring() { @Test public void testForDetailsTenuring80() { - int i = 0; + var i = 0; for (String name : detailsTenuring80) { testWith("ps/details/tenuring/gccause/180/" + name, detailsTenuring80Diary[i], detailsTenuring80Unknown[i], detailsTenuring80Known[i++]); } @@ -218,7 +218,7 @@ public void testForDetailsTenuring80() { @Test public void testForDetailsTenuringAdaptiveSizing() { - int i = 0; + var i = 0; for (String name : detailsTenuringAdpativeSizing) { testWith(name, detailsTenuringAdaptiveSizingDiary[i], detailsTenuringAdaptiveSizingDiaryUnknown[i], detailsTenuringAdaptiveSizingDiaryKnown[i++]); } diff --git a/parser/src/test/java/com/microsoft/gctoolkit/parser/diary/SerialDefNewLogDiaryTest.java b/parser/src/test/java/com/microsoft/gctoolkit/parser/diary/SerialDefNewLogDiaryTest.java index 3cb23122..205011ac 100644 --- a/parser/src/test/java/com/microsoft/gctoolkit/parser/diary/SerialDefNewLogDiaryTest.java +++ b/parser/src/test/java/com/microsoft/gctoolkit/parser/diary/SerialDefNewLogDiaryTest.java @@ -8,7 +8,7 @@ public class SerialDefNewLogDiaryTest extends LogDiaryTest { @Test public void testForSerialDefNewDetails() { - int i = 0; + var i = 0; for (String name : serialDefNewDetails) { testWith(new TestLogFile(name).getFile(), name, serialDefNewDetailsDiary[i], serialDefNewDetailsUnknown[i], serialDefNewDetailsKnown[i++]); } @@ -16,7 +16,7 @@ public void testForSerialDefNewDetails() { @Test public void testForSerialDefNewDetailsTenuring() { - int i = 0; + var i = 0; for (String name : serialDefNewDetailsTenuring) { testWith(new TestLogFile(name).getFile(), name, serialDefNewDetailsTenuringDiary[i], serialDefNewDetailsTenuringUnknown[i], serialDefNewDetailsTenuringKnown[i++]); } @@ -24,7 +24,7 @@ public void testForSerialDefNewDetailsTenuring() { @Test public void testForSerialDefNewDetailsTenuring180() { - int i = 0; + var i = 0; for (String name : serialDefNewDetailsTenuring180) { testWith(new TestLogFile(name).getFile(), name, serialDefNewDetailsTenuring180Diary[i], serialDefNewDetailsTenuring180Unknown[i], serialDefNewDetailsTenuring180Known[i++]); } diff --git a/parser/src/test/java/com/microsoft/gctoolkit/parser/diary/ShenandoahLogDiaryTest.java b/parser/src/test/java/com/microsoft/gctoolkit/parser/diary/ShenandoahLogDiaryTest.java index 21875e0b..c7db2a9f 100644 --- a/parser/src/test/java/com/microsoft/gctoolkit/parser/diary/ShenandoahLogDiaryTest.java +++ b/parser/src/test/java/com/microsoft/gctoolkit/parser/diary/ShenandoahLogDiaryTest.java @@ -9,7 +9,7 @@ public class ShenandoahLogDiaryTest extends LogDiaryTest { @Test public void testForShenandoahLogDiaryPickups() { - int i = 0; + var i = 0; for (String name : shenandoahLogs) { testWith(new TestLogFile("shenandoah/" + name).getFile(), name, shenandoahDiary[i], shenandoahUnknown[i], shenandoahKnown[i++]); } diff --git a/parser/src/test/java/com/microsoft/gctoolkit/parser/diary/TestLogFile.java b/parser/src/test/java/com/microsoft/gctoolkit/parser/diary/TestLogFile.java index 1aba66fc..4d96709e 100644 --- a/parser/src/test/java/com/microsoft/gctoolkit/parser/diary/TestLogFile.java +++ b/parser/src/test/java/com/microsoft/gctoolkit/parser/diary/TestLogFile.java @@ -5,9 +5,7 @@ import java.io.File; import java.util.Arrays; -/** - * Abstract the log files location and provide some parsing of the file name scheme. - */ +/// Abstract the log files location and provide some parsing of the file name scheme. public class TestLogFile { private final File logFile; diff --git a/parser/src/test/java/com/microsoft/gctoolkit/parser/diary/VerboseLogDiaryTest.java b/parser/src/test/java/com/microsoft/gctoolkit/parser/diary/VerboseLogDiaryTest.java index 8f670aeb..cdabb3bd 100644 --- a/parser/src/test/java/com/microsoft/gctoolkit/parser/diary/VerboseLogDiaryTest.java +++ b/parser/src/test/java/com/microsoft/gctoolkit/parser/diary/VerboseLogDiaryTest.java @@ -8,7 +8,7 @@ public class VerboseLogDiaryTest extends LogDiaryTest { @Test public void testForVerbose() { - int i = 0; + var i = 0; for (String name : verbose) { testWith(new TestLogFile("verbose/" + name).getFile(), name, verboseDiary[i], verboseUnknown[i], verboseKnown[i++]); } @@ -16,7 +16,7 @@ public void testForVerbose() { @Test public void testForVerboseTenuring() { - int i = 0; + var i = 0; for (String name : verboseTenuring) { testWith(new TestLogFile("verbose/tenuring/" + name).getFile(), name, verboseTenuringDiary[i], verboseTenuringUnknown[i], verboseTenuringKnown[i++]); } diff --git a/parser/src/test/java/com/microsoft/gctoolkit/parser/diary/ZGCLogDiaryTest.java b/parser/src/test/java/com/microsoft/gctoolkit/parser/diary/ZGCLogDiaryTest.java index 0184d754..e4e86e19 100644 --- a/parser/src/test/java/com/microsoft/gctoolkit/parser/diary/ZGCLogDiaryTest.java +++ b/parser/src/test/java/com/microsoft/gctoolkit/parser/diary/ZGCLogDiaryTest.java @@ -9,7 +9,7 @@ public class ZGCLogDiaryTest extends LogDiaryTest { @Test public void testForZGCLogDiaryPickups() { - int i = 0; + var i = 0; for (String name : zgcLogs) { testWith(new TestLogFile("zgc/" + name).getFile(), name, zgcDiary[i], zgcUnknown[i], zgcKnown[i++]); } diff --git a/parser/src/test/java/com/microsoft/gctoolkit/parser/jvm/DecoratorsTest.java b/parser/src/test/java/com/microsoft/gctoolkit/parser/jvm/DecoratorsTest.java index 19eef5e1..789a63f0 100644 --- a/parser/src/test/java/com/microsoft/gctoolkit/parser/jvm/DecoratorsTest.java +++ b/parser/src/test/java/com/microsoft/gctoolkit/parser/jvm/DecoratorsTest.java @@ -42,23 +42,21 @@ public class DecoratorsTest { "[2018-04-04T09:10:00.586-0100][0.018s][1522825800586ms][18ms][10026341461044ns][17738937ns][1375][7427][info][gc] Using G1" }; - /** - * In lines at 0, there are 0 decorators - * In lines at 1, there is 1 decorator - * In lines at 2, there are 2 decorators - * ... - */ + /// In lines at 0, there are 0 decorators + /// In lines at 1, there is 1 decorator + /// In lines at 2, there are 2 decorators + /// ... @Test public void decoratorsCounts() { - for (int i = 0; i < decoratorsLines.length; i++) { - Decorators decorators = new Decorators(decoratorsLines[i]); + for (var i = 0; i < decoratorsLines.length; i++) { + var decorators = new Decorators(decoratorsLines[i]); assertEquals(i, decorators.getNumberOfDecorators()); } } @Test public void checkEachValue() { - Decorators decorators = new Decorators(decoratorsLines[decoratorsLines.length - 1]); + var decorators = new Decorators(decoratorsLines[decoratorsLines.length - 1]); assertEquals(ZonedDateTime.parse("2018-04-04T09:10:00.586-01:00"), decorators.getDateStamp()); assertEquals(18, (int) (decorators.getUpTime() * 1000.0d)); assertEquals(1522825800586L, decorators.getTimeMillis()); @@ -73,7 +71,7 @@ public void checkEachValue() { @Test public void decoratorValues() { - Decorators decorators = new Decorators(decoratorsValuesTestSupport[0]); + var decorators = new Decorators(decoratorsValuesTestSupport[0]); assertEquals(1522825800586L, decorators.getTimeMillis(), "timestamp -> "); assertEquals(10026341461044L, decorators.getTimeNano(), "timestamp -> "); decorators = new Decorators(decoratorsValuesTestSupport[1]); @@ -475,8 +473,8 @@ public void decoratorValues() { @Test public void LogFragmentTest() { - for ( int index = 0; index < logFragment.length; index++) { - Decorators decorators = new Decorators(logFragment[index]); + for ( var index = 0; index < logFragment.length; index++) { + var decorators = new Decorators(logFragment[index]); // compare uptime assertEquals(expectedTimeStamps[index],decorators.getUpTime()); diff --git a/parser/src/test/java/com/microsoft/gctoolkit/parser/patterns/G1GCPatternsTest.java b/parser/src/test/java/com/microsoft/gctoolkit/parser/patterns/G1GCPatternsTest.java index 8a7bc7fe..bf4f7361 100644 --- a/parser/src/test/java/com/microsoft/gctoolkit/parser/patterns/G1GCPatternsTest.java +++ b/parser/src/test/java/com/microsoft/gctoolkit/parser/patterns/G1GCPatternsTest.java @@ -19,16 +19,16 @@ public class G1GCPatternsTest implements G1GCPatterns { @Test public void testParallelParseRules() { - for (int i = 0; i < rules.length; i++) - for (int j = 0; j < lines.length; j++) { - int captured = captureTest(rules[i], lines[j]); + for (var i = 0; i < rules.length; i++) + for (var j = 0; j < lines.length; j++) { + var captured = captureTest(rules[i], lines[j]); if (i == j) { assertEquals( lines[j].length, captured, rules[i].getName() + " failed to captured it's lines"); } else { if ( captured != 0) - for( int k = 0; k < lines[j].length; k++) { + for( var k = 0; k < lines[j].length; k++) { rules[i].parse(lines[j][k]).notYetImplemented(); - System.out.println(lines[j][k]); + IO.println(lines[j][k]); } assertEquals(0, captured, rules[i].getName() + " captured data from group " + j); } diff --git a/parser/src/test/java/com/microsoft/gctoolkit/parser/patterns/GCCausePatternTest.java b/parser/src/test/java/com/microsoft/gctoolkit/parser/patterns/GCCausePatternTest.java index 50f3ed8e..02d796d1 100644 --- a/parser/src/test/java/com/microsoft/gctoolkit/parser/patterns/GCCausePatternTest.java +++ b/parser/src/test/java/com/microsoft/gctoolkit/parser/patterns/GCCausePatternTest.java @@ -74,18 +74,18 @@ public class GCCausePatternTest implements GenericTokens { @Test public void matchesAllGCCauses() { - String local = "\\([G1,A-Z,a-z, ,-,.gc\\(\\)]+\\)"; + var local = "\\([G1,A-Z,a-z, ,-,.gc\\(\\)]+\\)"; //\([G1,A-Z,a-z, ,-]+\) //GCParseRule cause = new GCParseRule("GC_CAUSE", local); - GCParseRule cause = new GCParseRule("GC_CAUSE", GC_CAUSE); - for (int i = 0; i < gcCauses.length; i++) { + var cause = new GCParseRule("GC_CAUSE", GC_CAUSE); + for (var i = 0; i < gcCauses.length; i++) { assertNotNull(cause.parse(gcCauses[i])); } } @Test public void onlyMatchCause() { - GCParseRule cause = new GCParseRule("GC_CAUSE", GC_CAUSE); + var cause = new GCParseRule("GC_CAUSE", GC_CAUSE); for (String s : extraText) { GCLogTrace trace = cause.parse(s); assertNotNull(trace); diff --git a/parser/src/test/java/com/microsoft/gctoolkit/parser/unittests/CMSParNewParserTest.java b/parser/src/test/java/com/microsoft/gctoolkit/parser/unittests/CMSParNewParserTest.java index 2a45703f..e8c04354 100644 --- a/parser/src/test/java/com/microsoft/gctoolkit/parser/unittests/CMSParNewParserTest.java +++ b/parser/src/test/java/com/microsoft/gctoolkit/parser/unittests/CMSParNewParserTest.java @@ -14,7 +14,7 @@ public class CMSParNewParserTest extends ParserTest { @Test public void testForSimpleLogs() { - int i = 0; + var i = 0; for (String name : simple) { try { Path path = new TestLogFile("cms/" + name).getFile().toPath(); @@ -44,7 +44,7 @@ public void testForSimpleLogs() { @Test public void testForDetails() { - int i = 0; + var i = 0; for (String name : details) { try { Path path = new TestLogFile("cms/parnew/details/" + name).getFile().toPath(); @@ -100,7 +100,7 @@ public void testForDetails() { @Test public void testForDetailsGCCause170() { - int i = 0; + var i = 0; for (String name : detailsGCCause170) { try { Path path = new TestLogFile("cms/parnew/details/gccause/170/" + name).getFile().toPath(); @@ -131,7 +131,7 @@ public void testForDetailsGCCause170() { @Test public void testForDetailsTenuring() { - int i = 0; + var i = 0; for (String name : detailsTenuring) { try { Path path = new TestLogFile("cms/parnew/details/tenuring/" + name).getFile().toPath(); @@ -213,7 +213,7 @@ public void testForDetailsTenuring() { @Test public void testForDefNewDetails() { - int i = 0; + var i = 0; for (String name : defNewDetailsLog) { try { Path path = new TestLogFile("cms/defnew/details/" + name).getFile().toPath(); @@ -241,7 +241,7 @@ public void testForDefNewDetails() { @Test public void testForParNewDetailsTenuringReference80() { - int i = 0; + var i = 0; for (String name : parNewDetailsTenuringReference180) { try { Path path = new TestLogFile("cms/parnew/details/tenuring/180/" + name).getFile().toPath(); @@ -270,7 +270,7 @@ public void testForParNewDetailsTenuringReference80() { @Test public void testForBrokenGCLockerWithTLAB() { - int i = 0; + var i = 0; for (String name : parNewDetailsTenuringTLAB) { try { Path path = new TestLogFile("cms/parnew/details/tenuring/tlab/" + name).getFile().toPath(); diff --git a/parser/src/test/java/com/microsoft/gctoolkit/parser/unittests/G1GCMetaspaceTest.java b/parser/src/test/java/com/microsoft/gctoolkit/parser/unittests/G1GCMetaspaceTest.java index 18f7ebfe..94f428f3 100644 --- a/parser/src/test/java/com/microsoft/gctoolkit/parser/unittests/G1GCMetaspaceTest.java +++ b/parser/src/test/java/com/microsoft/gctoolkit/parser/unittests/G1GCMetaspaceTest.java @@ -15,7 +15,7 @@ public class G1GCMetaspaceTest extends ParserTest { @Test public void countMetaspaceRecordsTest() { - int i = 0; + var i = 0; for (String name : details) { try { Path path = new TestLogFile("g1gc/details/" + name).getFile().toPath(); diff --git a/parser/src/test/java/com/microsoft/gctoolkit/parser/unittests/ICMSParNewParserTest.java b/parser/src/test/java/com/microsoft/gctoolkit/parser/unittests/ICMSParNewParserTest.java index 25210036..64ce542a 100644 --- a/parser/src/test/java/com/microsoft/gctoolkit/parser/unittests/ICMSParNewParserTest.java +++ b/parser/src/test/java/com/microsoft/gctoolkit/parser/unittests/ICMSParNewParserTest.java @@ -2,17 +2,12 @@ // Licensed under the MIT License. package com.microsoft.gctoolkit.parser.unittests; -import com.microsoft.gctoolkit.parser.GCLogTrace; -import com.microsoft.gctoolkit.parser.GCParseRule; import com.microsoft.gctoolkit.parser.diary.TestLogFile; -import com.microsoft.gctoolkit.time.DateTimeStamp; import org.junit.jupiter.api.Test; import java.io.IOException; import java.nio.file.Path; -import static com.microsoft.gctoolkit.parser.CMSPatterns.*; -import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.fail; public class ICMSParNewParserTest extends ParserTest { @@ -25,7 +20,7 @@ Young, DefNew, ParNew, ParNew (promotion failed), ParNew (concurrent mode failur @Test public void testForSimpleLogs() { - int i = 0; + var i = 0; for (String name : details) { try { Path path = new TestLogFile("icms/details/" + name).getFile().toPath(); @@ -68,7 +63,7 @@ public void testForSimpleLogs() { @Test public void testForDetailsTenuring() { - int i = 0; + var i = 0; for (String name : detailsTenuring) { try { Path path = new TestLogFile("icms/details/tenuring/" + name).getFile().toPath(); @@ -109,7 +104,7 @@ public void testForDetailsTenuring() { @Test public void testForDetailsDebug() { - int i = 0; + var i = 0; for (String name : detailsDebug) { try { Path path = new TestLogFile("icms/details/debug/" + name).getFile().toPath(); diff --git a/parser/src/test/java/com/microsoft/gctoolkit/parser/unittests/ParallelCollectorParserTest.java b/parser/src/test/java/com/microsoft/gctoolkit/parser/unittests/ParallelCollectorParserTest.java index 2e0b3904..6ec93b1a 100644 --- a/parser/src/test/java/com/microsoft/gctoolkit/parser/unittests/ParallelCollectorParserTest.java +++ b/parser/src/test/java/com/microsoft/gctoolkit/parser/unittests/ParallelCollectorParserTest.java @@ -15,7 +15,7 @@ public class ParallelCollectorParserTest extends ParserTest { @Test public void testForDetailsTenuringGCCause170() { - int i = 0; + var i = 0; for ( String name : detailsTenuringGCCause170) { try { Path path = new TestLogFile("ps/details/tenuring/gccause/170/" + name).getFile().toPath(); @@ -45,7 +45,7 @@ public void testForDetailsTenuringGCCause170() { @Test public void testForDetails() { - int i = 0; + var i = 0; for ( String name : details) { try { Path path = new TestLogFile("ps/details/" + name).getFile().toPath(); diff --git a/parser/src/test/java/com/microsoft/gctoolkit/parser/unittests/ParserTest.java b/parser/src/test/java/com/microsoft/gctoolkit/parser/unittests/ParserTest.java index e925e55f..da94b617 100644 --- a/parser/src/test/java/com/microsoft/gctoolkit/parser/unittests/ParserTest.java +++ b/parser/src/test/java/com/microsoft/gctoolkit/parser/unittests/ParserTest.java @@ -34,10 +34,8 @@ public abstract class ParserTest { - /** - * A mapping of GC event types to an index. This supports the counting of events. The tests will compare the - * expected counts against the counts that are captured here. - */ + /// A mapping of GC event types to an index. This supports the counting of events. The tests will compare the + /// expected counts against the counts that are captured here. private final Map collectorNameMapping = Map.ofEntries( Map.entry(GarbageCollectionTypes.Young, 0), Map.entry(GarbageCollectionTypes.DefNew, 1), @@ -89,7 +87,7 @@ private List findGarbageCollector(final int index) { public void analyzeResults(String gcLogName, TestResults testResults, int numberOfDifferentPhases, int[] invocationCounts) { assertEquals(numberOfDifferentPhases, testResults.numberOfDifferentPhases()); - for (int i = 0; i < invocationCounts.length; i++) { + for (var i = 0; i < invocationCounts.length; i++) { assertEquals(invocationCounts[i], testResults.getCount(i), "Phase Count Differs @ " + i + " for " + findGarbageCollector(i) + " in " + gcLogName); } } @@ -125,8 +123,8 @@ TestResults executeParsing(GCLogFile logfile) { TestResults testGenerationalRotatingLogFile(Path path) throws IOException { GCLogFile logfile = loadLogFile(path, true); Diarizer jvmConfiguration = getJVMConfiguration(logfile); - GenerationalHeapParser generationalHeapParser = new GenerationalHeapParser(); - TestResults testResults = new TestResults(); + var generationalHeapParser = new GenerationalHeapParser(); + var testResults = new TestResults(); generationalHeapParser.publishTo(testResults); generationalHeapParser.diary(jvmConfiguration.getDiary()); logfile.stream().map(String::trim).forEach(generationalHeapParser::receive); @@ -136,8 +134,8 @@ TestResults testGenerationalRotatingLogFile(Path path) throws IOException { TestResults testGenerationalSingleLogFile(Path path) throws IOException { GCLogFile logfile = loadLogFile(path, false); Diarizer jvmConfiguration = getJVMConfiguration(logfile); - GCLogParser generationalHeapParser = (jvmConfiguration.getDiary().isUnifiedLogging()) ? new UnifiedGenerationalParser() : new GenerationalHeapParser(); - TestResults testResults = new TestResults(); + GCLogParser generationalHeapParser = jvmConfiguration.getDiary().isUnifiedLogging() ? new UnifiedGenerationalParser() : new GenerationalHeapParser(); + var testResults = new TestResults(); generationalHeapParser.publishTo(testResults); generationalHeapParser.diary(jvmConfiguration.getDiary()); logfile.stream().map(String::trim).forEach(generationalHeapParser::receive); @@ -145,10 +143,10 @@ TestResults testGenerationalSingleLogFile(Path path) throws IOException { } TestResults testUnifiedG1GCSingleFile(Path path) throws IOException { - SingleGCLogFile logfile = new SingleGCLogFile(path); + var logfile = new SingleGCLogFile(path); Diarizer jvmConfiguration = getJVMConfiguration(logfile); - UnifiedG1GCParser parser = new UnifiedG1GCParser(); - TestResults testResults = new TestResults(); + var parser = new UnifiedG1GCParser(); + var testResults = new TestResults(); parser.publishTo(testResults); parser.diary(jvmConfiguration.getDiary()); logfile.stream().map(String::trim).forEach(parser::receive); @@ -159,8 +157,8 @@ TestResults testRegionalRotatingLogFile(Path path) throws IOException { GCLogFile logfile = loadLogFile(path, true); Diarizer jvmConfiguration = getJVMConfiguration(logfile); logfile.stream().map(String::trim).forEach(jvmConfiguration::diarize); - PreUnifiedG1GCParser parser = new PreUnifiedG1GCParser(); - TestResults testResults = new TestResults(); + var parser = new PreUnifiedG1GCParser(); + var testResults = new TestResults(); parser.publishTo(testResults); parser.diary(jvmConfiguration.getDiary()); logfile.stream().map(String::trim).forEach(parser::receive); @@ -170,17 +168,15 @@ TestResults testRegionalRotatingLogFile(Path path) throws IOException { TestResults testRegionalSingleLogFile(Path path) throws IOException { GCLogFile logfile = loadLogFile(path, false); Diarizer jvmConfiguration = getJVMConfiguration(logfile); - PreUnifiedG1GCParser parser = new PreUnifiedG1GCParser(); - TestResults testResults = new TestResults(); + var parser = new PreUnifiedG1GCParser(); + var testResults = new TestResults(); parser.publishTo(testResults); parser.diary(jvmConfiguration.getDiary()); logfile.stream().map(String::trim).forEach(parser::receive); return testResults; } - /** - * Setups an array of counts that is indexed by the type of GC event. - */ + /// Setups an array of counts that is indexed by the type of GC event. class TestResults implements JVMEventChannel { private final int[] counts = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 , 0, 0, 0, 0, 0}; @@ -191,7 +187,7 @@ public int getCount(int index) { } public int numberOfDifferentPhases() { - int count = 0; + var count = 0; for (int j : counts) if (j > 0) count++; @@ -207,18 +203,16 @@ public void registerListener(JVMEventChannelListener listener) { throw new IllegalStateException("Listener not used for testing"); } - /** - * Counts by the type of the incoming event. - * @param event - */ + /// Counts by the type of the incoming event. + /// @param event @Override public void publish(ChannelName channel, JVMEvent event) { if (!(event instanceof JVMTermination)) { - GCEvent gcEvent = (GCEvent) event; - int index = collectorNameMapping.get(gcEvent.getGarbageCollectionType()); + var gcEvent = (GCEvent) event; + var index = collectorNameMapping.get(gcEvent.getGarbageCollectionType()); counts[index] = counts[index] + 1; - if (event instanceof G1GCPauseEvent) { - if (((G1GCPauseEvent) event).getPermOrMetaspace() != null) + if (event instanceof G1GCPauseEvent pauseEvent) { + if (pauseEvent.getPermOrMetaspace() != null) metaSpaceRecordCount++; } } diff --git a/parser/src/test/java/com/microsoft/gctoolkit/parser/unittests/PreunifiedG1GCParserTest.java b/parser/src/test/java/com/microsoft/gctoolkit/parser/unittests/PreunifiedG1GCParserTest.java index 5ef99de1..755db9c0 100644 --- a/parser/src/test/java/com/microsoft/gctoolkit/parser/unittests/PreunifiedG1GCParserTest.java +++ b/parser/src/test/java/com/microsoft/gctoolkit/parser/unittests/PreunifiedG1GCParserTest.java @@ -14,7 +14,7 @@ public class PreunifiedG1GCParserTest extends ParserTest { @Test public void testForSolarisLogs() { - int i = 0; + var i = 0; for (String name : solaris) { try { Path path = new TestLogFile("g1gc/details/solaris/" + name).getFile().toPath(); @@ -41,7 +41,7 @@ public void testForSolarisLogs() { @Test public void testForDetailsLogs() { - int i = 0; + var i = 0; for (String name : details) { try { Path path = new TestLogFile("g1gc/details/" + name).getFile().toPath(); @@ -75,7 +75,7 @@ public void testForDetailsLogs() { @Test public void testForDetailsTenuringLogs() { - int i = 0; + var i = 0; for (String name : detailsTenuring) { try { Path path = new TestLogFile("g1gc/details/tenuring/" + name).getFile().toPath(); @@ -125,7 +125,7 @@ public void testForDetailsTenuringLogs() { @Test public void testForDetailsReferenceLogs() { - int i = 0; + var i = 0; for (String name : detailsReference) { try { Path path = new TestLogFile("g1gc/details/reference/" + name).getFile().toPath(); diff --git a/parser/src/test/java/com/microsoft/gctoolkit/parser/unittests/UnifiedG1GCParserTest.java b/parser/src/test/java/com/microsoft/gctoolkit/parser/unittests/UnifiedG1GCParserTest.java index ed4e0171..ce1eff18 100644 --- a/parser/src/test/java/com/microsoft/gctoolkit/parser/unittests/UnifiedG1GCParserTest.java +++ b/parser/src/test/java/com/microsoft/gctoolkit/parser/unittests/UnifiedG1GCParserTest.java @@ -14,7 +14,7 @@ public class UnifiedG1GCParserTest extends ParserTest { @Test public void testForDetailsLogs() { - int i = 0; + var i = 0; for (String name : details) { try { Path path = new TestLogFile("g1gc/" + name).getFile().toPath(); diff --git a/parser/src/test/java/com/microsoft/gctoolkit/parser/unittests/UnifiedGenerationalParserTest.java b/parser/src/test/java/com/microsoft/gctoolkit/parser/unittests/UnifiedGenerationalParserTest.java index ac81d721..bc7438b6 100644 --- a/parser/src/test/java/com/microsoft/gctoolkit/parser/unittests/UnifiedGenerationalParserTest.java +++ b/parser/src/test/java/com/microsoft/gctoolkit/parser/unittests/UnifiedGenerationalParserTest.java @@ -14,7 +14,7 @@ public class UnifiedGenerationalParserTest extends ParserTest { @Test public void testForDetailsLogs() { - int i = 0; + var i = 0; for (String name : details) { try { Path path = new TestLogFile("parallel/" + name).getFile().toPath(); @@ -41,7 +41,7 @@ public void testForDetailsLogs() { @Test public void testCMSLogsMissingTimeStamps() { - int i = 0; + var i = 0; for (String name : cms) { try { Path path = new TestLogFile("cms/" + name).getFile().toPath(); @@ -69,7 +69,7 @@ public void testCMSLogsMissingTimeStamps() { //Serial @Test public void testSerialLogs() { - int i = 0; + var i = 0; for (String name : serial) { try { Path path = new TestLogFile("serial/" + name).getFile().toPath(); diff --git a/parser/src/test/java/com/microsoft/gctoolkit/parser/vmops/SafepointPatternsTest.java b/parser/src/test/java/com/microsoft/gctoolkit/parser/vmops/SafepointPatternsTest.java index 6fd0f2ed..83bde0cf 100644 --- a/parser/src/test/java/com/microsoft/gctoolkit/parser/vmops/SafepointPatternsTest.java +++ b/parser/src/test/java/com/microsoft/gctoolkit/parser/vmops/SafepointPatternsTest.java @@ -36,7 +36,7 @@ public void testSafepointPatternsRules() { "FindDeadlocks" }; - int index = 0; + var index = 0; for (String line : lines) { Safepoint safepoint = TRACE.parse(line).toSafepoint(); assertNotNull(safepoint); diff --git a/pom.xml b/pom.xml index 554d6e94..2f0f782d 100644 --- a/pom.xml +++ b/pom.xml @@ -52,15 +52,15 @@ 3.0.0-M3 3.6.0 3.5.0 - 3.14.0 - 11 + 3.15.0 + 25 3.8.1 3.1.4 1.0 3.6.1 3.5.1 3.1.4 - 0.8.13 + 0.8.15 3.4.2 3.11.2 3.6.0 @@ -72,8 +72,8 @@ 3.3.1 4.0.0-M16 3.3.1 - 4.9.3.2 - 3.5.3 + 4.9.8.5 + 3.5.6 3.9.11 2.18.0 0.9.1 @@ -82,6 +82,7 @@ microsoft/gctoolkit git@github.com:${project.github.repository}.git 4.9.3 + 1.0.0 @@ -124,6 +125,12 @@ gctoolkit-gclogs ${project.version} + + org.jspecify + jspecify + ${jspecify.version} + provided + org.junit.jupiter junit-jupiter-engine @@ -185,12 +192,11 @@ maven-compiler-plugin ${maven.compiler-plugin.version} - {maven.compiler.release} - {maven.compiler.release} --module-version=${project.version} -Xlint:unchecked + 25 diff --git a/sample/pom.xml b/sample/pom.xml index 98970683..83548a8b 100644 --- a/sample/pom.xml +++ b/sample/pom.xml @@ -29,6 +29,10 @@ com.microsoft.gctoolkit gctoolkit-vertx + + + org.jspecify + jspecify org.junit.jupiter diff --git a/sample/src/main/java/com/microsoft/gctoolkit/sample/Main.java b/sample/src/main/java/com/microsoft/gctoolkit/sample/Main.java index 0897c15f..374daa00 100644 --- a/sample/src/main/java/com/microsoft/gctoolkit/sample/Main.java +++ b/sample/src/main/java/com/microsoft/gctoolkit/sample/Main.java @@ -15,7 +15,7 @@ public class Main { - public static void main(String[] args) throws IOException { + void main(String[] args) throws IOException { String userInput = args.length > 0 ? args[0] : ""; String gcLogFile = System.getProperty("gcLogFile", userInput); @@ -24,10 +24,10 @@ public static void main(String[] args) throws IOException { } if (Files.notExists(Path.of(gcLogFile))) { - throw new IllegalArgumentException(String.format("File %s not found.", gcLogFile)); + throw new IllegalArgumentException("File %s not found.".formatted(gcLogFile)); } - Main main = new Main(); + var main = new Main(); main.analyze(gcLogFile); } @@ -38,7 +38,7 @@ public void analyze(String gcLogFile) throws IOException { * The log files can be either in text, zip, or gzip format. */ GCLogFile logFile = new SingleGCLogFile(Path.of(gcLogFile)); - GCToolKit gcToolKit = new GCToolKit(); + var gcToolKit = new GCToolKit(); /** * This call will load all implementations of Aggregator that have been declared in module-info.java. @@ -53,10 +53,10 @@ public void analyze(String gcLogFile) throws IOException { JavaVirtualMachine machine = gcToolKit.analyze(logFile); // Retrieves the Aggregation for HeapOccupancyAfterCollectionSummary. This is a time-series aggregation. - String message = "The XYDataSet for %s contains %s items.\n"; + var message = "The XYDataSet for %s contains %s items.\n"; machine.getAggregation(HeapOccupancyAfterCollectionSummary.class) .map(HeapOccupancyAfterCollectionSummary::get) - .ifPresent(summary -> { + .ifPresent(summary -> summary.forEach((gcType, dataSet) -> { System.out.printf(message, gcType, dataSet.size()); switch (gcType) { @@ -70,13 +70,12 @@ public void analyze(String gcLogFile) throws IOException { remarkCount = dataSet.size(); break; default: - System.out.println(gcType + " not managed"); + IO.println(gcType + " not managed"); break; } - }); - }); + })); - Optional summary = machine.getAggregation(CollectionCycleCountsSummary.class); + var summary = machine.getAggregation(CollectionCycleCountsSummary.class); summary.ifPresent(s -> s.printOn(System.out)); // Retrieves the Aggregation for PauseTimeSummary. This is a com.microsoft.gctoolkit.sample.aggregation.RuntimeAggregation. machine.getAggregation(PauseTimeSummary.class).ifPresent(pauseTimeSummary -> { diff --git a/sample/src/main/java/com/microsoft/gctoolkit/sample/aggregation/CollectionCycleCountsSummary.java b/sample/src/main/java/com/microsoft/gctoolkit/sample/aggregation/CollectionCycleCountsSummary.java index 74ae2c3b..acf18bfd 100644 --- a/sample/src/main/java/com/microsoft/gctoolkit/sample/aggregation/CollectionCycleCountsSummary.java +++ b/sample/src/main/java/com/microsoft/gctoolkit/sample/aggregation/CollectionCycleCountsSummary.java @@ -13,7 +13,7 @@ public class CollectionCycleCountsSummary extends CollectionCycleCountsAggregati @Override public void count(GarbageCollectionTypes gcType) { - collectionCycleCounts.computeIfAbsent(gcType, key -> new AtomicInteger()).incrementAndGet(); + collectionCycleCounts.computeIfAbsent(gcType, _ -> new AtomicInteger()).incrementAndGet(); } private static final String FORMAT = "%s : %s%n"; diff --git a/sample/src/main/java/com/microsoft/gctoolkit/sample/aggregation/HeapOccupancyAfterCollectionSummary.java b/sample/src/main/java/com/microsoft/gctoolkit/sample/aggregation/HeapOccupancyAfterCollectionSummary.java index be32bfc9..383dfda2 100644 --- a/sample/src/main/java/com/microsoft/gctoolkit/sample/aggregation/HeapOccupancyAfterCollectionSummary.java +++ b/sample/src/main/java/com/microsoft/gctoolkit/sample/aggregation/HeapOccupancyAfterCollectionSummary.java @@ -13,8 +13,9 @@ public class HeapOccupancyAfterCollectionSummary extends HeapOccupancyAfterColle public HeapOccupancyAfterCollectionSummary() {} + @Override public void addDataPoint(GarbageCollectionTypes gcType, DateTimeStamp timeStamp, long heapOccupancy) { - aggregations.computeIfAbsent(gcType, key -> new XYDataSet()).add(timeStamp.getTimeStamp(),heapOccupancy); + aggregations.computeIfAbsent(gcType, _ -> new XYDataSet()).add(timeStamp.getTimeStamp(),heapOccupancy); } public Map get() { diff --git a/sample/src/main/java/com/microsoft/gctoolkit/sample/aggregation/PauseTimeAggregation.java b/sample/src/main/java/com/microsoft/gctoolkit/sample/aggregation/PauseTimeAggregation.java index 8b64cdd8..4d159a25 100644 --- a/sample/src/main/java/com/microsoft/gctoolkit/sample/aggregation/PauseTimeAggregation.java +++ b/sample/src/main/java/com/microsoft/gctoolkit/sample/aggregation/PauseTimeAggregation.java @@ -3,15 +3,11 @@ import com.microsoft.gctoolkit.aggregator.Aggregation; import com.microsoft.gctoolkit.aggregator.Collates; -/** - * API for an Aggregation that records pause time duration. A - * PauseTimeAggregation gets its data from a PauseTimeAggregator. - */ +/// API for an Aggregation that records pause time duration. A +/// PauseTimeAggregation gets its data from a PauseTimeAggregator. @Collates(PauseTimeAggregator.class) public abstract class PauseTimeAggregation extends Aggregation { - /** - * Record the duration of a pause event. This method is called from PauseTimeAggregator. - * @param duration The duration (in decimal seconds) of a GC pause. - */ + /// Record the duration of a pause event. This method is called from PauseTimeAggregator. + /// @param duration The duration (in decimal seconds) of a GC pause. public abstract void recordPauseDuration(double duration); } diff --git a/sample/src/main/java/com/microsoft/gctoolkit/sample/aggregation/PauseTimeAggregator.java b/sample/src/main/java/com/microsoft/gctoolkit/sample/aggregation/PauseTimeAggregator.java index 14404ff6..cccaa184 100644 --- a/sample/src/main/java/com/microsoft/gctoolkit/sample/aggregation/PauseTimeAggregator.java +++ b/sample/src/main/java/com/microsoft/gctoolkit/sample/aggregation/PauseTimeAggregator.java @@ -3,12 +3,9 @@ import com.microsoft.gctoolkit.aggregator.Aggregates; import com.microsoft.gctoolkit.aggregator.Aggregator; import com.microsoft.gctoolkit.aggregator.EventSource; -import com.microsoft.gctoolkit.event.g1gc.G1GCConcurrentEvent; import com.microsoft.gctoolkit.event.g1gc.G1GCPauseEvent; -/** - * An Aggregator that extracts pause time. - */ +/// An Aggregator that extracts pause time. @Aggregates({EventSource.G1GC}) public class PauseTimeAggregator extends Aggregator { diff --git a/sample/src/main/java/com/microsoft/gctoolkit/sample/aggregation/PauseTimeSummary.java b/sample/src/main/java/com/microsoft/gctoolkit/sample/aggregation/PauseTimeSummary.java index c05d016e..339ba03f 100644 --- a/sample/src/main/java/com/microsoft/gctoolkit/sample/aggregation/PauseTimeSummary.java +++ b/sample/src/main/java/com/microsoft/gctoolkit/sample/aggregation/PauseTimeSummary.java @@ -1,11 +1,9 @@ package com.microsoft.gctoolkit.sample.aggregation; -/** - * An implementation of PauseTimeAggregation which simply accumulates pause times, and - * provides methods for getting the total pause time and the percentage of time the - * application was paused. This is an instance of RuntimeAggregation, which gives us - * the run time represented by the GC log. - */ +/// An implementation of PauseTimeAggregation which simply accumulates pause times, and +/// provides methods for getting the total pause time and the percentage of time the +/// application was paused. This is an instance of RuntimeAggregation, which gives us +/// the run time represented by the GC log. public class PauseTimeSummary extends PauseTimeAggregation { private double totalPauseTime; @@ -25,18 +23,14 @@ public void recordPauseDuration(double duration) { totalPauseTime += duration; } - /** - * Get the total amount of time the application was paused for garbage collection. - * @return The total pause time. - */ + /// Get the total amount of time the application was paused for garbage collection. + /// @return The total pause time. public double getTotalPauseTime() { return totalPauseTime; } - /** - * Get the amount of time the application was paused as a percentage of total runtime. - * @return The percentage of time the application was paused. - */ + /// Get the amount of time the application was paused as a percentage of total runtime. + /// @return The percentage of time the application was paused. public double getPercentPaused() { return (totalPauseTime / super.estimatedRuntime()) * 100.0D; } diff --git a/sample/src/main/java/com/microsoft/gctoolkit/sample/collections/XYDataSet.java b/sample/src/main/java/com/microsoft/gctoolkit/sample/collections/XYDataSet.java index d304ad31..89971860 100644 --- a/sample/src/main/java/com/microsoft/gctoolkit/sample/collections/XYDataSet.java +++ b/sample/src/main/java/com/microsoft/gctoolkit/sample/collections/XYDataSet.java @@ -34,25 +34,21 @@ public boolean isEmpty() { return dataSeries.isEmpty(); } - /** - * Returns an immutable List of the items in this DataSet. - */ + /// Returns an immutable List of the items in this DataSet. public List getItems() { return List.copyOf(dataSeries); } public XYDataSet scaleSeries(double scaleFactor) { - XYDataSet scaled = new XYDataSet(); + var scaled = new XYDataSet(); for (Point item : dataSeries) { scaled.add(item.getX(), item.getY().doubleValue() * scaleFactor); } return scaled; } - /** - * Returns the largest Y value in the XYDataSet as an OptionalDouble, - * with an empty optional if the dataset is empty. - */ + /// Returns the largest Y value in the XYDataSet as an OptionalDouble, + /// with an empty optional if the dataset is empty. public OptionalDouble maxOfY() { return dataSeries.stream() .map(Point::getY) @@ -61,9 +57,9 @@ public OptionalDouble maxOfY() { } public XYDataSet scaleAndTranslateXAxis(double scale, double offset) { - XYDataSet translatedSeries = new XYDataSet(); + var translatedSeries = new XYDataSet(); for (Point dataPoint : dataSeries) { - double scaledXCoordinate = (scale * dataPoint.getX().doubleValue()) + offset; + var scaledXCoordinate = (scale * dataPoint.getX().doubleValue()) + offset; translatedSeries.add(scaledXCoordinate, dataPoint.getY()); } return translatedSeries; diff --git a/sample/src/main/java/module-info.java b/sample/src/main/java/module-info.java index ccbf78cf..225a9bba 100644 --- a/sample/src/main/java/module-info.java +++ b/sample/src/main/java/module-info.java @@ -7,6 +7,7 @@ module com.microsoft.gctoolkit.sample { requires com.microsoft.gctoolkit.api; requires java.logging; + requires transitive org.jspecify; exports com.microsoft.gctoolkit.sample; diff --git a/sample/src/test/java/com/microsoft/gctoolkit/sample/aggregation/HeapOccupancyAfterCollectionTest.java b/sample/src/test/java/com/microsoft/gctoolkit/sample/aggregation/HeapOccupancyAfterCollectionTest.java index badc1c62..bea45a54 100644 --- a/sample/src/test/java/com/microsoft/gctoolkit/sample/aggregation/HeapOccupancyAfterCollectionTest.java +++ b/sample/src/test/java/com/microsoft/gctoolkit/sample/aggregation/HeapOccupancyAfterCollectionTest.java @@ -16,9 +16,9 @@ class HeapOccupancyAfterCollectionTest { @Test void ignoresGenerationalEventsWithoutHeapSummary() { - HeapOccupancyAfterCollectionSummary summary = new HeapOccupancyAfterCollectionSummary(); - HeapOccupancyAfterCollection aggregator = new HeapOccupancyAfterCollection(summary); - DefNew event = new DefNew(new DateTimeStamp(1.0d), GCCause.ALLOCATION_FAILURE, 1.0d); + var summary = new HeapOccupancyAfterCollectionSummary(); + var aggregator = new HeapOccupancyAfterCollection(summary); + var event = new DefNew(new DateTimeStamp(1.0d), GCCause.ALLOCATION_FAILURE, 1.0d); assertDoesNotThrow(() -> aggregator.receive(event)); @@ -27,9 +27,9 @@ void ignoresGenerationalEventsWithoutHeapSummary() { @Test void ignoresZgcEventsWithoutMemorySummary() { - HeapOccupancyAfterCollectionSummary summary = new HeapOccupancyAfterCollectionSummary(); - HeapOccupancyAfterCollection aggregator = new HeapOccupancyAfterCollection(summary); - ZGCYoungCollection event = new ZGCYoungCollection( + var summary = new HeapOccupancyAfterCollectionSummary(); + var aggregator = new HeapOccupancyAfterCollection(summary); + var event = new ZGCYoungCollection( new DateTimeStamp(1.0d), GarbageCollectionTypes.ZGCMinorYoung, GCCause.ALLOCATION_FAILURE, diff --git a/vertx/pom.xml b/vertx/pom.xml index 21097c1c..bd87e3c1 100644 --- a/vertx/pom.xml +++ b/vertx/pom.xml @@ -24,6 +24,10 @@ vertx-core 5.0.12 + + org.jspecify + jspecify + org.junit.jupiter junit-jupiter-api diff --git a/vertx/src/main/java/com/microsoft/gctoolkit/vertx/DataSourceVerticle.java b/vertx/src/main/java/com/microsoft/gctoolkit/vertx/DataSourceVerticle.java index 354ea153..6c335da2 100644 --- a/vertx/src/main/java/com/microsoft/gctoolkit/vertx/DataSourceVerticle.java +++ b/vertx/src/main/java/com/microsoft/gctoolkit/vertx/DataSourceVerticle.java @@ -2,7 +2,6 @@ // Licensed under the MIT License. package com.microsoft.gctoolkit.vertx; -import com.microsoft.gctoolkit.io.GCLogFile; import com.microsoft.gctoolkit.message.DataSourceChannelListener; import io.vertx.core.AbstractVerticle; import io.vertx.core.Promise; @@ -11,9 +10,7 @@ import java.util.logging.Level; import java.util.logging.Logger; -/** - * A Vert.x verticle for handling data source messages. - */ +/// A Vert.x verticle for handling data source messages. public class DataSourceVerticle extends AbstractVerticle { // Logger for the DataSourceVerticle class. @@ -28,30 +25,24 @@ public class DataSourceVerticle extends AbstractVerticle { // Listener for processing data source messages. final private DataSourceChannelListener processor; - /** - * Constructor for DataSourceVerticle. - * @param vertx the Vert.x instance. - * @param channelName the name of the channel. - * @param listener the listener for processing data source messages. - */ + /// Constructor for DataSourceVerticle. + /// @param vertx the Vert.x instance. + /// @param channelName the name of the channel. + /// @param listener the listener for processing data source messages. public DataSourceVerticle(Vertx vertx, String channelName, DataSourceChannelListener listener) { this.vertx = vertx; this.inbox = channelName; this.processor = listener; } - /** - * Sets the ID of the verticle. - * @param id the ID to set. - */ + /// Sets the ID of the verticle. + /// @param id the ID to set. public void setID(String id) { this.id = id; } - /** - * Starts the verticle and sets up the event bus consumer for data source messages. - * @param promise the promise to complete when the verticle is started. - */ + /// Starts the verticle and sets up the event bus consumer for data source messages. + /// @param promise the promise to complete when the verticle is started. @Override public void start(Promise promise) { try { @@ -59,17 +50,15 @@ public void start(Promise promise) { processor.receive(message.body()); // Removed vertx.undeploy(id) to avoid double-undeploy }).completion() - .onComplete(ar -> promise.complete()); + .onComplete(_ -> promise.complete()); } catch(Throwable t) { LOGGER.log(Level.WARNING,"Vertx: processing DataSource failed",t); } } - /** - * Checks if this verticle is equal to another object. - * @param other the other object to compare. - * @return true if the objects are equal, false otherwise. - */ + /// Checks if this verticle is equal to another object. + /// @param other the other object to compare. + /// @return true if the objects are equal, false otherwise. @Override public boolean equals(Object other) { // we want Object.equals(other) because it's ok to have more than 1 AggregatorEngine on the bus @@ -77,10 +66,8 @@ public boolean equals(Object other) { return this == other; } - /** - * Returns the hash code of this verticle. - * @return the hash code. - */ + /// Returns the hash code of this verticle. + /// @return the hash code. @Override public int hashCode() { // see comment for equals diff --git a/vertx/src/main/java/com/microsoft/gctoolkit/vertx/JVMEventVerticle.java b/vertx/src/main/java/com/microsoft/gctoolkit/vertx/JVMEventVerticle.java index 227eab51..ba15d143 100644 --- a/vertx/src/main/java/com/microsoft/gctoolkit/vertx/JVMEventVerticle.java +++ b/vertx/src/main/java/com/microsoft/gctoolkit/vertx/JVMEventVerticle.java @@ -3,7 +3,6 @@ package com.microsoft.gctoolkit.vertx; import com.microsoft.gctoolkit.event.jvm.JVMEvent; -import com.microsoft.gctoolkit.event.jvm.JVMTermination; import com.microsoft.gctoolkit.message.JVMEventChannelListener; import io.vertx.core.AbstractVerticle; import io.vertx.core.Promise; @@ -12,9 +11,7 @@ import java.util.logging.Level; import java.util.logging.Logger; -/** - * A Vert.x verticle for dispatching JVMEvent. - */ +/// A Vert.x verticle for dispatching JVMEvent. public class JVMEventVerticle extends AbstractVerticle { // Logger for the JVMEventVerticle class. @@ -28,30 +25,24 @@ public class JVMEventVerticle extends AbstractVerticle { // ID of the verticle. private String id; - /** - * Constructor for JVMEventVerticle. - * @param vertx the Vert.x instance. - * @param channelName the name of the channel. - * @param listener the listener for processing JVM events. - */ + /// Constructor for JVMEventVerticle. + /// @param vertx the Vert.x instance. + /// @param channelName the name of the channel. + /// @param listener the listener for processing JVM events. public JVMEventVerticle(Vertx vertx, String channelName, JVMEventChannelListener listener) { this.vertx = vertx; this.inbox = channelName; this.processor = listener; } - /** - * Sets the ID of the verticle. - * @param id the ID to set. - */ + /// Sets the ID of the verticle. + /// @param id the ID to set. public void setID(String id) { this.id = id; } - /** - * Starts the verticle and sets up the event bus consumer for JVM events. - * @param promise the promise to complete when the verticle is started. - */ + /// Starts the verticle and sets up the event bus consumer for JVM events. + /// @param promise the promise to complete when the verticle is started. @Override public void start(Promise promise) { vertx.eventBus().consumer(inbox, message -> { @@ -63,7 +54,7 @@ public void start(Promise promise) { } // Removed vertx.undeploy(id) to avoid double-undeploy }).completion() - .onComplete(ar -> promise.complete()); + .onComplete(_ -> promise.complete()); } @Override diff --git a/vertx/src/main/java/com/microsoft/gctoolkit/vertx/VertxChannel.java b/vertx/src/main/java/com/microsoft/gctoolkit/vertx/VertxChannel.java index f91e821b..cfb5f534 100644 --- a/vertx/src/main/java/com/microsoft/gctoolkit/vertx/VertxChannel.java +++ b/vertx/src/main/java/com/microsoft/gctoolkit/vertx/VertxChannel.java @@ -9,9 +9,7 @@ import java.util.logging.Level; import java.util.logging.Logger; -/** - * A class that represents a Vert.x channel for handling JVM events. - */ +/// A class that represents a Vert.x channel for handling JVM events. public class VertxChannel { // Logger for the VertxChannel class. @@ -29,23 +27,17 @@ public class VertxChannel { vertx.eventBus().registerDefaultCodec(JVMEvent.class, new JVMEventCodec()); } - /** - * Default constructor. - */ + /// Default constructor. protected VertxChannel() { } - /** - * Gets the Vert.x instance. - * @return the Vert.x instance. - */ + /// Gets the Vert.x instance. + /// @return the Vert.x instance. protected Vertx vertx() { return vertx; } - /** - * Closes the Vert.x instance. - */ + /// Closes the Vert.x instance. public void close() { vertx().close() .onComplete(ar -> { diff --git a/vertx/src/main/java/com/microsoft/gctoolkit/vertx/VertxDataSourceChannel.java b/vertx/src/main/java/com/microsoft/gctoolkit/vertx/VertxDataSourceChannel.java index 47ccf54a..b04a515c 100644 --- a/vertx/src/main/java/com/microsoft/gctoolkit/vertx/VertxDataSourceChannel.java +++ b/vertx/src/main/java/com/microsoft/gctoolkit/vertx/VertxDataSourceChannel.java @@ -8,27 +8,21 @@ import java.util.concurrent.CountDownLatch; -/** - * A class that represents a Vert.x data source channel. - * It extends VertxChannel and implements DataSourceChannel. - */ +/// A class that represents a Vert.x data source channel. +/// It extends VertxChannel and implements DataSourceChannel. public class VertxDataSourceChannel extends VertxChannel implements DataSourceChannel { - /** - * Default constructor. - */ + /// Default constructor. public VertxDataSourceChannel() { super(); } - /** - * Registers a listener for the data source channel. - * @param listener the DataSourceParser listener to register. - */ + /// Registers a listener for the data source channel. + /// @param listener the DataSourceParser listener to register. @Override public void registerListener(DataSourceParser listener) { - final DataSourceVerticle processor = new DataSourceVerticle(vertx(), listener.channel().getName(), listener); - CountDownLatch latch = new CountDownLatch(1); + final var processor = new DataSourceVerticle(vertx(), listener.channel().getName(), listener); + var latch = new CountDownLatch(1); vertx().deployVerticle(processor) .onComplete(ar -> { processor.setID(ar.succeeded() ? ar.result() : ""); @@ -36,24 +30,20 @@ public void registerListener(DataSourceParser listener) { }); try { latch.await(); - } catch (InterruptedException e) { + } catch (InterruptedException _) { Thread.interrupted(); } } - /** - * Publishes a message to a specified channel. - * @param channel the channel to publish to. - * @param message the message to publish. - */ + /// Publishes a message to a specified channel. + /// @param channel the channel to publish to. + /// @param message the message to publish. @Override public void publish(ChannelName channel, String message) { vertx().eventBus().publish(channel.getName(), message); } - /** - * Closes the data source channel. - */ + /// Closes the data source channel. @Override public void close() { super.close(); diff --git a/vertx/src/main/java/com/microsoft/gctoolkit/vertx/VertxJVMEventChannel.java b/vertx/src/main/java/com/microsoft/gctoolkit/vertx/VertxJVMEventChannel.java index 77eb0bdc..a41e5200 100644 --- a/vertx/src/main/java/com/microsoft/gctoolkit/vertx/VertxJVMEventChannel.java +++ b/vertx/src/main/java/com/microsoft/gctoolkit/vertx/VertxJVMEventChannel.java @@ -11,30 +11,23 @@ import java.util.concurrent.CountDownLatch; import java.util.logging.Level; -import java.util.logging.Logger; -/** - * A class that represents a Vert.x JVM event channel. - * It extends VertxChannel and implements JVMEventChannel. - */ +/// A class that represents a Vert.x JVM event channel. +/// It extends VertxChannel and implements JVMEventChannel. public class VertxJVMEventChannel extends VertxChannel implements JVMEventChannel { // Delivery options for the event bus, using the JVMEventCodec. final private DeliveryOptions options = new DeliveryOptions().setCodecName(JVMEventCodec.NAME); - /** - * Default constructor. - */ + /// Default constructor. public VertxJVMEventChannel() {} - /** - * Registers a listener for the JVM event channel. - * @param listener the JVMEventChannelListener to register. - */ + /// Registers a listener for the JVM event channel. + /// @param listener the JVMEventChannelListener to register. @Override public void registerListener(JVMEventChannelListener listener) { - final JVMEventVerticle processor = new JVMEventVerticle(vertx(), listener.channel().getName(), listener); - CountDownLatch latch = new CountDownLatch(1); + final var processor = new JVMEventVerticle(vertx(), listener.channel().getName(), listener); + var latch = new CountDownLatch(1); vertx().deployVerticle(processor) .onComplete(ar -> { processor.setID(ar.succeeded() ? ar.result() : ""); @@ -49,11 +42,9 @@ public void registerListener(JVMEventChannelListener listener) { } } - /** - * Publishes a JVM event message to a specified channel. - * @param channel the channel to publish to. - * @param message the JVMEvent message to publish. - */ + /// Publishes a JVM event message to a specified channel. + /// @param channel the channel to publish to. + /// @param message the JVMEvent message to publish. @Override public void publish(ChannelName channel, JVMEvent message) { try { @@ -63,9 +54,7 @@ public void publish(ChannelName channel, JVMEvent message) { } } - /** - * Closes the VertxChannel. - */ + /// Closes the VertxChannel. @Override public void close() { super.close(); diff --git a/vertx/src/main/java/com/microsoft/gctoolkit/vertx/internal/util/concurrent/StartingGun.java b/vertx/src/main/java/com/microsoft/gctoolkit/vertx/internal/util/concurrent/StartingGun.java index 94f16deb..b904cd6a 100644 --- a/vertx/src/main/java/com/microsoft/gctoolkit/vertx/internal/util/concurrent/StartingGun.java +++ b/vertx/src/main/java/com/microsoft/gctoolkit/vertx/internal/util/concurrent/StartingGun.java @@ -2,30 +2,26 @@ import java.util.concurrent.locks.AbstractQueuedSynchronizer; -/** - * A StartingGun for services, where we can wait for one particular service - * to start up. - *

- * Instead of {@link java.util.concurrent.CountDownLatch}, we have a custom - * concurrency utility called StartingGun, which is like a CountDownLatch with - * a count of 1 and where the awaitUninterruptibly() method does not throw an - * exception. Similarly to the CountDownLatch, this uses the - * {@link AbstractQueuedSynchronizer} for the synchronization. - * - * @author Dr Heinz M. Kabutz - */ +/// A StartingGun for services, where we can wait for one particular service +/// to start up. +/// +/// Instead of [java.util.concurrent.CountDownLatch], we have a custom +/// concurrency utility called StartingGun, which is like a CountDownLatch with +/// a count of 1 and where the awaitUninterruptibly() method does not throw an +/// exception. Similarly to the CountDownLatch, this uses the +/// [AbstractQueuedSynchronizer] for the synchronization. +/// +/// @author Dr Heinz M. Kabutz public class StartingGun { private static final int UNUSED = 0; - /** - * Synchronization control For StartingGun. - * Uses AQS state to represent count. - */ + /// Synchronization control For StartingGun. + /// Uses AQS state to represent count. private static final class Sync extends AbstractQueuedSynchronizer { private static final long serialVersionUID = 1L; protected int tryAcquireShared(int unused) { - return (getState() == 1) ? 1 : -1; + return getState() == 1 ? 1 : -1; } protected boolean tryReleaseShared(int unused) { @@ -36,24 +32,18 @@ protected boolean tryReleaseShared(int unused) { private final Sync sync; - /** - * Constructs a {@code StartingGun}. - */ + /// Constructs a `StartingGun`. public StartingGun() { this.sync = new Sync(); } - /** - * Wait for the starting gun to fire, without propagating the - * InterruptedException. - */ + /// Wait for the starting gun to fire, without propagating the + /// InterruptedException. public void awaitUninterruptibly() { sync.acquireShared(UNUSED); } - /** - * Indicate that the service is ready for operation. - */ + /// Indicate that the service is ready for operation. public void ready() { sync.releaseShared(UNUSED); } diff --git a/vertx/src/main/java/module-info.java b/vertx/src/main/java/module-info.java index 04d821ed..1a8fe8de 100644 --- a/vertx/src/main/java/module-info.java +++ b/vertx/src/main/java/module-info.java @@ -9,6 +9,7 @@ requires com.microsoft.gctoolkit.api; requires io.vertx.core; requires java.logging; + requires transitive org.jspecify; provides com.microsoft.gctoolkit.message.DataSourceChannel with com.microsoft.gctoolkit.vertx.VertxDataSourceChannel; provides com.microsoft.gctoolkit.message.JVMEventChannel with com.microsoft.gctoolkit.vertx.VertxJVMEventChannel; diff --git a/vertx/src/test/java/com/microsoft/gctoolkit/vertx/internal/util/concurrent/StartingGunTest.java b/vertx/src/test/java/com/microsoft/gctoolkit/vertx/internal/util/concurrent/StartingGunTest.java index 73a13f16..fd0f88a8 100644 --- a/vertx/src/test/java/com/microsoft/gctoolkit/vertx/internal/util/concurrent/StartingGunTest.java +++ b/vertx/src/test/java/com/microsoft/gctoolkit/vertx/internal/util/concurrent/StartingGunTest.java @@ -13,7 +13,7 @@ public class StartingGunTest { @Test public void testStartingGunNoInterruptions() throws InterruptedException { - StartingGun sg = new StartingGun(); + var sg = new StartingGun(); Thread[] threads = startWaitingThreads(sg); Thread.sleep(PAUSE); @@ -27,7 +27,7 @@ public void testStartingGunNoInterruptions() throws InterruptedException { private Thread[] startWaitingThreads(StartingGun sg) { Thread[] threads = new Thread[10]; - for (int i = 0; i < threads.length; i++) { + for (var i = 0; i < threads.length; i++) { threads[i] = new Thread(sg::awaitUninterruptibly); threads[i].start(); } @@ -36,7 +36,7 @@ private Thread[] startWaitingThreads(StartingGun sg) { @Test public void testAwaitAfterReady() throws InterruptedException { - StartingGun sg = new StartingGun(); + var sg = new StartingGun(); sg.ready(); Thread[] threads = startWaitingThreads(sg); allThreadsDead(threads); @@ -44,9 +44,9 @@ public void testAwaitAfterReady() throws InterruptedException { @Test public void testInterruptedStatus() throws InterruptedException { - StartingGun sg = new StartingGun(); + var sg = new StartingGun(); Thread testingThread = Thread.currentThread(); - Thread thread = new Thread(() -> + var thread = new Thread(() -> { while (testingThread.getState() != Thread.State.WAITING) { Thread.yield(); @@ -67,7 +67,7 @@ public void testInterruptedStatus() throws InterruptedException { @Test public void testMultipleReadyCallsNoInterruptions() throws InterruptedException { - StartingGun sg = new StartingGun(); + var sg = new StartingGun(); Thread[] threads = startWaitingThreads(sg); Thread.sleep(PAUSE); @@ -79,7 +79,7 @@ public void testMultipleReadyCallsNoInterruptions() throws InterruptedException allThreadsDead(threads); threads = new Thread[10]; - for (int i = 0; i < threads.length; i++) { + for (var i = 0; i < threads.length; i++) { threads[i] = new Thread(sg::awaitUninterruptibly); threads[i].start(); } @@ -89,7 +89,7 @@ public void testMultipleReadyCallsNoInterruptions() throws InterruptedException @Test public void testStartingGunInterruptions() throws InterruptedException { - StartingGun sg = new StartingGun(); + var sg = new StartingGun(); Thread[] threads = startWaitingThreads(sg); Thread.sleep(PAUSE); diff --git a/vertx/src/test/java/com/microsoft/gctoolkit/vertx/io/GarbageCollectionEventSourceTest.java b/vertx/src/test/java/com/microsoft/gctoolkit/vertx/io/GarbageCollectionEventSourceTest.java index cb851bbc..6fae7b2c 100644 --- a/vertx/src/test/java/com/microsoft/gctoolkit/vertx/io/GarbageCollectionEventSourceTest.java +++ b/vertx/src/test/java/com/microsoft/gctoolkit/vertx/io/GarbageCollectionEventSourceTest.java @@ -88,8 +88,8 @@ private static void disableCaching() { private void assertExpectedLineCountInLog(int expectedNumberOfLines, GCLogFile logFile) { disableCaching(); - GCLogConsumer consumer = new GCLogConsumer(); - VertxDataSourceChannel channel = new VertxDataSourceChannel(); + var consumer = new GCLogConsumer(); + var channel = new VertxDataSourceChannel(); channel.registerListener(consumer); long[] observedNumberOfLines = {0L}; try { diff --git a/vertx/src/test/java/com/microsoft/gctoolkit/vertx/io/GarbageCollectionLogMetaDataTest.java b/vertx/src/test/java/com/microsoft/gctoolkit/vertx/io/GarbageCollectionLogMetaDataTest.java index 4d81e4e4..344e54e3 100644 --- a/vertx/src/test/java/com/microsoft/gctoolkit/vertx/io/GarbageCollectionLogMetaDataTest.java +++ b/vertx/src/test/java/com/microsoft/gctoolkit/vertx/io/GarbageCollectionLogMetaDataTest.java @@ -32,7 +32,7 @@ public void testPlainTextFile() { public void testSingleLogInZip() { try { Path path = new TestLogFile("gc.log.zip").getFile().toPath(); - SingleLogFileMetadata metaData = new SingleLogFileMetadata(path); + var metaData = new SingleLogFileMetadata(path); assertEquals(1, metaData.getNumberOfFiles()); assertFalse(metaData.isGZip()); assertTrue(metaData.isZip()); @@ -47,7 +47,7 @@ public void testSingleLogInZip() { public void testRotatingLogs() { try { Path path = new TestLogFile("rotating.zip").getFile().toPath(); - RotatingLogFileMetadata metaData = new RotatingLogFileMetadata(path); + var metaData = new RotatingLogFileMetadata(path); assertEquals(2, metaData.getNumberOfFiles()); assertFalse(metaData.isGZip()); assertTrue(metaData.isZip()); @@ -62,7 +62,7 @@ public void testRotatingLogs() { public void testZippedDirectoryWithRotatingLog() { try { Path path = new TestLogFile("rotating_directory.zip").getFile().toPath(); - RotatingLogFileMetadata metaData = new RotatingLogFileMetadata(path); + var metaData = new RotatingLogFileMetadata(path); assertEquals(2, metaData.getNumberOfFiles()); assertFalse(metaData.isGZip()); assertTrue(metaData.isZip()); @@ -77,7 +77,7 @@ public void testZippedDirectoryWithRotatingLog() { public void testGZipFile() { try { Path path = new TestLogFile("gc.log.gz").getFile().toPath(); - SingleLogFileMetadata metaData = new SingleLogFileMetadata(path); + var metaData = new SingleLogFileMetadata(path); assertEquals(1, metaData.getNumberOfFiles()); assertTrue(metaData.isGZip()); assertFalse(metaData.isZip()); @@ -95,7 +95,7 @@ public void testGZipFile() { public void testGZipTarFile() { try { Path path = new TestLogFile("gc.log.tar.gz").getFile().toPath(); - SingleLogFileMetadata metaData = new SingleLogFileMetadata(path); + var metaData = new SingleLogFileMetadata(path); assertEquals(1, metaData.getNumberOfFiles()); assertTrue(metaData.isGZip()); assertFalse(metaData.isZip()); @@ -110,7 +110,7 @@ public void testGZipTarFile() { public void testDirectory() { try { Path path = new TestLogFile("rotating_directory").getFile().toPath(); - RotatingLogFileMetadata metaData = new RotatingLogFileMetadata(path); + var metaData = new RotatingLogFileMetadata(path); assertEquals(2, metaData.getNumberOfFiles()); assertFalse(metaData.isGZip()); assertFalse(metaData.isZip()); diff --git a/vertx/src/test/java/com/microsoft/gctoolkit/vertx/io/TestLogFile.java b/vertx/src/test/java/com/microsoft/gctoolkit/vertx/io/TestLogFile.java index c9a98565..6484b9e6 100644 --- a/vertx/src/test/java/com/microsoft/gctoolkit/vertx/io/TestLogFile.java +++ b/vertx/src/test/java/com/microsoft/gctoolkit/vertx/io/TestLogFile.java @@ -5,9 +5,7 @@ import java.io.File; import java.util.Arrays; -/** - * Abstract the log files location and provide some parsing of the file name scheme. - */ +/// Abstract the log files location and provide some parsing of the file name scheme. public class TestLogFile { private final File logFile;