Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
1abc0e17
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看板
提交
1abc0e17
编写于
3月 14, 2011
作者:
R
rupashka
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
6464022: Memory leak in JOptionPane.createDialog
Reviewed-by: alexp
上级
d51a626e
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
154 addition
and
47 deletion
+154
-47
src/share/classes/javax/swing/JOptionPane.java
src/share/classes/javax/swing/JOptionPane.java
+24
-14
test/javax/swing/JOptionPane/6464022/bug6464022.java
test/javax/swing/JOptionPane/6464022/bug6464022.java
+83
-0
test/javax/swing/UIDefaults/6795356/bug6795356.java
test/javax/swing/UIDefaults/6795356/bug6795356.java
+3
-33
test/javax/swing/regtesthelpers/Util.java
test/javax/swing/regtesthelpers/Util.java
+44
-0
未找到文件。
src/share/classes/javax/swing/JOptionPane.java
浏览文件 @
1abc0e17
...
...
@@ -987,11 +987,33 @@ public class JOptionPane extends JComponent implements Accessible
}
dialog
.
pack
();
dialog
.
setLocationRelativeTo
(
parentComponent
);
final
PropertyChangeListener
listener
=
new
PropertyChangeListener
()
{
public
void
propertyChange
(
PropertyChangeEvent
event
)
{
// Let the defaultCloseOperation handle the closing
// if the user closed the window without selecting a button
// (newValue = null in that case). Otherwise, close the dialog.
if
(
dialog
.
isVisible
()
&&
event
.
getSource
()
==
JOptionPane
.
this
&&
(
event
.
getPropertyName
().
equals
(
VALUE_PROPERTY
)
||
event
.
getPropertyName
().
equals
(
INPUT_VALUE_PROPERTY
))
&&
event
.
getNewValue
()
!=
null
&&
event
.
getNewValue
()
!=
JOptionPane
.
UNINITIALIZED_VALUE
)
{
dialog
.
setVisible
(
false
);
}
}
};
WindowAdapter
adapter
=
new
WindowAdapter
()
{
private
boolean
gotFocus
=
false
;
public
void
windowClosing
(
WindowEvent
we
)
{
setValue
(
null
);
}
public
void
windowClosed
(
WindowEvent
e
)
{
removePropertyChangeListener
(
listener
);
dialog
.
getContentPane
().
removeAll
();
}
public
void
windowGainedFocus
(
WindowEvent
we
)
{
// Once window gets focus, set initial focus
if
(!
gotFocus
)
{
...
...
@@ -1008,20 +1030,8 @@ public class JOptionPane extends JComponent implements Accessible
setValue
(
JOptionPane
.
UNINITIALIZED_VALUE
);
}
});
addPropertyChangeListener
(
new
PropertyChangeListener
()
{
public
void
propertyChange
(
PropertyChangeEvent
event
)
{
// Let the defaultCloseOperation handle the closing
// if the user closed the window without selecting a button
// (newValue = null in that case). Otherwise, close the dialog.
if
(
dialog
.
isVisible
()
&&
event
.
getSource
()
==
JOptionPane
.
this
&&
(
event
.
getPropertyName
().
equals
(
VALUE_PROPERTY
)
||
event
.
getPropertyName
().
equals
(
INPUT_VALUE_PROPERTY
))
&&
event
.
getNewValue
()
!=
null
&&
event
.
getNewValue
()
!=
JOptionPane
.
UNINITIALIZED_VALUE
)
{
dialog
.
setVisible
(
false
);
}
}
});
addPropertyChangeListener
(
listener
);
}
...
...
test/javax/swing/JOptionPane/6464022/bug6464022.java
0 → 100644
浏览文件 @
1abc0e17
/*
* Copyright (c) 2011, 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
* @bug 6464022
* @summary Memory leak in JOptionPane.createDialog
* @author Pavel Porvatov
* @library ../../regtesthelpers
* @build Util
* @run main bug6464022
*/
import
javax.swing.*
;
import
java.lang.ref.WeakReference
;
import
java.util.ArrayList
;
import
java.util.List
;
public
class
bug6464022
{
private
static
JOptionPane
pane
;
public
static
void
main
(
String
[]
args
)
throws
Exception
{
final
List
<
WeakReference
<
JDialog
>>
references
=
new
ArrayList
<
WeakReference
<
JDialog
>>();
SwingUtilities
.
invokeAndWait
(
new
Runnable
()
{
public
void
run
()
{
pane
=
new
JOptionPane
(
null
,
JOptionPane
.
UNDEFINED_CONDITION
);
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
JDialog
dialog
=
pane
.
createDialog
(
null
,
"Test "
+
i
);
references
.
add
(
new
WeakReference
<
JDialog
>(
dialog
));
dialog
.
dispose
();
System
.
out
.
println
(
"Disposing Dialog:"
+
dialog
.
hashCode
());
}
}
});
Util
.
generateOOME
();
SwingUtilities
.
invokeAndWait
(
new
Runnable
()
{
public
void
run
()
{
int
allocatedCount
=
0
;
for
(
WeakReference
<
JDialog
>
ref
:
references
)
{
if
(
ref
.
get
()
!=
null
)
{
allocatedCount
++;
System
.
out
.
println
(
ref
.
get
().
hashCode
()
+
" is still allocated"
);
}
}
if
(
allocatedCount
>
0
)
{
throw
new
RuntimeException
(
"Some dialogs still exist in memory. Test failed"
);
}
else
{
System
.
out
.
println
(
"All dialogs were GCed. Test passed."
);
}
}
});
}
}
test/javax/swing/UIDefaults/6795356/bug6795356.java
浏览文件 @
1abc0e17
...
...
@@ -26,6 +26,8 @@
* @bug 6795356
* @summary Leak caused by javax.swing.UIDefaults.ProxyLazyValue.acc
* @author Alexander Potochkin
* @library ../../regtesthelpers
* @build Util
* @run main bug6795356
*/
...
...
@@ -58,43 +60,11 @@ public class bug6795356 {
weakRef
=
new
WeakReference
<
ProtectionDomain
>(
domain
);
domain
=
null
;
// Generate OutOfMemory and check the weak ref
generateOOME
();
Util
.
generateOOME
();
if
(
weakRef
.
get
()
!=
null
)
{
throw
new
RuntimeException
(
"Memory leak found!"
);
}
System
.
out
.
println
(
"Test passed"
);
}
static
void
generateOOME
()
{
List
<
Object
>
bigLeak
=
new
LinkedList
<
Object
>();
boolean
oome
=
false
;
System
.
out
.
print
(
"Filling the heap"
);
try
{
for
(
int
i
=
0
;
true
;
i
++)
{
// Now, use up all RAM
bigLeak
.
add
(
new
byte
[
1024
*
1024
]);
System
.
out
.
print
(
"."
);
// Give the GC a change at that weakref
if
(
i
%
10
==
0
)
{
System
.
gc
();
try
{
Thread
.
sleep
(
100
);
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
();
}
}
}
}
catch
(
OutOfMemoryError
e
)
{
bigLeak
=
null
;
oome
=
true
;
}
System
.
out
.
println
(
""
);
if
(!
oome
)
{
throw
new
RuntimeException
(
"Problem with test case - never got OOME"
);
}
System
.
out
.
println
(
"Got OOME"
);
}
}
test/javax/swing/regtesthelpers/Util.java
浏览文件 @
1abc0e17
...
...
@@ -24,6 +24,8 @@
import
javax.swing.*
;
import
java.awt.*
;
import
java.awt.image.BufferedImage
;
import
java.util.LinkedList
;
import
java.util.List
;
/**
* <p>This class contains utilities useful for regression testing.
...
...
@@ -72,4 +74,46 @@ public class Util {
return
true
;
}
/**
* Fills the heap until OutOfMemoryError occurs. This method is useful for
* WeakReferences removing.
*/
public
static
void
generateOOME
()
{
List
<
Object
>
bigLeak
=
new
LinkedList
<
Object
>();
boolean
oome
=
false
;
System
.
out
.
print
(
"Filling the heap"
);
try
{
for
(
int
i
=
0
;
true
;
i
++)
{
// Now, use up all RAM
bigLeak
.
add
(
new
byte
[
1024
*
1024
]);
System
.
out
.
print
(
"."
);
// Give the GC a change at that weakref
if
(
i
%
10
==
0
)
{
System
.
gc
();
try
{
Thread
.
sleep
(
100
);
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
();
}
}
}
}
catch
(
OutOfMemoryError
e
)
{
bigLeak
=
null
;
oome
=
true
;
}
System
.
out
.
println
(
""
);
if
(!
oome
)
{
throw
new
RuntimeException
(
"Problem with test case - never got OOME"
);
}
System
.
out
.
println
(
"Got OOME"
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录