Skip to content

Commit 7ae318e

Browse files
fangererqunaibit
authored andcommitted
Add profile for NO_VALUE in DynamicObjectStorage.GetItemWithState.
1 parent 50853e3 commit 7ae318e

File tree

3 files changed

+15
-16
lines changed

3 files changed

+15
-16
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/DynamicObjectStorage.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -146,16 +146,18 @@ private static int incrementLen(DynamicObjectStorage self, ReadAttributeFromDyna
146146
public static class GetItemWithState {
147147
@Specialization
148148
static Object string(DynamicObjectStorage self, String key, ThreadState state,
149-
@Shared("readKey") @Cached ReadAttributeFromDynamicObjectNode readKey) {
149+
@Shared("readKey") @Cached ReadAttributeFromDynamicObjectNode readKey,
150+
@Exclusive @Cached("createBinaryProfile()") ConditionProfile noValueProfile) {
150151
Object result = readKey.execute(self.store, key);
151-
return result == PNone.NO_VALUE ? null : result;
152+
return noValueProfile.profile(result == PNone.NO_VALUE) ? null : result;
152153
}
153154

154155
@Specialization(guards = "isBuiltinString(key, profile)", limit = "1")
155156
static Object pstring(DynamicObjectStorage self, PString key, ThreadState state,
156157
@Shared("readKey") @Cached ReadAttributeFromDynamicObjectNode readKey,
157-
@Shared("builtinStringProfile") @Cached IsBuiltinClassProfile profile) {
158-
return string(self, key.getValue(), state, readKey);
158+
@Shared("builtinStringProfile") @Cached IsBuiltinClassProfile profile,
159+
@Exclusive @Cached("createBinaryProfile()") ConditionProfile noValueProfile) {
160+
return string(self, key.getValue(), state, readKey, noValueProfile);
159161
}
160162

161163
@Specialization(guards = {"cachedShape == self.store.getShape()", "!isBuiltinString(key, profile)"}, limit = "1")
@@ -166,20 +168,21 @@ static Object notString(DynamicObjectStorage self, Object key, ThreadState state
166168
@Cached(value = "cachedShape.getKeyList().toArray()", dimensions = 1) Object[] keyList,
167169
@Shared("builtinStringProfile") @Cached IsBuiltinClassProfile profile,
168170
@CachedLibrary(limit = "2") PythonObjectLibrary lib,
169-
@Exclusive @Cached("createBinaryProfile()") ConditionProfile gotState) {
171+
@Exclusive @Cached("createBinaryProfile()") ConditionProfile gotState,
172+
@Exclusive @Cached("createBinaryProfile()") ConditionProfile noValueProfile) {
170173
long hash = self.getHashWithState(key, lib, state, gotState);
171174
for (int i = 0; i < keyList.length; i++) {
172175
Object currentKey = keyList[i];
173176
if (currentKey instanceof String) {
174177
if (gotState.profile(state != null)) {
175178
long keyHash = lib.hashWithState(currentKey, state);
176179
if (keyHash == hash && lib.equalsWithState(key, currentKey, lib, state)) {
177-
return string(self, (String) currentKey, state, readKey);
180+
return string(self, (String) currentKey, state, readKey, noValueProfile);
178181
}
179182
} else {
180183
long keyHash = lib.hash(currentKey);
181184
if (keyHash == hash && lib.equals(key, currentKey, lib)) {
182-
return string(self, (String) currentKey, null, readKey);
185+
return string(self, (String) currentKey, null, readKey, noValueProfile);
183186
}
184187
}
185188
}
@@ -192,7 +195,8 @@ static Object notStringLoop(DynamicObjectStorage self, Object key, ThreadState s
192195
@Shared("readKey") @Cached ReadAttributeFromDynamicObjectNode readKey,
193196
@Shared("builtinStringProfile") @Cached IsBuiltinClassProfile profile,
194197
@CachedLibrary(limit = "2") PythonObjectLibrary lib,
195-
@Exclusive @Cached("createBinaryProfile()") ConditionProfile gotState) {
198+
@Exclusive @Cached("createBinaryProfile()") ConditionProfile gotState,
199+
@Exclusive @Cached("createBinaryProfile()") ConditionProfile noValueProfile) {
196200
long hash = self.getHashWithState(key, lib, state, gotState);
197201
Iterator<Object> keys = self.store.getShape().getKeys().iterator();
198202
while (hasNext(keys)) {
@@ -202,12 +206,12 @@ static Object notStringLoop(DynamicObjectStorage self, Object key, ThreadState s
202206
if (gotState.profile(state != null)) {
203207
keyHash = lib.hashWithState(currentKey, state);
204208
if (keyHash == hash && lib.equalsWithState(key, currentKey, lib, state)) {
205-
return string(self, (String) currentKey, state, readKey);
209+
return string(self, (String) currentKey, state, readKey, noValueProfile);
206210
}
207211
} else {
208212
keyHash = lib.hash(currentKey);
209213
if (keyHash == hash && lib.equals(key, currentKey, lib)) {
210-
return string(self, (String) currentKey, null, readKey);
214+
return string(self, (String) currentKey, null, readKey, noValueProfile);
211215
}
212216
}
213217
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/HashingStorageNodes.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@
7575
import com.oracle.graal.python.nodes.PRaiseNode;
7676
import com.oracle.graal.python.nodes.SpecialMethodNames;
7777
import com.oracle.graal.python.nodes.attributes.LookupInheritedAttributeNode;
78-
import com.oracle.graal.python.nodes.attributes.ReadAttributeFromDynamicObjectNode;
7978
import com.oracle.graal.python.nodes.builtins.ListNodes.FastConstructListNode;
8079
import com.oracle.graal.python.nodes.call.special.LookupAndCallBinaryNode;
8180
import com.oracle.graal.python.nodes.call.special.LookupAndCallUnaryNode;
@@ -91,8 +90,6 @@
9190
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
9291
import com.oracle.truffle.api.Truffle;
9392
import com.oracle.truffle.api.dsl.Cached;
94-
import com.oracle.truffle.api.dsl.Cached.Exclusive;
95-
import com.oracle.truffle.api.dsl.Cached.Shared;
9693
import com.oracle.truffle.api.dsl.CachedContext;
9794
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
9895
import com.oracle.truffle.api.dsl.GenerateUncached;
@@ -366,7 +363,7 @@ public static GetItemNode create() {
366363
public abstract Object execute(VirtualFrame frame, HashingStorage storage, Object key);
367364

368365
@Specialization
369-
Object doGeneric(@SuppressWarnings("unused") VirtualFrame frame, HashingStorage storage, Object key,
366+
static Object doGeneric(@SuppressWarnings("unused") VirtualFrame frame, HashingStorage storage, Object key,
370367
@Cached("createBinaryProfile()") ConditionProfile hasFrame,
371368
@CachedLibrary(limit = "3") HashingStorageLibrary lib) {
372369
if (hasFrame.profile(frame != null)) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/frame/ReadGlobalOrBuiltinNode.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,9 @@
3232
import com.oracle.graal.python.builtins.objects.PNone;
3333
import com.oracle.graal.python.builtins.objects.common.HashingStorage;
3434
import com.oracle.graal.python.builtins.objects.common.HashingStorageLibrary;
35-
import com.oracle.graal.python.builtins.objects.common.HashingStorageNodes;
3635
import com.oracle.graal.python.builtins.objects.dict.PDict;
3736
import com.oracle.graal.python.builtins.objects.function.PArguments;
3837
import com.oracle.graal.python.builtins.objects.module.PythonModule;
39-
import com.oracle.graal.python.builtins.objects.object.PythonObject;
4038
import com.oracle.graal.python.nodes.BuiltinNames;
4139
import com.oracle.graal.python.nodes.PRaiseNode;
4240
import com.oracle.graal.python.nodes.attributes.ReadAttributeFromObjectNode;

0 commit comments

Comments
 (0)