Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_langtools
提交
caa32efb
D
dragonwell8_langtools
项目概览
openanolis
/
dragonwell8_langtools
通知
0
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dragonwell8_langtools
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
caa32efb
编写于
6月 19, 2009
作者:
J
jjg
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
6852856: javap changes to facilitate subclassing javap for variants
Reviewed-by: mcimadamore
上级
32dcd406
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
183 addition
and
59 deletion
+183
-59
src/share/classes/com/sun/tools/classfile/AccessFlags.java
src/share/classes/com/sun/tools/classfile/AccessFlags.java
+19
-19
src/share/classes/com/sun/tools/classfile/ConstantPool.java
src/share/classes/com/sun/tools/classfile/ConstantPool.java
+23
-1
src/share/classes/com/sun/tools/javap/AttributeWriter.java
src/share/classes/com/sun/tools/javap/AttributeWriter.java
+1
-1
src/share/classes/com/sun/tools/javap/ClassWriter.java
src/share/classes/com/sun/tools/javap/ClassWriter.java
+16
-8
src/share/classes/com/sun/tools/javap/ConstantWriter.java
src/share/classes/com/sun/tools/javap/ConstantWriter.java
+8
-4
src/share/classes/com/sun/tools/javap/JavapTask.java
src/share/classes/com/sun/tools/javap/JavapTask.java
+113
-26
src/share/classes/com/sun/tools/javap/SourceWriter.java
src/share/classes/com/sun/tools/javap/SourceWriter.java
+3
-0
未找到文件。
src/share/classes/com/sun/tools/classfile/AccessFlags.java
浏览文件 @
caa32efb
...
...
@@ -58,7 +58,7 @@ public class AccessFlags {
public
static
final
int
ACC_ENUM
=
0x4000
;
// class, inner, field
public
static
final
int
ACC_MODULE
=
0x8000
;
// class, inner, field, method
p
rivate
static
enum
Type
{
Class
,
InnerClass
,
Field
,
Method
};
p
ublic
static
enum
Kind
{
Class
,
InnerClass
,
Field
,
Method
};
AccessFlags
(
ClassReader
cr
)
throws
IOException
{
this
(
cr
.
readUnsignedShort
());
...
...
@@ -87,11 +87,11 @@ public class AccessFlags {
public
Set
<
String
>
getClassModifiers
()
{
int
f
=
((
flags
&
ACC_INTERFACE
)
!=
0
?
flags
&
~
ACC_ABSTRACT
:
flags
);
return
getModifiers
(
f
,
classModifiers
,
Type
.
Class
);
return
getModifiers
(
f
,
classModifiers
,
Kind
.
Class
);
}
public
Set
<
String
>
getClassFlags
()
{
return
getFlags
(
classFlags
,
Type
.
Class
);
return
getFlags
(
classFlags
,
Kind
.
Class
);
}
private
static
final
int
[]
innerClassModifiers
=
{
...
...
@@ -106,11 +106,11 @@ public class AccessFlags {
public
Set
<
String
>
getInnerClassModifiers
()
{
int
f
=
((
flags
&
ACC_INTERFACE
)
!=
0
?
flags
&
~
ACC_ABSTRACT
:
flags
);
return
getModifiers
(
f
,
innerClassModifiers
,
Type
.
InnerClass
);
return
getModifiers
(
f
,
innerClassModifiers
,
Kind
.
InnerClass
);
}
public
Set
<
String
>
getInnerClassFlags
()
{
return
getFlags
(
innerClassFlags
,
Type
.
InnerClass
);
return
getFlags
(
innerClassFlags
,
Kind
.
InnerClass
);
}
private
static
final
int
[]
fieldModifiers
=
{
...
...
@@ -124,11 +124,11 @@ public class AccessFlags {
};
public
Set
<
String
>
getFieldModifiers
()
{
return
getModifiers
(
fieldModifiers
,
Type
.
Field
);
return
getModifiers
(
fieldModifiers
,
Kind
.
Field
);
}
public
Set
<
String
>
getFieldFlags
()
{
return
getFlags
(
fieldFlags
,
Type
.
Field
);
return
getFlags
(
fieldFlags
,
Kind
.
Field
);
}
private
static
final
int
[]
methodModifiers
=
{
...
...
@@ -143,18 +143,18 @@ public class AccessFlags {
};
public
Set
<
String
>
getMethodModifiers
()
{
return
getModifiers
(
methodModifiers
,
Type
.
Method
);
return
getModifiers
(
methodModifiers
,
Kind
.
Method
);
}
public
Set
<
String
>
getMethodFlags
()
{
return
getFlags
(
methodFlags
,
Type
.
Method
);
return
getFlags
(
methodFlags
,
Kind
.
Method
);
}
private
Set
<
String
>
getModifiers
(
int
[]
modifierFlags
,
Type
t
)
{
private
Set
<
String
>
getModifiers
(
int
[]
modifierFlags
,
Kind
t
)
{
return
getModifiers
(
flags
,
modifierFlags
,
t
);
}
private
static
Set
<
String
>
getModifiers
(
int
flags
,
int
[]
modifierFlags
,
Type
t
)
{
private
static
Set
<
String
>
getModifiers
(
int
flags
,
int
[]
modifierFlags
,
Kind
t
)
{
Set
<
String
>
s
=
new
LinkedHashSet
<
String
>();
for
(
int
m:
modifierFlags
)
{
if
((
flags
&
m
)
!=
0
)
...
...
@@ -163,7 +163,7 @@ public class AccessFlags {
return
s
;
}
private
Set
<
String
>
getFlags
(
int
[]
expectedFlags
,
Type
t
)
{
private
Set
<
String
>
getFlags
(
int
[]
expectedFlags
,
Kind
t
)
{
Set
<
String
>
s
=
new
LinkedHashSet
<
String
>();
int
f
=
flags
;
for
(
int
e:
expectedFlags
)
{
...
...
@@ -180,7 +180,7 @@ public class AccessFlags {
return
s
;
}
private
static
String
flagToModifier
(
int
flag
,
Type
t
)
{
private
static
String
flagToModifier
(
int
flag
,
Kind
t
)
{
switch
(
flag
)
{
case
ACC_PUBLIC:
return
"public"
;
...
...
@@ -195,7 +195,7 @@ public class AccessFlags {
case
ACC_SYNCHRONIZED:
return
"synchronized"
;
case
0x80
:
return
(
t
==
Type
.
Field
?
"transient"
:
null
);
return
(
t
==
Kind
.
Field
?
"transient"
:
null
);
case
ACC_VOLATILE:
return
"volatile"
;
case
ACC_NATIVE:
...
...
@@ -211,7 +211,7 @@ public class AccessFlags {
}
}
private
static
String
flagToName
(
int
flag
,
Type
t
)
{
private
static
String
flagToName
(
int
flag
,
Kind
t
)
{
switch
(
flag
)
{
case
ACC_PUBLIC:
return
"ACC_PUBLIC"
;
...
...
@@ -224,11 +224,11 @@ public class AccessFlags {
case
ACC_FINAL:
return
"ACC_FINAL"
;
case
0x20
:
return
(
t
==
Type
.
Class
?
"ACC_SUPER"
:
"ACC_SYNCHRONIZED"
);
return
(
t
==
Kind
.
Class
?
"ACC_SUPER"
:
"ACC_SYNCHRONIZED"
);
case
0x40
:
return
(
t
==
Type
.
Field
?
"ACC_VOLATILE"
:
"ACC_BRIDGE"
);
return
(
t
==
Kind
.
Field
?
"ACC_VOLATILE"
:
"ACC_BRIDGE"
);
case
0x80
:
return
(
t
==
Type
.
Field
?
"ACC_TRANSIENT"
:
"ACC_VARARGS"
);
return
(
t
==
Kind
.
Field
?
"ACC_TRANSIENT"
:
"ACC_VARARGS"
);
case
ACC_NATIVE:
return
"ACC_NATIVE"
;
case
ACC_INTERFACE:
...
...
@@ -250,5 +250,5 @@ public class AccessFlags {
}
}
final
int
flags
;
public
final
int
flags
;
}
src/share/classes/com/sun/tools/classfile/ConstantPool.java
浏览文件 @
caa32efb
...
...
@@ -573,6 +573,11 @@ public class ConstantPool {
return
visitor
.
visitNameAndType
(
this
,
data
);
}
@Override
public
String
toString
()
{
return
"CONSTANT_NameAndType_info[name_index: "
+
name_index
+
", type_index: "
+
type_index
+
"]"
;
}
public
final
int
name_index
;
public
final
int
type_index
;
}
...
...
@@ -600,6 +605,11 @@ public class ConstantPool {
return
visitor
.
visitString
(
this
,
data
);
}
@Override
public
String
toString
()
{
return
"CONSTANT_String_info[class_index: "
+
string_index
+
"]"
;
}
public
final
int
string_index
;
}
...
...
@@ -618,7 +628,19 @@ public class ConstantPool {
@Override
public
String
toString
()
{
return
"CONSTANT_Utf8_info[value: "
+
value
+
"]"
;
if
(
value
.
length
()
<
32
&&
isPrintableAscii
(
value
))
return
"CONSTANT_Utf8_info[value: \""
+
value
+
"\"]"
;
else
return
"CONSTANT_Utf8_info[value: ("
+
value
.
length
()
+
" chars)]"
;
}
static
boolean
isPrintableAscii
(
String
s
)
{
for
(
int
i
=
0
;
i
<
s
.
length
();
i
++)
{
char
c
=
s
.
charAt
(
i
);
if
(
c
<
32
||
c
>=
127
)
return
false
;
}
return
true
;
}
public
<
R
,
D
>
R
accept
(
Visitor
<
R
,
D
>
visitor
,
D
data
)
{
...
...
src/share/classes/com/sun/tools/javap/AttributeWriter.java
浏览文件 @
caa32efb
...
...
@@ -74,7 +74,7 @@ import static com.sun.tools.classfile.AccessFlags.*;
public
class
AttributeWriter
extends
BasicWriter
implements
Attribute
.
Visitor
<
Void
,
Void
>
{
static
AttributeWriter
instance
(
Context
context
)
{
public
static
AttributeWriter
instance
(
Context
context
)
{
AttributeWriter
instance
=
context
.
get
(
AttributeWriter
.
class
);
if
(
instance
==
null
)
instance
=
new
AttributeWriter
(
context
);
...
...
src/share/classes/com/sun/tools/javap/ClassWriter.java
浏览文件 @
caa32efb
...
...
@@ -93,17 +93,25 @@ public class ClassWriter extends BasicWriter {
this
.
lastModified
=
lastModified
;
}
ClassFile
getClassFile
()
{
protected
ClassFile
getClassFile
()
{
return
classFile
;
}
Method
getMethod
()
{
protected
void
setClassFile
(
ClassFile
cf
)
{
classFile
=
cf
;
constant_pool
=
classFile
.
constant_pool
;
}
protected
Method
getMethod
()
{
return
method
;
}
protected
void
setMethod
(
Method
m
)
{
method
=
m
;
}
public
void
write
(
ClassFile
cf
)
{
classFile
=
cf
;
constant_pool
=
classFile
.
constant_pool
;
setClassFile
(
cf
);
if
((
options
.
sysInfo
||
options
.
verbose
)
&&
!
options
.
compat
)
{
if
(
uri
!=
null
)
{
...
...
@@ -197,13 +205,13 @@ public class ClassWriter extends BasicWriter {
println
();
}
void
writeFields
()
{
protected
void
writeFields
()
{
for
(
Field
f:
classFile
.
fields
)
{
writeField
(
f
);
}
}
void
writeField
(
Field
f
)
{
protected
void
writeField
(
Field
f
)
{
if
(!
options
.
checkAccess
(
f
.
access_flags
))
return
;
...
...
@@ -259,12 +267,12 @@ public class ClassWriter extends BasicWriter {
println
();
}
void
writeMethods
()
{
protected
void
writeMethods
()
{
for
(
Method
m:
classFile
.
methods
)
writeMethod
(
m
);
}
void
writeMethod
(
Method
m
)
{
protected
void
writeMethod
(
Method
m
)
{
if
(!
options
.
checkAccess
(
m
.
access_flags
))
return
;
...
...
src/share/classes/com/sun/tools/javap/ConstantWriter.java
浏览文件 @
caa32efb
...
...
@@ -40,7 +40,7 @@ import static com.sun.tools.classfile.ConstantPool.*;
* deletion without notice.</b>
*/
public
class
ConstantWriter
extends
BasicWriter
{
static
ConstantWriter
instance
(
Context
context
)
{
public
static
ConstantWriter
instance
(
Context
context
)
{
ConstantWriter
instance
=
context
.
get
(
ConstantWriter
.
class
);
if
(
instance
==
null
)
instance
=
new
ConstantWriter
(
context
);
...
...
@@ -54,7 +54,12 @@ public class ConstantWriter extends BasicWriter {
options
=
Options
.
instance
(
context
);
}
void
writeConstantPool
()
{
protected
void
writeConstantPool
()
{
ConstantPool
constant_pool
=
classWriter
.
getClassFile
().
constant_pool
;
writeConstantPool
(
constant_pool
);
}
protected
void
writeConstantPool
(
ConstantPool
constant_pool
)
{
ConstantPool
.
Visitor
<
Integer
,
Void
>
v
=
new
ConstantPool
.
Visitor
<
Integer
,
Void
>()
{
public
Integer
visitClass
(
CONSTANT_Class_info
info
,
Void
p
)
{
println
(
"#"
+
info
.
name_index
+
";\t// "
+
stringValue
(
info
));
...
...
@@ -114,7 +119,6 @@ public class ConstantWriter extends BasicWriter {
};
println
(
" Constant pool:"
);
ConstantPool
constant_pool
=
classWriter
.
getClassFile
().
constant_pool
;
int
cpx
=
1
;
while
(
cpx
<
constant_pool
.
size
())
{
try
{
...
...
@@ -127,7 +131,7 @@ public class ConstantWriter extends BasicWriter {
}
}
void
write
(
int
cpx
)
{
protected
void
write
(
int
cpx
)
{
ClassFile
classFile
=
classWriter
.
getClassFile
();
if
(
cpx
==
0
)
{
print
(
"#0"
);
...
...
src/share/classes/com/sun/tools/javap/JavapTask.java
浏览文件 @
caa32efb
...
...
@@ -36,6 +36,7 @@ import java.io.StringWriter;
import
java.io.Writer
;
import
java.security.DigestInputStream
;
import
java.security.MessageDigest
;
import
java.security.NoSuchAlgorithmException
;
import
java.text.MessageFormat
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
...
...
@@ -298,21 +299,28 @@ public class JavapTask implements DisassemblerTool.DisassemblerTask, Messages {
};
JavapTask
()
{
public
JavapTask
()
{
context
=
new
Context
();
context
.
put
(
Messages
.
class
,
this
);
options
=
Options
.
instance
(
context
);
attributeFactory
=
new
Attribute
.
Factory
();
}
JavapTask
(
Writer
out
,
public
JavapTask
(
Writer
out
,
JavaFileManager
fileManager
,
DiagnosticListener
<?
super
JavaFileObject
>
diagnosticListener
,
Iterable
<
String
>
options
,
Iterable
<
String
>
classes
)
{
DiagnosticListener
<?
super
JavaFileObject
>
diagnosticListener
)
{
this
();
this
.
log
=
getPrintWriterForWriter
(
out
);
this
.
fileManager
=
fileManager
;
this
.
diagnosticListener
=
diagnosticListener
;
}
public
JavapTask
(
Writer
out
,
JavaFileManager
fileManager
,
DiagnosticListener
<?
super
JavaFileObject
>
diagnosticListener
,
Iterable
<
String
>
options
,
Iterable
<
String
>
classes
)
{
this
(
out
,
fileManager
,
diagnosticListener
);
try
{
handleOptions
(
options
,
false
);
...
...
@@ -553,29 +561,10 @@ public class JavapTask implements DisassemblerTool.DisassemblerTask, Messages {
continue
;
}
}
Attribute
.
Factory
attributeFactory
=
new
Attribute
.
Factory
();
attributeFactory
.
setCompat
(
options
.
compat
);
attributeFactory
.
setJSR277
(
options
.
jsr277
);
InputStream
in
=
fo
.
openInputStream
();
SizeInputStream
sizeIn
=
null
;
MessageDigest
md
=
null
;
if
(
options
.
sysInfo
||
options
.
verbose
)
{
md
=
MessageDigest
.
getInstance
(
"MD5"
);
in
=
new
DigestInputStream
(
in
,
md
);
in
=
sizeIn
=
new
SizeInputStream
(
in
);
}
ClassFile
cf
=
ClassFile
.
read
(
in
,
attributeFactory
);
if
(
options
.
sysInfo
||
options
.
verbose
)
{
classWriter
.
setFile
(
fo
.
toUri
());
classWriter
.
setLastModified
(
fo
.
getLastModified
());
classWriter
.
setDigest
(
"MD5"
,
md
.
digest
());
classWriter
.
setFileSize
(
sizeIn
.
size
());
}
classWriter
.
write
(
cf
);
write
(
read
(
fo
));
}
catch
(
ConstantPoolException
e
)
{
diagnosticListener
.
report
(
createDiagnostic
(
"err.bad.constant.pool"
,
className
,
e
.
getLocalizedMessage
()));
...
...
@@ -606,6 +595,103 @@ public class JavapTask implements DisassemblerTool.DisassemblerTask, Messages {
return
ok
;
}
public
static
class
ClassFileInfo
{
ClassFileInfo
(
JavaFileObject
fo
,
ClassFile
cf
,
byte
[]
digest
,
int
size
)
{
this
.
fo
=
fo
;
this
.
cf
=
cf
;
this
.
digest
=
digest
;
this
.
size
=
size
;
}
public
final
JavaFileObject
fo
;
public
final
ClassFile
cf
;
public
final
byte
[]
digest
;
public
final
int
size
;
}
public
ClassFileInfo
read
(
JavaFileObject
fo
)
throws
IOException
,
ConstantPoolException
{
InputStream
in
=
fo
.
openInputStream
();
try
{
SizeInputStream
sizeIn
=
null
;
MessageDigest
md
=
null
;
if
(
options
.
sysInfo
||
options
.
verbose
)
{
try
{
md
=
MessageDigest
.
getInstance
(
"MD5"
);
}
catch
(
NoSuchAlgorithmException
ignore
)
{
}
in
=
new
DigestInputStream
(
in
,
md
);
in
=
sizeIn
=
new
SizeInputStream
(
in
);
}
ClassFile
cf
=
ClassFile
.
read
(
in
,
attributeFactory
);
byte
[]
digest
=
(
md
==
null
)
?
null
:
md
.
digest
();
int
size
=
(
sizeIn
==
null
)
?
-
1
:
sizeIn
.
size
();
return
new
ClassFileInfo
(
fo
,
cf
,
digest
,
size
);
}
finally
{
in
.
close
();
}
}
public
void
write
(
ClassFileInfo
info
)
{
ClassWriter
classWriter
=
ClassWriter
.
instance
(
context
);
if
(
options
.
sysInfo
||
options
.
verbose
)
{
classWriter
.
setFile
(
info
.
fo
.
toUri
());
classWriter
.
setLastModified
(
info
.
fo
.
getLastModified
());
classWriter
.
setDigest
(
"MD5"
,
info
.
digest
);
classWriter
.
setFileSize
(
info
.
size
);
}
classWriter
.
write
(
info
.
cf
);
}
protected
void
setClassFile
(
ClassFile
classFile
)
{
ClassWriter
classWriter
=
ClassWriter
.
instance
(
context
);
classWriter
.
setClassFile
(
classFile
);
}
protected
void
setMethod
(
Method
enclosingMethod
)
{
ClassWriter
classWriter
=
ClassWriter
.
instance
(
context
);
classWriter
.
setMethod
(
enclosingMethod
);
}
protected
void
write
(
Attribute
value
)
{
AttributeWriter
attrWriter
=
AttributeWriter
.
instance
(
context
);
ClassWriter
classWriter
=
ClassWriter
.
instance
(
context
);
ClassFile
cf
=
classWriter
.
getClassFile
();
attrWriter
.
write
(
cf
,
value
,
cf
.
constant_pool
);
}
protected
void
write
(
Attributes
attrs
)
{
AttributeWriter
attrWriter
=
AttributeWriter
.
instance
(
context
);
ClassWriter
classWriter
=
ClassWriter
.
instance
(
context
);
ClassFile
cf
=
classWriter
.
getClassFile
();
attrWriter
.
write
(
cf
,
attrs
,
cf
.
constant_pool
);
}
protected
void
write
(
ConstantPool
constant_pool
)
{
ConstantWriter
constantWriter
=
ConstantWriter
.
instance
(
context
);
constantWriter
.
writeConstantPool
(
constant_pool
);
}
protected
void
write
(
ConstantPool
constant_pool
,
int
value
)
{
ConstantWriter
constantWriter
=
ConstantWriter
.
instance
(
context
);
constantWriter
.
write
(
value
);
}
protected
void
write
(
ConstantPool
.
CPInfo
value
)
{
ConstantWriter
constantWriter
=
ConstantWriter
.
instance
(
context
);
constantWriter
.
println
(
value
);
}
protected
void
write
(
Field
value
)
{
ClassWriter
classWriter
=
ClassWriter
.
instance
(
context
);
classWriter
.
writeField
(
value
);
}
protected
void
write
(
Method
value
)
{
ClassWriter
classWriter
=
ClassWriter
.
instance
(
context
);
classWriter
.
writeMethod
(
value
);
}
private
JavaFileManager
getDefaultFileManager
(
final
DiagnosticListener
<?
super
JavaFileObject
>
dl
,
PrintWriter
log
)
{
return
JavapFileManager
.
create
(
dl
,
log
,
options
);
}
...
...
@@ -735,7 +821,7 @@ public class JavapTask implements DisassemblerTool.DisassemblerTask, Messages {
}
}
Context
context
;
protected
Context
context
;
JavaFileManager
fileManager
;
PrintWriter
log
;
DiagnosticListener
<?
super
JavaFileObject
>
diagnosticListener
;
...
...
@@ -744,6 +830,7 @@ public class JavapTask implements DisassemblerTool.DisassemblerTask, Messages {
//ResourceBundle bundle;
Locale
task_locale
;
Map
<
Locale
,
ResourceBundle
>
bundles
;
protected
Attribute
.
Factory
attributeFactory
;
private
static
final
String
progname
=
"javap"
;
...
...
src/share/classes/com/sun/tools/javap/SourceWriter.java
浏览文件 @
caa32efb
...
...
@@ -134,6 +134,9 @@ public class SourceWriter extends InstructionDetailWriter {
}
private
String
readSource
(
ClassFile
cf
)
{
if
(
fileManager
==
null
)
return
null
;
Location
location
;
if
(
fileManager
.
hasLocation
((
StandardLocation
.
SOURCE_PATH
)))
location
=
StandardLocation
.
SOURCE_PATH
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录