When the instance is terminated, all object references are cleared out in
case there might be a dangling reference to the instance object that might
pin it in memory. This includes .local, which should not be pinned
anywhere. I spent fair about of time recently tracing the termination code
to fix #1734, so I know it's doing what it's supposed to be doing.

I was going to suggest reverting your overrides before terminating the
instance. A more appropriate way to do that is to call the destination
method with no argument. The monitor maintains a queue of the destination
objects, so this will pop your monitor off of the queue and revert to the
previous destination.

The only other thing to comes to mind is that you are calling the terminate
API on the wrong thread or in the wrong circumstances (e.g., on the correct
thread but as the result of a callout from running oorexx code). I know you
tried doing the second one once before. Are you checking the you are
getting a true return value from the terminate call?

Rick



On Wed, Jul 20, 2022 at 11:04 AM Rony G. Flatscher <rony.flatsc...@wu.ac.at>
wrote:

> After further excessive (literally additional days of) debugging I can
> state that upon Rexx interpreter instance (RII) terminations using the
> native Terminate() API, ooRexx does not release/run the uninit methods of
> at least the monitored objects (ooRexx BSF objects) of the .local monitors!
>
> =====
> Here the relevant parts after creating, using and Terminate() 1,000 RIIs:
>
> References from ooRexx objects (under the control of ooRexx), pinning Java
> objects:
>
> ... cut ...*RexxAnalyzeRegistry category=[[B]**                    - 
> RefCount: entries=[  **2 000**] | references: min=[        1] max=[        1] 
> avg=[      1,0] sum=[    2 000]**                    - MemSize:  entries=[  2 
> 000] | references: min=[        1] max=[        1] avg=[      1,0] sum=[    
> **2 000**]**RexxAnalyzeRegistry category=[[C]**                    - 
> RefCount: entries=[  **2 000**] | references: min=[        1] max=[        1] 
> avg=[      1,0] sum=[    2 000]**                    - MemSize:  entries=[  2 
> 000] | references: min=[        2] max=[        2] avg=[      2,0] sum=[    
> **4 000**]**RexxAnalyzeRegistry category=[[I]**                    - 
> RefCount: entries=[  **4 000**] | references: min=[        1] max=[        1] 
> avg=[      1,0] sum=[    4 000]**                    - MemSize:  entries=[  4 
> 000] | references: min=[        4] max=[        4] avg=[      4,0] sum=[   
> **16 000**]**RexxAnalyzeRegistry category=[java.io.InputStreamReader]**       
>              - RefCount: entries=[  **1 000**] | references: min=[        1] 
> max=[        1] avg=[      1,0] sum=[    1 000]**RexxAnalyzeRegistry 
> category=[java.io.PrintWriter]**                    - RefCount: entries=[  
> **2 000**] | references: min=[        1] max=[        1] avg=[      1,0] 
> sum=[    2 000]*
>
> ... cut ...
>
> References from Java objects (under the control of BSF4ooRexx), pinning 
> ooRexx engines (REXX_ENGINE, REXX_SCRIPT_ENGINE) and ooRexx objects 
> (REXX_PROXY):
>
>
> org.rexxla.bsf.engines.rexx.RexxCleanupRef:
> RexxCleanupRef [2022-07-20 15:16:10.613000000]
>              RefKind:         Instances:         Finalized: Not Yet Finalized:
> ------------------------------------------------------------------------------
> [TEST]..............: [               0] [               0] [               0]
> [REXX_ENGINE].......: [           1 002] [           1 000] [               
> 2][REXX_PROXY]........: [           9 000] [           8 994] [               
> 6]
> [REXX_SCRIPT_ENGINE]: [           1 000] [             999] [               1]
> ------------------------------------------------------------------------------
> Totals..............: [          11 002] [          10 993] [               9]
>
> ---
>
> Here the ooRexx objects referenced by BSF4ooRexx on the Java side (cf. 
> REXX_PROXY above):
>
> OREXX_REGISTRY related:
>         OREXX_REGISTRY           ~items: 6
>         OREXX_REGISTRY_REFCOUNTER~items: 6
>
> t_jsr223.rex: ooRexx 5.0.0 r12473 (17 Jul 2022) / BSF 641.20220717 / Java 
> 17.0.3.1 (released: 2022-04-22), 64-bit (amd64) / Windows 10.0.19043
>
> count_rexx_gc: [4] count_java_gc: [4]
>
> ... cut ...
>
> =====
> Here the relevant parts after creating, using and Terminate() 1,000 RIIs,
> this time running the following Rexx program right before termination of a
> RII from the Java side:
>
>                  ... cut ...
>                * String rexxCode =   // reset .input, .output, .error, 
> .traceOutput, .debugInput to free BSF objects if any
>                     "  lDir = .local  -- get .local                      ;\n" 
> +
>                     "  lDir['INPUT'      ]= .monitor~new(ldir['STDIN' ]) ;\n" 
> +
>                     "  lDir['OUTPUT'     ]= .monitor~new(ldir['STDOUT']) ;\n" 
> +
>                     "  lDir['ERROR'      ]= .monitor~new(ldir['STDERR']) ;\n" 
> +
>                     "  lDir['TRACEOUTPUT']= .monitor~new(ldir['ERROR' ]) ;\n" 
> +
>                     "  lDir['DEBUGINPUT' ]= .monitor~new(ldir['INPUT' ]) ;\n" 
> ;
> *
>
>                 Object obj=null;
>                 try {
>                         obj=rexxInterface.jniRexxRunProgram(
>                                 rii_ID,         // RexxInstance instance ID
>                                 2,              // invocationType,         // 
> determines whether "CallProgram", "LoadPackage" or "LoadPackageFromData" is 
> to be used
>                                 "RexxEngine_terminate_cleanup_local_monitors" 
> ,   // fileName
>                                 *rexxCode *,      // Rexx code to execute
>                                 null            // arguments
>                                 );
>                  }
>                  ... cut ...
>
>                  
> res=rexxInterface.jniRexxTerminateInterpreterInstance(rii_ID);  // wait for 
> termination of all Rexx threads of this interpreter instance
>
>                  ... cut ...
>
>
> Doing this for every RII will cause the UNINIT method of the BSF objects
> to be run, correctly removing the pinned (peer) Java objects:
>
> References from ooRexx, pinning Java objects:
>
> ... cut ...*RexxAnalyzeRegistry category=[[B]**                    - 
> RefCount: entries=[      **2**] | references: min=[        1] max=[        1] 
> avg=[      1,0] sum=[        2]**                    - MemSize:  entries=[    
>   2] | references: min=[        1] max=[        1] avg=[      1,0] sum=[      
>   **2**]**RexxAnalyzeRegistry category=[[C]**                    - RefCount: 
> entries=[      **2**] | references: min=[        1] max=[        1] avg=[     
>  1,0] sum=[        2]**                    - MemSize:  entries=[      2] | 
> references: min=[        2] max=[        2] avg=[      2,0] sum=[        
> **4**]**RexxAnalyzeRegistry category=[[I]**                    - RefCount: 
> entries=[      **4**] | references: min=[        1] max=[        1] avg=[     
>  1,0] sum=[        4]**                    - MemSize:  entries=[      4] | 
> references: min=[        4] max=[        4] avg=[      4,0] sum=[       
> **16**]**RexxAnalyzeRegistry category=[java.io.InputStreamReader]**           
>          - RefCount: entries=[      **1**] | references: min=[        1] 
> max=[        1] avg=[      1,0] sum=[        1]**RexxAnalyzeRegistry 
> category=[java.io.PrintWriter]**                    - RefCount: entries=[     
>  **2**] | references: min=[        1] max=[        1] avg=[      1,0] sum=[   
>      2]*
> ... cut ...
>
> References from Java objects (under the control of BSF4ooRexx), pinning 
> ooRexx engines (REXX_ENGINE, REXX_SCRIPT_ENGINE) and ooRexx objects 
> (REXX_PROXY):
>
> org.rexxla.bsf.engines.rexx.RexxCleanupRef:
> RexxCleanupRef [2022-07-20 15:39:04.692000000]
>              RefKind:         Instances:         Finalized: Not Yet Finalized:
> ------------------------------------------------------------------------------
> [TEST]..............: [               0] [               0] [               0]
> [REXX_ENGINE].......: [           1 002] [           1 000] [               2]
> [REXX_PROXY]........: [           9 000] [           8 994] [               6]
> [REXX_SCRIPT_ENGINE]: [           1 000] [             999] [               1]
> ------------------------------------------------------------------------------
> Totals..............: [          11 002] [          10 993] [               9]
>
> ---
>
> Here the ooRexx objects referenced by BSF4ooRexx on the Java side (cf. 
> REXX_PROXY above):
>
> OREXX_REGISTRY related:
>         OREXX_REGISTRY           ~items: 6
>         OREXX_REGISTRY_REFCOUNTER~items: 6
>
> t_jsr223.rex: ooRexx 5.0.0 r12473 (17 Jul 2022) / BSF 641.20220717 / Java 
> 17.0.3.1 (released: 2022-04-22), 64-bit (amd64) / Windows 10.0.19043
>
> count_rexx_gc: [4] count_java_gc: [4]
>
> ... cut ...
>
> ---rony
>
>
> _______________________________________________
> Oorexx-devel mailing list
> Oorexx-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/oorexx-devel
>
_______________________________________________
Oorexx-devel mailing list
Oorexx-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/oorexx-devel

Reply via email to