Skip to content

Commit ef48551

Browse files
committed
[GR-51935] Feature Cleanup Part 2.
PullRequest: graal/16903
2 parents 458e164 + d5f7c92 commit ef48551

File tree

13 files changed

+358
-354
lines changed

13 files changed

+358
-354
lines changed

sdk/src/com.oracle.svm.core.annotate/src/com/oracle/svm/core/annotate/RecomputeFieldValue.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2010, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2010, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -212,11 +212,4 @@ enum Kind {
212212
* @since 22.3
213213
*/
214214
boolean isFinal() default false;
215-
216-
/**
217-
* If true, ignores previously computed values and calculates the value for every field read.
218-
*
219-
* @since 22.3
220-
*/
221-
boolean disableCaching() default false;
222215
}

substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/typestate/TypeState.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ public static TypeState forConstant(PointsToAnalysis bb, JavaConstant constant,
165165
}
166166

167167
public static SingleTypeState forExactType(PointsToAnalysis bb, AnalysisType exactType, boolean canBeNull) {
168+
assert exactType.getContextInsensitiveAnalysisObject() != null : exactType;
168169
return forExactType(bb, exactType.getContextInsensitiveAnalysisObject(), canBeNull);
169170
}
170171

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

Lines changed: 0 additions & 41 deletions
This file was deleted.

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

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@
6464
import com.oracle.svm.core.util.VMError;
6565
import com.oracle.svm.util.ReflectionUtil;
6666

67-
import sun.security.jca.ProviderList;
6867
import sun.security.util.SecurityConstants;
6968

7069
/*
@@ -290,7 +289,6 @@ final class Target_javax_crypto_JceSecurity {
290289
// value == PROVIDER_VERIFIED is successfully verified
291290
// value is failure cause Exception in error case
292291
@Alias //
293-
@RecomputeFieldValue(kind = RecomputeFieldValue.Kind.Custom, declClass = VerificationCacheTransformer.class, disableCaching = true) //
294292
private static Map<Object, Object> verificationResults;
295293

296294
@Alias //
@@ -334,13 +332,6 @@ static Exception getVerificationResult(Provider p) {
334332
throw VMError.unsupportedFeature("Trying to verify a provider that was not registered at build time: " + p + ". " +
335333
"All providers must be registered and verified in the Native Image builder. ");
336334
}
337-
338-
private static class VerificationCacheTransformer implements FieldValueTransformer {
339-
@Override
340-
public Object transform(Object receiver, Object originalValue) {
341-
return SecurityProvidersFilter.instance().cleanVerificationCache(originalValue);
342-
}
343-
}
344335
}
345336

346337
@TargetClass(className = "javax.crypto.JceSecurity", innerClass = "WeakIdentityWrapper")
@@ -549,21 +540,6 @@ final class Target_sun_security_jca_ProviderConfig_ProviderLoader {
549540
static Target_sun_security_jca_ProviderConfig_ProviderLoader INSTANCE;
550541
}
551542

552-
@TargetClass(className = "sun.security.jca.Providers")
553-
final class Target_sun_security_jca_Providers {
554-
@Alias//
555-
@RecomputeFieldValue(kind = RecomputeFieldValue.Kind.Custom, declClass = ProviderListTransformer.class, disableCaching = true)//
556-
private static ProviderList providerList;
557-
558-
private static class ProviderListTransformer implements FieldValueTransformer {
559-
@Override
560-
public Object transform(Object receiver, Object originalValue) {
561-
ProviderList originalProviderList = (ProviderList) originalValue;
562-
return SecurityProvidersFilter.instance().cleanUnregisteredProviders(originalProviderList);
563-
}
564-
}
565-
}
566-
567543
/** Dummy class to have a class with the file's name. */
568544
public final class SecuritySubstitutions {
569545
}

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/JavaLangThreadGroupSubstitutions.java

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,6 @@ final class Target_java_lang_ThreadGroup {
5151
@RecomputeFieldValue(kind = RecomputeFieldValue.Kind.Custom, declClass = ThreadGroupThreadsRecomputation.class)//
5252
Thread[] injectedThreads;
5353

54-
/*
55-
* JavaThreadsFeature.reachableThreadGroups is updated in an object replacer, during analysis,
56-
* thus the recomputation may see an incomplete value. By disabling caching eventually the
57-
* recomputed value will be the correct one. No additional caching is necessary since
58-
* reachableThreadGroups will eventually reach a stable value during analysis and there is no
59-
* risk to discover new objects in later phases.
60-
*/
61-
@Alias @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.Custom, declClass = ThreadGroupNGroupsRecomputation.class, disableCaching = true)//
62-
private int ngroups;
63-
@Alias @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.Custom, declClass = ThreadGroupGroupsRecomputation.class, disableCaching = true)//
64-
private ThreadGroup[] groups;
65-
6654
/*
6755
* All ThreadGroups in the image heap are strong and will be stored in ThreadGroup.groups.
6856
*/
@@ -146,38 +134,6 @@ public Object transform(Object receiver, Object originalValue) {
146134
}
147135
}
148136

