8323794: Remove unused jimage compressor plugin configuration
Reviewed-by: jlaskey, mchung
This commit is contained in:
parent
7be9f1d054
commit
8b29e127c2
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -27,7 +27,6 @@ package jdk.internal.jimage.decompressor;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.util.Objects;
|
||||
import jdk.internal.jimage.decompressor.ResourceDecompressor.StringsProvider;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -45,19 +44,25 @@ public final class CompressedResourceHeader {
|
||||
|
||||
private static final int SIZE = 29;
|
||||
public static final int MAGIC = 0xCAFEFAFA;
|
||||
|
||||
// Standard header offsets
|
||||
private static final int MAGIC_OFFSET = 0; // 4 bytes
|
||||
private static final int COMPRESSED_OFFSET = 4; // 8 bytes
|
||||
private static final int UNCOMPRESSED_OFFSET = 12; // 8 bytes
|
||||
private static final int DECOMPRESSOR_NAME_OFFSET = 20; // 4 bytes, followed by 4 byte gap
|
||||
private static final int IS_TERMINAL_OFFSET = 28; // 1 byte
|
||||
|
||||
private final long uncompressedSize;
|
||||
private final long compressedSize;
|
||||
private final int decompressorNameOffset;
|
||||
private final int contentOffset;
|
||||
private final boolean isTerminal;
|
||||
|
||||
public CompressedResourceHeader(long compressedSize,
|
||||
long uncompressedSize, int decompressorNameOffset, int contentOffset,
|
||||
long uncompressedSize, int decompressorNameOffset,
|
||||
boolean isTerminal) {
|
||||
this.compressedSize = compressedSize;
|
||||
this.uncompressedSize = uncompressedSize;
|
||||
this.decompressorNameOffset = decompressorNameOffset;
|
||||
this.contentOffset = contentOffset;
|
||||
this.isTerminal = isTerminal;
|
||||
}
|
||||
|
||||
@ -69,18 +74,6 @@ public final class CompressedResourceHeader {
|
||||
return decompressorNameOffset;
|
||||
}
|
||||
|
||||
public int getContentOffset() {
|
||||
return contentOffset;
|
||||
}
|
||||
|
||||
public String getStoredContent(StringsProvider provider) {
|
||||
Objects.requireNonNull(provider);
|
||||
if(contentOffset == -1) {
|
||||
return null;
|
||||
}
|
||||
return provider.getString(contentOffset);
|
||||
}
|
||||
|
||||
public long getUncompressedSize() {
|
||||
return uncompressedSize;
|
||||
}
|
||||
@ -97,7 +90,8 @@ public final class CompressedResourceHeader {
|
||||
buffer.putLong(compressedSize);
|
||||
buffer.putLong(uncompressedSize);
|
||||
buffer.putInt(decompressorNameOffset);
|
||||
buffer.putInt(contentOffset);
|
||||
// Compatibility
|
||||
buffer.putInt(-1);
|
||||
buffer.put(isTerminal ? (byte)1 : (byte)0);
|
||||
return buffer.array();
|
||||
}
|
||||
@ -115,16 +109,16 @@ public final class CompressedResourceHeader {
|
||||
}
|
||||
ByteBuffer buffer = ByteBuffer.wrap(resource, 0, SIZE);
|
||||
buffer.order(order);
|
||||
int magic = buffer.getInt();
|
||||
if(magic != MAGIC) {
|
||||
int magic = buffer.getInt(MAGIC_OFFSET);
|
||||
if (magic != MAGIC) {
|
||||
return null;
|
||||
}
|
||||
long size = buffer.getLong();
|
||||
long uncompressedSize = buffer.getLong();
|
||||
int decompressorNameOffset = buffer.getInt();
|
||||
int contentIndex = buffer.getInt();
|
||||
byte isTerminal = buffer.get();
|
||||
long size = buffer.getLong(COMPRESSED_OFFSET);
|
||||
long uncompressedSize = buffer.getLong(UNCOMPRESSED_OFFSET);
|
||||
int decompressorNameOffset = buffer.getInt(DECOMPRESSOR_NAME_OFFSET);
|
||||
// skip unused 'contentOffset' int
|
||||
byte isTerminal = buffer.get(IS_TERMINAL_OFFSET);
|
||||
return new CompressedResourceHeader(size, uncompressedSize,
|
||||
decompressorNameOffset, contentIndex, isTerminal == 1);
|
||||
decompressorNameOffset, isTerminal == 1);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -24,14 +24,11 @@
|
||||
*/
|
||||
package jdk.internal.jimage.decompressor;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Properties;
|
||||
import jdk.internal.jimage.decompressor.ResourceDecompressor.StringsProvider;
|
||||
|
||||
/**
|
||||
@ -75,17 +72,8 @@ public final class Decompressor {
|
||||
if (pluginName == null) {
|
||||
throw new IOException("Plugin name not found");
|
||||
}
|
||||
String storedContent = header.getStoredContent(provider);
|
||||
Properties props = new Properties();
|
||||
if (storedContent != null) {
|
||||
try (ByteArrayInputStream stream
|
||||
= new ByteArrayInputStream(storedContent.
|
||||
getBytes(StandardCharsets.UTF_8));) {
|
||||
props.loadFromXML(stream);
|
||||
}
|
||||
}
|
||||
decompressor = ResourceDecompressorRepository.
|
||||
newResourceDecompressor(props, pluginName);
|
||||
newResourceDecompressor(pluginName);
|
||||
if (decompressor == null) {
|
||||
throw new IOException("Plugin not found: " + pluginName);
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -25,7 +25,6 @@
|
||||
package jdk.internal.jimage.decompressor;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -54,12 +53,10 @@ public abstract class ResourceDecompressorFactory {
|
||||
|
||||
/**
|
||||
* To build a new decompressor.
|
||||
* @param properties Contains configuration.
|
||||
* @return A new decompressor.
|
||||
* @throws IOException
|
||||
*/
|
||||
public abstract ResourceDecompressor newDecompressor(Properties properties)
|
||||
throws IOException;
|
||||
public abstract ResourceDecompressor newDecompressor() throws IOException;
|
||||
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -27,7 +27,6 @@ package jdk.internal.jimage.decompressor;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -54,17 +53,15 @@ public final class ResourceDecompressorRepository {
|
||||
|
||||
/**
|
||||
* Build a new decompressor for the passed name.
|
||||
* @param properties Contains plugin configuration.
|
||||
* @param name The plugin name to build.
|
||||
* @return A decompressor or null if not found
|
||||
* @throws IOException
|
||||
*/
|
||||
public static ResourceDecompressor newResourceDecompressor(Properties properties,
|
||||
String name) throws IOException {
|
||||
public static ResourceDecompressor newResourceDecompressor(String name) throws IOException {
|
||||
|
||||
ResourceDecompressorFactory fact = factories.get(name);
|
||||
if (fact != null) {
|
||||
return fact.newDecompressor(properties);
|
||||
return fact.newDecompressor();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -33,7 +33,6 @@ import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -228,9 +227,7 @@ public class StringSharingDecompressor implements ResourceDecompressor {
|
||||
return StringSharingDecompressorFactory.NAME;
|
||||
}
|
||||
|
||||
public StringSharingDecompressor(Properties properties) {
|
||||
|
||||
}
|
||||
public StringSharingDecompressor() {}
|
||||
|
||||
@Override
|
||||
public byte[] decompress(StringsProvider reader, byte[] content,
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -25,7 +25,6 @@
|
||||
package jdk.internal.jimage.decompressor;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -45,8 +44,8 @@ public class StringSharingDecompressorFactory extends ResourceDecompressorFactor
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceDecompressor newDecompressor(Properties properties)
|
||||
public ResourceDecompressor newDecompressor()
|
||||
throws IOException {
|
||||
return new StringSharingDecompressor(properties);
|
||||
return new StringSharingDecompressor();
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,6 @@
|
||||
*/
|
||||
package jdk.internal.jimage.decompressor;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.zip.Inflater;
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -25,7 +25,6 @@
|
||||
package jdk.internal.jimage.decompressor;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -44,7 +43,7 @@ public final class ZipDecompressorFactory extends ResourceDecompressorFactory {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceDecompressor newDecompressor(Properties properties)
|
||||
public ResourceDecompressor newDecompressor()
|
||||
throws IOException {
|
||||
return new ZipDecompressor();
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -448,7 +448,8 @@ public class ResourcePoolManager {
|
||||
|
||||
public static CompressedModuleData newCompressedResource(ResourcePoolEntry original,
|
||||
ByteBuffer compressed,
|
||||
String plugin, String pluginConfig, StringTable strings,
|
||||
String plugin,
|
||||
StringTable strings,
|
||||
ByteOrder order) {
|
||||
Objects.requireNonNull(original);
|
||||
Objects.requireNonNull(compressed);
|
||||
@ -461,13 +462,9 @@ public class ResourcePoolManager {
|
||||
uncompressed_size = comp.getUncompressedSize();
|
||||
}
|
||||
int nameOffset = strings.addString(plugin);
|
||||
int configOffset = -1;
|
||||
if (pluginConfig != null) {
|
||||
configOffset = strings.addString(plugin);
|
||||
}
|
||||
CompressedResourceHeader rh
|
||||
= new CompressedResourceHeader(compressed.limit(), original.contentLength(),
|
||||
nameOffset, configOffset, isTerminal);
|
||||
nameOffset, isTerminal);
|
||||
// Merge header with content;
|
||||
byte[] h = rh.getBytes(order);
|
||||
ByteBuffer bb = ByteBuffer.allocate(compressed.limit() + h.length);
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2014, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -32,7 +32,6 @@ import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
@ -306,14 +305,14 @@ public class StringSharingPlugin extends AbstractPlugin implements ResourcePrevi
|
||||
in.transformAndCopy((resource) -> {
|
||||
ResourcePoolEntry res = resource;
|
||||
if (predicate.test(resource.path()) && resource.path().endsWith(".class")) {
|
||||
byte[] compressed = null;
|
||||
byte[] compressed;
|
||||
try {
|
||||
compressed = visit.transform(resource, result, ((ResourcePoolImpl)in).getStringTable());
|
||||
} catch (Exception ex) {
|
||||
throw new PluginException(ex);
|
||||
}
|
||||
res = ResourcePoolManager.newCompressedResource(resource,
|
||||
ByteBuffer.wrap(compressed), getName(), null,
|
||||
ByteBuffer.wrap(compressed), getName(),
|
||||
((ResourcePoolImpl)in).getStringTable(), in.byteOrder());
|
||||
}
|
||||
return res;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -114,7 +114,7 @@ public final class ZipPlugin extends AbstractPlugin {
|
||||
byte[] compressed;
|
||||
compressed = compress(resource.contentBytes(), this.compressionLevel);
|
||||
res = ResourcePoolManager.newCompressedResource(resource,
|
||||
ByteBuffer.wrap(compressed), getName(), null,
|
||||
ByteBuffer.wrap(compressed), getName(),
|
||||
((ResourcePoolImpl)in).getStringTable(), in.byteOrder());
|
||||
}
|
||||
return res;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -31,11 +31,9 @@
|
||||
* @run main ResourcePoolTest
|
||||
*/
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
@ -44,7 +42,6 @@ import java.util.function.Function;
|
||||
import jdk.tools.jlink.internal.ResourcePoolManager;
|
||||
import jdk.tools.jlink.plugin.ResourcePool;
|
||||
import jdk.tools.jlink.plugin.ResourcePoolModule;
|
||||
import jdk.tools.jlink.plugin.ResourcePool;
|
||||
import jdk.tools.jlink.plugin.ResourcePoolEntry;
|
||||
|
||||
public class ResourcePoolTest {
|
||||
@ -139,7 +136,7 @@ public class ResourcePoolTest {
|
||||
try {
|
||||
resources.add(ResourcePoolManager.
|
||||
newCompressedResource(ResourcePoolEntry.create(path, new byte[0]),
|
||||
ByteBuffer.allocate(99), "bitcruncher", null,
|
||||
ByteBuffer.allocate(99), "bitcruncher",
|
||||
((ResourcePoolManager)resources).getStringTable(), ByteOrder.nativeOrder()));
|
||||
} catch (Exception ex) {
|
||||
throw new RuntimeException(ex);
|
||||
@ -207,7 +204,7 @@ public class ResourcePoolTest {
|
||||
ResourcePoolEntry res3 = ResourcePoolEntry.create("/module2/toto1", new byte[7]);
|
||||
resources2.add(res3);
|
||||
resources2.add(ResourcePoolManager.newCompressedResource(res1,
|
||||
ByteBuffer.allocate(7), "zip", null, resources1.getStringTable(),
|
||||
ByteBuffer.allocate(7), "zip", resources1.getStringTable(),
|
||||
ByteOrder.nativeOrder()));
|
||||
checkResources(resources2, res1, res2);
|
||||
}
|
||||
|
@ -370,7 +370,7 @@ public class CompressorPluginTest {
|
||||
byte[] decompressed = compressed.contentBytes();
|
||||
for (ResourceDecompressorFactory factory : decompressors) {
|
||||
try {
|
||||
ResourceDecompressor decompressor = factory.newDecompressor(new Properties());
|
||||
ResourceDecompressor decompressor = factory.newDecompressor();
|
||||
decompressed = decompressor.decompress(
|
||||
strings::get, decompressed,
|
||||
CompressedResourceHeader.getSize(), header.getUncompressedSize());
|
||||
|
Loading…
x
Reference in New Issue
Block a user