Example #1
0
  /** Compile two module definitions used by the test, jdk.test and jdk.translet. */
  public static void main(String[] args) throws Exception {

    boolean compiled;
    // Compile module jdk.test declaration
    compiled = CompilerUtils.compile(SRC_DIR.resolve("jdk.test"), MODS_DIR.resolve("jdk.test"));
    if (!compiled) {
      throw new RuntimeException("Test failed to compile module jdk.test");
    }

    // Compile module jdk.translet declaration
    compiled =
        CompilerUtils.compile(
            SRC_DIR.resolve("jdk.translet"),
            MODS_DIR.resolve("jdk.translet"),
            "--add-exports=jdk.test/test=jdk.translet",
            "-p",
            MODS_DIR.toString());
    if (!compiled) {
      throw new RuntimeException("Test failed to compile module jdk.translet");
    }

    // Sanity check that the test, jdk.test/test/MainGC.java,
    // correctly walks module jdk.test's reads list and package
    // test's, defined to module jdk.translet, export list at
    // GC safepoints.
    ProcessBuilder pb =
        ProcessTools.createJavaProcessBuilder(
            "-Xlog:modules=trace", "-p", MODS_DIR.toString(), "-m", "jdk.test/test.MainGC");
    OutputAnalyzer oa = new OutputAnalyzer(pb.start());
    oa.shouldContain("package test defined in module jdk.test, exports list being walked")
        .shouldContain("module jdk.test reads list being walked")
        .shouldHaveExitValue(0);
  }
  public void compile(Element element) {
    if (!element.getChildren().isEmpty()) {
      throw new CompilationError("<script> elements can't have children", element);
    }
    String pathname = null;
    String script = element.getText();
    if (element.getAttribute(SRC_ATTR_NAME) != null) {
      pathname = element.getAttributeValue(SRC_ATTR_NAME);
      File file = mEnv.resolveReference(element, SRC_ATTR_NAME);
      try {
        script =
            "#file "
                + element.getAttributeValue(SRC_ATTR_NAME)
                + "\n"
                + "#line 1\n"
                + FileUtils.readFileString(file);
      } catch (IOException e) {
        throw new CompilationError(e);
      }
    }
    try {
      // If it is when=immediate, emit code inline
      if ("immediate".equals(element.getAttributeValue("when"))) {
        mEnv.compileScript(
            CompilerUtils.sourceLocationDirective(element, true)
                + script
                + CompilerUtils.endSourceLocationDirective,
            element);
      } else {
        // Compile scripts to run at construction time in the view
        // instantiation queue.

        mEnv.compileScript(
            // Provide file info for anonymous function name
            CompilerUtils.sourceLocationDirective(element, true)
                + VIEW_INSTANTIATION_FNAME
                + "({'class': lz.script, attrs: "
                + "{script: function () {\n"
                + "#beginContent\n"
                + "#pragma 'scriptElement'\n"
                + CompilerUtils.sourceLocationDirective(element, true)
                + script
                + CompilerUtils.endSourceLocationDirective
                + "\n#endContent\n"
                +
                // Scripts have no children
                "}}}, 1)",
            element);
      }
    } catch (CompilationError e) {
      // TODO: [2003-01-16] Instead of this, put the filename in ParseException,
      // and modify CompilationError.initElement to copy it from there.
      if (pathname != null) {
        e.setPathname(pathname);
      }
      throw e;
    }
  }
Example #3
0
  public void run() throws Throwable {
    if (Files.notExists(jdkMods)) {
      return;
    }

    if (!CompilerUtils.compile(src, classes)) {
      throw new AssertionError("Compilation failure. See log.");
    }

    String modName = "test";
    Files.createDirectories(jmods);
    Files.createDirectories(jars);
    Path jarfile = jars.resolve("test.jar");
    JarUtils.createJarFile(jarfile, classes);

    Path image = Paths.get("mysmallimage");
    runJmod(jarfile.toString(), modName);
    runJlink(image, modName, "--compress", "2");
    execute(image, modName);

    Files.delete(jmods.resolve(modName + ".jmod"));

    image = Paths.get("myimage");
    runJmod(classes.toString(), modName);
    runJlink(image, modName);
    execute(image, modName);
  }
Example #4
0
 public JavaClass createClass(String name, Type type, boolean constructed)
     throws CompilerException {
   JavaClass javaClass =
       new JavaClass(
           pkg,
           name,
           type.getTag(),
           CompilerUtils.getTaggingMode(getModule(), type),
           true,
           runtimeTypes.get(type.getClass().getSimpleName()));
   currentClass.push(javaClass);
   return javaClass;
 }
Example #5
0
  public String getType(JavaClass javaClass, Type type) throws CompilerException {
    String typeName;
    String name = null;
    boolean newType = false;

    if (type instanceof NamedType) {
      name = ((NamedType) type).getName();
      type = ((NamedType) type).getType();
    }

    if (type instanceof TypeReference) {
      if (type instanceof UsefulType) {
        typeName = ((UsefulType) type).getType();
      } else {
        String asn1TypeName = ((TypeReference) type).getType();
        addReferencedType(asn1TypeName);
        typeName = CompilerUtils.formatName(asn1TypeName);
      }
    } else if (type instanceof BooleanType) {
      typeName = ch.eskaton.asn4j.runtime.types.ASN1Boolean.class.getSimpleName();
    } else if (type instanceof VisibleString) {
      typeName = ch.eskaton.asn4j.runtime.types.ASN1VisibleString.class.getSimpleName();
    } else if (type instanceof OctetString) {
      typeName = ch.eskaton.asn4j.runtime.types.ASN1OctetString.class.getSimpleName();
    } else if (type instanceof IntegerType) {
      if (((IntegerType) type).getNamedNumbers() != null && name != null) {
        typeName = CompilerUtils.formatTypeName(name);
        newType = true;
      } else {
        typeName = ch.eskaton.asn4j.runtime.types.ASN1Integer.class.getSimpleName();
      }
    } else if (type instanceof BitString) {
      if (((BitString) type).getNamedBits() != null && name != null) {
        typeName = CompilerUtils.formatTypeName(name);
        newType = true;
      } else {
        typeName = ch.eskaton.asn4j.runtime.types.ASN1BitString.class.getSimpleName();
      }
    } else if (type instanceof SequenceOfType) {
      if (name != null) {
        typeName = CompilerUtils.formatTypeName(name);
        newType = true;
      } else {
        typeName = ch.eskaton.asn4j.runtime.types.ASN1SequenceOf.class.getSimpleName();
      }
    } else if (type instanceof SetType) {
      if (name != null) {
        typeName = CompilerUtils.formatTypeName(name);
        newType = true;
      } else {
        typeName = ch.eskaton.asn4j.runtime.types.ASN1Set.class.getSimpleName();
      }
    } else if (type instanceof SequenceType) {
      if (name != null) {
        typeName = CompilerUtils.formatTypeName(name);
        newType = true;
      } else {
        typeName = ch.eskaton.asn4j.runtime.types.ASN1Sequence.class.getSimpleName();
      }
    } else if (type instanceof Choice) {
      typeName = CompilerUtils.formatTypeName(name);
      newType = true;
    } else {
      throw new CompilerException("Unsupported type: " + type.getClass());
    }

    if (newType) {
      this.<Type, TypeCompiler>getCompiler(Type.class).compile(this, typeName, type);
      definedTypes.add(name);
    }

    return typeName;
  }