changeset 14491:e1579b30cbec

Fix for 8142485, Jake doesn't build on Windows after recent change to libjimage Reviewed-by: mchung, jlaskey
author jfdenise
date Tue, 17 Nov 2015 15:41:56 +0100
parents 67c711a267db
children c40287b843b3
files src/java.base/share/classes/jdk/internal/jimage/decompressor/CompressedResourceHeader.java src/java.base/share/classes/jdk/internal/jimage/decompressor/ResourceDecompressor.java src/java.base/share/classes/jdk/internal/jimage/decompressor/StringSharingDecompressor.java src/java.base/share/classes/jdk/internal/jimage/decompressor/ZipDecompressor.java src/java.base/share/native/libjimage/ImageNativeSubstrate.cpp src/java.base/share/native/libjimage/imageDecompressor.cpp src/java.base/share/native/libjimage/imageDecompressor.hpp src/java.base/share/native/libjimage/imageFile.cpp
diffstat 8 files changed, 68 insertions(+), 36 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/share/classes/jdk/internal/jimage/decompressor/CompressedResourceHeader.java	Tue Nov 17 12:56:35 2015 +0100
+++ b/src/java.base/share/classes/jdk/internal/jimage/decompressor/CompressedResourceHeader.java	Tue Nov 17 15:41:56 2015 +0100
@@ -37,16 +37,16 @@
  */
 public final class CompressedResourceHeader {
 
-    private static final int SIZE = 21;
+    private static final int SIZE = 29;
     public static final int MAGIC = 0xCAFEFAFA;
-    private final int uncompressedSize;
-    private final int compressedSize;
+    private final long uncompressedSize;
+    private final long compressedSize;
     private final int decompressorNameOffset;
     private final int contentOffset;
     private final boolean isTerminal;
 
-    public CompressedResourceHeader(int compressedSize,
-            int uncompressedSize, int decompressorNameOffset, int contentOffset,
+    public CompressedResourceHeader(long compressedSize,
+            long uncompressedSize, int decompressorNameOffset, int contentOffset,
             boolean isTerminal) {
         this.compressedSize = compressedSize;
         this.uncompressedSize = uncompressedSize;
@@ -75,11 +75,11 @@
         return provider.getString(contentOffset);
     }
 
-    public int getUncompressedSize() {
+    public long getUncompressedSize() {
         return uncompressedSize;
     }
 
-    public int getResourceSize() {
+    public long getResourceSize() {
         return compressedSize;
     }
 
@@ -88,8 +88,8 @@
         ByteBuffer buffer = ByteBuffer.allocate(SIZE);
         buffer.order(order);
         buffer.putInt(MAGIC);
-        buffer.putInt(compressedSize);
-        buffer.putInt(uncompressedSize);
+        buffer.putLong(compressedSize);
+        buffer.putLong(uncompressedSize);
         buffer.putInt(decompressorNameOffset);
         buffer.putInt(contentOffset);
         buffer.put(isTerminal ? (byte)1 : (byte)0);
@@ -113,8 +113,8 @@
         if(magic != MAGIC) {
             return null;
         }
-        int size = buffer.getInt();
-        int uncompressedSize = buffer.getInt();
+        long size = buffer.getLong();
+        long uncompressedSize = buffer.getLong();
         int decompressorNameOffset = buffer.getInt();
         int contentIndex = buffer.getInt();
         byte isTerminal = buffer.get();
--- a/src/java.base/share/classes/jdk/internal/jimage/decompressor/ResourceDecompressor.java	Tue Nov 17 12:56:35 2015 +0100
+++ b/src/java.base/share/classes/jdk/internal/jimage/decompressor/ResourceDecompressor.java	Tue Nov 17 15:41:56 2015 +0100
@@ -49,5 +49,5 @@
      * @throws Exception
      */
     public byte[] decompress(StringsProvider strings, byte[] content, int offset,
-            int originalSize) throws Exception;
+            long originalSize) throws Exception;
 }
--- a/src/java.base/share/classes/jdk/internal/jimage/decompressor/StringSharingDecompressor.java	Tue Nov 17 12:56:35 2015 +0100
+++ b/src/java.base/share/classes/jdk/internal/jimage/decompressor/StringSharingDecompressor.java	Tue Nov 17 15:41:56 2015 +0100
@@ -224,7 +224,7 @@
 
     @Override
     public byte[] decompress(StringsProvider reader, byte[] content,
-            int offset, int originalSize) throws Exception {
+            int offset, long originalSize) throws Exception {
         return normalize(reader, content, offset);
     }
 }
--- a/src/java.base/share/classes/jdk/internal/jimage/decompressor/ZipDecompressor.java	Tue Nov 17 12:56:35 2015 +0100
+++ b/src/java.base/share/classes/jdk/internal/jimage/decompressor/ZipDecompressor.java	Tue Nov 17 15:41:56 2015 +0100
@@ -25,8 +25,6 @@
 package jdk.internal.jimage.decompressor;
 
 import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.util.zip.DataFormatException;
 import java.util.zip.Inflater;
 
 /**
@@ -61,7 +59,7 @@
 
     @Override
     public byte[] decompress(StringsProvider reader, byte[] content, int offset,
-            int originalSize) throws Exception {
+            long originalSize) throws Exception {
         byte[] decompressed = decompress(content, offset);
         return decompressed;
     }
--- a/src/java.base/share/native/libjimage/ImageNativeSubstrate.cpp	Tue Nov 17 12:56:35 2015 +0100
+++ b/src/java.base/share/native/libjimage/ImageNativeSubstrate.cpp	Tue Nov 17 15:41:56 2015 +0100
@@ -137,7 +137,7 @@
     if (is_read) {
         const ImageStrings strings = reader->get_strings();
         ImageDecompressor::decompress_resource(compressedAddress, uncompressedAddress,
-                (u4) uncompressed_size, &strings);
+                uncompressed_size, &strings, reader->endian());
     }
     return (jboolean) is_read;
 }
--- a/src/java.base/share/native/libjimage/imageDecompressor.cpp	Tue Nov 17 12:56:35 2015 +0100
+++ b/src/java.base/share/native/libjimage/imageDecompressor.cpp	Tue Nov 17 15:41:56 2015 +0100
@@ -105,32 +105,66 @@
     return NULL;
 }
 
+// Sparc to read unaligned content
+// u8 l = (*(u8*) ptr);
+// If ptr is not aligned, sparc will fail.
+u8 ImageDecompressor::getU8(u1* ptr, Endian *endian) {
+    u8 ret;
+    if (endian->is_big_endian()) {
+        ret = (u8)ptr[0] << 56 | (u8)ptr[1] << 48 | (u8)ptr[2]<<40 | (u8)ptr[3]<<32 |
+                ptr[4]<<24 | ptr[5]<<16 | ptr[6]<<8 | ptr[7];
+    } else {
+        ret = ptr[0] | ptr[1]<<8 | ptr[2]<<16 | ptr[3]<<24 | (u8)ptr[4]<<32 |
+                (u8)ptr[5]<<40 | (u8)ptr[6]<<48 | (u8)ptr[7]<<56;
+    }
+    return ret;
+}
+
+u4 ImageDecompressor::getU4(u1* ptr, Endian *endian) {
+    u4 ret;
+    if (endian->is_big_endian()) {
+        ret = ptr[0] << 24 | ptr[1]<<16 | (ptr[2]<<8) | ptr[3];
+    } else {
+        ret = ptr[0] | ptr[1]<<8 | (ptr[2]<<16) | ptr[3]<<24;
+    }
+    return ret;
+}
+
 /*
  * Decompression entry point. Called from ImageFileReader::get_resource.
  */
 void ImageDecompressor::decompress_resource(u1* compressed, u1* uncompressed,
-                u4 uncompressed_size, const ImageStrings* strings) {
+                u8 uncompressed_size, const ImageStrings* strings, Endian *endian) {
     bool has_header = false;
     u1* decompressed_resource = compressed;
     u1* compressed_resource = compressed;
-
     // Resource could have been transformed by a stack of decompressors.
     // Iterate and decompress resources until there is no more header.
     do {
         ResourceHeader _header;
-        memcpy(&_header, compressed_resource, sizeof (ResourceHeader));
+        u1* compressed_resource_base = compressed_resource;
+        _header._magic = getU4(compressed_resource, endian);
+        compressed_resource += 4;
+        _header._size = getU8(compressed_resource, endian);
+        compressed_resource += 8;
+        _header._uncompressed_size = getU8(compressed_resource, endian);
+        compressed_resource += 8;
+        _header._decompressor_name_offset = getU4(compressed_resource, endian);
+        compressed_resource += 4;
+        _header._decompressor_config_offset = getU4(compressed_resource, endian);
+        compressed_resource += 4;
+        _header._is_terminal = *compressed_resource;
+        compressed_resource += 1;
         has_header = _header._magic == ResourceHeader::resource_header_magic;
         if (has_header) {
             // decompressed_resource array contains the result of decompression
-            decompressed_resource = new u1[_header._uncompressed_size];
+            decompressed_resource = new u1[(size_t) _header._uncompressed_size];
             // Retrieve the decompressor name
             const char* decompressor_name = strings->get(_header._decompressor_name_offset);
             assert(decompressor_name && "image decompressor not found");
             // Retrieve the decompressor instance
             ImageDecompressor* decompressor = get_decompressor(decompressor_name);
             assert(decompressor && "image decompressor not found");
-            u1* compressed_resource_base = compressed_resource;
-            compressed_resource += ResourceHeader::resource_header_length;
             // Ask the decompressor to decompress the compressed content
             decompressor->decompress_resource(compressed_resource, decompressed_resource,
                 &_header, strings);
@@ -140,7 +174,7 @@
             compressed_resource = decompressed_resource;
         }
     } while (has_header);
-    memcpy(uncompressed, decompressed_resource, uncompressed_size);
+    memcpy(uncompressed, decompressed_resource, (size_t) uncompressed_size);
     delete decompressed_resource;
 }
 
@@ -293,14 +327,14 @@
             }
         }
     }
