Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
60d3202f
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看板
提交
60d3202f
编写于
10月 22, 2009
作者:
A
alexp
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
6795356: Leak caused by javax.swing.UIDefaults.ProxyLazyValue.acc
Reviewed-by: hawtin
上级
a7f0ac69
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
215 addition
and
3 deletion
+215
-3
src/share/classes/javax/swing/JTable.java
src/share/classes/javax/swing/JTable.java
+2
-1
src/share/classes/javax/swing/plaf/metal/OceanTheme.java
src/share/classes/javax/swing/plaf/metal/OceanTheme.java
+2
-1
src/share/classes/sun/swing/SwingLazyValue.java
src/share/classes/sun/swing/SwingLazyValue.java
+15
-1
test/javax/swing/UIDefaults/6795356/SwingLazyValueTest.java
test/javax/swing/UIDefaults/6795356/SwingLazyValueTest.java
+44
-0
test/javax/swing/UIDefaults/6795356/TableTest.java
test/javax/swing/UIDefaults/6795356/TableTest.java
+52
-0
test/javax/swing/UIDefaults/6795356/bug6795356.java
test/javax/swing/UIDefaults/6795356/bug6795356.java
+100
-0
未找到文件。
src/share/classes/javax/swing/JTable.java
浏览文件 @
60d3202f
...
...
@@ -57,6 +57,7 @@ import sun.swing.SwingUtilities2;
import
sun.swing.SwingUtilities2.Section
;
import
static
sun
.
swing
.
SwingUtilities2
.
Section
.*;
import
sun.swing.PrintingStatus
;
import
sun.swing.SwingLazyValue
;
/**
* The <code>JTable</code> is used to display and edit regular two-dimensional tables
...
...
@@ -5316,7 +5317,7 @@ public class JTable extends JComponent implements TableModelListener, Scrollable
}
private
void
setLazyValue
(
Hashtable
h
,
Class
c
,
String
s
)
{
h
.
put
(
c
,
new
UIDefaults
.
Proxy
LazyValue
(
s
));
h
.
put
(
c
,
new
Swing
LazyValue
(
s
));
}
private
void
setLazyRenderer
(
Class
c
,
String
s
)
{
...
...
src/share/classes/javax/swing/plaf/metal/OceanTheme.java
浏览文件 @
60d3202f
...
...
@@ -32,6 +32,7 @@ import javax.swing.*;
import
javax.swing.plaf.*
;
import
sun.swing.SwingUtilities2
;
import
sun.swing.PrintColorUIResource
;
import
sun.swing.SwingLazyValue
;
/**
* The default theme for the {@code MetalLookAndFeel}.
...
...
@@ -128,7 +129,7 @@ public class OceanTheme extends DefaultMetalTheme {
* @throws NullPointerException if {@code table} is {@code null}
*/
public
void
addCustomEntriesToTable
(
UIDefaults
table
)
{
Object
focusBorder
=
new
UIDefaults
.
Proxy
LazyValue
(
Object
focusBorder
=
new
Swing
LazyValue
(
"javax.swing.plaf.BorderUIResource$LineBorderUIResource"
,
new
Object
[]
{
getPrimary1
()});
// .30 0 DDE8F3 white secondary2
...
...
src/share/classes/sun/swing/SwingLazyValue.java
浏览文件 @
60d3202f
...
...
@@ -26,6 +26,9 @@ package sun.swing;
import
java.lang.reflect.Constructor
;
import
java.lang.reflect.Method
;
import
java.lang.reflect.AccessibleObject
;
import
java.security.AccessController
;
import
java.security.PrivilegedAction
;
import
javax.swing.UIDefaults
;
/**
...
...
@@ -65,13 +68,15 @@ public class SwingLazyValue implements UIDefaults.LazyValue {
if
(
methodName
!=
null
)
{
Class
[]
types
=
getClassArray
(
args
);
Method
m
=
c
.
getMethod
(
methodName
,
types
);
makeAccessible
(
m
);
return
m
.
invoke
(
c
,
args
);
}
else
{
Class
[]
types
=
getClassArray
(
args
);
Constructor
constructor
=
c
.
getConstructor
(
types
);
makeAccessible
(
constructor
);
return
constructor
.
newInstance
(
args
);
}
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
// Ideally we would throw an exception, unfortunately
// often times there are errors as an initial look and
// feel is loaded before one can be switched. Perhaps a
...
...
@@ -81,6 +86,15 @@ public class SwingLazyValue implements UIDefaults.LazyValue {
return
null
;
}
private
void
makeAccessible
(
final
AccessibleObject
object
)
{
AccessController
.
doPrivileged
(
new
PrivilegedAction
<
Void
>()
{
public
Void
run
()
{
object
.
setAccessible
(
true
);
return
null
;
}
});
}
private
Class
[]
getClassArray
(
Object
[]
args
)
{
Class
[]
types
=
null
;
if
(
args
!=
null
)
{
...
...
test/javax/swing/UIDefaults/6795356/SwingLazyValueTest.java
0 → 100644
浏览文件 @
60d3202f
/*
* Copyright 2009 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.
*/
/*
* @test
* @bug 6795356
* @summary Checks that SwingLazyValue class correclty works
* @author Alexander Potochkin
* @run main SwingLazyValueTest
*/
import
sun.swing.SwingLazyValue
;
import
javax.swing.*
;
public
class
SwingLazyValueTest
{
public
static
void
main
(
String
[]
args
)
throws
Exception
{
if
(
new
SwingLazyValue
(
"javax.swing.JTable$DoubleRenderer"
).
createValue
(
null
)
==
null
)
{
throw
new
RuntimeException
(
"SwingLazyValue doesn't work"
);
}
}
}
test/javax/swing/UIDefaults/6795356/TableTest.java
0 → 100644
浏览文件 @
60d3202f
/*
* Copyright 2009 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.
*/
/*
* @test
* @bug 6795356
* @summary Checks that SwingLazyValue class correclty works
* @author Alexander Potochkin
* @run main/othervm TableTest
*/
import
sun.applet.AppletSecurity
;
import
javax.swing.*
;
import
javax.swing.table.TableCellEditor
;
import
java.awt.*
;
public
class
TableTest
{
public
static
void
main
(
String
[]
args
)
throws
Exception
{
KeyboardFocusManager
.
getCurrentKeyboardFocusManager
();
System
.
setSecurityManager
(
new
AppletSecurity
());
JTable
table
=
new
JTable
();
TableCellEditor
de
=
table
.
getDefaultEditor
(
Double
.
class
);
if
(
de
==
null
)
{
throw
new
RuntimeException
(
"Table default editor is null"
);
}
}
}
test/javax/swing/UIDefaults/6795356/bug6795356.java
0 → 100644
浏览文件 @
60d3202f
/*
* Copyright 2009 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.
*/
/*
* @test
* @bug 6795356
* @summary Leak caused by javax.swing.UIDefaults.ProxyLazyValue.acc
* @author Alexander Potochkin
* @run main bug6795356
*/
import
java.lang.ref.WeakReference
;
import
java.security.ProtectionDomain
;
import
java.security.AccessController
;
import
java.security.PrivilegedAction
;
import
java.security.AccessControlContext
;
import
java.util.LinkedList
;
import
java.util.List
;
import
javax.swing.*
;
public
class
bug6795356
{
volatile
static
WeakReference
<
ProtectionDomain
>
weakRef
;
public
static
void
main
(
String
[]
args
)
throws
Exception
{
ProtectionDomain
domain
=
new
ProtectionDomain
(
null
,
null
);
AccessController
.
doPrivileged
(
new
PrivilegedAction
<
Object
>()
{
public
Object
run
()
{
// this initialize ProxyLazyValues
UIManager
.
getLookAndFeel
();
return
null
;
}
},
new
AccessControlContext
(
new
ProtectionDomain
[]{
domain
}));
weakRef
=
new
WeakReference
<
ProtectionDomain
>(
domain
);
domain
=
null
;
// Generate OutOfMemory and check the weak ref
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"
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录