Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
6277f7b6
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看板
提交
6277f7b6
编写于
4月 17, 2009
作者:
A
asaha
浏览文件
操作
浏览文件
下载
差异文件
Merge
上级
4e51a1aa
f6f6bec0
变更
23
隐藏空白更改
内联
并排
Showing
23 changed file
with
296 addition
and
157 deletion
+296
-157
src/share/classes/java/nio/ByteBufferAs-X-Buffer.java
src/share/classes/java/nio/ByteBufferAs-X-Buffer.java
+6
-4
src/share/classes/java/nio/Direct-X-Buffer.java
src/share/classes/java/nio/Direct-X-Buffer.java
+6
-4
src/share/classes/java/nio/Heap-X-Buffer.java
src/share/classes/java/nio/Heap-X-Buffer.java
+6
-3
src/share/classes/java/nio/StringCharBuffer.java
src/share/classes/java/nio/StringCharBuffer.java
+4
-2
src/share/classes/sun/nio/ch/AsynchronousFileChannelImpl.java
...share/classes/sun/nio/ch/AsynchronousFileChannelImpl.java
+24
-10
src/share/classes/sun/nio/ch/FileChannelImpl.java
src/share/classes/sun/nio/ch/FileChannelImpl.java
+30
-33
src/share/classes/sun/nio/ch/FileLockImpl.java
src/share/classes/sun/nio/ch/FileLockImpl.java
+4
-6
src/share/classes/sun/nio/ch/FileLockTable.java
src/share/classes/sun/nio/ch/FileLockTable.java
+10
-19
src/share/classes/sun/nio/ch/SimpleAsynchronousFileChannelImpl.java
...classes/sun/nio/ch/SimpleAsynchronousFileChannelImpl.java
+15
-23
src/windows/classes/sun/nio/ch/WindowsAsynchronousFileChannelImpl.java
...lasses/sun/nio/ch/WindowsAsynchronousFileChannelImpl.java
+2
-9
src/windows/native/sun/nio/ch/FileDispatcherImpl.c
src/windows/native/sun/nio/ch/FileDispatcherImpl.c
+1
-1
test/java/nio/Buffer/Basic-X.java
test/java/nio/Buffer/Basic-X.java
+7
-2
test/java/nio/Buffer/Basic.java
test/java/nio/Buffer/Basic.java
+1
-1
test/java/nio/Buffer/BasicByte.java
test/java/nio/Buffer/BasicByte.java
+5
-0
test/java/nio/Buffer/BasicChar.java
test/java/nio/Buffer/BasicChar.java
+7
-2
test/java/nio/Buffer/BasicDouble.java
test/java/nio/Buffer/BasicDouble.java
+5
-0
test/java/nio/Buffer/BasicFloat.java
test/java/nio/Buffer/BasicFloat.java
+5
-0
test/java/nio/Buffer/BasicInt.java
test/java/nio/Buffer/BasicInt.java
+5
-0
test/java/nio/Buffer/BasicLong.java
test/java/nio/Buffer/BasicLong.java
+5
-0
test/java/nio/Buffer/BasicShort.java
test/java/nio/Buffer/BasicShort.java
+5
-0
test/java/nio/channels/AsynchronousFileChannel/Basic.java
test/java/nio/channels/AsynchronousFileChannel/Basic.java
+44
-37
test/java/nio/channels/AsynchronousFileChannel/Lock.java
test/java/nio/channels/AsynchronousFileChannel/Lock.java
+1
-1
test/java/nio/channels/FileChannel/ReleaseOnCloseDeadlock.java
...java/nio/channels/FileChannel/ReleaseOnCloseDeadlock.java
+98
-0
未找到文件。
src/share/classes/java/nio/ByteBufferAs-X-Buffer.java
浏览文件 @
6277f7b6
...
...
@@ -196,10 +196,12 @@ class ByteBufferAs$Type$Buffer$RW$$BO$ // package-private
if
((
start
<
0
)
||
(
end
>
len
)
||
(
start
>
end
))
throw
new
IndexOutOfBoundsException
();
int
sublen
=
end
-
start
;
int
off
=
offset
+
((
pos
+
start
)
<<
$LG_BYTES_PER_VALUE
$
);
assert
(
off
>=
0
);
return
new
ByteBufferAsCharBuffer
$RW
$
$BO
$
(
bb
,
-
1
,
0
,
sublen
,
sublen
,
off
);
return
new
ByteBufferAsCharBuffer
$RW
$
$BO
$
(
bb
,
-
1
,
pos
+
start
,
pos
+
end
,
capacity
(),
offset
);
}
#
end
[
char
]
...
...
src/share/classes/java/nio/Direct-X-Buffer.java
浏览文件 @
6277f7b6
...
...
@@ -412,10 +412,12 @@ class Direct$Type$Buffer$RW$$BO$
if
((
start
<
0
)
||
(
end
>
len
)
||
(
start
>
end
))
throw
new
IndexOutOfBoundsException
();
int
sublen
=
end
-
start
;
int
off
=
(
pos
+
start
)
<<
$LG_BYTES_PER_VALUE
$
;
assert
(
off
>=
0
);
return
new
DirectCharBuffer
$RW
$
$BO
$
(
this
,
-
1
,
0
,
sublen
,
sublen
,
off
);
return
new
DirectCharBuffer
$RW
$
$BO
$
(
this
,
-
1
,
pos
+
start
,
pos
+
end
,
capacity
(),
offset
);
}
#
end
[
char
]
...
...
src/share/classes/java/nio/Heap-X-Buffer.java
浏览文件 @
6277f7b6
...
...
@@ -572,10 +572,13 @@ class Heap$Type$Buffer$RW$
||
(
end
>
length
())
||
(
start
>
end
))
throw
new
IndexOutOfBoundsException
();
int
len
=
end
-
start
;
int
pos
=
position
()
;
return
new
HeapCharBuffer
$RW
$
(
hb
,
-
1
,
0
,
len
,
len
,
offset
+
position
()
+
start
);
-
1
,
pos
+
start
,
pos
+
end
,
capacity
(),
offset
);
}
#
end
[
char
]
...
...
src/share/classes/java/nio/StringCharBuffer.java
浏览文件 @
6277f7b6
...
...
@@ -102,10 +102,12 @@ class StringCharBuffer // package-private
public
final
CharBuffer
subSequence
(
int
start
,
int
end
)
{
try
{
int
pos
=
position
();
return
new
StringCharBuffer
(
str
,
-
1
,
return
new
StringCharBuffer
(
str
,
-
1
,
pos
+
checkIndex
(
start
,
pos
),
pos
+
checkIndex
(
end
,
pos
),
remaining
(),
offset
);
capacity
(),
offset
);
}
catch
(
IllegalArgumentException
x
)
{
throw
new
IndexOutOfBoundsException
();
}
...
...
src/share/classes/sun/nio/ch/AsynchronousFileChannelImpl.java
浏览文件 @
6277f7b6
...
...
@@ -113,16 +113,16 @@ abstract class AsynchronousFileChannelImpl
}
}
final
void
invalidateAllLocks
()
{
final
void
invalidateAllLocks
()
throws
IOException
{
if
(
fileLockTable
!=
null
)
{
try
{
fileLockTable
.
removeAll
(
new
FileLockTable
.
Releaser
()
{
public
void
release
(
FileLock
fl
)
{
((
FileLockImpl
)
fl
).
invalidate
();
for
(
FileLock
fl:
fileLockTable
.
removeAll
())
{
synchronized
(
fl
)
{
if
(
fl
.
isValid
())
{
FileLockImpl
fli
=
(
FileLockImpl
)
fl
;
implRelease
(
fli
);
fli
.
invalidate
();
}
});
}
catch
(
IOException
e
)
{
throw
new
AssertionError
(
e
);
}
}
}
}
...
...
@@ -158,7 +158,21 @@ abstract class AsynchronousFileChannelImpl
}
/**
* Invoked by FileLockImpl to release lock acquired by this channel.
* Releases the given file lock.
*/
protected
abstract
void
implRelease
(
FileLockImpl
fli
)
throws
IOException
;
/**
* Invoked by FileLockImpl to release the given file lock and remove it
* from the lock table.
*/
abstract
void
release
(
FileLockImpl
fli
)
throws
IOException
;
final
void
release
(
FileLockImpl
fli
)
throws
IOException
{
try
{
begin
();
implRelease
(
fli
);
removeFromFileLockTable
(
fli
);
}
finally
{
end
();
}
}
}
src/share/classes/sun/nio/ch/FileChannelImpl.java
浏览文件 @
6277f7b6
...
...
@@ -33,8 +33,6 @@ import java.nio.BufferPoolMXBean;
import
java.nio.channels.*
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Iterator
;
import
java.lang.reflect.Field
;
import
java.security.AccessController
;
import
javax.management.ObjectName
;
import
javax.management.MalformedObjectNameException
;
...
...
@@ -95,14 +93,16 @@ public class FileChannelImpl
// -- Standard channel operations --
protected
void
implCloseChannel
()
throws
IOException
{
//
Invalidate and releas
e any locks that we still hold
//
Release and invalidat
e any locks that we still hold
if
(
fileLockTable
!=
null
)
{
fileLockTable
.
removeAll
(
new
FileLockTable
.
Releaser
()
{
public
void
release
(
FileLock
fl
)
throws
IOException
{
((
FileLockImpl
)
fl
).
invalidate
();
nd
.
release
(
fd
,
fl
.
position
(),
fl
.
size
());
for
(
FileLock
fl:
fileLockTable
.
removeAll
())
{
synchronized
(
fl
)
{
if
(
fl
.
isValid
())
{
nd
.
release
(
fd
,
fl
.
position
(),
fl
.
size
());
((
FileLockImpl
)
fl
).
invalidate
();
}
}
}
);
}
}
nd
.
preClose
(
fd
);
...
...
@@ -912,32 +912,33 @@ public class FileChannelImpl
FileLockImpl
fli
=
new
FileLockImpl
(
this
,
position
,
size
,
shared
);
FileLockTable
flt
=
fileLockTable
();
flt
.
add
(
fli
);
boolean
i
=
tru
e
;
boolean
completed
=
fals
e
;
int
ti
=
-
1
;
try
{
begin
();
ti
=
threads
.
add
();
if
(!
isOpen
())
return
null
;
int
result
=
nd
.
lock
(
fd
,
true
,
position
,
size
,
shared
);
if
(
result
==
FileDispatcher
.
RET_EX_LOCK
)
{
assert
shared
;
FileLockImpl
fli2
=
new
FileLockImpl
(
this
,
position
,
size
,
false
);
flt
.
replace
(
fli
,
fli2
);
return
fli2
;
}
if
(
result
==
FileDispatcher
.
INTERRUPTED
||
result
==
FileDispatcher
.
NO_LOCK
)
{
flt
.
remove
(
fli
);
i
=
false
;
int
n
;
do
{
n
=
nd
.
lock
(
fd
,
true
,
position
,
size
,
shared
);
}
while
((
n
==
FileDispatcher
.
INTERRUPTED
)
&&
isOpen
());
if
(
isOpen
())
{
if
(
n
==
FileDispatcher
.
RET_EX_LOCK
)
{
assert
shared
;
FileLockImpl
fli2
=
new
FileLockImpl
(
this
,
position
,
size
,
false
);
flt
.
replace
(
fli
,
fli2
);
fli
=
fli2
;
}
completed
=
true
;
}
}
catch
(
IOException
e
)
{
flt
.
remove
(
fli
);
throw
e
;
}
finally
{
if
(!
completed
)
flt
.
remove
(
fli
);
threads
.
remove
(
ti
);
try
{
end
(
i
);
end
(
completed
);
}
catch
(
ClosedByInterruptException
e
)
{
throw
new
FileLockInterruptionException
();
}
...
...
@@ -985,7 +986,6 @@ public class FileChannelImpl
}
void
release
(
FileLockImpl
fli
)
throws
IOException
{
ensureOpen
();
int
ti
=
threads
.
add
();
try
{
ensureOpen
();
...
...
@@ -1005,7 +1005,7 @@ public class FileChannelImpl
*/
private
static
class
SimpleFileLockTable
extends
FileLockTable
{
// synchronize on list for access
private
List
<
FileLock
>
lockList
=
new
ArrayList
<
FileLock
>(
2
);
private
final
List
<
FileLock
>
lockList
=
new
ArrayList
<
FileLock
>(
2
);
public
SimpleFileLockTable
()
{
}
...
...
@@ -1034,14 +1034,11 @@ public class FileChannelImpl
}
}
public
void
removeAll
(
Releaser
releaser
)
throws
IOException
{
public
List
<
FileLock
>
removeAll
()
{
synchronized
(
lockList
)
{
Iterator
<
FileLock
>
i
=
lockList
.
iterator
();
while
(
i
.
hasNext
())
{
FileLock
fl
=
i
.
next
();
releaser
.
release
(
fl
);
i
.
remove
();
}
List
<
FileLock
>
result
=
new
ArrayList
<
FileLock
>(
lockList
);
lockList
.
clear
();
return
result
;
}
}
...
...
src/share/classes/sun/nio/ch/FileLockImpl.java
浏览文件 @
6277f7b6
...
...
@@ -31,25 +31,24 @@ import java.nio.channels.*;
public
class
FileLockImpl
extends
FileLock
{
boolean
valid
;
private
volatile
boolean
valid
=
true
;
FileLockImpl
(
FileChannel
channel
,
long
position
,
long
size
,
boolean
shared
)
{
super
(
channel
,
position
,
size
,
shared
);
this
.
valid
=
true
;
}
FileLockImpl
(
AsynchronousFileChannel
channel
,
long
position
,
long
size
,
boolean
shared
)
{
super
(
channel
,
position
,
size
,
shared
);
this
.
valid
=
true
;
}
public
synchronized
boolean
isValid
()
{
public
boolean
isValid
()
{
return
valid
;
}
synchronized
void
invalidate
()
{
void
invalidate
()
{
assert
Thread
.
holdsLock
(
this
);
valid
=
false
;
}
...
...
@@ -66,5 +65,4 @@ public class FileLockImpl
valid
=
false
;
}
}
}
src/share/classes/sun/nio/ch/FileLockTable.java
浏览文件 @
6277f7b6
...
...
@@ -60,23 +60,12 @@ abstract class FileLockTable {
*/
public
abstract
void
remove
(
FileLock
fl
);
/**
* An implementation of this interface releases a given file lock.
* Used with removeAll.
*/
public
abstract
interface
Releaser
{
void
release
(
FileLock
fl
)
throws
IOException
;
}
/**
* Removes all file locks from the table.
* <p>
* The Releaser#release method is invoked for each file lock before
* it is removed.
*
* @
throws IOException if the release method throws IOException
* @
return The list of file locks removed
*/
public
abstract
void
removeAll
(
Releaser
r
)
throws
IOException
;
public
abstract
List
<
FileLock
>
removeAll
()
;
/**
* Replaces an existing file lock in the table.
...
...
@@ -195,7 +184,7 @@ class SharedFileLockTable extends FileLockTable {
FileLockReference
ref
=
list
.
get
(
index
);
FileLock
lock
=
ref
.
get
();
if
(
lock
==
fl
)
{
assert
(
lock
!=
null
)
&&
(
lock
.
channel
()
==
channel
);
assert
(
lock
!=
null
)
&&
(
lock
.
acquiredBy
()
==
channel
);
ref
.
clear
();
list
.
remove
(
index
);
break
;
...
...
@@ -206,7 +195,8 @@ class SharedFileLockTable extends FileLockTable {
}
@Override
public
void
removeAll
(
Releaser
releaser
)
throws
IOException
{
public
List
<
FileLock
>
removeAll
()
{
List
<
FileLock
>
result
=
new
ArrayList
<
FileLock
>();
List
<
FileLockReference
>
list
=
lockMap
.
get
(
fileKey
);
if
(
list
!=
null
)
{
synchronized
(
list
)
{
...
...
@@ -216,13 +206,13 @@ class SharedFileLockTable extends FileLockTable {
FileLock
lock
=
ref
.
get
();
// remove locks obtained by this channel
if
(
lock
!=
null
&&
lock
.
channel
()
==
channel
)
{
// invoke the releaser to invalidate/release the lock
releaser
.
release
(
lock
);
if
(
lock
!=
null
&&
lock
.
acquiredBy
()
==
channel
)
{
// remove the lock from the list
ref
.
clear
();
list
.
remove
(
index
);
// add to result
result
.
add
(
lock
);
}
else
{
index
++;
}
...
...
@@ -232,6 +222,7 @@ class SharedFileLockTable extends FileLockTable {
removeKeyIfEmpty
(
fileKey
,
list
);
}
}
return
result
;
}
@Override
...
...
src/share/classes/sun/nio/ch/SimpleAsynchronousFileChannelImpl.java
浏览文件 @
6277f7b6
...
...
@@ -97,6 +97,9 @@ public class SimpleAsynchronousFileChannelImpl
// then it will throw ClosedChannelException
}
// Invalidate and release any locks that we still hold
invalidateAllLocks
();
// signal any threads blocked on this channel
nd
.
preClose
(
fdObj
);
threads
.
signalAndWait
();
...
...
@@ -109,9 +112,6 @@ public class SimpleAsynchronousFileChannelImpl
closeLock
.
writeLock
().
unlock
();
}
// Invalidate and release any locks that we still hold
invalidateAllLocks
();
// close file
nd
.
close
(
fdObj
);
...
...
@@ -226,11 +226,9 @@ public class SimpleAsynchronousFileChannelImpl
do
{
n
=
nd
.
lock
(
fdObj
,
true
,
position
,
size
,
shared
);
}
while
((
n
==
FileDispatcher
.
INTERRUPTED
)
&&
isOpen
());
if
(
n
==
FileDispatcher
.
LOCKED
)
{
if
(
n
==
FileDispatcher
.
LOCKED
&&
isOpen
()
)
{
result
.
setResult
(
fli
);
}
else
{
if
(
n
!=
FileDispatcher
.
INTERRUPTED
)
throw
new
AssertionError
();
throw
new
AsynchronousCloseException
();
}
}
catch
(
IOException
x
)
{
...
...
@@ -279,16 +277,16 @@ public class SimpleAsynchronousFileChannelImpl
do
{
n
=
nd
.
lock
(
fdObj
,
false
,
position
,
size
,
shared
);
}
while
((
n
==
FileDispatcher
.
INTERRUPTED
)
&&
isOpen
());
if
(
n
!=
FileDispatcher
.
LOCKED
)
{
if
(
n
==
FileDispatcher
.
NO_LOCK
)
return
null
;
// locked by someone else
if
(
n
==
FileDispatcher
.
INTERRUPTED
)
throw
new
AsynchronousCloseException
();
// should not get here
throw
new
AssertionError
();
if
(
n
==
FileDispatcher
.
LOCKED
&&
isOpen
())
{
gotLock
=
true
;
return
fli
;
// lock acquired
}
gotLock
=
true
;
return
fli
;
if
(
n
==
FileDispatcher
.
NO_LOCK
)
return
null
;
// locked by someone else
if
(
n
==
FileDispatcher
.
INTERRUPTED
)
throw
new
AsynchronousCloseException
();
// should not get here
throw
new
AssertionError
();
}
finally
{
if
(!
gotLock
)
removeFromFileLockTable
(
fli
);
...
...
@@ -298,14 +296,8 @@ public class SimpleAsynchronousFileChannelImpl
}
@Override
void
release
(
FileLockImpl
fli
)
throws
IOException
{
try
{
begin
();
nd
.
release
(
fdObj
,
fli
.
position
(),
fli
.
size
());
removeFromFileLockTable
(
fli
);
}
finally
{
end
();
}
protected
void
implRelease
(
FileLockImpl
fli
)
throws
IOException
{
nd
.
release
(
fdObj
,
fli
.
position
(),
fli
.
size
());
}
@Override
...
...
src/windows/classes/sun/nio/ch/WindowsAsynchronousFileChannelImpl.java
浏览文件 @
6277f7b6
...
...
@@ -354,16 +354,9 @@ public class WindowsAsynchronousFileChannelImpl
}
}
// invoke by FileFileImpl to release lock
@Override
void
release
(
FileLockImpl
fli
)
throws
IOException
{
try
{
begin
();
nd
.
release
(
fdObj
,
fli
.
position
(),
fli
.
size
());
removeFromFileLockTable
(
fli
);
}
finally
{
end
();
}
protected
void
implRelease
(
FileLockImpl
fli
)
throws
IOException
{
nd
.
release
(
fdObj
,
fli
.
position
(),
fli
.
size
());
}
/**
...
...
src/windows/native/sun/nio/ch/FileDispatcherImpl.c
浏览文件 @
6277f7b6
...
...
@@ -414,7 +414,7 @@ Java_sun_nio_ch_FileDispatcherImpl_release0(JNIEnv *env, jobject this,
o
.
Offset
=
lowPos
;
o
.
OffsetHigh
=
highPos
;
result
=
UnlockFileEx
(
h
,
0
,
lowNumBytes
,
highNumBytes
,
&
o
);
if
(
result
==
0
)
{
if
(
result
==
0
&&
GetLastError
()
!=
ERROR_NOT_LOCKED
)
{
JNU_ThrowIOExceptionWithLastError
(
env
,
"Release failed"
);
}
}
...
...
test/java/nio/Buffer/Basic-X.java
浏览文件 @
6277f7b6
...
...
@@ -365,8 +365,11 @@ public class Basic$Type$
b
.
position
(
2
);
ck
(
b
,
b
.
charAt
(
1
),
'd'
);
CharBuffer
c
=
(
CharBuffer
)
b
.
subSequence
(
1
,
4
);
ck
(
b
,
b
.
subSequence
(
1
,
4
).
toString
().
equals
(
"def"
));
CharBuffer
c
=
b
.
subSequence
(
1
,
4
);
ck
(
c
,
c
.
capacity
(),
b
.
capacity
());
ck
(
c
,
c
.
position
(),
b
.
position
()+
1
);
ck
(
c
,
c
.
limit
(),
b
.
position
()+
4
);
ck
(
c
,
b
.
subSequence
(
1
,
4
).
toString
().
equals
(
"def"
));
// 4938424
b
.
position
(
4
);
...
...
@@ -722,6 +725,8 @@ public class Basic$Type$
ck
(
b
,
start
,
b
.
position
());
ck
(
b
,
end
,
b
.
limit
());
ck
(
b
,
s
.
length
(),
b
.
capacity
());
b
.
position
(
6
);
ck
(
b
,
b
.
subSequence
(
0
,
3
).
toString
().
equals
(
"ghi"
));
// The index, relative to the position, must be non-negative and
// smaller than remaining().
...
...
test/java/nio/Buffer/Basic.java
浏览文件 @
6277f7b6
...
...
@@ -25,7 +25,7 @@
* @summary Unit test for buffers
* @bug 4413135 4414911 4416536 4416562 4418782 4471053 4472779 4490253 4523725
* 4526177 4463011 4660660 4661219 4663521 4782970 4804304 4938424 6231529
* 6221101 6234263 6535542 6591971 6593946
* 6221101 6234263 6535542 6591971 6593946
6795561
* @author Mark Reinhold
*/
...
...
test/java/nio/Buffer/BasicByte.java
浏览文件 @
6277f7b6
...
...
@@ -371,6 +371,9 @@ public class BasicByte
...
...
@@ -783,6 +786,8 @@ public class BasicByte
...
...
test/java/nio/Buffer/BasicChar.java
浏览文件 @
6277f7b6
...
...
@@ -365,8 +365,11 @@ public class BasicChar
b
.
position
(
2
);
ck
(
b
,
b
.
charAt
(
1
),
'd'
);
CharBuffer
c
=
(
CharBuffer
)
b
.
subSequence
(
1
,
4
);
ck
(
b
,
b
.
subSequence
(
1
,
4
).
toString
().
equals
(
"def"
));
CharBuffer
c
=
b
.
subSequence
(
1
,
4
);
ck
(
c
,
c
.
capacity
(),
b
.
capacity
());
ck
(
c
,
c
.
position
(),
b
.
position
()+
1
);
ck
(
c
,
c
.
limit
(),
b
.
position
()+
4
);
ck
(
c
,
b
.
subSequence
(
1
,
4
).
toString
().
equals
(
"def"
));
// 4938424
b
.
position
(
4
);
...
...
@@ -722,6 +725,8 @@ public class BasicChar
ck
(
b
,
start
,
b
.
position
());
ck
(
b
,
end
,
b
.
limit
());
ck
(
b
,
s
.
length
(),
b
.
capacity
());
b
.
position
(
6
);
ck
(
b
,
b
.
subSequence
(
0
,
3
).
toString
().
equals
(
"ghi"
));
// The index, relative to the position, must be non-negative and
// smaller than remaining().
...
...
test/java/nio/Buffer/BasicDouble.java
浏览文件 @
6277f7b6
...
...
@@ -371,6 +371,9 @@ public class BasicDouble
...
...
@@ -783,6 +786,8 @@ public class BasicDouble
...
...
test/java/nio/Buffer/BasicFloat.java
浏览文件 @
6277f7b6
...
...
@@ -371,6 +371,9 @@ public class BasicFloat
...
...
@@ -783,6 +786,8 @@ public class BasicFloat
...
...
test/java/nio/Buffer/BasicInt.java
浏览文件 @
6277f7b6
...
...
@@ -371,6 +371,9 @@ public class BasicInt
...
...
@@ -783,6 +786,8 @@ public class BasicInt
...
...
test/java/nio/Buffer/BasicLong.java
浏览文件 @
6277f7b6
...
...
@@ -371,6 +371,9 @@ public class BasicLong
...
...
@@ -783,6 +786,8 @@ public class BasicLong
...
...
test/java/nio/Buffer/BasicShort.java
浏览文件 @
6277f7b6
...
...
@@ -371,6 +371,9 @@ public class BasicShort
...
...
@@ -783,6 +786,8 @@ public class BasicShort
...
...
test/java/nio/channels/AsynchronousFileChannel/Basic.java
浏览文件 @
6277f7b6
...
...
@@ -22,7 +22,7 @@
*/
/* @test
* @bug 4607272
* @bug 4607272
6822643
* @summary Unit test for AsynchronousFileChannel
*/
...
...
@@ -51,7 +51,6 @@ public class Basic {
// run tests
testUsingCompletionHandlers
(
ch
);
testUsingWaitOnResult
(
ch
);
testLocking
(
ch
);
testInterruptHandlerThread
(
ch
);
// close channel and invoke test that expects channel to be closed
...
...
@@ -59,6 +58,7 @@ public class Basic {
testClosedChannel
(
ch
);
// these tests open the file themselves
testLocking
(
blah
.
toPath
());
testCustomThreadPool
(
blah
.
toPath
());
testAsynchronousClose
(
blah
.
toPath
());
testCancel
(
blah
.
toPath
());
...
...
@@ -160,47 +160,54 @@ public class Basic {
}
// exercise lock methods
static
void
testLocking
(
AsynchronousFileChannel
ch
)
throws
IOException
{
static
void
testLocking
(
Path
file
)
throws
IOException
{
System
.
out
.
println
(
"testLocking"
);
// test 1 - acquire lock and check that tryLock throws
// OverlappingFileLockException
AsynchronousFileChannel
ch
=
AsynchronousFileChannel
.
open
(
file
,
READ
,
WRITE
);
FileLock
fl
;
try
{
fl
=
ch
.
lock
().
get
();
}
catch
(
ExecutionException
x
)
{
throw
new
RuntimeException
(
x
);
}
catch
(
InterruptedException
x
)
{
throw
new
RuntimeException
(
"Should not be interrupted"
);
}
if
(!
fl
.
acquiredBy
().
equals
(
ch
))
throw
new
RuntimeException
(
"FileLock#acquiredBy returned incorrect channel"
);
try
{
ch
.
tryLock
();
throw
new
RuntimeException
(
"OverlappingFileLockException expected"
);
}
catch
(
OverlappingFileLockException
x
)
{
}
fl
.
release
();
// test 1 - acquire lock and check that tryLock throws
// OverlappingFileLockException
try
{
fl
=
ch
.
lock
().
get
();
}
catch
(
ExecutionException
x
)
{
throw
new
RuntimeException
(
x
);
}
catch
(
InterruptedException
x
)
{
throw
new
RuntimeException
(
"Should not be interrupted"
);
}
if
(!
fl
.
acquiredBy
().
equals
(
ch
))
throw
new
RuntimeException
(
"FileLock#acquiredBy returned incorrect channel"
);
try
{
ch
.
tryLock
();
throw
new
RuntimeException
(
"OverlappingFileLockException expected"
);
}
catch
(
OverlappingFileLockException
x
)
{
}
fl
.
release
();
// test 2 - acquire try and check that lock throws OverlappingFileLockException
fl
=
ch
.
tryLock
();
if
(
fl
==
null
)
throw
new
RuntimeException
(
"Unable to acquire lock"
);
try
{
ch
.
lock
(
null
,
new
CompletionHandler
<
FileLock
,
Void
>
()
{
public
void
completed
(
FileLock
result
,
Void
att
)
{
}
public
void
failed
(
Throwable
exc
,
Void
att
)
{
}
public
void
cancelled
(
Void
att
)
{
}
});
throw
new
RuntimeException
(
"OverlappingFileLockException expected"
);
}
catch
(
OverlappingFileLockException
x
)
{
// test 2 - acquire try and check that lock throws OverlappingFileLockException
fl
=
ch
.
tryLock
();
if
(
fl
==
null
)
throw
new
RuntimeException
(
"Unable to acquire lock"
);
try
{
ch
.
lock
(
null
,
new
CompletionHandler
<
FileLock
,
Void
>
()
{
public
void
completed
(
FileLock
result
,
Void
att
)
{
}
public
void
failed
(
Throwable
exc
,
Void
att
)
{
}
public
void
cancelled
(
Void
att
)
{
}
});
throw
new
RuntimeException
(
"OverlappingFileLockException expected"
);
}
catch
(
OverlappingFileLockException
x
)
{
}
}
finally
{
ch
.
close
();
}
fl
.
release
();
// test 3 - channel is closed so FileLock should no longer be valid
if
(
fl
.
isValid
())
throw
new
RuntimeException
(
"FileLock expected to be invalid"
);
}
// interrupt should not close channel
...
...
test/java/nio/channels/AsynchronousFileChannel/Lock.java
浏览文件 @
6277f7b6
...
...
@@ -23,7 +23,7 @@
/* @test
* @bug 4607272
* @bug 4607272
6814948
* @summary Unit test for AsynchronousFileChannel#lock method
*/
...
...
test/java/nio/channels/FileChannel/ReleaseOnCloseDeadlock.java
0 → 100644
浏览文件 @
6277f7b6
/*
* Copyright 2009 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/* @test
* @bug 6543863
* @summary Try to cause a deadlock between (Asynchronous)FileChannel.close
* and FileLock.release
*/
import
java.io.*
;
import
java.nio.file.Path
;
import
static
java
.
nio
.
file
.
StandardOpenOption
.*;
import
java.nio.channels.*
;
import
java.util.concurrent.*
;
public
class
ReleaseOnCloseDeadlock
{
private
static
final
int
LOCK_COUNT
=
1024
;
public
static
void
main
(
String
[]
args
)
throws
IOException
{
File
blah
=
File
.
createTempFile
(
"blah"
,
null
);
blah
.
deleteOnExit
();
for
(
int
i
=
0
;
i
<
100
;
i
++)
{
test
(
blah
.
toPath
());
}
}
static
void
test
(
Path
file
)
throws
IOException
{
FileLock
[]
locks
=
new
FileLock
[
LOCK_COUNT
];
FileChannel
fc
=
FileChannel
.
open
(
file
,
READ
,
WRITE
);
for
(
int
i
=
0
;
i
<
LOCK_COUNT
;
i
++)
{
locks
[
i
]
=
fc
.
lock
(
i
,
1
,
true
);
}
tryToDeadlock
(
fc
,
locks
);
AsynchronousFileChannel
ch
=
AsynchronousFileChannel
.
open
(
file
,
READ
,
WRITE
);
for
(
int
i
=
0
;
i
<
LOCK_COUNT
;
i
++)
{
try
{
locks
[
i
]
=
ch
.
lock
(
i
,
1
,
true
,
null
,
null
).
get
();
}
catch
(
InterruptedException
x
)
{
throw
new
RuntimeException
(
x
);
}
catch
(
ExecutionException
x
)
{
throw
new
RuntimeException
(
x
);
}
}
tryToDeadlock
(
ch
,
locks
);
}
static
void
tryToDeadlock
(
final
Channel
channel
,
FileLock
[]
locks
)
throws
IOException
{
// start thread to close the file (and invalidate the locks)
Thread
closer
=
new
Thread
(
new
Runnable
()
{
public
void
run
()
{
try
{
channel
.
close
();
}
catch
(
IOException
ignore
)
{
ignore
.
printStackTrace
();
}
}});
closer
.
start
();
// release the locks explicitly
for
(
int
i
=
0
;
i
<
locks
.
length
;
i
++)
{
try
{
locks
[
i
].
release
();
}
catch
(
ClosedChannelException
ignore
)
{
}
}
// we are done when closer has terminated
while
(
closer
.
isAlive
())
{
try
{
closer
.
join
();
}
catch
(
InterruptedException
ignore
)
{
}
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录