Skip to content

Commit adee114

Browse files
committed
Update HostedImageHeapMap documentation. No functional changes.
1 parent fdf916b commit adee114

File tree

2 files changed

+45
-18
lines changed

2 files changed

+45
-18
lines changed

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/util/ImageHeapMap.java

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,17 @@
3838

3939
/**
4040
* A thread-safe map implementation that optimizes its run time representation for space efficiency.
41-
*
42-
* At image build time the map is implemented as a {@link ConcurrentHashMap} wrapped into an
43-
* {@link EconomicMap}. The ImageHeapMapFeature intercepts each build time map and transforms it
44-
* into an actual memory-efficient {@link EconomicMap} backed by a flat object array during
45-
* analysis. The later image building stages see only the {@link EconomicMap}.
46-
*
41+
* <p>
42+
* At image build time the map is implemented as a {@link ConcurrentHashMap} or
43+
* {@link ConcurrentIdentityHashMap} wrapped into an {@link EconomicMapWrap}. The
44+
* ImageHeapCollectionFeature intercepts each build time map and transforms it into an actual
45+
* memory-efficient {@link EconomicMap} backed by a flat object array during analysis. The later
46+
* image building stages see only the {@link EconomicMap}.
47+
* <p>
48+
* Additionally, in layered builds, at run time this map can be part of a
49+
* {@link LayeredImageHeapMap} structure, i.e., conceptually a linked list of {@link EconomicMap}s
50+
* that spans across multiple layers.
51+
* <p>
4752
* This map implementation allows thread-safe collection of data at image build time and storing it
4853
* into a space efficient data structure at run time.
4954
*/
@@ -54,27 +59,43 @@ private ImageHeapMap() {
5459
}
5560

5661
/**
57-
* Create a hosted representation of an {@link ImageHeapMap}: a {@link ConcurrentHashMap}
58-
* wrapped into an {@link EconomicMap}. At run time this will be an actual memory-efficient
59-
* {@link EconomicMap} backed by a flat object array.
62+
* In non-layered builds this creates a regular {@link ImageHeapMap} (see above).
63+
* <p>
64+
* In layered builds this creates a map that expands across layers. During the current layer
65+
* build this is a {@link ConcurrentHashMap} wrapped by an {@link EconomicMapWrap}. At run time
66+
* it is part of a {@link LayeredImageHeapMap} structure, i.e., conceptually a linked list of
67+
* {@link EconomicMap}s that spans across multiple layers.
6068
*/
6169
@Platforms(Platform.HOSTED_ONLY.class) //
6270
public static <K, V> EconomicMap<K, V> create(String key) {
6371
return create(Equivalence.DEFAULT, key);
6472
}
6573

66-
@Platforms(Platform.HOSTED_ONLY.class) //
67-
public static <K, V> EconomicMap<K, V> createNonLayeredMap() {
68-
return createNonLayeredMap(Equivalence.DEFAULT);
69-
}
70-
74+
/**
75+
* Same as {@link #create(String)}, but if the {@code strategy} is {@link Equivalence#IDENTITY}
76+
* the hosted map is a {@link ConcurrentIdentityHashMap}.
77+
*/
7178
@Platforms(Platform.HOSTED_ONLY.class) //
7279
public static <K, V> EconomicMap<K, V> create(Equivalence strategy, String key) {
7380
assert key != null : "The key should not be null if the map needs to be automatically layered";
7481
VMError.guarantee(!BuildPhaseProvider.isAnalysisFinished(), "Trying to create an ImageHeapMap after analysis.");
7582
return HostedImageHeapMap.create(strategy, key, true);
7683
}
7784

85+
/**
86+
* Create an {@link ImageHeapMap}. At build time it is a {@link ConcurrentHashMap} wrapped into
87+
* an {@link EconomicMapWrap}. At run time this will be an actual memory-efficient
88+
* {@link EconomicMap} backed by a flat object array.
89+
*/
90+
@Platforms(Platform.HOSTED_ONLY.class) //
91+
public static <K, V> EconomicMap<K, V> createNonLayeredMap() {
92+
return createNonLayeredMap(Equivalence.DEFAULT);
93+
}
94+
95+
/**
96+
* Same as {@link #createNonLayeredMap()}, but if the {@code strategy} is
97+
* {@link Equivalence#IDENTITY} the hosted map is a {@link ConcurrentIdentityHashMap}.
98+
*/
7899
@Platforms(Platform.HOSTED_ONLY.class) //
79100
public static <K, V> EconomicMap<K, V> createNonLayeredMap(Equivalence strategy) {
80101
VMError.guarantee(!BuildPhaseProvider.isAnalysisFinished(), "Trying to create an ImageHeapMap after analysis.");
@@ -115,12 +136,10 @@ public EconomicMap<Object, Object> getRuntimeMap() {
115136
return runtimeMap;
116137
}
117138

118-
public static <K, V> HostedImageHeapMap<K, V> create(Equivalence strategy, String key, boolean needLayeredMap) {
139+
public static <K, V> HostedImageHeapMap<K, V> create(Equivalence strategy, String key, boolean isLayeredMap) {
119140
Map<K, V> hostedMap = (strategy == Equivalence.IDENTITY) ? new ConcurrentIdentityHashMap<>() : new ConcurrentHashMap<>();
120141
EconomicMap<Object, Object> currentLayerMap = EconomicMap.create(strategy);
121-
if (!needLayeredMap || !ImageLayerBuildingSupport.buildingImageLayer()) {
122-
return new HostedImageHeapMap<>(hostedMap, currentLayerMap, currentLayerMap);
123-
} else {
142+
if (ImageLayerBuildingSupport.buildingImageLayer() && isLayeredMap) {
124143
LayeredImageHeapMap<Object, Object> runtimeMap = new LayeredImageHeapMap<>(strategy, key);
125144
var previousMap = LayeredImageHeapMapStore.currentLayer().getImageHeapMapStore().put(key, currentLayerMap);
126145
if (previousMap != null) {
@@ -132,6 +151,8 @@ public static <K, V> HostedImageHeapMap<K, V> create(Equivalence strategy, Strin
132151
singleton.registerPreviousLayerHostedImageHeapMap(hostedImageHeapMap);
133152
}
134153
return hostedImageHeapMap;
154+
} else {
155+
return new HostedImageHeapMap<>(hostedMap, currentLayerMap, currentLayerMap);
135156
}
136157
}
137158
}

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/util/LayeredImageHeapMapStore.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@
3737
import com.oracle.svm.core.layeredimagesingleton.MultiLayeredImageSingleton;
3838
import com.oracle.svm.core.layeredimagesingleton.UnsavedSingleton;
3939

40+
/**
41+
* Per layer store for the {@link LayeredImageHeapMap}s. There exists one
42+
* {@link LayeredImageHeapMapStore} per layer and each entry in the underlying
43+
* {@link #imageHeapMapStore} corresponds to a specific {@link LayeredImageHeapMap}, identified by
44+
* its {@link LayeredImageHeapMap#getMapKey()}.
45+
*/
4046
public class LayeredImageHeapMapStore implements MultiLayeredImageSingleton, UnsavedSingleton {
4147
private final Map<String, EconomicMap<Object, Object>> imageHeapMapStore = new HashMap<>();
4248

0 commit comments

Comments
 (0)