changeset 5783:fbcafacf92ef

Update sun.tools.java class file reading/writing support to include the new constant pool entries (including invokedynamic)
author Robert Field <Robert.Field@oracle.com>
date Thu, 19 Jul 2012 15:28:41 -0700
parents 04266eb6947c
children 364c8ee07a1a
files src/share/classes/sun/tools/java/BinaryConstantPool.java src/share/classes/sun/tools/java/RuntimeConstants.java
diffstat 2 files changed, 29 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/sun/tools/java/BinaryConstantPool.java	Wed Jul 18 23:58:39 2012 -0700
+++ b/src/share/classes/sun/tools/java/BinaryConstantPool.java	Thu Jul 19 15:28:41 2012 -0700
@@ -28,6 +28,7 @@
 import java.io.IOException;
 import java.io.DataInputStream;
 import java.io.DataOutputStream;
+import java.io.EOFException;
 import java.util.Vector;
 import java.util.Hashtable;
 
@@ -86,6 +87,16 @@
                 // JVM 4.4.2 CONSTANT_*ref_info.class_index & name_and_type_index
                 cpool[i] = new Integer((in.readUnsignedShort() << 16) | in.readUnsignedShort());
                 break;
+                  
+              case CONSTANT_METHODHANDLE:
+                cpool[i] = readBytes(in, 3);
+                break;
+              case CONSTANT_METHODTYPE:
+                cpool[i] = readBytes(in, 2);
+                break;
+              case CONSTANT_INVOKEDYNAMIC:
+                cpool[i] = readBytes(in, 4);
+                break;
 
               case 0:
               default:
@@ -93,6 +104,13 @@
             }
         }
     }
+    
+    private byte[] readBytes(DataInputStream in, int cnt) throws IOException {
+        byte[] b = new byte[cnt];
+        int rcnt = in.read(b, 0, cnt);
+        if (rcnt != cnt) throw new EOFException("Expected " + cnt + " bytes, got " + rcnt);
+        return b;
+    }
 
     /**
      * get a integer
@@ -160,6 +178,9 @@
             case CONSTANT_FLOAT:
             case CONSTANT_LONG:
             case CONSTANT_DOUBLE:
+            case CONSTANT_METHODHANDLE:
+            case CONSTANT_METHODTYPE:
+            case CONSTANT_INVOKEDYNAMIC:
                 return getValue(n);
 
             case CONSTANT_CLASS:
@@ -312,6 +333,11 @@
                     out.writeShort(value & 0xFFFF);
                     break;
                 }
+                case CONSTANT_METHODHANDLE:
+                case CONSTANT_METHODTYPE:
+                case CONSTANT_INVOKEDYNAMIC:
+                    out.write((byte[])x, 0, ((byte[])x).length);
+                    break;
                 default:
                      throw new ClassFormatError("invalid constant type: "
                                                    + (int)types[i]);
--- a/src/share/classes/sun/tools/java/RuntimeConstants.java	Wed Jul 18 23:58:39 2012 -0700
+++ b/src/share/classes/sun/tools/java/RuntimeConstants.java	Thu Jul 19 15:28:41 2012 -0700
@@ -87,6 +87,9 @@
     int CONSTANT_METHOD              = 10;
     int CONSTANT_INTERFACEMETHOD     = 11;
     int CONSTANT_NAMEANDTYPE         = 12;
+    int CONSTANT_METHODHANDLE        = 15;
+    int CONSTANT_METHODTYPE          = 16;
+    int CONSTANT_INVOKEDYNAMIC       = 18;
 
     /* Access and modifier flags */
     int ACC_PUBLIC                   = 0x00000001;