Here the patch from 2022 that I successfully used for debugging the rework of the finalization of
Java (peer) objects due to changes to Java (deprecating the finalize method) where it was necessary
to exploit phantom references (cf. "javadoc java.lang.ref.PhantomReference") and have the ooRexx
garbage collector run at certain points in time:
Index: interpreter/expression/BuiltinFunctions.cpp
===================================================================
--- interpreter/expression/BuiltinFunctions.cpp (revision 12472)
+++ interpreter/expression/BuiltinFunctions.cpp (working copy)
@@ -2997,7 +2997,20 @@
return SystemInterpreter::popEnvironment(context);
}
+BUILTIN(GC)
+{
+ const size_t GC_Min = 0;
+ const size_t GC_Max = 0;
+ check_args(GC);
+
+ memoryObject.collectAndUninit(false); // keep stack
+
+ // the external environment implements this
+ return TheFalseObject;
+}
+
+
/**
* Qualify a stream name.
*/
@@ -3100,5 +3113,6 @@
&builtin_function_ENDLOCAL ,
&builtin_function_SETLOCAL ,
&builtin_function_QUALIFY ,
+ &builtin_function_GC ,
};
Index: interpreter/parser/KeywordConstants.cpp
===================================================================
--- interpreter/parser/KeywordConstants.cpp (revision 12472)
+++ interpreter/parser/KeywordConstants.cpp (working copy)
@@ -191,6 +191,7 @@
KeywordEntry("FORM", BUILTIN_FORM),
KeywordEntry("FORMAT", BUILTIN_FORMAT),
KeywordEntry("FUZZ", BUILTIN_FUZZ),
+ KeywordEntry("GC", BUILTIN_GC),
KeywordEntry("INSERT", BUILTIN_INSERT),
KeywordEntry("LASTPOS", BUILTIN_LASTPOS),
KeywordEntry("LEFT", BUILTIN_LEFT),
@@ -272,6 +273,7 @@
KeywordEntry("FORM", BUILTIN_FORM),
KeywordEntry("FORMAT", BUILTIN_FORMAT),
KeywordEntry("FUZZ", BUILTIN_FUZZ),
+ KeywordEntry("GC", BUILTIN_GC),
KeywordEntry("INSERT", BUILTIN_INSERT),
KeywordEntry("LASTPOS", BUILTIN_LASTPOS),
KeywordEntry("LEFT", BUILTIN_LEFT),
Index: interpreter/parser/Token.hpp
===================================================================
--- interpreter/parser/Token.hpp (revision 12472)
+++ interpreter/parser/Token.hpp (working copy)
@@ -508,6 +508,7 @@
BUILTIN_ENDLOCAL,
BUILTIN_SETLOCAL,
BUILTIN_QUALIFY,
+ BUILTIN_GC,
} BuiltinCode;
---rony
On 01.12.2024 12:37, Rony G. Flatscher wrote:
In the past there have been discussions about allowing a programmer to manually invoke the garbage
collector as is possible for other programming languages.
For debugging purposes it may be mandatory in certain situations to be able to manually invoke the
garbage collector as lately discussed on the RexxLA member list in the context of the ooRexx
debugger by Dom Wise.
Most programming languages allow for debugging purposes the interaction with the garbage
collector, e.g., Python [1], PHP [2], Java [3] (a very nice overview!), .Net [4] (e.g. C#). All
of these are major programming languages and/or garbage collecting runtime environments.
There are (granted rare) situations where it becomes important for developers to manually invoke
the garbage collector which ooRexx - unlike other programming languages - currently lacks. For
such scenarios a gc()-BIF would allow to debug edge cases linked to garbage collection which is
quite important for such ooRexx programs and libraries.
Having a gc()-BIF would allow the ooRexx developers to employ the garbage collector manually if
this becomes necessary.
[To inhibit naive usage, one could e.g. force the use of gc() by first enabling it and then
running the garbage collector or supplying an argument like "run manually", such that not only the
documentation for gc() would warn from improper use, but make its use a little bit cumbersome such
that it only gets used when really needed. OTOH, I think that ooRexx programmers who use gc()
would not do so naively.]
---rony
[1] Garbage Collection in Python, 2023:
<https://www.geeksforgeeks.org/garbage-collection-python/>
[2] Garbage Collection in PHP, 2013:
<https://stackoverflow.com/questions/19715048/what-gc-collect-cycles-function-is-useful-for>
[3] Nayak S., Garbage Collection in Java (very nice introductory overview), 2021:
<https://www.freecodecamp.org/news/garbage-collection-in-java-what-is-gc-and-how-it-works-in-the-jvm/>
[4] .Net (e.g., C#), 2021:
<https://learn.microsoft.com/en-us/dotnet/api/system.gc?view=net-9.0>
_______________________________________________
Oorexx-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/oorexx-devel