Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
7e634d24
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看板
提交
7e634d24
编写于
12月 10, 2015
作者:
L
lbourges
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8144445: Maximum size checking in Marlin ArrayCache utility methods is not optimal
Reviewed-by: prr, flar
上级
f8f1d2ef
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
161 addition
and
13 deletion
+161
-13
src/share/classes/sun/java2d/marlin/ArrayCache.java
src/share/classes/sun/java2d/marlin/ArrayCache.java
+27
-11
src/share/classes/sun/java2d/marlin/Stroker.java
src/share/classes/sun/java2d/marlin/Stroker.java
+3
-2
test/sun/java2d/marlin/ArrayCacheSizeTest.java
test/sun/java2d/marlin/ArrayCacheSizeTest.java
+131
-0
未找到文件。
src/share/classes/sun/java2d/marlin/ArrayCache.java
浏览文件 @
7e634d24
...
...
@@ -166,18 +166,31 @@ public final class ArrayCache implements MarlinConst {
* @return new array size
*/
public
static
int
getNewSize
(
final
int
curSize
,
final
int
needSize
)
{
// check if needSize is negative or integer overflow:
if
(
needSize
<
0
)
{
// hard overflow failure - we can't even accommodate
// new items without overflowing
throw
new
ArrayIndexOutOfBoundsException
(
"array exceeds maximum capacity !"
);
}
assert
curSize
>=
0
;
final
int
initial
=
(
curSize
&
MASK_CLR_1
);
int
size
;
if
(
initial
>
THRESHOLD_ARRAY_SIZE
)
{
size
=
initial
+
(
initial
>>
1
);
// x(3/2)
}
else
{
size
=
(
initial
)
<<
1
;
// x2
size
=
(
initial
<<
1
)
;
// x2
}
// ensure the new size is >= needed size:
if
(
size
<
needSize
)
{
// align to 4096:
// align to 4096
(may overflow)
:
size
=
((
needSize
>>
12
)
+
1
)
<<
12
;
}
// check integer overflow:
if
(
size
<
0
)
{
// resize to maximum capacity:
size
=
Integer
.
MAX_VALUE
;
}
return
size
;
}
...
...
@@ -188,26 +201,29 @@ public final class ArrayCache implements MarlinConst {
* @return new array size
*/
public
static
long
getNewLargeSize
(
final
long
curSize
,
final
long
needSize
)
{
// check if needSize is negative or integer overflow:
if
((
needSize
>>
31L
)
!=
0L
)
{
// hard overflow failure - we can't even accommodate
// new items without overflowing
throw
new
ArrayIndexOutOfBoundsException
(
"array exceeds maximum capacity !"
);
}
assert
curSize
>=
0L
;
long
size
;
if
(
curSize
>
THRESHOLD_HUGE_ARRAY_SIZE
)
{
size
=
curSize
+
(
curSize
>>
2L
);
// x(5/4)
}
else
if
(
curSize
>
THRESHOLD_LARGE_ARRAY_SIZE
)
{
size
=
curSize
+
(
curSize
>>
1L
);
// x(3/2)
}
else
{
size
=
curSize
<<
1L
;
// x2
size
=
(
curSize
<<
1L
)
;
// x2
}
// ensure the new size is >= needed size:
if
(
size
<
needSize
)
{
// align to 4096:
size
=
((
needSize
>>
12
)
+
1
)
<<
12
;
}
if
(
size
>=
Integer
.
MAX_VALUE
)
{
if
(
curSize
>=
Integer
.
MAX_VALUE
)
{
// hard overflow failure - we can't even accommodate
// new items without overflowing
throw
new
ArrayIndexOutOfBoundsException
(
"array exceeds maximum capacity !"
);
size
=
((
needSize
>>
12L
)
+
1L
)
<<
12L
;
}
// check integer overflow:
if
(
size
>
Integer
.
MAX_VALUE
)
{
// resize to maximum capacity:
size
=
Integer
.
MAX_VALUE
;
}
...
...
src/share/classes/sun/java2d/marlin/Stroker.java
浏览文件 @
7e634d24
...
...
@@ -1265,14 +1265,15 @@ final class Stroker implements PathConsumer2D, MarlinConst {
}
private
void
ensureSpace
(
final
int
n
)
{
if
(
end
+
n
>
curves
.
length
)
{
// use substraction to avoid integer overflow:
if
(
curves
.
length
-
end
<
n
)
{
if
(
doStats
)
{
RendererContext
.
stats
.
stat_array_stroker_polystack_curves
.
add
(
end
+
n
);
}
curves
=
rdrCtx
.
widenDirtyFloatArray
(
curves
,
end
,
end
+
n
);
}
if
(
numCurves
+
1
>
curveTypes
.
length
)
{
if
(
curveTypes
.
length
<=
numCurves
)
{
if
(
doStats
)
{
RendererContext
.
stats
.
stat_array_stroker_polystack_curveTypes
.
add
(
numCurves
+
1
);
...
...
test/sun/java2d/marlin/ArrayCacheSizeTest.java
0 → 100644
浏览文件 @
7e634d24
/*
* Copyright (c) 2015, 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
* 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import
sun.java2d.marlin.ArrayCache
;
/**
* @test
* @bug 8144445
* @summary Check the ArrayCache getNewLargeSize() method
* @run main ArrayCacheSizeTest
*/
public
class
ArrayCacheSizeTest
{
public
static
void
main
(
String
[]
args
)
{
testNewSize
();
testNewLargeSize
();
}
private
static
void
testNewSize
()
{
testNewSize
(
0
,
1
);
testNewSize
(
0
,
100000
);
testNewSize
(
4096
,
4097
);
testNewSize
(
4096
*
16
,
4096
*
16
+
1
);
testNewSize
(
4096
*
4096
*
4
,
4096
*
4096
*
4
+
1
);
testNewSize
(
4096
*
4096
*
4
,
Integer
.
MAX_VALUE
);
testNewSize
(
Integer
.
MAX_VALUE
-
1000
,
Integer
.
MAX_VALUE
);
testNewSizeExpectAIOB
(
Integer
.
MAX_VALUE
-
1000
,
Integer
.
MAX_VALUE
+
1
);
testNewSizeExpectAIOB
(
1
,
-
1
);
testNewSizeExpectAIOB
(
Integer
.
MAX_VALUE
,
-
1
);
}
private
static
void
testNewSizeExpectAIOB
(
final
int
curSize
,
final
int
needSize
)
{
try
{
testNewSize
(
curSize
,
needSize
);
throw
new
RuntimeException
(
"ArrayIndexOutOfBoundsException not thrown"
);
}
catch
(
ArrayIndexOutOfBoundsException
aiobe
)
{
System
.
out
.
println
(
"ArrayIndexOutOfBoundsException expected."
);
}
catch
(
RuntimeException
re
)
{
throw
re
;
}
catch
(
Throwable
th
)
{
throw
new
RuntimeException
(
"Unexpected exception"
,
th
);
}
}
private
static
void
testNewSize
(
final
int
curSize
,
final
int
needSize
)
{
int
size
=
ArrayCache
.
getNewSize
(
curSize
,
needSize
);
System
.
out
.
println
(
"getNewSize("
+
curSize
+
", "
+
needSize
+
") = "
+
size
);
if
(
size
<
0
||
size
<
needSize
)
{
throw
new
IllegalStateException
(
"Invalid getNewSize("
+
curSize
+
", "
+
needSize
+
") = "
+
size
+
" !"
);
}
}
private
static
void
testNewLargeSize
()
{
testNewLargeSize
(
0
,
1
);
testNewLargeSize
(
0
,
100000
);
testNewLargeSize
(
4096
,
4097
);
testNewLargeSize
(
4096
*
16
,
4096
*
16
+
1
);
testNewLargeSize
(
4096
*
4096
*
4
,
4096
*
4096
*
4
+
1
);
testNewLargeSize
(
4096
*
4096
*
4
,
Integer
.
MAX_VALUE
);
testNewLargeSize
(
Integer
.
MAX_VALUE
-
1000
,
Integer
.
MAX_VALUE
);
testNewLargeSizeExpectAIOB
(
Integer
.
MAX_VALUE
-
1000
,
Integer
.
MAX_VALUE
+
1L
);
testNewLargeSizeExpectAIOB
(
1
,
-
1L
);
testNewLargeSizeExpectAIOB
(
Integer
.
MAX_VALUE
,
-
1L
);
}
private
static
void
testNewLargeSizeExpectAIOB
(
final
long
curSize
,
final
long
needSize
)
{
try
{
testNewLargeSize
(
curSize
,
needSize
);
throw
new
RuntimeException
(
"ArrayIndexOutOfBoundsException not thrown"
);
}
catch
(
ArrayIndexOutOfBoundsException
aiobe
)
{
System
.
out
.
println
(
"ArrayIndexOutOfBoundsException expected."
);
}
catch
(
RuntimeException
re
)
{
throw
re
;
}
catch
(
Throwable
th
)
{
throw
new
RuntimeException
(
"Unexpected exception"
,
th
);
}
}
private
static
void
testNewLargeSize
(
final
long
curSize
,
final
long
needSize
)
{
long
size
=
ArrayCache
.
getNewLargeSize
(
curSize
,
needSize
);
System
.
out
.
println
(
"getNewLargeSize("
+
curSize
+
", "
+
needSize
+
") = "
+
size
);
if
(
size
<
0
||
size
<
needSize
||
size
>
Integer
.
MAX_VALUE
)
{
throw
new
IllegalStateException
(
"Invalid getNewLargeSize("
+
curSize
+
", "
+
needSize
+
") = "
+
size
+
" !"
);
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录