Skip to content

Commit df9591f

Browse files
committed
8216565: Specifying the same path creates a new directory in JFR.configure
Reviewed-by: ysuenaga, egahlin
1 parent 52f9024 commit df9591f

File tree

3 files changed

+55
-1
lines changed

3 files changed

+55
-1
lines changed

src/jdk.jfr/share/classes/jdk/jfr/internal/Repository.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ public static Repository getRepository() {
5656
}
5757

5858
public synchronized void setBasePath(SafePath baseLocation) throws Exception {
59+
60+
if(baseLocation.equals(this.baseLocation)) {
61+
Logger.log(LogTag.JFR, LogLevel.INFO, "Same base repository path " + baseLocation.toString() + " is set");
62+
return;
63+
}
5964
// Probe to see if repository can be created, needed for fail fast
6065
// during JVM startup or JFR.configure
6166
this.repository = createRepository(baseLocation);

src/jdk.jfr/share/classes/jdk/jfr/internal/SecuritySupport.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,19 @@ public Path toPath() {
171171
public String toString() {
172172
return text;
173173
}
174+
175+
@Override
176+
public boolean equals(Object other) {
177+
if(other != null && other instanceof SafePath){
178+
return this.toPath().equals(((SafePath) other).toPath());
179+
}
180+
return false;
181+
}
182+
183+
@Override
184+
public int hashCode() {
185+
return this.toPath().hashCode();
186+
}
174187
}
175188

176189
private interface RunnableWithCheckedException {

test/jdk/jdk/jfr/jcmd/TestJcmdConfigure.java

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,12 @@
2626
package jdk.jfr.jcmd;
2727

2828
import java.nio.file.Files;
29+
import java.nio.file.Paths;
2930
import java.util.ArrayList;
3031
import java.util.List;
3132

33+
import jdk.jfr.internal.Repository;
34+
import jdk.jfr.internal.SecuritySupport.SafePath;
3235
import jdk.jfr.internal.Options;
3336
import jdk.test.lib.Asserts;
3437
import jdk.test.lib.Utils;
@@ -40,7 +43,7 @@
4043
* @requires vm.hasJFR
4144
* @library /test/lib /test/jdk
4245
* @modules jdk.jfr/jdk.jfr.internal
43-
* @run main/othervm jdk.jfr.jcmd.TestJcmdConfigure
46+
* @run main/othervm -Xlog:jfr=info:file=jfr_info.txt jdk.jfr.jcmd.TestJcmdConfigure
4447
*/
4548
public class TestJcmdConfigure {
4649

@@ -53,6 +56,13 @@ public class TestJcmdConfigure {
5356
private static final String SAMPLE_THREADS = "samplethreads";
5457
private static final String UNSUPPORTED_OPTION = "unsupportedoption";
5558

59+
private static final String REPOSITORYPATH_1 = "./repo1";
60+
private static final String REPOSITORYPATH_2 = "./repo2";
61+
62+
private static final String REPOSITORYPATH_SETTING_1 = "repositorypath="+REPOSITORYPATH_1;
63+
private static final String REPOSITORYPATH_SETTING_2 = "repositorypath="+REPOSITORYPATH_2;
64+
private static final String JFR_UNIFIED_LOG_FILE = "jfr_info.txt";
65+
5666
public static void main(String[] args) throws Exception {
5767
//
5868
// Simple sanity tests against what is available in Java,
@@ -76,6 +86,8 @@ public static void main(String[] args) throws Exception {
7686
testNegative(UNSUPPORTED_OPTION, 100000);
7787
testNegative(MAX_CHUNK_SIZE, -500);
7888

89+
testRepository();
90+
7991
if (!testExceptions.isEmpty()) {
8092
for (Exception e : testExceptions) {
8193
System.out.println("Error: " + e.getMessage());
@@ -118,4 +130,28 @@ private static Object getOption(String name) {
118130
default: throw new RuntimeException("Unknown option " + name);
119131
}
120132
}
133+
134+
private static void testRepository(){
135+
final String findWhat = "[info][jfr] Same base repository path " + REPOSITORYPATH_1 + " is set";
136+
137+
try {
138+
JcmdHelper.jcmd("JFR.configure", REPOSITORYPATH_SETTING_1);
139+
SafePath initialPath = Repository.getRepository().getRepositoryPath();
140+
141+
JcmdHelper.jcmd("JFR.configure", REPOSITORYPATH_SETTING_1);
142+
SafePath samePath = Repository.getRepository().getRepositoryPath();
143+
Asserts.assertTrue(samePath.equals(initialPath));
144+
145+
List<String> lines = Files.readAllLines(Paths.get(JFR_UNIFIED_LOG_FILE));
146+
Asserts.assertTrue(lines.stream().anyMatch(l->l.contains(findWhat)));
147+
148+
JcmdHelper.jcmd("JFR.configure", REPOSITORYPATH_SETTING_2);
149+
SafePath changedPath = Repository.getRepository().getRepositoryPath();
150+
151+
Asserts.assertFalse(changedPath.equals(initialPath));
152+
153+
} catch(Exception e) {
154+
testExceptions.add(e);
155+
}
156+
}
121157
}

0 commit comments

Comments
 (0)