6982999: tools must support -target 7 bytecodes

Tue, 18 Jan 2011 08:37:05 -0800

author
ksrini
date
Tue, 18 Jan 2011 08:37:05 -0800
changeset 826
5cf6c432ef2f
parent 825
19f9b6548c70
child 827
b6f95173e769

6982999: tools must support -target 7 bytecodes
Reviewed-by: jjg, jrose

src/share/classes/com/sun/tools/classfile/Attribute.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/classfile/BootstrapMethods_attribute.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/classfile/ClassTranslator.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/classfile/ClassWriter.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/classfile/ConstantPool.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/classfile/Dependencies.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/jvm/ClassFile.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/jvm/ClassReader.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javap/AttributeWriter.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javap/ConstantWriter.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/tools/classfile/Attribute.java	Fri Jan 14 13:59:18 2011 -0800
     1.2 +++ b/src/share/classes/com/sun/tools/classfile/Attribute.java	Tue Jan 18 08:37:05 2011 -0800
     1.3 @@ -39,6 +39,7 @@
     1.4  
     1.5  public abstract class Attribute {
     1.6      public static final String AnnotationDefault        = "AnnotationDefault";
     1.7 +    public static final String BootstrapMethods         = "BootstrapMethods";
     1.8      public static final String CharacterRangeTable      = "CharacterRangeTable";
     1.9      public static final String Code                     = "Code";
    1.10      public static final String ConstantValue            = "ConstantValue";
    1.11 @@ -99,6 +100,7 @@
    1.12          protected void init() {
    1.13              standardAttributes = new HashMap<String,Class<? extends Attribute>>();
    1.14              standardAttributes.put(AnnotationDefault, AnnotationDefault_attribute.class);
    1.15 +            standardAttributes.put(BootstrapMethods, BootstrapMethods_attribute.class);
    1.16              standardAttributes.put(CharacterRangeTable, CharacterRangeTable_attribute.class);
    1.17              standardAttributes.put(Code,              Code_attribute.class);
    1.18              standardAttributes.put(ConstantValue,     ConstantValue_attribute.class);
    1.19 @@ -155,6 +157,7 @@
    1.20  
    1.21  
    1.22      public interface Visitor<R,P> {
    1.23 +        R visitBootstrapMethods(BootstrapMethods_attribute attr, P p);
    1.24          R visitDefault(DefaultAttribute attr, P p);
    1.25          R visitAnnotationDefault(AnnotationDefault_attribute attr, P p);
    1.26          R visitCharacterRangeTable(CharacterRangeTable_attribute attr, P p);
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/src/share/classes/com/sun/tools/classfile/BootstrapMethods_attribute.java	Tue Jan 18 08:37:05 2011 -0800
     2.3 @@ -0,0 +1,90 @@
     2.4 +/*
     2.5 + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
     2.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     2.7 + *
     2.8 + * This code is free software; you can redistribute it and/or modify it
     2.9 + * under the terms of the GNU General Public License version 2 only, as
    2.10 + * published by the Free Software Foundation.  Oracle designates this
    2.11 + * particular file as subject to the "Classpath" exception as provided
    2.12 + * by Oracle in the LICENSE file that accompanied this code.
    2.13 + *
    2.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    2.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    2.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    2.17 + * version 2 for more details (a copy is included in the LICENSE file that
    2.18 + * accompanied this code).
    2.19 + *
    2.20 + * You should have received a copy of the GNU General Public License version
    2.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    2.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    2.23 + *
    2.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    2.25 + * or visit www.oracle.com if you need additional information or have any
    2.26 + * questions.
    2.27 + */
    2.28 +
    2.29 +package com.sun.tools.classfile;
    2.30 +
    2.31 +import java.io.IOException;
    2.32 +
    2.33 +/**
    2.34 + * See JVMS3 <TBD>
    2.35 + * http://cr.openjdk.java.net/~jrose/pres/indy-javadoc-mlvm/
    2.36 + *
    2.37 + *  <p><b>This is NOT part of any supported API.
    2.38 + *  If you write code that depends on this, you do so at your own risk.
    2.39 + *  This code and its internal interfaces are subject to change or
    2.40 + *  deletion without notice.</b>
    2.41 + */
    2.42 +public class BootstrapMethods_attribute extends Attribute {
    2.43 +    public final BootstrapMethodSpecifier[] bootstrap_method_specifiers;
    2.44 +
    2.45 +    BootstrapMethods_attribute(ClassReader cr, int name_index, int length)
    2.46 +            throws IOException, AttributeException {
    2.47 +        super(name_index, length);
    2.48 +        int bootstrap_method_count = cr.readUnsignedShort();
    2.49 +        bootstrap_method_specifiers = new BootstrapMethodSpecifier[bootstrap_method_count];
    2.50 +        for (int i = 0; i < bootstrap_method_specifiers.length; i++)
    2.51 +            bootstrap_method_specifiers[i] = new BootstrapMethodSpecifier(cr);
    2.52 +    }
    2.53 +
    2.54 +    public  BootstrapMethods_attribute(int name_index, BootstrapMethodSpecifier[] bootstrap_method_specifiers) {
    2.55 +        super(name_index, length(bootstrap_method_specifiers));
    2.56 +        this.bootstrap_method_specifiers = bootstrap_method_specifiers;
    2.57 +    }
    2.58 +
    2.59 +    public static int length(BootstrapMethodSpecifier[] bootstrap_method_specifiers) {
    2.60 +        int n = 2;
    2.61 +        for (BootstrapMethodSpecifier b : bootstrap_method_specifiers)
    2.62 +            n += b.length();
    2.63 +        return n;
    2.64 +    }
    2.65 +
    2.66 +    @Override
    2.67 +    public <R, P> R accept(Visitor<R, P> visitor, P p) {
    2.68 +        return visitor.visitBootstrapMethods(this, p);
    2.69 +    }
    2.70 +
    2.71 +    public static class BootstrapMethodSpecifier {
    2.72 +        public int bootstrap_method_ref;
    2.73 +        public int[] bootstrap_arguments;
    2.74 +
    2.75 +        public BootstrapMethodSpecifier(int bootstrap_method_ref, int[] bootstrap_arguments) {
    2.76 +            this.bootstrap_method_ref = bootstrap_method_ref;
    2.77 +            this.bootstrap_arguments = bootstrap_arguments;
    2.78 +        }
    2.79 +        BootstrapMethodSpecifier(ClassReader cr) throws IOException {
    2.80 +            bootstrap_method_ref = cr.readUnsignedShort();
    2.81 +            int method_count = cr.readUnsignedShort();
    2.82 +            bootstrap_arguments = new int[method_count];
    2.83 +            for (int i = 0; i < bootstrap_arguments.length; i++) {
    2.84 +                bootstrap_arguments[i] = cr.readUnsignedShort();
    2.85 +            }
    2.86 +        }
    2.87 +
    2.88 +        int length() {
    2.89 +            // u2 (method_ref) + u2 (argc) + u2 * argc
    2.90 +            return 2 + 2 + (bootstrap_arguments.length * 2);
    2.91 +        }
    2.92 +    }
    2.93 +}
     3.1 --- a/src/share/classes/com/sun/tools/classfile/ClassTranslator.java	Fri Jan 14 13:59:18 2011 -0800
     3.2 +++ b/src/share/classes/com/sun/tools/classfile/ClassTranslator.java	Tue Jan 18 08:37:05 2011 -0800
     3.3 @@ -1,5 +1,5 @@
     3.4  /*
     3.5 - * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
     3.6 + * Copyright (c) 2008, 2011 Oracle and/or its affiliates. All rights reserved.
     3.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3.8   *
     3.9   * This code is free software; you can redistribute it and/or modify it
    3.10 @@ -31,7 +31,10 @@
    3.11  import com.sun.tools.classfile.ConstantPool.CONSTANT_Float_info;
    3.12  import com.sun.tools.classfile.ConstantPool.CONSTANT_Integer_info;
    3.13  import com.sun.tools.classfile.ConstantPool.CONSTANT_InterfaceMethodref_info;
    3.14 +import com.sun.tools.classfile.ConstantPool.CONSTANT_InvokeDynamic_info;
    3.15  import com.sun.tools.classfile.ConstantPool.CONSTANT_Long_info;
    3.16 +import com.sun.tools.classfile.ConstantPool.CONSTANT_MethodHandle_info;
    3.17 +import com.sun.tools.classfile.ConstantPool.CONSTANT_MethodType_info;
    3.18  import com.sun.tools.classfile.ConstantPool.CONSTANT_Methodref_info;
    3.19  import com.sun.tools.classfile.ConstantPool.CONSTANT_NameAndType_info;
    3.20  import com.sun.tools.classfile.ConstantPool.CONSTANT_String_info;
    3.21 @@ -304,6 +307,20 @@
    3.22          return info;
    3.23      }
    3.24  
    3.25 +    public CPInfo visitInvokeDynamic(CONSTANT_InvokeDynamic_info info, Map<Object, Object> translations) {
    3.26 +        CONSTANT_InvokeDynamic_info info2 = (CONSTANT_InvokeDynamic_info) translations.get(info);
    3.27 +        if (info2 == null) {
    3.28 +            ConstantPool cp2 = translate(info.cp, translations);
    3.29 +            if (cp2 == info.cp) {
    3.30 +                info2 = info;
    3.31 +            } else {
    3.32 +                info2 = new CONSTANT_InvokeDynamic_info(cp2, info.bootstrap_method_attr_index, info.name_and_type_index);
    3.33 +            }
    3.34 +            translations.put(info, info2);
    3.35 +        }
    3.36 +        return info;
    3.37 +    }
    3.38 +
    3.39      public CPInfo visitLong(CONSTANT_Long_info info, Map<Object, Object> translations) {
    3.40          CONSTANT_Long_info info2 = (CONSTANT_Long_info) translations.get(info);
    3.41          if (info2 == null) {
    3.42 @@ -339,6 +356,34 @@
    3.43          return info;
    3.44      }
    3.45  
    3.46 +    public CPInfo visitMethodHandle(CONSTANT_MethodHandle_info info, Map<Object, Object> translations) {
    3.47 +        CONSTANT_MethodHandle_info info2 = (CONSTANT_MethodHandle_info) translations.get(info);
    3.48 +        if (info2 == null) {
    3.49 +            ConstantPool cp2 = translate(info.cp, translations);
    3.50 +            if (cp2 == info.cp) {
    3.51 +                info2 = info;
    3.52 +            } else {
    3.53 +                info2 = new CONSTANT_MethodHandle_info(cp2, info.reference_kind, info.reference_index);
    3.54 +            }
    3.55 +            translations.put(info, info2);
    3.56 +        }
    3.57 +        return info;
    3.58 +    }
    3.59 +
    3.60 +    public CPInfo visitMethodType(CONSTANT_MethodType_info info, Map<Object, Object> translations) {
    3.61 +        CONSTANT_MethodType_info info2 = (CONSTANT_MethodType_info) translations.get(info);
    3.62 +        if (info2 == null) {
    3.63 +            ConstantPool cp2 = translate(info.cp, translations);
    3.64 +            if (cp2 == info.cp) {
    3.65 +                info2 = info;
    3.66 +            } else {
    3.67 +                info2 = new CONSTANT_MethodType_info(cp2, info.descriptor_index);
    3.68 +            }
    3.69 +            translations.put(info, info2);
    3.70 +        }
    3.71 +        return info;
    3.72 +    }
    3.73 +
    3.74      public CPInfo visitString(CONSTANT_String_info info, Map<Object, Object> translations) {
    3.75          CONSTANT_String_info info2 = (CONSTANT_String_info) translations.get(info);
    3.76          if (info2 == null) {
     4.1 --- a/src/share/classes/com/sun/tools/classfile/ClassWriter.java	Fri Jan 14 13:59:18 2011 -0800
     4.2 +++ b/src/share/classes/com/sun/tools/classfile/ClassWriter.java	Tue Jan 18 08:37:05 2011 -0800
     4.3 @@ -267,6 +267,12 @@
     4.4              return 1;
     4.5          }
     4.6  
     4.7 +        public Integer visitInvokeDynamic(CONSTANT_InvokeDynamic_info info, ClassOutputStream out) {
     4.8 +            out.writeShort(info.bootstrap_method_attr_index);
     4.9 +            out.writeShort(info.name_and_type_index);
    4.10 +            return 1;
    4.11 +        }
    4.12 +
    4.13          public Integer visitLong(CONSTANT_Long_info info, ClassOutputStream out) {
    4.14              out.writeLong(info.value);
    4.15              return 2;
    4.16 @@ -278,6 +284,17 @@
    4.17              return 1;
    4.18          }
    4.19  
    4.20 +        public Integer visitMethodHandle(CONSTANT_MethodHandle_info info, ClassOutputStream out) {
    4.21 +            out.writeByte(info.reference_kind.tag);
    4.22 +            out.writeShort(info.reference_index);
    4.23 +            return 1;
    4.24 +        }
    4.25 +
    4.26 +        public Integer visitMethodType(CONSTANT_MethodType_info info, ClassOutputStream out) {
    4.27 +            out.writeShort(info.descriptor_index);
    4.28 +            return 1;
    4.29 +        }
    4.30 +
    4.31          public Integer visitMethodref(CONSTANT_Methodref_info info, ClassOutputStream out) {
    4.32              return writeRef(info, out);
    4.33          }
    4.34 @@ -332,6 +349,19 @@
    4.35              return null;
    4.36          }
    4.37  
    4.38 +        public Void visitBootstrapMethods(BootstrapMethods_attribute attr, ClassOutputStream out) {
    4.39 +            out.writeShort(attr.bootstrap_method_specifiers.length);
    4.40 +            for (BootstrapMethods_attribute.BootstrapMethodSpecifier bsm : attr.bootstrap_method_specifiers) {
    4.41 +                out.writeShort(bsm.bootstrap_method_ref);
    4.42 +                int bsm_args_count = bsm.bootstrap_arguments.length;
    4.43 +                out.writeShort(bsm_args_count);
    4.44 +                for (int i : bsm.bootstrap_arguments) {
    4.45 +                    out.writeShort(i);
    4.46 +                }
    4.47 +            }
    4.48 +            return null;
    4.49 +        }
    4.50 +
    4.51          public Void visitCharacterRangeTable(CharacterRangeTable_attribute attr, ClassOutputStream out) {
    4.52              out.writeShort(attr.character_range_table.length);
    4.53              for (CharacterRangeTable_attribute.Entry e: attr.character_range_table)
     5.1 --- a/src/share/classes/com/sun/tools/classfile/ConstantPool.java	Fri Jan 14 13:59:18 2011 -0800
     5.2 +++ b/src/share/classes/com/sun/tools/classfile/ConstantPool.java	Tue Jan 18 08:37:05 2011 -0800
     5.3 @@ -1,5 +1,5 @@
     5.4  /*
     5.5 - * Copyright (c) 2007, 2009, Oracle and/or its affiliates. All rights reserved.
     5.6 + * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
     5.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     5.8   *
     5.9   * This code is free software; you can redistribute it and/or modify it
    5.10 @@ -114,6 +114,54 @@
    5.11      public static final int CONSTANT_Methodref = 10;
    5.12      public static final int CONSTANT_InterfaceMethodref = 11;
    5.13      public static final int CONSTANT_NameAndType = 12;
    5.14 +    public static final int CONSTANT_MethodHandle = 15;
    5.15 +    public static final int CONSTANT_MethodType = 16;
    5.16 +    public static final int CONSTANT_InvokeDynamic = 18;
    5.17 +
    5.18 +    public static enum RefKind {
    5.19 +        REF_getField(1, "getfield"),
    5.20 +        REF_getStatic(2, "getstatic"),
    5.21 +        REF_putField(3, "putfield"),
    5.22 +        REF_putStatic(4, "putstatic"),
    5.23 +        REF_invokeVirtual(5, "invokevirtual"),
    5.24 +        REF_invokeStatic(6, "invokestatic"),
    5.25 +        REF_invokeSpecial(7, "invokespecial"),
    5.26 +        REF_newInvokeSpecial(8, "newinvokespecial"),
    5.27 +        REF_invokeInterface(9, "invokeinterface");
    5.28 +
    5.29 +        public final int tag;
    5.30 +        public final String name;
    5.31 +
    5.32 +        RefKind(int tag, String name) {
    5.33 +            this.tag = tag;
    5.34 +            this.name = name;
    5.35 +        }
    5.36 +
    5.37 +        static RefKind getRefkind(int tag) {
    5.38 +            switch(tag) {
    5.39 +                case 1:
    5.40 +                    return REF_getField;
    5.41 +                case 2:
    5.42 +                    return REF_getStatic;
    5.43 +                case 3:
    5.44 +                    return REF_putField;
    5.45 +                case 4:
    5.46 +                    return REF_putStatic;
    5.47 +                case 5:
    5.48 +                    return REF_invokeVirtual;
    5.49 +                case 6:
    5.50 +                    return REF_invokeStatic;
    5.51 +                case 7:
    5.52 +                    return REF_invokeSpecial;
    5.53 +                case 8:
    5.54 +                    return REF_newInvokeSpecial;
    5.55 +                case 9:
    5.56 +                    return REF_invokeInterface;
    5.57 +                default:
    5.58 +                    return null;
    5.59 +            }
    5.60 +        }
    5.61 +    }
    5.62  
    5.63      ConstantPool(ClassReader cr) throws IOException, InvalidEntry {
    5.64          int count = cr.readUnsignedShort();
    5.65 @@ -146,11 +194,23 @@
    5.66                  pool[i] = new CONSTANT_InterfaceMethodref_info(this, cr);
    5.67                  break;
    5.68  
    5.69 +            case CONSTANT_InvokeDynamic:
    5.70 +                pool[i] = new CONSTANT_InvokeDynamic_info(this, cr);
    5.71 +                break;
    5.72 +
    5.73              case CONSTANT_Long:
    5.74                  pool[i] = new CONSTANT_Long_info(cr);
    5.75                  i++;
    5.76                  break;
    5.77  
    5.78 +            case CONSTANT_MethodHandle:
    5.79 +                pool[i] = new CONSTANT_MethodHandle_info(this, cr);
    5.80 +                break;
    5.81 +
    5.82 +            case CONSTANT_MethodType:
    5.83 +                pool[i] = new CONSTANT_MethodType_info(this, cr);
    5.84 +                break;
    5.85 +
    5.86              case CONSTANT_Methodref:
    5.87                  pool[i] = new CONSTANT_Methodref_info(this, cr);
    5.88                  break;
    5.89 @@ -279,9 +339,12 @@
    5.90          R visitFloat(CONSTANT_Float_info info, P p);
    5.91          R visitInteger(CONSTANT_Integer_info info, P p);
    5.92          R visitInterfaceMethodref(CONSTANT_InterfaceMethodref_info info, P p);
    5.93 +        R visitInvokeDynamic(CONSTANT_InvokeDynamic_info info, P p);
    5.94          R visitLong(CONSTANT_Long_info info, P p);
    5.95          R visitNameAndType(CONSTANT_NameAndType_info info, P p);
    5.96          R visitMethodref(CONSTANT_Methodref_info info, P p);
    5.97 +        R visitMethodHandle(CONSTANT_MethodHandle_info info, P p);
    5.98 +        R visitMethodType(CONSTANT_MethodType_info info, P p);
    5.99          R visitString(CONSTANT_String_info info, P p);
   5.100          R visitUtf8(CONSTANT_Utf8_info info, P p);
   5.101      }
   5.102 @@ -548,6 +611,44 @@
   5.103          }
   5.104      }
   5.105  
   5.106 +    public static class CONSTANT_InvokeDynamic_info extends CPInfo {
   5.107 +        CONSTANT_InvokeDynamic_info(ConstantPool cp, ClassReader cr) throws IOException {
   5.108 +            super(cp);
   5.109 +            bootstrap_method_attr_index = cr.readUnsignedShort();
   5.110 +            name_and_type_index = cr.readUnsignedShort();
   5.111 +        }
   5.112 +
   5.113 +        public CONSTANT_InvokeDynamic_info(ConstantPool cp, int bootstrap_method_index, int name_and_type_index) {
   5.114 +            super(cp);
   5.115 +            this.bootstrap_method_attr_index = bootstrap_method_index;
   5.116 +            this.name_and_type_index = name_and_type_index;
   5.117 +        }
   5.118 +
   5.119 +        public int getTag() {
   5.120 +            return CONSTANT_InvokeDynamic;
   5.121 +        }
   5.122 +
   5.123 +        public int byteLength() {
   5.124 +            return 5;
   5.125 +        }
   5.126 +
   5.127 +        @Override
   5.128 +        public String toString() {
   5.129 +            return "CONSTANT_InvokeDynamic_info[bootstrap_method_index: " + bootstrap_method_attr_index + ", name_and_type_index: " + name_and_type_index + "]";
   5.130 +        }
   5.131 +
   5.132 +        public <R, D> R accept(Visitor<R, D> visitor, D data) {
   5.133 +            return visitor.visitInvokeDynamic(this, data);
   5.134 +        }
   5.135 +
   5.136 +        public CONSTANT_NameAndType_info getNameAndTypeInfo() throws ConstantPoolException {
   5.137 +            return cp.getNameAndTypeInfo(name_and_type_index);
   5.138 +        }
   5.139 +
   5.140 +        public final int bootstrap_method_attr_index;
   5.141 +        public final int name_and_type_index;
   5.142 +    }
   5.143 +
   5.144      public static class CONSTANT_Long_info extends CPInfo {
   5.145          CONSTANT_Long_info(ClassReader cr) throws IOException {
   5.146              value = cr.readLong();
   5.147 @@ -582,6 +683,87 @@
   5.148          public final long value;
   5.149      }
   5.150  
   5.151 +    public static class CONSTANT_MethodHandle_info extends CPInfo {
   5.152 +        CONSTANT_MethodHandle_info(ConstantPool cp, ClassReader cr) throws IOException {
   5.153 +            super(cp);
   5.154 +            reference_kind =  RefKind.getRefkind(cr.readUnsignedByte());
   5.155 +            reference_index = cr.readUnsignedShort();
   5.156 +        }
   5.157 +
   5.158 +        public CONSTANT_MethodHandle_info(ConstantPool cp, RefKind ref_kind, int member_index) {
   5.159 +            super(cp);
   5.160 +            this.reference_kind = ref_kind;
   5.161 +            this.reference_index = member_index;
   5.162 +        }
   5.163 +
   5.164 +        public int getTag() {
   5.165 +            return CONSTANT_MethodHandle;
   5.166 +        }
   5.167 +
   5.168 +        public int byteLength() {
   5.169 +            return 4;
   5.170 +        }
   5.171 +
   5.172 +        @Override
   5.173 +        public String toString() {
   5.174 +            return "CONSTANT_MethodHandle_info[ref_kind: " + reference_kind + ", member_index: " + reference_index + "]";
   5.175 +        }
   5.176 +
   5.177 +        public <R, D> R accept(Visitor<R, D> visitor, D data) {
   5.178 +            return visitor.visitMethodHandle(this, data);
   5.179 +        }
   5.180 +
   5.181 +        public CPRefInfo getCPRefInfo() throws ConstantPoolException {
   5.182 +            int expected = CONSTANT_Methodref;
   5.183 +            int actual = cp.get(reference_index).getTag();
   5.184 +            // allow these tag types also:
   5.185 +            switch (actual) {
   5.186 +                case CONSTANT_Fieldref:
   5.187 +                case CONSTANT_InterfaceMethodref:
   5.188 +                    expected = actual;
   5.189 +            }
   5.190 +            return (CPRefInfo) cp.get(reference_index, expected);
   5.191 +        }
   5.192 +
   5.193 +        public final RefKind reference_kind;
   5.194 +        public final int reference_index;
   5.195 +    }
   5.196 +
   5.197 +    public static class CONSTANT_MethodType_info extends CPInfo {
   5.198 +        CONSTANT_MethodType_info(ConstantPool cp, ClassReader cr) throws IOException {
   5.199 +            super(cp);
   5.200 +            descriptor_index = cr.readUnsignedShort();
   5.201 +        }
   5.202 +
   5.203 +        public CONSTANT_MethodType_info(ConstantPool cp, int signature_index) {
   5.204 +            super(cp);
   5.205 +            this.descriptor_index = signature_index;
   5.206 +        }
   5.207 +
   5.208 +        public int getTag() {
   5.209 +            return CONSTANT_MethodType;
   5.210 +        }
   5.211 +
   5.212 +        public int byteLength() {
   5.213 +            return 3;
   5.214 +        }
   5.215 +
   5.216 +        @Override
   5.217 +        public String toString() {
   5.218 +            return "CONSTANT_MethodType_info[signature_index: " + descriptor_index + "]";
   5.219 +        }
   5.220 +
   5.221 +        public <R, D> R accept(Visitor<R, D> visitor, D data) {
   5.222 +            return visitor.visitMethodType(this, data);
   5.223 +        }
   5.224 +
   5.225 +        public String getType() throws ConstantPoolException {
   5.226 +            return cp.getUTF8Value(descriptor_index);
   5.227 +        }
   5.228 +
   5.229 +        public final int descriptor_index;
   5.230 +    }
   5.231 +
   5.232      public static class CONSTANT_Methodref_info extends CPRefInfo {
   5.233          CONSTANT_Methodref_info(ConstantPool cp, ClassReader cr) throws IOException {
   5.234              super(cp, cr, CONSTANT_Methodref);
   5.235 @@ -729,5 +911,4 @@
   5.236          public final String value;
   5.237      }
   5.238  
   5.239 -
   5.240  }
     6.1 --- a/src/share/classes/com/sun/tools/classfile/Dependencies.java	Fri Jan 14 13:59:18 2011 -0800
     6.2 +++ b/src/share/classes/com/sun/tools/classfile/Dependencies.java	Tue Jan 18 08:37:05 2011 -0800
     6.3 @@ -1,5 +1,5 @@
     6.4  /*
     6.5 - * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
     6.6 + * Copyright (c) 2009, 2011 Oracle and/or its affiliates. All rights reserved.
     6.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     6.8   *
     6.9   * This code is free software; you can redistribute it and/or modify it
    6.10 @@ -626,10 +626,26 @@
    6.11                  return visitRef(info, p);
    6.12              }
    6.13  
    6.14 +            public Void visitInvokeDynamic(CONSTANT_InvokeDynamic_info info, Void p) {
    6.15 +                return null;
    6.16 +            }
    6.17 +
    6.18              public Void visitLong(CONSTANT_Long_info info, Void p) {
    6.19                  return null;
    6.20              }
    6.21  
    6.22 +            public Void visitMethodHandle(CONSTANT_MethodHandle_info info, Void p) {
    6.23 +                return null;
    6.24 +            }
    6.25 +
    6.26 +            public Void visitMethodType(CONSTANT_MethodType_info info, Void p) {
    6.27 +                return null;
    6.28 +            }
    6.29 +
    6.30 +            public Void visitMethodref(CONSTANT_Methodref_info info, Void p) {
    6.31 +                return visitRef(info, p);
    6.32 +            }
    6.33 +
    6.34              public Void visitNameAndType(CONSTANT_NameAndType_info info, Void p) {
    6.35                  try {
    6.36                      new Signature(info.type_index).getType(constant_pool).accept(this, null);
    6.37 @@ -639,10 +655,6 @@
    6.38                  }
    6.39              }
    6.40  
    6.41 -            public Void visitMethodref(CONSTANT_Methodref_info info, Void p) {
    6.42 -                return visitRef(info, p);
    6.43 -            }
    6.44 -
    6.45              public Void visitString(CONSTANT_String_info info, Void p) {
    6.46                  return null;
    6.47              }
     7.1 --- a/src/share/classes/com/sun/tools/javac/jvm/ClassFile.java	Fri Jan 14 13:59:18 2011 -0800
     7.2 +++ b/src/share/classes/com/sun/tools/javac/jvm/ClassFile.java	Tue Jan 18 08:37:05 2011 -0800
     7.3 @@ -1,5 +1,5 @@
     7.4  /*
     7.5 - * Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved.
     7.6 + * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
     7.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     7.8   *
     7.9   * This code is free software; you can redistribute it and/or modify it
    7.10 @@ -80,6 +80,9 @@
    7.11      public final static int CONSTANT_Methodref = 10;
    7.12      public final static int CONSTANT_InterfaceMethodref = 11;
    7.13      public final static int CONSTANT_NameandType = 12;
    7.14 +    public final static int CONSTANT_MethodHandle = 15;
    7.15 +    public final static int CONSTANT_MethodType = 16;
    7.16 +    public final static int CONSTANT_InvokeDynamic = 18;
    7.17  
    7.18      public final static int MAX_PARAMETERS = 0xff;
    7.19      public final static int MAX_DIMENSIONS = 0xff;
     8.1 --- a/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java	Fri Jan 14 13:59:18 2011 -0800
     8.2 +++ b/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java	Tue Jan 18 08:37:05 2011 -0800
     8.3 @@ -434,14 +434,19 @@
     8.4              }
     8.5              case CONSTANT_Class:
     8.6              case CONSTANT_String:
     8.7 +            case CONSTANT_MethodType:
     8.8                  bp = bp + 2;
     8.9                  break;
    8.10 +            case CONSTANT_MethodHandle:
    8.11 +                bp = bp + 3;
    8.12 +                break;
    8.13              case CONSTANT_Fieldref:
    8.14              case CONSTANT_Methodref:
    8.15              case CONSTANT_InterfaceMethodref:
    8.16              case CONSTANT_NameandType:
    8.17              case CONSTANT_Integer:
    8.18              case CONSTANT_Float:
    8.19 +            case CONSTANT_InvokeDynamic:
    8.20                  bp = bp + 4;
    8.21                  break;
    8.22              case CONSTANT_Long:
    8.23 @@ -510,6 +515,15 @@
    8.24          case CONSTANT_Double:
    8.25              poolObj[i] = new Double(getDouble(index + 1));
    8.26              break;
    8.27 +        case CONSTANT_MethodHandle:
    8.28 +            skipBytes(4);
    8.29 +            break;
    8.30 +        case CONSTANT_MethodType:
    8.31 +            skipBytes(3);
    8.32 +            break;
    8.33 +        case CONSTANT_InvokeDynamic:
    8.34 +            skipBytes(5);
    8.35 +            break;
    8.36          default:
    8.37              throw badClassFile("bad.const.pool.tag", Byte.toString(tag));
    8.38          }
    8.39 @@ -1821,6 +1835,13 @@
    8.40          sym.savedParameterNames = paramNames.reverse();
    8.41      }
    8.42  
    8.43 +    /**
    8.44 +     * skip n bytes
    8.45 +     */
    8.46 +    void skipBytes(int n) {
    8.47 +        bp = bp + n;
    8.48 +    }
    8.49 +
    8.50      /** Skip a field or method
    8.51       */
    8.52      void skipMember() {
     9.1 --- a/src/share/classes/com/sun/tools/javap/AttributeWriter.java	Fri Jan 14 13:59:18 2011 -0800
     9.2 +++ b/src/share/classes/com/sun/tools/javap/AttributeWriter.java	Tue Jan 18 08:37:05 2011 -0800
     9.3 @@ -31,6 +31,7 @@
     9.4  import com.sun.tools.classfile.AnnotationDefault_attribute;
     9.5  import com.sun.tools.classfile.Attribute;
     9.6  import com.sun.tools.classfile.Attributes;
     9.7 +import com.sun.tools.classfile.BootstrapMethods_attribute;
     9.8  import com.sun.tools.classfile.CharacterRangeTable_attribute;
     9.9  import com.sun.tools.classfile.Code_attribute;
    9.10  import com.sun.tools.classfile.CompilationID_attribute;
    9.11 @@ -151,6 +152,25 @@
    9.12          return null;
    9.13      }
    9.14  
    9.15 +    public Void visitBootstrapMethods(BootstrapMethods_attribute attr, Void p) {
    9.16 +        println(Attribute.BootstrapMethods + ":");
    9.17 +        for (int i = 0; i < attr.bootstrap_method_specifiers.length ; i++) {
    9.18 +            BootstrapMethods_attribute.BootstrapMethodSpecifier bsm = attr.bootstrap_method_specifiers[i];
    9.19 +            indent(+1);
    9.20 +            print(i + ": #" + bsm.bootstrap_method_ref + " ");
    9.21 +            println(constantWriter.stringValue(bsm.bootstrap_method_ref));
    9.22 +            indent(+1);
    9.23 +            println("Method arguments:");
    9.24 +            indent(+1);
    9.25 +            for (int j = 0; j < bsm.bootstrap_arguments.length; j++) {
    9.26 +                print("#" + bsm.bootstrap_arguments[j] + " ");
    9.27 +                println(constantWriter.stringValue(bsm.bootstrap_arguments[j]));
    9.28 +            }
    9.29 +            indent(-3);
    9.30 +        }
    9.31 +        return null;
    9.32 +    }
    9.33 +
    9.34      public Void visitCharacterRangeTable(CharacterRangeTable_attribute attr, Void ignore) {
    9.35          println("CharacterRangeTable:");
    9.36          indent(+1);
    10.1 --- a/src/share/classes/com/sun/tools/javap/ConstantWriter.java	Fri Jan 14 13:59:18 2011 -0800
    10.2 +++ b/src/share/classes/com/sun/tools/javap/ConstantWriter.java	Tue Jan 18 08:37:05 2011 -0800
    10.3 @@ -1,5 +1,5 @@
    10.4  /*
    10.5 - * Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved.
    10.6 + * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
    10.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    10.8   *
    10.9   * This code is free software; you can redistribute it and/or modify it
   10.10 @@ -97,6 +97,13 @@
   10.11                  return 1;
   10.12              }
   10.13  
   10.14 +            public Integer visitInvokeDynamic(CONSTANT_InvokeDynamic_info info, Void p) {
   10.15 +                print("#" + info.bootstrap_method_attr_index + ":#" + info.name_and_type_index);
   10.16 +                tab();
   10.17 +                println("//  " + stringValue(info));
   10.18 +                return 1;
   10.19 +            }
   10.20 +
   10.21              public Integer visitLong(CONSTANT_Long_info info, Void p) {
   10.22                  println(stringValue(info));
   10.23                  return 2;
   10.24 @@ -116,6 +123,20 @@
   10.25                  return 1;
   10.26              }
   10.27  
   10.28 +            public Integer visitMethodHandle(CONSTANT_MethodHandle_info info, Void p) {
   10.29 +                print("#" + info.reference_kind.tag + ":#" + info.reference_index);
   10.30 +                tab();
   10.31 +                println("//  " + stringValue(info));
   10.32 +                return 1;
   10.33 +            }
   10.34 +
   10.35 +            public Integer visitMethodType(CONSTANT_MethodType_info info, Void p) {
   10.36 +                print("#" + info.descriptor_index);
   10.37 +                tab();
   10.38 +                println("//  " + stringValue(info));
   10.39 +                return 1;
   10.40 +            }
   10.41 +
   10.42              public Integer visitString(CONSTANT_String_info info, Void p) {
   10.43                  print("#" + info.string_index);
   10.44                  tab();
   10.45 @@ -201,14 +222,20 @@
   10.46                  return "String";
   10.47              case CONSTANT_Fieldref:
   10.48                  return "Field";
   10.49 +            case CONSTANT_MethodHandle:
   10.50 +                return "MethodHandle";
   10.51 +            case CONSTANT_MethodType:
   10.52 +                return "MethodType";
   10.53              case CONSTANT_Methodref:
   10.54                  return "Method";
   10.55              case CONSTANT_InterfaceMethodref:
   10.56                  return "InterfaceMethod";
   10.57 +            case CONSTANT_InvokeDynamic:
   10.58 +                return "InvokeDynamic";
   10.59              case CONSTANT_NameAndType:
   10.60                  return "NameAndType";
   10.61              default:
   10.62 -                return "(unknown tag)";
   10.63 +                return "(unknown tag " + tag + ")";
   10.64          }
   10.65      }
   10.66  
   10.67 @@ -264,6 +291,15 @@
   10.68              return visitRef(info, p);
   10.69          }
   10.70  
   10.71 +        public String visitInvokeDynamic(CONSTANT_InvokeDynamic_info info, Void p) {
   10.72 +            try {
   10.73 +                String callee = stringValue(info.getNameAndTypeInfo());
   10.74 +                return "#" + info.bootstrap_method_attr_index + ":" + callee;
   10.75 +            } catch (ConstantPoolException e) {
   10.76 +                return report(e);
   10.77 +            }
   10.78 +        }
   10.79 +
   10.80          public String visitLong(CONSTANT_Long_info info, Void p) {
   10.81              return info.value + "l";
   10.82          }
   10.83 @@ -288,6 +324,22 @@
   10.84              }
   10.85          }
   10.86  
   10.87 +        public String visitMethodHandle(CONSTANT_MethodHandle_info info, Void p) {
   10.88 +            try {
   10.89 +                return info.reference_kind.name + " " + stringValue(info.getCPRefInfo());
   10.90 +            } catch (ConstantPoolException e) {
   10.91 +                return report(e);
   10.92 +            }
   10.93 +        }
   10.94 +
   10.95 +        public String visitMethodType(CONSTANT_MethodType_info info, Void p) {
   10.96 +            try {
   10.97 +                return info.getType();
   10.98 +            } catch (ConstantPoolException e) {
   10.99 +                return report(e);
  10.100 +            }
  10.101 +        }
  10.102 +
  10.103          public String visitMethodref(CONSTANT_Methodref_info info, Void p) {
  10.104              return visitRef(info, p);
  10.105          }
  10.106 @@ -347,7 +399,6 @@
  10.107          }
  10.108      }
  10.109  
  10.110 -
  10.111      /* If name is a valid binary name, return it; otherwise quote it. */
  10.112      private static String checkName(String name) {
  10.113          if (name == null)

mercurial