|
186 | 186 | import com.oracle.graal.python.nodes.statement.AbstractImportNode;
|
187 | 187 | import com.oracle.graal.python.nodes.util.CastToJavaIntExactNode;
|
188 | 188 | import com.oracle.graal.python.runtime.GilNode;
|
189 |
| -import com.oracle.graal.python.runtime.IndirectCallData; |
190 | 189 | import com.oracle.graal.python.runtime.PosixSupportLibrary;
|
191 | 190 | import com.oracle.graal.python.runtime.PosixSupportLibrary.PosixException;
|
192 | 191 | import com.oracle.graal.python.runtime.PythonContext;
|
193 |
| -import com.oracle.graal.python.runtime.PythonContext.GetThreadStateNode; |
194 | 192 | import com.oracle.graal.python.runtime.PythonOptions;
|
195 | 193 | import com.oracle.graal.python.runtime.exception.ExceptionUtils;
|
196 | 194 | import com.oracle.graal.python.runtime.exception.PException;
|
@@ -1315,70 +1313,30 @@ static PNone doObject(Object ptr,
|
1315 | 1313 | }
|
1316 | 1314 | }
|
1317 | 1315 |
|
1318 |
| - @CApiBuiltin(ret = Int, args = {UNSIGNED_INT, UINTPTR_T, SIZE_T}, call = Direct) |
1319 |
| - @ImportStatic(CApiGuards.class) |
1320 |
| - abstract static class PyTraceMalloc_Track extends CApiTernaryBuiltinNode { |
1321 |
| - private static final TruffleLogger LOGGER = CApiContext.getLogger(PyTraceMalloc_Track.class); |
1322 |
| - |
1323 |
| - @Specialization(guards = {"isSingleContext()", "domain == cachedDomain"}, limit = "3") |
1324 |
| - static int doCachedDomainIdx(@SuppressWarnings("unused") int domain, long ptrVal, long size, |
1325 |
| - @Bind("this") Node inliningTarget, |
1326 |
| - @Shared @Cached("createFor(this)") IndirectCallData indirectCallData, |
1327 |
| - @Shared @Cached GetThreadStateNode getThreadStateNode, |
1328 |
| - @Cached("domain") @SuppressWarnings("unused") long cachedDomain, |
1329 |
| - @Cached("lookupDomain(inliningTarget, domain)") int cachedDomainIdx) { |
| 1316 | + @CApiBuiltin(ret = Void, args = {UNSIGNED_INT, UINTPTR_T, SIZE_T}, call = Ignored) |
| 1317 | + abstract static class PyTruffleTraceMalloc_Track extends CApiTernaryBuiltinNode { |
| 1318 | + private static final TruffleLogger LOGGER = CApiContext.getLogger(PyTruffleTraceMalloc_Track.class); |
1330 | 1319 |
|
| 1320 | + @Specialization |
| 1321 | + @TruffleBoundary |
| 1322 | + static Object doCachedDomainIdx(int domain, long ptrVal, long size) { |
1331 | 1323 | // this will also be called if the allocation failed
|
1332 | 1324 | if (ptrVal != 0) {
|
1333 |
| - CApiContext cApiContext = getCApiContext(inliningTarget); |
1334 |
| - cApiContext.getTraceMallocDomain(cachedDomainIdx).track(ptrVal, size); |
1335 |
| - cApiContext.increaseMemoryPressure(null, inliningTarget, getThreadStateNode, indirectCallData, size); |
1336 |
| - if (LOGGER.isLoggable(Level.FINE)) { |
1337 |
| - LOGGER.fine(PythonUtils.formatJString("Tracking memory (size: %d): %s", size, CApiContext.asHex(ptrVal))); |
1338 |
| - } |
| 1325 | + LOGGER.fine(() -> PythonUtils.formatJString("Tracking memory (domain: %d, size: %d): %s", domain, size, CApiContext.asHex(ptrVal))); |
1339 | 1326 | }
|
1340 |
| - return 0; |
1341 |
| - } |
1342 |
| - |
1343 |
| - @Specialization(replaces = "doCachedDomainIdx") |
1344 |
| - static int doGeneric(int domain, long ptrVal, long size, |
1345 |
| - @Bind("this") Node inliningTarget, |
1346 |
| - @Shared @Cached("createFor(this)") IndirectCallData indirectCallData, |
1347 |
| - @Shared @Cached GetThreadStateNode getThreadStateNode) { |
1348 |
| - return doCachedDomainIdx(domain, ptrVal, size, inliningTarget, indirectCallData, getThreadStateNode, domain, lookupDomain(inliningTarget, domain)); |
1349 |
| - } |
1350 |
| - |
1351 |
| - static int lookupDomain(Node inliningTarget, int domain) { |
1352 |
| - return getCApiContext(inliningTarget).findOrCreateTraceMallocDomain(domain); |
| 1327 | + return PNone.NO_VALUE; |
1353 | 1328 | }
|
1354 | 1329 | }
|
1355 | 1330 |
|
1356 |
| - @CApiBuiltin(ret = Int, args = {UNSIGNED_INT, UINTPTR_T}, call = Direct) |
1357 |
| - @ImportStatic(CApiGuards.class) |
1358 |
| - abstract static class PyTraceMalloc_Untrack extends CApiBinaryBuiltinNode { |
1359 |
| - private static final TruffleLogger LOGGER = CApiContext.getLogger(PyTraceMalloc_Untrack.class); |
1360 |
| - |
1361 |
| - @Specialization(guards = {"isSingleContext()", "domain == cachedDomain"}, limit = "3") |
1362 |
| - int doCachedDomainIdx(@SuppressWarnings("unused") int domain, long ptrVal, |
1363 |
| - @Cached("domain") @SuppressWarnings("unused") long cachedDomain, |
1364 |
| - @Cached("lookupDomain(domain)") int cachedDomainIdx) { |
1365 |
| - |
1366 |
| - CApiContext cApiContext = getCApiContext(); |
1367 |
| - long trackedMemorySize = cApiContext.getTraceMallocDomain(cachedDomainIdx).untrack(ptrVal); |
1368 |
| - cApiContext.reduceMemoryPressure(trackedMemorySize); |
1369 |
| - if (LOGGER.isLoggable(Level.FINE)) { |
1370 |
| - LOGGER.fine(PythonUtils.formatJString("Untracking memory (size: %d): %s", trackedMemorySize, CApiContext.asHex(ptrVal))); |
1371 |
| - } |
1372 |
| - return 0; |
1373 |
| - } |
1374 |
| - |
1375 |
| - @Specialization(replaces = "doCachedDomainIdx") |
1376 |
| - int doGeneric(int domain, long ptrVal) { |
1377 |
| - return doCachedDomainIdx(domain, ptrVal, domain, lookupDomain(domain)); |
1378 |
| - } |
| 1331 | + @CApiBuiltin(ret = Void, args = {UNSIGNED_INT, UINTPTR_T}, call = Ignored) |
| 1332 | + abstract static class PyTruffleTraceMalloc_Untrack extends CApiBinaryBuiltinNode { |
| 1333 | + private static final TruffleLogger LOGGER = CApiContext.getLogger(PyTruffleTraceMalloc_Untrack.class); |
1379 | 1334 |
|
1380 |
| - int lookupDomain(int domain) { |
1381 |
| - return getCApiContext().findOrCreateTraceMallocDomain(domain); |
| 1335 | + @Specialization |
| 1336 | + @TruffleBoundary |
| 1337 | + Object doCachedDomainIdx(int domain, long ptrVal) { |
| 1338 | + LOGGER.fine(() -> PythonUtils.formatJString("Untracking memory (domain: %d): %s", domain, CApiContext.asHex(ptrVal))); |
| 1339 | + return PNone.NO_VALUE; |
1382 | 1340 | }
|
1383 | 1341 | }
|
1384 | 1342 |
|
|
0 commit comments