Skip to content

Commit 5c4595d

Browse files
committed
Minor style/comments improvements
1 parent 957403d commit 5c4595d

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/BuiltinMethodDescriptor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ private static Builtin findBuiltinAnnotation(String name, NodeFactory<? extends
148148
// The builtin annotation allows us to differentiate between builtins shared for reversible
149149
// operations, such as int.__mul__ and int.__rmul__, which have the same node factory
150150
private final Builtin builtinAnnotation;
151-
// Name and isReverseOperation are shortcuts for builtinAnnotation.name()/reverseOperation()
151+
// Shortcuts for fields of builtinAnnotation that are accessed on a fast-path
152152
private final String name;
153153
private final boolean isReverseOperation;
154154
private final int minNumOfPositionalArgs;

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/PBuiltinFunction.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import com.oracle.truffle.api.interop.InteropLibrary;
5151
import com.oracle.truffle.api.library.ExportLibrary;
5252
import com.oracle.truffle.api.library.ExportMessage;
53+
import com.oracle.truffle.api.memory.MemoryFence;
5354
import com.oracle.truffle.api.nodes.RootNode;
5455
import com.oracle.truffle.api.object.Shape;
5556

@@ -230,10 +231,21 @@ String getExecutableName() {
230231
return getName();
231232
}
232233

233-
public void setDescriptor(BuiltinMethodDescriptor descriptor) {
234-
this.descriptor = descriptor;
234+
public void setDescriptor(BuiltinMethodDescriptor value) {
235+
assert value.getName().equals(getName()) && getBuiltinNodeFactory() == value.getFactory() : getName() + " vs " + value;
236+
// Only make sure that info is fully initialized, otherwise it is fine if it is set multiple
237+
// times from different threads, all of them should set the same value
238+
MemoryFence.storeStore();
239+
BuiltinMethodDescriptor local = descriptor;
240+
assert local == null || local == value : value;
241+
this.descriptor = value;
235242
}
236243

244+
/**
245+
* The descriptor is set lazily once this builtin function is stored in any special method slot.
246+
* I.e., one can assume that any builtin function looked up via special method slots has its
247+
* descriptor set.
248+
*/
237249
public BuiltinMethodDescriptor getDescriptor() {
238250
return descriptor;
239251
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/SpecialMethodSlot.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@
140140
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
141141
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
142142
import com.oracle.truffle.api.dsl.NodeFactory;
143-
import com.oracle.truffle.api.memory.MemoryFence;
144143
import com.oracle.truffle.api.object.DynamicObject;
145144
import com.oracle.truffle.api.object.DynamicObjectLibrary;
146145

@@ -658,10 +657,6 @@ private static Object asSlotValue(SpecialMethodSlot slot, Object value, PythonLa
658657
// Note: number of all builtins >> number of builtins used in slots, so it is
659658
// better to do this lazily
660659
language.registerBuiltinDescriptorCallTarget(info, builtinFun.getCallTarget());
661-
// Only make sure that info is fully initialized, otherwise it is fine if it is
662-
// set multiple times from different threads, all of them should set the same
663-
// value
664-
MemoryFence.storeStore();
665660
builtinFun.setDescriptor(info);
666661
}
667662
return info;

0 commit comments

Comments
 (0)