Skip to content

Commit

Permalink
Deprecate MemoryFence.
Browse files Browse the repository at this point in the history
  • Loading branch information
fniephaus committed Feb 15, 2022
1 parent fb8e726 commit 9de0d72
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 89 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2021, Oracle and/or its affiliates.
* Copyright (c) 2017, 2022, Oracle and/or its affiliates.
*
* All rights reserved.
*
Expand Down Expand Up @@ -29,14 +29,15 @@
*/
package com.oracle.truffle.llvm.runtime.nodes.memory;

import java.lang.invoke.VarHandle;

import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.memory.MemoryFence;
import com.oracle.truffle.llvm.runtime.nodes.api.LLVMStatementNode;

public abstract class LLVMFence extends LLVMStatementNode {

@Specialization
protected void doOp() {
MemoryFence.full();
VarHandle.fullFence();
}
}
1 change: 1 addition & 0 deletions truffle/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ This changelog summarizes major changes between Truffle versions relevant to lan
* Added `TruffleSafepoint.setAllowActions` to disable thread local actions temporarily for trusted internal guest code. Currently only allowed during the finalization of a context in `TruffleLanguage.finalizeContext(Object)`.
* Added `FrameDescriptor.getInfo()` and `FrameDescriptor.Builder.info()` to associate a user-defined object with a frame descriptor.
* GR-33851 Dropped Java 8 support.
* Deprecated `MemoryFence`. Please use `VarHandle` directly.

