OpenJDK / jigsaw / jake / jdk
changeset 14318:103e023995ba
Backout compressed resource header length change that breaks windows build
line wrap: on
line diff
--- a/src/java.base/share/classes/jdk/internal/jimage/decompressor/CompressedResourceHeader.java Thu Nov 12 15:00:53 2015 +0100 +++ b/src/java.base/share/classes/jdk/internal/jimage/decompressor/CompressedResourceHeader.java Thu Nov 12 18:51:54 2015 -0800 @@ -37,16 +37,16 @@ */ public final class CompressedResourceHeader { - private static final int SIZE = 29; + private static final int SIZE = 21; public static final int MAGIC = 0xCAFEFAFA; - private final long uncompressedSize; - private final long compressedSize; + private final int uncompressedSize; + private final int compressedSize; private final int decompressorNameOffset; private final int contentOffset; private final boolean isTerminal; - public CompressedResourceHeader(long compressedSize, - long uncompressedSize, int decompressorNameOffset, int contentOffset, + public CompressedResourceHeader(int compressedSize, + int uncompressedSize, int decompressorNameOffset, int contentOffset, boolean isTerminal) { this.compressedSize = compressedSize; this.uncompressedSize = uncompressedSize; @@ -75,11 +75,11 @@ return provider.getString(contentOffset); } - public long getUncompressedSize() { + public int getUncompressedSize() { return uncompressedSize; } - public long getResourceSize() { + public int getResourceSize() { return compressedSize; } @@ -88,8 +88,8 @@ ByteBuffer buffer = ByteBuffer.allocate(SIZE); buffer.order(order); buffer.putInt(MAGIC); - buffer.putLong(compressedSize); - buffer.putLong(uncompressedSize); + buffer.putInt(compressedSize); + buffer.putInt(uncompressedSize); buffer.putInt(decompressorNameOffset); buffer.putInt(contentOffset); buffer.put(isTerminal ? (byte)1 : (byte)0); @@ -113,8 +113,8 @@ if(magic != MAGIC) { return null; } - long size = buffer.getLong(); - long uncompressedSize = buffer.getLong(); + int size = buffer.getInt(); + int uncompressedSize = buffer.getInt(); int decompressorNameOffset = buffer.getInt(); int contentIndex = buffer.getInt(); byte isTerminal = buffer.get();
--- a/src/java.base/share/classes/jdk/internal/jimage/decompressor/ResourceDecompressor.java Thu Nov 12 15:00:53 2015 +0100 +++ b/src/java.base/share/classes/jdk/internal/jimage/decompressor/ResourceDecompressor.java Thu Nov 12 18:51:54 2015 -0800 @@ -49,5 +49,5 @@ * @throws Exception */ public byte[] decompress(StringsProvider strings, byte[] content, int offset, - long originalSize) throws Exception; + int originalSize) throws Exception; }
--- a/src/java.base/share/classes/jdk/internal/jimage/decompressor/StringSharingDecompressor.java Thu Nov 12 15:00:53 2015 +0100 +++ b/src/java.base/share/classes/jdk/internal/jimage/decompressor/StringSharingDecompressor.java Thu Nov 12 18:51:54 2015 -0800 @@ -224,7 +224,7 @@ @Override public byte[] decompress(StringsProvider reader, byte[] content, - int offset, long originalSize) throws Exception { + int offset, int originalSize) throws Exception { return normalize(reader, content, offset); } }
--- a/src/java.base/share/classes/jdk/internal/jimage/decompressor/ZipDecompressor.java Thu Nov 12 15:00:53 2015 +0100 +++ b/src/java.base/share/classes/jdk/internal/jimage/decompressor/ZipDecompressor.java Thu Nov 12 18:51:54 2015 -0800 @@ -25,6 +25,8 @@ package jdk.internal.jimage.decompressor; import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.util.zip.DataFormatException; import java.util.zip.Inflater; /** @@ -59,7 +61,7 @@ @Override public byte[] decompress(StringsProvider reader, byte[] content, int offset, - long originalSize) throws Exception { + int originalSize) throws Exception { byte[] decompressed = decompress(content, offset); return decompressed; }
--- a/src/java.base/share/native/libjimage/ImageNativeSubstrate.cpp Thu Nov 12 15:00:53 2015 +0100 +++ b/src/java.base/share/native/libjimage/ImageNativeSubstrate.cpp Thu Nov 12 18:51:54 2015 -0800 @@ -127,7 +127,7 @@ if (is_read) { const ImageStrings strings = reader->get_strings(); ImageDecompressor::decompress_resource(compressedAddress, uncompressedAddress, - uncompressed_size, &strings, reader->endian()); + (u4) uncompressed_size, &strings); } return (jboolean) is_read; }
--- a/src/java.base/share/native/libjimage/imageDecompressor.cpp Thu Nov 12 15:00:53 2015 +0100 +++ b/src/java.base/share/native/libjimage/imageDecompressor.cpp Thu Nov 12 18:51:54 2015 -0800 @@ -105,56 +105,20 @@ 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, - u8 uncompressed_size, const ImageStrings* strings, Endian *endian) { + u4 uncompressed_size, const ImageStrings* strings) { 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; - 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 = getU4(compressed_resource, endian); - compressed_resource += 1; + memcpy(&_header, compressed_resource, sizeof (ResourceHeader)); has_header = _header._magic == ResourceHeader::resource_header_magic; if (has_header) { // decompressed_resource array contains the result of decompression @@ -165,6 +129,8 @@ // 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); @@ -327,10 +293,10 @@ } } } - u8 remain = header->_size - (int)(data - data_base); - u8 computed = (u8)(uncompressed_resource - uncompressed_base) + remain; + u4 remain = header->_size - (int)(data - data_base); + u4 computed = (u4)(uncompressed_resource - uncompressed_base) + remain; if (header->_uncompressed_size != computed) - printf("Failure, expecting %llu but getting %llu\n", header->_uncompressed_size, + printf("Failure, expecting %d but getting %d\n", header->_uncompressed_size, computed); assert(header->_uncompressed_size == computed && "Constant Pool reconstruction failed");
--- a/src/java.base/share/native/libjimage/imageDecompressor.hpp Thu Nov 12 15:00:53 2015 +0100 +++ b/src/java.base/share/native/libjimage/imageDecompressor.hpp Thu Nov 12 18:51:54 2015 -0800 @@ -48,11 +48,13 @@ * 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 - u8 _size; // Resource size - u8 _uncompressed_size; // Expected uncompressed size + u4 _size; // Resource size + u4 _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. @@ -93,8 +95,6 @@ */ 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, - u8 uncompressed_size, const ImageStrings* strings, Endian* _endian); + u4 uncompressed_size, const ImageStrings* strings); }; /**
--- a/src/java.base/share/native/libjimage/imageFile.cpp Thu Nov 12 15:00:53 2015 +0100 +++ b/src/java.base/share/native/libjimage/imageFile.cpp Thu Nov 12 18:51:54 2015 -0800 @@ -577,7 +577,7 @@ // If not memory mapped read in bytes. if (!MemoryMapImage) { // Allocate buffer for compression. - compressed_data = new u1[compressed_size]; + compressed_data = new u1[(u4)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, uncompressed_size, - &strings, _endian); + ImageDecompressor::decompress_resource(compressed_data, uncompressed_data, (u4)uncompressed_size, + &strings); // If not memory mapped then release temporary buffer. if (!MemoryMapImage) { delete compressed_data;