1.1 --- a/rt/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeParser.java Thu Jul 10 08:17:52 2014 +0200
1.2 +++ b/rt/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeParser.java Wed Jul 16 07:57:22 2014 +0200
1.3 @@ -499,7 +499,7 @@
1.4 */
1.5 private static class CPX {
1.6
1.7 - int cpx;
1.8 + final int cpx;
1.9
1.10 CPX(int cpx) {
1.11 this.cpx = cpx;
1.12 @@ -511,9 +511,9 @@
1.13 *
1.14 * @author Sucheta Dambalkar (Adopted code from jdis)
1.15 */
1.16 - private static class CPX2 {
1.17 + static class CPX2 {
1.18
1.19 - int cpx1, cpx2;
1.20 + final int cpx1, cpx2;
1.21
1.22 CPX2(int cpx1, int cpx2) {
1.23 this.cpx1 = cpx1;
1.24 @@ -542,6 +542,7 @@
1.25 private FieldData[] fields;
1.26 private MethodData[] methods;
1.27 private InnerClassData[] innerClasses;
1.28 + private BootMethodData[] bootMethods;
1.29 private int attributes_count;
1.30 private AttrData[] attrs;
1.31 private int source_cpx = 0;
1.32 @@ -628,7 +629,7 @@
1.33 } else if (getTag(name_cpx) == CONSTANT_UTF8
1.34 && getString(name_cpx).equals("BootstrapMethods")) {
1.35 AttrData attr = new AttrData(this);
1.36 - readBootstrapMethods(in);
1.37 + bootMethods = readBootstrapMethods(in);
1.38 attr.read(name_cpx);
1.39 attrs[k] = attr;
1.40 } else {
1.41 @@ -640,9 +641,10 @@
1.42 in.close();
1.43 } // end ClassData.read()
1.44
1.45 - void readBootstrapMethods(DataInputStream in) throws IOException {
1.46 - int attr_len = in.readInt(); //attr_length
1.47 + BootMethodData[] readBootstrapMethods(DataInputStream in) throws IOException {
1.48 + int attr_len = in.readInt(); //attr_lengt
1.49 int number = in.readShort();
1.50 + BootMethodData[] arr = new BootMethodData[number];
1.51 for (int i = 0; i < number; i++) {
1.52 int ref = in.readShort();
1.53 int len = in.readShort();
1.54 @@ -650,13 +652,9 @@
1.55 for (int j = 0; j < len; j++) {
1.56 args[j] = in.readShort();
1.57 }
1.58 -
1.59 - System.err.print("ref: " + ref + " len: " + len + ":");
1.60 - for (int j = 0; j < len; j++) {
1.61 - System.err.print(" " + args[j]);
1.62 - }
1.63 - System.err.println();
1.64 + arr[i] = new BootMethodData(this, ref, args);
1.65 }
1.66 + return arr;
1.67 }
1.68
1.69 /**
1.70 @@ -1144,8 +1142,12 @@
1.71
1.72 case CONSTANT_NAMEANDTYPE:
1.73 return getName(((CPX2) x).cpx1) + ":" + StringValue(((CPX2) x).cpx2);
1.74 + case CONSTANT_METHODHANDLE:
1.75 + return "K" + ((CPX2)x).cpx1 + "@" + stringValue(((CPX2)x).cpx2, textual);
1.76 + case CONSTANT_METHODTYPE:
1.77 + return stringValue(((CPX)x).cpx, true);
1.78 default:
1.79 - return "UnknownTag"; //TBD
1.80 + return "UnknownTag" + tag; //TBD
1.81 }
1.82 }
1.83
1.84 @@ -1228,6 +1230,10 @@
1.85 return null;
1.86 }
1.87 }
1.88 +
1.89 + public String getBootMethod(int indx) {
1.90 + return bootMethods != null ? bootMethods[indx].toString() : null;
1.91 + }
1.92
1.93 /**
1.94 * Returns total constant pool entry count.
1.95 @@ -1586,6 +1592,31 @@
1.96 return accflags;
1.97 }
1.98 } // end InnerClassData
1.99 +
1.100 + private static class BootMethodData {
1.101 + private final ClassData clazz;
1.102 + private final int method;
1.103 + private final int[] args;
1.104 +
1.105 + private BootMethodData(ClassData clazz, int method, int[] args) {
1.106 + this.clazz = clazz;
1.107 + this.method = method;
1.108 + this.args = args;
1.109 + }
1.110 +
1.111 + @Override
1.112 + public String toString() {
1.113 + StringBuilder sb = new StringBuilder();
1.114 + sb.append(clazz.stringValue(method, true));
1.115 + sb.append('(');
1.116 + for (int indx : args) {
1.117 + sb.append("\n ");
1.118 + sb.append(clazz.stringValue(indx, true));
1.119 + }
1.120 + sb.append(')');
1.121 + return sb.toString();
1.122 + }
1.123 + }
1.124
1.125 /**
1.126 * Strores LineNumberTable data information.
2.1 --- a/rt/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java Thu Jul 10 08:17:52 2014 +0200
2.2 +++ b/rt/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java Wed Jul 16 07:57:22 2014 +0200
2.3 @@ -1054,6 +1054,9 @@
2.4 case opc_invokedynamic: {
2.5 int indx = readUShortArg(byteCodes, i);
2.6 System.err.println("invoke dynamic: " + indx);
2.7 + ByteCodeParser.CPX2 c2 = jc.getCpoolEntry(indx);
2.8 + System.err.println(" bootmethod: " + jc.getBootMethod(c2.cpx1));
2.9 + System.err.println(" name and type: " + jc.stringValue(c2.cpx2, true));
2.10 emit(smapper, this, "throw 'Invoke dynamic: ' + @1;", "" + indx);
2.11 i += 4;
2.12 break;