Skip to content

Commit 416b2af

Browse files
committed
Move SIMPLE_DATE_FORMAT out of class that defines options
1 parent c7cf482 commit 416b2af

File tree

3 files changed

+29
-25
lines changed

3 files changed

+29
-25
lines changed

compiler/src/jdk.graal.compiler.libgraal/src/jdk/graal/compiler/libgraal/LibGraalSubstitutions.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
import com.oracle.svm.core.annotate.Substitute;
3434
import com.oracle.svm.core.annotate.TargetClass;
3535

36-
import jdk.graal.compiler.debug.DebugOptions;
3736
import jdk.graal.compiler.debug.GraalError;
37+
import jdk.graal.compiler.debug.PathUtilities;
3838

3939
class LibGraalSubstitutions {
4040

@@ -143,7 +143,7 @@ static final class Target_java_text_DateFormatSymbols {
143143
*/
144144
@Substitute
145145
public static DateFormatSymbols getInstance(Locale unused) {
146-
return DebugOptions.getSharedDateFormatSymbols();
146+
return PathUtilities.getSharedDateFormatSymbols();
147147
}
148148
}
149149
}

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/debug/DebugOptions.java

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,10 @@
2727
import static jdk.graal.compiler.debug.PathUtilities.createDirectories;
2828
import static jdk.graal.compiler.debug.PathUtilities.exists;
2929
import static jdk.graal.compiler.debug.PathUtilities.getAbsolutePath;
30+
import static jdk.graal.compiler.debug.PathUtilities.getDateString;
3031
import static jdk.graal.compiler.debug.PathUtilities.getPath;
3132

3233
import java.io.IOException;
33-
import java.text.DateFormatSymbols;
34-
import java.text.SimpleDateFormat;
3534
import java.util.Date;
3635

3736
import jdk.graal.compiler.options.EnumMultiOptionKey;
@@ -325,21 +324,6 @@ public static String getDumpDirectory(OptionValues options) throws IOException {
325324
return dumpDir;
326325
}
327326

328-
/**
329-
* This circumvents instantiating {@link SimpleDateFormat} at libgraal runtime. This is needed
330-
* to avoid String-based class-lookup (to find resource bundle
331-
* {@code sun.text.resources.cldr.FormatData} as part of {@link SimpleDateFormat} construction)
332-
* and allows us to avoid class-lookup support in the image.
333-
*/
334-
private static final SimpleDateFormat SIMPLE_DATE_FORMAT = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss.SSS");
335-
336-
public static DateFormatSymbols getSharedDateFormatSymbols() {
337-
// SimpleDateFormat is not thread-safe
338-
synchronized (SIMPLE_DATE_FORMAT) {
339-
return SIMPLE_DATE_FORMAT.getDateFormatSymbols();
340-
}
341-
}
342-
343327
/**
344328
* Returns the {@link #getDumpDirectory} without attempting to create it.
345329
*/
@@ -349,12 +333,7 @@ public static String getDumpDirectoryName(OptionValues options) {
349333
dumpDir = getPath(DumpPath.getValue(options));
350334
} else {
351335
Date date = new Date(GraalServices.getGlobalTimeStamp());
352-
String dateString;
353-
// SimpleDateFormat is not thread-safe
354-
synchronized (SIMPLE_DATE_FORMAT) {
355-
dateString = SIMPLE_DATE_FORMAT.format(date);
356-
}
357-
dumpDir = getPath(DumpPath.getValue(options), dateString);
336+
dumpDir = getPath(DumpPath.getValue(options), getDateString(date));
358337
}
359338
dumpDir = getAbsolutePath(dumpDir);
360339
return dumpDir;

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/debug/PathUtilities.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434
import java.nio.file.InvalidPathException;
3535
import java.nio.file.OpenOption;
3636
import java.nio.file.Path;
37+
import java.text.DateFormatSymbols;
38+
import java.text.SimpleDateFormat;
39+
import java.util.Date;
3740
import java.util.Iterator;
3841
import java.util.ServiceLoader;
3942

@@ -85,6 +88,28 @@ public static String getPath(String first, String... more) {
8588
return PROVIDER.getPath(first, more);
8689
}
8790

91+
/**
92+
* This circumvents instantiating {@link SimpleDateFormat} at libgraal runtime. This is needed
93+
* to avoid String-based class-lookup (to find resource bundle
94+
* {@code sun.text.resources.cldr.FormatData} as part of {@link SimpleDateFormat} construction)
95+
* and allows us to avoid class-lookup support in the image.
96+
*/
97+
private static final SimpleDateFormat SIMPLE_DATE_FORMAT = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss.SSS");
98+
99+
public static DateFormatSymbols getSharedDateFormatSymbols() {
100+
// SimpleDateFormat is not thread-safe
101+
synchronized (SIMPLE_DATE_FORMAT) {
102+
return SIMPLE_DATE_FORMAT.getDateFormatSymbols();
103+
}
104+
}
105+
106+
public static String getDateString(Date date) {
107+
// SimpleDateFormat is not thread-safe
108+
synchronized (SIMPLE_DATE_FORMAT) {
109+
return SIMPLE_DATE_FORMAT.format(date);
110+
}
111+
}
112+
88113
/**
89114
* Gets the absolute pathname of {@code path}.
90115
*/

0 commit comments

Comments
 (0)