Skip to content

Commit 320fe54

Browse files
committed
[GR-25050] Various clean-ups.
PullRequest: graal/10007
2 parents b6eb871 + ee87ab3 commit 320fe54

File tree

45 files changed

+275
-145
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+275
-145
lines changed

sdk/src/org.graalvm.collections/snapshot.sigtest

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ meth public static <%0 extends java.lang.Object, %1 extends java.lang.Object> or
3434
meth public static <%0 extends java.lang.Object, %1 extends java.lang.Object> org.graalvm.collections.EconomicMap<{%%0},{%%1}> create(org.graalvm.collections.Equivalence,org.graalvm.collections.UnmodifiableEconomicMap<{%%0},{%%1}>)
3535
meth public static <%0 extends java.lang.Object, %1 extends java.lang.Object> org.graalvm.collections.EconomicMap<{%%0},{%%1}> create(org.graalvm.collections.UnmodifiableEconomicMap<{%%0},{%%1}>)
3636
meth public static <%0 extends java.lang.Object, %1 extends java.lang.Object> org.graalvm.collections.EconomicMap<{%%0},{%%1}> wrapMap(java.util.Map<{%%0},{%%1}>)
37+
meth public static <%0 extends java.lang.Object, %1 extends java.lang.Object> org.graalvm.collections.MapCursor<{%%0},{%%1}> emptyCursor()
3738
meth public void putAll(org.graalvm.collections.EconomicMap<{org.graalvm.collections.EconomicMap%0},{org.graalvm.collections.EconomicMap%1}>)
3839
meth public void putAll(org.graalvm.collections.UnmodifiableEconomicMap<? extends {org.graalvm.collections.EconomicMap%0},? extends {org.graalvm.collections.EconomicMap%1}>)
3940
meth public {org.graalvm.collections.EconomicMap%1} putIfAbsent({org.graalvm.collections.EconomicMap%0},{org.graalvm.collections.EconomicMap%1})

sdk/src/org.graalvm.collections/src/org/graalvm/collections/EconomicMap.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,4 +230,32 @@ static <K, V> EconomicMap<K, V> create(Equivalence strategy, int initialCapacity
230230
static <K, V> EconomicMap<K, V> wrapMap(Map<K, V> map) {
231231
return new EconomicMapWrap<>(map);
232232
}
233+
234+
/**
235+
* Return an empty {@link MapCursor}.
236+
*
237+
* @since 22.0
238+
*/
239+
static <K, V> MapCursor<K, V> emptyCursor() {
240+
return new MapCursor<K, V>() {
241+
@Override
242+
public void remove() {
243+
}
244+
245+
@Override
246+
public boolean advance() {
247+
return false;
248+
}
249+
250+
@Override
251+
public K getKey() {
252+
return null;
253+
}
254+
255+
@Override
256+
public V getValue() {
257+
return null;
258+
}
259+
};
260+
}
233261
}

substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/AnalysisObjectScanningObserver.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@
3333

3434
import jdk.vm.ci.meta.JavaConstant;
3535

