Skip to content

Commit 68e9ff8

Browse files
committed
Add counting profile for invalidating handleValidAssumption.
1 parent f3ebc7f commit 68e9ff8

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/PythonAbstractObject.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,10 @@ public final void setNativeWrapper(DynamicObjectNativeWrapper nativeWrapper) {
181181
this.nativeWrapper = nativeWrapper;
182182
}
183183

184-
public final void clearNativeWrapper() {
184+
public final void clearNativeWrapper(ConditionProfile hasHandleValidAssumptionProfile) {
185185
// The null check is important because it might be that we actually never got a to-native
186186
// message but still modified the reference count.
187-
if (nativeWrapper != null && nativeWrapper.getHandleValidAssumption() != null) {
187+
if (hasHandleValidAssumptionProfile.profile(nativeWrapper != null && nativeWrapper.getHandleValidAssumption() != null)) {
188188
nativeWrapper.getHandleValidAssumption().invalidate("releasing handle for native wrapper");
189189
}
190190
nativeWrapper = null;

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/CExtNodes.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3014,32 +3014,34 @@ public abstract static class ClearNativeWrapperNode extends Node {
30143014
public abstract void execute(Object delegate, PythonNativeWrapper nativeWrapper);
30153015

30163016
@Specialization(guards = "!isPrimitiveNativeWrapper(nativeWrapper)")
3017-
static void doPythonAbstractObject(PythonAbstractObject delegate, PythonNativeWrapper nativeWrapper) {
3017+
static void doPythonAbstractObject(PythonAbstractObject delegate, PythonNativeWrapper nativeWrapper,
3018+
@Cached("createCountingProfile()") ConditionProfile hasHandleValidAssumptionProfile) {
30183019
// For non-temporary wrappers (all wrappers that need to preserve identity):
30193020
// If this assertion fails, it indicates that the native code still uses a free'd native
30203021
// wrapper.
30213022
// TODO(fa): explicitly mark native wrappers to be identity preserving
30223023
assert !(nativeWrapper instanceof PythonObjectNativeWrapper) || delegate.getNativeWrapper() == nativeWrapper : "inconsistent native wrappers";
3023-
delegate.clearNativeWrapper();
3024+
delegate.clearNativeWrapper(hasHandleValidAssumptionProfile);
30243025
}
30253026

30263027
@Specialization(guards = "delegate == null")
30273028
static void doPrimitiveNativeWrapper(@SuppressWarnings("unused") Object delegate, PrimitiveNativeWrapper nativeWrapper,
3028-
@Cached("createBinaryProfile()") ConditionProfile profile,
3029+
@Cached("createCountingProfile()") ConditionProfile hasHandleValidAssumptionProfile,
30293030
@Shared("contextRef") @CachedContext(PythonLanguage.class) ContextReference<PythonContext> contextRef) {
30303031
assert !isSmallIntegerWrapperSingleton(contextRef, nativeWrapper) : "clearing primitive native wrapper singleton of small integer";
3031-
if (profile.profile(nativeWrapper.getHandleValidAssumption() != null)) {
3032+
if (hasHandleValidAssumptionProfile.profile(nativeWrapper.getHandleValidAssumption() != null)) {
30323033
nativeWrapper.getHandleValidAssumption().invalidate("releasing handle for native wrapper");
30333034
}
30343035
}
30353036

30363037
@Specialization(guards = "delegate != null")
30373038
static void doPrimitiveNativeWrapperMaterialized(PythonAbstractObject delegate, PrimitiveNativeWrapper nativeWrapper,
30383039
@Cached("createBinaryProfile()") ConditionProfile profile,
3040+
@Cached("createCountingProfile()") ConditionProfile hasHandleValidAssumptionProfile,
30393041
@Shared("contextRef") @CachedContext(PythonLanguage.class) ContextReference<PythonContext> contextRef) {
30403042
if (profile.profile(delegate.getNativeWrapper() == nativeWrapper)) {
30413043
assert !isSmallIntegerWrapperSingleton(contextRef, nativeWrapper) : "clearing primitive native wrapper singleton of small integer";
3042-
delegate.clearNativeWrapper();
3044+
delegate.clearNativeWrapper(hasHandleValidAssumptionProfile);
30433045
}
30443046
}
30453047

0 commit comments

Comments
 (0)