Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
0d0dba7f
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看板
提交
0d0dba7f
编写于
5月 17, 2013
作者:
P
pchelko
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
7079254: Toolkit eventListener leaks memory
Reviewed-by: serb, art
上级
f932a121
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
149 addition
and
4 deletion
+149
-4
src/share/classes/java/awt/Component.java
src/share/classes/java/awt/Component.java
+11
-0
src/share/classes/java/awt/Container.java
src/share/classes/java/awt/Container.java
+35
-4
test/java/awt/LightweightDispatcher/LWDispatcherMemoryLeakTest.java
...awt/LightweightDispatcher/LWDispatcherMemoryLeakTest.java
+103
-0
未找到文件。
src/share/classes/java/awt/Component.java
浏览文件 @
0d0dba7f
...
...
@@ -1671,6 +1671,15 @@ public abstract class Component implements ImageObserver, MenuContainer,
/* do nothing */
}
/*
* Delete references from LightweithDispatcher of a heavyweight parent
*/
void
clearLightweightDispatcherOnRemove
(
Component
removedComponent
)
{
if
(
parent
!=
null
)
{
parent
.
clearLightweightDispatcherOnRemove
(
removedComponent
);
}
}
/**
* @deprecated As of JDK version 1.1,
* replaced by <code>setVisible(boolean)</code>.
...
...
@@ -6974,6 +6983,8 @@ public abstract class Component implements ImageObserver, MenuContainer,
}
synchronized
(
getTreeLock
())
{
clearLightweightDispatcherOnRemove
(
this
);
if
(
isFocusOwner
()
&&
KeyboardFocusManager
.
isAutoFocusTransferEnabledFor
(
this
))
{
transferFocus
(
true
);
}
...
...
src/share/classes/java/awt/Container.java
浏览文件 @
0d0dba7f
...
...
@@ -3306,6 +3306,16 @@ public class Container extends Component {
}
}
@Override
void
clearLightweightDispatcherOnRemove
(
Component
removedComponent
)
{
if
(
dispatcher
!=
null
)
{
dispatcher
.
removeReferences
(
removedComponent
);
}
else
{
//It is a Lightweight Container, should clear parent`s Dispatcher
super
.
clearLightweightDispatcherOnRemove
(
removedComponent
);
}
}
final
Container
getTraversalRoot
()
{
if
(
isFocusCycleRoot
())
{
return
findTraversalRoot
();
...
...
@@ -4411,6 +4421,7 @@ class LightweightDispatcher implements java.io.Serializable, AWTEventListener {
//System.out.println("Disposing lw dispatcher");
stopListeningForOtherDrags
();
mouseEventTarget
=
null
;
targetLastEntered
=
null
;
}
/**
...
...
@@ -4502,6 +4513,7 @@ class LightweightDispatcher implements java.io.Serializable, AWTEventListener {
// MOUSE_CLICKED.
if
(!
isMouseGrab
(
e
)
&&
id
!=
MouseEvent
.
MOUSE_CLICKED
)
{
mouseEventTarget
=
(
mouseOver
!=
nativeContainer
)
?
mouseOver:
null
;
isCleaned
=
false
;
}
if
(
mouseEventTarget
!=
null
)
{
...
...
@@ -4545,10 +4557,14 @@ class LightweightDispatcher implements java.io.Serializable, AWTEventListener {
retargetMouseEvent
(
mouseOver
,
id
,
e
);
break
;
}
//Consuming of wheel events is implemented in "retargetMouseEvent".
if
(
id
!=
MouseEvent
.
MOUSE_WHEEL
)
{
e
.
consume
();
}
//Consuming of wheel events is implemented in "retargetMouseEvent".
if
(
id
!=
MouseEvent
.
MOUSE_WHEEL
)
{
e
.
consume
();
}
}
else
if
(
isCleaned
&&
id
!=
MouseEvent
.
MOUSE_WHEEL
)
{
//After mouseEventTarget was removed and cleaned should consume all events
//until new mouseEventTarget is found
e
.
consume
();
}
return
e
.
isConsumed
();
}
...
...
@@ -4891,6 +4907,11 @@ class LightweightDispatcher implements java.io.Serializable, AWTEventListener {
*/
private
transient
Component
targetLastEntered
;
/**
* Indicates whether {@code mouseEventTarget} was removed and nulled
*/
private
transient
boolean
isCleaned
;
/**
* Is the mouse over the native container
*/
...
...
@@ -4925,4 +4946,14 @@ class LightweightDispatcher implements java.io.Serializable, AWTEventListener {
AWTEvent
.
MOUSE_EVENT_MASK
|
AWTEvent
.
MOUSE_MOTION_EVENT_MASK
|
AWTEvent
.
MOUSE_WHEEL_EVENT_MASK
;
void
removeReferences
(
Component
removedComponent
)
{
if
(
mouseEventTarget
==
removedComponent
)
{
isCleaned
=
true
;
mouseEventTarget
=
null
;
}
if
(
targetLastEntered
==
removedComponent
)
{
targetLastEntered
=
null
;
}
}
}
test/java/awt/LightweightDispatcher/LWDispatcherMemoryLeakTest.java
0 → 100644
浏览文件 @
0d0dba7f
/*
* Copyright (c) 2013, 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
java.awt.AWTException
;
import
java.awt.FlowLayout
;
import
java.awt.Robot
;
import
java.lang.ref.Reference
;
import
java.lang.ref.WeakReference
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
import
javax.swing.JButton
;
import
javax.swing.JFrame
;
import
javax.swing.JPanel
;
import
javax.swing.SwingUtilities
;
import
test.java.awt.regtesthelpers.Util
;
/*
@test
@bug 7079254
@summary Toolkit eventListener leaks memory
@library ../regtesthelpers
@build Util
@compile LWDispatcherMemoryLeakTest.java
@run main/othervm -Xmx10M LWDispatcherMemoryLeakTest
*/
public
class
LWDispatcherMemoryLeakTest
{
private
static
JFrame
frame
;
private
static
WeakReference
<
JButton
>
button
;
private
static
WeakReference
<
JPanel
>
p
;
public
static
void
init
()
throws
Throwable
{
SwingUtilities
.
invokeAndWait
(
new
Runnable
()
{
@Override
public
void
run
()
{
frame
=
new
JFrame
();
frame
.
setLayout
(
new
FlowLayout
());
button
=
new
WeakReference
<
JButton
>(
new
JButton
(
"Text"
));
p
=
new
WeakReference
<
JPanel
>(
new
JPanel
(
new
FlowLayout
()));
p
.
get
().
add
(
button
.
get
());
frame
.
add
(
p
.
get
());
frame
.
setBounds
(
500
,
400
,
200
,
200
);
frame
.
setVisible
(
true
);
}
});
Util
.
waitTillShown
(
button
.
get
());
Util
.
clickOnComp
(
button
.
get
(),
new
Robot
());
SwingUtilities
.
invokeAndWait
(
new
Runnable
()
{
@Override
public
void
run
()
{
frame
.
remove
(
p
.
get
());
}
});
Util
.
waitForIdle
(
null
);
assertGC
();
}
public
static
void
assertGC
()
throws
Throwable
{
List
<
byte
[]>
alloc
=
new
ArrayList
<
byte
[]>();
int
size
=
10
*
1024
;
while
(
true
)
{
try
{
alloc
.
add
(
new
byte
[
size
]);
}
catch
(
OutOfMemoryError
err
)
{
break
;
}
}
alloc
=
null
;
if
(
button
.
get
()
!=
null
)
{
throw
new
Exception
(
"Test failed: JButton was not collected"
);
}
}
public
static
void
main
(
String
args
[])
throws
Throwable
{
init
();
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录