diff --git a/docs/contributor/IMPLEMENTATION_DETAILS.md b/docs/contributor/IMPLEMENTATION_DETAILS.md index b540380319..7b9cef7609 100644 --- a/docs/contributor/IMPLEMENTATION_DETAILS.md +++ b/docs/contributor/IMPLEMENTATION_DETAILS.md @@ -276,7 +276,7 @@ When a managed object is passed to a native extension code: accessed any primitive elements are (like the previous step) boxed into a `PythonAbstractObject`. -* When NFI calls `toNative`/`asPointer`, we: +* When a C API transition needs a native pointer for a managed object, we: * Allocate a native stub that will represent the object on the native side. We allocate room for the `refcount` and type pointer to avoid upcalls for reading those. For some types such as floats, we also store the diff --git a/graalpython/com.oracle.graal.python.cext/CMakeLists.txt b/graalpython/com.oracle.graal.python.cext/CMakeLists.txt index 8ad41ba7bd..ffb606b6ce 100644 --- a/graalpython/com.oracle.graal.python.cext/CMakeLists.txt +++ b/graalpython/com.oracle.graal.python.cext/CMakeLists.txt @@ -50,7 +50,6 @@ endif() require_var(GRAALPY_PARENT_DIR) require_var(CAPI_INC_DIR) require_var(PYCONFIG_INCLUDE_DIR) -require_var(TRUFFLE_NFI_H_INC) require_var(GRAALPY_EXT) if(NOT DEFINED SRC_DIR) @@ -200,7 +199,6 @@ include_directories( "${SRC_DIR}/include" "${CAPI_INC_DIR}" "${PYCONFIG_INCLUDE_DIR}" - "${TRUFFLE_NFI_H_INC}" ) function(native_module name core src_files) diff --git a/graalpython/com.oracle.graal.python.cext/src/capi.c b/graalpython/com.oracle.graal.python.cext/src/capi.c index f42088521c..4c2564481b 100644 --- a/graalpython/com.oracle.graal.python.cext/src/capi.c +++ b/graalpython/com.oracle.graal.python.cext/src/capi.c @@ -41,7 +41,6 @@ #include "capi.h" #include #include -#include #include "pycore_gc.h" // _PyGC_InitState diff --git a/graalpython/com.oracle.graal.python.cext/src/pystate.c b/graalpython/com.oracle.graal.python.cext/src/pystate.c index 93a2faada1..eb28b2c479 100644 --- a/graalpython/com.oracle.graal.python.cext/src/pystate.c +++ b/graalpython/com.oracle.graal.python.cext/src/pystate.c @@ -29,7 +29,6 @@ #endif // GraalPy change #include "capi.h" -#include static THREAD_LOCAL int graalpy_attached_thread = 0; static THREAD_LOCAL int graalpy_gilstate_counter = 0; diff --git a/graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_ctypes.py b/graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_ctypes.py index b3f47b6573..7ce23fd9db 100644 --- a/graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_ctypes.py +++ b/graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_ctypes.py @@ -1,4 +1,4 @@ -# Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2024, 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 @@ -128,7 +128,6 @@ def test_buffer(self): assert struct.Struct(buffer.format).size == int_format.size assert buffer.shape == (2, 2) -# TODO: GR-60735, we cannot support this without NFI struct by value support def ignore_test_custom_libs(): # 16B: returned in registers on System V AMD64 ABI class MySmallStruct1(ctypes.Structure): diff --git a/graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_member.py b/graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_member.py index c2c1c2a708..1d17ba9ae6 100644 --- a/graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_member.py +++ b/graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_member.py @@ -1,4 +1,4 @@ -# Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2022, 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 @@ -101,6 +101,22 @@ def test_member(self): return Py_None; } + PyObject* set_string_inplace(PyObject *self, PyObject *arg) { + TestMemberObject *tmo = (TestMemberObject *)self; + Py_ssize_t len; + const char *utf8 = PyUnicode_AsUTF8AndSize(arg, &len); + if (utf8 == NULL) + return NULL; + if (len >= (Py_ssize_t)sizeof(tmo->member_string_inplace)) { + PyErr_SetString(PyExc_ValueError, "string too long"); + return NULL; + } + memcpy(tmo->member_string_inplace, utf8, len); + tmo->member_string_inplace[len] = 0; + Py_INCREF(Py_None); + return Py_None; + } + PyObject* get_min_values(PyObject *self) { PyObject *result = PyTuple_New(9); PyTuple_SetItem(result, 0, PyLong_FromSsize_t(CHAR_MIN)); @@ -138,6 +154,7 @@ def test_member(self): float member_float; double member_double; char *member_string; + char member_string_inplace[8]; char member_char; char member_byte; unsigned char member_ubyte; @@ -159,6 +176,7 @@ def test_member(self): {"member_float", T_FLOAT, offsetof(TestMemberObject, member_float), 0, "float member"}, {"member_double", T_DOUBLE, offsetof(TestMemberObject, member_double), 0, "double member"}, {"member_string", T_STRING, offsetof(TestMemberObject, member_string), 0, "string member"}, + {"member_string_inplace", T_STRING_INPLACE, offsetof(TestMemberObject, member_string_inplace), 0, "string inplace member"}, {"member_char", T_CHAR, offsetof(TestMemberObject, member_char), 0, "char member"}, {"member_byte", T_BYTE, offsetof(TestMemberObject, member_byte), 0, "byte member"}, {"member_ubyte", T_UBYTE, offsetof(TestMemberObject, member_ubyte), 0, "ubyte member"}, @@ -172,6 +190,7 @@ def test_member(self): """, tp_methods=''' {"set_string", (PyCFunction)set_string, METH_O, ""}, + {"set_string_inplace", (PyCFunction)set_string_inplace, METH_O, ""}, {"get_min_values", (PyCFunction)get_min_values, METH_NOARGS, ""}, {"get_max_values", (PyCFunction)get_max_values, METH_NOARGS, ""} ''', @@ -277,6 +296,19 @@ def test_member(self): assert type(obj.member_string) is str assert obj.member_string == "hello" + # T_STRING_INPLACE + assert type(obj.member_string_inplace) is str + assert obj.member_string_inplace == "" + assert_raises(TypeError, delattr, obj, "member_string_inplace") + assert_raises(TypeError, setattr, obj, "member_string_inplace", "hello") + obj.set_string_inplace("hello") + assert type(obj.member_string_inplace) is str + assert obj.member_string_inplace == "hello" + obj.set_string_inplace("hi") + assert obj.member_string_inplace == "hi" + assert_raises(ValueError, obj.set_string_inplace, "too long") + assert obj.member_string_inplace == "hi" + # T_CHAR assert type(obj.member_char) is str assert obj.member_char == "\x00", "was: %r" % obj.member_char diff --git a/graalpython/com.oracle.graal.python.test/src/tests/test_interop.py b/graalpython/com.oracle.graal.python.test/src/tests/test_interop.py index ea4c2583bc..42f1789d5e 100644 --- a/graalpython/com.oracle.graal.python.test/src/tests/test_interop.py +++ b/graalpython/com.oracle.graal.python.test/src/tests/test_interop.py @@ -514,14 +514,6 @@ def test_host_lookup(self): else: assert False, "requesting a non-existing host symbol should raise KeyError" - def test_internal_languages_dont_eval(self): - try: - polyglot.eval(language="nfi", string="default") - except ValueError as e: - assert str(e) == "polyglot language 'nfi' not found" - - assert polyglot.eval(language="python", string="21 * 2") == 42 - def test_module_eval_returns_last_expr(self): assert polyglot.eval(language="python", string="x = 2; x") == 2 diff --git a/graalpython/com.oracle.graal.python/pom.xml b/graalpython/com.oracle.graal.python/pom.xml index 591f571137..fd0f6790ba 100644 --- a/graalpython/com.oracle.graal.python/pom.xml +++ b/graalpython/com.oracle.graal.python/pom.xml @@ -67,10 +67,6 @@ SOFTWARE. org.graalvm.truffle truffle-api - - org.graalvm.truffle - truffle-nfi - org.graalvm.tools profiler-tool diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/PythonLanguage.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/PythonLanguage.java index 69ed89ce4d..9e1ba1e502 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/PythonLanguage.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/PythonLanguage.java @@ -157,7 +157,6 @@ version = PythonLanguage.VERSION, // characterMimeTypes = {PythonLanguage.MIME_TYPE}, // defaultMimeType = PythonLanguage.MIME_TYPE, // - dependentLanguages = "nfi", // interactive = true, internal = false, // contextPolicy = TruffleLanguage.ContextPolicy.SHARED, // fileTypeDetectors = PythonFileDetector.class, // @@ -371,7 +370,7 @@ public boolean isSingleContext() { /** * A generic source cache for all kinds of {@link Source} objects. For example, this should be - * used to cache the sources created from NFI signature strings to ensure code sharing. + * used to cache synthetic sources to ensure code sharing. */ private final ConcurrentHashMap sourceCache = new ConcurrentHashMap<>(); diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/MMapModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/MMapModuleBuiltins.java index 8b285a5ec0..87de8bda5d 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/MMapModuleBuiltins.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/MMapModuleBuiltins.java @@ -53,7 +53,7 @@ import com.oracle.graal.python.builtins.objects.cext.capi.ExternalFunctionInvoker; import com.oracle.graal.python.builtins.objects.cext.capi.NativeCAPISymbol; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTiming; -import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeNode; +import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeInternalNode; import com.oracle.graal.python.builtins.objects.mmap.PMMap; import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode; import com.oracle.graal.python.runtime.PosixConstants; @@ -112,7 +112,7 @@ public void postInitialize(Python3Core core) { ExternalFunctionInvoker.invokeMMAP_INIT_BUFFERPROTOCOL( TIMING_MMAP_INIT_BUFFERPROTOCOL, CApiContext.getNativeSymbol(null, NativeCAPISymbol.FUN_MMAP_INIT_BUFFERPROTOCOL), - PythonToNativeNode.executeLongUncached(promoted)); + PythonToNativeInternalNode.executeUncached(promoted, false)); }); } } diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextAbstractBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextAbstractBuiltins.java index a8338b0625..18dc6e8b17 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextAbstractBuiltins.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextAbstractBuiltins.java @@ -79,8 +79,8 @@ import com.oracle.graal.python.builtins.objects.cext.capi.CApiContext; import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.AsCharPointerNode; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.CharPtrToPythonNode; -import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativeToPythonNode; -import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeNewRefNode; +import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativeToPythonInternalNode; +import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeInternalNode; import com.oracle.graal.python.builtins.objects.dict.PDict; import com.oracle.graal.python.builtins.objects.function.PBuiltinFunction; import com.oracle.graal.python.builtins.objects.getsetdescriptor.GetSetDescriptor; @@ -172,14 +172,15 @@ public final class PythonCextAbstractBuiltins { private static final TruffleLogger PY_OBJECT_SET_DOC_LOGGER = CApiContext.getLogger(PythonCextAbstractBuiltins.class); + /////// PyNumber /////// @CApiBuiltin(ret = PyObjectRawPointer, args = {PyObjectRawPointer}, call = Ignored, acquireGil = false) static long GraalPyPrivate_PyNumber_Index(long objPtr) { - Object obj = NativeToPythonNode.executeRawUncached(objPtr); + Object obj = NativeToPythonInternalNode.executeUncached(objPtr, false); checkNonNullArgUncached(obj); if (PyLongCheckNode.executeUncached(obj)) { - return PythonToNativeNewRefNode.executeLongUncached(obj); + return PythonToNativeInternalNode.executeNewRefUncached(obj); } TpSlots slots = GetObjectSlotsNode.executeUncached(obj); if (slots.nb_index() == null) { @@ -187,28 +188,28 @@ static long GraalPyPrivate_PyNumber_Index(long objPtr) { } Object result = CallSlotUnaryNode.executeUncached(slots.nb_index(), obj); if (PyLongCheckExactNode.executeUncached(result)) { - return PythonToNativeNewRefNode.executeLongUncached(result); + return PythonToNativeInternalNode.executeNewRefUncached(result); } if (!PyLongCheckNode.executeUncached(result)) { throw PRaiseNode.raiseStatic(null, TypeError, ErrorMessages.INDEX_RETURNED_NON_INT, result); } WarningsModuleBuiltins.WarnNode.getUncached().warnFormat(null, null, DeprecationWarning, 1, ErrorMessages.WARN_P_RETURNED_NON_P, obj, T___INDEX__, "int", result, "int"); - return PythonToNativeNewRefNode.executeLongUncached(result); + return PythonToNativeInternalNode.executeNewRefUncached(result); } @CApiBuiltin(ret = PyObjectRawPointer, args = {PyObjectRawPointer}, call = Ignored, acquireGil = false) static long GraalPyPrivate_PyNumber_IndexCopy(long objPtr) { - Object obj = NativeToPythonNode.executeRawUncached(objPtr); + Object obj = NativeToPythonInternalNode.executeUncached(objPtr, false); Object result = PyLongCopyNodeGen.getUncached().execute(null, obj); - return PythonToNativeNewRefNode.executeLongUncached(result); + return PythonToNativeInternalNode.executeNewRefUncached(result); } @CApiBuiltin(ret = PyObjectRawPointer, args = {PyObjectRawPointer}, call = Ignored, acquireGil = false) static long GraalPyPrivate_PyNumber_Long(long objectPtr) { - Object object = NativeToPythonNode.executeRawUncached(objectPtr); + Object object = NativeToPythonInternalNode.executeUncached(objectPtr, false); Object result = PyNumberLongNode.executeUncached(object); - return PythonToNativeNewRefNode.executeLongUncached(result); + return PythonToNativeInternalNode.executeNewRefUncached(result); } // TODO(CAPI STATIC): uses nodes without @GenerateUncached @@ -263,244 +264,244 @@ protected boolean checkBase(int base) { @CApiBuiltin(ret = PyObjectRawPointer, args = {PyObjectRawPointer}, call = Ignored, acquireGil = false) static long GraalPyPrivate_PyNumber_Float(long objectPtr) { - Object object = NativeToPythonNode.executeRawUncached(objectPtr); + Object object = NativeToPythonInternalNode.executeUncached(objectPtr, false); double result = PyNumberFloatNode.executeUncached(object); - return PythonToNativeNewRefNode.executeLongUncached(result); + return PythonToNativeInternalNode.executeNewRefUncached(result); } @CApiBuiltin(ret = PyObjectRawPointer, args = {PyObjectRawPointer, PyObjectRawPointer}, call = Ignored, acquireGil = false) static long GraalPyPrivate_PyNumber_Add(long o1Ptr, long o2Ptr) { - Object o1 = NativeToPythonNode.executeRawUncached(o1Ptr); - Object o2 = NativeToPythonNode.executeRawUncached(o2Ptr); + Object o1 = NativeToPythonInternalNode.executeUncached(o1Ptr, false); + Object o2 = NativeToPythonInternalNode.executeUncached(o2Ptr, false); Object result = PyNumberAddNode.getUncached().execute(null, o1, o2); - return PythonToNativeNewRefNode.executeLongUncached(result); + return PythonToNativeInternalNode.executeNewRefUncached(result); } @CApiBuiltin(ret = PyObjectRawPointer, args = {PyObjectRawPointer, PyObjectRawPointer}, call = Ignored, acquireGil = false) static long GraalPyPrivate_PyNumber_Subtract(long o1Ptr, long o2Ptr) { - Object o1 = NativeToPythonNode.executeRawUncached(o1Ptr); - Object o2 = NativeToPythonNode.executeRawUncached(o2Ptr); + Object o1 = NativeToPythonInternalNode.executeUncached(o1Ptr, false); + Object o2 = NativeToPythonInternalNode.executeUncached(o2Ptr, false); Object result = PyNumberSubtractNode.getUncached().execute(null, o1, o2); - return PythonToNativeNewRefNode.executeLongUncached(result); + return PythonToNativeInternalNode.executeNewRefUncached(result); } @CApiBuiltin(ret = PyObjectRawPointer, args = {PyObjectRawPointer, PyObjectRawPointer}, call = Ignored, acquireGil = false) static long GraalPyPrivate_PyNumber_Multiply(long o1Ptr, long o2Ptr) { - Object o1 = NativeToPythonNode.executeRawUncached(o1Ptr); - Object o2 = NativeToPythonNode.executeRawUncached(o2Ptr); + Object o1 = NativeToPythonInternalNode.executeUncached(o1Ptr, false); + Object o2 = NativeToPythonInternalNode.executeUncached(o2Ptr, false); Object result = PyNumberMultiplyNode.getUncached().execute(null, o1, o2); - return PythonToNativeNewRefNode.executeLongUncached(result); + return PythonToNativeInternalNode.executeNewRefUncached(result); } @CApiBuiltin(ret = PyObjectRawPointer, args = {PyObjectRawPointer, PyObjectRawPointer}, call = Ignored, acquireGil = false) static long GraalPyPrivate_PyNumber_Remainder(long o1Ptr, long o2Ptr) { - Object o1 = NativeToPythonNode.executeRawUncached(o1Ptr); - Object o2 = NativeToPythonNode.executeRawUncached(o2Ptr); + Object o1 = NativeToPythonInternalNode.executeUncached(o1Ptr, false); + Object o2 = NativeToPythonInternalNode.executeUncached(o2Ptr, false); Object result = PyNumberRemainderNode.getUncached().execute(null, o1, o2); - return PythonToNativeNewRefNode.executeLongUncached(result); + return PythonToNativeInternalNode.executeNewRefUncached(result); } @CApiBuiltin(ret = PyObjectRawPointer, args = {PyObjectRawPointer, PyObjectRawPointer}, call = Ignored, acquireGil = false) static long GraalPyPrivate_PyNumber_TrueDivide(long o1Ptr, long o2Ptr) { - Object o1 = NativeToPythonNode.executeRawUncached(o1Ptr); - Object o2 = NativeToPythonNode.executeRawUncached(o2Ptr); + Object o1 = NativeToPythonInternalNode.executeUncached(o1Ptr, false); + Object o2 = NativeToPythonInternalNode.executeUncached(o2Ptr, false); Object result = PyNumberTrueDivideNode.getUncached().execute(null, o1, o2); - return PythonToNativeNewRefNode.executeLongUncached(result); + return PythonToNativeInternalNode.executeNewRefUncached(result); } @CApiBuiltin(ret = PyObjectRawPointer, args = {PyObjectRawPointer, PyObjectRawPointer}, call = Ignored, acquireGil = false) static long GraalPyPrivate_PyNumber_FloorDivide(long o1Ptr, long o2Ptr) { - Object o1 = NativeToPythonNode.executeRawUncached(o1Ptr); - Object o2 = NativeToPythonNode.executeRawUncached(o2Ptr); + Object o1 = NativeToPythonInternalNode.executeUncached(o1Ptr, false); + Object o2 = NativeToPythonInternalNode.executeUncached(o2Ptr, false); Object result = PyNumberFloorDivideNode.getUncached().execute(null, o1, o2); - return PythonToNativeNewRefNode.executeLongUncached(result); + return PythonToNativeInternalNode.executeNewRefUncached(result); } @CApiBuiltin(ret = PyObjectRawPointer, args = {PyObjectRawPointer, PyObjectRawPointer}, call = Ignored, acquireGil = false) static long GraalPyPrivate_PyNumber_Divmod(long o1Ptr, long o2Ptr) { - Object o1 = NativeToPythonNode.executeRawUncached(o1Ptr); - Object o2 = NativeToPythonNode.executeRawUncached(o2Ptr); + Object o1 = NativeToPythonInternalNode.executeUncached(o1Ptr, false); + Object o2 = NativeToPythonInternalNode.executeUncached(o2Ptr, false); Object result = PyNumberDivmodNode.getUncached().execute(null, o1, o2); - return PythonToNativeNewRefNode.executeLongUncached(result); + return PythonToNativeInternalNode.executeNewRefUncached(result); } @CApiBuiltin(ret = PyObjectRawPointer, args = {PyObjectRawPointer, PyObjectRawPointer}, call = Ignored, acquireGil = false) static long GraalPyPrivate_PyNumber_And(long o1Ptr, long o2Ptr) { - Object o1 = NativeToPythonNode.executeRawUncached(o1Ptr); - Object o2 = NativeToPythonNode.executeRawUncached(o2Ptr); + Object o1 = NativeToPythonInternalNode.executeUncached(o1Ptr, false); + Object o2 = NativeToPythonInternalNode.executeUncached(o2Ptr, false); Object result = PyNumberAndNode.getUncached().execute(null, o1, o2); - return PythonToNativeNewRefNode.executeLongUncached(result); + return PythonToNativeInternalNode.executeNewRefUncached(result); } @CApiBuiltin(ret = PyObjectRawPointer, args = {PyObjectRawPointer, PyObjectRawPointer}, call = Ignored, acquireGil = false) static long GraalPyPrivate_PyNumber_Or(long o1Ptr, long o2Ptr) { - Object o1 = NativeToPythonNode.executeRawUncached(o1Ptr); - Object o2 = NativeToPythonNode.executeRawUncached(o2Ptr); + Object o1 = NativeToPythonInternalNode.executeUncached(o1Ptr, false); + Object o2 = NativeToPythonInternalNode.executeUncached(o2Ptr, false); Object result = PyNumberOrNode.getUncached().execute(null, o1, o2); - return PythonToNativeNewRefNode.executeLongUncached(result); + return PythonToNativeInternalNode.executeNewRefUncached(result); } @CApiBuiltin(ret = PyObjectRawPointer, args = {PyObjectRawPointer, PyObjectRawPointer}, call = Ignored, acquireGil = false) static long GraalPyPrivate_PyNumber_Xor(long o1Ptr, long o2Ptr) { - Object o1 = NativeToPythonNode.executeRawUncached(o1Ptr); - Object o2 = NativeToPythonNode.executeRawUncached(o2Ptr); + Object o1 = NativeToPythonInternalNode.executeUncached(o1Ptr, false); + Object o2 = NativeToPythonInternalNode.executeUncached(o2Ptr, false); Object result = PyNumberXorNode.getUncached().execute(null, o1, o2); - return PythonToNativeNewRefNode.executeLongUncached(result); + return PythonToNativeInternalNode.executeNewRefUncached(result); } @CApiBuiltin(ret = PyObjectRawPointer, args = {PyObjectRawPointer, PyObjectRawPointer}, call = Ignored, acquireGil = false) static long GraalPyPrivate_PyNumber_Lshift(long o1Ptr, long o2Ptr) { - Object o1 = NativeToPythonNode.executeRawUncached(o1Ptr); - Object o2 = NativeToPythonNode.executeRawUncached(o2Ptr); + Object o1 = NativeToPythonInternalNode.executeUncached(o1Ptr, false); + Object o2 = NativeToPythonInternalNode.executeUncached(o2Ptr, false); Object result = PyNumberLshiftNode.getUncached().execute(null, o1, o2); - return PythonToNativeNewRefNode.executeLongUncached(result); + return PythonToNativeInternalNode.executeNewRefUncached(result); } @CApiBuiltin(ret = PyObjectRawPointer, args = {PyObjectRawPointer, PyObjectRawPointer}, call = Ignored, acquireGil = false) static long GraalPyPrivate_PyNumber_Rshift(long o1Ptr, long o2Ptr) { - Object o1 = NativeToPythonNode.executeRawUncached(o1Ptr); - Object o2 = NativeToPythonNode.executeRawUncached(o2Ptr); + Object o1 = NativeToPythonInternalNode.executeUncached(o1Ptr, false); + Object o2 = NativeToPythonInternalNode.executeUncached(o2Ptr, false); Object result = PyNumberRshiftNode.getUncached().execute(null, o1, o2); - return PythonToNativeNewRefNode.executeLongUncached(result); + return PythonToNativeInternalNode.executeNewRefUncached(result); } @CApiBuiltin(ret = PyObjectRawPointer, args = {PyObjectRawPointer, PyObjectRawPointer}, call = Ignored, acquireGil = false) static long GraalPyPrivate_PyNumber_MatrixMultiply(long o1Ptr, long o2Ptr) { - Object o1 = NativeToPythonNode.executeRawUncached(o1Ptr); - Object o2 = NativeToPythonNode.executeRawUncached(o2Ptr); + Object o1 = NativeToPythonInternalNode.executeUncached(o1Ptr, false); + Object o2 = NativeToPythonInternalNode.executeUncached(o2Ptr, false); Object result = PyNumberMatrixMultiplyNode.getUncached().execute(null, o1, o2); - return PythonToNativeNewRefNode.executeLongUncached(result); + return PythonToNativeInternalNode.executeNewRefUncached(result); } @CApiBuiltin(ret = PyObjectRawPointer, args = {PyObjectRawPointer, PyObjectRawPointer}, call = Ignored, acquireGil = false) static long GraalPyPrivate_PyNumber_InPlaceAdd(long o1Ptr, long o2Ptr) { - Object o1 = NativeToPythonNode.executeRawUncached(o1Ptr); - Object o2 = NativeToPythonNode.executeRawUncached(o2Ptr); + Object o1 = NativeToPythonInternalNode.executeUncached(o1Ptr, false); + Object o2 = NativeToPythonInternalNode.executeUncached(o2Ptr, false); Object result = PyNumberInPlaceAddNode.getUncached().execute(null, o1, o2); - return PythonToNativeNewRefNode.executeLongUncached(result); + return PythonToNativeInternalNode.executeNewRefUncached(result); } @CApiBuiltin(ret = PyObjectRawPointer, args = {PyObjectRawPointer, PyObjectRawPointer}, call = Ignored, acquireGil = false) static long GraalPyPrivate_PyNumber_InPlaceSubtract(long o1Ptr, long o2Ptr) { - Object o1 = NativeToPythonNode.executeRawUncached(o1Ptr); - Object o2 = NativeToPythonNode.executeRawUncached(o2Ptr); + Object o1 = NativeToPythonInternalNode.executeUncached(o1Ptr, false); + Object o2 = NativeToPythonInternalNode.executeUncached(o2Ptr, false); Object result = PyNumberInPlaceSubtractNode.getUncached().execute(null, o1, o2); - return PythonToNativeNewRefNode.executeLongUncached(result); + return PythonToNativeInternalNode.executeNewRefUncached(result); } @CApiBuiltin(ret = PyObjectRawPointer, args = {PyObjectRawPointer, PyObjectRawPointer}, call = Ignored, acquireGil = false) static long GraalPyPrivate_PyNumber_InPlaceMultiply(long o1Ptr, long o2Ptr) { - Object o1 = NativeToPythonNode.executeRawUncached(o1Ptr); - Object o2 = NativeToPythonNode.executeRawUncached(o2Ptr); + Object o1 = NativeToPythonInternalNode.executeUncached(o1Ptr, false); + Object o2 = NativeToPythonInternalNode.executeUncached(o2Ptr, false); Object result = PyNumberInPlaceMultiplyNode.getUncached().execute(null, o1, o2); - return PythonToNativeNewRefNode.executeLongUncached(result); + return PythonToNativeInternalNode.executeNewRefUncached(result); } @CApiBuiltin(ret = PyObjectRawPointer, args = {PyObjectRawPointer, PyObjectRawPointer}, call = Ignored, acquireGil = false) static long GraalPyPrivate_PyNumber_InPlaceRemainder(long o1Ptr, long o2Ptr) { - Object o1 = NativeToPythonNode.executeRawUncached(o1Ptr); - Object o2 = NativeToPythonNode.executeRawUncached(o2Ptr); + Object o1 = NativeToPythonInternalNode.executeUncached(o1Ptr, false); + Object o2 = NativeToPythonInternalNode.executeUncached(o2Ptr, false); Object result = PyNumberInPlaceRemainderNode.getUncached().execute(null, o1, o2); - return PythonToNativeNewRefNode.executeLongUncached(result); + return PythonToNativeInternalNode.executeNewRefUncached(result); } @CApiBuiltin(ret = PyObjectRawPointer, args = {PyObjectRawPointer, PyObjectRawPointer}, call = Ignored, acquireGil = false) static long GraalPyPrivate_PyNumber_InPlaceTrueDivide(long o1Ptr, long o2Ptr) { - Object o1 = NativeToPythonNode.executeRawUncached(o1Ptr); - Object o2 = NativeToPythonNode.executeRawUncached(o2Ptr); + Object o1 = NativeToPythonInternalNode.executeUncached(o1Ptr, false); + Object o2 = NativeToPythonInternalNode.executeUncached(o2Ptr, false); Object result = PyNumberInPlaceTrueDivideNode.getUncached().execute(null, o1, o2); - return PythonToNativeNewRefNode.executeLongUncached(result); + return PythonToNativeInternalNode.executeNewRefUncached(result); } @CApiBuiltin(ret = PyObjectRawPointer, args = {PyObjectRawPointer, PyObjectRawPointer}, call = Ignored, acquireGil = false) static long GraalPyPrivate_PyNumber_InPlaceFloorDivide(long o1Ptr, long o2Ptr) { - Object o1 = NativeToPythonNode.executeRawUncached(o1Ptr); - Object o2 = NativeToPythonNode.executeRawUncached(o2Ptr); + Object o1 = NativeToPythonInternalNode.executeUncached(o1Ptr, false); + Object o2 = NativeToPythonInternalNode.executeUncached(o2Ptr, false); Object result = PyNumberInPlaceFloorDivideNode.getUncached().execute(null, o1, o2); - return PythonToNativeNewRefNode.executeLongUncached(result); + return PythonToNativeInternalNode.executeNewRefUncached(result); } @CApiBuiltin(ret = PyObjectRawPointer, args = {PyObjectRawPointer, PyObjectRawPointer}, call = Ignored, acquireGil = false) static long GraalPyPrivate_PyNumber_InPlaceAnd(long o1Ptr, long o2Ptr) { - Object o1 = NativeToPythonNode.executeRawUncached(o1Ptr); - Object o2 = NativeToPythonNode.executeRawUncached(o2Ptr); + Object o1 = NativeToPythonInternalNode.executeUncached(o1Ptr, false); + Object o2 = NativeToPythonInternalNode.executeUncached(o2Ptr, false); Object result = PyNumberInPlaceAndNode.getUncached().execute(null, o1, o2); - return PythonToNativeNewRefNode.executeLongUncached(result); + return PythonToNativeInternalNode.executeNewRefUncached(result); } @CApiBuiltin(ret = PyObjectRawPointer, args = {PyObjectRawPointer, PyObjectRawPointer}, call = Ignored, acquireGil = false) static long GraalPyPrivate_PyNumber_InPlaceOr(long o1Ptr, long o2Ptr) { - Object o1 = NativeToPythonNode.executeRawUncached(o1Ptr); - Object o2 = NativeToPythonNode.executeRawUncached(o2Ptr); + Object o1 = NativeToPythonInternalNode.executeUncached(o1Ptr, false); + Object o2 = NativeToPythonInternalNode.executeUncached(o2Ptr, false); Object result = PyNumberInPlaceOrNode.getUncached().execute(null, o1, o2); - return PythonToNativeNewRefNode.executeLongUncached(result); + return PythonToNativeInternalNode.executeNewRefUncached(result); } @CApiBuiltin(ret = PyObjectRawPointer, args = {PyObjectRawPointer, PyObjectRawPointer}, call = Ignored, acquireGil = false) static long GraalPyPrivate_PyNumber_InPlaceXor(long o1Ptr, long o2Ptr) { - Object o1 = NativeToPythonNode.executeRawUncached(o1Ptr); - Object o2 = NativeToPythonNode.executeRawUncached(o2Ptr); + Object o1 = NativeToPythonInternalNode.executeUncached(o1Ptr, false); + Object o2 = NativeToPythonInternalNode.executeUncached(o2Ptr, false); Object result = PyNumberInPlaceXorNode.getUncached().execute(null, o1, o2); - return PythonToNativeNewRefNode.executeLongUncached(result); + return PythonToNativeInternalNode.executeNewRefUncached(result); } @CApiBuiltin(ret = PyObjectRawPointer, args = {PyObjectRawPointer, PyObjectRawPointer}, call = Ignored, acquireGil = false) static long GraalPyPrivate_PyNumber_InPlaceLshift(long o1Ptr, long o2Ptr) { - Object o1 = NativeToPythonNode.executeRawUncached(o1Ptr); - Object o2 = NativeToPythonNode.executeRawUncached(o2Ptr); + Object o1 = NativeToPythonInternalNode.executeUncached(o1Ptr, false); + Object o2 = NativeToPythonInternalNode.executeUncached(o2Ptr, false); Object result = PyNumberInPlaceLshiftNode.getUncached().execute(null, o1, o2); - return PythonToNativeNewRefNode.executeLongUncached(result); + return PythonToNativeInternalNode.executeNewRefUncached(result); } @CApiBuiltin(ret = PyObjectRawPointer, args = {PyObjectRawPointer, PyObjectRawPointer}, call = Ignored, acquireGil = false) static long GraalPyPrivate_PyNumber_InPlaceRshift(long o1Ptr, long o2Ptr) { - Object o1 = NativeToPythonNode.executeRawUncached(o1Ptr); - Object o2 = NativeToPythonNode.executeRawUncached(o2Ptr); + Object o1 = NativeToPythonInternalNode.executeUncached(o1Ptr, false); + Object o2 = NativeToPythonInternalNode.executeUncached(o2Ptr, false); Object result = PyNumberInPlaceRshiftNode.getUncached().execute(null, o1, o2); - return PythonToNativeNewRefNode.executeLongUncached(result); + return PythonToNativeInternalNode.executeNewRefUncached(result); } @CApiBuiltin(ret = PyObjectRawPointer, args = {PyObjectRawPointer, PyObjectRawPointer}, call = Ignored, acquireGil = false) static long GraalPyPrivate_PyNumber_InPlaceMatrixMultiply(long o1Ptr, long o2Ptr) { - Object o1 = NativeToPythonNode.executeRawUncached(o1Ptr); - Object o2 = NativeToPythonNode.executeRawUncached(o2Ptr); + Object o1 = NativeToPythonInternalNode.executeUncached(o1Ptr, false); + Object o2 = NativeToPythonInternalNode.executeUncached(o2Ptr, false); Object result = PyNumberInPlaceMatrixMultiplyNode.getUncached().execute(null, o1, o2); - return PythonToNativeNewRefNode.executeLongUncached(result); + return PythonToNativeInternalNode.executeNewRefUncached(result); } @CApiBuiltin(ret = PyObjectRawPointer, args = {PyObjectRawPointer, PyObjectRawPointer, PyObjectRawPointer}, call = Ignored, acquireGil = false) static long GraalPyPrivate_PyNumber_InPlacePower(long o1Ptr, long o2Ptr, long o3Ptr) { - Object o1 = NativeToPythonNode.executeRawUncached(o1Ptr); - Object o2 = NativeToPythonNode.executeRawUncached(o2Ptr); - Object o3 = NativeToPythonNode.executeRawUncached(o3Ptr); + Object o1 = NativeToPythonInternalNode.executeUncached(o1Ptr, false); + Object o2 = NativeToPythonInternalNode.executeUncached(o2Ptr, false); + Object o3 = NativeToPythonInternalNode.executeUncached(o3Ptr, false); Object result = PyNumberInPlacePowerNode.getUncached().execute(null, o1, o2, o3); - return PythonToNativeNewRefNode.executeLongUncached(result); + return PythonToNativeInternalNode.executeNewRefUncached(result); } @CApiBuiltin(ret = PyObjectRawPointer, args = {PyObjectRawPointer, PyObjectRawPointer, PyObjectRawPointer}, call = Ignored, acquireGil = false) static long GraalPyPrivate_PyNumber_Power(long o1Ptr, long o2Ptr, long o3Ptr) { - Object o1 = NativeToPythonNode.executeRawUncached(o1Ptr); - Object o2 = NativeToPythonNode.executeRawUncached(o2Ptr); - Object o3 = NativeToPythonNode.executeRawUncached(o3Ptr); + Object o1 = NativeToPythonInternalNode.executeUncached(o1Ptr, false); + Object o2 = NativeToPythonInternalNode.executeUncached(o2Ptr, false); + Object o3 = NativeToPythonInternalNode.executeUncached(o3Ptr, false); Object result = PyNumberPowerNode.getUncached().execute(null, o1, o2, o3); - return PythonToNativeNewRefNode.executeLongUncached(result); + return PythonToNativeInternalNode.executeNewRefUncached(result); } /////// PySequence /////// @CApiBuiltin(ret = PyObjectRawPointer, args = {PyObjectRawPointer}, call = Direct, acquireGil = false) static long PySequence_Tuple(long objPtr) { - Object obj = NativeToPythonNode.executeRawUncached(objPtr); + Object obj = NativeToPythonInternalNode.executeUncached(objPtr, false); checkNonNullArgUncached(obj); Object result = GetClassNode.executeUncached(obj) == PythonBuiltinClassType.PTuple ? obj : ConstructTupleNode.getUncached().execute(null, obj); - return PythonToNativeNewRefNode.executeLongUncached(result); + return PythonToNativeInternalNode.executeNewRefUncached(result); } @CApiBuiltin(ret = PyObjectRawPointer, args = {PyObjectRawPointer}, call = Direct, acquireGil = false) static long PySequence_List(long objPtr) { - Object obj = NativeToPythonNode.executeRawUncached(objPtr); + Object obj = NativeToPythonInternalNode.executeUncached(objPtr, false); Object result = ConstructListNode.getUncached().execute(null, obj); - return PythonToNativeNewRefNode.executeLongUncached(result); + return PythonToNativeInternalNode.executeNewRefUncached(result); } @CApiBuiltin(ret = Int, args = {PyObjectRawPointer, Py_ssize_t, PyObjectRawPointer}, call = Ignored, acquireGil = false) @@ -508,27 +509,27 @@ static int GraalPyPrivate_Sequence_SetItem(long objPtr, long key, long valuePtr) if ((int) key != key) { throw PRaiseNode.raiseStatic(null, PythonErrorType.OverflowError, ErrorMessages.CANNOT_FIT_P_INTO_INDEXSIZED_INT, key); } - Object obj = NativeToPythonNode.executeRawUncached(objPtr); - Object value = NativeToPythonNode.executeRawUncached(valuePtr); + Object obj = NativeToPythonInternalNode.executeUncached(objPtr, false); + Object value = NativeToPythonInternalNode.executeUncached(valuePtr, false); PySequenceSetItemNode.executeUncached(obj, (int) key, value); return 0; } @CApiBuiltin(ret = PyObjectRawPointer, args = {PyObjectRawPointer, Py_ssize_t, Py_ssize_t}, call = Direct, acquireGil = false) static long PySequence_GetSlice(long objPtr, long iLow, long iHigh) { - Object obj = NativeToPythonNode.executeRawUncached(objPtr); + Object obj = NativeToPythonInternalNode.executeUncached(objPtr, false); if (PySequenceCheckNode.executeUncached(obj)) { Object getItemCallable = PyObjectLookupAttr.executeUncached(obj, T___GETITEM__); Object result = CallNode.executeUncached(getItemCallable, PySliceNew.executeUncached(iLow, iHigh, PNone.NONE)); - return PythonToNativeNewRefNode.executeLongUncached(result); + return PythonToNativeInternalNode.executeNewRefUncached(result); } throw PRaiseNode.raiseStatic(null, TypeError, ErrorMessages.OBJ_IS_UNSLICEABLE, obj); } @CApiBuiltin(ret = Int, args = {PyObjectRawPointer, PyObjectRawPointer}, call = Direct, acquireGil = false) static int PySequence_Contains(long haystackPtr, long needlePtr) { - Object haystack = NativeToPythonNode.executeRawUncached(haystackPtr); - Object needle = NativeToPythonNode.executeRawUncached(needlePtr); + Object haystack = NativeToPythonInternalNode.executeUncached(haystackPtr, false); + Object needle = NativeToPythonInternalNode.executeUncached(needlePtr, false); return PInt.intValue(PySequenceContainsNode.executeUncached(haystack, needle)); } @@ -537,25 +538,25 @@ static long PySequence_InPlaceRepeat(long objPtr, long n) { if (!PInt.isIntRange(n)) { throw PRaiseNode.raiseStatic(null, OverflowError); } - Object obj = NativeToPythonNode.executeRawUncached(objPtr); + Object obj = NativeToPythonInternalNode.executeUncached(objPtr, false); Object result = PySequenceInPlaceRepeatNode.executeUncached(obj, (int) n); - return PythonToNativeNewRefNode.executeLongUncached(result); + return PythonToNativeInternalNode.executeNewRefUncached(result); } @CApiBuiltin(ret = PyObjectRawPointer, args = {PyObjectRawPointer, PyObjectRawPointer}, call = Direct) static long PySequence_Concat(long s1Ptr, long s2Ptr) { - Object s1 = NativeToPythonNode.executeRawUncached(s1Ptr); - Object s2 = NativeToPythonNode.executeRawUncached(s2Ptr); + Object s1 = NativeToPythonInternalNode.executeUncached(s1Ptr, false); + Object s2 = NativeToPythonInternalNode.executeUncached(s2Ptr, false); Object result = PySequenceConcatNode.executeUncached(s1, s2); - return PythonToNativeNewRefNode.executeLongUncached(result); + return PythonToNativeInternalNode.executeNewRefUncached(result); } @CApiBuiltin(ret = PyObjectRawPointer, args = {PyObjectRawPointer, PyObjectRawPointer}, call = Direct) static long PySequence_InPlaceConcat(long s1Ptr, long s2Ptr) { - Object s1 = NativeToPythonNode.executeRawUncached(s1Ptr); - Object s2 = NativeToPythonNode.executeRawUncached(s2Ptr); + Object s1 = NativeToPythonInternalNode.executeUncached(s1Ptr, false); + Object s2 = NativeToPythonInternalNode.executeUncached(s2Ptr, false); Object result = PySequenceInPlaceConcatNode.executeUncached(s1, s2); - return PythonToNativeNewRefNode.executeLongUncached(result); + return PythonToNativeInternalNode.executeNewRefUncached(result); } @CApiBuiltin(ret = Int, args = {PyObjectRawPointer, Py_ssize_t}, call = Ignored) @@ -563,7 +564,7 @@ static int GraalPyPrivate_Sequence_DelItem(long oPtr, long i) { if ((int) i != i) { throw PRaiseNode.raiseStatic(null, PythonErrorType.OverflowError, ErrorMessages.CANNOT_FIT_P_INTO_INDEXSIZED_INT, i); } - Object o = NativeToPythonNode.executeRawUncached(oPtr); + Object o = NativeToPythonInternalNode.executeUncached(oPtr, false); PySequenceDelItemNode.executeUncached(o, (int) i); return 0; } @@ -573,23 +574,23 @@ static long GraalPyPrivate_Sequence_GetItem(long delegatePtr, long position) { if ((int) position != position) { throw PRaiseNode.raiseStatic(null, PythonErrorType.OverflowError, ErrorMessages.CANNOT_FIT_P_INTO_INDEXSIZED_INT, position); } - Object delegate = NativeToPythonNode.executeRawUncached(delegatePtr); + Object delegate = NativeToPythonInternalNode.executeUncached(delegatePtr, false); Object result = PySequenceGetItemNode.executeUncached(delegate, (int) position); - return PythonToNativeNewRefNode.executeLongUncached(result); + return PythonToNativeInternalNode.executeNewRefUncached(result); } @CApiBuiltin(ret = Py_ssize_t, args = {PyObjectRawPointer}, call = Ignored) static long GraalPyPrivate_Sequence_Size(long objPtr) { - Object obj = NativeToPythonNode.executeRawUncached(objPtr); + Object obj = NativeToPythonInternalNode.executeUncached(objPtr, false); return PySequenceSizeNode.executeUncached(obj); } @CApiBuiltin(ret = Int, args = {PyObjectRawPointer, Py_ssize_t, Py_ssize_t, PyObjectRawPointer}, call = Direct) static int PySequence_SetSlice(long sequencePtr, long iLow, long iHigh, long sPtr) { - Object sequence = NativeToPythonNode.executeRawUncached(sequencePtr); + Object sequence = NativeToPythonInternalNode.executeUncached(sequencePtr, false); TpSlots slots = GetObjectSlotsNode.executeUncached(sequence); if (slots.mp_ass_subscript() != null) { - Object s = NativeToPythonNode.executeRawUncached(sPtr); + Object s = NativeToPythonInternalNode.executeUncached(sPtr, false); PSlice slice = PySliceNew.executeUncached(iLow, iHigh, PNone.NONE); CallSlotMpAssSubscriptNode.executeUncached(slots.mp_ass_subscript(), sequence, slice, s); return 0; @@ -600,7 +601,7 @@ static int PySequence_SetSlice(long sequencePtr, long iLow, long iHigh, long sPt @CApiBuiltin(ret = Int, args = {PyObjectRawPointer, Py_ssize_t, Py_ssize_t}, call = Direct) static int PySequence_DelSlice(long sequencePtr, long iLow, long iHigh) { - Object sequence = NativeToPythonNode.executeRawUncached(sequencePtr); + Object sequence = NativeToPythonInternalNode.executeUncached(sequencePtr, false); TpSlots slots = GetObjectSlotsNode.executeUncached(sequence); if (slots.mp_ass_subscript() != null) { PSlice slice = PySliceNew.executeUncached(iLow, iHigh, PNone.NONE); @@ -613,15 +614,15 @@ static int PySequence_DelSlice(long sequencePtr, long iLow, long iHigh) { @CApiBuiltin(ret = Py_ssize_t, args = {PyObjectRawPointer, PyObjectRawPointer}, call = Direct) static long PySequence_Count(long haystackPtr, long needlePtr) { - Object haystack = NativeToPythonNode.executeRawUncached(haystackPtr); - Object needle = NativeToPythonNode.executeRawUncached(needlePtr); + Object haystack = NativeToPythonInternalNode.executeUncached(haystackPtr, false); + Object needle = NativeToPythonInternalNode.executeUncached(needlePtr, false); return PySequenceIterSearchNode.executeUncached(haystack, needle, PySequenceIterSearchNode.PY_ITERSEARCH_COUNT); } @CApiBuiltin(ret = Py_ssize_t, args = {PyObjectRawPointer, PyObjectRawPointer}, call = Direct) static long PySequence_Index(long haystackPtr, long needlePtr) { - Object haystack = NativeToPythonNode.executeRawUncached(haystackPtr); - Object needle = NativeToPythonNode.executeRawUncached(needlePtr); + Object haystack = NativeToPythonInternalNode.executeUncached(haystackPtr, false); + Object needle = NativeToPythonInternalNode.executeUncached(needlePtr, false); return PySequenceIterSearchNode.executeUncached(haystack, needle, PySequenceIterSearchNode.PY_ITERSEARCH_INDEX); } @@ -629,23 +630,23 @@ static long PySequence_Index(long haystackPtr, long needlePtr) { @CApiBuiltin(ret = PyObjectRawPointer, args = {PyObjectRawPointer, PyObjectRawPointer}, call = Direct) static long PyObject_GetItem(long objPtr, long keyPtr) { - Object obj = NativeToPythonNode.executeRawUncached(objPtr); - Object key = NativeToPythonNode.executeRawUncached(keyPtr); + Object obj = NativeToPythonInternalNode.executeUncached(objPtr, false); + Object key = NativeToPythonInternalNode.executeUncached(keyPtr, false); Object result = PyObjectGetItem.executeUncached(obj, key); - return PythonToNativeNewRefNode.executeLongUncached(result); + return PythonToNativeInternalNode.executeNewRefUncached(result); } @CApiBuiltin(name = "GraalPyPrivate_Object_GetItemString", ret = PyObjectRawPointer, args = {PyObjectRawPointer, ConstCharPtr}, call = Ignored) static long GraalPyPrivate_Object_GetItemString(long objPtr, long keyPtr) { - Object obj = NativeToPythonNode.executeRawUncached(objPtr); - Object key = CharPtrToPythonNode.getUncached().execute(keyPtr); + Object obj = NativeToPythonInternalNode.executeUncached(objPtr, false); + Object key = CharPtrToPythonNode.executeUncached(keyPtr); Object result = PyObjectGetItem.executeUncached(obj, key); - return PythonToNativeNewRefNode.executeLongUncached(result); + return PythonToNativeInternalNode.executeNewRefUncached(result); } @CApiBuiltin(ret = Py_ssize_t, args = {PyObjectRawPointer}, call = Ignored) static long GraalPyPrivate_Object_Size(long objPtr) { - Object obj = NativeToPythonNode.executeRawUncached(objPtr); + Object obj = NativeToPythonInternalNode.executeUncached(objPtr, false); // Native objects are handled in C assert !(obj instanceof PythonAbstractNativeObject); // TODO: theoretically, it is legal for __LEN__ to return a PythonNativeVoidPtr, @@ -655,7 +656,7 @@ static long GraalPyPrivate_Object_Size(long objPtr) { @CApiBuiltin(ret = Py_ssize_t, args = {PyObjectRawPointer, Py_ssize_t}, call = Direct) static long PyObject_LengthHint(long objPtr, long defaultValue) { - Object obj = NativeToPythonNode.executeRawUncached(objPtr); + Object obj = NativeToPythonInternalNode.executeUncached(objPtr, false); int len = IteratorNodes.GetLength.executeUncached(obj); if (len == -1) { return defaultValue; @@ -667,7 +668,7 @@ static long PyObject_LengthHint(long objPtr, long defaultValue) { @CApiBuiltin(ret = PyObjectRawPointer, args = {PyObjectRawPointer}, call = Direct) static long PyMapping_Keys(long objPtr) { - Object obj = NativeToPythonNode.executeRawUncached(objPtr); + Object obj = NativeToPythonInternalNode.executeUncached(objPtr, false); checkNonNullArgUncached(obj); ConstructListNode listNode = ConstructListNode.getUncached(); Object listResult; @@ -680,12 +681,12 @@ static long PyMapping_Keys(long objPtr) { Object view = CallNode.executeUncached(callable); listResult = listNode.execute(null, view); } - return PythonToNativeNewRefNode.executeLongUncached(listResult); + return PythonToNativeInternalNode.executeNewRefUncached(listResult); } @CApiBuiltin(ret = PyObjectRawPointer, args = {PyObjectRawPointer}, call = Direct) static long PyMapping_Items(long objPtr) { - Object obj = NativeToPythonNode.executeRawUncached(objPtr); + Object obj = NativeToPythonInternalNode.executeUncached(objPtr, false); checkNonNullArgUncached(obj); ConstructListNode listNode = ConstructListNode.getUncached(); Object listResult; @@ -698,12 +699,12 @@ static long PyMapping_Items(long objPtr) { Object view = CallNode.executeUncached(callable); listResult = listNode.execute(null, view); } - return PythonToNativeNewRefNode.executeLongUncached(listResult); + return PythonToNativeInternalNode.executeNewRefUncached(listResult); } @CApiBuiltin(ret = PyObjectRawPointer, args = {PyObjectRawPointer}, call = Direct) static long PyMapping_Values(long objPtr) { - Object obj = NativeToPythonNode.executeRawUncached(objPtr); + Object obj = NativeToPythonInternalNode.executeUncached(objPtr, false); checkNonNullArgUncached(obj); ConstructListNode listNode = ConstructListNode.getUncached(); Object listResult; @@ -716,12 +717,12 @@ static long PyMapping_Values(long objPtr) { Object view = CallNode.executeUncached(callable); listResult = listNode.execute(null, view); } - return PythonToNativeNewRefNode.executeLongUncached(listResult); + return PythonToNativeInternalNode.executeNewRefUncached(listResult); } @CApiBuiltin(ret = Py_ssize_t, args = {PyObjectRawPointer}, call = Ignored) static long GraalPyPrivate_Mapping_Size(long objPtr) { - Object obj = NativeToPythonNode.executeRawUncached(objPtr); + Object obj = NativeToPythonInternalNode.executeUncached(objPtr, false); Object cls = GetClassNode.executeUncached(obj); if (IsSameTypeNode.executeUncached(cls, PythonBuiltinClassType.PSet) || IsSameTypeNode.executeUncached(cls, PythonBuiltinClassType.PFrozenSet) || @@ -735,13 +736,13 @@ static long GraalPyPrivate_Mapping_Size(long objPtr) { @CApiBuiltin(ret = PyObjectRawPointer, args = {PyObjectRawPointer}, call = Direct) static long PyIter_Next(long iteratorPtr) { - Object iterator = NativeToPythonNode.executeRawUncached(iteratorPtr); + Object iterator = NativeToPythonInternalNode.executeUncached(iteratorPtr, false); try { Object result = PyIterNextNode.executeUncached(iterator); if (result == NATIVE_NULL) { return NULLPTR; } - return PythonToNativeNewRefNode.executeLongUncached(result); + return PythonToNativeInternalNode.executeNewRefUncached(result); } catch (IteratorExhausted e) { return NULLPTR; } @@ -749,15 +750,15 @@ static long PyIter_Next(long iteratorPtr) { @CApiBuiltin(ret = PyObjectRawPointer, args = {PyObjectRawPointer, PyObjectRawPointer}, call = Ignored) static long GraalPyPrivate_Iter_Send(long iterPtr, long argPtr) { - Object iter = NativeToPythonNode.executeRawUncached(iterPtr); - Object arg = NativeToPythonNode.executeRawUncached(argPtr); + Object iter = NativeToPythonInternalNode.executeUncached(iterPtr, false); + Object arg = NativeToPythonInternalNode.executeUncached(argPtr, false); if (arg instanceof PNone && PyIterCheckNode.executeUncached(iter)) { try { Object result = PyIterNextNode.executeUncached(iter); if (result == NATIVE_NULL) { return NULLPTR; } - return PythonToNativeNewRefNode.executeLongUncached(result); + return PythonToNativeInternalNode.executeNewRefUncached(result); } catch (IteratorExhausted e) { return NULLPTR; } @@ -767,7 +768,7 @@ static long GraalPyPrivate_Iter_Send(long iterPtr, long argPtr) { if (result == NATIVE_NULL) { return NULLPTR; } - return PythonToNativeNewRefNode.executeLongUncached(result); + return PythonToNativeInternalNode.executeNewRefUncached(result); } catch (PException e) { e.expectStopIteration(null, IsBuiltinObjectProfile.getUncached()); return NULLPTR; @@ -776,7 +777,7 @@ static long GraalPyPrivate_Iter_Send(long iterPtr, long argPtr) { @CApiBuiltin(ret = ConstCharPtr, args = {PyObjectRawPointer}, call = Direct) static long PyObject_GetDoc(long objPtr) { - Object obj = NativeToPythonNode.executeRawUncached(objPtr); + Object obj = NativeToPythonInternalNode.executeUncached(objPtr, false); try { Object doc = PyObjectLookupAttr.executeUncached(obj, T___DOC__); if (!(doc instanceof PNone)) { @@ -790,8 +791,8 @@ static long PyObject_GetDoc(long objPtr) { @CApiBuiltin(ret = Int, args = {PyObjectRawPointer, ConstCharPtr}, call = Direct) static int PyObject_SetDoc(long objPtr, long valuePtr) { - Object obj = NativeToPythonNode.executeRawUncached(objPtr); - Object value = CharPtrToPythonNode.getUncached().execute(valuePtr); + Object obj = NativeToPythonInternalNode.executeUncached(objPtr, false); + Object value = CharPtrToPythonNode.executeUncached(valuePtr); if (obj instanceof PBuiltinFunction builtinFunction) { CFunctionDocUtils.writeDocAndTextSignature(builtinFunction, builtinFunction.getName(), value); return 1; diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextArrayBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextArrayBuiltins.java index 27c49c2664..47fc8ebd6a 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextArrayBuiltins.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextArrayBuiltins.java @@ -60,8 +60,8 @@ import com.oracle.graal.python.builtins.objects.array.ArrayNodes; import com.oracle.graal.python.builtins.objects.array.PArray; import com.oracle.graal.python.builtins.objects.buffer.BufferFlags; -import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativeToPythonNode; -import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeNewRefNode; +import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativeToPythonInternalNode; +import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeInternalNode; import com.oracle.graal.python.builtins.objects.cext.structs.CFields; import com.oracle.graal.python.builtins.objects.cext.structs.CStructAccess; import com.oracle.graal.python.builtins.objects.cext.structs.CStructAccess.WriteTruffleStringNode; @@ -96,7 +96,7 @@ static int GraalPyPrivate_Array_getbuffer(long arrayPtr, long pyBufferPtr, int f PArray array = expectArray(arrayPtr, "GraalPyPrivate_Array_getbuffer"); long bufPtr = ArrayNodes.EnsureNativeStorageNode.executeUncached(array).getPtr(); writePtrField(pyBufferPtr, CFields.Py_buffer__buf, bufPtr); - writePtrField(pyBufferPtr, CFields.Py_buffer__obj, PythonToNativeNewRefNode.executeLongUncached(array)); + writePtrField(pyBufferPtr, CFields.Py_buffer__obj, PythonToNativeInternalNode.executeNewRefUncached(array)); writeLongField(pyBufferPtr, CFields.Py_buffer__len, array.getBytesLength()); writeIntField(pyBufferPtr, CFields.Py_buffer__readonly, 0); writeIntField(pyBufferPtr, CFields.Py_buffer__ndim, 1); @@ -141,7 +141,7 @@ static void GraalPyPrivate_Array_releasebuffer(long arrayPtr, long pyBufferPtr) } private static PArray expectArray(long arrayPtr, String where) { - Object obj = NativeToPythonNode.executeRawUncached(arrayPtr); + Object obj = NativeToPythonInternalNode.executeUncached(arrayPtr, false); if (CompilerDirectives.injectBranchProbability(CompilerDirectives.UNLIKELY_PROBABILITY, !(obj instanceof PArray))) { throw PythonCextBuiltins.badInternalCall(where, "arrayPtr"); } diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextBoolBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextBoolBuiltins.java index 19e1def9b8..9789c30947 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextBoolBuiltins.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextBoolBuiltins.java @@ -44,6 +44,7 @@ import static com.oracle.graal.python.builtins.objects.cext.capi.transitions.ArgDescriptor.PyObjectRawPointer; import com.oracle.graal.python.builtins.modules.cext.PythonCextBuiltins.CApiBuiltin; +import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.EnsurePythonObjectNode; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeInternalNode; import com.oracle.graal.python.runtime.PythonContext; @@ -53,11 +54,15 @@ public final class PythonCextBoolBuiltins { // matters, but keeping their codesize small still makes sense. @CApiBuiltin(ret = PyObjectRawPointer, call = Ignored, acquireGil = false, canRaise = false) public static long GraalPyPrivate_True() { - return PythonToNativeInternalNode.executeUncached(PythonContext.get(null).getTrue(), true); + Object trueValue = PythonContext.get(null).getTrue(); + assert EnsurePythonObjectNode.doesNotNeedPromotion(trueValue); + return PythonToNativeInternalNode.executeUncached(trueValue, true); } @CApiBuiltin(ret = PyObjectRawPointer, call = Ignored, acquireGil = false, canRaise = false) public static long GraalPyPrivate_False() { - return PythonToNativeInternalNode.executeUncached(PythonContext.get(null).getFalse(), true); + Object falseValue = PythonContext.get(null).getFalse(); + assert EnsurePythonObjectNode.doesNotNeedPromotion(falseValue); + return PythonToNativeInternalNode.executeUncached(falseValue, true); } } diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextBuiltins.java index b7795d519a..ab1197fa51 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextBuiltins.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextBuiltins.java @@ -136,8 +136,7 @@ import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.HandlePointerConverter; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativeToPythonClassInternalNode; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativeToPythonInternalNode; -import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativeToPythonNode; -import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeNewRefNode; +import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeInternalNode; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.UpdateHandleTableReferenceNode; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.ToNativeTypeNode; import com.oracle.graal.python.builtins.objects.cext.common.CExtCommonNodes.TransformPExceptionToNativeCachedNode; @@ -730,7 +729,7 @@ public Object execute(Object[] arguments) { private void castArguments(Object[] arguments, Object[] argCast) { for (int i = 0; i < argNodes.length; i++) { Object arg = arguments[i]; - argCast[i] = argNodes[i] == null ? arg : argNodes[i].execute(arg); + argCast[i] = argNodes[i] == null ? arg : argNodes[i].execute((Long) arg); } } } @@ -842,7 +841,7 @@ public enum CApiCallPath { @CApiBuiltin(ret = PyObjectRawPointer, call = Ignored) static long GraalPyPrivate_FileSystemDefaultEncoding() { - return PythonToNativeNewRefNode.executeLongUncached(GetFileSystemEncodingNode.getFileSystemEncoding()); + return PythonToNativeInternalNode.executeNewRefUncached(GetFileSystemEncodingNode.getFileSystemEncoding()); } private static final TruffleString[] TYPE_LOOKUP_MODULES = new TruffleString[]{ @@ -852,17 +851,17 @@ static long GraalPyPrivate_FileSystemDefaultEncoding() { @CApiBuiltin(ret = PyTypeObjectRawPointer, args = {ConstCharPtr}, call = Ignored) static long GraalPyPrivate_Type(long typeNamePtr) { - TruffleString typeName = (TruffleString) CharPtrToPythonNode.getUncached().execute(typeNamePtr); + TruffleString typeName = (TruffleString) CharPtrToPythonNode.executeUncached(typeNamePtr); Python3Core core = PythonContext.get(null).getCore(); for (PythonBuiltinClassType type : PythonBuiltinClassType.VALUES) { if (type.getName().equalsUncached(typeName, TS_ENCODING)) { - return PythonToNativeNewRefNode.executeLongUncached(core.lookupType(type)); + return PythonToNativeInternalNode.executeNewRefUncached(core.lookupType(type)); } } for (TruffleString module : TYPE_LOOKUP_MODULES) { Object attribute = core.lookupBuiltinModule(module).getAttribute(typeName); if (attribute != PNone.NO_VALUE) { - return PythonToNativeNewRefNode.executeLongUncached(attribute); + return PythonToNativeInternalNode.executeNewRefUncached(attribute); } } throw PRaiseNode.raiseStatic(null, PythonErrorType.KeyError, ErrorMessages.APOSTROPHE_S, typeName); @@ -992,12 +991,12 @@ public static void GraalPyPrivate_NotifyTypeReady(long pointer) { @CApiBuiltin(ret = PyFrameObjectRawPointer, args = {PyThreadState, PyCodeObjectRawPointer, PyObjectRawPointer, PyObjectRawPointer}, call = Direct) static long PyFrame_New(long threadState, long codePtr, long globalsPtr, long localsPtr) { - PCode code = (PCode) NativeToPythonNode.executeRawUncached(codePtr); - PythonObject globals = (PythonObject) NativeToPythonNode.executeRawUncached(globalsPtr); - Object locals = localsPtr == NULLPTR ? null : NativeToPythonNode.executeRawUncached(localsPtr); + PCode code = (PCode) NativeToPythonInternalNode.executeUncached(codePtr, false); + PythonObject globals = (PythonObject) NativeToPythonInternalNode.executeUncached(globalsPtr, false); + Object locals = localsPtr == NULLPTR ? null : NativeToPythonInternalNode.executeUncached(localsPtr, false); PythonLanguage language = PythonLanguage.get(null); Object frameLocals = locals == null || PGuards.isPNone(locals) ? PFactory.createDict(language) : locals; - return PythonToNativeNewRefNode.executeLongUncached(PFactory.createPFrame(language, threadState, code, globals, frameLocals)); + return PythonToNativeInternalNode.executeNewRefUncached(PFactory.createPFrame(language, threadState, code, globals, frameLocals)); } @CApiBuiltin(ret = PyObjectRawPointer, args = {Pointer, PyObjectRawPointer, Py_ssize_t, Int, Py_ssize_t, ConstCharPtr, Int, Pointer, Pointer, Pointer, Pointer}, call = Ignored) @@ -1006,8 +1005,8 @@ static long GraalPyPrivate_MemoryViewFromBuffer(long bufferStructPointer, long o int itemsize = CastToJavaIntExactNode.executeUncached(itemsizeArg); int len = CastToJavaIntExactNode.executeUncached(lenArg); boolean readonly = readonlyArg != 0; - Object owner = ownerPtr == NULLPTR ? null : NativeToPythonNode.executeRawUncached(ownerPtr); - TruffleString format = (TruffleString) CharPtrToPythonNode.getUncached().execute(formatPtr); + Object owner = ownerPtr == NULLPTR ? null : NativeToPythonInternalNode.executeUncached(ownerPtr, false); + TruffleString format = (TruffleString) CharPtrToPythonNode.executeUncached(formatPtr); int[] shape = null; int[] strides = null; int[] suboffsets = null; @@ -1036,7 +1035,7 @@ static long GraalPyPrivate_MemoryViewFromBuffer(long bufferStructPointer, long o Object memoryView = PFactory.createMemoryView(PythonLanguage.get(null), PythonContext.get(null), bufferLifecycleManager, buffer, owner, len, readonly, itemsize, BufferFormat.forMemoryView(format, TruffleString.CodePointLengthNode.getUncached(), TruffleString.CodePointAtIndexUTF32Node.getUncached()), format, ndim, bufPointer, 0, shape, strides, suboffsets, flags); - return PythonToNativeNewRefNode.executeLongUncached(memoryView); + return PythonToNativeInternalNode.executeNewRefUncached(memoryView); } private static int[] readLongArrayElementsAsInts(long pointer, int elements) { @@ -1451,7 +1450,7 @@ static int GraalPyPrivate_Native_Options() { @CApiBuiltin(ret = Void, args = {Int, ConstCharPtr}, call = Ignored) @TruffleBoundary static void GraalPyPrivate_LogString(int level, long messagePtr) { - TruffleString message = (TruffleString) CharPtrToPythonNode.getUncached().execute(messagePtr); + TruffleString message = (TruffleString) CharPtrToPythonNode.executeUncached(messagePtr); String msg = message.toJavaStringUncached(); switch (level) { case GRAALPY_LOG_INFO: @@ -1652,7 +1651,7 @@ private static PythonManagedClass lookupBuiltinTypeWithName(PythonContext contex @CApiBuiltin(ret = CHAR_PTR, args = {PyObjectRawPointer}, call = Ignored) static long GraalPyPrivate_GetMMapData(long objectPtr) { - PMMap object = (PMMap) NativeToPythonNode.executeRawUncached(objectPtr); + PMMap object = (PMMap) NativeToPythonInternalNode.executeUncached(objectPtr, false); PythonContext context = PythonContext.get(null); try { return PosixSupportLibrary.getUncached().mmapGetPointer(context.getPosixSupport(), object.getPosixSupportHandle()); diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextByteArrayBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextByteArrayBuiltins.java index f87d137d5d..5fad4c1e0c 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextByteArrayBuiltins.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextByteArrayBuiltins.java @@ -50,7 +50,7 @@ import com.oracle.graal.python.builtins.objects.bytes.PByteArray; import com.oracle.graal.python.builtins.objects.cext.PythonAbstractNativeObject; import com.oracle.graal.python.builtins.objects.cext.capi.PySequenceArrayWrapper; -import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativeToPythonNode; +import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativeToPythonInternalNode; import com.oracle.graal.python.builtins.objects.cext.structs.CFields; import com.oracle.graal.python.nodes.ErrorMessages; import com.oracle.graal.python.nodes.PRaiseNode; @@ -62,7 +62,7 @@ public final class PythonCextByteArrayBuiltins { @CApiBuiltin(ret = CHAR_PTR, args = {PyObjectRawPointer}, call = Direct) static long PyByteArray_AsString(long bytesPtr) { - Object obj = NativeToPythonNode.executeRawUncached(bytesPtr); + Object obj = NativeToPythonInternalNode.executeUncached(bytesPtr, false); if (obj instanceof PByteArray bytes) { return PySequenceArrayWrapper.ensureNativeSequence(bytes); } diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextBytesBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextBytesBuiltins.java index 213e9842f5..2932059be8 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextBytesBuiltins.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextBytesBuiltins.java @@ -72,8 +72,8 @@ import com.oracle.graal.python.builtins.objects.bytes.PBytesLike; import com.oracle.graal.python.builtins.objects.cext.PythonAbstractNativeObject; import com.oracle.graal.python.builtins.objects.cext.capi.PySequenceArrayWrapper; -import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativeToPythonNode; -import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeNewRefNode; +import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativeToPythonInternalNode; +import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeInternalNode; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.ArgDescriptor; import com.oracle.graal.python.builtins.objects.cext.structs.CFields; import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes.GetItemScalarNode; @@ -109,7 +109,7 @@ public final class PythonCextBytesBuiltins { */ @CApiBuiltin(ret = Py_ssize_t, args = {PyObjectRawPointer}, call = Direct) static long PyBytes_Size(long objPtr) { - Object obj = NativeToPythonNode.executeRawUncached(objPtr); + Object obj = NativeToPythonInternalNode.executeUncached(objPtr, false); if (obj instanceof PBytes bytes) { return PyObjectSizeNode.executeUncached(bytes); } @@ -121,10 +121,10 @@ static long PyBytes_Size(long objPtr) { @CApiBuiltin(ret = PyObjectRawPointer, args = {PyObjectRawPointer, PyObjectRawPointer}, call = Ignored) static long GraalPyPrivate_Bytes_Concat(long originalPtr, long newPartPtr) { - Object original = NativeToPythonNode.executeRawUncached(originalPtr); - Object newPart = NativeToPythonNode.executeRawUncached(newPartPtr); + Object original = NativeToPythonInternalNode.executeUncached(originalPtr, false); + Object newPart = NativeToPythonInternalNode.executeUncached(newPartPtr, false); Object result = BytesCommonBuiltins.ConcatNode.executeUncached(original, newPart); - return PythonToNativeNewRefNode.executeLongUncached(result); + return PythonToNativeInternalNode.executeNewRefUncached(result); } // TODO(CAPI STATIC): uses nodes without @GenerateUncached @@ -171,7 +171,7 @@ static long GraalPyPrivate_Bytes_FromStringAndSize(long nativePointer, long size try { byte[] bytes = getByteArray(nativePointer, size); Object result = PFactory.createBytes(PythonLanguage.get(null), bytes); - return PythonToNativeNewRefNode.executeLongUncached(result); + return PythonToNativeInternalNode.executeNewRefUncached(result); } catch (OverflowException e) { throw PRaiseNode.raiseStatic(null, PythonErrorType.SystemError, ErrorMessages.NEGATIVE_SIZE_PASSED); } @@ -182,7 +182,7 @@ static long GraalPyPrivate_ByteArray_FromStringAndSize(long nativePointer, long try { byte[] bytes = getByteArray(nativePointer, size); Object result = PFactory.createByteArray(PythonLanguage.get(null), bytes); - return PythonToNativeNewRefNode.executeLongUncached(result); + return PythonToNativeInternalNode.executeNewRefUncached(result); } catch (OverflowException e) { throw PRaiseNode.raiseStatic(null, PythonErrorType.SystemError, ErrorMessages.NEGATIVE_SIZE_PASSED); } @@ -191,7 +191,7 @@ static long GraalPyPrivate_ByteArray_FromStringAndSize(long nativePointer, long @CApiBuiltin(name = "PyByteArray_Resize", ret = Int, args = {PyObjectRawPointer, Py_ssize_t}, call = Direct) @CApiBuiltin(ret = Int, args = {PyObjectRawPointer, Py_ssize_t}, call = Ignored) static int GraalPyPrivate_Bytes_Resize(long selfPtr, long newSizeL) { - Object self = NativeToPythonNode.executeRawUncached(selfPtr); + Object self = NativeToPythonInternalNode.executeUncached(selfPtr, false); if (CompilerDirectives.injectBranchProbability(CompilerDirectives.SLOWPATH_PROBABILITY, !(self instanceof PBytesLike))) { throw PRaiseNode.raiseStatic(null, SystemError, ErrorMessages.EXPECTED_S_NOT_P, "a bytes object", self); } @@ -212,7 +212,7 @@ static int GraalPyPrivate_Bytes_Resize(long selfPtr, long newSizeL) { static long GraalPyPrivate_Bytes_EmptyWithCapacity(long size) { try { Object result = PFactory.createBytes(PythonLanguage.get(null), new byte[PInt.intValueExact(size)]); - return PythonToNativeNewRefNode.executeLongUncached(result); + return PythonToNativeInternalNode.executeNewRefUncached(result); } catch (OverflowException e) { throw PRaiseNode.raiseStatic(null, IndexError, ErrorMessages.CANNOT_FIT_P_INTO_INDEXSIZED_INT, size); } @@ -220,14 +220,14 @@ static long GraalPyPrivate_Bytes_EmptyWithCapacity(long size) { @CApiBuiltin(ret = PyObjectRawPointer, call = Ignored) static long GraalPyPrivate_Bytes_Empty() { - return PythonToNativeNewRefNode.executeLongUncached(PFactory.createEmptyBytes(PythonLanguage.get(null))); + return PythonToNativeInternalNode.executeNewRefUncached(PFactory.createEmptyBytes(PythonLanguage.get(null))); } @CApiBuiltin(ret = PyObjectRawPointer, args = {Py_ssize_t}, call = Ignored) static long GraalPyPrivate_ByteArray_EmptyWithCapacity(long size) { try { Object result = PFactory.createByteArray(PythonLanguage.get(null), new byte[PInt.intValueExact(size)]); - return PythonToNativeNewRefNode.executeLongUncached(result); + return PythonToNativeInternalNode.executeNewRefUncached(result); } catch (OverflowException e) { throw PRaiseNode.raiseStatic(null, IndexError, ErrorMessages.CANNOT_FIT_P_INTO_INDEXSIZED_INT, size); } @@ -235,7 +235,7 @@ static long GraalPyPrivate_ByteArray_EmptyWithCapacity(long size) { @CApiBuiltin(ret = Int, args = {PyObjectRawPointer}, call = CApiCallPath.Ignored) static int GraalPyPrivate_Bytes_CheckEmbeddedNull(long bytesPtr) { - Object bytes = NativeToPythonNode.executeRawUncached(bytesPtr); + Object bytes = NativeToPythonInternalNode.executeUncached(bytesPtr, false); SequenceStorage sequenceStorage = GetBytesStorage.executeUncached(bytes); int len = sequenceStorage.length(); try { @@ -252,7 +252,7 @@ static int GraalPyPrivate_Bytes_CheckEmbeddedNull(long bytesPtr) { @CApiBuiltin(ret = CHAR_PTR, args = {PyObjectRawPointer}, call = Direct) static long PyBytes_AsString(long bytesPtr) { - Object obj = NativeToPythonNode.executeRawUncached(bytesPtr); + Object obj = NativeToPythonInternalNode.executeUncached(bytesPtr, false); if (obj instanceof PBytes bytes) { return PySequenceArrayWrapper.ensureNativeSequence(bytes); } diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextCEvalBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextCEvalBuiltins.java index 377c87dcc1..f6fa50d2de 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextCEvalBuiltins.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextCEvalBuiltins.java @@ -59,8 +59,8 @@ import com.oracle.graal.python.builtins.objects.cell.PCell; import com.oracle.graal.python.builtins.objects.cext.capi.CApiContext; import com.oracle.graal.python.builtins.objects.cext.capi.ExternalFunctionNodes.ToNativeBorrowedNode; -import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativeToPythonNode; -import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeNewRefNode; +import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativeToPythonInternalNode; +import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeInternalNode; import com.oracle.graal.python.builtins.objects.cext.structs.CStructAccess; import com.oracle.graal.python.builtins.objects.code.CodeNodes; import com.oracle.graal.python.builtins.objects.code.PCode; @@ -130,11 +130,11 @@ static long PyEval_GetFrame() { static long GraalPyPrivate_Eval_EvalCodeEx(long codePtr, long globalsPtr, long localsPtr, long argumentArrayPtr, int argumentCount, long kwsPtr, int kwsCount, long defaultValueArrayPtr, int defaultValueCount, long kwdefaultsWrapperPtr, long closureObjPtr) { - PCode code = (PCode) NativeToPythonNode.executeRawUncached(codePtr); - PythonObject globals = (PythonObject) NativeToPythonNode.executeRawUncached(globalsPtr); - Object locals = NativeToPythonNode.executeRawUncached(localsPtr); - Object kwdefaultsWrapper = NativeToPythonNode.executeRawUncached(kwdefaultsWrapperPtr); - Object closureObj = NativeToPythonNode.executeRawUncached(closureObjPtr); + PCode code = (PCode) NativeToPythonInternalNode.executeUncached(codePtr, false); + PythonObject globals = (PythonObject) NativeToPythonInternalNode.executeUncached(globalsPtr, false); + Object locals = NativeToPythonInternalNode.executeUncached(localsPtr, false); + Object kwdefaultsWrapper = NativeToPythonInternalNode.executeUncached(kwdefaultsWrapperPtr, false); + Object closureObj = NativeToPythonInternalNode.executeUncached(closureObjPtr, false); Object[] defaults = CStructAccess.ReadObjectNode.getUncached().readPyObjectArray(defaultValueArrayPtr, defaultValueCount); if (!PGuards.isPNone(kwdefaultsWrapper) && !PGuards.isDict(kwdefaultsWrapper)) { throw PRaiseNode.raiseStatic(null, SystemError, ErrorMessages.BAD_ARG_TO_INTERNAL_FUNC); @@ -167,7 +167,7 @@ static long GraalPyPrivate_Eval_EvalCodeEx(long codePtr, long globalsPtr, long l RootCallTarget rootCallTarget = CodeNodes.GetCodeCallTargetNode.executeUncached(code); Object result = CallDispatchers.SimpleIndirectInvokeNode.executeUncached(rootCallTarget, pArguments); - return PythonToNativeNewRefNode.executeLongUncached(result); + return PythonToNativeInternalNode.executeNewRefUncached(result); } @CApiBuiltin(ret = PyObjectBorrowed, args = {}, call = Direct) diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextCapsuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextCapsuleBuiltins.java index 3c1797fc5d..7219847e73 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextCapsuleBuiltins.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextCapsuleBuiltins.java @@ -61,8 +61,8 @@ import com.oracle.graal.python.builtins.modules.cext.PythonCextCapsuleBuiltinsFactory.PyCapsuleNewNodeGen; import com.oracle.graal.python.builtins.objects.capsule.PyCapsule; import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.FromCharPointerNode; -import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativeToPythonNode; -import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeNewRefNode; +import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativeToPythonInternalNode; +import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeInternalNode; import com.oracle.graal.python.nodes.PRaiseNode; import com.oracle.graal.python.nodes.StringLiterals; import com.oracle.graal.python.nodes.attributes.ReadAttributeFromObjectNode; @@ -85,7 +85,7 @@ public final class PythonCextCapsuleBuiltins { @CApiBuiltin(ret = PyObjectRawPointer, args = {Pointer, ConstCharPtr, PY_CAPSULE_DESTRUCTOR}, call = Direct) static long PyCapsule_New(long pointer, long namePtr, long destructor) { PyCapsule capsule = PyCapsuleNewNode.executeUncached(pointer, namePtr, destructor); - return PythonToNativeNewRefNode.executeLongUncached(capsule); + return PythonToNativeInternalNode.executeNewRefUncached(capsule); } @GenerateCached(false) @@ -117,7 +117,7 @@ static PyCapsule doGeneric(Node inliningTarget, long pointer, long namePtr, long @CApiBuiltin(ret = Int, args = {PyObjectRawPointer, ConstCharPtr}, call = Direct) static int PyCapsule_IsValid(long oPtr, long namePtr) { - Object obj = NativeToPythonNode.executeRawUncached(oPtr); + Object obj = NativeToPythonInternalNode.executeUncached(oPtr, false); if (!(obj instanceof PyCapsule capsule)) { return 0; } @@ -132,7 +132,7 @@ static int PyCapsule_IsValid(long oPtr, long namePtr) { @CApiBuiltin(ret = Pointer, args = {PyObjectRawPointer, ConstCharPtr}, call = Direct) static long PyCapsule_GetPointer(long oPtr, long namePtr) { - Object capsule = NativeToPythonNode.executeRawUncached(oPtr); + Object capsule = NativeToPythonInternalNode.executeUncached(oPtr, false); return PyCapsuleGetPointerNode.executeUncached(capsule, namePtr); } @@ -285,7 +285,7 @@ static boolean capsuleNameMatches(long name1, long name2) { } private static PyCapsule expectCapsule(long oPtr, String builtinName) { - Object obj = NativeToPythonNode.executeRawUncached(oPtr); + Object obj = NativeToPythonInternalNode.executeUncached(oPtr, false); if (CompilerDirectives.injectBranchProbability(CompilerDirectives.SLOWPATH_PROBABILITY, !(obj instanceof PyCapsule capsule) || capsule.getPointer() == NULLPTR)) { throw PRaiseNode.raiseStatic(null, ValueError, CALLED_WITH_INVALID_PY_CAPSULE_OBJECT, builtinName); } diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextClassBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextClassBuiltins.java index b296f7dcb6..37ba4ef181 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextClassBuiltins.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextClassBuiltins.java @@ -47,29 +47,29 @@ import com.oracle.graal.python.PythonLanguage; import com.oracle.graal.python.builtins.modules.cext.PythonCextBuiltins.CApiBuiltin; import com.oracle.graal.python.builtins.objects.method.PDecoratedMethod; -import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativeToPythonNode; -import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeNewRefNode; +import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativeToPythonInternalNode; +import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeInternalNode; import com.oracle.graal.python.runtime.object.PFactory; public final class PythonCextClassBuiltins { @CApiBuiltin(ret = PyObjectRawPointer, args = {PyObjectRawPointer}, call = Direct) static long PyInstanceMethod_New(long funcPtr) { - Object func = NativeToPythonNode.executeRawUncached(funcPtr); + Object func = NativeToPythonInternalNode.executeUncached(funcPtr, false); checkNonNullArgUncached(func); PDecoratedMethod res = PFactory.createInstancemethod(PythonLanguage.get(null)); res.setCallable(func); - return PythonToNativeNewRefNode.executeLongUncached(res); + return PythonToNativeInternalNode.executeNewRefUncached(res); } @CApiBuiltin(ret = PyObjectRawPointer, args = {PyObjectRawPointer, PyObjectRawPointer}, call = Direct) static long PyMethod_New(long funcPtr, long selfPtr) { - Object func = NativeToPythonNode.executeRawUncached(funcPtr); - Object self = NativeToPythonNode.executeRawUncached(selfPtr); + Object func = NativeToPythonInternalNode.executeUncached(funcPtr, false); + Object self = NativeToPythonInternalNode.executeUncached(selfPtr, false); checkNonNullArgUncached(func); checkNonNullArgUncached(self); // Note: CPython also constructs the object directly, without running the constructor or // checking the inputs. - return PythonToNativeNewRefNode.executeLongUncached(PFactory.createMethod(PythonLanguage.get(null), self, func)); + return PythonToNativeInternalNode.executeNewRefUncached(PFactory.createMethod(PythonLanguage.get(null), self, func)); } } diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextCodeBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextCodeBuiltins.java index 0b20c25166..5d6391ef4e 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextCodeBuiltins.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextCodeBuiltins.java @@ -54,8 +54,8 @@ import com.oracle.graal.python.builtins.objects.code.CodeNodes; import com.oracle.graal.python.builtins.objects.code.PCode; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.CharPtrToPythonNode; -import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativeToPythonNode; -import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeNewRefNode; +import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativeToPythonInternalNode; +import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeInternalNode; import com.oracle.graal.python.nodes.call.CallNode; import com.oracle.truffle.api.strings.TruffleString; @@ -67,17 +67,17 @@ static long PyUnstable_Code_NewWithPosOnlyArgs(int argcount, int posonlyargcount long namesPtr, long varnamesPtr, long freevarsPtr, long cellvarsPtr, long filenamePtr, long namePtr, long qualnamePtr, int firstlineno, long lnotabPtr, long exceptionTablePtr) { - Object code = NativeToPythonNode.executeRawUncached(codePtr); - Object consts = NativeToPythonNode.executeRawUncached(constsPtr); - Object names = NativeToPythonNode.executeRawUncached(namesPtr); - Object varnames = NativeToPythonNode.executeRawUncached(varnamesPtr); - Object freevars = NativeToPythonNode.executeRawUncached(freevarsPtr); - Object cellvars = NativeToPythonNode.executeRawUncached(cellvarsPtr); - Object filename = NativeToPythonNode.executeRawUncached(filenamePtr); - Object name = NativeToPythonNode.executeRawUncached(namePtr); - Object qualname = NativeToPythonNode.executeRawUncached(qualnamePtr); - Object lnotab = NativeToPythonNode.executeRawUncached(lnotabPtr); - Object exceptionTable = NativeToPythonNode.executeRawUncached(exceptionTablePtr); + Object code = NativeToPythonInternalNode.executeUncached(codePtr, false); + Object consts = NativeToPythonInternalNode.executeUncached(constsPtr, false); + Object names = NativeToPythonInternalNode.executeUncached(namesPtr, false); + Object varnames = NativeToPythonInternalNode.executeUncached(varnamesPtr, false); + Object freevars = NativeToPythonInternalNode.executeUncached(freevarsPtr, false); + Object cellvars = NativeToPythonInternalNode.executeUncached(cellvarsPtr, false); + Object filename = NativeToPythonInternalNode.executeUncached(filenamePtr, false); + Object name = NativeToPythonInternalNode.executeUncached(namePtr, false); + Object qualname = NativeToPythonInternalNode.executeUncached(qualnamePtr, false); + Object lnotab = NativeToPythonInternalNode.executeUncached(lnotabPtr, false); + Object exceptionTable = NativeToPythonInternalNode.executeUncached(exceptionTablePtr, false); /* * This rearranges the arguments (freevars, cellvars). */ @@ -90,19 +90,19 @@ static long PyUnstable_Code_NewWithPosOnlyArgs(int argcount, int posonlyargcount firstlineno, lnotab, exceptionTable, freevars, cellvars }; - return PythonToNativeNewRefNode.executeLongUncached(CallNode.executeUncached(PythonBuiltinClassType.PCode, args)); + return PythonToNativeInternalNode.executeNewRefUncached(CallNode.executeUncached(PythonBuiltinClassType.PCode, args)); } @CApiBuiltin(ret = PyCodeObjectRawPointer, args = {ConstCharPtr, ConstCharPtr, Int}, call = Direct) static long PyCode_NewEmpty(long filenamePtr, long funcnamePtr, int lineno) { - TruffleString filename = (TruffleString) CharPtrToPythonNode.getUncached().execute(filenamePtr); - TruffleString funcname = (TruffleString) CharPtrToPythonNode.getUncached().execute(funcnamePtr); - return PythonToNativeNewRefNode.executeLongUncached(createCodeNewEmpty(filename, funcname, lineno)); + TruffleString filename = (TruffleString) CharPtrToPythonNode.executeUncached(filenamePtr); + TruffleString funcname = (TruffleString) CharPtrToPythonNode.executeUncached(funcnamePtr); + return PythonToNativeInternalNode.executeNewRefUncached(createCodeNewEmpty(filename, funcname, lineno)); } @CApiBuiltin(ret = Int, args = {PyCodeObjectRawPointer, Int}, call = Direct) static int PyCode_Addr2Line(long codePtr, int lasti) { - PCode code = (PCode) NativeToPythonNode.executeRawUncached(codePtr); + PCode code = (PCode) NativeToPythonInternalNode.executeUncached(codePtr, false); if (lasti < 0) { return code.co_firstlineno(); } @@ -111,14 +111,14 @@ static int PyCode_Addr2Line(long codePtr, int lasti) { @CApiBuiltin(ret = PyObjectRawPointer, args = {PyCodeObjectRawPointer}, call = Direct) static long GraalPyCode_GetName(long codePtr) { - PCode code = (PCode) NativeToPythonNode.executeRawUncached(codePtr); - return PythonToNativeNewRefNode.executeLongUncached(code.getName()); + PCode code = (PCode) NativeToPythonInternalNode.executeUncached(codePtr, false); + return PythonToNativeInternalNode.executeNewRefUncached(code.getName()); } @CApiBuiltin(ret = PyObjectRawPointer, args = {PyCodeObjectRawPointer}, call = Direct) static long GraalPyCode_GetFileName(long codePtr) { - PCode code = (PCode) NativeToPythonNode.executeRawUncached(codePtr); - return PythonToNativeNewRefNode.executeLongUncached(code.getFilename()); + PCode code = (PCode) NativeToPythonInternalNode.executeUncached(codePtr, false); + return PythonToNativeInternalNode.executeNewRefUncached(code.getFilename()); } static PCode createCodeNewEmpty(TruffleString filename, TruffleString funcname, int lineno) { diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextCodecBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextCodecBuiltins.java index b270c93024..0f1ad26316 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextCodecBuiltins.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextCodecBuiltins.java @@ -48,7 +48,7 @@ import com.oracle.graal.python.builtins.modules.cext.PythonCextBuiltins.CApiBuiltin; import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.CharPtrToPythonNode; -import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeNewRefNode; +import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeInternalNode; import com.oracle.graal.python.builtins.objects.tuple.PTuple; import com.oracle.truffle.api.strings.TruffleString; @@ -56,15 +56,15 @@ public final class PythonCextCodecBuiltins { @CApiBuiltin(ret = PyObjectRawPointer, args = {ConstCharPtr}, call = Direct) static long PyCodec_Encoder(long encodingPtr) { - TruffleString encoding = (TruffleString) CharPtrToPythonNode.getUncached().execute(encodingPtr); + TruffleString encoding = (TruffleString) CharPtrToPythonNode.executeUncached(encodingPtr); PTuple codecInfo = CodecsModuleBuiltins.PyCodecLookupNode.executeUncached(encoding); - return PythonToNativeNewRefNode.executeLongUncached(SequenceStorageNodes.GetItemScalarNode.executeUncached(codecInfo.getSequenceStorage(), 0)); + return PythonToNativeInternalNode.executeNewRefUncached(SequenceStorageNodes.GetItemScalarNode.executeUncached(codecInfo.getSequenceStorage(), 0)); } @CApiBuiltin(ret = PyObjectRawPointer, args = {ConstCharPtr}, call = Direct) static long PyCodec_Decoder(long encodingPtr) { - TruffleString encoding = (TruffleString) CharPtrToPythonNode.getUncached().execute(encodingPtr); + TruffleString encoding = (TruffleString) CharPtrToPythonNode.executeUncached(encodingPtr); PTuple codecInfo = CodecsModuleBuiltins.PyCodecLookupNode.executeUncached(encoding); - return PythonToNativeNewRefNode.executeLongUncached(SequenceStorageNodes.GetItemScalarNode.executeUncached(codecInfo.getSequenceStorage(), 1)); + return PythonToNativeInternalNode.executeNewRefUncached(SequenceStorageNodes.GetItemScalarNode.executeUncached(codecInfo.getSequenceStorage(), 1)); } } diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextComplexBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextComplexBuiltins.java index ce73b60f22..975e7d3d28 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextComplexBuiltins.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextComplexBuiltins.java @@ -56,8 +56,8 @@ import com.oracle.graal.python.builtins.modules.cext.PythonCextBuiltins.CApiBinaryBuiltinNode; import com.oracle.graal.python.builtins.modules.cext.PythonCextBuiltins.CApiBuiltin; import com.oracle.graal.python.builtins.objects.PNone; -import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativeToPythonNode; -import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeNewRefNode; +import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativeToPythonInternalNode; +import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeInternalNode; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.ArgDescriptor; import com.oracle.graal.python.builtins.objects.cext.structs.CFields; import com.oracle.graal.python.builtins.objects.complex.ComplexBuiltins; @@ -101,7 +101,7 @@ static int doGeneric(Object obj, long out, @CApiBuiltin(ret = ArgDescriptor.Double, args = {PyObjectRawPointer}, call = Ignored) static double GraalPyPrivate_Complex_RealAsDouble(long objPtr) { - Object obj = NativeToPythonNode.executeRawUncached(objPtr); + Object obj = NativeToPythonInternalNode.executeUncached(objPtr, false); if (obj instanceof PComplex complex) { return complex.getReal(); } @@ -117,7 +117,7 @@ static double GraalPyPrivate_Complex_RealAsDouble(long objPtr) { @CApiBuiltin(ret = ArgDescriptor.Double, args = {PyObjectRawPointer}, call = Ignored) static double GraalPyPrivate_Complex_ImagAsDouble(long objPtr) { - Object obj = NativeToPythonNode.executeRawUncached(objPtr); + Object obj = NativeToPythonInternalNode.executeUncached(objPtr, false); if (obj instanceof PComplex complex) { return complex.getImag(); } @@ -129,6 +129,6 @@ static double GraalPyPrivate_Complex_ImagAsDouble(long objPtr) { @CApiBuiltin(ret = PyObjectRawPointer, args = {ArgDescriptor.Double, ArgDescriptor.Double}, call = Direct) static long PyComplex_FromDoubles(double r, double i) { - return PythonToNativeNewRefNode.executeLongUncached(PFactory.createComplex(PythonLanguage.get(null), r, i)); + return PythonToNativeInternalNode.executeNewRefUncached(PFactory.createComplex(PythonLanguage.get(null), r, i)); } } diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextContextBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextContextBuiltins.java index 63e70c3926..7eac1f8967 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextContextBuiltins.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextContextBuiltins.java @@ -56,8 +56,8 @@ import com.oracle.graal.python.builtins.objects.PNone; import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.PRaiseNativeNode; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.CharPtrToPythonNode; -import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativeToPythonNode; -import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeNewRefNode; +import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativeToPythonInternalNode; +import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeInternalNode; import com.oracle.graal.python.builtins.objects.contextvars.PContextVar; import com.oracle.graal.python.builtins.objects.contextvars.PContextVarsContext; import com.oracle.graal.python.lib.PyContextCopyCurrent; @@ -82,14 +82,14 @@ static long PyContextVar_New(long namePtr, long defPtr) { if (namePtr == NULLPTR) { return NULLPTR; } - TruffleString name = (TruffleString) CharPtrToPythonNode.getUncached().execute(namePtr); - Object def = defPtr == NULLPTR ? PNone.NO_VALUE : NativeToPythonNode.executeRawUncached(defPtr); - return PythonToNativeNewRefNode.executeLongUncached(CallNode.executeUncached(PythonBuiltinClassType.ContextVar, name, def)); + TruffleString name = (TruffleString) CharPtrToPythonNode.executeUncached(namePtr); + Object def = defPtr == NULLPTR ? PNone.NO_VALUE : NativeToPythonInternalNode.executeUncached(defPtr, false); + return PythonToNativeInternalNode.executeNewRefUncached(CallNode.executeUncached(PythonBuiltinClassType.ContextVar, name, def)); } @CApiBuiltin(ret = PyObjectRawPointer, args = {PyObjectRawPointer, PyObjectRawPointer, Pointer}, call = Ignored) static long GraalPyPrivate_ContextVar_Get(long varPtr, long defPtr, long marker) { - Object var = NativeToPythonNode.executeRawUncached(varPtr); + Object var = NativeToPythonInternalNode.executeUncached(varPtr, false); if (!(var instanceof PContextVar pvar)) { return PRaiseNativeNode.raiseStatic(marker, PythonBuiltinClassType.TypeError, ErrorMessages.INSTANCE_OF_CONTEXTVAR_EXPECTED); } @@ -100,16 +100,16 @@ static long GraalPyPrivate_ContextVar_Get(long varPtr, long defPtr, long marker) if (defPtr == NULLPTR) { result = pvar.getDefault() == PContextVar.NO_DEFAULT ? PNone.NO_VALUE : pvar.getDefault(); } else { - result = NativeToPythonNode.executeRawUncached(defPtr); + result = NativeToPythonInternalNode.executeUncached(defPtr, false); } } - return PythonToNativeNewRefNode.executeLongUncached(result); + return PythonToNativeInternalNode.executeNewRefUncached(result); } @CApiBuiltin(ret = PyObjectRawPointer, args = {PyObjectRawPointer, PyObjectRawPointer}, call = Direct) static long PyContextVar_Set(long varPtr, long valPtr) { - Object var = NativeToPythonNode.executeRawUncached(varPtr); - Object val = NativeToPythonNode.executeRawUncached(valPtr); + Object var = NativeToPythonInternalNode.executeUncached(varPtr, false); + Object val = NativeToPythonInternalNode.executeUncached(valPtr, false); if (!(var instanceof PContextVar pvar)) { throw PRaiseNode.raiseStatic(null, PythonBuiltinClassType.TypeError, ErrorMessages.INSTANCE_OF_CONTEXTVAR_EXPECTED); } @@ -118,28 +118,28 @@ static long PyContextVar_Set(long varPtr, long valPtr) { PythonContext.PythonThreadState threadState = pythonContext.getThreadState(language); Object oldValue = pvar.getValue(null, threadState); pvar.setValue(null, threadState, val); - return PythonToNativeNewRefNode.executeLongUncached(PFactory.createContextVarsToken(language, pvar, oldValue)); + return PythonToNativeInternalNode.executeNewRefUncached(PFactory.createContextVarsToken(language, pvar, oldValue)); } @CApiBuiltin(ret = PyObjectRawPointer, call = Direct) static long PyContext_CopyCurrent() { - return PythonToNativeNewRefNode.executeLongUncached(PyContextCopyCurrent.executeUncached()); + return PythonToNativeInternalNode.executeNewRefUncached(PyContextCopyCurrent.executeUncached()); } @CApiBuiltin(ret = PyObjectRawPointer, args = {PyObjectRawPointer}, call = Direct) static long PyContext_Copy(long contextPtr) { - PContextVarsContext context = (PContextVarsContext) NativeToPythonNode.executeRawUncached(contextPtr); - return PythonToNativeNewRefNode.executeLongUncached(PFactory.copyContextVarsContext(PythonLanguage.get(null), context)); + PContextVarsContext context = (PContextVarsContext) NativeToPythonInternalNode.executeUncached(contextPtr, false); + return PythonToNativeInternalNode.executeNewRefUncached(PFactory.copyContextVarsContext(PythonLanguage.get(null), context)); } @CApiBuiltin(ret = PyObjectRawPointer, call = Direct) static long PyContext_New() { - return PythonToNativeNewRefNode.executeLongUncached(PFactory.createContextVarsContext(PythonLanguage.get(null))); + return PythonToNativeInternalNode.executeNewRefUncached(PFactory.createContextVarsContext(PythonLanguage.get(null))); } @CApiBuiltin(ret = Int, args = {PyObjectRawPointer}, call = Direct) static int PyContext_Enter(long contextPtr) { - PContextVarsContext context = (PContextVarsContext) NativeToPythonNode.executeRawUncached(contextPtr); + PContextVarsContext context = (PContextVarsContext) NativeToPythonInternalNode.executeUncached(contextPtr, false); PythonContext pythonContext = PythonContext.get(null); PythonContext.PythonThreadState threadState = pythonContext.getThreadState(PythonLanguage.get(null)); context.enter(null, threadState, PRaiseNode.getUncached()); @@ -148,7 +148,7 @@ static int PyContext_Enter(long contextPtr) { @CApiBuiltin(ret = Int, args = {PyObjectRawPointer}, call = Direct) static int PyContext_Exit(long contextPtr) { - PContextVarsContext context = (PContextVarsContext) NativeToPythonNode.executeRawUncached(contextPtr); + PContextVarsContext context = (PContextVarsContext) NativeToPythonInternalNode.executeUncached(contextPtr, false); PythonContext pythonContext = PythonContext.get(null); PythonContext.PythonThreadState threadState = pythonContext.getThreadState(PythonLanguage.get(null)); context.leave(threadState); diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextDescrBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextDescrBuiltins.java index afd94851c0..81e1155a17 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextDescrBuiltins.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextDescrBuiltins.java @@ -57,6 +57,7 @@ import com.oracle.graal.python.builtins.modules.cext.PythonCextBuiltins.CApiBuiltin; import com.oracle.graal.python.builtins.modules.cext.PythonCextBuiltins.CApiUnaryBuiltinNode; import com.oracle.graal.python.builtins.objects.PNone; +import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.EnsurePythonObjectNode; import com.oracle.graal.python.builtins.objects.cext.capi.MethodDescriptorWrapper; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.CharPtrToPythonNode; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativeToPythonClassInternalNode; @@ -97,8 +98,8 @@ static Object doNativeCallable(TruffleString name, Object cls, long getter, long public static long GraalPyPrivate_Descr_NewClassMethod(long methodDefPtr, long nameRaw, long docRaw, int flags, long methPtr, long typeRaw) { CompilerAsserts.neverPartOfCompilation(); PythonLanguage language = PythonLanguage.get(null); - TruffleString name = (TruffleString) CharPtrToPythonNode.getUncached().execute(nameRaw); - Object doc = CharPtrToPythonNode.getUncached().execute(docRaw); + TruffleString name = (TruffleString) CharPtrToPythonNode.executeUncached(nameRaw); + Object doc = CharPtrToPythonNode.executeUncached(docRaw); assert doc == PNone.NO_VALUE || doc instanceof TruffleString; Object type = NativeToPythonClassInternalNode.executeUncached(typeRaw); PBuiltinFunction func = MethodDescriptorWrapper.createWrapperFunction(language, name, methPtr, type, flags); @@ -108,6 +109,7 @@ public static long GraalPyPrivate_Descr_NewClassMethod(long methodDefPtr, long n PDecoratedMethod classMethod = PFactory.createBuiltinClassmethodFromCallableObj(language, func); WriteAttributeToPythonObjectNode.executeUncached(classMethod, T___NAME__, name); HiddenAttr.WriteLongNode.executeUncached(classMethod, METHOD_DEF_PTR, methodDefPtr); + assert EnsurePythonObjectNode.doesNotNeedPromotion(classMethod); return PythonToNativeInternalNode.executeUncached(classMethod, true); } } diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextDictBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextDictBuiltins.java index 1324fddbe9..4cbba37438 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextDictBuiltins.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextDictBuiltins.java @@ -152,6 +152,7 @@ static long PyDict_New() { CApiTiming.enter(); try { PDict dict = PFactory.createDict(PythonLanguage.get(null)); + assert EnsurePythonObjectNode.doesNotNeedPromotion(dict); return PythonToNativeInternalNode.executeUncached(dict, true); } finally { CApiTiming.exit(TIMING_PYDICT_NEW); @@ -165,7 +166,7 @@ abstract static class _PyDict_Next extends CApi5BuiltinNode { static int next(PDict dict, long posPtr, long keyPtr, long valuePtr, long hashPtr, @Bind Node inliningTarget, @Bind PythonContext context, - @Cached CApiTransitions.PythonToNativeNode toNativeNode, + @Cached CApiTransitions.PythonToNativeInternalNode toNativeNode, @Cached InlinedBranchProfile needsRewriteProfile, @Cached InlinedBranchProfile economicMapProfile, @Cached HashingStorageLen lenNode, @@ -253,13 +254,13 @@ static int next(PDict dict, long posPtr, long keyPtr, long valuePtr, long hashPt Object key = itKey.execute(inliningTarget, storage, it); assert ensureKeyNode.execute(context, key, false) == key; // Borrowed reference - NativeMemory.writePtr(keyPtr, toNativeNode.executeLong(key)); + NativeMemory.writePtr(keyPtr, toNativeNode.execute(inliningTarget, key)); } if (valuePtr != NULLPTR) { Object value = itValue.execute(inliningTarget, storage, it); assert ensureValueNode.execute(context, value, false) == value; // Borrowed reference - NativeMemory.writePtr(valuePtr, toNativeNode.executeLong(value)); + NativeMemory.writePtr(valuePtr, toNativeNode.execute(inliningTarget, value)); } if (hashPtr != NULLPTR) { long hash = itKeyHash.execute(null, inliningTarget, storage, it); diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextLongBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextLongBuiltins.java index d4ee5628ba..da4a136c8f 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextLongBuiltins.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextLongBuiltins.java @@ -69,8 +69,8 @@ import com.oracle.graal.python.builtins.modules.cext.PythonCextBuiltins.CApiUnaryBuiltinNode; import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes; import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.CastToNativeLongNode; -import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativeToPythonNode; -import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeNewRefNode; +import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativeToPythonInternalNode; +import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeInternalNode; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.ArgDescriptor; import com.oracle.graal.python.builtins.objects.cext.common.CExtCommonNodes.ConvertPIntToPrimitiveNode; import com.oracle.graal.python.builtins.objects.cext.common.CExtCommonNodes.TransformPExceptionToNativeCachedNode; @@ -117,7 +117,7 @@ static long getDC(Object n, @CApiBuiltin(ret = PyObjectRawPointer, args = {ArgDescriptor.Double}, call = Ignored, acquireGil = false) static long GraalPyPrivate_Long_FromDouble(double d) { Object result = PyLongFromDoubleNode.executeUncached(d); - return PythonToNativeNewRefNode.executeLongUncached(result); + return PythonToNativeInternalNode.executeNewRefUncached(result); } @CApiBuiltin(ret = PyObjectTransfer, args = {ConstCharPtrAsTruffleString, Int}, call = Ignored) @@ -183,12 +183,12 @@ static long doSignedLong(long n) { @CApiBuiltin(ret = PyObjectRawPointer, args = {UNSIGNED_LONG_LONG}, call = Ignored, acquireGil = false) static long GraalPyPrivate_Long_FromUnsignedLongLong(long n) { Object result = n >= 0 ? n : PFactory.createInt(PythonLanguage.get(null), PInt.longToUnsignedBigInteger(n)); - return PythonToNativeNewRefNode.executeLongUncached(result); + return PythonToNativeInternalNode.executeNewRefUncached(result); } @CApiBuiltin(ret = SIZE_T, args = {PyObjectRawPointer}, call = Ignored, acquireGil = false) static long GraalPyPrivate_Long_NumBits(long objPtr) { - Object obj = NativeToPythonNode.executeRawUncached(objPtr); + Object obj = NativeToPythonInternalNode.executeUncached(objPtr, false); if (obj instanceof Integer value) { return Integer.SIZE - Integer.numberOfLeadingZeros(Math.abs(value)); } else if (obj instanceof Long value) { diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextMethodBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextMethodBuiltins.java index 666682f120..896dcaf04e 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextMethodBuiltins.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextMethodBuiltins.java @@ -56,6 +56,7 @@ import com.oracle.graal.python.PythonLanguage; import com.oracle.graal.python.builtins.modules.cext.PythonCextBuiltins.CApiBuiltin; import com.oracle.graal.python.builtins.objects.PNone; +import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.EnsurePythonObjectNode; import com.oracle.graal.python.builtins.objects.cext.capi.MethodDescriptorWrapper; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.CharPtrToPythonNode; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativeToPythonInternalNode; @@ -98,14 +99,15 @@ public static long GraalPyPrivate_CMethod_NewEx(long methodDefPtr, long nameRaw, // errors are expected to be thrown already in native code assert verifyFlags(flags, clsRaw); - TruffleString name = (TruffleString) CharPtrToPythonNode.getUncached().execute(nameRaw); + TruffleString name = (TruffleString) CharPtrToPythonNode.executeUncached(nameRaw); Object self = NativeToPythonInternalNode.executeUncached(selfRaw, false); Object module = NativeToPythonInternalNode.executeUncached(moduleRaw, false); Object cls = NativeToPythonInternalNode.executeUncached(clsRaw, false); - Object doc = CharPtrToPythonNode.getUncached().execute(docRaw); + Object doc = CharPtrToPythonNode.executeUncached(docRaw); assert doc == PNone.NO_VALUE || doc instanceof TruffleString; PythonBuiltinObject result = cFunctionNewExMethodNode(PythonLanguage.get(null), methodDefPtr, name, methPtr, flags, self, module, cls, doc); + assert EnsurePythonObjectNode.doesNotNeedPromotion(result); return PythonToNativeInternalNode.executeUncached(result, true); } diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextModuleBuiltins.java index 79a5586a10..7731e3ab25 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextModuleBuiltins.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextModuleBuiltins.java @@ -84,7 +84,7 @@ import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTiming; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.CharPtrToPythonNode; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativeToPythonInternalNode; -import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeNode; +import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeInternalNode; import com.oracle.graal.python.builtins.objects.cext.structs.CFields; import com.oracle.graal.python.builtins.objects.cext.structs.CStructs; import com.oracle.graal.python.builtins.objects.module.PythonModule; @@ -294,8 +294,8 @@ private static void addMethodsToObject(long functions, Object module, Object mod int flags = readIntField(def, CFields.PyMethodDef__ml_flags); long docRaw = readPtrField(def, CFields.PyMethodDef__ml_doc); - TruffleString name = (TruffleString) CharPtrToPythonNode.getUncached().execute(nameRaw); - Object doc = CharPtrToPythonNode.getUncached().execute(docRaw); + TruffleString name = (TruffleString) CharPtrToPythonNode.executeUncached(nameRaw); + Object doc = CharPtrToPythonNode.executeUncached(docRaw); assert doc == PNone.NO_VALUE || doc instanceof TruffleString; PythonBuiltinObject func = PythonCextMethodBuiltins.cFunctionNewExMethodNode(language, def, name, cfunc, flags, module, modName, PNone.NO_VALUE, doc); @@ -311,7 +311,7 @@ abstract static class GraalPyPrivate_Module_Traverse extends CApiTernaryBuiltinN static int doGeneric(PythonModule self, long visitFun, long arg, @Bind Node inliningTarget, @Cached CheckPrimitiveFunctionResultNode checkPrimitiveFunctionResultNode, - @Cached PythonToNativeNode toNativeNode) { + @Cached PythonToNativeInternalNode toNativeNode) { /* * As in 'moduleobject.c: module_traverse': 'if (m->md_def && m->md_def->m_traverse && @@ -327,7 +327,7 @@ static int doGeneric(PythonModule self, long visitFun, long arg, PythonContext ctx = PythonContext.get(inliningTarget); NativeFunctionPointer traverseExecutable = bindFunctionPointer(mTraverse, ExternalFunctionSignature.TRAVERSEPROC); int ires = ExternalFunctionInvoker.invokeTRAVERSEPROC(null, TIMING_INVOKE_TRAVERSE_PROC, ctx.ensureNativeContext(), BoundaryCallData.getUncached(), - ctx.getThreadState(PythonLanguage.get(inliningTarget)), traverseExecutable, toNativeNode.executeLong(self), visitFun, arg); + ctx.getThreadState(PythonLanguage.get(inliningTarget)), traverseExecutable, toNativeNode.execute(inliningTarget, self), visitFun, arg); checkPrimitiveFunctionResultNode.executeLong(inliningTarget, ctx.getThreadState(PythonLanguage.get(inliningTarget)), StringLiterals.T_VISIT, ires); return ires; } diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextObjectBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextObjectBuiltins.java index 726f1fc4b3..736485da88 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextObjectBuiltins.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextObjectBuiltins.java @@ -58,10 +58,10 @@ import static com.oracle.graal.python.builtins.objects.cext.capi.transitions.ArgDescriptor.Void; import static com.oracle.graal.python.builtins.objects.ints.PInt.intValue; import static com.oracle.graal.python.builtins.objects.object.PythonObject.IMMORTAL_REFCNT; -import static com.oracle.graal.python.runtime.nativeaccess.NativeMemory.readPtrArrayElement; import static com.oracle.graal.python.nodes.ErrorMessages.UNHASHABLE_TYPE_P; import static com.oracle.graal.python.nodes.SpecialMethodNames.T___BYTES__; import static com.oracle.graal.python.nodes.StringLiterals.T_JAVA; +import static com.oracle.graal.python.runtime.nativeaccess.NativeMemory.readPtrArrayElement; import static com.oracle.graal.python.util.PythonUtils.TS_ENCODING; import java.io.PrintWriter; @@ -88,9 +88,8 @@ import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.HandleContext; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.HandlePointerConverter; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativeToPythonInternalNode; -import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativeToPythonNode; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonObjectReference; -import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeNewRefNode; +import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeInternalNode; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.UpdateHandleTableReferenceNode; import com.oracle.graal.python.builtins.objects.cext.structs.CFields; import com.oracle.graal.python.builtins.objects.cext.structs.CStructAccess; @@ -152,8 +151,6 @@ import com.oracle.truffle.api.dsl.Cached.Shared; import com.oracle.truffle.api.dsl.Fallback; import com.oracle.truffle.api.dsl.Specialization; -import com.oracle.truffle.api.interop.InteropLibrary; -import com.oracle.truffle.api.interop.UnsupportedMessageException; import com.oracle.truffle.api.library.CachedLibrary; import com.oracle.truffle.api.nodes.Node; import com.oracle.truffle.api.profiles.InlinedBranchProfile; @@ -216,7 +213,7 @@ static Object doLong(long arrayPointer, int len, for (int i = 0; i < resolved.length; i++) { long elem = readPtrArrayElement(arrayPointer, i); pointers[i] = elem; - resolved[i] = nativeToPythonNode.execute(inliningTarget, elem, false); + resolved[i] = nativeToPythonNode.execute(inliningTarget, elem); } HandleContext handleContext = PythonContext.get(inliningTarget).handleContext; for (int i = 0; i < resolved.length; i++) { @@ -239,18 +236,6 @@ static Object doLong(long arrayPointer, int len, return PNone.NO_VALUE; } - @Specialization(limit = "1") - static Object doInteropPointer(Object pointer, int len, - @Bind Node inliningTarget, - @Shared @Cached UpdateHandleTableReferenceNode updateRefNode, - @Shared @Cached NativeToPythonInternalNode nativeToPythonNode, - @CachedLibrary("pointer") InteropLibrary lib) { - try { - return doLong(lib.asPointer(pointer), len, inliningTarget, updateRefNode, nativeToPythonNode); - } catch (UnsupportedMessageException e) { - throw CompilerDirectives.shouldNotReachHere(e); - } - } } @CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, PyObject, PyObject, Int}, call = Ignored) @@ -497,7 +482,7 @@ static long unhashable(Object obj, @CApiBuiltin(ret = Int, args = {PyObjectRawPointer}, call = Ignored) static int GraalPyPrivate_Object_IsTrue(long objPtr) { - Object obj = NativeToPythonNode.executeRawUncached(objPtr); + Object obj = NativeToPythonInternalNode.executeUncached(objPtr, false); return PyObjectIsTrueNode.executeUncached(obj) ? 1 : 0; } @@ -687,9 +672,9 @@ static Object ascii(Object obj, Object spec, @CApiBuiltin(ret = PyObjectRawPointer, args = {PyObjectRawPointer}, call = Ignored) static long GraalPyPrivate_Object_GetIter(long objectPtr) { - Object object = NativeToPythonNode.executeRawUncached(objectPtr); + Object object = NativeToPythonInternalNode.executeUncached(objectPtr, false); Object result = PyObjectGetIter.executeUncached(object); - return PythonToNativeNewRefNode.executeLongUncached(result); + return PythonToNativeInternalNode.executeNewRefUncached(result); } /* diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextSetBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextSetBuiltins.java index e4d9670eb7..9973ce5785 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextSetBuiltins.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextSetBuiltins.java @@ -59,6 +59,7 @@ import com.oracle.graal.python.builtins.modules.cext.PythonCextBuiltins.CApiBuiltin; import com.oracle.graal.python.builtins.modules.cext.PythonCextBuiltins.CApiUnaryBuiltinNode; import com.oracle.graal.python.builtins.objects.PNone; +import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.EnsurePythonObjectNode; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTiming; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativeToPythonInternalNode; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeInternalNode; @@ -109,6 +110,7 @@ static long PySet_New(long iterablePtr) { Object iterable = NativeToPythonInternalNode.executeUncached(iterablePtr, false); set = ConstructSetNode.getUncached().execute(null, iterable); } + assert EnsurePythonObjectNode.doesNotNeedPromotion(set); return PythonToNativeInternalNode.executeUncached(set, true); } finally { CApiTiming.exit(TIMING_PYSET_NEW); diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextTupleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextTupleBuiltins.java index 1ea514751d..e4409a8319 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextTupleBuiltins.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextTupleBuiltins.java @@ -60,7 +60,7 @@ import com.oracle.graal.python.builtins.objects.PNone; import com.oracle.graal.python.builtins.objects.cext.PythonAbstractNativeObject; import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.EnsurePythonObjectNode; -import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeNewRefNode; +import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeInternalNode; import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes; import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes.EnsureCapacityNode; import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes.GetItemNode; @@ -90,7 +90,7 @@ public final class PythonCextTupleBuiltins { @CApiBuiltin(ret = PyObjectRawPointer, call = Ignored) static long GraalPyPrivate_Tuple_Empty() { - return PythonToNativeNewRefNode.executeLongUncached(PFactory.createEmptyTuple(PythonLanguage.get(null))); + return PythonToNativeInternalNode.executeNewRefUncached(PFactory.createEmptyTuple(PythonLanguage.get(null))); } @CApiBuiltin(ret = PyObjectBorrowed, args = {PyObject, Py_ssize_t}, call = Ignored) diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextTypeBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextTypeBuiltins.java index f410a21b0d..5554ba51f6 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextTypeBuiltins.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextTypeBuiltins.java @@ -55,12 +55,12 @@ import static com.oracle.graal.python.builtins.objects.cext.capi.transitions.ArgDescriptor.PyTypeObjectRawPointer; import static com.oracle.graal.python.builtins.objects.cext.capi.transitions.ArgDescriptor.Py_ssize_t; import static com.oracle.graal.python.builtins.objects.cext.structs.CFields.PyTypeObject__tp_name; -import static com.oracle.graal.python.runtime.nativeaccess.NativeMemory.NULLPTR; import static com.oracle.graal.python.nodes.HiddenAttr.AS_BUFFER; import static com.oracle.graal.python.nodes.HiddenAttr.METHOD_DEF_PTR; import static com.oracle.graal.python.nodes.SpecialAttributeNames.T___DOC__; import static com.oracle.graal.python.nodes.SpecialAttributeNames.T___NAME__; import static com.oracle.graal.python.runtime.PythonContext.NATIVE_NULL; +import static com.oracle.graal.python.runtime.nativeaccess.NativeMemory.NULLPTR; import static com.oracle.graal.python.util.PythonUtils.EMPTY_OBJECT_ARRAY; import com.oracle.graal.python.PythonLanguage; @@ -88,7 +88,6 @@ import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.CharPtrToPythonNode; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativeToPythonClassInternalNode; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativeToPythonInternalNode; -import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativeToPythonNode; import com.oracle.graal.python.builtins.objects.cext.common.CExtCommonNodes; import com.oracle.graal.python.builtins.objects.cext.common.CExtCommonNodes.TransformExceptionToNativeNode; import com.oracle.graal.python.builtins.objects.cext.common.CExtContext; @@ -107,7 +106,6 @@ import com.oracle.graal.python.lib.PyDictGetItem; import com.oracle.graal.python.lib.PyDictSetDefault; import com.oracle.graal.python.lib.PyDictSetItem; -import com.oracle.graal.python.runtime.nativeaccess.NativeFunctionPointer; import com.oracle.graal.python.nodes.ErrorMessages; import com.oracle.graal.python.nodes.HiddenAttr; import com.oracle.graal.python.nodes.PRaiseNode; @@ -119,6 +117,7 @@ import com.oracle.graal.python.nodes.util.CastToTruffleStringNode; import com.oracle.graal.python.runtime.PythonContext; import com.oracle.graal.python.runtime.exception.PException; +import com.oracle.graal.python.runtime.nativeaccess.NativeFunctionPointer; import com.oracle.graal.python.runtime.object.PFactory; import com.oracle.graal.python.runtime.sequence.storage.MroSequenceStorage; import com.oracle.graal.python.util.Function; @@ -317,8 +316,8 @@ public static int GraalPyPrivate_Type_AddFunctionToType(long methodDefPtr, long try { Object type = NativeToPythonClassInternalNode.executeUncached(typeRaw); Object dict = NativeToPythonInternalNode.executeUncached(dictRaw, false); - TruffleString name = (TruffleString) CharPtrToPythonNode.getUncached().execute(nameRaw); - Object doc = CharPtrToPythonNode.getUncached().execute(docRaw); + TruffleString name = (TruffleString) CharPtrToPythonNode.executeUncached(nameRaw); + Object doc = CharPtrToPythonNode.executeUncached(docRaw); assert doc == PNone.NO_VALUE || doc instanceof TruffleString; Object func = typeAddMethod(PythonLanguage.get(null), methodDefPtr, name, cfunc, flags, type, doc); PyDictSetDefault.executeUncached(dict, name, func); @@ -348,9 +347,9 @@ public static int GraalPyPrivate_Type_AddOperators(long type) { @TruffleBoundary public static int GraalPyPrivate_Type_AddMember(long clazzPtr, long tpDictPtr, long memberNamePtr, int memberType, long offset, int canSet, long memberDocPtr) { Object clazz = NativeToPythonClassInternalNode.executeUncached(clazzPtr); - PDict tpDict = (PDict) NativeToPythonNode.executeRawUncached(tpDictPtr); - TruffleString memberName = (TruffleString) CharPtrToPythonNode.getUncached().execute(memberNamePtr); - Object memberDoc = memberDocPtr == NULLPTR ? PNone.NO_VALUE : CharPtrToPythonNode.getUncached().execute(memberDocPtr); + PDict tpDict = (PDict) NativeToPythonInternalNode.executeUncached(tpDictPtr, false); + TruffleString memberName = (TruffleString) CharPtrToPythonNode.executeUncached(memberNamePtr); + Object memberDoc = memberDocPtr == NULLPTR ? PNone.NO_VALUE : CharPtrToPythonNode.executeUncached(memberDocPtr); return addMember(clazz, tpDict, memberName, memberType, offset, canSet, memberDoc); } @@ -377,9 +376,9 @@ public static int addMember(Object clazz, PDict tpDict, TruffleString memberName @CApiBuiltin(ret = Int, args = {PyTypeObjectRawPointer, PyObjectRawPointer, ConstCharPtr, Pointer, Pointer, ConstCharPtr, Pointer}, call = Ignored) static int GraalPyPrivate_Type_AddGetSet(long clsPtr, long dictPtr, long namePtr, long getter, long setter, long docPtr, long closure) { Object cls = NativeToPythonClassInternalNode.executeUncached(clsPtr); - PDict dict = (PDict) NativeToPythonNode.executeRawUncached(dictPtr); - TruffleString name = (TruffleString) CharPtrToPythonNode.getUncached().execute(namePtr); - Object doc = docPtr == NULLPTR ? PNone.NO_VALUE : CharPtrToPythonNode.getUncached().execute(docPtr); + PDict dict = (PDict) NativeToPythonInternalNode.executeUncached(dictPtr, false); + TruffleString name = (TruffleString) CharPtrToPythonNode.executeUncached(namePtr); + Object doc = docPtr == NULLPTR ? PNone.NO_VALUE : CharPtrToPythonNode.executeUncached(docPtr); return addGetSet(cls, dict, name, getter, setter, doc, closure); } diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextUnicodeBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextUnicodeBuiltins.java index ad88890e77..4a86ec37ff 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextUnicodeBuiltins.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextUnicodeBuiltins.java @@ -112,6 +112,7 @@ import com.oracle.graal.python.builtins.objects.PNone; import com.oracle.graal.python.builtins.objects.bytes.PBytes; import com.oracle.graal.python.builtins.objects.cext.PythonAbstractNativeObject; +import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.EnsurePythonObjectNode; import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.FromCharPointerNode; import com.oracle.graal.python.builtins.objects.cext.capi.PySequenceArrayWrapper; import com.oracle.graal.python.builtins.objects.cext.capi.UnicodeObjectNodes.UnicodeAsWideCharNode; @@ -341,7 +342,9 @@ static long GraalPyPrivate_Unicode_LookupAndIntern(long objPtr) { * str.intern'ed string may still yield failse */ ConcurrentWeakSet interningCache = PythonContext.get(null).getCApiContext().getPstringInterningCache(); - return PythonToNativeInternalNode.executeUncached(interningCache.intern(str, s -> s), true); + PString interned = interningCache.intern(str, s -> s); + assert EnsurePythonObjectNode.doesNotNeedPromotion(interned); + return PythonToNativeInternalNode.executeUncached(interned, true); } else { /* * If it's a subclass, we don't really know what putting it in the interned dict might diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextWeakrefBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextWeakrefBuiltins.java index ad3b013c86..138bae8354 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextWeakrefBuiltins.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextWeakrefBuiltins.java @@ -57,8 +57,8 @@ import com.oracle.graal.python.builtins.objects.PNone; import com.oracle.graal.python.builtins.objects.cext.capi.ExternalFunctionNodes.ToNativeBorrowedNode; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions; -import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativeToPythonNode; -import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeNewRefNode; +import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativeToPythonInternalNode; +import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeInternalNode; import com.oracle.graal.python.builtins.objects.module.PythonModule; import com.oracle.graal.python.builtins.objects.referencetype.PReferenceType; import com.oracle.graal.python.builtins.objects.referencetype.ReferenceTypeBuiltins.ReferenceTypeNode; @@ -90,16 +90,16 @@ public static long PyWeakref_NewProxy(long objectPtr, long callbackPtr) { if (callbackPtr == NULLPTR) { callback = PNone.NO_VALUE; } else { - callback = NativeToPythonNode.executeRawUncached(callbackPtr); + callback = NativeToPythonInternalNode.executeUncached(callbackPtr, false); } - Object object = NativeToPythonNode.executeRawUncached(objectPtr); + Object object = NativeToPythonInternalNode.executeUncached(objectPtr, false); Object proxy = PyObjectCallMethodObjArgs.executeUncached(weakrefModule, T_PROXY_TYPE, object, callback); - return PythonToNativeNewRefNode.executeLongUncached(proxy); + return PythonToNativeInternalNode.executeNewRefUncached(proxy); } @CApiBuiltin(ret = PyObjectRawPointer, args = {PyObjectRawPointer}, call = Direct, acquireGil = false) public static long PyWeakref_GetObject(long referencePtr) { - Object reference = NativeToPythonNode.executeRawUncached(referencePtr); + Object reference = NativeToPythonInternalNode.executeUncached(referencePtr, false); if (reference instanceof PReferenceType ref) { return ToNativeBorrowedNode.executeUncached(ref.getPyObject()); } else if (reference instanceof PProxyType proxy) { @@ -118,7 +118,7 @@ public static long PyWeakref_GetObject(long referencePtr) { @CApiBuiltin(name = "_PyWeakref_ClearRef", ret = Void, args = {PYWEAKREFERENCE_PTR}, call = Direct, acquireGil = false, canRaise = false) public static void PyWeakref_ClearRef(long referencePtr) { - Object reference = NativeToPythonNode.executeRawUncached(referencePtr); + Object reference = NativeToPythonInternalNode.executeUncached(referencePtr, false); if (reference instanceof PReferenceType ref) { ref.clearRef(); } diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/datetime/DateNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/datetime/DateNodes.java index 3615848c65..ad8fb02f47 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/datetime/DateNodes.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/datetime/DateNodes.java @@ -60,13 +60,13 @@ import com.oracle.graal.python.builtins.objects.cext.structs.CStructAccess; import com.oracle.graal.python.builtins.objects.type.TypeNodes; import com.oracle.graal.python.lib.PyLongAsIntNode; -import com.oracle.graal.python.runtime.nativeaccess.NativeMemory; import com.oracle.graal.python.nodes.ErrorMessages; import com.oracle.graal.python.nodes.PGuards; import com.oracle.graal.python.nodes.PRaiseNode; import com.oracle.graal.python.nodes.call.CallNode; import com.oracle.graal.python.runtime.IndirectCallData.BoundaryCallData; import com.oracle.graal.python.runtime.PythonContext; +import com.oracle.graal.python.runtime.nativeaccess.NativeMemory; import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; import com.oracle.truffle.api.dsl.Cached; import com.oracle.truffle.api.dsl.Fallback; @@ -146,20 +146,20 @@ static Object newDate(Node inliningTarget, Object cls, int year, int month, int @Cached TypeNodes.GetInstanceShape getInstanceShape, @Cached TypeNodes.NeedsNativeAllocationNode needsNativeAllocationNode, @Cached ExternalFunctionNodes.PyObjectCheckFunctionResultNode checkFunctionResultNode, - @Cached CApiTransitions.PythonToNativeNode toNativeNode, - @Cached CApiTransitions.NativeToPythonTransferNode fromNativeNode) { + @Cached CApiTransitions.PythonToNativeInternalNode toNativeNode, + @Cached CApiTransitions.NativeToPythonInternalNode fromNativeNode) { if (!needsNativeAllocationNode.execute(inliningTarget, cls)) { Shape shape = getInstanceShape.execute(cls); return new PDate(cls, shape, year, month, day); } else { - long clsPointer = toNativeNode.executeLong(cls); + long clsPointer = toNativeNode.execute(inliningTarget, cls); try { PythonContext context = PythonContext.get(inliningTarget); var callable = CApiContext.getNativeSymbol(inliningTarget, NativeCAPISymbol.FUN_DATE_SUBTYPE_NEW); long nativeResult = ExternalFunctionInvoker.invokeDATE_SUBTYPE_NEW(null, C_API_TIMING, context.ensureNativeContext(), BoundaryCallData.getUncached(), context.getThreadState(PythonLanguage.get(inliningTarget)), callable, clsPointer, year, month, day); - return checkFunctionResultNode.execute(context, NativeCAPISymbol.FUN_DATE_SUBTYPE_NEW.getTsName(), fromNativeNode.execute(nativeResult)); + return checkFunctionResultNode.execute(context, NativeCAPISymbol.FUN_DATE_SUBTYPE_NEW.getTsName(), fromNativeNode.executeTransfer(inliningTarget, nativeResult)); } finally { Reference.reachabilityFence(cls); } diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/datetime/DateTimeNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/datetime/DateTimeNodes.java index bc3dea3ed9..7d785799af 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/datetime/DateTimeNodes.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/datetime/DateTimeNodes.java @@ -65,13 +65,13 @@ import com.oracle.graal.python.builtins.objects.type.TypeNodes; import com.oracle.graal.python.lib.PyLongAsIntNode; import com.oracle.graal.python.lib.PyTZInfoCheckNode; -import com.oracle.graal.python.runtime.nativeaccess.NativeMemory; import com.oracle.graal.python.nodes.ErrorMessages; import com.oracle.graal.python.nodes.PGuards; import com.oracle.graal.python.nodes.PRaiseNode; import com.oracle.graal.python.nodes.call.CallNode; import com.oracle.graal.python.runtime.IndirectCallData.BoundaryCallData; import com.oracle.graal.python.runtime.PythonContext; +import com.oracle.graal.python.runtime.nativeaccess.NativeMemory; import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; import com.oracle.truffle.api.dsl.Cached; import com.oracle.truffle.api.dsl.Fallback; @@ -230,8 +230,8 @@ static Object newDateTime(Node inliningTarget, Object cls, int year, int month, @Cached TypeNodes.GetInstanceShape getInstanceShape, @Cached TypeNodes.NeedsNativeAllocationNode needsNativeAllocationNode, @Cached ExternalFunctionNodes.PyObjectCheckFunctionResultNode checkFunctionResultNode, - @Cached CApiTransitions.PythonToNativeNode toNativeNode, - @Cached CApiTransitions.NativeToPythonTransferNode fromNativeNode) { + @Cached CApiTransitions.PythonToNativeInternalNode toNativeNode, + @Cached CApiTransitions.NativeToPythonInternalNode fromNativeNode) { // create DateTime without thorough validation final Object tzInfo; @@ -250,16 +250,16 @@ static Object newDateTime(Node inliningTarget, Object cls, int year, int month, Shape shape = getInstanceShape.execute(cls); return new PDateTime(cls, shape, year, month, day, hour, minute, second, microsecond, tzInfo, fold); } else { - long clsPointer = toNativeNode.executeLong(cls); + long clsPointer = toNativeNode.execute(inliningTarget, cls); Object effectiveTzInfo = tzInfo != null ? tzInfo : PNone.NO_VALUE; - long tzInfoPointer = toNativeNode.executeLong(effectiveTzInfo); + long tzInfoPointer = toNativeNode.execute(inliningTarget, effectiveTzInfo); try { PythonContext context = PythonContext.get(inliningTarget); var callable = CApiContext.getNativeSymbol(inliningTarget, NativeCAPISymbol.FUN_DATETIME_SUBTYPE_NEW); long nativeResult = ExternalFunctionInvoker.invokeDATETIME_SUBTYPE_NEW(null, C_API_TIMING, context.ensureNativeContext(), BoundaryCallData.getUncached(), context.getThreadState(context.getLanguage(inliningTarget)), callable, clsPointer, year, month, day, hour, minute, second, microsecond, tzInfoPointer, fold); - return checkFunctionResultNode.execute(context, NativeCAPISymbol.FUN_DATETIME_SUBTYPE_NEW.getTsName(), fromNativeNode.execute(nativeResult)); + return checkFunctionResultNode.execute(context, NativeCAPISymbol.FUN_DATETIME_SUBTYPE_NEW.getTsName(), fromNativeNode.executeTransfer(inliningTarget, nativeResult)); } finally { Reference.reachabilityFence(cls); Reference.reachabilityFence(effectiveTzInfo); diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/datetime/TimeDeltaNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/datetime/TimeDeltaNodes.java index 086aab8826..dd9aaee63a 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/datetime/TimeDeltaNodes.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/datetime/TimeDeltaNodes.java @@ -56,7 +56,7 @@ import com.oracle.graal.python.builtins.objects.cext.capi.NativeCAPISymbol; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTiming; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions; -import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativeToPythonTransferNode; +import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativeToPythonInternalNode; import com.oracle.graal.python.builtins.objects.cext.structs.CFields; import com.oracle.graal.python.builtins.objects.type.TypeNodes; import com.oracle.graal.python.lib.PyFloatAsDoubleNode; @@ -179,14 +179,14 @@ private static Object createTimeDeltaFromMicroseconds(Node inliningTarget, Objec secondsNormalized, microsecondsNormalized); } else { - long clsPointer = CApiTransitions.PythonToNativeNode.executeLongUncached(cls); + long clsPointer = CApiTransitions.PythonToNativeInternalNode.executeUncached(cls, false); try { PythonContext context = PythonContext.get(null); var callable = CApiContext.getNativeSymbol(null, NativeCAPISymbol.FUN_TIMEDELTA_SUBTYPE_NEW); long nativeResult = ExternalFunctionInvoker.invokeTIMEDELTA_SUBTYPE_NEW(null, C_API_TIMING, context.ensureNativeContext(), BoundaryCallData.getUncached(), context.getThreadState(context.getLanguage(inliningTarget)), callable, clsPointer, daysNormalized, secondsNormalized, microsecondsNormalized); - return PyObjectCheckFunctionResultNode.executeUncached(NativeCAPISymbol.FUN_TIMEDELTA_SUBTYPE_NEW.getTsName(), NativeToPythonTransferNode.executeRawUncached(nativeResult)); + return PyObjectCheckFunctionResultNode.executeUncached(NativeCAPISymbol.FUN_TIMEDELTA_SUBTYPE_NEW.getTsName(), NativeToPythonInternalNode.executeUncached(nativeResult, true)); } finally { Reference.reachabilityFence(cls); } diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/datetime/TimeNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/datetime/TimeNodes.java index 515084e153..59ebbe8753 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/datetime/TimeNodes.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/datetime/TimeNodes.java @@ -56,7 +56,7 @@ import com.oracle.graal.python.builtins.objects.cext.capi.NativeCAPISymbol; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTiming; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions; -import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativeToPythonTransferNode; +import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativeToPythonInternalNode; import com.oracle.graal.python.builtins.objects.cext.structs.CFields; import com.oracle.graal.python.builtins.objects.cext.structs.CStructAccess; import com.oracle.graal.python.builtins.objects.function.PKeyword; @@ -167,17 +167,16 @@ public static Object newTimeUnchecked(Object cls, int hour, int minute, int seco Shape shape = GetInstanceShape.executeUncached(cls); return new PTime(cls, shape, hour, minute, second, microsecond, tzInfo, fold); } else { - CApiTransitions.PythonToNativeNode toNative = CApiTransitions.PythonToNativeNode.getUncached(); - long clsPointer = toNative.executeLong(cls); + long clsPointer = CApiTransitions.PythonToNativeInternalNode.executeUncached(cls, false); Object effectiveTzInfo = tzInfo != null ? tzInfo : PNone.NO_VALUE; - long tzInfoPointer = toNative.executeLong(effectiveTzInfo); + long tzInfoPointer = CApiTransitions.PythonToNativeInternalNode.executeUncached(effectiveTzInfo, false); try { PythonContext context = PythonContext.get(null); var callable = CApiContext.getNativeSymbol(null, NativeCAPISymbol.FUN_TIME_SUBTYPE_NEW); long nativeResult = ExternalFunctionInvoker.invokeTIME_SUBTYPE_NEW(null, C_API_TIMING, context.ensureNativeContext(), BoundaryCallData.getUncached(), context.getThreadState(context.getLanguage()), callable, clsPointer, hour, minute, second, microsecond, tzInfoPointer, fold); - return PyObjectCheckFunctionResultNode.executeUncached(NativeCAPISymbol.FUN_TIME_SUBTYPE_NEW.getTsName(), NativeToPythonTransferNode.executeRawUncached(nativeResult)); + return PyObjectCheckFunctionResultNode.executeUncached(NativeCAPISymbol.FUN_TIME_SUBTYPE_NEW.getTsName(), NativeToPythonInternalNode.executeUncached(nativeResult, true)); } finally { Reference.reachabilityFence(cls); Reference.reachabilityFence(effectiveTzInfo); diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/datetime/TzInfoBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/datetime/TzInfoBuiltins.java index b7c6b45dfc..6e22c65e13 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/datetime/TzInfoBuiltins.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/datetime/TzInfoBuiltins.java @@ -66,7 +66,7 @@ import com.oracle.graal.python.builtins.objects.cext.capi.NativeCAPISymbol; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTiming; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions; -import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativeToPythonTransferNode; +import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativeToPythonInternalNode; import com.oracle.graal.python.builtins.objects.function.PKeyword; import com.oracle.graal.python.builtins.objects.type.TpSlots; import com.oracle.graal.python.builtins.objects.type.TypeNodes; @@ -118,15 +118,14 @@ static Object newTzInfo(Object cls, Object[] arguments, PKeyword[] keywords, if (!needsNativeAllocationNode.execute(inliningTarget, cls)) { return new PTzInfo(cls, getInstanceShape.execute(cls)); } else { - CApiTransitions.PythonToNativeNode toNative = CApiTransitions.PythonToNativeNode.getUncached(); - long clsPointer = toNative.executeLong(cls); + long clsPointer = CApiTransitions.PythonToNativeInternalNode.executeUncached(cls, false); try { PythonContext context = PythonContext.get(inliningTarget); var callable = CApiContext.getNativeSymbol(inliningTarget, NativeCAPISymbol.FUN_PY_TYPE_GENERIC_NEW); long nativeResult = ExternalFunctionInvoker.invokePY_TYPE_GENERIC_NEW(null, C_API_TIMING, context.ensureNativeContext(), BoundaryCallData.getUncached(), context.getThreadState(context.getLanguage(inliningTarget)), callable, clsPointer, NULLPTR, NULLPTR); - return PyObjectCheckFunctionResultNode.executeUncached(NativeCAPISymbol.FUN_PY_TYPE_GENERIC_NEW.getTsName(), NativeToPythonTransferNode.executeRawUncached(nativeResult)); + return PyObjectCheckFunctionResultNode.executeUncached(NativeCAPISymbol.FUN_PY_TYPE_GENERIC_NEW.getTsName(), NativeToPythonInternalNode.executeUncached(nativeResult, true)); } finally { Reference.reachabilityFence(cls); } diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/BytesBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/BytesBuiltins.java index 5ed4012f20..ceab7c45e4 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/BytesBuiltins.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/BytesBuiltins.java @@ -68,7 +68,6 @@ import com.oracle.graal.python.lib.PyBytesCheckNode; import com.oracle.graal.python.lib.PyIndexCheckNode; import com.oracle.graal.python.lib.RichCmpOp; -import com.oracle.graal.python.runtime.nativeaccess.NativeMemory; import com.oracle.graal.python.nodes.ErrorMessages; import com.oracle.graal.python.nodes.PNodeWithContext; import com.oracle.graal.python.nodes.PRaiseNode; @@ -86,6 +85,7 @@ import com.oracle.graal.python.runtime.IndirectCallData.InteropCallData; import com.oracle.graal.python.runtime.PythonContext; import com.oracle.graal.python.runtime.exception.PException; +import com.oracle.graal.python.runtime.nativeaccess.NativeMemory; import com.oracle.graal.python.runtime.object.PFactory; import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage; import com.oracle.graal.python.util.PythonUtils; @@ -187,27 +187,28 @@ static PBytes doBuiltin(@SuppressWarnings("unused") Object cls, byte[] bytes, return PFactory.createBytes(language, bytes); } - @Specialization(guards = "!needsNativeAllocationNode.execute(inliningTarget, cls)") + @Specialization(guards = "!needsNativeAllocationNode.execute(inliningTarget, cls)", limit = "1") static PBytes doManaged(@SuppressWarnings("unused") Node inliningTarget, Object cls, byte[] bytes, - @SuppressWarnings("unused") @Shared @Cached TypeNodes.NeedsNativeAllocationNode needsNativeAllocationNode, + @SuppressWarnings("unused") @Exclusive @Cached TypeNodes.NeedsNativeAllocationNode needsNativeAllocationNode, @Cached TypeNodes.GetInstanceShape getInstanceShape) { return PFactory.createBytes(cls, getInstanceShape.execute(cls), bytes); } - @Specialization(guards = "needsNativeAllocationNode.execute(inliningTarget, cls)") - static Object doNative(@SuppressWarnings("unused") Node inliningTarget, Object cls, byte[] bytes, - @SuppressWarnings("unused") @Shared @Cached TypeNodes.NeedsNativeAllocationNode needsNativeAllocationNode, + @Specialization(guards = "needsNativeAllocationNode.execute(inliningTarget, cls)", limit = "1") + static Object doNative(Node inliningTarget, Object cls, byte[] bytes, + @SuppressWarnings("unused") @Exclusive @Cached TypeNodes.NeedsNativeAllocationNode needsNativeAllocationNode, @Cached AsCharPointerNode asCharPointerNode, - @Cached(inline = false) CApiTransitions.PythonToNativeNode toNative, - @Cached(inline = false) CApiTransitions.NativeToPythonTransferNode toPython) { + @Cached CApiTransitions.PythonToNativeInternalNode toNative, + @Cached CApiTransitions.NativeToPythonInternalNode toPython) { long dataPointer = asCharPointerNode.execute(bytes); - long clsPointer = toNative.executeLong(cls); + long clsPointer = toNative.execute(inliningTarget, cls); try { PythonContext context = PythonContext.get(inliningTarget); var callable = CApiContext.getNativeSymbol(inliningTarget, FUN_BYTES_SUBTYPE_NEW); - return toPython.execute(ExternalFunctionInvoker.invokeBYTES_SUBTYPE_NEW(null, C_API_TIMING, + long result = ExternalFunctionInvoker.invokeBYTES_SUBTYPE_NEW(null, C_API_TIMING, context.ensureNativeContext(), BoundaryCallData.getUncached(), - context.getThreadState(context.getLanguage(inliningTarget)), callable, clsPointer, dataPointer, bytes.length)); + context.getThreadState(context.getLanguage(inliningTarget)), callable, clsPointer, dataPointer, bytes.length); + return toPython.executeTransfer(inliningTarget, result); } finally { Reference.reachabilityFence(cls); NativeMemory.free(dataPointer); diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/CApiContext.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/CApiContext.java index 5636115b77..303358bcc1 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/CApiContext.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/CApiContext.java @@ -93,12 +93,11 @@ import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.FirstToNativeNode; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.HandleContext; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.HandlePointerConverter; -import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativeToPythonNode; +import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativeToPythonInternalNode; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeInternalNode; import com.oracle.graal.python.builtins.objects.cext.common.CExtContext; import com.oracle.graal.python.builtins.objects.cext.common.LoadCExtException.ApiInitException; import com.oracle.graal.python.builtins.objects.cext.common.LoadCExtException.ImportException; -import com.oracle.graal.python.builtins.objects.cext.common.NativePointer; import com.oracle.graal.python.builtins.objects.cext.copying.NativeLibraryLocator; import com.oracle.graal.python.builtins.objects.cext.structs.CFields; import com.oracle.graal.python.builtins.objects.cext.structs.CStructAccess; @@ -150,9 +149,7 @@ import com.oracle.truffle.api.TruffleLogger; import com.oracle.truffle.api.TruffleSafepoint; import com.oracle.truffle.api.exception.AbstractTruffleException; -import com.oracle.truffle.api.interop.InteropLibrary; import com.oracle.truffle.api.interop.TruffleObject; -import com.oracle.truffle.api.interop.UnsupportedMessageException; import com.oracle.truffle.api.nodes.ExplodeLoop; import com.oracle.truffle.api.nodes.ExplodeLoop.LoopExplosionKind; import com.oracle.truffle.api.nodes.Node; @@ -310,8 +307,9 @@ public TruffleString getInitFunctionName() { /** * This list holds a strong reference to all loaded extension libraries to keep the library - * objects alive. This is necessary because NFI will {@code dlclose} the library (and thus - * {@code munmap} all code) if the library object is no longer reachable. However, it can happen + * objects alive. This is necessary because native library handles may {@code dlclose} the + * library (and thus {@code munmap} all code) if the library object is no longer reachable. + * However, it can happen * that we still store raw function pointers (as Java {@code long} values) in a native object * that is referenced by a * {@link com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativeObjectReference}. @@ -361,21 +359,6 @@ public ConcurrentWeakSet getPstringInterningCache() { return pstringInterningCache; } - /** - * Tries to convert the object to a pointer (type: {@code long}) to avoid materialization of - * pointer objects. If that is not possible, the object will be returned as given. - */ - public static Object asPointer(Object ptr, InteropLibrary lib) { - if (lib.isPointer(ptr)) { - try { - return lib.asPointer(ptr); - } catch (UnsupportedMessageException e) { - throw CompilerDirectives.shouldNotReachHere(e); - } - } - return ptr; - } - public long nextTssKey() { return nextTssKey.incrementAndGet(); } @@ -532,17 +515,6 @@ private static NativeFunctionPointer[] getNativeCAPISymbols(Node caller) { return PythonContext.get(caller).getCApiContext().nativeCAPISymbols; } - public static boolean isIdenticalToSymbol(Object obj, NativeCAPISymbol symbol) { - CompilerAsserts.neverPartOfCompilation(); - InteropLibrary objLib = InteropLibrary.getUncached(obj); - objLib.toNative(obj); - try { - return isIdenticalToSymbol(objLib.asPointer(obj), symbol); - } catch (UnsupportedMessageException e) { - throw new RuntimeException(e); - } - } - public static boolean isIdenticalToSymbol(long ptr, NativeCAPISymbol symbol) { CompilerAsserts.neverPartOfCompilation(); NativeFunctionPointer nativeSymbol = getNativeSymbol(null, symbol); @@ -598,8 +570,7 @@ private static void publishGraalPyTestCAPI(PythonContext context) { if (!context.getOption(PythonOptions.EnableDebuggingBuiltins)) { return; } - NativePointer testCAPIPointer = context.allocateContextMemory(CStructs.GraalPy_Test_CAPI.size()); - long testCAPI = testCAPIPointer.asPointer(); + long testCAPI = context.allocateContextMemory(CStructs.GraalPy_Test_CAPI.size()); long[] testCAPIFunctions = { PythonCextBuiltinRegistry.GraalPyPrivate_ToNative.getNativePointer(), PythonCextBuiltinRegistry.GraalPyPrivate_DisableReferenceQueuePolling.getNativePointer(), @@ -1004,7 +975,6 @@ private static CApiContext loadCApi(Node node, PythonContext context, TruffleStr "cannot use native module.", actualReason))); } loc = new NativeLibraryLocator(context, capiFile, isolateNative); - context.ensureNFILanguage(node, "allowNativeAccess", "true"); int dlopenFlags = isolateNative ? PosixConstants.RTLD_LOCAL.value : PosixConstants.RTLD_GLOBAL.value; LOGGER.config(() -> "loading CAPI from " + loc.getCapiLibrary() + " as native"); NativeContext nativeContext = context.ensureNativeContext(); @@ -1196,8 +1166,8 @@ public static Object loadCExtModule(Node location, PythonContext context, Module * finalization didn't run. * * The memory of the shared library may have been re-used if the GraalPy context was shut down - * (cleanly or not), the sources were collected, and NFI's mechanism for unloading libraries - * triggered a dlclose that dropped the refcount of the python-native library to 0. We leak 1 + * (cleanly or not), the sources were collected, and native library unloading triggered a + * dlclose that dropped the refcount of the python-native library to 0. We leak 1 * byte of memory and this shutdown hook for each context that ever initialized the C API. */ private void addNativeFinalizer(PythonContext context, long finalizingPointer) { @@ -1333,7 +1303,7 @@ public Object initCApiModule(Node node, NativeLibrary sharedLibrary, TruffleStri long nativeResult = ExternalFunctionInvoker.invokeMODINIT(null, TIMING_INVOKE_MODULE_INIT, nativeContext, BoundaryCallData.getUncached(), context.getThreadState(context.getLanguage()), ExternalFunctionSignature.MODINIT.bind(nativeContext, pyinitFunc)); - Object result = PyObjectCheckFunctionResultNodeGen.getUncached().execute(context, initFuncName, NativeToPythonNode.executeUncached(nativeResult)); + Object result = PyObjectCheckFunctionResultNodeGen.getUncached().execute(context, initFuncName, NativeToPythonInternalNode.executeUncached(nativeResult, false)); if (!(result instanceof PythonModule)) { // Multi-phase extension module initialization diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/CApiMemberAccessNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/CApiMemberAccessNodes.java index 350106b656..2ffd7de03f 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/CApiMemberAccessNodes.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/CApiMemberAccessNodes.java @@ -40,14 +40,17 @@ */ package com.oracle.graal.python.builtins.objects.cext.capi; +import static com.oracle.graal.python.util.PythonUtils.TS_ENCODING; + import com.oracle.graal.python.PythonLanguage; import com.oracle.graal.python.annotations.Builtin; import com.oracle.graal.python.builtins.PythonBuiltinClassType; import com.oracle.graal.python.builtins.objects.PNone; import com.oracle.graal.python.builtins.objects.cext.capi.CApiMemberAccessNodesFactory.BadMemberDescrNodeGen; -import com.oracle.graal.python.builtins.objects.cext.capi.CApiMemberAccessNodesFactory.NativePtrToPythonWrapperNodeGen; +import com.oracle.graal.python.builtins.objects.cext.capi.CApiMemberAccessNodesFactory.NativeCharToTruffleStringNodeGen; import com.oracle.graal.python.builtins.objects.cext.capi.CApiMemberAccessNodesFactory.ReadMemberNodeGen; import com.oracle.graal.python.builtins.objects.cext.capi.CApiMemberAccessNodesFactory.ReadOnlyMemberNodeGen; +import com.oracle.graal.python.builtins.objects.cext.capi.CApiMemberAccessNodesFactory.StringAsPythonStringNodeGen; import com.oracle.graal.python.builtins.objects.cext.capi.CApiMemberAccessNodesFactory.WriteByteNodeGen; import com.oracle.graal.python.builtins.objects.cext.capi.CApiMemberAccessNodesFactory.WriteCharNodeGen; import com.oracle.graal.python.builtins.objects.cext.capi.CApiMemberAccessNodesFactory.WriteDoubleNodeGen; @@ -60,25 +63,21 @@ import com.oracle.graal.python.builtins.objects.cext.capi.CApiMemberAccessNodesFactory.WriteShortNodeGen; import com.oracle.graal.python.builtins.objects.cext.capi.CApiMemberAccessNodesFactory.WriteUIntNodeGen; import com.oracle.graal.python.builtins.objects.cext.capi.CApiMemberAccessNodesFactory.WriteULongNodeGen; -import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativePtrToPythonNode; +import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.FromCharPointerNode; +import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativeToPythonNode; +import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeInternalNode; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeNode; import com.oracle.graal.python.builtins.objects.cext.common.CExtCommonNodes.AsNativeCharNode; import com.oracle.graal.python.builtins.objects.cext.common.CExtCommonNodes.AsNativePrimitiveNode; -import com.oracle.graal.python.builtins.objects.cext.common.CExtCommonNodesFactory.NativePrimitiveAsPythonBooleanNodeGen; -import com.oracle.graal.python.builtins.objects.cext.common.CExtCommonNodesFactory.NativePrimitiveAsPythonCharNodeGen; -import com.oracle.graal.python.builtins.objects.cext.common.CExtCommonNodesFactory.NativeUnsignedByteNodeGen; -import com.oracle.graal.python.builtins.objects.cext.common.CExtCommonNodesFactory.NativeUnsignedPrimitiveAsPythonObjectNodeGen; -import com.oracle.graal.python.builtins.objects.cext.common.CExtCommonNodesFactory.NativeUnsignedShortNodeGen; -import com.oracle.graal.python.builtins.objects.cext.common.CExtCommonNodesFactory.StringAsPythonStringNodeGen; import com.oracle.graal.python.builtins.objects.cext.common.CExtToJavaNode; import com.oracle.graal.python.builtins.objects.cext.structs.CConstants; import com.oracle.graal.python.builtins.objects.cext.structs.CStructAccess; import com.oracle.graal.python.builtins.objects.cext.structs.CStructs; import com.oracle.graal.python.builtins.objects.function.PBuiltinFunction; import com.oracle.graal.python.builtins.objects.getsetdescriptor.DescriptorDeleteMarker; +import com.oracle.graal.python.builtins.objects.ints.PInt; import com.oracle.graal.python.builtins.objects.type.TypeNodes.IsSameTypeNode; import com.oracle.graal.python.lib.PyFloatAsDoubleNode; -import com.oracle.graal.python.runtime.nativeaccess.NativeMemory; import com.oracle.graal.python.nodes.ErrorMessages; import com.oracle.graal.python.nodes.PRaiseNode; import com.oracle.graal.python.nodes.function.BuiltinFunctionRootNode; @@ -87,17 +86,23 @@ import com.oracle.graal.python.nodes.object.BuiltinClassProfiles.IsBuiltinObjectProfile; import com.oracle.graal.python.nodes.object.GetClassNode; import com.oracle.graal.python.runtime.exception.PException; +import com.oracle.graal.python.runtime.nativeaccess.NativeMemory; import com.oracle.graal.python.runtime.object.PFactory; import com.oracle.graal.python.util.PythonUtils.PrototypeNodeFactory; +import com.oracle.truffle.api.CompilerAsserts; import com.oracle.truffle.api.CompilerDirectives; import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; import com.oracle.truffle.api.dsl.Bind; import com.oracle.truffle.api.dsl.Cached; import com.oracle.truffle.api.dsl.GenerateInline; +import com.oracle.truffle.api.dsl.NeverDefault; import com.oracle.truffle.api.dsl.Specialization; import com.oracle.truffle.api.frame.VirtualFrame; import com.oracle.truffle.api.nodes.Node; import com.oracle.truffle.api.strings.TruffleString; +import com.oracle.truffle.api.strings.TruffleString.Encoding; +import com.oracle.truffle.api.strings.TruffleString.FromNativePointerNode; +import com.oracle.truffle.api.strings.TruffleString.SwitchEncodingNode; public class CApiMemberAccessNodes { @@ -131,47 +136,48 @@ private static boolean isReadOnlyType(int type) { return type == T_STRING || type == T_STRING_INPLACE; } - private static CExtToJavaNode getReadConverterNode(int type) { - switch (type) { - case T_SHORT: - case T_INT: - case T_LONG: - case T_LONGLONG: - case T_FLOAT: - case T_DOUBLE: - case T_BYTE: - case T_PYSSIZET: - case T_NONE: - // no conversion needed - return null; - case T_STRING: - case T_STRING_INPLACE: - return StringAsPythonStringNodeGen.create(); - case T_BOOL: - return NativePrimitiveAsPythonBooleanNodeGen.create(); - case T_CHAR: - return NativePrimitiveAsPythonCharNodeGen.create(); - case T_UBYTE: - return NativeUnsignedByteNodeGen.create(); - case T_USHORT: - return NativeUnsignedShortNodeGen.create(); - case T_UINT: - case T_ULONG: - case T_ULONGLONG: - return NativeUnsignedPrimitiveAsPythonObjectNodeGen.create(); - case T_OBJECT: - case T_OBJECT_EX: - return NativePtrToPythonWrapperNodeGen.create(); + /** Implements case {@code T_STRING} of function {@code PyMember_GetOne}. Just wraps {@link FromCharPointerNode} to fulfill the interface. */ + @GenerateInline(false) + public abstract static class StringAsPythonStringNode extends CExtToJavaNode { + + @Specialization + static TruffleString doNative(long value, + @Bind Node inliningTarget, + @Cached FromCharPointerNode fromPtr) { + assert value != NativeMemory.NULLPTR; + return fromPtr.execute(inliningTarget, value); } - throw CompilerDirectives.shouldNotReachHere("invalid member type"); } + /** + * Implements case {@code T_CHAR} of function {@code PyMember_GetOne}. Expects a pointer that points to a single native {@code char} which represents an UTF-8 code point. + */ @GenerateInline(false) - abstract static class NativePtrToPythonWrapperNode extends CExtToJavaNode { + abstract static class NativeCharToTruffleStringNode extends CExtToJavaNode { @Specialization - Object doGeneric(long pointer, - @Cached NativePtrToPythonNode nativePtrToPythonNode) { - return nativePtrToPythonNode.execute(pointer, false); + static TruffleString doLong(long ptr, + @Cached FromNativePointerNode fromNativePointerNode, + @Cached SwitchEncodingNode switchEncodingNode) { + TruffleString ts = fromNativePointerNode.execute(ptr, 0, 1, Encoding.UTF_8, true); + return switchEncodingNode.execute(ts, TS_ENCODING); + } + } + + static final class NoConversionRequiredNode extends CExtToJavaNode { + + static final NoConversionRequiredNode INSTANCE = new NoConversionRequiredNode(); + + private NoConversionRequiredNode() { + } + + @Override + public Object execute(@SuppressWarnings("unused") long pointer) { + throw CompilerDirectives.shouldNotReachHere(); + } + + @Override + public boolean isAdoptable() { + return false; } } @@ -179,18 +185,15 @@ Object doGeneric(long pointer, public abstract static class ReadMemberNode extends PythonUnaryBuiltinNode { private static final Builtin BUILTIN = ReadMemberNode.class.getAnnotation(Builtin.class); - @Child private CExtToJavaNode asPythonObjectNode; - /** The specified member type. */ private final int type; /** The offset where to read from (will be passed to the native getter). */ private final int offset; - protected ReadMemberNode(int type, int offset, CExtToJavaNode asPythonObjectNode) { + protected ReadMemberNode(int type, int offset) { this.type = type; this.offset = offset; - this.asPythonObjectNode = asPythonObjectNode; } protected static boolean isCharSigned() { @@ -200,58 +203,100 @@ protected static boolean isCharSigned() { @Specialization Object doGeneric(@SuppressWarnings("unused") VirtualFrame frame, Object self, @Bind Node inliningTarget, - @Cached PythonToNativeNode toNativeNode, + @Cached PythonToNativeInternalNode toNativeNode, + @Cached("createAsPythonObjectNode()") CExtToJavaNode asPythonObjectNode, @Cached PRaiseNode raiseNode) { - long selfPtr = toNativeNode.executeLong(self); + CompilerAsserts.partialEvaluationConstant(type); + CompilerAsserts.partialEvaluationConstant(offset); + + // in case of T_LONGLONG or T_ULONGLONG, we assume that 'sizeof(long long)' is 'Long.BYTES' + assert type != T_LONGLONG && type != T_ULONGLONG || CStructs.long__long.size() == Long.BYTES; + + // in case of T_PYSSIZET, we assume that 'sizeof(Py_ssize_t)' is 'Long.BYTES' + assert type != T_PYSSIZET || CStructs.Py_ssize_t.size() == Long.BYTES; + + long selfPtr = toNativeNode.execute(inliningTarget, self); long memberPtr = NativeMemory.getFieldPtr(selfPtr, offset); - Object nativeResult = switch (type) { - case T_CHAR, T_BYTE, T_UBYTE, T_BOOL -> { - byte n = NativeMemory.readByte(memberPtr); - if (isCharSigned()) { // TODO(native-access) profile - yield (int) n; + long addr; + switch (type) { + case T_BOOL -> { + return NativeMemory.readByte(memberPtr) != 0; + } + case T_CHAR, T_STRING_INPLACE -> addr = memberPtr; + case T_BYTE -> { + byte b = NativeMemory.readByte(memberPtr); + if (isCharSigned()) { + return (int) b; } - yield Byte.toUnsignedInt(n); + return Byte.toUnsignedInt(b); + } + case T_UBYTE -> { + return Byte.toUnsignedInt(NativeMemory.readByte(memberPtr)); } - case T_SHORT, T_USHORT -> (int) NativeMemory.readShort(memberPtr); - case T_INT, T_UINT -> NativeMemory.readInt(memberPtr); - case T_LONG, T_ULONG -> NativeMemory.readLong(memberPtr); - case T_FLOAT -> (double) NativeMemory.readFloat(memberPtr); - case T_DOUBLE -> NativeMemory.readDouble(memberPtr); - case T_OBJECT, T_OBJECT_EX -> NativeMemory.readPtr(memberPtr); - case T_STRING -> NativeMemory.readPtr(memberPtr); - case T_STRING_INPLACE -> memberPtr; - case T_LONGLONG, T_ULONGLONG -> { - assert CStructs.long__long.size() == Long.BYTES; - yield NativeMemory.readLong(memberPtr); + case T_SHORT -> { + return (int) NativeMemory.readShort(memberPtr); } - case T_PYSSIZET -> { - assert CStructs.Py_ssize_t.size() == Long.BYTES; - yield NativeMemory.readLong(memberPtr); + case T_USHORT -> { + return ((int) NativeMemory.readShort(memberPtr)) & 0xffff; + } + case T_INT -> { + return NativeMemory.readInt(memberPtr); + } + case T_UINT -> { + return NativeMemory.readInt(memberPtr) & 0xffffffffL; + } + case T_LONG, T_LONGLONG, T_PYSSIZET -> { + return NativeMemory.readLong(memberPtr); + } + case T_ULONG, T_ULONGLONG -> { + long l = NativeMemory.readLong(memberPtr); + if (l >= 0) { + return l; + } + return PFactory.createInt(PythonLanguage.get(this), PInt.longToUnsignedBigInteger(l)); + } + case T_FLOAT -> { + return (double) NativeMemory.readFloat(memberPtr); + } + case T_DOUBLE -> { + return NativeMemory.readDouble(memberPtr); + } + case T_OBJECT, T_STRING -> { + addr = NativeMemory.readPtr(memberPtr); + if (addr == NativeMemory.NULLPTR) { + return PNone.NONE; + } + } + case T_OBJECT_EX -> { + addr = NativeMemory.readPtr(memberPtr); + if (addr == NativeMemory.NULLPTR) { + throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.AttributeError); + } + } + case T_NONE -> { + return PNone.NONE; } - case T_NONE -> PNone.NONE; default -> throw CompilerDirectives.shouldNotReachHere("invalid member type"); - }; - - assert !(nativeResult instanceof Byte || nativeResult instanceof Short || nativeResult instanceof Float || nativeResult instanceof Character || nativeResult instanceof PException || - nativeResult instanceof String) : nativeResult + " " + nativeResult.getClass(); - if (asPythonObjectNode != null) { - // TODO(native-access) some of these could be inlined into the switch above - nativeResult = asPythonObjectNode.execute(nativeResult); - } - if (type == T_OBJECT_EX && nativeResult == PNone.NO_VALUE) { - throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.AttributeError); - } - if (type == T_OBJECT && nativeResult == PNone.NO_VALUE) { - nativeResult = PNone.NONE; } - return nativeResult; + + assert addr != NativeMemory.NULLPTR; + return asPythonObjectNode.execute(addr); + } + + @NeverDefault + final CExtToJavaNode createAsPythonObjectNode() { + return switch (type) { + case T_CHAR -> NativeCharToTruffleStringNodeGen.create(); + case T_STRING, T_STRING_INPLACE -> StringAsPythonStringNodeGen.create(); + case T_OBJECT, T_OBJECT_EX -> NativeToPythonNode.create(); + default -> NoConversionRequiredNode.INSTANCE; + }; } @TruffleBoundary public static PBuiltinFunction createBuiltinFunction(PythonLanguage language, Object owner, TruffleString propertyName, int type, int offset) { - CExtToJavaNode asPythonObjectNode = getReadConverterNode(type); BuiltinFunctionRootNode rootNode = language.createCachedPropAccessRootNode( - l -> new BuiltinFunctionRootNode(l, BUILTIN, new PrototypeNodeFactory<>(ReadMemberNodeGen.create(type, offset, asPythonObjectNode)), true), + l -> new BuiltinFunctionRootNode(l, BUILTIN, new PrototypeNodeFactory<>(ReadMemberNodeGen.create(type, offset)), true), ReadMemberNode.class, BUILTIN.name(), type, offset); int flags = PBuiltinFunction.getFlags(BUILTIN, rootNode.getSignature()); return PFactory.createBuiltinFunction(language, propertyName, owner, 0, flags, rootNode); @@ -553,7 +598,7 @@ protected WriteMemberNode(int type, int offset) { Object doGeneric(Object self, Object value, @Bind Node inliningTarget, @Cached PRaiseNode raiseNode) { - long selfPtr = toNativeNode.executeLong(self) + offset; + long selfPtr = toNativeNode.execute(self) + offset; /* * Deleting values is only allowed for members with object type (see structmember.c: diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/CExtNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/CExtNodes.java index e7ec3e511b..8c390f2bbe 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/CExtNodes.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/CExtNodes.java @@ -102,9 +102,7 @@ import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.HandlePointerConverter; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativeToPythonClassInternalNode; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativeToPythonInternalNode; -import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativeToPythonTransferNode; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeInternalNode; -import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeNode; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.UpdateStrongRefNode; import com.oracle.graal.python.builtins.objects.cext.common.CExtCommonNodes; import com.oracle.graal.python.builtins.objects.cext.common.CExtCommonNodes.TransformExceptionFromNativeNode; @@ -202,21 +200,20 @@ public abstract static class FloatSubtypeNew extends Node { public abstract Object execute(Node inliningTarget, Object object, double arg); @Specialization - static Object doGeneric(Object object, double arg, - @Bind Node inliningTarget, - @Cached PythonToNativeNode toNativeNode, - @Cached NativeToPythonTransferNode toJavaNode, + static Object doGeneric(Node inliningTarget, Object object, double arg, + @Cached PythonToNativeInternalNode toNativeNode, + @Cached NativeToPythonInternalNode toJavaNode, @Cached PyObjectCheckFunctionResultNode checkFunctionResultNode) { assert TypeNodes.NeedsNativeAllocationNode.executeUncached(object); NativeFunctionPointer callable = CApiContext.getNativeSymbol(inliningTarget, NativeCAPISymbol.FUN_FLOAT_SUBTYPE_NEW); long result; try { - result = ExternalFunctionInvoker.invokeFLOAT_SUBTYPE_NEW(callable.getAddress(), toNativeNode.executeLong(object), arg); + result = ExternalFunctionInvoker.invokeFLOAT_SUBTYPE_NEW(callable.getAddress(), toNativeNode.execute(inliningTarget, object), arg); } catch (Throwable e) { throw CompilerDirectives.shouldNotReachHere(e); } return checkFunctionResultNode.execute(PythonContext.get(inliningTarget), NativeCAPISymbol.FUN_FLOAT_SUBTYPE_NEW.getTsName(), - toJavaNode.execute(result)); + toJavaNode.executeTransfer(inliningTarget, result)); } } @@ -235,9 +232,9 @@ static Object doGeneric(Node inliningTarget, Object object, Object arg, NativeFunctionPointer callable = CApiContext.getNativeSymbol(inliningTarget, NativeCAPISymbol.FUN_TUPLE_SUBTYPE_NEW); try { long result = ExternalFunctionInvoker.invokeTUPLE_SUBTYPE_NEW(callable.getAddress(), - toNativeNode.execute(inliningTarget, object, false), - toNativeNode.execute(inliningTarget, arg, false)); - return toJavaNode.execute(inliningTarget, result, true); + toNativeNode.execute(inliningTarget, object), + toNativeNode.execute(inliningTarget, arg)); + return toJavaNode.executeTransfer(inliningTarget, result); } catch (Throwable e) { throw CompilerDirectives.shouldNotReachHere(e); } @@ -260,10 +257,10 @@ static Object doGeneric(Node inliningTarget, Object object, Object arg, try { Object promotedArg = ensurePythonObjectNode.execute(PythonContext.get(inliningTarget), arg, false); long result = ExternalFunctionInvoker.invokeUNICODE_SUBTYPE_NEW(callable.getAddress(), - toNativeNode.execute(inliningTarget, object, false), - toNativeNode.execute(inliningTarget, promotedArg, false)); + toNativeNode.execute(inliningTarget, object), + toNativeNode.execute(inliningTarget, promotedArg)); Reference.reachabilityFence(promotedArg); - return toJavaNode.execute(inliningTarget, result, true); + return toJavaNode.executeTransfer(inliningTarget, result); } catch (Throwable e) { throw CompilerDirectives.shouldNotReachHere(e); } @@ -276,7 +273,7 @@ public static T allocateNativePart(Node inliningTarget, long nativeObject; try { nativeObject = ExternalFunctionInvoker.invokePY_TYPE_GENERIC_NEW_RAW(CApiContext.getNativeSymbol(inliningTarget, NativeCAPISymbol.FUN_PY_TYPE_GENERIC_NEW_RAW).getAddress(), - PythonToNativeNode.executeLongUncached(cls), 0L, 0L); + PythonToNativeInternalNode.executeUncached(cls, false), 0L, 0L); } catch (Throwable t) { throw CompilerDirectives.shouldNotReachHere(t); } finally { @@ -851,7 +848,7 @@ static void doDecref(Node inliningTarget, long pointer, if (HandlePointerConverter.pointsToPyFloatHandle(pointer) || HandlePointerConverter.pointsToPyIntHandle(pointer)) { return; } - Object object = toPythonNode.execute(inliningTarget, pointer, false); + Object object = toPythonNode.execute(inliningTarget, pointer); if (object instanceof PythonAbstractNativeObject) { // Native objects use their native reference count and deallocator. if (CApiTransitions.subNativeRefCount(pointer, 1) == 0) { @@ -1048,7 +1045,7 @@ static Object createModule(Node node, CApiContext capiContext, ModuleSpec module PythonToNativeInternalNode.executeUncached(moduleSpec.originalModuleSpec, false), moduleDefPtr); TransformExceptionFromNativeNode.getUncached().execute(null, threadState, mName, result == NULLPTR, true, ErrorMessages.CREATION_FAILD_WITHOUT_EXCEPTION, ErrorMessages.CREATION_RAISED_EXCEPTION); - module = NativeToPythonTransferNode.executeRawUncached(result); + module = NativeToPythonInternalNode.executeUncached(result, true); /* * We are more strict than CPython and require this to be a PythonModule object. This @@ -1219,18 +1216,17 @@ public abstract static class CreateMemoryViewFromNativeNode extends PNodeWithCon public abstract PMemoryView execute(Node inliningTarget, PythonNativeObject object, int flags); @Specialization - static PMemoryView fromNative(PythonNativeObject buf, int flags, - @Bind Node inliningTarget, - @Cached(inline = false) PythonToNativeNode toNativeNode, - @Cached(inline = false) NativeToPythonTransferNode asPythonObjectNode, + static PMemoryView fromNative(Node inliningTarget, PythonNativeObject buf, int flags, + @Cached PythonToNativeInternalNode toNativeNode, + @Cached NativeToPythonInternalNode asPythonObjectNode, @Cached(inline = false) PyObjectCheckFunctionResultNode checkFunctionResultNode) { - long bufPointer = toNativeNode.executeLong(buf); + long bufPointer = toNativeNode.execute(inliningTarget, buf); try { PythonContext context = PythonContext.get(inliningTarget); var callable = CApiContext.getNativeSymbol(inliningTarget, FUN_GRAALPY_MEMORYVIEW_FROM_OBJECT); long result = ExternalFunctionInvoker.invokeGRAALPY_MEMORYVIEW_FROM_OBJECT(null, C_API_TIMING, context.ensureNativeContext(), BoundaryCallData.getUncached(), context.getThreadState(PythonLanguage.get(inliningTarget)), callable, bufPointer, flags); - return (PMemoryView) checkFunctionResultNode.execute(context, FUN_GRAALPY_MEMORYVIEW_FROM_OBJECT.getTsName(), asPythonObjectNode.executeRaw(result)); + return (PMemoryView) checkFunctionResultNode.execute(context, FUN_GRAALPY_MEMORYVIEW_FROM_OBJECT.getTsName(), asPythonObjectNode.executeTransfer(inliningTarget, result)); } finally { Reference.reachabilityFence(buf); } diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/ExternalFunctionNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/ExternalFunctionNodes.java index cc748f2672..93a5d225f9 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/ExternalFunctionNodes.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/ExternalFunctionNodes.java @@ -107,18 +107,14 @@ import com.oracle.graal.python.builtins.objects.cext.capi.ExternalFunctionNodesFactory.CheckIterNextResultNodeGen; import com.oracle.graal.python.builtins.objects.cext.capi.ExternalFunctionNodesFactory.CreateNativeArgsTupleNodeGen; import com.oracle.graal.python.builtins.objects.cext.capi.ExternalFunctionNodesFactory.CreateNativeKwNamesTupleNodeGen; -import com.oracle.graal.python.builtins.objects.cext.capi.ExternalFunctionNodesFactory.FromLongNodeGen; -import com.oracle.graal.python.builtins.objects.cext.capi.ExternalFunctionNodesFactory.FromUInt32NodeGen; import com.oracle.graal.python.builtins.objects.cext.capi.ExternalFunctionNodesFactory.PyObjectCheckFunctionResultNodeGen; import com.oracle.graal.python.builtins.objects.cext.capi.ExternalFunctionNodesFactory.ReleaseNativeArgsTupleNodeGen; -import com.oracle.graal.python.builtins.objects.cext.capi.ExternalFunctionNodesFactory.ToInt32NodeGen; -import com.oracle.graal.python.builtins.objects.cext.capi.ExternalFunctionNodesFactory.ToInt64NodeGen; import com.oracle.graal.python.builtins.objects.cext.capi.ExternalFunctionNodesFactory.ToPythonStringNodeGen; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.ArgDescriptor; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTiming; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.HandlePointerConverter; -import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativeToPythonNode; +import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativeToPythonInternalNode; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativeToPythonReturnNode; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeInternalNode; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeNode; @@ -176,7 +172,6 @@ import com.oracle.truffle.api.dsl.Bind; import com.oracle.truffle.api.dsl.Cached; import com.oracle.truffle.api.dsl.Cached.Shared; -import com.oracle.truffle.api.dsl.Fallback; import com.oracle.truffle.api.dsl.GenerateCached; import com.oracle.truffle.api.dsl.GenerateInline; import com.oracle.truffle.api.dsl.GenerateUncached; @@ -213,103 +208,6 @@ public static PKeyword[] createKwDefaults(NativeFunctionPointer callable, long c return new PKeyword[]{new PKeyword(KW_CALLABLE, callable), new PKeyword(KW_CLOSURE, closure)}; } - /** - * On Windows, "long" is 32 bits, so that we might need to convert int to long for consistency. - */ - @GenerateInline(false) - @GenerateUncached - public abstract static class FromLongNode extends CExtToJavaNode { - - @Specialization - static long doInt(int value) { - return value & 0xFFFFFFFFL; - } - - @Specialization - static long doLong(long value) { - return value; - } - - @Fallback - static Object doOther(Object value) { - assert CApiTransitions.isBackendPointerObject(value); - return value; - } - - @NeverDefault - public static FromLongNode create() { - return FromLongNodeGen.create(); - } - - public static FromLongNode getUncached() { - return FromLongNodeGen.getUncached(); - } - } - - @GenerateInline(false) - @GenerateUncached - public abstract static class FromUInt32Node extends CExtToJavaNode { - - @Specialization - static int doInt(int value) { - return value; - } - - @Specialization - static int doLong(long value) { - assert value < (1L << 32); - return (int) value; - } - - @NeverDefault - public static FromUInt32Node create() { - return FromUInt32NodeGen.create(); - } - - public static FromUInt32Node getUncached() { - return FromUInt32NodeGen.getUncached(); - } - } - - @GenerateInline(false) - public abstract static class ToInt64Node extends CExtToNativeNode { - - @Specialization - static long doInt(int value) { - return value; - } - - @Specialization - static long doLong(long value) { - return value; - } - - @Fallback - static Object doOther(Object value) { - assert CApiTransitions.isBackendPointerObject(value); - return value; - } - - @NeverDefault - public static ToInt64Node create() { - return ToInt64NodeGen.create(); - } - } - - @GenerateInline(false) - public abstract static class ToInt32Node extends CExtToNativeNode { - - @Specialization - static int doInt(int value) { - return value; - } - - @NeverDefault - public static ToInt32Node create() { - return ToInt32NodeGen.create(); - } - } - @GenerateInline(false) public static final class ToNativeBorrowedNode extends CExtToNativeNode { @@ -317,7 +215,7 @@ public static final class ToNativeBorrowedNode extends CExtToNativeNode { @Child private PythonToNativeNode toNative = PythonToNativeNode.create(); @Override - public Object execute(Object object) { + public long execute(Object object) { assert canBorrowDirectly(object); /* * In this case, it is not necessary to explicitly keep the promoted object alive @@ -329,7 +227,7 @@ public Object execute(Object object) { PythonContext ctx = PythonContext.get(this); Object promoted = ensurePythonObjectNode.execute(ctx, object, false); assert promoted == object || PythonToNativeInternalNode.isImmortal(ctx, promoted); - return toNative.executeLong(promoted); + return toNative.execute(promoted); } private static boolean canBorrowDirectly(Object object) { @@ -343,7 +241,7 @@ private static boolean canBorrowDirectly(Object object) { @TruffleBoundary(allowInlining = true) public static long executeUncached(Object object) { Object promoted = EnsurePythonObjectNode.executeUncached(PythonContext.get(null), object, false); - return PythonToNativeNode.executeLongUncached(promoted); + return PythonToNativeInternalNode.executeUncached(promoted, false); } } @@ -354,8 +252,8 @@ public abstract static class ToPythonStringNode extends CExtToJavaNode { static Object doIt(long pointer, @Bind Node inliningTarget, @Cached CastToTruffleStringNode castToStringNode, - @Cached NativeToPythonNode nativeToPythonNode) { - Object result = nativeToPythonNode.executeRaw(pointer); + @Cached NativeToPythonInternalNode nativeToPythonNode) { + Object result = nativeToPythonNode.execute(inliningTarget, pointer); if (result == PNone.NO_VALUE) { return result; } @@ -700,7 +598,7 @@ final Object nativeToPython(PythonContext context, long lresult) { nativeToPythonReturnNode = insert(NativeToPythonReturnNode.create()); checkResultNode = insert(PyObjectCheckFunctionResultNodeGen.create()); } - return checkResultNode.execute(context, name, nativeToPythonReturnNode.executeRaw(lresult)); + return checkResultNode.execute(context, name, nativeToPythonReturnNode.execute(lresult)); } } @@ -757,7 +655,7 @@ final NativeToPythonReturnNode ensureNativeToPythonReturnNode() { } final Object returnNativeObjectToPython(long lresult) { - Object result = ensureNativeToPythonReturnNode().executeRaw(lresult); + Object result = ensureNativeToPythonReturnNode().execute(lresult); if (result == PNone.NO_VALUE) { transformExceptionFromNative(); } @@ -796,7 +694,7 @@ protected Object readArgumentsAndInvokeExternalFunction(VirtualFrame frame, Nati } else { managedArgsTuple = PFactory.createTuple(context.getLanguage(this), args); assert EnsurePythonObjectNode.doesNotNeedPromotion(managedArgsTuple); - argsTuplePtr = argsTupleToNativeNode.executeLong(managedArgsTuple); + argsTuplePtr = argsTupleToNativeNode.execute(managedArgsTuple); } try { @@ -872,7 +770,7 @@ protected Object readArgumentsAndInvokeExternalFunction(VirtualFrame frame, Nati } else { managedArgsTuple = PFactory.createTuple(context.getLanguage(this), args); assert EnsurePythonObjectNode.doesNotNeedPromotion(managedArgsTuple); - argsTuplePtr = argsToNativeNode.executeLong(managedArgsTuple); + argsTuplePtr = argsToNativeNode.execute(managedArgsTuple); } PKeyword[] kwargs = readKwargsNode.execute(frame); @@ -881,7 +779,7 @@ protected Object readArgumentsAndInvokeExternalFunction(VirtualFrame frame, Nati try { long l = ExternalFunctionInvoker.invokePYCFUNCTION_WITH_KEYWORDS(frame, timing, context.ensureNativeContext(), boundaryCallData, ensureGetThreadStateNode().executeCached(context), - boundFunction, selfToNativeNode.executeLong(self), argsTuplePtr, kwargsToNativeNode.executeLong(kwargsDict)); + boundFunction, selfToNativeNode.execute(self), argsTuplePtr, kwargsToNativeNode.execute(kwargsDict)); return nativeToPython(context, l); } finally { Reference.reachabilityFence(self); @@ -990,7 +888,7 @@ protected Object readArgumentsAndInvokeExternalFunction(VirtualFrame frame, Nati } else { managedArgsTuple = PFactory.createTuple(context.getLanguage(this), args); assert EnsurePythonObjectNode.doesNotNeedPromotion(managedArgsTuple); - argsTuplePtr = argsTupleToNativeNode.executeLong(managedArgsTuple); + argsTuplePtr = argsTupleToNativeNode.execute(managedArgsTuple); } PKeyword[] kwargs = readKwargsNode.execute(frame); @@ -1035,7 +933,7 @@ protected Object readArgumentsAndInvokeExternalFunction(VirtualFrame frame, Nati } else { managedArgsTuple = PFactory.createTuple(context.getLanguage(this), args); assert EnsurePythonObjectNode.doesNotNeedPromotion(managedArgsTuple); - argsTuplePtr = argsTupleToNativeNode.executeLong(managedArgsTuple); + argsTuplePtr = argsTupleToNativeNode.execute(managedArgsTuple); } PKeyword[] kwargs = readKwargsNode.execute(frame); @@ -1093,7 +991,7 @@ protected Object readArgumentsAndInvokeExternalFunction(VirtualFrame frame, Nati } else { managedArgsTuple = PFactory.createTuple(context.getLanguage(this), args); assert EnsurePythonObjectNode.doesNotNeedPromotion(managedArgsTuple); - argsTuplePtr = argsTupleToNativeNode.executeLong(managedArgsTuple); + argsTuplePtr = argsTupleToNativeNode.execute(managedArgsTuple); } PKeyword[] kwargs = readKwargsNode.execute(frame); @@ -1187,7 +1085,7 @@ final Object invokeExternalFunction(VirtualFrame frame, NativeFunctionPointer bo PythonContext context = PythonContext.get(this); try { long l = ExternalFunctionInvoker.invokePYCFUNCTION(frame, timing, context.ensureNativeContext(), boundaryCallData, ensureGetThreadStateNode().executeCached(context), boundFunction, - selfToNativeNode.executeLong(self), arg); + selfToNativeNode.execute(self), arg); return nativeToPython(context, l); } finally { Reference.reachabilityFence(self); @@ -1218,7 +1116,7 @@ protected Object readArgumentsAndInvokeExternalFunction(VirtualFrame frame, Nati Object self = readSelf(frame); Object arg = ensurePythonObject(readArgNode.execute(frame)); try { - return invokeExternalFunction(frame, boundFunction, self, argToNativeNode.executeLong(arg)); + return invokeExternalFunction(frame, boundFunction, self, argToNativeNode.execute(arg)); } finally { Reference.reachabilityFence(arg); } @@ -1288,7 +1186,7 @@ protected Object readArgumentsAndInvokeExternalFunction(VirtualFrame frame, Nati try { long l = ExternalFunctionInvoker.invokePYCFUNCTION_FAST_WITH_KEYWORDS(frame, timing, context.ensureNativeContext(), boundaryCallData, ensureGetThreadStateNode().executeCached(context), - boundFunction, argToNativeNode.executeLong(self), nativeFastcallArgs, args.length, kwnamesTuplePtr); + boundFunction, argToNativeNode.execute(self), nativeFastcallArgs, args.length, kwnamesTuplePtr); return nativeToPython(context, l); } finally { MethFastcallRoot.freeFastcallArgsArray(nativeFastcallArgs); @@ -1370,7 +1268,7 @@ protected Object readArgumentsAndInvokeExternalFunction(VirtualFrame frame, Nati try { long l = ExternalFunctionInvoker.invokePYCMETHOD(frame, timing, context.ensureNativeContext(), boundaryCallData, ensureGetThreadStateNode().executeCached(context), - boundFunction, argToNativeNode.executeLong(self), argToNativeNode.executeLong(cls), nativeFastcallArgs, args.length, kwNamesToNativeNode.executeLong(kwnamesTuple)); + boundFunction, argToNativeNode.execute(self), argToNativeNode.execute(cls), nativeFastcallArgs, args.length, kwNamesToNativeNode.execute(kwnamesTuple)); return nativeToPython(context, l); } finally { MethFastcallRoot.freeFastcallArgsArray(nativeFastcallArgs); @@ -1434,7 +1332,7 @@ protected Object readArgumentsAndInvokeExternalFunction(VirtualFrame frame, Nati try { long l = ExternalFunctionInvoker.invokePYCFUNCTION_FAST(frame, timing, context.ensureNativeContext(), boundaryCallData, ensureGetThreadStateNode().executeCached(context), - boundFunction, argToNativeNode.executeLong(self), argsArray, promotedArgs.length); + boundFunction, argToNativeNode.execute(self), argsArray, promotedArgs.length); return nativeToPython(context, l); } finally { freeFastcallArgsArray(argsArray); @@ -1456,7 +1354,7 @@ static long createFastcallArgsArray(Object[] data, PythonToNativeNode argToNativ long ptr = NativeMemory.malloc((long) data.length * NativeMemory.POINTER_SIZE); for (int i = 0; i < data.length; i++) { assert EnsurePythonObjectNode.doesNotNeedPromotion(data[i]); - NativeMemory.writePtrArrayElement(ptr, i, argToNativeNode.executeLong(data[i])); + NativeMemory.writePtrArrayElement(ptr, i, argToNativeNode.execute(data[i])); } return ptr; } @@ -2016,7 +1914,7 @@ protected Object readArgumentsAndInvokeExternalFunction(VirtualFrame frame, Nati Object self = readSelf(frame); long lresult = invokeExternalFunction(frame, boundFunction, self); PythonContext context = PythonContext.get(this); - return checkIterNextResultNode.execute(context.getThreadState(context.getLanguage()), ensureNativeToPythonReturnNode().executeRaw(lresult)); + return checkIterNextResultNode.execute(context.getThreadState(context.getLanguage()), ensureNativeToPythonReturnNode().execute(lresult)); } @Override @@ -2385,14 +2283,14 @@ static long doGeneric(PythonContext context, Object[] args, NativeFunctionPointer callable = CApiContext.getNativeSymbol(inliningTarget, FUN_PY_TYPE_GENERIC_ALLOC); long op = ExternalFunctionInvoker.invokeTYPE_GENERIC_ALLOC(null, TIMING_invokeTypeGenericAlloc, context.ensureNativeContext(), BoundaryCallData.getUncached(), context.getThreadState(context.getLanguage(inliningTarget)), callable, - pythonToNativeNode.execute(inliningTarget, argsTupleClass, false), n); + pythonToNativeNode.execute(inliningTarget, argsTupleClass), n); long obItem = CStructAccess.getFieldPtr(op, CFields.PyTupleObject__ob_item); for (int i = 0; i < n; i++) { Object promoted = materializePrimitiveNode.execute(context, args[i], false); args[i] = promoted; - writePtrArrayElement(obItem, i, pythonToNativeNode.execute(inliningTarget, promoted, true)); + writePtrArrayElement(obItem, i, pythonToNativeNode.executeNewRef(inliningTarget, promoted)); } if (LOGGER.isLoggable(Level.FINE)) { @@ -2431,15 +2329,16 @@ static long doGeneric(PythonContext context, Object[] args, NativeFunctionPointer callable = CApiContext.getNativeSymbol(inliningTarget, FUN_PY_TYPE_GENERIC_ALLOC); long op = ExternalFunctionInvoker.invokeTYPE_GENERIC_ALLOC(null, CreateNativeArgsTupleNode.TIMING_invokeTypeGenericAlloc, context.ensureNativeContext(), BoundaryCallData.getUncached(), context.getThreadState(context.getLanguage(inliningTarget)), callable, - pythonToNativeNode.execute(inliningTarget, argsTupleClass, false), n); + pythonToNativeNode.execute(inliningTarget, argsTupleClass), n); long obItem = CStructAccess.getFieldPtr(op, CFields.PyTupleObject__ob_item); for (int i = 0; i < n; i++) { assert args[i] instanceof TruffleString; PString promoted = internStringArg(context, (TruffleString) args[i]); + assert EnsurePythonObjectNode.doesNotNeedPromotion(promoted); args[i] = promoted; - long nativeString = pythonToNativeNode.execute(inliningTarget, promoted, true); + long nativeString = pythonToNativeNode.executeNewRef(inliningTarget, promoted); CApiTransitions.setGraalPyUnicodeObjectInterned(HandlePointerConverter.pointerToStub(nativeString), CApiTransitions.GRAALPY_UNICODE_INTERN_STATE_INTERNED); writePtrArrayElement(obItem, i, nativeString); } diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/PThreadState.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/PThreadState.java index 17bf7287e3..fda55ba29e 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/PThreadState.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/PThreadState.java @@ -50,7 +50,7 @@ import com.oracle.graal.python.PythonLanguage; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.HandlePointerConverter; -import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeNode; +import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeInternalNode; import com.oracle.graal.python.builtins.objects.cext.structs.CFields; import com.oracle.graal.python.builtins.objects.cext.structs.CStructAccess; import com.oracle.graal.python.builtins.objects.cext.structs.CStructs; @@ -64,15 +64,13 @@ import com.oracle.truffle.api.CompilerDirectives; import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; import com.oracle.truffle.api.TruffleLogger; -import com.oracle.truffle.api.interop.InteropLibrary; /** * Emulates CPython's {@code PyThreadState} struct. *

- * This wrapper does intentionally not implement {@link InteropLibrary#isPointer(Object)}, - * {@link InteropLibrary#asPointer(Object)}, and {@link InteropLibrary#toNative(Object)} because the - * factory method {@link #getOrCreateNativeThreadState(PythonLanguage, PythonContext)} will already - * return the appropriate pointer object that implements that. + * This wrapper intentionally does not expose pointer conversion because the factory method + * {@link #getOrCreateNativeThreadState(PythonLanguage, PythonContext)} returns the appropriate + * native pointer. *

*/ public abstract class PThreadState { @@ -114,14 +112,14 @@ public static PDict getOrCreateThreadStateDict(PythonContext context, PythonThre PDict threadStateDict = threadState.getDict(); if (threadStateDict != null) { - assert PythonToNativeNode.executeLongUncached(threadStateDict) == CStructAccess.readPtrField(nativeThreadState, CFields.PyThreadState__dict); + assert PythonToNativeInternalNode.executeUncached(threadStateDict, false) == CStructAccess.readPtrField(nativeThreadState, CFields.PyThreadState__dict); return threadStateDict; } threadStateDict = PFactory.createDict(context.getLanguage()); threadState.setDict(threadStateDict); assert CStructAccess.readPtrField(nativeThreadState, CFields.PyThreadState__dict) == NULLPTR; - CStructAccess.writePtrField(nativeThreadState, CFields.PyThreadState__dict, PythonToNativeNode.executeLongUncached(threadStateDict)); + CStructAccess.writePtrField(nativeThreadState, CFields.PyThreadState__dict, PythonToNativeInternalNode.executeUncached(threadStateDict, false)); return threadStateDict; } diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/PyCFunctionWrapper.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/PyCFunctionWrapper.java index f0d2945329..6b1969a69a 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/PyCFunctionWrapper.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/PyCFunctionWrapper.java @@ -54,7 +54,7 @@ import com.oracle.graal.python.builtins.objects.PNone; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTiming; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativeToPythonInternalNode; -import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeNewRefNode; +import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeInternalNode; import com.oracle.graal.python.builtins.objects.cext.common.CExtCommonNodes.TransformExceptionToNativeNode; import com.oracle.graal.python.builtins.objects.cext.common.CExtContext; import com.oracle.graal.python.builtins.objects.function.PBuiltinFunction; @@ -211,7 +211,7 @@ public long executeUnary(long arg0) { Object[] pArgs = CreateArgumentsNode.executeUncached(callTargetName, PythonUtils.EMPTY_OBJECT_ARRAY, PKeyword.EMPTY_KEYWORDS, signature, jArg0, null, defaults, PKeyword.EMPTY_KEYWORDS, false); Object result = SimpleIndirectInvokeNode.executeUncached(callTarget, pArgs); - return PythonToNativeNewRefNode.executeLongUncached(result); + return PythonToNativeInternalNode.executeNewRefUncached(result); } catch (Throwable t) { throw checkThrowableBeforeNative(t, toString(), ""); } @@ -246,7 +246,7 @@ public long executeBinary(long arg0, long arg1) { Object[] pArgs = CreateArgumentsNode.executeUncached(callTargetName, new Object[]{jArg1}, PKeyword.EMPTY_KEYWORDS, signature, jArg0, null, defaults, PKeyword.EMPTY_KEYWORDS, false); Object result = SimpleIndirectInvokeNode.executeUncached(callTarget, pArgs); - return PythonToNativeNewRefNode.executeLongUncached(result); + return PythonToNativeInternalNode.executeNewRefUncached(result); } catch (Throwable t) { throw checkThrowableBeforeNative(t, toString(), ""); } @@ -282,7 +282,7 @@ public long executeVarargs(long arg0, long arg1) { Object[] pArgs = CreateArgumentsNode.executeUncached(callTargetName, starArgsArray, PKeyword.EMPTY_KEYWORDS, signature, receiver, null, defaults, PKeyword.EMPTY_KEYWORDS, false); Object result = SimpleIndirectInvokeNode.executeUncached(callTarget, pArgs); - return PythonToNativeNewRefNode.executeLongUncached(result); + return PythonToNativeInternalNode.executeNewRefUncached(result); } catch (Throwable t) { throw checkThrowableBeforeNative(t, toString(), ""); } @@ -320,7 +320,7 @@ public long executeKeywords(long arg0, long arg1, long arg2) { Object[] pArgs = CreateArgumentsNode.executeUncached(callTargetName, starArgsArray, kwArgsArray, signature, receiver, null, defaults, PKeyword.EMPTY_KEYWORDS, false); Object result = SimpleIndirectInvokeNode.executeUncached(callTarget, pArgs); - return PythonToNativeNewRefNode.executeLongUncached(result); + return PythonToNativeInternalNode.executeNewRefUncached(result); } catch (Throwable t) { throw checkThrowableBeforeNative(t, toString(), ""); } diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/PyDateTimeCAPIWrapper.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/PyDateTimeCAPIWrapper.java index 6805942e6c..269cff21d8 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/PyDateTimeCAPIWrapper.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/PyDateTimeCAPIWrapper.java @@ -52,7 +52,7 @@ import com.oracle.graal.python.builtins.modules.cext.PythonCextBuiltinRegistry; import com.oracle.graal.python.builtins.objects.capsule.PyCapsule; -import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeNewRefNode; +import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeInternalNode; import com.oracle.graal.python.builtins.objects.cext.structs.CFields; import com.oracle.graal.python.builtins.objects.cext.structs.CStructs; import com.oracle.graal.python.builtins.objects.type.PythonManagedClass; @@ -153,27 +153,26 @@ public static void destroyWrapper(PyCapsule capsule) { private static long allocatePyDatetimeCAPI(Object datetimeModule) { PyObjectGetAttr getAttr = PyObjectGetAttr.getUncached(); - PythonToNativeNewRefNode toNativeNode = PythonToNativeNewRefNode.getUncached(); PythonManagedClass date = (PythonManagedClass) getAttr.execute(null, datetimeModule, T_DATE); SetBasicSizeNode.executeUncached(date, CStructs.PyDateTime_Date.size()); - long dateType = toNativeNode.executeLong(date); + long dateType = PythonToNativeInternalNode.executeNewRefUncached(date); PythonManagedClass dt = (PythonManagedClass) getAttr.execute(null, datetimeModule, T_DATETIME); SetBasicSizeNode.executeUncached(dt, CStructs.PyDateTime_DateTime.size()); - long datetimeType = toNativeNode.executeLong(dt); + long datetimeType = PythonToNativeInternalNode.executeNewRefUncached(dt); PythonManagedClass time = (PythonManagedClass) getAttr.execute(null, datetimeModule, T_TIME); SetBasicSizeNode.executeUncached(time, CStructs.PyDateTime_Time.size()); - long timeType = toNativeNode.executeLong(time); + long timeType = PythonToNativeInternalNode.executeNewRefUncached(time); PythonManagedClass delta = (PythonManagedClass) getAttr.execute(null, datetimeModule, T_TIMEDELTA); SetBasicSizeNode.executeUncached(delta, CStructs.PyDateTime_Delta.size()); - long deltaType = toNativeNode.executeLong(delta); + long deltaType = PythonToNativeInternalNode.executeNewRefUncached(delta); - long tzInfoType = toNativeNode.executeLong(getAttr.execute(null, datetimeModule, T_TZINFO)); + long tzInfoType = PythonToNativeInternalNode.executeNewRefUncached(getAttr.execute(null, datetimeModule, T_TZINFO)); Object timezoneType = getAttr.execute(null, datetimeModule, T_TIMEZONE); - long timezoneUTC = toNativeNode.executeLong(getAttr.execute(null, timezoneType, T_UTC)); + long timezoneUTC = PythonToNativeInternalNode.executeNewRefUncached(getAttr.execute(null, timezoneType, T_UTC)); long mem = allocate(CStructs.PyDateTime_CAPI); writePtrField(mem, CFields.PyDateTime_CAPI__DateType, dateType); diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/PyMemoryViewWrapper.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/PyMemoryViewWrapper.java index 8e2ae4304b..6fcad6cfb3 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/PyMemoryViewWrapper.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/PyMemoryViewWrapper.java @@ -55,7 +55,7 @@ import static com.oracle.truffle.api.CompilerDirectives.shouldNotReachHere; import com.oracle.graal.python.builtins.objects.buffer.PythonBufferAccessLibrary; -import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeNewRefNode; +import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeInternalNode; import com.oracle.graal.python.builtins.objects.cext.structs.CFields; import com.oracle.graal.python.builtins.objects.cext.structs.CStructs; import com.oracle.graal.python.builtins.objects.ints.PInt; @@ -93,7 +93,7 @@ public static long allocate(PMemoryView object) { long memWithHead = calloc(CStructs.PyMemoryViewObject.size() + presize); long mem = memWithHead + presize; - writePtrField(mem, PyObject__ob_type, PythonToNativeNewRefNode.executeLongUncached(type)); + writePtrField(mem, PyObject__ob_type, PythonToNativeInternalNode.executeNewRefUncached(type)); writeLongField(mem, PyObject__ob_refcnt, PythonObject.IMMORTAL_REFCNT); writeIntField(mem, PyMemoryViewObject__flags, object.getFlags()); writeLongField(mem, PyMemoryViewObject__exports, object.getExports().get()); @@ -117,7 +117,7 @@ public static long allocate(PMemoryView object) { } if (object.getOwner() != null) { - writePtrField(view, CFields.Py_buffer__obj, PythonToNativeNewRefNode.executeLongUncached(object.getOwner())); + writePtrField(view, CFields.Py_buffer__obj, PythonToNativeInternalNode.executeNewRefUncached(object.getOwner())); } writeLongField(view, CFields.Py_buffer__len, object.getLength()); writeLongField(view, CFields.Py_buffer__itemsize, object.getItemSize()); diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/TpSlotWrapper.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/TpSlotWrapper.java index 33b269e2a5..b73045de85 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/TpSlotWrapper.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/TpSlotWrapper.java @@ -57,7 +57,7 @@ import com.oracle.graal.python.builtins.objects.PNone; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTiming; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativeToPythonInternalNode; -import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeNewRefNode; +import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeInternalNode; import com.oracle.graal.python.builtins.objects.cext.common.CExtCommonNodes.TransformExceptionToNativeNode; import com.oracle.graal.python.builtins.objects.function.PKeyword; import com.oracle.graal.python.builtins.objects.ints.PInt; @@ -246,7 +246,7 @@ private long executeGetAttr(long arg0, long arg1) { Object jArg0 = NativeToPythonInternalNode.executeUncached(arg0, false); Object jArg1 = NativeToPythonInternalNode.executeUncached(arg1, false); Object result = CallManagedSlotGetAttrNode.executeUncached(getSlot(), jArg0, jArg1); - return PythonToNativeNewRefNode.executeLongUncached(result); + return PythonToNativeInternalNode.executeNewRefUncached(result); } catch (Throwable t) { throw checkThrowableBeforeNative(t, "GetAttrWrapper", getSlot()); } @@ -279,7 +279,7 @@ private long executeBinarySlot(long arg0, long arg1) { Object jArg0 = NativeToPythonInternalNode.executeUncached(arg0, false); Object jArg1 = NativeToPythonInternalNode.executeUncached(arg1, false); Object result = CallSlotBinaryFuncNode.executeUncached(getSlot(), jArg0, jArg1); - return PythonToNativeNewRefNode.executeLongUncached(result); + return PythonToNativeInternalNode.executeNewRefUncached(result); } catch (Throwable t) { throw checkThrowableBeforeNative(t, "BinarySlotFuncWrapper", getSlot()); } @@ -370,7 +370,7 @@ private long executeBinaryOpSlot(long arg0, long arg1) { TpSlot otherSlot = binaryOp.getSlotValue(GetTpSlotsNode.executeUncached(otherType)); boolean sameTypes = IsSameTypeNode.executeUncached(receiverType, otherType); Object result = CallSlotBinaryOpNode.executeUncached(getSlot(), receiver, receiverType, other, otherSlot, otherType, sameTypes, binaryOp); - return PythonToNativeNewRefNode.executeLongUncached(result); + return PythonToNativeInternalNode.executeNewRefUncached(result); } catch (Throwable t) { throw checkThrowableBeforeNative(t, "BinaryOpSlotFuncWrapper", getSlot()); } @@ -402,7 +402,7 @@ private long executeUnary(long arg0) { try { Object jArg0 = NativeToPythonInternalNode.executeUncached(arg0, false); Object result = CallSlotUnaryNode.executeUncached(getSlot(), jArg0); - return PythonToNativeNewRefNode.executeLongUncached(result); + return PythonToNativeInternalNode.executeNewRefUncached(result); } catch (Throwable t) { throw checkThrowableBeforeNative(t, "UnaryFuncWrapper", getSlot()); } @@ -439,7 +439,7 @@ private long executeIterNext(long arg0) { } catch (IteratorExhausted e) { return NULLPTR; } - return PythonToNativeNewRefNode.executeLongUncached(result); + return PythonToNativeInternalNode.executeNewRefUncached(result); } catch (Throwable t) { throw checkThrowableBeforeNative(t, "IterNextWrapper", getSlot()); } @@ -681,7 +681,7 @@ private long executeNew(long arg0, long arg1, long arg2) { PKeyword[] kwArgsArray = ExpandKeywordStarargsNode.executeUncached(kwArgs); Object result = CallSlotTpNewNode.executeUncached(getSlot(), receiver, pArgs, kwArgsArray); - return PythonToNativeNewRefNode.executeLongUncached(result); + return PythonToNativeInternalNode.executeNewRefUncached(result); } catch (Throwable t) { throw checkThrowableBeforeNative(t, "NewWrapper", getSlot()); } @@ -717,7 +717,7 @@ private long executeCall(long arg0, long arg1, long arg2) { Object[] starArgsArray = ExecutePositionalStarargsNode.executeUncached(starArgs); PKeyword[] kwArgsArray = ExpandKeywordStarargsNode.executeUncached(kwArgs); Object result = CallSlotTpCallNode.executeUncached(getSlot(), receiver, starArgsArray, kwArgsArray); - return PythonToNativeNewRefNode.executeLongUncached(result); + return PythonToNativeInternalNode.executeNewRefUncached(result); } catch (Throwable t) { throw checkThrowableBeforeNative(t, "CallWrapper", getSlot()); } @@ -756,7 +756,7 @@ private long executeNbPower(long arg0, long arg1, long arg2) { TpSlots wSlots = GetTpSlotsNode.executeUncached(wType); boolean sameTypes = IsSameTypeNode.executeUncached(vType, wType); Object result = CallSlotNbPowerNode.executeUncached(getSlot(), v, vType, w, wSlots.nb_power(), wType, z, sameTypes); - return PythonToNativeNewRefNode.executeLongUncached(result); + return PythonToNativeInternalNode.executeNewRefUncached(result); } catch (Throwable t) { throw checkThrowableBeforeNative(t, "NbPowerWrapper", getSlot()); } @@ -791,7 +791,7 @@ private long executeNbInPlacePower(long arg0, long arg1, long arg2) { Object w = NativeToPythonInternalNode.executeUncached(arg1, false); Object z = NativeToPythonInternalNode.executeUncached(arg2, false); Object result = CallSlotNbInPlacePowerNode.executeUncached(getSlot(), v, w, z); - return PythonToNativeNewRefNode.executeLongUncached(result); + return PythonToNativeInternalNode.executeNewRefUncached(result); } catch (Throwable t) { throw checkThrowableBeforeNative(t, "NbInPlacePowerWrapper", getSlot()); } @@ -826,7 +826,7 @@ private long executeRichcmpFunction(long arg0, long arg1, int arg2) { Object jArg1 = NativeToPythonInternalNode.executeUncached(arg1, false); RichCmpOp op = RichCmpOp.fromNative(arg2); Object result = CallSlotRichCmpNode.executeUncached(getSlot(), jArg0, jArg1, op); - return PythonToNativeNewRefNode.executeLongUncached(result); + return PythonToNativeInternalNode.executeNewRefUncached(result); } catch (Throwable t) { throw checkThrowableBeforeNative(t, "RichcmpFunctionWrapper", getSlot()); } @@ -859,7 +859,7 @@ private long executeSsizeargfuncSlot(long arg0, long arg1) { Object jArg0 = NativeToPythonInternalNode.executeUncached(arg0, false); int index = ssizeAsIntUncached(arg1); Object result = CallSlotSizeArgFun.executeUncached(getSlot(), jArg0, index); - return PythonToNativeNewRefNode.executeLongUncached(result); + return PythonToNativeInternalNode.executeNewRefUncached(result); } catch (Throwable t) { throw checkThrowableBeforeNative(t, "SsizeargfuncWrapper", getSlot()); } @@ -1001,7 +1001,7 @@ private long executeDescrGetFunction(long arg0, long arg1, long arg2) { Object obj = NativeToPythonInternalNode.executeUncached(arg1, false); Object cls = NativeToPythonInternalNode.executeUncached(arg2, false); Object result = CallSlotDescrGet.executeUncached(getSlot(), receiver, obj, cls); - return PythonToNativeNewRefNode.executeLongUncached(result); + return PythonToNativeInternalNode.executeNewRefUncached(result); } catch (Throwable t) { throw checkThrowableBeforeNative(t, "DescrGetFunctionWrapper", getSlot()); } diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/transitions/ArgDescriptor.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/transitions/ArgDescriptor.java index ab453c27f5..88c8f410d3 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/transitions/ArgDescriptor.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/transitions/ArgDescriptor.java @@ -41,7 +41,6 @@ package com.oracle.graal.python.builtins.objects.cext.capi.transitions; import com.oracle.graal.python.annotations.NativeSimpleType; -import com.oracle.graal.python.builtins.objects.cext.capi.ExternalFunctionNodes.FromLongNode; import com.oracle.graal.python.builtins.objects.cext.capi.ExternalFunctionNodes.ToNativeBorrowedNode; import com.oracle.graal.python.builtins.objects.cext.capi.ExternalFunctionNodes.ToPythonStringNode; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.CharPtrToPythonNode; @@ -83,7 +82,7 @@ enum ArgBehavior { UInt32(NativeSimpleType.SINT32), Int64(NativeSimpleType.SINT64), UInt64(NativeSimpleType.SINT64), - Long(NativeSimpleType.SINT64, null, FromLongNode::create, FromLongNode.getUncached()), + Long(NativeSimpleType.SINT64), Float32(NativeSimpleType.FLOAT), Float64(NativeSimpleType.DOUBLE), Void(NativeSimpleType.VOID), diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/transitions/CApiTransitions.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/transitions/CApiTransitions.java index 778ee9bb6b..4dd463333d 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/transitions/CApiTransitions.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/transitions/CApiTransitions.java @@ -91,7 +91,6 @@ import com.oracle.graal.python.builtins.objects.cext.capi.PyMemoryViewWrapper; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitionsFactory.AllocateNativeObjectStubNodeGen; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitionsFactory.FirstToNativeNodeGen; -import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitionsFactory.NativePtrToPythonNodeGen; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitionsFactory.NativeToPythonClassInternalNodeGen; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitionsFactory.NativeToPythonClassNodeGen; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitionsFactory.NativeToPythonInternalNodeGen; @@ -152,9 +151,6 @@ import com.oracle.truffle.api.dsl.ImportStatic; import com.oracle.truffle.api.dsl.NeverDefault; import com.oracle.truffle.api.dsl.Specialization; -import com.oracle.truffle.api.interop.InteropLibrary; -import com.oracle.truffle.api.interop.UnsupportedMessageException; -import com.oracle.truffle.api.library.CachedLibrary; import com.oracle.truffle.api.nodes.Node; import com.oracle.truffle.api.profiles.InlinedBranchProfile; import com.oracle.truffle.api.profiles.InlinedConditionProfile; @@ -424,7 +420,7 @@ public NativeStorageReference(HandleContext handleContext, NativeSequenceStorage } } - public Object getPtr() { + public long getPtr() { return ptr; } @@ -443,13 +439,7 @@ public void setSize(int size) { @Override @TruffleBoundary public String toString() { - Object ptrStr; - try { - ptrStr = Long.toHexString(InteropLibrary.getUncached().asPointer(ptr)); - } catch (UnsupportedMessageException e) { - ptrStr = ptr; - } - return String.format("NativeStorageReference<0x%s, %d>", ptrStr, size); + return String.format("NativeStorageReference<0x%x, %d>", ptr, size); } } @@ -716,7 +706,7 @@ private static void processNativeStorageReference(NativeStorageReference referen throw CompilerDirectives.shouldNotReachHere(t); } } - assert !InteropLibrary.getUncached().isNull(reference.ptr); + assert reference.ptr != NULLPTR; freeNativeStorage(reference); } @@ -726,7 +716,7 @@ private static void processPyCapsuleReference(PyCapsuleReference reference) { // Our capsule is dead, so create a temporary copy that doesn't have a reference anymore PyCapsule capsule = PFactory.createCapsule(PythonLanguage.get(null), reference.data); assert EnsurePythonObjectNode.doesNotNeedPromotion(capsule); - long capsulePointer = PythonToNativeNode.executeLongUncached(capsule); + long capsulePointer = PythonToNativeInternalNode.executeUncached(capsule, false); try { ExternalFunctionInvoker.invokeGRAALPY_CAPSULE_CALL_DESTRUCTOR( CApiContext.getNativeSymbol(null, NativeCAPISymbol.FUN_GRAALPY_CAPSULE_CALL_DESTRUCTOR).getAddress(), @@ -1722,7 +1712,10 @@ private static T logResult(T value) { @GenerateInline(false) public abstract static class CharPtrToPythonNode extends CExtToJavaNode { - public abstract Object execute(long pointer); + @TruffleBoundary + public static Object executeUncached(long pointer) { + return CApiTransitionsFactory.CharPtrToPythonNodeGen.getUncached().execute(pointer); + } @Specialization static Object doGeneric(long pointer, @@ -1754,12 +1747,26 @@ public static CharPtrToPythonNode getUncached() { @ImportStatic(CApiContext.class) public abstract static class PythonToNativeInternalNode extends Node { + public final long execute(Node inliningTarget, Object object) { + return execute(inliningTarget, object, false); + } + + public final long executeNewRef(Node inliningTarget, Object object) { + return execute(inliningTarget, object, true); + } + @TruffleBoundary public static long executeUncached(Object obj, boolean needsTransfer) { return PythonToNativeInternalNodeGen.getUncached().execute(null, obj, needsTransfer); } - public abstract long execute(Node inliningTarget, Object object, boolean needsTransfer); + @TruffleBoundary + public static long executeNewRefUncached(Object obj) { + Object promoted = EnsurePythonObjectNode.executeUncached(PythonContext.get(null), obj, false); + return executeUncached(promoted, true); + } + + abstract long execute(Node inliningTarget, Object object, boolean needsTransfer); @Specialization static long doInteger(int i, @SuppressWarnings("unused") boolean needsTransfer) { @@ -2005,18 +2012,11 @@ private static boolean isGcTrackedIfNecessary(PythonObject object) { @GenerateInline(false) public abstract static class PythonToNativeNode extends CExtToNativeNode { - public abstract long executeLong(Object object); - - @TruffleBoundary - public static long executeLongUncached(Object obj) { - return getUncached().executeLong(obj); - } - @Specialization static long doGeneric(Object obj, @Bind Node inliningTarget, @Cached PythonToNativeInternalNode internalNode) { - return internalNode.execute(inliningTarget, obj, false); + return internalNode.execute(inliningTarget, obj); } @NeverDefault @@ -2060,13 +2060,6 @@ public static PythonToNativeNode getUncached() { @GenerateInline(false) public abstract static class PythonToNativeNewRefNode extends CExtToNativeNode { - public abstract long executeLong(Object object); - - @TruffleBoundary - public static long executeLongUncached(Object obj) { - return getUncached().executeLong(obj); - } - @Specialization static long doGeneric(Object obj, @Bind Node inliningTarget, @@ -2077,7 +2070,7 @@ static long doGeneric(Object obj, * will be kept alive with a strong reference from the handle table. */ Object promoted = ensurePythonObjectNode.execute(PythonContext.get(inliningTarget), obj, false); - return internalNode.execute(inliningTarget, promoted, true); + return internalNode.executeNewRef(inliningTarget, promoted); } @NeverDefault @@ -2095,15 +2088,23 @@ public static PythonToNativeNewRefNode getUncached() { @GenerateCached(false) public abstract static class NativeToPythonInternalNode extends Node { - public final Object execute(Node inliningTarget, long value, boolean needsTransfer) { - return execute(inliningTarget, value, needsTransfer, false); + public final Object execute(Node inliningTarget, long value) { + return execute(inliningTarget, value, false, false); + } + + public final Object executeTransfer(Node inliningTarget, long object) { + return execute(inliningTarget, object, true, false); + } + + public final Object executeTransferAndRelease(Node inliningTarget, long object) { + return execute(inliningTarget, object, true, true); } - public abstract Object execute(Node inliningTarget, long value, boolean needsTransfer, boolean release); + abstract Object execute(Node inliningTarget, long value, boolean needsTransfer, boolean release); @TruffleBoundary public static Object executeUncached(long value, boolean needsTransfer) { - return NativeToPythonInternalNodeGen.getUncached().execute(null, value, needsTransfer); + return NativeToPythonInternalNodeGen.getUncached().execute(null, value, needsTransfer, false); } @Specialization @@ -2220,23 +2221,21 @@ static PythonAbstractObject updateRef(Node node, InlinedExactClassProfile wrappe @GenerateInline(false) public abstract static class NativeToPythonNode extends CExtToJavaNode { - public abstract Object executeRaw(long pointer); - @TruffleBoundary public static Object executeRawUncached(long pointer) { - return NativeToPythonNodeGen.getUncached().executeRaw(pointer); + return NativeToPythonNodeGen.getUncached().execute(pointer); } @TruffleBoundary - public static Object executeUncached(Object obj) { - return NativeToPythonNodeGen.getUncached().execute(obj); + public static Object executeUncached(long pointer) { + return executeRawUncached(pointer); } @Specialization static Object doLong(long value, @Bind Node inliningTarget, @Shared @Cached NativeToPythonInternalNode nativeToPythonInternalNode) { - return nativeToPythonInternalNode.execute(inliningTarget, value, false); + return nativeToPythonInternalNode.execute(inliningTarget, value); } @NeverDefault @@ -2253,18 +2252,11 @@ public static NativeToPythonNode getUncached() { @GenerateInline(false) public abstract static class NativeToPythonTransferNode extends CExtToJavaNode { - public abstract Object executeRaw(long pointer); - - @TruffleBoundary - public static Object executeRawUncached(long pointer) { - return NativeToPythonTransferNodeGen.getUncached().executeRaw(pointer); - } - @Specialization static Object doLong(long pointer, @Bind Node inliningTarget, @Shared @Cached NativeToPythonInternalNode nativeToPythonInternalNode) { - return nativeToPythonInternalNode.execute(inliningTarget, pointer, true); + return nativeToPythonInternalNode.executeTransfer(inliningTarget, pointer); } @NeverDefault @@ -2281,8 +2273,6 @@ public static NativeToPythonTransferNode getUncached() { @GenerateInline(false) public abstract static class NativeToPythonReturnNode extends CExtToJavaNode { - public abstract Object executeRaw(long pointer); - @TruffleBoundary public static Object executeUncached(long pointer) { return NativeToPythonReturnNodeGen.getUncached().execute(pointer); @@ -2292,19 +2282,7 @@ public static Object executeUncached(long pointer) { static Object doLong(long pointer, @Bind Node inliningTarget, @Shared @Cached NativeToPythonInternalNode nativeToPythonInternalNode) { - return nativeToPythonInternalNode.execute(inliningTarget, pointer, true, true); - } - - @Specialization(limit = "1") - static Object doNativePointer(Object pointer, - @Bind Node inliningTarget, - @CachedLibrary("pointer") InteropLibrary lib, - @Shared @Cached NativeToPythonInternalNode nativeToPythonInternalNode) { - try { - return doLong(lib.asPointer(pointer), inliningTarget, nativeToPythonInternalNode); - } catch (UnsupportedMessageException e) { - throw CompilerDirectives.shouldNotReachHere(e); - } + return nativeToPythonInternalNode.executeTransferAndRelease(inliningTarget, pointer); } @NeverDefault @@ -2323,11 +2301,6 @@ public abstract static class NativePtrToPythonNode extends PNodeWithContext { public abstract Object execute(long object, boolean stealing); - @TruffleBoundary - public static Object executeUncached(long object, boolean stealing) { - return NativePtrToPythonNodeGen.getUncached().execute(object, stealing); - } - @Specialization @SuppressWarnings({"truffle-static-method", "truffle-sharing"}) static Object doNonWrapper(long pointer, boolean stealing, @@ -2527,7 +2500,7 @@ static Object doGeneric(Node inliningTarget, long pointer, public abstract static class NativeToPythonClassNode extends CExtToJavaNode { @TruffleBoundary - public static Object executeUncached(Object obj) { + public static Object executeUncached(long obj) { return NativeToPythonClassNodeGen.getUncached().execute(obj); } @@ -2538,18 +2511,6 @@ static Object doLong(long value, return nativeToPythonInternalNode.execute(inliningTarget, value); } - @Specialization(limit = "1") - static Object doInteropPointer(Object nativePointer, - @Bind Node inliningTarget, - @Shared @Cached NativeToPythonClassInternalNode nativeToPythonInternalNode, - @CachedLibrary("nativePointer") InteropLibrary lib) { - try { - return nativeToPythonInternalNode.execute(inliningTarget, lib.asPointer(nativePointer)); - } catch (UnsupportedMessageException e) { - throw CompilerDirectives.shouldNotReachHere(e); - } - } - @NeverDefault public static NativeToPythonClassNode create() { return NativeToPythonClassNodeGen.create(); diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/transitions/ToNativeTypeNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/transitions/ToNativeTypeNode.java index 273faed72a..a98b71a7a7 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/transitions/ToNativeTypeNode.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/transitions/ToNativeTypeNode.java @@ -66,8 +66,7 @@ import com.oracle.graal.python.builtins.objects.PNone; import com.oracle.graal.python.builtins.objects.PythonAbstractObject; import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.EnsurePythonObjectNode; -import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeNewRefNode; -import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeNode; +import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeInternalNode; import com.oracle.graal.python.builtins.objects.cext.structs.CFields; import com.oracle.graal.python.builtins.objects.cext.structs.CStructAccess; import com.oracle.graal.python.builtins.objects.cext.structs.CStructs; @@ -159,8 +158,6 @@ static void initializeType(PythonManagedClass clazz, long mem, boolean heaptype, TpSlots slots = GetTpSlotsNode.executeUncached(clazz); boolean isType = IsBuiltinClassExactProfile.profileClassSlowPath(clazz, PythonBuiltinClassType.PythonClass); - PythonToNativeNode toNative = PythonToNativeNode.getUncached(); - PythonToNativeNewRefNode toNativeNewRef = PythonToNativeNewRefNode.getUncached(); GetTypeFlagsNode getTypeFlagsNode = GetTypeFlagsNodeGen.getUncached(); PythonContext ctx = PythonContext.get(null); @@ -173,7 +170,7 @@ static void initializeType(PythonManagedClass clazz, long mem, boolean heaptype, writePtrField(mem, PyObject__ob_type, mem); } else { PythonAbstractObject promotedType = EnsurePythonObjectNode.executeUncached(ctx, GetClassNode.executeUncached(clazz)); - writePtrField(mem, PyObject__ob_type, toNative.executeLong(promotedType)); + writePtrField(mem, PyObject__ob_type, PythonToNativeInternalNode.executeUncached(promotedType, false)); } long flags = getTypeFlagsNode.execute(clazz); @@ -253,7 +250,7 @@ static void initializeType(PythonManagedClass clazz, long mem, boolean heaptype, if (!isType) { // "object" base needs to be initialized explicitly in capi.c PythonAbstractObject promotedBase = EnsurePythonObjectNode.executeUncached(ctx, base); - writePtrField(mem, CFields.PyTypeObject__tp_base, toNative.executeLong(promotedBase)); + writePtrField(mem, CFields.PyTypeObject__tp_base, PythonToNativeInternalNode.executeUncached(promotedBase, false)); } // TODO(fa): we could cache the dict instance on the class' native wrapper @@ -265,7 +262,7 @@ static void initializeType(PythonManagedClass clazz, long mem, boolean heaptype, dict.setDictStorage(HashingStorageAddAllToOther.executeUncached(dictStorage, storage)); } assert EnsurePythonObjectNode.doesNotNeedPromotion(dict); - writePtrField(mem, CFields.PyTypeObject__tp_dict, toNative.executeLong(dict)); + writePtrField(mem, CFields.PyTypeObject__tp_dict, PythonToNativeInternalNode.executeUncached(dict, false)); for (TpSlotMeta def : TpSlotMeta.VALUES) { if (!def.hasGroup() && def.hasNativeWrapperFactory()) { @@ -282,15 +279,15 @@ static void initializeType(PythonManagedClass clazz, long mem, boolean heaptype, clazz.basesTuple = PFactory.createTuple(language, GetBaseClassesNode.executeUncached(clazz)); } assert EnsurePythonObjectNode.doesNotNeedPromotion(clazz.basesTuple); - writePtrField(mem, CFields.PyTypeObject__tp_bases, toNative.executeLong(clazz.basesTuple)); + writePtrField(mem, CFields.PyTypeObject__tp_bases, PythonToNativeInternalNode.executeUncached(clazz.basesTuple, false)); if (clazz.mroStore == null) { clazz.mroStore = PFactory.createTuple(language, GetMroStorageNode.executeUncached(clazz)); } assert EnsurePythonObjectNode.doesNotNeedPromotion(clazz.mroStore); - writePtrField(mem, CFields.PyTypeObject__tp_mro, toNative.executeLong(clazz.mroStore)); + writePtrField(mem, CFields.PyTypeObject__tp_mro, PythonToNativeInternalNode.executeUncached(clazz.mroStore, false)); writePtrField(mem, CFields.PyTypeObject__tp_cache, NULLPTR); PDict subclasses = GetSubclassesNode.executeUncached(clazz); - writePtrField(mem, CFields.PyTypeObject__tp_subclasses, toNativeNewRef.executeLong(subclasses)); + writePtrField(mem, CFields.PyTypeObject__tp_subclasses, PythonToNativeInternalNode.executeNewRefUncached(subclasses)); writePtrField(mem, CFields.PyTypeObject__tp_weaklist, NULLPTR); writePtrField(mem, CFields.PyTypeObject__tp_del, lookup(clazz, PyTypeObject__tp_del, HiddenAttr.DEL)); @@ -310,11 +307,11 @@ static void initializeType(PythonManagedClass clazz, long mem, boolean heaptype, writePtrField(mem, CFields.PyHeapTypeObject__as_mapping, asMapping); writePtrField(mem, CFields.PyHeapTypeObject__as_sequence, asSequence); writePtrField(mem, CFields.PyHeapTypeObject__as_buffer, asBuffer); - writePtrField(mem, CFields.PyHeapTypeObject__ht_name, toNativeNewRef.executeLong(clazz.getName())); - writePtrField(mem, CFields.PyHeapTypeObject__ht_qualname, toNativeNewRef.executeLong(clazz.getQualName())); + writePtrField(mem, CFields.PyHeapTypeObject__ht_name, PythonToNativeInternalNode.executeNewRefUncached(clazz.getName())); + writePtrField(mem, CFields.PyHeapTypeObject__ht_qualname, PythonToNativeInternalNode.executeNewRefUncached(clazz.getQualName())); writePtrField(mem, CFields.PyHeapTypeObject__ht_module, NULLPTR); Object dunderSlots = clazz.getAttribute(SpecialAttributeNames.T___SLOTS__); - writePtrField(mem, CFields.PyHeapTypeObject__ht_slots, dunderSlots != PNone.NO_VALUE ? toNativeNewRef.executeLong(dunderSlots) : NULLPTR); + writePtrField(mem, CFields.PyHeapTypeObject__ht_slots, dunderSlots != PNone.NO_VALUE ? PythonToNativeInternalNode.executeNewRefUncached(dunderSlots) : NULLPTR); } } diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/common/CExtCommonNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/common/CExtCommonNodes.java index e3be85d589..731dc4219b 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/common/CExtCommonNodes.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/common/CExtCommonNodes.java @@ -44,10 +44,6 @@ import static com.oracle.graal.python.builtins.objects.cext.structs.CStructAccess.readPtrField; import static com.oracle.graal.python.builtins.objects.cext.structs.CStructAccess.writePtrField; import static com.oracle.graal.python.builtins.objects.str.StringUtils.byteIndexToCodepointIndex; -import static com.oracle.graal.python.runtime.nativeaccess.NativeMemory.readByteArrayElement; -import static com.oracle.graal.python.runtime.nativeaccess.NativeMemory.readByteArrayElements; -import static com.oracle.graal.python.runtime.nativeaccess.NativeMemory.readIntArrayElement; -import static com.oracle.graal.python.runtime.nativeaccess.NativeMemory.readShortArrayElement; import static com.oracle.graal.python.nodes.ErrorMessages.RETURNED_NULL_WO_SETTING_EXCEPTION; import static com.oracle.graal.python.nodes.ErrorMessages.RETURNED_RESULT_WITH_EXCEPTION_SET; import static com.oracle.graal.python.nodes.StringLiterals.T_IGNORE; @@ -56,6 +52,10 @@ import static com.oracle.graal.python.runtime.exception.PythonErrorType.SystemError; import static com.oracle.graal.python.runtime.exception.PythonErrorType.TypeError; import static com.oracle.graal.python.runtime.exception.PythonErrorType.UnicodeEncodeError; +import static com.oracle.graal.python.runtime.nativeaccess.NativeMemory.readByteArrayElement; +import static com.oracle.graal.python.runtime.nativeaccess.NativeMemory.readByteArrayElements; +import static com.oracle.graal.python.runtime.nativeaccess.NativeMemory.readIntArrayElement; +import static com.oracle.graal.python.runtime.nativeaccess.NativeMemory.readShortArrayElement; import static com.oracle.graal.python.util.PythonUtils.TS_ENCODING; import static com.oracle.graal.python.util.PythonUtils.tsLiteral; @@ -69,10 +69,10 @@ import com.oracle.graal.python.builtins.objects.bytes.BytesCommonBuiltins; import com.oracle.graal.python.builtins.objects.cext.capi.CApiContext; import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes; -import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.FromCharPointerNode; +import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.EnsurePythonObjectNode; import com.oracle.graal.python.builtins.objects.cext.capi.PThreadState; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions; -import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeNewRefNode; +import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeInternalNode; import com.oracle.graal.python.builtins.objects.cext.common.CExtCommonNodesFactory.GetIndexNodeGen; import com.oracle.graal.python.builtins.objects.cext.common.CExtCommonNodesFactory.ReadUnicodeArrayNodeGen; import com.oracle.graal.python.builtins.objects.cext.common.CExtCommonNodesFactory.TransformPExceptionToNativeCachedNodeGen; @@ -84,8 +84,6 @@ import com.oracle.graal.python.builtins.objects.type.slots.TpSlotLen.CallSlotLenNode; import com.oracle.graal.python.lib.PyNumberAsSizeNode; import com.oracle.graal.python.lib.PyNumberIndexNode; -import com.oracle.graal.python.runtime.nativeaccess.NativeFunctionPointer; -import com.oracle.graal.python.runtime.nativeaccess.NativeMemory; import com.oracle.graal.python.nodes.ErrorMessages; import com.oracle.graal.python.nodes.PConstructAndRaiseNode; import com.oracle.graal.python.nodes.PGuards; @@ -99,6 +97,7 @@ import com.oracle.graal.python.runtime.PythonOptions; import com.oracle.graal.python.runtime.exception.PException; import com.oracle.graal.python.runtime.exception.PythonErrorType; +import com.oracle.graal.python.runtime.nativeaccess.NativeFunctionPointer; import com.oracle.graal.python.runtime.object.PFactory; import com.oracle.graal.python.util.OverflowException; import com.oracle.graal.python.util.PythonUtils; @@ -414,12 +413,14 @@ public static void executeUncached(Object pythonException) { static void setCurrentException(Node inliningTarget, Object pythonException, @Cached GetThreadStateNode getThreadStateNode, @Cached CExtNodes.XDecRefPointerNode decRefPointerNode, - @Cached(inline = false) PythonToNativeNewRefNode pythonToNativeNode) { + @Cached EnsurePythonObjectNode ensurePythonObjectNode, + @Cached PythonToNativeInternalNode pythonToNativeNode) { /* * Run the ToNative conversion early so that the reference poll won't interrupt between * the read and write. */ - long currentException = pythonToNativeNode.executeLong(pythonException); + Object promotedException = ensurePythonObjectNode.execute(PythonContext.get(inliningTarget), pythonException, false); + long currentException = pythonToNativeNode.executeNewRef(inliningTarget, promotedException); long nativeThreadState = PThreadState.getOrCreateNativeThreadState(getThreadStateNode.execute(inliningTarget)); long oldException = readPtrField(nativeThreadState, CFields.PyThreadState__current_exception); writePtrField(nativeThreadState, CFields.PyThreadState__current_exception, currentException); @@ -483,12 +484,12 @@ public static Object executeUncached(PythonThreadState threadState) { } @Specialization - static Object getException(PythonThreadState threadState, - @Cached CApiTransitions.NativeToPythonTransferNode nativeToPythonNode) { + static Object getException(Node inliningTarget, PythonThreadState threadState, + @Cached CApiTransitions.NativeToPythonInternalNode nativeToPythonNode) { long nativeThreadState = threadState.getNativePointer(); if (nativeThreadState != PythonAbstractObject.UNINITIALIZED) { assert nativeThreadState != PythonAbstractObject.NATIVE_POINTER_FREED; - Object exception = nativeToPythonNode.execute(readPtrField(nativeThreadState, CFields.PyThreadState__current_exception)); + Object exception = nativeToPythonNode.executeTransfer(inliningTarget, readPtrField(nativeThreadState, CFields.PyThreadState__current_exception)); writePtrField(nativeThreadState, CFields.PyThreadState__current_exception, 0L); return exception; } @@ -888,49 +889,14 @@ private static Object toInt64(Node inliningTarget, Object object, int signed, bo } } - /** - * This node converts a {@link String} object to a {@link TruffleString} or it converts a - * {@code NULL} pointer to {@link PNone#NONE}. This is a very special use case and certainly - * only good for reading a member of type - * {@link com.oracle.graal.python.builtins.objects.cext.capi.CApiMemberAccessNodes#T_STRING}. - */ - @GenerateInline(false) // footprint reduction 32 -> 13, inherits non-inlineable execute() - @GenerateUncached - @ImportStatic(NativeMemory.class) - public abstract static class StringAsPythonStringNode extends CExtToJavaNode { - - @Specialization - static TruffleString doJavaString(String value, - @Cached TruffleString.FromJavaStringNode fromJavaStringNode) { - // TODO review with GR-37896 - return fromJavaStringNode.execute(value, TS_ENCODING); - } - - @Specialization - static TruffleString doTruffleString(TruffleString value) { - return value; - } - - @SuppressWarnings("unused") - @Specialization(guards = "value == NULLPTR") - static Object doGeneric(long value) { - return PNone.NONE; - } - - @Specialization - static TruffleString doNative(long value, - @Bind Node inliningTarget, - @Cached FromCharPointerNode fromPtr) { - return fromPtr.execute(inliningTarget, value); - } - } - /** * This node converts a C Boolean value to Python Boolean. */ @GenerateInline(false) // footprint reduction 24 -> 5, inherits non-inlineable execute() @GenerateUncached - public abstract static class NativePrimitiveAsPythonBooleanNode extends CExtToJavaNode { + public abstract static class NativePrimitiveAsPythonBooleanNode extends Node { + + public abstract Object execute(Object value); @Specialization static Boolean doBoolean(Boolean b) { @@ -968,112 +934,6 @@ static Object doGeneric(Object n, } } - /** - * This node converts a native primitive value to an appropriate Python char value (a - * single-char Python string). - */ - @GenerateInline(false) // footprint reduction 36 -> 17 - @GenerateUncached - public abstract static class NativePrimitiveAsPythonCharNode extends CExtToJavaNode { - - @Specialization - static TruffleString doByte(byte b, - @Shared("fromInt") @Cached TruffleString.FromIntArrayUTF32Node fromIntArrayNode, - @Shared("switchEnc") @Cached TruffleString.SwitchEncodingNode switchEncodingNode) { - // fromIntArrayNode return utf32, thich is at this point the same as TS_ENCODING, - // but might change in the future - return switchEncodingNode.execute(fromIntArrayNode.execute(new int[]{b}), TS_ENCODING); - } - - @Specialization - static TruffleString doShort(short i, - @Shared("fromInt") @Cached TruffleString.FromIntArrayUTF32Node fromIntArrayNode, - @Shared("switchEnc") @Cached TruffleString.SwitchEncodingNode switchEncodingNode) { - // fromIntArrayNode return utf32, thich is at this point the same as TS_ENCODING, - // but might change in the future - return switchEncodingNode.execute(fromIntArrayNode.execute(new int[]{i}, 0, 1), TS_ENCODING); - } - - @Specialization - static TruffleString doLong(long l, - @Cached TruffleString.FromLongNode fromLongNode) { - return fromLongNode.execute(l, TS_ENCODING, true); - } - - @Specialization(replaces = {"doByte", "doShort", "doLong"}, limit = "1") - static Object doGeneric(Object n, - @CachedLibrary("n") InteropLibrary lib, - @Shared("fromInt") @Cached TruffleString.FromIntArrayUTF32Node fromIntArrayNode, - @Shared("switchEnc") @Cached TruffleString.SwitchEncodingNode switchEncodingNode) { - if (lib.fitsInShort(n)) { - try { - // fromIntArrayNode return utf32, thich is at this point the same as - // TS_ENCODING, - // but might change in the future - return switchEncodingNode.execute(fromIntArrayNode.execute(new int[]{lib.asShort(n)}, 0, 1), TS_ENCODING); - } catch (UnsupportedMessageException e) { - // fall through - } - } - throw CompilerDirectives.shouldNotReachHere(); - } - } - - @GenerateInline(false) // footprint reduction 20 -> 1, inherits non-inlineable execute() - @GenerateUncached - public abstract static class NativeUnsignedByteNode extends CExtToJavaNode { - - @Specialization - static int doUnsignedIntPositive(int n) { - return n & 0xff; - } - } - - @GenerateInline(false) // footprint reduction 20 -> 1, inherits non-inlineable execute() - @GenerateUncached - public abstract static class NativeUnsignedShortNode extends CExtToJavaNode { - - @Specialization - static int doUnsignedIntPositive(int n) { - return n & 0xffff; - } - } - - /** - * This node converts a native primitive value to an appropriate Python value considering the - * native value as unsigned. For example, a negative {@code int} value will be converted to a - * positive {@code long} value. - */ - @GenerateInline(false) // footprint reduction 24 -> 5, inherits non-inlineable execute() - - @GenerateUncached - public abstract static class NativeUnsignedPrimitiveAsPythonObjectNode extends CExtToJavaNode { - - @Specialization(guards = "n >= 0") - static int doUnsignedIntPositive(int n) { - return n; - } - - @Specialization(replaces = "doUnsignedIntPositive") - static long doUnsignedInt(int n) { - if (n < 0) { - return n & 0xffffffffL; - } - return n; - } - - @Specialization(guards = "n >= 0") - static long doUnsignedLongPositive(long n) { - return n; - } - - @Specialization(guards = "n < 0") - static Object doUnsignedLongNegative(long n, - @Bind PythonLanguage language) { - return PFactory.createInt(language, PInt.longToUnsignedBigInteger(n)); - } - } - /** * Converts a Python character (1-element Python string) into a UTF-8 encoded C {@code char}. * According to CPython, we need to encode the whole Python string before we access the first @@ -1081,7 +941,7 @@ static Object doUnsignedLongNegative(long n, */ @GenerateInline(false) // footprint reduction 28 -> 9, inherits non-inlineable execute() @GenerateUncached - public abstract static class AsNativeCharNode extends CExtToNativeNode { + public abstract static class AsNativeCharNode extends Node { public abstract byte executeByte(Object value); @@ -1104,7 +964,7 @@ static byte doGeneric(Object value, * * @see AsNativePrimitiveNode */ - public abstract static class AsFixedNativePrimitiveNode extends CExtToNativeNode { + public abstract static class AsFixedNativePrimitiveNode extends Node { private final int targetTypeSize; private final int signed; @@ -1114,6 +974,8 @@ protected AsFixedNativePrimitiveNode(int targetTypeSize, boolean signed) { this.signed = PInt.intValue(signed); } + public abstract Object execute(Object object); + // Adding specializations for primitives does not make a lot of sense just to avoid // un-/boxing in the interpreter since interop will force un-/boxing anyway. @Specialization @@ -1168,7 +1030,7 @@ public static GetIndexNode create() { public static NativeFunctionPointer bindFunctionPointer(long pointer, NativeCExtSymbol descriptor) { PythonContext pythonContext = PythonContext.get(null); if (!pythonContext.isNativeAccessAllowed()) { - LOGGER.severe(PythonUtils.formatJString("Attempting to bind %s to an NFI signature but native access is not allowed", pointer)); + LOGGER.severe(PythonUtils.formatJString("Attempting to bind %s to a native callable but native access is not allowed", pointer)); } if (LOGGER.isLoggable(Level.FINER)) { LOGGER.finer(PythonUtils.formatJString("Binding %s to native callable %s", pointer, descriptor.getName())); diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/common/CExtToJavaNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/common/CExtToJavaNode.java index 6efd66acfb..478d40bf56 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/common/CExtToJavaNode.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/common/CExtToJavaNode.java @@ -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 @@ -43,5 +43,5 @@ import com.oracle.graal.python.nodes.PNodeWithContext; public abstract class CExtToJavaNode extends PNodeWithContext { - public abstract Object execute(Object object); + public abstract Object execute(long pointer); } diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/common/CExtToNativeNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/common/CExtToNativeNode.java index 29e3ba34e4..f655198fab 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/common/CExtToNativeNode.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/common/CExtToNativeNode.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2023, 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 @@ -44,5 +44,5 @@ public abstract class CExtToNativeNode extends PNodeWithContext { - public abstract Object execute(Object object); + public abstract long execute(Object object); } diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/common/NativePointer.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/common/NativePointer.java deleted file mode 100644 index 38e005fd63..0000000000 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/common/NativePointer.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright (c) 2023, 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 - * - * Subject to the condition set forth below, permission is hereby granted to any - * person obtaining a copy of this software, associated documentation and/or - * data (collectively the "Software"), free of charge and under any and all - * copyright rights in the Software, and any and all patent rights owned or - * freely licensable by each licensor hereunder covering either (i) the - * unmodified Software as contributed to or provided by such licensor, or (ii) - * the Larger Works (as defined below), to deal in both - * - * (a) the Software, and - * - * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if - * one is included with the Software each a "Larger Work" to which the Software - * is contributed by such licensors), - * - * without restriction, including without limitation the rights to copy, create - * derivative works of, display, perform, and distribute the Software and make, - * use, sell, offer for sale, import, export, have made, and have sold the - * Software and the Larger Work(s), and to sublicense the foregoing rights on - * either these or other terms. - * - * This license is subject to the following condition: - * - * The above copyright notice and either this complete permission notice or at a - * minimum a reference to the UPL must be included in all copies or substantial - * portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.oracle.graal.python.builtins.objects.cext.common; - -import com.oracle.graal.python.runtime.PythonContext; -import com.oracle.truffle.api.CompilerAsserts; -import com.oracle.truffle.api.interop.InteropLibrary; -import com.oracle.truffle.api.interop.TruffleObject; -import com.oracle.truffle.api.library.ExportLibrary; -import com.oracle.truffle.api.library.ExportMessage; - -/** Currently only used for wrapping pointers to call TruffleString, see GR-71311. */ -@ExportLibrary(InteropLibrary.class) -public final class NativePointer implements TruffleObject { - private final long ptr; - - private NativePointer(long ptr) { - /* - * Instances of this type may only be created if native access is allowed because other code - * relies on that and may use Unsafe without further checking. - */ - assert PythonContext.get(null).getEnv().isNativeAccessAllowed(); - this.ptr = ptr; - } - - public static NativePointer wrap(long ptr) { - return new NativePointer(ptr); - } - - @ExportMessage - public boolean isPointer() { - return true; - } - - @ExportMessage - public long asPointer() { - return ptr; - } - - @ExportMessage - public boolean isNull() { - return ptr == 0; - } - - @Override - public String toString() { - CompilerAsserts.neverPartOfCompilation(); - return String.format("<0x%016x>", ptr); - } -} diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/structs/CStructAccess.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/structs/CStructAccess.java index 6c9f896557..7187290021 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/structs/CStructAccess.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/structs/CStructAccess.java @@ -46,16 +46,18 @@ import com.oracle.graal.python.builtins.objects.cext.PythonNativeObject; import com.oracle.graal.python.builtins.objects.cext.capi.CApiContext; +import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.EnsurePythonObjectNode; import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.FromCharPointerNode; import com.oracle.graal.python.builtins.objects.cext.capi.ExternalFunctionInvoker; import com.oracle.graal.python.builtins.objects.cext.capi.NativeCAPISymbol; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativePtrToPythonNode; -import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeNewRefNode; +import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeInternalNode; import com.oracle.graal.python.builtins.objects.cext.structs.CStructAccessFactory.ReadCharPtrNodeGen; import com.oracle.graal.python.builtins.objects.cext.structs.CStructAccessFactory.ReadObjectNodeGen; import com.oracle.graal.python.builtins.objects.cext.structs.CStructAccessFactory.WriteTruffleStringNodeGen; import com.oracle.graal.python.runtime.nativeaccess.NativeMemory; import com.oracle.graal.python.nodes.PGuards; +import com.oracle.graal.python.runtime.PythonContext; import com.oracle.truffle.api.CompilerDirectives; import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; import com.oracle.truffle.api.dsl.Bind; @@ -294,14 +296,17 @@ public final void writeArray(long pointer, Object[] values, int length, int sour @Specialization static void writeLong(long pointer, long offset, Object value, + @Bind Node inliningTarget, @Cached NativePtrToPythonNode toPython, - @Cached PythonToNativeNewRefNode toNative) { + @Cached EnsurePythonObjectNode ensurePythonObjectNode, + @Cached PythonToNativeInternalNode toNative) { assert offset >= 0; long old = NativeMemory.readPtr(pointer + offset); if (old != NULLPTR) { toPython.execute(old, true); } - NativeMemory.writePtr(pointer + offset, toNative.executeLong(value)); + Object promoted = ensurePythonObjectNode.execute(PythonContext.get(inliningTarget), value, false); + NativeMemory.writePtr(pointer + offset, toNative.executeNewRef(inliningTarget, promoted)); } } } diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/SequenceStorageNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/SequenceStorageNodes.java index fb9f0b9239..a9c404d528 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/SequenceStorageNodes.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/SequenceStorageNodes.java @@ -58,8 +58,8 @@ import com.oracle.graal.python.builtins.objects.bytes.BytesNodes; import com.oracle.graal.python.builtins.objects.bytes.PBytesLike; import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes; -import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativeToPythonNode; -import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeNewRefNode; +import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativeToPythonInternalNode; +import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeInternalNode; import com.oracle.graal.python.builtins.objects.cext.structs.CStructAccess; import com.oracle.graal.python.builtins.objects.common.IndexNodes.NormalizeIndexCustomMessageNode; import com.oracle.graal.python.builtins.objects.common.IndexNodes.NormalizeIndexNode; @@ -657,8 +657,9 @@ protected abstract static class GetNativeItemScalarNode extends Node { @Specialization protected static Object doNativeObject(NativeObjectSequenceStorage storage, int idx, - @Cached NativeToPythonNode toJavaNode) { - return toJavaNode.executeRaw(readPtrArrayElement(storage.getPtr(), idx)); + @Bind Node inliningTarget, + @Cached NativeToPythonInternalNode toJavaNode) { + return toJavaNode.execute(inliningTarget, readPtrArrayElement(storage.getPtr(), idx)); } @Specialization @@ -818,10 +819,11 @@ protected static SequenceStorage doNativeByte(NativeByteSequenceStorage storage, @Specialization protected static SequenceStorage doNativeObject(NativeObjectSequenceStorage storage, int start, @SuppressWarnings("unused") int stop, int step, int length, - @Cached NativeToPythonNode toJavaNode) { + @Bind Node inliningTarget, + @Cached NativeToPythonInternalNode toJavaNode) { Object[] newArray = new Object[length]; for (int i = start, j = 0; j < length; i += step, j++) { - newArray[j] = toJavaNode.executeRaw(readPtrArrayElement(storage.getPtr(), i)); + newArray[j] = toJavaNode.execute(inliningTarget, readPtrArrayElement(storage.getPtr(), i)); } return new ObjectSequenceStorage(newArray); } @@ -1386,10 +1388,12 @@ protected static void doNativeByte(NativeByteSequenceStorage storage, int idx, O @Specialization protected static void doNativeObject(NativeObjectSequenceStorage storage, int idx, Object value, @Bind Node inliningTarget, - @Cached PythonToNativeNewRefNode toNative, + @Cached CExtNodes.EnsurePythonObjectNode ensurePythonObjectNode, + @Cached PythonToNativeInternalNode toNative, @Cached CExtNodes.XDecRefPointerNode decRefPointerNode) { long old = readPtrArrayElement(storage.getPtr(), idx); - writePtrArrayElement(storage.getPtr(), idx, toNative.executeLong(value)); + Object promoted = ensurePythonObjectNode.execute(PythonContext.get(inliningTarget), value, false); + writePtrArrayElement(storage.getPtr(), idx, toNative.executeNewRef(inliningTarget, promoted)); decRefPointerNode.execute(inliningTarget, old); } } @@ -1408,8 +1412,11 @@ protected static void doNativeByte(NativeByteSequenceStorage storage, int idx, O @Specialization protected static void doNativeObject(NativeObjectSequenceStorage storage, int idx, Object value, - @Cached PythonToNativeNewRefNode toNative) { - writePtrArrayElement(storage.getPtr(), idx, toNative.executeLong(value)); + @Bind Node inliningTarget, + @Cached CExtNodes.EnsurePythonObjectNode ensurePythonObjectNode, + @Cached PythonToNativeInternalNode toNative) { + Object promoted = ensurePythonObjectNode.execute(PythonContext.get(inliningTarget), value, false); + writePtrArrayElement(storage.getPtr(), idx, toNative.executeNewRef(inliningTarget, promoted)); } } @@ -4068,13 +4075,15 @@ static SequenceStorage doNativeStorage(Node inliningTarget, NativeIntSequenceSto @Specialization protected static SequenceStorage doNativeObjectStorage(Node inliningTarget, NativeObjectSequenceStorage storage, int index, Object value, @Exclusive @Cached EnsureCapacityNode ensureCapacityNode, - @Cached PythonToNativeNewRefNode toNative) { + @Cached CExtNodes.EnsurePythonObjectNode ensurePythonObjectNode, + @Cached PythonToNativeInternalNode toNative) { int newLength = storage.length() + 1; ensureCapacityNode.execute(inliningTarget, storage, newLength); for (int i = storage.length(); i > index; i--) { writePtrArrayElement(storage.getPtr(), i, readPtrArrayElement(storage.getPtr(), i - 1)); } - writePtrArrayElement(storage.getPtr(), index, toNative.executeLong(value)); + Object promoted = ensurePythonObjectNode.execute(PythonContext.get(inliningTarget), value, false); + writePtrArrayElement(storage.getPtr(), index, toNative.executeNewRef(inliningTarget, promoted)); storage.setNewLength(newLength); return storage; } diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/complex/ComplexBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/complex/ComplexBuiltins.java index bf764875f4..d826018d60 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/complex/ComplexBuiltins.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/complex/ComplexBuiltins.java @@ -257,20 +257,20 @@ static PComplex doManaged(@SuppressWarnings("unused") Node inliningTarget, Objec @Fallback static Object doNative(Node inliningTarget, Object cls, double real, double imaginary, - @Cached(inline = false) CApiTransitions.PythonToNativeNode toNativeNode, - @Cached(inline = false) CApiTransitions.NativeToPythonTransferNode toPythonNode, + @Cached CApiTransitions.PythonToNativeInternalNode toNativeNode, + @Cached CApiTransitions.NativeToPythonInternalNode toPythonNode, @Cached(inline = false) PyObjectCheckFunctionResultNode checkFunctionResultNode) { NativeCAPISymbol symbol = NativeCAPISymbol.FUN_COMPLEX_SUBTYPE_FROM_DOUBLES; // classes are always Python objects assert EnsurePythonObjectNode.doesNotNeedPromotion(cls); - long clsPointer = toNativeNode.executeLong(cls); + long clsPointer = toNativeNode.execute(inliningTarget, cls); try { PythonContext context = PythonContext.get(inliningTarget); var callable = CApiContext.getNativeSymbol(inliningTarget, symbol); long nativeResult = ExternalFunctionInvoker.invokeCOMPLEX_SUBTYPE_FROM_DOUBLES(null, C_API_TIMING, context.ensureNativeContext(), BoundaryCallData.getUncached(), context.getThreadState(PythonLanguage.get(inliningTarget)), callable, clsPointer, real, imaginary); - return checkFunctionResultNode.execute(context, symbol.getTsName(), toPythonNode.execute(nativeResult)); + return checkFunctionResultNode.execute(context, symbol.getTsName(), toPythonNode.executeTransfer(inliningTarget, nativeResult)); } finally { Reference.reachabilityFence(cls); } diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/BaseExceptionBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/BaseExceptionBuiltins.java index f0194a8bf3..48c1823533 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/BaseExceptionBuiltins.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/BaseExceptionBuiltins.java @@ -160,23 +160,23 @@ static Object doManaged(Object cls, @SuppressWarnings("unused") Object[] args, @ @Specialization(guards = "needsNativeAllocationNode.execute(inliningTarget, cls)", limit = "1") static Object doNativeSubtype(Object cls, Object[] args, @SuppressWarnings("unused") PKeyword[] kwargs, - @SuppressWarnings("unused") @Bind Node inliningTarget, + @Bind Node inliningTarget, @SuppressWarnings("unused") @Cached.Exclusive @Cached TypeNodes.NeedsNativeAllocationNode needsNativeAllocationNode, @Bind PythonLanguage language, - @Cached CApiTransitions.PythonToNativeNode toNativeNode, - @Cached CApiTransitions.NativeToPythonTransferNode toPythonNode, + @Cached CApiTransitions.PythonToNativeInternalNode toNativeNode, + @Cached CApiTransitions.NativeToPythonInternalNode toPythonNode, @Cached PyObjectCheckFunctionResultNode checkFunctionResultNode) { Object argsTuple = args.length > 0 ? PFactory.createTuple(language, args) : PFactory.createEmptyTuple(language); assert EnsurePythonObjectNode.doesNotNeedPromotion(cls); assert EnsurePythonObjectNode.doesNotNeedPromotion(argsTuple); - long clsPointer = toNativeNode.executeLong(cls); - long argsTuplePointer = toNativeNode.executeLong(argsTuple); + long clsPointer = toNativeNode.execute(inliningTarget, cls); + long argsTuplePointer = toNativeNode.execute(inliningTarget, argsTuple); try { PythonContext context = PythonContext.get(inliningTarget); var callable = CApiContext.getNativeSymbol(inliningTarget, NativeCAPISymbol.FUN_EXCEPTION_SUBTYPE_NEW); long nativeResult = ExternalFunctionInvoker.invokeEXCEPTION_SUBTYPE_NEW(null, C_API_TIMING, context.ensureNativeContext(), BoundaryCallData.getUncached(), context.getThreadState(PythonLanguage.get(inliningTarget)), callable, clsPointer, argsTuplePointer); - return checkFunctionResultNode.execute(context, NativeCAPISymbol.FUN_EXCEPTION_SUBTYPE_NEW.getTsName(), toPythonNode.execute(nativeResult)); + return checkFunctionResultNode.execute(context, NativeCAPISymbol.FUN_EXCEPTION_SUBTYPE_NEW.getTsName(), toPythonNode.executeTransfer(inliningTarget, nativeResult)); } finally { Reference.reachabilityFence(cls); Reference.reachabilityFence(argsTuple); diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/mmap/MMapBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/mmap/MMapBuiltins.java index 19baa772dd..c3c7a364cb 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/mmap/MMapBuiltins.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/mmap/MMapBuiltins.java @@ -597,7 +597,7 @@ abstract static class ResizeNode extends PythonBuiltinNode { @SuppressWarnings("unused") static long resize(PMMap self, Object n, @Bind Node inliningTarget) { - // TODO: implement resize in NFI + // TODO: implement resize throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.SystemError, ErrorMessages.RESIZING_NOT_AVAILABLE); } } diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/object/ObjectBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/object/ObjectBuiltins.java index 1d38f5444a..3c8f75e7c1 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/object/ObjectBuiltins.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/object/ObjectBuiltins.java @@ -356,18 +356,18 @@ protected abstract static class CallNativeGenericNewNode extends Node { abstract Object execute(Node inliningTarget, Object cls); @Specialization - static Object call(Object cls, - @Bind Node inliningTarget, - @Cached(inline = false) CApiTransitions.PythonToNativeNode toNativeNode, - @Cached(inline = false) CApiTransitions.NativeToPythonTransferNode toPythonNode) { + static Object call(Node inliningTarget, Object cls, + @Cached CApiTransitions.PythonToNativeInternalNode toNativeNode, + @Cached CApiTransitions.NativeToPythonInternalNode toPythonNode) { assert EnsurePythonObjectNode.doesNotNeedPromotion(cls); - long clsPointer = toNativeNode.executeLong(cls); + long clsPointer = toNativeNode.execute(inliningTarget, cls); try { PythonContext context = PythonContext.get(inliningTarget); var callable = CApiContext.getNativeSymbol(inliningTarget, FUN_PY_OBJECT_NEW); - return toPythonNode.execute(ExternalFunctionInvoker.invokePY_OBJECT_NEW(null, C_API_TIMING, + long nativeResult = ExternalFunctionInvoker.invokePY_OBJECT_NEW(null, C_API_TIMING, context.ensureNativeContext(), BoundaryCallData.getUncached(), - context.getThreadState(context.getLanguage(inliningTarget)), callable, clsPointer)); + context.getThreadState(context.getLanguage(inliningTarget)), callable, clsPointer); + return toPythonNode.executeTransfer(inliningTarget, nativeResult); } finally { Reference.reachabilityFence(cls); } diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/object/ObjectNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/object/ObjectNodes.java index 5152e8e0ef..93207ee1d0 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/object/ObjectNodes.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/object/ObjectNodes.java @@ -87,7 +87,7 @@ import com.oracle.graal.python.builtins.objects.cext.capi.CApiContext; import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.EnsurePythonObjectNode; import com.oracle.graal.python.builtins.objects.cext.capi.ExternalFunctionInvoker; -import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeNode; +import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeInternalNode; import com.oracle.graal.python.builtins.objects.common.EconomicMapStorage; import com.oracle.graal.python.builtins.objects.common.HashingStorage; import com.oracle.graal.python.builtins.objects.common.HashingStorageNodes.HashingStorageDelItem; @@ -624,11 +624,10 @@ abstract static class CheckBasesizeForGetState extends Node { public abstract boolean execute(Node inliningTarget, Object obj, Object type, int slotNum); @Specialization - static boolean doNative(@SuppressWarnings("unused") PythonAbstractNativeObject obj, Object type, int slotNum, - @Bind Node inliningTarget, - @Cached(inline = false) PythonToNativeNode toNativeNode) { + static boolean doNative(Node inliningTarget, @SuppressWarnings("unused") PythonAbstractNativeObject obj, Object type, int slotNum, + @Cached PythonToNativeInternalNode toNativeNode) { assert EnsurePythonObjectNode.doesNotNeedPromotion(type); - long typePointer = toNativeNode.executeLong(type); + long typePointer = toNativeNode.execute(inliningTarget, type); try { return ExternalFunctionInvoker.invokeCHECK_BASICSIZE_FOR_GETSTATE( CApiContext.getNativeSymbol(inliningTarget, FUN_CHECK_BASICSIZE_FOR_GETSTATE).getAddress(), typePointer, diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/str/StringNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/str/StringNodes.java index a47b088d51..7da4308958 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/str/StringNodes.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/str/StringNodes.java @@ -61,7 +61,6 @@ import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.HandlePointerConverter; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeInternalNode; -import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeNode; import com.oracle.graal.python.builtins.objects.cext.structs.CFields; import com.oracle.graal.python.builtins.objects.cext.structs.CStructAccess; import com.oracle.graal.python.builtins.objects.common.SequenceNodes; @@ -200,7 +199,7 @@ static int doNativeObject(PythonNativeObject x, @Bind Node inliningTarget, @Cached GetClassNode getClassNode, @Cached IsSubtypeNode isSubtypeNode, - @Cached PythonToNativeNode toNativeNode, + @Cached PythonToNativeInternalNode toNativeNode, @Cached PRaiseNode raiseNode) { if (isSubtypeNode.execute(getClassNode.execute(inliningTarget, x), PythonBuiltinClassType.PString)) { // read the native data @@ -210,7 +209,7 @@ static int doNativeObject(PythonNativeObject x, long lresult = ExternalFunctionInvoker.invokePY_UNICODE_GET_LENGTH(null, C_API_TIMING, context.ensureNativeContext(), BoundaryCallData.getUncached(), context.getThreadState(context.getLanguage(inliningTarget)), callable, - toNativeNode.executeLong(x)); + toNativeNode.execute(inliningTarget, x)); try { return PInt.intValueExact(lresult); } catch (OverflowException e) { diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/PythonManagedClass.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/PythonManagedClass.java index 3fd214babc..e86fceafa4 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/PythonManagedClass.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/PythonManagedClass.java @@ -35,7 +35,7 @@ import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.EnsurePythonObjectNode; import com.oracle.graal.python.builtins.objects.cext.capi.ExternalFunctionInvoker; import com.oracle.graal.python.builtins.objects.cext.capi.NativeCAPISymbol; -import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeNode; +import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeInternalNode; import com.oracle.graal.python.builtins.objects.common.HashingStorage; import com.oracle.graal.python.builtins.objects.common.HashingStorageNodes; import com.oracle.graal.python.builtins.objects.dict.PDict; @@ -289,7 +289,7 @@ private void unsafeSetSuperClass(PythonAbstractClass... newBaseClasses) { try { ExternalFunctionInvoker.invokeTRUFFLE_CHECK_TYPE_READY( CApiContext.getNativeSymbol(null, NativeCAPISymbol.FUN_TRUFFLE_CHECK_TYPE_READY).getAddress(), - PythonToNativeNode.executeLongUncached(base)); + PythonToNativeInternalNode.executeUncached(base, false)); } catch (Throwable t) { throw CompilerDirectives.shouldNotReachHere(t); } diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/TypeNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/TypeNodes.java index de9fdbf84e..960f28b93f 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/TypeNodes.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/TypeNodes.java @@ -122,7 +122,7 @@ import com.oracle.graal.python.builtins.objects.cext.capi.ExternalFunctionInvoker; import com.oracle.graal.python.builtins.objects.cext.capi.NativeCAPISymbol; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTiming; -import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeNode; +import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeInternalNode; import com.oracle.graal.python.builtins.objects.cext.structs.CFields; import com.oracle.graal.python.builtins.objects.cext.structs.CStructAccess; import com.oracle.graal.python.builtins.objects.common.EconomicMapStorage; @@ -635,7 +635,7 @@ private static Object initializeType(Node inliningTarget, PythonNativeClass obj, PythonContext context = PythonContext.get(null); var callable = CApiContext.getNativeSymbol(null, NativeCAPISymbol.FUN_PY_TYPE_READY); int res = ExternalFunctionInvoker.invokePY_TYPE_READY(null, C_API_TIMING, context.ensureNativeContext(), - BoundaryCallData.getUncached(), context.getThreadState(PythonLanguage.get(inliningTarget)), callable, PythonToNativeNode.executeLongUncached(obj)); + BoundaryCallData.getUncached(), context.getThreadState(PythonLanguage.get(inliningTarget)), callable, PythonToNativeInternalNode.executeUncached(obj, false)); if (res < 0) { throw PRaiseNode.raiseStatic(inliningTarget, SystemError, ErrorMessages.LAZY_INITIALIZATION_FAILED, obj); } diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotBinaryFunc.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotBinaryFunc.java index 0cd49cba36..1625dd90d0 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotBinaryFunc.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotBinaryFunc.java @@ -53,7 +53,7 @@ import com.oracle.graal.python.builtins.objects.cext.capi.ExternalFunctionNodes.PyObjectCheckFunctionResultNode; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTiming; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativeToPythonInternalNode; -import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeNode; +import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeInternalNode; import com.oracle.graal.python.builtins.objects.function.PArguments; import com.oracle.graal.python.builtins.objects.type.slots.PythonDispatchers.BinaryPythonSlotDispatcherNode; import com.oracle.graal.python.builtins.objects.type.slots.TpSlot.TpSlotBuiltinBase; @@ -154,8 +154,8 @@ static Object callPython(VirtualFrame frame, Node inliningTarget, TpSlotPythonSi static Object callNative(VirtualFrame frame, Node inliningTarget, TpSlotCExtNative slot, Object self, Object arg, @Exclusive @Cached GetThreadStateNode getThreadStateNode, @Cached EnsurePythonObjectNode ensurePythonObjectNode, - @Cached(inline = false) PythonToNativeNode selfToNativeNode, - @Cached(inline = false) PythonToNativeNode argToNativeNode, + @Cached PythonToNativeInternalNode selfToNativeNode, + @Cached PythonToNativeInternalNode argToNativeNode, @Cached("createFor($node)") BoundaryCallData boundaryCallData, @Cached NativeToPythonInternalNode toPythonNode, @Exclusive @Cached(inline = false) PyObjectCheckFunctionResultNode checkResultNode) { @@ -165,8 +165,8 @@ static Object callNative(VirtualFrame frame, Node inliningTarget, TpSlotCExtNati Object promotedArg = ensurePythonObjectNode.execute(ctx, arg, false); try { long lresult = ExternalFunctionInvoker.invokeBINARYFUNC(frame, C_API_TIMING, ctx.ensureNativeContext(), boundaryCallData, state, slot.callable, - selfToNativeNode.executeLong(promotedSelf), argToNativeNode.executeLong(promotedArg)); - return checkResultNode.execute(state, T_BINARY_SLOT, toPythonNode.execute(inliningTarget, lresult, true)); + selfToNativeNode.execute(inliningTarget, promotedSelf), argToNativeNode.execute(inliningTarget, promotedArg)); + return checkResultNode.execute(state, T_BINARY_SLOT, toPythonNode.executeTransfer(inliningTarget, lresult)); } finally { Reference.reachabilityFence(promotedSelf); Reference.reachabilityFence(promotedArg); diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotBinaryOp.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotBinaryOp.java index aa974134a6..dd8fdba2e5 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotBinaryOp.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotBinaryOp.java @@ -81,7 +81,7 @@ import com.oracle.graal.python.builtins.objects.cext.capi.ExternalFunctionNodes.PyObjectCheckFunctionResultNode; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTiming; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativeToPythonInternalNode; -import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeNode; +import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeInternalNode; import com.oracle.graal.python.builtins.objects.function.PArguments; import com.oracle.graal.python.builtins.objects.function.PBuiltinFunction; import com.oracle.graal.python.builtins.objects.function.PFunction; @@ -375,8 +375,8 @@ static Object callNative(VirtualFrame frame, Node inliningTarget, TpSlotCExtNati Object selfType, Object arg, TpSlot otherSlot, Object otherType, boolean sameTypes, ReversibleSlot op, @Exclusive @Cached GetThreadStateNode getThreadStateNode, @Cached EnsurePythonObjectNode ensurePythonObjectNode, - @Cached(inline = false) PythonToNativeNode selfToNativeNode, - @Cached(inline = false) PythonToNativeNode argToNativeNode, + @Cached PythonToNativeInternalNode selfToNativeNode, + @Cached PythonToNativeInternalNode argToNativeNode, @Cached("createFor($node)") BoundaryCallData boundaryCallData, @Cached NativeToPythonInternalNode toPythonNode, @Exclusive @Cached(inline = false) PyObjectCheckFunctionResultNode checkResultNode) { @@ -386,8 +386,8 @@ static Object callNative(VirtualFrame frame, Node inliningTarget, TpSlotCExtNati Object promotedArg = ensurePythonObjectNode.execute(ctx, arg, false); try { long lresult = ExternalFunctionInvoker.invokeBINARYFUNC(frame, C_API_TIMING, ctx.ensureNativeContext(), boundaryCallData, state, slot.callable, - selfToNativeNode.executeLong(promotedSelf), argToNativeNode.executeLong(promotedArg)); - return checkResultNode.execute(state, op.name, toPythonNode.execute(inliningTarget, lresult, true)); + selfToNativeNode.execute(inliningTarget, promotedSelf), argToNativeNode.execute(inliningTarget, promotedArg)); + return checkResultNode.execute(state, op.name, toPythonNode.executeTransfer(inliningTarget, lresult)); } finally { Reference.reachabilityFence(promotedSelf); Reference.reachabilityFence(promotedArg); diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotDescrGet.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotDescrGet.java index 53b0239c54..93de696524 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotDescrGet.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotDescrGet.java @@ -56,7 +56,7 @@ import com.oracle.graal.python.builtins.objects.cext.capi.ExternalFunctionNodes.PyObjectCheckFunctionResultNode; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTiming; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativeToPythonInternalNode; -import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeNode; +import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeInternalNode; import com.oracle.graal.python.builtins.objects.function.PArguments; import com.oracle.graal.python.builtins.objects.function.PBuiltinFunction; import com.oracle.graal.python.builtins.objects.function.PFunction; @@ -224,9 +224,9 @@ static Object callPython(VirtualFrame frame, Node inliningTarget, TpSlotPythonSi static Object callNative(VirtualFrame frame, Node inliningTarget, TpSlotNative slot, Object self, Object obj, Object value, @Cached GetThreadStateNode getThreadStateNode, @Cached EnsurePythonObjectNode ensurePythonObjectNode, - @Cached(inline = false) PythonToNativeNode selfToNativeNode, - @Cached(inline = false) PythonToNativeNode objToNativeNode, - @Cached(inline = false) PythonToNativeNode valueToNativeNode, + @Cached PythonToNativeInternalNode selfToNativeNode, + @Cached PythonToNativeInternalNode objToNativeNode, + @Cached PythonToNativeInternalNode valueToNativeNode, @Cached("createFor($node)") BoundaryCallData boundaryCallData, @Cached NativeToPythonInternalNode toPythonNode, @Cached(inline = false) PyObjectCheckFunctionResultNode checkResultNode) { @@ -237,10 +237,10 @@ static Object callNative(VirtualFrame frame, Node inliningTarget, TpSlotNative s Object promotedValue = ensurePythonObjectNode.execute(ctx, value, false); try { long lresult = ExternalFunctionInvoker.invokeDESCRGETFUNC(frame, C_API_TIMING, ctx.ensureNativeContext(), boundaryCallData, threadState, slot.callable, - selfToNativeNode.executeLong(promotedSelf), // - objToNativeNode.executeLong(promotedObj), // - valueToNativeNode.executeLong(promotedValue)); - return checkResultNode.execute(threadState, T___GET__, toPythonNode.execute(inliningTarget, lresult, true)); + selfToNativeNode.execute(inliningTarget, promotedSelf), // + objToNativeNode.execute(inliningTarget, promotedObj), // + valueToNativeNode.execute(inliningTarget, promotedValue)); + return checkResultNode.execute(threadState, T___GET__, toPythonNode.executeTransfer(inliningTarget, lresult)); } finally { Reference.reachabilityFence(promotedSelf); Reference.reachabilityFence(promotedObj); diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotDescrSet.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotDescrSet.java index 21b2ab5c7c..23f34fab69 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotDescrSet.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotDescrSet.java @@ -210,9 +210,9 @@ static void callNative(VirtualFrame frame, Node inliningTarget, TpSlotNative slo Object promotedValue = ensurePythonObjectNode.execute(ctx, value, false); try { int iresult = ExternalFunctionInvoker.invokeDESCRSETFUNC(frame, C_API_TIMING, ctx.ensureNativeContext(), boundaryCallData, threadState, slot.callable, - selfToNativeNode.execute(inliningTarget, promotedSelf, false), // - objToNativeNode.execute(inliningTarget, promotedObj, false), // - valueToNativeNode.execute(inliningTarget, promotedValue, false)); + selfToNativeNode.execute(inliningTarget, promotedSelf), // + objToNativeNode.execute(inliningTarget, promotedObj), // + valueToNativeNode.execute(inliningTarget, promotedValue)); checkResultNode.executeInt(inliningTarget, threadState, T___SET__, iresult); } finally { Reference.reachabilityFence(promotedSelf); diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotGetAttr.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotGetAttr.java index 3d3ae4267b..6032694823 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotGetAttr.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotGetAttr.java @@ -57,8 +57,8 @@ import com.oracle.graal.python.builtins.objects.cext.capi.ExternalFunctionNodes.PExternalFunctionWrapper; import com.oracle.graal.python.builtins.objects.cext.capi.ExternalFunctionNodes.PyObjectCheckFunctionResultNode; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTiming; -import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativeToPythonTransferNode; -import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeNode; +import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativeToPythonInternalNode; +import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeInternalNode; import com.oracle.graal.python.builtins.objects.function.PArguments; import com.oracle.graal.python.builtins.objects.type.TpSlots; import com.oracle.graal.python.builtins.objects.type.slots.PythonDispatchers.BinaryPythonSlotDispatcherNode; @@ -255,10 +255,10 @@ static Object callNative(VirtualFrame frame, TpSlots slots, TpSlotNative slot, O @Cached GetThreadStateNode getThreadStateNode, @Cached InlinedConditionProfile isGetAttrProfile, @Cached AsCharPointerNode asCharPointerNode, - @Cached PythonToNativeNode nameToNativeNode, + @Cached PythonToNativeInternalNode nameToNativeNode, @Cached EnsurePythonObjectNode ensurePythonObjectNode, - @Cached PythonToNativeNode selfToNativeNode, - @Cached NativeToPythonTransferNode toPythonNode, + @Cached PythonToNativeInternalNode selfToNativeNode, + @Cached NativeToPythonInternalNode toPythonNode, @Cached("createFor($node)") BoundaryCallData boundaryCallData, @Cached PyObjectCheckFunctionResultNode checkResultNode) { boolean isGetAttr = isGetAttrProfile.profile(inliningTarget, slots.tp_getattr() == slot); @@ -269,13 +269,13 @@ static Object callNative(VirtualFrame frame, TpSlots slots, TpSlotNative slot, O nameArg = asCharPointerNode.execute(name); } else { promotedName = ensurePythonObjectNode.execute(context, name, false); - nameArg = nameToNativeNode.executeLong(promotedName); + nameArg = nameToNativeNode.execute(inliningTarget, promotedName); } long lresult; PythonThreadState threadState = getThreadStateNode.execute(inliningTarget, context); try { lresult = ExternalFunctionInvoker.invokeGETATTRFUNC(frame, C_API_TIMING, context.ensureNativeContext(), boundaryCallData, threadState, slot.callable, - selfToNativeNode.executeLong(promotedSelf), nameArg); + selfToNativeNode.execute(inliningTarget, promotedSelf), nameArg); } finally { Reference.reachabilityFence(promotedSelf); if (isGetAttr) { @@ -287,7 +287,7 @@ static Object callNative(VirtualFrame frame, TpSlots slots, TpSlotNative slot, O Reference.reachabilityFence(promotedName); } } - return checkResultNode.execute(threadState, T___GETATTR__, toPythonNode.executeRaw(lresult)); + return checkResultNode.execute(threadState, T___GETATTR__, toPythonNode.executeTransfer(inliningTarget, lresult)); } } diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotHashFun.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotHashFun.java index 69f5c89176..bfb5303d02 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotHashFun.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotHashFun.java @@ -52,7 +52,7 @@ import com.oracle.graal.python.builtins.objects.cext.capi.ExternalFunctionNodes.PExternalFunctionWrapper; import com.oracle.graal.python.builtins.objects.cext.capi.ExternalFunctionNodes.CheckPrimitiveFunctionResultNode; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTiming; -import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeNode; +import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeInternalNode; import com.oracle.graal.python.builtins.objects.function.PArguments; import com.oracle.graal.python.builtins.objects.ints.IntBuiltins; import com.oracle.graal.python.builtins.objects.type.TpSlots.TpSlotMeta; @@ -177,7 +177,7 @@ static long callPython(VirtualFrame frame, TpSlotPythonSingle slot, Object self, @Specialization static long callNative(VirtualFrame frame, Node inliningTarget, TpSlotCExtNative slot, Object self, @Exclusive @Cached GetThreadStateNode getThreadStateNode, - @Cached(inline = false) PythonToNativeNode toNativeNode, + @Cached PythonToNativeInternalNode toNativeNode, @Cached EnsurePythonObjectNode ensurePythonObjectNode, @Cached("createFor($node)") BoundaryCallData boundaryCallData, @Exclusive @Cached CheckPrimitiveFunctionResultNode checkResultNode) { @@ -186,7 +186,7 @@ static long callNative(VirtualFrame frame, Node inliningTarget, TpSlotCExtNative Object promotedSelf = ensurePythonObjectNode.execute(ctx, self, false); try { long lresult = ExternalFunctionInvoker.invokeHASHFUNC(frame, C_API_TIMING, ctx.ensureNativeContext(), boundaryCallData, state, slot.callable, - toNativeNode.executeLong(promotedSelf)); + toNativeNode.execute(inliningTarget, promotedSelf)); return checkResultNode.executeLong(inliningTarget, state, T___HASH__, lresult); } finally { Reference.reachabilityFence(promotedSelf); diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotInquiry.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotInquiry.java index 8c6bd1f099..a5609e06da 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotInquiry.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotInquiry.java @@ -180,7 +180,7 @@ static boolean callNative(VirtualFrame frame, Node inliningTarget, TpSlotNative Object promotedSelf = ensurePythonObjectNode.execute(ctx, self, false); try { int iresult = ExternalFunctionInvoker.invokeINQUIRY(frame, C_API_TIMING, ctx.ensureNativeContext(), boundaryCallData, threadState, slot.callable, - toNativeNode.execute(inliningTarget, promotedSelf, false)); + toNativeNode.execute(inliningTarget, promotedSelf)); return checkResultNode.executeBool(inliningTarget, threadState, T___BOOL__, iresult); } finally { Reference.reachabilityFence(promotedSelf); diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotIterNext.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotIterNext.java index b4560e1c81..ea8d304d4b 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotIterNext.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotIterNext.java @@ -55,7 +55,7 @@ import com.oracle.graal.python.builtins.objects.cext.capi.ExternalFunctionNodes.PExternalFunctionWrapper; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTiming; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativeToPythonInternalNode; -import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeNode; +import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeInternalNode; import com.oracle.graal.python.builtins.objects.cext.common.CExtCommonNodes; import com.oracle.graal.python.builtins.objects.function.PArguments; import com.oracle.graal.python.builtins.objects.function.PBuiltinFunction; @@ -197,7 +197,7 @@ static Object callPython(VirtualFrame frame, TpSlotPythonSingle slot, Object sel @Specialization static Object callNative(VirtualFrame frame, Node inliningTarget, TpSlotCExtNative slot, Object self, @Cached GetThreadStateNode getThreadStateNode, - @Cached(inline = false) PythonToNativeNode toNativeNode, + @Cached PythonToNativeInternalNode toNativeNode, @Cached EnsurePythonObjectNode ensurePythonObjectNode, @Cached("createFor($node)") BoundaryCallData boundaryCallData, @Cached NativeToPythonInternalNode toPythonNode, @@ -207,8 +207,8 @@ static Object callNative(VirtualFrame frame, Node inliningTarget, TpSlotCExtNati Object promotedSelf = ensurePythonObjectNode.execute(ctx, self, false); try { long nativeResult = ExternalFunctionInvoker.invokeITERNEXTFUNC(frame, C_API_TIMING, ctx.ensureNativeContext(), boundaryCallData, state, slot.callable, - toNativeNode.executeLong(promotedSelf)); - Object pythonResult = toPythonNode.execute(inliningTarget, nativeResult, true); + toNativeNode.execute(inliningTarget, promotedSelf)); + Object pythonResult = toPythonNode.executeTransfer(inliningTarget, nativeResult); if (pythonResult == PNone.NO_VALUE) { Object currentException = readAndClearNativeException.execute(inliningTarget, state); if (currentException != PNone.NO_VALUE) { diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotLen.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotLen.java index 171c1dd639..158dd88724 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotLen.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotLen.java @@ -53,7 +53,7 @@ import com.oracle.graal.python.builtins.objects.cext.capi.ExternalFunctionNodes.CheckPrimitiveFunctionResultNode; import com.oracle.graal.python.builtins.objects.cext.capi.ExternalFunctionNodes.PExternalFunctionWrapper; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTiming; -import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeNode; +import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeInternalNode; import com.oracle.graal.python.builtins.objects.function.PArguments; import com.oracle.graal.python.builtins.objects.ints.PInt; import com.oracle.graal.python.builtins.objects.type.slots.PythonDispatchers.UnaryPythonSlotDispatcherNode; @@ -177,7 +177,7 @@ static int callPython(VirtualFrame frame, TpSlotPythonSingle slot, Object self, static int callNative(VirtualFrame frame, Node inliningTarget, TpSlotCExtNative slot, Object self, @Exclusive @Cached GetThreadStateNode getThreadStateNode, @Cached EnsurePythonObjectNode ensurePythonObjectNode, - @Cached(inline = false) PythonToNativeNode toNativeNode, + @Cached PythonToNativeInternalNode toNativeNode, @Cached("createFor($node)") BoundaryCallData boundaryCallData, @Exclusive @Cached PRaiseNode raiseNode, @Exclusive @Cached CheckPrimitiveFunctionResultNode checkResultNode) { @@ -186,7 +186,7 @@ static int callNative(VirtualFrame frame, Node inliningTarget, TpSlotCExtNative Object promotedSelf = ensurePythonObjectNode.execute(ctx, self, false); try { long lresult = ExternalFunctionInvoker.invokeLENFUNC(frame, C_API_TIMING, ctx.ensureNativeContext(), boundaryCallData, state, slot.callable, - toNativeNode.executeLong(promotedSelf)); + toNativeNode.execute(inliningTarget, promotedSelf)); long l = checkResultNode.executeLong(inliningTarget, state, T___LEN__, lresult); if (!PInt.isIntRange(l)) { raiseOverflow(inliningTarget, raiseNode, l); diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotMpAssSubscript.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotMpAssSubscript.java index dd4d651f1a..260d445345 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotMpAssSubscript.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotMpAssSubscript.java @@ -57,7 +57,7 @@ import com.oracle.graal.python.builtins.objects.type.slots.TpSlotInquiry.CheckInquiryResultNode; import com.oracle.graal.python.builtins.objects.cext.capi.ExternalFunctionNodes.PExternalFunctionWrapper; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTiming; -import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeNode; +import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeInternalNode; import com.oracle.graal.python.builtins.objects.function.PArguments; import com.oracle.graal.python.builtins.objects.function.PBuiltinFunction; import com.oracle.graal.python.builtins.objects.type.slots.PythonDispatchers.BinaryPythonSlotDispatcherNode; @@ -216,9 +216,9 @@ static void callNative(VirtualFrame frame, TpSlotNative slot, Object self, Objec @Bind PythonContext ctx, @Cached GetThreadStateNode getThreadStateNode, @Cached EnsurePythonObjectNode ensurePythonObjectNode, - @Cached PythonToNativeNode selfToNativeNode, - @Cached PythonToNativeNode keyToNativeNode, - @Cached PythonToNativeNode valueToNativeNode, + @Cached PythonToNativeInternalNode selfToNativeNode, + @Cached PythonToNativeInternalNode keyToNativeNode, + @Cached PythonToNativeInternalNode valueToNativeNode, @Cached("createFor($node)") BoundaryCallData boundaryCallData, @Cached CheckInquiryResultNode checkResultNode) { PythonThreadState threadState = getThreadStateNode.execute(inliningTarget); @@ -227,7 +227,8 @@ static void callNative(VirtualFrame frame, TpSlotNative slot, Object self, Objec Object promotedValue = ensurePythonObjectNode.execute(ctx, value, false); try { int iresult = ExternalFunctionInvoker.invokeOBJOBJARGPROC(frame, C_API_TIMING, ctx.ensureNativeContext(), boundaryCallData, threadState, slot.callable, - selfToNativeNode.executeLong(promotedSelf), keyToNativeNode.executeLong(promotedKey), valueToNativeNode.executeLong(promotedValue)); + selfToNativeNode.execute(inliningTarget, promotedSelf), keyToNativeNode.execute(inliningTarget, promotedKey), valueToNativeNode.execute(inliningTarget, + promotedValue)); checkResultNode.executeBool(inliningTarget, threadState, T___SETITEM__, iresult); } finally { Reference.reachabilityFence(promotedSelf); diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotNbPower.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotNbPower.java index 454c52dda9..40194c04b8 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotNbPower.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotNbPower.java @@ -56,7 +56,7 @@ import com.oracle.graal.python.builtins.objects.cext.capi.ExternalFunctionNodes.PyObjectCheckFunctionResultNode; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTiming; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativeToPythonInternalNode; -import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeNode; +import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeInternalNode; import com.oracle.graal.python.builtins.objects.function.PArguments; import com.oracle.graal.python.builtins.objects.function.PBuiltinFunction; import com.oracle.graal.python.builtins.objects.type.TpSlots; @@ -180,9 +180,9 @@ static Object callNative(VirtualFrame frame, Node inliningTarget, TpSlotCExtNati Object v, Object vType, Object w, TpSlot wSlot, Object wType, Object z, boolean sameTypes, @Cached GetThreadStateNode getThreadStateNode, @Cached EnsurePythonObjectNode ensurePythonObjectNode, - @Cached(inline = false) PythonToNativeNode vToNative, - @Cached(inline = false) PythonToNativeNode wToNative, - @Cached(inline = false) PythonToNativeNode zToNative, + @Cached PythonToNativeInternalNode vToNative, + @Cached PythonToNativeInternalNode wToNative, + @Cached PythonToNativeInternalNode zToNative, @Cached("createFor($node)") BoundaryCallData boundaryCallData, @Cached NativeToPythonInternalNode toPythonNode, @Cached(inline = false) PyObjectCheckFunctionResultNode checkResultNode) { @@ -193,8 +193,8 @@ static Object callNative(VirtualFrame frame, Node inliningTarget, TpSlotCExtNati Object promotedZ = ensurePythonObjectNode.execute(ctx, z, false); try { long lresult = ExternalFunctionInvoker.invokeTERNARYFUNC(frame, C_API_TIMING, ctx.ensureNativeContext(), boundaryCallData, state, slot.callable, - vToNative.executeLong(promotedV), wToNative.executeLong(promotedW), zToNative.executeLong(promotedZ)); - return checkResultNode.execute(state, T___POW__, toPythonNode.execute(inliningTarget, lresult, true)); + vToNative.execute(inliningTarget, promotedV), wToNative.execute(inliningTarget, promotedW), zToNative.execute(inliningTarget, promotedZ)); + return checkResultNode.execute(state, T___POW__, toPythonNode.executeTransfer(inliningTarget, lresult)); } finally { Reference.reachabilityFence(promotedV); Reference.reachabilityFence(promotedW); @@ -276,9 +276,9 @@ static Object callPython(VirtualFrame frame, Node inliningTarget, TpSlotPythonSi static Object callNative(VirtualFrame frame, Node inliningTarget, TpSlotCExtNative slot, Object v, Object w, Object z, @Cached GetThreadStateNode getThreadStateNode, @Cached EnsurePythonObjectNode ensurePythonObjectNode, - @Cached(inline = false) PythonToNativeNode vToNative, - @Cached(inline = false) PythonToNativeNode wToNative, - @Cached(inline = false) PythonToNativeNode zToNative, + @Cached PythonToNativeInternalNode vToNative, + @Cached PythonToNativeInternalNode wToNative, + @Cached PythonToNativeInternalNode zToNative, @Cached("createFor($node)") BoundaryCallData boundaryCallData, @Cached NativeToPythonInternalNode toPythonNode, @Cached(inline = false) PyObjectCheckFunctionResultNode checkResultNode) { @@ -289,8 +289,8 @@ static Object callNative(VirtualFrame frame, Node inliningTarget, TpSlotCExtNati Object promotedZ = ensurePythonObjectNode.execute(ctx, z, false); try { long lresult = ExternalFunctionInvoker.invokeTERNARYFUNC(frame, C_API_TIMING, ctx.ensureNativeContext(), boundaryCallData, state, slot.callable, - vToNative.executeLong(promotedV), wToNative.executeLong(promotedW), zToNative.executeLong(promotedZ)); - return checkResultNode.execute(state, T___IPOW__, toPythonNode.execute(inliningTarget, lresult, true)); + vToNative.execute(inliningTarget, promotedV), wToNative.execute(inliningTarget, promotedW), zToNative.execute(inliningTarget, promotedZ)); + return checkResultNode.execute(state, T___IPOW__, toPythonNode.executeTransfer(inliningTarget, lresult)); } finally { Reference.reachabilityFence(promotedV); Reference.reachabilityFence(promotedW); diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotRepr.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotRepr.java index 6380fb01b1..c29d83bb37 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotRepr.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotRepr.java @@ -50,7 +50,7 @@ import com.oracle.graal.python.builtins.objects.cext.capi.ExternalFunctionNodes.PyObjectCheckFunctionResultNode; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTiming; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativeToPythonInternalNode; -import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeNode; +import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeInternalNode; import com.oracle.graal.python.builtins.objects.function.PArguments; import com.oracle.graal.python.builtins.objects.function.PFunction; import com.oracle.graal.python.builtins.objects.object.ObjectNodes; @@ -112,7 +112,7 @@ static Object callPython(VirtualFrame frame, TpSlotPythonSingle slot, Object sel static Object callNative(VirtualFrame frame, Node inliningTarget, TpSlotCExtNative slot, Object self, @Cached GetThreadStateNode getThreadStateNode, @Cached EnsurePythonObjectNode ensurePythonObjectNode, - @Cached(inline = false) PythonToNativeNode toNativeNode, + @Cached PythonToNativeInternalNode toNativeNode, @Cached("createFor($node)") BoundaryCallData boundaryCallData, @Cached NativeToPythonInternalNode toPythonNode, @Cached(inline = false) PyObjectCheckFunctionResultNode checkResultNode) { @@ -121,8 +121,8 @@ static Object callNative(VirtualFrame frame, Node inliningTarget, TpSlotCExtNati Object promotedSelf = ensurePythonObjectNode.execute(ctx, self, false); try { long lresult = ExternalFunctionInvoker.invokeREPRFUNC(frame, C_API_TIMING, ctx.ensureNativeContext(), boundaryCallData, state, slot.callable, - toNativeNode.executeLong(promotedSelf)); - return checkResultNode.execute(state, T___REPR__, toPythonNode.execute(inliningTarget, lresult, true)); + toNativeNode.execute(inliningTarget, promotedSelf)); + return checkResultNode.execute(state, T___REPR__, toPythonNode.executeTransfer(inliningTarget, lresult)); } finally { Reference.reachabilityFence(promotedSelf); } diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotRichCompare.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotRichCompare.java index b8fcaaf5c1..83a436fda0 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotRichCompare.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotRichCompare.java @@ -56,7 +56,7 @@ import com.oracle.graal.python.builtins.objects.cext.capi.ExternalFunctionNodes.PyObjectCheckFunctionResultNode; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTiming; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativeToPythonInternalNode; -import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeNode; +import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeInternalNode; import com.oracle.graal.python.builtins.objects.function.PArguments; import com.oracle.graal.python.builtins.objects.function.PBuiltinFunction; import com.oracle.graal.python.builtins.objects.type.slots.NodeFactoryUtils.WrapperNodeFactory; @@ -249,8 +249,8 @@ static Object callPython(VirtualFrame frame, Node inliningTarget, TpSlotRichCmpP @Specialization static Object callNative(VirtualFrame frame, Node inliningTarget, TpSlotCExtNative slot, Object a, Object b, RichCmpOp op, @Exclusive @Cached GetThreadStateNode getThreadStateNode, - @Cached(inline = false) PythonToNativeNode toNativeNodeA, - @Cached(inline = false) PythonToNativeNode toNativeNodeB, + @Cached PythonToNativeInternalNode toNativeNodeA, + @Cached PythonToNativeInternalNode toNativeNodeB, @Cached EnsurePythonObjectNode ensurePythonObjectNode, @Cached("createFor($node)") BoundaryCallData boundaryCallData, @Exclusive @Cached NativeToPythonInternalNode toPythonNode, @@ -261,8 +261,8 @@ static Object callNative(VirtualFrame frame, Node inliningTarget, TpSlotCExtNati Object promotedB = ensurePythonObjectNode.execute(ctx, b, false); try { long lresult = ExternalFunctionInvoker.invokeRICHCMPFUNC(frame, C_API_TIMING, ctx.ensureNativeContext(), boundaryCallData, state, slot.callable, - toNativeNodeA.executeLong(promotedA), toNativeNodeB.executeLong(promotedB), op.asNative()); - return checkResultNode.execute(state, T_TP_RICHCOMPARE, toPythonNode.execute(inliningTarget, lresult, true)); + toNativeNodeA.execute(inliningTarget, promotedA), toNativeNodeB.execute(inliningTarget, promotedB), op.asNative()); + return checkResultNode.execute(state, T_TP_RICHCOMPARE, toPythonNode.executeTransfer(inliningTarget, lresult)); } finally { Reference.reachabilityFence(promotedA); Reference.reachabilityFence(promotedB); diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotSetAttr.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotSetAttr.java index 1ffcaef0f1..42793da21c 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotSetAttr.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotSetAttr.java @@ -60,7 +60,7 @@ import com.oracle.graal.python.builtins.objects.type.slots.TpSlotInquiry.CheckInquiryResultNode; import com.oracle.graal.python.builtins.objects.cext.capi.ExternalFunctionNodes.PExternalFunctionWrapper; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTiming; -import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeNode; +import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeInternalNode; import com.oracle.graal.python.builtins.objects.function.PArguments; import com.oracle.graal.python.builtins.objects.function.PBuiltinFunction; import com.oracle.graal.python.builtins.objects.type.TpSlots; @@ -272,9 +272,9 @@ static void callNative(VirtualFrame frame, TpSlots slots, TpSlotNative slot, Obj @Cached InlinedConditionProfile isSetAttrProfile, @Cached AsCharPointerNode asCharPointerNode, @Cached EnsurePythonObjectNode ensurePythonObjectNode, - @Cached PythonToNativeNode nameToNativeNode, - @Cached PythonToNativeNode selfToNativeNode, - @Cached PythonToNativeNode valueToNativeNode, + @Cached PythonToNativeInternalNode nameToNativeNode, + @Cached PythonToNativeInternalNode selfToNativeNode, + @Cached PythonToNativeInternalNode valueToNativeNode, @Cached("createFor($node)") BoundaryCallData boundaryCallData, @Cached CheckInquiryResultNode checkResultNode) { assert PyUnicodeCheckNode.executeUncached(name); @@ -286,14 +286,14 @@ static void callNative(VirtualFrame frame, TpSlots slots, TpSlotNative slot, Obj nameArg = asCharPointerNode.execute(name); } else { promotedName = ensurePythonObjectNode.execute(context, name, false); - nameArg = nameToNativeNode.executeLong(promotedName); + nameArg = nameToNativeNode.execute(inliningTarget, promotedName); } Object promotedValue = ensurePythonObjectNode.execute(context, value, false); int iresult; PythonThreadState threadState = getThreadStateNode.execute(inliningTarget, context); try { iresult = ExternalFunctionInvoker.invokeSETATTRFUNC(frame, C_API_TIMING, context.ensureNativeContext(), boundaryCallData, threadState, slot.callable, - selfToNativeNode.executeLong(promotedSelf), nameArg, valueToNativeNode.executeLong(promotedValue)); + selfToNativeNode.execute(inliningTarget, promotedSelf), nameArg, valueToNativeNode.execute(inliningTarget, promotedValue)); } finally { Reference.reachabilityFence(promotedSelf); if (isSetAttr) { diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotSizeArgFun.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotSizeArgFun.java index 6be12fad54..5070e5c6cf 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotSizeArgFun.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotSizeArgFun.java @@ -54,7 +54,7 @@ import com.oracle.graal.python.builtins.objects.cext.capi.ExternalFunctionNodes.PyObjectCheckFunctionResultNode; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTiming; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativeToPythonInternalNode; -import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeNode; +import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeInternalNode; import com.oracle.graal.python.builtins.objects.function.PArguments; import com.oracle.graal.python.builtins.objects.function.PBuiltinFunction; import com.oracle.graal.python.builtins.objects.type.TpSlots; @@ -262,7 +262,7 @@ static Object callPython(VirtualFrame frame, Node inliningTarget, TpSlotPythonSi static Object callNative(VirtualFrame frame, Node inliningTarget, TpSlotCExtNative slot, Object self, int index, @Exclusive @Cached GetThreadStateNode getThreadStateNode, @Cached EnsurePythonObjectNode ensurePythonObjectNode, - @Cached(inline = false) PythonToNativeNode toNativeNode, + @Cached PythonToNativeInternalNode toNativeNode, @Cached("createFor($node)") BoundaryCallData boundaryCallData, @Cached NativeToPythonInternalNode toPythonNode, @Exclusive @Cached(inline = false) PyObjectCheckFunctionResultNode checkResultNode) { @@ -271,8 +271,8 @@ static Object callNative(VirtualFrame frame, Node inliningTarget, TpSlotCExtNati Object promotedSelf = ensurePythonObjectNode.execute(ctx, self, false); try { long lresult = ExternalFunctionInvoker.invokeSSIZEARGFUNC(frame, C_API_TIMING, ctx.ensureNativeContext(), boundaryCallData, threadState, slot.callable, - toNativeNode.executeLong(promotedSelf), index); - return checkResultNode.execute(threadState, T___GETITEM__, toPythonNode.execute(inliningTarget, lresult, true)); + toNativeNode.execute(inliningTarget, promotedSelf), index); + return checkResultNode.execute(threadState, T___GETITEM__, toPythonNode.executeTransfer(inliningTarget, lresult)); } finally { Reference.reachabilityFence(promotedSelf); } diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotSqAssItem.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotSqAssItem.java index c4933fabc7..fbf70d0721 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotSqAssItem.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotSqAssItem.java @@ -57,7 +57,7 @@ import com.oracle.graal.python.builtins.objects.type.slots.TpSlotInquiry.CheckInquiryResultNode; import com.oracle.graal.python.builtins.objects.cext.capi.ExternalFunctionNodes.PExternalFunctionWrapper; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTiming; -import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeNode; +import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeInternalNode; import com.oracle.graal.python.builtins.objects.function.PArguments; import com.oracle.graal.python.builtins.objects.function.PBuiltinFunction; import com.oracle.graal.python.builtins.objects.type.slots.NodeFactoryUtils.WrapperNodeFactory; @@ -294,8 +294,8 @@ static void callNative(VirtualFrame frame, TpSlotNative slot, Object self, long @Bind PythonContext context, @Cached GetThreadStateNode getThreadStateNode, @Cached EnsurePythonObjectNode ensurePythonObjectNode, - @Cached PythonToNativeNode selfToNativeNode, - @Cached PythonToNativeNode valueToNativeNode, + @Cached PythonToNativeInternalNode selfToNativeNode, + @Cached PythonToNativeInternalNode valueToNativeNode, @Cached("createFor($node)") BoundaryCallData boundaryCallData, @Cached CheckInquiryResultNode checkResultNode) { PythonThreadState threadState = getThreadStateNode.execute(inliningTarget, context); @@ -303,7 +303,7 @@ static void callNative(VirtualFrame frame, TpSlotNative slot, Object self, long Object promotedValue = ensurePythonObjectNode.execute(context, value, false); try { int iresult = ExternalFunctionInvoker.invokeSSIZEOBJARGPROC(frame, C_API_TIMING, context.ensureNativeContext(), boundaryCallData, threadState, slot.callable, - selfToNativeNode.executeLong(promotedSelf), key, valueToNativeNode.executeLong(promotedValue)); + selfToNativeNode.execute(inliningTarget, promotedSelf), key, valueToNativeNode.execute(inliningTarget, promotedValue)); checkResultNode.executeBool(inliningTarget, threadState, T___SETITEM__, iresult); } finally { Reference.reachabilityFence(promotedSelf); diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotSqContains.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotSqContains.java index 5e715944c4..57edfc3bd4 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotSqContains.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotSqContains.java @@ -152,8 +152,8 @@ static boolean callNative(VirtualFrame frame, Node inliningTarget, TpSlotCExtNat Object promotedArg = ensurePythonObjectNode.execute(ctx, arg, false); try { int iresult = ExternalFunctionInvoker.invokeOBJOBJPROC(frame, C_API_TIMING, ctx.ensureNativeContext(), boundaryCallData, state, slot.callable, - selfToNativeNode.execute(inliningTarget, promotedSelf, false), - argToNativeNode.execute(inliningTarget, promotedArg, false)); + selfToNativeNode.execute(inliningTarget, promotedSelf), + argToNativeNode.execute(inliningTarget, promotedArg)); return checkResultNode.executeBool(inliningTarget, state, T___CONTAINS__, iresult); } finally { Reference.reachabilityFence(promotedSelf); diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotUnaryFunc.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotUnaryFunc.java index fb1832e1be..d90d961030 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotUnaryFunc.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotUnaryFunc.java @@ -51,7 +51,7 @@ import com.oracle.graal.python.builtins.objects.cext.capi.ExternalFunctionNodes.PyObjectCheckFunctionResultNode; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTiming; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativeToPythonInternalNode; -import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeNode; +import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeInternalNode; import com.oracle.graal.python.builtins.objects.function.PArguments; import com.oracle.graal.python.builtins.objects.type.slots.PythonDispatchers.UnaryPythonSlotDispatcherNode; import com.oracle.graal.python.builtins.objects.type.slots.TpSlot.TpSlotBuiltinBase; @@ -133,7 +133,7 @@ static Object callNative(VirtualFrame frame, Node inliningTarget, TpSlotCExtNati @Bind PythonContext context, @Cached GetThreadStateNode getThreadStateNode, @Cached EnsurePythonObjectNode ensurePythonObjectNode, - @Cached(inline = false) PythonToNativeNode toNativeNode, + @Cached PythonToNativeInternalNode toNativeNode, @Cached("createFor($node)") BoundaryCallData boundaryCallData, @Cached NativeToPythonInternalNode toPythonNode, @Cached(inline = false) PyObjectCheckFunctionResultNode checkResultNode) { @@ -141,8 +141,8 @@ static Object callNative(VirtualFrame frame, Node inliningTarget, TpSlotCExtNati Object promotedSelf = ensurePythonObjectNode.execute(context, self, false); try { long lresult = ExternalFunctionInvoker.invokeUNARYFUNC(frame, C_API_TIMING, context.ensureNativeContext(), boundaryCallData, state, slot.callable, - toNativeNode.executeLong(promotedSelf)); - return checkResultNode.execute(state, T_UNARY_SLOT, toPythonNode.execute(inliningTarget, lresult, true, true)); + toNativeNode.execute(inliningTarget, promotedSelf)); + return checkResultNode.execute(state, T_UNARY_SLOT, toPythonNode.executeTransferAndRelease(inliningTarget, lresult)); } finally { Reference.reachabilityFence(promotedSelf); } diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotVarargs.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotVarargs.java index bf8813f3f0..e94c5f2bab 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotVarargs.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotVarargs.java @@ -346,16 +346,16 @@ static Object callNative(VirtualFrame frame, TpSlotCExtNative slot, Object self, } else { managedArgsTuple = PFactory.createTuple(context.getLanguage(inliningTarget), args); assert EnsurePythonObjectNode.doesNotNeedPromotion(managedArgsTuple); - argsTuplePtr = toNativeNode.execute(inliningTarget, managedArgsTuple, false); + argsTuplePtr = toNativeNode.execute(inliningTarget, managedArgsTuple); } Object kwargsDict = keywords.length > 0 ? PFactory.createDict(language, keywords) : NO_VALUE; assert EnsurePythonObjectNode.doesNotNeedPromotion(kwargsDict); try { long nativeResult = ExternalFunctionInvoker.invokeTERNARYFUNC(frame, C_API_TIMING, context.ensureNativeContext(), boundaryCallData, state, slot.callable, - toNativeNode.execute(inliningTarget, promotedSelf, false), + toNativeNode.execute(inliningTarget, promotedSelf), argsTuplePtr, - toNativeNode.execute(inliningTarget, kwargsDict, false)); - return checkResultNode.execute(state, name, toPythonNode.execute(inliningTarget, nativeResult, true, true)); + toNativeNode.execute(inliningTarget, kwargsDict)); + return checkResultNode.execute(state, name, toPythonNode.executeTransferAndRelease(inliningTarget, nativeResult)); } finally { if (managedArgsTuple != null) { eagerTupleState.report(inliningTarget, managedArgsTuple); @@ -414,15 +414,15 @@ static Object callNative(VirtualFrame frame, Node inliningTarget, TpSlotCExtNati } else { managedArgsTuple = PFactory.createTuple(context.getLanguage(inliningTarget), args); assert EnsurePythonObjectNode.doesNotNeedPromotion(managedArgsTuple); - argsTuplePtr = toNativeNode.execute(inliningTarget, managedArgsTuple, false); + argsTuplePtr = toNativeNode.execute(inliningTarget, managedArgsTuple); } Object kwargsDict = keywords.length > 0 ? PFactory.createDict(language, keywords) : NO_VALUE; assert EnsurePythonObjectNode.doesNotNeedPromotion(kwargsDict); try { int nativeResult = ExternalFunctionInvoker.invokeINITPROC(frame, C_API_TIMING, context.ensureNativeContext(), boundaryCallData, state, slot.callable, - toNativeNode.execute(inliningTarget, promotedSelf, false), + toNativeNode.execute(inliningTarget, promotedSelf), argsTuplePtr, - toNativeNode.execute(inliningTarget, kwargsDict, false)); + toNativeNode.execute(inliningTarget, kwargsDict)); checkResultNode.executeInt(inliningTarget, state, T___INIT__, nativeResult); } finally { if (managedArgsTuple != null) { diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectHashNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectHashNode.java index a67d2a56cf..91970605f4 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectHashNode.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectHashNode.java @@ -53,7 +53,7 @@ import com.oracle.graal.python.builtins.objects.cext.capi.ExternalFunctionInvoker; import com.oracle.graal.python.builtins.objects.cext.capi.NativeCAPISymbol; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTiming; -import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeNode; +import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeInternalNode; import com.oracle.graal.python.builtins.objects.cext.structs.CFields; import com.oracle.graal.python.builtins.objects.str.PString; import com.oracle.graal.python.builtins.objects.type.TpSlots; @@ -223,7 +223,7 @@ private static TpSlots callTypeReady(Node inliningTarget, Object object, PythonA var callable = CApiContext.getNativeSymbol(null, NativeCAPISymbol.FUN_PY_TYPE_READY); int res = ExternalFunctionInvoker.invokePY_TYPE_READY(null, C_API_TIMING, context.ensureNativeContext(), BoundaryCallData.getUncached(), context.getThreadState(context.getLanguage(inliningTarget)), callable, - PythonToNativeNode.executeLongUncached(klass)); + PythonToNativeInternalNode.executeUncached(klass, false)); if (res < 0) { throw raiseSystemError(inliningTarget, klass); } diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/ErrorMessages.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/ErrorMessages.java index 8a24137828..25a3cb9424 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/ErrorMessages.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/ErrorMessages.java @@ -1302,9 +1302,6 @@ public abstract class ErrorMessages { public static final TruffleString NULL_ARG_INTERNAL = tsLiteral("null argument to internal routine"); - public static final TruffleString NFI_NOT_AVAILABLE = tsLiteral("GraalPy option '%s' is set to '%s, but the 'nfi' language, which is required for this feature, is not available. " + - "If this is a GraalPy standalone distribution: this indicates internal error. If GraalPy was used as a Maven dependency: " + - "are you missing a runtime dependency 'org.graalvm.truffle:truffle-nfi-libffi', which should be a dependency of 'org.graalvm.polyglot:python{-community}'?"); public static final TruffleString NATIVE_EXTENSIONS_VIRTUAL_THREAD = tsLiteral("Python native extensions cannot be used from Java virtual threads. " + "Run Python code that may load or call native extensions on a platform thread."); diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/PGuards.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/PGuards.java index fc55f5f0bd..5de77dd4d3 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/PGuards.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/PGuards.java @@ -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 @@ -52,7 +52,6 @@ import com.oracle.graal.python.builtins.objects.bytes.PBytesLike; import com.oracle.graal.python.builtins.objects.cext.PythonNativeClass; import com.oracle.graal.python.builtins.objects.cext.PythonNativeObject; -import com.oracle.graal.python.builtins.objects.cext.common.NativePointer; import com.oracle.graal.python.builtins.objects.code.PCode; import com.oracle.graal.python.builtins.objects.common.EconomicMapStorage; import com.oracle.graal.python.builtins.objects.common.EmptyStorage; @@ -108,7 +107,6 @@ import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff; import com.oracle.truffle.api.dsl.Idempotent; import com.oracle.truffle.api.exception.AbstractTruffleException; -import com.oracle.truffle.api.interop.InteropLibrary; import com.oracle.truffle.api.nodes.Node; import com.oracle.truffle.api.nodes.UnexpectedResultException; import com.oracle.truffle.api.strings.TruffleString; @@ -523,16 +521,6 @@ public static boolean isIndexOrSlice(Node inliningTarget, PyIndexCheckNode index return indexCheckNode.execute(inliningTarget, key) || isPSlice(key); } - public static boolean isNullOrZero(Object value, InteropLibrary lib) { - if (value instanceof Long) { - return ((long) value) == 0; - } else if (value instanceof NativePointer nativePointer) { - return nativePointer.isNull(); - } else { - return lib.isNull(value); - } - } - /* CPython tests that tp_iter is dict_iter */ public static boolean hasBuiltinDictIter(Node inliningTarget, PDict dict, GetPythonObjectClassNode getClassNode, GetCachedTpSlotsNode getSlots) { return isBuiltinDict(dict) || getSlots.execute(inliningTarget, getClassNode.execute(inliningTarget, dict)).tp_iter() == DictBuiltins.SLOTS.tp_iter(); diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/StringLiterals.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/StringLiterals.java index bffa16044b..a13d0082df 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/StringLiterals.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/StringLiterals.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 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 @@ -136,7 +136,6 @@ public abstract class StringLiterals { public static final TruffleString T_VERSION = tsLiteral("version"); public static final String J_DEFAULT = "default"; public static final TruffleString T_DEFAULT = tsLiteral(J_DEFAULT); - public static final String J_NFI_LANGUAGE = "nfi"; public static final TruffleString T_ID = tsLiteral("id"); public static final TruffleString T_SITE = tsLiteral("site"); public static final TruffleString T_GRAALPYTHON = tsLiteral("graalpy"); diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/arrow/capsule/ArrowArrayCapsuleDestructor.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/arrow/capsule/ArrowArrayCapsuleDestructor.java index d5af1163fe..9fff61038b 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/arrow/capsule/ArrowArrayCapsuleDestructor.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/arrow/capsule/ArrowArrayCapsuleDestructor.java @@ -46,7 +46,7 @@ import com.oracle.graal.python.annotations.CApiUpcallTarget; import com.oracle.graal.python.builtins.modules.cext.PythonCextCapsuleBuiltins.PyCapsuleGetPointerNode; -import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativeToPythonNode; +import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativeToPythonInternalNode; import com.oracle.graal.python.nodes.arrow.ArrowArray; import com.oracle.graal.python.nodes.arrow.ArrowReleaseCallback; import com.oracle.graal.python.runtime.PythonContext; @@ -77,7 +77,7 @@ private static void execute(long capsulePointer) { CompilerAsserts.neverPartOfCompilation(); PythonContext ctx = PythonContext.get(null); ctx.ensureNativeAccess(); - Object capsule = NativeToPythonNode.executeRawUncached(capsulePointer); + Object capsule = NativeToPythonInternalNode.executeUncached(capsulePointer, false); long capsuleNamePointer = ctx.stringToNativeUtf8Bytes(ArrowArray.CAPSULE_NAME, false); try { var arrowArray = ArrowArray.wrap(PyCapsuleGetPointerNode.executeUncached(capsule, capsuleNamePointer)); diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/arrow/capsule/ArrowSchemaCapsuleDestructor.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/arrow/capsule/ArrowSchemaCapsuleDestructor.java index a0e5adc585..8fbbe775f1 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/arrow/capsule/ArrowSchemaCapsuleDestructor.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/arrow/capsule/ArrowSchemaCapsuleDestructor.java @@ -46,7 +46,7 @@ import com.oracle.graal.python.annotations.CApiUpcallTarget; import com.oracle.graal.python.builtins.modules.cext.PythonCextCapsuleBuiltins.PyCapsuleGetPointerNode; -import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativeToPythonNode; +import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativeToPythonInternalNode; import com.oracle.graal.python.nodes.arrow.ArrowReleaseCallback; import com.oracle.graal.python.nodes.arrow.ArrowSchema; import com.oracle.graal.python.runtime.PythonContext; @@ -77,7 +77,7 @@ private static void execute(long capsulePointer) { CompilerAsserts.neverPartOfCompilation(); PythonContext ctx = PythonContext.get(null); ctx.ensureNativeAccess(); - Object capsule = NativeToPythonNode.executeRawUncached(capsulePointer); + Object capsule = NativeToPythonInternalNode.executeUncached(capsulePointer, false); long capsuleNamePointer = ctx.stringToNativeUtf8Bytes(ArrowSchema.CAPSULE_NAME, false); try { var arrowSchema = ArrowSchema.wrap(PyCapsuleGetPointerNode.executeUncached(capsule, capsuleNamePointer)); diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/object/GetDictIfExistsNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/object/GetDictIfExistsNode.java index 195eec107d..d3d0bfaf34 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/object/GetDictIfExistsNode.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/object/GetDictIfExistsNode.java @@ -161,7 +161,7 @@ static PDict doNativeObject(PythonAbstractNativeObject object, assert EnsurePythonObjectNode.doesNotNeedPromotion(object); NativeFunctionPointer callable = CApiContext.getNativeSymbol(inliningTarget, FUN_PY_OBJECT_GET_DICT_PTR); try { - long dictPtr = ExternalFunctionInvoker.invokeGETDICTPTRFUN(callable.getAddress(), pythonToNativeNode.execute(inliningTarget, object, false)); + long dictPtr = ExternalFunctionInvoker.invokeGETDICTPTRFUN(callable.getAddress(), pythonToNativeNode.execute(inliningTarget, object)); Reference.reachabilityFence(object); if (dictPtr == NULLPTR) { return null; diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/object/SetDictNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/object/SetDictNode.java index 67bb986913..0b093b39fa 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/object/SetDictNode.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/object/SetDictNode.java @@ -98,8 +98,8 @@ static void doNativeObject(Node inliningTarget, PythonAbstractNativeObject objec @Cached PythonToNativeInternalNode dictToNative, @Cached CheckPrimitiveFunctionResultNode checkResult) { assert !IsTypeNode.executeUncached(object); - long objectPointer = objectToNative.execute(inliningTarget, object, false); - long dictPointer = dictToNative.execute(inliningTarget, dict, false); + long objectPointer = objectToNative.execute(inliningTarget, object); + long dictPointer = dictToNative.execute(inliningTarget, dict); PythonContext context = PythonContext.get(inliningTarget); var callable = CApiContext.getNativeSymbol(inliningTarget, FUN_PY_OBJECT_GENERIC_SET_DICT); int result = ExternalFunctionInvoker.invokePY_OBJECT_GENERIC_SET_DICT(null, C_API_TIMING, context.ensureNativeContext(), diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/NativePosixSupport.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/NativePosixSupport.java index 28dba24183..d7b63a16b4 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/NativePosixSupport.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/NativePosixSupport.java @@ -45,7 +45,6 @@ import static com.oracle.graal.python.annotations.NativeSimpleType.SINT32; import static com.oracle.graal.python.annotations.NativeSimpleType.SINT64; import static com.oracle.graal.python.annotations.NativeSimpleType.VOID; -import static com.oracle.graal.python.nodes.StringLiterals.J_NFI_LANGUAGE; import static com.oracle.graal.python.nodes.StringLiterals.T_NATIVE; import static com.oracle.graal.python.runtime.NativePosixConstants.OFFSETOF_STRUCT_IN6_ADDR_S6_ADDR; import static com.oracle.graal.python.runtime.NativePosixConstants.OFFSETOF_STRUCT_IN_ADDR_S_ADDR; @@ -138,7 +137,6 @@ import com.oracle.truffle.api.library.ExportLibrary; import com.oracle.truffle.api.library.ExportMessage; import com.oracle.truffle.api.nodes.Node; -import com.oracle.truffle.api.source.Source; import com.oracle.truffle.api.strings.TruffleString; import sun.misc.Unsafe; @@ -150,8 +148,6 @@ @ExportLibrary(PosixSupportLibrary.class) public final class NativePosixSupport extends PosixSupport { private static final String SUPPORTING_NATIVE_LIB_NAME = "posix"; - private static final Source NFI_WARMUP_SIGNATURE = Source.newBuilder(J_NFI_LANGUAGE, "with native ():void", "python-nfi-warmup").internal(true).build(); - private static final int UNAME_BUF_LENGTH = 256; private static final int DIRENT_NAME_BUF_LENGTH = 256; private static final int PWD_OUTPUT_LEN = 5; @@ -664,15 +660,6 @@ public void setEnv(Env env) { if (env.isPreInitialization()) { return; } - // Load NFI on the Python thread before any blocking native read can pin it. - // Workaround for GR-75767 - if (env.getInternalLanguages().containsKey(J_NFI_LANGUAGE)) { - try { - env.parseInternal(NFI_WARMUP_SIGNATURE).call(); - } catch (RuntimeException e1) { - LOGGER.log(Level.FINE, "Failed to eagerly initialize NFI warmup signature.", e1); - } - } // Java NIO (and TruffleFile) do not expect/support changing native working directory since // it is inherently thread-unsafe operation. It is not defined how NIO behaves when native // cwd changes, thus we need to prevent TruffleFile from resolving relative paths using diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/PythonContext.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/PythonContext.java index a637d23d12..548eaa1012 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/PythonContext.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/PythonContext.java @@ -55,7 +55,6 @@ import static com.oracle.graal.python.nodes.StringLiterals.J_EXT_DYLIB; import static com.oracle.graal.python.nodes.StringLiterals.J_EXT_SO; import static com.oracle.graal.python.nodes.StringLiterals.J_LIB_PREFIX; -import static com.oracle.graal.python.nodes.StringLiterals.J_NFI_LANGUAGE; import static com.oracle.graal.python.nodes.StringLiterals.T_DASH; import static com.oracle.graal.python.nodes.StringLiterals.T_DOT; import static com.oracle.graal.python.nodes.StringLiterals.T_EMPTY_STRING; @@ -112,7 +111,6 @@ import com.oracle.graal.python.PythonLanguage; import com.oracle.graal.python.annotations.PythonOS; import com.oracle.graal.python.builtins.Python3Core; -import com.oracle.graal.python.builtins.PythonBuiltinClassType; import com.oracle.graal.python.builtins.modules.MarshalModuleBuiltins; import com.oracle.graal.python.builtins.modules.MathGuards; import com.oracle.graal.python.builtins.objects.PNone; @@ -124,7 +122,6 @@ import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTiming; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions; import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.HandleContext; -import com.oracle.graal.python.builtins.objects.cext.common.NativePointer; import com.oracle.graal.python.builtins.objects.common.HashingStorage; import com.oracle.graal.python.builtins.objects.common.HashingStorageNodes.HashingStorageGetItem; import com.oracle.graal.python.builtins.objects.common.HashingStorageNodes.HashingStorageGetIterator; @@ -242,7 +239,7 @@ public final class PythonContext extends Python3Core { /** * List of native memory that should be free'd if this context is finalized. */ - private List nativeResources; + private List nativeResources; private volatile boolean finalizing; @@ -287,16 +284,16 @@ public long stringToNativeUtf8Bytes(TruffleString string, boolean contextMemory) throw CompilerDirectives.shouldNotReachHere(); } TruffleString utf8String = string.switchEncodingUncached(Encoding.UTF_8); - NativePointer mem; + long mem; int byteLength = utf8String.byteLength(Encoding.UTF_8); if (contextMemory) { mem = allocateContextMemory(byteLength + 1); - NativeMemory.writeByte(mem.asPointer() + byteLength, (byte) 0); + NativeMemory.writeByte(mem + byteLength, (byte) 0); } else { - mem = NativePointer.wrap(NativeMemory.callocByteArray(byteLength + 1)); + mem = NativeMemory.callocByteArray(byteLength + 1); } utf8String.copyToNativeMemoryUncached(0, mem, 0, byteLength, Encoding.UTF_8); - return mem.asPointer(); + return mem; } public void ensureNativeAccess() { @@ -2934,12 +2931,6 @@ public boolean isFinalizing() { return finalizing; } - public void ensureNFILanguage(Node nodeForRaise, String optionName, String optionValue) { - if (!env.getInternalLanguages().containsKey(J_NFI_LANGUAGE)) { - throw PRaiseNode.raiseStatic(nodeForRaise, PythonBuiltinClassType.SystemError, ErrorMessages.NFI_NOT_AVAILABLE, optionName, optionValue); - } - } - @TruffleBoundary public TruffleString getSoAbi() { if (soABI == null) { @@ -3023,17 +3014,17 @@ public static void setWasStackWalk() { * Allocates native memory that will be free'd if the context is disposed. * * @param byteSize Number of bytes to allocate. - * @return An interop pointer. + * @return A native pointer. */ @TruffleBoundary - public NativePointer allocateContextMemory(int byteSize) { + public long allocateContextMemory(int byteSize) { ensureNativeAccess(); if (nativeResources == null) { nativeResources = new LinkedList<>(); } - NativePointer nativePointer = NativePointer.wrap(NativeMemory.malloc(byteSize)); + long nativePointer = NativeMemory.malloc(byteSize); if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.fine(String.format("Allocated %d bytes of context memory: %s", byteSize, nativePointer)); + LOGGER.fine(String.format("Allocated %d bytes of context memory: 0x%x", byteSize, nativePointer)); } nativeResources.add(nativePointer); return nativePointer; @@ -3042,11 +3033,11 @@ public NativePointer allocateContextMemory(int byteSize) { private void freeContextMemory() { if (nativeResources != null) { ensureNativeAccess(); - for (NativePointer nativePointer : nativeResources) { + for (long nativePointer : nativeResources) { if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.fine(String.format("Freeing context memory: %s", nativePointer)); + LOGGER.fine(String.format("Freeing context memory: 0x%x", nativePointer)); } - NativeMemory.free(nativePointer.asPointer()); + NativeMemory.free(nativePointer); } } } diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/sequence/storage/NativeSequenceStorage.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/sequence/storage/NativeSequenceStorage.java index 8c92dd3191..76399fb323 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/sequence/storage/NativeSequenceStorage.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/sequence/storage/NativeSequenceStorage.java @@ -49,13 +49,8 @@ import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativeStorageReference; import com.oracle.graal.python.util.PythonUtils; import com.oracle.truffle.api.TruffleLogger; -import com.oracle.truffle.api.interop.InteropLibrary; -import com.oracle.truffle.api.interop.TruffleObject; -import com.oracle.truffle.api.library.ExportLibrary; -import com.oracle.truffle.api.library.ExportMessage; -@ExportLibrary(InteropLibrary.class) -public abstract class NativeSequenceStorage extends SequenceStorage implements TruffleObject { +public abstract class NativeSequenceStorage extends SequenceStorage { private static final TruffleLogger LOGGER = PythonLanguage.getLogger(NativeSequenceStorage.class); @@ -136,13 +131,4 @@ public Object[] getReplicatedNativeReferences() { return replicatedNativeReferences; } - @ExportMessage - boolean isPointer() { - return true; - } - - @ExportMessage - long asPointer() { - return ptr; - } } diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/util/PythonUtils.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/util/PythonUtils.java index b4ab48635c..e5a3ae94fe 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/util/PythonUtils.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/util/PythonUtils.java @@ -93,8 +93,6 @@ import com.oracle.truffle.api.TruffleOptions; import com.oracle.truffle.api.dsl.GeneratedBy; import com.oracle.truffle.api.dsl.NodeFactory; -import com.oracle.truffle.api.interop.InteropLibrary; -import com.oracle.truffle.api.interop.UnsupportedMessageException; import com.oracle.truffle.api.memory.ByteArraySupport; import com.oracle.truffle.api.nodes.Node; import com.oracle.truffle.api.nodes.NodeUtil; @@ -1001,39 +999,11 @@ public static long crcHqx(int initialValue, byte[] bytes, int offset, int length 0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0, }; - public static String formatPointer(Object pointer) { - CompilerAsserts.neverPartOfCompilation(); - InteropLibrary lib = InteropLibrary.getUncached(pointer); - if (lib.isPointer(pointer)) { - try { - return String.format("%s#0x%016x", pointer.getClass().getSimpleName(), lib.asPointer(pointer)); - } catch (UnsupportedMessageException e) { - throw CompilerDirectives.shouldNotReachHere(e); - } - } - return String.valueOf(pointer); - } - public static String formatPointer(long pointer) { CompilerAsserts.neverPartOfCompilation(); return String.format("0x%016x", pointer); } - public static long coerceToLong(Object allocated, InteropLibrary lib) { - if (allocated instanceof Long) { - return (long) allocated; - } else { - if (!lib.isPointer(allocated)) { - lib.toNative(allocated); - } - try { - return lib.asPointer(allocated); - } catch (UnsupportedMessageException e) { - throw CompilerDirectives.shouldNotReachHere(e); - } - } - } - /** * Use this helper in PE code or behind Truffle boundary if the PE caller does not push * encapsulating node (either directly or, e.g., via @@ -1050,12 +1020,6 @@ public static Object callCallTarget(CallTarget target, Node location, Object... return location != null && location.isAdoptable() ? target.call(location, args) : target.call(args); } - public static InteropLibrary getUncachedInterop(InteropLibrary existing, Object obj) { - // TODO: have a simple LRU cache of "uncached" pointer InteropLibrary in context? - // "accepts" should be fast and saves us the concurrent hash map lookup in getUncached - return existing != null && existing.accepts(obj) ? existing : InteropLibrary.getUncached(obj); - } - /** * Node factory that creates new instances of given node by cloning a prototype node instance * passed in the constructor. We use cloning as opposed to a producer lambda, because this diff --git a/graalpython/lib-python/3/test/test_import/__init__.py b/graalpython/lib-python/3/test/test_import/__init__.py index cb0ed5bea3..aaa1bc0f1d 100644 --- a/graalpython/lib-python/3/test/test_import/__init__.py +++ b/graalpython/lib-python/3/test/test_import/__init__.py @@ -1593,7 +1593,7 @@ def exec_module(*args): else: importlib.SourceLoader.exec_module = old_exec_module - @impl_detail("[GR-27024] [GR-23324] posix NFI support", graalpy=False) + @impl_detail("[GR-27024] [GR-23324] posix native support", graalpy=False) @unittest.skipUnless(TESTFN_UNENCODABLE, 'need TESTFN_UNENCODABLE') def test_unencodable_filename(self): # Issue #11619: The Python parser and the import machinery must not diff --git a/graalpython/lib-python/3/test/test_unicode_file.py b/graalpython/lib-python/3/test/test_unicode_file.py index 23e8d20c39..63513263e0 100644 --- a/graalpython/lib-python/3/test/test_unicode_file.py +++ b/graalpython/lib-python/3/test/test_unicode_file.py @@ -120,13 +120,13 @@ def _test_single(self, filename): # The 'test' functions are unittest entry points, and simply call our # _test functions with each of the filename combinations we wish to test - @impl_detail("[GR-27024] [GR-23324] posix NFI support", graalpy=False) + @impl_detail("[GR-27024] [GR-23324] posix native support", graalpy=False) def test_single_files(self): self._test_single(TESTFN_UNICODE) if TESTFN_UNENCODABLE is not None: self._test_single(TESTFN_UNENCODABLE) - @impl_detail("[GR-27024] [GR-23324] posix NFI support", graalpy=False) + @impl_detail("[GR-27024] [GR-23324] posix native support", graalpy=False) def test_directories(self): # For all 'equivalent' combinations: # Make dir with encoded, chdir with unicode, checkdir with encoded diff --git a/mx.graalpython/mx_pominit.py b/mx.graalpython/mx_pominit.py index abc6e9ee4a..668f00f0fe 100644 --- a/mx.graalpython/mx_pominit.py +++ b/mx.graalpython/mx_pominit.py @@ -124,7 +124,6 @@ "com.oracle.graal.python.bouncycastle": (LOCAL_GROUP_ID, "com.oracle.graal.python.bouncycastle"), "truffle:TRUFFLE_API": ("org.graalvm.truffle", "truffle-api", GRAALVM_VERSION), "truffle:TRUFFLE_DSL_PROCESSOR": ("org.graalvm.truffle", "truffle-dsl-processor", GRAALVM_VERSION), - "truffle:TRUFFLE_NFI": ("org.graalvm.truffle", "truffle-nfi", GRAALVM_VERSION), "truffle:TRUFFLE_ICU4J": ("org.graalvm.shadowed", "icu4j", GRAALVM_VERSION), "truffle:TRUFFLE_XZ": ("org.graalvm.shadowed", "xz", GRAALVM_VERSION), "tools:TRUFFLE_PROFILER": ("org.graalvm.tools", "profiler-tool", GRAALVM_VERSION), diff --git a/mx.graalpython/native-image.properties b/mx.graalpython/native-image.properties index 0764a3e689..9dbb5c43ea 100644 --- a/mx.graalpython/native-image.properties +++ b/mx.graalpython/native-image.properties @@ -1,6 +1,6 @@ # This file contains native-image arguments needed to build graalpython -Requires = language:regex language:nfi language:xz +Requires = language:regex language:xz JavaArgs = -Dpolyglot.image-build-time.PreinitializeContexts=python \ --add-exports org.graalvm.nativeimage/org.graalvm.nativeimage.impl=ALL-UNNAMED diff --git a/mx.graalpython/suite.py b/mx.graalpython/suite.py index 9ddfa6a8d3..f70e224544 100644 --- a/mx.graalpython/suite.py +++ b/mx.graalpython/suite.py @@ -384,7 +384,6 @@ "com.oracle.graal.python.annotations", "com.oracle.graal.python.pegparser", "truffle:TRUFFLE_API", - "truffle:TRUFFLE_NFI", "tools:TRUFFLE_PROFILER", "sdk:POLYGLOT", "truffle:TRUFFLE_XZ", @@ -707,7 +706,6 @@ "CMAKE_BUILD_TYPE": "", "CAPI_INC_DIR": "/jni_gen", "PYCONFIG_INCLUDE_DIR": "/-/", - "TRUFFLE_NFI_H_INC": "/include", "GRAALPY_PARENT_DIR": "", "GRAALPY_EXT": "", "LIBFFI_DIST": "/-//" @@ -743,7 +741,6 @@ "CMAKE_BUILD_TYPE": "", "CAPI_INC_DIR": "/jni_gen", "PYCONFIG_INCLUDE_DIR": "/-//", - "TRUFFLE_NFI_H_INC": "/include", "GRAALPY_PARENT_DIR": "", "GRAALPY_EXT": "", "LIBFFI_DIST": "/-//" @@ -885,7 +882,6 @@ "relative_module_path": "../modules", "relative_extracted_lib_paths": { "truffle.attach.library": "../jvmlibs/", - "truffle.nfi.library": "../jvmlibs/", }, "liblang_relpath": "../lib/", "default_vm_args": [ @@ -1079,9 +1075,6 @@ "sdk:POLYGLOT", "sdk:NATIVEIMAGE", "sdk:COLLECTIONS", - "truffle:TRUFFLE_NFI", - "truffle:TRUFFLE_NFI_LIBFFI", - "truffle:TRUFFLE_NFI_PANAMA", "truffle:TRUFFLE_ICU4J", "truffle:TRUFFLE_XZ", ], @@ -1123,9 +1116,6 @@ "sdk:POLYGLOT", "sdk:NATIVEIMAGE", "sdk:COLLECTIONS", - "truffle:TRUFFLE_NFI", - "truffle:TRUFFLE_NFI_LIBFFI", # runtime dependency - "truffle:TRUFFLE_NFI_PANAMA", # runtime dependency "truffle:TRUFFLE_ICU4J", "truffle:TRUFFLE_XZ", ], @@ -1560,7 +1550,6 @@ }, "jvmlibs/": [ "extracted-dependency:truffle:TRUFFLE_ATTACH_GRAALVM_SUPPORT", - "extracted-dependency:truffle:TRUFFLE_NFI_NATIVE_GRAALVM_SUPPORT", ], "modules/": [ "classpath-dependencies:GRAALPY_STANDALONE_DEPENDENCIES", diff --git a/pom.xml b/pom.xml index ba3e3038b4..e3a34ed2b4 100644 --- a/pom.xml +++ b/pom.xml @@ -111,11 +111,6 @@ SOFTWARE. com.oracle.graal.python ${project.version}
- - org.graalvm.truffle - truffle-nfi - ${graalvm.version} - org.graalvm.tools profiler-tool