コード例 #1
0
  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);
    }
  }
コード例 #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);
    }
  }
コード例 #3
0
ファイル: T7093325.java プロジェクト: karianna/jdk8_tl
  void verifyBytecode(JavaSource source, int id) {
    boolean lastInlined = false;
    boolean hasCode = false;
    int gapsCount = 0;
    for (int i = 0; i < stmts.length; i++) {
      lastInlined = stmts[i].canInline;
      hasCode = hasCode || !stmts[i].empty;
      if (lastInlined && hasCode) {
        hasCode = false;
        gapsCount++;
      }
    }
    if (!lastInlined) {
      gapsCount++;
    }

    File compiledTest = new File(String.format("Test%s.class", id));
    try {
      ClassFile cf = ClassFile.read(compiledTest);
      if (cf == null) {
        throw new Error("Classfile not found: " + compiledTest.getName());
      }

      Method test_method = null;
      for (Method m : cf.methods) {
        if (m.getName(cf.constant_pool).equals("test")) {
          test_method = m;
          break;
        }
      }

      if (test_method == null) {
        throw new Error("Method test() not found in class Test");
      }

      Code_attribute code = null;
      for (Attribute a : test_method.attributes) {
        if (a.getName(cf.constant_pool).equals(Attribute.Code)) {
          code = (Code_attribute) a;
          break;
        }
      }

      if (code == null) {
        throw new Error("Code attribute not found in method test()");
      }

      int actualGapsCount = 0;
      for (int i = 0; i < code.exception_table_langth; i++) {
        int catchType = code.exception_table[i].catch_type;
        if (catchType == 0) { // any
          actualGapsCount++;
        }
      }

      if (actualGapsCount != gapsCount) {
        throw new Error(
            "Bad exception table for test()\n"
                + "expected gaps: "
                + gapsCount
                + "\n"
                + "found gaps: "
                + actualGapsCount
                + "\n"
                + source);
      }
    } catch (Exception e) {
      e.printStackTrace();
      throw new Error("error reading " + compiledTest + ": " + e);
    }
  }