36-
class AnalysisObjectScanningObserver implements ObjectScanningObserver {
36+
public class AnalysisObjectScanningObserver implements ObjectScanningObserver {
3737

3838
private final BigBang bb;
3939

40-
AnalysisObjectScanningObserver(BigBang bb) {
40+
public AnalysisObjectScanningObserver(BigBang bb) {
4141
this.bb = bb;
4242
}
4343

substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/PointsToAnalysis.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,7 @@ public AnalysisMethod addRootMethod(Executable method) {
435435
@Override
436436
@SuppressWarnings("try")
437437
public AnalysisMethod addRootMethod(AnalysisMethod aMethod) {
438+
assert !universe.sealed() : "Cannot register root methods after analysis universe is sealed.";
438439
if (aMethod.isRootMethod()) {
439440
return aMethod;
440441
}

substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/meta/AnalysisUniverse.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,8 @@ public AnalysisMethod lookup(JavaMethod method) {
397397
} else if (result instanceof ResolvedJavaMethod) {
398398
return (AnalysisMethod) result;
399399
}
400-
throw new UnsupportedFeatureException("Unresolved method found. Probably there are some compilation or classpath problems. " + method.format("%H.%n(%p)"));
400+
throw new UnsupportedFeatureException("Unresolved method found: " + (method != null ? method.format("%H.%n(%p)") : "null") +
401+
". Probably there are some compilation or classpath problems. ");
401402
}
402403

403404
@Override

substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/util/AnalysisFuture.java

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,23 +49,22 @@ protected void setException(Throwable t) {
4949
throw new GraalError(t);
5050
}
5151

52-
/** Run the task and wait for it to complete, if necessary. */
53-
public void ensureDone() {
52+
/** Run the task, wait for it to complete if necessary, then retrieve its result. */
53+
public V ensureDone() {
5454
try {
5555
/*
56-
* If the task is not done yet trigger its execution and call get(), which waits for the
57-
* computation to complete, if necessary.
58-
*
59-
* A task is "done" even if it failed with an exception. The exception is only reported
60-
* when get() is invoked. That's why, to support this execution pattern without miss any
61-
* exceptions, we report the error eagerly as a GraalError as soon as it is encountered.
56+
* Trigger the task execution and call get(), which waits for the computation to
57+
* complete, if necessary.
58+
*
59+
* A task is done even if it failed with an exception. The exception is only reported
60+
* when get() is invoked. We report any error eagerly as a GraalError as soon as it is
61+
* encountered.
6262
*/
63-
if (!isDone()) {
64-
run();
65-
get();
66-
}
63+
run();
64+
return get();
6765
} catch (InterruptedException | ExecutionException e) {
68-
AnalysisError.shouldNotReachHere(e);
66+
throw AnalysisError.shouldNotReachHere(e);
6967
}
7068
}
69+
7170
}

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/c/GraalAccess.java renamed to substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/util/GraalAccess.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -22,7 +22,7 @@
2222
* or visit www.oracle.com if you need additional information or have any
2323
* questions.
2424
*/
25-
package com.oracle.svm.hosted.c;
25+
package com.oracle.graal.pointsto.util;
2626

2727
import org.graalvm.compiler.api.replacements.SnippetReflectionProvider;
2828
import org.graalvm.compiler.api.runtime.GraalJVMCICompiler;
@@ -32,7 +32,10 @@
3232
import jdk.vm.ci.code.TargetDescription;
3333
import jdk.vm.ci.runtime.JVMCI;
3434

35-
public class GraalAccess {
35+
public final class GraalAccess {
36+
37+
private GraalAccess() {
38+
}
3639

3740
public static TargetDescription getOriginalTarget() {
3841
return getGraalCapability(RuntimeProvider.class).getHostBackend().getTarget();
@@ -46,7 +49,7 @@ public static SnippetReflectionProvider getOriginalSnippetReflection() {
4649
return getGraalCapability(SnippetReflectionProvider.class);
4750
}
4851

49-
private static <T> T getGraalCapability(Class<T> clazz) {
52+
public static <T> T getGraalCapability(Class<T> clazz) {
5053
GraalJVMCICompiler compiler = (GraalJVMCICompiler) JVMCI.getRuntime().getCompiler();
5154
return compiler.getGraalRuntime().getCapability(clazz);
5255
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright (c) 2021, 2021, 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;
26+
27+
import org.graalvm.nativeimage.ImageSingletons;
28+
import org.graalvm.nativeimage.Platform;
29+
import org.graalvm.nativeimage.Platforms;
30+
31+
@Platforms(Platform.HOSTED_ONLY.class)
32+
public final class BuildPhaseProvider {
33+
34+
private boolean analysisFinished;
35+
private boolean hostedUniverseBuilt;
36+
37+
public static void init() {
38+
ImageSingletons.add(BuildPhaseProvider.class, new BuildPhaseProvider());
39+
}
40+
41+
static BuildPhaseProvider singleton() {
42+
return ImageSingletons.lookup(BuildPhaseProvider.class);
43+
}
44+
45+
BuildPhaseProvider() {
46+
}
47+
48+
public static void markAnalysisFinished() {
49+
singleton().analysisFinished = true;
50+
}
51+
52+
public static boolean isAnalysisFinished() {
53+
return singleton().analysisFinished;
54+
}
55+
56+
public static void markHostedUniverseBuilt() {
57+
singleton().hostedUniverseBuilt = true;
58+
}
59+
60+
public static boolean isHostedUniverseBuilt() {
61+
return singleton().hostedUniverseBuilt;
62+
}
63+
}

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/c/CGlobalDataNonConstantRegistry.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,16 @@
2424
*/
2525
package com.oracle.svm.core.c;
2626

27-
import com.oracle.svm.core.graal.code.CGlobalDataInfo;
27+
import java.util.concurrent.locks.Lock;
28+
import java.util.concurrent.locks.ReentrantLock;
29+
2830
import org.graalvm.collections.EconomicMap;
2931
import org.graalvm.collections.Equivalence;
3032
import org.graalvm.nativeimage.Platform;
3133
import org.graalvm.nativeimage.Platforms;
3234

33-
import java.util.concurrent.locks.Lock;
34-
import java.util.concurrent.locks.ReentrantLock;
35+
import com.oracle.svm.core.graal.code.CGlobalDataInfo;
36+
import com.oracle.svm.core.util.ImageHeapMap;
3537

3638
/*
3739
* The following class is a helper registry, that contains only CGlobalDataInfo for
@@ -40,11 +42,14 @@
4042
*/
4143
public class CGlobalDataNonConstantRegistry {
4244

43-
private final EconomicMap<CGlobalDataImpl<?>, CGlobalDataInfo> cGlobalDataInfos = EconomicMap.create(Equivalence.IDENTITY);
45+
private final EconomicMap<CGlobalDataImpl<?>, CGlobalDataInfo> cGlobalDataInfos = ImageHeapMap.create(Equivalence.IDENTITY);
4446

4547
@Platforms(Platform.HOSTED_ONLY.class) //
4648
private final Lock lock = new ReentrantLock();
4749

50+
/**
51+
* Invoked at runtime via com.oracle.svm.hosted.c.CGlobalDataFeature#getCGlobalDataInfoMethod.
52+
*/
4853
public CGlobalDataInfo getCGlobalDataInfo(CGlobalDataImpl<?> cGlobalData) {
4954
return cGlobalDataInfos.get(cGlobalData);
5055
}

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

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,13 @@
2929

3030
import org.graalvm.collections.EconomicMap;
3131
import org.graalvm.collections.EconomicMapWrap;
32+
import org.graalvm.collections.Equivalence;
3233
import org.graalvm.collections.MapCursor;
3334
import org.graalvm.nativeimage.Platform;
3435
import org.graalvm.nativeimage.Platforms;
3536
import org.graalvm.nativeimage.hosted.Feature;
3637

38+
import com.oracle.svm.core.BuildPhaseProvider;
3739
import com.oracle.svm.core.annotate.AutomaticFeature;
3840

3941
/**
@@ -60,7 +62,14 @@ private ImageHeapMap() {
6062
*/
6163
@Platforms(Platform.HOSTED_ONLY.class) //
6264
public static <K, V> EconomicMap<K, V> create() {
63-
return new HostedImageHeapMap<>();
65+
VMError.guarantee(!BuildPhaseProvider.isAnalysisFinished(), "Trying to create an ImageHeapMap after analysis.");
66+
return new HostedImageHeapMap<>(Equivalence.DEFAULT);
67+
}
68+
69+
@Platforms(Platform.HOSTED_ONLY.class) //
70+
public static <K, V> EconomicMap<K, V> create(Equivalence strategy) {
71+
VMError.guarantee(!BuildPhaseProvider.isAnalysisFinished(), "Trying to create an ImageHeapMap after analysis.");
72+
return new HostedImageHeapMap<>(strategy);
6473
}
6574
}
6675

@@ -69,17 +78,15 @@ final class HostedImageHeapMap<K, V> extends EconomicMapWrap<K, V> {
6978

7079
final EconomicMap<Object, Object> runtimeMap;
7180

72-
HostedImageHeapMap() {
81+
HostedImageHeapMap(Equivalence strategy) {
7382
super(new ConcurrentHashMap<>());
74-
this.runtimeMap = EconomicMap.create();
83+
this.runtimeMap = EconomicMap.create(strategy);
7584
}
7685
}
7786

7887
@AutomaticFeature
7988
final class ImageHeapMapFeature implements Feature {
8089

81-
private boolean afterAnalysis;
82-
8390
private final Set<HostedImageHeapMap<?, ?>> allInstances = ConcurrentHashMap.newKeySet();
8491

8592
@Override
@@ -90,7 +97,7 @@ public void duringSetup(DuringSetupAccess config) {
9097
private Object imageHeapMapTransformer(Object obj) {
9198
if (obj instanceof HostedImageHeapMap) {
9299
HostedImageHeapMap<?, ?> hostedImageHeapMap = (HostedImageHeapMap<?, ?>) obj;
93-
if (afterAnalysis) {
100+
if (BuildPhaseProvider.isAnalysisFinished()) {
94101
VMError.guarantee(allInstances.contains(hostedImageHeapMap), "ImageHeapMap reachable after analysis that was not seen during analysis");
95102
} else {
96103
allInstances.add(hostedImageHeapMap);
@@ -110,11 +117,6 @@ public void duringAnalysis(DuringAnalysisAccess access) {
110117
}
111118
}
112119

113-
@Override
114-
public void afterAnalysis(AfterAnalysisAccess access) {
115-
afterAnalysis = true;
116-
}
117-
118120
@Override
119121
public void afterImageWrite(AfterImageWriteAccess access) {
120122
for (HostedImageHeapMap<?, ?> hostedImageHeapMap : allInstances) {

0 commit comments

Comments
 (0)