mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 07:14:30 +02:00
8199791: (se) More Selector cleanup
Reviewed-by: redestad, bpb
This commit is contained in:
parent
de23920e05
commit
3bb85f5fc5
33 changed files with 754 additions and 1516 deletions
|
@ -127,7 +127,7 @@ class DevPollArrayWrapper {
|
|||
// descriptor is registered with /dev/poll.
|
||||
private final BitSet registered = new BitSet();
|
||||
|
||||
DevPollArrayWrapper() {
|
||||
DevPollArrayWrapper() throws IOException {
|
||||
int allocationSize = NUM_POLLFDS * SIZE_POLLFD;
|
||||
pollArray = new AllocatedNativeObject(allocationSize, true);
|
||||
pollArrayAddress = pollArray.address();
|
||||
|
@ -136,7 +136,7 @@ class DevPollArrayWrapper {
|
|||
eventsHigh = new HashMap<>();
|
||||
}
|
||||
|
||||
void initInterrupt(int fd0, int fd1) {
|
||||
void initInterrupt(int fd0, int fd1) throws IOException {
|
||||
outgoingInterruptFD = fd1;
|
||||
incomingInterruptFD = fd0;
|
||||
register(wfd, fd0, POLLIN);
|
||||
|
@ -200,7 +200,7 @@ class DevPollArrayWrapper {
|
|||
}
|
||||
}
|
||||
|
||||
void release(int fd) {
|
||||
void release(int fd) throws IOException {
|
||||
synchronized (updateLock) {
|
||||
// ignore any pending update for this file descriptor
|
||||
setUpdateEvents(fd, IGNORE);
|
||||
|
@ -297,7 +297,11 @@ class DevPollArrayWrapper {
|
|||
boolean interrupted = false;
|
||||
|
||||
public void interrupt() {
|
||||
interrupt(outgoingInterruptFD);
|
||||
try {
|
||||
IOUtil.write1(outgoingInterruptFD, (byte)0);
|
||||
} catch (IOException ioe) {
|
||||
throw new InternalError(ioe);
|
||||
}
|
||||
}
|
||||
|
||||
public int interruptedIndex() {
|
||||
|
@ -312,13 +316,12 @@ class DevPollArrayWrapper {
|
|||
interrupted = false;
|
||||
}
|
||||
|
||||
private native int init();
|
||||
private native void register(int wfd, int fd, int mask);
|
||||
private native int init() throws IOException;
|
||||
private native void register(int wfd, int fd, int mask) throws IOException;
|
||||
private native void registerMultiple(int wfd, long address, int len)
|
||||
throws IOException;
|
||||
private native int poll0(long pollAddress, int numfds, long timeout,
|
||||
int wfd);
|
||||
private static native void interrupt(int fd);
|
||||
private native int poll0(long pollAddress, int numfds, long timeout, int wfd)
|
||||
throws IOException;
|
||||
|
||||
static {
|
||||
IOUtil.load();
|
||||
|
|
|
@ -61,7 +61,7 @@ class DevPollSelectorImpl
|
|||
* Package private constructor called by factory method in
|
||||
* the abstract superclass Selector.
|
||||
*/
|
||||
DevPollSelectorImpl(SelectorProvider sp) {
|
||||
DevPollSelectorImpl(SelectorProvider sp) throws IOException {
|
||||
super(sp);
|
||||
long pipeFds = IOUtil.makePipe(false);
|
||||
fd0 = (int) (pipeFds >>> 32);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2018, 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
|
||||
|
@ -181,12 +181,26 @@ class EventPortWrapper {
|
|||
}
|
||||
|
||||
// poll for events
|
||||
int updated = port_getn(pfd, pollArrayAddress, POLL_MAX, timeout);
|
||||
int numEntries;
|
||||
long to = timeout;
|
||||
boolean timedPoll = (to > 0);
|
||||
do {
|
||||
long startTime = timedPoll ? System.currentTimeMillis() : 0;
|
||||
numEntries = port_getn(pfd, pollArrayAddress, POLL_MAX, timeout);
|
||||
if (numEntries == IOStatus.INTERRUPTED && timedPoll) {
|
||||
// timed poll interrupted so need to adjust timeout
|
||||
to -= System.currentTimeMillis() - startTime;
|
||||
if (to <= 0) {
|
||||
// timeout also expired so no retry
|
||||
numEntries = 0;
|
||||
}
|
||||
}
|
||||
} while (numEntries == IOStatus.INTERRUPTED);
|
||||
|
||||
// after polling we need to queue all polled file descriptors as they
|
||||
// are candidates to register for the next poll.
|
||||
synchronized (updateLock) {
|
||||
for (int i=0; i<updated; i++) {
|
||||
for (int i=0; i<numEntries; i++) {
|
||||
if (getSource(i) == PORT_SOURCE_USER) {
|
||||
interrupted = true;
|
||||
setDescriptor(i, -1);
|
||||
|
@ -199,7 +213,7 @@ class EventPortWrapper {
|
|||
}
|
||||
}
|
||||
|
||||
return updated;
|
||||
return numEntries;
|
||||
}
|
||||
|
||||
private void setInterest(int fd) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2008, 2018, 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
|
||||
|
@ -164,7 +164,10 @@ class SolarisEventPort
|
|||
// A error here is fatal (thread will not be replaced)
|
||||
replaceMe = false;
|
||||
try {
|
||||
port_get(port, address);
|
||||
int n;
|
||||
do {
|
||||
n = port_get(port, address);
|
||||
} while (n == IOStatus.INTERRUPTED);
|
||||
} catch (IOException x) {
|
||||
x.printStackTrace();
|
||||
return;
|
||||
|
@ -240,7 +243,7 @@ class SolarisEventPort
|
|||
/**
|
||||
* Retrieves a single event from a port
|
||||
*/
|
||||
static native void port_get(int port, long pe) throws IOException;
|
||||
static native int port_get(int port, long address) throws IOException;
|
||||
|
||||
/**
|
||||
* Retrieves at most {@code max} events from a port.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2001, 2018, 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
|
||||
|
@ -176,14 +176,3 @@ Java_sun_nio_ch_DevPollArrayWrapper_poll0(JNIEnv *env, jobject this,
|
|||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_sun_nio_ch_DevPollArrayWrapper_interrupt(JNIEnv *env, jclass this, jint fd)
|
||||
{
|
||||
int fakebuf[1];
|
||||
fakebuf[0] = 1;
|
||||
if (write(fd, fakebuf, 1) < 0) {
|
||||
JNU_ThrowIOExceptionWithLastError(env,
|
||||
"Write to interrupt fd failed");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2008, 2018, 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
|
||||
|
@ -23,17 +23,18 @@
|
|||
* questions.
|
||||
*/
|
||||
|
||||
#include "jni.h"
|
||||
#include "jni_util.h"
|
||||
#include "jvm.h"
|
||||
#include "jlong.h"
|
||||
#include "nio_util.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <dlfcn.h>
|
||||
#include <sys/types.h>
|
||||
#include <port.h>
|
||||
|
||||
#include "jni.h"
|
||||
#include "jni_util.h"
|
||||
#include "jvm.h"
|
||||
#include "jlong.h"
|
||||
#include "nio.h"
|
||||
#include "nio_util.h"
|
||||
|
||||
#include "sun_nio_ch_SolarisEventPort.h"
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
|
@ -51,8 +52,10 @@ JNIEXPORT void JNICALL
|
|||
Java_sun_nio_ch_SolarisEventPort_port_1close
|
||||
(JNIEnv* env, jclass clazz, jint port)
|
||||
{
|
||||
int res;
|
||||
RESTARTABLE(close(port), res);
|
||||
int res = close(port);
|
||||
if (res < 0 && res != EINTR) {
|
||||
JNU_ThrowIOExceptionWithLastError(env, "close failed");
|
||||
}
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL
|
||||
|
@ -93,17 +96,23 @@ Java_sun_nio_ch_SolarisEventPort_port_1send(JNIEnv* env, jclass clazz,
|
|||
}
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_sun_nio_ch_SolarisEventPort_port_1get(JNIEnv* env, jclass clazz,
|
||||
jint port, jlong eventAddress)
|
||||
{
|
||||
int res;
|
||||
port_event_t* ev = (port_event_t*)jlong_to_ptr(eventAddress);
|
||||
|
||||
RESTARTABLE(port_get((int)port, ev, NULL), res);
|
||||
res = port_get((int)port, ev, NULL);
|
||||
if (res == -1) {
|
||||
JNU_ThrowIOExceptionWithLastError(env, "port_get");
|
||||
if (errno == EINTR) {
|
||||
return IOS_INTERRUPTED;
|
||||
} else {
|
||||
JNU_ThrowIOExceptionWithLastError(env, "port_get failed");
|
||||
return IOS_THROWN;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
|
@ -125,9 +134,13 @@ Java_sun_nio_ch_SolarisEventPort_port_1getn(JNIEnv* env, jclass clazz,
|
|||
}
|
||||
|
||||
res = port_getn((int)port, list, (uint_t)max, &n, tsp);
|
||||
if (res == -1) {
|
||||
if (errno != ETIME && errno != EINTR)
|
||||
JNU_ThrowIOExceptionWithLastError(env, "port_getn");
|
||||
if (res == -1 && errno != ETIME) {
|
||||
if (errno == EINTR) {
|
||||
return IOS_INTERRUPTED;
|
||||
} else {
|
||||
JNU_ThrowIOExceptionWithLastError(env, "port_getn failed");
|
||||
return IOS_THROWN;
|
||||
}
|
||||
}
|
||||
|
||||
return (jint)n;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue