Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
c7e0111d
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
c7e0111d
编写于
3月 01, 2010
作者:
V
vinnie
浏览文件
操作
浏览文件
下载
差异文件
Merge
上级
3c4c1193
fe7814be
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
269 addition
and
14 deletion
+269
-14
src/share/classes/java/lang/String.java
src/share/classes/java/lang/String.java
+1
-1
src/share/classes/java/util/DualPivotQuicksort.java
src/share/classes/java/util/DualPivotQuicksort.java
+8
-8
src/share/classes/sun/nio/fs/AbstractWatchKey.java
src/share/classes/sun/nio/fs/AbstractWatchKey.java
+35
-2
src/solaris/native/java/io/UnixFileSystem_md.c
src/solaris/native/java/io/UnixFileSystem_md.c
+3
-3
test/java/nio/file/WatchService/LotsOfEvents.java
test/java/nio/file/WatchService/LotsOfEvents.java
+222
-0
未找到文件。
src/share/classes/java/lang/String.java
浏览文件 @
c7e0111d
...
...
@@ -1492,7 +1492,7 @@ public final class String
*/
public
int
hashCode
()
{
int
h
=
hash
;
if
(
h
==
0
)
{
if
(
h
==
0
&&
count
>
0
)
{
int
off
=
offset
;
char
val
[]
=
value
;
int
len
=
count
;
...
...
src/share/classes/java/util/DualPivotQuicksort.java
浏览文件 @
c7e0111d
...
...
@@ -253,7 +253,7 @@ final class DualPivotQuicksort {
a
[
less
]
=
ak
;
}
less
++;
}
else
{
// (a[k] > pivot1) -
Move a[k] to right part
}
else
{
// (a[k] > pivot1) - Move a[k] to right part
/*
* We know that pivot1 == a[e3] == pivot2. Thus, we know
* that great will still be >= k when the following loop
...
...
@@ -531,7 +531,7 @@ final class DualPivotQuicksort {
a
[
less
]
=
ak
;
}
less
++;
}
else
{
// (a[k] > pivot1) -
Move a[k] to right part
}
else
{
// (a[k] > pivot1) - Move a[k] to right part
/*
* We know that pivot1 == a[e3] == pivot2. Thus, we know
* that great will still be >= k when the following loop
...
...
@@ -826,7 +826,7 @@ final class DualPivotQuicksort {
a
[
less
]
=
ak
;
}
less
++;
}
else
{
// (a[k] > pivot1) -
Move a[k] to right part
}
else
{
// (a[k] > pivot1) - Move a[k] to right part
/*
* We know that pivot1 == a[e3] == pivot2. Thus, we know
* that great will still be >= k when the following loop
...
...
@@ -1119,7 +1119,7 @@ final class DualPivotQuicksort {
a
[
less
]
=
ak
;
}
less
++;
}
else
{
// (a[k] > pivot1) -
Move a[k] to right part
}
else
{
// (a[k] > pivot1) - Move a[k] to right part
/*
* We know that pivot1 == a[e3] == pivot2. Thus, we know
* that great will still be >= k when the following loop
...
...
@@ -1414,7 +1414,7 @@ final class DualPivotQuicksort {
a
[
less
]
=
ak
;
}
less
++;
}
else
{
// (a[k] > pivot1) -
Move a[k] to right part
}
else
{
// (a[k] > pivot1) - Move a[k] to right part
/*
* We know that pivot1 == a[e3] == pivot2. Thus, we know
* that great will still be >= k when the following loop
...
...
@@ -1531,7 +1531,7 @@ final class DualPivotQuicksort {
* Sorts the specified range of the array into ascending order. The range
* to be sorted extends from the index {@code fromIndex}, inclusive, to
* the index {@code toIndex}, exclusive. If {@code fromIndex == toIndex},
* the range to be sorted is empty
and the call is a no-op).
* the range to be sorted is empty and the call is a no-op).
*
* <p>The {@code <} relation does not provide a total order on all float
* values: {@code -0.0f == 0.0f} is {@code true} and a {@code Float.NaN}
...
...
@@ -1787,7 +1787,7 @@ final class DualPivotQuicksort {
a
[
less
]
=
ak
;
}
less
++;
}
else
{
// (a[k] > pivot1) -
Move a[k] to right part
}
else
{
// (a[k] > pivot1) - Move a[k] to right part
/*
* We know that pivot1 == a[e3] == pivot2. Thus, we know
* that great will still be >= k when the following loop
...
...
@@ -2160,7 +2160,7 @@ final class DualPivotQuicksort {
a
[
less
]
=
ak
;
}
less
++;
}
else
{
// (a[k] > pivot1) -
Move a[k] to right part
}
else
{
// (a[k] > pivot1) - Move a[k] to right part
/*
* We know that pivot1 == a[e3] == pivot2. Thus, we know
* that great will still be >= k when the following loop
...
...
src/share/classes/sun/nio/fs/AbstractWatchKey.java
浏览文件 @
c7e0111d
...
...
@@ -59,10 +59,15 @@ abstract class AbstractWatchKey extends WatchKey {
// pending events
private
List
<
WatchEvent
<?>>
events
;
// maps a context to the last event for the context (iff the last queued
// event for the context is an ENTRY_MODIFY event).
private
Map
<
Object
,
WatchEvent
<?>>
lastModifyEvents
;
protected
AbstractWatchKey
(
AbstractWatchService
watcher
)
{
this
.
watcher
=
watcher
;
this
.
state
=
State
.
READY
;
this
.
events
=
new
ArrayList
<
WatchEvent
<?>>();
this
.
lastModifyEvents
=
new
HashMap
<
Object
,
WatchEvent
<?>>();
}
final
AbstractWatchService
watcher
()
{
...
...
@@ -86,6 +91,7 @@ abstract class AbstractWatchKey extends WatchKey {
*/
@SuppressWarnings
(
"unchecked"
)
final
void
signalEvent
(
WatchEvent
.
Kind
<?>
kind
,
Object
context
)
{
boolean
isModify
=
(
kind
==
StandardWatchEventKind
.
ENTRY_MODIFY
);
synchronized
(
this
)
{
int
size
=
events
.
size
();
if
(
size
>
0
)
{
...
...
@@ -100,17 +106,43 @@ abstract class AbstractWatchKey extends WatchKey {
return
;
}
// if this is a modify event and the last entry for the context
// is a modify event then we simply increment the count
if
(!
lastModifyEvents
.
isEmpty
())
{
if
(
isModify
)
{
WatchEvent
<?>
ev
=
lastModifyEvents
.
get
(
context
);
if
(
ev
!=
null
)
{
assert
ev
.
kind
()
==
StandardWatchEventKind
.
ENTRY_MODIFY
;
((
Event
<?>)
ev
).
increment
();
return
;
}
}
else
{
// not a modify event so remove from the map as the
// last event will no longer be a modify event.
lastModifyEvents
.
remove
(
context
);
}
}
// if the list has reached the limit then drop pending events
// and queue an OVERFLOW event
if
(
size
>=
MAX_EVENT_LIST_SIZE
)
{
events
.
clear
();
kind
=
StandardWatchEventKind
.
OVERFLOW
;
isModify
=
false
;
context
=
null
;
}
}
// non-repeated event
events
.
add
(
new
Event
<
Object
>((
WatchEvent
.
Kind
<
Object
>)
kind
,
context
));
Event
<
Object
>
ev
=
new
Event
<
Object
>((
WatchEvent
.
Kind
<
Object
>)
kind
,
context
);
if
(
isModify
)
{
lastModifyEvents
.
put
(
context
,
ev
);
}
else
if
(
kind
==
StandardWatchEventKind
.
OVERFLOW
)
{
// drop all pending events
events
.
clear
();
lastModifyEvents
.
clear
();
}
events
.
add
(
ev
);
signal
();
}
}
...
...
@@ -120,6 +152,7 @@ abstract class AbstractWatchKey extends WatchKey {
synchronized
(
this
)
{
List
<
WatchEvent
<?>>
result
=
events
;
events
=
new
ArrayList
<
WatchEvent
<?>>();
lastModifyEvents
.
clear
();
return
result
;
}
}
...
...
src/solaris/native/java/io/UnixFileSystem_md.c
浏览文件 @
c7e0111d
...
...
@@ -414,9 +414,9 @@ Java_java_io_UnixFileSystem_getSpace(JNIEnv *env, jobject this,
jlong
rv
=
0L
;
WITH_FIELD_PLATFORM_STRING
(
env
,
file
,
ids
.
path
,
path
)
{
struct
statvfs
fsstat
;
memset
(
&
fsstat
,
0
,
sizeof
(
struct
statvfs
));
if
(
statvfs
(
path
,
&
fsstat
)
==
0
)
{
struct
statvfs
64
fsstat
;
memset
(
&
fsstat
,
0
,
sizeof
(
fsstat
));
if
(
statvfs
64
(
path
,
&
fsstat
)
==
0
)
{
switch
(
t
)
{
case
java_io_FileSystem_SPACE_TOTAL
:
rv
=
jlong_mul
(
long_to_jlong
(
fsstat
.
f_frsize
),
...
...
test/java/nio/file/WatchService/
OverflowEventIsLoner
.java
→
test/java/nio/file/WatchService/
LotsOfEvents
.java
浏览文件 @
c7e0111d
...
...
@@ -22,22 +22,74 @@
*/
/* @test
* @bug 6907760
* @summary
Check that the OVERFLOW event is not retrieved with other events
* @bug 6907760
6929532
* @summary
Tests WatchService behavior when lots of events are pending
* @library ..
* @run main/timeout=180 LotsOfEvents
*/
import
java.nio.file.*
;
import
static
java
.
nio
.
file
.
StandardWatchEventKind
.*;
import
java.io.IOException
;
import
java.util.List
;
import
java.io.OutputStream
;
import
java.util.*
;
import
java.util.concurrent.TimeUnit
;
public
class
OverflowEventIsLoner
{
public
class
LotsOfEvents
{
static
void
drainEvents
(
WatchService
watcher
,
WatchEvent
.
Kind
<?>
expectedKind
,
int
count
)
static
final
Random
rand
=
new
Random
();
public
static
void
main
(
String
[]
args
)
throws
Exception
{
Path
dir
=
TestUtil
.
createTemporaryDirectory
();
try
{
testOverflowEvent
(
dir
);
testModifyEventsQueuing
(
dir
);
}
finally
{
TestUtil
.
removeAll
(
dir
);
}
}
/**
* Tests that OVERFLOW events are not retreived with other events.
*/
static
void
testOverflowEvent
(
Path
dir
)
throws
IOException
,
InterruptedException
{
WatchService
watcher
=
dir
.
getFileSystem
().
newWatchService
();
try
{
dir
.
register
(
watcher
,
ENTRY_CREATE
,
ENTRY_DELETE
);
// create a lot of files
int
n
=
1024
;
Path
[]
files
=
new
Path
[
n
];
for
(
int
i
=
0
;
i
<
n
;
i
++)
{
files
[
i
]
=
dir
.
resolve
(
"foo"
+
i
).
createFile
();
}
// give time for events to accumulate (improve chance of overflow)
Thread
.
sleep
(
1000
);
// check that we see the create events (or overflow)
drainAndCheckOverflowEvents
(
watcher
,
ENTRY_CREATE
,
n
);
// delete the files
for
(
int
i
=
0
;
i
<
n
;
i
++)
{
files
[
i
].
delete
();
}
// give time for events to accumulate (improve chance of overflow)
Thread
.
sleep
(
1000
);
// check that we see the delete events (or overflow)
drainAndCheckOverflowEvents
(
watcher
,
ENTRY_DELETE
,
n
);
}
finally
{
watcher
.
close
();
}
}
static
void
drainAndCheckOverflowEvents
(
WatchService
watcher
,
WatchEvent
.
Kind
<?>
expectedKind
,
int
count
)
throws
IOException
,
InterruptedException
{
// wait for key to be signalled - the timeout is long to allow for
...
...
@@ -77,46 +129,94 @@ public class OverflowEventIsLoner {
throw
new
RuntimeException
(
"Insufficient events"
);
}
/**
* Tests that check that ENTRY_MODIFY events are queued efficiently
*/
static
void
testModifyEventsQueuing
(
Path
dir
)
throws
IOException
,
InterruptedException
{
// this test uses a random number of files
final
int
nfiles
=
5
+
rand
.
nextInt
(
10
);
DirectoryEntry
[]
entries
=
new
DirectoryEntry
[
nfiles
];
for
(
int
i
=
0
;
i
<
nfiles
;
i
++)
{
entries
[
i
]
=
new
DirectoryEntry
(
dir
.
resolve
(
"foo"
+
i
));
// "some" of the files exist, some do not.
entries
[
i
].
deleteIfExists
();
if
(
rand
.
nextBoolean
())
entries
[
i
].
create
();
}
static
void
test
(
Path
dir
)
throws
IOException
,
InterruptedException
{
WatchService
watcher
=
dir
.
getFileSystem
().
newWatchService
();
try
{
WatchKey
key
=
dir
.
register
(
watcher
,
ENTRY_CREATE
,
ENTRY_DELETE
);
dir
.
register
(
watcher
,
ENTRY_CREATE
,
ENTRY_DELETE
,
ENTRY_MODIFY
);
// create a lot of files
int
n
=
1024
;
Path
[]
files
=
new
Path
[
n
];
for
(
int
i
=
0
;
i
<
n
;
i
++)
{
files
[
i
]
=
dir
.
resolve
(
"foo"
+
i
).
createFile
();
}
// do several rounds of noise and test
for
(
int
round
=
0
;
round
<
10
;
round
++)
{
// give time for events to accumulate (improve chance of overflow)
Thread
.
sleep
(
1000
);
// check that we see the create events (or overflow)
drainEvents
(
watcher
,
ENTRY_CREATE
,
n
);
// make some noise!!!
for
(
int
i
=
0
;
i
<
100
;
i
++)
{
DirectoryEntry
entry
=
entries
[
rand
.
nextInt
(
nfiles
)];
int
action
=
rand
.
nextInt
(
10
);
switch
(
action
)
{
case
0
:
entry
.
create
();
break
;
case
1
:
entry
.
deleteIfExists
();
break
;
default
:
entry
.
modifyIfExists
();
}
}
// delete the files
for
(
int
i
=
0
;
i
<
n
;
i
++)
{
files
[
i
].
delete
();
// process events and ensure that we don't get repeated modify
// events for the same file.
WatchKey
key
=
watcher
.
poll
(
15
,
TimeUnit
.
SECONDS
);
do
{
Set
<
Path
>
modified
=
new
HashSet
<
Path
>();
for
(
WatchEvent
<?>
event:
key
.
pollEvents
())
{
WatchEvent
.
Kind
<?>
kind
=
event
.
kind
();
Path
file
=
(
kind
==
OVERFLOW
)
?
null
:
(
Path
)
event
.
context
();
if
(
kind
==
ENTRY_MODIFY
)
{
boolean
added
=
modified
.
add
(
file
);
if
(!
added
)
{
throw
new
RuntimeException
(
"ENTRY_MODIFY events not queued efficiently"
);
}
}
else
{
if
(
file
!=
null
)
modified
.
remove
(
file
);
}
}
if
(!
key
.
reset
())
throw
new
RuntimeException
(
"Key is no longer valid"
);
key
=
watcher
.
poll
(
2
,
TimeUnit
.
SECONDS
);
}
while
(
key
!=
null
);
}
// give time for events to accumulate (improve chance of overflow)
Thread
.
sleep
(
1000
);
// check that we see the delete events (or overflow)
drainEvents
(
watcher
,
ENTRY_DELETE
,
n
);
}
finally
{
watcher
.
close
();
}
}
public
static
void
main
(
String
[]
args
)
throws
Exception
{
Path
dir
=
TestUtil
.
createTemporaryDirectory
();
try
{
test
(
dir
);
}
finally
{
TestUtil
.
removeAll
(
dir
);
static
class
DirectoryEntry
{
private
final
Path
file
;
DirectoryEntry
(
Path
file
)
{
this
.
file
=
file
;
}
void
create
()
throws
IOException
{
if
(
file
.
notExists
())
file
.
createFile
();
}
void
deleteIfExists
()
throws
IOException
{
file
.
deleteIfExists
();
}
void
modifyIfExists
()
throws
IOException
{
if
(
file
.
exists
())
{
OutputStream
out
=
file
.
newOutputStream
(
StandardOpenOption
.
APPEND
);
try
{
out
.
write
(
"message"
.
getBytes
());
}
finally
{
out
.
close
();
}
}
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录