8323794: Remove unused jimage compressor plugin configuration

Reviewed-by: jlaskey, mchung
This commit is contained in:
Claes Redestad 2024-01-17 15:41:13 +00:00
parent 7be9f1d054
commit 8b29e127c2
13 changed files with 47 additions and 84 deletions

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * 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.ByteBuffer;
import java.nio.ByteOrder; import java.nio.ByteOrder;
import java.util.Objects; 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; private static final int SIZE = 29;
public static final int MAGIC = 0xCAFEFAFA; 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 uncompressedSize;
private final long compressedSize; private final long compressedSize;
private final int decompressorNameOffset; private final int decompressorNameOffset;
private final int contentOffset;
private final boolean isTerminal; private final boolean isTerminal;
public CompressedResourceHeader(long compressedSize, public CompressedResourceHeader(long compressedSize,
long uncompressedSize, int decompressorNameOffset, int contentOffset, long uncompressedSize, int decompressorNameOffset,
boolean isTerminal) { boolean isTerminal) {
this.compressedSize = compressedSize; this.compressedSize = compressedSize;
this.uncompressedSize = uncompressedSize; this.uncompressedSize = uncompressedSize;
this.decompressorNameOffset = decompressorNameOffset; this.decompressorNameOffset = decompressorNameOffset;
this.contentOffset = contentOffset;
this.isTerminal = isTerminal; this.isTerminal = isTerminal;
} }
@ -69,18 +74,6 @@ public final class CompressedResourceHeader {
return decompressorNameOffset; 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() { public long getUncompressedSize() {
return uncompressedSize; return uncompressedSize;
} }
@ -97,7 +90,8 @@ public final class CompressedResourceHeader {
buffer.putLong(compressedSize); buffer.putLong(compressedSize);
buffer.putLong(uncompressedSize); buffer.putLong(uncompressedSize);
buffer.putInt(decompressorNameOffset); buffer.putInt(decompressorNameOffset);
buffer.putInt(contentOffset); // Compatibility
buffer.putInt(-1);
buffer.put(isTerminal ? (byte)1 : (byte)0); buffer.put(isTerminal ? (byte)1 : (byte)0);
return buffer.array(); return buffer.array();
} }
@ -115,16 +109,16 @@ public final class CompressedResourceHeader {
} }
ByteBuffer buffer = ByteBuffer.wrap(resource, 0, SIZE); ByteBuffer buffer = ByteBuffer.wrap(resource, 0, SIZE);
buffer.order(order); buffer.order(order);
int magic = buffer.getInt(); int magic = buffer.getInt(MAGIC_OFFSET);
if(magic != MAGIC) { if (magic != MAGIC) {
return null; return null;
} }
long size = buffer.getLong(); long size = buffer.getLong(COMPRESSED_OFFSET);
long uncompressedSize = buffer.getLong(); long uncompressedSize = buffer.getLong(UNCOMPRESSED_OFFSET);
int decompressorNameOffset = buffer.getInt(); int decompressorNameOffset = buffer.getInt(DECOMPRESSOR_NAME_OFFSET);
int contentIndex = buffer.getInt(); // skip unused 'contentOffset' int
byte isTerminal = buffer.get(); byte isTerminal = buffer.get(IS_TERMINAL_OFFSET);
return new CompressedResourceHeader(size, uncompressedSize, return new CompressedResourceHeader(size, uncompressedSize,
decompressorNameOffset, contentIndex, isTerminal == 1); decompressorNameOffset, isTerminal == 1);
} }
} }

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -24,14 +24,11 @@
*/ */
package jdk.internal.jimage.decompressor; package jdk.internal.jimage.decompressor;
import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
import java.nio.ByteOrder; import java.nio.ByteOrder;
import java.nio.charset.StandardCharsets;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.Properties;
import jdk.internal.jimage.decompressor.ResourceDecompressor.StringsProvider; import jdk.internal.jimage.decompressor.ResourceDecompressor.StringsProvider;
/** /**
@ -75,17 +72,8 @@ public final class Decompressor {
if (pluginName == null) { if (pluginName == null) {
throw new IOException("Plugin name not found"); 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. decompressor = ResourceDecompressorRepository.
newResourceDecompressor(props, pluginName); newResourceDecompressor(pluginName);
if (decompressor == null) { if (decompressor == null) {
throw new IOException("Plugin not found: " + pluginName); throw new IOException("Plugin not found: " + pluginName);
} }

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,7 +25,6 @@
package jdk.internal.jimage.decompressor; package jdk.internal.jimage.decompressor;
import java.io.IOException; import java.io.IOException;
import java.util.Properties;
/** /**
* *
@ -54,12 +53,10 @@ public abstract class ResourceDecompressorFactory {
/** /**
* To build a new decompressor. * To build a new decompressor.
* @param properties Contains configuration.
* @return A new decompressor. * @return A new decompressor.
* @throws IOException * @throws IOException
*/ */
public abstract ResourceDecompressor newDecompressor(Properties properties) public abstract ResourceDecompressor newDecompressor() throws IOException;
throws IOException;
} }

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * 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.io.IOException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Properties;
/** /**
* *
@ -54,17 +53,15 @@ public final class ResourceDecompressorRepository {
/** /**
* Build a new decompressor for the passed name. * Build a new decompressor for the passed name.
* @param properties Contains plugin configuration.
* @param name The plugin name to build. * @param name The plugin name to build.
* @return A decompressor or null if not found * @return A decompressor or null if not found
* @throws IOException * @throws IOException
*/ */
public static ResourceDecompressor newResourceDecompressor(Properties properties, public static ResourceDecompressor newResourceDecompressor(String name) throws IOException {
String name) throws IOException {
ResourceDecompressorFactory fact = factories.get(name); ResourceDecompressorFactory fact = factories.get(name);
if (fact != null) { if (fact != null) {
return fact.newDecompressor(properties); return fact.newDecompressor();
} }
return null; return null;
} }

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * 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.nio.ByteOrder;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Properties;
/** /**
* *
@ -228,9 +227,7 @@ public class StringSharingDecompressor implements ResourceDecompressor {
return StringSharingDecompressorFactory.NAME; return StringSharingDecompressorFactory.NAME;
} }
public StringSharingDecompressor(Properties properties) { public StringSharingDecompressor() {}
}
@Override @Override
public byte[] decompress(StringsProvider reader, byte[] content, public byte[] decompress(StringsProvider reader, byte[] content,

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,7 +25,6 @@
package jdk.internal.jimage.decompressor; package jdk.internal.jimage.decompressor;
import java.io.IOException; import java.io.IOException;
import java.util.Properties;
/** /**
* *
@ -45,8 +44,8 @@ public class StringSharingDecompressorFactory extends ResourceDecompressorFactor
} }
@Override @Override
public ResourceDecompressor newDecompressor(Properties properties) public ResourceDecompressor newDecompressor()
throws IOException { throws IOException {
return new StringSharingDecompressor(properties); return new StringSharingDecompressor();
} }
} }

View File

@ -24,7 +24,6 @@
*/ */
package jdk.internal.jimage.decompressor; package jdk.internal.jimage.decompressor;
import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.zip.Inflater; import java.util.zip.Inflater;

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,7 +25,6 @@
package jdk.internal.jimage.decompressor; package jdk.internal.jimage.decompressor;
import java.io.IOException; import java.io.IOException;
import java.util.Properties;
/** /**
* *
@ -44,7 +43,7 @@ public final class ZipDecompressorFactory extends ResourceDecompressorFactory {
} }
@Override @Override
public ResourceDecompressor newDecompressor(Properties properties) public ResourceDecompressor newDecompressor()
throws IOException { throws IOException {
return new ZipDecompressor(); return new ZipDecompressor();
} }

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * 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, public static CompressedModuleData newCompressedResource(ResourcePoolEntry original,
ByteBuffer compressed, ByteBuffer compressed,
String plugin, String pluginConfig, StringTable strings, String plugin,
StringTable strings,
ByteOrder order) { ByteOrder order) {
Objects.requireNonNull(original); Objects.requireNonNull(original);
Objects.requireNonNull(compressed); Objects.requireNonNull(compressed);
@ -461,13 +462,9 @@ public class ResourcePoolManager {
uncompressed_size = comp.getUncompressedSize(); uncompressed_size = comp.getUncompressedSize();
} }
int nameOffset = strings.addString(plugin); int nameOffset = strings.addString(plugin);
int configOffset = -1;
if (pluginConfig != null) {
configOffset = strings.addString(plugin);
}
CompressedResourceHeader rh CompressedResourceHeader rh
= new CompressedResourceHeader(compressed.limit(), original.contentLength(), = new CompressedResourceHeader(compressed.limit(), original.contentLength(),
nameOffset, configOffset, isTerminal); nameOffset, isTerminal);
// Merge header with content; // Merge header with content;
byte[] h = rh.getBytes(order); byte[] h = rh.getBytes(order);
ByteBuffer bb = ByteBuffer.allocate(compressed.limit() + h.length); ByteBuffer bb = ByteBuffer.allocate(compressed.limit() + h.length);

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * 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.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
@ -306,14 +305,14 @@ public class StringSharingPlugin extends AbstractPlugin implements ResourcePrevi
in.transformAndCopy((resource) -> { in.transformAndCopy((resource) -> {
ResourcePoolEntry res = resource; ResourcePoolEntry res = resource;
if (predicate.test(resource.path()) && resource.path().endsWith(".class")) { if (predicate.test(resource.path()) && resource.path().endsWith(".class")) {
byte[] compressed = null; byte[] compressed;
try { try {
compressed = visit.transform(resource, result, ((ResourcePoolImpl)in).getStringTable()); compressed = visit.transform(resource, result, ((ResourcePoolImpl)in).getStringTable());
} catch (Exception ex) { } catch (Exception ex) {
throw new PluginException(ex); throw new PluginException(ex);
} }
res = ResourcePoolManager.newCompressedResource(resource, res = ResourcePoolManager.newCompressedResource(resource,
ByteBuffer.wrap(compressed), getName(), null, ByteBuffer.wrap(compressed), getName(),
((ResourcePoolImpl)in).getStringTable(), in.byteOrder()); ((ResourcePoolImpl)in).getStringTable(), in.byteOrder());
} }
return res; return res;

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * 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; byte[] compressed;
compressed = compress(resource.contentBytes(), this.compressionLevel); compressed = compress(resource.contentBytes(), this.compressionLevel);
res = ResourcePoolManager.newCompressedResource(resource, res = ResourcePoolManager.newCompressedResource(resource,
ByteBuffer.wrap(compressed), getName(), null, ByteBuffer.wrap(compressed), getName(),
((ResourcePoolImpl)in).getStringTable(), in.byteOrder()); ((ResourcePoolImpl)in).getStringTable(), in.byteOrder());
} }
return res; return res;

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -31,11 +31,9 @@
* @run main ResourcePoolTest * @run main ResourcePoolTest
*/ */
import java.io.ByteArrayInputStream;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.ByteOrder; import java.nio.ByteOrder;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
@ -44,7 +42,6 @@ import java.util.function.Function;
import jdk.tools.jlink.internal.ResourcePoolManager; import jdk.tools.jlink.internal.ResourcePoolManager;
import jdk.tools.jlink.plugin.ResourcePool; import jdk.tools.jlink.plugin.ResourcePool;
import jdk.tools.jlink.plugin.ResourcePoolModule; import jdk.tools.jlink.plugin.ResourcePoolModule;
import jdk.tools.jlink.plugin.ResourcePool;
import jdk.tools.jlink.plugin.ResourcePoolEntry; import jdk.tools.jlink.plugin.ResourcePoolEntry;
public class ResourcePoolTest { public class ResourcePoolTest {
@ -139,7 +136,7 @@ public class ResourcePoolTest {
try { try {
resources.add(ResourcePoolManager. resources.add(ResourcePoolManager.
newCompressedResource(ResourcePoolEntry.create(path, new byte[0]), newCompressedResource(ResourcePoolEntry.create(path, new byte[0]),
ByteBuffer.allocate(99), "bitcruncher", null, ByteBuffer.allocate(99), "bitcruncher",
((ResourcePoolManager)resources).getStringTable(), ByteOrder.nativeOrder())); ((ResourcePoolManager)resources).getStringTable(), ByteOrder.nativeOrder()));
} catch (Exception ex) { } catch (Exception ex) {
throw new RuntimeException(ex); throw new RuntimeException(ex);
@ -207,7 +204,7 @@ public class ResourcePoolTest {
ResourcePoolEntry res3 = ResourcePoolEntry.create("/module2/toto1", new byte[7]); ResourcePoolEntry res3 = ResourcePoolEntry.create("/module2/toto1", new byte[7]);
resources2.add(res3); resources2.add(res3);
resources2.add(ResourcePoolManager.newCompressedResource(res1, resources2.add(ResourcePoolManager.newCompressedResource(res1,
ByteBuffer.allocate(7), "zip", null, resources1.getStringTable(), ByteBuffer.allocate(7), "zip", resources1.getStringTable(),
ByteOrder.nativeOrder())); ByteOrder.nativeOrder()));
checkResources(resources2, res1, res2); checkResources(resources2, res1, res2);
} }

View File

@ -370,7 +370,7 @@ public class CompressorPluginTest {
byte[] decompressed = compressed.contentBytes(); byte[] decompressed = compressed.contentBytes();
for (ResourceDecompressorFactory factory : decompressors) { for (ResourceDecompressorFactory factory : decompressors) {
try { try {
ResourceDecompressor decompressor = factory.newDecompressor(new Properties()); ResourceDecompressor decompressor = factory.newDecompressor();
decompressed = decompressor.decompress( decompressed = decompressor.decompress(
strings::get, decompressed, strings::get, decompressed,
CompressedResourceHeader.getSize(), header.getUncompressedSize()); CompressedResourceHeader.getSize(), header.getUncompressedSize());