Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import static com.oracle.svm.core.option.RuntimeOptionKey.RuntimeOptionKeyFlag.RelevantForCompilationIsolates;

import java.util.Arrays;
import java.util.List;

import org.graalvm.collections.EconomicMap;
import org.graalvm.nativeimage.CurrentIsolate;
Expand Down Expand Up @@ -101,9 +100,9 @@
import com.oracle.svm.core.traits.SingletonLayeredInstallationKind.Independent;
import com.oracle.svm.core.traits.SingletonLayeredInstallationKind.InitialLayerOnly;
import com.oracle.svm.core.traits.SingletonTraits;
import com.oracle.svm.core.util.AbstractImageHeapList;
import com.oracle.svm.core.util.CounterSupport;
import com.oracle.svm.core.util.ImageHeapList;
import com.oracle.svm.core.util.RuntimeImageHeapList;
import com.oracle.svm.core.util.TimeUtils;
import com.oracle.svm.core.util.VMError;

Expand Down Expand Up @@ -1283,7 +1282,7 @@ public static class DiagnosticThunkRegistry {
@Platforms(Platform.HOSTED_ONLY.class) //
final int runtimeCompilationPosition;

private final List<DiagnosticThunk> thunks = ImageHeapList.create(DiagnosticThunk.class);
private final AbstractImageHeapList<DiagnosticThunk> thunks = ImageHeapList.create(DiagnosticThunk.class);
private int[] initialInvocationCount;

@Fold
Expand Down Expand Up @@ -1368,12 +1367,7 @@ int size() {
}

DiagnosticThunk getThunk(int index) {
/*
* Use an explicit cast to aid open-world analysis. Otherwise, this may trigger false
* positive violations of @RestrictHeapAccess since some implementations of List.get()
* can allocate.
*/
return ((RuntimeImageHeapList<DiagnosticThunk>) thunks).get(index);
return thunks.get(index);
}

int getInitialInvocationCount(int index) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright (c) 2025, 2025, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.oracle.svm.core.util;

import java.util.AbstractList;
import java.util.ArrayList;
import java.util.List;

import com.oracle.svm.core.heap.RestrictHeapAccess;
import com.oracle.svm.core.util.ImageHeapList.HostedImageHeapList;

/**
* Super type for {@link HostedImageHeapList} and {@link RuntimeImageHeapList} that allows declaring
* a more restricted type for fields initialized with {@link ImageHeapList#create(Class)} to aid
* open-world analysis. When such a field is analysed in an open-world it gets injected all possible
* subtypes of its declared type. Declaring the type as {@link AbstractImageHeapList} allows us to
* only inject {@link RuntimeImageHeapList}.This enables a more precise analysis and avoids for
* example triggering false-positive violations of @{@link RestrictHeapAccess}: if the field was
* declared as {@link List} then implementations of {@link List} for which simple access operations
* can allocate, such as {@link ArrayList#get(int)}, could become reachable from code annotated
* with @{@link RestrictHeapAccess}.
*/
public abstract sealed class AbstractImageHeapList<E> extends AbstractList<E> permits HostedImageHeapList, RuntimeImageHeapList {
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
package com.oracle.svm.core.util;

import java.lang.reflect.Array;
import java.util.AbstractList;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
Expand Down Expand Up @@ -57,17 +56,17 @@
public final class ImageHeapList {

@Platforms(Platform.HOSTED_ONLY.class) //
public static <E> List<E> create(Class<E> elementClass) {
public static <E> AbstractImageHeapList<E> create(Class<E> elementClass) {
return create(elementClass, null);
}

@Platforms(Platform.HOSTED_ONLY.class) //
public static List<?> createGeneric(Class<?> elementClass) {
public static AbstractImageHeapList<?> createGeneric(Class<?> elementClass) {
return create(elementClass, null);
}

@Platforms(Platform.HOSTED_ONLY.class) //
public static <E> List<E> create(Class<E> elementClass, Comparator<E> comparator) {
public static <E> AbstractImageHeapList<E> create(Class<E> elementClass, Comparator<E> comparator) {
VMError.guarantee(!BuildPhaseProvider.isAnalysisFinished(), "Trying to create an ImageHeapList after analysis.");
return new HostedImageHeapList<>(elementClass, comparator);
}
Expand All @@ -76,7 +75,7 @@ private ImageHeapList() {
}

@Platforms(Platform.HOSTED_ONLY.class) //
public static final class HostedImageHeapList<E> extends AbstractList<E> {
public static final class HostedImageHeapList<E> extends AbstractImageHeapList<E> {
private final Comparator<E> comparator;
private final List<E> hostedList;
private final RuntimeImageHeapList<E> runtimeList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
*/
package com.oracle.svm.core.util;

import java.util.AbstractList;

import org.graalvm.nativeimage.Platform;
import org.graalvm.nativeimage.Platforms;

Expand All @@ -34,7 +32,7 @@
/**
* The immutable runtime list view for an {@link ImageHeapList}.
*/
public final class RuntimeImageHeapList<E> extends AbstractList<E> {
public final class RuntimeImageHeapList<E> extends AbstractImageHeapList<E> {

E[] elementData;

Expand Down