提交 52b2c472 编写于 作者: K kvn

Merge

/* /*
* Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -583,7 +583,12 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo ...@@ -583,7 +583,12 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo
// setVisible could have changed the native maximized state // setVisible could have changed the native maximized state
deliverZoom(true); deliverZoom(true);
} else { } else {
switch (((Frame)target).getExtendedState()) { int frameState = ((Frame)target).getExtendedState();
if ((frameState & Frame.ICONIFIED) != 0) {
// Treat all state bit masks with ICONIFIED bit as ICONIFIED state.
frameState = Frame.ICONIFIED;
}
switch (frameState) {
case Frame.ICONIFIED: case Frame.ICONIFIED:
CWrapper.NSWindow.miniaturize(nsWindowPtr); CWrapper.NSWindow.miniaturize(nsWindowPtr);
break; break;
...@@ -788,6 +793,10 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo ...@@ -788,6 +793,10 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo
if (prevWindowState == windowState) return; if (prevWindowState == windowState) return;
final long nsWindowPtr = getNSWindowPtr(); final long nsWindowPtr = getNSWindowPtr();
if ((windowState & Frame.ICONIFIED) != 0) {
// Treat all state bit masks with ICONIFIED bit as ICONIFIED state.
windowState = Frame.ICONIFIED;
}
switch (windowState) { switch (windowState) {
case Frame.ICONIFIED: case Frame.ICONIFIED:
if (prevWindowState == Frame.MAXIMIZED_BOTH) { if (prevWindowState == Frame.MAXIMIZED_BOTH) {
......
...@@ -110,7 +110,7 @@ public class FileChannelImpl ...@@ -110,7 +110,7 @@ public class FileChannelImpl
} }
} }
nd.preClose(fd); // signal any threads blocked on this channel
threads.signalAndWait(); threads.signalAndWait();
if (parent != null) { if (parent != null) {
......
...@@ -82,8 +82,9 @@ class NativeThreadSet { ...@@ -82,8 +82,9 @@ class NativeThreadSet {
// Signals all threads in this set. // Signals all threads in this set.
// //
void signalAndWait() { synchronized void signalAndWait() {
synchronized (this) { boolean interrupted = false;
while (used > 0) {
int u = used; int u = used;
int n = elts.length; int n = elts.length;
for (int i = 0; i < n; i++) { for (int i = 0; i < n; i++) {
...@@ -96,16 +97,15 @@ class NativeThreadSet { ...@@ -96,16 +97,15 @@ class NativeThreadSet {
break; break;
} }
waitingToEmpty = true; waitingToEmpty = true;
boolean interrupted = false; try {
while (used > 0) { wait(50);
try { } catch (InterruptedException e) {
wait(); interrupted = true;
} catch (InterruptedException e) { } finally {
interrupted = true; waitingToEmpty = false;
}
} }
if (interrupted)
Thread.currentThread().interrupt();
} }
if (interrupted)
Thread.currentThread().interrupt();
} }
} }
...@@ -88,7 +88,6 @@ public class SimpleAsynchronousFileChannelImpl ...@@ -88,7 +88,6 @@ public class SimpleAsynchronousFileChannelImpl
invalidateAllLocks(); invalidateAllLocks();
// signal any threads blocked on this channel // signal any threads blocked on this channel
nd.preClose(fdObj);
threads.signalAndWait(); threads.signalAndWait();
// wait until all async I/O operations have completely gracefully // wait until all async I/O operations have completely gracefully
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include "java_awt_Transparency.h" #include "java_awt_Transparency.h"
#include "jvm_md.h" #include "jvm_md.h"
#include "sizecalc.h" #include "sizecalc.h"
#include <jni_util.h>
#define GTK2_LIB_VERSIONED VERSIONED_JNI_LIB_NAME("gtk-x11-2.0", "0") #define GTK2_LIB_VERSIONED VERSIONED_JNI_LIB_NAME("gtk-x11-2.0", "0")
#define GTK2_LIB JNI_LIB_NAME("gtk-x11-2.0") #define GTK2_LIB JNI_LIB_NAME("gtk-x11-2.0")
...@@ -456,13 +457,19 @@ void update_supported_actions(JNIEnv *env) { ...@@ -456,13 +457,19 @@ void update_supported_actions(JNIEnv *env) {
const gchar * const * schemes = NULL; const gchar * const * schemes = NULL;
jclass cls_action = (*env)->FindClass(env, "java/awt/Desktop$Action"); jclass cls_action = (*env)->FindClass(env, "java/awt/Desktop$Action");
CHECK_NULL(cls_action);
jclass cls_xDesktopPeer = (*env)->FindClass(env, "sun/awt/X11/XDesktopPeer"); jclass cls_xDesktopPeer = (*env)->FindClass(env, "sun/awt/X11/XDesktopPeer");
CHECK_NULL(cls_xDesktopPeer);
jfieldID fld_supportedActions = (*env)->GetStaticFieldID(env, cls_xDesktopPeer, "supportedActions", "Ljava/util/List;"); jfieldID fld_supportedActions = (*env)->GetStaticFieldID(env, cls_xDesktopPeer, "supportedActions", "Ljava/util/List;");
CHECK_NULL(fld_supportedActions);
jobject supportedActions = (*env)->GetStaticObjectField(env, cls_xDesktopPeer, fld_supportedActions); jobject supportedActions = (*env)->GetStaticObjectField(env, cls_xDesktopPeer, fld_supportedActions);
jclass cls_arrayList = (*env)->FindClass(env, "java/util/ArrayList"); jclass cls_arrayList = (*env)->FindClass(env, "java/util/ArrayList");
CHECK_NULL(cls_arrayList);
jmethodID mid_arrayListAdd = (*env)->GetMethodID(env, cls_arrayList, "add", "(Ljava/lang/Object;)Z"); jmethodID mid_arrayListAdd = (*env)->GetMethodID(env, cls_arrayList, "add", "(Ljava/lang/Object;)Z");
CHECK_NULL(mid_arrayListAdd);
jmethodID mid_arrayListClear = (*env)->GetMethodID(env, cls_arrayList, "clear", "()V"); jmethodID mid_arrayListClear = (*env)->GetMethodID(env, cls_arrayList, "clear", "()V");
CHECK_NULL(mid_arrayListClear);
(*env)->CallVoidMethod(env, supportedActions, mid_arrayListClear); (*env)->CallVoidMethod(env, supportedActions, mid_arrayListClear);
......
...@@ -32,27 +32,32 @@ ...@@ -32,27 +32,32 @@
#include "sun_nio_ch_NativeThread.h" #include "sun_nio_ch_NativeThread.h"
#include "nio_util.h" #include "nio_util.h"
#ifdef __linux__ #ifdef __linux__
#include <pthread.h> #include <pthread.h>
#include <sys/signal.h> #include <sys/signal.h>
/* Also defined in net/linux_close.c */
/* Also defined in src/solaris/native/java/net/linux_close.c */ #define INTERRUPT_SIGNAL (__SIGRTMAX - 2)
#define INTERRUPT_SIGNAL (__SIGRTMAX - 2) #elif __solaris__
#include <thread.h>
#include <signal.h>
#define INTERRUPT_SIGNAL (SIGRTMAX - 2)
#elif _ALLBSD_SOURCE
#include <pthread.h>
#include <signal.h>
/* Also defined in net/bsd_close.c */
#define INTERRUPT_SIGNAL SIGIO
#else
#error "missing platform-specific definition here"
#endif
static void static void
nullHandler(int sig) nullHandler(int sig)
{ {
} }
#endif
JNIEXPORT void JNICALL JNIEXPORT void JNICALL
Java_sun_nio_ch_NativeThread_init(JNIEnv *env, jclass cl) Java_sun_nio_ch_NativeThread_init(JNIEnv *env, jclass cl)
{ {
#ifdef __linux__
/* Install the null handler for INTERRUPT_SIGNAL. This might overwrite the /* Install the null handler for INTERRUPT_SIGNAL. This might overwrite the
* handler previously installed by java/net/linux_close.c, but that's okay * handler previously installed by java/net/linux_close.c, but that's okay
* since neither handler actually does anything. We install our own * since neither handler actually does anything. We install our own
...@@ -67,25 +72,27 @@ Java_sun_nio_ch_NativeThread_init(JNIEnv *env, jclass cl) ...@@ -67,25 +72,27 @@ Java_sun_nio_ch_NativeThread_init(JNIEnv *env, jclass cl)
sigemptyset(&sa.sa_mask); sigemptyset(&sa.sa_mask);
if (sigaction(INTERRUPT_SIGNAL, &sa, &osa) < 0) if (sigaction(INTERRUPT_SIGNAL, &sa, &osa) < 0)
JNU_ThrowIOExceptionWithLastError(env, "sigaction"); JNU_ThrowIOExceptionWithLastError(env, "sigaction");
#endif
} }
JNIEXPORT jlong JNICALL JNIEXPORT jlong JNICALL
Java_sun_nio_ch_NativeThread_current(JNIEnv *env, jclass cl) Java_sun_nio_ch_NativeThread_current(JNIEnv *env, jclass cl)
{ {
#ifdef __linux__ #ifdef __solaris__
return (long)pthread_self(); return (jlong)thr_self();
#else #else
return -1; return (jlong)pthread_self();
#endif #endif
} }
JNIEXPORT void JNICALL JNIEXPORT void JNICALL
Java_sun_nio_ch_NativeThread_signal(JNIEnv *env, jclass cl, jlong thread) Java_sun_nio_ch_NativeThread_signal(JNIEnv *env, jclass cl, jlong thread)
{ {
#ifdef __linux__ int ret;
if (pthread_kill((pthread_t)thread, INTERRUPT_SIGNAL)) #ifdef __solaris__
JNU_ThrowIOExceptionWithLastError(env, "Thread signal failed"); ret = thr_kill((thread_t)thread, INTERRUPT_SIGNAL);
#else
ret = pthread_kill((pthread_t)thread, INTERRUPT_SIGNAL);
#endif #endif
if (ret != 0)
JNU_ThrowIOExceptionWithLastError(env, "Thread signal failed");
} }
...@@ -188,11 +188,6 @@ java/net/DatagramSocket/SendDatagramToBadAddress.java macosx-all ...@@ -188,11 +188,6 @@ java/net/DatagramSocket/SendDatagramToBadAddress.java macosx-all
# 6963118 # 6963118
java/nio/channels/Selector/Wakeup.java windows-all java/nio/channels/Selector/Wakeup.java windows-all
# 7133499, 7133497
java/nio/channels/AsyncCloseAndInterrupt.java macosx-all
java/nio/channels/AsynchronousFileChannel/Lock.java macosx-all
java/nio/channels/FileChannel/Transfer.java macosx-all
# 7141822 # 7141822
java/nio/channels/DatagramChannel/ChangingAddress.java macosx-all java/nio/channels/DatagramChannel/ChangingAddress.java macosx-all
......
/*
* Copyright (c) 2014, 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.
*/
/* @test
@bug 8032078
@summary Frame.setExtendedState throws RuntimeException, if
windowState=ICONIFIED|MAXIMIZED_BOTH, on OS X
@author Anton Litvinov
*/
import java.awt.*;
import sun.awt.SunToolkit;
public class ExceptionOnSetExtendedStateTest {
private static final int[] frameStates = { Frame.NORMAL, Frame.ICONIFIED, Frame.MAXIMIZED_BOTH };
private static final SunToolkit toolkit = (SunToolkit)Toolkit.getDefaultToolkit();
private static boolean validatePlatform() {
String osName = System.getProperty("os.name");
if (osName == null) {
throw new RuntimeException("Name of the current OS could not be retrieved.");
}
return osName.startsWith("Mac");
}
private static void testStateChange(int oldState, int newState, boolean decoratedFrame) {
System.out.println(String.format(
"testStateChange: oldState='%d', newState='%d', decoratedFrame='%b'",
oldState, newState, decoratedFrame));
Frame frame = new Frame("ExceptionOnSetExtendedStateTest");
frame.setSize(200, 200);
frame.setUndecorated(!decoratedFrame);
frame.setVisible(true);
toolkit.realSync();
frame.setExtendedState(oldState);
sleep(1000);
frame.setExtendedState(newState);
boolean stateWasNotChanged = true;
int currentState = 0;
for (int i = 0; (i < 3) && stateWasNotChanged; i++) {
sleep(1000);
currentState = frame.getExtendedState();
if ((currentState == newState) ||
(((newState & Frame.ICONIFIED) != 0) && ((currentState & Frame.ICONIFIED) != 0))) {
stateWasNotChanged = false;
}
}
frame.dispose();
if (stateWasNotChanged) {
throw new RuntimeException(String.format(
"Frame state was not changed. currentState='%d'", currentState));
}
}
private static void sleep(int millis) {
try {
Thread.sleep(millis);
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
if (!validatePlatform()) {
System.out.println("This test is only for OS X.");
return;
}
// Verify that changing states of decorated/undecorated frame to/from supported states
// and the state bit mask ICONIFIED | MAXIMIZED_BOTH does not raise RuntimeException.
for (int i = 0; i < frameStates.length; i++) {
testStateChange(frameStates[i], Frame.ICONIFIED | Frame.MAXIMIZED_BOTH, true);
testStateChange(frameStates[i], Frame.ICONIFIED | Frame.MAXIMIZED_BOTH, false);
testStateChange(Frame.ICONIFIED | Frame.MAXIMIZED_BOTH, frameStates[i], true);
testStateChange(Frame.ICONIFIED | Frame.MAXIMIZED_BOTH, frameStates[i], false);
}
}
}
...@@ -22,52 +22,54 @@ ...@@ -22,52 +22,54 @@
*/ */
/** /**
* * Utility class for tests. A simple "in-thread" server to accept connections
* Utility class for tests. A simple server, which waits for a connection, * and write bytes.
* writes out n bytes and waits.
* @author kladko * @author kladko
*/ */
import java.net.Socket; import java.net.Socket;
import java.net.ServerSocket; import java.net.ServerSocket;
import java.net.SocketAddress;
import java.net.InetSocketAddress;
import java.io.IOException;
import java.io.Closeable;
public class ByteServer implements Closeable {
public class ByteServer { private final ServerSocket ss;
private Socket s;
public static final String LOCALHOST = "localhost"; ByteServer() throws IOException {
private int bytecount; this.ss = new ServerSocket(0);
private Socket socket; }
private ServerSocket serversocket;
private Thread serverthread; SocketAddress address() {
volatile Exception savedException; return new InetSocketAddress(ss.getInetAddress(), ss.getLocalPort());
}
public ByteServer(int bytecount) throws Exception{ void acceptConnection() throws IOException {
this.bytecount = bytecount; if (s != null)
serversocket = new ServerSocket(0); throw new IllegalStateException("already connected");
this.s = ss.accept();
} }
public int port() { void closeConnection() throws IOException {
return serversocket.getLocalPort(); Socket s = this.s;
if (s != null) {
this.s = null;
s.close();
}
} }
public void start() { void write(int count) throws IOException {
serverthread = new Thread() { if (s == null)
public void run() { throw new IllegalStateException("no connection");
try { s.getOutputStream().write(new byte[count]);
socket = serversocket.accept();
socket.getOutputStream().write(new byte[bytecount]);
socket.getOutputStream().flush();
} catch (Exception e) {
System.err.println("Exception in ByteServer: " + e);
System.exit(1);
}
}
};
serverthread.start();
} }
public void exit() throws Exception { public void close() throws IOException {
serverthread.join(); if (s != null)
socket.close(); s.close();
serversocket.close(); ss.close();
} }
} }
...@@ -27,27 +27,25 @@ ...@@ -27,27 +27,25 @@
* @author kladko * @author kladko
*/ */
import java.net.*; import java.nio.channels.Selector;
import java.nio.*; import java.nio.channels.SelectionKey;
import java.nio.channels.*; import java.nio.channels.SocketChannel;
public class ReadAfterConnect { public class ReadAfterConnect {
public static void main(String[] argv) throws Exception { public static void main(String[] argv) throws Exception {
ByteServer server = new ByteServer(0); // server: accept connection and do nothing try (ByteServer server = new ByteServer();
server.start(); SocketChannel sc = SocketChannel.open(server.address())) {
InetSocketAddress isa = new InetSocketAddress(
InetAddress.getByName(ByteServer.LOCALHOST), server.port()); server.acceptConnection();
Selector sel = Selector.open();
SocketChannel sc = SocketChannel.open(); try (Selector sel = Selector.open()) {
sc.connect(isa); sc.configureBlocking(false);
sc.configureBlocking(false); sc.register(sel, SelectionKey.OP_READ);
sc.register(sel, SelectionKey.OP_READ); // Previously channel would get selected here, although there is nothing to read
// Previously channel would get selected here, although there is nothing to read if (sel.selectNow() != 0)
if (sel.selectNow() != 0) throw new Exception("Select returned nonzero value");
throw new Exception("Select returned nonzero value"); }
sc.close(); }
server.exit();
} }
} }
...@@ -28,60 +28,62 @@ ...@@ -28,60 +28,62 @@
* @author kladko * @author kladko
*/ */
import java.net.*; import java.nio.ByteBuffer;
import java.nio.*; import java.nio.channels.Selector;
import java.nio.channels.*; import java.nio.channels.SelectionKey;
import java.nio.channels.SocketChannel;
public class SelectAfterRead { public class SelectAfterRead {
final static int TIMEOUT = 1000; private static final int TIMEOUT = 1000;
public static void main(String[] argv) throws Exception { public static void main(String[] argv) throws Exception {
InetAddress lh = InetAddress.getByName(ByteServer.LOCALHOST);
// server: accept connection and write one byte // server: accept connection and write one byte
ByteServer server = new ByteServer(1); try (ByteServer server = new ByteServer();
server.start(); SocketChannel sc = SocketChannel.open(server.address())) {
Selector sel = Selector.open();
SocketChannel sc = SocketChannel.open(); server.acceptConnection();
sc.connect(new InetSocketAddress(lh, server.port())); server.write(1);
sc.read(ByteBuffer.allocate(1));
sc.configureBlocking(false); try (Selector sel = Selector.open()) {
sc.register(sel, SelectionKey.OP_READ); sc.read(ByteBuffer.allocate(1));
// previously on Windows select would select channel here, although there was sc.configureBlocking(false);
// nothing to read sc.register(sel, SelectionKey.OP_READ);
if (sel.selectNow() != 0) // previously on Windows select would select channel here, although there was
throw new Exception("Select returned nonzero value"); // nothing to read
sc.close(); if (sel.selectNow() != 0)
sel.close(); throw new Exception("Select returned nonzero value");
server.exit(); }
}
// Now we will test a two reads combination // Now we will test a two reads combination
// server: accept connection and write two bytes // server: accept connection and write two bytes
server = new ByteServer(2); try (ByteServer server = new ByteServer();
server.start(); SocketChannel sc = SocketChannel.open(server.address())) {
sc = SocketChannel.open();
sc.connect(new InetSocketAddress(lh, server.port())); server.acceptConnection();
sc.configureBlocking(false); server.write(2);
sel = Selector.open();
sc.register(sel, SelectionKey.OP_READ); try (Selector sel = Selector.open()) {
if (sel.select(TIMEOUT) != 1) sc.configureBlocking(false);
throw new Exception("One selected key expected"); sc.register(sel, SelectionKey.OP_READ);
sel.selectedKeys().clear(); if (sel.select(TIMEOUT) != 1)
// previously on Windows a channel would get selected only once throw new Exception("One selected key expected");
if (sel.selectNow() != 1) sel.selectedKeys().clear();
throw new Exception("One selected key expected"); // previously on Windows a channel would get selected only once
// Previously on Windows two consequent reads would cause select() if (sel.selectNow() != 1)
// to select a channel, although there was nothing remaining to throw new Exception("One selected key expected");
// read in the channel // Previously on Windows two consequent reads would cause select()
if (sc.read(ByteBuffer.allocate(1)) != 1) // to select a channel, although there was nothing remaining to
throw new Exception("One byte expected"); // read in the channel
if (sc.read(ByteBuffer.allocate(1)) != 1) if (sc.read(ByteBuffer.allocate(1)) != 1)
throw new Exception("One byte expected"); throw new Exception("One byte expected");
if (sel.selectNow() != 0) if (sc.read(ByteBuffer.allocate(1)) != 1)
throw new Exception("Select returned nonzero value"); throw new Exception("One byte expected");
sc.close(); if (sel.selectNow() != 0)
sel.close(); throw new Exception("Select returned nonzero value");
server.exit(); }
}
} }
} }
...@@ -22,36 +22,33 @@ ...@@ -22,36 +22,33 @@
*/ */
/* @test /* @test
@bug 4645302 * @bug 4645302
@summary Socket with OP_WRITE would get selected only once * @summary Socket with OP_WRITE would get selected only once
@author kladko * @author kladko
*/ */
import java.net.*; import java.nio.channels.Selector;
import java.nio.*; import java.nio.channels.SelectionKey;
import java.nio.channels.*; import java.nio.channels.SocketChannel;
public class SelectWrite { public class SelectWrite {
public static void main(String[] argv) throws Exception { public static void main(String[] argv) throws Exception {
ByteServer server = new ByteServer(0); try (ByteServer server = new ByteServer();
// server: accept connection and do nothing SocketChannel sc = SocketChannel.open(server.address())) {
server.start();
InetSocketAddress isa = new InetSocketAddress( server.acceptConnection();
InetAddress.getByName(ByteServer.LOCALHOST), server.port());
Selector sel = Selector.open(); try (Selector sel = Selector.open()) {
SocketChannel sc = SocketChannel.open(); sc.configureBlocking(false);
sc.connect(isa); sc.register(sel, SelectionKey.OP_WRITE);
sc.configureBlocking(false); sel.select();
sc.register(sel, SelectionKey.OP_WRITE); sel.selectedKeys().clear();
sel.select(); if (sel.select() == 0) {
sel.selectedKeys().clear(); throw new Exception("Select returned zero");
if (sel.select() == 0) { }
throw new Exception("Select returned zero"); }
} }
sc.close();
sel.close();
} }
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册