Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit dfacd3f

Browse files
authored
simplify scala.runtime.Statics.releaseFence (#23953)
2 parents b0595c7 + d8652dd commit dfacd3f

File tree

1 file changed

+1
-45
lines changed

1 file changed

+1
-45
lines changed

‎library/src/scala/runtime/Statics.java‎

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@
1212

1313
package scala.runtime;
1414

15-
import java.lang.invoke.MethodHandle;
16-
import java.lang.invoke.MethodHandles;
17-
import java.lang.invoke.MethodType;
18-
import java.lang.reflect.Field;
19-
2015
/** Not for public consumption. Usage by the runtime only.
2116
*/
2217

@@ -145,46 +140,7 @@ private static int anyHashNumber(Number x) {
145140

146141
// @ForceInline would be nice here.
147142
public static void releaseFence() throws Throwable {
148-
VM.RELEASE_FENCE.invoke();
149-
}
150-
151-
final static class VM {
152-
static final MethodHandle RELEASE_FENCE;
153-
154-
static {
155-
RELEASE_FENCE = mkHandle();
156-
}
157-
158-
private static MethodHandle mkHandle() {
159-
MethodHandles.Lookup lookup = MethodHandles.lookup();
160-
try {
161-
return lookup.findStatic(Class.forName("java.lang.invoke.VarHandle"), "releaseFence", MethodType.methodType(Void.TYPE));
162-
} catch (NoSuchMethodException | ClassNotFoundException e) {
163-
try {
164-
Class<?> unsafeClass = Class.forName("sun.misc.Unsafe");
165-
return lookup.findVirtual(unsafeClass, "storeFence", MethodType.methodType(void.class)).bindTo(findUnsafe(unsafeClass));
166-
} catch (NoSuchMethodException | ClassNotFoundException | IllegalAccessException e1) {
167-
ExceptionInInitializerError error = new ExceptionInInitializerError(e1);
168-
error.addSuppressed(e);
169-
throw error;
170-
}
171-
} catch (IllegalAccessException e) {
172-
throw new ExceptionInInitializerError(e);
173-
}
174-
}
175-
176-
private static Object findUnsafe(Class<?> unsafeClass) throws IllegalAccessException {
177-
Object found = null;
178-
for (Field field : unsafeClass.getDeclaredFields()) {
179-
if (field.getType() == unsafeClass) {
180-
field.setAccessible(true);
181-
found = field.get(null);
182-
break;
183-
}
184-
}
185-
if (found == null) throw new IllegalStateException("No instance of Unsafe found");
186-
return found;
187-
}
143+
java.lang.invoke.VarHandle.releaseFence();
188144
}
189145

190146
/**

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /