Skip to content

Commit e9a3619

Browse files
fangerertimfel
authored andcommitted
Use long value (if possible) as key in PyTraceMalloc_*
1 parent a25bcb2 commit e9a3619

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextBuiltins.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1409,10 +1409,11 @@ int doCachedDomainIdx(@SuppressWarnings("unused") int domain, Object pointerObje
14091409
// this will also be called if the allocation failed
14101410
if (!lib.isNull(pointerObject)) {
14111411
CApiContext cApiContext = getCApiContext();
1412-
cApiContext.getTraceMallocDomain(cachedDomainIdx).track(pointerObject, size);
1412+
Object key = CApiContext.asPointer(pointerObject, lib);
1413+
cApiContext.getTraceMallocDomain(cachedDomainIdx).track(key, size);
14131414
cApiContext.increaseMemoryPressure(null, getThreadStateNode, this, size);
14141415
if (LOGGER.isLoggable(Level.FINE)) {
1415-
LOGGER.fine(() -> PythonUtils.formatJString("Tracking memory (size: %d): %s", size, CApiContext.asHex(pointerObject)));
1416+
LOGGER.fine(() -> PythonUtils.formatJString("Tracking memory (size: %d): %s", size, CApiContext.asHex(key)));
14161417
}
14171418
}
14181419
return 0;
@@ -1438,20 +1439,23 @@ abstract static class PyTraceMalloc_Untrack extends CApiBinaryBuiltinNode {
14381439
@Specialization(guards = {"isSingleContext()", "domain == cachedDomain"}, limit = "3")
14391440
int doCachedDomainIdx(@SuppressWarnings("unused") int domain, Object pointerObject,
14401441
@Cached("domain") @SuppressWarnings("unused") long cachedDomain,
1441-
@Cached("lookupDomain(domain)") int cachedDomainIdx) {
1442+
@Cached("lookupDomain(domain)") int cachedDomainIdx,
1443+
@CachedLibrary("pointerObject") InteropLibrary lib) {
14421444

14431445
CApiContext cApiContext = getCApiContext();
1444-
long trackedMemorySize = cApiContext.getTraceMallocDomain(cachedDomainIdx).untrack(pointerObject);
1446+
Object key = CApiContext.asPointer(pointerObject, lib);
1447+
long trackedMemorySize = cApiContext.getTraceMallocDomain(cachedDomainIdx).untrack(key);
14451448
cApiContext.reduceMemoryPressure(trackedMemorySize);
14461449
if (LOGGER.isLoggable(Level.FINE)) {
1447-
LOGGER.fine(() -> PythonUtils.formatJString("Untracking memory (size: %d): %s", trackedMemorySize, CApiContext.asHex(pointerObject)));
1450+
LOGGER.fine(() -> PythonUtils.formatJString("Untracking memory (size: %d): %s", trackedMemorySize, CApiContext.asHex(key)));
14481451
}
14491452
return 0;
14501453
}
14511454

14521455
@Specialization(replaces = "doCachedDomainIdx")
1453-
int doGeneric(int domain, Object pointerObject) {
1454-
return doCachedDomainIdx(domain, pointerObject, domain, lookupDomain(domain));
1456+
int doGeneric(int domain, Object pointerObject,
1457+
@CachedLibrary(limit = "3") InteropLibrary lib) {
1458+
return doCachedDomainIdx(domain, pointerObject, domain, lookupDomain(domain), lib);
14551459
}
14561460

14571461
int lookupDomain(int domain) {

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,7 @@ public static Object asPointer(Object ptr, InteropLibrary lib) {
282282
try {
283283
return lib.asPointer(ptr);
284284
} catch (UnsupportedMessageException e) {
285-
CompilerDirectives.transferToInterpreter();
286-
throw new IllegalStateException();
285+
throw CompilerDirectives.shouldNotReachHere(e);
287286
}
288287
}
289288
return ptr;

0 commit comments

Comments
 (0)