Skip to content

Commit a7ee8e7

Browse files
committed
Allocate GC head for mv objects
1 parent bbc6baf commit a7ee8e7

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,7 +1295,7 @@ public static Object executeUncached(Object pointerObject) {
12951295
@Specialization
12961296
static Object resolveLongCached(Node inliningTarget, long pointer,
12971297
@Exclusive @Cached ResolveHandleNode resolveHandleNode,
1298-
@Cached UpdateRefNode updateRefNode) {
1298+
@Exclusive @Cached UpdateRefNode updateRefNode) {
12991299
Object lookup = CApiTransitions.lookupNative(pointer);
13001300
if (lookup != null) {
13011301
if (lookup instanceof PythonAbstractObjectNativeWrapper objectNativeWrapper) {
@@ -1313,7 +1313,7 @@ static Object resolveLongCached(Node inliningTarget, long pointer,
13131313
static Object resolveGeneric(Node inliningTarget, Object pointerObject,
13141314
@CachedLibrary(limit = "3") InteropLibrary lib,
13151315
@Exclusive @Cached ResolveHandleNode resolveHandleNode,
1316-
@Cached UpdateRefNode updateRefNode) {
1316+
@Exclusive @Cached UpdateRefNode updateRefNode) {
13171317
if (lib.isPointer(pointerObject)) {
13181318
Object lookup;
13191319
long pointer;

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151

5252
import com.oracle.graal.python.builtins.objects.buffer.PythonBufferAccessLibrary;
5353
import com.oracle.graal.python.builtins.objects.cext.capi.PythonNativeWrapper.PythonAbstractObjectNativeWrapper;
54+
import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions;
5455
import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeNewRefNode;
5556
import com.oracle.graal.python.builtins.objects.cext.structs.CFields;
5657
import com.oracle.graal.python.builtins.objects.cext.structs.CStructAccess;
@@ -61,6 +62,7 @@
6162
import com.oracle.graal.python.nodes.ErrorMessages;
6263
import com.oracle.graal.python.nodes.PRaiseNode;
6364
import com.oracle.graal.python.nodes.object.GetClassNode;
65+
import com.oracle.graal.python.runtime.PythonContext;
6466
import com.oracle.truffle.api.CompilerDirectives;
6567
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
6668
import com.oracle.truffle.api.interop.InteropLibrary;
@@ -98,9 +100,15 @@ private static Object allocate(PMemoryView object) {
98100
CStructAccess.WriteIntNode writeI32Node = CStructAccess.WriteIntNode.getUncached();
99101
CExtNodes.AsCharPointerNode asCharPointerNode = CExtNodes.AsCharPointerNode.getUncached();
100102

101-
Object mem = CStructAccess.AllocateNode.allocUncached(PyMemoryViewObject);
102-
writeI64Node.write(mem, PyObject__ob_refcnt, IMMORTAL_REFCNT); // TODO: immortal for now
103-
writePointerNode.write(mem, PyObject__ob_type, PythonToNativeNewRefNode.executeUncached(GetClassNode.executeUncached(object)));
103+
Object mem;
104+
if (!PythonContext.get(null).isNativeAccessAllowed()) { // accommodate managed mode.
105+
mem = CStructAccess.AllocateNode.allocUncached(PyMemoryViewObject.size()); /*- GC head alloc is not needed */
106+
writeI64Node.write(mem, PyObject__ob_refcnt, IMMORTAL_REFCNT); // TODO: immortal for now
107+
writePointerNode.write(mem, PyObject__ob_type, PythonToNativeNewRefNode.executeUncached(GetClassNode.executeUncached(object)));
108+
} else {
109+
long taggedPointer = CApiTransitions.FirstToNativeNode.executeUncached(object.getNativeWrapper(), true /*- TODO: immortal for now */);
110+
mem = CApiTransitions.HandlePointerConverter.pointerToStub(taggedPointer);
111+
}
104112
writeI32Node.write(mem, PyMemoryViewObject__flags, object.getFlags());
105113
writeI64Node.write(mem, PyMemoryViewObject__exports, object.getExports().get());
106114
// TODO: ignoring mbuf, hash and weakreflist for now

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/transitions/CApiTransitions.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
import com.oracle.graal.python.builtins.objects.cext.structs.CStructs;
9191
import com.oracle.graal.python.builtins.objects.floats.PFloat;
9292
import com.oracle.graal.python.builtins.objects.getsetdescriptor.DescriptorDeleteMarker;
93+
import com.oracle.graal.python.builtins.objects.memoryview.PMemoryView;
9394
import com.oracle.graal.python.builtins.objects.object.PythonObject;
9495
import com.oracle.graal.python.builtins.objects.traceback.LazyTraceback;
9596
import com.oracle.graal.python.builtins.objects.tuple.PTuple;
@@ -924,6 +925,7 @@ static long doOther(Node inliningTarget, PythonAbstractObjectNativeWrapper wrapp
924925
@Exclusive @Cached InlinedConditionProfile isVarObjectProfile,
925926
@Exclusive @Cached InlinedConditionProfile isGcProfile,
926927
@Exclusive @Cached InlinedConditionProfile isFloatObjectProfile,
928+
@Exclusive @Cached InlinedConditionProfile isMemViewObjectProfile,
927929
@Cached GetClassNode getClassNode,
928930
@Cached(inline = false) GetTypeFlagsNode getTypeFlagsNode,
929931
@Exclusive @Cached AllocateNativeObjectStubNode allocateNativeObjectStubNode) {
@@ -939,6 +941,8 @@ static long doOther(Node inliningTarget, PythonAbstractObjectNativeWrapper wrapp
939941
ctype = CStructs.GraalPyVarObject;
940942
} else if (isFloatObjectProfile.profile(inliningTarget, delegate instanceof Double || delegate instanceof PFloat)) {
941943
ctype = CStructs.GraalPyFloatObject;
944+
} else if (isMemViewObjectProfile.profile(inliningTarget, delegate instanceof PMemoryView)) {
945+
ctype = CStructs.PyMemoryViewObject;
942946
} else {
943947
ctype = CStructs.GraalPyObject;
944948
}
@@ -1438,7 +1442,7 @@ protected boolean needsTransfer() {
14381442
static Object doWrapper(PythonNativeWrapper value,
14391443
@Bind("$node") Node inliningTarget,
14401444
@Exclusive @Cached InlinedExactClassProfile wrapperProfile,
1441-
@Cached UpdateRefNode updateRefNode) {
1445+
@Exclusive @Cached UpdateRefNode updateRefNode) {
14421446
return handleWrapper(inliningTarget, wrapperProfile, updateRefNode, false, value);
14431447
}
14441448

@@ -1455,7 +1459,7 @@ Object doNonWrapper(Object value,
14551459
@Cached InlinedConditionProfile isNativeWrapperProfile,
14561460
@Cached InlinedConditionProfile isHandleSpaceProfile,
14571461
@Exclusive @Cached InlinedExactClassProfile wrapperProfile,
1458-
@Cached UpdateRefNode updateRefNode) {
1462+
@Exclusive @Cached UpdateRefNode updateRefNode) {
14591463
assert !(value instanceof TruffleString);
14601464
assert !(value instanceof PythonAbstractObject);
14611465
assert !(value instanceof Number);

0 commit comments

Comments
 (0)