Skip to content

Commit 26e9b54

Browse files
committed
Merge master HEAD into openj9-staging
Signed-off-by: J9 Build <[email protected]>
2 parents 149f51a + 77b9b0b commit 26e9b54

File tree

60 files changed

+1323
-239
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+1323
-239
lines changed

doc/testing.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ <h4 id="failure_handler_timeout">FAILURE_HANDLER_TIMEOUT</h4>
434434
<p>Sets the argument <code>-timeoutHandlerTimeout</code> for JTReg. The
435435
default value is 0. This is only valid if the failure handler is
436436
built.</p>
437-
<h4 id="jtreg_test_thread_factory">JTREG_TEST_THREAD_FACTORY</h4>
437+
<h4 id="test_thread_factory">TEST_THREAD_FACTORY</h4>
438438
<p>Sets the <code>-testThreadFactory</code> for JTReg. It should be the
439439
fully qualified classname of a class which implements
440440
<code>java.util.concurrent.ThreadFactory</code>. One such implementation

doc/testing.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ Defaults to 4.
380380
Sets the argument `-timeoutHandlerTimeout` for JTReg. The default value is 0.
381381
This is only valid if the failure handler is built.
382382

383-
#### JTREG_TEST_THREAD_FACTORY
383+
#### TEST_THREAD_FACTORY
384384

385385
Sets the `-testThreadFactory` for JTReg. It should be the fully qualified
386386
classname of a class which implements `java.util.concurrent.ThreadFactory`. One

make/common/FileUtils.gmk

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ ifeq ($(call isTargetOs, macosx), true)
136136
$(CP) -fRP '$(call DecodeSpace, $<)' '$(call DecodeSpace, $@)'; \
137137
fi
138138
if [ -n "`$(XATTR) -ls '$(call DecodeSpace, $@)'`" ]; then \
139-
$(CHMOD) u+w '$(call DecodeSpace, $@)'; \
139+
$(CHMOD) -h u+w '$(call DecodeSpace, $@)'; \
140140
$(XATTR) -cs '$(call DecodeSpace, $@)'; \
141141
fi
142142
endef

src/java.base/share/classes/java/io/Console.java

+6-25
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
import jdk.internal.io.JdkConsoleImpl;
3535
import jdk.internal.io.JdkConsoleProvider;
3636
import jdk.internal.javac.PreviewFeature;
37-
import jdk.internal.util.StaticProperty;
37+
import sun.nio.cs.UTF_8;
3838
import sun.security.action.GetPropertyAction;
3939

