Skip to content

Commit

Permalink
Merge master HEAD into openj9-staging
Browse files Browse the repository at this point in the history
Signed-off-by: J9 Build <j9build@ca.ibm.com>
  • Loading branch information
j9build committed Oct 24, 2024
2 parents 149f51a + 77b9b0b commit 26e9b54
Show file tree
Hide file tree
Showing 60 changed files with 1,323 additions and 239 deletions.
2 changes: 1 addition & 1 deletion doc/testing.html
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ <h4 id="failure_handler_timeout">FAILURE_HANDLER_TIMEOUT</h4>
<p>Sets the argument <code>-timeoutHandlerTimeout</code> for JTReg. The
default value is 0. This is only valid if the failure handler is
built.</p>
<h4 id="jtreg_test_thread_factory">JTREG_TEST_THREAD_FACTORY</h4>
<h4 id="test_thread_factory">TEST_THREAD_FACTORY</h4>
<p>Sets the <code>-testThreadFactory</code> for JTReg. It should be the
fully qualified classname of a class which implements
<code>java.util.concurrent.ThreadFactory</code>. One such implementation
Expand Down
2 changes: 1 addition & 1 deletion doc/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ Defaults to 4.
Sets the argument `-timeoutHandlerTimeout` for JTReg. The default value is 0.
This is only valid if the failure handler is built.

#### JTREG_TEST_THREAD_FACTORY
#### TEST_THREAD_FACTORY

Sets the `-testThreadFactory` for JTReg. It should be the fully qualified
classname of a class which implements `java.util.concurrent.ThreadFactory`. One
Expand Down
2 changes: 1 addition & 1 deletion make/common/FileUtils.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ ifeq ($(call isTargetOs, macosx), true)
$(CP) -fRP '$(call DecodeSpace, $<)' '$(call DecodeSpace, $@)'; \
fi
if [ -n "`$(XATTR) -ls '$(call DecodeSpace, $@)'`" ]; then \
$(CHMOD) u+w '$(call DecodeSpace, $@)'; \
$(CHMOD) -h u+w '$(call DecodeSpace, $@)'; \
$(XATTR) -cs '$(call DecodeSpace, $@)'; \
fi
endef
Expand Down
31 changes: 6 additions & 25 deletions src/java.base/share/classes/java/io/Console.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import jdk.internal.io.JdkConsoleImpl;
import jdk.internal.io.JdkConsoleProvider;
import jdk.internal.javac.PreviewFeature;
import jdk.internal.util.StaticProperty;
import sun.nio.cs.UTF_8;
import sun.security.action.GetPropertyAction;

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