-    u4 remain = header->_size - (int)(data - data_base);
-    u4 computed = (u4)(uncompressed_resource - uncompressed_base) + remain;
+    u8 remain = header->_size - (int)(data - data_base);
+    u8 computed = (u8)(uncompressed_resource - uncompressed_base) + remain;
     if (header->_uncompressed_size != computed)
-        printf("Failure, expecting %d but getting %d\n", header->_uncompressed_size,
+        printf("Failure, expecting %llu but getting %llu\n", header->_uncompressed_size,
                 computed);
     assert(header->_uncompressed_size == computed &&
                 "Constant Pool reconstruction failed");
-    memcpy(uncompressed_resource, data, remain);
+    memcpy(uncompressed_resource, data, (size_t) remain);
 }
 
 /*
--- a/src/java.base/share/native/libjimage/imageDecompressor.hpp	Tue Nov 17 12:56:35 2015 +0100
+++ b/src/java.base/share/native/libjimage/imageDecompressor.hpp	Tue Nov 17 15:41:56 2015 +0100
@@ -48,13 +48,11 @@
  *   have been used to compress the resource.
  */
 struct ResourceHeader {
-    /* Length of header, needed to retrieve content offset */
-    static const u1 resource_header_length = 21;
     /* magic bytes that identifies a compressed resource header*/
     static const u4 resource_header_magic = 0xCAFEFAFA;
     u4 _magic; // Resource header
-    u4 _size;    // Resource size
-    u4 _uncompressed_size;  // Expected uncompressed size
+    u8 _size;    // Resource size
+    u8 _uncompressed_size;  // Expected uncompressed size
     u4 _decompressor_name_offset;    // Strings table decompressor offset
     u4 _decompressor_config_offset; // Strings table config offset
     u1 _is_terminal; // Last decompressor 1, otherwise 0.
@@ -95,6 +93,8 @@
      */
     inline const char* get_name() const { return _name; }
 
+    static u8 getU8(u1* ptr, Endian *endian);
+    static u4 getU4(u1* ptr, Endian *endian);
 
 protected:
     ImageDecompressor(const char* name) : _name(name) {
@@ -107,7 +107,7 @@
     static void image_decompressor_close();
     static ImageDecompressor* get_decompressor(const char * decompressor_name) ;
     static void decompress_resource(u1* compressed, u1* uncompressed,
-        u4 uncompressed_size, const ImageStrings* strings);
+        u8 uncompressed_size, const ImageStrings* strings, Endian* _endian);
 };
 
 /**
--- a/src/java.base/share/native/libjimage/imageFile.cpp	Tue Nov 17 12:56:35 2015 +0100
+++ b/src/java.base/share/native/libjimage/imageFile.cpp	Tue Nov 17 15:41:56 2015 +0100
@@ -577,7 +577,7 @@
         // If not memory mapped read in bytes.
         if (!MemoryMapImage) {
             // Allocate buffer for compression.
-            compressed_data = new u1[(u4)compressed_size];
+            compressed_data = new u1[(size_t)compressed_size];
             // Read bytes from offset beyond the image index.
             bool is_read = read_at(compressed_data, compressed_size, _index_size + offset);
             assert(is_read && "error reading from image or short read");
@@ -587,8 +587,8 @@
         // Get image string table.
         const ImageStrings strings = get_strings();
         // Decompress resource.
-        ImageDecompressor::decompress_resource(compressed_data, uncompressed_data, (u4)uncompressed_size,
-                        &strings);
+        ImageDecompressor::decompress_resource(compressed_data, uncompressed_data, uncompressed_size,
+                        &strings, _endian);
         // If not memory mapped then release temporary buffer.
         if (!MemoryMapImage) {
                 delete compressed_data;