Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ test.test_functools.TestLRUC.test_lru_cache_threaded @ darwin-arm64,linux-aarch6
test.test_functools.TestLRUC.test_lru_cache_threaded2 @ darwin-arm64,linux-aarch64,linux-aarch64-github,linux-x86_64,linux-x86_64-github,win32-AMD64,win32-AMD64-github
test.test_functools.TestLRUC.test_lru_cache_threaded3 @ darwin-arm64,linux-aarch64,linux-aarch64-github,linux-x86_64,linux-x86_64-github,win32-AMD64,win32-AMD64-github
test.test_functools.TestLRUC.test_lru_cache_typed_is_not_recursive @ darwin-arm64,linux-aarch64,linux-aarch64-github,linux-x86_64,linux-x86_64-github,win32-AMD64,win32-AMD64-github
# GR-71869
!test.test_functools.TestLRUC.test_lru_cache_weakrefable @ darwin-arm64,linux-x86_64,win32-AMD64
test.test_functools.TestLRUC.test_lru_cache_weakrefable @ darwin-arm64,linux-x86_64,win32-AMD64
test.test_functools.TestLRUC.test_lru_hash_only_once @ darwin-arm64,linux-aarch64,linux-aarch64-github,linux-x86_64,linux-x86_64-github,win32-AMD64,win32-AMD64-github
test.test_functools.TestLRUC.test_lru_method @ darwin-arm64,linux-aarch64,linux-aarch64-github,linux-x86_64,linux-x86_64-github,win32-AMD64,win32-AMD64-github
test.test_functools.TestLRUC.test_lru_no_args @ darwin-arm64,linux-aarch64,linux-aarch64-github,linux-x86_64,linux-x86_64-github,win32-AMD64,win32-AMD64-github
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ final Object executeCached(SuperObject self) {

@Specialization(guards = {"isSingleContext()", "self == cachedSelf"}, assumptions = {"cachedSelf.getNeverReinitializedAssumption()"}, limit = "1")
static Object cached(@NeverDefault @SuppressWarnings("unused") SuperObject self,
@SuppressWarnings("unused") @Cached("self") SuperObject cachedSelf,
@Cached(value = "self.getType()") Object type) {
@SuppressWarnings("unused") @Cached(value = "self", weak = true) SuperObject cachedSelf,
@Cached(value = "self.getType()", weak = true) Object type) {
return type;
}

Expand All @@ -167,8 +167,8 @@ abstract static class GetObjectTypeNode extends PNodeWithContext {

@Specialization(guards = {"isSingleContext()", "self == cachedSelf"}, assumptions = {"cachedSelf.getNeverReinitializedAssumption()"}, limit = "1")
static Object cached(@NeverDefault @SuppressWarnings("unused") SuperObject self,
@SuppressWarnings("unused") @Cached("self") SuperObject cachedSelf,
@Cached(value = "self.getObjectType()") Object type) {
@SuppressWarnings("unused") @Cached(value = "self", weak = true) SuperObject cachedSelf,
@Cached(value = "self.getObjectType()", weak = true) Object type) {
return type;
}

Expand All @@ -190,8 +190,8 @@ final Object executeCached(SuperObject self) {

@Specialization(guards = {"isSingleContext()", "self == cachedSelf"}, assumptions = {"cachedSelf.getNeverReinitializedAssumption()"}, limit = "1")
static Object cached(@NeverDefault @SuppressWarnings("unused") SuperObject self,
@SuppressWarnings("unused") @Cached("self") SuperObject cachedSelf,
@Cached(value = "self.getObject()") Object object) {
@SuppressWarnings("unused") @Cached(value = "self", weak = true) SuperObject cachedSelf,
@Cached(value = "self.getObject()", weak = true) Object object) {
return object;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ MroSequenceStorage.FinalAttributeAssumptionPair findAttrAndAssumptionInMRO(Objec
assumptions = "cachedAttrInMROInfo.getAssumption()")
static Object lookupConstantMROCached(Object klass,
@Bind Node inliningTarget,
@Cached("klass") Object cachedKlass,
@Cached(value = "klass", weak = true) Object cachedKlass,
@Cached IsSameTypeNode isSameTypeNode,
@Cached("findAttrAndAssumptionInMRO(cachedKlass)") MroSequenceStorage.FinalAttributeAssumptionPair cachedAttrInMROInfo) {
return cachedAttrInMROInfo.getValue();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2026, 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 @@ -45,6 +45,7 @@
import com.oracle.graal.python.builtins.objects.object.PythonObject;
import com.oracle.graal.python.builtins.objects.type.PythonManagedClass;
import com.oracle.graal.python.nodes.PNodeWithContext;
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.GenerateInline;
import com.oracle.truffle.api.dsl.GenerateUncached;
Expand Down Expand Up @@ -99,7 +100,7 @@ protected static boolean isLongLivedObject(DynamicObject object) {

@Idempotent
protected static boolean isPrimitive(Object value) {
return value instanceof Integer || value instanceof Long || value instanceof Boolean || value instanceof Double;
return PythonUtils.isPrimitive(value);
}

@NonIdempotent
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2026, 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 @@ -54,6 +54,7 @@
import com.oracle.truffle.api.dsl.NonIdempotent;
import com.oracle.truffle.api.strings.TruffleString;
import com.oracle.truffle.api.utilities.CyclicAssumption;
import com.oracle.truffle.api.utilities.TruffleWeakReference;

public final class MroSequenceStorage extends ArrayBasedSequenceStorage {

Expand All @@ -71,7 +72,8 @@ public final class MroSequenceStorage extends ArrayBasedSequenceStorage {

public static final class FinalAttributeAssumptionPair {
@CompilationFinal private Assumption assumption;
@CompilationFinal private Object value;
@CompilationFinal private TruffleWeakReference<Object> value;
private Object valueStrongReference;

public FinalAttributeAssumptionPair() {
this.assumption = Truffle.getRuntime().createAssumption("attribute in MRO final");
Expand All @@ -87,11 +89,16 @@ public void invalidate() {

@NonIdempotent
public Object getValue() {
return value;
return value.get();
}

public void setValue(Object value) {
this.value = value;
if (PythonUtils.isPrimitive(value)) {
// DynamicObjectStorage does not store the boxed object, but the raw primitive
// value, so we must protect the boxed object from GC ourselves
valueStrongReference = value;
}
this.value = new TruffleWeakReference<>(value);
}

@NonIdempotent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,10 @@ public static Object builtinClassToType(Object cls) {
return cls;
}

public static boolean isPrimitive(Object value) {
return value instanceof Integer || value instanceof Long || value instanceof Boolean || value instanceof Double;
}

public static final class NodeCounterWithLimit implements NodeVisitor {
private int count;
private final int limit;
Expand Down
2 changes: 1 addition & 1 deletion graalpython/lib-python/3/test/test_functools.py
Original file line number Diff line number Diff line change
Expand Up @@ -1872,7 +1872,7 @@ def test_staticmethod(x):

del A
del test_function
gc.collect()
support.gc_collect()

for ref in refs:
self.assertIsNone(ref())
Expand Down
Loading