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 <[email protected]>
  • Loading branch information
j9build committed Aug 7, 2024
2 parents f519721 + 6940cfb commit 68fc7eb
Show file tree
Hide file tree
Showing 11 changed files with 392 additions and 53 deletions.
112 changes: 73 additions & 39 deletions src/java.base/share/classes/java/lang/runtime/SwitchBootstraps.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@

import static java.lang.invoke.MethodHandles.Lookup.ClassOption.NESTMATE;
import static java.lang.invoke.MethodHandles.Lookup.ClassOption.STRONG;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import static java.util.Objects.requireNonNull;
Expand Down Expand Up @@ -95,19 +96,13 @@ private SwitchBootstraps() {}
private static final ClassDesc CD_Objects = ReferenceClassDescImpl.ofValidated("Ljava/util/Objects;");

private static class StaticHolders {
private static final MethodHandle NULL_CHECK;
private static final MethodHandle IS_ZERO;
private static final MethodHandle MAPPED_ENUM_LOOKUP;
private static final MethodHandle MAPPED_ENUM_SWITCH;

static {
try {
NULL_CHECK = LOOKUP.findStatic(Objects.class, "isNull",
MethodType.methodType(boolean.class, Object.class));
IS_ZERO = LOOKUP.findStatic(SwitchBootstraps.class, "isZero",
MethodType.methodType(boolean.class, int.class));
MAPPED_ENUM_LOOKUP = LOOKUP.findStatic(SwitchBootstraps.class, "mappedEnumLookup",
MethodType.methodType(int.class, Enum.class, MethodHandles.Lookup.class,
Class.class, EnumDesc[].class, EnumMap.class));
MAPPED_ENUM_SWITCH = LOOKUP.findStatic(SwitchBootstraps.class, "mappedEnumSwitch",
MethodType.methodType(int.class, Enum.class, int.class, MethodHandles.Lookup.class,
Class.class, EnumDesc[].class, MappedEnumCache.class));
}
catch (ReflectiveOperationException e) {
throw new ExceptionInInitializerError(e);
Expand Down Expand Up @@ -211,10 +206,6 @@ private static void verifyLabel(Object label, Class<?> selectorType) {
}
}

private static boolean isZero(int value) {
return value == 0;
}

/**
* Bootstrap method for linking an {@code invokedynamic} call site that
* implements a {@code switch} on a target of an enum type. The static
Expand Down Expand Up @@ -286,23 +277,27 @@ public static CallSite enumSwitch(MethodHandles.Lookup lookup,
labels = labels.clone();

Class<?> enumClass = invocationType.parameterType(0);
labels = Stream.of(labels).map(l -> convertEnumConstants(lookup, enumClass, l)).toArray();
boolean constantsOnly = true;
int len = labels.length;

for (int i = 0; i < len; i++) {
Object convertedLabel =
convertEnumConstants(lookup, enumClass, labels[i]);
labels[i] = convertedLabel;
if (constantsOnly)
constantsOnly = convertedLabel instanceof EnumDesc;
}

MethodHandle target;
boolean constantsOnly = Stream.of(labels).allMatch(l -> enumClass.isAssignableFrom(EnumDesc.class));

if (labels.length > 0 && constantsOnly) {
//If all labels are enum constants, construct an optimized handle for repeat index 0:
//if (selector == null) return -1
//else if (idx == 0) return mappingArray[selector.ordinal()]; //mapping array created lazily
//else return "typeSwitch(labels)"
MethodHandle body =
MethodHandles.guardWithTest(MethodHandles.dropArguments(StaticHolders.NULL_CHECK, 0, int.class),
MethodHandles.dropArguments(MethodHandles.constant(int.class, -1), 0, int.class, Object.class),
MethodHandles.guardWithTest(MethodHandles.dropArguments(StaticHolders.IS_ZERO, 1, Object.class),
generateTypeSwitch(lookup, invocationType.parameterType(0), labels),
MethodHandles.insertArguments(StaticHolders.MAPPED_ENUM_LOOKUP, 1, lookup, enumClass, labels, new EnumMap())));
target = MethodHandles.permuteArguments(body, MethodType.methodType(int.class, Object.class, int.class), 1, 0);
EnumDesc<?>[] enumDescLabels =
Arrays.copyOf(labels, labels.length, EnumDesc[].class);
target = MethodHandles.insertArguments(StaticHolders.MAPPED_ENUM_SWITCH, 2, lookup, enumClass, enumDescLabels, new MappedEnumCache());
} else {
target = generateTypeSwitch(lookup, invocationType.parameterType(0), labels);
}
Expand Down Expand Up @@ -331,26 +326,63 @@ private static <E extends Enum<E>> Object convertEnumConstants(MethodHandles.Loo
}
}

private static <T extends Enum<T>> int mappedEnumLookup(T value, MethodHandles.Lookup lookup, Class<T> enumClass, EnumDesc<?>[] labels, EnumMap enumMap) {
if (enumMap.map == null) {
T[] constants = SharedSecrets.getJavaLangAccess().getEnumConstantsShared(enumClass);
int[] map = new int[constants.length];
int ordinal = 0;

for (T constant : constants) {
map[ordinal] = labels.length;
private static <T extends Enum<T>> int mappedEnumSwitch(T value, int restartIndex, MethodHandles.Lookup lookup, Class<T> enumClass, EnumDesc<?>[] labels, MappedEnumCache enumCache) throws Throwable {
if (value == null) {
return -1;
}

for (int i = 0; i < labels.length; i++) {
if (Objects.equals(labels[i].constantName(), constant.name())) {
map[ordinal] = i;
break;
if (restartIndex != 0) {
MethodHandle generatedSwitch = enumCache.generatedSwitch;
if (generatedSwitch == null) {
synchronized (enumCache) {
generatedSwitch = enumCache.generatedSwitch;

if (generatedSwitch == null) {
generatedSwitch =
generateTypeSwitch(lookup, enumClass, labels)
.asType(MethodType.methodType(int.class,
Enum.class,
int.class));
enumCache.generatedSwitch = generatedSwitch;
}
}
}

return (int) generatedSwitch.invokeExact(value, restartIndex);
}

int[] constantsMap = enumCache.constantsMap;

if (constantsMap == null) {
synchronized (enumCache) {
constantsMap = enumCache.constantsMap;

ordinal++;
if (constantsMap == null) {
T[] constants = SharedSecrets.getJavaLangAccess()
.getEnumConstantsShared(enumClass);
constantsMap = new int[constants.length];
int ordinal = 0;

for (T constant : constants) {
constantsMap[ordinal] = labels.length;

for (int i = 0; i < labels.length; i++) {
if (Objects.equals(labels[i].constantName(),
constant.name())) {
constantsMap[ordinal] = i;
break;
}
}

ordinal++;
}

enumCache.constantsMap = constantsMap;
}
}
}
return enumMap.map[value.ordinal()];

return constantsMap[value.ordinal()];
}

private static final class ResolvedEnumLabels implements BiPredicate<Integer, Object> {
Expand Down Expand Up @@ -395,9 +427,11 @@ public boolean test(Integer labelIndex, Object value) {
}
}

private static final class EnumMap {
private static final class MappedEnumCache {
@Stable
public int[] constantsMap;
@Stable
public int[] map;
public MethodHandle generatedSwitch;
}

/*
Expand Down
22 changes: 20 additions & 2 deletions src/java.base/share/native/launcher/main.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1995, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1995, 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 @@ -110,7 +110,25 @@ main(int argc, char **argv)
}
}
}
JLI_CmdToArgs(GetCommandLine());

// Obtain the command line in UTF-16, then convert it to ANSI code page
// without the "best-fit" option
LPWSTR wcCmdline = GetCommandLineW();
int mbSize = WideCharToMultiByte(CP_ACP,
WC_NO_BEST_FIT_CHARS | WC_COMPOSITECHECK | WC_DEFAULTCHAR,
wcCmdline, -1, NULL, 0, NULL, NULL);
// If the call to WideCharToMultiByte() fails, it returns 0, which
// will then make the following JLI_MemAlloc() to issue exit(1)
LPSTR mbCmdline = JLI_MemAlloc(mbSize);
if (WideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS | WC_COMPOSITECHECK | WC_DEFAULTCHAR,
wcCmdline, -1, mbCmdline, mbSize, NULL, NULL) == 0) {
perror("command line encoding conversion failure");
exit(1);
}

JLI_CmdToArgs(mbCmdline);
JLI_MemFree(mbCmdline);

margc = JLI_GetStdArgc();
// add one more to mark the end
margv = (char **)JLI_MemAlloc((margc + 1) * (sizeof(char *)));
Expand Down
7 changes: 6 additions & 1 deletion src/java.desktop/share/classes/javax/swing/JOptionPane.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 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 @@ -883,6 +883,11 @@ public static int showOptionDialog(Component parentComponent,

Object selectedValue = pane.getValue();

if (parentComponent != null) {
parentComponent.revalidate();
parentComponent.repaint();
}

if(selectedValue == null)
return CLOSED_OPTION;
if(options == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2474,11 +2474,7 @@ public void cancel() {
}
}

/**
* Returns true is a print job is ongoing but will
* be cancelled and the next opportunity. false is
* returned otherwise.
*/
@Override
public boolean isCancelled() {

boolean cancelled = false;
Expand Down
2 changes: 1 addition & 1 deletion test/jdk/ProblemList.txt
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,7 @@ javax/sound/sampled/Clip/ClipFlushCrash.java 8308395 linux-x64
# jdk_swing

javax/swing/plaf/basic/BasicTextUI/8001470/bug8001470.java 8233177 linux-all,windows-all
javax/swing/plaf/basic/BasicDirectoryModel/LoaderThreadCount.java 8333880 windows-all

javax/swing/JFrame/MaximizeWindowTest.java 8321289 linux-all
javax/swing/JWindow/ShapedAndTranslucentWindows/ShapedTranslucentPerPixelTranslucentGradient.java 8233582 linux-all
Expand Down Expand Up @@ -743,7 +744,6 @@ jdk/jfr/event/runtime/TestResidentSetSizeEvent.java 8309846 aix-ppc6
jdk/jfr/startupargs/TestStartName.java 8214685 windows-x64
jdk/jfr/startupargs/TestStartDuration.java 8214685 windows-x64
jdk/jfr/jvm/TestWaste.java 8282427 generic-all
jdk/jfr/api/consumer/recordingstream/TestOnEvent.java 8255404 linux-x64,linux-aarch64

############################################################################

Expand Down
5 changes: 3 additions & 2 deletions test/jdk/com/sun/jdi/JdwpListenTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 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 @@ -50,7 +50,8 @@ public class JdwpListenTest {

// Set to true to allow testing of attach from wrong address (expected to fail).
// It's off by default as it causes test time increase and test interference (see JDK-8231915).
private static boolean allowNegativeTesting = false;
private static boolean allowNegativeTesting =
"true".equalsIgnoreCase(System.getProperty("jdk.jdi.allowNegativeTesting"));

public static void main(String[] args) throws Exception {
List<InetAddress> addresses = Utils.getAddressesWithSymbolicAndNumericScopes();
Expand Down
15 changes: 14 additions & 1 deletion test/jdk/com/sun/jdi/JdwpNetProps.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 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 @@ -49,6 +49,11 @@
*/
public class JdwpNetProps {

// Set to true to allow testing of attach from wrong address (expected to fail).
// It's off by default as it causes test interference (see JDK-8311990).
private static boolean allowNegativeAttachTesting =
"true".equalsIgnoreCase(System.getProperty("jdk.jdi.allowNegativeTesting"));

public static void main(String[] args) throws Exception {
InetAddress addrs[] = InetAddress.getAllByName("localhost");
InetAddress ipv4Address = null;
Expand Down Expand Up @@ -171,6 +176,14 @@ public ListenTest preferIPv6Addresses(String value) {
}

public void run(TestResult expectedResult) throws Exception {
log("\nTest: listen at " + listenAddress + ", attaching to " + connectAddress
+ ", preferIPv4Stack = " + preferIPv4Stack
+ ", preferIPv6Addresses = " + preferIPv6Addresses
+ ", expectedResult = " + expectedResult);
if (expectedResult == TestResult.AttachFailed && !allowNegativeAttachTesting) {
log("SKIPPED: negative attach testing is disabled");
return;
}
List<String> options = new LinkedList<>();
if (preferIPv4Stack != null) {
options.add("-Djava.net.preferIPv4Stack=" + preferIPv4Stack.toString());
Expand Down
80 changes: 80 additions & 0 deletions test/jdk/javax/swing/JOptionPane/OptionPaneInput.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Copyright (c) 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

import java.awt.Canvas;
import java.awt.Color;
import java.awt.Graphics2D;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;

/*
* @test
* @bug 8235404
* @summary Checks that JOptionPane doesn't block drawing strings on another component
* @library /java/awt/regtesthelpers
* @build PassFailJFrame
* @run main/manual OptionPaneInput
*/
public class OptionPaneInput {
private static JFrame f;
private static Canvas c;
private static JTextField t;
private static final String instructions = """
1. Type "test" into the message dialog.
2. Press enter key.
3. Press OK button.
4. If the OptionPaneInput frame has test drawn on it, pass. Otherwise fail.
""";

public static void main(String[] args) throws Exception {
PassFailJFrame testFrame = new PassFailJFrame(instructions);

SwingUtilities.invokeAndWait(() -> createGUI());
testFrame.awaitAndCheck();
}

public static void createGUI() {
f = new JFrame("OptionPaneInput");
c = new Canvas();
t = new JTextField();
f.add(c);

t.addActionListener(e -> {
String text = t.getText();
Graphics2D g2 = (Graphics2D)(c.getGraphics());
g2.setColor(Color.BLACK);
g2.drawString(text, 10, 10);
System.out.println("drawing "+text);
g2.dispose();
});

f.setSize(300, 100);
PassFailJFrame.addTestWindow(f);
PassFailJFrame.positionTestWindow(f, PassFailJFrame.Position.HORIZONTAL);
f.setVisible(true);

JOptionPane.showMessageDialog(f, t);
}
}
Loading

0 comments on commit 68fc7eb

Please sign in to comment.