Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
38a136fd
D
dragonwell8_jdk
项目概览
openanolis
/
dragonwell8_jdk
通知
3
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
38a136fd
编写于
3月 24, 2015
作者:
A
amurillo
浏览文件
操作
浏览文件
下载
差异文件
Merge
上级
8a9e08eb
b0830931
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
216 addition
and
0 deletion
+216
-0
test/java/lang/instrument/ManyMethodsBenchmarkAgent.java
test/java/lang/instrument/ManyMethodsBenchmarkAgent.java
+75
-0
test/java/lang/instrument/ManyMethodsBenchmarkApp.java
test/java/lang/instrument/ManyMethodsBenchmarkApp.java
+141
-0
未找到文件。
test/java/lang/instrument/ManyMethodsBenchmarkAgent.java
0 → 100644
浏览文件 @
38a136fd
/*
* 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.
*/
/**
* @test
* @bug 8046246
* @summary Tests and benchmarks the JVMTI RedefineClasses when a
* single class (and its parent) contains many methods.
*
* @run build ManyMethodsBenchmarkApp ManyMethodsBenchmarkAgent
* @run shell MakeJAR3.sh ManyMethodsBenchmarkAgent 'Can-Retransform-Classes: true'
* @run main/othervm -javaagent:ManyMethodsBenchmarkAgent.jar ManyMethodsBenchmarkApp
*/
import
java.lang.instrument.*
;
public
class
ManyMethodsBenchmarkAgent
{
public
static
boolean
fail
=
false
;
public
static
boolean
completed
=
false
;
private
static
Instrumentation
instrumentation
;
public
static
void
premain
(
String
agentArgs
,
Instrumentation
instrumentation
)
{
System
.
out
.
println
(
"ManyMethodsBenchmarkAgent started"
);
ManyMethodsBenchmarkAgent
.
instrumentation
=
instrumentation
;
System
.
out
.
println
(
"ManyMethodsBenchmarkAgent finished"
);
}
static
void
instr
()
{
System
.
out
.
println
(
"ManyMethodsBenchmarkAgent.instr started"
);
Class
[]
allClasses
=
instrumentation
.
getAllLoadedClasses
();
for
(
int
i
=
0
;
i
<
allClasses
.
length
;
i
++)
{
Class
klass
=
allClasses
[
i
];
String
name
=
klass
.
getName
();
if
(!
name
.
equals
(
"Base"
))
{
continue
;
}
System
.
err
.
println
(
"Instrumenting the class: "
+
klass
);
try
{
instrumentation
.
retransformClasses
(
klass
);
}
catch
(
Throwable
e
)
{
System
.
err
.
println
(
"Error: bad return from retransform: "
+
klass
);
System
.
err
.
println
(
" ERROR: "
+
e
);
fail
=
true
;
}
}
completed
=
true
;
System
.
out
.
println
(
"ManyMethodsBenchmarkAgent.instr finished"
);
}
}
test/java/lang/instrument/ManyMethodsBenchmarkApp.java
0 → 100644
浏览文件 @
38a136fd
/*
* Copyright 2015 Google 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 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.io.File
;
import
java.io.FileWriter
;
import
java.io.PrintStream
;
import
java.lang.reflect.InvocationTargetException
;
import
java.lang.reflect.Method
;
import
java.lang.reflect.Type
;
import
java.net.URL
;
import
java.net.URLClassLoader
;
import
java.util.Arrays
;
import
java.util.List
;
import
javax.tools.JavaCompiler
;
import
javax.tools.StandardJavaFileManager
;
import
javax.tools.ToolProvider
;
/**
* A manual benchmark of the JVMTI RedefineClasses when a
* single class (and its parent) contains many methods.
*/
public
class
ManyMethodsBenchmarkApp
{
// Limit is 64k but we can not put such many as the CP limit is 32k.
// In practice, it means a real limit is much lower (less than 22000).
static
final
int
METHOD_COUNT
=
20000
;
static
Class
<?>
loadClassInNewClassLoader
(
String
className
)
throws
Exception
{
URL
[]
urls
=
{
new
File
(
"."
).
toURI
().
toURL
()
};
URLClassLoader
ucl
=
new
URLClassLoader
(
urls
,
null
);
Class
<?>
klazz
=
Class
.
forName
(
className
,
true
,
ucl
);
return
klazz
;
}
static
void
benchmarkClassOperations
(
String
className
)
throws
Exception
{
Class
<?>
klazz
=
loadClassInNewClassLoader
(
className
);
Method
[]
methods
=
klazz
.
getDeclaredMethods
();
if
(
methods
.
length
!=
METHOD_COUNT
)
{
throw
new
AssertionError
(
"unexpected method count: "
+
methods
.
length
+
" expected: "
+
METHOD_COUNT
);
}
methods
=
klazz
.
getMethods
();
// returned methods includes those inherited from Object
int
objectMethodSlop
=
100
;
if
(
methods
.
length
<=
METHOD_COUNT
||
methods
.
length
>=
METHOD_COUNT
+
objectMethodSlop
)
{
throw
new
AssertionError
(
"unexpected method count: "
+
methods
.
length
);
}
// Invoke methods to make them appear in the constant pool cache
Object
obj
=
klazz
.
newInstance
();
Object
[]
args
=
new
Object
[
0
];
for
(
Method
m:
methods
)
{
try
{
Class
<?>[]
types
=
m
.
getParameterTypes
();
String
name
=
m
.
getName
();
// System.out.println("method: " + name + "; argno: " + types.length);
if
(
types
.
length
==
0
&&
name
.
length
()
==
2
&&
name
.
startsWith
(
"f"
))
{
m
.
invoke
(
obj
,
args
);
}
}
catch
(
InvocationTargetException
ex
)
{
ex
.
printStackTrace
();
}
}
}
public
static
void
main
(
String
[]
args
)
throws
Exception
{
System
.
out
.
println
(
"test started: ManyMethodsBenchmarkApp"
);
// Create source files with many methods
File
base
=
new
File
(
"Base.java"
);
try
(
FileWriter
fw
=
new
FileWriter
(
base
))
{
fw
.
write
(
"public class Base {\n"
);
final
int
L
=
10
;
// Each of the first L methods makes calls to its own chunk of METHOD_COUNT/L methods
for
(
int
k
=
0
;
k
<
L
;
k
++)
{
fw
.
write
(
" public void f"
+
k
+
"() {\n"
);
int
shift
=
(
k
==
0
)
?
L
:
0
;
for
(
int
i
=
(
k
*
(
METHOD_COUNT
/
L
))
+
shift
;
i
<
(
k
+
1
)
*
METHOD_COUNT
/
L
;
i
++)
{
fw
.
write
(
" f"
+
i
+
"();\n"
);
}
fw
.
write
(
" }\n"
);
}
// The rest of (METHOD_COUNT - L) methods have empty body
for
(
int
i
=
L
;
i
<
METHOD_COUNT
;
i
++)
{
fw
.
write
(
" public static void f"
+
i
+
"() {}\n"
);
}
fw
.
write
(
"}\n"
);
}
// Compile the generated source files.
JavaCompiler
compiler
=
ToolProvider
.
getSystemJavaCompiler
();
List
<
File
>
files
=
Arrays
.
asList
(
new
File
[]
{
base
});
try
(
StandardJavaFileManager
fileManager
=
compiler
.
getStandardFileManager
(
null
,
null
,
null
))
{
compiler
.
getTask
(
null
,
fileManager
,
null
,
null
,
null
,
fileManager
.
getJavaFileObjectsFromFiles
(
files
))
.
call
();
}
benchmarkClassOperations
(
"Base"
);
ManyMethodsBenchmarkAgent
.
instr
();
// Cleanup
base
.
delete
();
new
File
(
"Base.class"
).
delete
();
if
(!
ManyMethodsBenchmarkAgent
.
completed
)
{
throw
new
Exception
(
"ERROR: ManyMethodsBenchmarkAgent did not complete."
);
}
if
(
ManyMethodsBenchmarkAgent
.
fail
)
{
throw
new
Exception
(
"ERROR: ManyMethodsBenchmarkAgent failed."
);
}
else
{
System
.
out
.
println
(
"ManyMethodsBenchmarkAgent succeeded."
);
}
System
.
out
.
println
(
"test finished: ManyMethodsBenchmarkApp"
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录