Skip to content

Commit c03caa1

Browse files
committed
Fix test issues and rename to HeterCont
1 parent 5499d74 commit c03caa1

File tree

5 files changed

+26
-28
lines changed

5 files changed

+26
-28
lines changed

src/java.base/share/classes/jdk/internal/access/StableComponentContainer.java renamed to src/java.base/share/classes/jdk/internal/access/HeterogeneousContainer.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package jdk.internal.access;
22

3-
import java.util.Collection;
43
import java.util.Objects;
54
import java.util.Set;
65
import java.util.function.Function;
@@ -20,15 +19,15 @@
2019
* @param <T> The common type of the components. The type can be {@linkplain Object} if
2120
* there is no common super type for the components.
2221
*/
23-
public sealed interface StableComponentContainer<T> permits StableComponentContainerImpl {
22+
public sealed interface HeterogeneousContainer<T> permits HeterogeneousContainerImpl {
2423

2524
/**
2625
* {@return the associated component for the provided {@code type}}
2726
*
2827
* @param type to use as lookup
2928
* @param <C> component type
3029
* @throws IllegalArgumentException if the provided {@code type} was not specified
31-
* {@linkplain StableComponentContainer#of(Set) at construction}.
30+
* {@linkplain HeterogeneousContainer#of(Set) at construction}.
3231
*/
3332
<C extends T> C get(Class<C> type);
3433

@@ -41,7 +40,7 @@ public sealed interface StableComponentContainer<T> permits StableComponentConta
4140
* (nullable)
4241
* @param <C> component type
4342
* @throws IllegalArgumentException if the provided {@code type} was not specified
44-
* {@linkplain StableComponentContainer#of(Set) at construction}.
43+
* {@linkplain HeterogeneousContainer#of(Set) at construction}.
4544
*/
4645
<C extends T> C orElse(Class<C> type, C other);
4746

@@ -51,7 +50,7 @@ public sealed interface StableComponentContainer<T> permits StableComponentConta
5150
*
5251
* @param type to use as lookup
5352
* @throws IllegalArgumentException if the provided {@code type} was not specified
54-
* {@linkplain StableComponentContainer#of(Set) at construction}.
53+
* {@linkplain HeterogeneousContainer#of(Set) at construction}.
5554
*/
5655
boolean isInitialized(Class<? extends T> type);
5756

@@ -60,7 +59,7 @@ public sealed interface StableComponentContainer<T> permits StableComponentConta
6059
*
6160
* @param type to use as lookup
6261
* @throws IllegalArgumentException if the provided {@code type} was not specified
63-
* {@linkplain StableComponentContainer#of(Set) at construction}.
62+
* {@linkplain HeterogeneousContainer#of(Set) at construction}.
6463
* @throws IllegalStateException if the provided {@code type} was already associated
6564
* with a component
6665
*/
@@ -101,7 +100,7 @@ public sealed interface StableComponentContainer<T> permits StableComponentConta
101100
* @return the current (existing or computed) component associated with
102101
* the specified type
103102
* @throws IllegalArgumentException if the provided {@code type} was not specified
104-
* {@linkplain StableComponentContainer#of(Set) at construction}.
103+
* {@linkplain HeterogeneousContainer#of(Set) at construction}.
105104
*/
106105
<C extends T> C computeIfAbsent(Class<C> type,
107106
Function<Class<C>, ? extends C> mappingFunction);
@@ -114,15 +113,15 @@ <C extends T> C computeIfAbsent(Class<C> type,
114113
* @param <T> the common type of the components. The type can be {@linkplain Object}
115114
* if there is no common super type for the components.
116115
*/
117-
static <T> StableComponentContainer<T> of(Set<Class<? extends T>> types) {
116+
static <T> HeterogeneousContainer<T> of(Set<Class<? extends T>> types) {
118117
// TOC TOU protection and
119118
// implicit null check of `types` and explicit null check on all its elements
120119
final Object[] inputs = new Object[types.size()];
121120
int idx = 0;
122121
for (Object type : types) {
123122
inputs[idx++] = Objects.requireNonNull(type);
124123
}
125-
return StableComponentContainerImpl.of(inputs);
124+
return HeterogeneousContainerImpl.of(inputs);
126125
}
127126

128127
/**
@@ -134,7 +133,7 @@ static <T> StableComponentContainer<T> of(Set<Class<? extends T>> types) {
134133
* @param <T> the common type of the components. The type can be {@linkplain Object}
135134
* if there is no common super type for the components.
136135
*/
137-
static <T> StableComponentContainer<T> of(Class<T> type) {
136+
static <T> HeterogeneousContainer<T> of(Class<T> type) {
138137
// Implicit null check
139138
if (!type.isSealed()) {
140139
throw new IllegalArgumentException("The provided type must be sealed: " + type);

src/java.base/share/classes/jdk/internal/access/StableComponentContainerImpl.java renamed to src/java.base/share/classes/jdk/internal/access/HeterogeneousContainerImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import java.util.function.Function;
1111

1212
@AOTSafeClassInitializer
13-
record StableComponentContainerImpl<T>(@Stable Object[] table) implements StableComponentContainer<T> {
13+
record HeterogeneousContainerImpl<T>(@Stable Object[] table) implements HeterogeneousContainer<T> {
1414

1515
private static final Unsafe UNSAFE = Unsafe.getUnsafe();
1616

@@ -127,7 +127,7 @@ private static int availableIndex(int probe) {
127127
return -probe - 1;
128128
}
129129

130-
static <T> StableComponentContainer<T> of(Object[] inputs) {
130+
static <T> HeterogeneousContainer<T> of(Object[] inputs) {
131131
// Prepopulate all the keys upfront
132132
final Object[] table = new Object[inputs.length << 2];
133133
for (Object type : inputs) {
@@ -136,7 +136,7 @@ static <T> StableComponentContainer<T> of(Object[] inputs) {
136136
final int keyIndex = availableIndex(probe);
137137
table[keyIndex] = type;
138138
}
139-
return new StableComponentContainerImpl<>(table);
139+
return new HeterogeneousContainerImpl<>(table);
140140
}
141141

142142
}

src/java.base/share/classes/jdk/internal/access/SharedSecrets.java

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,13 @@
2525

2626
package jdk.internal.access;
2727

28-
import jdk.internal.vm.annotation.AOTSafeClassInitializer;
2928
import jdk.internal.vm.annotation.DontInline;
3029
import jdk.internal.vm.annotation.ForceInline;
3130
import jdk.internal.vm.annotation.Stable;
3231

3332
import javax.crypto.SealedObject;
3433
import javax.crypto.spec.SecretKeySpec;
3534
import java.io.ObjectInputFilter;
36-
import java.lang.constant.Constable;
3735
import java.lang.invoke.MethodHandles;
3836
import java.lang.module.ModuleDescriptor;
3937
import java.net.HttpCookie;
@@ -84,24 +82,24 @@ interface and provides the ability to call package-private methods
8482
* code that would lead to the initialization of such fields, or else the AOT
8583
* cache creation will fail.
8684
*/
87-
@AOTSafeClassInitializer
8885
public final class SharedSecrets {
8986
private SharedSecrets() { }
9087

9188
// Todo: Remove this field.
9289
@Stable private static JavaLangAccess javaLangAccess;
9390

94-
// Sentinel value signaling that no explicit class initialization should be performed
95-
private static final String NO_INIT = "";
91+
// Sentinel value signaling that no explicit class initialization should be performed.
92+
// Must not be of type Class or String.
93+
private static final Object NO_INIT = new Object();
9694

9795
// This map is used to associate a certain Access interface to another class where
9896
// the implementation of said interface resides
99-
private static final Map<Class<? extends Access>, Constable> IMPLEMENTATIONS = implementations();
97+
private static final Map<Class<? extends Access>, Object> IMPLEMENTATIONS = implementations();
10098

10199
// In order to avoid creating a circular dependency graph, we refrain from using
102100
// ImmutableCollections. This means we have to resort to mutating a map.
103-
private static Map<Class<? extends Access>, Constable> implementations() {
104-
final Map<Class<? extends Access>, Constable> map = new HashMap<>();
101+
private static Map<Class<? extends Access>, Object> implementations() {
102+
final Map<Class<? extends Access>, Object> map = new HashMap<>();
105103

106104
map.put(JavaAWTFontAccess.class, NO_INIT);
107105
map.put(JavaBeansAccess.class, NO_INIT);
@@ -138,8 +136,8 @@ private static Map<Class<? extends Access>, Constable> implementations() {
138136
return Collections.unmodifiableMap(map);
139137
}
140138

141-
private static final StableComponentContainer<Access> COMPONENTS =
142-
StableComponentContainer.of(IMPLEMENTATIONS.keySet());
139+
private static final HeterogeneousContainer<Access> COMPONENTS =
140+
HeterogeneousContainer.of(IMPLEMENTATIONS.keySet());
143141

144142
@ForceInline
145143
public static <T extends Access> T get(Class<T> clazz) {
@@ -151,16 +149,17 @@ public static <T extends Access> T get(Class<T> clazz) {
151149

152150
@DontInline
153151
private static <T extends Access> T getSlowPath(Class<T> clazz) {
154-
final Constable implementation = IMPLEMENTATIONS.get(clazz);
152+
final Object implementation = IMPLEMENTATIONS.get(clazz);
155153
// We can't use pattern matching here as that would trigger
156154
// classfile initialization
157155
if (implementation instanceof Class<?> c) {
158156
ensureClassInitialized(c);
159-
} else if (implementation instanceof String s && !s.equals(NO_INIT)) {
157+
} else if (implementation instanceof String s) {
160158
ensureClassInitialized(s);
161159
} else {
162-
throw new InternalError("Should not reach here: " + implementation);
160+
throw new InternalError("Should not reach here: " + clazz + " -> " + implementation);
163161
}
162+
164163
// The component should now be initialized
165164
return COMPONENTS.get(clazz);
166165
}

test/jdk/java/io/Serializable/serialFilter/CheckArrayTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public void subclassedOIS(String pattern, int arraySize, Object[] array) throws
9797
// Check the arraysize against the filter
9898
ObjectInputFilter filter = ObjectInputFilter.Config.createFilter(pattern);
9999
ois.setObjectInputFilter(filter);
100-
SharedSecrets.getJavaObjectInputStreamAccess()
100+
SharedSecrets.get(JavaObjectInputStreamAccess.class)
101101
.checkArray(ois, array.getClass(), arraySize);
102102
Assert.assertTrue(array.length >= arraySize,
103103
"Should have thrown InvalidClassException due to array size");

test/jdk/java/net/InetAddress/getOriginalHostName.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
public class getOriginalHostName {
3737

3838
private static final JavaNetInetAddressAccess jna =
39-
SharedSecrets.getJavaNetInetAddressAccess();
39+
SharedSecrets.get(JavaNetInetAddressAccess.class);
4040

4141
public static void main(String[] args) throws Exception {
4242
final String HOST = "dummyserver.java.net";

0 commit comments

Comments
 (0)