# HG changeset patch # User lkorinth # Date 1550483328 -3600 # Node ID 88b84fc64d34c869a1942c1032a8d5f805c532b3 # Parent 2a78b2963793bfae05f5213a8bd66efe5488d8f4 8217385: JTREG: Clean up, make sure to close resources Reviewed-by: tschatzl, sangheki diff -r 2a78b2963793 -r 88b84fc64d34 test/hotspot/jtreg/gc/g1/humongousObjects/TestHumongousClassLoader.java --- a/test/hotspot/jtreg/gc/g1/humongousObjects/TestHumongousClassLoader.java Wed Feb 13 13:27:17 2019 +0100 +++ b/test/hotspot/jtreg/gc/g1/humongousObjects/TestHumongousClassLoader.java Mon Feb 18 10:48:48 2019 +0100 @@ -156,6 +156,7 @@ URLClassLoader urlLoader = new URLClassLoader(url); Class simpleClassLoaderClass = urlLoader.loadClass(SIMPLE_CLASSLOADER_NAME); + urlLoader.close(); ClassLoader simpleClassLoader = (ClassLoader) simpleClassLoaderClass .getConstructor(java.lang.ClassLoader.class) diff -r 2a78b2963793 -r 88b84fc64d34 test/hotspot/jtreg/gc/g1/plab/lib/LogParser.java --- a/test/hotspot/jtreg/gc/g1/plab/lib/LogParser.java Wed Feb 13 13:27:17 2019 +0100 +++ b/test/hotspot/jtreg/gc/g1/plab/lib/LogParser.java Mon Feb 18 10:48:48 2019 +0100 @@ -95,36 +95,37 @@ } private PlabReport parseLines() throws NumberFormatException { - Scanner lineScanner = new Scanner(log); - PlabReport plabReport = new PlabReport(); - Optional gc_id; - while (lineScanner.hasNextLine()) { - String line = lineScanner.nextLine(); - gc_id = getGcId(line, GC_ID_PATTERN); - if (gc_id.isPresent()) { - Matcher matcher = PAIRS_PATTERN.matcher(line); - if (matcher.find()) { - if (!plabReport.containsKey(gc_id.get())) { - plabReport.put(gc_id.get(), new PlabGCStatistics()); + try (Scanner lineScanner = new Scanner(log)) { + PlabReport plabReport = new PlabReport(); + Optional gc_id; + while (lineScanner.hasNextLine()) { + String line = lineScanner.nextLine(); + gc_id = getGcId(line, GC_ID_PATTERN); + if (gc_id.isPresent()) { + Matcher matcher = PAIRS_PATTERN.matcher(line); + if (matcher.find()) { + if (!plabReport.containsKey(gc_id.get())) { + plabReport.put(gc_id.get(), new PlabGCStatistics()); + } + ReportType reportType = line.contains("Young") ? ReportType.SURVIVOR_STATS : ReportType.OLD_STATS; + + PlabGCStatistics gcStat = plabReport.get(gc_id.get()); + if (!gcStat.containsKey(reportType)) { + gcStat.put(reportType, new PlabInfo()); + } + + // Extract all pairs from log. + PlabInfo plabInfo = gcStat.get(reportType); + do { + String pair = matcher.group(); + String[] nameValue = pair.replaceAll(": ", ":").split(":"); + plabInfo.put(nameValue[0].trim(), Long.parseLong(nameValue[1])); + } while (matcher.find()); } - ReportType reportType = line.contains("Young") ? ReportType.SURVIVOR_STATS : ReportType.OLD_STATS; - - PlabGCStatistics gcStat = plabReport.get(gc_id.get()); - if (!gcStat.containsKey(reportType)) { - gcStat.put(reportType, new PlabInfo()); - } - - // Extract all pairs from log. - PlabInfo plabInfo = gcStat.get(reportType); - do { - String pair = matcher.group(); - String[] nameValue = pair.replaceAll(": ", ":").split(":"); - plabInfo.put(nameValue[0].trim(), Long.parseLong(nameValue[1])); - } while (matcher.find()); } } + return plabReport; } - return plabReport; } private static Optional getGcId(String line, Pattern pattern) { diff -r 2a78b2963793 -r 88b84fc64d34 test/hotspot/jtreg/gc/stress/gcbasher/TestGCBasher.java --- a/test/hotspot/jtreg/gc/stress/gcbasher/TestGCBasher.java Wed Feb 13 13:27:17 2019 +0100 +++ b/test/hotspot/jtreg/gc/stress/gcbasher/TestGCBasher.java Mon Feb 18 10:48:48 2019 +0100 @@ -38,14 +38,15 @@ HashMap deps = new HashMap<>(); FileSystem fs = FileSystems.getFileSystem(URI.create("jrt:/")); - Stream s = Files.walk(fs.getPath("/")); - for (Path p : (Iterable)s::iterator) { - if (p.toString().endsWith(".class") && - !p.getFileName().toString().equals("module-info.class")) { - byte[] data = Files.readAllBytes(p); - Decompiler d = new Decompiler(data); - ClassInfo ci = d.getClassInfo(); - deps.put(ci.getName(), ci); + try (Stream s = Files.walk(fs.getPath("/"))) { + for (Path p : (Iterable)s::iterator) { + if (p.toString().endsWith(".class") && + !p.getFileName().toString().equals("module-info.class")) { + byte[] data = Files.readAllBytes(p); + Decompiler d = new Decompiler(data); + ClassInfo ci = d.getClassInfo(); + deps.put(ci.getName(), ci); + } } } }