## Version 22.0.0
* Truffle DSL generated code now inherits all annotations on constructor parameters to the static create factory method.
Expand Down
4 changes: 2 additions & 2 deletions truffle/src/com.oracle.truffle.api.library/snapshot.sigtest
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ meth public final {com.oracle.truffle.api.library.LibraryFactory%0} getUncached(
meth public java.lang.String toString()
meth public static <%0 extends com.oracle.truffle.api.library.Library> com.oracle.truffle.api.library.LibraryFactory<{%%0}> resolve(java.lang.Class<{%%0}>)
supr java.lang.Object
hfds EMPTY_DEFAULT_EXPORT_ARRAY,LIBRARIES,UNSAFE,afterBuiltinDefaultExports,aot,beforeBuiltinDefaultExports,cachedCache,dispatchLibrary,eagerExportProviders,exportCache,externalDefaultProviders,libraryClass,messages,nameToMessages,proxyExports,uncachedCache,uncachedDispatch
hcls CachedAOTExports,ProxyExports,ResolvedDispatch
hfds EMPTY_DEFAULT_EXPORT_ARRAY,LIBRARIES,afterBuiltinDefaultExports,aot,beforeBuiltinDefaultExports,cachedCache,dispatchLibrary,eagerExportProviders,exportCache,externalDefaultProviders,libraryClass,messages,nameToMessages,proxyExports,uncachedCache,uncachedDispatch
hcls CachedAOTExports,Lazy,ProxyExports,ResolvedDispatch

CLSS public abstract com.oracle.truffle.api.library.Message
cons protected !varargs init(java.lang.Class<? extends com.oracle.truffle.api.library.Library>,java.lang.String,int,java.lang.Class<?>,java.lang.Class<?>[])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
/**
* Smoke test of the API methods.
*/
@SuppressWarnings("deprecation")
public class MemoryFenceTest {

@BeforeClass
Expand Down
3 changes: 2 additions & 1 deletion truffle/src/com.oracle.truffle.api/snapshot.sigtest
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ meth public static int indexOfWithOrMask(byte[],int,int,byte[],byte[])
meth public static int indexOfWithOrMask(char[],int,int,char[],char[])
meth public static int indexOfWithOrMask(java.lang.String,int,int,java.lang.String,java.lang.String)
supr java.lang.Object
hfds JAVA_SPEC,UNSAFE,javaStringCoderFieldOffset,javaStringValueFieldOffset
hfds UNSAFE,javaStringCoderFieldOffset,javaStringValueFieldOffset

CLSS public abstract interface com.oracle.truffle.api.Assumption
meth public abstract boolean isValid()
Expand Down Expand Up @@ -959,6 +959,7 @@ meth public static com.oracle.truffle.api.memory.ByteArraySupport littleEndian()
supr java.lang.Object

CLSS public final com.oracle.truffle.api.memory.MemoryFence
anno 0 java.lang.Deprecated(boolean forRemoval=true, java.lang.String since="22.1.0")
meth public static void acquire()
meth public static void full()
meth public static void loadLoad()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1161,26 +1161,6 @@ public boolean verifyModuleVisibility(Object lookupModule, Class<?> memberClass)
public boolean isNonTruffleClass(Class<?> clazz) {
return TruffleJDKServices.isNonTruffleClass(clazz);
}

public void fullFence() {
TruffleJDKServices.fullFence();
}

public void acquireFence() {
TruffleJDKServices.acquireFence();
}

public void releaseFence() {
TruffleJDKServices.releaseFence();
}

public void loadLoadFence() {
TruffleJDKServices.loadLoadFence();
}

public void storeStoreFence() {
TruffleJDKServices.storeStoreFence();
}
}

// A separate class to break the cycle such that Accessor can fully initialize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
*/
package com.oracle.truffle.api.impl;

import java.lang.invoke.VarHandle;
import java.util.Collections;
import java.util.List;
import java.util.ServiceLoader;
Expand Down Expand Up @@ -143,42 +142,4 @@ static boolean isNonTruffleClass(Class<?> clazz) {
ClassLoader classLoader = clazz.getClassLoader();
return truffleClassLoader != classLoader;
}

/**
* Ensures that loads and stores before the fence will not be reordered with loads and stores
* after the fence.
*/
static void fullFence() {
VarHandle.fullFence();
}

/**
* Ensures that loads before the fence will not be reordered with loads and stores after the
* fence.
*/
static void acquireFence() {
VarHandle.acquireFence();
}

/**
* Ensures that loads and stores before the fence will not be reordered with stores after the
* fence.
*/
static void releaseFence() {
VarHandle.releaseFence();
}

/**
* Ensures that loads before the fence will not be reordered with loads after the fence.
*/
static void loadLoadFence() {
VarHandle.loadLoadFence();
}

/**
* Ensures that stores before the fence will not be reordered with stores after the fence.
*/
static void storeStoreFence() {
VarHandle.storeStoreFence();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
Expand Down Expand Up @@ -40,7 +40,7 @@
*/
package com.oracle.truffle.api.memory;

import com.oracle.truffle.api.impl.Accessor;
import java.lang.invoke.VarHandle;

/**
* Provides memory fence methods for fine-grained control of memory ordering. Their semantics follow
Expand All @@ -49,7 +49,9 @@
* class from Java 9 and later.
*
* @since 21.2
* @deprecated Please use {@link VarHandle} directly.
*/
@Deprecated(since = "22.1.0", forRemoval = true)
public final class MemoryFence {

private MemoryFence() {
Expand All @@ -62,7 +64,7 @@ private MemoryFence() {
* @since 21.2
*/
public static void full() {
MemoryFenceAccessor.jdkServicesAccessor().fullFence();
VarHandle.fullFence();
}

/**
Expand All @@ -72,7 +74,7 @@ public static void full() {
* @since 21.2
*/
public static void acquire() {
MemoryFenceAccessor.jdkServicesAccessor().acquireFence();
VarHandle.acquireFence();
}

/**
Expand All @@ -82,7 +84,7 @@ public static void acquire() {
* @since 21.2
*/
public static void release() {
MemoryFenceAccessor.jdkServicesAccessor().releaseFence();
VarHandle.releaseFence();
}

/**
Expand All @@ -91,7 +93,7 @@ public static void release() {
* @since 21.2
*/
public static void loadLoad() {
MemoryFenceAccessor.jdkServicesAccessor().loadLoadFence();
VarHandle.loadLoadFence();
}

/**
Expand All @@ -100,18 +102,6 @@ public static void loadLoad() {
* @since 21.2
*/
public static void storeStore() {
MemoryFenceAccessor.jdkServicesAccessor().storeStoreFence();
}
}

final class MemoryFenceAccessor extends Accessor {

private static final MemoryFenceAccessor ACCESSOR = new MemoryFenceAccessor();

private MemoryFenceAccessor() {
}

static JDKSupport jdkServicesAccessor() {
return ACCESSOR.jdkSupport();
VarHandle.storeStoreFence();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ public class TruffleTypes {
public static final String UnexpectedResultException_Name = "com.oracle.truffle.api.nodes.UnexpectedResultException";
public static final String VirtualFrame_Name = "com.oracle.truffle.api.frame.VirtualFrame";
public static final String HostLanguage_Name = "com.oracle.truffle.polyglot.HostLanguage";
public static final String MemoryFence_Name = "com.oracle.truffle.api.memory.MemoryFence";

public final DeclaredType Assumption = c.getDeclaredType(Assumption_Name);
public final DeclaredType CompilerAsserts = c.getDeclaredType(CompilerAsserts_Name);
Expand Down Expand Up @@ -137,7 +136,6 @@ public class TruffleTypes {
public final DeclaredType UnexpectedResultException = c.getDeclaredType(UnexpectedResultException_Name);
public final DeclaredType VirtualFrame = c.getDeclaredType(VirtualFrame_Name);
public final DeclaredType HostLanguage = c.getDeclaredTypeOptional(HostLanguage_Name);
public final DeclaredType MemoryFence = c.getDeclaredTypeOptional(MemoryFence_Name);

// DSL API
public static final String Bind_Name = "com.oracle.truffle.api.dsl.Bind";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
import static javax.lang.model.element.Modifier.PUBLIC;
import static javax.lang.model.element.Modifier.STATIC;

import java.lang.invoke.VarHandle;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
Expand Down Expand Up @@ -4270,7 +4271,7 @@ private Collection<IfTriple> persistSpecializationClass(FrameState frameState, S
// here: we must ensure that the item that is being appended to the list is fully
// initialized.
builder.startStatement();
builder.startStaticCall(context.getTypes().MemoryFence, "storeStore");
builder.startStaticCall(context.getType(VarHandle.class), "storeStoreFence");
builder.end();
builder.end();
builder.startStatement();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@
*/
package com.oracle.truffle.object;

import java.lang.invoke.VarHandle;
import java.util.EnumSet;
import java.util.Map;
import java.util.Objects;

import com.oracle.truffle.api.Assumption;
import com.oracle.truffle.api.TruffleOptions;
import com.oracle.truffle.api.memory.MemoryFence;
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.object.Location;
import com.oracle.truffle.api.object.ObjectType;
Expand Down Expand Up @@ -174,7 +174,7 @@ protected Support() {

public final void setShapeWithStoreFence(DynamicObject object, Shape shape) {
if (shape.isShared()) {
MemoryFence.storeStore();
VarHandle.storeStoreFence();
}
super.setShape(object, shape);
}
Expand Down

0 comments on commit 9de0d72

Please sign in to comment.