149-
@Platforms(Platform.HOSTED_ONLY.class)
150-
class ThreadGroupNUnstartedThreadsRecomputation implements FieldValueTransformer {
151-
@Override
152-
public Object transform(Object receiver, Object originalValue) {
153-
ThreadGroup group = (ThreadGroup) receiver;
154-
int result = 0;
155-
for (Thread thread : JavaThreadsFeature.singleton().reachableThreads.keySet()) {
156-
/* The main thread is recomputed as running and therefore not counted as unstarted. */
157-
if (thread.getThreadGroup() == group && thread != PlatformThreads.singleton().mainThread) {
158-
result++;
159-
}
160-
}
161-
return result;
162-
}
163-
}
164-
165-
@Platforms(Platform.HOSTED_ONLY.class)
166-
class ThreadGroupNThreadsRecomputation implements FieldValueTransformer {
167-
@Override
168-
public Object transform(Object receiver, Object originalValue) {
169-
ThreadGroup group = (ThreadGroup) receiver;
170-
171-
if (group == PlatformThreads.singleton().mainGroup) {
172-
/* The main group contains the main thread, which we recompute as running. */
173-
return 1;
174-
} else {
175-
/* No other thread group has a thread running at startup. */
176-
return 0;
177-
}
178-
}
179-
}
180-
181137
@Platforms(Platform.HOSTED_ONLY.class)
182138
class ThreadGroupThreadsRecomputation implements FieldValueTransformer {
183139
@Override
@@ -194,24 +150,6 @@ public Object transform(Object receiver, Object originalValue) {
194150
}
195151
}
196152