private static native String encoding();
private static final boolean istty = istty();
static final Charset CHARSET;
static final Charset CHARSET =
Charset.forName(GetPropertyAction.privilegedGetProperty("stdout.encoding"), UTF_8.INSTANCE);
private static final Console cons = instantiateConsole();
static {
Charset cs = null;

if (istty) {
String csname = encoding();
if (csname == null) {
csname = GetPropertyAction.privilegedGetProperty("stdout.encoding");
}
if (csname != null) {
cs = Charset.forName(csname, null);
}
}
if (cs == null) {
cs = Charset.forName(StaticProperty.nativeEncoding(),
Charset.defaultCharset());
}

CHARSET = cs;

cons = instantiateConsole();

// Set up JavaIOAccess in SharedSecrets
SharedSecrets.setJavaIOAccess(new JavaIOAccess() {
public Console console() {
Expand Down Expand Up @@ -689,6 +671,5 @@ public Console run() {
return c;
}

private static final Console cons;
private static native boolean istty();
}
4 changes: 2 additions & 2 deletions src/java.base/share/classes/java/lang/Boolean.java
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,8 @@ public static int hashCode(boolean value) {
* same value; {@code false} otherwise.
*/
public boolean equals(Object obj) {
if (obj instanceof Boolean) {
return value == ((Boolean)obj).booleanValue();
if (obj instanceof Boolean b) {
return value == b.booleanValue();
}
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions src/java.base/share/classes/java/lang/Byte.java
Original file line number Diff line number Diff line change
Expand Up @@ -477,8 +477,8 @@ public static int hashCode(byte value) {
* {@code false} otherwise.
*/
public boolean equals(Object obj) {
if (obj instanceof Byte) {
return value == ((Byte)obj).byteValue();
if (obj instanceof Byte b) {
return value == b.byteValue();
}
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions src/java.base/share/classes/java/lang/Character.java
Original file line number Diff line number Diff line change
Expand Up @@ -9066,8 +9066,8 @@ public static int hashCode(char value) {
* {@code false} otherwise.
*/
public boolean equals(Object obj) {
if (obj instanceof Character) {
return value == ((Character)obj).charValue();
if (obj instanceof Character c) {
return value == c.charValue();
}
return false;
}
Expand Down
5 changes: 2 additions & 3 deletions src/java.base/share/classes/java/lang/Double.java
Original file line number Diff line number Diff line change
Expand Up @@ -1257,9 +1257,8 @@ public static int hashCode(double value) {
* @jls 15.21.1 Numerical Equality Operators == and !=
*/
public boolean equals(Object obj) {
return (obj instanceof Double)
&& (doubleToLongBits(((Double)obj).value) ==
doubleToLongBits(value));
return (obj instanceof Double d) &&
(doubleToLongBits(d.value) == doubleToLongBits(value));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/java.base/share/classes/java/lang/Float.java
Original file line number Diff line number Diff line change
Expand Up @@ -889,8 +889,8 @@ public static int hashCode(float value) {
* @jls 15.21.1 Numerical Equality Operators == and !=
*/
public boolean equals(Object obj) {
return (obj instanceof Float)
&& (floatToIntBits(((Float)obj).value) == floatToIntBits(value));
return (obj instanceof Float f) &&
(floatToIntBits(f.value) == floatToIntBits(value));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/java.base/share/classes/java/lang/Integer.java
Original file line number Diff line number Diff line change
Expand Up @@ -1147,8 +1147,8 @@ public static int hashCode(int value) {
* {@code false} otherwise.
*/
public boolean equals(Object obj) {
if (obj instanceof Integer) {
return value == ((Integer)obj).intValue();
if (obj instanceof Integer i) {
return value == i.intValue();
}
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions src/java.base/share/classes/java/lang/Long.java
Original file line number Diff line number Diff line change
Expand Up @@ -1245,8 +1245,8 @@ public static int hashCode(long value) {
* {@code false} otherwise.
*/
public boolean equals(Object obj) {
if (obj instanceof Long) {
return value == ((Long)obj).longValue();
if (obj instanceof Long ell) {
return value == ell.longValue();
}
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions src/java.base/share/classes/java/lang/Short.java
Original file line number Diff line number Diff line change
Expand Up @@ -483,8 +483,8 @@ public static int hashCode(short value) {
* {@code false} otherwise.
*/
public boolean equals(Object obj) {
if (obj instanceof Short) {
return value == ((Short)obj).shortValue();
if (obj instanceof Short s) {
return value == s.shortValue();
}
return false;
}
Expand Down
15 changes: 6 additions & 9 deletions src/java.base/share/classes/java/lang/System.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,7 @@ private System() {
* corresponds to display output or another output destination
* specified by the host environment or user. The encoding used
* in the conversion from characters to bytes is equivalent to
* {@link Console#charset()} if the {@code Console} exists,
* <a href="#stdout.encoding">stdout.encoding</a> otherwise.
* {@link ##stdout.encoding stdout.encoding}.
* <p>
* For simple stand-alone Java applications, a typical way to write
* a line of output data is:
Expand All @@ -168,8 +167,7 @@ private System() {
* @see java.io.PrintStream#println(long)
* @see java.io.PrintStream#println(java.lang.Object)
* @see java.io.PrintStream#println(java.lang.String)
* @see Console#charset()
* @see <a href="#stdout.encoding">stdout.encoding</a>
* @see ##stdout.encoding stdout.encoding
*/
public static final PrintStream out = null;

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

Expand Down Expand Up @@ -788,7 +784,8 @@ public static native void arraycopy(Object src, int srcPos,
* <td>Character encoding name derived from the host environment and/or
* the user's settings. Setting this system property has no effect.</td></tr>
* <tr><th scope="row">{@systemProperty stdout.encoding}</th>
* <td>Character encoding name for {@link System#out System.out}.
* <td>Character encoding name for {@link System#out System.out} and
* {@link System#console() System.console()}.
* The Java runtime can be started with the system property set to {@code UTF-8},
* starting it with the property set to another value leads to undefined behavior.
* <tr><th scope="row">{@systemProperty stderr.encoding}</th>
Expand Down
27 changes: 5 additions & 22 deletions src/java.base/share/classes/java/util/Locale.java
Original file line number Diff line number Diff line change
Expand Up @@ -1126,28 +1126,11 @@ private static synchronized Locale getFormatLocale() {
}

private static Locale initDefault() {
String language, region, script, country, variant;
language = StaticProperty.USER_LANGUAGE;
// for compatibility, check for old user.region property
region = StaticProperty.USER_REGION;
if (!region.isEmpty()) {
// region can be of form country, country_variant, or _variant
int i = region.indexOf('_');
if (i >= 0) {
country = region.substring(0, i);
variant = region.substring(i + 1);
} else {
country = region;
variant = "";
}
script = "";
} else {
script = StaticProperty.USER_SCRIPT;
country = StaticProperty.USER_COUNTRY;
variant = StaticProperty.USER_VARIANT;
}

return getInstance(language, script, country, variant,
return getInstance(
StaticProperty.USER_LANGUAGE,
StaticProperty.USER_SCRIPT,
StaticProperty.USER_COUNTRY,
StaticProperty.USER_VARIANT,
getDefaultExtensions(StaticProperty.USER_EXTENSIONS)
.orElse(null));
}
Expand Down
24 changes: 19 additions & 5 deletions src/java.base/share/classes/jdk/internal/util/StaticProperty.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -98,19 +98,33 @@ private StaticProperty() {}
USER_LANGUAGE = getProperty(props, "user.language", "en");
USER_LANGUAGE_DISPLAY = getProperty(props, "user.language.display", USER_LANGUAGE);
USER_LANGUAGE_FORMAT = getProperty(props, "user.language.format", USER_LANGUAGE);
USER_SCRIPT = getProperty(props, "user.script", "");
// for compatibility, check for old user.region property
USER_REGION = getProperty(props, "user.region", "");
if (!USER_REGION.isEmpty()) {
// region can be of form country, country_variant, or _variant
int i = USER_REGION.indexOf('_');
if (i >= 0) {
USER_COUNTRY = USER_REGION.substring(0, i);
USER_VARIANT = USER_REGION.substring(i + 1);
} else {
USER_COUNTRY = USER_REGION;
USER_VARIANT = "";
}
USER_SCRIPT = "";
} else {
USER_SCRIPT = getProperty(props, "user.script", "");
USER_COUNTRY = getProperty(props, "user.country", "");
USER_VARIANT = getProperty(props, "user.variant", "");
}
USER_SCRIPT_DISPLAY = getProperty(props, "user.script.display", USER_SCRIPT);
USER_SCRIPT_FORMAT = getProperty(props, "user.script.format", USER_SCRIPT);
USER_COUNTRY = getProperty(props, "user.country", "");
USER_COUNTRY_DISPLAY = getProperty(props, "user.country.display", USER_COUNTRY);
USER_COUNTRY_FORMAT = getProperty(props, "user.country.format", USER_COUNTRY);
USER_VARIANT = getProperty(props, "user.variant", "");
USER_VARIANT_DISPLAY = getProperty(props, "user.variant.display", USER_VARIANT);
USER_VARIANT_FORMAT = getProperty(props, "user.variant.format", USER_VARIANT);
USER_EXTENSIONS = getProperty(props, "user.extensions", "");
USER_EXTENSIONS_DISPLAY = getProperty(props, "user.extensions.display", USER_EXTENSIONS);
USER_EXTENSIONS_FORMAT = getProperty(props, "user.extensions.format", USER_EXTENSIONS);
USER_REGION = getProperty(props, "user.region", "");
}

private static String getProperty(Properties props, String key) {
Expand Down
34 changes: 28 additions & 6 deletions src/java.base/share/classes/sun/nio/ch/ChannelInputStream.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -38,6 +38,7 @@
import java.util.Arrays;
import java.util.Objects;
import jdk.internal.util.ArraysSupport;
import jdk.internal.vm.annotation.Stable;

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

// if isOther is true, then the file being read is not a regular file,
// nor a directory, nor a symbolic link, hence possibly not seekable
private @Stable Boolean isOther;

/**
* Initialize a ChannelInputStream that reads from the given channel.
*/
ChannelInputStream(ReadableByteChannel ch) {
this.ch = ch;
}

private boolean isOther() throws IOException {
Boolean isOther = this.isOther;
if (isOther == null) {
if (ch instanceof FileChannelImpl fci)
this.isOther = isOther = fci.isOther();
else
this.isOther = isOther = Boolean.FALSE;
}
return isOther;
}

/**
* Reads a sequence of bytes from the channel into the given buffer.
*/
Expand Down Expand Up @@ -105,7 +121,8 @@ public synchronized int read(byte[] bs, int off, int len)

@Override
public byte[] readAllBytes() throws IOException {
if (!(ch instanceof SeekableByteChannel sbc))
if (!(ch instanceof SeekableByteChannel sbc) ||
(ch instanceof FileChannelImpl fci && isOther()))
return super.readAllBytes();

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

if (!(ch instanceof SeekableByteChannel sbc))
if (!(ch instanceof SeekableByteChannel sbc) ||
(ch instanceof FileChannelImpl fci && isOther()))
return super.readNBytes(len);

long length = sbc.size();
Expand Down Expand Up @@ -192,7 +210,9 @@ public byte[] readNBytes(int len) throws IOException {
@Override
public int available() throws IOException {
// special case where the channel is to a file
if (ch instanceof SeekableByteChannel sbc) {
if (ch instanceof FileChannelImpl fci) {
return fci.available();
} else if (ch instanceof SeekableByteChannel sbc) {
long rem = Math.max(0, sbc.size() - sbc.position());
return (rem > Integer.MAX_VALUE) ? Integer.MAX_VALUE : (int)rem;
}
Expand All @@ -202,7 +222,8 @@ public int available() throws IOException {
@Override
public synchronized long skip(long n) throws IOException {
// special case where the channel is to a file
if (ch instanceof SeekableByteChannel sbc) {
if (ch instanceof SeekableByteChannel sbc &&
!(ch instanceof FileChannelImpl fci && isOther())) {
long pos = sbc.position();
long newPos;
if (n > 0) {
Expand All @@ -224,7 +245,8 @@ public synchronized long skip(long n) throws IOException {
public long transferTo(OutputStream out) throws IOException {
Objects.requireNonNull(out, "out");

if (ch instanceof FileChannel fc) {
if (ch instanceof FileChannel fc &&
!(fc instanceof FileChannelImpl fci && isOther())) {
// FileChannel -> SocketChannel
if (out instanceof SocketOutputStream sos) {
SocketChannelImpl sc = sos.channel();
Expand Down
Loading

0 comments on commit 26e9b54

Please sign in to comment.