< prev index next >

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.debug/src/org/graalvm/compiler/debug/GlobalMetrics.java

Print this page
rev 56282 : [mq]: graal

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.

@@ -84,11 +84,13 @@
         long[] vals = values;
         if (vals != null) {
             EconomicMap<MetricKey, Long> map = asKeyValueMap();
             String metricsFile = DebugOptions.AggregatedMetricsFile.getValue(options);
             boolean csv = metricsFile != null && (metricsFile.endsWith(".csv") || metricsFile.endsWith(".CSV"));
-            try (PrintStream p = metricsFile == null ? DebugContext.DEFAULT_LOG_STREAM : new PrintStream(Files.newOutputStream(Paths.get(metricsFile)))) {
+            PrintStream p = null;
+            try {
+                p = metricsFile == null ? DebugContext.DEFAULT_LOG_STREAM : new PrintStream(Files.newOutputStream(Paths.get(metricsFile)));
                 if (!csv) {
                     if (!map.isEmpty()) {
                         p.println("++ Aggregated Metrics ++");
                     }
                 }

@@ -108,10 +110,15 @@
                         p.println("-- Aggregated Metrics --");
                     }
                 }
             } catch (IOException e) {
                 e.printStackTrace();
+            } finally {
+                // Don't close DEFAULT_LOG_STREAM
+                if (metricsFile != null && p != null) {
+                    p.close();
+                }
             }
         }
 
         if (DebugOptions.ListMetrics.getValue(options)) {
             PrintStream p = System.out;
< prev index next >