Skip to content

Commit 3b07664

Browse files
committed
Avoid downcalls when setting native storage items
1 parent 67678de commit 3b07664

File tree

3 files changed

+11
-19
lines changed

3 files changed

+11
-19
lines changed

graalpython/com.oracle.graal.python.cext/src/capi.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -506,14 +506,6 @@ PyAPI_FUNC(void) PyTruffle_ObjectArrayRelease(PyObject** array, int32_t size) {
506506
}
507507
}
508508

509-
PyAPI_FUNC(void) PyTruffle_SetStorageItem(PyObject** ptr, int32_t index, PyObject* newitem) {
510-
Py_XSETREF(ptr[index], newitem);
511-
}
512-
513-
PyAPI_FUNC(void) PyTruffle_InitializeStorageItem(PyObject** ptr, int32_t index, PyObject* newitem) {
514-
ptr[index] = newitem;
515-
}
516-
517509
#define ReadMember(object, offset, T) ((T*)(((char*)object) + offset))[0]
518510

519511
PyAPI_FUNC(int) ReadShortMember(void* object, Py_ssize_t offset) {

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,6 @@ public enum NativeCAPISymbol implements NativeCExtSymbol {
124124
FUN_PTR_COMPARE("truffle_ptr_compare", Int, Pointer, Pointer, Int),
125125
FUN_PTR_ADD("truffle_ptr_add", Pointer, Pointer, Py_ssize_t),
126126
FUN_PY_TRUFFLE_OBJECT_ARRAY_RELEASE("PyTruffle_ObjectArrayRelease", ArgDescriptor.Void, Pointer, Int),
127-
FUN_PY_TRUFFLE_SET_STORAGE_ITEM("PyTruffle_SetStorageItem", ArgDescriptor.Void, Pointer, Int, PyObject),
128-
FUN_PY_TRUFFLE_INITIALIZE_STORAGE_ITEM("PyTruffle_InitializeStorageItem", ArgDescriptor.Void, Pointer, Int, PyObject),
129127
FUN_PY_OBJECT_GET_DICT_PTR("_PyObject_GetDictPtr", Pointer, PyObject),
130128
FUN_PY_OBJECT_GENERIC_SET_DICT("PyObject_GenericSetDict", Int, PyObject, PyObject, Pointer),
131129
FUN_PY_OBJECT_NEW("PyTruffle_Object_New", PyObjectTransfer, PyTypeObject),

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

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
*/
2626
package com.oracle.graal.python.builtins.objects.common;
2727

28-
import static com.oracle.graal.python.builtins.objects.cext.capi.NativeCAPISymbol.FUN_PY_TRUFFLE_INITIALIZE_STORAGE_ITEM;
29-
import static com.oracle.graal.python.builtins.objects.cext.capi.NativeCAPISymbol.FUN_PY_TRUFFLE_SET_STORAGE_ITEM;
3028
import static com.oracle.graal.python.builtins.objects.iterator.IteratorBuiltins.NextHelperNode.STOP_MARKER;
3129
import static com.oracle.graal.python.runtime.exception.PythonErrorType.IndexError;
3230
import static com.oracle.graal.python.runtime.exception.PythonErrorType.MemoryError;
@@ -50,7 +48,6 @@
5048
import com.oracle.graal.python.builtins.objects.bytes.BytesNodes;
5149
import com.oracle.graal.python.builtins.objects.bytes.PBytesLike;
5250
import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes;
53-
import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.PCallCapiFunction;
5451
import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativeToPythonNode;
5552
import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeNewRefNode;
5653
import com.oracle.graal.python.builtins.objects.cext.structs.CStructAccess;
@@ -1146,9 +1143,14 @@ protected static void doNativeByte(NativeByteSequenceStorage storage, int idx, O
11461143

11471144
@Specialization
11481145
protected static void doNativeObject(NativeObjectSequenceStorage storage, int idx, Object value,
1149-
@Cached PCallCapiFunction call,
1150-
@Cached PythonToNativeNewRefNode toSulongNode) {
1151-
call.call(FUN_PY_TRUFFLE_SET_STORAGE_ITEM, storage.getPtr(), idx, toSulongNode.execute(value));
1146+
@Bind("this") Node inliningTarget,
1147+
@Cached PythonToNativeNewRefNode toNative,
1148+
@Cached CStructAccess.ReadPointerNode readPointerNode,
1149+
@Cached CStructAccess.WritePointerNode writePointerNode,
1150+
@Cached CExtNodes.DecRefPointerNode decRefPointerNode) {
1151+
Object old = readPointerNode.readArrayElement(storage.getPtr(), idx);
1152+
writePointerNode.writeArrayElement(storage.getPtr(), idx, toNative.execute(value));
1153+
decRefPointerNode.execute(inliningTarget, old);
11521154
}
11531155
}
11541156

@@ -1167,9 +1169,9 @@ protected static void doNativeByte(NativeByteSequenceStorage storage, int idx, O
11671169

11681170
@Specialization
11691171
protected static void doNativeObject(NativeObjectSequenceStorage storage, int idx, Object value,
1170-
@Cached PCallCapiFunction call,
1171-
@Cached PythonToNativeNewRefNode toSulongNode) {
1172-
call.call(FUN_PY_TRUFFLE_INITIALIZE_STORAGE_ITEM, storage.getPtr(), idx, toSulongNode.execute(value));
1172+
@Cached CStructAccess.WritePointerNode writePointerNode,
1173+
@Cached PythonToNativeNewRefNode toNative) {
1174+
writePointerNode.writeArrayElement(storage.getPtr(), idx, toNative.execute(value));
11731175
}
11741176
}
11751177

0 commit comments

Comments
 (0)