[m-rev.] for review: [java] Run finalisers only if main/2 returns normally
Julien Fischer
jfischer at opturion.com
Thu Jan 1 22:28:32 AEDT 2015
Hi Paul,
On Tue, 30 Dec 2014, Paul Bone wrote:
> ---
> [java] Run finalisers only if main/2 returns normally
>
> finalisers should be executed only if main/2 returns normally, it does not
> throw an exception. The C backends probably already do this correctly but
Given the behaviour specified below, there is no "probably" about it.
That's exactly what they do,
> the Java backend did not. I have not checked the C# or Erlang backends.
The C# backend runs the finalisers when main/2 terminates with an uncaught
exception (i.e. it implements the "wrong" behaviour).
The Erlang backend appears to be correct.
> java/runtime/MercuryThreadPool.java:
> Add a parameter to the shutdown() method to specify whether the backend
> is aborting.
>
> In runMain(), run finalisers only if the runtime is exiting normally.
>
> java/runtime/MercuryRuntime.java:
> Add a parameter to the finalise() method allowing standalone Java
> applications to specify whether or not they are aborting when the
s/the/they/
> finalise the RTS.
A better design IMO would be to have two methods: one that finalises
the runtime system normally and the other that does an immediate abort,
for example something like:
MercuryRuntime.shutdown() // run finalisers, shutdown the thread pool.
MercuryRuntime.abort() // abort immediately.
> doc/reference_manual.texi:
> Specify this behaviour.
Which behaviour? The following would be more meaningful:
Specify the behaviour of finalise directives if main/2 terminates
with an uncaught exception.
...
> ---
> doc/reference_manual.texi | 2 ++
> java/runtime/MercuryRuntime.java | 15 +++++++++++----
> java/runtime/MercuryThreadPool.java | 19 +++++++++++++++----
> samples/java_interface/standalone_java/JavaMain.java | 6 ++++--
> 4 files changed, 32 insertions(+), 10 deletions(-)
>
> diff --git a/doc/reference_manual.texi b/doc/reference_manual.texi
> index d9b355c..da7cd0b 100644
> --- a/doc/reference_manual.texi
> +++ b/doc/reference_manual.texi
> @@ -4835,6 +4835,8 @@ If @samp{finalpredname/arity} terminates with an uncaught exception then
> the program will immediately abort execution. No predicates specified
> by other @samp{finalise} directives that have not yet been executed will
> be executed.
> +If @samp{main/2} terminates with an uncaught exception then no predicates
> +specified by any @samp{finalise} directives will be executed.
I suggest:
If the program's @samp{main/2} predicate terminates with an uncaught exception
then no finalisation predicates will be executed.
Cheers,
Julien.
More information about the reviews
mailing list