4040
/**
@@ -580,7 +580,8 @@ public void flush() {
580580
* the {@code Console}.
581581
* <p>
582582
* The returned charset corresponds to the input and output source
583-
* (e.g., keyboard and/or display) specified by the host environment or user.
583+
* (e.g., keyboard and/or display) specified by the host environment or user,
584+
* which defaults to the one based on {@link System##stdout.encoding stdout.encoding}.
584585
* It may not necessarily be the same as the default charset returned from
585586
* {@link java.nio.charset.Charset#defaultCharset() Charset.defaultCharset()}.
586587
*
@@ -614,30 +615,11 @@ private static UnsupportedOperationException newUnsupportedOperationException()
614615
"Console class itself does not provide implementation");
615616
}
616617

617-
private static native String encoding();
618618
private static final boolean istty = istty();
619-
static final Charset CHARSET;
619+
static final Charset CHARSET =
620+
Charset.forName(GetPropertyAction.privilegedGetProperty("stdout.encoding"), UTF_8.INSTANCE);
621+
private static final Console cons = instantiateConsole();
620622
static {
621-
Charset cs = null;
622-
623-
if (istty) {
624-
String csname = encoding();
625-
if (csname == null) {
626-
csname = GetPropertyAction.privilegedGetProperty("stdout.encoding");
627-
}
628-
if (csname != null) {
629-
cs = Charset.forName(csname, null);
630-
}
631-
}
632-
if (cs == null) {
633-
cs = Charset.forName(StaticProperty.nativeEncoding(),
634-
Charset.defaultCharset());
635-
}
636-
637-
CHARSET = cs;
638-
639-
cons = instantiateConsole();
640-
641623
// Set up JavaIOAccess in SharedSecrets
642624
SharedSecrets.setJavaIOAccess(new JavaIOAccess() {
643625
public Console console() {
@@ -689,6 +671,5 @@ public Console run() {
689671
return c;
690672
}
691673

692-
private static final Console cons;
693674
private static native boolean istty();
694675
}

src/java.base/share/classes/java/lang/Boolean.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,8 @@ public static int hashCode(boolean value) {
255255
* same value; {@code false} otherwise.
256256
*/
257257
public boolean equals(Object obj) {
258-
if (obj instanceof Boolean) {
259-
return value == ((Boolean)obj).booleanValue();
258+
if (obj instanceof Boolean b) {
259+
return value == b.booleanValue();
260260
}
261261
return false;
262262
}

src/java.base/share/classes/java/lang/Byte.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -477,8 +477,8 @@ public static int hashCode(byte value) {
477477
* {@code false} otherwise.
478478
*/
479479
public boolean equals(Object obj) {
480-
if (obj instanceof Byte) {
481-
return value == ((Byte)obj).byteValue();
480+
if (obj instanceof Byte b) {
481+
return value == b.byteValue();
482482
}
483483
return false;
484484
}

src/java.base/share/classes/java/lang/Character.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -9066,8 +9066,8 @@ public static int hashCode(char value) {
90669066
* {@code false} otherwise.
90679067
*/
90689068
public boolean equals(Object obj) {
9069-
if (obj instanceof Character) {
9070-
return value == ((Character)obj).charValue();
9069+
if (obj instanceof Character c) {
9070+
return value == c.charValue();
90719071
}
90729072
return false;
90739073
}

src/java.base/share/classes/java/lang/Double.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -1257,9 +1257,8 @@ public static int hashCode(double value) {
12571257
* @jls 15.21.1 Numerical Equality Operators == and !=
12581258
*/
12591259
public boolean equals(Object obj) {
1260-
return (obj instanceof Double)
1261-
&& (doubleToLongBits(((Double)obj).value) ==
1262-
doubleToLongBits(value));
1260+
return (obj instanceof Double d) &&
1261+
(doubleToLongBits(d.value) == doubleToLongBits(value));
12631262
}
12641263

12651264
/**

src/java.base/share/classes/java/lang/Float.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -889,8 +889,8 @@ public static int hashCode(float value) {
889889
* @jls 15.21.1 Numerical Equality Operators == and !=
890890
*/
891891
public boolean equals(Object obj) {
892-
return (obj instanceof Float)
893-
&& (floatToIntBits(((Float)obj).value) == floatToIntBits(value));
892+
return (obj instanceof Float f) &&
893+
(floatToIntBits(f.value) == floatToIntBits(value));
894894
}
895895

896896
/**

src/java.base/share/classes/java/lang/Integer.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1147,8 +1147,8 @@ public static int hashCode(int value) {
11471147
* {@code false} otherwise.
11481148
*/
11491149
public boolean equals(Object obj) {
1150-
if (obj instanceof Integer) {
1151-
return value == ((Integer)obj).intValue();
1150+
if (obj instanceof Integer i) {
1151+
return value == i.intValue();
11521152
}
11531153
return false;
11541154
}

src/java.base/share/classes/java/lang/Long.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1245,8 +1245,8 @@ public static int hashCode(long value) {
12451245
* {@code false} otherwise.
12461246
*/
12471247
public boolean equals(Object obj) {
1248-
if (obj instanceof Long) {
1249-
return value == ((Long)obj).longValue();
1248+
if (obj instanceof Long ell) {
1249+
return value == ell.longValue();
12501250
}
12511251
return false;
12521252
}

src/java.base/share/classes/java/lang/Short.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -483,8 +483,8 @@ public static int hashCode(short value) {
483483
* {@code false} otherwise.
484484
*/
485485
public boolean equals(Object obj) {
486-
if (obj instanceof Short) {
487-
return value == ((Short)obj).shortValue();
486+
if (obj instanceof Short s) {
487+
return value == s.shortValue();
488488
}
489489
return false;
490490
}

src/java.base/share/classes/java/lang/System.java

+6-9
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,7 @@ private System() {
147147
* corresponds to display output or another output destination
148148
* specified by the host environment or user. The encoding used
149149
* in the conversion from characters to bytes is equivalent to
150-
* {@link Console#charset()} if the {@code Console} exists,
151-
* <a href="#stdout.encoding">stdout.encoding</a> otherwise.
150+
* {@link ##stdout.encoding stdout.encoding}.
152151
* <p>
153152
* For simple stand-alone Java applications, a typical way to write
154153
* a line of output data is:
@@ -168,8 +167,7 @@ private System() {
168167
* @see java.io.PrintStream#println(long)
169168
* @see java.io.PrintStream#println(java.lang.Object)
170169
* @see java.io.PrintStream#println(java.lang.String)
171-
* @see Console#charset()
172-
* @see <a href="#stdout.encoding">stdout.encoding</a>
170+
* @see ##stdout.encoding stdout.encoding
173171
*/
174172
public static final PrintStream out = null;
175173

@@ -185,11 +183,9 @@ private System() {
185183
* variable {@code out}, has been redirected to a file or other
186184
* destination that is typically not continuously monitored.
187185
* The encoding used in the conversion from characters to bytes is
188-
* equivalent to {@link Console#charset()} if the {@code Console}
189-
* exists, <a href="#stderr.encoding">stderr.encoding</a> otherwise.
186+
* equivalent to {@link ##stderr.encoding stderr.encoding}.
190187
*
191-
* @see Console#charset()
192-
* @see <a href="#stderr.encoding">stderr.encoding</a>
188+
* @see ##stderr.encoding stderr.encoding
193189
*/
194190
public static final PrintStream err = null;
195191

@@ -788,7 +784,8 @@ public static native void arraycopy(Object src, int srcPos,
788784
* <td>Character encoding name derived from the host environment and/or
789785
* the user's settings. Setting this system property has no effect.</td></tr>
790786
* <tr><th scope="row">{@systemProperty stdout.encoding}</th>
791-
* <td>Character encoding name for {@link System#out System.out}.
787+
* <td>Character encoding name for {@link System#out System.out} and
788+
* {@link System#console() System.console()}.
792789
* The Java runtime can be started with the system property set to {@code UTF-8},
793790
* starting it with the property set to another value leads to undefined behavior.
794791
* <tr><th scope="row">{@systemProperty stderr.encoding}</th>

src/java.base/share/classes/java/util/Locale.java

+5-22
Original file line numberDiff line numberDiff line change
@@ -1126,28 +1126,11 @@ private static synchronized Locale getFormatLocale() {
11261126
}
11271127

11281128
private static Locale initDefault() {
1129-
String language, region, script, country, variant;
1130-
language = StaticProperty.USER_LANGUAGE;
1131-
// for compatibility, check for old user.region property
1132-
region = StaticProperty.USER_REGION;
1133-
if (!region.isEmpty()) {
1134-
// region can be of form country, country_variant, or _variant
1135-
int i = region.indexOf('_');
1136-
if (i >= 0) {
1137-
country = region.substring(0, i);
1138-
variant = region.substring(i + 1);
1139-
} else {
1140-
country = region;
1141-
variant = "";
1142-
}
1143-
script = "";
1144-
} else {
1145-
script = StaticProperty.USER_SCRIPT;
1146-
country = StaticProperty.USER_COUNTRY;
1147-
variant = StaticProperty.USER_VARIANT;
1148-
}
1149-
1150-
return getInstance(language, script, country, variant,
1129+
return getInstance(
1130+
StaticProperty.USER_LANGUAGE,
1131+
StaticProperty.USER_SCRIPT,
1132+
StaticProperty.USER_COUNTRY,
1133+
StaticProperty.USER_VARIANT,
11511134
getDefaultExtensions(StaticProperty.USER_EXTENSIONS)
11521135
.orElse(null));
11531136
}

src/java.base/share/classes/jdk/internal/util/StaticProperty.java

+19-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -98,19 +98,33 @@ private StaticProperty() {}
9898
USER_LANGUAGE = getProperty(props, "user.language", "en");
9999
USER_LANGUAGE_DISPLAY = getProperty(props, "user.language.display", USER_LANGUAGE);
100100
USER_LANGUAGE_FORMAT = getProperty(props, "user.language.format", USER_LANGUAGE);
101-
USER_SCRIPT = getProperty(props, "user.script", "");
101+
// for compatibility, check for old user.region property
102+
USER_REGION = getProperty(props, "user.region", "");
103+
if (!USER_REGION.isEmpty()) {
104+
// region can be of form country, country_variant, or _variant
105+
int i = USER_REGION.indexOf('_');
106+
if (i >= 0) {
107+
USER_COUNTRY = USER_REGION.substring(0, i);
108+
USER_VARIANT = USER_REGION.substring(i + 1);
109+
} else {
110+
USER_COUNTRY = USER_REGION;
111+
USER_VARIANT = "";
112+
}
113+
USER_SCRIPT = "";
114+
} else {
115+
USER_SCRIPT = getProperty(props, "user.script", "");
116+
USER_COUNTRY = getProperty(props, "user.country", "");
117+
USER_VARIANT = getProperty(props, "user.variant", "");
118+
}
102119
USER_SCRIPT_DISPLAY = getProperty(props, "user.script.display", USER_SCRIPT);
103120
USER_SCRIPT_FORMAT = getProperty(props, "user.script.format", USER_SCRIPT);
104-
USER_COUNTRY = getProperty(props, "user.country", "");
105121
USER_COUNTRY_DISPLAY = getProperty(props, "user.country.display", USER_COUNTRY);
106122
USER_COUNTRY_FORMAT = getProperty(props, "user.country.format", USER_COUNTRY);
107-
USER_VARIANT = getProperty(props, "user.variant", "");
108123
USER_VARIANT_DISPLAY = getProperty(props, "user.variant.display", USER_VARIANT);
109124
USER_VARIANT_FORMAT = getProperty(props, "user.variant.format", USER_VARIANT);
110125
USER_EXTENSIONS = getProperty(props, "user.extensions", "");
111126
USER_EXTENSIONS_DISPLAY = getProperty(props, "user.extensions.display", USER_EXTENSIONS);
112127
USER_EXTENSIONS_FORMAT = getProperty(props, "user.extensions.format", USER_EXTENSIONS);
113-
USER_REGION = getProperty(props, "user.region", "");
114128
}
115129

116130
private static String getProperty(Properties props, String key) {

src/java.base/share/classes/sun/nio/ch/ChannelInputStream.java

+28-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2001, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2001, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -38,6 +38,7 @@
3838
import java.util.Arrays;
3939
import java.util.Objects;
4040
import jdk.internal.util.ArraysSupport;
41+
import jdk.internal.vm.annotation.Stable;
4142

4243
/**
4344
* An InputStream that reads bytes from a channel.
@@ -53,13 +54,28 @@ class ChannelInputStream extends InputStream {
5354
private byte[] bs; // Invoker's previous array
5455
private byte[] b1;
5556

57+
// if isOther is true, then the file being read is not a regular file,
58+
// nor a directory, nor a symbolic link, hence possibly not seekable
59+
private @Stable Boolean isOther;
60+
5661
/**
5762
* Initialize a ChannelInputStream that reads from the given channel.
5863
*/
5964
ChannelInputStream(ReadableByteChannel ch) {
6065
this.ch = ch;
6166
}
6267

68+
private boolean isOther() throws IOException {
69+
Boolean isOther = this.isOther;
70+
if (isOther == null) {
71+
if (ch instanceof FileChannelImpl fci)
72+
this.isOther = isOther = fci.isOther();
73+
else
74+
this.isOther = isOther = Boolean.FALSE;
75+
}
76+
return isOther;
77+
}
78+
6379
/**
6480
* Reads a sequence of bytes from the channel into the given buffer.
6581
*/
@@ -105,7 +121,8 @@ public synchronized int read(byte[] bs, int off, int len)
105121

106122
@Override
107123
public byte[] readAllBytes() throws IOException {
108-
if (!(ch instanceof SeekableByteChannel sbc))
124+
if (!(ch instanceof SeekableByteChannel sbc) ||
125+
(ch instanceof FileChannelImpl fci && isOther()))
109126
return super.readAllBytes();
110127

111128
long length = sbc.size();
@@ -156,7 +173,8 @@ public byte[] readNBytes(int len) throws IOException {
156173
if (len == 0)
157174
return new byte[0];
158175

159-
if (!(ch instanceof SeekableByteChannel sbc))
176+
if (!(ch instanceof SeekableByteChannel sbc) ||
177+
(ch instanceof FileChannelImpl fci && isOther()))
160178
return super.readNBytes(len);
161179

162180
long length = sbc.size();
@@ -192,7 +210,9 @@ public byte[] readNBytes(int len) throws IOException {
192210
@Override
193211
public int available() throws IOException {
194212
// special case where the channel is to a file
195-
if (ch instanceof SeekableByteChannel sbc) {
213+
if (ch instanceof FileChannelImpl fci) {
214+
return fci.available();
215+
} else if (ch instanceof SeekableByteChannel sbc) {
196216
long rem = Math.max(0, sbc.size() - sbc.position());
197217
return (rem > Integer.MAX_VALUE) ? Integer.MAX_VALUE : (int)rem;
198218
}
@@ -202,7 +222,8 @@ public int available() throws IOException {
202222
@Override
203223
public synchronized long skip(long n) throws IOException {
204224
// special case where the channel is to a file
205-
if (ch instanceof SeekableByteChannel sbc) {
225+
if (ch instanceof SeekableByteChannel sbc &&
226+
!(ch instanceof FileChannelImpl fci && isOther())) {
206227
long pos = sbc.position();
207228
long newPos;
208229
if (n > 0) {
@@ -224,7 +245,8 @@ public synchronized long skip(long n) throws IOException {
224245
public long transferTo(OutputStream out) throws IOException {
225246
Objects.requireNonNull(out, "out");
226247

227-
if (ch instanceof FileChannel fc) {
248+
if (ch instanceof FileChannel fc &&
249+
!(fc instanceof FileChannelImpl fci && isOther())) {
228250
// FileChannel -> SocketChannel
229251
if (out instanceof SocketOutputStream sos) {
230252
SocketChannelImpl sc = sos.channel();

0 commit comments

Comments
 (0)