Skip to content

Commit

Permalink
Refactor static fields unsafe access.
Browse files Browse the repository at this point in the history
  • Loading branch information
cstancu committed Jul 16, 2020
1 parent f46bc6d commit 46cd5c7
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ public FieldFilterTypeFlow filterFlow(BigBang bb) {

if (filterFlow == null) {
if (FILTER_FLOW_UPDATER.compareAndSet(this, null, new FieldFilterTypeFlow(source))) {
/*
* The newly installed FieldFilterTypeFlow can be used by other threads before
* addUse() is called / done. This is not a problem. The filterFlow stores its own
* state and after the use is actually linked the state, if any, is transfered to
* the use.
*/
filterFlow.addUse(bb, this);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,9 @@ public class AnalysisField implements ResolvedJavaField, OriginalFieldProvider {
private final AnalysisType declaringClass;
private final AnalysisType fieldType;

private final AnalysisUniverse universe;

public AnalysisField(AnalysisUniverse universe, ResolvedJavaField wrappedField) {
assert !wrappedField.isInternal();

this.universe = universe;
this.position = -1;
this.isUnsafeAccessed = new AtomicBoolean();
this.unsafeFrozenTypeState = new AtomicBoolean();
Expand Down Expand Up @@ -258,11 +255,11 @@ public void registerAsWritten(MethodTypeFlow method) {
}
}

public void registerAsUnsafeAccessed() {
registerAsUnsafeAccessed(DefaultUnsafePartition.get());
public void registerAsUnsafeAccessed(AnalysisUniverse universe) {
registerAsUnsafeAccessed(universe, DefaultUnsafePartition.get());
}

public void registerAsUnsafeAccessed(UnsafePartitionKind partitionKind) {
public void registerAsUnsafeAccessed(AnalysisUniverse universe, UnsafePartitionKind partitionKind) {

/*
* A field can potentially be registered as unsafe accessed multiple times. This is
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
import java.util.function.Predicate;
import java.util.stream.Collectors;

import com.oracle.svm.hosted.code.CompileQueue;
import org.graalvm.collections.Pair;
import org.graalvm.compiler.debug.DebugContext;
import org.graalvm.nativeimage.hosted.Feature;
Expand All @@ -71,6 +70,7 @@
import com.oracle.svm.hosted.c.NativeLibraries;
import com.oracle.svm.hosted.code.CEntryPointData;
import com.oracle.svm.hosted.code.CompilationInfoSupport;
import com.oracle.svm.hosted.code.CompileQueue;
import com.oracle.svm.hosted.code.SharedRuntimeConfigurationBuilder;
import com.oracle.svm.hosted.image.AbstractBootImage;
import com.oracle.svm.hosted.image.AbstractBootImage.NativeImageKind;
Expand Down Expand Up @@ -324,7 +324,7 @@ public boolean registerAsUnsafeAccessed(AnalysisField aField) {
if (!aField.isUnsafeAccessed()) {
/* Register the field as unsafe accessed. */
aField.registerAsAccessed();
aField.registerAsUnsafeAccessed();
aField.registerAsUnsafeAccessed(bb.getUniverse());
/* Force the update of registered unsafe loads and stores. */
bb.forceUnsafeUpdate(aField);
return true;
Expand All @@ -349,7 +349,7 @@ public void registerAsUnsafeAccessed(AnalysisField aField, UnsafePartitionKind p
if (!aField.isUnsafeAccessed()) {
/* Register the field as unsafe accessed. */
aField.registerAsAccessed();
aField.registerAsUnsafeAccessed(partitionKind);
aField.registerAsUnsafeAccessed(bb.getUniverse(), partitionKind);
/* Force the update of registered unsafe loads and stores. */
bb.forceUnsafeUpdate(aField);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,10 @@
import org.graalvm.word.PointerBase;
import org.graalvm.word.UnsignedWord;

import com.oracle.graal.pointsto.infrastructure.UniverseMetaAccess;
import com.oracle.graal.pointsto.meta.AnalysisField;
import com.oracle.graal.pointsto.meta.AnalysisType;
import com.oracle.graal.pointsto.meta.AnalysisUniverse;
import com.oracle.graal.pointsto.nodes.AnalysisArraysCopyOfNode;
import com.oracle.graal.pointsto.nodes.AnalysisUnsafePartitionLoadNode;
import com.oracle.graal.pointsto.nodes.AnalysisUnsafePartitionStoreNode;
Expand Down Expand Up @@ -461,9 +463,7 @@ private static void interceptUpdaterInvoke(MetaAccessProvider metaAccess, Snippe
RuntimeReflection.register(field);

// register the field for unsafe access
AnalysisField targetField = (AnalysisField) metaAccess.lookupJavaField(field);
targetField.registerAsAccessed();
targetField.registerAsUnsafeAccessed();
registerAsUnsafeAccessed(metaAccess, field);
} catch (NoSuchFieldException e) {
/*
* Ignore the exception. : If the field does not exist, there will be an error
Expand All @@ -477,6 +477,13 @@ private static void interceptUpdaterInvoke(MetaAccessProvider metaAccess, Snippe
}
}

private static void registerAsUnsafeAccessed(MetaAccessProvider metaAccess, Field field) {
AnalysisField targetField = (AnalysisField) metaAccess.lookupJavaField(field);
targetField.registerAsAccessed();
AnalysisUniverse universe = (AnalysisUniverse) ((UniverseMetaAccess) metaAccess).getUniverse();
targetField.registerAsUnsafeAccessed(universe);
}

private static void registerObjectPlugins(InvocationPlugins plugins) {
Registration r = new Registration(plugins, Object.class);
r.register1("clone", Receiver.class, new InvocationPlugin() {
Expand Down Expand Up @@ -584,9 +591,7 @@ private static boolean processObjectFieldOffset(GraphBuilderContext b, Field tar

if (analysis) {
/* Register the field for unsafe access. */
AnalysisField analysisTargetField = (AnalysisField) metaAccess.lookupJavaField(targetField);
analysisTargetField.registerAsAccessed();
analysisTargetField.registerAsUnsafeAccessed();
registerAsUnsafeAccessed(metaAccess, targetField);
/* Return false; the call is not replaced. */
return false;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public void processComputedValueFields(BigBang bb) {
case FieldOffset:
AnalysisField targetField = bb.getMetaAccess().lookupJavaField(cvField.getTargetField());
targetField.registerAsAccessed();
targetField.registerAsUnsafeAccessed();
targetField.registerAsUnsafeAccessed(bb.getUniverse());
break;
}
}
Expand Down

0 comments on commit 46cd5c7

Please sign in to comment.