changeset 10799:0ecba7b109ab

Image creation tool needs to generate jimage in endianness of target platform.
author chegar
date Thu, 09 Oct 2014 11:20:05 +0100
parents f25996bc3361
children b7eeec9aac5d
files make/src/classes/build/tools/module/ImageBuilder.java src/java.base/share/classes/jdk/internal/jimage/ImageFile.java
diffstat 2 files changed, 28 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/make/src/classes/build/tools/module/ImageBuilder.java	Thu Oct 09 11:20:50 2014 +0200
+++ b/make/src/classes/build/tools/module/ImageBuilder.java	Thu Oct 09 11:20:05 2014 +0100
@@ -36,6 +36,7 @@
 import java.io.InputStreamReader;
 import java.io.PrintWriter;
 import java.io.UncheckedIOException;
+import java.nio.ByteOrder;
 import java.nio.file.Files;
 import java.nio.file.InvalidPathException;
 import java.nio.file.Path;
@@ -178,6 +179,17 @@
             }
             String description() { return "Location of the output path"; }
         },
+        new Option(true, "--endian") {
+            void process(ImageBuilder task, String opt, String arg) throws BadArgs {
+                if (arg.equals("little"))
+                    task.options.endian = ByteOrder.LITTLE_ENDIAN;
+                else if (arg.equals("big"))
+                    task.options.endian = ByteOrder.BIG_ENDIAN;
+                else
+                    throw new BadArgs("Unknown byte order " + arg);
+            }
+            String description() { return "Byte order of the target runtime; {little,big}"; }
+        }
     };
 
     private final Options options = new Options();
@@ -211,6 +223,7 @@
         List<Path> libs;
         Set<String> mods = new HashSet<>();
         Path output;
+        ByteOrder endian = ByteOrder.nativeOrder(); // default, if not specified
     }
 
     public static void main(String[] args) throws Exception {
@@ -383,7 +396,7 @@
             Set<Archive> archives = modules.stream()
                                             .map(this::toModuleArchive)
                                             .collect(Collectors.toSet());
-            ImageFile.create(output, archives, imf);
+            ImageFile.create(output, archives, imf, options.endian);
         }
 
         ModuleArchive toModuleArchive(String mn) {
--- a/src/java.base/share/classes/jdk/internal/jimage/ImageFile.java	Thu Oct 09 11:20:50 2014 +0200
+++ b/src/java.base/share/classes/jdk/internal/jimage/ImageFile.java	Thu Oct 09 11:20:05 2014 +0100
@@ -29,6 +29,7 @@
 import java.io.DataOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;
+import java.nio.ByteOrder;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
@@ -111,16 +112,26 @@
                                    ImageModules modules)
         throws IOException
     {
+        return ImageFile.create(output, archives, modules, ByteOrder.nativeOrder());
+    }
+
+    public static ImageFile create(Path output,
+                                   Set<Archive> archives,
+                                   ImageModules modules,
+                                   ByteOrder byteOrder)
+        throws IOException
+    {
         ImageFile lib = new ImageFile(output);
         // get all resources
         lib.readModuleEntries(modules, archives);
         // write to modular image
-        lib.writeImage(modules, archives);
+        lib.writeImage(modules, archives, byteOrder);
         return lib;
     }
 
     private void writeImage(ImageModules modules,
-                            Set<Archive> archives)
+                            Set<Archive> archives,
+                            ByteOrder byteOrder)
         throws IOException
     {
         // name to Archive file
@@ -139,7 +150,7 @@
                     BufferedOutputStream bos = new BufferedOutputStream(fos);
                     DataOutputStream out = new DataOutputStream(bos)) {
                 // store index in addition of the class loader map for boot loader
-                BasicImageWriter writer = new BasicImageWriter();
+                BasicImageWriter writer = new BasicImageWriter(byteOrder);
                 Set<String> duplicates = new HashSet<>();
 
                 // build package map for modules and add as resources