Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_hotspot
提交
9c6cffe3
D
dragonwell8_hotspot
项目概览
openanolis
/
dragonwell8_hotspot
通知
2
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dragonwell8_hotspot
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
9c6cffe3
编写于
10月 01, 2014
作者:
E
ehelin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8049599: MetaspaceGC::_capacity_until_GC can overflow
Reviewed-by: jmasa, stefank
上级
03da718b
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
141 addition
and
15 deletion
+141
-15
src/share/vm/memory/metaspace.cpp
src/share/vm/memory/metaspace.cpp
+48
-14
src/share/vm/memory/metaspace.hpp
src/share/vm/memory/metaspace.hpp
+3
-1
src/share/vm/prims/whitebox.cpp
src/share/vm/prims/whitebox.cpp
+29
-0
test/gc/metaspace/TestCapacityUntilGCWrapAround.java
test/gc/metaspace/TestCapacityUntilGCWrapAround.java
+59
-0
test/testlibrary/whitebox/sun/hotspot/WhiteBox.java
test/testlibrary/whitebox/sun/hotspot/WhiteBox.java
+2
-0
未找到文件。
src/share/vm/memory/metaspace.cpp
浏览文件 @
9c6cffe3
...
...
@@ -1414,10 +1414,31 @@ size_t MetaspaceGC::capacity_until_GC() {
return
value
;
}
size_t
MetaspaceGC
::
inc_capacity_until_GC
(
size_t
v
)
{
bool
MetaspaceGC
::
inc_capacity_until_GC
(
size_t
v
,
size_t
*
new_cap_until_GC
,
size_t
*
old_cap_until_GC
)
{
assert_is_size_aligned
(
v
,
Metaspace
::
commit_alignment
());
return
(
size_t
)
Atomic
::
add_ptr
(
v
,
&
_capacity_until_GC
);
size_t
capacity_until_GC
=
(
size_t
)
_capacity_until_GC
;
size_t
new_value
=
capacity_until_GC
+
v
;
if
(
new_value
<
capacity_until_GC
)
{
// The addition wrapped around, set new_value to aligned max value.
new_value
=
align_size_down
(
max_uintx
,
Metaspace
::
commit_alignment
());
}
intptr_t
expected
=
(
intptr_t
)
capacity_until_GC
;
intptr_t
actual
=
Atomic
::
cmpxchg_ptr
((
intptr_t
)
new_value
,
&
_capacity_until_GC
,
expected
);
if
(
expected
!=
actual
)
{
return
false
;
}
if
(
new_cap_until_GC
!=
NULL
)
{
*
new_cap_until_GC
=
new_value
;
}
if
(
old_cap_until_GC
!=
NULL
)
{
*
old_cap_until_GC
=
capacity_until_GC
;
}
return
true
;
}
size_t
MetaspaceGC
::
dec_capacity_until_GC
(
size_t
v
)
{
...
...
@@ -1517,7 +1538,10 @@ void MetaspaceGC::compute_new_size() {
expand_bytes
=
align_size_up
(
expand_bytes
,
Metaspace
::
commit_alignment
());
// Don't expand unless it's significant
if
(
expand_bytes
>=
MinMetaspaceExpansion
)
{
size_t
new_capacity_until_GC
=
MetaspaceGC
::
inc_capacity_until_GC
(
expand_bytes
);
size_t
new_capacity_until_GC
=
0
;
bool
succeeded
=
MetaspaceGC
::
inc_capacity_until_GC
(
expand_bytes
,
&
new_capacity_until_GC
);
assert
(
succeeded
,
"Should always succesfully increment HWM when at safepoint"
);
Metaspace
::
tracer
()
->
report_gc_threshold
(
capacity_until_GC
,
new_capacity_until_GC
,
MetaspaceGCThresholdUpdater
::
ComputeNewSize
);
...
...
@@ -3319,19 +3343,29 @@ MetaWord* Metaspace::expand_and_allocate(size_t word_size, MetadataType mdtype)
size_t
delta_bytes
=
MetaspaceGC
::
delta_capacity_until_GC
(
word_size
*
BytesPerWord
);
assert
(
delta_bytes
>
0
,
"Must be"
);
size_t
after_inc
=
MetaspaceGC
::
inc_capacity_until_GC
(
delta_bytes
);
// capacity_until_GC might be updated concurrently, must calculate previous value.
size_t
before_inc
=
after_inc
-
delta_bytes
;
tracer
()
->
report_gc_threshold
(
before_inc
,
after_inc
,
MetaspaceGCThresholdUpdater
::
ExpandAndAllocate
);
if
(
PrintGCDetails
&&
Verbose
)
{
gclog_or_tty
->
print_cr
(
"Increase capacity to GC from "
SIZE_FORMAT
" to "
SIZE_FORMAT
,
before_inc
,
after_inc
);
size_t
before
=
0
;
size_t
after
=
0
;
MetaWord
*
res
;
bool
incremented
;
// Each thread increments the HWM at most once. Even if the thread fails to increment
// the HWM, an allocation is still attempted. This is because another thread must then
// have incremented the HWM and therefore the allocation might still succeed.
do
{
incremented
=
MetaspaceGC
::
inc_capacity_until_GC
(
delta_bytes
,
&
after
,
&
before
);
res
=
allocate
(
word_size
,
mdtype
);
}
while
(
!
incremented
&&
res
==
NULL
);
if
(
incremented
)
{
tracer
()
->
report_gc_threshold
(
before
,
after
,
MetaspaceGCThresholdUpdater
::
ExpandAndAllocate
);
if
(
PrintGCDetails
&&
Verbose
)
{
gclog_or_tty
->
print_cr
(
"Increase capacity to GC from "
SIZE_FORMAT
" to "
SIZE_FORMAT
,
before
,
after
);
}
}
return
allocate
(
word_size
,
mdtype
)
;
return
res
;
}
// Space allocated in the Metaspace. This may
...
...
src/share/vm/memory/metaspace.hpp
浏览文件 @
9c6cffe3
...
...
@@ -404,7 +404,9 @@ class MetaspaceGC : AllStatic {
static
void
post_initialize
();
static
size_t
capacity_until_GC
();
static
size_t
inc_capacity_until_GC
(
size_t
v
);
static
bool
inc_capacity_until_GC
(
size_t
v
,
size_t
*
new_cap_until_GC
=
NULL
,
size_t
*
old_cap_until_GC
=
NULL
);
static
size_t
dec_capacity_until_GC
(
size_t
v
);
static
bool
should_concurrent_collect
()
{
return
_should_concurrent_collect
;
}
...
...
src/share/vm/prims/whitebox.cpp
浏览文件 @
9c6cffe3
...
...
@@ -794,6 +794,33 @@ WB_ENTRY(void, WB_FreeMetaspace(JNIEnv* env, jobject wb, jobject class_loader, j
MetadataFactory
::
free_array
(
cld
,
(
Array
<
u1
>*
)(
uintptr_t
)
addr
);
WB_END
WB_ENTRY
(
jlong
,
WB_IncMetaspaceCapacityUntilGC
(
JNIEnv
*
env
,
jobject
wb
,
jlong
inc
))
if
(
inc
<
0
)
{
THROW_MSG_0
(
vmSymbols
::
java_lang_IllegalArgumentException
(),
err_msg
(
"WB_IncMetaspaceCapacityUntilGC: inc is negative: "
JLONG_FORMAT
,
inc
));
}
jlong
max_size_t
=
(
jlong
)
((
size_t
)
-
1
);
if
(
inc
>
max_size_t
)
{
THROW_MSG_0
(
vmSymbols
::
java_lang_IllegalArgumentException
(),
err_msg
(
"WB_IncMetaspaceCapacityUntilGC: inc does not fit in size_t: "
JLONG_FORMAT
,
inc
));
}
size_t
new_cap_until_GC
=
0
;
size_t
aligned_inc
=
align_size_down
((
size_t
)
inc
,
Metaspace
::
commit_alignment
());
bool
success
=
MetaspaceGC
::
inc_capacity_until_GC
(
aligned_inc
,
&
new_cap_until_GC
);
if
(
!
success
)
{
THROW_MSG_0
(
vmSymbols
::
java_lang_IllegalStateException
(),
"WB_IncMetaspaceCapacityUntilGC: could not increase capacity until GC "
"due to contention with another thread"
);
}
return
(
jlong
)
new_cap_until_GC
;
WB_END
WB_ENTRY
(
jlong
,
WB_MetaspaceCapacityUntilGC
(
JNIEnv
*
env
,
jobject
wb
))
return
(
jlong
)
MetaspaceGC
::
capacity_until_GC
();
WB_END
//Some convenience methods to deal with objects from java
int
WhiteBox
::
offset_for_field
(
const
char
*
field_name
,
oop
object
,
Symbol
*
signature_symbol
)
{
...
...
@@ -962,6 +989,8 @@ static JNINativeMethod methods[] = {
CC
"(Ljava/lang/ClassLoader;J)J"
,
(
void
*
)
&
WB_AllocateMetaspace
},
{
CC
"freeMetaspace"
,
CC
"(Ljava/lang/ClassLoader;JJ)V"
,
(
void
*
)
&
WB_FreeMetaspace
},
{
CC
"incMetaspaceCapacityUntilGC"
,
CC
"(J)J"
,
(
void
*
)
&
WB_IncMetaspaceCapacityUntilGC
},
{
CC
"metaspaceCapacityUntilGC"
,
CC
"()J"
,
(
void
*
)
&
WB_MetaspaceCapacityUntilGC
},
{
CC
"getCPUFeatures"
,
CC
"()Ljava/lang/String;"
,
(
void
*
)
&
WB_GetCPUFeatures
},
{
CC
"getNMethod"
,
CC
"(Ljava/lang/reflect/Executable;Z)[Ljava/lang/Object;"
,
(
void
*
)
&
WB_GetNMethod
},
...
...
test/gc/metaspace/TestCapacityUntilGCWrapAround.java
0 → 100644
浏览文件 @
9c6cffe3
/*
* Copyright (c) 2014, 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.
*/
/*
* @test
* @key gc
* @bug 8049831
* @library /testlibrary /testlibrary/whitebox
* @build TestCapacityUntilGCWrapAround
* @run main ClassFileInstaller sun.hotspot.WhiteBox
* sun.hotspot.WhiteBox$WhiteBoxPermission
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI TestCapacityUntilGCWrapAround
*/
import
sun.hotspot.WhiteBox
;
import
com.oracle.java.testlibrary.Asserts
;
import
com.oracle.java.testlibrary.Platform
;
public
class
TestCapacityUntilGCWrapAround
{
private
static
long
MB
=
1024
*
1024
;
private
static
long
GB
=
1024
*
MB
;
private
static
long
MAX_UINT
=
4
*
GB
-
1
;
// On 32-bit platforms
public
static
void
main
(
String
[]
args
)
{
if
(
Platform
.
is32bit
())
{
WhiteBox
wb
=
WhiteBox
.
getWhiteBox
();
long
before
=
wb
.
metaspaceCapacityUntilGC
();
// Now force possible overflow of capacity_until_GC.
long
after
=
wb
.
incMetaspaceCapacityUntilGC
(
MAX_UINT
);
Asserts
.
assertGTE
(
after
,
before
,
"Increasing with MAX_UINT should not cause wrap around: "
+
after
+
" < "
+
before
);
Asserts
.
assertLTE
(
after
,
MAX_UINT
,
"Increasing with MAX_UINT should not cause value larger than MAX_UINT:"
+
after
);
}
}
}
test/testlibrary/whitebox/sun/hotspot/WhiteBox.java
浏览文件 @
9c6cffe3
...
...
@@ -152,6 +152,8 @@ public class WhiteBox {
public
native
void
readReservedMemory
();
public
native
long
allocateMetaspace
(
ClassLoader
classLoader
,
long
size
);
public
native
void
freeMetaspace
(
ClassLoader
classLoader
,
long
addr
,
long
size
);
public
native
long
incMetaspaceCapacityUntilGC
(
long
increment
);
public
native
long
metaspaceCapacityUntilGC
();
// force Young GC
public
native
void
youngGC
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录