Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
09a38e15
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看板
提交
09a38e15
编写于
5月 13, 2015
作者:
S
serb
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8072775: Tremendous memory usage by JTextArea
Reviewed-by: vadim, prr
上级
a3799e58
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
141 addition
and
75 deletion
+141
-75
src/share/classes/sun/font/StandardTextSource.java
src/share/classes/sun/font/StandardTextSource.java
+40
-69
src/share/classes/sun/font/TextLabelFactory.java
src/share/classes/sun/font/TextLabelFactory.java
+6
-6
test/javax/swing/JTextArea/TextViewOOM/TextViewOOM.java
test/javax/swing/JTextArea/TextViewOOM/TextViewOOM.java
+95
-0
未找到文件。
src/share/classes/sun/font/StandardTextSource.java
浏览文件 @
09a38e15
/*
/*
* Copyright (c) 1998, 201
3
, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 201
5
, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
*
* This code is free software; you can redistribute it and/or modify it
* This code is free software; you can redistribute it and/or modify it
...
@@ -33,17 +33,18 @@ import java.awt.Font;
...
@@ -33,17 +33,18 @@ import java.awt.Font;
import
java.awt.font.FontRenderContext
;
import
java.awt.font.FontRenderContext
;
import
java.awt.font.LineMetrics
;
import
java.awt.font.LineMetrics
;
public
class
StandardTextSource
extends
TextSource
{
final
class
StandardTextSource
extends
TextSource
{
char
[]
chars
;
int
start
;
private
final
char
[]
chars
;
int
len
;
private
final
int
start
;
int
cstart
;
private
final
int
len
;
int
clen
;
private
final
int
cstart
;
int
level
;
// assumed all uniform
private
final
int
clen
;
int
flags
;
// see GlyphVector.java
private
final
int
level
;
// assumed all uniform
Font
font
;
private
final
int
flags
;
// see GlyphVector.java
FontRenderContext
frc
;
private
final
Font
font
;
CoreMetrics
cm
;
private
final
FontRenderContext
frc
;
private
final
CoreMetrics
cm
;
/**
/**
* Create a simple implementation of a TextSource.
* Create a simple implementation of a TextSource.
...
@@ -59,7 +60,7 @@ public class StandardTextSource extends TextSource {
...
@@ -59,7 +60,7 @@ public class StandardTextSource extends TextSource {
* and lm is the line metrics for the entire source text, but not
* and lm is the line metrics for the entire source text, but not
* necessarily the context.
* necessarily the context.
*/
*/
public
StandardTextSource
(
char
[]
chars
,
StandardTextSource
(
char
[]
chars
,
int
start
,
int
start
,
int
len
,
int
len
,
int
cstart
,
int
cstart
,
...
@@ -97,7 +98,7 @@ public class StandardTextSource extends TextSource {
...
@@ -97,7 +98,7 @@ public class StandardTextSource extends TextSource {
throw
new
IllegalArgumentException
(
"bad frc: null"
);
throw
new
IllegalArgumentException
(
"bad frc: null"
);
}
}
this
.
chars
=
chars
.
clone
()
;
this
.
chars
=
chars
;
this
.
start
=
start
;
this
.
start
=
start
;
this
.
len
=
len
;
this
.
len
=
len
;
this
.
cstart
=
cstart
;
this
.
cstart
=
cstart
;
...
@@ -115,40 +116,10 @@ public class StandardTextSource extends TextSource {
...
@@ -115,40 +116,10 @@ public class StandardTextSource extends TextSource {
}
}
}
}
/** Create a StandardTextSource whose context is coextensive with the source. */
public
StandardTextSource
(
char
[]
chars
,
int
start
,
int
len
,
int
level
,
int
flags
,
Font
font
,
FontRenderContext
frc
,
CoreMetrics
cm
)
{
this
(
chars
,
start
,
len
,
start
,
len
,
level
,
flags
,
font
,
frc
,
cm
);
}
/** Create a StandardTextSource whose context and source are coextensive with the entire char array. */
public
StandardTextSource
(
char
[]
chars
,
int
level
,
int
flags
,
Font
font
,
FontRenderContext
frc
)
{
this
(
chars
,
0
,
chars
.
length
,
0
,
chars
.
length
,
level
,
flags
,
font
,
frc
,
null
);
}
/** Create a StandardTextSource whose context and source are all the text in the String. */
public
StandardTextSource
(
String
str
,
int
level
,
int
flags
,
Font
font
,
FontRenderContext
frc
)
{
this
(
str
.
toCharArray
(),
0
,
str
.
length
(),
0
,
str
.
length
(),
level
,
flags
,
font
,
frc
,
null
);
}
// TextSource API
// TextSource API
public
char
[]
getChars
()
{
public
char
[]
getChars
()
{
return
chars
.
clone
()
;
return
chars
;
}
}
public
int
getStart
()
{
public
int
getStart
()
{
...
...
src/share/classes/sun/font/TextLabelFactory.java
浏览文件 @
09a38e15
/*
/*
* Copyright (c) 1998, 201
3
, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 201
5
, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
*
* This code is free software; you can redistribute it and/or modify it
* This code is free software; you can redistribute it and/or modify it
...
@@ -48,12 +48,12 @@ import java.text.Bidi;
...
@@ -48,12 +48,12 @@ import java.text.Bidi;
* @see TextLayout
* @see TextLayout
*/
*/
public
class
TextLabelFactory
{
public
final
class
TextLabelFactory
{
private
FontRenderContext
frc
;
private
final
FontRenderContext
frc
;
private
char
[]
text
;
private
final
char
[]
text
;
private
Bidi
bidi
;
private
final
Bidi
bidi
;
private
Bidi
lineBidi
;
private
Bidi
lineBidi
;
private
int
flags
;
private
final
int
flags
;
private
int
lineStart
;
private
int
lineStart
;
private
int
lineLimit
;
private
int
lineLimit
;
...
...
test/javax/swing/JTextArea/TextViewOOM/TextViewOOM.java
0 → 100644
浏览文件 @
09a38e15
/*
* 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
java.awt.EventQueue
;
import
javax.swing.JFrame
;
import
javax.swing.JScrollPane
;
import
javax.swing.JTextArea
;
/**
* @test
* @bug 8072775
* @run main/othervm -Xmx80m TextViewOOM
*/
public
class
TextViewOOM
{
private
static
JFrame
frame
;
private
static
JTextArea
ta
;
private
static
final
String
STRING
=
"\uDC00\uD802\uDFFF"
;
private
static
final
int
N
=
5000
;
private
static
void
createAndShowGUI
()
{
frame
=
new
JFrame
();
final
JScrollPane
jScrollPane1
=
new
JScrollPane
();
ta
=
new
JTextArea
();
ta
.
setEditable
(
false
);
ta
.
setColumns
(
20
);
ta
.
setRows
(
5
);
jScrollPane1
.
setViewportView
(
ta
);
frame
.
add
(
ta
);
frame
.
pack
();
frame
.
setLocationRelativeTo
(
null
);
frame
.
setVisible
(
true
);
}
public
static
void
main
(
final
String
[]
args
)
throws
Exception
{
/* Create and display the form */
EventQueue
.
invokeAndWait
(
TextViewOOM:
:
createAndShowGUI
);
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
System
.
gc
();
Thread
.
sleep
(
1000
);
}
long
mem
=
Runtime
.
getRuntime
().
totalMemory
()
-
Runtime
.
getRuntime
().
freeMemory
();
System
.
err
.
println
(
"Memory before creating the text: "
+
mem
);
final
StringBuilder
sb
=
new
StringBuilder
(
N
*
STRING
.
length
());
for
(
int
i
=
0
;
i
<
N
;
i
++)
{
sb
.
append
(
STRING
);
}
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
System
.
gc
();
Thread
.
sleep
(
1000
);
}
mem
=
Runtime
.
getRuntime
().
totalMemory
()
-
Runtime
.
getRuntime
().
freeMemory
();
System
.
err
.
println
(
"Memory after creating the text: "
+
mem
);
EventQueue
.
invokeAndWait
(()
->
{
ta
.
setText
(
sb
.
toString
());
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
System
.
gc
();
try
{
Thread
.
sleep
(
200
);}
catch
(
InterruptedException
iex
)
{}
}
long
mem1
=
Runtime
.
getRuntime
().
totalMemory
()
-
Runtime
.
getRuntime
().
freeMemory
();
System
.
err
.
println
(
"Memory after setting the text: "
+
mem1
);
});
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
System
.
gc
();
Thread
.
sleep
(
1000
);
}
mem
=
Runtime
.
getRuntime
().
totalMemory
()
-
Runtime
.
getRuntime
().
freeMemory
();
System
.
err
.
println
(
"Final memory after everything: "
+
mem
);
EventQueue
.
invokeAndWait
(
frame:
:
dispose
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录