Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
b9193e45
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看板
提交
b9193e45
编写于
1月 08, 2009
作者:
B
bpatel
浏览文件
操作
浏览文件
下载
差异文件
Merge
上级
aa5ca51f
2681ca16
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
144 addition
and
96 deletion
+144
-96
src/share/native/java/io/io_util.c
src/share/native/java/io/io_util.c
+16
-8
test/java/io/readBytes/ReadBytesBounds.java
test/java/io/readBytes/ReadBytesBounds.java
+57
-88
test/sun/jvmstat/monitor/MonitoredVm/CR6672135.java
test/sun/jvmstat/monitor/MonitoredVm/CR6672135.java
+71
-0
未找到文件。
src/share/native/java/io/io_util.c
浏览文件 @
b9193e45
...
...
@@ -58,12 +58,24 @@ readSingle(JNIEnv *env, jobject this, jfieldID fid) {
*/
#define BUF_SIZE 8192
/*
* Returns true if the array slice defined by the given offset and length
* is out of bounds.
*/
static
int
outOfBounds
(
JNIEnv
*
env
,
jint
off
,
jint
len
,
jbyteArray
array
)
{
return
((
off
<
0
)
||
(
len
<
0
)
||
// We are very careful to avoid signed integer overflow,
// the result of which is undefined in C.
((
*
env
)
->
GetArrayLength
(
env
,
array
)
-
off
<
len
));
}
int
readBytes
(
JNIEnv
*
env
,
jobject
this
,
jbyteArray
bytes
,
jint
off
,
jint
len
,
jfieldID
fid
)
{
int
nread
,
datalen
;
int
nread
;
char
stackBuf
[
BUF_SIZE
];
char
*
buf
=
0
;
FD
fd
;
...
...
@@ -72,10 +84,8 @@ readBytes(JNIEnv *env, jobject this, jbyteArray bytes,
JNU_ThrowNullPointerException
(
env
,
0
);
return
-
1
;
}
datalen
=
(
*
env
)
->
GetArrayLength
(
env
,
bytes
);
if
((
off
<
0
)
||
(
off
>
datalen
)
||
(
len
<
0
)
||
((
off
+
len
)
>
datalen
)
||
((
off
+
len
)
<
0
))
{
if
(
outOfBounds
(
env
,
off
,
len
,
bytes
))
{
JNU_ThrowByName
(
env
,
"java/lang/IndexOutOfBoundsException"
,
0
);
return
-
1
;
}
...
...
@@ -136,7 +146,7 @@ void
writeBytes
(
JNIEnv
*
env
,
jobject
this
,
jbyteArray
bytes
,
jint
off
,
jint
len
,
jfieldID
fid
)
{
int
n
,
datalen
;
int
n
;
char
stackBuf
[
BUF_SIZE
];
char
*
buf
=
0
;
FD
fd
;
...
...
@@ -145,10 +155,8 @@ writeBytes(JNIEnv *env, jobject this, jbyteArray bytes,
JNU_ThrowNullPointerException
(
env
,
0
);
return
;
}
datalen
=
(
*
env
)
->
GetArrayLength
(
env
,
bytes
);
if
((
off
<
0
)
||
(
off
>
datalen
)
||
(
len
<
0
)
||
((
off
+
len
)
>
datalen
)
||
((
off
+
len
)
<
0
))
{
if
(
outOfBounds
(
env
,
off
,
len
,
bytes
))
{
JNU_ThrowByName
(
env
,
"java/lang/IndexOutOfBoundsException"
,
0
);
return
;
}
...
...
test/java/io/readBytes/ReadBytesBounds.java
浏览文件 @
b9193e45
...
...
@@ -22,107 +22,76 @@
*/
/*
@test
@bug 4017728 4079849
@summary Check for correct Array Bounds check in read of FileInputStream and
RandomAccessFile
*/
*
@test
* @bug 4017728 4079849 6788196
*
@summary Check for correct Array Bounds check in read of FileInputStream and
*
RandomAccessFile
*/
import
java.io.*
;
/*
* The test calls the read(byte buf[] , int off , int len) of FileInputStream with
* different values of off and len to see if the ArrayOutOfBoundsException is
* thrown according to the JLS1.0 specification. The read(...) method calls
* readBytes(...) in native code(io_util.c). The read(...) method in RandomAccessFile
* also calls the same native method. So one should see similar results.
* The test calls the read(byte buf[] , int off , int len) of
* FileInputStream with different values of off and len to see if the
* IndexOutOfBoundsException is thrown. The read(...) method calls
* readBytes(...) in native code(io_util.c). The read(...) method in
* RandomAccessFile also calls the same native method. So one should
* see similar results.
*/
public
class
ReadBytesBounds
{
public
static
void
main
(
String
argv
[])
throws
Exception
{
int
num_test_cases
=
12
;
int
off
[]
=
{-
1
,
-
1
,
0
,
0
,
33
,
33
,
0
,
32
,
32
,
4
,
1
,
0
};
int
len
[]
=
{-
1
,
0
,
-
1
,
33
,
0
,
4
,
32
,
0
,
4
,
16
,
31
,
0
};
boolean
results
[]
=
{
false
,
false
,
false
,
false
,
false
,
false
,
true
,
true
,
false
,
true
,
true
,
true
};
static
final
FileInputStream
fis
;
static
final
RandomAccessFile
raf
;
static
final
byte
[]
b
=
new
byte
[
32
];
static
{
try
{
String
dir
=
System
.
getProperty
(
"test.src"
,
"."
);
File
testFile
=
new
File
(
dir
,
"input.txt"
);
fis
=
new
FileInputStream
(
testFile
);
raf
=
new
RandomAccessFile
(
testFile
,
"r"
);
}
catch
(
Throwable
t
)
{
throw
new
Error
(
t
);
}
}
FileInputStream
fis
=
null
;
RandomAccessFile
raf
=
null
;
public
static
void
main
(
String
argv
[])
throws
Throwable
{
byte
b
[]
=
new
byte
[
32
];
testRead
(-
1
,
-
1
,
false
);
testRead
(-
1
,
0
,
false
);
testRead
(
0
,
-
1
,
false
);
testRead
(
0
,
33
,
false
);
testRead
(
33
,
0
,
false
);
testRead
(
33
,
4
,
false
);
testRead
(
0
,
32
,
true
);
testRead
(
32
,
0
,
true
);
testRead
(
32
,
4
,
false
);
testRead
(
4
,
16
,
true
);
testRead
(
1
,
31
,
true
);
testRead
(
0
,
0
,
true
);
testRead
(
31
,
Integer
.
MAX_VALUE
,
false
);
testRead
(
0
,
Integer
.
MAX_VALUE
,
false
);
testRead
(-
1
,
Integer
.
MAX_VALUE
,
false
);
testRead
(-
4
,
Integer
.
MIN_VALUE
,
false
);
testRead
(
0
,
Integer
.
MIN_VALUE
,
false
);
}
int
num_good
=
0
;
int
num_bad
=
0
;
String
dir
=
System
.
getProperty
(
"test.src"
,
"."
);
File
testFile
=
new
File
(
dir
,
"input.txt"
);
fis
=
new
FileInputStream
(
testFile
);
for
(
int
i
=
0
;
i
<
num_test_cases
;
i
++)
{
try
{
int
bytes_read
=
fis
.
read
(
b
,
off
[
i
]
,
len
[
i
]);
}
catch
(
IndexOutOfBoundsException
aiobe
)
{
if
(
results
[
i
])
{
throw
new
RuntimeException
(
"Unexpected result"
);
}
else
{
num_good
++;
}
continue
;
}
if
(
results
[
i
])
{
num_good
++;
}
else
{
throw
new
RuntimeException
(
"Unexpected result"
);
}
static
void
testRead
(
int
off
,
int
len
,
boolean
expected
)
throws
Throwable
{
System
.
err
.
printf
(
"off=%d len=%d expected=%b%n"
,
off
,
len
,
expected
);
boolean
result
;
try
{
fis
.
read
(
b
,
off
,
len
);
raf
.
read
(
b
,
off
,
len
);
result
=
true
;
}
catch
(
IndexOutOfBoundsException
e
)
{
result
=
false
;
}
System
.
out
.
println
(
"Results for FileInputStream.read"
);
System
.
out
.
println
(
"\nTotal number of test cases = "
+
num_test_cases
+
"\nNumber succeded = "
+
num_good
+
"\nNumber failed = "
+
num_bad
);
num_good
=
0
;
num_bad
=
0
;
raf
=
new
RandomAccessFile
(
testFile
,
"r"
);
for
(
int
i
=
0
;
i
<
num_test_cases
;
i
++)
{
try
{
int
bytes_read
=
raf
.
read
(
b
,
off
[
i
]
,
len
[
i
]);
}
catch
(
IndexOutOfBoundsException
aiobe
)
{
if
(
results
[
i
])
{
throw
new
RuntimeException
(
"Unexpected result"
);
}
else
{
num_good
++;
}
continue
;
}
if
(
results
[
i
])
{
num_good
++;
}
else
{
throw
new
RuntimeException
(
"Unexpected result"
);
}
if
(
result
!=
expected
)
{
throw
new
RuntimeException
(
String
.
format
(
"Unexpected result off=%d len=%d expected=%b"
,
off
,
len
,
expected
));
}
System
.
out
.
println
(
"Results for RandomAccessFile.read"
);
System
.
out
.
println
(
"\nTotal number of test cases = "
+
num_test_cases
+
"\nNumber succeded = "
+
num_good
+
"\nNumber failed = "
+
num_bad
);
}
}
test/sun/jvmstat/monitor/MonitoredVm/CR6672135.java
0 → 100644
浏览文件 @
b9193e45
/*
* Copyright 2004 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.
*/
import
java.net.URISyntaxException
;
import
java.util.Set
;
import
sun.jvmstat.monitor.MonitorException
;
import
sun.jvmstat.monitor.MonitoredHost
;
import
sun.jvmstat.monitor.MonitoredVm
;
import
sun.jvmstat.monitor.VmIdentifier
;
/**
*
* @test
* @bug 6672135
* @summary setInterval() for local MonitoredHost and local MonitoredVm
* @author Tomas Hurka
*/
public
class
CR6672135
{
private
static
final
int
INTERVAL
=
2000
;
public
static
void
main
(
String
[]
args
)
{
int
vmInterval
;
int
hostInterval
;
try
{
MonitoredHost
localHost
=
MonitoredHost
.
getMonitoredHost
(
"localhost"
);
Set
vms
=
localHost
.
activeVms
();
Integer
vmInt
=
(
Integer
)
vms
.
iterator
().
next
();
String
uriString
=
"//"
+
vmInt
+
"?mode=r"
;
// NOI18N
VmIdentifier
vmId
=
new
VmIdentifier
(
uriString
);
MonitoredVm
vm
=
localHost
.
getMonitoredVm
(
vmId
);
vm
.
setInterval
(
INTERVAL
);
localHost
.
setInterval
(
INTERVAL
);
vmInterval
=
vm
.
getInterval
();
hostInterval
=
localHost
.
getInterval
();
}
catch
(
Exception
ex
)
{
throw
new
Error
(
"Test failed"
,
ex
);
}
System
.
out
.
println
(
"VM "
+
vmInterval
);
if
(
vmInterval
!=
INTERVAL
)
{
throw
new
Error
(
"Test failed"
);
}
System
.
out
.
println
(
"Host "
+
hostInterval
);
if
(
hostInterval
!=
INTERVAL
)
{
throw
new
Error
(
"Test failed"
);
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录