8217385: JTREG: Clean up, make sure to close resources

Reviewed-by: tschatzl, sangheki
This commit is contained in:
Leo Korinth 2019-02-18 10:48:48 +01:00
parent 29021027db
commit 3d13ab6882
3 changed files with 36 additions and 33 deletions

View File

@ -156,6 +156,7 @@ public class TestHumongousClassLoader {
URLClassLoader urlLoader = new URLClassLoader(url);
Class<?> simpleClassLoaderClass = urlLoader.loadClass(SIMPLE_CLASSLOADER_NAME);
urlLoader.close();
ClassLoader simpleClassLoader = (ClassLoader) simpleClassLoaderClass
.getConstructor(java.lang.ClassLoader.class)

View File

@ -95,36 +95,37 @@ final public class LogParser {
}
private PlabReport parseLines() throws NumberFormatException {
Scanner lineScanner = new Scanner(log);
PlabReport plabReport = new PlabReport();
Optional<Long> 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;
try (Scanner lineScanner = new Scanner(log)) {
PlabReport plabReport = new PlabReport();
Optional<Long> 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());
}
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());
// 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<Long> getGcId(String line, Pattern pattern) {

View File

@ -38,14 +38,15 @@ public class TestGCBasher {
HashMap<String, ClassInfo> deps = new HashMap<>();
FileSystem fs = FileSystems.getFileSystem(URI.create("jrt:/"));
Stream<Path> s = Files.walk(fs.getPath("/"));
for (Path p : (Iterable<Path>)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<Path> s = Files.walk(fs.getPath("/"))) {
for (Path p : (Iterable<Path>)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);
}
}
}
}