Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
242b5ee8
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看板
提交
242b5ee8
编写于
4月 30, 2013
作者:
M
mchung
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8013531: Provide a utility class in com.sun.tools.classfile to find field/method references
Reviewed-by: alanb
上级
2e027391
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
53 addition
and
233 deletion
+53
-233
test/sun/reflect/CallerSensitive/CallerSensitiveFinder.java
test/sun/reflect/CallerSensitive/CallerSensitiveFinder.java
+51
-29
test/sun/reflect/CallerSensitive/MethodFinder.java
test/sun/reflect/CallerSensitive/MethodFinder.java
+0
-201
test/sun/reflect/CallerSensitive/MissingCallerSensitive.java
test/sun/reflect/CallerSensitive/MissingCallerSensitive.java
+2
-3
未找到文件。
test/sun/reflect/CallerSensitive/CallerSensitiveFinder.java
浏览文件 @
242b5ee8
...
...
@@ -46,10 +46,10 @@ import java.util.concurrent.FutureTask;
* @bug 8010117
* @summary Verify if CallerSensitive methods are annotated with
* sun.reflect.CallerSensitive annotation
* @build CallerSensitiveFinder
MethodFinder
* @build CallerSensitiveFinder
* @run main/othervm/timeout=900 -mx600m CallerSensitiveFinder
*/
public
class
CallerSensitiveFinder
extends
MethodFinder
{
public
class
CallerSensitiveFinder
{
private
static
int
numThreads
=
3
;
private
static
boolean
verbose
=
false
;
public
static
void
main
(
String
[]
args
)
throws
Exception
{
...
...
@@ -71,8 +71,7 @@ public class CallerSensitiveFinder extends MethodFinder {
if
(
classes
.
isEmpty
())
{
classes
.
addAll
(
PlatformClassPath
.
getJREClasses
());
}
final
String
method
=
"sun/reflect/Reflection.getCallerClass"
;
CallerSensitiveFinder
csfinder
=
new
CallerSensitiveFinder
(
method
);
CallerSensitiveFinder
csfinder
=
new
CallerSensitiveFinder
();
List
<
String
>
errors
=
csfinder
.
run
(
classes
);
if
(!
errors
.
isEmpty
())
{
...
...
@@ -82,8 +81,46 @@ public class CallerSensitiveFinder extends MethodFinder {
}
private
final
List
<
String
>
csMethodsMissingAnnotation
=
new
ArrayList
<>();
public
CallerSensitiveFinder
(
String
...
methods
)
{
super
(
methods
);
private
final
ReferenceFinder
finder
;
public
CallerSensitiveFinder
()
{
this
.
finder
=
new
ReferenceFinder
(
getFilter
(),
getVisitor
());
}
private
ReferenceFinder
.
Filter
getFilter
()
{
final
String
classname
=
"sun/reflect/Reflection"
;
final
String
method
=
"getCallerClass"
;
return
new
ReferenceFinder
.
Filter
()
{
public
boolean
accept
(
ConstantPool
cpool
,
CPRefInfo
cpref
)
{
try
{
CONSTANT_NameAndType_info
nat
=
cpref
.
getNameAndTypeInfo
();
return
cpref
.
getClassName
().
equals
(
classname
)
&&
nat
.
getName
().
equals
(
method
);
}
catch
(
ConstantPoolException
ex
)
{
throw
new
RuntimeException
(
ex
);
}
}
};
}
private
ReferenceFinder
.
Visitor
getVisitor
()
{
return
new
ReferenceFinder
.
Visitor
()
{
public
void
visit
(
ClassFile
cf
,
Method
m
,
List
<
CPRefInfo
>
refs
)
{
try
{
String
name
=
String
.
format
(
"%s#%s %s"
,
cf
.
getName
(),
m
.
getName
(
cf
.
constant_pool
),
m
.
descriptor
.
getValue
(
cf
.
constant_pool
));
if
(!
CallerSensitiveFinder
.
isCallerSensitive
(
m
,
cf
.
constant_pool
))
{
csMethodsMissingAnnotation
.
add
(
name
);
System
.
err
.
println
(
"Missing @CallerSensitive: "
+
name
);
}
else
{
if
(
verbose
)
{
System
.
out
.
format
(
"@CS %s%n"
,
name
);
}
}
}
catch
(
ConstantPoolException
ex
)
{
throw
new
RuntimeException
(
ex
);
}
}
};
}
public
List
<
String
>
run
(
List
<
Path
>
classes
)
throws
IOException
,
InterruptedException
,
...
...
@@ -125,27 +162,12 @@ public class CallerSensitiveFinder extends MethodFinder {
return
false
;
}
public
void
referenceFound
(
ClassFile
cf
,
Method
m
,
Set
<
Integer
>
refs
)
throws
ConstantPoolException
{
String
name
=
String
.
format
(
"%s#%s %s"
,
cf
.
getName
(),
m
.
getName
(
cf
.
constant_pool
),
m
.
descriptor
.
getValue
(
cf
.
constant_pool
));
if
(!
CallerSensitiveFinder
.
isCallerSensitive
(
m
,
cf
.
constant_pool
))
{
csMethodsMissingAnnotation
.
add
(
name
);
System
.
err
.
println
(
"Missing @CallerSensitive: "
+
name
);
}
else
{
if
(
verbose
)
{
System
.
out
.
format
(
"@CS %s%n"
,
name
);
}
}
}
private
final
List
<
FutureTask
<
String
>>
tasks
=
new
ArrayList
<
FutureTask
<
String
>>();
private
FutureTask
<
String
>
getTask
(
final
ClassFile
cf
)
{
FutureTask
<
String
>
task
=
new
FutureTask
<
String
>(
new
Callable
<
String
>()
{
public
String
call
()
throws
Exception
{
return
parse
(
cf
);
private
final
List
<
FutureTask
<
Void
>>
tasks
=
new
ArrayList
<
FutureTask
<
Void
>>();
private
FutureTask
<
Void
>
getTask
(
final
ClassFile
cf
)
{
FutureTask
<
Void
>
task
=
new
FutureTask
<
Void
>(
new
Callable
<
Void
>()
{
public
Void
call
()
throws
Exception
{
finder
.
parse
(
cf
);
return
null
;
}
});
tasks
.
add
(
task
);
...
...
@@ -153,8 +175,8 @@ public class CallerSensitiveFinder extends MethodFinder {
}
private
void
waitForCompletion
()
throws
InterruptedException
,
ExecutionException
{
for
(
FutureTask
<
String
>
t
:
tasks
)
{
String
s
=
t
.
get
();
for
(
FutureTask
<
Void
>
t
:
tasks
)
{
t
.
get
();
}
System
.
out
.
println
(
"Parsed "
+
tasks
.
size
()
+
" classfiles"
);
}
...
...
test/sun/reflect/CallerSensitive/MethodFinder.java
已删除
100644 → 0
浏览文件 @
2e027391
/*
* 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.util.*
;
import
com.sun.tools.classfile.*
;
import
static
com
.
sun
.
tools
.
classfile
.
ConstantPool
.*;
import
com.sun.tools.classfile.Instruction.TypeKind
;
/**
* MethodFinder utility class to find references to the given methods.
*/
public
abstract
class
MethodFinder
{
final
List
<
String
>
methods
;
public
MethodFinder
(
String
...
methods
)
{
this
.
methods
=
Arrays
.
asList
(
methods
);
}
/**
* A callback method will be invoked when a method referencing
* any of the lookup methods.
*
* @param cf ClassFile
* @param m Method
* @param refs Set of constant pool indices that reference the methods
* matching the given lookup method names
*/
public
abstract
void
referenceFound
(
ClassFile
cf
,
Method
m
,
Set
<
Integer
>
refs
)
throws
ConstantPoolException
;
public
String
parse
(
ClassFile
cf
)
throws
ConstantPoolException
{
List
<
Integer
>
cprefs
=
new
ArrayList
<
Integer
>();
int
index
=
1
;
for
(
ConstantPool
.
CPInfo
cpInfo
:
cf
.
constant_pool
.
entries
())
{
if
(
cpInfo
.
accept
(
cpVisitor
,
null
))
{
cprefs
.
add
(
index
);
}
index
+=
cpInfo
.
size
();
}
if
(!
cprefs
.
isEmpty
())
{
for
(
Method
m
:
cf
.
methods
)
{
Set
<
Integer
>
refs
=
new
HashSet
<
Integer
>();
Code_attribute
c_attr
=
(
Code_attribute
)
m
.
attributes
.
get
(
Attribute
.
Code
);
if
(
c_attr
!=
null
)
{
for
(
Instruction
instr
:
c_attr
.
getInstructions
())
{
int
idx
=
instr
.
accept
(
codeVisitor
,
cprefs
);
if
(
idx
>
0
)
{
refs
.
add
(
idx
);
}
}
}
if
(
refs
.
size
()
>
0
)
{
referenceFound
(
cf
,
m
,
refs
);
}
}
}
return
cprefs
.
isEmpty
()
?
""
:
cf
.
getName
();
}
private
ConstantPool
.
Visitor
<
Boolean
,
Void
>
cpVisitor
=
new
ConstantPool
.
Visitor
<
Boolean
,
Void
>()
{
private
boolean
matches
(
CPRefInfo
info
)
{
try
{
CONSTANT_NameAndType_info
nat
=
info
.
getNameAndTypeInfo
();
return
matches
(
info
.
getClassName
(),
nat
.
getName
(),
nat
.
getType
());
}
catch
(
ConstantPoolException
ex
)
{
return
false
;
}
}
private
boolean
matches
(
String
cn
,
String
name
,
String
type
)
{
return
methods
.
contains
(
cn
+
"."
+
name
);
}
public
Boolean
visitClass
(
CONSTANT_Class_info
info
,
Void
p
)
{
return
false
;
}
public
Boolean
visitInterfaceMethodref
(
CONSTANT_InterfaceMethodref_info
info
,
Void
p
)
{
return
matches
(
info
);
}
public
Boolean
visitMethodref
(
CONSTANT_Methodref_info
info
,
Void
p
)
{
return
matches
(
info
);
}
public
Boolean
visitDouble
(
CONSTANT_Double_info
info
,
Void
p
)
{
return
false
;
}
public
Boolean
visitFieldref
(
CONSTANT_Fieldref_info
info
,
Void
p
)
{
return
false
;
}
public
Boolean
visitFloat
(
CONSTANT_Float_info
info
,
Void
p
)
{
return
false
;
}
public
Boolean
visitInteger
(
CONSTANT_Integer_info
info
,
Void
p
)
{
return
false
;
}
public
Boolean
visitInvokeDynamic
(
CONSTANT_InvokeDynamic_info
info
,
Void
p
)
{
return
false
;
}
public
Boolean
visitLong
(
CONSTANT_Long_info
info
,
Void
p
)
{
return
false
;
}
public
Boolean
visitNameAndType
(
CONSTANT_NameAndType_info
info
,
Void
p
)
{
return
false
;
}
public
Boolean
visitMethodHandle
(
CONSTANT_MethodHandle_info
info
,
Void
p
)
{
return
false
;
}
public
Boolean
visitMethodType
(
CONSTANT_MethodType_info
info
,
Void
p
)
{
return
false
;
}
public
Boolean
visitString
(
CONSTANT_String_info
info
,
Void
p
)
{
return
false
;
}
public
Boolean
visitUtf8
(
CONSTANT_Utf8_info
info
,
Void
p
)
{
return
false
;
}
};
private
Instruction
.
KindVisitor
<
Integer
,
List
<
Integer
>>
codeVisitor
=
new
Instruction
.
KindVisitor
<
Integer
,
List
<
Integer
>>()
{
public
Integer
visitNoOperands
(
Instruction
instr
,
List
<
Integer
>
p
)
{
return
0
;
}
public
Integer
visitArrayType
(
Instruction
instr
,
TypeKind
kind
,
List
<
Integer
>
p
)
{
return
0
;
}
public
Integer
visitBranch
(
Instruction
instr
,
int
offset
,
List
<
Integer
>
p
)
{
return
0
;
}
public
Integer
visitConstantPoolRef
(
Instruction
instr
,
int
index
,
List
<
Integer
>
p
)
{
return
p
.
contains
(
index
)
?
index
:
0
;
}
public
Integer
visitConstantPoolRefAndValue
(
Instruction
instr
,
int
index
,
int
value
,
List
<
Integer
>
p
)
{
return
p
.
contains
(
index
)
?
index
:
0
;
}
public
Integer
visitLocal
(
Instruction
instr
,
int
index
,
List
<
Integer
>
p
)
{
return
0
;
}
public
Integer
visitLocalAndValue
(
Instruction
instr
,
int
index
,
int
value
,
List
<
Integer
>
p
)
{
return
0
;
}
public
Integer
visitLookupSwitch
(
Instruction
instr
,
int
default_
,
int
npairs
,
int
[]
matches
,
int
[]
offsets
,
List
<
Integer
>
p
)
{
return
0
;
}
public
Integer
visitTableSwitch
(
Instruction
instr
,
int
default_
,
int
low
,
int
high
,
int
[]
offsets
,
List
<
Integer
>
p
)
{
return
0
;
}
public
Integer
visitValue
(
Instruction
instr
,
int
value
,
List
<
Integer
>
p
)
{
return
0
;
}
public
Integer
visitUnknown
(
Instruction
instr
,
List
<
Integer
>
p
)
{
return
0
;
}
};
}
test/sun/reflect/CallerSensitive/MissingCallerSensitive.java
浏览文件 @
242b5ee8
...
...
@@ -27,7 +27,7 @@
* @bug 8010117
* @summary Test CallerSensitiveFinder to find missing annotation
* @compile -XDignore.symbol.file MissingCallerSensitive.java
* @build CallerSensitiveFinder
MethodFinder
* @build CallerSensitiveFinder
* @run main MissingCallerSensitive
*/
...
...
@@ -40,8 +40,7 @@ public class MissingCallerSensitive {
List
<
Path
>
classes
=
new
ArrayList
<>();
classes
.
add
(
Paths
.
get
(
testclasses
,
"MissingCallerSensitive.class"
));
final
String
method
=
"sun/reflect/Reflection.getCallerClass"
;
CallerSensitiveFinder
csfinder
=
new
CallerSensitiveFinder
(
method
);
CallerSensitiveFinder
csfinder
=
new
CallerSensitiveFinder
();
List
<
String
>
errors
=
csfinder
.
run
(
classes
);
if
(
errors
.
size
()
!=
1
)
{
throw
new
RuntimeException
(
"Unexpected number of methods found: "
+
errors
.
size
());
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录