diff -r 4883a96b6d37 -r 5693904ecbde src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/RepositoryFiles.java --- a/src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/RepositoryFiles.java Thu Aug 15 02:55:30 2019 +0200 +++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/RepositoryFiles.java Thu Aug 15 02:58:28 2019 +0200 @@ -48,8 +48,8 @@ private final FileAccess fileAccess; private final NavigableMap pathSet = new TreeMap<>(); private final Map pathLookup = new HashMap<>(); + private final Path repository; private volatile boolean closed; - private Path repository; public RepositoryFiles(FileAccess fileAccess, Path repository) { this.repository = repository; @@ -129,17 +129,21 @@ } private boolean updatePaths() throws IOException { - if (repository == null) { - SafePath p = Repository.getRepository().getRepositoryPath(); - if (p == null) { - return false; + boolean foundNew = false; + Path repoPath = repository; + if (repoPath == null) { + // Always get the latest repository if 'jcmd JFR.configure + // repositorypath=...' has been executed + SafePath sf = Repository.getRepository().getRepositoryPath(); + if (sf == null) { + return false; // not initialized } - repository = p.toPath(); + repoPath = sf.toPath(); } - boolean foundNew = false; - List added = new ArrayList<>(); - Set current = new HashSet<>(); - try (DirectoryStream dirStream = fileAccess.newDirectoryStream(repository)) { + + try (DirectoryStream dirStream = fileAccess.newDirectoryStream(repoPath)) { + List added = new ArrayList<>(); + Set current = new HashSet<>(); for (Path p : dirStream) { if (!pathLookup.containsKey(p)) { String s = p.toString(); @@ -150,32 +154,32 @@ current.add(p); } } - } - List removed = new ArrayList<>(); - for (Path p : pathLookup.keySet()) { - if (!current.contains(p)) { - removed.add(p); + List removed = new ArrayList<>(); + for (Path p : pathLookup.keySet()) { + if (!current.contains(p)) { + removed.add(p); + } + } + + for (Path remove : removed) { + Long time = pathLookup.get(remove); + pathSet.remove(time); + pathLookup.remove(remove); } - } - - for (Path remove : removed) { - Long time = pathLookup.get(remove); - pathSet.remove(time); - pathLookup.remove(remove); + Collections.sort(added, (p1, p2) -> p1.compareTo(p2)); + for (Path p : added) { + // Only add files that have a complete header + // as the JVM may be in progress writing the file + long size = fileAccess.fileSize(p); + if (size >= ChunkHeader.HEADER_SIZE) { + long startNanos = readStartTime(p); + pathSet.put(startNanos, p); + pathLookup.put(p, startNanos); + foundNew = true; + } + } + return foundNew; } - Collections.sort(added, (p1, p2) -> p1.compareTo(p2)); - for (Path p : added) { - // Only add files that have a complete header - // as the JVM may be in progress writing the file - long size = fileAccess.fileSize(p); - if (size >= ChunkHeader.HEADER_SIZE) { - long startNanos = readStartTime(p); - pathSet.put(startNanos, p); - pathLookup.put(p, startNanos); - foundNew = true; - } - } - return foundNew; } private long readStartTime(Path p) throws IOException {