void verifyBytecode(VarargsMethod selected, JavaSource source, int id) {
    bytecodeCheckCount.incrementAndGet();
    File compiledTest = new File(String.format("Test%d.class", id));
    try {
      ClassFile cf = ClassFile.read(compiledTest);
      Method testMethod = null;
      for (Method m : cf.methods) {
        if (m.getName(cf.constant_pool).equals("test")) {
          testMethod = m;
          break;
        }
      }
      if (testMethod == null) {
        throw new Error("Test method not found");
      }
      Code_attribute ea = (Code_attribute) testMethod.attributes.get(Attribute.Code);
      if (testMethod == null) {
        throw new Error("Code attribute for test() method not found");
      }

      for (Instruction i : ea.getInstructions()) {
        if (i.getMnemonic().equals("invokevirtual")) {
          int cp_entry = i.getUnsignedShort(1);
          CONSTANT_Methodref_info methRef =
              (CONSTANT_Methodref_info) cf.constant_pool.get(cp_entry);
          String type = methRef.getNameAndTypeInfo().getType();
          String sig = selected.parameterTypes.bytecodeSigStr;
          if (!type.contains(sig)) {
            throw new Error(
                "Unexpected type method call: "
                    + type
                    + ""
                    + "\nfound: "
                    + sig
                    + "\n"
                    + source.getCharContent(true));
          }
          break;
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
      throw new Error("error reading " + compiledTest + ": " + e);
    }
  }
Example #2
0
  void verifyBytecode(VarargsMethod selected) {
    bytecodeCheckCount++;
    File compiledTest = new File("Test.class");
    try {
      ClassFile cf = ClassFile.read(compiledTest);
      Method testMethod = null;
      for (Method m : cf.methods) {
        if (m.getName(cf.constant_pool).equals("test")) {
          testMethod = m;
          break;
        }
      }
      if (testMethod == null) {
        throw new Error("Test method not found");
      }
      Code_attribute ea = (Code_attribute) testMethod.attributes.get(Attribute.Code);
      if (testMethod == null) {
        throw new Error("Code attribute for test() method not found");
      }

      for (Instruction i : ea.getInstructions()) {
        if (i.getMnemonic().equals("invokevirtual")) {
          int cp_entry = i.getUnsignedShort(1);
          CONSTANT_Methodref_info methRef =
              (CONSTANT_Methodref_info) cf.constant_pool.get(cp_entry);
          String type = methRef.getNameAndTypeInfo().getType();
          if (!type.contains(selected.varargsElement.bytecodeString)) {
            throw new Error("Unexpected type method call: " + type);
          }
          break;
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
      throw new Error("error reading " + compiledTest + ": " + e);
    }
  }