Tue, 03 Jun 2008 13:26:47 -0700
4075303: Use javap to enquire aboput a specific inner class
4348375: Javap is not internationalized
4459541: "javap -l" shows line numbers as signed short; they should be unsigned
4501660: change diagnostic of -help as 'print this help message and exit'
4776241: unused source file in javap...
4870651: javap should recognize generics, varargs, enum
4876942: javap invoked without args does not print help screen
4880663: javap could output whitespace between class name and opening brace
4975569: javap doesn't print new flag bits
6271787: javap dumps LocalVariableTypeTable attribute in hex, needs to print a table
6305779: javap: support annotations
6439940: Clean up javap implementation
6469569: wrong check of searchpath in JavapEnvironment
6474890: javap does not open .zip files in -classpath
6587786: Javap throws error : "ERROR:Could not find <classname>" for JRE classes
6622215: javap ignores certain relevant access flags
6622216: javap names some attributes incorrectly
6622232: javap gets whitespace confused
6622260: javap prints negative bytes incorrectly in hex
Reviewed-by: ksrini
1.1 --- a/make/build.properties Fri May 30 11:08:40 2008 +0100 1.2 +++ b/make/build.properties Tue Jun 03 13:26:47 2008 -0700 1.3 @@ -66,7 +66,7 @@ 1.4 # set the following to -version to verify the versions of javac being used 1.5 javac.version.opt = 1.6 # in time, there should be no exceptions to -Xlint:all 1.7 -javac.lint.opts = -Xlint:all,-unchecked,-deprecation,-fallthrough,-cast,-serial -Werror 1.8 +javac.lint.opts = -Xlint:all,-deprecation,-fallthrough,-serial -Werror 1.9 1.10 # options for the <javadoc> task for javac 1.11 javadoc.jls3.url=http://java.sun.com/docs/books/jls/ 1.12 @@ -120,6 +120,8 @@ 1.13 tools/javah/ 1.14 1.15 javap.includes = \ 1.16 + com/sun/tools/classfile/ \ 1.17 + com/sun/tools/javap/ \ 1.18 sun/tools/javap/ 1.19 1.20 javap.tests = \
2.1 --- a/make/build.xml Fri May 30 11:08:40 2008 +0100 2.2 +++ b/make/build.xml Tue Jun 03 13:26:47 2008 -0700 2.3 @@ -136,7 +136,7 @@ 2.4 <arg value="-html:${findbugs.home}/src/xsl/fancy.xsl"/> 2.5 <arg value="${dist.findbugs.dir}/findbugs.xml"/> 2.6 <redirector output="${dist.findbugs.dir}/findbugs.html"/> 2.7 - </exec> 2.8 + </exec> 2.9 </target> 2.10 2.11 <target name="coverage" depends="-def-cobertura,build-all-classes,instrument-classes,jtreg,coverage-report"/> 2.12 @@ -301,14 +301,15 @@ 2.13 jarmainclass="sun.tools.javap.Main"/> 2.14 </target> 2.15 2.16 - <target name="build-classes-javap" depends="build-bootstrap-javac"> 2.17 + <target name="build-classes-javap" depends="build-classes-javac"> 2.18 <build-classes name="javap" includes="${javap.includes}"/> 2.19 </target> 2.20 2.21 - <target name="build-javap" depends="build-bootstrap-javac"> 2.22 + <target name="build-javap" depends="build-javac"> 2.23 <build-tool name="javap" 2.24 includes="${javap.includes}" 2.25 - jarmainclass="sun.tools.javap.Main"/> 2.26 + jarmainclass="sun.tools.javap.Main" 2.27 + jarclasspath="javac.jar"/> 2.28 </target> 2.29 2.30 <!-- (no javadoc for javap) --> 2.31 @@ -480,7 +481,7 @@ 2.32 destdir="@{gensrc.dir}" 2.33 includes="@{includes}"/> 2.34 <copy todir="@{gensrc.dir}"> 2.35 - <fileset dir="${src.classes.dir}" includes="${javac.includes}"/> 2.36 + <fileset dir="${src.classes.dir}" includes="@{includes}"/> 2.37 <globmapper from="*.properties-template" to="*.properties"/> 2.38 <filterset begintoken="$(" endtoken=")"> 2.39 <filter token="JDK_VERSION" value="${jdk.version}"/>
3.1 --- a/make/netbeans/common/standard-ide-actions-no-javadoc.ent Fri May 30 11:08:40 2008 +0100 3.2 +++ b/make/netbeans/common/standard-ide-actions-no-javadoc.ent Tue Jun 03 13:26:47 2008 -0700 3.3 @@ -157,5 +157,5 @@ 3.4 </action> 3.5 3.6 <action name="javadoc"> 3.7 - <target>javadoc-nb</target> 3.8 + <target>-javadoc-nb</target> 3.9 </action>
4.1 --- a/make/netbeans/common/standard-ide-actions.ent Fri May 30 11:08:40 2008 +0100 4.2 +++ b/make/netbeans/common/standard-ide-actions.ent Tue Jun 03 13:26:47 2008 -0700 4.3 @@ -157,5 +157,5 @@ 4.4 </action> 4.5 4.6 <action name="javadoc"> 4.7 - <target>javadoc-nb</target> 4.8 + <target>-javadoc-nb</target> 4.9 </action>
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 5.2 +++ b/src/share/classes/com/sun/tools/classfile/AccessFlags.java Tue Jun 03 13:26:47 2008 -0700 5.3 @@ -0,0 +1,254 @@ 5.4 +/* 5.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. 5.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5.7 + * 5.8 + * This code is free software; you can redistribute it and/or modify it 5.9 + * under the terms of the GNU General Public License version 2 only, as 5.10 + * published by the Free Software Foundation. Sun designates this 5.11 + * particular file as subject to the "Classpath" exception as provided 5.12 + * by Sun in the LICENSE file that accompanied this code. 5.13 + * 5.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 5.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 5.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 5.17 + * version 2 for more details (a copy is included in the LICENSE file that 5.18 + * accompanied this code). 5.19 + * 5.20 + * You should have received a copy of the GNU General Public License version 5.21 + * 2 along with this work; if not, write to the Free Software Foundation, 5.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 5.23 + * 5.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 5.25 + * CA 95054 USA or visit www.sun.com if you need additional information or 5.26 + * have any questions. 5.27 + */ 5.28 + 5.29 +package com.sun.tools.classfile; 5.30 + 5.31 +import java.io.IOException; 5.32 +import java.util.LinkedHashSet; 5.33 +import java.util.Set; 5.34 + 5.35 +/** 5.36 + * See JVMS3, sections 4.2, 4.6, 4.7. 5.37 + * 5.38 + * <p><b>This is NOT part of any API supported by Sun Microsystems. If 5.39 + * you write code that depends on this, you do so at your own risk. 5.40 + * This code and its internal interfaces are subject to change or 5.41 + * deletion without notice.</b> 5.42 + */ 5.43 +public class AccessFlags { 5.44 + public static final int ACC_PUBLIC = 0x0001; // class, inner, field, method 5.45 + public static final int ACC_PRIVATE = 0x0002; // inner, field, method 5.46 + public static final int ACC_PROTECTED = 0x0004; // inner, field, method 5.47 + public static final int ACC_STATIC = 0x0008; // inner, field, method 5.48 + public static final int ACC_FINAL = 0x0010; // class, inner, field, method 5.49 + public static final int ACC_SUPER = 0x0020; // class 5.50 + public static final int ACC_SYNCHRONIZED = 0x0020; // method 5.51 + public static final int ACC_VOLATILE = 0x0040; // field 5.52 + public static final int ACC_BRIDGE = 0x0040; // method 5.53 + public static final int ACC_TRANSIENT = 0x0080; // field 5.54 + public static final int ACC_VARARGS = 0x0080; // method 5.55 + public static final int ACC_NATIVE = 0x0100; // method 5.56 + public static final int ACC_INTERFACE = 0x0200; // class, inner 5.57 + public static final int ACC_ABSTRACT = 0x0400; // class, inner, method 5.58 + public static final int ACC_STRICT = 0x0800; // method 5.59 + public static final int ACC_SYNTHETIC = 0x1000; // class, inner, field, method 5.60 + public static final int ACC_ANNOTATION = 0x2000; // class, inner 5.61 + public static final int ACC_ENUM = 0x4000; // class, inner, field 5.62 + public static final int ACC_MODULE = 0x8000; // class, inner, field, method 5.63 + 5.64 + private static enum Type { Class, InnerClass, Field, Method}; 5.65 + 5.66 + AccessFlags(ClassReader cr) throws IOException { 5.67 + this(cr.readUnsignedShort()); 5.68 + } 5.69 + 5.70 + public AccessFlags(int flags) { 5.71 + this.flags = flags; 5.72 + } 5.73 + 5.74 + public AccessFlags ignore(int mask) { 5.75 + return new AccessFlags(flags & ~mask); 5.76 + } 5.77 + 5.78 + public boolean is(int mask) { 5.79 + return (flags & mask) != 0; 5.80 + } 5.81 + 5.82 + private static final int[] classModifiers = { 5.83 + ACC_PUBLIC, ACC_FINAL, ACC_ABSTRACT, ACC_MODULE 5.84 + }; 5.85 + 5.86 + private static final int[] classFlags = { 5.87 + ACC_PUBLIC, ACC_FINAL, ACC_SUPER, ACC_INTERFACE, ACC_ABSTRACT, 5.88 + ACC_SYNTHETIC, ACC_ANNOTATION, ACC_ENUM, ACC_MODULE 5.89 + }; 5.90 + 5.91 + public Set<String> getClassModifiers() { 5.92 + int f = ((flags & ACC_INTERFACE) != 0 ? flags & ~ACC_ABSTRACT : flags); 5.93 + return getModifiers(f, classModifiers, Type.Class); 5.94 + } 5.95 + 5.96 + public Set<String> getClassFlags() { 5.97 + return getFlags(classFlags, Type.Class); 5.98 + } 5.99 + 5.100 + private static final int[] innerClassModifiers = { 5.101 + ACC_PUBLIC, ACC_PRIVATE, ACC_PROTECTED, ACC_STATIC, ACC_FINAL, 5.102 + ACC_ABSTRACT, ACC_MODULE 5.103 + }; 5.104 + 5.105 + private static final int[] innerClassFlags = { 5.106 + ACC_PUBLIC, ACC_PRIVATE, ACC_PROTECTED, ACC_STATIC, ACC_FINAL, ACC_SUPER, 5.107 + ACC_INTERFACE, ACC_ABSTRACT, ACC_SYNTHETIC, ACC_ANNOTATION, ACC_ENUM, ACC_MODULE 5.108 + }; 5.109 + 5.110 + public Set<String> getInnerClassModifiers() { 5.111 + int f = ((flags & ACC_INTERFACE) != 0 ? flags & ~ACC_ABSTRACT : flags); 5.112 + return getModifiers(f, innerClassModifiers, Type.InnerClass); 5.113 + } 5.114 + 5.115 + public Set<String> getInnerClassFlags() { 5.116 + return getFlags(innerClassFlags, Type.InnerClass); 5.117 + } 5.118 + 5.119 + private static final int[] fieldModifiers = { 5.120 + ACC_PUBLIC, ACC_PRIVATE, ACC_PROTECTED, ACC_STATIC, ACC_FINAL, 5.121 + ACC_VOLATILE, ACC_TRANSIENT, ACC_MODULE 5.122 + }; 5.123 + 5.124 + private static final int[] fieldFlags = { 5.125 + ACC_PUBLIC, ACC_PRIVATE, ACC_PROTECTED, ACC_STATIC, ACC_FINAL, 5.126 + ACC_VOLATILE, ACC_TRANSIENT, ACC_SYNTHETIC, ACC_ENUM, ACC_MODULE 5.127 + }; 5.128 + 5.129 + public Set<String> getFieldModifiers() { 5.130 + return getModifiers(fieldModifiers, Type.Field); 5.131 + } 5.132 + 5.133 + public Set<String> getFieldFlags() { 5.134 + return getFlags(fieldFlags, Type.Field); 5.135 + } 5.136 + 5.137 + private static final int[] methodModifiers = { 5.138 + ACC_PUBLIC, ACC_PRIVATE, ACC_PROTECTED, ACC_STATIC, ACC_FINAL, 5.139 + ACC_SYNCHRONIZED, ACC_NATIVE, ACC_ABSTRACT, ACC_STRICT, ACC_MODULE 5.140 + }; 5.141 + 5.142 + private static final int[] methodFlags = { 5.143 + ACC_PUBLIC, ACC_PRIVATE, ACC_PROTECTED, ACC_STATIC, ACC_FINAL, 5.144 + ACC_SYNCHRONIZED, ACC_BRIDGE, ACC_VARARGS, ACC_NATIVE, ACC_ABSTRACT, 5.145 + ACC_STRICT, ACC_SYNTHETIC, ACC_MODULE 5.146 + }; 5.147 + 5.148 + public Set<String> getMethodModifiers() { 5.149 + return getModifiers(methodModifiers, Type.Method); 5.150 + } 5.151 + 5.152 + public Set<String> getMethodFlags() { 5.153 + return getFlags(methodFlags, Type.Method); 5.154 + } 5.155 + 5.156 + private Set<String> getModifiers(int[] modifierFlags, Type t) { 5.157 + return getModifiers(flags, modifierFlags, t); 5.158 + } 5.159 + 5.160 + private static Set<String> getModifiers(int flags, int[] modifierFlags, Type t) { 5.161 + Set<String> s = new LinkedHashSet<String>(); 5.162 + for (int m: modifierFlags) { 5.163 + if ((flags & m) != 0) 5.164 + s.add(flagToModifier(m, t)); 5.165 + } 5.166 + return s; 5.167 + } 5.168 + 5.169 + private Set<String> getFlags(int[] expectedFlags, Type t) { 5.170 + Set<String> s = new LinkedHashSet<String>(); 5.171 + int f = flags; 5.172 + for (int e: expectedFlags) { 5.173 + if ((f & e) != 0) { 5.174 + s.add(flagToName(e, t)); 5.175 + f = f & ~e; 5.176 + } 5.177 + } 5.178 + while (f != 0) { 5.179 + int bit = Integer.highestOneBit(f); 5.180 + s.add("0x" + Integer.toHexString(bit)); 5.181 + f = f & ~bit; 5.182 + } 5.183 + return s; 5.184 + } 5.185 + 5.186 + private static String flagToModifier(int flag, Type t) { 5.187 + switch (flag) { 5.188 + case ACC_PUBLIC: 5.189 + return "public"; 5.190 + case ACC_PRIVATE: 5.191 + return "private"; 5.192 + case ACC_PROTECTED: 5.193 + return "protected"; 5.194 + case ACC_STATIC: 5.195 + return "static"; 5.196 + case ACC_FINAL: 5.197 + return "final"; 5.198 + case ACC_SYNCHRONIZED: 5.199 + return "synchronized"; 5.200 + case 0x80: 5.201 + return (t == Type.Field ? "transient" : null); 5.202 + case ACC_VOLATILE: 5.203 + return "volatile"; 5.204 + case ACC_NATIVE: 5.205 + return "native"; 5.206 + case ACC_ABSTRACT: 5.207 + return "abstract"; 5.208 + case ACC_STRICT: 5.209 + return "strictfp"; 5.210 + case ACC_MODULE: 5.211 + return "module"; 5.212 + default: 5.213 + return null; 5.214 + } 5.215 + } 5.216 + 5.217 + private static String flagToName(int flag, Type t) { 5.218 + switch (flag) { 5.219 + case ACC_PUBLIC: 5.220 + return "ACC_PUBLIC"; 5.221 + case ACC_PRIVATE: 5.222 + return "ACC_PRIVATE"; 5.223 + case ACC_PROTECTED: 5.224 + return "ACC_PROTECTED"; 5.225 + case ACC_STATIC: 5.226 + return "ACC_STATIC"; 5.227 + case ACC_FINAL: 5.228 + return "ACC_FINAL"; 5.229 + case 0x20: 5.230 + return (t == Type.Class ? "ACC_SUPER" : "ACC_SYNCHRONIZED"); 5.231 + case 0x40: 5.232 + return (t == Type.Field ? "ACC_VOLATILE" : "ACC_BRIDGE"); 5.233 + case 0x80: 5.234 + return (t == Type.Field ? "ACC_TRANSIENT" : "ACC_VARARGS"); 5.235 + case ACC_NATIVE: 5.236 + return "ACC_NATIVE"; 5.237 + case ACC_INTERFACE: 5.238 + return "ACC_INTERFACE"; 5.239 + case ACC_ABSTRACT: 5.240 + return "ACC_ABSTRACT"; 5.241 + case ACC_STRICT: 5.242 + return "ACC_STRICT"; 5.243 + case ACC_SYNTHETIC: 5.244 + return "ACC_SYNTHETIC"; 5.245 + case ACC_ANNOTATION: 5.246 + return "ACC_ANNOTATION"; 5.247 + case ACC_ENUM: 5.248 + return "ACC_ENUM"; 5.249 + case ACC_MODULE: 5.250 + return "ACC_MODULE"; 5.251 + default: 5.252 + return null; 5.253 + } 5.254 + } 5.255 + 5.256 + final int flags; 5.257 +}
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 6.2 +++ b/src/share/classes/com/sun/tools/classfile/Annotation.java Tue Jun 03 13:26:47 2008 -0700 6.3 @@ -0,0 +1,243 @@ 6.4 +/* 6.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. 6.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 6.7 + * 6.8 + * This code is free software; you can redistribute it and/or modify it 6.9 + * under the terms of the GNU General Public License version 2 only, as 6.10 + * published by the Free Software Foundation. Sun designates this 6.11 + * particular file as subject to the "Classpath" exception as provided 6.12 + * by Sun in the LICENSE file that accompanied this code. 6.13 + * 6.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 6.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 6.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 6.17 + * version 2 for more details (a copy is included in the LICENSE file that 6.18 + * accompanied this code). 6.19 + * 6.20 + * You should have received a copy of the GNU General Public License version 6.21 + * 2 along with this work; if not, write to the Free Software Foundation, 6.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 6.23 + * 6.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 6.25 + * CA 95054 USA or visit www.sun.com if you need additional information or 6.26 + * have any questions. 6.27 + */ 6.28 + 6.29 +package com.sun.tools.classfile; 6.30 + 6.31 +import java.io.IOException; 6.32 + 6.33 +/** 6.34 + * See JVMS3, section 4.8.16. 6.35 + * 6.36 + * <p><b>This is NOT part of any API supported by Sun Microsystems. If 6.37 + * you write code that depends on this, you do so at your own risk. 6.38 + * This code and its internal interfaces are subject to change or 6.39 + * deletion without notice.</b> 6.40 + */ 6.41 +public class Annotation { 6.42 + static class InvalidAnnotation extends AttributeException { 6.43 + InvalidAnnotation(String msg) { 6.44 + super(msg); 6.45 + } 6.46 + } 6.47 + 6.48 + Annotation(ClassReader cr) throws IOException, InvalidAnnotation { 6.49 + type_index = cr.readUnsignedShort(); 6.50 + num_element_value_pairs = cr.readUnsignedShort(); 6.51 + element_value_pairs = new element_value_pair[num_element_value_pairs]; 6.52 + for (int i = 0; i < element_value_pairs.length; i++) 6.53 + element_value_pairs[i] = new element_value_pair(cr); 6.54 + } 6.55 + 6.56 + public Annotation(ConstantPool constant_pool, 6.57 + int type_index, 6.58 + element_value_pair[] element_value_pairs) { 6.59 + this.type_index = type_index; 6.60 + num_element_value_pairs = element_value_pairs.length; 6.61 + this.element_value_pairs = element_value_pairs; 6.62 + } 6.63 + 6.64 + public int length() { 6.65 + int n = 2 /*type_index*/ + 2 /*num_element_value_pairs*/; 6.66 + for (element_value_pair pair: element_value_pairs) 6.67 + n += pair.length(); 6.68 + return n; 6.69 + } 6.70 + 6.71 + public final int type_index; 6.72 + public final int num_element_value_pairs; 6.73 + public final element_value_pair element_value_pairs[]; 6.74 + 6.75 + /** 6.76 + * See JVMS3, section 4.8.16.1. 6.77 + */ 6.78 + public static abstract class element_value { 6.79 + public static element_value read(ClassReader cr) 6.80 + throws IOException, InvalidAnnotation { 6.81 + int tag = cr.readUnsignedByte(); 6.82 + switch (tag) { 6.83 + case 'B': 6.84 + case 'C': 6.85 + case 'D': 6.86 + case 'F': 6.87 + case 'I': 6.88 + case 'J': 6.89 + case 'S': 6.90 + case 'Z': 6.91 + case 's': 6.92 + return new Primitive_element_value(cr, tag); 6.93 + 6.94 + case 'e': 6.95 + return new Enum_element_value(cr, tag); 6.96 + 6.97 + case 'c': 6.98 + return new Class_element_value(cr, tag); 6.99 + 6.100 + case '@': 6.101 + return new Annotation_element_value(cr, tag); 6.102 + 6.103 + case '[': 6.104 + return new Array_element_value(cr, tag); 6.105 + 6.106 + default: 6.107 + throw new InvalidAnnotation("unrecognized tag: " + tag); 6.108 + } 6.109 + } 6.110 + 6.111 + protected element_value(int tag) { 6.112 + this.tag = tag; 6.113 + } 6.114 + 6.115 + public abstract int length(); 6.116 + 6.117 + public abstract <R,P> R accept(Visitor<R,P> visitor, P p); 6.118 + 6.119 + public interface Visitor<R,P> { 6.120 + R visitPrimitive(Primitive_element_value ev, P p); 6.121 + R visitEnum(Enum_element_value ev, P p); 6.122 + R visitClass(Class_element_value ev, P p); 6.123 + R visitAnnotation(Annotation_element_value ev, P p); 6.124 + R visitArray(Array_element_value ev, P p); 6.125 + } 6.126 + 6.127 + public final int tag; 6.128 + } 6.129 + 6.130 + public static class Primitive_element_value extends element_value { 6.131 + Primitive_element_value(ClassReader cr, int tag) throws IOException { 6.132 + super(tag); 6.133 + const_value_index = cr.readUnsignedShort(); 6.134 + } 6.135 + 6.136 + @Override 6.137 + public int length() { 6.138 + return 2; 6.139 + } 6.140 + 6.141 + public <R,P> R accept(Visitor<R,P> visitor, P p) { 6.142 + return visitor.visitPrimitive(this, p); 6.143 + } 6.144 + 6.145 + public final int const_value_index; 6.146 + 6.147 + } 6.148 + 6.149 + public static class Enum_element_value extends element_value { 6.150 + Enum_element_value(ClassReader cr, int tag) throws IOException { 6.151 + super(tag); 6.152 + type_name_index = cr.readUnsignedShort(); 6.153 + const_name_index = cr.readUnsignedShort(); 6.154 + } 6.155 + 6.156 + @Override 6.157 + public int length() { 6.158 + return 4; 6.159 + } 6.160 + 6.161 + public <R,P> R accept(Visitor<R,P> visitor, P p) { 6.162 + return visitor.visitEnum(this, p); 6.163 + } 6.164 + 6.165 + public final int type_name_index; 6.166 + public final int const_name_index; 6.167 + } 6.168 + 6.169 + public static class Class_element_value extends element_value { 6.170 + Class_element_value(ClassReader cr, int tag) throws IOException { 6.171 + super(tag); 6.172 + class_info_index = cr.readUnsignedShort(); 6.173 + } 6.174 + 6.175 + @Override 6.176 + public int length() { 6.177 + return 2; 6.178 + } 6.179 + 6.180 + public <R,P> R accept(Visitor<R,P> visitor, P p) { 6.181 + return visitor.visitClass(this, p); 6.182 + } 6.183 + 6.184 + public final int class_info_index; 6.185 + } 6.186 + 6.187 + public static class Annotation_element_value extends element_value { 6.188 + Annotation_element_value(ClassReader cr, int tag) 6.189 + throws IOException, InvalidAnnotation { 6.190 + super(tag); 6.191 + annotation_value = new Annotation(cr); 6.192 + } 6.193 + 6.194 + @Override 6.195 + public int length() { 6.196 + return annotation_value.length(); 6.197 + } 6.198 + 6.199 + public <R,P> R accept(Visitor<R,P> visitor, P p) { 6.200 + return visitor.visitAnnotation(this, p); 6.201 + } 6.202 + 6.203 + public final Annotation annotation_value; 6.204 + } 6.205 + 6.206 + public static class Array_element_value extends element_value { 6.207 + Array_element_value(ClassReader cr, int tag) 6.208 + throws IOException, InvalidAnnotation { 6.209 + super(tag); 6.210 + num_values = cr.readUnsignedShort(); 6.211 + values = new element_value[num_values]; 6.212 + for (int i = 0; i < values.length; i++) 6.213 + values[i] = element_value.read(cr); 6.214 + } 6.215 + 6.216 + @Override 6.217 + public int length() { 6.218 + int n = 2; 6.219 + for (int i = 0; i < values.length; i++) 6.220 + n += values[i].length(); 6.221 + return n; 6.222 + } 6.223 + 6.224 + public <R,P> R accept(Visitor<R,P> visitor, P p) { 6.225 + return visitor.visitArray(this, p); 6.226 + } 6.227 + 6.228 + public final int num_values; 6.229 + public final element_value[] values; 6.230 + } 6.231 + 6.232 + public static class element_value_pair { 6.233 + element_value_pair(ClassReader cr) 6.234 + throws IOException, InvalidAnnotation { 6.235 + element_name_index = cr.readUnsignedShort(); 6.236 + value = element_value.read(cr); 6.237 + } 6.238 + 6.239 + public int length() { 6.240 + return 2 + value.length(); 6.241 + } 6.242 + 6.243 + public final int element_name_index; 6.244 + public final element_value value; 6.245 + } 6.246 +}
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 7.2 +++ b/src/share/classes/com/sun/tools/classfile/AnnotationDefault_attribute.java Tue Jun 03 13:26:47 2008 -0700 7.3 @@ -0,0 +1,61 @@ 7.4 +/* 7.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. 7.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 7.7 + * 7.8 + * This code is free software; you can redistribute it and/or modify it 7.9 + * under the terms of the GNU General Public License version 2 only, as 7.10 + * published by the Free Software Foundation. Sun designates this 7.11 + * particular file as subject to the "Classpath" exception as provided 7.12 + * by Sun in the LICENSE file that accompanied this code. 7.13 + * 7.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 7.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 7.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 7.17 + * version 2 for more details (a copy is included in the LICENSE file that 7.18 + * accompanied this code). 7.19 + * 7.20 + * You should have received a copy of the GNU General Public License version 7.21 + * 2 along with this work; if not, write to the Free Software Foundation, 7.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 7.23 + * 7.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 7.25 + * CA 95054 USA or visit www.sun.com if you need additional information or 7.26 + * have any questions. 7.27 + */ 7.28 + 7.29 +package com.sun.tools.classfile; 7.30 + 7.31 +import java.io.IOException; 7.32 + 7.33 +/** 7.34 + * See JVMS3, section 4.8.15. 7.35 + * 7.36 + * <p><b>This is NOT part of any API supported by Sun Microsystems. If 7.37 + * you write code that depends on this, you do so at your own risk. 7.38 + * This code and its internal interfaces are subject to change or 7.39 + * deletion without notice.</b> 7.40 + */ 7.41 +public class AnnotationDefault_attribute extends Attribute { 7.42 + AnnotationDefault_attribute(ClassReader cr, int name_index, int length) 7.43 + throws IOException, Annotation.InvalidAnnotation { 7.44 + super(name_index, length); 7.45 + default_value = Annotation.element_value.read(cr); 7.46 + } 7.47 + 7.48 + public AnnotationDefault_attribute(ConstantPool constant_pool, Annotation.element_value default_value) 7.49 + throws ConstantPoolException { 7.50 + this(constant_pool.getUTF8Index(Attribute.AnnotationDefault), default_value); 7.51 + } 7.52 + 7.53 + public AnnotationDefault_attribute(int name_index, Annotation.element_value default_value) { 7.54 + super(name_index, default_value.length()); 7.55 + this.default_value = default_value; 7.56 + } 7.57 + 7.58 + public <R, D> R accept(Visitor<R, D> visitor, D data) { 7.59 + return visitor.visitAnnotationDefault(this, data); 7.60 + } 7.61 + 7.62 + public final Annotation.element_value default_value; 7.63 +} 7.64 +
8.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 8.2 +++ b/src/share/classes/com/sun/tools/classfile/Attribute.java Tue Jun 03 13:26:47 2008 -0700 8.3 @@ -0,0 +1,199 @@ 8.4 +/* 8.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. 8.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 8.7 + * 8.8 + * This code is free software; you can redistribute it and/or modify it 8.9 + * under the terms of the GNU General Public License version 2 only, as 8.10 + * published by the Free Software Foundation. Sun designates this 8.11 + * particular file as subject to the "Classpath" exception as provided 8.12 + * by Sun in the LICENSE file that accompanied this code. 8.13 + * 8.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 8.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 8.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 8.17 + * version 2 for more details (a copy is included in the LICENSE file that 8.18 + * accompanied this code). 8.19 + * 8.20 + * You should have received a copy of the GNU General Public License version 8.21 + * 2 along with this work; if not, write to the Free Software Foundation, 8.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 8.23 + * 8.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 8.25 + * CA 95054 USA or visit www.sun.com if you need additional information or 8.26 + * have any questions. 8.27 + */ 8.28 + 8.29 +package com.sun.tools.classfile; 8.30 + 8.31 +import java.io.IOException; 8.32 +import java.lang.reflect.Constructor; 8.33 +import java.util.HashMap; 8.34 +import java.util.Map; 8.35 + 8.36 +/** 8.37 + * <p><b>This is NOT part of any API supported by Sun Microsystems. If 8.38 + * you write code that depends on this, you do so at your own risk. 8.39 + * This code and its internal interfaces are subject to change or 8.40 + * deletion without notice.</b> 8.41 + */ 8.42 + 8.43 +public abstract class Attribute { 8.44 + public static final String AnnotationDefault = "AnnotationDefault"; 8.45 + public static final String CharacterRangeTable = "CharacterRangeTable"; 8.46 + public static final String Code = "Code"; 8.47 + public static final String ConstantValue = "ConstantValue"; 8.48 + public static final String CompilationID = "CompilationID"; 8.49 + public static final String Deprecated = "Deprecated"; 8.50 + public static final String EnclosingMethod = "EnclosingMethod"; 8.51 + public static final String Exceptions = "Exceptions"; 8.52 + public static final String InnerClasses = "InnerClasses"; 8.53 + public static final String LineNumberTable = "LineNumberTable"; 8.54 + public static final String LocalVariableTable = "LocalVariableTable"; 8.55 + public static final String LocalVariableTypeTable = "LocalVariableTypeTable"; 8.56 + public static final String RuntimeVisibleAnnotations = "RuntimeVisibleAnnotations"; 8.57 + public static final String RuntimeInvisibleAnnotations = "RuntimeInvisibleAnnotations"; 8.58 + public static final String RuntimeVisibleParameterAnnotations = "RuntimeVisibleParameterAnnotations"; 8.59 + public static final String RuntimeInvisibleParameterAnnotations = "RuntimeInvisibleParameterAnnotations"; 8.60 + public static final String Signature = "Signature"; 8.61 + public static final String SourceDebugExtension = "SourceDebugExtension"; 8.62 + public static final String SourceFile = "SourceFile"; 8.63 + public static final String SourceID = "SourceID"; 8.64 + public static final String StackMap = "StackMap"; 8.65 + public static final String StackMapTable = "StackMapTable"; 8.66 + public static final String Synthetic = "Synthetic"; 8.67 + 8.68 + // JSR 277/294 8.69 + public static final String Module = "Module"; 8.70 + public static final String ModuleExportTable = "ModuleExportTable"; 8.71 + public static final String ModuleMemberTable = "ModuleMemberTable"; 8.72 + 8.73 + public static class Factory { 8.74 + public Factory() { 8.75 + // defer init of standardAttributeClasses until after options set up 8.76 + } 8.77 + 8.78 + public void setCompat(boolean compat) { 8.79 + this.compat = compat; 8.80 + } 8.81 + 8.82 + public void setJSR277(boolean jsr277) { 8.83 + this.jsr277 = jsr277; 8.84 + } 8.85 + 8.86 + public Attribute createAttribute(ClassReader cr, int name_index, byte[] data) 8.87 + throws IOException { 8.88 + if (standardAttributes == null) 8.89 + init(); 8.90 + 8.91 + ConstantPool cp = cr.getConstantPool(); 8.92 + try { 8.93 + String name = cp.getUTF8Value(name_index); 8.94 + Class<? extends Attribute> attrClass = standardAttributes.get(name); 8.95 + if (attrClass != null) { 8.96 + try { 8.97 + Class<?>[] constrArgTypes = {ClassReader.class, int.class, int.class}; 8.98 + Constructor<? extends Attribute> constr = attrClass.getDeclaredConstructor(constrArgTypes); 8.99 + return constr.newInstance(new Object[] { cr, name_index, data.length }); 8.100 + } catch (Throwable t) { 8.101 + // fall through and use DefaultAttribute 8.102 + // t.printStackTrace(); 8.103 + } 8.104 + } 8.105 + } catch (ConstantPoolException e) { 8.106 + // fall through and use DefaultAttribute 8.107 + } 8.108 + return new DefaultAttribute(cr, name_index, data); 8.109 + } 8.110 + 8.111 + protected void init() { 8.112 + standardAttributes = new HashMap<String,Class<? extends Attribute>>(); 8.113 + standardAttributes.put(AnnotationDefault, AnnotationDefault_attribute.class); 8.114 + standardAttributes.put(CharacterRangeTable, CharacterRangeTable_attribute.class); 8.115 + standardAttributes.put(Code, Code_attribute.class); 8.116 + standardAttributes.put(ConstantValue, ConstantValue_attribute.class); 8.117 + standardAttributes.put(Deprecated, Deprecated_attribute.class); 8.118 + standardAttributes.put(EnclosingMethod, EnclosingMethod_attribute.class); 8.119 + standardAttributes.put(Exceptions, Exceptions_attribute.class); 8.120 + standardAttributes.put(InnerClasses, InnerClasses_attribute.class); 8.121 + standardAttributes.put(LineNumberTable, LineNumberTable_attribute.class); 8.122 + standardAttributes.put(LocalVariableTable, LocalVariableTable_attribute.class); 8.123 + standardAttributes.put(LocalVariableTypeTable, LocalVariableTypeTable_attribute.class); 8.124 + 8.125 + if (jsr277) { 8.126 + standardAttributes.put(Module, Module_attribute.class); 8.127 + standardAttributes.put(ModuleExportTable, ModuleExportTable_attribute.class); 8.128 + standardAttributes.put(ModuleMemberTable, ModuleMemberTable_attribute.class); 8.129 + } 8.130 + 8.131 + if (!compat) { // old javap does not recognize recent attributes 8.132 + standardAttributes.put(CompilationID, CompilationID_attribute.class); 8.133 + standardAttributes.put(RuntimeInvisibleAnnotations, RuntimeInvisibleAnnotations_attribute.class); 8.134 + standardAttributes.put(RuntimeInvisibleParameterAnnotations, RuntimeInvisibleParameterAnnotations_attribute.class); 8.135 + standardAttributes.put(RuntimeVisibleAnnotations, RuntimeVisibleAnnotations_attribute.class); 8.136 + standardAttributes.put(RuntimeVisibleParameterAnnotations, RuntimeVisibleParameterAnnotations_attribute.class); 8.137 + standardAttributes.put(Signature, Signature_attribute.class); 8.138 + standardAttributes.put(SourceID, SourceID_attribute.class); 8.139 + } 8.140 + 8.141 + standardAttributes.put(SourceDebugExtension, SourceDebugExtension_attribute.class); 8.142 + standardAttributes.put(SourceFile, SourceFile_attribute.class); 8.143 + standardAttributes.put(StackMap, StackMap_attribute.class); 8.144 + standardAttributes.put(StackMapTable, StackMapTable_attribute.class); 8.145 + standardAttributes.put(Synthetic, Synthetic_attribute.class); 8.146 + } 8.147 + 8.148 + private Map<String,Class<? extends Attribute>> standardAttributes; 8.149 + private boolean compat; // don't support recent attrs in compatibility mode 8.150 + private boolean jsr277; // support new jsr277 attrs 8.151 + } 8.152 + 8.153 + public static Attribute read(ClassReader cr) throws IOException { 8.154 + return cr.readAttribute(); 8.155 + } 8.156 + 8.157 + protected Attribute(int name_index, int length) { 8.158 + attribute_name_index = name_index; 8.159 + attribute_length = length; 8.160 + } 8.161 + 8.162 + public String getName(ConstantPool constant_pool) throws ConstantPoolException { 8.163 + return constant_pool.getUTF8Value(attribute_name_index); 8.164 + } 8.165 + 8.166 + public abstract <R,D> R accept(Attribute.Visitor<R,D> visitor, D data); 8.167 + 8.168 + public final int attribute_name_index; 8.169 + public final int attribute_length; 8.170 + 8.171 + 8.172 + public interface Visitor<R,P> { 8.173 + R visitDefault(DefaultAttribute attr, P p); 8.174 + R visitAnnotationDefault(AnnotationDefault_attribute attr, P p); 8.175 + R visitCharacterRangeTable(CharacterRangeTable_attribute attr, P p); 8.176 + R visitCode(Code_attribute attr, P p); 8.177 + R visitCompilationID(CompilationID_attribute attr, P p); 8.178 + R visitConstantValue(ConstantValue_attribute attr, P p); 8.179 + R visitDeprecated(Deprecated_attribute attr, P p); 8.180 + R visitEnclosingMethod(EnclosingMethod_attribute attr, P p); 8.181 + R visitExceptions(Exceptions_attribute attr, P p); 8.182 + R visitInnerClasses(InnerClasses_attribute attr, P p); 8.183 + R visitLineNumberTable(LineNumberTable_attribute attr, P p); 8.184 + R visitLocalVariableTable(LocalVariableTable_attribute attr, P p); 8.185 + R visitLocalVariableTypeTable(LocalVariableTypeTable_attribute attr, P p); 8.186 + R visitRuntimeVisibleAnnotations(RuntimeVisibleAnnotations_attribute attr, P p); 8.187 + R visitRuntimeInvisibleAnnotations(RuntimeInvisibleAnnotations_attribute attr, P p); 8.188 + R visitRuntimeVisibleParameterAnnotations(RuntimeVisibleParameterAnnotations_attribute attr, P p); 8.189 + R visitRuntimeInvisibleParameterAnnotations(RuntimeInvisibleParameterAnnotations_attribute attr, P p); 8.190 + R visitSignature(Signature_attribute attr, P p); 8.191 + R visitSourceDebugExtension(SourceDebugExtension_attribute attr, P p); 8.192 + R visitSourceFile(SourceFile_attribute attr, P p); 8.193 + R visitSourceID(SourceID_attribute attr, P p); 8.194 + R visitStackMap(StackMap_attribute attr, P p); 8.195 + R visitStackMapTable(StackMapTable_attribute attr, P p); 8.196 + R visitSynthetic(Synthetic_attribute attr, P p); 8.197 + 8.198 + R visitModule(Module_attribute attr, P p); 8.199 + R visitModuleExportTable(ModuleExportTable_attribute attr, P p); 8.200 + R visitModuleMemberTable(ModuleMemberTable_attribute attr, P p); 8.201 + } 8.202 +}
9.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 9.2 +++ b/src/share/classes/com/sun/tools/classfile/AttributeException.java Tue Jun 03 13:26:47 2008 -0700 9.3 @@ -0,0 +1,40 @@ 9.4 +/* 9.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. 9.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 9.7 + * 9.8 + * This code is free software; you can redistribute it and/or modify it 9.9 + * under the terms of the GNU General Public License version 2 only, as 9.10 + * published by the Free Software Foundation. Sun designates this 9.11 + * particular file as subject to the "Classpath" exception as provided 9.12 + * by Sun in the LICENSE file that accompanied this code. 9.13 + * 9.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 9.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 9.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 9.17 + * version 2 for more details (a copy is included in the LICENSE file that 9.18 + * accompanied this code). 9.19 + * 9.20 + * You should have received a copy of the GNU General Public License version 9.21 + * 2 along with this work; if not, write to the Free Software Foundation, 9.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 9.23 + * 9.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 9.25 + * CA 95054 USA or visit www.sun.com if you need additional information or 9.26 + * have any questions. 9.27 + */ 9.28 + 9.29 +package com.sun.tools.classfile; 9.30 + 9.31 +/* 9.32 + * <p><b>This is NOT part of any API supported by Sun Microsystems. If 9.33 + * you write code that depends on this, you do so at your own risk. 9.34 + * This code and its internal interfaces are subject to change or 9.35 + * deletion without notice.</b> 9.36 + */ 9.37 +public class AttributeException extends Exception { 9.38 + AttributeException() { } 9.39 + 9.40 + AttributeException(String msg) { 9.41 + super(msg); 9.42 + } 9.43 +}
10.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 10.2 +++ b/src/share/classes/com/sun/tools/classfile/Attributes.java Tue Jun 03 13:26:47 2008 -0700 10.3 @@ -0,0 +1,87 @@ 10.4 +/* 10.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. 10.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 10.7 + * 10.8 + * This code is free software; you can redistribute it and/or modify it 10.9 + * under the terms of the GNU General Public License version 2 only, as 10.10 + * published by the Free Software Foundation. Sun designates this 10.11 + * particular file as subject to the "Classpath" exception as provided 10.12 + * by Sun in the LICENSE file that accompanied this code. 10.13 + * 10.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 10.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 10.17 + * version 2 for more details (a copy is included in the LICENSE file that 10.18 + * accompanied this code). 10.19 + * 10.20 + * You should have received a copy of the GNU General Public License version 10.21 + * 2 along with this work; if not, write to the Free Software Foundation, 10.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 10.23 + * 10.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 10.25 + * CA 95054 USA or visit www.sun.com if you need additional information or 10.26 + * have any questions. 10.27 + */ 10.28 + 10.29 +package com.sun.tools.classfile; 10.30 + 10.31 +import java.io.IOException; 10.32 +import java.util.Arrays; 10.33 +import java.util.HashMap; 10.34 +import java.util.Iterator; 10.35 +import java.util.Map; 10.36 + 10.37 +/* 10.38 + * <p><b>This is NOT part of any API supported by Sun Microsystems. If 10.39 + * you write code that depends on this, you do so at your own risk. 10.40 + * This code and its internal interfaces are subject to change or 10.41 + * deletion without notice.</b> 10.42 + */ 10.43 +public class Attributes implements Iterable<Attribute> { 10.44 + Attributes(ClassReader cr) throws IOException { 10.45 + map = new HashMap<String,Attribute>(); 10.46 + int attrs_count = cr.readUnsignedShort(); 10.47 + attrs = new Attribute[attrs_count]; 10.48 + for (int i = 0; i < attrs_count; i++) { 10.49 + Attribute attr = Attribute.read(cr); 10.50 + attrs[i] = attr; 10.51 + try { 10.52 + map.put(attr.getName(cr.getConstantPool()), attr); 10.53 + } catch (ConstantPoolException e) { 10.54 + // don't enter invalid names in map 10.55 + } 10.56 + } 10.57 + } 10.58 + 10.59 + public Attributes(ConstantPool constant_pool, Attribute[] attrs) { 10.60 + this.attrs = attrs; 10.61 + map = new HashMap<String,Attribute>(); 10.62 + for (int i = 0; i < attrs.length; i++) { 10.63 + Attribute attr = attrs[i]; 10.64 + try { 10.65 + map.put(attr.getName(constant_pool), attr); 10.66 + } catch (ConstantPoolException e) { 10.67 + // don't enter invalid names in map 10.68 + } 10.69 + } 10.70 + } 10.71 + 10.72 + public Iterator<Attribute> iterator() { 10.73 + return Arrays.asList(attrs).iterator(); 10.74 + } 10.75 + 10.76 + public Attribute get(int index) { 10.77 + return attrs[index]; 10.78 + } 10.79 + 10.80 + public Attribute get(String name) { 10.81 + return map.get(name); 10.82 + } 10.83 + 10.84 + public int size() { 10.85 + return attrs.length; 10.86 + } 10.87 + 10.88 + public final Attribute[] attrs; 10.89 + public final Map<String, Attribute> map; 10.90 +}
11.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 11.2 +++ b/src/share/classes/com/sun/tools/classfile/CharacterRangeTable_attribute.java Tue Jun 03 13:26:47 2008 -0700 11.3 @@ -0,0 +1,90 @@ 11.4 +/* 11.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. 11.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 11.7 + * 11.8 + * This code is free software; you can redistribute it and/or modify it 11.9 + * under the terms of the GNU General Public License version 2 only, as 11.10 + * published by the Free Software Foundation. Sun designates this 11.11 + * particular file as subject to the "Classpath" exception as provided 11.12 + * by Sun in the LICENSE file that accompanied this code. 11.13 + * 11.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 11.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11.17 + * version 2 for more details (a copy is included in the LICENSE file that 11.18 + * accompanied this code). 11.19 + * 11.20 + * You should have received a copy of the GNU General Public License version 11.21 + * 2 along with this work; if not, write to the Free Software Foundation, 11.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 11.23 + * 11.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 11.25 + * CA 95054 USA or visit www.sun.com if you need additional information or 11.26 + * have any questions. 11.27 + */ 11.28 + 11.29 +package com.sun.tools.classfile; 11.30 + 11.31 +import java.io.IOException; 11.32 + 11.33 +/** 11.34 + * <p><b>This is NOT part of any API supported by Sun Microsystems. If 11.35 + * you write code that depends on this, you do so at your own risk. 11.36 + * This code and its internal interfaces are subject to change or 11.37 + * deletion without notice.</b> 11.38 + */ 11.39 +public class CharacterRangeTable_attribute extends Attribute { 11.40 + public static final int CRT_STATEMENT = 0x0001; 11.41 + public static final int CRT_BLOCK = 0x0002; 11.42 + public static final int CRT_ASSIGNMENT = 0x0004; 11.43 + public static final int CRT_FLOW_CONTROLLER = 0x0008; 11.44 + public static final int CRT_FLOW_TARGET = 0x0010; 11.45 + public static final int CRT_INVOKE = 0x0020; 11.46 + public static final int CRT_CREATE = 0x0040; 11.47 + public static final int CRT_BRANCH_TRUE = 0x0080; 11.48 + public static final int CRT_BRANCH_FALSE = 0x0100; 11.49 + 11.50 + CharacterRangeTable_attribute(ClassReader cr, int name_index, int length) throws IOException { 11.51 + super(name_index, length); 11.52 + int character_range_table_length = cr.readUnsignedShort(); 11.53 + character_range_table = new Entry[character_range_table_length]; 11.54 + for (int i = 0; i < character_range_table_length; i++) 11.55 + character_range_table[i] = new Entry(cr); 11.56 + } 11.57 + 11.58 + public CharacterRangeTable_attribute(ConstantPool constant_pool, Entry[] character_range_table) 11.59 + throws ConstantPoolException { 11.60 + this(constant_pool.getUTF8Index(Attribute.CharacterRangeTable), character_range_table); 11.61 + } 11.62 + 11.63 + public CharacterRangeTable_attribute(int name_index, Entry[] character_range_table) { 11.64 + super(name_index, character_range_table.length * Entry.length()); 11.65 + this.character_range_table = character_range_table; 11.66 + } 11.67 + 11.68 + public <R, D> R accept(Visitor<R, D> visitor, D data) { 11.69 + return visitor.visitCharacterRangeTable(this, data); 11.70 + } 11.71 + 11.72 + public final Entry[] character_range_table; 11.73 + 11.74 + public static class Entry { 11.75 + Entry(ClassReader cr) throws IOException { 11.76 + start_pc = cr.readUnsignedShort(); 11.77 + end_pc = cr.readUnsignedShort(); 11.78 + character_range_start = cr.readInt(); 11.79 + character_range_end = cr.readInt(); 11.80 + flags = cr.readUnsignedShort(); 11.81 + } 11.82 + 11.83 + public static int length() { 11.84 + return 14; 11.85 + } 11.86 + 11.87 + public final int start_pc; 11.88 + public final int end_pc; 11.89 + public final int character_range_start; 11.90 + public final int character_range_end; 11.91 + public final int flags; 11.92 + }; 11.93 +}
12.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 12.2 +++ b/src/share/classes/com/sun/tools/classfile/ClassFile.java Tue Jun 03 13:26:47 2008 -0700 12.3 @@ -0,0 +1,153 @@ 12.4 +/* 12.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. 12.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 12.7 + * 12.8 + * This code is free software; you can redistribute it and/or modify it 12.9 + * under the terms of the GNU General Public License version 2 only, as 12.10 + * published by the Free Software Foundation. Sun designates this 12.11 + * particular file as subject to the "Classpath" exception as provided 12.12 + * by Sun in the LICENSE file that accompanied this code. 12.13 + * 12.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 12.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12.17 + * version 2 for more details (a copy is included in the LICENSE file that 12.18 + * accompanied this code). 12.19 + * 12.20 + * You should have received a copy of the GNU General Public License version 12.21 + * 2 along with this work; if not, write to the Free Software Foundation, 12.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 12.23 + * 12.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 12.25 + * CA 95054 USA or visit www.sun.com if you need additional information or 12.26 + * have any questions. 12.27 + */ 12.28 + 12.29 +package com.sun.tools.classfile; 12.30 + 12.31 +import java.io.File; 12.32 +import java.io.FileInputStream; 12.33 +import java.io.IOException; 12.34 +import java.io.InputStream; 12.35 + 12.36 +import static com.sun.tools.classfile.AccessFlags.*; 12.37 + 12.38 +/** 12.39 + * See JVMS3, section 4.2. 12.40 + * 12.41 + * <p><b>This is NOT part of any API supported by Sun Microsystems. If 12.42 + * you write code that depends on this, you do so at your own risk. 12.43 + * This code and its internal interfaces are subject to change or 12.44 + * deletion without notice.</b> 12.45 + */ 12.46 +public class ClassFile { 12.47 + public static ClassFile read(File file) 12.48 + throws IOException, ConstantPoolException { 12.49 + return read(file, new Attribute.Factory()); 12.50 + } 12.51 + 12.52 + public static ClassFile read(File file, Attribute.Factory attributeFactory) 12.53 + throws IOException, ConstantPoolException { 12.54 + FileInputStream in = new FileInputStream(file); 12.55 + try { 12.56 + return new ClassFile(in, attributeFactory); 12.57 + } finally { 12.58 + try { 12.59 + in.close(); 12.60 + } catch (IOException e) { 12.61 + // ignore 12.62 + } 12.63 + } 12.64 + } 12.65 + 12.66 + public static ClassFile read(InputStream in) 12.67 + throws IOException, ConstantPoolException { 12.68 + return new ClassFile(in, new Attribute.Factory()); 12.69 + } 12.70 + 12.71 + public static ClassFile read(InputStream in, Attribute.Factory attributeFactory) 12.72 + throws IOException, ConstantPoolException { 12.73 + return new ClassFile(in, attributeFactory); 12.74 + } 12.75 + 12.76 + ClassFile(InputStream in, Attribute.Factory attributeFactory) throws IOException, ConstantPoolException { 12.77 + ClassReader cr = new ClassReader(this, in, attributeFactory); 12.78 + magic = cr.readInt(); 12.79 + minor_version = cr.readUnsignedShort(); 12.80 + major_version = cr.readUnsignedShort(); 12.81 + constant_pool = new ConstantPool(cr); 12.82 + access_flags = new AccessFlags(cr); 12.83 + this_class = cr.readUnsignedShort(); 12.84 + super_class = cr.readUnsignedShort(); 12.85 + 12.86 + int interfaces_count = cr.readUnsignedShort(); 12.87 + interfaces = new int[interfaces_count]; 12.88 + for (int i = 0; i < interfaces_count; i++) 12.89 + interfaces[i] = cr.readUnsignedShort(); 12.90 + 12.91 + int fields_count = cr.readUnsignedShort(); 12.92 + fields = new Field[fields_count]; 12.93 + for (int i = 0; i < fields_count; i++) 12.94 + fields[i] = new Field(cr); 12.95 + 12.96 + int methods_count = cr.readUnsignedShort(); 12.97 + methods = new Method[methods_count]; 12.98 + for (int i = 0; i < methods_count; i++) 12.99 + methods[i] = new Method(cr); 12.100 + 12.101 + attributes = new Attributes(cr); 12.102 + } 12.103 + 12.104 + public ClassFile(int magic, int minor_version, int major_version, 12.105 + ConstantPool constant_pool, AccessFlags access_flags, 12.106 + int this_class, int super_class, int[] interfaces, 12.107 + Field[] fields, Method[] methods, Attributes attributes) { 12.108 + this.magic = magic; 12.109 + this.minor_version = minor_version; 12.110 + this.major_version = major_version; 12.111 + this.constant_pool = constant_pool; 12.112 + this.access_flags = access_flags; 12.113 + this.this_class = this_class; 12.114 + this.super_class = super_class; 12.115 + this.interfaces = interfaces; 12.116 + this.fields = fields; 12.117 + this.methods = methods; 12.118 + this.attributes = attributes; 12.119 + } 12.120 + 12.121 + public String getName() throws ConstantPoolException { 12.122 + return constant_pool.getClassInfo(this_class).getName(); 12.123 + } 12.124 + 12.125 + public String getSuperclassName() throws ConstantPoolException { 12.126 + return constant_pool.getClassInfo(super_class).getName(); 12.127 + } 12.128 + 12.129 + public String getInterfaceName(int i) throws ConstantPoolException { 12.130 + return constant_pool.getClassInfo(interfaces[i]).getName(); 12.131 + } 12.132 + 12.133 + public Attribute getAttribute(String name) { 12.134 + return attributes.get(name); 12.135 + } 12.136 + 12.137 + public boolean isClass() { 12.138 + return !isInterface(); 12.139 + } 12.140 + 12.141 + public boolean isInterface() { 12.142 + return access_flags.is(ACC_INTERFACE); 12.143 + } 12.144 + 12.145 + public final int magic; 12.146 + public final int minor_version; 12.147 + public final int major_version; 12.148 + public final ConstantPool constant_pool; 12.149 + public final AccessFlags access_flags; 12.150 + public final int this_class; 12.151 + public final int super_class; 12.152 + public final int[] interfaces; 12.153 + public final Field[] fields; 12.154 + public final Method[] methods; 12.155 + public final Attributes attributes; 12.156 +}
13.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 13.2 +++ b/src/share/classes/com/sun/tools/classfile/ClassReader.java Tue Jun 03 13:26:47 2008 -0700 13.3 @@ -0,0 +1,109 @@ 13.4 +/* 13.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. 13.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 13.7 + * 13.8 + * This code is free software; you can redistribute it and/or modify it 13.9 + * under the terms of the GNU General Public License version 2 only, as 13.10 + * published by the Free Software Foundation. Sun designates this 13.11 + * particular file as subject to the "Classpath" exception as provided 13.12 + * by Sun in the LICENSE file that accompanied this code. 13.13 + * 13.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 13.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13.17 + * version 2 for more details (a copy is included in the LICENSE file that 13.18 + * accompanied this code). 13.19 + * 13.20 + * You should have received a copy of the GNU General Public License version 13.21 + * 2 along with this work; if not, write to the Free Software Foundation, 13.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 13.23 + * 13.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 13.25 + * CA 95054 USA or visit www.sun.com if you need additional information or 13.26 + * have any questions. 13.27 + */ 13.28 + 13.29 +package com.sun.tools.classfile; 13.30 + 13.31 +import java.io.BufferedInputStream; 13.32 +import java.io.ByteArrayInputStream; 13.33 +import java.io.DataInputStream; 13.34 +import java.io.IOException; 13.35 +import java.io.InputStream; 13.36 + 13.37 +/** 13.38 + * <p><b>This is NOT part of any API supported by Sun Microsystems. If 13.39 + * you write code that depends on this, you do so at your own risk. 13.40 + * This code and its internal interfaces are subject to change or 13.41 + * deletion without notice.</b> 13.42 + */ 13.43 +public class ClassReader { 13.44 + ClassReader(ClassFile classFile, InputStream in, Attribute.Factory attributeFactory) throws IOException { 13.45 + // null checks 13.46 + classFile.getClass(); 13.47 + attributeFactory.getClass(); 13.48 + 13.49 + this.classFile = classFile; 13.50 + this.in = new DataInputStream(new BufferedInputStream(in)); 13.51 + this.attributeFactory = attributeFactory; 13.52 + } 13.53 + 13.54 + ClassFile getClassFile() { 13.55 + return classFile; 13.56 + } 13.57 + 13.58 + ConstantPool getConstantPool() { 13.59 + return classFile.constant_pool; 13.60 + } 13.61 + 13.62 + public Attribute readAttribute() throws IOException { 13.63 + int name_index = readUnsignedShort(); 13.64 + int length = readInt(); 13.65 + byte[] data = new byte[length]; 13.66 + readFully(data); 13.67 + 13.68 + DataInputStream prev = in; 13.69 + in = new DataInputStream(new ByteArrayInputStream(data)); 13.70 + try { 13.71 + return attributeFactory.createAttribute(this, name_index, data); 13.72 + } finally { 13.73 + in = prev; 13.74 + } 13.75 + } 13.76 + 13.77 + public void readFully(byte[] b) throws IOException { 13.78 + in.readFully(b); 13.79 + } 13.80 + 13.81 + public int readUnsignedByte() throws IOException { 13.82 + return in.readUnsignedByte(); 13.83 + } 13.84 + 13.85 + public int readUnsignedShort() throws IOException { 13.86 + return in.readUnsignedShort(); 13.87 + } 13.88 + 13.89 + public int readInt() throws IOException { 13.90 + return in.readInt(); 13.91 + } 13.92 + 13.93 + public long readLong() throws IOException { 13.94 + return in.readLong(); 13.95 + } 13.96 + 13.97 + public float readFloat() throws IOException { 13.98 + return in.readFloat(); 13.99 + } 13.100 + 13.101 + public double readDouble() throws IOException { 13.102 + return in.readDouble(); 13.103 + } 13.104 + 13.105 + public String readUTF() throws IOException { 13.106 + return in.readUTF(); 13.107 + } 13.108 + 13.109 + private DataInputStream in; 13.110 + private ClassFile classFile; 13.111 + private Attribute.Factory attributeFactory; 13.112 +}
14.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 14.2 +++ b/src/share/classes/com/sun/tools/classfile/ClassTranslator.java Tue Jun 03 13:26:47 2008 -0700 14.3 @@ -0,0 +1,368 @@ 14.4 +/* 14.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. 14.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 14.7 + * 14.8 + * This code is free software; you can redistribute it and/or modify it 14.9 + * under the terms of the GNU General Public License version 2 only, as 14.10 + * published by the Free Software Foundation. Sun designates this 14.11 + * particular file as subject to the "Classpath" exception as provided 14.12 + * by Sun in the LICENSE file that accompanied this code. 14.13 + * 14.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 14.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14.17 + * version 2 for more details (a copy is included in the LICENSE file that 14.18 + * accompanied this code). 14.19 + * 14.20 + * You should have received a copy of the GNU General Public License version 14.21 + * 2 along with this work; if not, write to the Free Software Foundation, 14.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 14.23 + * 14.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 14.25 + * CA 95054 USA or visit www.sun.com if you need additional information or 14.26 + * have any questions. 14.27 + */ 14.28 + 14.29 +package com.sun.tools.classfile; 14.30 + 14.31 +import com.sun.tools.classfile.ConstantPool.CONSTANT_Class_info; 14.32 +import com.sun.tools.classfile.ConstantPool.CONSTANT_Double_info; 14.33 +import com.sun.tools.classfile.ConstantPool.CONSTANT_Fieldref_info; 14.34 +import com.sun.tools.classfile.ConstantPool.CONSTANT_Float_info; 14.35 +import com.sun.tools.classfile.ConstantPool.CONSTANT_Integer_info; 14.36 +import com.sun.tools.classfile.ConstantPool.CONSTANT_InterfaceMethodref_info; 14.37 +import com.sun.tools.classfile.ConstantPool.CONSTANT_Long_info; 14.38 +import com.sun.tools.classfile.ConstantPool.CONSTANT_Methodref_info; 14.39 +import com.sun.tools.classfile.ConstantPool.CONSTANT_NameAndType_info; 14.40 +import com.sun.tools.classfile.ConstantPool.CONSTANT_String_info; 14.41 +import com.sun.tools.classfile.ConstantPool.CONSTANT_Utf8_info; 14.42 +import com.sun.tools.classfile.ConstantPool.CPInfo; 14.43 +import java.util.Map; 14.44 + 14.45 +/** 14.46 + * Rewrites a class file using a map of translations. 14.47 + * 14.48 + * <p><b>This is NOT part of any API supported by Sun Microsystems. If 14.49 + * you write code that depends on this, you do so at your own risk. 14.50 + * This code and its internal interfaces are subject to change or 14.51 + * deletion without notice.</b> 14.52 + */ 14.53 +public class ClassTranslator 14.54 + implements ConstantPool.Visitor<ConstantPool.CPInfo,Map<Object,Object>> { 14.55 + /** 14.56 + * Create a new ClassFile from {@code cf}, such that for all entries 14.57 + * {@code k -\> v} in {@code translations}, 14.58 + * each occurrence of {@code k} in {@code cf} will be replaced by {@code v}. 14.59 + * in 14.60 + * @param cf the class file to be processed 14.61 + * @param translations the set of translations to be applied 14.62 + * @return a copy of {@code} with the values in {@code translations} substituted 14.63 + */ 14.64 + public ClassFile translate(ClassFile cf, Map<Object,Object> translations) { 14.65 + ClassFile cf2 = (ClassFile) translations.get(cf); 14.66 + if (cf2 == null) { 14.67 + ConstantPool constant_pool2 = translate(cf.constant_pool, translations); 14.68 + Field[] fields2 = translate(cf.fields, cf.constant_pool, translations); 14.69 + Method[] methods2 = translateMethods(cf.methods, cf.constant_pool, translations); 14.70 + Attributes attributes2 = translateAttributes(cf.attributes, cf.constant_pool, 14.71 + translations); 14.72 + 14.73 + if (constant_pool2 == cf.constant_pool && 14.74 + fields2 == cf.fields && 14.75 + methods2 == cf.methods && 14.76 + attributes2 == cf.attributes) 14.77 + cf2 = cf; 14.78 + else 14.79 + cf2 = new ClassFile( 14.80 + cf.magic, 14.81 + cf.minor_version, 14.82 + cf.major_version, 14.83 + constant_pool2, 14.84 + cf.access_flags, 14.85 + cf.this_class, 14.86 + cf.super_class, 14.87 + cf.interfaces, 14.88 + fields2, 14.89 + methods2, 14.90 + attributes2); 14.91 + translations.put(cf, cf2); 14.92 + } 14.93 + return cf2; 14.94 + } 14.95 + 14.96 + ConstantPool translate(ConstantPool cp, Map<Object,Object> translations) { 14.97 + ConstantPool cp2 = (ConstantPool) translations.get(cp); 14.98 + if (cp2 == null) { 14.99 + ConstantPool.CPInfo[] pool2 = new ConstantPool.CPInfo[cp.size()]; 14.100 + boolean eq = true; 14.101 + for (int i = 0; i < cp.size(); i++) { 14.102 + ConstantPool.CPInfo cpInfo; 14.103 + try { 14.104 + cpInfo = cp.get(i); 14.105 + } catch (ConstantPool.InvalidIndex e) { 14.106 + throw new IllegalStateException(e); 14.107 + } 14.108 + ConstantPool.CPInfo cpInfo2 = translate(cpInfo, translations); 14.109 + eq &= (cpInfo == cpInfo2); 14.110 + pool2[i] = cpInfo2; 14.111 + if (cpInfo.getTag() != cpInfo2.getTag()) 14.112 + throw new IllegalStateException(); 14.113 + switch (cpInfo.getTag()) { 14.114 + case ConstantPool.CONSTANT_Double: 14.115 + case ConstantPool.CONSTANT_Long: 14.116 + i += 1; 14.117 + } 14.118 + } 14.119 + 14.120 + if (eq) 14.121 + cp2 = cp; 14.122 + else 14.123 + cp2 = new ConstantPool(pool2); 14.124 + 14.125 + translations.put(cp, cp2); 14.126 + } 14.127 + return cp2; 14.128 + } 14.129 + 14.130 + ConstantPool.CPInfo translate(ConstantPool.CPInfo cpInfo, Map<Object,Object> translations) { 14.131 + ConstantPool.CPInfo cpInfo2 = (ConstantPool.CPInfo) translations.get(cpInfo); 14.132 + if (cpInfo2 == null) { 14.133 + cpInfo2 = cpInfo.accept(this, translations); 14.134 + translations.put(cpInfo, cpInfo2); 14.135 + } 14.136 + return cpInfo2; 14.137 + } 14.138 + 14.139 + Field[] translate(Field[] fields, ConstantPool constant_pool, Map<Object,Object> translations) { 14.140 + Field[] fields2 = (Field[]) translations.get(fields); 14.141 + if (fields2 == null) { 14.142 + fields2 = new Field[fields.length]; 14.143 + for (int i = 0; i < fields.length; i++) 14.144 + fields2[i] = translate(fields[i], constant_pool, translations); 14.145 + if (equal(fields, fields2)) 14.146 + fields2 = fields; 14.147 + translations.put(fields, fields2); 14.148 + } 14.149 + return fields2; 14.150 + } 14.151 + 14.152 + Field translate(Field field, ConstantPool constant_pool, Map<Object,Object> translations) { 14.153 + Field field2 = (Field) translations.get(field); 14.154 + if (field2 == null) { 14.155 + Attributes attributes2 = translateAttributes(field.attributes, constant_pool, 14.156 + translations); 14.157 + 14.158 + if (attributes2 == field.attributes) 14.159 + field2 = field; 14.160 + else 14.161 + field2 = new Field( 14.162 + field.access_flags, 14.163 + field.name_index, 14.164 + field.descriptor, 14.165 + attributes2); 14.166 + translations.put(field, field2); 14.167 + } 14.168 + return field2; 14.169 + } 14.170 + 14.171 + Method[] translateMethods(Method[] methods, ConstantPool constant_pool, Map<Object,Object> translations) { 14.172 + Method[] methods2 = (Method[]) translations.get(methods); 14.173 + if (methods2 == null) { 14.174 + methods2 = new Method[methods.length]; 14.175 + for (int i = 0; i < methods.length; i++) 14.176 + methods2[i] = translate(methods[i], constant_pool, translations); 14.177 + if (equal(methods, methods2)) 14.178 + methods2 = methods; 14.179 + translations.put(methods, methods2); 14.180 + } 14.181 + return methods2; 14.182 + } 14.183 + 14.184 + Method translate(Method method, ConstantPool constant_pool, Map<Object,Object> translations) { 14.185 + Method method2 = (Method) translations.get(method); 14.186 + if (method2 == null) { 14.187 + Attributes attributes2 = translateAttributes(method.attributes, constant_pool, 14.188 + translations); 14.189 + 14.190 + if (attributes2 == method.attributes) 14.191 + method2 = method; 14.192 + else 14.193 + method2 = new Method( 14.194 + method.access_flags, 14.195 + method.name_index, 14.196 + method.descriptor, 14.197 + attributes2); 14.198 + translations.put(method, method2); 14.199 + } 14.200 + return method2; 14.201 + } 14.202 + 14.203 + Attributes translateAttributes(Attributes attributes, 14.204 + ConstantPool constant_pool, Map<Object,Object> translations) { 14.205 + Attributes attributes2 = (Attributes) translations.get(attributes); 14.206 + if (attributes2 == null) { 14.207 + Attribute[] attrArray2 = new Attribute[attributes.size()]; 14.208 + ConstantPool constant_pool2 = translate(constant_pool, translations); 14.209 + boolean attrsEqual = true; 14.210 + for (int i = 0; i < attributes.size(); i++) { 14.211 + Attribute attr = attributes.get(i); 14.212 + Attribute attr2 = translate(attr, translations); 14.213 + if (attr2 != attr) 14.214 + attrsEqual = false; 14.215 + attrArray2[i] = attr2; 14.216 + } 14.217 + if ((constant_pool2 == constant_pool) && attrsEqual) 14.218 + attributes2 = attributes; 14.219 + else 14.220 + attributes2 = new Attributes(constant_pool2, attrArray2); 14.221 + translations.put(attributes, attributes2); 14.222 + } 14.223 + return attributes2; 14.224 + } 14.225 + 14.226 + Attribute translate(Attribute attribute, Map<Object,Object> translations) { 14.227 + Attribute attribute2 = (Attribute) translations.get(attribute); 14.228 + if (attribute2 == null) { 14.229 + attribute2 = attribute; // don't support translation within attributes yet 14.230 + // (what about Code attribute) 14.231 + translations.put(attribute, attribute2); 14.232 + } 14.233 + return attribute2; 14.234 + } 14.235 + 14.236 + private static <T> boolean equal(T[] a1, T[] a2) { 14.237 + if (a1 == null || a2 == null) 14.238 + return (a1 == a2); 14.239 + if (a1.length != a2.length) 14.240 + return false; 14.241 + for (int i = 0; i < a1.length; i++) { 14.242 + if (a1[i] != a2[i]) 14.243 + return false; 14.244 + } 14.245 + return true; 14.246 + } 14.247 + 14.248 + public CPInfo visitClass(CONSTANT_Class_info info, Map<Object, Object> translations) { 14.249 + CONSTANT_Class_info info2 = (CONSTANT_Class_info) translations.get(info); 14.250 + if (info2 == null) { 14.251 + ConstantPool cp2 = translate(info.cp, translations); 14.252 + if (cp2 == info.cp) 14.253 + info2 = info; 14.254 + else 14.255 + info2 = new CONSTANT_Class_info(cp2, info.name_index); 14.256 + translations.put(info, info2); 14.257 + } 14.258 + return info; 14.259 + } 14.260 + 14.261 + public CPInfo visitDouble(CONSTANT_Double_info info, Map<Object, Object> translations) { 14.262 + CONSTANT_Double_info info2 = (CONSTANT_Double_info) translations.get(info); 14.263 + if (info2 == null) { 14.264 + info2 = info; 14.265 + translations.put(info, info2); 14.266 + } 14.267 + return info; 14.268 + } 14.269 + 14.270 + public CPInfo visitFieldref(CONSTANT_Fieldref_info info, Map<Object, Object> translations) { 14.271 + CONSTANT_Fieldref_info info2 = (CONSTANT_Fieldref_info) translations.get(info); 14.272 + if (info2 == null) { 14.273 + ConstantPool cp2 = translate(info.cp, translations); 14.274 + if (cp2 == info.cp) 14.275 + info2 = info; 14.276 + else 14.277 + info2 = new CONSTANT_Fieldref_info(cp2, info.class_index, info.name_and_type_index); 14.278 + translations.put(info, info2); 14.279 + } 14.280 + return info; 14.281 + } 14.282 + 14.283 + public CPInfo visitFloat(CONSTANT_Float_info info, Map<Object, Object> translations) { 14.284 + CONSTANT_Float_info info2 = (CONSTANT_Float_info) translations.get(info); 14.285 + if (info2 == null) { 14.286 + info2 = info; 14.287 + translations.put(info, info2); 14.288 + } 14.289 + return info; 14.290 + } 14.291 + 14.292 + public CPInfo visitInteger(CONSTANT_Integer_info info, Map<Object, Object> translations) { 14.293 + CONSTANT_Integer_info info2 = (CONSTANT_Integer_info) translations.get(info); 14.294 + if (info2 == null) { 14.295 + info2 = info; 14.296 + translations.put(info, info2); 14.297 + } 14.298 + return info; 14.299 + } 14.300 + 14.301 + public CPInfo visitInterfaceMethodref(CONSTANT_InterfaceMethodref_info info, Map<Object, Object> translations) { 14.302 + CONSTANT_InterfaceMethodref_info info2 = (CONSTANT_InterfaceMethodref_info) translations.get(info); 14.303 + if (info2 == null) { 14.304 + ConstantPool cp2 = translate(info.cp, translations); 14.305 + if (cp2 == info.cp) 14.306 + info2 = info; 14.307 + else 14.308 + info2 = new CONSTANT_InterfaceMethodref_info(cp2, info.class_index, info.name_and_type_index); 14.309 + translations.put(info, info2); 14.310 + } 14.311 + return info; 14.312 + } 14.313 + 14.314 + public CPInfo visitLong(CONSTANT_Long_info info, Map<Object, Object> translations) { 14.315 + CONSTANT_Long_info info2 = (CONSTANT_Long_info) translations.get(info); 14.316 + if (info2 == null) { 14.317 + info2 = info; 14.318 + translations.put(info, info2); 14.319 + } 14.320 + return info; 14.321 + } 14.322 + 14.323 + public CPInfo visitNameAndType(CONSTANT_NameAndType_info info, Map<Object, Object> translations) { 14.324 + CONSTANT_NameAndType_info info2 = (CONSTANT_NameAndType_info) translations.get(info); 14.325 + if (info2 == null) { 14.326 + ConstantPool cp2 = translate(info.cp, translations); 14.327 + if (cp2 == info.cp) 14.328 + info2 = info; 14.329 + else 14.330 + info2 = new CONSTANT_NameAndType_info(cp2, info.name_index, info.type_index); 14.331 + translations.put(info, info2); 14.332 + } 14.333 + return info; 14.334 + } 14.335 + 14.336 + public CPInfo visitMethodref(CONSTANT_Methodref_info info, Map<Object, Object> translations) { 14.337 + CONSTANT_Methodref_info info2 = (CONSTANT_Methodref_info) translations.get(info); 14.338 + if (info2 == null) { 14.339 + ConstantPool cp2 = translate(info.cp, translations); 14.340 + if (cp2 == info.cp) 14.341 + info2 = info; 14.342 + else 14.343 + info2 = new CONSTANT_Methodref_info(cp2, info.class_index, info.name_and_type_index); 14.344 + translations.put(info, info2); 14.345 + } 14.346 + return info; 14.347 + } 14.348 + 14.349 + public CPInfo visitString(CONSTANT_String_info info, Map<Object, Object> translations) { 14.350 + CONSTANT_String_info info2 = (CONSTANT_String_info) translations.get(info); 14.351 + if (info2 == null) { 14.352 + ConstantPool cp2 = translate(info.cp, translations); 14.353 + if (cp2 == info.cp) 14.354 + info2 = info; 14.355 + else 14.356 + info2 = new CONSTANT_String_info(cp2, info.string_index); 14.357 + translations.put(info, info2); 14.358 + } 14.359 + return info; 14.360 + } 14.361 + 14.362 + public CPInfo visitUtf8(CONSTANT_Utf8_info info, Map<Object, Object> translations) { 14.363 + CONSTANT_Utf8_info info2 = (CONSTANT_Utf8_info) translations.get(info); 14.364 + if (info2 == null) { 14.365 + info2 = info; 14.366 + translations.put(info, info2); 14.367 + } 14.368 + return info; 14.369 + } 14.370 + 14.371 +}
15.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 15.2 +++ b/src/share/classes/com/sun/tools/classfile/ClassWriter.java Tue Jun 03 13:26:47 2008 -0700 15.3 @@ -0,0 +1,689 @@ 15.4 +/* 15.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. 15.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 15.7 + * 15.8 + * This code is free software; you can redistribute it and/or modify it 15.9 + * under the terms of the GNU General Public License version 2 only, as 15.10 + * published by the Free Software Foundation. Sun designates this 15.11 + * particular file as subject to the "Classpath" exception as provided 15.12 + * by Sun in the LICENSE file that accompanied this code. 15.13 + * 15.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 15.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 15.17 + * version 2 for more details (a copy is included in the LICENSE file that 15.18 + * accompanied this code). 15.19 + * 15.20 + * You should have received a copy of the GNU General Public License version 15.21 + * 2 along with this work; if not, write to the Free Software Foundation, 15.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 15.23 + * 15.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 15.25 + * CA 95054 USA or visit www.sun.com if you need additional information or 15.26 + * have any questions. 15.27 + */ 15.28 + 15.29 +package com.sun.tools.classfile; 15.30 + 15.31 +import java.io.ByteArrayOutputStream; 15.32 +import java.io.DataOutputStream; 15.33 +import java.io.File; 15.34 +import java.io.FileOutputStream; 15.35 +import java.io.IOException; 15.36 +import java.io.OutputStream; 15.37 + 15.38 +import static com.sun.tools.classfile.Annotation.*; 15.39 +import static com.sun.tools.classfile.ConstantPool.*; 15.40 +import static com.sun.tools.classfile.StackMapTable_attribute.*; 15.41 +import static com.sun.tools.classfile.StackMapTable_attribute.verification_type_info.*; 15.42 + 15.43 +/** 15.44 + * Write a ClassFile data structure to a file or stream. 15.45 + * 15.46 + * <p><b>This is NOT part of any API supported by Sun Microsystems. If 15.47 + * you write code that depends on this, you do so at your own risk. 15.48 + * This code and its internal interfaces are subject to change or 15.49 + * deletion without notice.</b> 15.50 + */ 15.51 +public class ClassWriter { 15.52 + public ClassWriter() { 15.53 + attributeWriter = new AttributeWriter(); 15.54 + constantPoolWriter = new ConstantPoolWriter(); 15.55 + out = new ClassOutputStream(); 15.56 + } 15.57 + 15.58 + /** 15.59 + * Write a ClassFile data structure to a file. 15.60 + */ 15.61 + public void write(ClassFile classFile, File f) throws IOException { 15.62 + FileOutputStream f_out = new FileOutputStream(f); 15.63 + try { 15.64 + write(classFile, f_out); 15.65 + } finally { 15.66 + f_out.close(); 15.67 + } 15.68 + } 15.69 + 15.70 + /** 15.71 + * Write a ClassFile data structure to a stream. 15.72 + */ 15.73 + public void write(ClassFile classFile, OutputStream s) throws IOException { 15.74 + this.classFile = classFile; 15.75 + out.reset(); 15.76 + write(); 15.77 + out.writeTo(s); 15.78 + } 15.79 + 15.80 + protected void write() throws IOException { 15.81 + writeHeader(); 15.82 + writeConstantPool(); 15.83 + writeAccessFlags(classFile.access_flags); 15.84 + writeClassInfo(); 15.85 + writeFields(); 15.86 + writeMethods(); 15.87 + writeAttributes(classFile.attributes); 15.88 + } 15.89 + 15.90 + protected void writeHeader() { 15.91 + out.writeInt(classFile.magic); 15.92 + out.writeShort(classFile.minor_version); 15.93 + out.writeShort(classFile.major_version); 15.94 + } 15.95 + 15.96 + protected void writeAccessFlags(AccessFlags flags) { 15.97 + out.writeShort(flags.flags); 15.98 + } 15.99 + 15.100 + protected void writeAttributes(Attributes attributes) { 15.101 + int size = attributes.size(); 15.102 + out.writeShort(size); 15.103 + for (Attribute attr: attributes) 15.104 + attributeWriter.write(attr, out); 15.105 + } 15.106 + 15.107 + protected void writeClassInfo() { 15.108 + out.writeShort(classFile.this_class); 15.109 + out.writeShort(classFile.super_class); 15.110 + int[] interfaces = classFile.interfaces; 15.111 + out.writeShort(interfaces.length); 15.112 + for (int i: interfaces) 15.113 + out.writeShort(i); 15.114 + } 15.115 + 15.116 + protected void writeDescriptor(Descriptor d) { 15.117 + out.writeShort(d.index); 15.118 + } 15.119 + 15.120 + protected void writeConstantPool() { 15.121 + ConstantPool pool = classFile.constant_pool; 15.122 + int size = pool.size(); 15.123 + out.writeShort(size); 15.124 + try { 15.125 + for (int i = 1; i < size; ) { 15.126 + i += constantPoolWriter.write(pool.get(i), out); 15.127 + } 15.128 + } catch (ConstantPoolException e) { 15.129 + throw new Error(e); // ?? 15.130 + } 15.131 + } 15.132 + 15.133 + protected void writeFields() throws IOException { 15.134 + Field[] fields = classFile.fields; 15.135 + out.writeShort(fields.length); 15.136 + for (Field f: fields) 15.137 + writeField(f); 15.138 + } 15.139 + 15.140 + protected void writeField(Field f) throws IOException { 15.141 + writeAccessFlags(f.access_flags); 15.142 + out.writeShort(f.name_index); 15.143 + writeDescriptor(f.descriptor); 15.144 + writeAttributes(f.attributes); 15.145 + } 15.146 + 15.147 + protected void writeMethods() throws IOException { 15.148 + Method[] methods = classFile.methods; 15.149 + out.writeShort(methods.length); 15.150 + for (Method m: methods) { 15.151 + writeMethod(m); 15.152 + } 15.153 + } 15.154 + 15.155 + protected void writeMethod(Method m) throws IOException { 15.156 + writeAccessFlags(m.access_flags); 15.157 + out.writeShort(m.name_index); 15.158 + writeDescriptor(m.descriptor); 15.159 + writeAttributes(m.attributes); 15.160 + } 15.161 + 15.162 + protected ClassFile classFile; 15.163 + protected ClassOutputStream out; 15.164 + protected AttributeWriter attributeWriter; 15.165 + protected ConstantPoolWriter constantPoolWriter; 15.166 + 15.167 + /** 15.168 + * Subtype of ByteArrayOutputStream with the convenience methods of 15.169 + * a DataOutputStream. Since ByteArrayOutputStream does not throw 15.170 + * IOException, there are no exceptions from the additional 15.171 + * convenience methods either, 15.172 + */ 15.173 + protected static class ClassOutputStream extends ByteArrayOutputStream { 15.174 + public ClassOutputStream() { 15.175 + d = new DataOutputStream(this); 15.176 + } 15.177 + 15.178 + public void writeByte(int value) { 15.179 + try { 15.180 + d.writeByte(value); 15.181 + } catch (IOException ignore) { 15.182 + } 15.183 + } 15.184 + 15.185 + public void writeShort(int value) { 15.186 + try { 15.187 + d.writeShort(value); 15.188 + } catch (IOException ignore) { 15.189 + } 15.190 + } 15.191 + 15.192 + public void writeInt(int value) { 15.193 + try { 15.194 + d.writeInt(value); 15.195 + } catch (IOException ignore) { 15.196 + } 15.197 + } 15.198 + 15.199 + public void writeLong(long value) { 15.200 + try { 15.201 + d.writeLong(value); 15.202 + } catch (IOException ignore) { 15.203 + } 15.204 + } 15.205 + 15.206 + public void writeFloat(float value) { 15.207 + try { 15.208 + d.writeFloat(value); 15.209 + } catch (IOException ignore) { 15.210 + } 15.211 + } 15.212 + 15.213 + public void writeDouble(double value) { 15.214 + try { 15.215 + d.writeDouble(value); 15.216 + } catch (IOException ignore) { 15.217 + } 15.218 + } 15.219 + 15.220 + public void writeUTF(String value) { 15.221 + try { 15.222 + d.writeUTF(value); 15.223 + } catch (IOException ignore) { 15.224 + } 15.225 + } 15.226 + 15.227 + public void writeTo(ClassOutputStream s) { 15.228 + try { 15.229 + super.writeTo(s); 15.230 + } catch (IOException ignore) { 15.231 + } 15.232 + } 15.233 + 15.234 + private DataOutputStream d; 15.235 + } 15.236 + 15.237 + /** 15.238 + * Writer for the entries in the constant pool. 15.239 + */ 15.240 + protected static class ConstantPoolWriter 15.241 + implements ConstantPool.Visitor<Integer,ClassOutputStream> { 15.242 + protected int write(CPInfo info, ClassOutputStream out) { 15.243 + out.writeByte(info.getTag()); 15.244 + return info.accept(this, out); 15.245 + } 15.246 + 15.247 + public Integer visitClass(CONSTANT_Class_info info, ClassOutputStream out) { 15.248 + out.writeShort(info.name_index); 15.249 + return 1; 15.250 + } 15.251 + 15.252 + public Integer visitDouble(CONSTANT_Double_info info, ClassOutputStream out) { 15.253 + out.writeDouble(info.value); 15.254 + return 2; 15.255 + } 15.256 + 15.257 + public Integer visitFieldref(CONSTANT_Fieldref_info info, ClassOutputStream out) { 15.258 + writeRef(info, out); 15.259 + return 1; 15.260 + } 15.261 + 15.262 + public Integer visitFloat(CONSTANT_Float_info info, ClassOutputStream out) { 15.263 + out.writeFloat(info.value); 15.264 + return 1; 15.265 + } 15.266 + 15.267 + public Integer visitInteger(CONSTANT_Integer_info info, ClassOutputStream out) { 15.268 + out.writeInt(info.value); 15.269 + return 1; 15.270 + } 15.271 + 15.272 + public Integer visitInterfaceMethodref(CONSTANT_InterfaceMethodref_info info, ClassOutputStream out) { 15.273 + writeRef(info, out); 15.274 + return 1; 15.275 + } 15.276 + 15.277 + public Integer visitLong(CONSTANT_Long_info info, ClassOutputStream out) { 15.278 + out.writeLong(info.value); 15.279 + return 2; 15.280 + } 15.281 + 15.282 + public Integer visitNameAndType(CONSTANT_NameAndType_info info, ClassOutputStream out) { 15.283 + out.writeShort(info.name_index); 15.284 + out.writeShort(info.type_index); 15.285 + return 1; 15.286 + } 15.287 + 15.288 + public Integer visitMethodref(CONSTANT_Methodref_info info, ClassOutputStream out) { 15.289 + return writeRef(info, out); 15.290 + } 15.291 + 15.292 + public Integer visitString(CONSTANT_String_info info, ClassOutputStream out) { 15.293 + out.writeShort(info.string_index); 15.294 + return 1; 15.295 + } 15.296 + 15.297 + public Integer visitUtf8(CONSTANT_Utf8_info info, ClassOutputStream out) { 15.298 + out.writeUTF(info.value); 15.299 + return 1; 15.300 + } 15.301 + 15.302 + protected Integer writeRef(CPRefInfo info, ClassOutputStream out) { 15.303 + out.writeShort(info.class_index); 15.304 + out.writeShort(info.name_and_type_index); 15.305 + return 1; 15.306 + } 15.307 + } 15.308 + 15.309 + /** 15.310 + * Writer for the different types of attribute. 15.311 + */ 15.312 + protected static class AttributeWriter implements Attribute.Visitor<Void,ClassOutputStream> { 15.313 + public void write(Attributes attributes, ClassOutputStream out) { 15.314 + int size = attributes.size(); 15.315 + out.writeShort(size); 15.316 + for (Attribute a: attributes) 15.317 + write(a, out); 15.318 + } 15.319 + 15.320 + // Note: due to the use of shared resources, this method is not reentrant. 15.321 + public void write(Attribute attr, ClassOutputStream out) { 15.322 + out.writeShort(attr.attribute_name_index); 15.323 + sharedOut.reset(); 15.324 + attr.accept(this, sharedOut); 15.325 + out.writeInt(sharedOut.size()); 15.326 + sharedOut.writeTo(out); 15.327 + } 15.328 + 15.329 + protected ClassOutputStream sharedOut = new ClassOutputStream(); 15.330 + protected AnnotationWriter annotationWriter = new AnnotationWriter(); 15.331 + 15.332 + public Void visitDefault(DefaultAttribute attr, ClassOutputStream out) { 15.333 + out.write(attr.info, 0, attr.info.length); 15.334 + return null; 15.335 + } 15.336 + 15.337 + public Void visitAnnotationDefault(AnnotationDefault_attribute attr, ClassOutputStream out) { 15.338 + annotationWriter.write(attr.default_value, out); 15.339 + return null; 15.340 + } 15.341 + 15.342 + public Void visitCharacterRangeTable(CharacterRangeTable_attribute attr, ClassOutputStream out) { 15.343 + out.writeShort(attr.character_range_table.length); 15.344 + for (CharacterRangeTable_attribute.Entry e: attr.character_range_table) 15.345 + writeCharacterRangeTableEntry(e, out); 15.346 + return null; 15.347 + } 15.348 + 15.349 + protected void writeCharacterRangeTableEntry(CharacterRangeTable_attribute.Entry entry, ClassOutputStream out) { 15.350 + out.writeShort(entry.start_pc); 15.351 + out.writeShort(entry.end_pc); 15.352 + out.writeInt(entry.character_range_start); 15.353 + out.writeInt(entry.character_range_end); 15.354 + out.writeShort(entry.flags); 15.355 + } 15.356 + 15.357 + public Void visitCode(Code_attribute attr, ClassOutputStream out) { 15.358 + out.writeShort(attr.max_stack); 15.359 + out.writeShort(attr.max_locals); 15.360 + out.writeInt(attr.code.length); 15.361 + out.write(attr.code, 0, attr.code.length); 15.362 + out.writeShort(attr.exception_table.length); 15.363 + for (Code_attribute.Exception_data e: attr.exception_table) 15.364 + writeExceptionTableEntry(e, out); 15.365 + new AttributeWriter().write(attr.attributes, out); 15.366 + return null; 15.367 + } 15.368 + 15.369 + protected void writeExceptionTableEntry(Code_attribute.Exception_data exception_data, ClassOutputStream out) { 15.370 + out.writeShort(exception_data.start_pc); 15.371 + out.writeShort(exception_data.end_pc); 15.372 + out.writeShort(exception_data.handler_pc); 15.373 + out.writeShort(exception_data.catch_type); 15.374 + } 15.375 + 15.376 + public Void visitCompilationID(CompilationID_attribute attr, ClassOutputStream out) { 15.377 + out.writeShort(attr.compilationID_index); 15.378 + return null; 15.379 + } 15.380 + 15.381 + public Void visitConstantValue(ConstantValue_attribute attr, ClassOutputStream out) { 15.382 + out.writeShort(attr.constantvalue_index); 15.383 + return null; 15.384 + } 15.385 + 15.386 + public Void visitDeprecated(Deprecated_attribute attr, ClassOutputStream out) { 15.387 + return null; 15.388 + } 15.389 + 15.390 + public Void visitEnclosingMethod(EnclosingMethod_attribute attr, ClassOutputStream out) { 15.391 + out.writeShort(attr.class_index); 15.392 + out.writeShort(attr.method_index); 15.393 + return null; 15.394 + } 15.395 + 15.396 + public Void visitExceptions(Exceptions_attribute attr, ClassOutputStream out) { 15.397 + out.writeShort(attr.exception_index_table.length); 15.398 + for (int i: attr.exception_index_table) 15.399 + out.writeShort(i); 15.400 + return null; 15.401 + } 15.402 + 15.403 + public Void visitInnerClasses(InnerClasses_attribute attr, ClassOutputStream out) { 15.404 + out.writeShort(attr.classes.length); 15.405 + for (InnerClasses_attribute.Info info: attr.classes) 15.406 + writeInnerClassesInfo(info, out); 15.407 + return null; 15.408 + } 15.409 + 15.410 + protected void writeInnerClassesInfo(InnerClasses_attribute.Info info, ClassOutputStream out) { 15.411 + out.writeShort(info.inner_class_info_index); 15.412 + out.writeShort(info.outer_class_info_index); 15.413 + out.writeShort(info.inner_name_index); 15.414 + writeAccessFlags(info.inner_class_access_flags, out); 15.415 + } 15.416 + 15.417 + public Void visitLineNumberTable(LineNumberTable_attribute attr, ClassOutputStream out) { 15.418 + out.writeShort(attr.line_number_table.length); 15.419 + for (LineNumberTable_attribute.Entry e: attr.line_number_table) 15.420 + writeLineNumberTableEntry(e, out); 15.421 + return null; 15.422 + } 15.423 + 15.424 + protected void writeLineNumberTableEntry(LineNumberTable_attribute.Entry entry, ClassOutputStream out) { 15.425 + out.writeShort(entry.start_pc); 15.426 + out.writeShort(entry.line_number); 15.427 + } 15.428 + 15.429 + public Void visitLocalVariableTable(LocalVariableTable_attribute attr, ClassOutputStream out) { 15.430 + out.writeShort(attr.local_variable_table.length); 15.431 + for (LocalVariableTable_attribute.Entry e: attr.local_variable_table) 15.432 + writeLocalVariableTableEntry(e, out); 15.433 + return null; 15.434 + } 15.435 + 15.436 + protected void writeLocalVariableTableEntry(LocalVariableTable_attribute.Entry entry, ClassOutputStream out) { 15.437 + out.writeShort(entry.start_pc); 15.438 + out.writeShort(entry.length); 15.439 + out.writeShort(entry.name_index); 15.440 + out.writeShort(entry.descriptor_index); 15.441 + out.writeShort(entry.index); 15.442 + } 15.443 + 15.444 + public Void visitLocalVariableTypeTable(LocalVariableTypeTable_attribute attr, ClassOutputStream out) { 15.445 + out.writeByte(attr.local_variable_table.length); 15.446 + for (LocalVariableTypeTable_attribute.Entry e: attr.local_variable_table) 15.447 + writeLocalVariableTypeTableEntry(e, out); 15.448 + return null; 15.449 + } 15.450 + 15.451 + protected void writeLocalVariableTypeTableEntry(LocalVariableTypeTable_attribute.Entry entry, ClassOutputStream out) { 15.452 + out.writeShort(entry.start_pc); 15.453 + out.writeShort(entry.length); 15.454 + out.writeShort(entry.name_index); 15.455 + out.writeShort(entry.signature_index); 15.456 + out.writeShort(entry.index); 15.457 + } 15.458 + 15.459 + public Void visitModule(Module_attribute attr, ClassOutputStream out) { 15.460 + out.writeShort(attr.module_name); 15.461 + return null; 15.462 + } 15.463 + 15.464 + public Void visitModuleExportTable(ModuleExportTable_attribute attr, ClassOutputStream out) { 15.465 + out.writeShort(attr.export_type_table.length); 15.466 + for (int i: attr.export_type_table) 15.467 + out.writeShort(i); 15.468 + return null; 15.469 + } 15.470 + 15.471 + public Void visitModuleMemberTable(ModuleMemberTable_attribute attr, ClassOutputStream out) { 15.472 + out.writeShort(attr.package_member_table.length); 15.473 + for (int i: attr.package_member_table) 15.474 + out.writeShort(i); 15.475 + return null; 15.476 + } 15.477 + 15.478 + public Void visitRuntimeVisibleAnnotations(RuntimeVisibleAnnotations_attribute attr, ClassOutputStream out) { 15.479 + annotationWriter.write(attr.annotations, out); 15.480 + return null; 15.481 + } 15.482 + 15.483 + public Void visitRuntimeInvisibleAnnotations(RuntimeInvisibleAnnotations_attribute attr, ClassOutputStream out) { 15.484 + annotationWriter.write(attr.annotations, out); 15.485 + return null; 15.486 + } 15.487 + 15.488 + public Void visitRuntimeVisibleParameterAnnotations(RuntimeVisibleParameterAnnotations_attribute attr, ClassOutputStream out) { 15.489 + out.writeByte(attr.parameter_annotations.length); 15.490 + for (Annotation[] annos: attr.parameter_annotations) 15.491 + annotationWriter.write(annos, out); 15.492 + return null; 15.493 + } 15.494 + 15.495 + public Void visitRuntimeInvisibleParameterAnnotations(RuntimeInvisibleParameterAnnotations_attribute attr, ClassOutputStream out) { 15.496 + out.writeByte(attr.parameter_annotations.length); 15.497 + for (Annotation[] annos: attr.parameter_annotations) 15.498 + annotationWriter.write(annos, out); 15.499 + return null; 15.500 + } 15.501 + 15.502 + public Void visitSignature(Signature_attribute attr, ClassOutputStream out) { 15.503 + out.writeShort(attr.signature_index); 15.504 + return null; 15.505 + } 15.506 + 15.507 + public Void visitSourceDebugExtension(SourceDebugExtension_attribute attr, ClassOutputStream out) { 15.508 + out.write(attr.debug_extension, 0, attr.debug_extension.length); 15.509 + return null; 15.510 + } 15.511 + 15.512 + public Void visitSourceFile(SourceFile_attribute attr, ClassOutputStream out) { 15.513 + out.writeShort(attr.sourcefile_index); 15.514 + return null; 15.515 + } 15.516 + 15.517 + public Void visitSourceID(SourceID_attribute attr, ClassOutputStream out) { 15.518 + out.writeShort(attr.sourceID_index); 15.519 + return null; 15.520 + } 15.521 + 15.522 + public Void visitStackMap(StackMap_attribute attr, ClassOutputStream out) { 15.523 + if (stackMapWriter == null) 15.524 + stackMapWriter = new StackMapTableWriter(); 15.525 + 15.526 + out.writeShort(attr.entries.length); 15.527 + for (stack_map_frame f: attr.entries) 15.528 + stackMapWriter.write(f, out); 15.529 + return null; 15.530 + } 15.531 + 15.532 + public Void visitStackMapTable(StackMapTable_attribute attr, ClassOutputStream out) { 15.533 + if (stackMapWriter == null) 15.534 + stackMapWriter = new StackMapTableWriter(); 15.535 + 15.536 + out.writeShort(attr.entries.length); 15.537 + for (stack_map_frame f: attr.entries) 15.538 + stackMapWriter.write(f, out); 15.539 + return null; 15.540 + } 15.541 + 15.542 + public Void visitSynthetic(Synthetic_attribute attr, ClassOutputStream out) { 15.543 + return null; 15.544 + } 15.545 + 15.546 + protected void writeAccessFlags(AccessFlags flags, ClassOutputStream p) { 15.547 + sharedOut.writeShort(flags.flags); 15.548 + } 15.549 + 15.550 + protected StackMapTableWriter stackMapWriter; 15.551 + } 15.552 + 15.553 + /** 15.554 + * Writer for the frames of StackMap and StackMapTable attributes. 15.555 + */ 15.556 + protected static class StackMapTableWriter 15.557 + implements stack_map_frame.Visitor<Void,ClassOutputStream> { 15.558 + 15.559 + public void write(stack_map_frame frame, ClassOutputStream out) { 15.560 + out.write(frame.frame_type); 15.561 + frame.accept(this, out); 15.562 + } 15.563 + 15.564 + public Void visit_same_frame(same_frame frame, ClassOutputStream p) { 15.565 + return null; 15.566 + } 15.567 + 15.568 + public Void visit_same_locals_1_stack_item_frame(same_locals_1_stack_item_frame frame, ClassOutputStream out) { 15.569 + writeVerificationTypeInfo(frame.stack[0], out); 15.570 + return null; 15.571 + } 15.572 + 15.573 + public Void visit_same_locals_1_stack_item_frame_extended(same_locals_1_stack_item_frame_extended frame, ClassOutputStream out) { 15.574 + out.writeShort(frame.offset_delta); 15.575 + writeVerificationTypeInfo(frame.stack[0], out); 15.576 + return null; 15.577 + } 15.578 + 15.579 + public Void visit_chop_frame(chop_frame frame, ClassOutputStream out) { 15.580 + out.writeShort(frame.offset_delta); 15.581 + return null; 15.582 + } 15.583 + 15.584 + public Void visit_same_frame_extended(same_frame_extended frame, ClassOutputStream out) { 15.585 + out.writeShort(frame.offset_delta); 15.586 + return null; 15.587 + } 15.588 + 15.589 + public Void visit_append_frame(append_frame frame, ClassOutputStream out) { 15.590 + out.writeShort(frame.offset_delta); 15.591 + for (verification_type_info l: frame.locals) 15.592 + writeVerificationTypeInfo(l, out); 15.593 + return null; 15.594 + } 15.595 + 15.596 + public Void visit_full_frame(full_frame frame, ClassOutputStream out) { 15.597 + out.writeShort(frame.offset_delta); 15.598 + out.writeShort(frame.locals.length); 15.599 + for (verification_type_info l: frame.locals) 15.600 + writeVerificationTypeInfo(l, out); 15.601 + out.writeShort(frame.stack.length); 15.602 + for (verification_type_info s: frame.stack) 15.603 + writeVerificationTypeInfo(s, out); 15.604 + return null; 15.605 + } 15.606 + 15.607 + protected void writeVerificationTypeInfo(verification_type_info info, 15.608 + ClassOutputStream out) { 15.609 + out.write(info.tag); 15.610 + switch (info.tag) { 15.611 + case ITEM_Top: 15.612 + case ITEM_Integer: 15.613 + case ITEM_Float: 15.614 + case ITEM_Long: 15.615 + case ITEM_Double: 15.616 + case ITEM_Null: 15.617 + case ITEM_UninitializedThis: 15.618 + break; 15.619 + 15.620 + case ITEM_Object: 15.621 + Object_variable_info o = (Object_variable_info) info; 15.622 + out.writeShort(o.cpool_index); 15.623 + break; 15.624 + 15.625 + case ITEM_Uninitialized: 15.626 + Uninitialized_variable_info u = (Uninitialized_variable_info) info; 15.627 + out.writeShort(u.offset); 15.628 + break; 15.629 + 15.630 + default: 15.631 + throw new Error(); 15.632 + } 15.633 + } 15.634 + } 15.635 + 15.636 + /** 15.637 + * Writer for annotations and the values they contain. 15.638 + */ 15.639 + protected static class AnnotationWriter 15.640 + implements Annotation.element_value.Visitor<Void,ClassOutputStream> { 15.641 + public void write(Annotation[] annos, ClassOutputStream out) { 15.642 + out.writeShort(annos.length); 15.643 + for (Annotation anno: annos) 15.644 + write(anno, out); 15.645 + } 15.646 + 15.647 + public void write(Annotation anno, ClassOutputStream out) { 15.648 + out.writeShort(anno.type_index); 15.649 + out.writeShort(anno.element_value_pairs.length); 15.650 + for (element_value_pair p: anno.element_value_pairs) 15.651 + write(p, out); 15.652 + } 15.653 + 15.654 + public void write(element_value_pair pair, ClassOutputStream out) { 15.655 + out.writeShort(pair.element_name_index); 15.656 + write(pair.value, out); 15.657 + } 15.658 + 15.659 + public void write(element_value ev, ClassOutputStream out) { 15.660 + out.writeByte(ev.tag); 15.661 + ev.accept(this, out); 15.662 + } 15.663 + 15.664 + public Void visitPrimitive(Primitive_element_value ev, ClassOutputStream out) { 15.665 + out.writeShort(ev.const_value_index); 15.666 + return null; 15.667 + } 15.668 + 15.669 + public Void visitEnum(Enum_element_value ev, ClassOutputStream out) { 15.670 + out.writeShort(ev.type_name_index); 15.671 + out.writeShort(ev.const_name_index); 15.672 + return null; 15.673 + } 15.674 + 15.675 + public Void visitClass(Class_element_value ev, ClassOutputStream out) { 15.676 + out.writeShort(ev.class_info_index); 15.677 + return null; 15.678 + } 15.679 + 15.680 + public Void visitAnnotation(Annotation_element_value ev, ClassOutputStream out) { 15.681 + write(ev.annotation_value, out); 15.682 + return null; 15.683 + } 15.684 + 15.685 + public Void visitArray(Array_element_value ev, ClassOutputStream out) { 15.686 + out.writeShort(ev.num_values); 15.687 + for (element_value v: ev.values) 15.688 + write(v, out); 15.689 + return null; 15.690 + } 15.691 + } 15.692 +}
16.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 16.2 +++ b/src/share/classes/com/sun/tools/classfile/Code_attribute.java Tue Jun 03 13:26:47 2008 -0700 16.3 @@ -0,0 +1,123 @@ 16.4 +/* 16.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. 16.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 16.7 + * 16.8 + * This code is free software; you can redistribute it and/or modify it 16.9 + * under the terms of the GNU General Public License version 2 only, as 16.10 + * published by the Free Software Foundation. Sun designates this 16.11 + * particular file as subject to the "Classpath" exception as provided 16.12 + * by Sun in the LICENSE file that accompanied this code. 16.13 + * 16.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 16.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 16.17 + * version 2 for more details (a copy is included in the LICENSE file that 16.18 + * accompanied this code). 16.19 + * 16.20 + * You should have received a copy of the GNU General Public License version 16.21 + * 2 along with this work; if not, write to the Free Software Foundation, 16.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 16.23 + * 16.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 16.25 + * CA 95054 USA or visit www.sun.com if you need additional information or 16.26 + * have any questions. 16.27 + */ 16.28 + 16.29 +package com.sun.tools.classfile; 16.30 + 16.31 +import java.io.IOException; 16.32 + 16.33 +/** 16.34 + * See JVMS3, section 4.8.3. 16.35 + * 16.36 + * <p><b>This is NOT part of any API supported by Sun Microsystems. If 16.37 + * you write code that depends on this, you do so at your own risk. 16.38 + * This code and its internal interfaces are subject to change or 16.39 + * deletion without notice.</b> 16.40 + */ 16.41 +public class Code_attribute extends Attribute { 16.42 + public class InvalidIndex extends AttributeException { 16.43 + InvalidIndex(int index) { 16.44 + this.index = index; 16.45 + } 16.46 + 16.47 + @Override 16.48 + public String getMessage() { 16.49 + // i18n 16.50 + return "invalid index " + index + " in Code attribute"; 16.51 + } 16.52 + 16.53 + public final int index; 16.54 + } 16.55 + 16.56 + Code_attribute(ClassReader cr, int name_index, int length) 16.57 + throws IOException, ConstantPoolException { 16.58 + super(name_index, length); 16.59 + max_stack = cr.readUnsignedShort(); 16.60 + max_locals = cr.readUnsignedShort(); 16.61 + code_length = cr.readInt(); 16.62 + code = new byte[code_length]; 16.63 + cr.readFully(code); 16.64 + exception_table_langth = cr.readUnsignedShort(); 16.65 + exception_table = new Exception_data[exception_table_langth]; 16.66 + for (int i = 0; i < exception_table_langth; i++) 16.67 + exception_table[i] = new Exception_data(cr); 16.68 + attributes = new Attributes(cr); 16.69 + } 16.70 + 16.71 + public int getByte(int offset) throws InvalidIndex { 16.72 + if (offset < 0 || offset >= code.length) 16.73 + throw new InvalidIndex(offset); 16.74 + return code[offset]; 16.75 + } 16.76 + 16.77 + public int getUnsignedByte(int offset) throws InvalidIndex { 16.78 + if (offset < 0 || offset >= code.length) 16.79 + throw new InvalidIndex(offset); 16.80 + return code[offset] & 0xff; 16.81 + } 16.82 + 16.83 + public int getShort(int offset) throws InvalidIndex { 16.84 + if (offset < 0 || offset + 1 >= code.length) 16.85 + throw new InvalidIndex(offset); 16.86 + return (code[offset] << 8) | (code[offset + 1] & 0xFF); 16.87 + } 16.88 + 16.89 + public int getUnsignedShort(int offset) throws InvalidIndex { 16.90 + if (offset < 0 || offset + 1 >= code.length) 16.91 + throw new InvalidIndex(offset); 16.92 + return ((code[offset] << 8) | (code[offset + 1] & 0xFF)) & 0xFFFF; 16.93 + } 16.94 + 16.95 + public int getInt(int offset) throws InvalidIndex { 16.96 + if (offset < 0 || offset + 3 >= code.length) 16.97 + throw new InvalidIndex(offset); 16.98 + return (getShort(offset) << 16) | (getShort(offset + 2) & 0xFFFF); 16.99 + } 16.100 + 16.101 + public <R, D> R accept(Visitor<R, D> visitor, D data) { 16.102 + return visitor.visitCode(this, data); 16.103 + } 16.104 + 16.105 + public final int max_stack; 16.106 + public final int max_locals; 16.107 + public final int code_length; 16.108 + public final byte[] code; 16.109 + public final int exception_table_langth; 16.110 + public final Exception_data[] exception_table; 16.111 + public final Attributes attributes; 16.112 + 16.113 + public class Exception_data { 16.114 + Exception_data(ClassReader cr) throws IOException { 16.115 + start_pc = cr.readUnsignedShort(); 16.116 + end_pc = cr.readUnsignedShort(); 16.117 + handler_pc = cr.readUnsignedShort(); 16.118 + catch_type = cr.readUnsignedShort(); 16.119 + } 16.120 + 16.121 + public final int start_pc; 16.122 + public final int end_pc; 16.123 + public final int handler_pc; 16.124 + public final int catch_type; 16.125 + } 16.126 +}
17.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 17.2 +++ b/src/share/classes/com/sun/tools/classfile/CompilationID_attribute.java Tue Jun 03 13:26:47 2008 -0700 17.3 @@ -0,0 +1,62 @@ 17.4 +/* 17.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. 17.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 17.7 + * 17.8 + * This code is free software; you can redistribute it and/or modify it 17.9 + * under the terms of the GNU General Public License version 2 only, as 17.10 + * published by the Free Software Foundation. Sun designates this 17.11 + * particular file as subject to the "Classpath" exception as provided 17.12 + * by Sun in the LICENSE file that accompanied this code. 17.13 + * 17.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 17.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 17.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 17.17 + * version 2 for more details (a copy is included in the LICENSE file that 17.18 + * accompanied this code). 17.19 + * 17.20 + * You should have received a copy of the GNU General Public License version 17.21 + * 2 along with this work; if not, write to the Free Software Foundation, 17.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 17.23 + * 17.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 17.25 + * CA 95054 USA or visit www.sun.com if you need additional information or 17.26 + * have any questions. 17.27 + */ 17.28 +package com.sun.tools.classfile; 17.29 + 17.30 +import java.io.IOException; 17.31 + 17.32 +/** 17.33 + * <p><b>This is NOT part of any API supported by Sun Microsystems. If 17.34 + * you write code that depends on this, you do so at your own risk. 17.35 + * This code and its internal interfaces are subject to change or 17.36 + * deletion without notice.</b> 17.37 + */ 17.38 +public class CompilationID_attribute extends Attribute { 17.39 + 17.40 + CompilationID_attribute(ClassReader cr, int name_index, int length) throws IOException { 17.41 + super(name_index, length); 17.42 + compilationID_index = cr.readUnsignedShort(); 17.43 + } 17.44 + 17.45 + public CompilationID_attribute(ConstantPool constant_pool, int compilationID_index) 17.46 + throws ConstantPoolException { 17.47 + this(constant_pool.getUTF8Index(Attribute.CompilationID), compilationID_index); 17.48 + } 17.49 + 17.50 + public CompilationID_attribute(int name_index, int compilationID_index) { 17.51 + super(name_index, 2); 17.52 + this.compilationID_index = compilationID_index; 17.53 + } 17.54 + 17.55 + String getCompilationID(ConstantPool constant_pool) 17.56 + throws ConstantPoolException { 17.57 + return constant_pool.getUTF8Value(compilationID_index); 17.58 + } 17.59 + 17.60 + public <R, D> R accept(Visitor<R, D> visitor, D data) { 17.61 + return visitor.visitCompilationID(this, data); 17.62 + } 17.63 + 17.64 + public final int compilationID_index; 17.65 +}
18.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 18.2 +++ b/src/share/classes/com/sun/tools/classfile/ConstantPool.java Tue Jun 03 13:26:47 2008 -0700 18.3 @@ -0,0 +1,562 @@ 18.4 +/* 18.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. 18.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 18.7 + * 18.8 + * This code is free software; you can redistribute it and/or modify it 18.9 + * under the terms of the GNU General Public License version 2 only, as 18.10 + * published by the Free Software Foundation. Sun designates this 18.11 + * particular file as subject to the "Classpath" exception as provided 18.12 + * by Sun in the LICENSE file that accompanied this code. 18.13 + * 18.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 18.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 18.17 + * version 2 for more details (a copy is included in the LICENSE file that 18.18 + * accompanied this code). 18.19 + * 18.20 + * You should have received a copy of the GNU General Public License version 18.21 + * 2 along with this work; if not, write to the Free Software Foundation, 18.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18.23 + * 18.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 18.25 + * CA 95054 USA or visit www.sun.com if you need additional information or 18.26 + * have any questions. 18.27 + */ 18.28 + 18.29 +package com.sun.tools.classfile; 18.30 + 18.31 +import java.io.IOException; 18.32 + 18.33 +/** 18.34 + * See JVMS3, section 4.5. 18.35 + * 18.36 + * <p><b>This is NOT part of any API supported by Sun Microsystems. If 18.37 + * you write code that depends on this, you do so at your own risk. 18.38 + * This code and its internal interfaces are subject to change or 18.39 + * deletion without notice.</b> 18.40 + */ 18.41 +public class ConstantPool { 18.42 + 18.43 + public class InvalidIndex extends ConstantPoolException { 18.44 + InvalidIndex(int index) { 18.45 + super(index); 18.46 + } 18.47 + 18.48 + @Override 18.49 + public String getMessage() { 18.50 + // i18n 18.51 + return "invalid index #" + index; 18.52 + } 18.53 + } 18.54 + 18.55 + public class UnexpectedEntry extends ConstantPoolException { 18.56 + UnexpectedEntry(int index, int expected_tag, int found_tag) { 18.57 + super(index); 18.58 + this.expected_tag = expected_tag; 18.59 + this.found_tag = found_tag; 18.60 + } 18.61 + 18.62 + @Override 18.63 + public String getMessage() { 18.64 + // i18n? 18.65 + return "unexpected entry at #" + index + " -- expected tag " + expected_tag + ", found " + found_tag; 18.66 + } 18.67 + 18.68 + public final int expected_tag; 18.69 + public final int found_tag; 18.70 + } 18.71 + 18.72 + public class InvalidEntry extends ConstantPoolException { 18.73 + InvalidEntry(int index, int tag) { 18.74 + super(index); 18.75 + this.tag = tag; 18.76 + } 18.77 + 18.78 + @Override 18.79 + public String getMessage() { 18.80 + // i18n? 18.81 + return "unexpected tag at #" + index + ": " + tag; 18.82 + } 18.83 + 18.84 + public final int tag; 18.85 + } 18.86 + 18.87 + public class EntryNotFound extends ConstantPoolException { 18.88 + EntryNotFound(Object value) { 18.89 + super(-1); 18.90 + this.value = value; 18.91 + } 18.92 + 18.93 + @Override 18.94 + public String getMessage() { 18.95 + // i18n? 18.96 + return "value not found: " + value; 18.97 + } 18.98 + 18.99 + public final Object value; 18.100 + } 18.101 + 18.102 + public static final int CONSTANT_Utf8 = 1; 18.103 + public static final int CONSTANT_Integer = 3; 18.104 + public static final int CONSTANT_Float = 4; 18.105 + public static final int CONSTANT_Long = 5; 18.106 + public static final int CONSTANT_Double = 6; 18.107 + public static final int CONSTANT_Class = 7; 18.108 + public static final int CONSTANT_String = 8; 18.109 + public static final int CONSTANT_Fieldref = 9; 18.110 + public static final int CONSTANT_Methodref = 10; 18.111 + public static final int CONSTANT_InterfaceMethodref = 11; 18.112 + public static final int CONSTANT_NameAndType = 12; 18.113 + 18.114 + ConstantPool(ClassReader cr) throws IOException, InvalidEntry { 18.115 + int count = cr.readUnsignedShort(); 18.116 + pool = new CPInfo[count]; 18.117 + for (int i = 1; i < count; i++) { 18.118 + int tag = cr.readUnsignedByte(); 18.119 + switch (tag) { 18.120 + case CONSTANT_Class: 18.121 + pool[i] = new CONSTANT_Class_info(this, cr); 18.122 + break; 18.123 + 18.124 + case CONSTANT_Double: 18.125 + pool[i] = new CONSTANT_Double_info(cr); 18.126 + i++; 18.127 + break; 18.128 + 18.129 + case CONSTANT_Fieldref: 18.130 + pool[i] = new CONSTANT_Fieldref_info(this, cr); 18.131 + break; 18.132 + 18.133 + case CONSTANT_Float: 18.134 + pool[i] = new CONSTANT_Float_info(cr); 18.135 + break; 18.136 + 18.137 + case CONSTANT_Integer: 18.138 + pool[i] = new CONSTANT_Integer_info(cr); 18.139 + break; 18.140 + 18.141 + case CONSTANT_InterfaceMethodref: 18.142 + pool[i] = new CONSTANT_InterfaceMethodref_info(this, cr); 18.143 + break; 18.144 + 18.145 + case CONSTANT_Long: 18.146 + pool[i] = new CONSTANT_Long_info(cr); 18.147 + i++; 18.148 + break; 18.149 + 18.150 + case CONSTANT_Methodref: 18.151 + pool[i] = new CONSTANT_Methodref_info(this, cr); 18.152 + break; 18.153 + 18.154 + case CONSTANT_NameAndType: 18.155 + pool[i] = new CONSTANT_NameAndType_info(this, cr); 18.156 + break; 18.157 + 18.158 + case CONSTANT_String: 18.159 + pool[i] = new CONSTANT_String_info(cr); 18.160 + break; 18.161 + 18.162 + case CONSTANT_Utf8: 18.163 + pool[i] = new CONSTANT_Utf8_info(cr); 18.164 + break; 18.165 + 18.166 + default: 18.167 + throw new InvalidEntry(i, tag); 18.168 + } 18.169 + } 18.170 + } 18.171 + 18.172 + public ConstantPool(CPInfo[] pool) { 18.173 + this.pool = pool; 18.174 + } 18.175 + 18.176 + public int size() { 18.177 + return pool.length; 18.178 + } 18.179 + 18.180 + public CPInfo get(int index) throws InvalidIndex { 18.181 + if (index <= 0 || index >= pool.length) 18.182 + throw new InvalidIndex(index); 18.183 + CPInfo info = pool[index]; 18.184 + if (info == null) { 18.185 + // this occurs for indices referencing the "second half" of an 18.186 + // 8 byte constant, such as CONSTANT_Double or CONSTANT_Long 18.187 + throw new InvalidIndex(index); 18.188 + } 18.189 + return pool[index]; 18.190 + } 18.191 + 18.192 + private CPInfo get(int index, int expected_type) throws InvalidIndex, UnexpectedEntry { 18.193 + CPInfo info = get(index); 18.194 + if (info.getTag() != expected_type) 18.195 + throw new UnexpectedEntry(index, expected_type, info.getTag()); 18.196 + return info; 18.197 + } 18.198 + 18.199 + public CONSTANT_Utf8_info getUTF8Info(int index) throws InvalidIndex, UnexpectedEntry { 18.200 + return ((CONSTANT_Utf8_info) get(index, CONSTANT_Utf8)); 18.201 + } 18.202 + 18.203 + public CONSTANT_Class_info getClassInfo(int index) throws InvalidIndex, UnexpectedEntry { 18.204 + return ((CONSTANT_Class_info) get(index, CONSTANT_Class)); 18.205 + } 18.206 + 18.207 + public CONSTANT_NameAndType_info getNameAndTypeInfo(int index) throws InvalidIndex, UnexpectedEntry { 18.208 + return ((CONSTANT_NameAndType_info) get(index, CONSTANT_NameAndType)); 18.209 + } 18.210 + 18.211 + public String getUTF8Value(int index) throws InvalidIndex, UnexpectedEntry { 18.212 + return getUTF8Info(index).value; 18.213 + } 18.214 + 18.215 + public int getUTF8Index(String value) throws EntryNotFound { 18.216 + for (int i = 1; i < pool.length; i++) { 18.217 + CPInfo info = pool[i]; 18.218 + if (info instanceof CONSTANT_Utf8_info && 18.219 + ((CONSTANT_Utf8_info) info).value.equals(value)) 18.220 + return i; 18.221 + } 18.222 + throw new EntryNotFound(value); 18.223 + } 18.224 + 18.225 + private CPInfo[] pool; 18.226 + 18.227 + public interface Visitor<R,P> { 18.228 + R visitClass(CONSTANT_Class_info info, P p); 18.229 + R visitDouble(CONSTANT_Double_info info, P p); 18.230 + R visitFieldref(CONSTANT_Fieldref_info info, P p); 18.231 + R visitFloat(CONSTANT_Float_info info, P p); 18.232 + R visitInteger(CONSTANT_Integer_info info, P p); 18.233 + R visitInterfaceMethodref(CONSTANT_InterfaceMethodref_info info, P p); 18.234 + R visitLong(CONSTANT_Long_info info, P p); 18.235 + R visitNameAndType(CONSTANT_NameAndType_info info, P p); 18.236 + R visitMethodref(CONSTANT_Methodref_info info, P p); 18.237 + R visitString(CONSTANT_String_info info, P p); 18.238 + R visitUtf8(CONSTANT_Utf8_info info, P p); 18.239 + } 18.240 + 18.241 + public static abstract class CPInfo { 18.242 + CPInfo() { 18.243 + this.cp = null; 18.244 + } 18.245 + 18.246 + CPInfo(ConstantPool cp) { 18.247 + this.cp = cp; 18.248 + } 18.249 + 18.250 + public abstract int getTag(); 18.251 + 18.252 + public abstract <R,D> R accept(Visitor<R,D> visitor, D data); 18.253 + 18.254 + protected final ConstantPool cp; 18.255 + } 18.256 + 18.257 + public static abstract class CPRefInfo extends CPInfo { 18.258 + protected CPRefInfo(ConstantPool cp, ClassReader cr, int tag) throws IOException { 18.259 + super(cp); 18.260 + this.tag = tag; 18.261 + class_index = cr.readUnsignedShort(); 18.262 + name_and_type_index = cr.readUnsignedShort(); 18.263 + } 18.264 + 18.265 + protected CPRefInfo(ConstantPool cp, int tag, int class_index, int name_and_type_index) { 18.266 + super(cp); 18.267 + this.tag = tag; 18.268 + this.class_index = class_index; 18.269 + this.name_and_type_index = name_and_type_index; 18.270 + } 18.271 + 18.272 + public int getTag() { 18.273 + return tag; 18.274 + } 18.275 + 18.276 + public CONSTANT_Class_info getClassInfo() throws ConstantPoolException { 18.277 + return cp.getClassInfo(class_index); 18.278 + } 18.279 + 18.280 + public String getClassName() throws ConstantPoolException { 18.281 + return cp.getClassInfo(class_index).getName(); 18.282 + } 18.283 + 18.284 + public CONSTANT_NameAndType_info getNameAndTypeInfo() throws ConstantPoolException { 18.285 + return cp.getNameAndTypeInfo(name_and_type_index); 18.286 + } 18.287 + 18.288 + public final int tag; 18.289 + public final int class_index; 18.290 + public final int name_and_type_index; 18.291 + } 18.292 + 18.293 + public static class CONSTANT_Class_info extends CPInfo { 18.294 + CONSTANT_Class_info(ConstantPool cp, ClassReader cr) throws IOException { 18.295 + super(cp); 18.296 + name_index = cr.readUnsignedShort(); 18.297 + } 18.298 + 18.299 + public CONSTANT_Class_info(ConstantPool cp, int name_index) { 18.300 + super(cp); 18.301 + this.name_index = name_index; 18.302 + } 18.303 + 18.304 + public int getTag() { 18.305 + return CONSTANT_Class; 18.306 + } 18.307 + 18.308 + public String getName() throws ConstantPoolException { 18.309 + return cp.getUTF8Value(name_index); 18.310 + } 18.311 + 18.312 + @Override 18.313 + public String toString() { 18.314 + return "CONSTANT_Class_info[name_index: " + name_index + "]"; 18.315 + } 18.316 + 18.317 + public <R, D> R accept(Visitor<R, D> visitor, D data) { 18.318 + return visitor.visitClass(this, data); 18.319 + } 18.320 + 18.321 + public final int name_index; 18.322 + } 18.323 + 18.324 + public static class CONSTANT_Double_info extends CPInfo { 18.325 + CONSTANT_Double_info(ClassReader cr) throws IOException { 18.326 + value = cr.readDouble(); 18.327 + } 18.328 + 18.329 + public CONSTANT_Double_info(double value) { 18.330 + this.value = value; 18.331 + } 18.332 + 18.333 + public int getTag() { 18.334 + return CONSTANT_Double; 18.335 + } 18.336 + 18.337 + @Override 18.338 + public String toString() { 18.339 + return "CONSTANT_Double_info[value: " + value + "]"; 18.340 + } 18.341 + 18.342 + public <R, D> R accept(Visitor<R, D> visitor, D data) { 18.343 + return visitor.visitDouble(this, data); 18.344 + } 18.345 + 18.346 + public final double value; 18.347 + } 18.348 + 18.349 + public static class CONSTANT_Fieldref_info extends CPRefInfo { 18.350 + CONSTANT_Fieldref_info(ConstantPool cp, ClassReader cr) throws IOException { 18.351 + super(cp, cr, CONSTANT_Fieldref); 18.352 + } 18.353 + 18.354 + public CONSTANT_Fieldref_info(ConstantPool cp, int class_index, int name_and_type_index) { 18.355 + super(cp, CONSTANT_Fieldref, class_index, name_and_type_index); 18.356 + } 18.357 + 18.358 + @Override 18.359 + public String toString() { 18.360 + return "CONSTANT_Fieldref_info[class_index: " + class_index + ", name_and_type_index: " + name_and_type_index + "]"; 18.361 + } 18.362 + 18.363 + public <R, D> R accept(Visitor<R, D> visitor, D data) { 18.364 + return visitor.visitFieldref(this, data); 18.365 + } 18.366 + } 18.367 + 18.368 + public static class CONSTANT_Float_info extends CPInfo { 18.369 + CONSTANT_Float_info(ClassReader cr) throws IOException { 18.370 + value = cr.readFloat(); 18.371 + } 18.372 + 18.373 + public CONSTANT_Float_info(float value) { 18.374 + this.value = value; 18.375 + } 18.376 + 18.377 + public int getTag() { 18.378 + return CONSTANT_Float; 18.379 + } 18.380 + 18.381 + @Override 18.382 + public String toString() { 18.383 + return "CONSTANT_Float_info[value: " + value + "]"; 18.384 + } 18.385 + 18.386 + public <R, D> R accept(Visitor<R, D> visitor, D data) { 18.387 + return visitor.visitFloat(this, data); 18.388 + } 18.389 + 18.390 + public final float value; 18.391 + } 18.392 + 18.393 + public static class CONSTANT_Integer_info extends CPInfo { 18.394 + CONSTANT_Integer_info(ClassReader cr) throws IOException { 18.395 + value = cr.readInt(); 18.396 + } 18.397 + 18.398 + public CONSTANT_Integer_info(int value) { 18.399 + this.value = value; 18.400 + } 18.401 + 18.402 + public int getTag() { 18.403 + return CONSTANT_Integer; 18.404 + } 18.405 + 18.406 + @Override 18.407 + public String toString() { 18.408 + return "CONSTANT_Integer_info[value: " + value + "]"; 18.409 + } 18.410 + 18.411 + public <R, D> R accept(Visitor<R, D> visitor, D data) { 18.412 + return visitor.visitInteger(this, data); 18.413 + } 18.414 + 18.415 + public final int value; 18.416 + } 18.417 + 18.418 + public static class CONSTANT_InterfaceMethodref_info extends CPRefInfo { 18.419 + CONSTANT_InterfaceMethodref_info(ConstantPool cp, ClassReader cr) throws IOException { 18.420 + super(cp, cr, CONSTANT_InterfaceMethodref); 18.421 + } 18.422 + 18.423 + public CONSTANT_InterfaceMethodref_info(ConstantPool cp, int class_index, int name_and_type_index) { 18.424 + super(cp, CONSTANT_InterfaceMethodref, class_index, name_and_type_index); 18.425 + } 18.426 + 18.427 + @Override 18.428 + public String toString() { 18.429 + return "CONSTANT_InterfaceMethodref_info[class_index: " + class_index + ", name_and_type_index: " + name_and_type_index + "]"; 18.430 + } 18.431 + 18.432 + public <R, D> R accept(Visitor<R, D> visitor, D data) { 18.433 + return visitor.visitInterfaceMethodref(this, data); 18.434 + } 18.435 + } 18.436 + 18.437 + public static class CONSTANT_Long_info extends CPInfo { 18.438 + CONSTANT_Long_info(ClassReader cr) throws IOException { 18.439 + value = cr.readLong(); 18.440 + } 18.441 + 18.442 + public CONSTANT_Long_info(long value) { 18.443 + this.value = value; 18.444 + } 18.445 + 18.446 + public int getTag() { 18.447 + return CONSTANT_Long; 18.448 + } 18.449 + 18.450 + @Override 18.451 + public String toString() { 18.452 + return "CONSTANT_Long_info[value: " + value + "]"; 18.453 + } 18.454 + 18.455 + public <R, D> R accept(Visitor<R, D> visitor, D data) { 18.456 + return visitor.visitLong(this, data); 18.457 + } 18.458 + 18.459 + public final long value; 18.460 + } 18.461 + 18.462 + public static class CONSTANT_Methodref_info extends CPRefInfo { 18.463 + CONSTANT_Methodref_info(ConstantPool cp, ClassReader cr) throws IOException { 18.464 + super(cp, cr, CONSTANT_Methodref); 18.465 + } 18.466 + 18.467 + public CONSTANT_Methodref_info(ConstantPool cp, int class_index, int name_and_type_index) { 18.468 + super(cp, CONSTANT_Methodref, class_index, name_and_type_index); 18.469 + } 18.470 + 18.471 + @Override 18.472 + public String toString() { 18.473 + return "CONSTANT_Methodref_info[class_index: " + class_index + ", name_and_type_index: " + name_and_type_index + "]"; 18.474 + } 18.475 + 18.476 + public <R, D> R accept(Visitor<R, D> visitor, D data) { 18.477 + return visitor.visitMethodref(this, data); 18.478 + } 18.479 + } 18.480 + 18.481 + public static class CONSTANT_NameAndType_info extends CPInfo { 18.482 + CONSTANT_NameAndType_info(ConstantPool cp, ClassReader cr) throws IOException { 18.483 + super(cp); 18.484 + name_index = cr.readUnsignedShort(); 18.485 + type_index = cr.readUnsignedShort(); 18.486 + } 18.487 + 18.488 + public CONSTANT_NameAndType_info(ConstantPool cp, int name_index, int type_index) { 18.489 + super(cp); 18.490 + this.name_index = name_index; 18.491 + this.type_index = type_index; 18.492 + } 18.493 + 18.494 + public int getTag() { 18.495 + return CONSTANT_NameAndType; 18.496 + } 18.497 + 18.498 + public String getName() throws ConstantPoolException { 18.499 + return cp.getUTF8Value(name_index); 18.500 + } 18.501 + 18.502 + public String getType() throws ConstantPoolException { 18.503 + return cp.getUTF8Value(type_index); 18.504 + } 18.505 + 18.506 + public <R, D> R accept(Visitor<R, D> visitor, D data) { 18.507 + return visitor.visitNameAndType(this, data); 18.508 + } 18.509 + 18.510 + public final int name_index; 18.511 + public final int type_index; 18.512 + } 18.513 + 18.514 + public static class CONSTANT_String_info extends CPInfo { 18.515 + CONSTANT_String_info(ClassReader cr) throws IOException { 18.516 + string_index = cr.readUnsignedShort(); 18.517 + } 18.518 + 18.519 + public CONSTANT_String_info(ConstantPool cp, int string_index) { 18.520 + super(cp); 18.521 + this.string_index = string_index; 18.522 + } 18.523 + 18.524 + public int getTag() { 18.525 + return CONSTANT_String; 18.526 + } 18.527 + 18.528 + public String getString() throws ConstantPoolException { 18.529 + return cp.getUTF8Value(string_index); 18.530 + } 18.531 + 18.532 + public <R, D> R accept(Visitor<R, D> visitor, D data) { 18.533 + return visitor.visitString(this, data); 18.534 + } 18.535 + 18.536 + public final int string_index; 18.537 + } 18.538 + 18.539 + public static class CONSTANT_Utf8_info extends CPInfo { 18.540 + CONSTANT_Utf8_info(ClassReader cr) throws IOException { 18.541 + value = cr.readUTF(); 18.542 + } 18.543 + 18.544 + public CONSTANT_Utf8_info(String value) { 18.545 + this.value = value; 18.546 + } 18.547 + 18.548 + public int getTag() { 18.549 + return CONSTANT_Utf8; 18.550 + } 18.551 + 18.552 + @Override 18.553 + public String toString() { 18.554 + return "CONSTANT_Utf8_info[value: " + value + "]"; 18.555 + } 18.556 + 18.557 + public <R, D> R accept(Visitor<R, D> visitor, D data) { 18.558 + return visitor.visitUtf8(this, data); 18.559 + } 18.560 + 18.561 + public final String value; 18.562 + } 18.563 + 18.564 + 18.565 +}
19.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 19.2 +++ b/src/share/classes/com/sun/tools/classfile/ConstantPoolException.java Tue Jun 03 13:26:47 2008 -0700 19.3 @@ -0,0 +1,41 @@ 19.4 +/* 19.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. 19.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 19.7 + * 19.8 + * This code is free software; you can redistribute it and/or modify it 19.9 + * under the terms of the GNU General Public License version 2 only, as 19.10 + * published by the Free Software Foundation. Sun designates this 19.11 + * particular file as subject to the "Classpath" exception as provided 19.12 + * by Sun in the LICENSE file that accompanied this code. 19.13 + * 19.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 19.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 19.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 19.17 + * version 2 for more details (a copy is included in the LICENSE file that 19.18 + * accompanied this code). 19.19 + * 19.20 + * You should have received a copy of the GNU General Public License version 19.21 + * 2 along with this work; if not, write to the Free Software Foundation, 19.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 19.23 + * 19.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 19.25 + * CA 95054 USA or visit www.sun.com if you need additional information or 19.26 + * have any questions. 19.27 + */ 19.28 + 19.29 + 19.30 +package com.sun.tools.classfile; 19.31 + 19.32 +/* 19.33 + * <p><b>This is NOT part of any API supported by Sun Microsystems. If 19.34 + * you write code that depends on this, you do so at your own risk. 19.35 + * This code and its internal interfaces are subject to change or 19.36 + * deletion without notice.</b> 19.37 + */ 19.38 +public class ConstantPoolException extends Exception { 19.39 + ConstantPoolException(int index) { 19.40 + this.index = index; 19.41 + } 19.42 + 19.43 + public final int index; 19.44 +}
20.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 20.2 +++ b/src/share/classes/com/sun/tools/classfile/ConstantValue_attribute.java Tue Jun 03 13:26:47 2008 -0700 20.3 @@ -0,0 +1,59 @@ 20.4 +/* 20.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. 20.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 20.7 + * 20.8 + * This code is free software; you can redistribute it and/or modify it 20.9 + * under the terms of the GNU General Public License version 2 only, as 20.10 + * published by the Free Software Foundation. Sun designates this 20.11 + * particular file as subject to the "Classpath" exception as provided 20.12 + * by Sun in the LICENSE file that accompanied this code. 20.13 + * 20.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 20.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 20.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 20.17 + * version 2 for more details (a copy is included in the LICENSE file that 20.18 + * accompanied this code). 20.19 + * 20.20 + * You should have received a copy of the GNU General Public License version 20.21 + * 2 along with this work; if not, write to the Free Software Foundation, 20.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20.23 + * 20.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 20.25 + * CA 95054 USA or visit www.sun.com if you need additional information or 20.26 + * have any questions. 20.27 + */ 20.28 + 20.29 +package com.sun.tools.classfile; 20.30 + 20.31 +import java.io.IOException; 20.32 + 20.33 +/** 20.34 + * See JVMS3, section 4.8.2. 20.35 + * 20.36 + * <p><b>This is NOT part of any API supported by Sun Microsystems. If 20.37 + * you write code that depends on this, you do so at your own risk. 20.38 + * This code and its internal interfaces are subject to change or 20.39 + * deletion without notice.</b> 20.40 + */ 20.41 +public class ConstantValue_attribute extends Attribute { 20.42 + ConstantValue_attribute(ClassReader cr, int name_index, int length) throws IOException { 20.43 + super(name_index, length); 20.44 + constantvalue_index = cr.readUnsignedShort(); 20.45 + } 20.46 + 20.47 + public ConstantValue_attribute(ConstantPool constant_pool, int constantvalue_index) 20.48 + throws ConstantPoolException { 20.49 + this(constant_pool.getUTF8Index(Attribute.ConstantValue), constantvalue_index); 20.50 + } 20.51 + 20.52 + public ConstantValue_attribute(int name_index, int constantvalue_index) { 20.53 + super(name_index, 2); 20.54 + this.constantvalue_index = constantvalue_index; 20.55 + } 20.56 + 20.57 + public <R, D> R accept(Visitor<R, D> visitor, D data) { 20.58 + return visitor.visitConstantValue(this, data); 20.59 + } 20.60 + 20.61 + public final int constantvalue_index; 20.62 +}
21.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 21.2 +++ b/src/share/classes/com/sun/tools/classfile/DefaultAttribute.java Tue Jun 03 13:26:47 2008 -0700 21.3 @@ -0,0 +1,50 @@ 21.4 +/* 21.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. 21.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 21.7 + * 21.8 + * This code is free software; you can redistribute it and/or modify it 21.9 + * under the terms of the GNU General Public License version 2 only, as 21.10 + * published by the Free Software Foundation. Sun designates this 21.11 + * particular file as subject to the "Classpath" exception as provided 21.12 + * by Sun in the LICENSE file that accompanied this code. 21.13 + * 21.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 21.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 21.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 21.17 + * version 2 for more details (a copy is included in the LICENSE file that 21.18 + * accompanied this code). 21.19 + * 21.20 + * You should have received a copy of the GNU General Public License version 21.21 + * 2 along with this work; if not, write to the Free Software Foundation, 21.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 21.23 + * 21.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 21.25 + * CA 95054 USA or visit www.sun.com if you need additional information or 21.26 + * have any questions. 21.27 + */ 21.28 + 21.29 +package com.sun.tools.classfile; 21.30 + 21.31 +/* 21.32 + * <p><b>This is NOT part of any API supported by Sun Microsystems. If 21.33 + * you write code that depends on this, you do so at your own risk. 21.34 + * This code and its internal interfaces are subject to change or 21.35 + * deletion without notice.</b> 21.36 + */ 21.37 +public class DefaultAttribute extends Attribute { 21.38 + DefaultAttribute(ClassReader cr, int name_index, byte[] data) { 21.39 + super(name_index, data.length); 21.40 + info = data; 21.41 + } 21.42 + 21.43 + public DefaultAttribute(ConstantPool constant_pool, int name_index, byte[] info) { 21.44 + super(name_index, info.length); 21.45 + this.info = info; 21.46 + } 21.47 + 21.48 + public <R, P> R accept(Visitor<R, P> visitor, P p) { 21.49 + return visitor.visitDefault(this, p); 21.50 + } 21.51 + 21.52 + public final byte[] info; 21.53 +}
22.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 22.2 +++ b/src/share/classes/com/sun/tools/classfile/Deprecated_attribute.java Tue Jun 03 13:26:47 2008 -0700 22.3 @@ -0,0 +1,55 @@ 22.4 +/* 22.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. 22.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 22.7 + * 22.8 + * This code is free software; you can redistribute it and/or modify it 22.9 + * under the terms of the GNU General Public License version 2 only, as 22.10 + * published by the Free Software Foundation. Sun designates this 22.11 + * particular file as subject to the "Classpath" exception as provided 22.12 + * by Sun in the LICENSE file that accompanied this code. 22.13 + * 22.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 22.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 22.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 22.17 + * version 2 for more details (a copy is included in the LICENSE file that 22.18 + * accompanied this code). 22.19 + * 22.20 + * You should have received a copy of the GNU General Public License version 22.21 + * 2 along with this work; if not, write to the Free Software Foundation, 22.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 22.23 + * 22.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 22.25 + * CA 95054 USA or visit www.sun.com if you need additional information or 22.26 + * have any questions. 22.27 + */ 22.28 + 22.29 +package com.sun.tools.classfile; 22.30 + 22.31 +import java.io.IOException; 22.32 + 22.33 +/** 22.34 + * See JVMS3, section 4.8.15. 22.35 + * 22.36 + * <p><b>This is NOT part of any API supported by Sun Microsystems. If 22.37 + * you write code that depends on this, you do so at your own risk. 22.38 + * This code and its internal interfaces are subject to change or 22.39 + * deletion without notice.</b> 22.40 + */ 22.41 +public class Deprecated_attribute extends Attribute { 22.42 + Deprecated_attribute(ClassReader cr, int name_index, int length) throws IOException { 22.43 + super(name_index, length); 22.44 + } 22.45 + 22.46 + public Deprecated_attribute(ConstantPool constant_pool) 22.47 + throws ConstantPoolException { 22.48 + this(constant_pool.getUTF8Index(Attribute.Deprecated)); 22.49 + } 22.50 + 22.51 + public Deprecated_attribute(int name_index) { 22.52 + super(name_index, 0); 22.53 + } 22.54 + 22.55 + public <R, D> R accept(Visitor<R, D> visitor, D data) { 22.56 + return visitor.visitDeprecated(this, data); 22.57 + } 22.58 +}
23.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 23.2 +++ b/src/share/classes/com/sun/tools/classfile/Descriptor.java Tue Jun 03 13:26:47 2008 -0700 23.3 @@ -0,0 +1,198 @@ 23.4 +/* 23.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. 23.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 23.7 + * 23.8 + * This code is free software; you can redistribute it and/or modify it 23.9 + * under the terms of the GNU General Public License version 2 only, as 23.10 + * published by the Free Software Foundation. Sun designates this 23.11 + * particular file as subject to the "Classpath" exception as provided 23.12 + * by Sun in the LICENSE file that accompanied this code. 23.13 + * 23.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 23.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 23.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 23.17 + * version 2 for more details (a copy is included in the LICENSE file that 23.18 + * accompanied this code). 23.19 + * 23.20 + * You should have received a copy of the GNU General Public License version 23.21 + * 2 along with this work; if not, write to the Free Software Foundation, 23.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 23.23 + * 23.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 23.25 + * CA 95054 USA or visit www.sun.com if you need additional information or 23.26 + * have any questions. 23.27 + */ 23.28 + 23.29 + 23.30 +package com.sun.tools.classfile; 23.31 + 23.32 +import java.io.IOException; 23.33 + 23.34 +/** 23.35 + * See JVMS3, section 4.4. 23.36 + * 23.37 + * <p><b>This is NOT part of any API supported by Sun Microsystems. If 23.38 + * you write code that depends on this, you do so at your own risk. 23.39 + * This code and its internal interfaces are subject to change or 23.40 + * deletion without notice.</b> 23.41 + */ 23.42 +public class Descriptor { 23.43 + public class InvalidDescriptor extends DescriptorException { 23.44 + InvalidDescriptor(String desc) { 23.45 + this.desc = desc; 23.46 + this.index = -1; 23.47 + } 23.48 + 23.49 + InvalidDescriptor(String desc, int index) { 23.50 + this.desc = desc; 23.51 + this.index = index; 23.52 + } 23.53 + 23.54 + @Override 23.55 + public String getMessage() { 23.56 + // i18n 23.57 + if (index == -1) 23.58 + return "invalid descriptor \"" + desc + "\""; 23.59 + else 23.60 + return "descriptor is invalid at offset " + index + " in \"" + desc + "\""; 23.61 + } 23.62 + 23.63 + public final String desc; 23.64 + public final int index; 23.65 + 23.66 + } 23.67 + 23.68 + public Descriptor(ClassReader cr) throws IOException { 23.69 + this(cr.readUnsignedShort()); 23.70 + } 23.71 + 23.72 + public Descriptor(int index) { 23.73 + this.index = index; 23.74 + 23.75 + } 23.76 + 23.77 + public String getValue(ConstantPool constant_pool) throws ConstantPoolException { 23.78 + return constant_pool.getUTF8Value(index); 23.79 + } 23.80 + 23.81 + public int getParameterCount(ConstantPool constant_pool) 23.82 + throws ConstantPoolException, InvalidDescriptor { 23.83 + String desc = getValue(constant_pool); 23.84 + int end = desc.indexOf(")"); 23.85 + if (end == -1) 23.86 + throw new InvalidDescriptor(desc); 23.87 + parse(desc, 0, end + 1); 23.88 + return count; 23.89 + 23.90 + } 23.91 + 23.92 + public String getParameterTypes(ConstantPool constant_pool) 23.93 + throws ConstantPoolException, InvalidDescriptor { 23.94 + String desc = getValue(constant_pool); 23.95 + int end = desc.indexOf(")"); 23.96 + if (end == -1) 23.97 + throw new InvalidDescriptor(desc); 23.98 + return parse(desc, 0, end + 1); 23.99 + } 23.100 + 23.101 + public String getReturnType(ConstantPool constant_pool) 23.102 + throws ConstantPoolException, InvalidDescriptor { 23.103 + String desc = getValue(constant_pool); 23.104 + int end = desc.indexOf(")"); 23.105 + if (end == -1) 23.106 + throw new InvalidDescriptor(desc); 23.107 + return parse(desc, end + 1, desc.length()); 23.108 + } 23.109 + 23.110 + public String getFieldType(ConstantPool constant_pool) 23.111 + throws ConstantPoolException, InvalidDescriptor { 23.112 + String desc = getValue(constant_pool); 23.113 + return parse(desc, 0, desc.length()); 23.114 + } 23.115 + 23.116 + private String parse(String desc, int start, int end) 23.117 + throws InvalidDescriptor { 23.118 + int p = start; 23.119 + StringBuffer sb = new StringBuffer(); 23.120 + int dims = 0; 23.121 + count = 0; 23.122 + 23.123 + while (p < end) { 23.124 + String type; 23.125 + char ch; 23.126 + switch (ch = desc.charAt(p++)) { 23.127 + case '(': 23.128 + sb.append('('); 23.129 + continue; 23.130 + 23.131 + case ')': 23.132 + sb.append(')'); 23.133 + continue; 23.134 + 23.135 + case '[': 23.136 + dims++; 23.137 + continue; 23.138 + 23.139 + case 'B': 23.140 + type = "byte"; 23.141 + break; 23.142 + 23.143 + case 'C': 23.144 + type = "char"; 23.145 + break; 23.146 + 23.147 + case 'D': 23.148 + type = "double"; 23.149 + break; 23.150 + 23.151 + case 'F': 23.152 + type = "float"; 23.153 + break; 23.154 + 23.155 + case 'I': 23.156 + type = "int"; 23.157 + break; 23.158 + 23.159 + case 'J': 23.160 + type = "long"; 23.161 + break; 23.162 + 23.163 + case 'L': 23.164 + int sep = desc.indexOf(';', p); 23.165 + if (sep == -1) 23.166 + throw new InvalidDescriptor(desc, p - 1); 23.167 + type = desc.substring(p, sep).replace('/', '.'); 23.168 + p = sep + 1; 23.169 + break; 23.170 + 23.171 + case 'S': 23.172 + type = "short"; 23.173 + break; 23.174 + 23.175 + case 'Z': 23.176 + type = "boolean"; 23.177 + break; 23.178 + 23.179 + case 'V': 23.180 + type = "void"; 23.181 + break; 23.182 + 23.183 + default: 23.184 + throw new InvalidDescriptor(desc, p - 1); 23.185 + } 23.186 + 23.187 + if (sb.length() > 1 && sb.charAt(0) == '(') 23.188 + sb.append(", "); 23.189 + sb.append(type); 23.190 + for ( ; dims > 0; dims-- ) 23.191 + sb.append("[]"); 23.192 + 23.193 + count++; 23.194 + } 23.195 + 23.196 + return sb.toString(); 23.197 + } 23.198 + 23.199 + public final int index; 23.200 + private int count; 23.201 +}
24.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 24.2 +++ b/src/share/classes/com/sun/tools/classfile/DescriptorException.java Tue Jun 03 13:26:47 2008 -0700 24.3 @@ -0,0 +1,36 @@ 24.4 +/* 24.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. 24.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 24.7 + * 24.8 + * This code is free software; you can redistribute it and/or modify it 24.9 + * under the terms of the GNU General Public License version 2 only, as 24.10 + * published by the Free Software Foundation. Sun designates this 24.11 + * particular file as subject to the "Classpath" exception as provided 24.12 + * by Sun in the LICENSE file that accompanied this code. 24.13 + * 24.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 24.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 24.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 24.17 + * version 2 for more details (a copy is included in the LICENSE file that 24.18 + * accompanied this code). 24.19 + * 24.20 + * You should have received a copy of the GNU General Public License version 24.21 + * 2 along with this work; if not, write to the Free Software Foundation, 24.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 24.23 + * 24.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 24.25 + * CA 95054 USA or visit www.sun.com if you need additional information or 24.26 + * have any questions. 24.27 + */ 24.28 + 24.29 + 24.30 +package com.sun.tools.classfile; 24.31 + 24.32 +/* 24.33 + * <p><b>This is NOT part of any API supported by Sun Microsystems. If 24.34 + * you write code that depends on this, you do so at your own risk. 24.35 + * This code and its internal interfaces are subject to change or 24.36 + * deletion without notice.</b> 24.37 + */ 24.38 +public class DescriptorException extends Exception { 24.39 +}
25.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 25.2 +++ b/src/share/classes/com/sun/tools/classfile/EnclosingMethod_attribute.java Tue Jun 03 13:26:47 2008 -0700 25.3 @@ -0,0 +1,73 @@ 25.4 + 25.5 +/* 25.6 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. 25.7 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 25.8 + * 25.9 + * This code is free software; you can redistribute it and/or modify it 25.10 + * under the terms of the GNU General Public License version 2 only, as 25.11 + * published by the Free Software Foundation. Sun designates this 25.12 + * particular file as subject to the "Classpath" exception as provided 25.13 + * by Sun in the LICENSE file that accompanied this code. 25.14 + * 25.15 + * This code is distributed in the hope that it will be useful, but WITHOUT 25.16 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 25.17 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 25.18 + * version 2 for more details (a copy is included in the LICENSE file that 25.19 + * accompanied this code). 25.20 + * 25.21 + * You should have received a copy of the GNU General Public License version 25.22 + * 2 along with this work; if not, write to the Free Software Foundation, 25.23 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 25.24 + * 25.25 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 25.26 + * CA 95054 USA or visit www.sun.com if you need additional information or 25.27 + * have any questions. 25.28 + */ 25.29 + 25.30 +package com.sun.tools.classfile; 25.31 + 25.32 +import java.io.IOException; 25.33 + 25.34 +/** 25.35 + * See JVMS3, section 4.8.7. 25.36 + * 25.37 + * <p><b>This is NOT part of any API supported by Sun Microsystems. If 25.38 + * you write code that depends on this, you do so at your own risk. 25.39 + * This code and its internal interfaces are subject to change or 25.40 + * deletion without notice.</b> 25.41 + */ 25.42 +public class EnclosingMethod_attribute extends Attribute { 25.43 + EnclosingMethod_attribute(ClassReader cr, int name_index, int length) throws IOException { 25.44 + super(name_index, length); 25.45 + class_index = cr.readUnsignedShort(); 25.46 + method_index = cr.readUnsignedShort(); 25.47 + } 25.48 + 25.49 + public EnclosingMethod_attribute(ConstantPool constant_pool, int class_index, int method_index) 25.50 + throws ConstantPoolException { 25.51 + this(constant_pool.getUTF8Index(Attribute.EnclosingMethod), class_index, method_index); 25.52 + } 25.53 + 25.54 + public EnclosingMethod_attribute(int name_index, int class_index, int method_index) { 25.55 + super(name_index, 4); 25.56 + this.class_index = class_index; 25.57 + this.method_index = method_index; 25.58 + } 25.59 + 25.60 + public String getClassName(ConstantPool constant_pool) throws ConstantPoolException { 25.61 + return constant_pool.getClassInfo(class_index).getName(); 25.62 + } 25.63 + 25.64 + public String getMethodName(ConstantPool constant_pool) throws ConstantPoolException { 25.65 + if (method_index == 0) 25.66 + return ""; 25.67 + return constant_pool.getNameAndTypeInfo(method_index).getName(); 25.68 + } 25.69 + 25.70 + public <R, D> R accept(Visitor<R, D> visitor, D data) { 25.71 + return visitor.visitEnclosingMethod(this, data); 25.72 + } 25.73 + 25.74 + public final int class_index; 25.75 + public final int method_index; 25.76 +}
26.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 26.2 +++ b/src/share/classes/com/sun/tools/classfile/Exceptions_attribute.java Tue Jun 03 13:26:47 2008 -0700 26.3 @@ -0,0 +1,69 @@ 26.4 +/* 26.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. 26.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 26.7 + * 26.8 + * This code is free software; you can redistribute it and/or modify it 26.9 + * under the terms of the GNU General Public License version 2 only, as 26.10 + * published by the Free Software Foundation. Sun designates this 26.11 + * particular file as subject to the "Classpath" exception as provided 26.12 + * by Sun in the LICENSE file that accompanied this code. 26.13 + * 26.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 26.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 26.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 26.17 + * version 2 for more details (a copy is included in the LICENSE file that 26.18 + * accompanied this code). 26.19 + * 26.20 + * You should have received a copy of the GNU General Public License version 26.21 + * 2 along with this work; if not, write to the Free Software Foundation, 26.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 26.23 + * 26.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 26.25 + * CA 95054 USA or visit www.sun.com if you need additional information or 26.26 + * have any questions. 26.27 + */ 26.28 + 26.29 +package com.sun.tools.classfile; 26.30 + 26.31 +import java.io.IOException; 26.32 + 26.33 +/** 26.34 + * See JVMS3, section 4.8.5. 26.35 + * 26.36 + * <p><b>This is NOT part of any API supported by Sun Microsystems. If 26.37 + * you write code that depends on this, you do so at your own risk. 26.38 + * This code and its internal interfaces are subject to change or 26.39 + * deletion without notice.</b> 26.40 + */ 26.41 +public class Exceptions_attribute extends Attribute { 26.42 + Exceptions_attribute(ClassReader cr, int name_index, int length) throws IOException { 26.43 + super(name_index, length); 26.44 + number_of_exceptions = cr.readUnsignedShort(); 26.45 + exception_index_table = new int[number_of_exceptions]; 26.46 + for (int i = 0; i < number_of_exceptions; i++) 26.47 + exception_index_table[i] = cr.readUnsignedShort(); 26.48 + } 26.49 + 26.50 + public Exceptions_attribute(ConstantPool constant_pool, int[] exception_index_table) 26.51 + throws ConstantPoolException { 26.52 + this(constant_pool.getUTF8Index(Attribute.Exceptions), exception_index_table); 26.53 + } 26.54 + 26.55 + public Exceptions_attribute(int name_index, int[] exception_index_table) { 26.56 + super(name_index, 2 + 2 * exception_index_table.length); 26.57 + this.number_of_exceptions = exception_index_table.length; 26.58 + this.exception_index_table = exception_index_table; 26.59 + } 26.60 + 26.61 + public String getException(int index, ConstantPool constant_pool) throws ConstantPoolException { 26.62 + int exception_index = exception_index_table[index]; 26.63 + return constant_pool.getClassInfo(exception_index).getName(); 26.64 + } 26.65 + 26.66 + public <R, D> R accept(Visitor<R, D> visitor, D data) { 26.67 + return visitor.visitExceptions(this, data); 26.68 + } 26.69 + 26.70 + public final int number_of_exceptions; 26.71 + public final int[] exception_index_table; 26.72 +}
27.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 27.2 +++ b/src/share/classes/com/sun/tools/classfile/Field.java Tue Jun 03 13:26:47 2008 -0700 27.3 @@ -0,0 +1,61 @@ 27.4 +/* 27.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. 27.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 27.7 + * 27.8 + * This code is free software; you can redistribute it and/or modify it 27.9 + * under the terms of the GNU General Public License version 2 only, as 27.10 + * published by the Free Software Foundation. Sun designates this 27.11 + * particular file as subject to the "Classpath" exception as provided 27.12 + * by Sun in the LICENSE file that accompanied this code. 27.13 + * 27.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 27.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 27.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 27.17 + * version 2 for more details (a copy is included in the LICENSE file that 27.18 + * accompanied this code). 27.19 + * 27.20 + * You should have received a copy of the GNU General Public License version 27.21 + * 2 along with this work; if not, write to the Free Software Foundation, 27.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 27.23 + * 27.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 27.25 + * CA 95054 USA or visit www.sun.com if you need additional information or 27.26 + * have any questions. 27.27 + */ 27.28 + 27.29 +package com.sun.tools.classfile; 27.30 + 27.31 +import java.io.IOException; 27.32 + 27.33 +/* 27.34 + * <p><b>This is NOT part of any API supported by Sun Microsystems. If 27.35 + * you write code that depends on this, you do so at your own risk. 27.36 + * This code and its internal interfaces are subject to change or 27.37 + * deletion without notice.</b> 27.38 + */ 27.39 +public class Field { 27.40 + Field(ClassReader cr) throws IOException { 27.41 + access_flags = new AccessFlags(cr); 27.42 + name_index = cr.readUnsignedShort(); 27.43 + descriptor = new Descriptor(cr); 27.44 + attributes = new Attributes(cr); 27.45 + } 27.46 + 27.47 + public Field(AccessFlags access_flags, 27.48 + int name_index, Descriptor descriptor, 27.49 + Attributes attributes) { 27.50 + this.access_flags = access_flags; 27.51 + this.name_index = name_index; 27.52 + this.descriptor = descriptor; 27.53 + this.attributes = attributes; 27.54 + } 27.55 + 27.56 + public String getName(ConstantPool constant_pool) throws ConstantPoolException { 27.57 + return constant_pool.getUTF8Value(name_index); 27.58 + } 27.59 + 27.60 + public final AccessFlags access_flags; 27.61 + public final int name_index; 27.62 + public final Descriptor descriptor; 27.63 + public final Attributes attributes; 27.64 +}
28.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 28.2 +++ b/src/share/classes/com/sun/tools/classfile/InnerClasses_attribute.java Tue Jun 03 13:26:47 2008 -0700 28.3 @@ -0,0 +1,102 @@ 28.4 +/* 28.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. 28.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 28.7 + * 28.8 + * This code is free software; you can redistribute it and/or modify it 28.9 + * under the terms of the GNU General Public License version 2 only, as 28.10 + * published by the Free Software Foundation. Sun designates this 28.11 + * particular file as subject to the "Classpath" exception as provided 28.12 + * by Sun in the LICENSE file that accompanied this code. 28.13 + * 28.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 28.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 28.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 28.17 + * version 2 for more details (a copy is included in the LICENSE file that 28.18 + * accompanied this code). 28.19 + * 28.20 + * You should have received a copy of the GNU General Public License version 28.21 + * 2 along with this work; if not, write to the Free Software Foundation, 28.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 28.23 + * 28.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 28.25 + * CA 95054 USA or visit www.sun.com if you need additional information or 28.26 + * have any questions. 28.27 + */ 28.28 + 28.29 +package com.sun.tools.classfile; 28.30 + 28.31 +import java.io.IOException; 28.32 + 28.33 +import com.sun.tools.classfile.ConstantPool.*; 28.34 + 28.35 +/** 28.36 + * See JVMS3, section 4.8.6. 28.37 + * 28.38 + * <p><b>This is NOT part of any API supported by Sun Microsystems. If 28.39 + * you write code that depends on this, you do so at your own risk. 28.40 + * This code and its internal interfaces are subject to change or 28.41 + * deletion without notice.</b> 28.42 + */ 28.43 +public class InnerClasses_attribute extends Attribute { 28.44 + InnerClasses_attribute(ClassReader cr, int name_index, int length) throws IOException { 28.45 + super(name_index, length); 28.46 + number_of_classes = cr.readUnsignedShort(); 28.47 + classes = new Info[number_of_classes]; 28.48 + for (int i = 0; i < number_of_classes; i++) 28.49 + classes[i] = new Info(cr); 28.50 + } 28.51 + 28.52 + public InnerClasses_attribute(ConstantPool constant_pool, Info[] classes) 28.53 + throws ConstantPoolException { 28.54 + this(constant_pool.getUTF8Index(Attribute.InnerClasses), classes); 28.55 + } 28.56 + 28.57 + public InnerClasses_attribute(int name_index, Info[] classes) { 28.58 + super(name_index, 2 + Info.length() * classes.length); 28.59 + this.number_of_classes = classes.length; 28.60 + this.classes = classes; 28.61 + } 28.62 + 28.63 + public <R, D> R accept(Visitor<R, D> visitor, D data) { 28.64 + return visitor.visitInnerClasses(this, data); 28.65 + } 28.66 + 28.67 + public final int number_of_classes; 28.68 + public final Info[] classes; 28.69 + 28.70 + public static class Info { 28.71 + Info(ClassReader cr) throws IOException { 28.72 + inner_class_info_index = cr.readUnsignedShort(); 28.73 + outer_class_info_index = cr.readUnsignedShort(); 28.74 + inner_name_index = cr.readUnsignedShort(); 28.75 + inner_class_access_flags = new AccessFlags(cr.readUnsignedShort()); 28.76 + } 28.77 + 28.78 + public CONSTANT_Class_info getInnerClassInfo(ConstantPool constant_pool) throws ConstantPoolException { 28.79 + if (inner_class_info_index == 0) 28.80 + return null; 28.81 + return constant_pool.getClassInfo(inner_class_info_index); 28.82 + } 28.83 + 28.84 + public CONSTANT_Class_info getOuterClassInfo(ConstantPool constant_pool) throws ConstantPoolException { 28.85 + if (outer_class_info_index == 0) 28.86 + return null; 28.87 + return constant_pool.getClassInfo(outer_class_info_index); 28.88 + } 28.89 + 28.90 + public String getInnerName(ConstantPool constant_pool) throws ConstantPoolException { 28.91 + if (inner_name_index == 0) 28.92 + return null; 28.93 + return constant_pool.getUTF8Value(inner_name_index); 28.94 + } 28.95 + 28.96 + public static int length() { 28.97 + return 8; 28.98 + } 28.99 + 28.100 + public final int inner_class_info_index; 28.101 + public final int outer_class_info_index; 28.102 + public final int inner_name_index; 28.103 + public final AccessFlags inner_class_access_flags; 28.104 + } 28.105 +}
29.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 29.2 +++ b/src/share/classes/com/sun/tools/classfile/LineNumberTable_attribute.java Tue Jun 03 13:26:47 2008 -0700 29.3 @@ -0,0 +1,78 @@ 29.4 +/* 29.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. 29.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 29.7 + * 29.8 + * This code is free software; you can redistribute it and/or modify it 29.9 + * under the terms of the GNU General Public License version 2 only, as 29.10 + * published by the Free Software Foundation. Sun designates this 29.11 + * particular file as subject to the "Classpath" exception as provided 29.12 + * by Sun in the LICENSE file that accompanied this code. 29.13 + * 29.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 29.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 29.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 29.17 + * version 2 for more details (a copy is included in the LICENSE file that 29.18 + * accompanied this code). 29.19 + * 29.20 + * You should have received a copy of the GNU General Public License version 29.21 + * 2 along with this work; if not, write to the Free Software Foundation, 29.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 29.23 + * 29.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 29.25 + * CA 95054 USA or visit www.sun.com if you need additional information or 29.26 + * have any questions. 29.27 + */ 29.28 + 29.29 +package com.sun.tools.classfile; 29.30 + 29.31 +import java.io.IOException; 29.32 + 29.33 +/** 29.34 + * See JVMS3, section 4.8.12. 29.35 + * 29.36 + * <p><b>This is NOT part of any API supported by Sun Microsystems. If 29.37 + * you write code that depends on this, you do so at your own risk. 29.38 + * This code and its internal interfaces are subject to change or 29.39 + * deletion without notice.</b> 29.40 + */ 29.41 +public class LineNumberTable_attribute extends Attribute { 29.42 + LineNumberTable_attribute(ClassReader cr, int name_index, int length) throws IOException { 29.43 + super(name_index, length); 29.44 + line_number_table_length = cr.readUnsignedShort(); 29.45 + line_number_table = new Entry[line_number_table_length]; 29.46 + for (int i = 0; i < line_number_table_length; i++) 29.47 + line_number_table[i] = new Entry(cr); 29.48 + } 29.49 + 29.50 + public LineNumberTable_attribute(ConstantPool constant_pool, Entry[] line_number_table) 29.51 + throws ConstantPoolException { 29.52 + this(constant_pool.getUTF8Index(Attribute.LineNumberTable), line_number_table); 29.53 + } 29.54 + 29.55 + public LineNumberTable_attribute(int name_index, Entry[] line_number_table) { 29.56 + super(name_index, line_number_table.length * Entry.length()); 29.57 + this.line_number_table_length = line_number_table.length; 29.58 + this.line_number_table = line_number_table; 29.59 + } 29.60 + 29.61 + public <R, D> R accept(Visitor<R, D> visitor, D data) { 29.62 + return visitor.visitLineNumberTable(this, data); 29.63 + } 29.64 + 29.65 + public final int line_number_table_length; 29.66 + public final Entry[] line_number_table; 29.67 + 29.68 + public static class Entry { 29.69 + Entry(ClassReader cr) throws IOException { 29.70 + start_pc = cr.readUnsignedShort(); 29.71 + line_number = cr.readUnsignedShort(); 29.72 + } 29.73 + 29.74 + public static int length() { 29.75 + return 4; 29.76 + } 29.77 + 29.78 + public final int start_pc; 29.79 + public final int line_number; 29.80 + } 29.81 +}
30.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 30.2 +++ b/src/share/classes/com/sun/tools/classfile/LocalVariableTable_attribute.java Tue Jun 03 13:26:47 2008 -0700 30.3 @@ -0,0 +1,84 @@ 30.4 +/* 30.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. 30.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 30.7 + * 30.8 + * This code is free software; you can redistribute it and/or modify it 30.9 + * under the terms of the GNU General Public License version 2 only, as 30.10 + * published by the Free Software Foundation. Sun designates this 30.11 + * particular file as subject to the "Classpath" exception as provided 30.12 + * by Sun in the LICENSE file that accompanied this code. 30.13 + * 30.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 30.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 30.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 30.17 + * version 2 for more details (a copy is included in the LICENSE file that 30.18 + * accompanied this code). 30.19 + * 30.20 + * You should have received a copy of the GNU General Public License version 30.21 + * 2 along with this work; if not, write to the Free Software Foundation, 30.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 30.23 + * 30.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 30.25 + * CA 95054 USA or visit www.sun.com if you need additional information or 30.26 + * have any questions. 30.27 + */ 30.28 + 30.29 +package com.sun.tools.classfile; 30.30 + 30.31 +import java.io.IOException; 30.32 + 30.33 +/** 30.34 + * See JVMS3, section 4.8.13. 30.35 + * 30.36 + * <p><b>This is NOT part of any API supported by Sun Microsystems. If 30.37 + * you write code that depends on this, you do so at your own risk. 30.38 + * This code and its internal interfaces are subject to change or 30.39 + * deletion without notice.</b> 30.40 + */ 30.41 +public class LocalVariableTable_attribute extends Attribute { 30.42 + LocalVariableTable_attribute(ClassReader cr, int name_index, int length) throws IOException { 30.43 + super(name_index, length); 30.44 + local_variable_table_length = cr.readUnsignedShort(); 30.45 + local_variable_table = new Entry[local_variable_table_length]; 30.46 + for (int i = 0; i < local_variable_table_length; i++) 30.47 + local_variable_table[i] = new Entry(cr); 30.48 + } 30.49 + 30.50 + public LocalVariableTable_attribute(ConstantPool constant_pool, Entry[] local_variable_table) 30.51 + throws ConstantPoolException { 30.52 + this(constant_pool.getUTF8Index(Attribute.LocalVariableTable), local_variable_table); 30.53 + } 30.54 + 30.55 + public LocalVariableTable_attribute(int name_index, Entry[] local_variable_table) { 30.56 + super(name_index, local_variable_table.length * Entry.length()); 30.57 + this.local_variable_table_length = local_variable_table.length; 30.58 + this.local_variable_table = local_variable_table; 30.59 + } 30.60 + 30.61 + public <R, D> R accept(Visitor<R, D> visitor, D data) { 30.62 + return visitor.visitLocalVariableTable(this, data); 30.63 + } 30.64 + 30.65 + public final int local_variable_table_length; 30.66 + public final Entry[] local_variable_table; 30.67 + 30.68 + public static class Entry { 30.69 + Entry(ClassReader cr) throws IOException { 30.70 + start_pc = cr.readUnsignedShort(); 30.71 + length = cr.readUnsignedShort(); 30.72 + name_index = cr.readUnsignedShort(); 30.73 + descriptor_index = cr.readUnsignedShort(); 30.74 + index = cr.readUnsignedShort(); 30.75 + } 30.76 + 30.77 + public static int length() { 30.78 + return 10; 30.79 + } 30.80 + 30.81 + public final int start_pc; 30.82 + public final int length; 30.83 + public final int name_index; 30.84 + public final int descriptor_index; 30.85 + public final int index; 30.86 + } 30.87 +}
31.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 31.2 +++ b/src/share/classes/com/sun/tools/classfile/LocalVariableTypeTable_attribute.java Tue Jun 03 13:26:47 2008 -0700 31.3 @@ -0,0 +1,84 @@ 31.4 +/* 31.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. 31.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 31.7 + * 31.8 + * This code is free software; you can redistribute it and/or modify it 31.9 + * under the terms of the GNU General Public License version 2 only, as 31.10 + * published by the Free Software Foundation. Sun designates this 31.11 + * particular file as subject to the "Classpath" exception as provided 31.12 + * by Sun in the LICENSE file that accompanied this code. 31.13 + * 31.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 31.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 31.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 31.17 + * version 2 for more details (a copy is included in the LICENSE file that 31.18 + * accompanied this code). 31.19 + * 31.20 + * You should have received a copy of the GNU General Public License version 31.21 + * 2 along with this work; if not, write to the Free Software Foundation, 31.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 31.23 + * 31.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 31.25 + * CA 95054 USA or visit www.sun.com if you need additional information or 31.26 + * have any questions. 31.27 + */ 31.28 + 31.29 +package com.sun.tools.classfile; 31.30 + 31.31 +import java.io.IOException; 31.32 + 31.33 +/** 31.34 + * See JVMS3, section 4.8.14. 31.35 + * 31.36 + * <p><b>This is NOT part of any API supported by Sun Microsystems. If 31.37 + * you write code that depends on this, you do so at your own risk. 31.38 + * This code and its internal interfaces are subject to change or 31.39 + * deletion without notice.</b> 31.40 + */ 31.41 +public class LocalVariableTypeTable_attribute extends Attribute { 31.42 + LocalVariableTypeTable_attribute(ClassReader cr, int name_index, int length) throws IOException { 31.43 + super(name_index, length); 31.44 + local_variable_table_length = cr.readUnsignedShort(); 31.45 + local_variable_table = new Entry[local_variable_table_length]; 31.46 + for (int i = 0; i < local_variable_table_length; i++) 31.47 + local_variable_table[i] = new Entry(cr); 31.48 + } 31.49 + 31.50 + public LocalVariableTypeTable_attribute(ConstantPool constant_pool, Entry[] local_variable_table) 31.51 + throws ConstantPoolException { 31.52 + this(constant_pool.getUTF8Index(Attribute.LocalVariableTypeTable), local_variable_table); 31.53 + } 31.54 + 31.55 + public LocalVariableTypeTable_attribute(int name_index, Entry[] local_variable_table) { 31.56 + super(name_index, local_variable_table.length * Entry.length()); 31.57 + this.local_variable_table_length = local_variable_table.length; 31.58 + this.local_variable_table = local_variable_table; 31.59 + } 31.60 + 31.61 + public <R, D> R accept(Visitor<R, D> visitor, D data) { 31.62 + return visitor.visitLocalVariableTypeTable(this, data); 31.63 + } 31.64 + 31.65 + public final int local_variable_table_length; 31.66 + public final Entry[] local_variable_table; 31.67 + 31.68 + public static class Entry { 31.69 + Entry(ClassReader cr) throws IOException { 31.70 + start_pc = cr.readUnsignedShort(); 31.71 + length = cr.readUnsignedShort(); 31.72 + name_index = cr.readUnsignedShort(); 31.73 + signature_index = cr.readUnsignedShort(); 31.74 + index = cr.readUnsignedShort(); 31.75 + } 31.76 + 31.77 + public static int length() { 31.78 + return 10; 31.79 + } 31.80 + 31.81 + public final int start_pc; 31.82 + public final int length; 31.83 + public final int name_index; 31.84 + public final int signature_index; 31.85 + public final int index; 31.86 + } 31.87 +}
32.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 32.2 +++ b/src/share/classes/com/sun/tools/classfile/Method.java Tue Jun 03 13:26:47 2008 -0700 32.3 @@ -0,0 +1,61 @@ 32.4 +/* 32.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. 32.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 32.7 + * 32.8 + * This code is free software; you can redistribute it and/or modify it 32.9 + * under the terms of the GNU General Public License version 2 only, as 32.10 + * published by the Free Software Foundation. Sun designates this 32.11 + * particular file as subject to the "Classpath" exception as provided 32.12 + * by Sun in the LICENSE file that accompanied this code. 32.13 + * 32.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 32.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 32.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 32.17 + * version 2 for more details (a copy is included in the LICENSE file that 32.18 + * accompanied this code). 32.19 + * 32.20 + * You should have received a copy of the GNU General Public License version 32.21 + * 2 along with this work; if not, write to the Free Software Foundation, 32.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 32.23 + * 32.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 32.25 + * CA 95054 USA or visit www.sun.com if you need additional information or 32.26 + * have any questions. 32.27 + */ 32.28 + 32.29 +package com.sun.tools.classfile; 32.30 + 32.31 +import java.io.IOException; 32.32 + 32.33 +/* 32.34 + * <p><b>This is NOT part of any API supported by Sun Microsystems. If 32.35 + * you write code that depends on this, you do so at your own risk. 32.36 + * This code and its internal interfaces are subject to change or 32.37 + * deletion without notice.</b> 32.38 + */ 32.39 +public class Method { 32.40 + Method(ClassReader cr) throws IOException { 32.41 + access_flags = new AccessFlags(cr); 32.42 + name_index = cr.readUnsignedShort(); 32.43 + descriptor = new Descriptor(cr); 32.44 + attributes = new Attributes(cr); 32.45 + } 32.46 + 32.47 + public Method(AccessFlags access_flags, 32.48 + int name_index, Descriptor descriptor, 32.49 + Attributes attributes) { 32.50 + this.access_flags = access_flags; 32.51 + this.name_index = name_index; 32.52 + this.descriptor = descriptor; 32.53 + this.attributes = attributes; 32.54 + } 32.55 + 32.56 + public String getName(ConstantPool constant_pool) throws ConstantPoolException { 32.57 + return constant_pool.getUTF8Value(name_index); 32.58 + } 32.59 + 32.60 + public final AccessFlags access_flags; 32.61 + public final int name_index; 32.62 + public final Descriptor descriptor; 32.63 + public final Attributes attributes; 32.64 +}
33.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 33.2 +++ b/src/share/classes/com/sun/tools/classfile/ModuleExportTable_attribute.java Tue Jun 03 13:26:47 2008 -0700 33.3 @@ -0,0 +1,70 @@ 33.4 +/* 33.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. 33.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 33.7 + * 33.8 + * This code is free software; you can redistribute it and/or modify it 33.9 + * under the terms of the GNU General Public License version 2 only, as 33.10 + * published by the Free Software Foundation. Sun designates this 33.11 + * particular file as subject to the "Classpath" exception as provided 33.12 + * by Sun in the LICENSE file that accompanied this code. 33.13 + * 33.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 33.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 33.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 33.17 + * version 2 for more details (a copy is included in the LICENSE file that 33.18 + * accompanied this code). 33.19 + * 33.20 + * You should have received a copy of the GNU General Public License version 33.21 + * 2 along with this work; if not, write to the Free Software Foundation, 33.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 33.23 + * 33.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 33.25 + * CA 95054 USA or visit www.sun.com if you need additional information or 33.26 + * have any questions. 33.27 + */ 33.28 + 33.29 +package com.sun.tools.classfile; 33.30 + 33.31 +import java.io.IOException; 33.32 + 33.33 +/** 33.34 + * See JSR 277. 33.35 + * 33.36 + * <p><b>This is NOT part of any API supported by Sun Microsystems. If 33.37 + * you write code that depends on this, you do so at your own risk. 33.38 + * This code and its internal interfaces are subject to change or 33.39 + * deletion without notice.</b> 33.40 + */ 33.41 +public class ModuleExportTable_attribute extends Attribute { 33.42 + ModuleExportTable_attribute(ClassReader cr, int name_index, int length) throws IOException { 33.43 + super(name_index, length); 33.44 + int export_type_length = cr.readUnsignedShort(); 33.45 + export_type_table = new int[export_type_length]; 33.46 + for (int i = 0; i < export_type_table.length; i++) 33.47 + export_type_table[i] = cr.readUnsignedShort(); 33.48 + } 33.49 + 33.50 + public ModuleExportTable_attribute(ConstantPool cp, int[] export_type_table) 33.51 + throws ConstantPoolException { 33.52 + this(cp.getUTF8Index(Attribute.ModuleExportTable), export_type_table); 33.53 + } 33.54 + 33.55 + public ModuleExportTable_attribute(int name_index, int[] export_type_table) { 33.56 + super(name_index, 2 * export_type_table.length); 33.57 + this.export_type_table = export_type_table; 33.58 + } 33.59 + 33.60 + public int getExportTypeCount() { 33.61 + return export_type_table.length; 33.62 + } 33.63 + 33.64 + public String getExportTypeName(int index, ConstantPool constant_pool) throws ConstantPoolException { 33.65 + return constant_pool.getUTF8Value(export_type_table[index]); 33.66 + } 33.67 + 33.68 + public <R, P> R accept(Visitor<R, P> visitor, P p) { 33.69 + return visitor.visitModuleExportTable(this, p); 33.70 + } 33.71 + 33.72 + public final int[] export_type_table; 33.73 +}
34.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 34.2 +++ b/src/share/classes/com/sun/tools/classfile/ModuleMemberTable_attribute.java Tue Jun 03 13:26:47 2008 -0700 34.3 @@ -0,0 +1,69 @@ 34.4 +/* 34.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. 34.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 34.7 + * 34.8 + * This code is free software; you can redistribute it and/or modify it 34.9 + * under the terms of the GNU General Public License version 2 only, as 34.10 + * published by the Free Software Foundation. Sun designates this 34.11 + * particular file as subject to the "Classpath" exception as provided 34.12 + * by Sun in the LICENSE file that accompanied this code. 34.13 + * 34.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 34.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 34.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 34.17 + * version 2 for more details (a copy is included in the LICENSE file that 34.18 + * accompanied this code). 34.19 + * 34.20 + * You should have received a copy of the GNU General Public License version 34.21 + * 2 along with this work; if not, write to the Free Software Foundation, 34.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 34.23 + * 34.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 34.25 + * CA 95054 USA or visit www.sun.com if you need additional information or 34.26 + * have any questions. 34.27 + */ 34.28 +package com.sun.tools.classfile; 34.29 + 34.30 +import java.io.IOException; 34.31 + 34.32 +/** 34.33 + * See JSR 277. 34.34 + * 34.35 + * <p><b>This is NOT part of any API supported by Sun Microsystems. If 34.36 + * you write code that depends on this, you do so at your own risk. 34.37 + * This code and its internal interfaces are subject to change or 34.38 + * deletion without notice.</b> 34.39 + */ 34.40 +public class ModuleMemberTable_attribute extends Attribute { 34.41 + ModuleMemberTable_attribute(ClassReader cr, int name_index, int length) throws IOException { 34.42 + super(name_index, length); 34.43 + int package_member_length = cr.readUnsignedShort(); 34.44 + package_member_table = new int[package_member_length]; 34.45 + for (int i = 0; i < package_member_table.length; i++) 34.46 + package_member_table[i] = cr.readUnsignedShort(); 34.47 + } 34.48 + 34.49 + public ModuleMemberTable_attribute(ConstantPool cp, int[] package_member_table) 34.50 + throws ConstantPoolException { 34.51 + this(cp.getUTF8Index(Attribute.ModuleMemberTable), package_member_table); 34.52 + } 34.53 + 34.54 + public ModuleMemberTable_attribute(int name_index, int[] package_member_table) { 34.55 + super(name_index, 2 * package_member_table.length); 34.56 + this.package_member_table = package_member_table; 34.57 + } 34.58 + 34.59 + public int getPackageMemberCount() { 34.60 + return package_member_table.length; 34.61 + } 34.62 + 34.63 + public String getPackageMemberName(int index, ConstantPool constant_pool) throws ConstantPoolException { 34.64 + return constant_pool.getUTF8Value(package_member_table[index]); 34.65 + } 34.66 + 34.67 + public <R, P> R accept(Visitor<R, P> visitor, P p) { 34.68 + return visitor.visitModuleMemberTable(this, p); 34.69 + } 34.70 + 34.71 + public final int[] package_member_table; 34.72 +}
35.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 35.2 +++ b/src/share/classes/com/sun/tools/classfile/Module_attribute.java Tue Jun 03 13:26:47 2008 -0700 35.3 @@ -0,0 +1,64 @@ 35.4 +/* 35.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. 35.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 35.7 + * 35.8 + * This code is free software; you can redistribute it and/or modify it 35.9 + * under the terms of the GNU General Public License version 2 only, as 35.10 + * published by the Free Software Foundation. Sun designates this 35.11 + * particular file as subject to the "Classpath" exception as provided 35.12 + * by Sun in the LICENSE file that accompanied this code. 35.13 + * 35.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 35.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 35.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 35.17 + * version 2 for more details (a copy is included in the LICENSE file that 35.18 + * accompanied this code). 35.19 + * 35.20 + * You should have received a copy of the GNU General Public License version 35.21 + * 2 along with this work; if not, write to the Free Software Foundation, 35.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 35.23 + * 35.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 35.25 + * CA 95054 USA or visit www.sun.com if you need additional information or 35.26 + * have any questions. 35.27 + */ 35.28 + 35.29 +package com.sun.tools.classfile; 35.30 + 35.31 +import java.io.IOException; 35.32 + 35.33 +/** 35.34 + * See JSR 277. 35.35 + * 35.36 + * <p><b>This is NOT part of any API supported by Sun Microsystems. If 35.37 + * you write code that depends on this, you do so at your own risk. 35.38 + * This code and its internal interfaces are subject to change or 35.39 + * deletion without notice.</b> 35.40 + */ 35.41 +public class Module_attribute extends Attribute { 35.42 + Module_attribute(ClassReader cr, int name_index, int length) throws IOException { 35.43 + super(name_index, length); 35.44 + module_name = cr.readUnsignedShort(); 35.45 + } 35.46 + 35.47 + public Module_attribute(ConstantPool constant_pool, int module_name) 35.48 + throws ConstantPoolException { 35.49 + this(constant_pool.getUTF8Index(Attribute.Module), module_name); 35.50 + } 35.51 + 35.52 + public Module_attribute(int name_index, int module_name) { 35.53 + super(name_index, 2); 35.54 + this.module_name = module_name; 35.55 + } 35.56 + 35.57 + public String getModuleName(ConstantPool constant_pool) throws ConstantPoolException { 35.58 + return constant_pool.getUTF8Value(module_name); 35.59 + } 35.60 + 35.61 + public <R, D> R accept(Visitor<R, D> visitor, D data) { 35.62 + return visitor.visitModule(this, data); 35.63 + } 35.64 + 35.65 + public final int module_name; 35.66 + 35.67 +}
36.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 36.2 +++ b/src/share/classes/com/sun/tools/classfile/OpCodes.java Tue Jun 03 13:26:47 2008 -0700 36.3 @@ -0,0 +1,868 @@ 36.4 +/* 36.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. 36.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 36.7 + * 36.8 + * This code is free software; you can redistribute it and/or modify it 36.9 + * under the terms of the GNU General Public License version 2 only, as 36.10 + * published by the Free Software Foundation. Sun designates this 36.11 + * particular file as subject to the "Classpath" exception as provided 36.12 + * by Sun in the LICENSE file that accompanied this code. 36.13 + * 36.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 36.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 36.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 36.17 + * version 2 for more details (a copy is included in the LICENSE file that 36.18 + * accompanied this code). 36.19 + * 36.20 + * You should have received a copy of the GNU General Public License version 36.21 + * 2 along with this work; if not, write to the Free Software Foundation, 36.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 36.23 + * 36.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 36.25 + * CA 95054 USA or visit www.sun.com if you need additional information or 36.26 + * have any questions. 36.27 + */ 36.28 + 36.29 +package com.sun.tools.classfile; 36.30 + 36.31 +import java.util.HashMap; 36.32 + 36.33 +/** 36.34 + * See JVMS3, section 6. 36.35 + * 36.36 + * <p><b>This is NOT part of any API supported by Sun Microsystems. If 36.37 + * you write code that depends on this, you do so at your own risk. 36.38 + * This code and its internal interfaces are subject to change or 36.39 + * deletion without notice.</b> 36.40 + */ 36.41 +public class OpCodes { 36.42 + 36.43 + public static int opcLength(int opc) throws IllegalArgumentException { 36.44 + switch (opc >> 8) { 36.45 + case 0: 36.46 + return opcLengthsTab[opc]; 36.47 + case opc_wide: 36.48 + switch (opc & 0xFF) { 36.49 + case opc_aload: 36.50 + case opc_astore: 36.51 + case opc_fload: 36.52 + case opc_fstore: 36.53 + case opc_iload: 36.54 + case opc_istore: 36.55 + case opc_lload: 36.56 + case opc_lstore: 36.57 + case opc_dload: 36.58 + case opc_dstore: 36.59 + case opc_ret: 36.60 + return 4; 36.61 + case opc_iinc: 36.62 + return 6; 36.63 + default: 36.64 + throw new IllegalArgumentException(); 36.65 + } 36.66 + case opc_nonpriv: 36.67 + case opc_priv: 36.68 + return 2; 36.69 + default: 36.70 + throw new IllegalArgumentException(); 36.71 + } 36.72 + } 36.73 + 36.74 + public static String opcName(int opc) { 36.75 + try { 36.76 + switch (opc >> 8) { 36.77 + case 0: 36.78 + return opcNamesTab[opc]; 36.79 + case opc_wide: 36.80 + { 36.81 + String mnem = opcNamesTab[opc & 0xFF] + "_w"; 36.82 + if (mnemocodes.get(mnem) == null) { 36.83 + return null; // non-existent opcode 36.84 + } 36.85 + return mnem; 36.86 + } 36.87 + case opc_nonpriv: 36.88 + return opcExtNamesTab[opc & 0xFF]; 36.89 + case opc_priv: 36.90 + return opcPrivExtNamesTab[opc & 0xFF]; 36.91 + default: 36.92 + return null; 36.93 + } 36.94 + } catch (ArrayIndexOutOfBoundsException e) { 36.95 + switch (opc) { 36.96 + case opc_nonpriv: 36.97 + return "nonpriv"; 36.98 + case opc_priv: 36.99 + return "priv"; 36.100 + default: 36.101 + return null; 36.102 + } 36.103 + } 36.104 + } 36.105 + 36.106 + /* Opcodes */ 36.107 + public static final int opc_dead = -2; 36.108 + public static final int opc_label = -1; 36.109 + public static final int opc_nop = 0; 36.110 + public static final int opc_aconst_null = 1; 36.111 + public static final int opc_iconst_m1 = 2; 36.112 + public static final int opc_iconst_0 = 3; 36.113 + public static final int opc_iconst_1 = 4; 36.114 + public static final int opc_iconst_2 = 5; 36.115 + public static final int opc_iconst_3 = 6; 36.116 + public static final int opc_iconst_4 = 7; 36.117 + public static final int opc_iconst_5 = 8; 36.118 + public static final int opc_lconst_0 = 9; 36.119 + public static final int opc_lconst_1 = 10; 36.120 + public static final int opc_fconst_0 = 11; 36.121 + public static final int opc_fconst_1 = 12; 36.122 + public static final int opc_fconst_2 = 13; 36.123 + public static final int opc_dconst_0 = 14; 36.124 + public static final int opc_dconst_1 = 15; 36.125 + public static final int opc_bipush = 16; 36.126 + public static final int opc_sipush = 17; 36.127 + public static final int opc_ldc = 18; 36.128 + public static final int opc_ldc_w = 19; 36.129 + public static final int opc_ldc2_w = 20; 36.130 + public static final int opc_iload = 21; 36.131 + public static final int opc_lload = 22; 36.132 + public static final int opc_fload = 23; 36.133 + public static final int opc_dload = 24; 36.134 + public static final int opc_aload = 25; 36.135 + public static final int opc_iload_0 = 26; 36.136 + public static final int opc_iload_1 = 27; 36.137 + public static final int opc_iload_2 = 28; 36.138 + public static final int opc_iload_3 = 29; 36.139 + public static final int opc_lload_0 = 30; 36.140 + public static final int opc_lload_1 = 31; 36.141 + public static final int opc_lload_2 = 32; 36.142 + public static final int opc_lload_3 = 33; 36.143 + public static final int opc_fload_0 = 34; 36.144 + public static final int opc_fload_1 = 35; 36.145 + public static final int opc_fload_2 = 36; 36.146 + public static final int opc_fload_3 = 37; 36.147 + public static final int opc_dload_0 = 38; 36.148 + public static final int opc_dload_1 = 39; 36.149 + public static final int opc_dload_2 = 40; 36.150 + public static final int opc_dload_3 = 41; 36.151 + public static final int opc_aload_0 = 42; 36.152 + public static final int opc_aload_1 = 43; 36.153 + public static final int opc_aload_2 = 44; 36.154 + public static final int opc_aload_3 = 45; 36.155 + public static final int opc_iaload = 46; 36.156 + public static final int opc_laload = 47; 36.157 + public static final int opc_faload = 48; 36.158 + public static final int opc_daload = 49; 36.159 + public static final int opc_aaload = 50; 36.160 + public static final int opc_baload = 51; 36.161 + public static final int opc_caload = 52; 36.162 + public static final int opc_saload = 53; 36.163 + public static final int opc_istore = 54; 36.164 + public static final int opc_lstore = 55; 36.165 + public static final int opc_fstore = 56; 36.166 + public static final int opc_dstore = 57; 36.167 + public static final int opc_astore = 58; 36.168 + public static final int opc_istore_0 = 59; 36.169 + public static final int opc_istore_1 = 60; 36.170 + public static final int opc_istore_2 = 61; 36.171 + public static final int opc_istore_3 = 62; 36.172 + public static final int opc_lstore_0 = 63; 36.173 + public static final int opc_lstore_1 = 64; 36.174 + public static final int opc_lstore_2 = 65; 36.175 + public static final int opc_lstore_3 = 66; 36.176 + public static final int opc_fstore_0 = 67; 36.177 + public static final int opc_fstore_1 = 68; 36.178 + public static final int opc_fstore_2 = 69; 36.179 + public static final int opc_fstore_3 = 70; 36.180 + public static final int opc_dstore_0 = 71; 36.181 + public static final int opc_dstore_1 = 72; 36.182 + public static final int opc_dstore_2 = 73; 36.183 + public static final int opc_dstore_3 = 74; 36.184 + public static final int opc_astore_0 = 75; 36.185 + public static final int opc_astore_1 = 76; 36.186 + public static final int opc_astore_2 = 77; 36.187 + public static final int opc_astore_3 = 78; 36.188 + public static final int opc_iastore = 79; 36.189 + public static final int opc_lastore = 80; 36.190 + public static final int opc_fastore = 81; 36.191 + public static final int opc_dastore = 82; 36.192 + public static final int opc_aastore = 83; 36.193 + public static final int opc_bastore = 84; 36.194 + public static final int opc_castore = 85; 36.195 + public static final int opc_sastore = 86; 36.196 + public static final int opc_pop = 87; 36.197 + public static final int opc_pop2 = 88; 36.198 + public static final int opc_dup = 89; 36.199 + public static final int opc_dup_x1 = 90; 36.200 + public static final int opc_dup_x2 = 91; 36.201 + public static final int opc_dup2 = 92; 36.202 + public static final int opc_dup2_x1 = 93; 36.203 + public static final int opc_dup2_x2 = 94; 36.204 + public static final int opc_swap = 95; 36.205 + public static final int opc_iadd = 96; 36.206 + public static final int opc_ladd = 97; 36.207 + public static final int opc_fadd = 98; 36.208 + public static final int opc_dadd = 99; 36.209 + public static final int opc_isub = 100; 36.210 + public static final int opc_lsub = 101; 36.211 + public static final int opc_fsub = 102; 36.212 + public static final int opc_dsub = 103; 36.213 + public static final int opc_imul = 104; 36.214 + public static final int opc_lmul = 105; 36.215 + public static final int opc_fmul = 106; 36.216 + public static final int opc_dmul = 107; 36.217 + public static final int opc_idiv = 108; 36.218 + public static final int opc_ldiv = 109; 36.219 + public static final int opc_fdiv = 110; 36.220 + public static final int opc_ddiv = 111; 36.221 + public static final int opc_irem = 112; 36.222 + public static final int opc_lrem = 113; 36.223 + public static final int opc_frem = 114; 36.224 + public static final int opc_drem = 115; 36.225 + public static final int opc_ineg = 116; 36.226 + public static final int opc_lneg = 117; 36.227 + public static final int opc_fneg = 118; 36.228 + public static final int opc_dneg = 119; 36.229 + public static final int opc_ishl = 120; 36.230 + public static final int opc_lshl = 121; 36.231 + public static final int opc_ishr = 122; 36.232 + public static final int opc_lshr = 123; 36.233 + public static final int opc_iushr = 124; 36.234 + public static final int opc_lushr = 125; 36.235 + public static final int opc_iand = 126; 36.236 + public static final int opc_land = 127; 36.237 + public static final int opc_ior = 128; 36.238 + public static final int opc_lor = 129; 36.239 + public static final int opc_ixor = 130; 36.240 + public static final int opc_lxor = 131; 36.241 + public static final int opc_iinc = 132; 36.242 + public static final int opc_i2l = 133; 36.243 + public static final int opc_i2f = 134; 36.244 + public static final int opc_i2d = 135; 36.245 + public static final int opc_l2i = 136; 36.246 + public static final int opc_l2f = 137; 36.247 + public static final int opc_l2d = 138; 36.248 + public static final int opc_f2i = 139; 36.249 + public static final int opc_f2l = 140; 36.250 + public static final int opc_f2d = 141; 36.251 + public static final int opc_d2i = 142; 36.252 + public static final int opc_d2l = 143; 36.253 + public static final int opc_d2f = 144; 36.254 + public static final int opc_i2b = 145; 36.255 + public static final int opc_int2byte = 145; 36.256 + public static final int opc_i2c = 146; 36.257 + public static final int opc_int2char = 146; 36.258 + public static final int opc_i2s = 147; 36.259 + public static final int opc_int2short = 147; 36.260 + public static final int opc_lcmp = 148; 36.261 + public static final int opc_fcmpl = 149; 36.262 + public static final int opc_fcmpg = 150; 36.263 + public static final int opc_dcmpl = 151; 36.264 + public static final int opc_dcmpg = 152; 36.265 + public static final int opc_ifeq = 153; 36.266 + public static final int opc_ifne = 154; 36.267 + public static final int opc_iflt = 155; 36.268 + public static final int opc_ifge = 156; 36.269 + public static final int opc_ifgt = 157; 36.270 + public static final int opc_ifle = 158; 36.271 + public static final int opc_if_icmpeq = 159; 36.272 + public static final int opc_if_icmpne = 160; 36.273 + public static final int opc_if_icmplt = 161; 36.274 + public static final int opc_if_icmpge = 162; 36.275 + public static final int opc_if_icmpgt = 163; 36.276 + public static final int opc_if_icmple = 164; 36.277 + public static final int opc_if_acmpeq = 165; 36.278 + public static final int opc_if_acmpne = 166; 36.279 + public static final int opc_goto = 167; 36.280 + public static final int opc_jsr = 168; 36.281 + public static final int opc_ret = 169; 36.282 + public static final int opc_tableswitch = 170; 36.283 + public static final int opc_lookupswitch = 171; 36.284 + public static final int opc_ireturn = 172; 36.285 + public static final int opc_lreturn = 173; 36.286 + public static final int opc_freturn = 174; 36.287 + public static final int opc_dreturn = 175; 36.288 + public static final int opc_areturn = 176; 36.289 + public static final int opc_return = 177; 36.290 + public static final int opc_getstatic = 178; 36.291 + public static final int opc_putstatic = 179; 36.292 + public static final int opc_getfield = 180; 36.293 + public static final int opc_putfield = 181; 36.294 + public static final int opc_invokevirtual = 182; 36.295 + public static final int opc_invokenonvirtual = 183; 36.296 + public static final int opc_invokespecial = 183; 36.297 + public static final int opc_invokestatic = 184; 36.298 + public static final int opc_invokeinterface = 185; 36.299 +// public static final int opc_xxxunusedxxx = 186; 36.300 + public static final int opc_new = 187; 36.301 + public static final int opc_newarray = 188; 36.302 + public static final int opc_anewarray = 189; 36.303 + public static final int opc_arraylength = 190; 36.304 + public static final int opc_athrow = 191; 36.305 + public static final int opc_checkcast = 192; 36.306 + public static final int opc_instanceof = 193; 36.307 + public static final int opc_monitorenter = 194; 36.308 + public static final int opc_monitorexit = 195; 36.309 + public static final int opc_wide = 196; 36.310 + public static final int opc_multianewarray = 197; 36.311 + public static final int opc_ifnull = 198; 36.312 + public static final int opc_ifnonnull = 199; 36.313 + public static final int opc_goto_w = 200; 36.314 + public static final int opc_jsr_w = 201; 36.315 + 36.316 + /* Pseudo-instructions */ 36.317 + public static final int opc_bytecode = 203; 36.318 + public static final int opc_try = 204; 36.319 + public static final int opc_endtry = 205; 36.320 + public static final int opc_catch = 206; 36.321 + public static final int opc_var = 207; 36.322 + public static final int opc_endvar = 208; 36.323 + public static final int opc_localsmap = 209; 36.324 + public static final int opc_stackmap = 210; 36.325 + 36.326 + /* PicoJava prefixes */ 36.327 + public static final int opc_nonpriv = 254; 36.328 + public static final int opc_priv = 255; 36.329 + 36.330 + /* Wide instructions */ 36.331 + public static final int opc_iload_w = (opc_wide << 8 ) | opc_iload; 36.332 + public static final int opc_lload_w = (opc_wide << 8 ) | opc_lload; 36.333 + public static final int opc_fload_w = (opc_wide << 8 ) | opc_fload; 36.334 + public static final int opc_dload_w = (opc_wide << 8 ) | opc_dload; 36.335 + public static final int opc_aload_w = (opc_wide << 8 ) | opc_aload; 36.336 + public static final int opc_istore_w = (opc_wide << 8 ) | opc_istore; 36.337 + public static final int opc_lstore_w = (opc_wide << 8 ) | opc_lstore; 36.338 + public static final int opc_fstore_w = (opc_wide << 8 ) | opc_fstore; 36.339 + public static final int opc_dstore_w = (opc_wide << 8 ) | opc_dstore; 36.340 + public static final int opc_astore_w = (opc_wide << 8 ) | opc_astore; 36.341 + public static final int opc_ret_w = (opc_wide << 8 ) | opc_ret; 36.342 + public static final int opc_iinc_w = (opc_wide << 8 ) | opc_iinc; 36.343 + 36.344 + /* Opcode Names */ 36.345 + private static final String opcNamesTab[] = { 36.346 + "nop", 36.347 + "aconst_null", 36.348 + "iconst_m1", 36.349 + "iconst_0", 36.350 + "iconst_1", 36.351 + "iconst_2", 36.352 + "iconst_3", 36.353 + "iconst_4", 36.354 + "iconst_5", 36.355 + "lconst_0", 36.356 + "lconst_1", 36.357 + "fconst_0", 36.358 + "fconst_1", 36.359 + "fconst_2", 36.360 + "dconst_0", 36.361 + "dconst_1", 36.362 + "bipush", 36.363 + "sipush", 36.364 + "ldc", 36.365 + "ldc_w", 36.366 + "ldc2_w", 36.367 + "iload", 36.368 + "lload", 36.369 + "fload", 36.370 + "dload", 36.371 + "aload", 36.372 + "iload_0", 36.373 + "iload_1", 36.374 + "iload_2", 36.375 + "iload_3", 36.376 + "lload_0", 36.377 + "lload_1", 36.378 + "lload_2", 36.379 + "lload_3", 36.380 + "fload_0", 36.381 + "fload_1", 36.382 + "fload_2", 36.383 + "fload_3", 36.384 + "dload_0", 36.385 + "dload_1", 36.386 + "dload_2", 36.387 + "dload_3", 36.388 + "aload_0", 36.389 + "aload_1", 36.390 + "aload_2", 36.391 + "aload_3", 36.392 + "iaload", 36.393 + "laload", 36.394 + "faload", 36.395 + "daload", 36.396 + "aaload", 36.397 + "baload", 36.398 + "caload", 36.399 + "saload", 36.400 + "istore", 36.401 + "lstore", 36.402 + "fstore", 36.403 + "dstore", 36.404 + "astore", 36.405 + "istore_0", 36.406 + "istore_1", 36.407 + "istore_2", 36.408 + "istore_3", 36.409 + "lstore_0", 36.410 + "lstore_1", 36.411 + "lstore_2", 36.412 + "lstore_3", 36.413 + "fstore_0", 36.414 + "fstore_1", 36.415 + "fstore_2", 36.416 + "fstore_3", 36.417 + "dstore_0", 36.418 + "dstore_1", 36.419 + "dstore_2", 36.420 + "dstore_3", 36.421 + "astore_0", 36.422 + "astore_1", 36.423 + "astore_2", 36.424 + "astore_3", 36.425 + "iastore", 36.426 + "lastore", 36.427 + "fastore", 36.428 + "dastore", 36.429 + "aastore", 36.430 + "bastore", 36.431 + "castore", 36.432 + "sastore", 36.433 + "pop", 36.434 + "pop2", 36.435 + "dup", 36.436 + "dup_x1", 36.437 + "dup_x2", 36.438 + "dup2", 36.439 + "dup2_x1", 36.440 + "dup2_x2", 36.441 + "swap", 36.442 + "iadd", 36.443 + "ladd", 36.444 + "fadd", 36.445 + "dadd", 36.446 + "isub", 36.447 + "lsub", 36.448 + "fsub", 36.449 + "dsub", 36.450 + "imul", 36.451 + "lmul", 36.452 + "fmul", 36.453 + "dmul", 36.454 + "idiv", 36.455 + "ldiv", 36.456 + "fdiv", 36.457 + "ddiv", 36.458 + "irem", 36.459 + "lrem", 36.460 + "frem", 36.461 + "drem", 36.462 + "ineg", 36.463 + "lneg", 36.464 + "fneg", 36.465 + "dneg", 36.466 + "ishl", 36.467 + "lshl", 36.468 + "ishr", 36.469 + "lshr", 36.470 + "iushr", 36.471 + "lushr", 36.472 + "iand", 36.473 + "land", 36.474 + "ior", 36.475 + "lor", 36.476 + "ixor", 36.477 + "lxor", 36.478 + "iinc", 36.479 + "i2l", 36.480 + "i2f", 36.481 + "i2d", 36.482 + "l2i", 36.483 + "l2f", 36.484 + "l2d", 36.485 + "f2i", 36.486 + "f2l", 36.487 + "f2d", 36.488 + "d2i", 36.489 + "d2l", 36.490 + "d2f", 36.491 + "i2b", 36.492 + "i2c", 36.493 + "i2s", 36.494 + "lcmp", 36.495 + "fcmpl", 36.496 + "fcmpg", 36.497 + "dcmpl", 36.498 + "dcmpg", 36.499 + "ifeq", 36.500 + "ifne", 36.501 + "iflt", 36.502 + "ifge", 36.503 + "ifgt", 36.504 + "ifle", 36.505 + "if_icmpeq", 36.506 + "if_icmpne", 36.507 + "if_icmplt", 36.508 + "if_icmpge", 36.509 + "if_icmpgt", 36.510 + "if_icmple", 36.511 + "if_acmpeq", 36.512 + "if_acmpne", 36.513 + "goto", 36.514 + "jsr", 36.515 + "ret", 36.516 + "tableswitch", 36.517 + "lookupswitch", 36.518 + "ireturn", 36.519 + "lreturn", 36.520 + "freturn", 36.521 + "dreturn", 36.522 + "areturn", 36.523 + "return", 36.524 + "getstatic", 36.525 + "putstatic", 36.526 + "getfield", 36.527 + "putfield", 36.528 + "invokevirtual", 36.529 + "invokespecial", // was "invokenonvirtual", 36.530 + "invokestatic", 36.531 + "invokeinterface", 36.532 + "bytecode 186", //"xxxunusedxxx", 36.533 + "new", 36.534 + "newarray", 36.535 + "anewarray", 36.536 + "arraylength", 36.537 + "athrow", 36.538 + "checkcast", 36.539 + "instanceof", 36.540 + "monitorenter", 36.541 + "monitorexit", 36.542 + null, // "wide", 36.543 + "multianewarray", 36.544 + "ifnull", 36.545 + "ifnonnull", 36.546 + "goto_w", 36.547 + "jsr_w", 36.548 + "bytecode 202", // "breakpoint", 36.549 + "bytecode", 36.550 + "try", 36.551 + "endtry", 36.552 + "catch", 36.553 + "var", 36.554 + "endvar", 36.555 + "locals_map", 36.556 + "stack_map" 36.557 + }; 36.558 + 36.559 + /* Opcode Lengths */ 36.560 + private static final int opcLengthsTab[] = { 36.561 + 1, 36.562 + 1, 36.563 + 1, 36.564 + 1, 36.565 + 1, 36.566 + 1, 36.567 + 1, 36.568 + 1, 36.569 + 1, 36.570 + 1, 36.571 + 1, 36.572 + 1, 36.573 + 1, 36.574 + 1, 36.575 + 1, 36.576 + 1, 36.577 + 2, 36.578 + 3, 36.579 + 2, 36.580 + 3, 36.581 + 3, 36.582 + 2, 36.583 + 2, 36.584 + 2, 36.585 + 2, 36.586 + 2, 36.587 + 1, 36.588 + 1, 36.589 + 1, 36.590 + 1, 36.591 + 1, 36.592 + 1, 36.593 + 1, 36.594 + 1, 36.595 + 1, 36.596 + 1, 36.597 + 1, 36.598 + 1, 36.599 + 1, 36.600 + 1, 36.601 + 1, 36.602 + 1, 36.603 + 1, 36.604 + 1, 36.605 + 1, 36.606 + 1, 36.607 + 1, 36.608 + 1, 36.609 + 1, 36.610 + 1, 36.611 + 1, 36.612 + 1, 36.613 + 1, 36.614 + 1, 36.615 + 2, 36.616 + 2, 36.617 + 2, 36.618 + 2, 36.619 + 2, 36.620 + 1, 36.621 + 1, 36.622 + 1, 36.623 + 1, 36.624 + 1, 36.625 + 1, 36.626 + 1, 36.627 + 1, 36.628 + 1, 36.629 + 1, 36.630 + 1, 36.631 + 1, 36.632 + 1, 36.633 + 1, 36.634 + 1, 36.635 + 1, 36.636 + 1, 36.637 + 1, 36.638 + 1, 36.639 + 1, 36.640 + 1, 36.641 + 1, 36.642 + 1, 36.643 + 1, 36.644 + 1, 36.645 + 1, 36.646 + 1, 36.647 + 1, 36.648 + 1, 36.649 + 1, 36.650 + 1, 36.651 + 1, 36.652 + 1, 36.653 + 1, 36.654 + 1, 36.655 + 1, 36.656 + 1, 36.657 + 1, 36.658 + 1, 36.659 + 1, 36.660 + 1, 36.661 + 1, 36.662 + 1, 36.663 + 1, 36.664 + 1, 36.665 + 1, 36.666 + 1, 36.667 + 1, 36.668 + 1, 36.669 + 1, 36.670 + 1, 36.671 + 1, 36.672 + 1, 36.673 + 1, 36.674 + 1, 36.675 + 1, 36.676 + 1, 36.677 + 1, 36.678 + 1, 36.679 + 1, 36.680 + 1, 36.681 + 1, 36.682 + 1, 36.683 + 1, 36.684 + 1, 36.685 + 1, 36.686 + 1, 36.687 + 1, 36.688 + 1, 36.689 + 1, 36.690 + 1, 36.691 + 1, 36.692 + 1, 36.693 + 3, 36.694 + 1, 36.695 + 1, 36.696 + 1, 36.697 + 1, 36.698 + 1, 36.699 + 1, 36.700 + 1, 36.701 + 1, 36.702 + 1, 36.703 + 1, 36.704 + 1, 36.705 + 1, 36.706 + 1, 36.707 + 1, 36.708 + 1, 36.709 + 1, 36.710 + 1, 36.711 + 1, 36.712 + 1, 36.713 + 1, 36.714 + 3, 36.715 + 3, 36.716 + 3, 36.717 + 3, 36.718 + 3, 36.719 + 3, 36.720 + 3, 36.721 + 3, 36.722 + 3, 36.723 + 3, 36.724 + 3, 36.725 + 3, 36.726 + 3, 36.727 + 3, 36.728 + 3, 36.729 + 3, 36.730 + 2, 36.731 + 99, 36.732 + 99, 36.733 + 1, 36.734 + 1, 36.735 + 1, 36.736 + 1, 36.737 + 1, 36.738 + 1, 36.739 + 3, 36.740 + 3, 36.741 + 3, 36.742 + 3, 36.743 + 3, 36.744 + 3, 36.745 + 3, 36.746 + 5, 36.747 + 0, 36.748 + 3, 36.749 + 2, 36.750 + 3, 36.751 + 1, 36.752 + 1, 36.753 + 3, 36.754 + 3, 36.755 + 1, 36.756 + 1, 36.757 + 0, // wide 36.758 + 4, 36.759 + 3, 36.760 + 3, 36.761 + 5, 36.762 + 5, 36.763 + 1, 36.764 + 1, 0, 0, 0, 0, 0 // pseudo 36.765 + }; 36.766 + 36.767 + /* Type codes, used in newarray opcode */ 36.768 + public static final int T_CLASS = 0x00000002; 36.769 + public static final int T_BOOLEAN = 0x00000004; 36.770 + public static final int T_CHAR = 0x00000005; 36.771 + public static final int T_FLOAT = 0x00000006; 36.772 + public static final int T_DOUBLE = 0x00000007; 36.773 + public static final int T_BYTE = 0x00000008; 36.774 + public static final int T_SHORT = 0x00000009; 36.775 + public static final int T_INT = 0x0000000a; 36.776 + public static final int T_LONG = 0x0000000b; 36.777 + 36.778 + private static HashMap<String,Integer> mnemocodes = new HashMap<String,Integer>(301, 0.5f); 36.779 + private static String opcExtNamesTab[]=new String[128]; 36.780 + private static String opcPrivExtNamesTab[]=new String[128]; 36.781 + 36.782 + private static void defineNonPriv(int opc, String mnem) { 36.783 + mnemocodes.put(opcExtNamesTab[opc] = mnem, opc_nonpriv * 256 + opc); 36.784 + } 36.785 + 36.786 + private static void definePriv(int opc, String mnem) { 36.787 + mnemocodes.put(opcPrivExtNamesTab[opc] = "priv_" + mnem, opc_priv * 256 + opc); 36.788 + } 36.789 + 36.790 + private static void defineExt(int opc, String mnem) { 36.791 + defineNonPriv(opc, mnem); 36.792 + definePriv(opc, mnem); 36.793 + } 36.794 + 36.795 + static { 36.796 + for (int i = 0; i < opc_wide; i++) { 36.797 + mnemocodes.put(opcNamesTab[i], i); 36.798 + } 36.799 + for (int i = opc_wide + 1; i < opcNamesTab.length; i++) { 36.800 + mnemocodes.put(opcNamesTab[i], i); 36.801 + } 36.802 + mnemocodes.put("invokenonvirtual", opc_invokespecial); 36.803 + 36.804 + mnemocodes.put("iload_w", opc_iload_w); 36.805 + mnemocodes.put("lload_w", opc_lload_w); 36.806 + mnemocodes.put("fload_w", opc_fload_w); 36.807 + mnemocodes.put("dload_w", opc_dload_w); 36.808 + mnemocodes.put("aload_w", opc_aload_w); 36.809 + mnemocodes.put("istore_w", opc_istore_w); 36.810 + mnemocodes.put("lstore_w", opc_lstore_w); 36.811 + mnemocodes.put("fstore_w", opc_fstore_w); 36.812 + mnemocodes.put("dstore_w", opc_dstore_w); 36.813 + mnemocodes.put("astore_w", opc_astore_w); 36.814 + mnemocodes.put("ret_w", opc_ret_w); 36.815 + mnemocodes.put("iinc_w", opc_iinc_w); 36.816 + 36.817 + mnemocodes.put("nonpriv", opc_nonpriv); 36.818 + mnemocodes.put("priv", opc_priv); 36.819 + 36.820 + defineExt(0, "load_ubyte"); 36.821 + defineExt(1, "load_byte"); 36.822 + defineExt(2, "load_char"); 36.823 + defineExt(3, "load_short"); 36.824 + defineExt(4, "load_word"); 36.825 + defineExt(10, "load_char_oe"); 36.826 + defineExt(11, "load_short_oe"); 36.827 + defineExt(12, "load_word_oe"); 36.828 + defineExt(16, "ncload_ubyte"); 36.829 + defineExt(17, "ncload_byte"); 36.830 + defineExt(18, "ncload_char"); 36.831 + defineExt(19, "ncload_short"); 36.832 + defineExt(20, "ncload_word"); 36.833 + defineExt(26, "ncload_char_oe"); 36.834 + defineExt(27, "ncload_short_oe"); 36.835 + defineExt(28, "ncload_word_oe"); 36.836 + defineExt(30, "cache_flush"); 36.837 + defineExt(32, "store_byte"); 36.838 + defineExt(34, "store_short"); 36.839 + defineExt(36, "store_word"); 36.840 + defineExt(42, "store_short_oe"); 36.841 + defineExt(44, "store_word_oe"); 36.842 + defineExt(48, "ncstore_byte"); 36.843 + defineExt(50, "ncstore_short"); 36.844 + defineExt(52, "ncstore_word"); 36.845 + defineExt(58, "ncstore_short_oe"); 36.846 + defineExt(60, "ncstore_word_oe"); 36.847 + defineExt(62, "zero_line"); 36.848 + defineNonPriv(5, "ret_from_sub"); 36.849 + defineNonPriv(63, "enter_sync_method"); 36.850 + definePriv(5, "ret_from_trap"); 36.851 + definePriv(6, "read_dcache_tag"); 36.852 + definePriv(7, "read_dcache_data"); 36.853 + definePriv(14, "read_icache_tag"); 36.854 + definePriv(15, "read_icache_data"); 36.855 + definePriv(22, "powerdown"); 36.856 + definePriv(23, "read_scache_data"); 36.857 + definePriv(31, "cache_index_flush"); 36.858 + definePriv(38, "write_dcache_tag"); 36.859 + definePriv(39, "write_dcache_data"); 36.860 + definePriv(46, "write_icache_tag"); 36.861 + definePriv(47, "write_icache_data"); 36.862 + definePriv(54, "reset"); 36.863 + definePriv(55, "write_scache_data"); 36.864 + for (int i = 0; i < 32; i++) { 36.865 + definePriv(i + 64, "read_reg_" + i); 36.866 + } 36.867 + for (int i = 0; i < 32; i++) { 36.868 + definePriv(i + 96, "write_reg_" + i); 36.869 + } 36.870 + } 36.871 +}
37.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 37.2 +++ b/src/share/classes/com/sun/tools/classfile/RuntimeAnnotations_attribute.java Tue Jun 03 13:26:47 2008 -0700 37.3 @@ -0,0 +1,61 @@ 37.4 +/* 37.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. 37.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 37.7 + * 37.8 + * This code is free software; you can redistribute it and/or modify it 37.9 + * under the terms of the GNU General Public License version 2 only, as 37.10 + * published by the Free Software Foundation. Sun designates this 37.11 + * particular file as subject to the "Classpath" exception as provided 37.12 + * by Sun in the LICENSE file that accompanied this code. 37.13 + * 37.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 37.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 37.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 37.17 + * version 2 for more details (a copy is included in the LICENSE file that 37.18 + * accompanied this code). 37.19 + * 37.20 + * You should have received a copy of the GNU General Public License version 37.21 + * 2 along with this work; if not, write to the Free Software Foundation, 37.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 37.23 + * 37.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 37.25 + * CA 95054 USA or visit www.sun.com if you need additional information or 37.26 + * have any questions. 37.27 + */ 37.28 + 37.29 +package com.sun.tools.classfile; 37.30 + 37.31 +import java.io.IOException; 37.32 + 37.33 +/** 37.34 + * See JVMS3, section 4.8.16 and 4.8.17. 37.35 + * 37.36 + * <p><b>This is NOT part of any API supported by Sun Microsystems. If 37.37 + * you write code that depends on this, you do so at your own risk. 37.38 + * This code and its internal interfaces are subject to change or 37.39 + * deletion without notice.</b> 37.40 + */ 37.41 +public abstract class RuntimeAnnotations_attribute extends Attribute { 37.42 + protected RuntimeAnnotations_attribute(ClassReader cr, int name_index, int length) 37.43 + throws IOException, Annotation.InvalidAnnotation { 37.44 + super(name_index, length); 37.45 + int num_annotations = cr.readUnsignedShort(); 37.46 + annotations = new Annotation[num_annotations]; 37.47 + for (int i = 0; i < annotations.length; i++) 37.48 + annotations[i] = new Annotation(cr); 37.49 + } 37.50 + 37.51 + protected RuntimeAnnotations_attribute(int name_index, Annotation[] annotations) { 37.52 + super(name_index, length(annotations)); 37.53 + this.annotations = annotations; 37.54 + } 37.55 + 37.56 + private static int length(Annotation[] annos) { 37.57 + int n = 2; 37.58 + for (Annotation anno: annos) 37.59 + n += anno.length(); 37.60 + return n; 37.61 + } 37.62 + 37.63 + public final Annotation[] annotations; 37.64 +}
38.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 38.2 +++ b/src/share/classes/com/sun/tools/classfile/RuntimeInvisibleAnnotations_attribute.java Tue Jun 03 13:26:47 2008 -0700 38.3 @@ -0,0 +1,56 @@ 38.4 +/* 38.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. 38.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 38.7 + * 38.8 + * This code is free software; you can redistribute it and/or modify it 38.9 + * under the terms of the GNU General Public License version 2 only, as 38.10 + * published by the Free Software Foundation. Sun designates this 38.11 + * particular file as subject to the "Classpath" exception as provided 38.12 + * by Sun in the LICENSE file that accompanied this code. 38.13 + * 38.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 38.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 38.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 38.17 + * version 2 for more details (a copy is included in the LICENSE file that 38.18 + * accompanied this code). 38.19 + * 38.20 + * You should have received a copy of the GNU General Public License version 38.21 + * 2 along with this work; if not, write to the Free Software Foundation, 38.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 38.23 + * 38.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 38.25 + * CA 95054 USA or visit www.sun.com if you need additional information or 38.26 + * have any questions. 38.27 + */ 38.28 + 38.29 +package com.sun.tools.classfile; 38.30 + 38.31 +import java.io.IOException; 38.32 + 38.33 +/** 38.34 + * See JVMS3, section 4.8.17. 38.35 + * 38.36 + * <p><b>This is NOT part of any API supported by Sun Microsystems. If 38.37 + * you write code that depends on this, you do so at your own risk. 38.38 + * This code and its internal interfaces are subject to change or 38.39 + * deletion without notice.</b> 38.40 + */ 38.41 +public class RuntimeInvisibleAnnotations_attribute extends RuntimeAnnotations_attribute { 38.42 + RuntimeInvisibleAnnotations_attribute(ClassReader cr, int name_index, int length) 38.43 + throws IOException, AttributeException { 38.44 + super(cr, name_index, length); 38.45 + } 38.46 + 38.47 + public RuntimeInvisibleAnnotations_attribute(ConstantPool cp, Annotation[] annotations) 38.48 + throws ConstantPoolException { 38.49 + this(cp.getUTF8Index(Attribute.RuntimeInvisibleAnnotations), annotations); 38.50 + } 38.51 + 38.52 + public RuntimeInvisibleAnnotations_attribute(int name_index, Annotation[] annotations) { 38.53 + super(name_index, annotations); 38.54 + } 38.55 + 38.56 + public <R, P> R accept(Visitor<R, P> visitor, P p) { 38.57 + return visitor.visitRuntimeInvisibleAnnotations(this, p); 38.58 + } 38.59 +}
39.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 39.2 +++ b/src/share/classes/com/sun/tools/classfile/RuntimeInvisibleParameterAnnotations_attribute.java Tue Jun 03 13:26:47 2008 -0700 39.3 @@ -0,0 +1,56 @@ 39.4 +/* 39.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. 39.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 39.7 + * 39.8 + * This code is free software; you can redistribute it and/or modify it 39.9 + * under the terms of the GNU General Public License version 2 only, as 39.10 + * published by the Free Software Foundation. Sun designates this 39.11 + * particular file as subject to the "Classpath" exception as provided 39.12 + * by Sun in the LICENSE file that accompanied this code. 39.13 + * 39.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 39.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 39.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 39.17 + * version 2 for more details (a copy is included in the LICENSE file that 39.18 + * accompanied this code). 39.19 + * 39.20 + * You should have received a copy of the GNU General Public License version 39.21 + * 2 along with this work; if not, write to the Free Software Foundation, 39.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 39.23 + * 39.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 39.25 + * CA 95054 USA or visit www.sun.com if you need additional information or 39.26 + * have any questions. 39.27 + */ 39.28 + 39.29 +package com.sun.tools.classfile; 39.30 + 39.31 +import java.io.IOException; 39.32 + 39.33 +/** 39.34 + * See JVMS3, section 4.8.18. 39.35 + * 39.36 + * <p><b>This is NOT part of any API supported by Sun Microsystems. If 39.37 + * you write code that depends on this, you do so at your own risk. 39.38 + * This code and its internal interfaces are subject to change or 39.39 + * deletion without notice.</b> 39.40 + */ 39.41 +public class RuntimeInvisibleParameterAnnotations_attribute extends RuntimeParameterAnnotations_attribute { 39.42 + RuntimeInvisibleParameterAnnotations_attribute(ClassReader cr, int name_index, int length) 39.43 + throws IOException, Annotation.InvalidAnnotation { 39.44 + super(cr, name_index, length); 39.45 + } 39.46 + 39.47 + public RuntimeInvisibleParameterAnnotations_attribute(ConstantPool cp, Annotation[][] parameter_annotations) 39.48 + throws ConstantPoolException { 39.49 + this(cp.getUTF8Index(Attribute.RuntimeInvisibleParameterAnnotations), parameter_annotations); 39.50 + } 39.51 + 39.52 + public RuntimeInvisibleParameterAnnotations_attribute(int name_index, Annotation[][] parameter_annotations) { 39.53 + super(name_index, parameter_annotations); 39.54 + } 39.55 + 39.56 + public <R, P> R accept(Visitor<R, P> visitor, P p) { 39.57 + return visitor.visitRuntimeInvisibleParameterAnnotations(this, p); 39.58 + } 39.59 +}
40.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 40.2 +++ b/src/share/classes/com/sun/tools/classfile/RuntimeParameterAnnotations_attribute.java Tue Jun 03 13:26:47 2008 -0700 40.3 @@ -0,0 +1,70 @@ 40.4 +/* 40.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. 40.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 40.7 + * 40.8 + * This code is free software; you can redistribute it and/or modify it 40.9 + * under the terms of the GNU General Public License version 2 only, as 40.10 + * published by the Free Software Foundation. Sun designates this 40.11 + * particular file as subject to the "Classpath" exception as provided 40.12 + * by Sun in the LICENSE file that accompanied this code. 40.13 + * 40.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 40.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 40.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 40.17 + * version 2 for more details (a copy is included in the LICENSE file that 40.18 + * accompanied this code). 40.19 + * 40.20 + * You should have received a copy of the GNU General Public License version 40.21 + * 2 along with this work; if not, write to the Free Software Foundation, 40.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 40.23 + * 40.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 40.25 + * CA 95054 USA or visit www.sun.com if you need additional information or 40.26 + * have any questions. 40.27 + */ 40.28 + 40.29 +package com.sun.tools.classfile; 40.30 + 40.31 +import java.io.IOException; 40.32 + 40.33 +/** 40.34 + * See JVMS3, section 4.8.18 and 4.8.19. 40.35 + * 40.36 + * <p><b>This is NOT part of any API supported by Sun Microsystems. If 40.37 + * you write code that depends on this, you do so at your own risk. 40.38 + * This code and its internal interfaces are subject to change or 40.39 + * deletion without notice.</b> 40.40 + */ 40.41 +public abstract class RuntimeParameterAnnotations_attribute extends Attribute { 40.42 + RuntimeParameterAnnotations_attribute(ClassReader cr, int name_index, int length) 40.43 + throws IOException, Annotation.InvalidAnnotation { 40.44 + super(name_index, length); 40.45 + int num_parameters = cr.readUnsignedByte(); 40.46 + parameter_annotations = new Annotation[num_parameters][]; 40.47 + for (int p = 0; p < parameter_annotations.length; p++) { 40.48 + int num_annotations = cr.readUnsignedShort(); 40.49 + Annotation[] annotations = new Annotation[num_annotations]; 40.50 + for (int i = 0; i < num_annotations; i++) 40.51 + annotations[i] = new Annotation(cr); 40.52 + parameter_annotations[p] = annotations; 40.53 + } 40.54 + } 40.55 + 40.56 + protected RuntimeParameterAnnotations_attribute(int name_index, Annotation[][] parameter_annotations) { 40.57 + super(name_index, length(parameter_annotations)); 40.58 + this.parameter_annotations = parameter_annotations; 40.59 + } 40.60 + 40.61 + private static int length(Annotation[][] anno_arrays) { 40.62 + int n = 1; 40.63 + for (Annotation[] anno_array: anno_arrays) { 40.64 + n += 2; 40.65 + for (Annotation anno: anno_array) 40.66 + n += anno.length(); 40.67 + } 40.68 + return n; 40.69 + } 40.70 + 40.71 + public final Annotation[][] parameter_annotations; 40.72 +} 40.73 +
41.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 41.2 +++ b/src/share/classes/com/sun/tools/classfile/RuntimeVisibleAnnotations_attribute.java Tue Jun 03 13:26:47 2008 -0700 41.3 @@ -0,0 +1,56 @@ 41.4 +/* 41.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. 41.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 41.7 + * 41.8 + * This code is free software; you can redistribute it and/or modify it 41.9 + * under the terms of the GNU General Public License version 2 only, as 41.10 + * published by the Free Software Foundation. Sun designates this 41.11 + * particular file as subject to the "Classpath" exception as provided 41.12 + * by Sun in the LICENSE file that accompanied this code. 41.13 + * 41.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 41.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 41.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 41.17 + * version 2 for more details (a copy is included in the LICENSE file that 41.18 + * accompanied this code). 41.19 + * 41.20 + * You should have received a copy of the GNU General Public License version 41.21 + * 2 along with this work; if not, write to the Free Software Foundation, 41.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 41.23 + * 41.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 41.25 + * CA 95054 USA or visit www.sun.com if you need additional information or 41.26 + * have any questions. 41.27 + */ 41.28 + 41.29 +package com.sun.tools.classfile; 41.30 + 41.31 +import java.io.IOException; 41.32 + 41.33 +/** 41.34 + * See JVMS3, section 4.8.16. 41.35 + * 41.36 + * <p><b>This is NOT part of any API supported by Sun Microsystems. If 41.37 + * you write code that depends on this, you do so at your own risk. 41.38 + * This code and its internal interfaces are subject to change or 41.39 + * deletion without notice.</b> 41.40 + */ 41.41 +public class RuntimeVisibleAnnotations_attribute extends RuntimeAnnotations_attribute { 41.42 + RuntimeVisibleAnnotations_attribute(ClassReader cr, int name_index, int length) 41.43 + throws IOException, Annotation.InvalidAnnotation { 41.44 + super(cr, name_index, length); 41.45 + } 41.46 + 41.47 + public RuntimeVisibleAnnotations_attribute(ConstantPool cp, Annotation[] annotations) 41.48 + throws ConstantPoolException { 41.49 + this(cp.getUTF8Index(Attribute.RuntimeVisibleAnnotations), annotations); 41.50 + } 41.51 + 41.52 + public RuntimeVisibleAnnotations_attribute(int name_index, Annotation[] annotations) { 41.53 + super(name_index, annotations); 41.54 + } 41.55 + 41.56 + public <R, P> R accept(Visitor<R, P> visitor, P p) { 41.57 + return visitor.visitRuntimeVisibleAnnotations(this, p); 41.58 + } 41.59 +}
42.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 42.2 +++ b/src/share/classes/com/sun/tools/classfile/RuntimeVisibleParameterAnnotations_attribute.java Tue Jun 03 13:26:47 2008 -0700 42.3 @@ -0,0 +1,56 @@ 42.4 +/* 42.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. 42.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 42.7 + * 42.8 + * This code is free software; you can redistribute it and/or modify it 42.9 + * under the terms of the GNU General Public License version 2 only, as 42.10 + * published by the Free Software Foundation. Sun designates this 42.11 + * particular file as subject to the "Classpath" exception as provided 42.12 + * by Sun in the LICENSE file that accompanied this code. 42.13 + * 42.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 42.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 42.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 42.17 + * version 2 for more details (a copy is included in the LICENSE file that 42.18 + * accompanied this code). 42.19 + * 42.20 + * You should have received a copy of the GNU General Public License version 42.21 + * 2 along with this work; if not, write to the Free Software Foundation, 42.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 42.23 + * 42.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 42.25 + * CA 95054 USA or visit www.sun.com if you need additional information or 42.26 + * have any questions. 42.27 + */ 42.28 + 42.29 +package com.sun.tools.classfile; 42.30 + 42.31 +import java.io.IOException; 42.32 + 42.33 +/** 42.34 + * See JVMS3, section 4.8.18. 42.35 + * 42.36 + * <p><b>This is NOT part of any API supported by Sun Microsystems. If 42.37 + * you write code that depends on this, you do so at your own risk. 42.38 + * This code and its internal interfaces are subject to change or 42.39 + * deletion without notice.</b> 42.40 + */ 42.41 +public class RuntimeVisibleParameterAnnotations_attribute extends RuntimeParameterAnnotations_attribute { 42.42 + RuntimeVisibleParameterAnnotations_attribute(ClassReader cr, int name_index, int length) 42.43 + throws IOException, Annotation.InvalidAnnotation { 42.44 + super(cr, name_index, length); 42.45 + } 42.46 + 42.47 + public RuntimeVisibleParameterAnnotations_attribute(ConstantPool cp, Annotation[][] parameter_annotations) 42.48 + throws ConstantPoolException { 42.49 + this(cp.getUTF8Index(Attribute.RuntimeVisibleParameterAnnotations), parameter_annotations); 42.50 + } 42.51 + 42.52 + public RuntimeVisibleParameterAnnotations_attribute(int name_index, Annotation[][] parameter_annotations) { 42.53 + super(name_index, parameter_annotations); 42.54 + } 42.55 + 42.56 + public <R, P> R accept(Visitor<R, P> visitor, P p) { 42.57 + return visitor.visitRuntimeVisibleParameterAnnotations(this, p); 42.58 + } 42.59 +}
43.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 43.2 +++ b/src/share/classes/com/sun/tools/classfile/Signature.java Tue Jun 03 13:26:47 2008 -0700 43.3 @@ -0,0 +1,275 @@ 43.4 +/* 43.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. 43.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 43.7 + * 43.8 + * This code is free software; you can redistribute it and/or modify it 43.9 + * under the terms of the GNU General Public License version 2 only, as 43.10 + * published by the Free Software Foundation. Sun designates this 43.11 + * particular file as subject to the "Classpath" exception as provided 43.12 + * by Sun in the LICENSE file that accompanied this code. 43.13 + * 43.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 43.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 43.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 43.17 + * version 2 for more details (a copy is included in the LICENSE file that 43.18 + * accompanied this code). 43.19 + * 43.20 + * You should have received a copy of the GNU General Public License version 43.21 + * 2 along with this work; if not, write to the Free Software Foundation, 43.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 43.23 + * 43.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 43.25 + * CA 95054 USA or visit www.sun.com if you need additional information or 43.26 + * have any questions. 43.27 + */ 43.28 + 43.29 +package com.sun.tools.classfile; 43.30 + 43.31 +import java.util.ArrayList; 43.32 +import java.util.List; 43.33 + 43.34 +/** 43.35 + * See JVMS3 4.4.4. 43.36 + * 43.37 + * <p><b>This is NOT part of any API supported by Sun Microsystems. If 43.38 + * you write code that depends on this, you do so at your own risk. 43.39 + * This code and its internal interfaces are subject to change or 43.40 + * deletion without notice.</b> 43.41 + */ 43.42 +public class Signature extends Descriptor { 43.43 + 43.44 + public Signature(int index) { 43.45 + super(index); 43.46 + } 43.47 + 43.48 + public Type getType(ConstantPool constant_pool) throws ConstantPoolException { 43.49 + if (type == null) 43.50 + type = parse(getValue(constant_pool)); 43.51 + return type; 43.52 + } 43.53 + 43.54 + @Override 43.55 + public int getParameterCount(ConstantPool constant_pool) throws ConstantPoolException { 43.56 + Type.MethodType m = (Type.MethodType) getType(constant_pool); 43.57 + return m.argTypes.size(); 43.58 + } 43.59 + 43.60 + @Override 43.61 + public String getParameterTypes(ConstantPool constant_pool) throws ConstantPoolException { 43.62 + Type.MethodType m = (Type.MethodType) getType(constant_pool); 43.63 + StringBuilder sb = new StringBuilder(); 43.64 + sb.append("("); 43.65 + String sep = ""; 43.66 + for (Type argType: m.argTypes) { 43.67 + sb.append(sep); 43.68 + sb.append(argType); 43.69 + sep = ", "; 43.70 + } 43.71 + sb.append(")"); 43.72 + return sb.toString(); 43.73 + } 43.74 + 43.75 + @Override 43.76 + public String getReturnType(ConstantPool constant_pool) throws ConstantPoolException { 43.77 + Type.MethodType m = (Type.MethodType) getType(constant_pool); 43.78 + return m.returnType.toString(); 43.79 + } 43.80 + 43.81 + @Override 43.82 + public String getFieldType(ConstantPool constant_pool) throws ConstantPoolException { 43.83 + return getType(constant_pool).toString(); 43.84 + } 43.85 + 43.86 + private Type parse(String sig) { 43.87 + this.sig = sig; 43.88 + sigp = 0; 43.89 + 43.90 + List<Type> typeArgTypes = null; 43.91 + if (sig.charAt(sigp) == '<') 43.92 + typeArgTypes = parseTypeArgTypes(); 43.93 + 43.94 + if (sig.charAt(sigp) == '(') { 43.95 + List<Type> argTypes = parseTypeSignatures(')'); 43.96 + Type returnType = parseTypeSignature(); 43.97 + List<Type> throwsTypes = null; 43.98 + while (sigp < sig.length() && sig.charAt(sigp) == '^') { 43.99 + sigp++; 43.100 + if (throwsTypes == null) 43.101 + throwsTypes = new ArrayList<Type>(); 43.102 + throwsTypes.add(parseTypeSignature()); 43.103 + } 43.104 + return new Type.MethodType(typeArgTypes, argTypes, returnType, throwsTypes); 43.105 + } else { 43.106 + Type t = parseTypeSignature(); 43.107 + if (typeArgTypes == null && sigp == sig.length()) 43.108 + return t; 43.109 + Type superclass = t; 43.110 + List<Type> superinterfaces = new ArrayList<Type>(); 43.111 + while (sigp < sig.length()) 43.112 + superinterfaces.add(parseTypeSignature()); 43.113 + return new Type.ClassSigType(typeArgTypes, superclass, superinterfaces); 43.114 + 43.115 + } 43.116 + } 43.117 + 43.118 + private Type parseTypeSignature() { 43.119 + switch (sig.charAt(sigp)) { 43.120 + case 'B': 43.121 + sigp++; 43.122 + return new Type.SimpleType("byte"); 43.123 + 43.124 + case 'C': 43.125 + sigp++; 43.126 + return new Type.SimpleType("char"); 43.127 + 43.128 + case 'D': 43.129 + sigp++; 43.130 + return new Type.SimpleType("double"); 43.131 + 43.132 + case 'F': 43.133 + sigp++; 43.134 + return new Type.SimpleType("float"); 43.135 + 43.136 + case 'I': 43.137 + sigp++; 43.138 + return new Type.SimpleType("int"); 43.139 + 43.140 + case 'J': 43.141 + sigp++; 43.142 + return new Type.SimpleType("long"); 43.143 + 43.144 + case 'L': 43.145 + return parseClassTypeSignature(); 43.146 + 43.147 + case 'S': 43.148 + sigp++; 43.149 + return new Type.SimpleType("short"); 43.150 + 43.151 + case 'T': 43.152 + return parseTypeVariableSignature(); 43.153 + 43.154 + case 'V': 43.155 + sigp++; 43.156 + return new Type.SimpleType("void"); 43.157 + 43.158 + case 'Z': 43.159 + sigp++; 43.160 + return new Type.SimpleType("boolean"); 43.161 + 43.162 + case '[': 43.163 + sigp++; 43.164 + return new Type.ArrayType(parseTypeSignature()); 43.165 + 43.166 + case '*': 43.167 + sigp++; 43.168 + return new Type.WildcardType(); 43.169 + 43.170 + case '+': 43.171 + sigp++; 43.172 + return new Type.WildcardType("extends", parseTypeSignature()); 43.173 + 43.174 + case '-': 43.175 + sigp++; 43.176 + return new Type.WildcardType("super", parseTypeSignature()); 43.177 + 43.178 + default: 43.179 + throw new IllegalStateException(debugInfo()); 43.180 + } 43.181 + } 43.182 + 43.183 + private List<Type> parseTypeSignatures(char term) { 43.184 + sigp++; 43.185 + List<Type> types = new ArrayList<Type>(); 43.186 + while (sig.charAt(sigp) != term) 43.187 + types.add(parseTypeSignature()); 43.188 + sigp++; 43.189 + return types; 43.190 + } 43.191 + 43.192 + private Type parseClassTypeSignature() { 43.193 + assert sig.charAt(sigp) == 'L'; 43.194 + sigp++; 43.195 + return parseClassTypeSignatureRest(); 43.196 + } 43.197 + 43.198 + private Type parseClassTypeSignatureRest() { 43.199 + StringBuilder sb = new StringBuilder(); 43.200 + Type t = null; 43.201 + char sigch; 43.202 + while (true) { 43.203 + switch (sigch = sig.charAt(sigp)) { 43.204 + case '/': 43.205 + sigp++; 43.206 + sb.append("."); 43.207 + break; 43.208 + 43.209 + case '.': 43.210 + sigp++; 43.211 + if (t == null) 43.212 + t = new Type.SimpleType(sb.toString()); 43.213 + return new Type.InnerClassType(t, parseClassTypeSignatureRest()); 43.214 + 43.215 + case ';': 43.216 + sigp++; 43.217 + if (t == null) 43.218 + t = new Type.SimpleType(sb.toString()); 43.219 + return t; 43.220 + 43.221 + case '<': 43.222 + List<Type> argTypes = parseTypeSignatures('>'); 43.223 + t = new Type.ClassType(sb.toString(), argTypes); 43.224 + break; 43.225 + 43.226 + default: 43.227 + sigp++; 43.228 + sb.append(sigch); 43.229 + break; 43.230 + } 43.231 + } 43.232 + } 43.233 + 43.234 + private List<Type> parseTypeArgTypes() { 43.235 + assert sig.charAt(sigp) == '<'; 43.236 + sigp++; 43.237 + List<Type> types = null; 43.238 + types = new ArrayList<Type>(); 43.239 + while (sig.charAt(sigp) != '>') 43.240 + types.add(parseTypeArgType()); 43.241 + sigp++; 43.242 + return types; 43.243 + } 43.244 + 43.245 + private Type parseTypeArgType() { 43.246 + int sep = sig.indexOf(":", sigp); 43.247 + String name = sig.substring(sigp, sep); 43.248 + Type classBound = null; 43.249 + List<Type> interfaceBounds = null; 43.250 + sigp = sep + 1; 43.251 + if (sig.charAt(sigp) != ':') 43.252 + classBound = parseTypeSignature(); 43.253 + while (sig.charAt(sigp) == ':') { 43.254 + sigp++; 43.255 + if (interfaceBounds == null) 43.256 + interfaceBounds = new ArrayList<Type>(); 43.257 + interfaceBounds.add(parseTypeSignature()); 43.258 + } 43.259 + return new Type.TypeArgType(name, classBound, interfaceBounds); 43.260 + } 43.261 + 43.262 + private Type parseTypeVariableSignature() { 43.263 + sigp++; 43.264 + int sep = sig.indexOf(';', sigp); 43.265 + Type t = new Type.SimpleType(sig.substring(sigp, sep)); 43.266 + sigp = sep + 1; 43.267 + return t; 43.268 + } 43.269 + 43.270 + private String debugInfo() { 43.271 + return sig.substring(0, sigp) + "!" + sig.charAt(sigp) + "!" + sig.substring(sigp+1); 43.272 + } 43.273 + 43.274 + private String sig; 43.275 + private int sigp; 43.276 + 43.277 + private Type type; 43.278 +}
44.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 44.2 +++ b/src/share/classes/com/sun/tools/classfile/Signature_attribute.java Tue Jun 03 13:26:47 2008 -0700 44.3 @@ -0,0 +1,67 @@ 44.4 +/* 44.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. 44.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 44.7 + * 44.8 + * This code is free software; you can redistribute it and/or modify it 44.9 + * under the terms of the GNU General Public License version 2 only, as 44.10 + * published by the Free Software Foundation. Sun designates this 44.11 + * particular file as subject to the "Classpath" exception as provided 44.12 + * by Sun in the LICENSE file that accompanied this code. 44.13 + * 44.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 44.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 44.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 44.17 + * version 2 for more details (a copy is included in the LICENSE file that 44.18 + * accompanied this code). 44.19 + * 44.20 + * You should have received a copy of the GNU General Public License version 44.21 + * 2 along with this work; if not, write to the Free Software Foundation, 44.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 44.23 + * 44.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 44.25 + * CA 95054 USA or visit www.sun.com if you need additional information or 44.26 + * have any questions. 44.27 + */ 44.28 + 44.29 +package com.sun.tools.classfile; 44.30 + 44.31 +import java.io.IOException; 44.32 + 44.33 +/** 44.34 + * See JVMS3, section 4.8.9. 44.35 + * 44.36 + * <p><b>This is NOT part of any API supported by Sun Microsystems. If 44.37 + * you write code that depends on this, you do so at your own risk. 44.38 + * This code and its internal interfaces are subject to change or 44.39 + * deletion without notice.</b> 44.40 + */ 44.41 +public class Signature_attribute extends Attribute { 44.42 + Signature_attribute(ClassReader cr, int name_index, int length) throws IOException { 44.43 + super(name_index, length); 44.44 + signature_index = cr.readUnsignedShort(); 44.45 + } 44.46 + 44.47 + public Signature_attribute(ConstantPool constant_pool, int signature_index) 44.48 + throws ConstantPoolException { 44.49 + this(constant_pool.getUTF8Index(Attribute.Signature), signature_index); 44.50 + } 44.51 + 44.52 + public Signature_attribute(int name_index, int signature_index) { 44.53 + super(name_index, 2); 44.54 + this.signature_index = signature_index; 44.55 + } 44.56 + 44.57 + public String getSignature(ConstantPool constant_pool) throws ConstantPoolException { 44.58 + return constant_pool.getUTF8Value(signature_index); 44.59 + } 44.60 + 44.61 + public Signature getParsedSignature() { 44.62 + return new Signature(signature_index); 44.63 + } 44.64 + 44.65 + public <R, D> R accept(Visitor<R, D> visitor, D data) { 44.66 + return visitor.visitSignature(this, data); 44.67 + } 44.68 + 44.69 + public final int signature_index; 44.70 +}
45.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 45.2 +++ b/src/share/classes/com/sun/tools/classfile/SourceDebugExtension_attribute.java Tue Jun 03 13:26:47 2008 -0700 45.3 @@ -0,0 +1,71 @@ 45.4 +/* 45.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. 45.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 45.7 + * 45.8 + * This code is free software; you can redistribute it and/or modify it 45.9 + * under the terms of the GNU General Public License version 2 only, as 45.10 + * published by the Free Software Foundation. Sun designates this 45.11 + * particular file as subject to the "Classpath" exception as provided 45.12 + * by Sun in the LICENSE file that accompanied this code. 45.13 + * 45.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 45.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 45.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 45.17 + * version 2 for more details (a copy is included in the LICENSE file that 45.18 + * accompanied this code). 45.19 + * 45.20 + * You should have received a copy of the GNU General Public License version 45.21 + * 2 along with this work; if not, write to the Free Software Foundation, 45.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 45.23 + * 45.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 45.25 + * CA 95054 USA or visit www.sun.com if you need additional information or 45.26 + * have any questions. 45.27 + */ 45.28 + 45.29 +package com.sun.tools.classfile; 45.30 + 45.31 +import java.io.ByteArrayInputStream; 45.32 +import java.io.DataInputStream; 45.33 +import java.io.IOException; 45.34 + 45.35 +/** 45.36 + * See JVMS3, section 4.8.15. 45.37 + * 45.38 + * <p><b>This is NOT part of any API supported by Sun Microsystems. If 45.39 + * you write code that depends on this, you do so at your own risk. 45.40 + * This code and its internal interfaces are subject to change or 45.41 + * deletion without notice.</b> 45.42 + */ 45.43 +public class SourceDebugExtension_attribute extends Attribute { 45.44 + SourceDebugExtension_attribute(ClassReader cr, int name_index, int length) throws IOException { 45.45 + super(name_index, length); 45.46 + debug_extension = new byte[attribute_length]; 45.47 + cr.readFully(debug_extension); 45.48 + } 45.49 + 45.50 + public SourceDebugExtension_attribute(ConstantPool constant_pool, byte[] debug_extension) 45.51 + throws ConstantPoolException { 45.52 + this(constant_pool.getUTF8Index(Attribute.SourceDebugExtension), debug_extension); 45.53 + } 45.54 + 45.55 + public SourceDebugExtension_attribute(int name_index, byte[] debug_extension) { 45.56 + super(name_index, debug_extension.length); 45.57 + this.debug_extension = debug_extension; 45.58 + } 45.59 + 45.60 + public String getValue() { 45.61 + DataInputStream d = new DataInputStream(new ByteArrayInputStream(debug_extension)); 45.62 + try { 45.63 + return d.readUTF(); 45.64 + } catch (IOException e) { 45.65 + return null; 45.66 + } 45.67 + } 45.68 + 45.69 + public <R, D> R accept(Visitor<R, D> visitor, D data) { 45.70 + return visitor.visitSourceDebugExtension(this, data); 45.71 + } 45.72 + 45.73 + public final byte[] debug_extension; 45.74 +}
46.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 46.2 +++ b/src/share/classes/com/sun/tools/classfile/SourceFile_attribute.java Tue Jun 03 13:26:47 2008 -0700 46.3 @@ -0,0 +1,63 @@ 46.4 +/* 46.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. 46.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 46.7 + * 46.8 + * This code is free software; you can redistribute it and/or modify it 46.9 + * under the terms of the GNU General Public License version 2 only, as 46.10 + * published by the Free Software Foundation. Sun designates this 46.11 + * particular file as subject to the "Classpath" exception as provided 46.12 + * by Sun in the LICENSE file that accompanied this code. 46.13 + * 46.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 46.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 46.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 46.17 + * version 2 for more details (a copy is included in the LICENSE file that 46.18 + * accompanied this code). 46.19 + * 46.20 + * You should have received a copy of the GNU General Public License version 46.21 + * 2 along with this work; if not, write to the Free Software Foundation, 46.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 46.23 + * 46.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 46.25 + * CA 95054 USA or visit www.sun.com if you need additional information or 46.26 + * have any questions. 46.27 + */ 46.28 + 46.29 +package com.sun.tools.classfile; 46.30 + 46.31 +import java.io.IOException; 46.32 + 46.33 +/** 46.34 + * See JVMS3, section 4.8.10. 46.35 + * 46.36 + * <p><b>This is NOT part of any API supported by Sun Microsystems. If 46.37 + * you write code that depends on this, you do so at your own risk. 46.38 + * This code and its internal interfaces are subject to change or 46.39 + * deletion without notice.</b> 46.40 + */ 46.41 +public class SourceFile_attribute extends Attribute { 46.42 + SourceFile_attribute(ClassReader cr, int name_index, int length) throws IOException { 46.43 + super(name_index, length); 46.44 + sourcefile_index = cr.readUnsignedShort(); 46.45 + } 46.46 + 46.47 + public SourceFile_attribute(ConstantPool constant_pool, int sourcefile_index) 46.48 + throws ConstantPoolException { 46.49 + this(constant_pool.getUTF8Index(Attribute.SourceFile), sourcefile_index); 46.50 + } 46.51 + 46.52 + public SourceFile_attribute(int name_index, int sourcefile_index) { 46.53 + super(name_index, 2); 46.54 + this.sourcefile_index = sourcefile_index; 46.55 + } 46.56 + 46.57 + public String getSourceFile(ConstantPool constant_pool) throws ConstantPoolException { 46.58 + return constant_pool.getUTF8Value(sourcefile_index); 46.59 + } 46.60 + 46.61 + public <R, P> R accept(Visitor<R, P> visitor, P p) { 46.62 + return visitor.visitSourceFile(this, p); 46.63 + } 46.64 + 46.65 + public final int sourcefile_index; 46.66 +}
47.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 47.2 +++ b/src/share/classes/com/sun/tools/classfile/SourceID_attribute.java Tue Jun 03 13:26:47 2008 -0700 47.3 @@ -0,0 +1,61 @@ 47.4 +/* 47.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. 47.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 47.7 + * 47.8 + * This code is free software; you can redistribute it and/or modify it 47.9 + * under the terms of the GNU General Public License version 2 only, as 47.10 + * published by the Free Software Foundation. Sun designates this 47.11 + * particular file as subject to the "Classpath" exception as provided 47.12 + * by Sun in the LICENSE file that accompanied this code. 47.13 + * 47.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 47.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 47.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 47.17 + * version 2 for more details (a copy is included in the LICENSE file that 47.18 + * accompanied this code). 47.19 + * 47.20 + * You should have received a copy of the GNU General Public License version 47.21 + * 2 along with this work; if not, write to the Free Software Foundation, 47.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 47.23 + * 47.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 47.25 + * CA 95054 USA or visit www.sun.com if you need additional information or 47.26 + * have any questions. 47.27 + */ 47.28 +package com.sun.tools.classfile; 47.29 + 47.30 +import java.io.IOException; 47.31 + 47.32 +/** 47.33 + * <p><b>This is NOT part of any API supported by Sun Microsystems. If 47.34 + * you write code that depends on this, you do so at your own risk. 47.35 + * This code and its internal interfaces are subject to change or 47.36 + * deletion without notice.</b> 47.37 + */ 47.38 +public class SourceID_attribute extends Attribute { 47.39 + 47.40 + SourceID_attribute(ClassReader cr, int name_index, int length) throws IOException { 47.41 + super(name_index, length); 47.42 + sourceID_index = cr.readUnsignedShort(); 47.43 + } 47.44 + 47.45 + public SourceID_attribute(ConstantPool constant_pool, int sourceID_index) 47.46 + throws ConstantPoolException { 47.47 + this(constant_pool.getUTF8Index(Attribute.SourceID), sourceID_index); 47.48 + } 47.49 + 47.50 + public SourceID_attribute(int name_index, int sourceID_index) { 47.51 + super(name_index, 2); 47.52 + this.sourceID_index = sourceID_index; 47.53 + } 47.54 + 47.55 + String getSourceID(ConstantPool constant_pool) throws ConstantPoolException { 47.56 + return constant_pool.getUTF8Value(sourceID_index); 47.57 + } 47.58 + 47.59 + public <R, D> R accept(Visitor<R, D> visitor, D data) { 47.60 + return visitor.visitSourceID(this, data); 47.61 + } 47.62 + 47.63 + public final int sourceID_index; 47.64 +}
48.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 48.2 +++ b/src/share/classes/com/sun/tools/classfile/StackMapTable_attribute.java Tue Jun 03 13:26:47 2008 -0700 48.3 @@ -0,0 +1,349 @@ 48.4 +/* 48.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. 48.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 48.7 + * 48.8 + * This code is free software; you can redistribute it and/or modify it 48.9 + * under the terms of the GNU General Public License version 2 only, as 48.10 + * published by the Free Software Foundation. Sun designates this 48.11 + * particular file as subject to the "Classpath" exception as provided 48.12 + * by Sun in the LICENSE file that accompanied this code. 48.13 + * 48.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 48.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 48.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 48.17 + * version 2 for more details (a copy is included in the LICENSE file that 48.18 + * accompanied this code). 48.19 + * 48.20 + * You should have received a copy of the GNU General Public License version 48.21 + * 2 along with this work; if not, write to the Free Software Foundation, 48.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 48.23 + * 48.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 48.25 + * CA 95054 USA or visit www.sun.com if you need additional information or 48.26 + * have any questions. 48.27 + */ 48.28 + 48.29 +package com.sun.tools.classfile; 48.30 + 48.31 +import java.io.IOException; 48.32 + 48.33 +/** 48.34 + * See JVMS3, section 4.8.4. 48.35 + * 48.36 + * <p><b>This is NOT part of any API supported by Sun Microsystems. If 48.37 + * you write code that depends on this, you do so at your own risk. 48.38 + * This code and its internal interfaces are subject to change or 48.39 + * deletion without notice.</b> 48.40 + */ 48.41 +public class StackMapTable_attribute extends Attribute { 48.42 + static class InvalidStackMap extends AttributeException { 48.43 + InvalidStackMap(String msg) { 48.44 + super(msg); 48.45 + } 48.46 + } 48.47 + 48.48 + StackMapTable_attribute(ClassReader cr, int name_index, int length) 48.49 + throws IOException, InvalidStackMap { 48.50 + super(name_index, length); 48.51 + number_of_entries = cr.readUnsignedShort(); 48.52 + entries = new stack_map_frame[number_of_entries]; 48.53 + for (int i = 0; i < number_of_entries; i++) 48.54 + entries[i] = stack_map_frame.read(cr); 48.55 + } 48.56 + 48.57 + public StackMapTable_attribute(ConstantPool constant_pool, stack_map_frame[] entries) 48.58 + throws ConstantPoolException { 48.59 + this(constant_pool.getUTF8Index(Attribute.StackMapTable), entries); 48.60 + } 48.61 + 48.62 + public StackMapTable_attribute(int name_index, stack_map_frame[] entries) { 48.63 + super(name_index, length(entries)); 48.64 + this.number_of_entries = entries.length; 48.65 + this.entries = entries; 48.66 + } 48.67 + 48.68 + public <R, D> R accept(Visitor<R, D> visitor, D data) { 48.69 + return visitor.visitStackMapTable(this, data); 48.70 + } 48.71 + 48.72 + static int length(stack_map_frame[] entries) { 48.73 + int n = 2; 48.74 + for (stack_map_frame entry: entries) 48.75 + n += entry.length(); 48.76 + return n; 48.77 + } 48.78 + 48.79 + public final int number_of_entries; 48.80 + public final stack_map_frame entries[]; 48.81 + 48.82 + public static abstract class stack_map_frame { 48.83 + static stack_map_frame read(ClassReader cr) 48.84 + throws IOException, InvalidStackMap { 48.85 + int frame_type = cr.readUnsignedByte(); 48.86 + if (frame_type <= 63) 48.87 + return new same_frame(frame_type); 48.88 + else if (frame_type <= 127) 48.89 + return new same_locals_1_stack_item_frame(frame_type, cr); 48.90 + else if (frame_type <= 246) 48.91 + throw new Error("unknown frame_type " + frame_type); 48.92 + else if (frame_type == 247) 48.93 + return new same_locals_1_stack_item_frame_extended(frame_type, cr); 48.94 + else if (frame_type <= 250) 48.95 + return new chop_frame(frame_type, cr); 48.96 + else if (frame_type == 251) 48.97 + return new same_frame_extended(frame_type, cr); 48.98 + else if (frame_type <= 254) 48.99 + return new append_frame(frame_type, cr); 48.100 + else 48.101 + return new full_frame(frame_type, cr); 48.102 + } 48.103 + 48.104 + protected stack_map_frame(int frame_type) { 48.105 + this.frame_type = frame_type; 48.106 + } 48.107 + 48.108 + public int length() { 48.109 + return 1; 48.110 + } 48.111 + 48.112 + public abstract <R,D> R accept(Visitor<R,D> visitor, D data); 48.113 + 48.114 + public final int frame_type; 48.115 + 48.116 + public static interface Visitor<R,P> { 48.117 + R visit_same_frame(same_frame frame, P p); 48.118 + R visit_same_locals_1_stack_item_frame(same_locals_1_stack_item_frame frame, P p); 48.119 + R visit_same_locals_1_stack_item_frame_extended(same_locals_1_stack_item_frame_extended frame, P p); 48.120 + R visit_chop_frame(chop_frame frame, P p); 48.121 + R visit_same_frame_extended(same_frame_extended frame, P p); 48.122 + R visit_append_frame(append_frame frame, P p); 48.123 + R visit_full_frame(full_frame frame, P p); 48.124 + } 48.125 + } 48.126 + 48.127 + public static class same_frame extends stack_map_frame { 48.128 + same_frame(int frame_type) { 48.129 + super(frame_type); 48.130 + } 48.131 + 48.132 + public <R, D> R accept(Visitor<R, D> visitor, D data) { 48.133 + return visitor.visit_same_frame(this, data); 48.134 + } 48.135 + } 48.136 + 48.137 + public static class same_locals_1_stack_item_frame extends stack_map_frame { 48.138 + same_locals_1_stack_item_frame(int frame_type, ClassReader cr) 48.139 + throws IOException, InvalidStackMap { 48.140 + super(frame_type); 48.141 + stack = new verification_type_info[1]; 48.142 + stack[0] = verification_type_info.read(cr); 48.143 + } 48.144 + 48.145 + @Override 48.146 + public int length() { 48.147 + return super.length() + stack[0].length(); 48.148 + } 48.149 + 48.150 + public <R, D> R accept(Visitor<R, D> visitor, D data) { 48.151 + return visitor.visit_same_locals_1_stack_item_frame(this, data); 48.152 + } 48.153 + 48.154 + public final verification_type_info[] stack; 48.155 + } 48.156 + 48.157 + public static class same_locals_1_stack_item_frame_extended extends stack_map_frame { 48.158 + same_locals_1_stack_item_frame_extended(int frame_type, ClassReader cr) 48.159 + throws IOException, InvalidStackMap { 48.160 + super(frame_type); 48.161 + offset_delta = cr.readUnsignedShort(); 48.162 + stack = new verification_type_info[1]; 48.163 + stack[0] = verification_type_info.read(cr); 48.164 + } 48.165 + 48.166 + @Override 48.167 + public int length() { 48.168 + return super.length() + 2 + stack[0].length(); 48.169 + } 48.170 + 48.171 + public <R, D> R accept(Visitor<R, D> visitor, D data) { 48.172 + return visitor.visit_same_locals_1_stack_item_frame_extended(this, data); 48.173 + } 48.174 + 48.175 + public final int offset_delta; 48.176 + public final verification_type_info[] stack; 48.177 + } 48.178 + 48.179 + public static class chop_frame extends stack_map_frame { 48.180 + chop_frame(int frame_type, ClassReader cr) throws IOException { 48.181 + super(frame_type); 48.182 + offset_delta = cr.readUnsignedShort(); 48.183 + } 48.184 + 48.185 + @Override 48.186 + public int length() { 48.187 + return super.length() + 2; 48.188 + } 48.189 + 48.190 + public <R, D> R accept(Visitor<R, D> visitor, D data) { 48.191 + return visitor.visit_chop_frame(this, data); 48.192 + } 48.193 + 48.194 + public final int offset_delta; 48.195 + } 48.196 + 48.197 + public static class same_frame_extended extends stack_map_frame { 48.198 + same_frame_extended(int frame_type, ClassReader cr) throws IOException { 48.199 + super(frame_type); 48.200 + offset_delta = cr.readUnsignedShort(); 48.201 + } 48.202 + 48.203 + @Override 48.204 + public int length() { 48.205 + return super.length() + 2; 48.206 + } 48.207 + 48.208 + public <R, D> R accept(Visitor<R, D> visitor, D data) { 48.209 + return visitor.visit_same_frame_extended(this, data); 48.210 + } 48.211 + 48.212 + public final int offset_delta; 48.213 + } 48.214 + 48.215 + public static class append_frame extends stack_map_frame { 48.216 + append_frame(int frame_type, ClassReader cr) 48.217 + throws IOException, InvalidStackMap { 48.218 + super(frame_type); 48.219 + offset_delta = cr.readUnsignedShort(); 48.220 + locals = new verification_type_info[frame_type - 251]; 48.221 + for (int i = 0; i < locals.length; i++) 48.222 + locals[i] = verification_type_info.read(cr); 48.223 + } 48.224 + 48.225 + @Override 48.226 + public int length() { 48.227 + int n = super.length() + 2; 48.228 + for (verification_type_info local: locals) 48.229 + n += local.length(); 48.230 + return n; 48.231 + } 48.232 + 48.233 + public <R, D> R accept(Visitor<R, D> visitor, D data) { 48.234 + return visitor.visit_append_frame(this, data); 48.235 + } 48.236 + 48.237 + public final int offset_delta; 48.238 + public final verification_type_info[] locals; 48.239 + } 48.240 + 48.241 + public static class full_frame extends stack_map_frame { 48.242 + full_frame(int frame_type, ClassReader cr) 48.243 + throws IOException, InvalidStackMap { 48.244 + super(frame_type); 48.245 + offset_delta = cr.readUnsignedShort(); 48.246 + number_of_locals = cr.readUnsignedShort(); 48.247 + locals = new verification_type_info[number_of_locals]; 48.248 + for (int i = 0; i < locals.length; i++) 48.249 + locals[i] = verification_type_info.read(cr); 48.250 + number_of_stack_items = cr.readUnsignedShort(); 48.251 + stack = new verification_type_info[number_of_stack_items]; 48.252 + for (int i = 0; i < stack.length; i++) 48.253 + stack[i] = verification_type_info.read(cr); 48.254 + } 48.255 + 48.256 + @Override 48.257 + public int length() { 48.258 + int n = super.length() + 2; 48.259 + for (verification_type_info local: locals) 48.260 + n += local.length(); 48.261 + n += 2; 48.262 + for (verification_type_info item: stack) 48.263 + n += item.length(); 48.264 + return n; 48.265 + } 48.266 + 48.267 + public <R, D> R accept(Visitor<R, D> visitor, D data) { 48.268 + return visitor.visit_full_frame(this, data); 48.269 + } 48.270 + 48.271 + public final int offset_delta; 48.272 + public final int number_of_locals; 48.273 + public final verification_type_info[] locals; 48.274 + public final int number_of_stack_items; 48.275 + public final verification_type_info[] stack; 48.276 + } 48.277 + 48.278 + public static class verification_type_info { 48.279 + public static final int ITEM_Top = 0; 48.280 + public static final int ITEM_Integer = 1; 48.281 + public static final int ITEM_Float = 2; 48.282 + public static final int ITEM_Long = 4; 48.283 + public static final int ITEM_Double = 3; 48.284 + public static final int ITEM_Null = 5; 48.285 + public static final int ITEM_UninitializedThis = 6; 48.286 + public static final int ITEM_Object = 7; 48.287 + public static final int ITEM_Uninitialized = 8; 48.288 + 48.289 + static verification_type_info read(ClassReader cr) 48.290 + throws IOException, InvalidStackMap { 48.291 + int tag = cr.readUnsignedByte(); 48.292 + switch (tag) { 48.293 + case ITEM_Top: 48.294 + case ITEM_Integer: 48.295 + case ITEM_Float: 48.296 + case ITEM_Long: 48.297 + case ITEM_Double: 48.298 + case ITEM_Null: 48.299 + case ITEM_UninitializedThis: 48.300 + return new verification_type_info(tag); 48.301 + 48.302 + case ITEM_Object: 48.303 + return new Object_variable_info(cr); 48.304 + 48.305 + case ITEM_Uninitialized: 48.306 + return new Uninitialized_variable_info(cr); 48.307 + 48.308 + default: 48.309 + throw new InvalidStackMap("unrecognized verification_type_info tag"); 48.310 + } 48.311 + } 48.312 + 48.313 + verification_type_info(int tag) { 48.314 + this.tag = tag; 48.315 + } 48.316 + 48.317 + public int length() { 48.318 + return 1; 48.319 + } 48.320 + 48.321 + public final int tag; 48.322 + } 48.323 + 48.324 + public static class Object_variable_info extends verification_type_info { 48.325 + Object_variable_info(ClassReader cr) throws IOException { 48.326 + super(ITEM_Object); 48.327 + cpool_index = cr.readUnsignedShort(); 48.328 + } 48.329 + 48.330 + @Override 48.331 + public int length() { 48.332 + return super.length() + 2; 48.333 + } 48.334 + 48.335 + public final int cpool_index; 48.336 + } 48.337 + 48.338 + public static class Uninitialized_variable_info extends verification_type_info { 48.339 + Uninitialized_variable_info(ClassReader cr) throws IOException { 48.340 + super(ITEM_Uninitialized); 48.341 + offset = cr.readUnsignedShort(); 48.342 + } 48.343 + 48.344 + @Override 48.345 + public int length() { 48.346 + return super.length() + 2; 48.347 + } 48.348 + 48.349 + public final int offset; 48.350 + 48.351 + } 48.352 +}
49.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 49.2 +++ b/src/share/classes/com/sun/tools/classfile/StackMap_attribute.java Tue Jun 03 13:26:47 2008 -0700 49.3 @@ -0,0 +1,70 @@ 49.4 +/* 49.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. 49.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 49.7 + * 49.8 + * This code is free software; you can redistribute it and/or modify it 49.9 + * under the terms of the GNU General Public License version 2 only, as 49.10 + * published by the Free Software Foundation. Sun designates this 49.11 + * particular file as subject to the "Classpath" exception as provided 49.12 + * by Sun in the LICENSE file that accompanied this code. 49.13 + * 49.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 49.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 49.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 49.17 + * version 2 for more details (a copy is included in the LICENSE file that 49.18 + * accompanied this code). 49.19 + * 49.20 + * You should have received a copy of the GNU General Public License version 49.21 + * 2 along with this work; if not, write to the Free Software Foundation, 49.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 49.23 + * 49.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 49.25 + * CA 95054 USA or visit www.sun.com if you need additional information or 49.26 + * have any questions. 49.27 + */ 49.28 + 49.29 +package com.sun.tools.classfile; 49.30 + 49.31 +import java.io.IOException; 49.32 + 49.33 +/** 49.34 + * <p><b>This is NOT part of any API supported by Sun Microsystems. If 49.35 + * you write code that depends on this, you do so at your own risk. 49.36 + * This code and its internal interfaces are subject to change or 49.37 + * deletion without notice.</b> 49.38 + */ 49.39 +public class StackMap_attribute extends Attribute { 49.40 + StackMap_attribute(ClassReader cr, int name_index, int length) 49.41 + throws IOException, StackMapTable_attribute.InvalidStackMap { 49.42 + super(name_index, length); 49.43 + number_of_entries = cr.readUnsignedShort(); 49.44 + entries = new stack_map_frame[number_of_entries]; 49.45 + for (int i = 0; i < number_of_entries; i++) 49.46 + entries[i] = new stack_map_frame(cr); 49.47 + } 49.48 + 49.49 + public StackMap_attribute(ConstantPool constant_pool, stack_map_frame[] entries) 49.50 + throws ConstantPoolException { 49.51 + this(constant_pool.getUTF8Index(Attribute.StackMap), entries); 49.52 + } 49.53 + 49.54 + public StackMap_attribute(int name_index, stack_map_frame[] entries) { 49.55 + super(name_index, StackMapTable_attribute.length(entries)); 49.56 + this.number_of_entries = entries.length; 49.57 + this.entries = entries; 49.58 + } 49.59 + 49.60 + public <R, D> R accept(Visitor<R, D> visitor, D data) { 49.61 + return visitor.visitStackMap(this, data); 49.62 + } 49.63 + 49.64 + public final int number_of_entries; 49.65 + public final stack_map_frame entries[]; 49.66 + 49.67 + public static class stack_map_frame extends StackMapTable_attribute.full_frame { 49.68 + stack_map_frame(ClassReader cr) 49.69 + throws IOException, StackMapTable_attribute.InvalidStackMap { 49.70 + super(255, cr); 49.71 + } 49.72 + } 49.73 +}
50.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 50.2 +++ b/src/share/classes/com/sun/tools/classfile/Synthetic_attribute.java Tue Jun 03 13:26:47 2008 -0700 50.3 @@ -0,0 +1,55 @@ 50.4 +/* 50.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. 50.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 50.7 + * 50.8 + * This code is free software; you can redistribute it and/or modify it 50.9 + * under the terms of the GNU General Public License version 2 only, as 50.10 + * published by the Free Software Foundation. Sun designates this 50.11 + * particular file as subject to the "Classpath" exception as provided 50.12 + * by Sun in the LICENSE file that accompanied this code. 50.13 + * 50.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 50.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 50.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 50.17 + * version 2 for more details (a copy is included in the LICENSE file that 50.18 + * accompanied this code). 50.19 + * 50.20 + * You should have received a copy of the GNU General Public License version 50.21 + * 2 along with this work; if not, write to the Free Software Foundation, 50.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 50.23 + * 50.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 50.25 + * CA 95054 USA or visit www.sun.com if you need additional information or 50.26 + * have any questions. 50.27 + */ 50.28 + 50.29 +package com.sun.tools.classfile; 50.30 + 50.31 +import java.io.IOException; 50.32 + 50.33 +/** 50.34 + * See JVMS3, section 4.8.8. 50.35 + * 50.36 + * <p><b>This is NOT part of any API supported by Sun Microsystems. If 50.37 + * you write code that depends on this, you do so at your own risk. 50.38 + * This code and its internal interfaces are subject to change or 50.39 + * deletion without notice.</b> 50.40 + */ 50.41 +public class Synthetic_attribute extends Attribute { 50.42 + Synthetic_attribute(ClassReader cr, int name_index, int length) throws IOException { 50.43 + super(name_index, length); 50.44 + } 50.45 + 50.46 + public Synthetic_attribute(ConstantPool constant_pool) 50.47 + throws ConstantPoolException { 50.48 + this(constant_pool.getUTF8Index(Attribute.Synthetic)); 50.49 + } 50.50 + 50.51 + public Synthetic_attribute(int name_index) { 50.52 + super(name_index, 0); 50.53 + } 50.54 + 50.55 + public <R, D> R accept(Visitor<R, D> visitor, D data) { 50.56 + return visitor.visitSynthetic(this, data); 50.57 + } 50.58 +}
51.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 51.2 +++ b/src/share/classes/com/sun/tools/classfile/Type.java Tue Jun 03 13:26:47 2008 -0700 51.3 @@ -0,0 +1,232 @@ 51.4 +/* 51.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. 51.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 51.7 + * 51.8 + * This code is free software; you can redistribute it and/or modify it 51.9 + * under the terms of the GNU General Public License version 2 only, as 51.10 + * published by the Free Software Foundation. Sun designates this 51.11 + * particular file as subject to the "Classpath" exception as provided 51.12 + * by Sun in the LICENSE file that accompanied this code. 51.13 + * 51.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 51.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 51.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 51.17 + * version 2 for more details (a copy is included in the LICENSE file that 51.18 + * accompanied this code). 51.19 + * 51.20 + * You should have received a copy of the GNU General Public License version 51.21 + * 2 along with this work; if not, write to the Free Software Foundation, 51.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 51.23 + * 51.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 51.25 + * CA 95054 USA or visit www.sun.com if you need additional information or 51.26 + * have any questions. 51.27 + */ 51.28 + 51.29 +package com.sun.tools.classfile; 51.30 + 51.31 +import java.util.List; 51.32 + 51.33 +/* 51.34 + * <p><b>This is NOT part of any API supported by Sun Microsystems. If 51.35 + * you write code that depends on this, you do so at your own risk. 51.36 + * This code and its internal interfaces are subject to change or 51.37 + * deletion without notice.</b> 51.38 + */ 51.39 +public class Type { 51.40 + protected Type() { } 51.41 + 51.42 + public boolean isObject() { 51.43 + return false; 51.44 + } 51.45 + 51.46 + protected static void append(StringBuilder sb, String prefix, List<? extends Type> types, String suffix) { 51.47 + sb.append(prefix); 51.48 + String sep = ""; 51.49 + for (Type t: types) { 51.50 + sb.append(sep); 51.51 + sb.append(t); 51.52 + sep = ", "; 51.53 + } 51.54 + sb.append(suffix); 51.55 + } 51.56 + 51.57 + protected static void appendIfNotEmpty(StringBuilder sb, String prefix, List<? extends Type> types, String suffix) { 51.58 + if (types != null && types.size() > 0) 51.59 + append(sb, prefix, types, suffix); 51.60 + } 51.61 + 51.62 + public static class SimpleType extends Type { 51.63 + public SimpleType(String name) { 51.64 + this.name = name; 51.65 + } 51.66 + 51.67 + @Override 51.68 + public String toString() { 51.69 + return name; 51.70 + } 51.71 + 51.72 + @Override 51.73 + public boolean isObject() { 51.74 + return name.equals("java.lang.Object"); 51.75 + } 51.76 + 51.77 + public final String name; 51.78 + } 51.79 + 51.80 + public static class ArrayType extends Type { 51.81 + public ArrayType(Type elemType) { 51.82 + this.elemType = elemType; 51.83 + } 51.84 + 51.85 + @Override 51.86 + public String toString() { 51.87 + return elemType + "[]"; 51.88 + } 51.89 + 51.90 + public final Type elemType; 51.91 + } 51.92 + 51.93 + public static class MethodType extends Type { 51.94 + public MethodType(List<? extends Type> argTypes, Type resultType) { 51.95 + this(null, argTypes, resultType, null); 51.96 + } 51.97 + 51.98 + public MethodType(List<? extends Type> typeArgTypes, 51.99 + List<? extends Type> argTypes, 51.100 + Type returnType, 51.101 + List<? extends Type> throwsTypes) { 51.102 + this.typeArgTypes = typeArgTypes; 51.103 + this.argTypes = argTypes; 51.104 + this.returnType = returnType; 51.105 + this.throwsTypes = throwsTypes; 51.106 + } 51.107 + 51.108 + @Override 51.109 + public String toString() { 51.110 + StringBuilder sb = new StringBuilder(); 51.111 + appendIfNotEmpty(sb, "<", typeArgTypes, "> "); 51.112 + sb.append(returnType); 51.113 + append(sb, " (", argTypes, ")"); 51.114 + appendIfNotEmpty(sb, " throws ", throwsTypes, ""); 51.115 + return sb.toString(); 51.116 + } 51.117 + 51.118 + public final List<? extends Type> typeArgTypes; 51.119 + public final List<? extends Type> argTypes; 51.120 + public final Type returnType; 51.121 + public final List<? extends Type> throwsTypes; 51.122 + } 51.123 + 51.124 + public static class ClassSigType extends Type { 51.125 + public ClassSigType(List<Type> typeArgTypes, Type superclassType, List<Type> superinterfaceTypes) { 51.126 + this.typeArgTypes = typeArgTypes; 51.127 + this.superclassType = superclassType; 51.128 + this.superinterfaceTypes = superinterfaceTypes; 51.129 + } 51.130 + 51.131 + @Override 51.132 + public String toString() { 51.133 + StringBuilder sb = new StringBuilder(); 51.134 + appendIfNotEmpty(sb, "<", typeArgTypes, ">"); 51.135 + if (superclassType != null && !superclassType.isObject()) { 51.136 + sb.append(" extends "); 51.137 + sb.append(superclassType); 51.138 + } 51.139 + appendIfNotEmpty(sb, " implements ", superinterfaceTypes, ""); 51.140 + return sb.toString(); 51.141 + } 51.142 + 51.143 + public final List<Type> typeArgTypes; 51.144 + public final Type superclassType; 51.145 + public final List<Type> superinterfaceTypes; 51.146 + } 51.147 + 51.148 + public static class ClassType extends Type { 51.149 + public ClassType(String name, List<Type> typeArgs) { 51.150 + this.name = name; 51.151 + this.typeArgs = typeArgs; 51.152 + } 51.153 + 51.154 + @Override 51.155 + public String toString() { 51.156 + StringBuilder sb = new StringBuilder(); 51.157 + sb.append(name); 51.158 + appendIfNotEmpty(sb, "<", typeArgs, ">"); 51.159 + return sb.toString(); 51.160 + } 51.161 + 51.162 + public final String name; 51.163 + public final List<Type> typeArgs; 51.164 + } 51.165 + 51.166 + 51.167 + public static class InnerClassType extends Type { 51.168 + public InnerClassType(Type outerType, Type innerType) { 51.169 + this.outerType = outerType; 51.170 + this.innerType = innerType; 51.171 + } 51.172 + 51.173 + @Override 51.174 + public String toString() { 51.175 + return outerType + "." + innerType; 51.176 + } 51.177 + 51.178 + public final Type outerType; 51.179 + public final Type innerType; 51.180 + } 51.181 + 51.182 + public static class TypeArgType extends Type { 51.183 + public TypeArgType(String name, Type classBound, List<Type> interfaceBounds) { 51.184 + this.name = name; 51.185 + this.classBound = classBound; 51.186 + this.interfaceBounds = interfaceBounds; 51.187 + } 51.188 + 51.189 + @Override 51.190 + public String toString() { 51.191 + StringBuilder sb = new StringBuilder(); 51.192 + sb.append(name); 51.193 + String sep = " extends "; 51.194 + if (classBound != null && !classBound.isObject()) { 51.195 + sb.append(sep); 51.196 + sb.append(classBound); 51.197 + sep = " & "; 51.198 + } 51.199 + if (interfaceBounds != null) { 51.200 + for (Type bound: interfaceBounds) { 51.201 + sb.append(sep); 51.202 + sb.append(bound); 51.203 + sep = " & "; 51.204 + } 51.205 + } 51.206 + return sb.toString(); 51.207 + } 51.208 + 51.209 + public final String name; 51.210 + public final Type classBound; 51.211 + public final List<Type> interfaceBounds; 51.212 + } 51.213 + 51.214 + public static class WildcardType extends Type { 51.215 + public WildcardType() { 51.216 + this(null, null); 51.217 + } 51.218 + 51.219 + public WildcardType(String kind, Type boundType) { 51.220 + this.kind = kind; 51.221 + this.boundType = boundType; 51.222 + } 51.223 + 51.224 + @Override 51.225 + public String toString() { 51.226 + if (kind == null) 51.227 + return "?"; 51.228 + else 51.229 + return "? " + kind + " " + boundType; 51.230 + } 51.231 + 51.232 + public final String kind; 51.233 + public final Type boundType; 51.234 + } 51.235 +}
52.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 52.2 +++ b/src/share/classes/com/sun/tools/classfile/package.html Tue Jun 03 13:26:47 2008 -0700 52.3 @@ -0,0 +1,12 @@ 52.4 +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 52.5 +<html> 52.6 + <head> 52.7 + <title></title> 52.8 + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 52.9 + </head> 52.10 + <body> 52.11 + A minimalist library to read and write class files into objects closely 52.12 + based on the corresponding definitions in the Java Virtual Machine 52.13 + Specification (JVMS). 52.14 + </body> 52.15 +</html>
53.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 53.2 +++ b/src/share/classes/com/sun/tools/javap/AnnotationWriter.java Tue Jun 03 13:26:47 2008 -0700 53.3 @@ -0,0 +1,114 @@ 53.4 +/* 53.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. 53.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 53.7 + * 53.8 + * This code is free software; you can redistribute it and/or modify it 53.9 + * under the terms of the GNU General Public License version 2 only, as 53.10 + * published by the Free Software Foundation. Sun designates this 53.11 + * particular file as subject to the "Classpath" exception as provided 53.12 + * by Sun in the LICENSE file that accompanied this code. 53.13 + * 53.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 53.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 53.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 53.17 + * version 2 for more details (a copy is included in the LICENSE file that 53.18 + * accompanied this code). 53.19 + * 53.20 + * You should have received a copy of the GNU General Public License version 53.21 + * 2 along with this work; if not, write to the Free Software Foundation, 53.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 53.23 + * 53.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 53.25 + * CA 95054 USA or visit www.sun.com if you need additional information or 53.26 + * have any questions. 53.27 + */ 53.28 + 53.29 +package com.sun.tools.javap; 53.30 + 53.31 +import com.sun.tools.classfile.Annotation; 53.32 +import com.sun.tools.classfile.Annotation.Annotation_element_value; 53.33 +import com.sun.tools.classfile.Annotation.Array_element_value; 53.34 +import com.sun.tools.classfile.Annotation.Class_element_value; 53.35 +import com.sun.tools.classfile.Annotation.Enum_element_value; 53.36 +import com.sun.tools.classfile.Annotation.Primitive_element_value; 53.37 + 53.38 +/** 53.39 + * A writer for writing annotations as text. 53.40 + * 53.41 + * <p><b>This is NOT part of any API supported by Sun Microsystems. If 53.42 + * you write code that depends on this, you do so at your own risk. 53.43 + * This code and its internal interfaces are subject to change or 53.44 + * deletion without notice.</b> 53.45 + */ 53.46 +public class AnnotationWriter extends BasicWriter { 53.47 + static AnnotationWriter instance(Context context) { 53.48 + AnnotationWriter instance = context.get(AnnotationWriter.class); 53.49 + if (instance == null) 53.50 + instance = new AnnotationWriter(context); 53.51 + return instance; 53.52 + } 53.53 + 53.54 + protected AnnotationWriter(Context context) { 53.55 + super(context); 53.56 + } 53.57 + 53.58 + public void write(Annotation annot) { 53.59 + print("#" + annot.type_index + "("); 53.60 + for (int i = 0; i < annot.num_element_value_pairs; i++) { 53.61 + if (i > 0) 53.62 + print(","); 53.63 + write(annot.element_value_pairs[i]); 53.64 + } 53.65 + print(")"); 53.66 + } 53.67 + 53.68 + public void write(Annotation.element_value_pair pair) { 53.69 + print("#" + pair.element_name_index + ":"); 53.70 + write(pair.value); 53.71 + } 53.72 + 53.73 + public void write(Annotation.element_value value) { 53.74 + ev_writer.write(value); 53.75 + } 53.76 + 53.77 + element_value_Writer ev_writer = new element_value_Writer(); 53.78 + 53.79 + class element_value_Writer implements Annotation.element_value.Visitor<Void,Void> { 53.80 + public void write(Annotation.element_value value) { 53.81 + value.accept(this, null); 53.82 + } 53.83 + 53.84 + public Void visitPrimitive(Primitive_element_value ev, Void p) { 53.85 + print(((char) ev.tag) + "#" + ev.const_value_index); 53.86 + return null; 53.87 + } 53.88 + 53.89 + public Void visitEnum(Enum_element_value ev, Void p) { 53.90 + print(((char) ev.tag) + "#" + ev.type_name_index + ".#" + ev.const_name_index); 53.91 + return null; 53.92 + } 53.93 + 53.94 + public Void visitClass(Class_element_value ev, Void p) { 53.95 + print(((char) ev.tag) + "#" + ev.class_info_index); 53.96 + return null; 53.97 + } 53.98 + 53.99 + public Void visitAnnotation(Annotation_element_value ev, Void p) { 53.100 + print((char) ev.tag); 53.101 + AnnotationWriter.this.write(ev.annotation_value); 53.102 + return null; 53.103 + } 53.104 + 53.105 + public Void visitArray(Array_element_value ev, Void p) { 53.106 + print("["); 53.107 + for (int i = 0; i < ev.num_values; i++) { 53.108 + if (i > 0) 53.109 + print(","); 53.110 + write(ev.values[i]); 53.111 + } 53.112 + print("]"); 53.113 + return null; 53.114 + } 53.115 + 53.116 + } 53.117 +}
54.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 54.2 +++ b/src/share/classes/com/sun/tools/javap/AttributeWriter.java Tue Jun 03 13:26:47 2008 -0700 54.3 @@ -0,0 +1,679 @@ 54.4 +/* 54.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. 54.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 54.7 + * 54.8 + * This code is free software; you can redistribute it and/or modify it 54.9 + * under the terms of the GNU General Public License version 2 only, as 54.10 + * published by the Free Software Foundation. Sun designates this 54.11 + * particular file as subject to the "Classpath" exception as provided 54.12 + * by Sun in the LICENSE file that accompanied this code. 54.13 + * 54.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 54.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 54.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 54.17 + * version 2 for more details (a copy is included in the LICENSE file that 54.18 + * accompanied this code). 54.19 + * 54.20 + * You should have received a copy of the GNU General Public License version 54.21 + * 2 along with this work; if not, write to the Free Software Foundation, 54.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 54.23 + * 54.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 54.25 + * CA 95054 USA or visit www.sun.com if you need additional information or 54.26 + * have any questions. 54.27 + */ 54.28 + 54.29 +package com.sun.tools.javap; 54.30 + 54.31 +import java.util.Formatter; 54.32 + 54.33 +import com.sun.tools.classfile.AccessFlags; 54.34 +import com.sun.tools.classfile.AnnotationDefault_attribute; 54.35 +import com.sun.tools.classfile.Attribute; 54.36 +import com.sun.tools.classfile.Attributes; 54.37 +import com.sun.tools.classfile.CharacterRangeTable_attribute; 54.38 +import com.sun.tools.classfile.Code_attribute; 54.39 +import com.sun.tools.classfile.CompilationID_attribute; 54.40 +import com.sun.tools.classfile.ConstantPool; 54.41 +import com.sun.tools.classfile.ConstantPoolException; 54.42 +import com.sun.tools.classfile.ConstantValue_attribute; 54.43 +import com.sun.tools.classfile.DefaultAttribute; 54.44 +import com.sun.tools.classfile.Deprecated_attribute; 54.45 +import com.sun.tools.classfile.EnclosingMethod_attribute; 54.46 +import com.sun.tools.classfile.Exceptions_attribute; 54.47 +import com.sun.tools.classfile.Field; 54.48 +import com.sun.tools.classfile.InnerClasses_attribute; 54.49 +import com.sun.tools.classfile.LineNumberTable_attribute; 54.50 +import com.sun.tools.classfile.LocalVariableTable_attribute; 54.51 +import com.sun.tools.classfile.LocalVariableTypeTable_attribute; 54.52 +import com.sun.tools.classfile.ModuleExportTable_attribute; 54.53 +import com.sun.tools.classfile.ModuleMemberTable_attribute; 54.54 +import com.sun.tools.classfile.Module_attribute; 54.55 +import com.sun.tools.classfile.RuntimeInvisibleAnnotations_attribute; 54.56 +import com.sun.tools.classfile.RuntimeInvisibleParameterAnnotations_attribute; 54.57 +import com.sun.tools.classfile.RuntimeVisibleAnnotations_attribute; 54.58 +import com.sun.tools.classfile.RuntimeVisibleParameterAnnotations_attribute; 54.59 +import com.sun.tools.classfile.Signature_attribute; 54.60 +import com.sun.tools.classfile.SourceDebugExtension_attribute; 54.61 +import com.sun.tools.classfile.SourceFile_attribute; 54.62 +import com.sun.tools.classfile.SourceID_attribute; 54.63 +import com.sun.tools.classfile.StackMapTable_attribute; 54.64 +import com.sun.tools.classfile.StackMap_attribute; 54.65 +import com.sun.tools.classfile.Synthetic_attribute; 54.66 + 54.67 +import static com.sun.tools.classfile.AccessFlags.*; 54.68 + 54.69 +/* 54.70 + * A writer for writing Attributes as text. 54.71 + * 54.72 + * <p><b>This is NOT part of any API supported by Sun Microsystems. If 54.73 + * you write code that depends on this, you do so at your own risk. 54.74 + * This code and its internal interfaces are subject to change or 54.75 + * deletion without notice.</b> 54.76 + */ 54.77 +public class AttributeWriter extends BasicWriter 54.78 + implements Attribute.Visitor<Void,Void> 54.79 +{ 54.80 + static AttributeWriter instance(Context context) { 54.81 + AttributeWriter instance = context.get(AttributeWriter.class); 54.82 + if (instance == null) 54.83 + instance = new AttributeWriter(context); 54.84 + return instance; 54.85 + } 54.86 + 54.87 + protected AttributeWriter(Context context) { 54.88 + super(context); 54.89 + context.put(AttributeWriter.class, this); 54.90 + annotationWriter = AnnotationWriter.instance(context); 54.91 + codeWriter = CodeWriter.instance(context); 54.92 + constantWriter = ConstantWriter.instance(context); 54.93 + options = Options.instance(context); 54.94 + } 54.95 + 54.96 + public void write(Object owner, Attribute attr, ConstantPool constant_pool) { 54.97 + if (attr != null) { 54.98 + // null checks 54.99 + owner.getClass(); 54.100 + constant_pool.getClass(); 54.101 + this.constant_pool = constant_pool; 54.102 + this.owner = owner; 54.103 + attr.accept(this, null); 54.104 + } 54.105 + } 54.106 + 54.107 + public void write(Object owner, Attributes attrs, ConstantPool constant_pool) { 54.108 + if (attrs != null) { 54.109 + // null checks 54.110 + owner.getClass(); 54.111 + constant_pool.getClass(); 54.112 + this.constant_pool = constant_pool; 54.113 + this.owner = owner; 54.114 + for (Attribute attr: attrs) 54.115 + attr.accept(this, null); 54.116 + } 54.117 + } 54.118 + 54.119 + public Void visitDefault(DefaultAttribute attr, Void ignore) { 54.120 + byte[] data = attr.info; 54.121 + int i = 0; 54.122 + int j = 0; 54.123 + print(" "); 54.124 + try { 54.125 + print(attr.getName(constant_pool)); 54.126 + } catch (ConstantPoolException e) { 54.127 + report(e); 54.128 + print("attribute name = #" + attr.attribute_name_index); 54.129 + } 54.130 + print(": "); 54.131 + println("length = 0x" + toHex(attr.info.length)); 54.132 + 54.133 + print(" "); 54.134 + 54.135 + while (i < data.length) { 54.136 + print(toHex(data[i], 2)); 54.137 + 54.138 + j++; 54.139 + if (j == 16) { 54.140 + println(); 54.141 + print(" "); 54.142 + j = 0; 54.143 + } else { 54.144 + print(" "); 54.145 + } 54.146 + i++; 54.147 + } 54.148 + println(); 54.149 + return null; 54.150 + } 54.151 + 54.152 + public Void visitAnnotationDefault(AnnotationDefault_attribute attr, Void ignore) { 54.153 + println(" AnnotationDefault: "); 54.154 + print(" default_value: "); 54.155 + annotationWriter.write(attr.default_value); 54.156 + return null; 54.157 + } 54.158 + 54.159 + public Void visitCharacterRangeTable(CharacterRangeTable_attribute attr, Void ignore) { 54.160 + print(" CharacterRangeTable: "); 54.161 + for (int i = 0; i < attr.character_range_table.length; i++) { 54.162 + CharacterRangeTable_attribute.Entry e = attr.character_range_table[i]; 54.163 + print(" " + e.start_pc + ", " + 54.164 + e.end_pc + ", " + 54.165 + Integer.toHexString(e.character_range_start) + ", " + 54.166 + Integer.toHexString(e.character_range_end) + ", " + 54.167 + Integer.toHexString(e.flags) + 54.168 + "\t// "); 54.169 + print(e.start_pc + ", " + 54.170 + e.end_pc + ", " + 54.171 + (e.character_range_start >> 10) + ":" + (e.character_range_start & 0x3ff) + ", " + 54.172 + (e.character_range_end >> 10) + ":" + (e.character_range_end & 0x3ff)); 54.173 + if ((e.flags & CharacterRangeTable_attribute.CRT_STATEMENT) != 0) 54.174 + print(", statement"); 54.175 + if ((e.flags & CharacterRangeTable_attribute.CRT_BLOCK) != 0) 54.176 + print(", block"); 54.177 + if ((e.flags & CharacterRangeTable_attribute.CRT_ASSIGNMENT) != 0) 54.178 + print(", assignment"); 54.179 + if ((e.flags & CharacterRangeTable_attribute.CRT_FLOW_CONTROLLER) != 0) 54.180 + print(", flow-controller"); 54.181 + if ((e.flags & CharacterRangeTable_attribute.CRT_FLOW_TARGET) != 0) 54.182 + print(", flow-target"); 54.183 + if ((e.flags & CharacterRangeTable_attribute.CRT_INVOKE) != 0) 54.184 + print(", invoke"); 54.185 + if ((e.flags & CharacterRangeTable_attribute.CRT_CREATE) != 0) 54.186 + print(", create"); 54.187 + if ((e.flags & CharacterRangeTable_attribute.CRT_BRANCH_TRUE) != 0) 54.188 + print(", branch-true"); 54.189 + if ((e.flags & CharacterRangeTable_attribute.CRT_BRANCH_FALSE) != 0) 54.190 + print(", branch-false"); 54.191 + 54.192 + 54.193 + 54.194 + } 54.195 + return null; 54.196 + } 54.197 + 54.198 + public Void visitCode(Code_attribute attr, Void ignore) { 54.199 + codeWriter.write(attr, constant_pool); 54.200 + println(); 54.201 + return null; 54.202 + } 54.203 + 54.204 + public Void visitCompilationID(CompilationID_attribute attr, Void ignore) { 54.205 + constantWriter.write(attr.compilationID_index); 54.206 + return null; 54.207 + } 54.208 + 54.209 + public Void visitConstantValue(ConstantValue_attribute attr, Void ignore) { 54.210 + if (options.compat) // BUG 6622216 javap names some attributes incorrectly 54.211 + print(" Constant value: "); 54.212 + else 54.213 + print(" ConstantValue: "); 54.214 + constantWriter.write(attr.constantvalue_index); 54.215 + if (!options.compat) // BUG 6622232 javap gets whitespace confused 54.216 + println(); 54.217 + return null; 54.218 + } 54.219 + 54.220 + public Void visitDeprecated(Deprecated_attribute attr, Void ignore) { 54.221 + if (!(options.compat && owner instanceof Field)) // BUG 6622232 javap gets whitespace confused 54.222 + print(" "); 54.223 + println("Deprecated: true"); 54.224 + return null; 54.225 + } 54.226 + 54.227 + public Void visitEnclosingMethod(EnclosingMethod_attribute attr, Void ignore) { 54.228 + print(" EnclosingMethod: #" + attr.class_index + ".#" + attr.method_index 54.229 + + "\t// " + getJavaClassName(attr)); 54.230 + if (attr.method_index != 0) 54.231 + print("." + getMethodName(attr)); 54.232 + println(); 54.233 + return null; 54.234 + } 54.235 + 54.236 + private String getJavaClassName(EnclosingMethod_attribute a) { 54.237 + try { 54.238 + return getJavaName(a.getClassName(constant_pool)); 54.239 + } catch (ConstantPoolException e) { 54.240 + return report(e); 54.241 + } 54.242 + } 54.243 + 54.244 + private String getMethodName(EnclosingMethod_attribute a) { 54.245 + try { 54.246 + return a.getMethodName(constant_pool); 54.247 + } catch (ConstantPoolException e) { 54.248 + return report(e); 54.249 + } 54.250 + } 54.251 + 54.252 + public Void visitExceptions(Exceptions_attribute attr, Void ignore) { 54.253 + println(" Exceptions: "); 54.254 + print(" throws "); 54.255 + for (int i = 0; i < attr.number_of_exceptions; i++) { 54.256 + if (i > 0) 54.257 + print(", "); 54.258 + print(getJavaException(attr, i)); 54.259 + } 54.260 + if (!options.compat) // BUG 6622232 javap gets whitespace confused 54.261 + println(); 54.262 + return null; 54.263 + } 54.264 + 54.265 + String getJavaException(Exceptions_attribute attr, int index) { 54.266 + try { 54.267 + return getJavaName(attr.getException(index, constant_pool)); 54.268 + } catch (ConstantPoolException e) { 54.269 + return report(e); 54.270 + } 54.271 + } 54.272 + 54.273 + public Void visitInnerClasses(InnerClasses_attribute attr, Void ignore) { 54.274 + boolean first = true; 54.275 + if (options.compat) { 54.276 + writeInnerClassHeader(); 54.277 + first = false; 54.278 + } 54.279 + for (int i = 0 ; i < attr.classes.length; i++) { 54.280 + InnerClasses_attribute.Info info = attr.classes[i]; 54.281 + //access 54.282 + AccessFlags access_flags = info.inner_class_access_flags; 54.283 + if (options.compat) { 54.284 + // BUG 6622215: javap ignores certain relevant access flags 54.285 + access_flags = access_flags.ignore(ACC_STATIC | ACC_PROTECTED | ACC_PRIVATE | ACC_INTERFACE | ACC_SYNTHETIC | ACC_ENUM); 54.286 + // BUG 6622232: javap gets whitespace confused 54.287 + print(" "); 54.288 + } 54.289 + if (options.checkAccess(access_flags)) { 54.290 + if (first) { 54.291 + writeInnerClassHeader(); 54.292 + first = false; 54.293 + } 54.294 + if (!options.compat) // BUG 6622232: javap gets whitespace confused 54.295 + print(" "); 54.296 + for (String name: access_flags.getInnerClassModifiers()) 54.297 + print(name + " "); 54.298 + if (info.inner_name_index!=0) { 54.299 + print("#" + info.inner_name_index + "= "); 54.300 + } 54.301 + print("#" + info.inner_class_info_index); 54.302 + if (info.outer_class_info_index != 0) { 54.303 + print(" of #" + info.outer_class_info_index); 54.304 + } 54.305 + print("; //"); 54.306 + if (info.inner_name_index != 0) { 54.307 + print(getInnerName(constant_pool, info) + "="); 54.308 + } 54.309 + constantWriter.write(info.inner_class_info_index); 54.310 + if (info.outer_class_info_index != 0) { 54.311 + print(" of "); 54.312 + constantWriter.write(info.outer_class_info_index); 54.313 + } 54.314 + println(); 54.315 + } 54.316 + } 54.317 + return null; 54.318 + } 54.319 + 54.320 + String getInnerName(ConstantPool constant_pool, InnerClasses_attribute.Info info) { 54.321 + try { 54.322 + return info.getInnerName(constant_pool); 54.323 + } catch (ConstantPoolException e) { 54.324 + return report(e); 54.325 + } 54.326 + } 54.327 + 54.328 + private void writeInnerClassHeader() { 54.329 + print(" "); 54.330 + if (options.compat) // BUG 6622216: javap names some attributes incorrectly 54.331 + print("InnerClass"); 54.332 + else 54.333 + print("InnerClasses"); 54.334 + println(": "); 54.335 + } 54.336 + 54.337 + public Void visitLineNumberTable(LineNumberTable_attribute attr, Void ignore) { 54.338 + println(" LineNumberTable: "); 54.339 + for (LineNumberTable_attribute.Entry entry: attr.line_number_table) { 54.340 + println(" line " + entry.line_number + ": " + entry.start_pc); 54.341 + } 54.342 + return null; 54.343 + } 54.344 + 54.345 + public Void visitLocalVariableTable(LocalVariableTable_attribute attr, Void ignore) { 54.346 + println(" LocalVariableTable: "); 54.347 + println(" Start Length Slot Name Signature"); 54.348 + 54.349 + for (LocalVariableTable_attribute.Entry entry : attr.local_variable_table) { 54.350 + Formatter formatter = new Formatter(); 54.351 + println(formatter.format("%8d %7d %5d %5s %s", 54.352 + entry.start_pc, entry.length, entry.index, 54.353 + constantWriter.stringValue(entry.name_index), 54.354 + constantWriter.stringValue(entry.descriptor_index))); 54.355 + } 54.356 + return null; 54.357 + } 54.358 + 54.359 + public Void visitLocalVariableTypeTable(LocalVariableTypeTable_attribute attr, Void ignore) { 54.360 + println(" LocalVariableTypeTable: "); 54.361 + println(" Start Length Slot Name Signature"); 54.362 + 54.363 + for (LocalVariableTypeTable_attribute.Entry entry : attr.local_variable_table) { 54.364 + Formatter formatter = new Formatter(); 54.365 + println(formatter.format("%8d %7d %5d %5s %s", 54.366 + entry.start_pc, entry.length, entry.index, 54.367 + constantWriter.stringValue(entry.name_index), 54.368 + constantWriter.stringValue(entry.signature_index))); 54.369 + } 54.370 + return null; 54.371 + } 54.372 + 54.373 + public Void visitModule(Module_attribute attr, Void ignore) { 54.374 + println(" Module: #" + attr.module_name + "\t// " + getModuleName(attr)); 54.375 + return null; 54.376 + } 54.377 + 54.378 + String getModuleName(Module_attribute attr) { 54.379 + try { 54.380 + return attr.getModuleName(constant_pool); 54.381 + } catch (ConstantPoolException e) { 54.382 + return report(e); 54.383 + } 54.384 + } 54.385 + 54.386 + public Void visitModuleExportTable(ModuleExportTable_attribute attr, Void ignore) { 54.387 + println(" ModuleExportTable:"); 54.388 + println(" Types: (" + attr.export_type_table.length + ")"); 54.389 + for (int i = 0; i < attr.export_type_table.length; i++) { 54.390 + println(" #" + attr.export_type_table[i] + "\t// " + getExportTypeName(attr, i)); 54.391 + } 54.392 + return null; 54.393 + } 54.394 + 54.395 + String getExportTypeName(ModuleExportTable_attribute attr, int index) { 54.396 + try { 54.397 + return attr.getExportTypeName(index, constant_pool); 54.398 + } catch (ConstantPoolException e) { 54.399 + return report(e); 54.400 + } 54.401 + } 54.402 + 54.403 + public Void visitModuleMemberTable(ModuleMemberTable_attribute attr, Void ignore) { 54.404 + println(" ModuleMemberTable:"); 54.405 + println(" Packages: (" + attr.package_member_table.length + ")"); 54.406 + for (int i = 0; i < attr.package_member_table.length; i++) { 54.407 + println(" #" + attr.package_member_table[i] + "\t// " + getPackageMemberName(attr, i)); 54.408 + } 54.409 + return null; 54.410 + } 54.411 + 54.412 + String getPackageMemberName(ModuleMemberTable_attribute attr, int index) { 54.413 + try { 54.414 + return attr.getPackageMemberName(index, constant_pool); 54.415 + } catch (ConstantPoolException e) { 54.416 + return report(e); 54.417 + } 54.418 + } 54.419 + 54.420 + public Void visitRuntimeVisibleAnnotations(RuntimeVisibleAnnotations_attribute attr, Void ignore) { 54.421 + println(" RuntimeVisibleAnnotations: "); 54.422 + for (int i = 0; i < attr.annotations.length; i++) { 54.423 + print(" " + i + ": "); 54.424 + annotationWriter.write(attr.annotations[i]); 54.425 + println(); 54.426 + } 54.427 + return null; 54.428 + } 54.429 + 54.430 + public Void visitRuntimeInvisibleAnnotations(RuntimeInvisibleAnnotations_attribute attr, Void ignore) { 54.431 + println(" RuntimeInvisibleAnnotations: "); 54.432 + for (int i = 0; i < attr.annotations.length; i++) { 54.433 + print(" " + i + ": "); 54.434 + annotationWriter.write(attr.annotations[i]); 54.435 + println(); 54.436 + } 54.437 + return null; 54.438 + } 54.439 + 54.440 + public Void visitRuntimeVisibleParameterAnnotations(RuntimeVisibleParameterAnnotations_attribute attr, Void ignore) { 54.441 + println(" RuntimeVisibleParameterAnnotations: "); 54.442 + for (int param = 0; param < attr.parameter_annotations.length; param++) { 54.443 + println(" parameter " + param + ": "); 54.444 + for (int i = 0; i < attr.parameter_annotations[param].length; i++) { 54.445 + print(" " + i + ": "); 54.446 + annotationWriter.write(attr.parameter_annotations[param][i]); 54.447 + println(); 54.448 + } 54.449 + } 54.450 + return null; 54.451 + } 54.452 + 54.453 + public Void visitRuntimeInvisibleParameterAnnotations(RuntimeInvisibleParameterAnnotations_attribute attr, Void ignore) { 54.454 + println(" RuntimeInvisibleParameterAnnotations: "); 54.455 + for (int param = 0; param < attr.parameter_annotations.length; param++) { 54.456 + println(" " + param + ": "); 54.457 + for (int i = 0; i < attr.parameter_annotations[param].length; i++) { 54.458 + print(" " + i + ": "); 54.459 + annotationWriter.write(attr.parameter_annotations[param][i]); 54.460 + println(); 54.461 + } 54.462 + } 54.463 + return null; 54.464 + } 54.465 + 54.466 + public Void visitSignature(Signature_attribute attr, Void ignore) { 54.467 + println(" Signature: #" + attr.signature_index + "\t// " + getSignature(attr)); 54.468 + return null; 54.469 + } 54.470 + 54.471 + String getSignature(Signature_attribute info) { 54.472 + try { 54.473 + return info.getSignature(constant_pool); 54.474 + } catch (ConstantPoolException e) { 54.475 + return report(e); 54.476 + } 54.477 + } 54.478 + 54.479 + public Void visitSourceDebugExtension(SourceDebugExtension_attribute attr, Void ignore) { 54.480 + println(" SourceDebugExtension: " + attr.getValue()); 54.481 + return null; 54.482 + } 54.483 + 54.484 + public Void visitSourceFile(SourceFile_attribute attr, Void ignore) { 54.485 + println(" SourceFile: \"" + getSourceFile(attr) + "\""); 54.486 + return null; 54.487 + } 54.488 + 54.489 + private String getSourceFile(SourceFile_attribute attr) { 54.490 + try { 54.491 + return attr.getSourceFile(constant_pool); 54.492 + } catch (ConstantPoolException e) { 54.493 + return report(e); 54.494 + } 54.495 + } 54.496 + 54.497 + public Void visitSourceID(SourceID_attribute attr, Void ignore) { 54.498 + constantWriter.write(attr.sourceID_index); 54.499 + return null; 54.500 + } 54.501 + 54.502 + public Void visitStackMap(StackMap_attribute attr, Void ignore) { 54.503 + println(" StackMap: number_of_entries = " + attr.number_of_entries); 54.504 + 54.505 + StackMapTableWriter w = new StackMapTableWriter(); 54.506 + for (StackMapTable_attribute.stack_map_frame entry : attr.entries) { 54.507 + w.write(entry); 54.508 + } 54.509 + println(); 54.510 + return null; 54.511 + } 54.512 + 54.513 + public Void visitStackMapTable(StackMapTable_attribute attr, Void ignore) { 54.514 + println(" StackMapTable: number_of_entries = " + attr.number_of_entries); 54.515 + 54.516 + StackMapTableWriter w = new StackMapTableWriter(); 54.517 + for (StackMapTable_attribute.stack_map_frame entry : attr.entries) { 54.518 + w.write(entry); 54.519 + } 54.520 + println(); 54.521 + return null; 54.522 + } 54.523 + 54.524 + class StackMapTableWriter // also handles CLDC StackMap attributes 54.525 + implements StackMapTable_attribute.stack_map_frame.Visitor<Void,Void> { 54.526 + public void write(StackMapTable_attribute.stack_map_frame frame) { 54.527 + frame.accept(this, null); 54.528 + } 54.529 + 54.530 + public Void visit_same_frame(StackMapTable_attribute.same_frame frame, Void p) { 54.531 + printHeader(frame); 54.532 + println(" /* same */"); 54.533 + return null; 54.534 + } 54.535 + 54.536 + public Void visit_same_locals_1_stack_item_frame(StackMapTable_attribute.same_locals_1_stack_item_frame frame, Void p) { 54.537 + printHeader(frame); 54.538 + println(" /* same_locals_1_stack_item */"); 54.539 + printMap("stack", frame.stack); 54.540 + return null; 54.541 + } 54.542 + 54.543 + public Void visit_same_locals_1_stack_item_frame_extended(StackMapTable_attribute.same_locals_1_stack_item_frame_extended frame, Void p) { 54.544 + printHeader(frame); 54.545 + println(" /* same_locals_1_stack_item_frame_extended */"); 54.546 + println(" offset_delta = " + frame.offset_delta); 54.547 + printMap("stack", frame.stack); 54.548 + return null; 54.549 + } 54.550 + 54.551 + public Void visit_chop_frame(StackMapTable_attribute.chop_frame frame, Void p) { 54.552 + printHeader(frame); 54.553 + println(" /* chop */"); 54.554 + println(" offset_delta = " + frame.offset_delta); 54.555 + return null; 54.556 + } 54.557 + 54.558 + public Void visit_same_frame_extended(StackMapTable_attribute.same_frame_extended frame, Void p) { 54.559 + printHeader(frame); 54.560 + println(" /* same_frame_extended */"); 54.561 + println(" offset_delta = " + frame.offset_delta); 54.562 + return null; 54.563 + } 54.564 + 54.565 + public Void visit_append_frame(StackMapTable_attribute.append_frame frame, Void p) { 54.566 + printHeader(frame); 54.567 + println(" /* append */"); 54.568 + println(" offset_delta = " + frame.offset_delta); 54.569 + printMap("locals", frame.locals); 54.570 + return null; 54.571 + } 54.572 + 54.573 + public Void visit_full_frame(StackMapTable_attribute.full_frame frame, Void p) { 54.574 + printHeader(frame); 54.575 + if (frame instanceof StackMap_attribute.stack_map_frame) { 54.576 + println(" offset = " + frame.offset_delta); 54.577 + } else { 54.578 + println(" /* full_frame */"); 54.579 + println(" offset_delta = " + frame.offset_delta); 54.580 + } 54.581 + printMap("locals", frame.locals); 54.582 + printMap("stack", frame.stack); 54.583 + return null; 54.584 + } 54.585 + 54.586 + void printHeader(StackMapTable_attribute.stack_map_frame frame) { 54.587 + print(" frame_type = " + frame.frame_type); 54.588 + } 54.589 + 54.590 + void printMap(String name, StackMapTable_attribute.verification_type_info[] map) { 54.591 + print(" " + name + " = ["); 54.592 + for (int i = 0; i < map.length; i++) { 54.593 + StackMapTable_attribute.verification_type_info info = map[i]; 54.594 + int tag = info.tag; 54.595 + switch (tag) { 54.596 + case StackMapTable_attribute.verification_type_info.ITEM_Object: 54.597 + print(" "); 54.598 + constantWriter.write(((StackMapTable_attribute.Object_variable_info) info).cpool_index); 54.599 + break; 54.600 + case StackMapTable_attribute.verification_type_info.ITEM_Uninitialized: 54.601 + print(" " + mapTypeName(tag)); 54.602 + print(" " + ((StackMapTable_attribute.Uninitialized_variable_info) info).offset); 54.603 + break; 54.604 + default: 54.605 + print(" " + mapTypeName(tag)); 54.606 + } 54.607 + print(i == (map.length - 1) ? " " : ","); 54.608 + } 54.609 + println("]"); 54.610 + } 54.611 + 54.612 + String mapTypeName(int tag) { 54.613 + switch (tag) { 54.614 + case StackMapTable_attribute.verification_type_info.ITEM_Top: 54.615 + return "top"; 54.616 + 54.617 + case StackMapTable_attribute.verification_type_info.ITEM_Integer: 54.618 + return "int"; 54.619 + 54.620 + case StackMapTable_attribute.verification_type_info.ITEM_Float: 54.621 + return "float"; 54.622 + 54.623 + case StackMapTable_attribute.verification_type_info.ITEM_Long: 54.624 + return "long"; 54.625 + 54.626 + case StackMapTable_attribute.verification_type_info.ITEM_Double: 54.627 + return "double"; 54.628 + 54.629 + case StackMapTable_attribute.verification_type_info.ITEM_Null: 54.630 + return "null"; 54.631 + 54.632 + case StackMapTable_attribute.verification_type_info.ITEM_UninitializedThis: 54.633 + return "this"; 54.634 + 54.635 + case StackMapTable_attribute.verification_type_info.ITEM_Object: 54.636 + return "CP"; 54.637 + 54.638 + case StackMapTable_attribute.verification_type_info.ITEM_Uninitialized: 54.639 + return "uninitialized"; 54.640 + 54.641 + default: 54.642 + report("unrecognized verification_type_info tag: " + tag); 54.643 + return "[tag:" + tag + "]"; 54.644 + } 54.645 + } 54.646 + } 54.647 + 54.648 + public Void visitSynthetic(Synthetic_attribute attr, Void ignore) { 54.649 + println("Synthetic: true"); 54.650 + return null; 54.651 + } 54.652 + 54.653 + static String getJavaName(String name) { 54.654 + return name.replace('/', '.'); 54.655 + } 54.656 + 54.657 + String toHex(byte b, int w) { 54.658 + if (options.compat) // BUG 6622260: javap prints negative bytes incorrectly in hex 54.659 + return toHex((int) b, w); 54.660 + else 54.661 + return toHex(b & 0xff, w); 54.662 + } 54.663 + 54.664 + static String toHex(int i) { 54.665 + return Integer.toString(i, 16).toUpperCase(); 54.666 + } 54.667 + 54.668 + static String toHex(int i, int w) { 54.669 + String s = Integer.toHexString(i).toUpperCase(); 54.670 + while (s.length() < w) 54.671 + s = "0" + s; 54.672 + return s.toUpperCase(); 54.673 + } 54.674 + 54.675 + private AnnotationWriter annotationWriter; 54.676 + private CodeWriter codeWriter; 54.677 + private ConstantWriter constantWriter; 54.678 + private Options options; 54.679 + 54.680 + private ConstantPool constant_pool; 54.681 + private Object owner; 54.682 +}
55.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 55.2 +++ b/src/share/classes/com/sun/tools/javap/BasicWriter.java Tue Jun 03 13:26:47 2008 -0700 55.3 @@ -0,0 +1,131 @@ 55.4 +/* 55.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. 55.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 55.7 + * 55.8 + * This code is free software; you can redistribute it and/or modify it 55.9 + * under the terms of the GNU General Public License version 2 only, as 55.10 + * published by the Free Software Foundation. Sun designates this 55.11 + * particular file as subject to the "Classpath" exception as provided 55.12 + * by Sun in the LICENSE file that accompanied this code. 55.13 + * 55.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 55.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 55.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 55.17 + * version 2 for more details (a copy is included in the LICENSE file that 55.18 + * accompanied this code). 55.19 + * 55.20 + * You should have received a copy of the GNU General Public License version 55.21 + * 2 along with this work; if not, write to the Free Software Foundation, 55.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 55.23 + * 55.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 55.25 + * CA 95054 USA or visit www.sun.com if you need additional information or 55.26 + * have any questions. 55.27 + */ 55.28 + 55.29 +package com.sun.tools.javap; 55.30 + 55.31 +import java.io.PrintWriter; 55.32 + 55.33 +import com.sun.tools.classfile.AttributeException; 55.34 +import com.sun.tools.classfile.ConstantPoolException; 55.35 +import com.sun.tools.classfile.DescriptorException; 55.36 + 55.37 +/* 55.38 + * A writer similar to a PrintWriter but which does not hide exceptions. 55.39 + * The standard print calls are line-buffered; report calls write messages directly. 55.40 + * 55.41 + * <p><b>This is NOT part of any API supported by Sun Microsystems. If 55.42 + * you write code that depends on this, you do so at your own risk. 55.43 + * This code and its internal interfaces are subject to change or 55.44 + * deletion without notice.</b> 55.45 + */ 55.46 +public class BasicWriter { 55.47 + protected BasicWriter(Context context) { 55.48 + lineWriter = LineWriter.instance(context); 55.49 + out = context.get(PrintWriter.class); 55.50 + } 55.51 + 55.52 + protected void print(String s) { 55.53 + lineWriter.print(s); 55.54 + } 55.55 + 55.56 + protected void print(Object o) { 55.57 + lineWriter.print(o == null ? null : o.toString()); 55.58 + } 55.59 + 55.60 + protected void println() { 55.61 + lineWriter.println(); 55.62 + } 55.63 + 55.64 + protected void println(String s) { 55.65 + lineWriter.print(s); 55.66 + lineWriter.println(); 55.67 + } 55.68 + 55.69 + protected void println(Object o) { 55.70 + lineWriter.print(o == null ? null : o.toString()); 55.71 + lineWriter.println(); 55.72 + } 55.73 + 55.74 + protected String report(AttributeException e) { 55.75 + out.println("Error: " + e.getMessage()); // i18n? 55.76 + return "???"; 55.77 + } 55.78 + 55.79 + protected String report(ConstantPoolException e) { 55.80 + out.println("Error: " + e.getMessage()); // i18n? 55.81 + return "???"; 55.82 + } 55.83 + 55.84 + protected String report(DescriptorException e) { 55.85 + out.println("Error: " + e.getMessage()); // i18n? 55.86 + return "???"; 55.87 + } 55.88 + 55.89 + protected String report(String msg) { 55.90 + out.println("Error: " + msg); // i18n? 55.91 + return "???"; 55.92 + } 55.93 + 55.94 + private LineWriter lineWriter; 55.95 + private PrintWriter out; 55.96 + 55.97 + private static class LineWriter { 55.98 + static LineWriter instance(Context context) { 55.99 + LineWriter instance = context.get(LineWriter.class); 55.100 + if (instance == null) 55.101 + instance = new LineWriter(context); 55.102 + return instance; 55.103 + } 55.104 + 55.105 + protected LineWriter(Context context) { 55.106 + context.put(LineWriter.class, this); 55.107 + out = context.get(PrintWriter.class); 55.108 + buffer = new StringBuilder(); 55.109 + } 55.110 + 55.111 + protected void print(String s) { 55.112 + if (s == null) 55.113 + s = "null"; 55.114 + for (int i = 0; i < s.length(); i++) { 55.115 + char c = s.charAt(i); 55.116 + if (c == '\n') { 55.117 + println(); 55.118 + } else { 55.119 + buffer.append(c); 55.120 + } 55.121 + } 55.122 + 55.123 + } 55.124 + 55.125 + protected void println() { 55.126 + out.println(buffer); 55.127 + buffer.setLength(0); 55.128 + } 55.129 + 55.130 + private PrintWriter out; 55.131 + private StringBuilder buffer; 55.132 + } 55.133 +} 55.134 +
56.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 56.2 +++ b/src/share/classes/com/sun/tools/javap/ClassWriter.java Tue Jun 03 13:26:47 2008 -0700 56.3 @@ -0,0 +1,488 @@ 56.4 +/* 56.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. 56.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 56.7 + * 56.8 + * This code is free software; you can redistribute it and/or modify it 56.9 + * under the terms of the GNU General Public License version 2 only, as 56.10 + * published by the Free Software Foundation. Sun designates this 56.11 + * particular file as subject to the "Classpath" exception as provided 56.12 + * by Sun in the LICENSE file that accompanied this code. 56.13 + * 56.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 56.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 56.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 56.17 + * version 2 for more details (a copy is included in the LICENSE file that 56.18 + * accompanied this code). 56.19 + * 56.20 + * You should have received a copy of the GNU General Public License version 56.21 + * 2 along with this work; if not, write to the Free Software Foundation, 56.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 56.23 + * 56.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 56.25 + * CA 95054 USA or visit www.sun.com if you need additional information or 56.26 + * have any questions. 56.27 + */ 56.28 + 56.29 +package com.sun.tools.javap; 56.30 + 56.31 +import java.util.Collection; 56.32 +import java.util.List; 56.33 + 56.34 +import com.sun.tools.classfile.AccessFlags; 56.35 +import com.sun.tools.classfile.Attribute; 56.36 +import com.sun.tools.classfile.Attributes; 56.37 +import com.sun.tools.classfile.ClassFile; 56.38 +import com.sun.tools.classfile.Code_attribute; 56.39 +import com.sun.tools.classfile.ConstantPool; 56.40 +import com.sun.tools.classfile.ConstantPoolException; 56.41 +import com.sun.tools.classfile.Descriptor; 56.42 +import com.sun.tools.classfile.DescriptorException; 56.43 +import com.sun.tools.classfile.Exceptions_attribute; 56.44 +import com.sun.tools.classfile.Field; 56.45 +import com.sun.tools.classfile.Method; 56.46 +import com.sun.tools.classfile.Signature; 56.47 +import com.sun.tools.classfile.Signature_attribute; 56.48 +import com.sun.tools.classfile.SourceFile_attribute; 56.49 +import com.sun.tools.classfile.Type; 56.50 + 56.51 +import static com.sun.tools.classfile.AccessFlags.*; 56.52 + 56.53 +/* 56.54 + * The main javap class to write the contents of a class file as text. 56.55 + * 56.56 + * <p><b>This is NOT part of any API supported by Sun Microsystems. If 56.57 + * you write code that depends on this, you do so at your own risk. 56.58 + * This code and its internal interfaces are subject to change or 56.59 + * deletion without notice.</b> 56.60 + */ 56.61 +public class ClassWriter extends BasicWriter { 56.62 + static ClassWriter instance(Context context) { 56.63 + ClassWriter instance = context.get(ClassWriter.class); 56.64 + if (instance == null) 56.65 + instance = new ClassWriter(context); 56.66 + return instance; 56.67 + } 56.68 + 56.69 + protected ClassWriter(Context context) { 56.70 + super(context); 56.71 + context.put(ClassWriter.class, this); 56.72 + options = Options.instance(context); 56.73 + attrWriter = AttributeWriter.instance(context); 56.74 + codeWriter = CodeWriter.instance(context); 56.75 + constantWriter = ConstantWriter.instance(context); 56.76 + } 56.77 + 56.78 + ClassFile getClassFile() { 56.79 + return classFile; 56.80 + } 56.81 + 56.82 + Method getMethod() { 56.83 + return method; 56.84 + } 56.85 + 56.86 + public void write(ClassFile cf) { 56.87 + classFile = cf; 56.88 + constant_pool = classFile.constant_pool; 56.89 + 56.90 + Attribute sfa = cf.getAttribute(Attribute.SourceFile); 56.91 + if (sfa instanceof SourceFile_attribute) { 56.92 + println("Compiled from \"" + getSourceFile((SourceFile_attribute) sfa) + "\""); 56.93 + } 56.94 + 56.95 + String name = getJavaName(classFile); 56.96 + AccessFlags flags = cf.access_flags; 56.97 + 56.98 + writeModifiers(flags.getClassModifiers()); 56.99 + 56.100 + if (classFile.isClass()) 56.101 + print("class "); 56.102 + else if (classFile.isInterface()) 56.103 + print("interface "); 56.104 + 56.105 + print(name); 56.106 + 56.107 + Signature_attribute sigAttr = getSignature(cf.attributes); 56.108 + if (sigAttr == null) { 56.109 + // use info from class file header 56.110 + if (classFile.isClass()) { 56.111 + if (classFile.super_class != 0 ) { 56.112 + String sn = getJavaSuperclassName(cf); 56.113 + if (!sn.equals("java.lang.Object") || options.compat) { // BUG XXXXXXXX 56.114 + print(" extends "); 56.115 + print(sn); 56.116 + } 56.117 + } 56.118 + } 56.119 + for (int i = 0; i < classFile.interfaces.length; i++) { 56.120 + print(i == 0 ? (classFile.isClass() ? " implements " : " extends ") : ","); 56.121 + print(getJavaInterfaceName(classFile, i)); 56.122 + } 56.123 + } else { 56.124 + try { 56.125 + Type t = sigAttr.getParsedSignature().getType(constant_pool); 56.126 + // The signature parser cannot disambiguate between a 56.127 + // FieldType and a ClassSignatureType that only contains a superclass type. 56.128 + if (t instanceof Type.ClassSigType) 56.129 + print(t); 56.130 + else if (!t.isObject()) { 56.131 + print(" extends "); 56.132 + print(t); 56.133 + } 56.134 + } catch (ConstantPoolException e) { 56.135 + print(report(e)); 56.136 + } 56.137 + } 56.138 + 56.139 + if (options.verbose) { 56.140 + println(); 56.141 + attrWriter.write(cf, cf.attributes, constant_pool); 56.142 + println(" minor version: " + cf.minor_version); 56.143 + println(" major version: " + cf.major_version); 56.144 + if (!options.compat) 56.145 + writeList(" flags: ", flags.getClassFlags(), NEWLINE); 56.146 + constantWriter.writeConstantPool(); 56.147 + println(); 56.148 + } else { 56.149 + if (!options.compat) 56.150 + print(" "); 56.151 + } 56.152 + 56.153 + println("{"); 56.154 + writeFields(); 56.155 + writeMethods(); 56.156 + println("}"); 56.157 + println(); 56.158 + } 56.159 + 56.160 + void writeFields() { 56.161 + for (Field f: classFile.fields) { 56.162 + writeField(f); 56.163 + } 56.164 + } 56.165 + 56.166 + void writeField(Field f) { 56.167 + if (!options.checkAccess(f.access_flags)) 56.168 + return; 56.169 + 56.170 + if (!(options.showLineAndLocalVariableTables 56.171 + || options.showDisassembled 56.172 + || options.verbose 56.173 + || options.showInternalSignatures 56.174 + || options.showAllAttrs)) { 56.175 + print(" "); 56.176 + } 56.177 + 56.178 + AccessFlags flags = f.access_flags; 56.179 + writeModifiers(flags.getFieldModifiers()); 56.180 + Signature_attribute sigAttr = getSignature(f.attributes); 56.181 + if (sigAttr == null) 56.182 + print(getFieldType(f.descriptor)); 56.183 + else { 56.184 + try { 56.185 + Type t = sigAttr.getParsedSignature().getType(constant_pool); 56.186 + print(t); 56.187 + } catch (ConstantPoolException e) { 56.188 + // report error? 56.189 + // fall back on non-generic descriptor 56.190 + print(getFieldType(f.descriptor)); 56.191 + } 56.192 + } 56.193 + print(" "); 56.194 + print(getFieldName(f)); 56.195 + print(";"); 56.196 + println(); 56.197 + 56.198 + if (options.showInternalSignatures) 56.199 + println(" Signature: " + getValue(f.descriptor)); 56.200 + 56.201 + if (options.verbose && !options.compat) 56.202 + writeList(" flags: ", flags.getFieldFlags(), NEWLINE); 56.203 + 56.204 + if (options.showAllAttrs) { 56.205 + for (Attribute attr: f.attributes) 56.206 + attrWriter.write(f, attr, constant_pool); 56.207 + println(); 56.208 + } 56.209 + 56.210 + if (options.showDisassembled || options.showLineAndLocalVariableTables) 56.211 + println(); 56.212 + } 56.213 + 56.214 + void writeMethods() { 56.215 + for (Method m: classFile.methods) 56.216 + writeMethod(m); 56.217 + } 56.218 + 56.219 + void writeMethod(Method m) { 56.220 + if (!options.checkAccess(m.access_flags)) 56.221 + return; 56.222 + 56.223 + method = m; 56.224 + 56.225 + if (!(options.showLineAndLocalVariableTables 56.226 + || options.showDisassembled 56.227 + || options.verbose 56.228 + || options.showInternalSignatures 56.229 + || options.showAllAttrs)) { 56.230 + print(" "); 56.231 + } 56.232 + 56.233 + AccessFlags flags = m.access_flags; 56.234 + 56.235 + Descriptor d; 56.236 + Type.MethodType methodType; 56.237 + List<? extends Type> methodExceptions; 56.238 + 56.239 + Signature_attribute sigAttr = getSignature(m.attributes); 56.240 + if (sigAttr == null) { 56.241 + d = m.descriptor; 56.242 + methodType = null; 56.243 + methodExceptions = null; 56.244 + } else { 56.245 + Signature methodSig = sigAttr.getParsedSignature(); 56.246 + d = methodSig; 56.247 + try { 56.248 + methodType = (Type.MethodType) methodSig.getType(constant_pool); 56.249 + methodExceptions = methodType.throwsTypes; 56.250 + if (methodExceptions != null && methodExceptions.size() == 0) 56.251 + methodExceptions = null; 56.252 + } catch (ConstantPoolException e) { 56.253 + // report error? 56.254 + // fall back on standard descriptor 56.255 + methodType = null; 56.256 + methodExceptions = null; 56.257 + } 56.258 + } 56.259 + 56.260 + writeModifiers(flags.getMethodModifiers()); 56.261 + if (methodType != null) { 56.262 + writeListIfNotEmpty("<", methodType.typeArgTypes, "> "); 56.263 + } 56.264 + if (getName(m).equals("<init>")) { 56.265 + print(getJavaName(classFile)); 56.266 + print(getParameterTypes(d, flags)); 56.267 + } else if (getName(m).equals("<clinit>")) { 56.268 + print("{}"); 56.269 + } else { 56.270 + print(getReturnType(d)); 56.271 + print(" "); 56.272 + print(getName(m)); 56.273 + print(getParameterTypes(d, flags)); 56.274 + } 56.275 + 56.276 + Attribute e_attr = m.attributes.get(Attribute.Exceptions); 56.277 + if (e_attr != null) { // if there are generic exceptions, there must be erased exceptions 56.278 + if (e_attr instanceof Exceptions_attribute) { 56.279 + Exceptions_attribute exceptions = (Exceptions_attribute) e_attr; 56.280 + if (options.compat) { // Bug XXXXXXX whitespace 56.281 + if (!(options.showLineAndLocalVariableTables 56.282 + || options.showDisassembled 56.283 + || options.verbose 56.284 + || options.showInternalSignatures 56.285 + || options.showAllAttrs)) { 56.286 + print(" "); 56.287 + } 56.288 + print(" "); 56.289 + } 56.290 + print(" throws "); 56.291 + if (methodExceptions != null) { // use generic list if available 56.292 + writeList("", methodExceptions, ""); 56.293 + } else { 56.294 + for (int i = 0; i < exceptions.number_of_exceptions; i++) { 56.295 + if (i > 0) 56.296 + print(", "); 56.297 + print(attrWriter.getJavaException(exceptions, i)); 56.298 + } 56.299 + } 56.300 + } else { 56.301 + report("Unexpected or invalid value for Exceptions attribute"); 56.302 + } 56.303 + } 56.304 + 56.305 + print(";"); 56.306 + println(); 56.307 + 56.308 + if (options.showInternalSignatures) 56.309 + println(" Signature: " + getValue(m.descriptor)); 56.310 + 56.311 + if (options.verbose && !options.compat) 56.312 + writeList(" flags: ", flags.getMethodFlags(), NEWLINE); 56.313 + 56.314 + Code_attribute code = null; 56.315 + Attribute c_attr = m.attributes.get(Attribute.Code); 56.316 + if (c_attr != null) { 56.317 + if (c_attr instanceof Code_attribute) 56.318 + code = (Code_attribute) c_attr; 56.319 + else 56.320 + report("Unexpected or invalid value for Code attribute"); 56.321 + } 56.322 + 56.323 + if (options.showDisassembled && !options.showAllAttrs) { 56.324 + if (code != null) { 56.325 + println(" Code:"); 56.326 + codeWriter.writeInstrs(code); 56.327 + codeWriter.writeExceptionTable(code); 56.328 + } 56.329 + println(); 56.330 + } 56.331 + 56.332 + if (options.showLineAndLocalVariableTables) { 56.333 + if (code != null) 56.334 + attrWriter.write(code, code.attributes.get(Attribute.LineNumberTable), constant_pool); 56.335 + println(); 56.336 + if (code != null) 56.337 + attrWriter.write(code, code.attributes.get(Attribute.LocalVariableTable), constant_pool); 56.338 + println(); 56.339 + println(); 56.340 + } 56.341 + 56.342 + if (options.showAllAttrs) { 56.343 + Attribute[] attrs = m.attributes.attrs; 56.344 + for (Attribute attr: attrs) 56.345 + attrWriter.write(m, attr, constant_pool); 56.346 + 56.347 +// // the following condition is to mimic old javap 56.348 +// if (!(attrs.length > 0 && 56.349 +// attrs[attrs.length - 1] instanceof Exceptions_attribute)) 56.350 + println(); 56.351 + } 56.352 + } 56.353 + 56.354 + void writeModifiers(Collection<String> items) { 56.355 + for (Object item: items) { 56.356 + print(item); 56.357 + print(" "); 56.358 + } 56.359 + } 56.360 + 56.361 + void writeList(String prefix, Collection<?> items, String suffix) { 56.362 + print(prefix); 56.363 + String sep = ""; 56.364 + for (Object item: items) { 56.365 + print(sep); 56.366 + print(item); 56.367 + sep = ", "; 56.368 + } 56.369 + print(suffix); 56.370 + } 56.371 + 56.372 + void writeListIfNotEmpty(String prefix, List<?> items, String suffix) { 56.373 + if (items != null && items.size() > 0) 56.374 + writeList(prefix, items, suffix); 56.375 + } 56.376 + 56.377 + Signature_attribute getSignature(Attributes attributes) { 56.378 + if (options.compat) // javap does not recognize recent attributes 56.379 + return null; 56.380 + return (Signature_attribute) attributes.get(Attribute.Signature); 56.381 + } 56.382 + 56.383 + String adjustVarargs(AccessFlags flags, String params) { 56.384 + if (flags.is(ACC_VARARGS) && !options.compat) { 56.385 + int i = params.lastIndexOf("[]"); 56.386 + if (i > 0) 56.387 + return params.substring(0, i) + "..." + params.substring(i+2); 56.388 + } 56.389 + 56.390 + return params; 56.391 + } 56.392 + 56.393 + String getJavaName(ClassFile cf) { 56.394 + try { 56.395 + return getJavaName(cf.getName()); 56.396 + } catch (ConstantPoolException e) { 56.397 + return report(e); 56.398 + } 56.399 + } 56.400 + 56.401 + String getJavaSuperclassName(ClassFile cf) { 56.402 + try { 56.403 + return getJavaName(cf.getSuperclassName()); 56.404 + } catch (ConstantPoolException e) { 56.405 + return report(e); 56.406 + } 56.407 + } 56.408 + 56.409 + String getJavaInterfaceName(ClassFile cf, int index) { 56.410 + try { 56.411 + return getJavaName(cf.getInterfaceName(index)); 56.412 + } catch (ConstantPoolException e) { 56.413 + return report(e); 56.414 + } 56.415 + } 56.416 + 56.417 + String getFieldType(Descriptor d) { 56.418 + try { 56.419 + return d.getFieldType(constant_pool); 56.420 + } catch (ConstantPoolException e) { 56.421 + return report(e); 56.422 + } catch (DescriptorException e) { 56.423 + return report(e); 56.424 + } 56.425 + } 56.426 + 56.427 + String getReturnType(Descriptor d) { 56.428 + try { 56.429 + return d.getReturnType(constant_pool); 56.430 + } catch (ConstantPoolException e) { 56.431 + return report(e); 56.432 + } catch (DescriptorException e) { 56.433 + return report(e); 56.434 + } 56.435 + } 56.436 + 56.437 + String getParameterTypes(Descriptor d, AccessFlags flags) { 56.438 + try { 56.439 + return adjustVarargs(flags, d.getParameterTypes(constant_pool)); 56.440 + } catch (ConstantPoolException e) { 56.441 + return report(e); 56.442 + } catch (DescriptorException e) { 56.443 + return report(e); 56.444 + } 56.445 + } 56.446 + 56.447 + String getValue(Descriptor d) { 56.448 + try { 56.449 + return d.getValue(constant_pool); 56.450 + } catch (ConstantPoolException e) { 56.451 + return report(e); 56.452 + } 56.453 + } 56.454 + 56.455 + String getFieldName(Field f) { 56.456 + try { 56.457 + return f.getName(constant_pool); 56.458 + } catch (ConstantPoolException e) { 56.459 + return report(e); 56.460 + } 56.461 + } 56.462 + 56.463 + String getName(Method m) { 56.464 + try { 56.465 + return m.getName(constant_pool); 56.466 + } catch (ConstantPoolException e) { 56.467 + return report(e); 56.468 + } 56.469 + } 56.470 + 56.471 + static String getJavaName(String name) { 56.472 + return name.replace('/', '.'); 56.473 + } 56.474 + 56.475 + String getSourceFile(SourceFile_attribute attr) { 56.476 + try { 56.477 + return attr.getSourceFile(constant_pool); 56.478 + } catch (ConstantPoolException e) { 56.479 + return report(e); 56.480 + } 56.481 + } 56.482 + 56.483 + private Options options; 56.484 + private AttributeWriter attrWriter; 56.485 + private CodeWriter codeWriter; 56.486 + private ConstantWriter constantWriter; 56.487 + private ClassFile classFile; 56.488 + private ConstantPool constant_pool; 56.489 + private Method method; 56.490 + private static final String NEWLINE = System.getProperty("line.separator", "\n"); 56.491 +}
57.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 57.2 +++ b/src/share/classes/com/sun/tools/javap/CodeWriter.java Tue Jun 03 13:26:47 2008 -0700 57.3 @@ -0,0 +1,344 @@ 57.4 +/* 57.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. 57.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 57.7 + * 57.8 + * This code is free software; you can redistribute it and/or modify it 57.9 + * under the terms of the GNU General Public License version 2 only, as 57.10 + * published by the Free Software Foundation. Sun designates this 57.11 + * particular file as subject to the "Classpath" exception as provided 57.12 + * by Sun in the LICENSE file that accompanied this code. 57.13 + * 57.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 57.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 57.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 57.17 + * version 2 for more details (a copy is included in the LICENSE file that 57.18 + * accompanied this code). 57.19 + * 57.20 + * You should have received a copy of the GNU General Public License version 57.21 + * 2 along with this work; if not, write to the Free Software Foundation, 57.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 57.23 + * 57.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 57.25 + * CA 95054 USA or visit www.sun.com if you need additional information or 57.26 + * have any questions. 57.27 + */ 57.28 + 57.29 +package com.sun.tools.javap; 57.30 + 57.31 +import com.sun.tools.classfile.AccessFlags; 57.32 +import com.sun.tools.classfile.Code_attribute; 57.33 +import com.sun.tools.classfile.ConstantPool; 57.34 +import com.sun.tools.classfile.ConstantPoolException; 57.35 +import com.sun.tools.classfile.DescriptorException; 57.36 +import com.sun.tools.classfile.Method; 57.37 + 57.38 +import static com.sun.tools.classfile.OpCodes.*; 57.39 + 57.40 +/* 57.41 + * Write the contents of a Code attribute. 57.42 + * 57.43 + * <p><b>This is NOT part of any API supported by Sun Microsystems. If 57.44 + * you write code that depends on this, you do so at your own risk. 57.45 + * This code and its internal interfaces are subject to change or 57.46 + * deletion without notice.</b> 57.47 + */ 57.48 +class CodeWriter extends BasicWriter { 57.49 + static CodeWriter instance(Context context) { 57.50 + CodeWriter instance = context.get(CodeWriter.class); 57.51 + if (instance == null) 57.52 + instance = new CodeWriter(context); 57.53 + return instance; 57.54 + } 57.55 + 57.56 + protected CodeWriter(Context context) { 57.57 + super(context); 57.58 + context.put(CodeWriter.class, this); 57.59 + attrWriter = AttributeWriter.instance(context); 57.60 + classWriter = ClassWriter.instance(context); 57.61 + constantWriter = ConstantWriter.instance(context); 57.62 + } 57.63 + 57.64 + void write(Code_attribute attr, ConstantPool constant_pool) { 57.65 + println(" Code:"); 57.66 + writeVerboseHeader(attr, constant_pool); 57.67 + writeInstrs(attr); 57.68 + writeExceptionTable(attr); 57.69 + attrWriter.write(attr, attr.attributes, constant_pool); 57.70 + } 57.71 + 57.72 + public void writeVerboseHeader(Code_attribute attr, ConstantPool constant_pool) { 57.73 + Method method = classWriter.getMethod(); 57.74 + String argCount; 57.75 + try { 57.76 + int n = method.descriptor.getParameterCount(constant_pool); 57.77 + if (!method.access_flags.is(AccessFlags.ACC_STATIC)) 57.78 + ++n; // for 'this' 57.79 + argCount = Integer.toString(n); 57.80 + } catch (ConstantPoolException e) { 57.81 + argCount = report(e); 57.82 + } catch (DescriptorException e) { 57.83 + argCount = report(e); 57.84 + } 57.85 + 57.86 + println(" Stack=" + attr.max_stack + 57.87 + ", Locals=" + attr.max_locals + 57.88 + ", Args_size=" + argCount); 57.89 + 57.90 + } 57.91 + 57.92 + public void writeInstrs(Code_attribute attr) { 57.93 + try { 57.94 + for (int pc = 0; pc < attr.code_length;) { 57.95 + print(" " + pc + ":\t"); 57.96 + pc += writeInstr(attr, pc); 57.97 + println(); 57.98 + } 57.99 + } catch (Code_attribute.InvalidIndex e) { 57.100 + println(report(e)); 57.101 + } 57.102 + } 57.103 + 57.104 + public int writeInstr(Code_attribute attr, int pc) 57.105 + throws Code_attribute.InvalidIndex { 57.106 + String lP = ""; 57.107 + int opcode = attr.getUnsignedByte(pc); 57.108 + int opcode2; 57.109 + String mnem; 57.110 + switch (opcode) { 57.111 + case opc_nonpriv: 57.112 + case opc_priv: { 57.113 + opcode2 = attr.getUnsignedByte(pc + 1); 57.114 + mnem = opcName((opcode << 8) + opcode2); 57.115 + if (mnem == null) { 57.116 + mnem = opcName(opcode) + " " + opcode2; 57.117 + } 57.118 + print(mnem); 57.119 + return 2; 57.120 + } 57.121 + case opc_wide: { 57.122 + opcode2 = attr.getUnsignedByte(pc + 1); 57.123 + mnem = opcName((opcode << 8) + opcode2); 57.124 + if (mnem == null) { 57.125 + print("bytecode " + opcode); 57.126 + return 1; 57.127 + } 57.128 + print(mnem + " " + attr.getUnsignedShort(pc + 2)); 57.129 + if (opcode2 == opc_iinc) { 57.130 + print(", " + attr.getShort(pc + 4)); 57.131 + return 6; 57.132 + } 57.133 + return 4; 57.134 + } 57.135 + } 57.136 + mnem = opcName(opcode); 57.137 + if (mnem == null) { 57.138 + print("bytecode " + opcode); 57.139 + return 1; 57.140 + } 57.141 + if (opcode > opc_jsr_w) { 57.142 + print("bytecode " + opcode); 57.143 + return 1; 57.144 + } 57.145 + print(opcName(opcode)); 57.146 + switch (opcode) { 57.147 + case opc_aload: 57.148 + case opc_astore: 57.149 + case opc_fload: 57.150 + case opc_fstore: 57.151 + case opc_iload: 57.152 + case opc_istore: 57.153 + case opc_lload: 57.154 + case opc_lstore: 57.155 + case opc_dload: 57.156 + case opc_dstore: 57.157 + case opc_ret: 57.158 + print("\t" + attr.getUnsignedByte(pc + 1)); 57.159 + return 2; 57.160 + case opc_iinc: 57.161 + print("\t" + attr.getUnsignedByte(pc + 1) + ", " + attr.getByte(pc + 2)); 57.162 + return 3; 57.163 + case opc_tableswitch: 57.164 + { 57.165 + int tb = align(pc + 1); 57.166 + int default_skip = attr.getInt(tb); 57.167 + int low = attr.getInt(tb + 4); 57.168 + int high = attr.getInt(tb + 8); 57.169 + int count = high - low; 57.170 + print("{ //" + low + " to " + high); 57.171 + for (int i = 0; i <= count; i++) { 57.172 + print("\n\t\t" + (i + low) + ": " + lP + (pc + attr.getInt(tb + 12 + 4 * i)) + ";"); 57.173 + } 57.174 + print("\n\t\tdefault: " + lP + (default_skip + pc) + " }"); 57.175 + return tb - pc + 16 + count * 4; 57.176 + } 57.177 + case opc_lookupswitch: 57.178 + { 57.179 + int tb = align(pc + 1); 57.180 + int default_skip = attr.getInt(tb); 57.181 + int npairs = attr.getInt(tb + 4); 57.182 + print("{ //" + npairs); 57.183 + for (int i = 1; i <= npairs; i++) { 57.184 + print("\n\t\t" + attr.getInt(tb + i * 8) + ": " + lP + (pc + attr.getInt(tb + 4 + i * 8)) + ";"); 57.185 + } 57.186 + print("\n\t\tdefault: " + lP + (default_skip + pc) + " }"); 57.187 + return tb - pc + (npairs + 1) * 8; 57.188 + } 57.189 + case opc_newarray: 57.190 + int type = attr.getUnsignedByte(pc + 1); 57.191 + switch (type) { 57.192 + case T_BOOLEAN: 57.193 + print(" boolean"); 57.194 + break; 57.195 + case T_BYTE: 57.196 + print(" byte"); 57.197 + break; 57.198 + case T_CHAR: 57.199 + print(" char"); 57.200 + break; 57.201 + case T_SHORT: 57.202 + print(" short"); 57.203 + break; 57.204 + case T_INT: 57.205 + print(" int"); 57.206 + break; 57.207 + case T_LONG: 57.208 + print(" long"); 57.209 + break; 57.210 + case T_FLOAT: 57.211 + print(" float"); 57.212 + break; 57.213 + case T_DOUBLE: 57.214 + print(" double"); 57.215 + break; 57.216 + case T_CLASS: 57.217 + print(" class"); 57.218 + break; 57.219 + default: 57.220 + print(" BOGUS TYPE:" + type); 57.221 + } 57.222 + return 2; 57.223 + case opc_anewarray: 57.224 + { 57.225 + int index = attr.getUnsignedShort(pc + 1); 57.226 + print("\t#" + index + "; //"); 57.227 + printConstant(index); 57.228 + return 3; 57.229 + } 57.230 + case opc_sipush: 57.231 + print("\t" + attr.getShort(pc + 1)); 57.232 + return 3; 57.233 + case opc_bipush: 57.234 + print("\t" + attr.getByte(pc + 1)); 57.235 + return 2; 57.236 + case opc_ldc: 57.237 + { 57.238 + int index = attr.getUnsignedByte(pc + 1); 57.239 + print("\t#" + index + "; //"); 57.240 + printConstant(index); 57.241 + return 2; 57.242 + } 57.243 + case opc_ldc_w: 57.244 + case opc_ldc2_w: 57.245 + case opc_instanceof: 57.246 + case opc_checkcast: 57.247 + case opc_new: 57.248 + case opc_putstatic: 57.249 + case opc_getstatic: 57.250 + case opc_putfield: 57.251 + case opc_getfield: 57.252 + case opc_invokevirtual: 57.253 + case opc_invokespecial: 57.254 + case opc_invokestatic: 57.255 + { 57.256 + int index = attr.getUnsignedShort(pc + 1); 57.257 + print("\t#" + index + "; //"); 57.258 + printConstant(index); 57.259 + return 3; 57.260 + } 57.261 + case opc_invokeinterface: 57.262 + { 57.263 + int index = attr.getUnsignedShort(pc + 1); 57.264 + int nargs = attr.getUnsignedByte(pc + 3); 57.265 + print("\t#" + index + ", " + nargs + "; //"); 57.266 + printConstant(index); 57.267 + return 5; 57.268 + } 57.269 + case opc_multianewarray: 57.270 + { 57.271 + int index = attr.getUnsignedShort(pc + 1); 57.272 + int dimensions = attr.getUnsignedByte(pc + 3); 57.273 + print("\t#" + index + ", " + dimensions + "; //"); 57.274 + printConstant(index); 57.275 + return 4; 57.276 + } 57.277 + case opc_jsr: 57.278 + case opc_goto: 57.279 + case opc_ifeq: 57.280 + case opc_ifge: 57.281 + case opc_ifgt: 57.282 + case opc_ifle: 57.283 + case opc_iflt: 57.284 + case opc_ifne: 57.285 + case opc_if_icmpeq: 57.286 + case opc_if_icmpne: 57.287 + case opc_if_icmpge: 57.288 + case opc_if_icmpgt: 57.289 + case opc_if_icmple: 57.290 + case opc_if_icmplt: 57.291 + case opc_if_acmpeq: 57.292 + case opc_if_acmpne: 57.293 + case opc_ifnull: 57.294 + case opc_ifnonnull: 57.295 + print("\t" + lP + (pc + attr.getShort(pc + 1))); 57.296 + return 3; 57.297 + case opc_jsr_w: 57.298 + case opc_goto_w: 57.299 + print("\t" + lP + (pc + attr.getInt(pc + 1))); 57.300 + return 5; 57.301 + default: 57.302 + return 1; 57.303 + } 57.304 + } 57.305 + 57.306 + public void writeExceptionTable(Code_attribute attr) { 57.307 + if (attr.exception_table_langth > 0) { 57.308 + println(" Exception table:"); 57.309 + println(" from to target type"); 57.310 + for (int i = 0; i < attr.exception_table.length; i++) { 57.311 + Code_attribute.Exception_data handler = attr.exception_table[i]; 57.312 + printFixedWidthInt(handler.start_pc, 6); 57.313 + printFixedWidthInt(handler.end_pc, 6); 57.314 + printFixedWidthInt(handler.handler_pc, 6); 57.315 + print(" "); 57.316 + int catch_type = handler.catch_type; 57.317 + if (catch_type == 0) { 57.318 + println("any"); 57.319 + } else { 57.320 + print("Class "); 57.321 + println(constantWriter.stringValue(catch_type)); 57.322 + println(""); 57.323 + } 57.324 + } 57.325 + } 57.326 + 57.327 + } 57.328 + 57.329 + private void printConstant(int index) { 57.330 + constantWriter.write(index); 57.331 + } 57.332 + 57.333 + private void printFixedWidthInt(int n, int width) { 57.334 + String s = String.valueOf(n); 57.335 + for (int i = s.length(); i < width; i++) 57.336 + print(" "); 57.337 + print(s); 57.338 + } 57.339 + 57.340 + private static int align(int n) { 57.341 + return (n + 3) & ~3; 57.342 + } 57.343 + 57.344 + private AttributeWriter attrWriter; 57.345 + private ClassWriter classWriter; 57.346 + private ConstantWriter constantWriter; 57.347 +}
58.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 58.2 +++ b/src/share/classes/com/sun/tools/javap/ConstantWriter.java Tue Jun 03 13:26:47 2008 -0700 58.3 @@ -0,0 +1,352 @@ 58.4 +/* 58.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. 58.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 58.7 + * 58.8 + * This code is free software; you can redistribute it and/or modify it 58.9 + * under the terms of the GNU General Public License version 2 only, as 58.10 + * published by the Free Software Foundation. Sun designates this 58.11 + * particular file as subject to the "Classpath" exception as provided 58.12 + * by Sun in the LICENSE file that accompanied this code. 58.13 + * 58.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 58.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 58.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 58.17 + * version 2 for more details (a copy is included in the LICENSE file that 58.18 + * accompanied this code). 58.19 + * 58.20 + * You should have received a copy of the GNU General Public License version 58.21 + * 2 along with this work; if not, write to the Free Software Foundation, 58.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 58.23 + * 58.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 58.25 + * CA 95054 USA or visit www.sun.com if you need additional information or 58.26 + * have any questions. 58.27 + */ 58.28 + 58.29 +package com.sun.tools.javap; 58.30 + 58.31 +import com.sun.tools.classfile.ClassFile; 58.32 +import com.sun.tools.classfile.ConstantPool; 58.33 +import com.sun.tools.classfile.ConstantPoolException; 58.34 + 58.35 +import static com.sun.tools.classfile.ConstantPool.*; 58.36 + 58.37 +/* 58.38 + * Write a constant pool entry. 58.39 + * 58.40 + * <p><b>This is NOT part of any API supported by Sun Microsystems. If 58.41 + * you write code that depends on this, you do so at your own risk. 58.42 + * This code and its internal interfaces are subject to change or 58.43 + * deletion without notice.</b> 58.44 + */ 58.45 +public class ConstantWriter extends BasicWriter { 58.46 + static ConstantWriter instance(Context context) { 58.47 + ConstantWriter instance = context.get(ConstantWriter.class); 58.48 + if (instance == null) 58.49 + instance = new ConstantWriter(context); 58.50 + return instance; 58.51 + } 58.52 + 58.53 + protected ConstantWriter(Context context) { 58.54 + super(context); 58.55 + context.put(ConstantWriter.class, this); 58.56 + classWriter = ClassWriter.instance(context); 58.57 + options = Options.instance(context); 58.58 + } 58.59 + 58.60 + void writeConstantPool() { 58.61 + ConstantPool.Visitor<Integer, Void> v = new ConstantPool.Visitor<Integer,Void>() { 58.62 + public Integer visitClass(CONSTANT_Class_info info, Void p) { 58.63 + println("#" + info.name_index + ";\t// " + stringValue(info)); 58.64 + return 1; 58.65 + } 58.66 + 58.67 + public Integer visitDouble(CONSTANT_Double_info info, Void p) { 58.68 + println(stringValue(info) + ";"); 58.69 + return 2; 58.70 + } 58.71 + 58.72 + public Integer visitFieldref(CONSTANT_Fieldref_info info, Void p) { 58.73 + println("#" + info.class_index + ".#" + info.name_and_type_index + ";\t// " + stringValue(info)); 58.74 + return 1; 58.75 + } 58.76 + 58.77 + public Integer visitFloat(CONSTANT_Float_info info, Void p) { 58.78 + println(stringValue(info) + ";"); 58.79 + return 1; 58.80 + } 58.81 + 58.82 + public Integer visitInteger(CONSTANT_Integer_info info, Void p) { 58.83 + println(stringValue(info) + ";"); 58.84 + return 1; 58.85 + } 58.86 + 58.87 + public Integer visitInterfaceMethodref(CONSTANT_InterfaceMethodref_info info, Void p) { 58.88 + println("#" + info.class_index + ".#" + info.name_and_type_index + ";\t// " + stringValue(info)); 58.89 + return 1; 58.90 + } 58.91 + 58.92 + public Integer visitLong(CONSTANT_Long_info info, Void p) { 58.93 + println(stringValue(info) + ";"); 58.94 + return 2; 58.95 + } 58.96 + 58.97 + public Integer visitNameAndType(CONSTANT_NameAndType_info info, Void p) { 58.98 + String tab = (options.compat ? "" : "\t"); // BUG 6622232 javap gets whitespace confused 58.99 + println("#" + info.name_index + ":#" + info.type_index + ";" + tab + "// " + stringValue(info)); 58.100 + return 1; 58.101 + } 58.102 + 58.103 + public Integer visitMethodref(CONSTANT_Methodref_info info, Void p) { 58.104 + println("#" + info.class_index + ".#" + info.name_and_type_index + ";\t// " + stringValue(info)); 58.105 + return 1; 58.106 + } 58.107 + 58.108 + public Integer visitString(CONSTANT_String_info info, Void p) { 58.109 + println("#" + info.string_index + ";\t// " + stringValue(info)); 58.110 + return 1; 58.111 + } 58.112 + 58.113 + public Integer visitUtf8(CONSTANT_Utf8_info info, Void p) { 58.114 + println(stringValue(info) + ";"); 58.115 + return 1; 58.116 + } 58.117 + 58.118 + }; 58.119 + println(" Constant pool:"); 58.120 + ConstantPool constant_pool = classWriter.getClassFile().constant_pool; 58.121 + int cpx = 1; 58.122 + while (cpx < constant_pool.size()) { 58.123 + try { 58.124 + CPInfo cpInfo = constant_pool.get(cpx); 58.125 + print("const #" + cpx + " = " + tagName(cpInfo.getTag()) + "\t"); 58.126 + cpx += cpInfo.accept(v, null); 58.127 + } catch (ConstantPool.InvalidIndex ex) { 58.128 + print("const #" + cpx); // should not happen 58.129 + } 58.130 + } 58.131 + } 58.132 + 58.133 + void write(int cpx) { 58.134 + ClassFile classFile = classWriter.getClassFile(); 58.135 + if (cpx == 0) { 58.136 + print("#0"); 58.137 + return; 58.138 + } 58.139 + 58.140 + CPInfo cpInfo; 58.141 + try { 58.142 + cpInfo = classFile.constant_pool.get(cpx); 58.143 + } catch (ConstantPoolException e) { 58.144 + print("#" + cpx); 58.145 + return; 58.146 + } 58.147 + 58.148 + int tag = cpInfo.getTag(); 58.149 + switch (tag) { 58.150 + case CONSTANT_Methodref: 58.151 + case CONSTANT_InterfaceMethodref: 58.152 + case CONSTANT_Fieldref: 58.153 + // simplify references within this class 58.154 + CPRefInfo ref = (CPRefInfo) cpInfo; 58.155 + try { 58.156 + if (ref.class_index == classFile.this_class) 58.157 + cpInfo = classFile.constant_pool.get(ref.name_and_type_index); 58.158 + } catch (ConstantPool.InvalidIndex e) { 58.159 + // ignore, for now 58.160 + } 58.161 + } 58.162 + print(tagName(tag) + " " + stringValue(cpInfo)); 58.163 + } 58.164 + 58.165 + String tagName(int tag) { 58.166 + switch (tag) { 58.167 + case CONSTANT_Utf8: 58.168 + return "Asciz"; 58.169 + case CONSTANT_Integer: 58.170 + return "int"; 58.171 + case CONSTANT_Float: 58.172 + return "float"; 58.173 + case CONSTANT_Long: 58.174 + return "long"; 58.175 + case CONSTANT_Double: 58.176 + return "double"; 58.177 + case CONSTANT_Class: 58.178 + return "class"; 58.179 + case CONSTANT_String: 58.180 + return "String"; 58.181 + case CONSTANT_Fieldref: 58.182 + return "Field"; 58.183 + case CONSTANT_Methodref: 58.184 + return "Method"; 58.185 + case CONSTANT_InterfaceMethodref: 58.186 + return "InterfaceMethod"; 58.187 + case CONSTANT_NameAndType: 58.188 + return "NameAndType"; 58.189 + default: 58.190 + return "unknown tag"; 58.191 + } 58.192 + } 58.193 + 58.194 + String stringValue(int constant_pool_index) { 58.195 + ClassFile classFile = classWriter.getClassFile(); 58.196 + try { 58.197 + return stringValue(classFile.constant_pool.get(constant_pool_index)); 58.198 + } catch (ConstantPool.InvalidIndex e) { 58.199 + return report(e); 58.200 + } 58.201 + } 58.202 + 58.203 + String stringValue(CPInfo cpInfo) { 58.204 + return stringValueVisitor.visit(cpInfo); 58.205 + } 58.206 + 58.207 + StringValueVisitor stringValueVisitor = new StringValueVisitor(); 58.208 + 58.209 + private class StringValueVisitor implements ConstantPool.Visitor<String, Void> { 58.210 + public String visit(CPInfo info) { 58.211 + return info.accept(this, null); 58.212 + } 58.213 + 58.214 + public String visitClass(CONSTANT_Class_info info, Void p) { 58.215 + return getCheckedName(info); 58.216 + } 58.217 + 58.218 + String getCheckedName(CONSTANT_Class_info info) { 58.219 + try { 58.220 + return checkName(info.getName()); 58.221 + } catch (ConstantPoolException e) { 58.222 + return report(e); 58.223 + } 58.224 + } 58.225 + 58.226 + public String visitDouble(CONSTANT_Double_info info, Void p) { 58.227 + return info.value + "d"; 58.228 + } 58.229 + 58.230 + public String visitFieldref(CONSTANT_Fieldref_info info, Void p) { 58.231 + return visitRef(info, p); 58.232 + } 58.233 + 58.234 + public String visitFloat(CONSTANT_Float_info info, Void p) { 58.235 + return info.value + "f"; 58.236 + } 58.237 + 58.238 + public String visitInteger(CONSTANT_Integer_info info, Void p) { 58.239 + return String.valueOf(info.value); 58.240 + } 58.241 + 58.242 + public String visitInterfaceMethodref(CONSTANT_InterfaceMethodref_info info, Void p) { 58.243 + return visitRef(info, p); 58.244 + } 58.245 + 58.246 + public String visitLong(CONSTANT_Long_info info, Void p) { 58.247 + return info.value + "l"; 58.248 + } 58.249 + 58.250 + public String visitNameAndType(CONSTANT_NameAndType_info info, Void p) { 58.251 + return getCheckedName(info) + ":" + getType(info); 58.252 + } 58.253 + 58.254 + String getCheckedName(CONSTANT_NameAndType_info info) { 58.255 + try { 58.256 + return checkName(info.getName()); 58.257 + } catch (ConstantPoolException e) { 58.258 + return report(e); 58.259 + } 58.260 + } 58.261 + 58.262 + String getType(CONSTANT_NameAndType_info info) { 58.263 + try { 58.264 + return info.getType(); 58.265 + } catch (ConstantPoolException e) { 58.266 + return report(e); 58.267 + } 58.268 + } 58.269 + 58.270 + public String visitMethodref(CONSTANT_Methodref_info info, Void p) { 58.271 + return visitRef(info, p); 58.272 + } 58.273 + 58.274 + public String visitString(CONSTANT_String_info info, Void p) { 58.275 + try { 58.276 + ClassFile classFile = classWriter.getClassFile(); 58.277 + int string_index = info.string_index; 58.278 + return stringValue(classFile.constant_pool.getUTF8Info(string_index)); 58.279 + } catch (ConstantPoolException e) { 58.280 + return report(e); 58.281 + } 58.282 + } 58.283 + 58.284 + public String visitUtf8(CONSTANT_Utf8_info info, Void p) { 58.285 + String s = info.value; 58.286 + StringBuilder sb = new StringBuilder(); 58.287 + for (int i = 0; i < s.length(); i++) { 58.288 + char c = s.charAt(i); 58.289 + switch (c) { 58.290 + case '\t': 58.291 + sb.append('\\').append('t'); 58.292 + break; 58.293 + case '\n': 58.294 + sb.append('\\').append('n'); 58.295 + break; 58.296 + case '\r': 58.297 + sb.append('\\').append('r'); 58.298 + break; 58.299 + case '\"': 58.300 + sb.append('\\').append('\"'); 58.301 + break; 58.302 + default: 58.303 + sb.append(c); 58.304 + } 58.305 + } 58.306 + return sb.toString(); 58.307 + } 58.308 + 58.309 + String visitRef(CPRefInfo info, Void p) { 58.310 + String cn = getCheckedClassName(info); 58.311 + String nat; 58.312 + try { 58.313 + nat = stringValue(info.getNameAndTypeInfo()); 58.314 + } catch (ConstantPoolException e) { 58.315 + nat = report(e); 58.316 + } 58.317 + return cn + "." + nat; 58.318 + } 58.319 + 58.320 + String getCheckedClassName(CPRefInfo info) { 58.321 + try { 58.322 + return checkName(info.getClassName()); 58.323 + } catch (ConstantPoolException e) { 58.324 + return report(e); 58.325 + } 58.326 + } 58.327 + } 58.328 + 58.329 + 58.330 + /* If name is a valid binary name, return it; otherwise quote it. */ 58.331 + private static String checkName(String name) { 58.332 + if (name == null) 58.333 + return "null"; 58.334 + 58.335 + int len = name.length(); 58.336 + if (len == 0) 58.337 + return "\"\""; 58.338 + 58.339 + int cc = '/'; 58.340 + int cp; 58.341 + for (int k = 0; k < len; k += Character.charCount(cp)) { 58.342 + cp = name.codePointAt(k); 58.343 + if ((cc == '/' && !Character.isJavaIdentifierStart(cp)) 58.344 + || (cp != '/' && !Character.isJavaIdentifierPart(cp))) { 58.345 + return "\"" + name + "\""; 58.346 + } 58.347 + cc = cp; 58.348 + } 58.349 + 58.350 + return name; 58.351 + } 58.352 + 58.353 + private ClassWriter classWriter; 58.354 + private Options options; 58.355 +}
59.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 59.2 +++ b/src/share/classes/com/sun/tools/javap/Context.java Tue Jun 03 13:26:47 2008 -0700 59.3 @@ -0,0 +1,55 @@ 59.4 +/* 59.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. 59.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 59.7 + * 59.8 + * This code is free software; you can redistribute it and/or modify it 59.9 + * under the terms of the GNU General Public License version 2 only, as 59.10 + * published by the Free Software Foundation. Sun designates this 59.11 + * particular file as subject to the "Classpath" exception as provided 59.12 + * by Sun in the LICENSE file that accompanied this code. 59.13 + * 59.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 59.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 59.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 59.17 + * version 2 for more details (a copy is included in the LICENSE file that 59.18 + * accompanied this code). 59.19 + * 59.20 + * You should have received a copy of the GNU General Public License version 59.21 + * 2 along with this work; if not, write to the Free Software Foundation, 59.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 59.23 + * 59.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 59.25 + * CA 95054 USA or visit www.sun.com if you need additional information or 59.26 + * have any questions. 59.27 + */ 59.28 + 59.29 +package com.sun.tools.javap; 59.30 + 59.31 +import java.util.HashMap; 59.32 +import java.util.Map; 59.33 + 59.34 +/* 59.35 + * Class from which to put/get shared resources. 59.36 + * 59.37 + * <p><b>This is NOT part of any API supported by Sun Microsystems. If 59.38 + * you write code that depends on this, you do so at your own risk. 59.39 + * This code and its internal interfaces are subject to change or 59.40 + * deletion without notice.</b> 59.41 + */ 59.42 +public class Context { 59.43 + public Context() { 59.44 + map = new HashMap<Class<?>, Object>(); 59.45 + } 59.46 + 59.47 + @SuppressWarnings("unchecked") 59.48 + public <T> T get(Class<T> key) { 59.49 + return (T) map.get(key); 59.50 + } 59.51 + 59.52 + @SuppressWarnings("unchecked") 59.53 + public <T> T put(Class<T> key, T value) { 59.54 + return (T) map.put(key, value); 59.55 + } 59.56 + 59.57 + Map<Class<?>, Object> map; 59.58 +}
60.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 60.2 +++ b/src/share/classes/com/sun/tools/javap/DisassemblerTool.java Tue Jun 03 13:26:47 2008 -0700 60.3 @@ -0,0 +1,150 @@ 60.4 +/* 60.5 + * Copyright 2005-2006 Sun Microsystems, Inc. All Rights Reserved. 60.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 60.7 + * 60.8 + * This code is free software; you can redistribute it and/or modify it 60.9 + * under the terms of the GNU General Public License version 2 only, as 60.10 + * published by the Free Software Foundation. Sun designates this 60.11 + * particular file as subject to the "Classpath" exception as provided 60.12 + * by Sun in the LICENSE file that accompanied this code. 60.13 + * 60.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 60.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 60.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 60.17 + * version 2 for more details (a copy is included in the LICENSE file that 60.18 + * accompanied this code). 60.19 + * 60.20 + * You should have received a copy of the GNU General Public License version 60.21 + * 2 along with this work; if not, write to the Free Software Foundation, 60.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 60.23 + * 60.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 60.25 + * CA 95054 USA or visit www.sun.com if you need additional information or 60.26 + * have any questions. 60.27 + */ 60.28 + 60.29 +package com.sun.tools.javap; //javax.tools; 60.30 + 60.31 +import java.io.Writer; 60.32 +import java.nio.charset.Charset; 60.33 +import java.util.Locale; 60.34 +import java.util.concurrent.Callable; 60.35 +import javax.tools.DiagnosticListener; 60.36 +import javax.tools.JavaFileManager; 60.37 +import javax.tools.JavaFileObject; 60.38 +import javax.tools.OptionChecker; 60.39 +import javax.tools.StandardJavaFileManager; 60.40 +import javax.tools.Tool; 60.41 + 60.42 +/** 60.43 + * This class is intended to be put in javax.tools. 60.44 + * 60.45 + * @see DiagnosticListener 60.46 + * @see Diagnostic 60.47 + * @see JavaFileManager 60.48 + * @since 1.6 60.49 + * 60.50 + * <p><b>This is NOT part of any API supported by Sun Microsystems. If 60.51 + * you write code that depends on this, you do so at your own risk. 60.52 + * This code and its internal interfaces are subject to change or 60.53 + * deletion without notice.</b> 60.54 + */ 60.55 +public interface DisassemblerTool extends Tool, OptionChecker { 60.56 + 60.57 + /** 60.58 + * Creates a future for a disassembly task with the given 60.59 + * components and arguments. The task might not have 60.60 + * completed as described in the DissemblerTask interface. 60.61 + * 60.62 + * <p>If a file manager is provided, it must be able to handle all 60.63 + * locations defined in {@link StandardLocation}. 60.64 + * 60.65 + * @param out a Writer for additional output from the compiler; 60.66 + * use {@code System.err} if {@code null} 60.67 + * @param fileManager a file manager; if {@code null} use the 60.68 + * compiler's standard filemanager 60.69 + * @param diagnosticListener a diagnostic listener; if {@code 60.70 + * null} use the compiler's default method for reporting 60.71 + * diagnostics 60.72 + * @param options compiler options, {@code null} means no options 60.73 + * @param classes class names (for annotation processing), {@code 60.74 + * null} means no class names 60.75 + * @param compilationUnits the compilation units to compile, {@code 60.76 + * null} means no compilation units 60.77 + * @return an object representing the compilation 60.78 + * @throws RuntimeException if an unrecoverable error 60.79 + * occurred in a user supplied component. The 60.80 + * {@linkplain Throwable#getCause() cause} will be the error in 60.81 + * user code. 60.82 + * @throws IllegalArgumentException if any of the given 60.83 + * compilation units are of other kind than 60.84 + * {@linkplain JavaFileObject.Kind#SOURCE source} 60.85 + */ 60.86 + DisassemblerTask getTask(Writer out, 60.87 + JavaFileManager fileManager, 60.88 + DiagnosticListener<? super JavaFileObject> diagnosticListener, 60.89 + Iterable<String> options, 60.90 + Iterable<String> classes); 60.91 + 60.92 + /** 60.93 + * Gets a new instance of the standard file manager implementation 60.94 + * for this tool. The file manager will use the given diagnostic 60.95 + * listener for producing any non-fatal diagnostics. Fatal errors 60.96 + * will be signalled with the appropriate exceptions. 60.97 + * 60.98 + * <p>The standard file manager will be automatically reopened if 60.99 + * it is accessed after calls to {@code flush} or {@code close}. 60.100 + * The standard file manager must be usable with other tools. 60.101 + * 60.102 + * @param diagnosticListener a diagnostic listener for non-fatal 60.103 + * diagnostics; if {@code null} use the compiler's default method 60.104 + * for reporting diagnostics 60.105 + * @param locale the locale to apply when formatting diagnostics; 60.106 + * {@code null} means the {@linkplain Locale#getDefault() default locale}. 60.107 + * @param charset the character set used for decoding bytes; if 60.108 + * {@code null} use the platform default 60.109 + * @return the standard file manager 60.110 + */ 60.111 + StandardJavaFileManager getStandardFileManager( 60.112 + DiagnosticListener<? super JavaFileObject> diagnosticListener, 60.113 + Locale locale, 60.114 + Charset charset); 60.115 + 60.116 + /** 60.117 + * Interface representing a future for a disassembly task. The 60.118 + * task has not yet started. To start the task, call 60.119 + * the {@linkplain #call call} method. 60.120 + * 60.121 + * <p>Before calling the call method, additional aspects of the 60.122 + * task can be configured, for example, by calling the 60.123 + * {@linkplain #setLocale setLocale} method. 60.124 + */ 60.125 + interface DisassemblerTask extends Callable<Boolean> { 60.126 + 60.127 + /** 60.128 + * Set the locale to be applied when formatting diagnostics and 60.129 + * other localized data. 60.130 + * 60.131 + * @param locale the locale to apply; {@code null} means apply no 60.132 + * locale 60.133 + * @throws IllegalStateException if the task has started 60.134 + */ 60.135 + void setLocale(Locale locale); 60.136 + 60.137 + /** 60.138 + * Performs this compilation task. The compilation may only 60.139 + * be performed once. Subsequent calls to this method throw 60.140 + * IllegalStateException. 60.141 + * 60.142 + * @return true if and only all the files compiled without errors; 60.143 + * false otherwise 60.144 + * 60.145 + * @throws RuntimeException if an unrecoverable error occurred 60.146 + * in a user-supplied component. The 60.147 + * {@linkplain Throwable#getCause() cause} will be the error 60.148 + * in user code. 60.149 + * @throws IllegalStateException if called more than once 60.150 + */ 60.151 + Boolean call(); 60.152 + } 60.153 +}
61.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 61.2 +++ b/src/share/classes/com/sun/tools/javap/InternalError.java Tue Jun 03 13:26:47 2008 -0700 61.3 @@ -0,0 +1,46 @@ 61.4 +/* 61.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. 61.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 61.7 + * 61.8 + * This code is free software; you can redistribute it and/or modify it 61.9 + * under the terms of the GNU General Public License version 2 only, as 61.10 + * published by the Free Software Foundation. Sun designates this 61.11 + * particular file as subject to the "Classpath" exception as provided 61.12 + * by Sun in the LICENSE file that accompanied this code. 61.13 + * 61.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 61.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 61.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 61.17 + * version 2 for more details (a copy is included in the LICENSE file that 61.18 + * accompanied this code). 61.19 + * 61.20 + * You should have received a copy of the GNU General Public License version 61.21 + * 2 along with this work; if not, write to the Free Software Foundation, 61.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 61.23 + * 61.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 61.25 + * CA 95054 USA or visit www.sun.com if you need additional information or 61.26 + * have any questions. 61.27 + */ 61.28 + 61.29 +package com.sun.tools.javap; 61.30 + 61.31 +/** 61.32 + * <p><b>This is NOT part of any API supported by Sun Microsystems. If 61.33 + * you write code that depends on this, you do so at your own risk. 61.34 + * This code and its internal interfaces are subject to change or 61.35 + * deletion without notice.</b> 61.36 + */ 61.37 +public class InternalError extends Error { 61.38 + InternalError(Throwable t, Object... args) { 61.39 + super("Internal error", t); 61.40 + this.args = args; 61.41 + } 61.42 + 61.43 + InternalError(Object... args) { 61.44 + super("Internal error"); 61.45 + this.args = args; 61.46 + } 61.47 + 61.48 + public final Object[] args; 61.49 +}
62.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 62.2 +++ b/src/share/classes/com/sun/tools/javap/JavapFileManager.java Tue Jun 03 13:26:47 2008 -0700 62.3 @@ -0,0 +1,86 @@ 62.4 +/* 62.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. 62.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 62.7 + * 62.8 + * This code is free software; you can redistribute it and/or modify it 62.9 + * under the terms of the GNU General Public License version 2 only, as 62.10 + * published by the Free Software Foundation. Sun designates this 62.11 + * particular file as subject to the "Classpath" exception as provided 62.12 + * by Sun in the LICENSE file that accompanied this code. 62.13 + * 62.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 62.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 62.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 62.17 + * version 2 for more details (a copy is included in the LICENSE file that 62.18 + * accompanied this code). 62.19 + * 62.20 + * You should have received a copy of the GNU General Public License version 62.21 + * 2 along with this work; if not, write to the Free Software Foundation, 62.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 62.23 + * 62.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 62.25 + * CA 95054 USA or visit www.sun.com if you need additional information or 62.26 + * have any questions. 62.27 + */ 62.28 + 62.29 +package com.sun.tools.javap; 62.30 + 62.31 +import java.io.File; 62.32 +import java.io.PrintWriter; 62.33 +import java.nio.charset.Charset; 62.34 +import javax.tools.Diagnostic; 62.35 +import javax.tools.DiagnosticListener; 62.36 +import javax.tools.JavaFileObject; 62.37 + 62.38 +import com.sun.tools.javac.util.Context; 62.39 +import com.sun.tools.javac.util.JCDiagnostic; 62.40 +import com.sun.tools.javac.util.JavacFileManager; 62.41 + 62.42 +/** 62.43 + * javap's implementation of JavaFileManager. 62.44 + * 62.45 + * <p><b>This is NOT part of any API supported by Sun Microsystems. If 62.46 + * you write code that depends on this, you do so at your own risk. 62.47 + * This code and its internal interfaces are subject to change or 62.48 + * deletion without notice.</b> 62.49 + */ 62.50 +class JavapFileManager extends JavacFileManager { 62.51 + private JavapFileManager(Context context, Charset charset) { 62.52 + super(context, true, charset); 62.53 + } 62.54 + 62.55 + static JavapFileManager create(final DiagnosticListener<? super JavaFileObject> dl, PrintWriter log, Options options) { 62.56 + Context javac_context = new Context(); 62.57 + 62.58 + if (dl != null) { 62.59 + // Workaround bug 6625520: javac handles missing entries on classpath badly 62.60 + // Ignore spurious errors for missing files 62.61 + DiagnosticListener<JavaFileObject> wrapper = new DiagnosticListener<JavaFileObject>() { 62.62 + public void report(Diagnostic<? extends JavaFileObject> diagnostic) { 62.63 + if (diagnostic instanceof JCDiagnostic) { 62.64 + JCDiagnostic jcd = (JCDiagnostic) diagnostic; 62.65 + if (jcd.getCode().equals("compiler.err.error.reading.file")) { 62.66 + Object[] args = jcd.getArgs(); 62.67 + if (args.length > 0 && args[0] != null && args[0].toString().length() > 0) { 62.68 + File f = new File(args[0].toString()); 62.69 + if (!f.exists()) 62.70 + return; 62.71 + } 62.72 + } 62.73 + 62.74 + } 62.75 + dl.report(diagnostic); 62.76 + } 62.77 + }; 62.78 + javac_context.put(DiagnosticListener.class, wrapper); 62.79 + } 62.80 + 62.81 + javac_context.put(com.sun.tools.javac.util.Log.outKey, log); 62.82 + 62.83 + return new JavapFileManager(javac_context, null); 62.84 + } 62.85 + 62.86 + void setIgnoreSymbolFile(boolean b) { 62.87 + ignoreSymbolFile = b; 62.88 + } 62.89 +}
63.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 63.2 +++ b/src/share/classes/com/sun/tools/javap/JavapTask.java Tue Jun 03 13:26:47 2008 -0700 63.3 @@ -0,0 +1,624 @@ 63.4 +/* 63.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. 63.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 63.7 + * 63.8 + * This code is free software; you can redistribute it and/or modify it 63.9 + * under the terms of the GNU General Public License version 2 only, as 63.10 + * published by the Free Software Foundation. Sun designates this 63.11 + * particular file as subject to the "Classpath" exception as provided 63.12 + * by Sun in the LICENSE file that accompanied this code. 63.13 + * 63.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 63.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 63.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 63.17 + * version 2 for more details (a copy is included in the LICENSE file that 63.18 + * accompanied this code). 63.19 + * 63.20 + * You should have received a copy of the GNU General Public License version 63.21 + * 2 along with this work; if not, write to the Free Software Foundation, 63.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-15301 USA. 63.23 + * 63.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 63.25 + * CA 95054 USA or visit www.sun.com if you need additional information or 63.26 + * have any questions. 63.27 + */ 63.28 + 63.29 +package com.sun.tools.javap; 63.30 + 63.31 +import java.io.EOFException; 63.32 +import java.io.FileNotFoundException; 63.33 +import java.io.IOException; 63.34 +import java.io.OutputStream; 63.35 +import java.io.PrintWriter; 63.36 +import java.io.StringWriter; 63.37 +import java.io.Writer; 63.38 +import java.text.MessageFormat; 63.39 +import java.util.ArrayList; 63.40 +import java.util.Arrays; 63.41 +import java.util.HashMap; 63.42 +import java.util.Iterator; 63.43 +import java.util.List; 63.44 +import java.util.Locale; 63.45 +import java.util.Map; 63.46 +import java.util.MissingResourceException; 63.47 +import java.util.ResourceBundle; 63.48 + 63.49 +import javax.tools.Diagnostic; 63.50 +import javax.tools.DiagnosticListener; 63.51 +import javax.tools.JavaFileManager; 63.52 +import javax.tools.JavaFileObject; 63.53 +import javax.tools.StandardJavaFileManager; 63.54 +import javax.tools.StandardLocation; 63.55 + 63.56 +import com.sun.tools.classfile.*; 63.57 + 63.58 +/** 63.59 + * "Main" class for javap, normally accessed from the command line 63.60 + * via Main, or from JSR199 via DisassemblerTool. 63.61 + * 63.62 + * <p><b>This is NOT part of any API supported by Sun Microsystems. If 63.63 + * you write code that depends on this, you do so at your own risk. 63.64 + * This code and its internal interfaces are subject to change or 63.65 + * deletion without notice.</b> 63.66 + */ 63.67 +public class JavapTask implements DisassemblerTool.DisassemblerTask { 63.68 + public class BadArgs extends Exception { 63.69 + static final long serialVersionUID = 8765093759964640721L; 63.70 + BadArgs(String key, Object... args) { 63.71 + super(JavapTask.this.getMessage(key, args)); 63.72 + this.key = key; 63.73 + this.args = args; 63.74 + } 63.75 + 63.76 + BadArgs showUsage(boolean b) { 63.77 + showUsage = b; 63.78 + return this; 63.79 + } 63.80 + 63.81 + final String key; 63.82 + final Object[] args; 63.83 + boolean showUsage; 63.84 + } 63.85 + 63.86 + static abstract class Option { 63.87 + Option(boolean hasArg, String... aliases) { 63.88 + this.hasArg = hasArg; 63.89 + this.aliases = aliases; 63.90 + } 63.91 + 63.92 + boolean matches(String opt) { 63.93 + for (String a: aliases) { 63.94 + if (a.equals(opt)) 63.95 + return true; 63.96 + } 63.97 + return false; 63.98 + } 63.99 + 63.100 + boolean ignoreRest() { 63.101 + return false; 63.102 + } 63.103 + 63.104 + abstract void process(JavapTask task, String opt, String arg) throws BadArgs; 63.105 + 63.106 + final boolean hasArg; 63.107 + final String[] aliases; 63.108 + } 63.109 + 63.110 + static Option[] recognizedOptions = { 63.111 + 63.112 + new Option(false, "-help", "--help", "-?") { 63.113 + void process(JavapTask task, String opt, String arg) { 63.114 + task.options.help = true; 63.115 + } 63.116 + }, 63.117 + 63.118 + new Option(false, "-version") { 63.119 + void process(JavapTask task, String opt, String arg) { 63.120 + task.options.version = true; 63.121 + } 63.122 + }, 63.123 + 63.124 + new Option(false, "-fullversion") { 63.125 + void process(JavapTask task, String opt, String arg) { 63.126 + task.options.fullVersion = true; 63.127 + } 63.128 + }, 63.129 + 63.130 + new Option(false, "-v", "-verbose", "-all") { 63.131 + void process(JavapTask task, String opt, String arg) { 63.132 + task.options.verbose = true; 63.133 + task.options.showFlags = true; 63.134 + task.options.showAllAttrs = true; 63.135 + } 63.136 + }, 63.137 + 63.138 + new Option(false, "-l") { 63.139 + void process(JavapTask task, String opt, String arg) { 63.140 + task.options.showLineAndLocalVariableTables = true; 63.141 + } 63.142 + }, 63.143 + 63.144 + new Option(false, "-public") { 63.145 + void process(JavapTask task, String opt, String arg) { 63.146 + task.options.showAccess = AccessFlags.ACC_PUBLIC; 63.147 + } 63.148 + }, 63.149 + 63.150 + new Option(false, "-protected") { 63.151 + void process(JavapTask task, String opt, String arg) { 63.152 + task.options.showAccess = AccessFlags.ACC_PROTECTED; 63.153 + } 63.154 + }, 63.155 + 63.156 + new Option(false, "-package") { 63.157 + void process(JavapTask task, String opt, String arg) { 63.158 + task.options.showAccess = 0; 63.159 + } 63.160 + }, 63.161 + 63.162 + new Option(false, "-p", "-private") { 63.163 + void process(JavapTask task, String opt, String arg) { 63.164 + task.options.showAccess = AccessFlags.ACC_PRIVATE; 63.165 + } 63.166 + }, 63.167 + 63.168 + new Option(false, "-c") { 63.169 + void process(JavapTask task, String opt, String arg) { 63.170 + task.options.showDisassembled = true; 63.171 + } 63.172 + }, 63.173 + 63.174 + new Option(false, "-s") { 63.175 + void process(JavapTask task, String opt, String arg) { 63.176 + task.options.showInternalSignatures = true; 63.177 + } 63.178 + }, 63.179 + 63.180 +// new Option(false, "-all") { 63.181 +// void process(JavapTask task, String opt, String arg) { 63.182 +// task.options.showAllAttrs = true; 63.183 +// } 63.184 +// }, 63.185 + 63.186 + new Option(false, "-h") { 63.187 + void process(JavapTask task, String opt, String arg) throws BadArgs { 63.188 + throw task.new BadArgs("err.h.not.supported"); 63.189 + } 63.190 + }, 63.191 + 63.192 + new Option(false, "-verify", "-verify-verbose") { 63.193 + void process(JavapTask task, String opt, String arg) throws BadArgs { 63.194 + throw task.new BadArgs("err.verify.not.supported"); 63.195 + } 63.196 + }, 63.197 + 63.198 + new Option(false, "-Xold") { 63.199 + void process(JavapTask task, String opt, String arg) throws BadArgs { 63.200 + // -Xold is only supported as first arg when invoked from 63.201 + // command line; this is handled in Main,main 63.202 + throw task.new BadArgs("err.Xold.not.supported.here"); 63.203 + } 63.204 + }, 63.205 + 63.206 + new Option(false, "-Xnew") { 63.207 + void process(JavapTask task, String opt, String arg) throws BadArgs { 63.208 + // ignore: this _is_ the new version 63.209 + } 63.210 + }, 63.211 + 63.212 + new Option(false, "-XDcompat") { 63.213 + void process(JavapTask task, String opt, String arg) { 63.214 + task.options.compat = true; 63.215 + } 63.216 + }, 63.217 + 63.218 + new Option(false, "-XDjsr277") { 63.219 + void process(JavapTask task, String opt, String arg) { 63.220 + task.options.jsr277 = true; 63.221 + } 63.222 + }, 63.223 + 63.224 + new Option(false, "-XDignore.symbol.file") { 63.225 + void process(JavapTask task, String opt, String arg) { 63.226 + task.options.ignoreSymbolFile = true; 63.227 + } 63.228 + } 63.229 + 63.230 + }; 63.231 + 63.232 + JavapTask() { 63.233 + context = new Context(); 63.234 + options = Options.instance(context); 63.235 + } 63.236 + 63.237 + JavapTask(Writer out, 63.238 + JavaFileManager fileManager, 63.239 + DiagnosticListener<? super JavaFileObject> diagnosticListener, 63.240 + Iterable<String> options, 63.241 + Iterable<String> classes) { 63.242 + this(); 63.243 + this.log = getPrintWriterForWriter(out); 63.244 + this.fileManager = fileManager; 63.245 + this.diagnosticListener = diagnosticListener; 63.246 + 63.247 + try { 63.248 + handleOptions(options, false); 63.249 + } catch (BadArgs e) { 63.250 + throw new IllegalArgumentException(e.getMessage()); 63.251 + } 63.252 + 63.253 + this.classes = new ArrayList<String>(); 63.254 + for (String classname: classes) { 63.255 + classname.getClass(); // null-check 63.256 + this.classes.add(classname); 63.257 + } 63.258 + } 63.259 + 63.260 + public void setLocale(Locale locale) { 63.261 + if (locale == null) 63.262 + locale = Locale.getDefault(); 63.263 + task_locale = locale; 63.264 + } 63.265 + 63.266 + public void setLog(PrintWriter log) { 63.267 + this.log = log; 63.268 + } 63.269 + 63.270 + public void setLog(OutputStream s) { 63.271 + setLog(getPrintWriterForStream(s)); 63.272 + } 63.273 + 63.274 + private static PrintWriter getPrintWriterForStream(OutputStream s) { 63.275 + return new PrintWriter(s, true); 63.276 + } 63.277 + 63.278 + private static PrintWriter getPrintWriterForWriter(Writer w) { 63.279 + if (w == null) 63.280 + return getPrintWriterForStream(null); 63.281 + else if (w instanceof PrintWriter) 63.282 + return (PrintWriter) w; 63.283 + else 63.284 + return new PrintWriter(w, true); 63.285 + } 63.286 + 63.287 + public void setDiagnosticListener(DiagnosticListener<? super JavaFileObject> dl) { 63.288 + diagnosticListener = dl; 63.289 + } 63.290 + 63.291 + public void setDiagnosticListener(OutputStream s) { 63.292 + setDiagnosticListener(getDiagnosticListenerForStream(s)); 63.293 + } 63.294 + 63.295 + private DiagnosticListener<JavaFileObject> getDiagnosticListenerForStream(OutputStream s) { 63.296 + return getDiagnosticListenerForWriter(getPrintWriterForStream(s)); 63.297 + } 63.298 + 63.299 + private DiagnosticListener<JavaFileObject> getDiagnosticListenerForWriter(Writer w) { 63.300 + final PrintWriter pw = getPrintWriterForWriter(w); 63.301 + return new DiagnosticListener<JavaFileObject> () { 63.302 + public void report(Diagnostic<? extends JavaFileObject> diagnostic) { 63.303 + if (diagnostic.getKind() == Diagnostic.Kind.ERROR) { 63.304 + pw.print(getMessage("err.prefix")); 63.305 + pw.print(" "); 63.306 + } 63.307 + pw.println(diagnostic.getMessage(null)); 63.308 + } 63.309 + }; 63.310 + } 63.311 + 63.312 + int run(String[] args) { 63.313 + try { 63.314 + handleOptions(args); 63.315 + boolean ok = run(); 63.316 + return ok ? 0 : 1; 63.317 + } catch (BadArgs e) { 63.318 + diagnosticListener.report(createDiagnostic(e.key, e.args)); 63.319 + return 1; 63.320 + } catch (InternalError e) { 63.321 + Object[] e_args; 63.322 + if (e.getCause() == null) 63.323 + e_args = e.args; 63.324 + else { 63.325 + e_args = new Object[e.args.length + 1]; 63.326 + e_args[0] = e.getCause(); 63.327 + System.arraycopy(e.args, 0, e_args, 1, e.args.length); 63.328 + } 63.329 + diagnosticListener.report(createDiagnostic("err.internal.error", e_args)); 63.330 + return 1; 63.331 + } finally { 63.332 + log.flush(); 63.333 + } 63.334 + } 63.335 + 63.336 + public void handleOptions(String[] args) throws BadArgs { 63.337 + handleOptions(Arrays.asList(args), true); 63.338 + } 63.339 + 63.340 + private void handleOptions(Iterable<String> args, boolean allowClasses) throws BadArgs { 63.341 + if (log == null) { 63.342 + log = getPrintWriterForStream(System.out); 63.343 + if (diagnosticListener == null) 63.344 + diagnosticListener = getDiagnosticListenerForStream(System.err); 63.345 + } else { 63.346 + if (diagnosticListener == null) 63.347 + diagnosticListener = getDiagnosticListenerForWriter(log); 63.348 + } 63.349 + 63.350 + 63.351 + if (fileManager == null) 63.352 + fileManager = getDefaultFileManager(diagnosticListener, log); 63.353 + 63.354 + Iterator<String> iter = args.iterator(); 63.355 + if (!iter.hasNext()) 63.356 + options.help = true; 63.357 + 63.358 + while (iter.hasNext()) { 63.359 + String arg = iter.next(); 63.360 + if (arg.startsWith("-")) 63.361 + handleOption(arg, iter); 63.362 + else if (allowClasses) { 63.363 + if (classes == null) 63.364 + classes = new ArrayList<String>(); 63.365 + classes.add(arg); 63.366 + while (iter.hasNext()) 63.367 + classes.add(iter.next()); 63.368 + } else 63.369 + throw new BadArgs("err.unknown.option", arg).showUsage(true); 63.370 + } 63.371 + 63.372 + if (options.ignoreSymbolFile && fileManager instanceof JavapFileManager) 63.373 + ((JavapFileManager) fileManager).setIgnoreSymbolFile(true); 63.374 + 63.375 + if ((classes == null || classes.size() == 0) && 63.376 + !(options.help || options.version || options.fullVersion)) { 63.377 + throw new BadArgs("err.no.classes.specified"); 63.378 + } 63.379 + } 63.380 + 63.381 + private void handleOption(String name, Iterator<String> rest) throws BadArgs { 63.382 + for (Option o: recognizedOptions) { 63.383 + if (o.matches(name)) { 63.384 + if (o.hasArg) { 63.385 + if (rest.hasNext()) 63.386 + o.process(this, name, rest.next()); 63.387 + else 63.388 + throw new BadArgs("err.missing.arg", name).showUsage(true); 63.389 + } else 63.390 + o.process(this, name, null); 63.391 + 63.392 + if (o.ignoreRest()) { 63.393 + while (rest.hasNext()) 63.394 + rest.next(); 63.395 + } 63.396 + return; 63.397 + } 63.398 + } 63.399 + 63.400 + if (fileManager.handleOption(name, rest)) 63.401 + return; 63.402 + 63.403 + throw new BadArgs("err.unknown.option", name).showUsage(true); 63.404 + } 63.405 + 63.406 + public Boolean call() { 63.407 + return run(); 63.408 + } 63.409 + 63.410 + public boolean run() { 63.411 + if (options.help) 63.412 + showHelp(); 63.413 + 63.414 + if (options.version || options.fullVersion) 63.415 + showVersion(options.fullVersion); 63.416 + 63.417 + if (classes == null || classes.size() == 0) 63.418 + return true; 63.419 + 63.420 + context.put(PrintWriter.class, log); 63.421 + ClassWriter classWriter = ClassWriter.instance(context); 63.422 + 63.423 + boolean ok = true; 63.424 + 63.425 + for (String className: classes) { 63.426 + JavaFileObject fo; 63.427 + try { 63.428 + if (className.endsWith(".class")) { 63.429 + if (fileManager instanceof StandardJavaFileManager) { 63.430 + StandardJavaFileManager sfm = (StandardJavaFileManager) fileManager; 63.431 + fo = sfm.getJavaFileObjects(className).iterator().next(); 63.432 + } else { 63.433 + diagnosticListener.report(createDiagnostic("err.not.standard.file.manager", className)); 63.434 + ok = false; 63.435 + continue; 63.436 + } 63.437 + } else { 63.438 + fo = getClassFileObject(className); 63.439 + if (fo == null) { 63.440 + // see if it is an inner class, by replacing dots to $, starting from the right 63.441 + String cn = className; 63.442 + int lastDot; 63.443 + while (fo == null && (lastDot = cn.lastIndexOf(".")) != -1) { 63.444 + cn = cn.substring(0, lastDot) + "$" + cn.substring(lastDot + 1); 63.445 + fo = getClassFileObject(cn); 63.446 + } 63.447 + } 63.448 + if (fo == null) { 63.449 + diagnosticListener.report(createDiagnostic("err.class.not.found", className)); 63.450 + ok = false; 63.451 + continue; 63.452 + } 63.453 + } 63.454 + Attribute.Factory attributeFactory = new Attribute.Factory(); 63.455 + attributeFactory.setCompat(options.compat); 63.456 + attributeFactory.setJSR277(options.jsr277); 63.457 + ClassFile cf = ClassFile.read(fo.openInputStream(), attributeFactory); 63.458 + classWriter.write(cf); 63.459 + } catch (ConstantPoolException e) { 63.460 + diagnosticListener.report(createDiagnostic("err.bad.constant.pool", className, e.getLocalizedMessage())); 63.461 + ok = false; 63.462 + } catch (EOFException e) { 63.463 + diagnosticListener.report(createDiagnostic("err.end.of.file", className)); 63.464 + ok = false; 63.465 + } catch (FileNotFoundException e) { 63.466 + diagnosticListener.report(createDiagnostic("err.file.not.found", e.getLocalizedMessage())); 63.467 + ok = false; 63.468 + } catch (IOException e) { 63.469 + //e.printStackTrace(); 63.470 + Object msg = e.getLocalizedMessage(); 63.471 + if (msg == null) 63.472 + msg = e; 63.473 + diagnosticListener.report(createDiagnostic("err.ioerror", className, msg)); 63.474 + ok = false; 63.475 + } catch (Throwable t) { 63.476 + StringWriter sw = new StringWriter(); 63.477 + PrintWriter pw = new PrintWriter(sw); 63.478 + t.printStackTrace(pw); 63.479 + pw.close(); 63.480 + diagnosticListener.report(createDiagnostic("err.crash", t.toString(), sw.toString())); 63.481 + } 63.482 + } 63.483 + 63.484 + return ok; 63.485 + } 63.486 + 63.487 + private JavaFileManager getDefaultFileManager(final DiagnosticListener<? super JavaFileObject> dl, PrintWriter log) { 63.488 + return JavapFileManager.create(dl, log, options); 63.489 + } 63.490 + 63.491 + private JavaFileObject getClassFileObject(String className) throws IOException { 63.492 + JavaFileObject fo; 63.493 + fo = fileManager.getJavaFileForInput(StandardLocation.PLATFORM_CLASS_PATH, className, JavaFileObject.Kind.CLASS); 63.494 + if (fo == null) 63.495 + fo = fileManager.getJavaFileForInput(StandardLocation.CLASS_PATH, className, JavaFileObject.Kind.CLASS); 63.496 + return fo; 63.497 + } 63.498 + 63.499 + private void showHelp() { 63.500 + log.println(getMessage("main.usage", progname)); 63.501 + for (Option o: recognizedOptions) { 63.502 + String name = o.aliases[0].substring(1); // there must always be at least one name 63.503 + if (name.startsWith("X") || name.equals("fullversion") || name.equals("h") || name.equals("verify")) 63.504 + continue; 63.505 + log.println(getMessage("main.opt." + name)); 63.506 + } 63.507 + String[] fmOptions = { "-classpath", "-bootclasspath" }; 63.508 + for (String o: fmOptions) { 63.509 + if (fileManager.isSupportedOption(o) == -1) 63.510 + continue; 63.511 + String name = o.substring(1); 63.512 + log.println(getMessage("main.opt." + name)); 63.513 + } 63.514 + 63.515 + } 63.516 + 63.517 + private void showVersion(boolean full) { 63.518 + log.println(version(full ? "full" : "release")); 63.519 + } 63.520 + 63.521 + private static final String versionRBName = "com.sun.tools.javap.resources.version"; 63.522 + private static ResourceBundle versionRB; 63.523 + 63.524 + private String version(String key) { 63.525 + // key=version: mm.nn.oo[-milestone] 63.526 + // key=full: mm.mm.oo[-milestone]-build 63.527 + if (versionRB == null) { 63.528 + try { 63.529 + versionRB = ResourceBundle.getBundle(versionRBName); 63.530 + } catch (MissingResourceException e) { 63.531 + return getMessage("version.resource.missing", System.getProperty("java.version")); 63.532 + } 63.533 + } 63.534 + try { 63.535 + return versionRB.getString(key); 63.536 + } 63.537 + catch (MissingResourceException e) { 63.538 + return getMessage("version.unknown", System.getProperty("java.version")); 63.539 + } 63.540 + } 63.541 + 63.542 + private Diagnostic<JavaFileObject> createDiagnostic(final String key, final Object... args) { 63.543 + return new Diagnostic<JavaFileObject>() { 63.544 + public Kind getKind() { 63.545 + return Diagnostic.Kind.ERROR; 63.546 + } 63.547 + 63.548 + public JavaFileObject getSource() { 63.549 + return null; 63.550 + } 63.551 + 63.552 + public long getPosition() { 63.553 + return Diagnostic.NOPOS; 63.554 + } 63.555 + 63.556 + public long getStartPosition() { 63.557 + return Diagnostic.NOPOS; 63.558 + } 63.559 + 63.560 + public long getEndPosition() { 63.561 + return Diagnostic.NOPOS; 63.562 + } 63.563 + 63.564 + public long getLineNumber() { 63.565 + return Diagnostic.NOPOS; 63.566 + } 63.567 + 63.568 + public long getColumnNumber() { 63.569 + return Diagnostic.NOPOS; 63.570 + } 63.571 + 63.572 + public String getCode() { 63.573 + return key; 63.574 + } 63.575 + 63.576 + public String getMessage(Locale locale) { 63.577 + return JavapTask.this.getMessage(locale, key, args); 63.578 + } 63.579 + 63.580 + }; 63.581 + 63.582 + } 63.583 + 63.584 + private String getMessage(String key, Object... args) { 63.585 + return getMessage(task_locale, key, args); 63.586 + } 63.587 + 63.588 + private String getMessage(Locale locale, String key, Object... args) { 63.589 + if (bundles == null) { 63.590 + // could make this a HashMap<Locale,SoftReference<ResourceBundle>> 63.591 + // and for efficiency, keep a hard reference to the bundle for the task 63.592 + // locale 63.593 + bundles = new HashMap<Locale, ResourceBundle>(); 63.594 + } 63.595 + 63.596 + if (locale == null) 63.597 + locale = Locale.getDefault(); 63.598 + 63.599 + ResourceBundle b = bundles.get(locale); 63.600 + if (b == null) { 63.601 + try { 63.602 + b = ResourceBundle.getBundle("com.sun.tools.javap.resources.javap", locale); 63.603 + bundles.put(locale, b); 63.604 + } catch (MissingResourceException e) { 63.605 + throw new InternalError("Cannot find javap resource bundle for locale " + locale); 63.606 + } 63.607 + } 63.608 + 63.609 + try { 63.610 + return MessageFormat.format(b.getString(key), args); 63.611 + } catch (MissingResourceException e) { 63.612 + throw new InternalError(e, key); 63.613 + } 63.614 + } 63.615 + 63.616 + Context context; 63.617 + JavaFileManager fileManager; 63.618 + PrintWriter log; 63.619 + DiagnosticListener<? super JavaFileObject> diagnosticListener; 63.620 + List<String> classes; 63.621 + Options options; 63.622 + //ResourceBundle bundle; 63.623 + Locale task_locale; 63.624 + Map<Locale, ResourceBundle> bundles; 63.625 + 63.626 + private static final String progname = "javap"; 63.627 +}
64.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 64.2 +++ b/src/share/classes/com/sun/tools/javap/Main.java Tue Jun 03 13:26:47 2008 -0700 64.3 @@ -0,0 +1,68 @@ 64.4 +/* 64.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. 64.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 64.7 + * 64.8 + * This code is free software; you can redistribute it and/or modify it 64.9 + * under the terms of the GNU General Public License version 2 only, as 64.10 + * published by the Free Software Foundation. Sun designates this 64.11 + * particular file as subject to the "Classpath" exception as provided 64.12 + * by Sun in the LICENSE file that accompanied this code. 64.13 + * 64.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 64.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 64.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 64.17 + * version 2 for more details (a copy is included in the LICENSE file that 64.18 + * accompanied this code). 64.19 + * 64.20 + * You should have received a copy of the GNU General Public License version 64.21 + * 2 along with this work; if not, write to the Free Software Foundation, 64.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 64.23 + * 64.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 64.25 + * CA 95054 USA or visit www.sun.com if you need additional information or 64.26 + * have any questions. 64.27 + */ 64.28 + 64.29 +package com.sun.tools.javap; 64.30 + 64.31 +import java.io.PrintWriter; 64.32 + 64.33 +/** 64.34 + * Main entry point. 64.35 + * 64.36 + * <p><b>This is NOT part of any API supported by Sun Microsystems. If 64.37 + * you write code that depends on this, you do so at your own risk. 64.38 + * This code and its internal interfaces are subject to change or 64.39 + * deletion without notice.</b> 64.40 + */ 64.41 +public class Main { 64.42 + /** 64.43 + * Main entry point for the launcher. 64.44 + * Note: This method calls System.exit. 64.45 + * @param args command line arguments 64.46 + */ 64.47 + public static void main(String[] args) { 64.48 + if (args.length >= 1 && args[0].equals("-Xold")) { 64.49 + String[] nArgs = new String[args.length - 1]; 64.50 + System.arraycopy(args, 1, nArgs, 0, nArgs.length); 64.51 + sun.tools.javap.Main.main(args); // calls System.exit 64.52 + System.exit(1); 64.53 + } 64.54 + 64.55 + JavapTask t = new JavapTask(); 64.56 + int rc = t.run(args); 64.57 + System.exit(rc); 64.58 + } 64.59 + 64.60 + /** 64.61 + * Entry point that does <i>not</i> call System.exit. 64.62 + * @param args command line arguments 64.63 + * @param out output stream 64.64 + * @return an exit code. 0 means success, non-zero means an error occurred. 64.65 + */ 64.66 + public static int run(String[] args, PrintWriter out) { 64.67 + JavapTask t = new JavapTask(); 64.68 + t.setLog(out); 64.69 + return t.run(args); 64.70 + } 64.71 +}
65.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 65.2 +++ b/src/share/classes/com/sun/tools/javap/Options.java Tue Jun 03 13:26:47 2008 -0700 65.3 @@ -0,0 +1,84 @@ 65.4 +/* 65.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. 65.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 65.7 + * 65.8 + * This code is free software; you can redistribute it and/or modify it 65.9 + * under the terms of the GNU General Public License version 2 only, as 65.10 + * published by the Free Software Foundation. Sun designates this 65.11 + * particular file as subject to the "Classpath" exception as provided 65.12 + * by Sun in the LICENSE file that accompanied this code. 65.13 + * 65.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 65.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 65.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 65.17 + * version 2 for more details (a copy is included in the LICENSE file that 65.18 + * accompanied this code). 65.19 + * 65.20 + * You should have received a copy of the GNU General Public License version 65.21 + * 2 along with this work; if not, write to the Free Software Foundation, 65.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 65.23 + * 65.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 65.25 + * CA 95054 USA or visit www.sun.com if you need additional information or 65.26 + * have any questions. 65.27 + */ 65.28 + 65.29 +package com.sun.tools.javap; 65.30 + 65.31 +import com.sun.tools.classfile.AccessFlags; 65.32 + 65.33 +/* 65.34 + * Provides access to javap's options, set via the command line 65.35 + * or JSR 199 API. 65.36 + * <p><b>This is NOT part of any API supported by Sun Microsystems. If 65.37 + * you write code that depends on this, you do so at your own risk. 65.38 + * This code and its internal interfaces are subject to change or 65.39 + * deletion without notice.</b> 65.40 + */ 65.41 +public class Options { 65.42 + public static Options instance(Context context) { 65.43 + Options instance = context.get(Options.class); 65.44 + if (instance == null) 65.45 + instance = new Options(context); 65.46 + return instance; 65.47 + } 65.48 + 65.49 + protected Options(Context context) { 65.50 + context.put(Options.class, this); 65.51 + } 65.52 + 65.53 + /** 65.54 + * Checks access of class, field or method. 65.55 + */ 65.56 + public boolean checkAccess(AccessFlags flags){ 65.57 + 65.58 + boolean isPublic = flags.is(AccessFlags.ACC_PUBLIC); 65.59 + boolean isProtected = flags.is(AccessFlags.ACC_PROTECTED); 65.60 + boolean isPrivate = flags.is(AccessFlags.ACC_PRIVATE); 65.61 + boolean isPackage = !(isPublic || isProtected || isPrivate); 65.62 + 65.63 + if ((showAccess == AccessFlags.ACC_PUBLIC) && (isProtected || isPrivate || isPackage)) 65.64 + return false; 65.65 + else if ((showAccess == AccessFlags.ACC_PROTECTED) && (isPrivate || isPackage)) 65.66 + return false; 65.67 + else if ((showAccess == 0) && (isPrivate)) 65.68 + return false; 65.69 + else 65.70 + return true; 65.71 + } 65.72 + 65.73 + public boolean help; 65.74 + public boolean verbose; 65.75 + public boolean version; 65.76 + public boolean fullVersion; 65.77 + public boolean showFlags; 65.78 + public boolean showLineAndLocalVariableTables; 65.79 + public int showAccess; 65.80 + public boolean showDisassembled; 65.81 + public boolean showInternalSignatures; 65.82 + public boolean showAllAttrs; 65.83 + 65.84 + public boolean compat; // bug-for-bug compatibility mode with old javap 65.85 + public boolean jsr277; 65.86 + public boolean ignoreSymbolFile; // file manager should ignore ct.sym 65.87 +}
66.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 66.2 +++ b/src/share/classes/com/sun/tools/javap/overview.html Tue Jun 03 13:26:47 2008 -0700 66.3 @@ -0,0 +1,10 @@ 66.4 +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 66.5 +<html> 66.6 + <head> 66.7 + <title>javap: class file disassembler</title> 66.8 + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 66.9 + </head> 66.10 + <body> 66.11 + Javap is a class file disassembler. 66.12 + </body> 66.13 +</html>
67.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 67.2 +++ b/src/share/classes/com/sun/tools/javap/package.html Tue Jun 03 13:26:47 2008 -0700 67.3 @@ -0,0 +1,10 @@ 67.4 +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 67.5 +<html> 67.6 + <head> 67.7 + <title></title> 67.8 + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 67.9 + </head> 67.10 + <body> 67.11 + Classes to dump class files in text format. 67.12 + </body> 67.13 +</html>
68.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 68.2 +++ b/src/share/classes/com/sun/tools/javap/resources/javap.properties Tue Jun 03 13:26:47 2008 -0700 68.3 @@ -0,0 +1,62 @@ 68.4 + 68.5 +err.prefix=Error: 68.6 + 68.7 +err.bad.constant.pool=error while reading constant pool for {0}: {1} 68.8 +err.class.not.found=class not found: {0} 68.9 +err.crash=A serious internal error has occurred: {0}\nPlease file a bug report, and include the following information:\n{1} 68.10 +err.end.of.file=unexpected end of file while reading {0} 68.11 +err.file.not.found=file not found: {0} 68.12 +err.h.not.supported=-h is no longer available - use the 'javah' program 68.13 +err.internal.error=internal error: {0} {1} {2} 68.14 +err.ioerror=IO error reading {0}: {1} 68.15 +err.missing.arg=no value given for {0} 68.16 +err.no.classes.specified=no classes specified 68.17 +err.not.standard.file.manager=can only specify class files when using a standard file manager 68.18 +err.unknown.option=unknown option: {0} 68.19 +err.verify.not.supported=-verify not supported 68.20 +err.Xold.not.supported.here=-Xold must be given as the first option 68.21 + 68.22 +main.usage=\ 68.23 +Usage: {0} <options> <classes>\n\ 68.24 +where possible options include: 68.25 + 68.26 + 68.27 +main.opt.help=\ 68.28 +\ -help --help -? Print this usage message 68.29 + 68.30 +main.opt.version=\ 68.31 +\ -version Version information 68.32 + 68.33 +main.opt.v=\ 68.34 +\ -v -verbose Print additional information 68.35 + 68.36 +main.opt.l=\ 68.37 +\ -l Print line number and local variable tables 68.38 + 68.39 +main.opt.public=\ 68.40 +\ -public Show only public classes and members 68.41 + 68.42 +main.opt.protected=\ 68.43 +\ -protected Show protected/public classes and members 68.44 + 68.45 +main.opt.package=\ 68.46 +\ -package Show package/protected/public classes\n\ 68.47 +\ and members (default) 68.48 + 68.49 +main.opt.p=\ 68.50 +\ -p -private Show all classes and members 68.51 + 68.52 +main.opt.c=\ 68.53 +\ -c Disassemble the code 68.54 + 68.55 +main.opt.s=\ 68.56 +\ -s Print internal type signatures 68.57 + 68.58 +main.opt.classpath=\ 68.59 +\ -classpath <path> Specify where to find user class files 68.60 + 68.61 +main.opt.bootclasspath=\ 68.62 +\ -bootclasspath <path> Override location of bootstrap class files 68.63 + 68.64 + 68.65 +
69.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 69.2 +++ b/src/share/classes/com/sun/tools/javap/resources/version.properties-template Tue Jun 03 13:26:47 2008 -0700 69.3 @@ -0,0 +1,28 @@ 69.4 +# 69.5 +# Copyright 2007-2008 Sun Microsystems, Inc. All Rights Reserved. 69.6 +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 69.7 +# 69.8 +# This code is free software; you can redistribute it and/or modify it 69.9 +# under the terms of the GNU General Public License version 2 only, as 69.10 +# published by the Free Software Foundation. Sun designates this 69.11 +# particular file as subject to the "Classpath" exception as provided 69.12 +# by Sun in the LICENSE file that accompanied this code. 69.13 +# 69.14 +# This code is distributed in the hope that it will be useful, but WITHOUT 69.15 +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 69.16 +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 69.17 +# version 2 for more details (a copy is included in the LICENSE file that 69.18 +# accompanied this code). 69.19 +# 69.20 +# You should have received a copy of the GNU General Public License version 69.21 +# 2 along with this work; if not, write to the Free Software Foundation, 69.22 +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 69.23 +# 69.24 +# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 69.25 +# CA 95054 USA or visit www.sun.com if you need additional information or 69.26 +# have any questions. 69.27 +# 69.28 + 69.29 +jdk=$(JDK_VERSION) 69.30 +full=$(FULL_VERSION) 69.31 +release=$(RELEASE)
70.1 --- a/src/share/classes/sun/tools/javap/Main.java Fri May 30 11:08:40 2008 +0100 70.2 +++ b/src/share/classes/sun/tools/javap/Main.java Tue Jun 03 13:26:47 2008 -0700 70.3 @@ -49,6 +49,12 @@ 70.4 } 70.5 70.6 public static void main(String argv[]) { 70.7 + // unless first arg is -Xold, use new javap 70.8 + if (!(argv.length >= 1 && argv[0].equals("-Xold"))) { 70.9 + com.sun.tools.javap.Main.main(argv); 70.10 + return; 70.11 + } 70.12 + 70.13 entry(argv); 70.14 if (errorOccurred) { 70.15 System.exit(1); 70.16 @@ -178,6 +184,8 @@ 70.17 } 70.18 } else if (arg.equals("-all")) { 70.19 env.showallAttr = true; 70.20 + } else if (arg.equals("-Xold")) { 70.21 + // ignore: this is old javap 70.22 } else { 70.23 error("invalid flag: " + arg); 70.24 usage();
71.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 71.2 +++ b/test/tools/javap/4870651/T4870651.java Tue Jun 03 13:26:47 2008 -0700 71.3 @@ -0,0 +1,81 @@ 71.4 +/* 71.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. 71.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 71.7 + * 71.8 + * This code is free software; you can redistribute it and/or modify it 71.9 + * under the terms of the GNU General Public License version 2 only, as 71.10 + * published by the Free Software Foundation. 71.11 + * 71.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 71.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 71.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 71.15 + * version 2 for more details (a copy is included in the LICENSE file that 71.16 + * accompanied this code). 71.17 + * 71.18 + * You should have received a copy of the GNU General Public License version 71.19 + * 2 along with this work; if not, write to the Free Software Foundation, 71.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 71.21 + * 71.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 71.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 71.24 + * have any questions. 71.25 + */ 71.26 + 71.27 +/* 71.28 + * @test 71.29 + * @bug 4870651 71.30 + * @summary javap should recognize generics, varargs, enum 71.31 + * @build T4870651 Test 71.32 + * @run main T4870651 71.33 + */ 71.34 + 71.35 +import java.io.*; 71.36 + 71.37 +public class T4870651 { 71.38 + public static void main(String[] args) throws Exception { 71.39 + new T4870651().run(); 71.40 + } 71.41 + 71.42 + public void run() throws IOException { 71.43 + verify("Test", 71.44 + "class Test<T, E extends java.lang.Exception & java.lang.Comparable<T>, U extends java.lang.Comparable>", 71.45 + "v1(java.lang.String...)"); 71.46 + 71.47 + verify("Test$Enum", 71.48 + "flags: ACC_FINAL, ACC_SUPER, ACC_ENUM", 71.49 + "flags: ACC_PUBLIC, ACC_STATIC, ACC_FINAL, ACC_ENUM"); 71.50 + 71.51 + if (errors > 0) 71.52 + throw new Error(errors + " found."); 71.53 + } 71.54 + 71.55 + String javap(String className) { 71.56 + String testClasses = System.getProperty("test.classes", "."); 71.57 + StringWriter sw = new StringWriter(); 71.58 + PrintWriter out = new PrintWriter(sw); 71.59 + String[] args = { "-classpath", testClasses, "-v", className }; 71.60 + int rc = com.sun.tools.javap.Main.run(args, out); 71.61 + if (rc != 0) 71.62 + throw new Error("javap failed. rc=" + rc); 71.63 + out.close(); 71.64 + String output = sw.toString(); 71.65 + System.out.println("class " + className); 71.66 + System.out.println(output); 71.67 + return output; 71.68 + } 71.69 + 71.70 + void verify(String className, String... expects) { 71.71 + String output = javap(className); 71.72 + for (String expect: expects) { 71.73 + if (output.indexOf(expect)< 0) 71.74 + error(expect + " not found"); 71.75 + } 71.76 + } 71.77 + 71.78 + void error(String msg) { 71.79 + System.err.println(msg); 71.80 + errors++; 71.81 + } 71.82 + 71.83 + int errors; 71.84 +}
72.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 72.2 +++ b/test/tools/javap/4870651/Test.java Tue Jun 03 13:26:47 2008 -0700 72.3 @@ -0,0 +1,76 @@ 72.4 +/* 72.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. 72.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 72.7 + * 72.8 + * This code is free software; you can redistribute it and/or modify it 72.9 + * under the terms of the GNU General Public License version 2 only, as 72.10 + * published by the Free Software Foundation. 72.11 + * 72.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 72.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 72.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 72.15 + * version 2 for more details (a copy is included in the LICENSE file that 72.16 + * accompanied this code). 72.17 + * 72.18 + * You should have received a copy of the GNU General Public License version 72.19 + * 2 along with this work; if not, write to the Free Software Foundation, 72.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 72.21 + * 72.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 72.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 72.24 + * have any questions. 72.25 + */ 72.26 + 72.27 +import java.util.*; 72.28 + 72.29 +abstract class Test<T,E extends Exception & Comparable<T>,U extends Comparable> { 72.30 + T t; 72.31 + 72.32 + Test(T t) { } 72.33 + <G> Test(G g, int i) { } 72.34 + 72.35 + Test(String... args) { } 72.36 + Test(int i, Object[]... args) { } 72.37 + abstract void v1(String... args); 72.38 + abstract void v2(int i, String[]... args); 72.39 + 72.40 + abstract void a1(int x); 72.41 + abstract void a2(int[] x); 72.42 + abstract void a3(T x); 72.43 + abstract void a4(T[] x); 72.44 + 72.45 + abstract int r1(); 72.46 + abstract int[] r2(); 72.47 + abstract T r3(); 72.48 + abstract T[] r4(); 72.49 + 72.50 + abstract <G> void ga1(int x); 72.51 + abstract <G> void ga2(int[] x); 72.52 + abstract <G> void ga3(G x); 72.53 + abstract <G> void ga4(G[] x); 72.54 + 72.55 + abstract <G> int gr1(); 72.56 + abstract <G> int[] gr2(); 72.57 + abstract <G> G gr3(); 72.58 + abstract <G> G[] gr4(); 72.59 + 72.60 + abstract <G extends Exception> void ge() throws G; 72.61 + 72.62 + abstract void w(List<?> l); 72.63 + abstract void we(List<? extends T> l); 72.64 + abstract void ws(List<? super T> l); 72.65 + 72.66 + abstract void t1() throws Error; 72.67 + abstract void t2() throws E; 72.68 + abstract void t3() throws E,Error; 72.69 + 72.70 + abstract void i1(Test<T, E, Comparable> x); 72.71 + abstract void i3(Test<T, E, Comparable>.Inner<String> x); 72.72 + 72.73 + class Inner<Q> { } 72.74 + class Inner2<Q> extends Inner<Q> { } 72.75 + 72.76 + class Simple { } 72.77 + 72.78 + enum Enum { e1, e2, e3 } 72.79 +}
73.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 73.2 +++ b/test/tools/javap/ListTest.java Tue Jun 03 13:26:47 2008 -0700 73.3 @@ -0,0 +1,147 @@ 73.4 +/* 73.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. 73.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 73.7 + * 73.8 + * This code is free software; you can redistribute it and/or modify it 73.9 + * under the terms of the GNU General Public License version 2 only, as 73.10 + * published by the Free Software Foundation. 73.11 + * 73.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 73.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 73.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 73.15 + * version 2 for more details (a copy is included in the LICENSE file that 73.16 + * accompanied this code). 73.17 + * 73.18 + * You should have received a copy of the GNU General Public License version 73.19 + * 2 along with this work; if not, write to the Free Software Foundation, 73.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 73.21 + * 73.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 73.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 73.24 + * have any questions. 73.25 + */ 73.26 + 73.27 +import java.io.*; 73.28 +import java.util.*; 73.29 +import javax.tools.*; 73.30 + 73.31 +/* 73.32 + * @test 73.33 + * @bug 6439940 73.34 + * @summary Cleanup javap implementation 73.35 + * @run main/othervm ListTest 73.36 + */ 73.37 +public class ListTest { 73.38 + public static void main(String[] args) throws Exception { 73.39 + new ListTest().run(); 73.40 + } 73.41 + 73.42 + ListTest() { 73.43 + String v = System.getProperty("view.cmd"); 73.44 + // v = "/opt/teamware/7.7/bin/filemerge -r"; 73.45 + if (v != null) { 73.46 + viewResults = true; 73.47 + viewCmd = Arrays.asList(v.split(" +")); 73.48 + } 73.49 + } 73.50 + 73.51 + void run() throws Exception { 73.52 + StandardLocation[] locs = new StandardLocation[] { 73.53 + StandardLocation.PLATFORM_CLASS_PATH, 73.54 + StandardLocation.CLASS_PATH, 73.55 + }; 73.56 + 73.57 + int count = 0; 73.58 + int pass = 0; 73.59 + for (StandardLocation loc: locs) { 73.60 + for (String testClassName: list(loc)) { 73.61 + count++; 73.62 + if (test(testClassName)) 73.63 + pass++; 73.64 + } 73.65 + } 73.66 + 73.67 + if (pass < count) 73.68 + throw new Error(pass + "/" + count + " test cases passed"); 73.69 + } 73.70 + 73.71 + Iterable<String> list(StandardLocation loc) throws IOException { 73.72 + JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); 73.73 + StandardJavaFileManager sfm = compiler.getStandardFileManager(null, null, null); 73.74 + Set<JavaFileObject.Kind> kinds = Collections.singleton(JavaFileObject.Kind.CLASS); 73.75 + 73.76 + List<String> list = new ArrayList<String>(); 73.77 + for (JavaFileObject fo: sfm.list(loc, testPackage, kinds, true)) { 73.78 + //System.err.println(com.sun.tools.javac.util.Old199.getPath(fo)); 73.79 + list.add(sfm.inferBinaryName(loc, fo)); 73.80 + } 73.81 + return list; 73.82 + } 73.83 + 73.84 + boolean test(String testClassName) throws Exception { 73.85 + String[] args = new String[options.size() + 1]; 73.86 + options.toArray(args); 73.87 + args[args.length - 1] = testClassName; 73.88 + String oldOut = runOldJavap(args); 73.89 + String newOut = runNewJavap(args); 73.90 + boolean ok = oldOut.equals(newOut); 73.91 + System.err.println((ok ? "pass" : "FAIL") + ": " + testClassName); 73.92 + if (!ok && viewResults) 73.93 + view(oldOut, newOut); 73.94 + return ok; 73.95 + } 73.96 + 73.97 + String runOldJavap(String[] args) { 73.98 + //System.err.println("OLD: " + Arrays.asList(args)); 73.99 + PrintStream oldOut = System.out; 73.100 + ByteArrayOutputStream out = new ByteArrayOutputStream(); 73.101 + System.setOut(new PrintStream(out)); 73.102 + try { 73.103 + sun.tools.javap.Main.entry(args); 73.104 + } finally { 73.105 + System.setOut(oldOut); 73.106 + } 73.107 + return out.toString(); 73.108 + } 73.109 + 73.110 + String runNewJavap(String[] args) { 73.111 + String[] nArgs = new String[args.length + 2]; 73.112 + nArgs[0] = "-XDcompat"; 73.113 + nArgs[1] = "-XDignore.symbol.file"; 73.114 + System.arraycopy(args, 0, nArgs, 2, args.length); 73.115 + //System.err.println("NEW: " + Arrays.asList(nArgs)); 73.116 + StringWriter out = new StringWriter(); 73.117 + com.sun.tools.javap.Main.run(nArgs, new PrintWriter(out, true)); 73.118 + return out.toString(); 73.119 + } 73.120 + 73.121 + File write(String text, String suffix) throws IOException { 73.122 + File f = File.createTempFile("ListTest", suffix); 73.123 + FileWriter out = new FileWriter(f); 73.124 + out.write(text); 73.125 + out.close(); 73.126 + return f; 73.127 + } 73.128 + 73.129 + void view(String oldOut, String newOut) throws Exception { 73.130 + File oldFile = write(oldOut, "old"); 73.131 + File newFile = write(newOut, "new"); 73.132 + List<String> cmd = new ArrayList<String>(); 73.133 + cmd.addAll(viewCmd); 73.134 + cmd.add(oldFile.getPath()); 73.135 + cmd.add(newFile.getPath()); 73.136 + Process p = new ProcessBuilder(cmd).redirectErrorStream(true).start(); 73.137 + p.getOutputStream().close(); 73.138 + String line; 73.139 + BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream())); 73.140 + while ((line = in.readLine()) != null) 73.141 + System.err.println(line); 73.142 + in.close(); 73.143 + p.waitFor(); 73.144 + } 73.145 + 73.146 + String testPackage = "java.lang"; 73.147 + List<String> options = Arrays.asList("-v"); 73.148 + boolean viewResults; 73.149 + List<String> viewCmd; 73.150 +}
74.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 74.2 +++ b/test/tools/javap/OptionTest.java Tue Jun 03 13:26:47 2008 -0700 74.3 @@ -0,0 +1,143 @@ 74.4 +/* 74.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. 74.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 74.7 + * 74.8 + * This code is free software; you can redistribute it and/or modify it 74.9 + * under the terms of the GNU General Public License version 2 only, as 74.10 + * published by the Free Software Foundation. 74.11 + * 74.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 74.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 74.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 74.15 + * version 2 for more details (a copy is included in the LICENSE file that 74.16 + * accompanied this code). 74.17 + * 74.18 + * You should have received a copy of the GNU General Public License version 74.19 + * 2 along with this work; if not, write to the Free Software Foundation, 74.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 74.21 + * 74.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 74.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 74.24 + * have any questions. 74.25 + */ 74.26 + 74.27 +import java.io.*; 74.28 +import java.util.*; 74.29 + 74.30 +/* 74.31 + * @test 74.32 + * @bug 6439940 74.33 + * @summary Cleanup javap implementation 74.34 + * @run main/othervm OptionTest 74.35 + */ 74.36 +public class OptionTest { 74.37 + public static void main(String[] args) throws Exception { 74.38 + new OptionTest().run(); 74.39 + } 74.40 + 74.41 + OptionTest() { 74.42 + String v = System.getProperty("view.cmd"); 74.43 + if (v != null) { 74.44 + viewResults = true; 74.45 + viewCmd = Arrays.asList(v.split(" +")); 74.46 + } 74.47 + } 74.48 + 74.49 + 74.50 + void run() throws Exception { 74.51 + int count = 0; 74.52 + int pass = 0; 74.53 + // try combinations of options and compare old javap against new javap 74.54 + for (int i = 0; i < (1<<8); i++) { 74.55 + List<String> options = new ArrayList<String>(); 74.56 + if ((i & 0x01) != 0) 74.57 + options.add("-c"); 74.58 + if ((i & 0x02) != 0) 74.59 + options.add("-l"); 74.60 + if ((i & 0x04) != 0) 74.61 + options.add("-public"); 74.62 + if ((i & 0x08) != 0) 74.63 + options.add("-protected"); 74.64 + if ((i & 0x10) != 0) 74.65 + options.add("-package"); 74.66 + if ((i & 0x20) != 0) 74.67 + options.add("-private"); 74.68 + if ((i & 0x40) != 0) 74.69 + options.add("-s"); 74.70 + if ((i & 0x80) != 0) 74.71 + options.add("-verbose"); 74.72 + count++; 74.73 + if (test(options)) 74.74 + pass++; 74.75 + } 74.76 + 74.77 + if (pass < count) 74.78 + throw new Error(pass + "/" + count + " test cases passed"); 74.79 + } 74.80 + 74.81 + boolean test(List<String> options) throws Exception { 74.82 + String[] args = new String[options.size() + 1]; 74.83 + options.toArray(args); 74.84 + args[args.length - 1] = testClassName; 74.85 + String oldOut = runOldJavap(args); 74.86 + String newOut = runNewJavap(args); 74.87 + boolean ok = oldOut.equals(newOut); 74.88 + System.err.println((ok ? "pass" : "FAIL") + ": " + options); 74.89 + if (!ok && viewResults) 74.90 + view(oldOut, newOut); 74.91 + return ok; 74.92 + } 74.93 + 74.94 + String runOldJavap(String[] args) { 74.95 + //System.err.println("OLD: " + Arrays.asList(args)); 74.96 + PrintStream oldOut = System.out; 74.97 + ByteArrayOutputStream out = new ByteArrayOutputStream(); 74.98 + System.setOut(new PrintStream(out)); 74.99 + try { 74.100 + sun.tools.javap.Main.entry(args); 74.101 + } finally { 74.102 + System.setOut(oldOut); 74.103 + } 74.104 + return out.toString(); 74.105 + } 74.106 + 74.107 + String runNewJavap(String[] args) { 74.108 + String[] nArgs = new String[args.length + 2]; 74.109 + nArgs[0] = "-XDcompat"; 74.110 + nArgs[1] = "-XDignore.symbol.file"; 74.111 + System.arraycopy(args, 0, nArgs, 2, args.length); 74.112 + //System.err.println("NEW: " + Arrays.asList(nArgs)); 74.113 + StringWriter out = new StringWriter(); 74.114 + com.sun.tools.javap.Main.run(nArgs, new PrintWriter(out, true)); 74.115 + return out.toString(); 74.116 + } 74.117 + 74.118 + File write(String text, String suffix) throws IOException { 74.119 + File f = File.createTempFile("OptionTest", suffix); 74.120 + FileWriter out = new FileWriter(f); 74.121 + out.write(text); 74.122 + out.close(); 74.123 + return f; 74.124 + } 74.125 + 74.126 + void view(String oldOut, String newOut) throws Exception { 74.127 + File oldFile = write(oldOut, "old"); 74.128 + File newFile = write(newOut, "new"); 74.129 + List<String> cmd = new ArrayList<String>(); 74.130 + cmd.addAll(viewCmd); 74.131 + cmd.add(oldFile.getPath()); 74.132 + cmd.add(newFile.getPath()); 74.133 + Process p = new ProcessBuilder(cmd).redirectErrorStream(true).start(); 74.134 + p.getOutputStream().close(); 74.135 + String line; 74.136 + BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream())); 74.137 + while ((line = in.readLine()) != null) 74.138 + System.err.println(line); 74.139 + in.close(); 74.140 + p.waitFor(); 74.141 + } 74.142 + 74.143 + String testClassName = "java.lang.SecurityManager"; 74.144 + boolean viewResults; 74.145 + List<String> viewCmd; 74.146 +}
75.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 75.2 +++ b/test/tools/javap/T4075403.java Tue Jun 03 13:26:47 2008 -0700 75.3 @@ -0,0 +1,73 @@ 75.4 +/* 75.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. 75.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 75.7 + * 75.8 + * This code is free software; you can redistribute it and/or modify it 75.9 + * under the terms of the GNU General Public License version 2 only, as 75.10 + * published by the Free Software Foundation. 75.11 + * 75.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 75.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 75.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 75.15 + * version 2 for more details (a copy is included in the LICENSE file that 75.16 + * accompanied this code). 75.17 + * 75.18 + * You should have received a copy of the GNU General Public License version 75.19 + * 2 along with this work; if not, write to the Free Software Foundation, 75.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 75.21 + * 75.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 75.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 75.24 + * have any questions. 75.25 + */ 75.26 + 75.27 +/* 75.28 + * @test 75.29 + * @bug 4075403 75.30 + * @summary Use javap to inquire about a specific inner class 75.31 + */ 75.32 + 75.33 + 75.34 +import java.io.*; 75.35 + 75.36 +public class T4075403 { 75.37 + public static void main(String[] args) throws Exception { 75.38 + new T4075403().run(); 75.39 + } 75.40 + 75.41 + public void run() throws IOException { 75.42 + 75.43 + File javaFile = writeTestFile(); 75.44 + File classFile = compileTestFile(javaFile); 75.45 + javap("Outer.Inner"); 75.46 + } 75.47 + 75.48 + File writeTestFile() throws IOException { 75.49 + File f = new File("Outer.java"); 75.50 + PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(f))); 75.51 + out.println("class Outer { "); 75.52 + out.println(" class Inner { }"); 75.53 + out.println("}"); 75.54 + out.close(); 75.55 + return f; 75.56 + } 75.57 + 75.58 + File compileTestFile(File f) { 75.59 + int rc = com.sun.tools.javac.Main.compile(new String[] { "-g", f.getPath() }); 75.60 + if (rc != 0) 75.61 + throw new Error("compilation failed. rc=" + rc); 75.62 + String path = f.getPath(); 75.63 + return new File(path.substring(0, path.length() - 5) + ".class"); 75.64 + } 75.65 + 75.66 + String javap(String className) { 75.67 + StringWriter sw = new StringWriter(); 75.68 + PrintWriter out = new PrintWriter(sw); 75.69 + int rc = com.sun.tools.javap.Main.run(new String[] { "-classpath", ".", className }, out); 75.70 + if (rc != 0) 75.71 + throw new Error("javap failed. rc=" + rc); 75.72 + out.close(); 75.73 + System.out.println(sw.toString()); 75.74 + return sw.toString(); 75.75 + } 75.76 +}
76.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 76.2 +++ b/test/tools/javap/T4459541.java Tue Jun 03 13:26:47 2008 -0700 76.3 @@ -0,0 +1,112 @@ 76.4 +/* 76.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. 76.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 76.7 + * 76.8 + * This code is free software; you can redistribute it and/or modify it 76.9 + * under the terms of the GNU General Public License version 2 only, as 76.10 + * published by the Free Software Foundation. 76.11 + * 76.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 76.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 76.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 76.15 + * version 2 for more details (a copy is included in the LICENSE file that 76.16 + * accompanied this code). 76.17 + * 76.18 + * You should have received a copy of the GNU General Public License version 76.19 + * 2 along with this work; if not, write to the Free Software Foundation, 76.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 76.21 + * 76.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 76.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 76.24 + * have any questions. 76.25 + */ 76.26 + 76.27 +/* 76.28 + * @test 76.29 + * @bug 4459541 76.30 + * @summary "javap -l" shows line numbers as signed short; they should be unsigned. 76.31 + */ 76.32 + 76.33 +import java.io.*; 76.34 + 76.35 +public class T4459541 { 76.36 + public static void main(String[] args) throws Exception { 76.37 + new T4459541().run(); 76.38 + } 76.39 + 76.40 + public void run() throws IOException { 76.41 + File javaFile = writeTestFile(); 76.42 + File classFile = compileTestFile(javaFile); 76.43 + String output = javap(classFile); 76.44 + verify(output); 76.45 + } 76.46 + 76.47 + File writeTestFile() throws IOException { 76.48 + File f = new File("Test.java"); 76.49 + out = new PrintWriter(new BufferedWriter(new FileWriter(f))); 76.50 + println("class Test {"); 76.51 + println("void begin(int i) {"); 76.52 + println("i++;"); 76.53 + println("i++;"); 76.54 + println("}"); 76.55 + while (line < 32750) 76.56 + println("// " + line); 76.57 + println("void before_32767(int i) {"); 76.58 + println("i++;"); 76.59 + println("i++;"); 76.60 + println("}"); 76.61 + while (line < 32768-4) 76.62 + println("// " + line); 76.63 + println("void straddle_32768(int i) {"); 76.64 + while (line < 32768+4) 76.65 + println("i++;"); 76.66 + println("}"); 76.67 + while (line < 65520) 76.68 + println("// " + line); 76.69 + println("void between_32768_and_65536(int i) {"); 76.70 + println("i++;"); 76.71 + println("i++;"); 76.72 + println("}"); 76.73 + while (line < 65536-4) 76.74 + println("// " + line); 76.75 + println("void straddle_65536(int i) {"); 76.76 + while (line < 65536+4) 76.77 + println("i++;"); 76.78 + println("}"); 76.79 + println("}"); 76.80 + out.close(); 76.81 + return f; 76.82 + } 76.83 + 76.84 + File compileTestFile(File f) { 76.85 + int rc = com.sun.tools.javac.Main.compile(new String[] { f.getPath() }); 76.86 + if (rc != 0) 76.87 + throw new Error("compilation failed. rc=" + rc); 76.88 + String path = f.getPath(); 76.89 + return new File(path.substring(0, path.length() - 5) + ".class"); 76.90 + } 76.91 + 76.92 + String javap(File f) { 76.93 + StringWriter sw = new StringWriter(); 76.94 + PrintWriter out = new PrintWriter(sw); 76.95 + int rc = com.sun.tools.javap.Main.run(new String[] { "-l", f.getPath() }, out); 76.96 + if (rc != 0) 76.97 + throw new Error("javap failed. rc=" + rc); 76.98 + out.close(); 76.99 + return sw.toString(); 76.100 + } 76.101 + 76.102 + void verify(String output) { 76.103 + System.out.println(output); 76.104 + if (output.indexOf("-") >= 0) 76.105 + throw new Error("- found in output"); 76.106 + } 76.107 + 76.108 + void println(String text) { 76.109 + out.println(text); 76.110 + line++; 76.111 + } 76.112 + 76.113 + PrintWriter out; 76.114 + int line = 1; 76.115 +}
77.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 77.2 +++ b/test/tools/javap/T4501660.java Tue Jun 03 13:26:47 2008 -0700 77.3 @@ -0,0 +1,76 @@ 77.4 +/* 77.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. 77.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 77.7 + * 77.8 + * This code is free software; you can redistribute it and/or modify it 77.9 + * under the terms of the GNU General Public License version 2 only, as 77.10 + * published by the Free Software Foundation. 77.11 + * 77.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 77.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 77.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 77.15 + * version 2 for more details (a copy is included in the LICENSE file that 77.16 + * accompanied this code). 77.17 + * 77.18 + * You should have received a copy of the GNU General Public License version 77.19 + * 2 along with this work; if not, write to the Free Software Foundation, 77.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 77.21 + * 77.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 77.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 77.24 + * have any questions. 77.25 + */ 77.26 + 77.27 +/* 77.28 + * @test 77.29 + * @bug 4501660 77.30 + * @summary change diagnostic of -help as 'print this help message and exit' 77.31 + * (actually, verify -help does not cause premature exit) 77.32 + */ 77.33 + 77.34 +import java.io.*; 77.35 +import java.util.zip.*; 77.36 + 77.37 +public class T4501660 { 77.38 + public static void main(String[] args) throws Exception { 77.39 + new T4501660().run(); 77.40 + } 77.41 + 77.42 + public void run() throws IOException { 77.43 + String testClasses = System.getProperty("test.classes", "."); 77.44 + String output = javap("-classpath", testClasses, "-help", "T4501660"); 77.45 + verify(output, 77.46 + "-public", "-protected", "-private", // check -help output is present 77.47 + "class T4501660" // check class output is present 77.48 + ); 77.49 + 77.50 + if (errors > 0) 77.51 + throw new Error(errors + " found."); 77.52 + } 77.53 + 77.54 + String javap(String... args) { 77.55 + StringWriter sw = new StringWriter(); 77.56 + PrintWriter out = new PrintWriter(sw); 77.57 + //sun.tools.javap.Main.entry(args); 77.58 + int rc = com.sun.tools.javap.Main.run(args, out); 77.59 + if (rc != 0) 77.60 + throw new Error("javap failed. rc=" + rc); 77.61 + out.close(); 77.62 + System.out.println(sw); 77.63 + return sw.toString(); 77.64 + } 77.65 + 77.66 + void verify(String output, String... expects) { 77.67 + for (String expect: expects) { 77.68 + if (output.indexOf(expect)< 0) 77.69 + error(expect + " not found"); 77.70 + } 77.71 + } 77.72 + 77.73 + void error(String msg) { 77.74 + System.err.println(msg); 77.75 + errors++; 77.76 + } 77.77 + 77.78 + int errors; 77.79 +}
78.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 78.2 +++ b/test/tools/javap/T4876942.java Tue Jun 03 13:26:47 2008 -0700 78.3 @@ -0,0 +1,70 @@ 78.4 +/* 78.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. 78.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 78.7 + * 78.8 + * This code is free software; you can redistribute it and/or modify it 78.9 + * under the terms of the GNU General Public License version 2 only, as 78.10 + * published by the Free Software Foundation. 78.11 + * 78.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 78.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 78.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 78.15 + * version 2 for more details (a copy is included in the LICENSE file that 78.16 + * accompanied this code). 78.17 + * 78.18 + * You should have received a copy of the GNU General Public License version 78.19 + * 2 along with this work; if not, write to the Free Software Foundation, 78.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 78.21 + * 78.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 78.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 78.24 + * have any questions. 78.25 + */ 78.26 + 78.27 +/* 78.28 + * @test 78.29 + * @bug 4876942 78.30 + * @summary javap invoked without args does not print help screen 78.31 + */ 78.32 + 78.33 +import java.io.*; 78.34 +import java.util.zip.*; 78.35 + 78.36 +public class T4876942 { 78.37 + public static void main(String[] args) throws Exception { 78.38 + new T4876942().run(); 78.39 + } 78.40 + 78.41 + public void run() throws IOException { 78.42 + String output = javap(); 78.43 + verify(output, "-public", "-protected", "-private"); // check that some of the options are listed 78.44 + 78.45 + if (errors > 0) 78.46 + throw new Error(errors + " found."); 78.47 + } 78.48 + 78.49 + String javap(String... args) { 78.50 + StringWriter sw = new StringWriter(); 78.51 + PrintWriter out = new PrintWriter(sw); 78.52 + //sun.tools.javap.Main.entry(args); 78.53 + int rc = com.sun.tools.javap.Main.run(args, out); 78.54 + if (rc != 0) 78.55 + throw new Error("javap failed. rc=" + rc); 78.56 + out.close(); 78.57 + return sw.toString(); 78.58 + } 78.59 + 78.60 + void verify(String output, String... expects) { 78.61 + for (String expect: expects) { 78.62 + if (output.indexOf(expect)< 0) 78.63 + error(expect + " not found"); 78.64 + } 78.65 + } 78.66 + 78.67 + void error(String msg) { 78.68 + System.err.println(msg); 78.69 + errors++; 78.70 + } 78.71 + 78.72 + int errors; 78.73 +}
79.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 79.2 +++ b/test/tools/javap/T4880663.java Tue Jun 03 13:26:47 2008 -0700 79.3 @@ -0,0 +1,88 @@ 79.4 +/* 79.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. 79.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 79.7 + * 79.8 + * This code is free software; you can redistribute it and/or modify it 79.9 + * under the terms of the GNU General Public License version 2 only, as 79.10 + * published by the Free Software Foundation. 79.11 + * 79.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 79.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 79.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 79.15 + * version 2 for more details (a copy is included in the LICENSE file that 79.16 + * accompanied this code). 79.17 + * 79.18 + * You should have received a copy of the GNU General Public License version 79.19 + * 2 along with this work; if not, write to the Free Software Foundation, 79.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 79.21 + * 79.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 79.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 79.24 + * have any questions. 79.25 + */ 79.26 + 79.27 +/* 79.28 + * @test 79.29 + * @bug 4880663 79.30 + * @summary javap could output whitespace between class name and opening brace 79.31 + */ 79.32 + 79.33 + 79.34 +import java.io.*; 79.35 + 79.36 +public class T4880663 { 79.37 + public static void main(String[] args) throws Exception { 79.38 + new T4880663().run(); 79.39 + } 79.40 + 79.41 + public void run() throws IOException { 79.42 + File javaFile = writeTestFile(); 79.43 + File classFile = compileTestFile(javaFile); 79.44 + verify(classFile, "class Test {"); 79.45 + 79.46 + if (errors > 0) 79.47 + throw new Error(errors + " found."); 79.48 + } 79.49 + 79.50 + File writeTestFile() throws IOException { 79.51 + File f = new File("Test.java"); 79.52 + PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(f))); 79.53 + out.println("class Test { }"); 79.54 + out.close(); 79.55 + return f; 79.56 + } 79.57 + 79.58 + File compileTestFile(File f) { 79.59 + int rc = com.sun.tools.javac.Main.compile(new String[] { "-g", f.getPath() }); 79.60 + if (rc != 0) 79.61 + throw new Error("compilation failed. rc=" + rc); 79.62 + String path = f.getPath(); 79.63 + return new File(path.substring(0, path.length() - 5) + ".class"); 79.64 + } 79.65 + 79.66 + String javap(File classFile) { 79.67 + StringWriter sw = new StringWriter(); 79.68 + PrintWriter out = new PrintWriter(sw); 79.69 + int rc = com.sun.tools.javap.Main.run(new String[] { classFile.getPath() }, out); 79.70 + if (rc != 0) 79.71 + throw new Error("javap failed. rc=" + rc); 79.72 + out.close(); 79.73 + System.out.println(sw.toString()); 79.74 + return sw.toString(); 79.75 + } 79.76 + 79.77 + void verify(File classFile, String... expects) { 79.78 + String output = javap(classFile); 79.79 + for (String expect: expects) { 79.80 + if (output.indexOf(expect)< 0) 79.81 + error(expect + " not found"); 79.82 + } 79.83 + } 79.84 + 79.85 + void error(String msg) { 79.86 + System.err.println(msg); 79.87 + errors++; 79.88 + } 79.89 + 79.90 + int errors; 79.91 +}
80.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 80.2 +++ b/test/tools/javap/T4975569.java Tue Jun 03 13:26:47 2008 -0700 80.3 @@ -0,0 +1,94 @@ 80.4 +/* 80.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. 80.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 80.7 + * 80.8 + * This code is free software; you can redistribute it and/or modify it 80.9 + * under the terms of the GNU General Public License version 2 only, as 80.10 + * published by the Free Software Foundation. 80.11 + * 80.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 80.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 80.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 80.15 + * version 2 for more details (a copy is included in the LICENSE file that 80.16 + * accompanied this code). 80.17 + * 80.18 + * You should have received a copy of the GNU General Public License version 80.19 + * 2 along with this work; if not, write to the Free Software Foundation, 80.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 80.21 + * 80.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 80.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 80.24 + * have any questions. 80.25 + */ 80.26 + 80.27 +/* 80.28 + * @test 80.29 + * @bug 4975569 6622215 80.30 + * @summary javap doesn't print new flag bits 80.31 + */ 80.32 + 80.33 +import java.io.*; 80.34 +import java.util.*; 80.35 + 80.36 +public class T4975569 80.37 +{ 80.38 + public static void main(String... args) { 80.39 + new T4975569().run(); 80.40 + } 80.41 + 80.42 + void run() { 80.43 + verify("T4975569$Anno", "flags: ACC_INTERFACE, ACC_ABSTRACT, ACC_ANNOTATION"); 80.44 + verify("T4975569$E", "flags: ACC_FINAL, ACC_SUPER, ACC_ENUM"); 80.45 + verify("T4975569$S", "flags: ACC_BRIDGE, ACC_SYNTHETIC", 80.46 + "InnerClasses: \n static"); 80.47 + verify("T4975569$V", "void m(java.lang.String...)", 80.48 + "flags: ACC_VARARGS"); 80.49 + verify("T4975569$Prot", "InnerClasses: \n protected"); 80.50 + //verify("T4975569$Priv", "InnerClasses"); 80.51 + if (errors > 0) 80.52 + throw new Error(errors + " found."); 80.53 + } 80.54 + 80.55 + void verify(String className, String... expects) { 80.56 + String output = javap(className); 80.57 + for (String expect: expects) { 80.58 + if (output.indexOf(expect)< 0) 80.59 + error(expect + " not found"); 80.60 + } 80.61 + } 80.62 + 80.63 + void error(String msg) { 80.64 + System.err.println(msg); 80.65 + errors++; 80.66 + } 80.67 + 80.68 + int errors; 80.69 + 80.70 + String javap(String className) { 80.71 + String testClasses = System.getProperty("test.classes", "."); 80.72 + StringWriter sw = new StringWriter(); 80.73 + PrintWriter out = new PrintWriter(sw); 80.74 + String[] args = { "-v", "-classpath", testClasses, className }; 80.75 + int rc = com.sun.tools.javap.Main.run(args, out); 80.76 + if (rc != 0) 80.77 + throw new Error("javap failed. rc=" + rc); 80.78 + out.close(); 80.79 + String output = sw.toString(); 80.80 + System.out.println("class " + className); 80.81 + System.out.println(output); 80.82 + return output; 80.83 + } 80.84 + 80.85 + List x() { return null; }; 80.86 + 80.87 + class V { void m(String... args) { } } 80.88 + enum E { e; } 80.89 + @interface Anno { } 80.90 + static class S extends T4975569 { 80.91 + ArrayList x() { return null; } 80.92 + } 80.93 + 80.94 + protected class Prot { } 80.95 + //private class Priv { int i; } 80.96 +} 80.97 +
81.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 81.2 +++ b/test/tools/javap/T6271787.java Tue Jun 03 13:26:47 2008 -0700 81.3 @@ -0,0 +1,90 @@ 81.4 +/* 81.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. 81.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 81.7 + * 81.8 + * This code is free software; you can redistribute it and/or modify it 81.9 + * under the terms of the GNU General Public License version 2 only, as 81.10 + * published by the Free Software Foundation. 81.11 + * 81.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 81.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 81.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 81.15 + * version 2 for more details (a copy is included in the LICENSE file that 81.16 + * accompanied this code). 81.17 + * 81.18 + * You should have received a copy of the GNU General Public License version 81.19 + * 2 along with this work; if not, write to the Free Software Foundation, 81.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 81.21 + * 81.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 81.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 81.24 + * have any questions. 81.25 + */ 81.26 + 81.27 +/* 81.28 + * @test 81.29 + * @bug 6271787 81.30 + * @summary javap dumps LocalVariableTypeTable attribute in hex, needs to print a table 81.31 + */ 81.32 + 81.33 +import java.io.*; 81.34 + 81.35 +public class T6271787 { 81.36 + public static void main(String[] args) throws Exception { 81.37 + new T6271787().run(); 81.38 + } 81.39 + 81.40 + public void run() throws IOException { 81.41 + File javaFile = writeTestFile(); 81.42 + File classFile = compileTestFile(javaFile); 81.43 + 81.44 + verify(classFile, 81.45 + "LocalVariableTypeTable:", 81.46 + "0 5 0 this LTest<TT;>;" // should consider decoding this in javap 81.47 + ); 81.48 + 81.49 + if (errors > 0) 81.50 + throw new Error(errors + " found."); 81.51 + } 81.52 + 81.53 + File writeTestFile() throws IOException { 81.54 + File f = new File("Test.java"); 81.55 + PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(f))); 81.56 + out.println("class Test<T> { }"); 81.57 + out.close(); 81.58 + return f; 81.59 + } 81.60 + 81.61 + File compileTestFile(File f) { 81.62 + int rc = com.sun.tools.javac.Main.compile(new String[] { "-g", f.getPath() }); 81.63 + if (rc != 0) 81.64 + throw new Error("compilation failed. rc=" + rc); 81.65 + String path = f.getPath(); 81.66 + return new File(path.substring(0, path.length() - 5) + ".class"); 81.67 + } 81.68 + 81.69 + String javap(File f) { 81.70 + StringWriter sw = new StringWriter(); 81.71 + PrintWriter out = new PrintWriter(sw); 81.72 + int rc = com.sun.tools.javap.Main.run(new String[] { "-v", f.getPath() }, out); 81.73 + if (rc != 0) 81.74 + throw new Error("javap failed. rc=" + rc); 81.75 + out.close(); 81.76 + return sw.toString(); 81.77 + } 81.78 + 81.79 + void verify(File classFile, String... expects) { 81.80 + String output = javap(classFile); 81.81 + for (String expect: expects) { 81.82 + if (output.indexOf(expect)< 0) 81.83 + error(expect + " not found"); 81.84 + } 81.85 + } 81.86 + 81.87 + void error(String msg) { 81.88 + System.err.println(msg); 81.89 + errors++; 81.90 + } 81.91 + 81.92 + int errors; 81.93 +}
82.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 82.2 +++ b/test/tools/javap/T6474890.java Tue Jun 03 13:26:47 2008 -0700 82.3 @@ -0,0 +1,95 @@ 82.4 +/* 82.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. 82.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 82.7 + * 82.8 + * This code is free software; you can redistribute it and/or modify it 82.9 + * under the terms of the GNU General Public License version 2 only, as 82.10 + * published by the Free Software Foundation. 82.11 + * 82.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 82.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 82.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 82.15 + * version 2 for more details (a copy is included in the LICENSE file that 82.16 + * accompanied this code). 82.17 + * 82.18 + * You should have received a copy of the GNU General Public License version 82.19 + * 2 along with this work; if not, write to the Free Software Foundation, 82.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 82.21 + * 82.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 82.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 82.24 + * have any questions. 82.25 + */ 82.26 + 82.27 +/* 82.28 + * @test 82.29 + * @bug 6474890 82.30 + * @summary javap does not open .zip files in -classpath 82.31 + */ 82.32 + 82.33 +import java.io.*; 82.34 +import java.util.zip.*; 82.35 + 82.36 +public class T6474890 { 82.37 + public static void main(String[] args) throws Exception { 82.38 + new T6474890().run(); 82.39 + } 82.40 + 82.41 + public void run() throws IOException { 82.42 + File classDir = new File("classes"); 82.43 + classDir.mkdir(); 82.44 + 82.45 + String className = "Test"; 82.46 + File javaFile = writeTestFile(className); 82.47 + compileTestFile(classDir, javaFile); 82.48 + 82.49 + File zipFile = zip(classDir, new File(classDir + ".zip")); 82.50 + javap("-classpath", zipFile.getPath(), className); 82.51 + 82.52 + File jarFile = zip(classDir, new File(classDir + ".jar")); 82.53 + javap("-classpath", zipFile.getPath(), className); 82.54 + } 82.55 + 82.56 + File writeTestFile(String name) throws IOException { 82.57 + File f = new File(name + ".java"); 82.58 + PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(f))); 82.59 + out.println("class " + name + " { }"); 82.60 + out.close(); 82.61 + return f; 82.62 + } 82.63 + 82.64 + void compileTestFile(File classDir, File file) { 82.65 + int rc = com.sun.tools.javac.Main.compile( 82.66 + new String[] { "-d", classDir.getPath(), file.getPath() }); 82.67 + if (rc != 0) 82.68 + throw new Error("compilation failed. rc=" + rc); 82.69 + } 82.70 + 82.71 + File zip(File dir, File zipFile) throws IOException { 82.72 + ZipOutputStream zipOut = new ZipOutputStream(new FileOutputStream(zipFile)); 82.73 + for (File file: dir.listFiles()) { 82.74 + if (file.isFile()) { 82.75 + byte[] data = new byte[(int) file.length()]; 82.76 + DataInputStream in = new DataInputStream(new FileInputStream(file)); 82.77 + in.readFully(data); 82.78 + in.close(); 82.79 + zipOut.putNextEntry(new ZipEntry(file.getName())); 82.80 + zipOut.write(data, 0, data.length); 82.81 + zipOut.closeEntry(); 82.82 + } 82.83 + } 82.84 + zipOut.close(); 82.85 + return zipFile; 82.86 + } 82.87 + 82.88 + String javap(String... args) { 82.89 + StringWriter sw = new StringWriter(); 82.90 + PrintWriter out = new PrintWriter(sw); 82.91 + //sun.tools.javap.Main.entry(args); 82.92 + int rc = com.sun.tools.javap.Main.run(args, out); 82.93 + if (rc != 0) 82.94 + throw new Error("javap failed. rc=" + rc); 82.95 + out.close(); 82.96 + return sw.toString(); 82.97 + } 82.98 +}
83.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 83.2 +++ b/test/tools/javap/T6587786.java Tue Jun 03 13:26:47 2008 -0700 83.3 @@ -0,0 +1,52 @@ 83.4 +/* 83.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. 83.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 83.7 + * 83.8 + * This code is free software; you can redistribute it and/or modify it 83.9 + * under the terms of the GNU General Public License version 2 only, as 83.10 + * published by the Free Software Foundation. 83.11 + * 83.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 83.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 83.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 83.15 + * version 2 for more details (a copy is included in the LICENSE file that 83.16 + * accompanied this code). 83.17 + * 83.18 + * You should have received a copy of the GNU General Public License version 83.19 + * 2 along with this work; if not, write to the Free Software Foundation, 83.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 83.21 + * 83.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 83.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 83.24 + * have any questions. 83.25 + */ 83.26 + 83.27 +/* 83.28 + * @test 83.29 + * @bug 6587786 83.30 + * @summary Javap throws error : "ERROR:Could not find <classname>" for JRE classes 83.31 + */ 83.32 + 83.33 +import java.io.*; 83.34 + 83.35 +public class T6587786 { 83.36 + public static void main(String[] args) throws Exception { 83.37 + new T6587786().run(); 83.38 + } 83.39 + 83.40 + public void run() throws IOException { 83.41 + javap("com.sun.javadoc.Doc", "com.sun.crypto.provider.ai"); 83.42 + javap("com.sun.crypto.provider.ai", "com.sun.javadoc.ClassDoc"); 83.43 + } 83.44 + 83.45 + void javap(String... args) { 83.46 + StringWriter sw = new StringWriter(); 83.47 + PrintWriter out = new PrintWriter(sw); 83.48 + //sun.tools.javap.Main.entry(args); 83.49 + int rc = com.sun.tools.javap.Main.run(args, out); 83.50 + if (rc != 0) 83.51 + throw new Error("javap failed. rc=" + rc); 83.52 + out.close(); 83.53 + System.out.println(sw.toString()); 83.54 + } 83.55 +}
84.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 84.2 +++ b/test/tools/javap/T6622216.java Tue Jun 03 13:26:47 2008 -0700 84.3 @@ -0,0 +1,77 @@ 84.4 +/* 84.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. 84.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 84.7 + * 84.8 + * This code is free software; you can redistribute it and/or modify it 84.9 + * under the terms of the GNU General Public License version 2 only, as 84.10 + * published by the Free Software Foundation. 84.11 + * 84.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 84.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 84.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 84.15 + * version 2 for more details (a copy is included in the LICENSE file that 84.16 + * accompanied this code). 84.17 + * 84.18 + * You should have received a copy of the GNU General Public License version 84.19 + * 2 along with this work; if not, write to the Free Software Foundation, 84.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 84.21 + * 84.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 84.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 84.24 + * have any questions. 84.25 + */ 84.26 + 84.27 +/* 84.28 + * @test 84.29 + * @bug 6622216 84.30 + * @summary javap names some attributes incorrectly 84.31 + */ 84.32 + 84.33 +import java.io.*; 84.34 + 84.35 +public class T6622216 { 84.36 + public static void main(String[] args) throws Exception { 84.37 + new T6622216().run(); 84.38 + } 84.39 + 84.40 + public void run() throws IOException { 84.41 + File javaFile = writeTestFile(); 84.42 + File classFile = compileTestFile(javaFile); 84.43 + String output = javap(classFile); 84.44 + verify(output); 84.45 + } 84.46 + 84.47 + File writeTestFile() throws IOException { 84.48 + File f = new File("Outer.java"); 84.49 + PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(f))); 84.50 + out.println("class Outer {"); 84.51 + out.println(" class Inner { }"); 84.52 + out.println("}"); 84.53 + out.close(); 84.54 + return f; 84.55 + } 84.56 + 84.57 + File compileTestFile(File f) { 84.58 + int rc = com.sun.tools.javac.Main.compile(new String[] { f.getPath() }); 84.59 + if (rc != 0) 84.60 + throw new Error("compilation failed. rc=" + rc); 84.61 + String path = f.getPath(); 84.62 + return new File(path.substring(0, path.length() - 5) + ".class"); 84.63 + } 84.64 + 84.65 + String javap(File f) { 84.66 + StringWriter sw = new StringWriter(); 84.67 + PrintWriter out = new PrintWriter(sw); 84.68 + int rc = com.sun.tools.javap.Main.run(new String[] { "-v", f.getPath() }, out); 84.69 + if (rc != 0) 84.70 + throw new Error("javap failed. rc=" + rc); 84.71 + out.close(); 84.72 + return sw.toString(); 84.73 + } 84.74 + 84.75 + void verify(String output) { 84.76 + System.out.println(output); 84.77 + if (output.indexOf("InnerClasses") == -1) 84.78 + throw new Error("InnerClasses not found in output"); 84.79 + } 84.80 +}
85.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 85.2 +++ b/test/tools/javap/T6622232.java Tue Jun 03 13:26:47 2008 -0700 85.3 @@ -0,0 +1,97 @@ 85.4 +/* 85.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. 85.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 85.7 + * 85.8 + * This code is free software; you can redistribute it and/or modify it 85.9 + * under the terms of the GNU General Public License version 2 only, as 85.10 + * published by the Free Software Foundation. 85.11 + * 85.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 85.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 85.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 85.15 + * version 2 for more details (a copy is included in the LICENSE file that 85.16 + * accompanied this code). 85.17 + * 85.18 + * You should have received a copy of the GNU General Public License version 85.19 + * 2 along with this work; if not, write to the Free Software Foundation, 85.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 85.21 + * 85.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 85.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 85.24 + * have any questions. 85.25 + */ 85.26 + 85.27 +/* 85.28 + * @test 85.29 + * @bug 6622232 85.30 + * @summary javap gets whitespace confused 85.31 + */ 85.32 + 85.33 +import java.io.*; 85.34 + 85.35 +public class T6622232 { 85.36 + public static void main(String[] args) throws Exception { 85.37 + new T6622232().run(); 85.38 + } 85.39 + 85.40 + public void run() throws IOException { 85.41 + File javaFile = writeTestFile(); 85.42 + File classFile = compileTestFile(javaFile); 85.43 + String output = javap(classFile); 85.44 + 85.45 + // these are all examples of bad whitespace from old javap 85.46 + verifyNot(output, 85.47 + "\\Q Constant value: int 3Deprecated: true\\E", 85.48 + "^Deprecated: true", 85.49 + "\\Q throws java.lang.Exception, java.lang.Error Deprecated: true\\E" 85.50 + ); 85.51 + 85.52 + if (errors > 0) 85.53 + throw new Error(errors + " found."); 85.54 + } 85.55 + 85.56 + File writeTestFile() throws IOException { 85.57 + File f = new File("Test.java"); 85.58 + PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(f))); 85.59 + out.println("class Test { "); 85.60 + out.println(" @Deprecated static final int f1 = 3;"); 85.61 + out.println(" @Deprecated int f2;"); 85.62 + out.println(" @Deprecated void m() throws Exception, Error { }"); 85.63 + out.println("}"); 85.64 + out.close(); 85.65 + return f; 85.66 + } 85.67 + 85.68 + File compileTestFile(File f) { 85.69 + int rc = com.sun.tools.javac.Main.compile(new String[] { "-g", f.getPath() }); 85.70 + if (rc != 0) 85.71 + throw new Error("compilation failed. rc=" + rc); 85.72 + String path = f.getPath(); 85.73 + return new File(path.substring(0, path.length() - 5) + ".class"); 85.74 + } 85.75 + 85.76 + String javap(File f) { 85.77 + StringWriter sw = new StringWriter(); 85.78 + PrintWriter out = new PrintWriter(sw); 85.79 + int rc = com.sun.tools.javap.Main.run(new String[] { "-v", f.getPath() }, out); 85.80 + if (rc != 0) 85.81 + throw new Error("javap failed. rc=" + rc); 85.82 + out.close(); 85.83 + System.out.println(sw.toString()); 85.84 + return sw.toString(); 85.85 + } 85.86 + 85.87 + void verifyNot(String output, String... unexpects) { 85.88 + for (String unexpect: unexpects) { 85.89 + if (output.matches(unexpect)) 85.90 + error(unexpect + " unexpectedly found"); 85.91 + } 85.92 + } 85.93 + 85.94 + void error(String msg) { 85.95 + System.err.println(msg); 85.96 + errors++; 85.97 + } 85.98 + 85.99 + int errors; 85.100 +}
86.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 86.2 +++ b/test/tools/javap/T6622260.java Tue Jun 03 13:26:47 2008 -0700 86.3 @@ -0,0 +1,197 @@ 86.4 +/* 86.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. 86.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 86.7 + * 86.8 + * This code is free software; you can redistribute it and/or modify it 86.9 + * under the terms of the GNU General Public License version 2 only, as 86.10 + * published by the Free Software Foundation. 86.11 + * 86.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 86.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 86.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 86.15 + * version 2 for more details (a copy is included in the LICENSE file that 86.16 + * accompanied this code). 86.17 + * 86.18 + * You should have received a copy of the GNU General Public License version 86.19 + * 2 along with this work; if not, write to the Free Software Foundation, 86.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 86.21 + * 86.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 86.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 86.24 + * have any questions. 86.25 + */ 86.26 + 86.27 +/* 86.28 + * @test 86.29 + * @bug 6622260 86.30 + * @summary javap prints negative bytes incorrectly in hex 86.31 + */ 86.32 + 86.33 +import java.io.*; 86.34 + 86.35 +public class T6622260 { 86.36 + public static void main(String[] args) throws Exception { 86.37 + new T6622260().run(); 86.38 + } 86.39 + 86.40 + public void run() throws IOException { 86.41 + File javaFile = writeTestFile(); 86.42 + File classFile = compileTestFile(javaFile); 86.43 + modifyClassFile(classFile); 86.44 + String output = javap(classFile); 86.45 + verify(output); 86.46 + } 86.47 + 86.48 + File writeTestFile() throws IOException { 86.49 + File f = new File("Test.java"); 86.50 + PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(f))); 86.51 + out.println("@Deprecated class Test { int f; void m() { } }"); 86.52 + out.close(); 86.53 + return f; 86.54 + } 86.55 + 86.56 + File compileTestFile(File f) { 86.57 + int rc = com.sun.tools.javac.Main.compile(new String[] { f.getPath() }); 86.58 + if (rc != 0) 86.59 + throw new Error("compilation failed. rc=" + rc); 86.60 + String path = f.getPath(); 86.61 + return new File(path.substring(0, path.length() - 5) + ".class"); 86.62 + } 86.63 + 86.64 + void modifyClassFile(File f) throws IOException { 86.65 + String newAttributeName = "NonstandardAttribute"; 86.66 + byte[] newAttributeData = { 0, 1, 2, 127, (byte)128, (byte)129, (byte)254, (byte)255 }; 86.67 + 86.68 + DataInputStream in = new DataInputStream(new FileInputStream(f)); 86.69 + byte[] data = new byte[(int) f.length()]; 86.70 + in.readFully(data); 86.71 + in.close(); 86.72 + 86.73 + in = new DataInputStream(new ByteArrayInputStream(data)); 86.74 + in.skipBytes(4); // magic 86.75 + in.skipBytes(2); // minor 86.76 + in.skipBytes(2); // minor 86.77 + 86.78 + int constantPoolPos = data.length - in.available(); 86.79 + int constant_pool_count = skipConstantPool(in); 86.80 + 86.81 + int flagsPos = data.length - in.available(); 86.82 + in.skipBytes(2); // access_flags 86.83 + in.skipBytes(2); // this_class 86.84 + in.skipBytes(2); // super_class 86.85 + 86.86 + int interfaces_count = in.readUnsignedShort(); 86.87 + in.skipBytes(interfaces_count * 2); 86.88 + 86.89 + int field_count = in.readUnsignedShort(); 86.90 + for (int i = 0; i < field_count; i++) { 86.91 + in.skipBytes(6); // access_flags, name_index, descriptor_index 86.92 + skipAttributes(in); 86.93 + } 86.94 + 86.95 + int method_count = in.readUnsignedShort(); 86.96 + for (int i = 0; i < method_count; i++) { 86.97 + in.skipBytes(6); // access_flags, name_index, descriptor_index 86.98 + skipAttributes(in); 86.99 + } 86.100 + 86.101 + int classAttributesPos = data.length - in.available(); 86.102 + int attributes_count = in.readUnsignedShort(); 86.103 + 86.104 + f.renameTo(new File(f.getPath() + ".BAK")); 86.105 + DataOutputStream out = new DataOutputStream(new FileOutputStream(f)); 86.106 + 86.107 + // copy head 86.108 + out.write(data, 0, constantPoolPos); 86.109 + 86.110 + // copy constant pool, adding in name of new attribute 86.111 + out.writeShort(constant_pool_count + 1); 86.112 + out.write(data, constantPoolPos + 2, flagsPos - constantPoolPos - 2); 86.113 + out.write(1); // CONSTANT_Utf8 86.114 + out.writeUTF(newAttributeName); 86.115 + 86.116 + // copy flags, class, superclass, interfaces, fields and methods 86.117 + out.write(data, flagsPos, classAttributesPos - flagsPos); 86.118 + 86.119 + // copy class attributes, adding in new attribute 86.120 + out.writeShort(attributes_count + 1); 86.121 + out.write(data, classAttributesPos + 2, data.length - classAttributesPos - 2); 86.122 + out.writeShort(constant_pool_count); // index of new attribute name 86.123 + out.writeInt(newAttributeData.length); 86.124 + out.write(newAttributeData); 86.125 + out.close(); 86.126 + } 86.127 + 86.128 + int skipConstantPool(DataInputStream in) throws IOException { 86.129 + int constant_pool_count = in.readUnsignedShort(); 86.130 + for (int i = 1; i < constant_pool_count; i++) { 86.131 + int tag = in.readUnsignedByte(); 86.132 + switch (tag) { 86.133 + case 1: // CONSTANT_Utf8 86.134 + int length = in.readUnsignedShort(); 86.135 + in.skipBytes(length); // bytes 86.136 + break; 86.137 + 86.138 + case 3: // CONSTANT_Integer 86.139 + case 4: // CONSTANT_Float 86.140 + in.skipBytes(4); // bytes 86.141 + break; 86.142 + 86.143 + case 5: // CONSTANT_Long 86.144 + case 6: // CONSTANT_Double 86.145 + in.skipBytes(8); // high_bytes, low_bytes 86.146 + break; 86.147 + 86.148 + case 7: // CONSTANT_Class 86.149 + in.skipBytes(2); // name_index 86.150 + break; 86.151 + 86.152 + case 8: // CONSTANT_String 86.153 + in.skipBytes(2); // string_index 86.154 + break; 86.155 + 86.156 + case 9: // CONSTANT_FieldRef 86.157 + case 10: // CONSTANT_Methodref 86.158 + case 11: // CONSTANT_InterfaceMethodref 86.159 + in.skipBytes(4); // class_index, name_and_type_index 86.160 + break; 86.161 + 86.162 + case 12: // CONSTANT_NameAndType 86.163 + in.skipBytes(4); // name_index, descriptor_index 86.164 + break; 86.165 + 86.166 + default: 86.167 + throw new Error("constant pool tag: " + tag); 86.168 + } 86.169 + } 86.170 + return constant_pool_count; 86.171 + } 86.172 + 86.173 + int skipAttributes(DataInputStream in) throws IOException { 86.174 + int attributes_count = in.readUnsignedShort(); 86.175 + for (int i = 0; i < attributes_count; i++) { 86.176 + in.skipBytes(2); // attribute_name_index; 86.177 + int length = in.readInt(); 86.178 + in.skipBytes(length); // info 86.179 + } 86.180 + return attributes_count; 86.181 + } 86.182 + 86.183 + String javap(File f) { 86.184 + StringWriter sw = new StringWriter(); 86.185 + PrintWriter out = new PrintWriter(sw); 86.186 + int rc = com.sun.tools.javap.Main.run(new String[] { "-v", f.getPath() }, out); 86.187 + if (rc != 0) 86.188 + throw new Error("javap failed. rc=" + rc); 86.189 + out.close(); 86.190 + return sw.toString(); 86.191 + } 86.192 + 86.193 + void verify(String output) { 86.194 + System.out.println(output); 86.195 + if (output.indexOf("-") >= 0) 86.196 + throw new Error("- found in output"); 86.197 + if (output.indexOf("FFFFFF") >= 0) 86.198 + throw new Error("FFFFFF found in output"); 86.199 + } 86.200 +}