197-
@Platforms(Platform.HOSTED_ONLY.class)
198-
class ThreadGroupNGroupsRecomputation implements FieldValueTransformer {
199-
@Override
200-
public Object transform(Object receiver, Object originalValue) {
201-
ThreadGroup group = (ThreadGroup) receiver;
202-
return JavaThreadsFeature.singleton().reachableThreadGroups.get(group).ngroups;
203-
}
204-
}
205-
206-
@Platforms(Platform.HOSTED_ONLY.class)
207-
class ThreadGroupGroupsRecomputation implements FieldValueTransformer {
208-
@Override
209-
public Object transform(Object receiver, Object originalValue) {
210-
ThreadGroup group = (ThreadGroup) receiver;
211-
return JavaThreadsFeature.singleton().reachableThreadGroups.get(group).groups;
212-
}
213-
}
214-
215153
final class ThreadGroupThreadsAccessor {
216154
static Thread[] get(Target_java_lang_ThreadGroup that) {
217155
return that.injectedThreads;

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/JavaThreadsFeature.java

Lines changed: 6 additions & 141 deletions
Original file line numberDiff line numberDiff line change
@@ -24,157 +24,22 @@
2424
*/
2525
package com.oracle.svm.core.thread;
2626

27-
import java.util.Arrays;
28-
import java.util.Map;
29-
30-
import org.graalvm.nativeimage.ImageSingletons;
31-
import org.graalvm.nativeimage.Platform;
32-
import org.graalvm.nativeimage.Platforms;
33-
import org.graalvm.nativeimage.hosted.RuntimeClassInitialization;
34-
35-
import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature;
3627
import com.oracle.svm.core.feature.InternalFeature;
37-
import com.oracle.svm.core.util.ConcurrentIdentityHashMap;
38-
import com.oracle.svm.core.util.UserError;
39-
import com.oracle.svm.util.ClassUtil;
40-
41-
@AutomaticallyRegisteredFeature
42-
@Platforms(Platform.HOSTED_ONLY.class)
43-
class JavaThreadsFeature implements InternalFeature {
44-
45-
static JavaThreadsFeature singleton() {
46-
return ImageSingletons.lookup(JavaThreadsFeature.class);
47-
}
48-
49-
/**
50-
* All {@link Thread} objects that are reachable in the image heap. Only unstarted threads,
51-
* i.e., threads in state NEW, are allowed.
52-
*/
53-
final Map<Thread, Boolean> reachableThreads = new ConcurrentIdentityHashMap<>();
54-
/**
55-
* All {@link ThreadGroup} objects that are reachable in the image heap. The value of the map is
56-
* a helper object storing information that is used by the field value recomputations.
57-
*/
58-
final Map<ThreadGroup, ReachableThreadGroup> reachableThreadGroups = new ConcurrentIdentityHashMap<>();
59-
/** No new threads and thread groups can be discovered after the static analysis. */
60-
private boolean sealed;
61-
62-
@Override
63-
public void duringSetup(DuringSetupAccess access) {
64-
access.registerObjectReplacer(this::collectReachableObjects);
65-
66-
/*
67-
* This currently only means that we don't support setting custom values for
68-
* java.lang.ScopedValue.cacheSize at runtime.
69-
*/
70-
RuntimeClassInitialization.initializeAtBuildTime("java.lang.ScopedValue");
71-
RuntimeClassInitialization.initializeAtBuildTime("java.lang.ScopedValue$Cache");
72-
}
73-
74-
private Object collectReachableObjects(Object original) {
75-
if (original instanceof Thread) {
76-
Thread thread = (Thread) original;
77-
if (thread.getState() == Thread.State.NEW) {
78-
registerReachableObject(reachableThreads, thread, Boolean.TRUE);
79-
} else {
80-
/*
81-
* Started Threads must not be in the image heap. The error is reported in
82-
* DisallowedImageHeapObjectFeature (which is in a hosted project).
83-
*/
84-
}
85-
86-
} else if (original instanceof ThreadGroup) {
87-
ThreadGroup group = (ThreadGroup) original;
88-
if (registerReachableObject(reachableThreadGroups, group, new ReachableThreadGroup())) {
89-
ThreadGroup parent = group.getParent();
90-
if (parent != null) {
91-
/* Ensure ReachableThreadGroup object for parent is created. */
92-
collectReachableObjects(parent);
93-
/*
94-
* Build the tree of thread groups that is then written out in the image heap.
95-
* This tree is a subtree of all thread groups in the image generator,
96-
* containing only the thread groups that were found as reachable at run time.
97-
*/
98-
reachableThreadGroups.get(parent).add(group);
99-
} else {
100-
assert group == PlatformThreads.singleton().systemGroup;
101-
}
102-
}
103-
}
104-
return original;
105-
}
106-
107-
private <K, V> boolean registerReachableObject(Map<K, V> map, K object, V value) {
108-
boolean result = map.putIfAbsent(object, value) == null;
109-
if (sealed && result) {
110-
throw UserError.abort("%s is reachable in the image heap but was not seen during the points-to analysis: %s", ClassUtil.getUnqualifiedName(object.getClass()), object);
111-
}
112-
return result;
113-
}
114-
115-
@Override
116-
public void afterAnalysis(AfterAnalysisAccess access) {
117-
/*
118-
* No more changes to the reachable threads and thread groups are allowed after the
119-
* analysis.
120-
*/
121-
sealed = true;
12228

123-
/*
124-
* Compute the maximum thread id and autonumber sequence from all reachable threads, and use
125-
* these numbers as the initial values at run time. This still means that numbers are not
126-
* dense when threads other than the main thread are reachable. However, changing the thread
127-
* id or autonumber of a thread that the user created during image generation would be an
128-
* intrusion with unpredictable side effects.
129-
*/
130-
long maxThreadId = 0;
131-
int maxAutonumber = -1;
132-
for (Thread thread : reachableThreads.keySet()) {
133-
maxThreadId = Math.max(maxThreadId, threadId(thread));
134-
maxAutonumber = Math.max(maxAutonumber, autonumberOf(thread));
135-
}
136-
assert maxThreadId >= 1 : "main thread with id 1 must always be found";
137-
JavaThreads.threadSeqNumber.set(maxThreadId);
138-
JavaThreads.threadInitNumber.set(maxAutonumber);
139-
}
29+
public abstract class JavaThreadsFeature implements InternalFeature {
14030

141-
static long threadId(Thread thread) {
31+
protected static long threadId(Thread thread) {
14232
if (thread == PlatformThreads.singleton().mainThread) {
14333
return 1;
14434
}
14535
return JavaThreads.getThreadId(thread);
14636
}
14737

148-
private static final String AUTONUMBER_PREFIX = "Thread-";
149-
150-
static int autonumberOf(Thread thread) {
151-
if (thread.getName().startsWith(AUTONUMBER_PREFIX)) {
152-
try {
153-
return Integer.parseInt(thread.getName().substring(AUTONUMBER_PREFIX.length()));
154-
} catch (NumberFormatException ex) {
155-
/*
156-
* Ignore. If the suffix is not a valid integer number, then the thread name is not
157-
* an autonumber name.
158-
*/
159-
}
160-
}
161-
return -1;
38+
protected static void setThreadSeqNumber(long num) {
39+
JavaThreads.threadSeqNumber.set(num);
16240
}
163-
}
164-
165-
@Platforms(Platform.HOSTED_ONLY.class)
166-
class ReachableThreadGroup {
167-
int ngroups;
168-
ThreadGroup[] groups;
16941

170-
/* Copy of ThreadGroup.add(). */
171-
synchronized void add(ThreadGroup g) {
172-
if (groups == null) {
173-
groups = new ThreadGroup[4];
174-
} else if (ngroups == groups.length) {
175-
groups = Arrays.copyOf(groups, ngroups * 2);
176-
}
177-
groups[ngroups] = g;
178-
ngroups++;
42+
protected static void setThreadInitNumber(int num) {
43+
JavaThreads.threadInitNumber.set(num);
17944
}
18045
}

substratevm/src/com.oracle.svm.graal/src/com/oracle/svm/graal/isolated/IsolateAwareObjectConstantEqualityFeature.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,12 @@
2828
import org.graalvm.nativeimage.c.function.CEntryPoint;
2929

3030
import com.oracle.svm.core.SubstrateOptions;
31+
import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature;
3132
import com.oracle.svm.core.feature.InternalFeature;
33+
import com.oracle.svm.core.graal.RuntimeCompilation;
3234
import com.oracle.svm.core.meta.DirectSubstrateObjectConstant;
3335
import com.oracle.svm.core.meta.ObjectConstantEquality;
3436
import com.oracle.svm.core.meta.SubstrateObjectConstant;
35-
import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature;
3637
import com.oracle.svm.core.util.VMError;
3738

3839
import jdk.vm.ci.meta.Constant;
@@ -84,6 +85,8 @@ public boolean isInConfiguration(IsInConfigurationAccess access) {
8485

8586
@Override
8687
public void afterRegistration(AfterRegistrationAccess access) {
87-
ImageSingletons.add(ObjectConstantEquality.class, new IsolateAwareObjectConstantEquality());
88+
if (RuntimeCompilation.isEnabled()) {
89+
ImageSingletons.add(ObjectConstantEquality.class, new IsolateAwareObjectConstantEquality());
90+
}
8891
}
8992
}

0 commit comments

Comments
 (0)