Project

General

Profile

Bug #12117

automatically clear memptr addresses

Added by Constantin Asofiei 19 days ago. Updated 10 days ago.

Status:
New
Priority:
Normal
Assignee:
-
Target version:
-
Start date:
Due date:
% Done:

0%

billable:
No
vendor_id:
GCD
case_num:
version_reported:
version_resolved:
reviewer:
production:
No
env_name:
topics:

Related issues

Related to Runtime Infrastructure - Feature #9684: migrate from libffi (and C heap functions) to the built-in JDK FFM support New

History

#1 Updated by Constantin Asofiei 19 days ago

In FWD, we can track all allocated addresses and clean them up even if the 4GL code does not - this will be at the address level, with a reference counter similar as we do for OO:
  • we need to track the address across assignments, parameters, etc
  • internal usage of memptr - needs to be analyzed, I'm not sure if we need to create 'memptrvar' or not (similar to ObjectVar)
  • get/set-pointer-value or passing the memory address to a native call - that address will be marked as 'dirty' and will not be cleaned up automatically in FWD
  • otherwise, we need to track the scope of the memptr var (i.e. if the program or top-level block defining it is deleted/finished, and the reference counter for the address is zero, then we automatically release that memory)

#3 Updated by Greg Shah 18 days ago

To be clear: we will track reference counts to addresses not to memptr instances.

Another point: it is possible to calculate the address of an arbitrary index inside an allocated block of memory. This is something done all the time by native C code (and similar). I point this out because it is a potential anti-pattern where a returned address can be turned into a memptr or otherwise passed around (e.g. to a native API call) but it is from inside the block and might effectively be still in use after the memptr itself goes out of scope.

#4 Updated by Constantin Asofiei 18 days ago

Yes, any address incoming from or outgoing to native code will be 'dirty' and not automatically cleared.

#5 Updated by Greg Shah 18 days ago

The problem here is that it is possible for these addresses to be passed around as 64-bit integers and not necessarily as memptrs. So it is not 100% possible to catch all scenarios. But as I said, that is an anti-pattern.

#6 Updated by Constantin Asofiei 18 days ago

Greg Shah wrote:

The problem here is that it is possible for these addresses to be passed around as 64-bit integers and not necessarily as memptrs. So it is not 100% possible to catch all scenarios. But as I said, that is an anti-pattern.

Don't you need get-pointer-value to get this address from an allocation via memptr? In such case, again will not be tracked.

#7 Updated by Teodor Gorghe 18 days ago

  • Related to Feature #9684: migrate from libffi (and C heap functions) to the built-in JDK FFM support added

#8 Updated by Constantin Asofiei 10 days ago

Teodor, if you want to work on this, go ahead, please.

#9 Updated by Teodor Gorghe 10 days ago

I will handle this after finishing #12159.

Also available in: Atom PDF