First steps towards parsing invokeDynamic jdk8
authorJaroslav Tulach <jaroslav.tulach@apidesign.org>
Thu, 10 Jul 2014 08:11:53 +0200
branchjdk8
changeset 1640f61e9984adff
parent 1639 4b09a4b689a4
child 1641 2111057af3b2
First steps towards parsing invokeDynamic
rt/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeParser.java
rt/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java
     1.1 --- a/rt/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeParser.java	Thu Jun 26 23:54:17 2014 +0200
     1.2 +++ b/rt/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeParser.java	Thu Jul 10 08:11:53 2014 +0200
     1.3 @@ -28,6 +28,7 @@
     1.4  import java.io.DataInputStream;
     1.5  import java.io.IOException;
     1.6  import java.io.InputStream;
     1.7 +import java.util.Arrays;
     1.8  import org.apidesign.bck2brwsr.core.JavaScriptBody;
     1.9  import org.apidesign.bck2brwsr.core.JavaScriptPrototype;
    1.10  
    1.11 @@ -290,7 +291,7 @@
    1.12      public static final int opc_invokespecial            = 183;
    1.13      public static final int opc_invokestatic             = 184;
    1.14      public static final int opc_invokeinterface          = 185;
    1.15 -//    public static final int opc_xxxunusedxxx             = 186;
    1.16 +    public static final int opc_invokedynamic            = 186;
    1.17      public static final int opc_new                      = 187;
    1.18      public static final int opc_newarray                 = 188;
    1.19      public static final int opc_anewarray                = 189;
    1.20 @@ -624,6 +625,12 @@
    1.21                      AttrData attr = new AttrData(this);
    1.22                      attr.read(name_cpx);
    1.23                      attrs[k] = attr;
    1.24 +                } else if (getTag(name_cpx) == CONSTANT_UTF8
    1.25 +                    && getString(name_cpx).equals("BootstrapMethods")) {
    1.26 +                    AttrData attr = new AttrData(this);
    1.27 +                    readBootstrapMethods(in);
    1.28 +                    attr.read(name_cpx);
    1.29 +                    attrs[k] = attr;
    1.30                  } else {
    1.31                      AttrData attr = new AttrData(this);
    1.32                      attr.read(name_cpx, in);
    1.33 @@ -633,6 +640,25 @@
    1.34              in.close();
    1.35          } // end ClassData.read()
    1.36  
    1.37 +        void readBootstrapMethods(DataInputStream in) throws IOException {
    1.38 +            int attr_len = in.readInt();  //attr_length
    1.39 +            int number = in.readShort();
    1.40 +            for (int i = 0; i < number; i++) {
    1.41 +                int ref = in.readShort();
    1.42 +                int len = in.readShort();
    1.43 +                int[] args = new int[len];
    1.44 +                for (int j = 0; j < len; j++) {
    1.45 +                    args[j] = in.readShort();
    1.46 +                }
    1.47 +                
    1.48 +                System.err.print("ref: " + ref + " len: " + len + ":");
    1.49 +                for (int j = 0; j < len; j++) {
    1.50 +                    System.err.print(" " + args[j]);
    1.51 +                }
    1.52 +                System.err.println();
    1.53 +            }
    1.54 +        }
    1.55 +        
    1.56          /**
    1.57           * Reads and stores constant pool info.
    1.58           */
    1.59 @@ -1813,7 +1839,7 @@
    1.60                  stackMap[i] = new StackMapData(in, this);
    1.61              }
    1.62          }
    1.63 -
    1.64 +        
    1.65          /**
    1.66           * Return access of the method.
    1.67           */
     2.1 --- a/rt/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java	Thu Jun 26 23:54:17 2014 +0200
     2.2 +++ b/rt/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java	Thu Jul 10 08:11:53 2014 +0200
     2.3 @@ -1051,6 +1051,13 @@
     2.4                  case opc_invokestatic:
     2.5                      i = invokeStaticMethod(byteCodes, i, smapper, true);
     2.6                      break;
     2.7 +                case opc_invokedynamic: {
     2.8 +                    int indx = readUShortArg(byteCodes, i);
     2.9 +                    System.err.println("invoke dynamic: " + indx);
    2.10 +                    emit(smapper, this, "throw 'Invoke dynamic: ' + @1;", "" + indx);
    2.11 +                    i += 4;
    2.12 +                    break;
    2.13 +                }
    2.14                  case opc_new: {
    2.15                      int indx = readUShortArg(byteCodes, i);
    2.16                      String ci = jc.getClassName(indx);