Skip to content

Commit c6a95ec

Browse files
committed
Extract RuntimeImageHeapList.
1 parent 8ea59b7 commit c6a95ec

File tree

3 files changed

+65
-27
lines changed

3 files changed

+65
-27
lines changed

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

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import org.graalvm.nativeimage.Platforms;
3636

3737
import com.oracle.svm.core.BuildPhaseProvider;
38-
import com.oracle.svm.core.Uninterruptible;
3938

4039
/**
4140
* A list that is filled at image build time while the static analysis is running, and then read at
@@ -80,7 +79,7 @@ private ImageHeapList() {
8079
public static final class HostedImageHeapList<E> extends AbstractList<E> {
8180
private final Comparator<E> comparator;
8281
private final List<E> hostedList;
83-
public final RuntimeImageHeapList<E> runtimeList;
82+
private final RuntimeImageHeapList<E> runtimeList;
8483
/**
8584
* Used to signal if this list has been modified. If true, the change should be propagated
8685
* from the hosted list to the runtime list by calling {@link #update()}. This variable
@@ -96,6 +95,10 @@ private HostedImageHeapList(Class<E> elementClass, Comparator<E> comparator) {
9695
this.runtimeList = new RuntimeImageHeapList<>((E[]) Array.newInstance(elementClass, 0));
9796
}
9897

98+
public RuntimeImageHeapList<E> getRuntimeList() {
99+
return runtimeList;
100+
}
101+
99102
public synchronized boolean needsUpdate() {
100103
return modified;
101104
}
@@ -158,25 +161,3 @@ private static UnsupportedOperationException notSupported() {
158161
}
159162
}
160163
}
161-
162-
final class RuntimeImageHeapList<E> extends AbstractList<E> {
163-
164-
E[] elementData;
165-
166-
@Platforms(Platform.HOSTED_ONLY.class)
167-
RuntimeImageHeapList(E[] elementData) {
168-
this.elementData = elementData;
169-
}
170-
171-
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
172-
@Override
173-
public E get(int index) {
174-
return elementData[index];
175-
}
176-
177-
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
178-
@Override
179-
public int size() {
180-
return elementData.length;
181-
}
182-
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
package com.oracle.svm.core.util;
26+
27+
import java.util.AbstractList;
28+
29+
import org.graalvm.nativeimage.Platform;
30+
import org.graalvm.nativeimage.Platforms;
31+
32+
import com.oracle.svm.core.Uninterruptible;
33+
34+
/**
35+
* The immutable runtime list view for an {@link ImageHeapList}.
36+
*/
37+
public final class RuntimeImageHeapList<E> extends AbstractList<E> {
38+
39+
E[] elementData;
40+
41+
@Platforms(Platform.HOSTED_ONLY.class)
42+
RuntimeImageHeapList(E[] elementData) {
43+
this.elementData = elementData;
44+
}
45+
46+
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
47+
@Override
48+
public E get(int index) {
49+
return elementData[index];
50+
}
51+
52+
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
53+
@Override
54+
public int size() {
55+
return elementData.length;
56+
}
57+
}

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/heap/ImageHeapCollectionFeature.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ private Object replaceHostedWithRuntime(Object obj) {
6868
} else {
6969
allLists.add(hostedImageHeapList);
7070
}
71-
return hostedImageHeapList.runtimeList;
71+
return hostedImageHeapList.getRuntimeList();
7272
}
7373
return obj;
7474
}
@@ -101,7 +101,7 @@ public void duringAnalysis(DuringAnalysisAccess a) {
101101
allLists.parallelStream().forEach(hostedImageHeapList -> {
102102
if (hostedImageHeapList.needsUpdate()) {
103103
hostedImageHeapList.update();
104-
objectsToRescan.add(hostedImageHeapList.runtimeList);
104+
objectsToRescan.add(hostedImageHeapList.getRuntimeList());
105105
}
106106
});
107107
if (!objectsToRescan.isEmpty()) {
@@ -135,7 +135,7 @@ public void afterImageWrite(AfterImageWriteAccess access) {
135135
for (var hostedImageHeapList : allLists) {
136136
if (hostedImageHeapList.needsUpdate()) {
137137
throw VMError.shouldNotReachHere("ImageHeapList modified after static analysis:%n%s%n%s",
138-
hostedImageHeapList, hostedImageHeapList.runtimeList);
138+
hostedImageHeapList, hostedImageHeapList.getRuntimeList());
139139

140140
}
141141
}

0 commit comments

Comments
 (0)