--- a/make/build.properties Mon Jun 02 22:35:16 2008 -0700
+++ b/make/build.properties Fri Jun 06 15:17:35 2008 -0700
@@ -1,5 +1,5 @@
#
-# Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
+# Copyright 2007-2008 Sun Microsystems, Inc. All Rights Reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
@@ -66,7 +66,7 @@ javac.no.jdk.warnings = -XDignore.symbol
# set the following to -version to verify the versions of javac being used
javac.version.opt =
# in time, there should be no exceptions to -Xlint:all
-javac.lint.opts = -Xlint:all,-unchecked,-deprecation,-fallthrough,-cast,-serial -Werror
+javac.lint.opts = -Xlint:all,-deprecation,-fallthrough,-serial,-unchecked,-cast
# options for the <javadoc> task for javac
javadoc.jls3.url=http://java.sun.com/docs/books/jls/
@@ -120,6 +120,8 @@ javah.tests = \
tools/javah/
javap.includes = \
+ com/sun/tools/classfile/ \
+ com/sun/tools/javap/ \
sun/tools/javap/
javap.tests = \
--- a/make/build.xml Mon Jun 02 22:35:16 2008 -0700
+++ b/make/build.xml Fri Jun 06 15:17:35 2008 -0700
@@ -136,7 +136,7 @@
<arg value="-html:${findbugs.home}/src/xsl/fancy.xsl"/>
<arg value="${dist.findbugs.dir}/findbugs.xml"/>
<redirector output="${dist.findbugs.dir}/findbugs.html"/>
- </exec>
+ </exec>
</target>
<target name="coverage" depends="-def-cobertura,build-all-classes,instrument-classes,jtreg,coverage-report"/>
@@ -301,14 +301,15 @@
jarmainclass="sun.tools.javap.Main"/>
</target>
- <target name="build-classes-javap" depends="build-bootstrap-javac">
+ <target name="build-classes-javap" depends="build-classes-javac">
<build-classes name="javap" includes="${javap.includes}"/>
</target>
- <target name="build-javap" depends="build-bootstrap-javac">
+ <target name="build-javap" depends="build-javac">
<build-tool name="javap"
includes="${javap.includes}"
- jarmainclass="sun.tools.javap.Main"/>
+ jarmainclass="sun.tools.javap.Main"
+ jarclasspath="javac.jar"/>
</target>
<!-- (no javadoc for javap) -->
@@ -480,7 +481,7 @@
destdir="@{gensrc.dir}"
includes="@{includes}"/>
<copy todir="@{gensrc.dir}">
- <fileset dir="${src.classes.dir}" includes="${javac.includes}"/>
+ <fileset dir="${src.classes.dir}" includes="@{includes}"/>
<globmapper from="*.properties-template" to="*.properties"/>
<filterset begintoken="$(" endtoken=")">
<filter token="JDK_VERSION" value="${jdk.version}"/>
--- a/make/netbeans/common/standard-ide-actions-no-javadoc.ent Mon Jun 02 22:35:16 2008 -0700
+++ b/make/netbeans/common/standard-ide-actions-no-javadoc.ent Fri Jun 06 15:17:35 2008 -0700
@@ -157,5 +157,5 @@
</action>
<action name="javadoc">
- <target>javadoc-nb</target>
+ <target>-javadoc-nb</target>
</action>
--- a/make/netbeans/common/standard-ide-actions.ent Mon Jun 02 22:35:16 2008 -0700
+++ b/make/netbeans/common/standard-ide-actions.ent Fri Jun 06 15:17:35 2008 -0700
@@ -157,5 +157,5 @@
</action>
<action name="javadoc">
- <target>javadoc-nb</target>
+ <target>-javadoc-nb</target>
</action>
--- a/src/share/classes/sun/tools/javap/Main.java Mon Jun 02 22:35:16 2008 -0700
+++ b/src/share/classes/sun/tools/javap/Main.java Fri Jun 06 15:17:35 2008 -0700
@@ -49,6 +49,12 @@ public class Main {
}
public static void main(String argv[]) {
+ // unless first arg is -Xold, use new javap
+ if (!(argv.length >= 1 && argv[0].equals("-Xold"))) {
+ com.sun.tools.javap.Main.main(argv);
+ return;
+ }
+
entry(argv);
if (errorOccurred) {
System.exit(1);
@@ -178,6 +184,8 @@ public class Main {
}
} else if (arg.equals("-all")) {
env.showallAttr = true;
+ } else if (arg.equals("-Xold")) {
+ // ignore: this is old javap
} else {
error("invalid flag: " + arg);
usage();
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/classes/com/sun/tools/classfile/AccessFlags.java Fri Jun 06 15:17:35 2008 -0700
@@ -0,0 +1,254 @@
+/*
+ * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package com.sun.tools.classfile;
+
+import java.io.IOException;
+import java.util.LinkedHashSet;
+import java.util.Set;
+
+/**
+ * See JVMS3, sections 4.2, 4.6, 4.7.
+ *
+ * <p><b>This is NOT part of any API supported by Sun Microsystems. If
+ * you write code that depends on this, you do so at your own risk.
+ * This code and its internal interfaces are subject to change or
+ * deletion without notice.</b>
+ */
+public class AccessFlags {
+ public static final int ACC_PUBLIC = 0x0001; // class, inner, field, method
+ public static final int ACC_PRIVATE = 0x0002; // inner, field, method
+ public static final int ACC_PROTECTED = 0x0004; // inner, field, method
+ public static final int ACC_STATIC = 0x0008; // inner, field, method
+ public static final int ACC_FINAL = 0x0010; // class, inner, field, method
+ public static final int ACC_SUPER = 0x0020; // class
+ public static final int ACC_SYNCHRONIZED = 0x0020; // method
+ public static final int ACC_VOLATILE = 0x0040; // field
+ public static final int ACC_BRIDGE = 0x0040; // method
+ public static final int ACC_TRANSIENT = 0x0080; // field
+ public static final int ACC_VARARGS = 0x0080; // method
+ public static final int ACC_NATIVE = 0x0100; // method
+ public static final int ACC_INTERFACE = 0x0200; // class, inner
+ public static final int ACC_ABSTRACT = 0x0400; // class, inner, method
+ public static final int ACC_STRICT = 0x0800; // method
+ public static final int ACC_SYNTHETIC = 0x1000; // class, inner, field, method
+ public static final int ACC_ANNOTATION = 0x2000; // class, inner
+ public static final int ACC_ENUM = 0x4000; // class, inner, field
+ public static final int ACC_MODULE = 0x8000; // class, inner, field, method
+
+ private static enum Type { Class, InnerClass, Field, Method};
+
+ AccessFlags(ClassReader cr) throws IOException {
+ this(cr.readUnsignedShort());
+ }
+
+ public AccessFlags(int flags) {
+ this.flags = flags;
+ }
+
+ public AccessFlags ignore(int mask) {
+ return new AccessFlags(flags & ~mask);
+ }
+
+ public boolean is(int mask) {
+ return (flags & mask) != 0;
+ }
+
+ private static final int[] classModifiers = {
+ ACC_PUBLIC, ACC_FINAL, ACC_ABSTRACT, ACC_MODULE
+ };
+
+ private static final int[] classFlags = {
+ ACC_PUBLIC, ACC_FINAL, ACC_SUPER, ACC_INTERFACE, ACC_ABSTRACT,
+ ACC_SYNTHETIC, ACC_ANNOTATION, ACC_ENUM, ACC_MODULE
+ };
+
+ public Set<String> getClassModifiers() {
+ int f = ((flags & ACC_INTERFACE) != 0 ? flags & ~ACC_ABSTRACT : flags);
+ return getModifiers(f, classModifiers, Type.Class);
+ }
+
+ public Set<String> getClassFlags() {
+ return getFlags(classFlags, Type.Class);
+ }
+
+ private static final int[] innerClassModifiers = {
+ ACC_PUBLIC, ACC_PRIVATE, ACC_PROTECTED, ACC_STATIC, ACC_FINAL,
+ ACC_ABSTRACT, ACC_MODULE
+ };
+
+ private static final int[] innerClassFlags = {
+ ACC_PUBLIC, ACC_PRIVATE, ACC_PROTECTED, ACC_STATIC, ACC_FINAL, ACC_SUPER,
+ ACC_INTERFACE, ACC_ABSTRACT, ACC_SYNTHETIC, ACC_ANNOTATION, ACC_ENUM, ACC_MODULE
+ };
+
+ public Set<String> getInnerClassModifiers() {
+ int f = ((flags & ACC_INTERFACE) != 0 ? flags & ~ACC_ABSTRACT : flags);
+ return getModifiers(f, innerClassModifiers, Type.InnerClass);
+ }
+
+ public Set<String> getInnerClassFlags() {
+ return getFlags(innerClassFlags, Type.InnerClass);
+ }
+
+ private static final int[] fieldModifiers = {
+ ACC_PUBLIC, ACC_PRIVATE, ACC_PROTECTED, ACC_STATIC, ACC_FINAL,
+ ACC_VOLATILE, ACC_TRANSIENT, ACC_MODULE
+ };
+
+ private static final int[] fieldFlags = {
+ ACC_PUBLIC, ACC_PRIVATE, ACC_PROTECTED, ACC_STATIC, ACC_FINAL,
+ ACC_VOLATILE, ACC_TRANSIENT, ACC_SYNTHETIC, ACC_ENUM, ACC_MODULE
+ };
+
+ public Set<String> getFieldModifiers() {
+ return getModifiers(fieldModifiers, Type.Field);
+ }
+
+ public Set<String> getFieldFlags() {
+ return getFlags(fieldFlags, Type.Field);
+ }
+
+ private static final int[] methodModifiers = {
+ ACC_PUBLIC, ACC_PRIVATE, ACC_PROTECTED, ACC_STATIC, ACC_FINAL,
+ ACC_SYNCHRONIZED, ACC_NATIVE, ACC_ABSTRACT, ACC_STRICT, ACC_MODULE
+ };
+
+ private static final int[] methodFlags = {
+ ACC_PUBLIC, ACC_PRIVATE, ACC_PROTECTED, ACC_STATIC, ACC_FINAL,
+ ACC_SYNCHRONIZED, ACC_BRIDGE, ACC_VARARGS, ACC_NATIVE, ACC_ABSTRACT,
+ ACC_STRICT, ACC_SYNTHETIC, ACC_MODULE
+ };
+
+ public Set<String> getMethodModifiers() {
+ return getModifiers(methodModifiers, Type.Method);
+ }
+
+ public Set<String> getMethodFlags() {
+ return getFlags(methodFlags, Type.Method);
+ }
+
+ private Set<String> getModifiers(int[] modifierFlags, Type t) {
+ return getModifiers(flags, modifierFlags, t);
+ }
+
+ private static Set<String> getModifiers(int flags, int[] modifierFlags, Type t) {
+ Set<String> s = new LinkedHashSet<String>();
+ for (int m: modifierFlags) {
+ if ((flags & m) != 0)
+ s.add(flagToModifier(m, t));
+ }
+ return s;
+ }
+
+ private Set<String> getFlags(int[] expectedFlags, Type t) {
+ Set<String> s = new LinkedHashSet<String>();
+ int f = flags;
+ for (int e: expectedFlags) {
+ if ((f & e) != 0) {
+ s.add(flagToName(e, t));
+ f = f & ~e;
+ }
+ }
+ while (f != 0) {
+ int bit = Integer.highestOneBit(f);
+ s.add("0x" + Integer.toHexString(bit));
+ f = f & ~bit;
+ }
+ return s;
+ }
+
+ private static String flagToModifier(int flag, Type t) {
+ switch (flag) {
+ case ACC_PUBLIC:
+ return "public";
+ case ACC_PRIVATE:
+ return "private";
+ case ACC_PROTECTED:
+ return "protected";
+ case ACC_STATIC:
+ return "static";
+ case ACC_FINAL:
+ return "final";
+ case ACC_SYNCHRONIZED:
+ return "synchronized";
+ case 0x80:
+ return (t == Type.Field ? "transient" : null);
+ case ACC_VOLATILE:
+ return "volatile";
+ case ACC_NATIVE:
+ return "native";
+ case ACC_ABSTRACT:
+ return "abstract";
+ case ACC_STRICT:
+ return "strictfp";
+ case ACC_MODULE:
+ return "module";
+ default:
+ return null;
+ }
+ }
+
+ private static String flagToName(int flag, Type t) {
+ switch (flag) {
+ case ACC_PUBLIC:
+ return "ACC_PUBLIC";
+ case ACC_PRIVATE:
+ return "ACC_PRIVATE";
+ case ACC_PROTECTED:
+ return "ACC_PROTECTED";
+ case ACC_STATIC:
+ return "ACC_STATIC";
+ case ACC_FINAL:
+ return "ACC_FINAL";
+ case 0x20:
+ return (t == Type.Class ? "ACC_SUPER" : "ACC_SYNCHRONIZED");
+ case 0x40:
+ return (t == Type.Field ? "ACC_VOLATILE" : "ACC_BRIDGE");
+ case 0x80:
+ return (t == Type.Field ? "ACC_TRANSIENT" : "ACC_VARARGS");
+ case ACC_NATIVE:
+ return "ACC_NATIVE";
+ case ACC_INTERFACE:
+ return "ACC_INTERFACE";
+ case ACC_ABSTRACT:
+ return "ACC_ABSTRACT";
+ case ACC_STRICT:
+ return "ACC_STRICT";
+ case ACC_SYNTHETIC:
+ return "ACC_SYNTHETIC";
+ case ACC_ANNOTATION:
+ return "ACC_ANNOTATION";
+ case ACC_ENUM:
+ return "ACC_ENUM";
+ case ACC_MODULE:
+ return "ACC_MODULE";
+ default:
+ return null;
+ }
+ }
+
+ final int flags;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/classes/com/sun/tools/classfile/Annotation.java Fri Jun 06 15:17:35 2008 -0700
@@ -0,0 +1,243 @@
+/*
+ * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package com.sun.tools.classfile;
+
+import java.io.IOException;
+
+/**
+ * See JVMS3, section 4.8.16.
+ *
+ * <p><b>This is NOT part of any API supported by Sun Microsystems. If
+ * you write code that depends on this, you do so at your own risk.
+ * This code and its internal interfaces are subject to change or
+ * deletion without notice.</b>
+ */
+public class Annotation {
+ static class InvalidAnnotation extends AttributeException {
+ InvalidAnnotation(String msg) {
+ super(msg);
+ }
+ }
+
+ Annotation(ClassReader cr) throws IOException, InvalidAnnotation {
+ type_index = cr.readUnsignedShort();
+ num_element_value_pairs = cr.readUnsignedShort();
+ element_value_pairs = new element_value_pair[num_element_value_pairs];
+ for (int i = 0; i < element_value_pairs.length; i++)
+ element_value_pairs[i] = new element_value_pair(cr);
+ }
+
+ public Annotation(ConstantPool constant_pool,
+ int type_index,
+ element_value_pair[] element_value_pairs) {
+ this.type_index = type_index;
+ num_element_value_pairs = element_value_pairs.length;
+ this.element_value_pairs = element_value_pairs;
+ }
+
+ public int length() {
+ int n = 2 /*type_index*/ + 2 /*num_element_value_pairs*/;
+ for (element_value_pair pair: element_value_pairs)
+ n += pair.length();
+ return n;
+ }
+
+ public final int type_index;
+ public final int num_element_value_pairs;
+ public final element_value_pair element_value_pairs[];
+
+ /**
+ * See JVMS3, section 4.8.16.1.
+ */
+ public static abstract class element_value {
+ public static element_value read(ClassReader cr)
+ throws IOException, InvalidAnnotation {
+ int tag = cr.readUnsignedByte();
+ switch (tag) {
+ case 'B':
+ case 'C':
+ case 'D':
+ case 'F':
+ case 'I':
+ case 'J':
+ case 'S':
+ case 'Z':
+ case 's':
+ return new Primitive_element_value(cr, tag);
+
+ case 'e':
+ return new Enum_element_value(cr, tag);
+
+ case 'c':
+ return new Class_element_value(cr, tag);
+
+ case '@':
+ return new Annotation_element_value(cr, tag);
+
+ case '[':
+ return new Array_element_value(cr, tag);
+
+ default:
+ throw new InvalidAnnotation("unrecognized tag: " + tag);
+ }
+ }
+
+ protected element_value(int tag) {
+ this.tag = tag;
+ }
+
+ public abstract int length();
+
+ public abstract <R,P> R accept(Visitor<R,P> visitor, P p);
+
+ public interface Visitor<R,P> {
+ R visitPrimitive(Primitive_element_value ev, P p);
+ R visitEnum(Enum_element_value ev, P p);
+ R visitClass(Class_element_value ev, P p);
+ R visitAnnotation(Annotation_element_value ev, P p);
+ R visitArray(Array_element_value ev, P p);
+ }
+
+ public final int tag;
+ }
+
+ public static class Primitive_element_value extends element_value {
+ Primitive_element_value(ClassReader cr, int tag) throws IOException {
+ super(tag);
+ const_value_index = cr.readUnsignedShort();
+ }
+
+ @Override
+ public int length() {
+ return 2;
+ }
+
+ public <R,P> R accept(Visitor<R,P> visitor, P p) {
+ return visitor.visitPrimitive(this, p);
+ }
+
+ public final int const_value_index;
+
+ }
+
+ public static class Enum_element_value extends element_value {
+ Enum_element_value(ClassReader cr, int tag) throws IOException {
+ super(tag);
+ type_name_index = cr.readUnsignedShort();
+ const_name_index = cr.readUnsignedShort();
+ }
+
+ @Override
+ public int length() {
+ return 4;
+ }
+
+ public <R,P> R accept(Visitor<R,P> visitor, P p) {
+ return visitor.visitEnum(this, p);
+ }
+
+ public final int type_name_index;
+ public final int const_name_index;
+ }
+
+ public static class Class_element_value extends element_value {
+ Class_element_value(ClassReader cr, int tag) throws IOException {
+ super(tag);
+ class_info_index = cr.readUnsignedShort();
+ }
+
+ @Override
+ public int length() {
+ return 2;
+ }
+
+ public <R,P> R accept(Visitor<R,P> visitor, P p) {
+ return visitor.visitClass(this, p);
+ }
+
+ public final int class_info_index;
+ }
+
+ public static class Annotation_element_value extends element_value {
+ Annotation_element_value(ClassReader cr, int tag)
+ throws IOException, InvalidAnnotation {
+ super(tag);
+ annotation_value = new Annotation(cr);
+ }
+
+ @Override
+ public int length() {
+ return annotation_value.length();
+ }
+
+ public <R,P> R accept(Visitor<R,P> visitor, P p) {
+ return visitor.visitAnnotation(this, p);
+ }
+
+ public final Annotation annotation_value;
+ }
+
+ public static class Array_element_value extends element_value {
+ Array_element_value(ClassReader cr, int tag)
+ throws IOException, InvalidAnnotation {
+ super(tag);
+ num_values = cr.readUnsignedShort();
+ values = new element_value[num_values];
+ for (int i = 0; i < values.length; i++)
+ values[i] = element_value.read(cr);
+ }
+
+ @Override
+ public int length() {
+ int n = 2;
+ for (int i = 0; i < values.length; i++)
+ n += values[i].length();
+ return n;
+ }
+
+ public <R,P> R accept(Visitor<R,P> visitor, P p) {
+ return visitor.visitArray(this, p);
+ }
+
+ public final int num_values;
+ public final element_value[] values;
+ }
+
+ public static class element_value_pair {
+ element_value_pair(ClassReader cr)
+ throws IOException, InvalidAnnotation {
+ element_name_index = cr.readUnsignedShort();
+ value = element_value.read(cr);
+ }
+
+ public int length() {
+ return 2 + value.length();
+ }
+
+ public final int element_name_index;
+ public final element_value value;
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/classes/com/sun/tools/classfile/AnnotationDefault_attribute.java Fri Jun 06 15:17:35 2008 -0700
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package com.sun.tools.classfile;
+
+import java.io.IOException;
+
+/**
+ * See JVMS3, section 4.8.15.
+ *
+ * <p><b>This is NOT part of any API supported by Sun Microsystems. If
+ * you write code that depends on this, you do so at your own risk.
+ * This code and its internal interfaces are subject to change or
+ * deletion without notice.</b>
+ */
+public class AnnotationDefault_attribute extends Attribute {
+ AnnotationDefault_attribute(ClassReader cr, int name_index, int length)
+ throws IOException, Annotation.InvalidAnnotation {
+ super(name_index, length);
+ default_value = Annotation.element_value.read(cr);
+ }
+
+ public AnnotationDefault_attribute(ConstantPool constant_pool, Annotation.element_value default_value)
+ throws ConstantPoolException {
+ this(constant_pool.getUTF8Index(Attribute.AnnotationDefault), default_value);
+ }
+
+ public AnnotationDefault_attribute(int name_index, Annotation.element_value default_value) {
+ super(name_index, default_value.length());
+ this.default_value = default_value;
+ }
+
+ public <R, D> R accept(Visitor<R, D> visitor, D data) {
+ return visitor.visitAnnotationDefault(this, data);
+ }
+
+ public final Annotation.element_value default_value;
+}
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/classes/com/sun/tools/classfile/Attribute.java Fri Jun 06 15:17:35 2008 -0700
@@ -0,0 +1,199 @@
+/*
+ * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package com.sun.tools.classfile;
+
+import java.io.IOException;
+import java.lang.reflect.Constructor;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * <p><b>This is NOT part of any API supported by Sun Microsystems. If
+ * you write code that depends on this, you do so at your own risk.
+ * This code and its internal interfaces are subject to change or
+ * deletion without notice.</b>
+ */
+
+public abstract class Attribute {
+ public static final String AnnotationDefault = "AnnotationDefault";
+ public static final String CharacterRangeTable = "CharacterRangeTable";
+ public static final String Code = "Code";
+ public static final String ConstantValue = "ConstantValue";
+ public static final String CompilationID = "CompilationID";
+ public static final String Deprecated = "Deprecated";
+ public static final String EnclosingMethod = "EnclosingMethod";
+ public static final String Exceptions = "Exceptions";
+ public static final String InnerClasses = "InnerClasses";
+ public static final String LineNumberTable = "LineNumberTable";
+ public static final String LocalVariableTable = "LocalVariableTable";
+ public static final String LocalVariableTypeTable = "LocalVariableTypeTable";
+ public static final String RuntimeVisibleAnnotations = "RuntimeVisibleAnnotations";
+ public static final String RuntimeInvisibleAnnotations = "RuntimeInvisibleAnnotations";
+ public static final String RuntimeVisibleParameterAnnotations = "RuntimeVisibleParameterAnnotations";
+ public static final String RuntimeInvisibleParameterAnnotations = "RuntimeInvisibleParameterAnnotations";
+ public static final String Signature = "Signature";
+ public static final String SourceDebugExtension = "SourceDebugExtension";
+ public static final String SourceFile = "SourceFile";
+ public static final String SourceID = "SourceID";
+ public static final String StackMap = "StackMap";
+ public static final String StackMapTable = "StackMapTable";
+ public static final String Synthetic = "Synthetic";
+
+ // JSR 277/294
+ public static final String Module = "Module";
+ public static final String ModuleExportTable = "ModuleExportTable";
+ public static final String ModuleMemberTable = "ModuleMemberTable";
+
+ public static class Factory {
+ public Factory() {
+ // defer init of standardAttributeClasses until after options set up
+ }
+
+ public void setCompat(boolean compat) {
+ this.compat = compat;
+ }
+
+ public void setJSR277(boolean jsr277) {
+ this.jsr277 = jsr277;
+ }
+
+ public Attribute createAttribute(ClassReader cr, int name_index, byte[] data)
+ throws IOException {
+ if (standardAttributes == null)
+ init();
+
+ ConstantPool cp = cr.getConstantPool();
+ try {
+ String name = cp.getUTF8Value(name_index);
+ Class<? extends Attribute> attrClass = standardAttributes.get(name);
+ if (attrClass != null) {
+ try {
+ Class<?>[] constrArgTypes = {ClassReader.class, int.class, int.class};
+ Constructor<? extends Attribute> constr = attrClass.getDeclaredConstructor(constrArgTypes);
+ return constr.newInstance(new Object[] { cr, name_index, data.length });
+ } catch (Throwable t) {
+ // fall through and use DefaultAttribute
+ // t.printStackTrace();
+ }
+ }
+ } catch (ConstantPoolException e) {
+ // fall through and use DefaultAttribute
+ }
+ return new DefaultAttribute(cr, name_index, data);
+ }
+
+ protected void init() {
+ standardAttributes = new HashMap<String,Class<? extends Attribute>>();
+ standardAttributes.put(AnnotationDefault, AnnotationDefault_attribute.class);
+ standardAttributes.put(CharacterRangeTable, CharacterRangeTable_attribute.class);
+ standardAttributes.put(Code, Code_attribute.class);
+ standardAttributes.put(ConstantValue, ConstantValue_attribute.class);
+ standardAttributes.put(Deprecated, Deprecated_attribute.class);
+ standardAttributes.put(EnclosingMethod, EnclosingMethod_attribute.class);
+ standardAttributes.put(Exceptions, Exceptions_attribute.class);
+ standardAttributes.put(InnerClasses, InnerClasses_attribute.class);
+ standardAttributes.put(LineNumberTable, LineNumberTable_attribute.class);
+ standardAttributes.put(LocalVariableTable, LocalVariableTable_attribute.class);
+ standardAttributes.put(LocalVariableTypeTable, LocalVariableTypeTable_attribute.class);
+
+ if (jsr277) {
+ standardAttributes.put(Module, Module_attribute.class);
+ standardAttributes.put(ModuleExportTable, ModuleExportTable_attribute.class);
+ standardAttributes.put(ModuleMemberTable, ModuleMemberTable_attribute.class);
+ }
+
+ if (!compat) { // old javap does not recognize recent attributes
+ standardAttributes.put(CompilationID, CompilationID_attribute.class);
+ standardAttributes.put(RuntimeInvisibleAnnotations, RuntimeInvisibleAnnotations_attribute.class);
+ standardAttributes.put(RuntimeInvisibleParameterAnnotations, RuntimeInvisibleParameterAnnotations_attribute.class);
+ standardAttributes.put(RuntimeVisibleAnnotations, RuntimeVisibleAnnotations_attribute.class);
+ standardAttributes.put(RuntimeVisibleParameterAnnotations, RuntimeVisibleParameterAnnotations_attribute.class);
+ standardAttributes.put(Signature, Signature_attribute.class);
+ standardAttributes.put(SourceID, SourceID_attribute.class);
+ }
+
+ standardAttributes.put(SourceDebugExtension, SourceDebugExtension_attribute.class);
+ standardAttributes.put(SourceFile, SourceFile_attribute.class);
+ standardAttributes.put(StackMap, StackMap_attribute.class);
+ standardAttributes.put(StackMapTable, StackMapTable_attribute.class);
+ standardAttributes.put(Synthetic, Synthetic_attribute.class);
+ }
+
+ private Map<String,Class<? extends Attribute>> standardAttributes;
+ private boolean compat; // don't support recent attrs in compatibility mode
+ private boolean jsr277; // support new jsr277 attrs
+ }
+
+ public static Attribute read(ClassReader cr) throws IOException {
+ return cr.readAttribute();
+ }
+
+ protected Attribute(int name_index, int length) {
+ attribute_name_index = name_index;
+ attribute_length = length;
+ }
+
+ public String getName(ConstantPool constant_pool) throws ConstantPoolException {
+ return constant_pool.getUTF8Value(attribute_name_index);
+ }
+
+ public abstract <R,D> R accept(Attribute.Visitor<R,D> visitor, D data);
+
+ public final int attribute_name_index;
+ public final int attribute_length;
+
+
+ public interface Visitor<R,P> {
+ R visitDefault(DefaultAttribute attr, P p);
+ R visitAnnotationDefault(AnnotationDefault_attribute attr, P p);
+ R visitCharacterRangeTable(CharacterRangeTable_attribute attr, P p);
+ R visitCode(Code_attribute attr, P p);
+ R visitCompilationID(CompilationID_attribute attr, P p);
+ R visitConstantValue(ConstantValue_attribute attr, P p);
+ R visitDeprecated(Deprecated_attribute attr, P p);
+ R visitEnclosingMethod(EnclosingMethod_attribute attr, P p);
+ R visitExceptions(Exceptions_attribute attr, P p);
+ R visitInnerClasses(InnerClasses_attribute attr, P p);
+ R visitLineNumberTable(LineNumberTable_attribute attr, P p);
+ R visitLocalVariableTable(LocalVariableTable_attribute attr, P p);
+ R visitLocalVariableTypeTable(LocalVariableTypeTable_attribute attr, P p);
+ R visitRuntimeVisibleAnnotations(RuntimeVisibleAnnotations_attribute attr, P p);
+ R visitRuntimeInvisibleAnnotations(RuntimeInvisibleAnnotations_attribute attr, P p);
+ R visitRuntimeVisibleParameterAnnotations(RuntimeVisibleParameterAnnotations_attribute attr, P p);
+ R visitRuntimeInvisibleParameterAnnotations(RuntimeInvisibleParameterAnnotations_attribute attr, P p);
+ R visitSignature(Signature_attribute attr, P p);
+ R visitSourceDebugExtension(SourceDebugExtension_attribute attr, P p);
+ R visitSourceFile(SourceFile_attribute attr, P p);
+ R visitSourceID(SourceID_attribute attr, P p);
+ R visitStackMap(StackMap_attribute attr, P p);
+ R visitStackMapTable(StackMapTable_attribute attr, P p);
+ R visitSynthetic(Synthetic_attribute attr, P p);
+
+ R visitModule(Module_attribute attr, P p);
+ R visitModuleExportTable(ModuleExportTable_attribute attr, P p);
+ R visitModuleMemberTable(ModuleMemberTable_attribute attr, P p);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/classes/com/sun/tools/classfile/AttributeException.java Fri Jun 06 15:17:35 2008 -0700
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package com.sun.tools.classfile;
+
+/*
+ * <p><b>This is NOT part of any API supported by Sun Microsystems. If
+ * you write code that depends on this, you do so at your own risk.
+ * This code and its internal interfaces are subject to change or
+ * deletion without notice.</b>
+ */
+public class AttributeException extends Exception {
+ AttributeException() { }
+
+ AttributeException(String msg) {
+ super(msg);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/classes/com/sun/tools/classfile/Attributes.java Fri Jun 06 15:17:35 2008 -0700
@@ -0,0 +1,87 @@
+/*
+ * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package com.sun.tools.classfile;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+/*
+ * <p><b>This is NOT part of any API supported by Sun Microsystems. If
+ * you write code that depends on this, you do so at your own risk.
+ * This code and its internal interfaces are subject to change or
+ * deletion without notice.</b>
+ */
+public class Attributes implements Iterable<Attribute> {
+ Attributes(ClassReader cr) throws IOException {
+ map = new HashMap<String,Attribute>();
+ int attrs_count = cr.readUnsignedShort();
+ attrs = new Attribute[attrs_count];
+ for (int i = 0; i < attrs_count; i++) {
+ Attribute attr = Attribute.read(cr);
+ attrs[i] = attr;
+ try {
+ map.put(attr.getName(cr.getConstantPool()), attr);
+ } catch (ConstantPoolException e) {
+ // don't enter invalid names in map
+ }
+ }
+ }
+
+ public Attributes(ConstantPool constant_pool, Attribute[] attrs) {
+ this.attrs = attrs;
+ map = new HashMap<String,Attribute>();
+ for (int i = 0; i < attrs.length; i++) {
+ Attribute attr = attrs[i];
+ try {
+ map.put(attr.getName(constant_pool), attr);
+ } catch (ConstantPoolException e) {
+ // don't enter invalid names in map
+ }
+ }
+ }
+
+ public Iterator<Attribute> iterator() {
+ return Arrays.asList(attrs).iterator();
+ }
+
+ public Attribute get(int index) {
+ return attrs[index];
+ }
+
+ public Attribute get(String name) {
+ return map.get(name);
+ }
+
+ public int size() {
+ return attrs.length;
+ }
+
+ public final Attribute[] attrs;
+ public final Map<String, Attribute> map;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/classes/com/sun/tools/classfile/CharacterRangeTable_attribute.java Fri Jun 06 15:17:35 2008 -0700
@@ -0,0 +1,90 @@
+/*
+ * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package com.sun.tools.classfile;
+
+import java.io.IOException;
+
+/**
+ * <p><b>This is NOT part of any API supported by Sun Microsystems. If
+ * you write code that depends on this, you do so at your own risk.
+ * This code and its internal interfaces are subject to change or
+ * deletion without notice.</b>
+ */
+public class CharacterRangeTable_attribute extends Attribute {
+ public static final int CRT_STATEMENT = 0x0001;
+ public static final int CRT_BLOCK = 0x0002;
+ public static final int CRT_ASSIGNMENT = 0x0004;
+ public static final int CRT_FLOW_CONTROLLER = 0x0008;
+ public static final int CRT_FLOW_TARGET = 0x0010;
+ public static final int CRT_INVOKE = 0x0020;
+ public static final int CRT_CREATE = 0x0040;
+ public static final int CRT_BRANCH_TRUE = 0x0080;
+ public static final int CRT_BRANCH_FALSE = 0x0100;
+
+ CharacterRangeTable_attribute(ClassReader cr, int name_index, int length) throws IOException {
+ super(name_index, length);
+ int character_range_table_length = cr.readUnsignedShort();
+ character_range_table = new Entry[character_range_table_length];
+ for (int i = 0; i < character_range_table_length; i++)
+ character_range_table[i] = new Entry(cr);
+ }
+
+ public CharacterRangeTable_attribute(ConstantPool constant_pool, Entry[] character_range_table)
+ throws ConstantPoolException {
+ this(constant_pool.getUTF8Index(Attribute.CharacterRangeTable), character_range_table);
+ }
+
+ public CharacterRangeTable_attribute(int name_index, Entry[] character_range_table) {
+ super(name_index, character_range_table.length * Entry.length());
+ this.character_range_table = character_range_table;
+ }
+
+ public <R, D> R accept(Visitor<R, D> visitor, D data) {
+ return visitor.visitCharacterRangeTable(this, data);
+ }
+
+ public final Entry[] character_range_table;
+
+ public static class Entry {
+ Entry(ClassReader cr) throws IOException {
+ start_pc = cr.readUnsignedShort();
+ end_pc = cr.readUnsignedShort();
+ character_range_start = cr.readInt();
+ character_range_end = cr.readInt();
+ flags = cr.readUnsignedShort();
+ }
+
+ public static int length() {
+ return 14;
+ }
+
+ public final int start_pc;
+ public final int end_pc;
+ public final int character_range_start;
+ public final int character_range_end;
+ public final int flags;
+ };
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/classes/com/sun/tools/classfile/ClassFile.java Fri Jun 06 15:17:35 2008 -0700
@@ -0,0 +1,153 @@
+/*
+ * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package com.sun.tools.classfile;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import static com.sun.tools.classfile.AccessFlags.*;
+
+/**
+ * See JVMS3, section 4.2.
+ *
+ * <p><b>This is NOT part of any API supported by Sun Microsystems. If
+ * you write code that depends on this, you do so at your own risk.
+ * This code and its internal interfaces are subject to change or
+ * deletion without notice.</b>
+ */
+public class ClassFile {
+ public static ClassFile read(File file)
+ throws IOException, ConstantPoolException {
+ return read(file, new Attribute.Factory());
+ }
+
+ public static ClassFile read(File file, Attribute.Factory attributeFactory)
+ throws IOException, ConstantPoolException {
+ FileInputStream in = new FileInputStream(file);
+ try {
+ return new ClassFile(in, attributeFactory);
+ } finally {
+ try {
+ in.close();
+ } catch (IOException e) {
+ // ignore
+ }
+ }
+ }
+
+ public static ClassFile read(InputStream in)
+ throws IOException, ConstantPoolException {
+ return new ClassFile(in, new Attribute.Factory());
+ }
+
+ public static ClassFile read(InputStream in, Attribute.Factory attributeFactory)
+ throws IOException, ConstantPoolException {
+ return new ClassFile(in, attributeFactory);
+ }
+
+ ClassFile(InputStream in, Attribute.Factory attributeFactory) throws IOException, ConstantPoolException {
+ ClassReader cr = new ClassReader(this, in, attributeFactory);
+ magic = cr.readInt();
+ minor_version = cr.readUnsignedShort();
+ major_version = cr.readUnsignedShort();
+ constant_pool = new ConstantPool(cr);
+ access_flags = new AccessFlags(cr);
+ this_class = cr.readUnsignedShort();
+ super_class = cr.readUnsignedShort();
+
+ int interfaces_count = cr.readUnsignedShort();
+ interfaces = new int[interfaces_count];
+ for (int i = 0; i < interfaces_count; i++)
+ interfaces[i] = cr.readUnsignedShort();
+
+ int fields_count = cr.readUnsignedShort();
+ fields = new Field[fields_count];
+ for (int i = 0; i < fields_count; i++)
+ fields[i] = new Field(cr);
+
+ int methods_count = cr.readUnsignedShort();
+ methods = new Method[methods_count];
+ for (int i = 0; i < methods_count; i++)
+ methods[i] = new Method(cr);
+
+ attributes = new Attributes(cr);
+ }
+
+ public ClassFile(int magic, int minor_version, int major_version,
+ ConstantPool constant_pool, AccessFlags access_flags,
+ int this_class, int super_class, int[] interfaces,
+ Field[] fields, Method[] methods, Attributes attributes) {
+ this.magic = magic;
+ this.minor_version = minor_version;
+ this.major_version = major_version;
+ this.constant_pool = constant_pool;
+ this.access_flags = access_flags;
+ this.this_class = this_class;
+ this.super_class = super_class;
+ this.interfaces = interfaces;
+ this.fields = fields;
+ this.methods = methods;
+ this.attributes = attributes;
+ }
+
+ public String getName() throws ConstantPoolException {
+ return constant_pool.getClassInfo(this_class).getName();
+ }
+
+ public String getSuperclassName() throws ConstantPoolException {
+ return constant_pool.getClassInfo(super_class).getName();
+ }
+
+ public String getInterfaceName(int i) throws ConstantPoolException {
+ return constant_pool.getClassInfo(interfaces[i]).getName();
+ }
+
+ public Attribute getAttribute(String name) {
+ return attributes.get(name);
+ }
+
+ public boolean isClass() {
+ return !isInterface();
+ }
+
+ public boolean isInterface() {
+ return access_flags.is(ACC_INTERFACE);
+ }
+
+ public final int magic;
+ public final int minor_version;
+ public final int major_version;
+ public final ConstantPool constant_pool;
+ public final AccessFlags access_flags;
+ public final int this_class;
+ public final int super_class;
+ public final int[] interfaces;
+ public final Field[] fields;
+ public final Method[] methods;
+ public final Attributes attributes;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/classes/com/sun/tools/classfile/ClassReader.java Fri Jun 06 15:17:35 2008 -0700
@@ -0,0 +1,109 @@
+/*
+ * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package com.sun.tools.classfile;
+
+import java.io.BufferedInputStream;
+import java.io.ByteArrayInputStream;
+import java.io.DataInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * <p><b>This is NOT part of any API supported by Sun Microsystems. If
+ * you write code that depends on this, you do so at your own risk.
+ * This code and its internal interfaces are subject to change or
+ * deletion without notice.</b>
+ */
+public class ClassReader {
+ ClassReader(ClassFile classFile, InputStream in, Attribute.Factory attributeFactory) throws IOException {
+ // null checks
+ classFile.getClass();
+ attributeFactory.getClass();
+
+ this.classFile = classFile;
+ this.in = new DataInputStream(new BufferedInputStream(in));
+ this.attributeFactory = attributeFactory;
+ }
+
+ ClassFile getClassFile() {
+ return classFile;
+ }
+
+ ConstantPool getConstantPool() {
+ return classFile.constant_pool;
+ }
+
+ public Attribute readAttribute() throws IOException {
+ int name_index = readUnsignedShort();
+ int length = readInt();
+ byte[] data = new byte[length];
+ readFully(data);
+
+ DataInputStream prev = in;
+ in = new DataInputStream(new ByteArrayInputStream(data));
+ try {
+ return attributeFactory.createAttribute(this, name_index, data);
+ } finally {
+ in = prev;
+ }
+ }
+
+ public void readFully(byte[] b) throws IOException {
+ in.readFully(b);
+ }
+
+ public int readUnsignedByte() throws IOException {
+ return in.readUnsignedByte();
+ }
+
+ public int readUnsignedShort() throws IOException {
+ return in.readUnsignedShort();
+ }
+
+ public int readInt() throws IOException {
+ return in.readInt();
+ }
+
+ public long readLong() throws IOException {
+ return in.readLong();
+ }
+
+ public float readFloat() throws IOException {
+ return in.readFloat();
+ }
+
+ public double readDouble() throws IOException {
+ return in.readDouble();
+ }
+
+ public String readUTF() throws IOException {
+ return in.readUTF();
+ }
+
+ private DataInputStream in;
+ private ClassFile classFile;
+ private Attribute.Factory attributeFactory;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/classes/com/sun/tools/classfile/ClassTranslator.java Fri Jun 06 15:17:35 2008 -0700
@@ -0,0 +1,368 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package com.sun.tools.classfile;
+
+import com.sun.tools.classfile.ConstantPool.CONSTANT_Class_info;
+import com.sun.tools.classfile.ConstantPool.CONSTANT_Double_info;
+import com.sun.tools.classfile.ConstantPool.CONSTANT_Fieldref_info;
+import com.sun.tools.classfile.ConstantPool.CONSTANT_Float_info;
+import com.sun.tools.classfile.ConstantPool.CONSTANT_Integer_info;
+import com.sun.tools.classfile.ConstantPool.CONSTANT_InterfaceMethodref_info;
+import com.sun.tools.classfile.ConstantPool.CONSTANT_Long_info;
+import com.sun.tools.classfile.ConstantPool.CONSTANT_Methodref_info;
+import com.sun.tools.classfile.ConstantPool.CONSTANT_NameAndType_info;
+import com.sun.tools.classfile.ConstantPool.CONSTANT_String_info;
+import com.sun.tools.classfile.ConstantPool.CONSTANT_Utf8_info;
+import com.sun.tools.classfile.ConstantPool.CPInfo;
+import java.util.Map;
+
+/**
+ * Rewrites a class file using a map of translations.
+ *
+ * <p><b>This is NOT part of any API supported by Sun Microsystems. If
+ * you write code that depends on this, you do so at your own risk.
+ * This code and its internal interfaces are subject to change or
+ * deletion without notice.</b>
+ */
+public class ClassTranslator
+ implements ConstantPool.Visitor<ConstantPool.CPInfo,Map<Object,Object>> {
+ /**
+ * Create a new ClassFile from {@code cf}, such that for all entries
+ * {@code k -\> v} in {@code translations},
+ * each occurrence of {@code k} in {@code cf} will be replaced by {@code v}.
+ * in
+ * @param cf the class file to be processed
+ * @param translations the set of translations to be applied
+ * @return a copy of {@code} with the values in {@code translations} substituted
+ */
+ public ClassFile translate(ClassFile cf, Map<Object,Object> translations) {
+ ClassFile cf2 = (ClassFile) translations.get(cf);
+ if (cf2 == null) {
+ ConstantPool constant_pool2 = translate(cf.constant_pool, translations);
+ Field[] fields2 = translate(cf.fields, cf.constant_pool, translations);
+ Method[] methods2 = translateMethods(cf.methods, cf.constant_pool, translations);
+ Attributes attributes2 = translateAttributes(cf.attributes, cf.constant_pool,
+ translations);
+
+ if (constant_pool2 == cf.constant_pool &&
+ fields2 == cf.fields &&
+ methods2 == cf.methods &&
+ attributes2 == cf.attributes)
+ cf2 = cf;
+ else
+ cf2 = new ClassFile(
+ cf.magic,
+ cf.minor_version,
+ cf.major_version,
+ constant_pool2,
+ cf.access_flags,
+ cf.this_class,
+ cf.super_class,
+ cf.interfaces,
+ fields2,
+ methods2,
+ attributes2);
+ translations.put(cf, cf2);
+ }
+ return cf2;
+ }
+
+ ConstantPool translate(ConstantPool cp, Map<Object,Object> translations) {
+ ConstantPool cp2 = (ConstantPool) translations.get(cp);
+ if (cp2 == null) {
+ ConstantPool.CPInfo[] pool2 = new ConstantPool.CPInfo[cp.size()];
+ boolean eq = true;
+ for (int i = 0; i < cp.size(); i++) {
+ ConstantPool.CPInfo cpInfo;
+ try {
+ cpInfo = cp.get(i);
+ } catch (ConstantPool.InvalidIndex e) {
+ throw new IllegalStateException(e);
+ }
+ ConstantPool.CPInfo cpInfo2 = translate(cpInfo, translations);
+ eq &= (cpInfo == cpInfo2);
+ pool2[i] = cpInfo2;
+ if (cpInfo.getTag() != cpInfo2.getTag())
+ throw new IllegalStateException();
+ switch (cpInfo.getTag()) {
+ case ConstantPool.CONSTANT_Double:
+ case ConstantPool.CONSTANT_Long:
+ i += 1;
+ }
+ }
+
+ if (eq)
+ cp2 = cp;
+ else
+ cp2 = new ConstantPool(pool2);
+
+ translations.put(cp, cp2);
+ }
+ return cp2;
+ }
+
+ ConstantPool.CPInfo translate(ConstantPool.CPInfo cpInfo, Map<Object,Object> translations) {
+ ConstantPool.CPInfo cpInfo2 = (ConstantPool.CPInfo) translations.get(cpInfo);
+ if (cpInfo2 == null) {
+ cpInfo2 = cpInfo.accept(this, translations);
+ translations.put(cpInfo, cpInfo2);
+ }
+ return cpInfo2;
+ }
+
+ Field[] translate(Field[] fields, ConstantPool constant_pool, Map<Object,Object> translations) {
+ Field[] fields2 = (Field[]) translations.get(fields);
+ if (fields2 == null) {
+ fields2 = new Field[fields.length];
+ for (int i = 0; i < fields.length; i++)
+ fields2[i] = translate(fields[i], constant_pool, translations);
+ if (equal(fields, fields2))
+ fields2 = fields;
+ translations.put(fields, fields2);
+ }
+ return fields2;
+ }
+
+ Field translate(Field field, ConstantPool constant_pool, Map<Object,Object> translations) {
+ Field field2 = (Field) translations.get(field);
+ if (field2 == null) {
+ Attributes attributes2 = translateAttributes(field.attributes, constant_pool,
+ translations);
+
+ if (attributes2 == field.attributes)
+ field2 = field;
+ else
+ field2 = new Field(
+ field.access_flags,
+ field.name_index,
+ field.descriptor,
+ attributes2);
+ translations.put(field, field2);
+ }
+ return field2;
+ }
+
+ Method[] translateMethods(Method[] methods, ConstantPool constant_pool, Map<Object,Object> translations) {
+ Method[] methods2 = (Method[]) translations.get(methods);
+ if (methods2 == null) {
+ methods2 = new Method[methods.length];
+ for (int i = 0; i < methods.length; i++)
+ methods2[i] = translate(methods[i], constant_pool, translations);
+ if (equal(methods, methods2))
+ methods2 = methods;
+ translations.put(methods, methods2);
+ }
+ return methods2;
+ }
+
+ Method translate(Method method, ConstantPool constant_pool, Map<Object,Object> translations) {
+ Method method2 = (Method) translations.get(method);
+ if (method2 == null) {
+ Attributes attributes2 = translateAttributes(method.attributes, constant_pool,
+ translations);
+
+ if (attributes2 == method.attributes)
+ method2 = method;
+ else
+ method2 = new Method(
+ method.access_flags,
+ method.name_index,
+ method.descriptor,
+ attributes2);
+ translations.put(method, method2);
+ }
+ return method2;
+ }
+
+ Attributes translateAttributes(Attributes attributes,
+ ConstantPool constant_pool, Map<Object,Object> translations) {
+ Attributes attributes2 = (Attributes) translations.get(attributes);
+ if (attributes2 == null) {
+ Attribute[] attrArray2 = new Attribute[attributes.size()];
+ ConstantPool constant_pool2 = translate(constant_pool, translations);
+ boolean attrsEqual = true;
+ for (int i = 0; i < attributes.size(); i++) {
+ Attribute attr = attributes.get(i);
+ Attribute attr2 = translate(attr, translations);
+ if (attr2 != attr)
+ attrsEqual = false;
+ attrArray2[i] = attr2;
+ }
+ if ((constant_pool2 == constant_pool) && attrsEqual)
+ attributes2 = attributes;
+ else
+ attributes2 = new Attributes(constant_pool2, attrArray2);
+ translations.put(attributes, attributes2);
+ }
+ return attributes2;
+ }
+
+ Attribute translate(Attribute attribute, Map<Object,Object> translations) {
+ Attribute attribute2 = (Attribute) translations.get(attribute);
+ if (attribute2 == null) {
+ attribute2 = attribute; // don't support translation within attributes yet
+ // (what about Code attribute)
+ translations.put(attribute, attribute2);
+ }
+ return attribute2;
+ }
+
+ private static <T> boolean equal(T[] a1, T[] a2) {
+ if (a1 == null || a2 == null)
+ return (a1 == a2);
+ if (a1.length != a2.length)
+ return false;
+ for (int i = 0; i < a1.length; i++) {
+ if (a1[i] != a2[i])
+ return false;
+ }
+ return true;
+ }
+
+ public CPInfo visitClass(CONSTANT_Class_info info, Map<Object, Object> translations) {
+ CONSTANT_Class_info info2 = (CONSTANT_Class_info) translations.get(info);
+ if (info2 == null) {
+ ConstantPool cp2 = translate(info.cp, translations);
+ if (cp2 == info.cp)
+ info2 = info;
+ else
+ info2 = new CONSTANT_Class_info(cp2, info.name_index);
+ translations.put(info, info2);
+ }
+ return info;
+ }
+
+ public CPInfo visitDouble(CONSTANT_Double_info info, Map<Object, Object> translations) {
+ CONSTANT_Double_info info2 = (CONSTANT_Double_info) translations.get(info);
+ if (info2 == null) {
+ info2 = info;
+ translations.put(info, info2);
+ }
+ return info;
+ }
+
+ public CPInfo visitFieldref(CONSTANT_Fieldref_info info, Map<Object, Object> translations) {
+ CONSTANT_Fieldref_info info2 = (CONSTANT_Fieldref_info) translations.get(info);
+ if (info2 == null) {
+ ConstantPool cp2 = translate(info.cp, translations);
+ if (cp2 == info.cp)
+ info2 = info;
+ else
+ info2 = new CONSTANT_Fieldref_info(cp2, info.class_index, info.name_and_type_index);
+ translations.put(info, info2);
+ }
+ return info;
+ }
+
+ public CPInfo visitFloat(CONSTANT_Float_info info, Map<Object, Object> translations) {
+ CONSTANT_Float_info info2 = (CONSTANT_Float_info) translations.get(info);
+ if (info2 == null) {
+ info2 = info;
+ translations.put(info, info2);
+ }
+ return info;
+ }
+
+ public CPInfo visitInteger(CONSTANT_Integer_info info, Map<Object, Object> translations) {
+ CONSTANT_Integer_info info2 = (CONSTANT_Integer_info) translations.get(info);
+ if (info2 == null) {
+ info2 = info;
+ translations.put(info, info2);
+ }
+ return info;
+ }
+
+ public CPInfo visitInterfaceMethodref(CONSTANT_InterfaceMethodref_info info, Map<Object, Object> translations) {
+ CONSTANT_InterfaceMethodref_info info2 = (CONSTANT_InterfaceMethodref_info) translations.get(info);
+ if (info2 == null) {
+ ConstantPool cp2 = translate(info.cp, translations);
+ if (cp2 == info.cp)
+ info2 = info;
+ else
+ info2 = new CONSTANT_InterfaceMethodref_info(cp2, info.class_index, info.name_and_type_index);
+ translations.put(info, info2);
+ }
+ return info;
+ }
+
+ public CPInfo visitLong(CONSTANT_Long_info info, Map<Object, Object> translations) {
+ CONSTANT_Long_info info2 = (CONSTANT_Long_info) translations.get(info);
+ if (info2 == null) {
+ info2 = info;
+ translations.put(info, info2);
+ }
+ return info;
+ }
+
+ public CPInfo visitNameAndType(CONSTANT_NameAndType_info info, Map<Object, Object> translations) {
+ CONSTANT_NameAndType_info info2 = (CONSTANT_NameAndType_info) translations.get(info);
+ if (info2 == null) {
+ ConstantPool cp2 = translate(info.cp, translations);
+ if (cp2 == info.cp)
+ info2 = info;
+ else
+ info2 = new CONSTANT_NameAndType_info(cp2, info.name_index, info.type_index);
+ translations.put(info, info2);
+ }
+ return info;
+ }
+
+ public CPInfo visitMethodref(CONSTANT_Methodref_info info, Map<Object, Object> translations) {
+ CONSTANT_Methodref_info info2 = (CONSTANT_Methodref_info) translations.get(info);
+ if (info2 == null) {
+ ConstantPool cp2 = translate(info.cp, translations);
+ if (cp2 == info.cp)
+ info2 = info;
+ else
+ info2 = new CONSTANT_Methodref_info(cp2, info.class_index, info.name_and_type_index);
+ translations.put(info, info2);
+ }
+ return info;
+ }
+
+ public CPInfo visitString(CONSTANT_String_info info, Map<Object, Object> translations) {
+ CONSTANT_String_info info2 = (CONSTANT_String_info) translations.get(info);
+ if (info2 == null) {
+ ConstantPool cp2 = translate(info.cp, translations);
+ if (cp2 == info.cp)
+ info2 = info;
+ else
+ info2 = new CONSTANT_String_info(cp2, info.string_index);
+ translations.put(info, info2);
+ }
+ return info;
+ }
+
+ public CPInfo visitUtf8(CONSTANT_Utf8_info info, Map<Object, Object> translations) {
+ CONSTANT_Utf8_info info2 = (CONSTANT_Utf8_info) translations.get(info);
+ if (info2 == null) {
+ info2 = info;
+ translations.put(info, info2);
+ }
+ return info;
+ }
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/classes/com/sun/tools/classfile/ClassWriter.java Fri Jun 06 15:17:35 2008 -0700
@@ -0,0 +1,689 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package com.sun.tools.classfile;
+
+import java.io.ByteArrayOutputStream;
+import java.io.DataOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+
+import static com.sun.tools.classfile.Annotation.*;
+import static com.sun.tools.classfile.ConstantPool.*;
+import static com.sun.tools.classfile.StackMapTable_attribute.*;
+import static com.sun.tools.classfile.StackMapTable_attribute.verification_type_info.*;
+
+/**
+ * Write a ClassFile data structure to a file or stream.
+ *
+ * <p><b>This is NOT part of any API supported by Sun Microsystems. If
+ * you write code that depends on this, you do so at your own risk.
+ * This code and its internal interfaces are subject to change or
+ * deletion without notice.</b>
+ */
+public class ClassWriter {
+ public ClassWriter() {
+ attributeWriter = new AttributeWriter();
+ constantPoolWriter = new ConstantPoolWriter();
+ out = new ClassOutputStream();
+ }
+
+ /**
+ * Write a ClassFile data structure to a file.
+ */
+ public void write(ClassFile classFile, File f) throws IOException {
+ FileOutputStream f_out = new FileOutputStream(f);
+ try {
+ write(classFile, f_out);
+ } finally {
+ f_out.close();
+ }
+ }
+
+ /**
+ * Write a ClassFile data structure to a stream.
+ */
+ public void write(ClassFile classFile, OutputStream s) throws IOException {
+ this.classFile = classFile;
+ out.reset();
+ write();
+ out.writeTo(s);
+ }
+
+ protected void write() throws IOException {
+ writeHeader();
+ writeConstantPool();
+ writeAccessFlags(classFile.access_flags);
+ writeClassInfo();
+ writeFields();
+ writeMethods();
+ writeAttributes(classFile.attributes);
+ }
+
+ protected void writeHeader() {
+ out.writeInt(classFile.magic);
+ out.writeShort(classFile.minor_version);
+ out.writeShort(classFile.major_version);
+ }
+
+ protected void writeAccessFlags(AccessFlags flags) {
+ out.writeShort(flags.flags);
+ }
+
+ protected void writeAttributes(Attributes attributes) {
+ int size = attributes.size();
+ out.writeShort(size);
+ for (Attribute attr: attributes)
+ attributeWriter.write(attr, out);
+ }
+
+ protected void writeClassInfo() {
+ out.writeShort(classFile.this_class);
+ out.writeShort(classFile.super_class);
+ int[] interfaces = classFile.interfaces;
+ out.writeShort(interfaces.length);
+ for (int i: interfaces)
+ out.writeShort(i);
+ }
+
+ protected void writeDescriptor(Descriptor d) {
+ out.writeShort(d.index);
+ }
+
+ protected void writeConstantPool() {
+ ConstantPool pool = classFile.constant_pool;
+ int size = pool.size();
+ out.writeShort(size);
+ try {
+ for (int i = 1; i < size; ) {
+ i += constantPoolWriter.write(pool.get(i), out);
+ }
+ } catch (ConstantPoolException e) {
+ throw new Error(e); // ??
+ }
+ }
+
+ protected void writeFields() throws IOException {
+ Field[] fields = classFile.fields;
+ out.writeShort(fields.length);
+ for (Field f: fields)
+ writeField(f);
+ }
+
+ protected void writeField(Field f) throws IOException {
+ writeAccessFlags(f.access_flags);
+ out.writeShort(f.name_index);
+ writeDescriptor(f.descriptor);
+ writeAttributes(f.attributes);
+ }
+
+ protected void writeMethods() throws IOException {
+ Method[] methods = classFile.methods;
+ out.writeShort(methods.length);
+ for (Method m: methods) {
+ writeMethod(m);
+ }
+ }
+
+ protected void writeMethod(Method m) throws IOException {
+ writeAccessFlags(m.access_flags);
+ out.writeShort(m.name_index);
+ writeDescriptor(m.descriptor);
+ writeAttributes(m.attributes);
+ }
+
+ protected ClassFile classFile;
+ protected ClassOutputStream out;
+ protected AttributeWriter attributeWriter;
+ protected ConstantPoolWriter constantPoolWriter;
+
+ /**
+ * Subtype of ByteArrayOutputStream with the convenience methods of
+ * a DataOutputStream. Since ByteArrayOutputStream does not throw
+ * IOException, there are no exceptions from the additional
+ * convenience methods either,
+ */
+ protected static class ClassOutputStream extends ByteArrayOutputStream {
+ public ClassOutputStream() {
+ d = new DataOutputStream(this);
+ }
+
+ public void writeByte(int value) {
+ try {
+ d.writeByte(value);
+ } catch (IOException ignore) {
+ }
+ }
+
+ public void writeShort(int value) {
+ try {
+ d.writeShort(value);
+ } catch (IOException ignore) {
+ }
+ }
+
+ public void writeInt(int value) {
+ try {
+ d.writeInt(value);
+ } catch (IOException ignore) {
+ }
+ }
+
+ public void writeLong(long value) {
+ try {
+ d.writeLong(value);
+ } catch (IOException ignore) {
+ }
+ }
+
+ public void writeFloat(float value) {
+ try {
+ d.writeFloat(value);
+ } catch (IOException ignore) {
+ }
+ }
+
+ public void writeDouble(double value) {
+ try {
+ d.writeDouble(value);
+ } catch (IOException ignore) {
+ }
+ }
+
+ public void writeUTF(String value) {
+ try {
+ d.writeUTF(value);
+ } catch (IOException ignore) {
+ }
+ }
+
+ public void writeTo(ClassOutputStream s) {
+ try {
+ super.writeTo(s);
+ } catch (IOException ignore) {
+ }
+ }
+
+ private DataOutputStream d;
+ }
+
+ /**
+ * Writer for the entries in the constant pool.
+ */
+ protected static class ConstantPoolWriter
+ implements ConstantPool.Visitor<Integer,ClassOutputStream> {
+ protected int write(CPInfo info, ClassOutputStream out) {
+ out.writeByte(info.getTag());
+ return info.accept(this, out);
+ }
+
+ public Integer visitClass(CONSTANT_Class_info info, ClassOutputStream out) {
+ out.writeShort(info.name_index);
+ return 1;
+ }
+
+ public Integer visitDouble(CONSTANT_Double_info info, ClassOutputStream out) {
+ out.writeDouble(info.value);
+ return 2;
+ }
+
+ public Integer visitFieldref(CONSTANT_Fieldref_info info, ClassOutputStream out) {
+ writeRef(info, out);
+ return 1;
+ }
+
+ public Integer visitFloat(CONSTANT_Float_info info, ClassOutputStream out) {
+ out.writeFloat(info.value);
+ return 1;
+ }
+
+ public Integer visitInteger(CONSTANT_Integer_info info, ClassOutputStream out) {
+ out.writeInt(info.value);
+ return 1;
+ }
+
+ public Integer visitInterfaceMethodref(CONSTANT_InterfaceMethodref_info info, ClassOutputStream out) {
+ writeRef(info, out);
+ return 1;
+ }
+
+ public Integer visitLong(CONSTANT_Long_info info, ClassOutputStream out) {
+ out.writeLong(info.value);
+ return 2;
+ }
+
+ public Integer visitNameAndType(CONSTANT_NameAndType_info info, ClassOutputStream out) {
+ out.writeShort(info.name_index);
+ out.writeShort(info.type_index);
+ return 1;
+ }
+
+ public Integer visitMethodref(CONSTANT_Methodref_info info, ClassOutputStream out) {
+ return writeRef(info, out);
+ }
+
+ public Integer visitString(CONSTANT_String_info info, ClassOutputStream out) {
+ out.writeShort(info.string_index);
+ return 1;
+ }
+
+ public Integer visitUtf8(CONSTANT_Utf8_info info, ClassOutputStream out) {
+ out.writeUTF(info.value);
+ return 1;
+ }
+
+ protected Integer writeRef(CPRefInfo info, ClassOutputStream out) {
+ out.writeShort(info.class_index);
+ out.writeShort(info.name_and_type_index);
+ return 1;
+ }
+ }
+
+ /**
+ * Writer for the different types of attribute.
+ */
+ protected static class AttributeWriter implements Attribute.Visitor<Void,ClassOutputStream> {
+ public void write(Attributes attributes, ClassOutputStream out) {
+ int size = attributes.size();
+ out.writeShort(size);
+ for (Attribute a: attributes)
+ write(a, out);
+ }
+
+ // Note: due to the use of shared resources, this method is not reentrant.
+ public void write(Attribute attr, ClassOutputStream out) {
+ out.writeShort(attr.attribute_name_index);
+ sharedOut.reset();
+ attr.accept(this, sharedOut);
+ out.writeInt(sharedOut.size());
+ sharedOut.writeTo(out);
+ }
+
+ protected ClassOutputStream sharedOut = new ClassOutputStream();
+ protected AnnotationWriter annotationWriter = new AnnotationWriter();
+
+ public Void visitDefault(DefaultAttribute attr, ClassOutputStream out) {
+ out.write(attr.info, 0, attr.info.length);
+ return null;
+ }
+
+ public Void visitAnnotationDefault(AnnotationDefault_attribute attr, ClassOutputStream out) {
+ annotationWriter.write(attr.default_value, out);
+ return null;
+ }
+
+ public Void visitCharacterRangeTable(CharacterRangeTable_attribute attr, ClassOutputStream out) {
+ out.writeShort(attr.character_range_table.length);
+ for (CharacterRangeTable_attribute.Entry e: attr.character_range_table)
+ writeCharacterRangeTableEntry(e, out);
+ return null;
+ }
+
+ protected void writeCharacterRangeTableEntry(CharacterRangeTable_attribute.Entry entry, ClassOutputStream out) {
+ out.writeShort(entry.start_pc);
+ out.writeShort(entry.end_pc);
+ out.writeInt(entry.character_range_start);
+ out.writeInt(entry.character_range_end);
+ out.writeShort(entry.flags);
+ }
+
+ public Void visitCode(Code_attribute attr, ClassOutputStream out) {
+ out.writeShort(attr.max_stack);
+ out.writeShort(attr.max_locals);
+ out.writeInt(attr.code.length);
+ out.write(attr.code, 0, attr.code.length);
+ out.writeShort(attr.exception_table.length);
+ for (Code_attribute.Exception_data e: attr.exception_table)
+ writeExceptionTableEntry(e, out);
+ new AttributeWriter().write(attr.attributes, out);
+ return null;
+ }
+
+ protected void writeExceptionTableEntry(Code_attribute.Exception_data exception_data, ClassOutputStream out) {
+ out.writeShort(exception_data.start_pc);
+ out.writeShort(exception_data.end_pc);
+ out.writeShort(exception_data.handler_pc);
+ out.writeShort(exception_data.catch_type);
+ }
+
+ public Void visitCompilationID(CompilationID_attribute attr, ClassOutputStream out) {
+ out.writeShort(attr.compilationID_index);
+ return null;
+ }
+
+ public Void visitConstantValue(ConstantValue_attribute attr, ClassOutputStream out) {
+ out.writeShort(attr.constantvalue_index);
+ return null;
+ }
+
+ public Void visitDeprecated(Deprecated_attribute attr, ClassOutputStream out) {
+ return null;
+ }
+
+ public Void visitEnclosingMethod(EnclosingMethod_attribute attr, ClassOutputStream out) {
+ out.writeShort(attr.class_index);
+ out.writeShort(attr.method_index);
+ return null;
+ }
+
+ public Void visitExceptions(Exceptions_attribute attr, ClassOutputStream out) {
+ out.writeShort(attr.exception_index_table.length);
+ for (int i: attr.exception_index_table)
+ out.writeShort(i);
+ return null;
+ }
+
+ public Void visitInnerClasses(InnerClasses_attribute attr, ClassOutputStream out) {
+ out.writeShort(attr.classes.length);
+ for (InnerClasses_attribute.Info info: attr.classes)
+ writeInnerClassesInfo(info, out);
+ return null;
+ }
+
+ protected void writeInnerClassesInfo(InnerClasses_attribute.Info info, ClassOutputStream out) {
+ out.writeShort(info.inner_class_info_index);
+ out.writeShort(info.outer_class_info_index);
+ out.writeShort(info.inner_name_index);
+ writeAccessFlags(info.inner_class_access_flags, out);
+ }
+
+ public Void visitLineNumberTable(LineNumberTable_attribute attr, ClassOutputStream out) {
+ out.writeShort(attr.line_number_table.length);
+ for (LineNumberTable_attribute.Entry e: attr.line_number_table)
+ writeLineNumberTableEntry(e, out);
+ return null;
+ }
+
+ protected void writeLineNumberTableEntry(LineNumberTable_attribute.Entry entry, ClassOutputStream out) {
+ out.writeShort(entry.start_pc);
+ out.writeShort(entry.line_number);
+ }
+
+ public Void visitLocalVariableTable(LocalVariableTable_attribute attr, ClassOutputStream out) {
+ out.writeShort(attr.local_variable_table.length);
+ for (LocalVariableTable_attribute.Entry e: attr.local_variable_table)
+ writeLocalVariableTableEntry(e, out);
+ return null;
+ }
+
+ protected void writeLocalVariableTableEntry(LocalVariableTable_attribute.Entry entry, ClassOutputStream out) {
+ out.writeShort(entry.start_pc);
+ out.writeShort(entry.length);
+ out.writeShort(entry.name_index);
+ out.writeShort(entry.descriptor_index);
+ out.writeShort(entry.index);
+ }
+
+ public Void visitLocalVariableTypeTable(LocalVariableTypeTable_attribute attr, ClassOutputStream out) {
+ out.writeByte(attr.local_variable_table.length);
+ for (LocalVariableTypeTable_attribute.Entry e: attr.local_variable_table)
+ writeLocalVariableTypeTableEntry(e, out);
+ return null;
+ }
+
+ protected void writeLocalVariableTypeTableEntry(LocalVariableTypeTable_attribute.Entry entry, ClassOutputStream out) {
+ out.writeShort(entry.start_pc);
+ out.writeShort(entry.length);
+ out.writeShort(entry.name_index);
+ out.writeShort(entry.signature_index);
+ out.writeShort(entry.index);
+ }
+
+ public Void visitModule(Module_attribute attr, ClassOutputStream out) {
+ out.writeShort(attr.module_name);
+ return null;
+ }
+
+ public Void visitModuleExportTable(ModuleExportTable_attribute attr, ClassOutputStream out) {
+ out.writeShort(attr.export_type_table.length);
+ for (int i: attr.export_type_table)
+ out.writeShort(i);
+ return null;
+ }
+
+ public Void visitModuleMemberTable(ModuleMemberTable_attribute attr, ClassOutputStream out) {
+ out.writeShort(attr.package_member_table.length);
+ for (int i: attr.package_member_table)
+ out.writeShort(i);
+ return null;
+ }
+
+ public Void visitRuntimeVisibleAnnotations(RuntimeVisibleAnnotations_attribute attr, ClassOutputStream out) {
+ annotationWriter.write(attr.annotations, out);
+ return null;
+ }
+
+ public Void visitRuntimeInvisibleAnnotations(RuntimeInvisibleAnnotations_attribute attr, ClassOutputStream out) {
+ annotationWriter.write(attr.annotations, out);
+ return null;
+ }
+
+ public Void visitRuntimeVisibleParameterAnnotations(RuntimeVisibleParameterAnnotations_attribute attr, ClassOutputStream out) {
+ out.writeByte(attr.parameter_annotations.length);
+ for (Annotation[] annos: attr.parameter_annotations)
+ annotationWriter.write(annos, out);
+ return null;
+ }
+
+ public Void visitRuntimeInvisibleParameterAnnotations(RuntimeInvisibleParameterAnnotations_attribute attr, ClassOutputStream out) {
+ out.writeByte(attr.parameter_annotations.length);
+ for (Annotation[] annos: attr.parameter_annotations)
+ annotationWriter.write(annos, out);
+ return null;
+ }
+
+ public Void visitSignature(Signature_attribute attr, ClassOutputStream out) {
+ out.writeShort(attr.signature_index);
+ return null;
+ }
+
+ public Void visitSourceDebugExtension(SourceDebugExtension_attribute attr, ClassOutputStream out) {
+ out.write(attr.debug_extension, 0, attr.debug_extension.length);
+ return null;
+ }
+
+ public Void visitSourceFile(SourceFile_attribute attr, ClassOutputStream out) {
+ out.writeShort(attr.sourcefile_index);
+ return null;
+ }
+
+ public Void visitSourceID(SourceID_attribute attr, ClassOutputStream out) {
+ out.writeShort(attr.sourceID_index);
+ return null;
+ }
+
+ public Void visitStackMap(StackMap_attribute attr, ClassOutputStream out) {
+ if (stackMapWriter == null)
+ stackMapWriter = new StackMapTableWriter();
+
+ out.writeShort(attr.entries.length);
+ for (stack_map_frame f: attr.entries)
+ stackMapWriter.write(f, out);
+ return null;
+ }
+
+ public Void visitStackMapTable(StackMapTable_attribute attr, ClassOutputStream out) {
+ if (stackMapWriter == null)
+ stackMapWriter = new StackMapTableWriter();
+
+ out.writeShort(attr.entries.length);
+ for (stack_map_frame f: attr.entries)
+ stackMapWriter.write(f, out);
+ return null;
+ }
+
+ public Void visitSynthetic(Synthetic_attribute attr, ClassOutputStream out) {
+ return null;
+ }
+
+ protected void writeAccessFlags(AccessFlags flags, ClassOutputStream p) {
+ sharedOut.writeShort(flags.flags);
+ }
+
+ protected StackMapTableWriter stackMapWriter;
+ }
+
+ /**
+ * Writer for the frames of StackMap and StackMapTable attributes.
+ */
+ protected static class StackMapTableWriter
+ implements stack_map_frame.Visitor<Void,ClassOutputStream> {
+
+ public void write(stack_map_frame frame, ClassOutputStream out) {
+ out.write(frame.frame_type);
+ frame.accept(this, out);
+ }
+
+ public Void visit_same_frame(same_frame frame, ClassOutputStream p) {
+ return null;
+ }
+
+ public Void visit_same_locals_1_stack_item_frame(same_locals_1_stack_item_frame frame, ClassOutputStream out) {
+ writeVerificationTypeInfo(frame.stack[0], out);
+ return null;
+ }
+
+ public Void visit_same_locals_1_stack_item_frame_extended(same_locals_1_stack_item_frame_extended frame, ClassOutputStream out) {
+ out.writeShort(frame.offset_delta);
+ writeVerificationTypeInfo(frame.stack[0], out);
+ return null;
+ }
+
+ public Void visit_chop_frame(chop_frame frame, ClassOutputStream out) {
+ out.writeShort(frame.offset_delta);
+ return null;
+ }
+
+ public Void visit_same_frame_extended(same_frame_extended frame, ClassOutputStream out) {
+ out.writeShort(frame.offset_delta);
+ return null;
+ }
+
+ public Void visit_append_frame(append_frame frame, ClassOutputStream out) {
+ out.writeShort(frame.offset_delta);
+ for (verification_type_info l: frame.locals)
+ writeVerificationTypeInfo(l, out);
+ return null;
+ }
+
+ public Void visit_full_frame(full_frame frame, ClassOutputStream out) {
+ out.writeShort(frame.offset_delta);
+ out.writeShort(frame.locals.length);
+ for (verification_type_info l: frame.locals)
+ writeVerificationTypeInfo(l, out);
+ out.writeShort(frame.stack.length);
+ for (verification_type_info s: frame.stack)
+ writeVerificationTypeInfo(s, out);
+ return null;
+ }
+
+ protected void writeVerificationTypeInfo(verification_type_info info,
+ ClassOutputStream out) {
+ out.write(info.tag);
+ switch (info.tag) {
+ case ITEM_Top:
+ case ITEM_Integer:
+ case ITEM_Float:
+ case ITEM_Long:
+ case ITEM_Double:
+ case ITEM_Null:
+ case ITEM_UninitializedThis:
+ break;
+
+ case ITEM_Object:
+ Object_variable_info o = (Object_variable_info) info;
+ out.writeShort(o.cpool_index);
+ break;
+
+ case ITEM_Uninitialized:
+ Uninitialized_variable_info u = (Uninitialized_variable_info) info;
+ out.writeShort(u.offset);
+ break;
+
+ default:
+ throw new Error();
+ }
+ }
+ }
+
+ /**
+ * Writer for annotations and the values they contain.
+ */
+ protected static class AnnotationWriter
+ implements Annotation.element_value.Visitor<Void,ClassOutputStream> {
+ public void write(Annotation[] annos, ClassOutputStream out) {
+ out.writeShort(annos.length);
+ for (Annotation anno: annos)
+ write(anno, out);
+ }
+
+ public void write(Annotation anno, ClassOutputStream out) {
+ out.writeShort(anno.type_index);
+ out.writeShort(anno.element_value_pairs.length);
+ for (element_value_pair p: anno.element_value_pairs)
+ write(p, out);
+ }
+
+ public void write(element_value_pair pair, ClassOutputStream out) {
+ out.writeShort(pair.element_name_index);
+ write(pair.value, out);
+ }
+
+ public void write(element_value ev, ClassOutputStream out) {
+ out.writeByte(ev.tag);
+ ev.accept(this, out);
+ }
+
+ public Void visitPrimitive(Primitive_element_value ev, ClassOutputStream out) {
+ out.writeShort(ev.const_value_index);
+ return null;
+ }
+
+ public Void visitEnum(Enum_element_value ev, ClassOutputStream out) {
+ out.writeShort(ev.type_name_index);
+ out.writeShort(ev.const_name_index);
+ return null;
+ }
+
+ public Void visitClass(Class_element_value ev, ClassOutputStream out) {
+ out.writeShort(ev.class_info_index);
+ return null;
+ }
+
+ public Void visitAnnotation(Annotation_element_value ev, ClassOutputStream out) {
+ write(ev.annotation_value, out);
+ return null;
+ }
+
+ public Void visitArray(Array_element_value ev, ClassOutputStream out) {
+ out.writeShort(ev.num_values);
+ for (element_value v: ev.values)
+ write(v, out);
+ return null;
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/classes/com/sun/tools/classfile/Code_attribute.java Fri Jun 06 15:17:35 2008 -0700
@@ -0,0 +1,123 @@
+/*
+ * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package com.sun.tools.classfile;
+
+import java.io.IOException;
+
+/**
+ * See JVMS3, section 4.8.3.
+ *
+ * <p><b>This is NOT part of any API supported by Sun Microsystems. If
+ * you write code that depends on this, you do so at your own risk.
+ * This code and its internal interfaces are subject to change or
+ * deletion without notice.</b>
+ */
+public class Code_attribute extends Attribute {
+ public class InvalidIndex extends AttributeException {
+ InvalidIndex(int index) {
+ this.index = index;
+ }
+
+ @Override
+ public String getMessage() {
+ // i18n
+ return "invalid index " + index + " in Code attribute";
+ }
+
+ public final int index;
+ }
+
+ Code_attribute(ClassReader cr, int name_index, int length)
+ throws IOException, ConstantPoolException {
+ super(name_index, length);
+ max_stack = cr.readUnsignedShort();
+ max_locals = cr.readUnsignedShort();
+ code_length = cr.readInt();
+ code = new byte[code_length];
+ cr.readFully(code);
+ exception_table_langth = cr.readUnsignedShort();
+ exception_table = new Exception_data[exception_table_langth];
+ for (int i = 0; i < exception_table_langth; i++)
+ exception_table[i] = new Exception_data(cr);
+ attributes = new Attributes(cr);
+ }
+
+ public int getByte(int offset) throws InvalidIndex {
+ if (offset < 0 || offset >= code.length)
+ throw new InvalidIndex(offset);
+ return code[offset];
+ }
+
+ public int getUnsignedByte(int offset) throws InvalidIndex {
+ if (offset < 0 || offset >= code.length)
+ throw new InvalidIndex(offset);
+ return code[offset] & 0xff;
+ }
+
+ public int getShort(int offset) throws InvalidIndex {
+ if (offset < 0 || offset + 1 >= code.length)
+ throw new InvalidIndex(offset);
+ return (code[offset] << 8) | (code[offset + 1] & 0xFF);
+ }
+
+ public int getUnsignedShort(int offset) throws InvalidIndex {
+ if (offset < 0 || offset + 1 >= code.length)
+ throw new InvalidIndex(offset);
+ return ((code[offset] << 8) | (code[offset + 1] & 0xFF)) & 0xFFFF;
+ }
+
+ public int getInt(int offset) throws InvalidIndex {
+ if (offset < 0 || offset + 3 >= code.length)
+ throw new InvalidIndex(offset);
+ return (getShort(offset) << 16) | (getShort(offset + 2) & 0xFFFF);
+ }
+
+ public <R, D> R accept(Visitor<R, D> visitor, D data) {
+ return visitor.visitCode(this, data);
+ }
+
+ public final int max_stack;
+ public final int max_locals;
+ public final int code_length;
+ public final byte[] code;
+ public final int exception_table_langth;
+ public final Exception_data[] exception_table;
+ public final Attributes attributes;
+
+ public class Exception_data {
+ Exception_data(ClassReader cr) throws IOException {
+ start_pc = cr.readUnsignedShort();
+ end_pc = cr.readUnsignedShort();
+ handler_pc = cr.readUnsignedShort();
+ catch_type = cr.readUnsignedShort();
+ }
+
+ public final int start_pc;
+ public final int end_pc;
+ public final int handler_pc;
+ public final int catch_type;
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/classes/com/sun/tools/classfile/CompilationID_attribute.java Fri Jun 06 15:17:35 2008 -0700
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+package com.sun.tools.classfile;
+
+import java.io.IOException;
+
+/**
+ * <p><b>This is NOT part of any API supported by Sun Microsystems. If
+ * you write code that depends on this, you do so at your own risk.
+ * This code and its internal interfaces are subject to change or
+ * deletion without notice.</b>
+ */
+public class CompilationID_attribute extends Attribute {
+
+ CompilationID_attribute(ClassReader cr, int name_index, int length) throws IOException {
+ super(name_index, length);
+ compilationID_index = cr.readUnsignedShort();
+ }
+
+ public CompilationID_attribute(ConstantPool constant_pool, int compilationID_index)
+ throws ConstantPoolException {
+ this(constant_pool.getUTF8Index(Attribute.CompilationID), compilationID_index);
+ }
+
+ public CompilationID_attribute(int name_index, int compilationID_index) {
+ super(name_index, 2);
+ this.compilationID_index = compilationID_index;
+ }
+
+ String getCompilationID(ConstantPool constant_pool)
+ throws ConstantPoolException {
+ return constant_pool.getUTF8Value(compilationID_index);
+ }
+
+ public <R, D> R accept(Visitor<R, D> visitor, D data) {
+ return visitor.visitCompilationID(this, data);
+ }
+
+ public final int compilationID_index;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/classes/com/sun/tools/classfile/ConstantPool.java Fri Jun 06 15:17:35 2008 -0700
@@ -0,0 +1,562 @@
+/*
+ * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package com.sun.tools.classfile;
+
+import java.io.IOException;
+
+/**
+ * See JVMS3, section 4.5.
+ *
+ * <p><b>This is NOT part of any API supported by Sun Microsystems. If
+ * you write code that depends on this, you do so at your own risk.
+ * This code and its internal interfaces are subject to change or
+ * deletion without notice.</b>
+ */
+public class ConstantPool {
+
+ public class InvalidIndex extends ConstantPoolException {
+ InvalidIndex(int index) {
+ super(index);
+ }
+
+ @Override
+ public String getMessage() {
+ // i18n
+ return "invalid index #" + index;
+ }
+ }
+
+ public class UnexpectedEntry extends ConstantPoolException {
+ UnexpectedEntry(int index, int expected_tag, int found_tag) {
+ super(index);
+ this.expected_tag = expected_tag;
+ this.found_tag = found_tag;
+ }
+
+ @Override
+ public String getMessage() {
+ // i18n?
+ return "unexpected entry at #" + index + " -- expected tag " + expected_tag + ", found " + found_tag;
+ }
+
+ public final int expected_tag;
+ public final int found_tag;
+ }
+
+ public class InvalidEntry extends ConstantPoolException {
+ InvalidEntry(int index, int tag) {
+ super(index);
+ this.tag = tag;
+ }
+
+ @Override
+ public String getMessage() {
+ // i18n?
+ return "unexpected tag at #" + index + ": " + tag;
+ }
+
+ public final int tag;
+ }
+
+ public class EntryNotFound extends ConstantPoolException {
+ EntryNotFound(Object value) {
+ super(-1);
+ this.value = value;
+ }
+
+ @Override
+ public String getMessage() {
+ // i18n?
+ return "value not found: " + value;
+ }
+
+ public final Object value;
+ }
+
+ public static final int CONSTANT_Utf8 = 1;
+ public static final int CONSTANT_Integer = 3;
+ public static final int CONSTANT_Float = 4;
+ public static final int CONSTANT_Long = 5;
+ public static final int CONSTANT_Double = 6;
+ public static final int CONSTANT_Class = 7;
+ public static final int CONSTANT_String = 8;
+ public static final int CONSTANT_Fieldref = 9;
+ public static final int CONSTANT_Methodref = 10;
+ public static final int CONSTANT_InterfaceMethodref = 11;
+ public static final int CONSTANT_NameAndType = 12;
+
+ ConstantPool(ClassReader cr) throws IOException, InvalidEntry {
+ int count = cr.readUnsignedShort();
+ pool = new CPInfo[count];
+ for (int i = 1; i < count; i++) {
+ int tag = cr.readUnsignedByte();
+ switch (tag) {
+ case CONSTANT_Class:
+ pool[i] = new CONSTANT_Class_info(this, cr);
+ break;
+
+ case CONSTANT_Double:
+ pool[i] = new CONSTANT_Double_info(cr);
+ i++;
+ break;
+
+ case CONSTANT_Fieldref:
+ pool[i] = new CONSTANT_Fieldref_info(this, cr);
+ break;
+
+ case CONSTANT_Float:
+ pool[i] = new CONSTANT_Float_info(cr);
+ break;
+
+ case CONSTANT_Integer:
+ pool[i] = new CONSTANT_Integer_info(cr);
+ break;
+
+ case CONSTANT_InterfaceMethodref:
+ pool[i] = new CONSTANT_InterfaceMethodref_info(this, cr);
+ break;
+
+ case CONSTANT_Long:
+ pool[i] = new CONSTANT_Long_info(cr);
+ i++;
+ break;
+
+ case CONSTANT_Methodref:
+ pool[i] = new CONSTANT_Methodref_info(this, cr);
+ break;
+
+ case CONSTANT_NameAndType:
+ pool[i] = new CONSTANT_NameAndType_info(this, cr);
+ break;
+
+ case CONSTANT_String:
+ pool[i] = new CONSTANT_String_info(cr);
+ break;
+
+ case CONSTANT_Utf8:
+ pool[i] = new CONSTANT_Utf8_info(cr);
+ break;
+
+ default:
+ throw new InvalidEntry(i, tag);
+ }
+ }
+ }
+
+ public ConstantPool(CPInfo[] pool) {
+ this.pool = pool;
+ }
+
+ public int size() {
+ return pool.length;
+ }
+
+ public CPInfo get(int index) throws InvalidIndex {
+ if (index <= 0 || index >= pool.length)
+ throw new InvalidIndex(index);
+ CPInfo info = pool[index];
+ if (info == null) {
+ // this occurs for indices referencing the "second half" of an
+ // 8 byte constant, such as CONSTANT_Double or CONSTANT_Long
+ throw new InvalidIndex(index);
+ }
+ return pool[index];
+ }
+
+ private CPInfo get(int index, int expected_type) throws InvalidIndex, UnexpectedEntry {
+ CPInfo info = get(index);
+ if (info.getTag() != expected_type)
+ throw new UnexpectedEntry(index, expected_type, info.getTag());
+ return info;
+ }
+
+ public CONSTANT_Utf8_info getUTF8Info(int index) throws InvalidIndex, UnexpectedEntry {
+ return ((CONSTANT_Utf8_info) get(index, CONSTANT_Utf8));
+ }
+
+ public CONSTANT_Class_info getClassInfo(int index) throws InvalidIndex, UnexpectedEntry {
+ return ((CONSTANT_Class_info) get(index, CONSTANT_Class));
+ }
+
+ public CONSTANT_NameAndType_info getNameAndTypeInfo(int index) throws InvalidIndex, UnexpectedEntry {
+ return ((CONSTANT_NameAndType_info) get(index, CONSTANT_NameAndType));
+ }
+
+ public String getUTF8Value(int index) throws InvalidIndex, UnexpectedEntry {
+ return getUTF8Info(index).value;
+ }
+
+ public int getUTF8Index(String value) throws EntryNotFound {
+ for (int i = 1; i < pool.length; i++) {
+ CPInfo info = pool[i];
+ if (info instanceof CONSTANT_Utf8_info &&
+ ((CONSTANT_Utf8_info) info).value.equals(value))
+ return i;
+ }
+ throw new EntryNotFound(value);
+ }
+
+ private CPInfo[] pool;
+
+ public interface Visitor<R,P> {
+ R visitClass(CONSTANT_Class_info info, P p);
+ R visitDouble(CONSTANT_Double_info info, P p);
+ R visitFieldref(CONSTANT_Fieldref_info info, P p);
+ R visitFloat(CONSTANT_Float_info info, P p);
+ R visitInteger(CONSTANT_Integer_info info, P p);
+ R visitInterfaceMethodref(CONSTANT_InterfaceMethodref_info info, P p);
+ R visitLong(CONSTANT_Long_info info, P p);
+ R visitNameAndType(CONSTANT_NameAndType_info info, P p);
+ R visitMethodref(CONSTANT_Methodref_info info, P p);
+ R visitString(CONSTANT_String_info info, P p);
+ R visitUtf8(CONSTANT_Utf8_info info, P p);
+ }
+
+ public static abstract class CPInfo {
+ CPInfo() {
+ this.cp = null;
+ }
+
+ CPInfo(ConstantPool cp) {
+ this.cp = cp;
+ }
+
+ public abstract int getTag();
+
+ public abstract <R,D> R accept(Visitor<R,D> visitor, D data);
+
+ protected final ConstantPool cp;
+ }
+
+ public static abstract class CPRefInfo extends CPInfo {
+ protected CPRefInfo(ConstantPool cp, ClassReader cr, int tag) throws IOException {
+ super(cp);
+ this.tag = tag;
+ class_index = cr.readUnsignedShort();
+ name_and_type_index = cr.readUnsignedShort();
+ }
+
+ protected CPRefInfo(ConstantPool cp, int tag, int class_index, int name_and_type_index) {
+ super(cp);
+ this.tag = tag;
+ this.class_index = class_index;
+ this.name_and_type_index = name_and_type_index;
+ }
+
+ public int getTag() {
+ return tag;
+ }
+
+ public CONSTANT_Class_info getClassInfo() throws ConstantPoolException {
+ return cp.getClassInfo(class_index);
+ }
+
+ public String getClassName() throws ConstantPoolException {
+ return cp.getClassInfo(class_index).getName();
+ }
+
+ public CONSTANT_NameAndType_info getNameAndTypeInfo() throws ConstantPoolException {
+ return cp.getNameAndTypeInfo(name_and_type_index);
+ }
+
+ public final int tag;
+ public final int class_index;
+ public final int name_and_type_index;
+ }
+
+ public static class CONSTANT_Class_info extends CPInfo {
+ CONSTANT_Class_info(ConstantPool cp, ClassReader cr) throws IOException {
+ super(cp);
+ name_index = cr.readUnsignedShort();
+ }
+
+ public CONSTANT_Class_info(ConstantPool cp, int name_index) {
+ super(cp);
+ this.name_index = name_index;
+ }
+
+ public int getTag() {
+ return CONSTANT_Class;
+ }
+
+ public String getName() throws ConstantPoolException {
+ return cp.getUTF8Value(name_index);
+ }
+
+ @Override
+ public String toString() {
+ return "CONSTANT_Class_info[name_index: " + name_index + "]";
+ }
+
+ public <R, D> R accept(Visitor<R, D> visitor, D data) {
+ return visitor.visitClass(this, data);
+ }
+
+ public final int name_index;
+ }
+
+ public static class CONSTANT_Double_info extends CPInfo {
+ CONSTANT_Double_info(ClassReader cr) throws IOException {
+ value = cr.readDouble();
+ }
+
+ public CONSTANT_Double_info(double value) {
+ this.value = value;
+ }
+
+ public int getTag() {
+ return CONSTANT_Double;
+ }
+
+ @Override
+ public String toString() {
+ return "CONSTANT_Double_info[value: " + value + "]";
+ }
+
+ public <R, D> R accept(Visitor<R, D> visitor, D data) {
+ return visitor.visitDouble(this, data);
+ }
+
+ public final double value;
+ }
+
+ public static class CONSTANT_Fieldref_info extends CPRefInfo {
+ CONSTANT_Fieldref_info(ConstantPool cp, ClassReader cr) throws IOException {
+ super(cp, cr, CONSTANT_Fieldref);
+ }
+
+ public CONSTANT_Fieldref_info(ConstantPool cp, int class_index, int name_and_type_index) {
+ super(cp, CONSTANT_Fieldref, class_index, name_and_type_index);
+ }
+
+ @Override
+ public String toString() {
+ return "CONSTANT_Fieldref_info[class_index: " + class_index + ", name_and_type_index: " + name_and_type_index + "]";
+ }
+
+ public <R, D> R accept(Visitor<R, D> visitor, D data) {
+ return visitor.visitFieldref(this, data);
+ }
+ }
+
+ public static class CONSTANT_Float_info extends CPInfo {
+ CONSTANT_Float_info(ClassReader cr) throws IOException {
+ value = cr.readFloat();
+ }
+
+ public CONSTANT_Float_info(float value) {
+ this.value = value;
+ }
+
+ public int getTag() {
+ return CONSTANT_Float;
+ }
+
+ @Override
+ public String toString() {
+ return "CONSTANT_Float_info[value: " + value + "]";
+ }
+
+ public <R, D> R accept(Visitor<R, D> visitor, D data) {
+ return visitor.visitFloat(this, data);
+ }
+
+ public final float value;
+ }
+
+ public static class CONSTANT_Integer_info extends CPInfo {
+ CONSTANT_Integer_info(ClassReader cr) throws IOException {
+ value = cr.readInt();
+ }
+
+ public CONSTANT_Integer_info(int value) {
+ this.value = value;
+ }
+
+ public int getTag() {
+ return CONSTANT_Integer;
+ }
+
+ @Override
+ public String toString() {
+ return "CONSTANT_Integer_info[value: " + value + "]";
+ }
+
+ public <R, D> R accept(Visitor<R, D> visitor, D data) {
+ return visitor.visitInteger(this, data);
+ }
+
+ public final int value;
+ }
+
+ public static class CONSTANT_InterfaceMethodref_info extends CPRefInfo {
+ CONSTANT_InterfaceMethodref_info(ConstantPool cp, ClassReader cr) throws IOException {
+ super(cp, cr, CONSTANT_InterfaceMethodref);
+ }
+
+ public CONSTANT_InterfaceMethodref_info(ConstantPool cp, int class_index, int name_and_type_index) {
+ super(cp, CONSTANT_InterfaceMethodref, class_index, name_and_type_index);
+ }
+
+ @Override
+ public String toString() {
+ return "CONSTANT_InterfaceMethodref_info[class_index: " + class_index + ", name_and_type_index: " + name_and_type_index + "]";
+ }
+
+ public <R, D> R accept(Visitor<R, D> visitor, D data) {
+ return visitor.visitInterfaceMethodref(this, data);
+ }
+ }
+
+ public static class CONSTANT_Long_info extends CPInfo {
+ CONSTANT_Long_info(ClassReader cr) throws IOException {
+ value = cr.readLong();
+ }
+
+ public CONSTANT_Long_info(long value) {
+ this.value = value;
+ }
+
+ public int getTag() {
+ return CONSTANT_Long;
+ }
+
+ @Override
+ public String toString() {
+ return "CONSTANT_Long_info[value: " + value + "]";
+ }
+
+ public <R, D> R accept(Visitor<R, D> visitor, D data) {
+ return visitor.visitLong(this, data);
+ }
+
+ public final long value;
+ }
+
+ public static class CONSTANT_Methodref_info extends CPRefInfo {
+ CONSTANT_Methodref_info(ConstantPool cp, ClassReader cr) throws IOException {
+ super(cp, cr, CONSTANT_Methodref);
+ }
+
+ public CONSTANT_Methodref_info(ConstantPool cp, int class_index, int name_and_type_index) {
+ super(cp, CONSTANT_Methodref, class_index, name_and_type_index);
+ }
+
+ @Override
+ public String toString() {
+ return "CONSTANT_Methodref_info[class_index: " + class_index + ", name_and_type_index: " + name_and_type_index + "]";
+ }
+
+ public <R, D> R accept(Visitor<R, D> visitor, D data) {
+ return visitor.visitMethodref(this, data);
+ }
+ }
+
+ public static class CONSTANT_NameAndType_info extends CPInfo {
+ CONSTANT_NameAndType_info(ConstantPool cp, ClassReader cr) throws IOException {
+ super(cp);
+ name_index = cr.readUnsignedShort();
+ type_index = cr.readUnsignedShort();
+ }
+
+ public CONSTANT_NameAndType_info(ConstantPool cp, int name_index, int type_index) {
+ super(cp);
+ this.name_index = name_index;
+ this.type_index = type_index;
+ }
+
+ public int getTag() {
+ return CONSTANT_NameAndType;
+ }
+
+ public String getName() throws ConstantPoolException {
+ return cp.getUTF8Value(name_index);
+ }
+
+ public String getType() throws ConstantPoolException {
+ return cp.getUTF8Value(type_index);
+ }
+
+ public <R, D> R accept(Visitor<R, D> visitor, D data) {
+ return visitor.visitNameAndType(this, data);
+ }
+
+ public final int name_index;
+ public final int type_index;
+ }
+
+ public static class CONSTANT_String_info extends CPInfo {
+ CONSTANT_String_info(ClassReader cr) throws IOException {
+ string_index = cr.readUnsignedShort();
+ }
+
+ public CONSTANT_String_info(ConstantPool cp, int string_index) {
+ super(cp);
+ this.string_index = string_index;
+ }
+
+ public int getTag() {
+ return CONSTANT_String;
+ }
+
+ public String getString() throws ConstantPoolException {
+ return cp.getUTF8Value(string_index);
+ }
+
+ public <R, D> R accept(Visitor<R, D> visitor, D data) {
+ return visitor.visitString(this, data);
+ }
+
+ public final int string_index;
+ }
+
+ public static class CONSTANT_Utf8_info extends CPInfo {
+ CONSTANT_Utf8_info(ClassReader cr) throws IOException {
+ value = cr.readUTF();
+ }
+
+ public CONSTANT_Utf8_info(String value) {
+ this.value = value;
+ }
+
+ public int getTag() {
+ return CONSTANT_Utf8;
+ }
+
+ @Override
+ public String toString() {
+ return "CONSTANT_Utf8_info[value: " + value + "]";
+ }
+
+ public <R, D> R accept(Visitor<R, D> visitor, D data) {
+ return visitor.visitUtf8(this, data);
+ }
+
+ public final String value;
+ }
+
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/classes/com/sun/tools/classfile/ConstantPoolException.java Fri Jun 06 15:17:35 2008 -0700
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+
+package com.sun.tools.classfile;
+
+/*
+ * <p><b>This is NOT part of any API supported by Sun Microsystems. If
+ * you write code that depends on this, you do so at your own risk.
+ * This code and its internal interfaces are subject to change or
+ * deletion without notice.</b>
+ */
+public class ConstantPoolException extends Exception {
+ ConstantPoolException(int index) {
+ this.index = index;
+ }
+
+ public final int index;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/classes/com/sun/tools/classfile/ConstantValue_attribute.java Fri Jun 06 15:17:35 2008 -0700
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package com.sun.tools.classfile;
+
+import java.io.IOException;
+
+/**
+ * See JVMS3, section 4.8.2.
+ *
+ * <p><b>This is NOT part of any API supported by Sun Microsystems. If
+ * you write code that depends on this, you do so at your own risk.
+ * This code and its internal interfaces are subject to change or
+ * deletion without notice.</b>
+ */
+public class ConstantValue_attribute extends Attribute {
+ ConstantValue_attribute(ClassReader cr, int name_index, int length) throws IOException {
+ super(name_index, length);
+ constantvalue_index = cr.readUnsignedShort();
+ }
+
+ public ConstantValue_attribute(ConstantPool constant_pool, int constantvalue_index)
+ throws ConstantPoolException {
+ this(constant_pool.getUTF8Index(Attribute.ConstantValue), constantvalue_index);
+ }
+
+ public ConstantValue_attribute(int name_index, int constantvalue_index) {
+ super(name_index, 2);
+ this.constantvalue_index = constantvalue_index;
+ }
+
+ public <R, D> R accept(Visitor<R, D> visitor, D data) {
+ return visitor.visitConstantValue(this, data);
+ }
+
+ public final int constantvalue_index;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/classes/com/sun/tools/classfile/DefaultAttribute.java Fri Jun 06 15:17:35 2008 -0700
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package com.sun.tools.classfile;
+
+/*
+ * <p><b>This is NOT part of any API supported by Sun Microsystems. If
+ * you write code that depends on this, you do so at your own risk.
+ * This code and its internal interfaces are subject to change or
+ * deletion without notice.</b>
+ */
+public class DefaultAttribute extends Attribute {
+ DefaultAttribute(ClassReader cr, int name_index, byte[] data) {
+ super(name_index, data.length);
+ info = data;
+ }
+
+ public DefaultAttribute(ConstantPool constant_pool, int name_index, byte[] info) {
+ super(name_index, info.length);
+ this.info = info;
+ }
+
+ public <R, P> R accept(Visitor<R, P> visitor, P p) {
+ return visitor.visitDefault(this, p);
+ }
+
+ public final byte[] info;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/classes/com/sun/tools/classfile/Deprecated_attribute.java Fri Jun 06 15:17:35 2008 -0700
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package com.sun.tools.classfile;
+
+import java.io.IOException;
+
+/**
+ * See JVMS3, section 4.8.15.
+ *
+ * <p><b>This is NOT part of any API supported by Sun Microsystems. If
+ * you write code that depends on this, you do so at your own risk.
+ * This code and its internal interfaces are subject to change or
+ * deletion without notice.</b>
+ */
+public class Deprecated_attribute extends Attribute {
+ Deprecated_attribute(ClassReader cr, int name_index, int length) throws IOException {
+ super(name_index, length);
+ }
+
+ public Deprecated_attribute(ConstantPool constant_pool)
+ throws ConstantPoolException {
+ this(constant_pool.getUTF8Index(Attribute.Deprecated));
+ }
+
+ public Deprecated_attribute(int name_index) {
+ super(name_index, 0);
+ }
+
+ public <R, D> R accept(Visitor<R, D> visitor, D data) {
+ return visitor.visitDeprecated(this, data);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/classes/com/sun/tools/classfile/Descriptor.java Fri Jun 06 15:17:35 2008 -0700
@@ -0,0 +1,198 @@
+/*
+ * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+
+package com.sun.tools.classfile;
+
+import java.io.IOException;
+
+/**
+ * See JVMS3, section 4.4.
+ *
+ * <p><b>This is NOT part of any API supported by Sun Microsystems. If
+ * you write code that depends on this, you do so at your own risk.
+ * This code and its internal interfaces are subject to change or
+ * deletion without notice.</b>
+ */
+public class Descriptor {
+ public class InvalidDescriptor extends DescriptorException {
+ InvalidDescriptor(String desc) {
+ this.desc = desc;
+ this.index = -1;
+ }
+
+ InvalidDescriptor(String desc, int index) {
+ this.desc = desc;
+ this.index = index;
+ }
+
+ @Override
+ public String getMessage() {
+ // i18n
+ if (index == -1)
+ return "invalid descriptor \"" + desc + "\"";
+ else
+ return "descriptor is invalid at offset " + index + " in \"" + desc + "\"";
+ }
+
+ public final String desc;
+ public final int index;
+
+ }
+
+ public Descriptor(ClassReader cr) throws IOException {
+ this(cr.readUnsignedShort());
+ }
+
+ public Descriptor(int index) {
+ this.index = index;
+
+ }
+
+ public String getValue(ConstantPool constant_pool) throws ConstantPoolException {
+ return constant_pool.getUTF8Value(index);
+ }
+
+ public int getParameterCount(ConstantPool constant_pool)
+ throws ConstantPoolException, InvalidDescriptor {
+ String desc = getValue(constant_pool);
+ int end = desc.indexOf(")");
+ if (end == -1)
+ throw new InvalidDescriptor(desc);
+ parse(desc, 0, end + 1);
+ return count;
+
+ }
+
+ public String getParameterTypes(ConstantPool constant_pool)
+ throws ConstantPoolException, InvalidDescriptor {
+ String desc = getValue(constant_pool);
+ int end = desc.indexOf(")");
+ if (end == -1)
+ throw new InvalidDescriptor(desc);
+ return parse(desc, 0, end + 1);
+ }
+
+ public String getReturnType(ConstantPool constant_pool)
+ throws ConstantPoolException, InvalidDescriptor {
+ String desc = getValue(constant_pool);
+ int end = desc.indexOf(")");
+ if (end == -1)
+ throw new InvalidDescriptor(desc);
+ return parse(desc, end + 1, desc.length());
+ }
+
+ public String getFieldType(ConstantPool constant_pool)
+ throws ConstantPoolException, InvalidDescriptor {
+ String desc = getValue(constant_pool);
+ return parse(desc, 0, desc.length());
+ }
+
+ private String parse(String desc, int start, int end)
+ throws InvalidDescriptor {
+ int p = start;
+ StringBuffer sb = new StringBuffer();
+ int dims = 0;
+ count = 0;
+
+ while (p < end) {
+ String type;
+ char ch;
+ switch (ch = desc.charAt(p++)) {
+ case '(':
+ sb.append('(');
+ continue;
+
+ case ')':
+ sb.append(')');
+ continue;
+
+ case '[':
+ dims++;
+ continue;
+
+ case 'B':
+ type = "byte";
+ break;
+
+ case 'C':
+ type = "char";
+ break;
+
+ case 'D':
+ type = "double";
+ break;
+
+ case 'F':
+ type = "float";
+ break;
+
+ case 'I':
+ type = "int";
+ break;
+
+ case 'J':
+ type = "long";
+ break;
+
+ case 'L':
+ int sep = desc.indexOf(';', p);
+ if (sep == -1)
+ throw new InvalidDescriptor(desc, p - 1);
+ type = desc.substring(p, sep).replace('/', '.');
+ p = sep + 1;
+ break;
+
+ case 'S':
+ type = "short";
+ break;
+
+ case 'Z':
+ type = "boolean";
+ break;
+
+ case 'V':
+ type = "void";
+ break;
+
+ default:
+ throw new InvalidDescriptor(desc, p - 1);
+ }
+
+ if (sb.length() > 1 && sb.charAt(0) == '(')
+ sb.append(", ");
+ sb.append(type);
+ for ( ; dims > 0; dims-- )
+ sb.append("[]");
+
+ count++;
+ }
+
+ return sb.toString();
+ }
+
+ public final int index;
+ private int count;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/classes/com/sun/tools/classfile/DescriptorException.java Fri Jun 06 15:17:35 2008 -0700
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+
+package com.sun.tools.classfile;
+
+/*
+ * <p><b>This is NOT part of any API supported by Sun Microsystems. If
+ * you write code that depends on this, you do so at your own risk.
+ * This code and its internal interfaces are subject to change or
+ * deletion without notice.</b>
+ */
+public class DescriptorException extends Exception {
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/classes/com/sun/tools/classfile/EnclosingMethod_attribute.java Fri Jun 06 15:17:35 2008 -0700
@@ -0,0 +1,73 @@
+
+/*
+ * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package com.sun.tools.classfile;
+
+import java.io.IOException;
+
+/**
+ * See JVMS3, section 4.8.7.
+ *
+ * <p><b>This is NOT part of any API supported by Sun Microsystems. If
+ * you write code that depends on this, you do so at your own risk.
+ * This code and its internal interfaces are subject to change or
+ * deletion without notice.</b>
+ */
+public class EnclosingMethod_attribute extends Attribute {
+ EnclosingMethod_attribute(ClassReader cr, int name_index, int length) throws IOException {
+ super(name_index, length);
+ class_index = cr.readUnsignedShort();
+ method_index = cr.readUnsignedShort();
+ }
+
+ public EnclosingMethod_attribute(ConstantPool constant_pool, int class_index, int method_index)
+ throws ConstantPoolException {
+ this(constant_pool.getUTF8Index(Attribute.EnclosingMethod), class_index, method_index);
+ }
+
+ public EnclosingMethod_attribute(int name_index, int class_index, int method_index) {
+ super(name_index, 4);
+ this.class_index = class_index;
+ this.method_index = method_index;
+ }
+
+ public String getClassName(ConstantPool constant_pool) throws ConstantPoolException {
+ return constant_pool.getClassInfo(class_index).getName();
+ }
+
+ public String getMethodName(ConstantPool constant_pool) throws ConstantPoolException {
+ if (method_index == 0)
+ return "";
+ return constant_pool.getNameAndTypeInfo(method_index).getName();
+ }
+
+ public <R, D> R accept(Visitor<R, D> visitor, D data) {
+ return visitor.visitEnclosingMethod(this, data);
+ }
+
+ public final int class_index;
+ public final int method_index;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/classes/com/sun/tools/classfile/Exceptions_attribute.java Fri Jun 06 15:17:35 2008 -0700
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package com.sun.tools.classfile;
+
+import java.io.IOException;
+
+/**
+ * See JVMS3, section 4.8.5.
+ *
+ * <p><b>This is NOT part of any API supported by Sun Microsystems. If
+ * you write code that depends on this, you do so at your own risk.
+ * This code and its internal interfaces are subject to change or
+ * deletion without notice.</b>
+ */
+public class Exceptions_attribute extends Attribute {
+ Exceptions_attribute(ClassReader cr, int name_index, int length) throws IOException {
+ super(name_index, length);
+ number_of_exceptions = cr.readUnsignedShort();
+ exception_index_table = new int[number_of_exceptions];
+ for (int i = 0; i < number_of_exceptions; i++)
+ exception_index_table[i] = cr.readUnsignedShort();
+ }
+
+ public Exceptions_attribute(ConstantPool constant_pool, int[] exception_index_table)
+ throws ConstantPoolException {
+ this(constant_pool.getUTF8Index(Attribute.Exceptions), exception_index_table);
+ }
+
+ public Exceptions_attribute(int name_index, int[] exception_index_table) {
+ super(name_index, 2 + 2 * exception_index_table.length);
+ this.number_of_exceptions = exception_index_table.length;
+ this.exception_index_table = exception_index_table;
+ }
+
+ public String getException(int index, ConstantPool constant_pool) throws ConstantPoolException {
+ int exception_index = exception_index_table[index];
+ return constant_pool.getClassInfo(exception_index).getName();
+ }
+
+ public <R, D> R accept(Visitor<R, D> visitor, D data) {
+ return visitor.visitExceptions(this, data);
+ }
+
+ public final int number_of_exceptions;
+ public final int[] exception_index_table;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/classes/com/sun/tools/classfile/Field.java Fri Jun 06 15:17:35 2008 -0700
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package com.sun.tools.classfile;
+
+import java.io.IOException;
+
+/*
+ * <p><b>This is NOT part of any API supported by Sun Microsystems. If
+ * you write code that depends on this, you do so at your own risk.
+ * This code and its internal interfaces are subject to change or
+ * deletion without notice.</b>
+ */
+public class Field {
+ Field(ClassReader cr) throws IOException {
+ access_flags = new AccessFlags(cr);
+ name_index = cr.readUnsignedShort();
+ descriptor = new Descriptor(cr);
+ attributes = new Attributes(cr);
+ }
+
+ public Field(AccessFlags access_flags,
+ int name_index, Descriptor descriptor,
+ Attributes attributes) {
+ this.access_flags = access_flags;
+ this.name_index = name_index;
+ this.descriptor = descriptor;
+ this.attributes = attributes;
+ }
+
+ public String getName(ConstantPool constant_pool) throws ConstantPoolException {
+ return constant_pool.getUTF8Value(name_index);
+ }
+
+ public final AccessFlags access_flags;
+ public final int name_index;
+ public final Descriptor descriptor;
+ public final Attributes attributes;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/classes/com/sun/tools/classfile/InnerClasses_attribute.java Fri Jun 06 15:17:35 2008 -0700
@@ -0,0 +1,102 @@
+/*
+ * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package com.sun.tools.classfile;
+
+import java.io.IOException;
+
+import com.sun.tools.classfile.ConstantPool.*;
+
+/**
+ * See JVMS3, section 4.8.6.
+ *
+ * <p><b>This is NOT part of any API supported by Sun Microsystems. If
+ * you write code that depends on this, you do so at your own risk.
+ * This code and its internal interfaces are subject to change or
+ * deletion without notice.</b>
+ */
+public class InnerClasses_attribute extends Attribute {
+ InnerClasses_attribute(ClassReader cr, int name_index, int length) throws IOException {
+ super(name_index, length);
+ number_of_classes = cr.readUnsignedShort();
+ classes = new Info[number_of_classes];
+ for (int i = 0; i < number_of_classes; i++)
+ classes[i] = new Info(cr);
+ }
+
+ public InnerClasses_attribute(ConstantPool constant_pool, Info[] classes)
+ throws ConstantPoolException {
+ this(constant_pool.getUTF8Index(Attribute.InnerClasses), classes);
+ }
+
+ public InnerClasses_attribute(int name_index, Info[] classes) {
+ super(name_index, 2 + Info.length() * classes.length);
+ this.number_of_classes = classes.length;
+ this.classes = classes;
+ }
+
+ public <R, D> R accept(Visitor<R, D> visitor, D data) {
+ return visitor.visitInnerClasses(this, data);
+ }
+
+ public final int number_of_classes;
+ public final Info[] classes;
+
+ public static class Info {
+ Info(ClassReader cr) throws IOException {
+ inner_class_info_index = cr.readUnsignedShort();
+ outer_class_info_index = cr.readUnsignedShort();
+ inner_name_index = cr.readUnsignedShort();
+ inner_class_access_flags = new AccessFlags(cr.readUnsignedShort());
+ }
+
+ public CONSTANT_Class_info getInnerClassInfo(ConstantPool constant_pool) throws ConstantPoolException {
+ if (inner_class_info_index == 0)
+ return null;
+ return constant_pool.getClassInfo(inner_class_info_index);
+ }
+
+ public CONSTANT_Class_info getOuterClassInfo(ConstantPool constant_pool) throws ConstantPoolException {
+ if (outer_class_info_index == 0)
+ return null;
+ return constant_pool.getClassInfo(outer_class_info_index);
+ }
+
+ public String getInnerName(ConstantPool constant_pool) throws ConstantPoolException {
+ if (inner_name_index == 0)
+ return null;
+ return constant_pool.getUTF8Value(inner_name_index);
+ }
+
+ public static int length() {
+ return 8;
+ }
+
+ public final int inner_class_info_index;
+ public final int outer_class_info_index;
+ public final int inner_name_index;
+ public final AccessFlags inner_class_access_flags;
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/classes/com/sun/tools/classfile/LineNumberTable_attribute.java Fri Jun 06 15:17:35 2008 -0700
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package com.sun.tools.classfile;
+
+import java.io.IOException;
+
+/**
+ * See JVMS3, section 4.8.12.
+ *
+ * <p><b>This is NOT part of any API supported by Sun Microsystems. If
+ * you write code that depends on this, you do so at your own risk.
+ * This code and its internal interfaces are subject to change or
+ * deletion without notice.</b>
+ */
+public class LineNumberTable_attribute extends Attribute {
+ LineNumberTable_attribute(ClassReader cr, int name_index, int length) throws IOException {
+ super(name_index, length);
+ line_number_table_length = cr.readUnsignedShort();
+ line_number_table = new Entry[line_number_table_length];
+ for (int i = 0; i < line_number_table_length; i++)
+ line_number_table[i] = new Entry(cr);
+ }
+
+ public LineNumberTable_attribute(ConstantPool constant_pool, Entry[] line_number_table)
+ throws ConstantPoolException {
+ this(constant_pool.getUTF8Index(Attribute.LineNumberTable), line_number_table);
+ }
+
+ public LineNumberTable_attribute(int name_index, Entry[] line_number_table) {
+ super(name_index, line_number_table.length * Entry.length());
+ this.line_number_table_length = line_number_table.length;
+ this.line_number_table = line_number_table;
+ }
+
+ public <R, D> R accept(Visitor<R, D> visitor, D data) {
+ return visitor.visitLineNumberTable(this, data);
+ }
+
+ public final int line_number_table_length;
+ public final Entry[] line_number_table;
+
+ public static class Entry {
+ Entry(ClassReader cr) throws IOException {
+ start_pc = cr.readUnsignedShort();
+ line_number = cr.readUnsignedShort();
+ }
+
+ public static int length() {
+ return 4;
+ }
+
+ public final int start_pc;
+ public final int line_number;
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/classes/com/sun/tools/classfile/LocalVariableTable_attribute.java Fri Jun 06 15:17:35 2008 -0700
@@ -0,0 +1,84 @@
+/*
+ * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package com.sun.tools.classfile;
+
+import java.io.IOException;
+
+/**
+ * See JVMS3, section 4.8.13.
+ *
+ * <p><b>This is NOT part of any API supported by Sun Microsystems. If
+ * you write code that depends on this, you do so at your own risk.
+ * This code and its internal interfaces are subject to change or
+ * deletion without notice.</b>
+ */
+public class LocalVariableTable_attribute extends Attribute {
+ LocalVariableTable_attribute(ClassReader cr, int name_index, int length) throws IOException {
+ super(name_index, length);
+ local_variable_table_length = cr.readUnsignedShort();
+ local_variable_table = new Entry[local_variable_table_length];
+ for (int i = 0; i < local_variable_table_length; i++)
+ local_variable_table[i] = new Entry(cr);
+ }
+
+ public LocalVariableTable_attribute(ConstantPool constant_pool, Entry[] local_variable_table)
+ throws ConstantPoolException {
+ this(constant_pool.getUTF8Index(Attribute.LocalVariableTable), local_variable_table);
+ }
+
+ public LocalVariableTable_attribute(int name_index, Entry[] local_variable_table) {
+ super(name_index, local_variable_table.length * Entry.length());
+ this.local_variable_table_length = local_variable_table.length;
+ this.local_variable_table = local_variable_table;
+ }
+
+ public <R, D> R accept(Visitor<R, D> visitor, D data) {
+ return visitor.visitLocalVariableTable(this, data);
+ }
+
+ public final int local_variable_table_length;
+ public final Entry[] local_variable_table;
+
+ public static class Entry {
+ Entry(ClassReader cr) throws IOException {
+ start_pc = cr.readUnsignedShort();
+ length = cr.readUnsignedShort();
+ name_index = cr.readUnsignedShort();
+ descriptor_index = cr.readUnsignedShort();
+ index = cr.readUnsignedShort();
+ }
+
+ public static int length() {
+ return 10;
+ }
+
+ public final int start_pc;
+ public final int length;
+ public final int name_index;
+ public final int descriptor_index;
+ public final int index;
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/classes/com/sun/tools/classfile/LocalVariableTypeTable_attribute.java Fri Jun 06 15:17:35 2008 -0700
@@ -0,0 +1,84 @@
+/*
+ * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package com.sun.tools.classfile;
+
+import java.io.IOException;
+
+/**
+ * See JVMS3, section 4.8.14.
+ *
+ * <p><b>This is NOT part of any API supported by Sun Microsystems. If
+ * you write code that depends on this, you do so at your own risk.
+ * This code and its internal interfaces are subject to change or
+ * deletion without notice.</b>
+ */
+public class LocalVariableTypeTable_attribute extends Attribute {
+ LocalVariableTypeTable_attribute(ClassReader cr, int name_index, int length) throws IOException {
+ super(name_index, length);
+ local_variable_table_length = cr.readUnsignedShort();
+ local_variable_table = new Entry[local_variable_table_length];
+ for (int i = 0; i < local_variable_table_length; i++)
+ local_variable_table[i] = new Entry(cr);
+ }
+
+ public LocalVariableTypeTable_attribute(ConstantPool constant_pool, Entry[] local_variable_table)
+ throws ConstantPoolException {
+ this(constant_pool.getUTF8Index(Attribute.LocalVariableTypeTable), local_variable_table);
+ }
+
+ public LocalVariableTypeTable_attribute(int name_index, Entry[] local_variable_table) {
+ super(name_index, local_variable_table.length * Entry.length());
+ this.local_variable_table_length = local_variable_table.length;
+ this.local_variable_table = local_variable_table;
+ }
+
+ public <R, D> R accept(Visitor<R, D> visitor, D data) {
+ return visitor.visitLocalVariableTypeTable(this, data);
+ }
+
+ public final int local_variable_table_length;
+ public final Entry[] local_variable_table;
+
+ public static class Entry {
+ Entry(ClassReader cr) throws IOException {
+ start_pc = cr.readUnsignedShort();
+ length = cr.readUnsignedShort();
+ name_index = cr.readUnsignedShort();
+ signature_index = cr.readUnsignedShort();
+ index = cr.readUnsignedShort();
+ }
+
+ public static int length() {
+ return 10;
+ }
+
+ public final int start_pc;
+ public final int length;
+ public final int name_index;
+ public final int signature_index;
+ public final int index;
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/classes/com/sun/tools/classfile/Method.java Fri Jun 06 15:17:35 2008 -0700
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package com.sun.tools.classfile;
+
+import java.io.IOException;
+
+/*
+ * <p><b>This is NOT part of any API supported by Sun Microsystems. If
+ * you write code that depends on this, you do so at your own risk.
+ * This code and its internal interfaces are subject to change or
+ * deletion without notice.</b>
+ */
+public class Method {
+ Method(ClassReader cr) throws IOException {
+ access_flags = new AccessFlags(cr);
+ name_index = cr.readUnsignedShort();
+ descriptor = new Descriptor(cr);
+ attributes = new Attributes(cr);
+ }
+
+ public Method(AccessFlags access_flags,
+ int name_index, Descriptor descriptor,
+ Attributes attributes) {
+ this.access_flags = access_flags;
+ this.name_index = name_index;
+ this.descriptor = descriptor;
+ this.attributes = attributes;
+ }
+
+ public String getName(ConstantPool constant_pool) throws ConstantPoolException {
+ return constant_pool.getUTF8Value(name_index);
+ }
+
+ public final AccessFlags access_flags;
+ public final int name_index;
+ public final Descriptor descriptor;
+ public final Attributes attributes;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/classes/com/sun/tools/classfile/ModuleExportTable_attribute.java Fri Jun 06 15:17:35 2008 -0700
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package com.sun.tools.classfile;
+
+import java.io.IOException;
+
+/**
+ * See JSR 277.
+ *
+ * <p><b>This is NOT part of any API supported by Sun Microsystems. If
+ * you write code that depends on this, you do so at your own risk.
+ * This code and its internal interfaces are subject to change or
+ * deletion without notice.</b>
+ */
+public class ModuleExportTable_attribute extends Attribute {
+ ModuleExportTable_attribute(ClassReader cr, int name_index, int length) throws IOException {
+ super(name_index, length);
+ int export_type_length = cr.readUnsignedShort();
+ export_type_table = new int[export_type_length];
+ for (int i = 0; i < export_type_table.length; i++)
+ export_type_table[i] = cr.readUnsignedShort();
+ }
+
+ public ModuleExportTable_attribute(ConstantPool cp, int[] export_type_table)
+ throws ConstantPoolException {
+ this(cp.getUTF8Index(Attribute.ModuleExportTable), export_type_table);
+ }
+
+ public ModuleExportTable_attribute(int name_index, int[] export_type_table) {
+ super(name_index, 2 * export_type_table.length);
+ this.export_type_table = export_type_table;
+ }
+
+ public int getExportTypeCount() {
+ return export_type_table.length;
+ }
+
+ public String getExportTypeName(int index, ConstantPool constant_pool) throws ConstantPoolException {
+ return constant_pool.getUTF8Value(export_type_table[index]);
+ }
+
+ public <R, P> R accept(Visitor<R, P> visitor, P p) {
+ return visitor.visitModuleExportTable(this, p);
+ }
+
+ public final int[] export_type_table;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/classes/com/sun/tools/classfile/ModuleMemberTable_attribute.java Fri Jun 06 15:17:35 2008 -0700
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+package com.sun.tools.classfile;
+
+import java.io.IOException;
+
+/**
+ * See JSR 277.
+ *
+ * <p><b>This is NOT part of any API supported by Sun Microsystems. If
+ * you write code that depends on this, you do so at your own risk.
+ * This code and its internal interfaces are subject to change or
+ * deletion without notice.</b>
+ */
+public class ModuleMemberTable_attribute extends Attribute {
+ ModuleMemberTable_attribute(ClassReader cr, int name_index, int length) throws IOException {
+ super(name_index, length);
+ int package_member_length = cr.readUnsignedShort();
+ package_member_table = new int[package_member_length];
+ for (int i = 0; i < package_member_table.length; i++)
+ package_member_table[i] = cr.readUnsignedShort();
+ }
+
+ public ModuleMemberTable_attribute(ConstantPool cp, int[] package_member_table)
+ throws ConstantPoolException {
+ this(cp.getUTF8Index(Attribute.ModuleMemberTable), package_member_table);
+ }
+
+ public ModuleMemberTable_attribute(int name_index, int[] package_member_table) {
+ super(name_index, 2 * package_member_table.length);
+ this.package_member_table = package_member_table;
+ }
+
+ public int getPackageMemberCount() {
+ return package_member_table.length;
+ }
+
+ public String getPackageMemberName(int index, ConstantPool constant_pool) throws ConstantPoolException {
+ return constant_pool.getUTF8Value(package_member_table[index]);
+ }
+
+ public <R, P> R accept(Visitor<R, P> visitor, P p) {
+ return visitor.visitModuleMemberTable(this, p);
+ }
+
+ public final int[] package_member_table;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/classes/com/sun/tools/classfile/Module_attribute.java Fri Jun 06 15:17:35 2008 -0700
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package com.sun.tools.classfile;
+
+import java.io.IOException;
+
+/**
+ * See JSR 277.
+ *
+ * <p><b>This is NOT part of any API supported by Sun Microsystems. If
+ * you write code that depends on this, you do so at your own risk.
+ * This code and its internal interfaces are subject to change or
+ * deletion without notice.</b>
+ */
+public class Module_attribute extends Attribute {
+ Module_attribute(ClassReader cr, int name_index, int length) throws IOException {
+ super(name_index, length);
+ module_name = cr.readUnsignedShort();
+ }
+
+ public Module_attribute(ConstantPool constant_pool, int module_name)
+ throws ConstantPoolException {
+ this(constant_pool.getUTF8Index(Attribute.Module), module_name);
+ }
+
+ public Module_attribute(int name_index, int module_name) {
+ super(name_index, 2);
+ this.module_name = module_name;
+ }
+
+ public String getModuleName(ConstantPool constant_pool) throws ConstantPoolException {
+ return constant_pool.getUTF8Value(module_name);
+ }
+
+ public <R, D> R accept(Visitor<R, D> visitor, D data) {
+ return visitor.visitModule(this, data);
+ }
+
+ public final int module_name;
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/classes/com/sun/tools/classfile/OpCodes.java Fri Jun 06 15:17:35 2008 -0700
@@ -0,0 +1,868 @@
+/*
+ * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package com.sun.tools.classfile;
+
+import java.util.HashMap;
+
+/**
+ * See JVMS3, section 6.
+ *
+ * <p><b>This is NOT part of any API supported by Sun Microsystems. If
+ * you write code that depends on this, you do so at your own risk.
+ * This code and its internal interfaces are subject to change or
+ * deletion without notice.</b>
+ */
+public class OpCodes {
+
+ public static int opcLength(int opc) throws IllegalArgumentException {
+ switch (opc >> 8) {
+ case 0:
+ return opcLengthsTab[opc];
+ case opc_wide:
+ switch (opc & 0xFF) {
+ case opc_aload:
+ case opc_astore:
+ case opc_fload:
+ case opc_fstore:
+ case opc_iload:
+ case opc_istore:
+ case opc_lload:
+ case opc_lstore:
+ case opc_dload:
+ case opc_dstore:
+ case opc_ret:
+ return 4;
+ case opc_iinc:
+ return 6;
+ default:
+ throw new IllegalArgumentException();
+ }
+ case opc_nonpriv:
+ case opc_priv:
+ return 2;
+ default:
+ throw new IllegalArgumentException();
+ }
+ }
+
+ public static String opcName(int opc) {
+ try {
+ switch (opc >> 8) {
+ case 0:
+ return opcNamesTab[opc];
+ case opc_wide:
+ {
+ String mnem = opcNamesTab[opc & 0xFF] + "_w";
+ if (mnemocodes.get(mnem) == null) {
+ return null; // non-existent opcode
+ }
+ return mnem;
+ }
+ case opc_nonpriv:
+ return opcExtNamesTab[opc & 0xFF];
+ case opc_priv:
+ return opcPrivExtNamesTab[opc & 0xFF];
+ default:
+ return null;
+ }
+ } catch (ArrayIndexOutOfBoundsException e) {
+ switch (opc) {
+ case opc_nonpriv:
+ return "nonpriv";
+ case opc_priv:
+ return "priv";
+ default:
+ return null;
+ }
+ }
+ }
+
+ /* Opcodes */
+ public static final int opc_dead = -2;
+ public static final int opc_label = -1;
+ public static final int opc_nop = 0;
+ public static final int opc_aconst_null = 1;
+ public static final int opc_iconst_m1 = 2;
+ public static final int opc_iconst_0 = 3;
+ public static final int opc_iconst_1 = 4;
+ public static final int opc_iconst_2 = 5;
+ public static final int opc_iconst_3 = 6;
+ public static final int opc_iconst_4 = 7;
+ public static final int opc_iconst_5 = 8;
+ public static final int opc_lconst_0 = 9;
+ public static final int opc_lconst_1 = 10;
+ public static final int opc_fconst_0 = 11;
+ public static final int opc_fconst_1 = 12;
+ public static final int opc_fconst_2 = 13;
+ public static final int opc_dconst_0 = 14;
+ public static final int opc_dconst_1 = 15;
+ public static final int opc_bipush = 16;
+ public static final int opc_sipush = 17;
+ public static final int opc_ldc = 18;
+ public static final int opc_ldc_w = 19;
+ public static final int opc_ldc2_w = 20;
+ public static final int opc_iload = 21;
+ public static final int opc_lload = 22;
+ public static final int opc_fload = 23;
+ public static final int opc_dload = 24;
+ public static final int opc_aload = 25;
+ public static final int opc_iload_0 = 26;
+ public static final int opc_iload_1 = 27;
+ public static final int opc_iload_2 = 28;
+ public static final int opc_iload_3 = 29;
+ public static final int opc_lload_0 = 30;
+ public static final int opc_lload_1 = 31;
+ public static final int opc_lload_2 = 32;
+ public static final int opc_lload_3 = 33;
+ public static final int opc_fload_0 = 34;
+ public static final int opc_fload_1 = 35;
+ public static final int opc_fload_2 = 36;
+ public static final int opc_fload_3 = 37;
+ public static final int opc_dload_0 = 38;
+ public static final int opc_dload_1 = 39;
+ public static final int opc_dload_2 = 40;
+ public static final int opc_dload_3 = 41;
+ public static final int opc_aload_0 = 42;
+ public static final int opc_aload_1 = 43;
+ public static final int opc_aload_2 = 44;
+ public static final int opc_aload_3 = 45;
+ public static final int opc_iaload = 46;
+ public static final int opc_laload = 47;
+ public static final int opc_faload = 48;
+ public static final int opc_daload = 49;
+ public static final int opc_aaload = 50;
+ public static final int opc_baload = 51;
+ public static final int opc_caload = 52;
+ public static final int opc_saload = 53;
+ public static final int opc_istore = 54;
+ public static final int opc_lstore = 55;
+ public static final int opc_fstore = 56;
+ public static final int opc_dstore = 57;
+ public static final int opc_astore = 58;
+ public static final int opc_istore_0 = 59;
+ public static final int opc_istore_1 = 60;
+ public static final int opc_istore_2 = 61;
+ public static final int opc_istore_3 = 62;
+ public static final int opc_lstore_0 = 63;
+ public static final int opc_lstore_1 = 64;
+ public static final int opc_lstore_2 = 65;
+ public static final int opc_lstore_3 = 66;
+ public static final int opc_fstore_0 = 67;
+ public static final int opc_fstore_1 = 68;
+ public static final int opc_fstore_2 = 69;
+ public static final int opc_fstore_3 = 70;
+ public static final int opc_dstore_0 = 71;
+ public static final int opc_dstore_1 = 72;
+ public static final int opc_dstore_2 = 73;
+ public static final int opc_dstore_3 = 74;
+ public static final int opc_astore_0 = 75;
+ public static final int opc_astore_1 = 76;
+ public static final int opc_astore_2 = 77;
+ public static final int opc_astore_3 = 78;
+ public static final int opc_iastore = 79;
+ public static final int opc_lastore = 80;
+ public static final int opc_fastore = 81;
+ public static final int opc_dastore = 82;
+ public static final int opc_aastore = 83;
+ public static final int opc_bastore = 84;
+ public static final int opc_castore = 85;
+ public static final int opc_sastore = 86;
+ public static final int opc_pop = 87;
+ public static final int opc_pop2 = 88;
+ public static final int opc_dup = 89;
+ public static final int opc_dup_x1 = 90;
+ public static final int opc_dup_x2 = 91;
+ public static final int opc_dup2 = 92;
+ public static final int opc_dup2_x1 = 93;
+ public static final int opc_dup2_x2 = 94;
+ public static final int opc_swap = 95;
+ public static final int opc_iadd = 96;
+ public static final int opc_ladd = 97;
+ public static final int opc_fadd = 98;
+ public static final int opc_dadd = 99;
+ public static final int opc_isub = 100;
+ public static final int opc_lsub = 101;
+ public static final int opc_fsub = 102;
+ public static final int opc_dsub = 103;
+ public static final int opc_imul = 104;
+ public static final int opc_lmul = 105;
+ public static final int opc_fmul = 106;
+ public static final int opc_dmul = 107;
+ public static final int opc_idiv = 108;
+ public static final int opc_ldiv = 109;
+ public static final int opc_fdiv = 110;
+ public static final int opc_ddiv = 111;
+ public static final int opc_irem = 112;
+ public static final int opc_lrem = 113;
+ public static final int opc_frem = 114;
+ public static final int opc_drem = 115;
+ public static final int opc_ineg = 116;
+ public static final int opc_lneg = 117;
+ public static final int opc_fneg = 118;
+ public static final int opc_dneg = 119;
+ public static final int opc_ishl = 120;
+ public static final int opc_lshl = 121;
+ public static final int opc_ishr = 122;
+ public static final int opc_lshr = 123;
+ public static final int opc_iushr = 124;
+ public static final int opc_lushr = 125;
+ public static final int opc_iand = 126;
+ public static final int opc_land = 127;
+ public static final int opc_ior = 128;
+ public static final int opc_lor = 129;
+ public static final int opc_ixor = 130;
+ public static final int opc_lxor = 131;
+ public static final int opc_iinc = 132;
+ public static final int opc_i2l = 133;
+ public static final int opc_i2f = 134;
+ public static final int opc_i2d = 135;
+ public static final int opc_l2i = 136;
+ public static final int opc_l2f = 137;
+ public static final int opc_l2d = 138;
+ public static final int opc_f2i = 139;
+ public static final int opc_f2l = 140;
+ public static final int opc_f2d = 141;
+ public static final int opc_d2i = 142;
+ public static final int opc_d2l = 143;
+ public static final int opc_d2f = 144;
+ public static final int opc_i2b = 145;
+ public static final int opc_int2byte = 145;
+ public static final int opc_i2c = 146;
+ public static final int opc_int2char = 146;
+ public static final int opc_i2s = 147;
+ public static final int opc_int2short = 147;
+ public static final int opc_lcmp = 148;
+ public static final int opc_fcmpl = 149;
+ public static final int opc_fcmpg = 150;
+ public static final int opc_dcmpl = 151;
+ public static final int opc_dcmpg = 152;
+ public static final int opc_ifeq = 153;
+ public static final int opc_ifne = 154;
+ public static final int opc_iflt = 155;
+ public static final int opc_ifge = 156;
+ public static final int opc_ifgt = 157;
+ public static final int opc_ifle = 158;
+ public static final int opc_if_icmpeq = 159;
+ public static final int opc_if_icmpne = 160;
+ public static final int opc_if_icmplt = 161;
+ public static final int opc_if_icmpge = 162;
+ public static final int opc_if_icmpgt = 163;
+ public static final int opc_if_icmple = 164;
+ public static final int opc_if_acmpeq = 165;
+ public static final int opc_if_acmpne = 166;
+ public static final int opc_goto = 167;
+ public static final int opc_jsr = 168;
+ public static final int opc_ret = 169;
+ public static final int opc_tableswitch = 170;
+ public static final int opc_lookupswitch = 171;
+ public static final int opc_ireturn = 172;
+ public static final int opc_lreturn = 173;
+ public static final int opc_freturn = 174;
+ public static final int opc_dreturn = 175;
+ public static final int opc_areturn = 176;
+ public static final int opc_return = 177;
+ public static final int opc_getstatic = 178;
+ public static final int opc_putstatic = 179;
+ public static final int opc_getfield = 180;
+ public static final int opc_putfield = 181;
+ public static final int opc_invokevirtual = 182;
+ public static final int opc_invokenonvirtual = 183;
+ public static final int opc_invokespecial = 183;
+ public static final int opc_invokestatic = 184;
+ public static final int opc_invokeinterface = 185;
+// public static final int opc_xxxunusedxxx = 186;
+ public static final int opc_new = 187;
+ public static final int opc_newarray = 188;
+ public static final int opc_anewarray = 189;
+ public static final int opc_arraylength = 190;
+ public static final int opc_athrow = 191;
+ public static final int opc_checkcast = 192;
+ public static final int opc_instanceof = 193;
+ public static final int opc_monitorenter = 194;
+ public static final int opc_monitorexit = 195;
+ public static final int opc_wide = 196;
+ public static final int opc_multianewarray = 197;
+ public static final int opc_ifnull = 198;
+ public static final int opc_ifnonnull = 199;
+ public static final int opc_goto_w = 200;
+ public static final int opc_jsr_w = 201;
+
+ /* Pseudo-instructions */
+ public static final int opc_bytecode = 203;
+ public static final int opc_try = 204;
+ public static final int opc_endtry = 205;
+ public static final int opc_catch = 206;
+ public static final int opc_var = 207;
+ public static final int opc_endvar = 208;
+ public static final int opc_localsmap = 209;
+ public static final int opc_stackmap = 210;
+
+ /* PicoJava prefixes */
+ public static final int opc_nonpriv = 254;
+ public static final int opc_priv = 255;
+
+ /* Wide instructions */
+ public static final int opc_iload_w = (opc_wide << 8 ) | opc_iload;
+ public static final int opc_lload_w = (opc_wide << 8 ) | opc_lload;
+ public static final int opc_fload_w = (opc_wide << 8 ) | opc_fload;
+ public static final int opc_dload_w = (opc_wide << 8 ) | opc_dload;
+ public static final int opc_aload_w = (opc_wide << 8 ) | opc_aload;
+ public static final int opc_istore_w = (opc_wide << 8 ) | opc_istore;
+ public static final int opc_lstore_w = (opc_wide << 8 ) | opc_lstore;
+ public static final int opc_fstore_w = (opc_wide << 8 ) | opc_fstore;
+ public static final int opc_dstore_w = (opc_wide << 8 ) | opc_dstore;
+ public static final int opc_astore_w = (opc_wide << 8 ) | opc_astore;
+ public static final int opc_ret_w = (opc_wide << 8 ) | opc_ret;
+ public static final int opc_iinc_w = (opc_wide << 8 ) | opc_iinc;
+
+ /* Opcode Names */
+ private static final String opcNamesTab[] = {
+ "nop",
+ "aconst_null",
+ "iconst_m1",
+ "iconst_0",
+ "iconst_1",
+ "iconst_2",
+ "iconst_3",
+ "iconst_4",
+ "iconst_5",
+ "lconst_0",
+ "lconst_1",
+ "fconst_0",
+ "fconst_1",
+ "fconst_2",
+ "dconst_0",
+ "dconst_1",
+ "bipush",
+ "sipush",
+ "ldc",
+ "ldc_w",
+ "ldc2_w",
+ "iload",
+ "lload",
+ "fload",
+ "dload",
+ "aload",
+ "iload_0",
+ "iload_1",
+ "iload_2",
+ "iload_3",
+ "lload_0",
+ "lload_1",
+ "lload_2",
+ "lload_3",
+ "fload_0",
+ "fload_1",
+ "fload_2",
+ "fload_3",
+ "dload_0",
+ "dload_1",
+ "dload_2",
+ "dload_3",
+ "aload_0",
+ "aload_1",
+ "aload_2",
+ "aload_3",
+ "iaload",
+ "laload",
+ "faload",
+ "daload",
+ "aaload",
+ "baload",
+ "caload",
+ "saload",
+ "istore",
+ "lstore",
+ "fstore",
+ "dstore",
+ "astore",
+ "istore_0",
+ "istore_1",
+ "istore_2",
+ "istore_3",
+ "lstore_0",
+ "lstore_1",
+ "lstore_2",
+ "lstore_3",
+ "fstore_0",
+ "fstore_1",
+ "fstore_2",
+ "fstore_3",
+ "dstore_0",
+ "dstore_1",
+ "dstore_2",
+ "dstore_3",
+ "astore_0",
+ "astore_1",
+ "astore_2",
+ "astore_3",
+ "iastore",
+ "lastore",
+ "fastore",
+ "dastore",
+ "aastore",
+ "bastore",
+ "castore",
+ "sastore",
+ "pop",
+ "pop2",
+ "dup",
+ "dup_x1",
+ "dup_x2",
+ "dup2",
+ "dup2_x1",
+ "dup2_x2",
+ "swap",
+ "iadd",
+ "ladd",
+ "fadd",
+ "dadd",
+ "isub",
+ "lsub",
+ "fsub",
+ "dsub",
+ "imul",
+ "lmul",
+ "fmul",
+ "dmul",
+ "idiv",
+ "ldiv",
+ "fdiv",
+ "ddiv",
+ "irem",
+ "lrem",
+ "frem",
+ "drem",
+ "ineg",
+ "lneg",
+ "fneg",
+ "dneg",
+ "ishl",
+ "lshl",
+ "ishr",
+ "lshr",
+ "iushr",
+ "lushr",
+ "iand",
+ "land",
+ "ior",
+ "lor",
+ "ixor",
+ "lxor",
+ "iinc",
+ "i2l",
+ "i2f",
+ "i2d",
+ "l2i",
+ "l2f",
+ "l2d",
+ "f2i",
+ "f2l",
+ "f2d",
+ "d2i",
+ "d2l",
+ "d2f",
+ "i2b",
+ "i2c",
+ "i2s",
+ "lcmp",
+ "fcmpl",
+ "fcmpg",
+ "dcmpl",
+ "dcmpg",
+ "ifeq",
+ "ifne",
+ "iflt",
+ "ifge",
+ "ifgt",
+ "ifle",
+ "if_icmpeq",
+ "if_icmpne",
+ "if_icmplt",
+ "if_icmpge",
+ "if_icmpgt",
+ "if_icmple",
+ "if_acmpeq",
+ "if_acmpne",
+ "goto",
+ "jsr",
+ "ret",
+ "tableswitch",
+ "lookupswitch",
+ "ireturn",
+ "lreturn",
+ "freturn",
+ "dreturn",
+ "areturn",
+ "return",
+ "getstatic",
+ "putstatic",
+ "getfield",
+ "putfield",
+ "invokevirtual",
+ "invokespecial", // was "invokenonvirtual",
+ "invokestatic",
+ "invokeinterface",
+ "bytecode 186", //"xxxunusedxxx",
+ "new",
+ "newarray",
+ "anewarray",
+ "arraylength",
+ "athrow",
+ "checkcast",
+ "instanceof",
+ "monitorenter",
+ "monitorexit",
+ null, // "wide",
+ "multianewarray",
+ "ifnull",
+ "ifnonnull",
+ "goto_w",
+ "jsr_w",
+ "bytecode 202", // "breakpoint",
+ "bytecode",
+ "try",
+ "endtry",
+ "catch",
+ "var",
+ "endvar",
+ "locals_map",
+ "stack_map"
+ };
+
+ /* Opcode Lengths */
+ private static final int opcLengthsTab[] = {
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 2,
+ 3,
+ 2,
+ 3,
+ 3,
+ 2,
+ 2,
+ 2,
+ 2,
+ 2,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 2,
+ 2,
+ 2,
+ 2,
+ 2,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 3,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 3,
+ 3,
+ 3,
+ 3,
+ 3,
+ 3,
+ 3,
+ 3,
+ 3,
+ 3,
+ 3,
+ 3,
+ 3,
+ 3,
+ 3,
+ 3,
+ 2,
+ 99,
+ 99,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 3,
+ 3,
+ 3,
+ 3,
+ 3,
+ 3,
+ 3,
+ 5,
+ 0,
+ 3,
+ 2,
+ 3,
+ 1,
+ 1,
+ 3,
+ 3,
+ 1,
+ 1,
+ 0, // wide
+ 4,
+ 3,
+ 3,
+ 5,
+ 5,
+ 1,
+ 1, 0, 0, 0, 0, 0 // pseudo
+ };
+
+ /* Type codes, used in newarray opcode */
+ public static final int T_CLASS = 0x00000002;
+ public static final int T_BOOLEAN = 0x00000004;
+ public static final int T_CHAR = 0x00000005;
+ public static final int T_FLOAT = 0x00000006;
+ public static final int T_DOUBLE = 0x00000007;
+ public static final int T_BYTE = 0x00000008;
+ public static final int T_SHORT = 0x00000009;
+ public static final int T_INT = 0x0000000a;
+ public static final int T_LONG = 0x0000000b;
+
+ private static HashMap<String,Integer> mnemocodes = new HashMap<String,Integer>(301, 0.5f);
+ private static String opcExtNamesTab[]=new String[128];
+ private static String opcPrivExtNamesTab[]=new String[128];
+
+ private static void defineNonPriv(int opc, String mnem) {
+ mnemocodes.put(opcExtNamesTab[opc] = mnem, opc_nonpriv * 256 + opc);
+ }
+
+ private static void definePriv(int opc, String mnem) {
+ mnemocodes.put(opcPrivExtNamesTab[opc] = "priv_" + mnem, opc_priv * 256 + opc);
+ }
+
+ private static void defineExt(int opc, String mnem) {
+ defineNonPriv(opc, mnem);
+ definePriv(opc, mnem);
+ }
+
+ static {
+ for (int i = 0; i < opc_wide; i++) {
+ mnemocodes.put(opcNamesTab[i], i);
+ }
+ for (int i = opc_wide + 1; i < opcNamesTab.length; i++) {
+ mnemocodes.put(opcNamesTab[i], i);
+ }
+ mnemocodes.put("invokenonvirtual", opc_invokespecial);
+
+ mnemocodes.put("iload_w", opc_iload_w);
+ mnemocodes.put("lload_w", opc_lload_w);
+ mnemocodes.put("fload_w", opc_fload_w);
+ mnemocodes.put("dload_w", opc_dload_w);
+ mnemocodes.put("aload_w", opc_aload_w);
+ mnemocodes.put("istore_w", opc_istore_w);
+ mnemocodes.put("lstore_w", opc_lstore_w);
+ mnemocodes.put("fstore_w", opc_fstore_w);
+ mnemocodes.put("dstore_w", opc_dstore_w);
+ mnemocodes.put("astore_w", opc_astore_w);
+ mnemocodes.put("ret_w", opc_ret_w);
+ mnemocodes.put("iinc_w", opc_iinc_w);
+
+ mnemocodes.put("nonpriv", opc_nonpriv);
+ mnemocodes.put("priv", opc_priv);
+
+ defineExt(0, "load_ubyte");
+ defineExt(1, "load_byte");
+ defineExt(2, "load_char");
+ defineExt(3, "load_short");
+ defineExt(4, "load_word");
+ defineExt(10, "load_char_oe");
+ defineExt(11, "load_short_oe");
+ defineExt(12, "load_word_oe");
+ defineExt(16, "ncload_ubyte");
+ defineExt(17, "ncload_byte");
+ defineExt(18, "ncload_char");
+ defineExt(19, "ncload_short");
+ defineExt(20, "ncload_word");
+ defineExt(26, "ncload_char_oe");
+ defineExt(27, "ncload_short_oe");
+ defineExt(28, "ncload_word_oe");
+ defineExt(30, "cache_flush");
+ defineExt(32, "store_byte");
+ defineExt(34, "store_short");
+ defineExt(36, "store_word");
+ defineExt(42, "store_short_oe");
+ defineExt(44, "store_word_oe");
+ defineExt(48, "ncstore_byte");
+ defineExt(50, "ncstore_short");
+ defineExt(52, "ncstore_word");
+ defineExt(58, "ncstore_short_oe");
+ defineExt(60, "ncstore_word_oe");
+ defineExt(62, "zero_line");
+ defineNonPriv(5, "ret_from_sub");
+ defineNonPriv(63, "enter_sync_method");
+ definePriv(5, "ret_from_trap");
+ definePriv(6, "read_dcache_tag");
+ definePriv(7, "read_dcache_data");
+ definePriv(14, "read_icache_tag");
+ definePriv(15, "read_icache_data");
+ definePriv(22, "powerdown");
+ definePriv(23, "read_scache_data");
+ definePriv(31, "cache_index_flush");
+ definePriv(38, "write_dcache_tag");
+ definePriv(39, "write_dcache_data");
+ definePriv(46, "write_icache_tag");
+ definePriv(47, "write_icache_data");
+ definePriv(54, "reset");
+ definePriv(55, "write_scache_data");
+ for (int i = 0; i < 32; i++) {
+ definePriv(i + 64, "read_reg_" + i);
+ }
+ for (int i = 0; i < 32; i++) {
+ definePriv(i + 96, "write_reg_" + i);
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/classes/com/sun/tools/classfile/RuntimeAnnotations_attribute.java Fri Jun 06 15:17:35 2008 -0700
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package com.sun.tools.classfile;
+
+import java.io.IOException;
+
+/**
+ * See JVMS3, section 4.8.16 and 4.8.17.
+ *
+ * <p><b>This is NOT part of any API supported by Sun Microsystems. If
+ * you write code that depends on this, you do so at your own risk.
+ * This code and its internal interfaces are subject to change or
+ * deletion without notice.</b>
+ */
+public abstract class RuntimeAnnotations_attribute extends Attribute {
+ protected RuntimeAnnotations_attribute(ClassReader cr, int name_index, int length)
+ throws IOException, Annotation.InvalidAnnotation {
+ super(name_index, length);
+ int num_annotations = cr.readUnsignedShort();
+ annotations = new Annotation[num_annotations];
+ for (int i = 0; i < annotations.length; i++)
+ annotations[i] = new Annotation(cr);
+ }
+
+ protected RuntimeAnnotations_attribute(int name_index, Annotation[] annotations) {
+ super(name_index, length(annotations));
+ this.annotations = annotations;
+ }
+
+ private static int length(Annotation[] annos) {
+ int n = 2;
+ for (Annotation anno: annos)
+ n += anno.length();
+ return n;
+ }
+
+ public final Annotation[] annotations;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/classes/com/sun/tools/classfile/RuntimeInvisibleAnnotations_attribute.java Fri Jun 06 15:17:35 2008 -0700
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package com.sun.tools.classfile;
+
+import java.io.IOException;
+
+/**
+ * See JVMS3, section 4.8.17.
+ *
+ * <p><b>This is NOT part of any API supported by Sun Microsystems. If
+ * you write code that depends on this, you do so at your own risk.
+ * This code and its internal interfaces are subject to change or
+ * deletion without notice.</b>
+ */
+public class RuntimeInvisibleAnnotations_attribute extends RuntimeAnnotations_attribute {
+ RuntimeInvisibleAnnotations_attribute(ClassReader cr, int name_index, int length)
+ throws IOException, AttributeException {
+ super(cr, name_index, length);
+ }
+
+ public RuntimeInvisibleAnnotations_attribute(ConstantPool cp, Annotation[] annotations)
+ throws ConstantPoolException {
+ this(cp.getUTF8Index(Attribute.RuntimeInvisibleAnnotations), annotations);
+ }
+
+ public RuntimeInvisibleAnnotations_attribute(int name_index, Annotation[] annotations) {
+ super(name_index, annotations);
+ }
+
+ public <R, P> R accept(Visitor<R, P> visitor, P p) {
+ return visitor.visitRuntimeInvisibleAnnotations(this, p);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/classes/com/sun/tools/classfile/RuntimeInvisibleParameterAnnotations_attribute.java Fri Jun 06 15:17:35 2008 -0700
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package com.sun.tools.classfile;
+
+import java.io.IOException;
+
+/**
+ * See JVMS3, section 4.8.18.
+ *
+ * <p><b>This is NOT part of any API supported by Sun Microsystems. If
+ * you write code that depends on this, you do so at your own risk.
+ * This code and its internal interfaces are subject to change or
+ * deletion without notice.</b>
+ */
+public class RuntimeInvisibleParameterAnnotations_attribute extends RuntimeParameterAnnotations_attribute {
+ RuntimeInvisibleParameterAnnotations_attribute(ClassReader cr, int name_index, int length)
+ throws IOException, Annotation.InvalidAnnotation {
+ super(cr, name_index, length);
+ }
+
+ public RuntimeInvisibleParameterAnnotations_attribute(ConstantPool cp, Annotation[][] parameter_annotations)
+ throws ConstantPoolException {
+ this(cp.getUTF8Index(Attribute.RuntimeInvisibleParameterAnnotations), parameter_annotations);
+ }
+
+ public RuntimeInvisibleParameterAnnotations_attribute(int name_index, Annotation[][] parameter_annotations) {
+ super(name_index, parameter_annotations);
+ }
+
+ public <R, P> R accept(Visitor<R, P> visitor, P p) {
+ return visitor.visitRuntimeInvisibleParameterAnnotations(this, p);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/classes/com/sun/tools/classfile/RuntimeParameterAnnotations_attribute.java Fri Jun 06 15:17:35 2008 -0700
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package com.sun.tools.classfile;
+
+import java.io.IOException;
+
+/**
+ * See JVMS3, section 4.8.18 and 4.8.19.
+ *
+ * <p><b>This is NOT part of any API supported by Sun Microsystems. If
+ * you write code that depends on this, you do so at your own risk.
+ * This code and its internal interfaces are subject to change or
+ * deletion without notice.</b>
+ */
+public abstract class RuntimeParameterAnnotations_attribute extends Attribute {
+ RuntimeParameterAnnotations_attribute(ClassReader cr, int name_index, int length)
+ throws IOException, Annotation.InvalidAnnotation {
+ super(name_index, length);
+ int num_parameters = cr.readUnsignedByte();
+ parameter_annotations = new Annotation[num_parameters][];
+ for (int p = 0; p < parameter_annotations.length; p++) {
+ int num_annotations = cr.readUnsignedShort();
+ Annotation[] annotations = new Annotation[num_annotations];
+ for (int i = 0; i < num_annotations; i++)
+ annotations[i] = new Annotation(cr);
+ parameter_annotations[p] = annotations;
+ }
+ }
+
+ protected RuntimeParameterAnnotations_attribute(int name_index, Annotation[][] parameter_annotations) {
+ super(name_index, length(parameter_annotations));
+ this.parameter_annotations = parameter_annotations;
+ }
+
+ private static int length(Annotation[][] anno_arrays) {
+ int n = 1;
+ for (Annotation[] anno_array: anno_arrays) {
+ n += 2;
+ for (Annotation anno: anno_array)
+ n += anno.length();
+ }
+ return n;
+ }
+
+ public final Annotation[][] parameter_annotations;
+}
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/classes/com/sun/tools/classfile/RuntimeVisibleAnnotations_attribute.java Fri Jun 06 15:17:35 2008 -0700
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package com.sun.tools.classfile;
+
+import java.io.IOException;
+
+/**
+ * See JVMS3, section 4.8.16.
+ *
+ * <p><b>This is NOT part of any API supported by Sun Microsystems. If
+ * you write code that depends on this, you do so at your own risk.
+ * This code and its internal interfaces are subject to change or
+ * deletion without notice.</b>
+ */
+public class RuntimeVisibleAnnotations_attribute extends RuntimeAnnotations_attribute {
+ RuntimeVisibleAnnotations_attribute(ClassReader cr, int name_index, int length)
+ throws IOException, Annotation.InvalidAnnotation {
+ super(cr, name_index, length);
+ }
+
+ public RuntimeVisibleAnnotations_attribute(ConstantPool cp, Annotation[] annotations)
+ throws ConstantPoolException {
+ this(cp.getUTF8Index(Attribute.RuntimeVisibleAnnotations), annotations);
+ }
+
+ public RuntimeVisibleAnnotations_attribute(int name_index, Annotation[] annotations) {
+ super(name_index, annotations);
+ }
+
+ public <R, P> R accept(Visitor<R, P> visitor, P p) {
+ return visitor.visitRuntimeVisibleAnnotations(this, p);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/classes/com/sun/tools/classfile/RuntimeVisibleParameterAnnotations_attribute.java Fri Jun 06 15:17:35 2008 -0700
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package com.sun.tools.classfile;
+
+import java.io.IOException;
+
+/**
+ * See JVMS3, section 4.8.18.
+ *
+ * <p><b>This is NOT part of any API supported by Sun Microsystems. If
+ * you write code that depends on this, you do so at your own risk.
+ * This code and its internal interfaces are subject to change or
+ * deletion without notice.</b>
+ */
+public class RuntimeVisibleParameterAnnotations_attribute extends RuntimeParameterAnnotations_attribute {
+ RuntimeVisibleParameterAnnotations_attribute(ClassReader cr, int name_index, int length)
+ throws IOException, Annotation.InvalidAnnotation {
+ super(cr, name_index, length);
+ }
+
+ public RuntimeVisibleParameterAnnotations_attribute(ConstantPool cp, Annotation[][] parameter_annotations)
+ throws ConstantPoolException {
+ this(cp.getUTF8Index(Attribute.RuntimeVisibleParameterAnnotations), parameter_annotations);
+ }
+
+ public RuntimeVisibleParameterAnnotations_attribute(int name_index, Annotation[][] parameter_annotations) {
+ super(name_index, parameter_annotations);
+ }
+
+ public <R, P> R accept(Visitor<R, P> visitor, P p) {
+ return visitor.visitRuntimeVisibleParameterAnnotations(this, p);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/classes/com/sun/tools/classfile/Signature.java Fri Jun 06 15:17:35 2008 -0700
@@ -0,0 +1,275 @@
+/*
+ * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package com.sun.tools.classfile;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * See JVMS3 4.4.4.
+ *
+ * <p><b>This is NOT part of any API supported by Sun Microsystems. If
+ * you write code that depends on this, you do so at your own risk.
+ * This code and its internal interfaces are subject to change or
+ * deletion without notice.</b>
+ */
+public class Signature extends Descriptor {
+
+ public Signature(int index) {
+ super(index);
+ }
+
+ public Type getType(ConstantPool constant_pool) throws ConstantPoolException {
+ if (type == null)
+ type = parse(getValue(constant_pool));
+ return type;
+ }
+
+ @Override
+ public int getParameterCount(ConstantPool constant_pool) throws ConstantPoolException {
+ Type.MethodType m = (Type.MethodType) getType(constant_pool);
+ return m.argTypes.size();
+ }
+
+ @Override
+ public String getParameterTypes(ConstantPool constant_pool) throws ConstantPoolException {
+ Type.MethodType m = (Type.MethodType) getType(constant_pool);
+ StringBuilder sb = new StringBuilder();
+ sb.append("(");
+ String sep = "";
+ for (Type argType: m.argTypes) {
+ sb.append(sep);
+ sb.append(argType);
+ sep = ", ";
+ }
+ sb.append(")");
+ return sb.toString();
+ }
+
+ @Override
+ public String getReturnType(ConstantPool constant_pool) throws ConstantPoolException {
+ Type.MethodType m = (Type.MethodType) getType(constant_pool);
+ return m.returnType.toString();
+ }
+
+ @Override
+ public String getFieldType(ConstantPool constant_pool) throws ConstantPoolException {
+ return getType(constant_pool).toString();
+ }
+
+ private Type parse(String sig) {
+ this.sig = sig;
+ sigp = 0;
+
+ List<Type> typeArgTypes = null;
+ if (sig.charAt(sigp) == '<')
+ typeArgTypes = parseTypeArgTypes();
+
+ if (sig.charAt(sigp) == '(') {
+ List<Type> argTypes = parseTypeSignatures(')');
+ Type returnType = parseTypeSignature();
+ List<Type> throwsTypes = null;
+ while (sigp < sig.length() && sig.charAt(sigp) == '^') {
+ sigp++;
+ if (throwsTypes == null)
+ throwsTypes = new ArrayList<Type>();
+ throwsTypes.add(parseTypeSignature());
+ }
+ return new Type.MethodType(typeArgTypes, argTypes, returnType, throwsTypes);
+ } else {
+ Type t = parseTypeSignature();
+ if (typeArgTypes == null && sigp == sig.length())
+ return t;
+ Type superclass = t;
+ List<Type> superinterfaces = new ArrayList<Type>();
+ while (sigp < sig.length())
+ superinterfaces.add(parseTypeSignature());
+ return new Type.ClassSigType(typeArgTypes, superclass, superinterfaces);
+
+ }
+ }
+
+ private Type parseTypeSignature() {
+ switch (sig.charAt(sigp)) {
+ case 'B':
+ sigp++;
+ return new Type.SimpleType("byte");
+
+ case 'C':
+ sigp++;
+ return new Type.SimpleType("char");
+
+ case 'D':
+ sigp++;
+ return new Type.SimpleType("double");
+
+ case 'F':
+ sigp++;
+ return new Type.SimpleType("float");
+
+ case 'I':
+ sigp++;
+ return new Type.SimpleType("int");
+
+ case 'J':
+ sigp++;
+ return new Type.SimpleType("long");
+
+ case 'L':
+ return parseClassTypeSignature();
+
+ case 'S':
+ sigp++;
+ return new Type.SimpleType("short");
+
+ case 'T':
+ return parseTypeVariableSignature();
+
+ case 'V':
+ sigp++;
+ return new Type.SimpleType("void");
+
+ case 'Z':
+ sigp++;
+ return new Type.SimpleType("boolean");
+
+ case '[':
+ sigp++;
+ return new Type.ArrayType(parseTypeSignature());
+
+ case '*':
+ sigp++;
+ return new Type.WildcardType();
+
+ case '+':
+ sigp++;
+ return new Type.WildcardType("extends", parseTypeSignature());
+
+ case '-':
+ sigp++;
+ return new Type.WildcardType("super", parseTypeSignature());
+
+ default:
+ throw new IllegalStateException(debugInfo());
+ }
+ }
+
+ private List<Type> parseTypeSignatures(char term) {
+ sigp++;
+ List<Type> types = new ArrayList<Type>();
+ while (sig.charAt(sigp) != term)
+ types.add(parseTypeSignature());
+ sigp++;
+ return types;
+ }
+
+ private Type parseClassTypeSignature() {
+ assert sig.charAt(sigp) == 'L';
+ sigp++;
+ return parseClassTypeSignatureRest();
+ }
+
+ private Type parseClassTypeSignatureRest() {
+ StringBuilder sb = new StringBuilder();
+ Type t = null;
+ char sigch;
+ while (true) {
+ switch (sigch = sig.charAt(sigp)) {
+ case '/':
+ sigp++;
+ sb.append(".");
+ break;
+
+ case '.':
+ sigp++;
+ if (t == null)
+ t = new Type.SimpleType(sb.toString());
+ return new Type.InnerClassType(t, parseClassTypeSignatureRest());
+
+ case ';':
+ sigp++;
+ if (t == null)
+ t = new Type.SimpleType(sb.toString());
+ return t;
+
+ case '<':
+ List<Type> argTypes = parseTypeSignatures('>');
+ t = new Type.ClassType(sb.toString(), argTypes);
+ break;
+
+ default:
+ sigp++;
+ sb.append(sigch);
+ break;
+ }
+ }
+ }
+
+ private List<Type> parseTypeArgTypes() {
+ assert sig.charAt(sigp) == '<';
+ sigp++;
+ List<Type> types = null;
+ types = new ArrayList<Type>();
+ while (sig.charAt(sigp) != '>')
+ types.add(parseTypeArgType());
+ sigp++;
+ return types;
+ }
+
+ private Type parseTypeArgType() {
+ int sep = sig.indexOf(":", sigp);
+ String name = sig.substring(sigp, sep);
+ Type classBound = null;
+ List<Type> interfaceBounds = null;
+ sigp = sep + 1;
+ if (sig.charAt(sigp) != ':')
+ classBound = parseTypeSignature();
+ while (sig.charAt(sigp) == ':') {
+ sigp++;
+ if (interfaceBounds == null)
+ interfaceBounds = new ArrayList<Type>();
+ interfaceBounds.add(parseTypeSignature());
+ }
+ return new Type.TypeArgType(name, classBound, interfaceBounds);
+ }
+
+ private Type parseTypeVariableSignature() {
+ sigp++;
+ int sep = sig.indexOf(';', sigp);
+ Type t = new Type.SimpleType(sig.substring(sigp, sep));
+ sigp = sep + 1;
+ return t;
+ }
+
+ private String debugInfo() {
+ return sig.substring(0, sigp) + "!" + sig.charAt(sigp) + "!" + sig.substring(sigp+1);
+ }
+
+ private String sig;
+ private int sigp;
+
+ private Type type;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/classes/com/sun/tools/classfile/Signature_attribute.java Fri Jun 06 15:17:35 2008 -0700
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package com.sun.tools.classfile;
+
+import java.io.IOException;
+
+/**
+ * See JVMS3, section 4.8.9.
+ *
+ * <p><b>This is NOT part of any API supported by Sun Microsystems. If
+ * you write code that depends on this, you do so at your own risk.
+ * This code and its internal interfaces are subject to change or
+ * deletion without notice.</b>
+ */
+public class Signature_attribute extends Attribute {
+ Signature_attribute(ClassReader cr, int name_index, int length) throws IOException {
+ super(name_index, length);
+ signature_index = cr.readUnsignedShort();
+ }
+
+ public Signature_attribute(ConstantPool constant_pool, int signature_index)
+ throws ConstantPoolException {
+ this(constant_pool.getUTF8Index(Attribute.Signature), signature_index);
+ }
+
+ public Signature_attribute(int name_index, int signature_index) {
+ super(name_index, 2);
+ this.signature_index = signature_index;
+ }
+
+ public String getSignature(ConstantPool constant_pool) throws ConstantPoolException {
+ return constant_pool.getUTF8Value(signature_index);
+ }
+
+ public Signature getParsedSignature() {
+ return new Signature(signature_index);
+ }
+
+ public <R, D> R accept(Visitor<R, D> visitor, D data) {
+ return visitor.visitSignature(this, data);
+ }
+
+ public final int signature_index;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/classes/com/sun/tools/classfile/SourceDebugExtension_attribute.java Fri Jun 06 15:17:35 2008 -0700
@@ -0,0 +1,71 @@
+/*
+ * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package com.sun.tools.classfile;
+
+import java.io.ByteArrayInputStream;
+import java.io.DataInputStream;
+import java.io.IOException;
+
+/**
+ * See JVMS3, section 4.8.15.
+ *
+ * <p><b>This is NOT part of any API supported by Sun Microsystems. If
+ * you write code that depends on this, you do so at your own risk.
+ * This code and its internal interfaces are subject to change or
+ * deletion without notice.</b>
+ */
+public class SourceDebugExtension_attribute extends Attribute {
+ SourceDebugExtension_attribute(ClassReader cr, int name_index, int length) throws IOException {
+ super(name_index, length);