Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
320db92d
D
dragonwell8_jdk
项目概览
openanolis
/
dragonwell8_jdk
通知
4
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dragonwell8_jdk
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
320db92d
编写于
5月 24, 2012
作者:
A
alanb
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
7169050: (se) Selector.select slow on Solaris due to insertion of POLLREMOVE and 0 events
Reviewed-by: chegar, coffeys
上级
78fe8bc5
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
80 addition
and
59 deletion
+80
-59
src/solaris/classes/sun/nio/ch/DevPollArrayWrapper.java
src/solaris/classes/sun/nio/ch/DevPollArrayWrapper.java
+72
-44
src/solaris/native/sun/nio/ch/DevPollArrayWrapper.c
src/solaris/native/sun/nio/ch/DevPollArrayWrapper.c
+8
-15
未找到文件。
src/solaris/classes/sun/nio/ch/DevPollArrayWrapper.java
浏览文件 @
320db92d
...
@@ -25,9 +25,7 @@
...
@@ -25,9 +25,7 @@
package
sun.nio.ch
;
package
sun.nio.ch
;
import
sun.misc.*
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.util.LinkedList
;
/**
/**
...
@@ -66,6 +64,9 @@ class DevPollArrayWrapper {
...
@@ -66,6 +64,9 @@ class DevPollArrayWrapper {
static
final
short
EVENT_OFFSET
=
4
;
static
final
short
EVENT_OFFSET
=
4
;
static
final
short
REVENT_OFFSET
=
6
;
static
final
short
REVENT_OFFSET
=
6
;
// Special value to indicate that an update should be ignored
static
final
byte
CANCELLED
=
(
byte
)-
1
;
// Maximum number of open file descriptors
// Maximum number of open file descriptors
static
final
int
OPEN_MAX
=
fdLimit
();
static
final
int
OPEN_MAX
=
fdLimit
();
...
@@ -74,13 +75,16 @@ class DevPollArrayWrapper {
...
@@ -74,13 +75,16 @@ class DevPollArrayWrapper {
static
final
int
NUM_POLLFDS
=
Math
.
min
(
OPEN_MAX
-
1
,
8192
);
static
final
int
NUM_POLLFDS
=
Math
.
min
(
OPEN_MAX
-
1
,
8192
);
// Base address of the native pollArray
// Base address of the native pollArray
private
long
pollArrayAddress
;
private
final
long
pollArrayAddress
;
// Array of pollfd structs used for driver updates
// Array of pollfd structs used for driver updates
private
AllocatedNativeObject
updatePollArray
;
private
final
AllocatedNativeObject
updatePollArray
;
// Maximum number of POLL_FD structs to update at once
// Maximum number of POLL_FD structs to update at once
private
int
MAX_UPDATE_SIZE
=
Math
.
min
(
OPEN_MAX
,
10000
);
private
final
int
MAX_UPDATE_SIZE
=
Math
.
min
(
OPEN_MAX
,
512
);
// Initial size of arrays for fd registration changes
private
final
int
INITIAL_PENDING_UPDATE_SIZE
=
64
;
DevPollArrayWrapper
()
{
DevPollArrayWrapper
()
{
int
allocationSize
=
NUM_POLLFDS
*
SIZE_POLLFD
;
int
allocationSize
=
NUM_POLLFDS
*
SIZE_POLLFD
;
...
@@ -91,19 +95,6 @@ class DevPollArrayWrapper {
...
@@ -91,19 +95,6 @@ class DevPollArrayWrapper {
wfd
=
init
();
wfd
=
init
();
}
}
// Machinery for remembering fd registration changes
// A hashmap could be used but the number of changes pending
// is expected to be small
private
static
class
Updator
{
int
fd
;
int
mask
;
Updator
(
int
fd
,
int
mask
)
{
this
.
fd
=
fd
;
this
.
mask
=
mask
;
}
}
private
LinkedList
<
Updator
>
updateList
=
new
LinkedList
<
Updator
>();
// The pollfd array for results from devpoll driver
// The pollfd array for results from devpoll driver
private
AllocatedNativeObject
pollArray
;
private
AllocatedNativeObject
pollArray
;
...
@@ -122,6 +113,20 @@ class DevPollArrayWrapper {
...
@@ -122,6 +113,20 @@ class DevPollArrayWrapper {
// Number of updated pollfd entries
// Number of updated pollfd entries
int
updated
;
int
updated
;
// object to synchronize fd registration changes
private
final
Object
updateLock
=
new
Object
();
// number of file descriptors with registration changes pending
private
int
updateCount
;
// file descriptors with registration changes pending
private
int
[]
updateDescriptors
=
new
int
[
INITIAL_PENDING_UPDATE_SIZE
];
// events for file descriptors with registration changes pending, indexed
// by file descriptor and stored as bytes for efficiency reasons.
private
byte
[]
updateEvents
=
new
byte
[
OPEN_MAX
];
void
initInterrupt
(
int
fd0
,
int
fd1
)
{
void
initInterrupt
(
int
fd0
,
int
fd1
)
{
outgoingInterruptFD
=
fd1
;
outgoingInterruptFD
=
fd1
;
incomingInterruptFD
=
fd0
;
incomingInterruptFD
=
fd0
;
...
@@ -149,14 +154,32 @@ class DevPollArrayWrapper {
...
@@ -149,14 +154,32 @@ class DevPollArrayWrapper {
}
}
void
setInterest
(
int
fd
,
int
mask
)
{
void
setInterest
(
int
fd
,
int
mask
)
{
synchronized
(
updateList
)
{
synchronized
(
updateLock
)
{
updateList
.
add
(
new
Updator
(
fd
,
mask
));
// record the file descriptor and events, expanding the
// respective arrays first if necessary.
int
oldCapacity
=
updateDescriptors
.
length
;
if
(
updateCount
>=
oldCapacity
)
{
int
newCapacity
=
oldCapacity
+
INITIAL_PENDING_UPDATE_SIZE
;
int
[]
newDescriptors
=
new
int
[
newCapacity
];
System
.
arraycopy
(
updateDescriptors
,
0
,
newDescriptors
,
0
,
oldCapacity
);
updateDescriptors
=
newDescriptors
;
}
updateDescriptors
[
updateCount
++]
=
fd
;
// events are stored as bytes for efficiency reasons
byte
b
=
(
byte
)
mask
;
assert
(
b
==
mask
)
&&
(
b
!=
CANCELLED
);
updateEvents
[
fd
]
=
b
;
}
}
}
}
void
release
(
int
fd
)
{
void
release
(
int
fd
)
{
synchronized
(
updateList
)
{
synchronized
(
updateLock
)
{
updateList
.
add
(
new
Updator
(
fd
,
POLLREMOVE
));
// cancel any pending update for this file descriptor
updateEvents
[
fd
]
=
CANCELLED
;
// remove from /dev/poll
register
(
wfd
,
fd
,
POLLREMOVE
);
}
}
}
}
...
@@ -181,32 +204,37 @@ class DevPollArrayWrapper {
...
@@ -181,32 +204,37 @@ class DevPollArrayWrapper {
void
updateRegistrations
()
throws
IOException
{
void
updateRegistrations
()
throws
IOException
{
// Populate pollfd array with updated masks
// Populate pollfd array with updated masks
synchronized
(
updateList
)
{
synchronized
(
updateLock
)
{
while
(
updateList
.
size
()
>
0
)
{
// We have to insert a dummy node in between each
int
j
=
0
;
// real update to use POLLREMOVE on the fd first because
int
index
=
0
;
// otherwise the changes are simply OR'd together
while
(
j
<
updateCount
)
{
int
index
=
0
;
int
fd
=
updateDescriptors
[
j
];
Updator
u
=
null
;
short
events
=
updateEvents
[
fd
];
while
((
u
=
updateList
.
poll
())
!=
null
)
{
// First add pollfd struct to clear out this fd
// skip update if key has been cancelled
putPollFD
(
updatePollArray
,
index
,
u
.
fd
,
POLLREMOVE
);
if
(
events
!=
CANCELLED
)
{
// remove from /dev/poll when the interest ops changes to 0
if
(
events
==
0
)
events
=
POLLREMOVE
;
// populate pollfd array with updated event
putPollFD
(
updatePollArray
,
index
,
fd
,
events
);
index
++;
index
++;
// Now add pollfd to update this fd, if necessary
if
(
index
>=
MAX_UPDATE_SIZE
)
{
if
(
u
.
mask
!=
POLLREMOVE
)
{
registerMultiple
(
wfd
,
updatePollArray
.
address
(),
index
);
putPollFD
(
updatePollArray
,
index
,
u
.
fd
,
(
short
)
u
.
mask
);
index
=
0
;
index
++;
}
}
// Check against the max update size; these are
// all we will process. Valid index ranges from 0 to
// (MAX_UPDATE_SIZE - 1) and we can use up to 2 per loop
if
(
index
>
MAX_UPDATE_SIZE
-
2
)
break
;
}
}
// Register the changes with /dev/poll
j
++;
}
// write any remaining updates
if
(
index
>
0
)
registerMultiple
(
wfd
,
updatePollArray
.
address
(),
index
);
registerMultiple
(
wfd
,
updatePollArray
.
address
(),
index
);
}
updateCount
=
0
;
}
}
}
}
...
...
src/solaris/native/sun/nio/ch/DevPollArrayWrapper.c
浏览文件 @
320db92d
...
@@ -118,27 +118,20 @@ JNIEXPORT void JNICALL
...
@@ -118,27 +118,20 @@ JNIEXPORT void JNICALL
Java_sun_nio_ch_DevPollArrayWrapper_register
(
JNIEnv
*
env
,
jobject
this
,
Java_sun_nio_ch_DevPollArrayWrapper_register
(
JNIEnv
*
env
,
jobject
this
,
jint
wfd
,
jint
fd
,
jint
mask
)
jint
wfd
,
jint
fd
,
jint
mask
)
{
{
struct
pollfd
a
[
2
];
struct
pollfd
a
[
1
];
unsigned
char
*
pollBytes
=
(
unsigned
char
*
)
&
a
[
0
];
int
n
;
unsigned
char
*
pollEnd
=
pollBytes
+
sizeof
(
struct
pollfd
)
*
2
;
/* We clear it first, otherwise any entries between poll invocations
get OR'd together */
a
[
0
].
fd
=
fd
;
a
[
0
].
fd
=
fd
;
a
[
0
].
events
=
POLLREMOVE
;
a
[
0
].
events
=
mask
;
a
[
0
].
revents
=
0
;
a
[
0
].
revents
=
0
;
a
[
1
].
fd
=
fd
;
n
=
write
(
wfd
,
&
a
[
0
],
sizeof
(
a
));
a
[
1
].
events
=
mask
;
if
(
n
!=
sizeof
(
a
))
{
a
[
1
].
revents
=
0
;
if
(
n
<
0
)
{
while
(
pollBytes
<
pollEnd
)
{
int
bytesWritten
=
write
(
wfd
,
pollBytes
,
(
int
)(
pollEnd
-
pollBytes
));
if
(
bytesWritten
<
0
)
{
JNU_ThrowIOExceptionWithLastError
(
env
,
"Error writing pollfds"
);
JNU_ThrowIOExceptionWithLastError
(
env
,
"Error writing pollfds"
);
return
;
}
else
{
JNU_ThrowIOException
(
env
,
"Unexpected number of bytes written"
);
}
}
pollBytes
+=
bytesWritten
;
}
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录