Skip to content

Commit 9e3ca64

Browse files
committed
Change representation of Resource data from List<byte[]> to byte[][].
1 parent d7571e0 commit 9e3ca64

File tree

8 files changed

+21
-36
lines changed

8 files changed

+21
-36
lines changed

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Resources.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -628,8 +628,8 @@ public static InputStream createInputStream(Module module, String resourceName)
628628
} else if (entry == null) {
629629
return null;
630630
}
631-
List<byte[]> data = entry.getData();
632-
return data.isEmpty() ? null : new ByteArrayInputStream(data.get(0));
631+
byte[][] data = entry.getData();
632+
return data.length == 0 ? null : new ByteArrayInputStream(data[0]);
633633
}
634634

635635
private static ResourceStorageEntryBase findResourceForInputStream(Module module, String resourceName) {
@@ -703,8 +703,7 @@ private static void addURLEntries(List<URL> resourcesURLs, ResourceStorageEntry
703703
if (entry == null) {
704704
return;
705705
}
706-
int numberOfResources = entry.getData().size();
707-
for (int index = 0; index < numberOfResources; index++) {
706+
for (int index = 0; index < entry.getData().length; index++) {
708707
resourcesURLs.add(createURL(module, canonicalResourceName, index));
709708
}
710709
}

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/resources/NativeImageResourceFileSystemUtil.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,23 +40,14 @@ public static byte[] getBytes(String resourceName, boolean readOnly) {
4040
if (entry == null) {
4141
return new byte[0];
4242
}
43-
byte[] bytes = ((ResourceStorageEntry) entry).getData().get(0);
43+
byte[] bytes = ((ResourceStorageEntry) entry).getData()[0];
4444
if (readOnly) {
4545
return bytes;
4646
} else {
4747
return Arrays.copyOf(bytes, bytes.length);
4848
}
4949
}
5050

51-
public static int getSize(String resourceName) {
52-
Object entry = Resources.getAtRuntime(resourceName);
53-
if (entry == null) {
54-
return 0;
55-
} else {
56-
return ((ResourceStorageEntry) entry).getData().get(0).length;
57-
}
58-
}
59-
6051
public static String toRegexPattern(String globPattern) {
6152
return Target_jdk_nio_zipfs_ZipUtils.toRegexPattern(globPattern);
6253
}

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/resources/ResourceStorageEntry.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525

2626
package com.oracle.svm.core.jdk.resources;
2727

28-
import java.util.ArrayList;
29-
import java.util.List;
28+
import java.util.Arrays;
3029

3130
import org.graalvm.nativeimage.Platform;
3231
import org.graalvm.nativeimage.Platforms;
@@ -36,14 +35,16 @@
3635

3736
public final class ResourceStorageEntry extends ResourceStorageEntryBase {
3837

38+
private static byte[][] EMPTY_DATA = new byte[0][];
39+
3940
private final boolean isDirectory;
4041
private final boolean fromJar;
41-
private List<byte[]> data;
42+
private byte[][] data;
4243

4344
public ResourceStorageEntry(boolean isDirectory, boolean fromJar) {
4445
this.isDirectory = isDirectory;
4546
this.fromJar = fromJar;
46-
this.data = List.of();
47+
this.data = EMPTY_DATA;
4748
}
4849

4950
@Override
@@ -57,18 +58,17 @@ public boolean isFromJar() {
5758
}
5859

5960
@Override
60-
public List<byte[]> getData() {
61+
public byte[][] getData() {
6162
return data;
6263
}
6364

6465
@Platforms(Platform.HOSTED_ONLY.class)
6566
@Override
6667
public void addData(byte[] datum) {
67-
List<byte[]> newData = new ArrayList<>(data.size() + 1);
68-
newData.addAll(data);
69-
newData.add(datum);
68+
byte[][] newData = Arrays.copyOf(data, data.length + 1);
69+
newData[data.length] = datum;
7070
/* Always use a compact, immutable data structure in the image heap. */
71-
data = List.copyOf(newData);
71+
data = newData;
7272
}
7373

7474
/**
@@ -81,7 +81,7 @@ public void addData(byte[] datum) {
8181
public void replaceData(byte[]... replacementData) {
8282
VMError.guarantee(BuildPhaseProvider.isAnalysisFinished(), "Replacing data of a resource entry before analysis finished. Register standard resource instead.");
8383
VMError.guarantee(!BuildPhaseProvider.isCompilationFinished(), "Trying to replace data of a resource entry after compilation finished.");
84-
this.data = List.of(replacementData);
84+
this.data = replacementData;
8585
}
8686

8787
@Override

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/resources/ResourceStorageEntryBase.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525

2626
package com.oracle.svm.core.jdk.resources;
2727

28-
import java.util.List;
29-
3028
import org.graalvm.nativeimage.Platform;
3129
import org.graalvm.nativeimage.Platforms;
3230

@@ -41,7 +39,7 @@ public boolean isFromJar() {
4139
throw VMError.shouldNotReachHere("This should only be called on entries with data.");
4240
}
4341

44-
public List<byte[]> getData() {
42+
public byte[][] getData() {
4543
throw VMError.shouldNotReachHere("This should only be called on entries with data.");
4644
}
4745

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/resources/ResourceURLConnection.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public void connect() {
7777
Object entry = Resources.getAtRuntime(module, resourceName, false);
7878
if (entry != null) {
7979
ResourceStorageEntry resourceStorageEntry = (ResourceStorageEntry) entry;
80-
List<byte[]> bytes = resourceStorageEntry.getData();
80+
byte[][] bytes = resourceStorageEntry.getData();
8181
isDirectory = resourceStorageEntry.isDirectory();
8282
String urlRef = url.getRef();
8383
int index = 0;
@@ -88,12 +88,12 @@ public void connect() {
8888
throw new IllegalArgumentException("URL anchor '#" + urlRef + "' not allowed in " + JavaNetSubstitutions.RESOURCE_PROTOCOL + " URL");
8989
}
9090
}
91-
if (index < bytes.size()) {
92-
this.data = bytes.get(index);
91+
if (index < bytes.length) {
92+
this.data = bytes[index];
9393
} else {
9494
// This will happen only in case that we are creating one URL with the second URL as
9595
// a context.
96-
this.data = bytes.get(0);
96+
this.data = bytes[0];
9797
}
9898
} else {
9999
this.data = null;

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/EmbeddedResourceExporter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public static List<ResourceReportEntry> getResourceReportEntryList(ConcurrentHas
120120
List<EmbeddedResourceExporter.SourceSizePair> sources = new ArrayList<>();
121121
for (int i = 0; i < registeredEntrySources.size(); i++) {
122122
SourceAndOrigin sourceAndOrigin = registeredEntrySources.get(i);
123-
int size = storageEntry.getData().get(i).length;
123+
int size = storageEntry.getData()[i].length;
124124
sources.add(new SourceSizePair(sourceAndOrigin.source(), sourceAndOrigin.origin(), size));
125125
}
126126

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ProgressReporter.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@
111111
import jdk.graal.compiler.options.OptionStability;
112112
import jdk.graal.compiler.options.OptionValues;
113113
import jdk.graal.compiler.util.json.JsonWriter;
114-
import org.graalvm.nativeimage.impl.RuntimeResourceSupport;
115114

116115
@SingletonTraits(access = BuildtimeAccessOnly.class, layeredCallbacks = NoLayeredCallbacks.class, layeredInstallationKind = Independent.class)
117116
public class ProgressReporter {
@@ -513,7 +512,6 @@ private void printAnalysisStatistics(AnalysisUniverse universe, Collection<Strin
513512
l().a(stubsFormat, numForeignDowncalls, numForeignUpcalls)
514513
.doclink("registered for foreign access", "#glossary-foreign-downcall-and-upcall-registrations").println();
515514
}
516-
RuntimeResourceSupport runtimeResourceSupport = ImageSingletons.lookup(RuntimeResourceSupport.class);
517515
int resourceCount = Resources.currentLayer().resources().size();
518516
long totalResourceSize = 0;
519517
for (ConditionalRuntimeValue<ResourceStorageEntryBase> value : Resources.currentLayer().resources().getValues()) {
@@ -526,7 +524,6 @@ private void printAnalysisStatistics(AnalysisUniverse universe, Collection<Strin
526524
if (resourceCount > 0) {
527525
l().a("%,9d %s found with %s total size", resourceCount, resourceCount == 1 ? "resource" : "resources", ByteFormattingUtil.bytesToHuman(totalResourceSize)).println();
528526
}
529-
ConditionalRuntimeValue<ResourceStorageEntryBase> value;
530527
int numLibraries = libraries.size();
531528
if (numLibraries > 0) {
532529
TreeSet<String> sortedLibraries = new TreeSet<>(libraries);

web-image/src/com.oracle.svm.webimage/src/com/oracle/svm/webimage/substitute/system/WebImageJavaLangSubstitutions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ private InputStream getResourceAsStream(String resourceName) {
644644
resName = resName.substring(1);
645645
}
646646
ResourceStorageEntryBase res = Resources.getAtRuntime(SubstrateUtil.cast(this, Module.class), resName, true);
647-
return res == null ? null : new ByteArrayInputStream(res.getData().get(0));
647+
return res == null ? null : new ByteArrayInputStream(res.getData()[0]);
648648
}
649649
}
650650

0 commit comments

Comments
 (0)