[Bug fortran/88137] BACKTRACE seems to have a memory leak

2018-12-06 Thread jb at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88137

Janne Blomqvist  changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 Resolution|--- |FIXED

--- Comment #9 from Janne Blomqvist  ---
Fixed on trunk/8/7 branches, closing.

The commit to the gcc-7 branch is a merge of the two separate commits to trunk.

[Bug fortran/88137] BACKTRACE seems to have a memory leak

2018-12-06 Thread jb at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88137

--- Comment #8 from Janne Blomqvist  ---
Author: jb
Date: Thu Dec  6 15:38:25 2018
New Revision: 266858

URL: https://gcc.gnu.org/viewcvs?rev=266858=gcc=rev
Log:
Initialize backtrace state once

From backtrace.h for backtrace_create_state:

   Calling this function allocates resources that can not be freed.
   There is no backtrace_free_state function.  The state is used to
   cache information that is expensive to recompute.  Programs are
   expected to call this function at most once and to save the return
   value for all later calls to backtrace functions.

So instead of calling backtrace_create_state every time we wish to
show a backtrace, do it once and store the result in a static
variable.  libbacktrace allows multiple threads to access the state,
so no need to use TLS, but use atomic load/store to access the static
variable.

Regtested on x86_64-pc-linux-gnu.

libgfortran/ChangeLog:

2018-12-06  Janne Blomqvist  

Backport from trunk
PR libfortran/88137
* runtime/backtrace.c (show_backtrace): Store backtrace state in a
static variable, initialize once.

Modified:
branches/gcc-7-branch/libgfortran/ChangeLog
branches/gcc-7-branch/libgfortran/runtime/backtrace.c

[Bug fortran/88137] BACKTRACE seems to have a memory leak

2018-12-02 Thread jb at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88137

--- Comment #7 from Janne Blomqvist  ---
Author: jb
Date: Sun Dec  2 15:14:51 2018
New Revision: 266725

URL: https://gcc.gnu.org/viewcvs?rev=266725=gcc=rev
Log:
Use atomic load/store to access static backtrace state pointer

As the static backtrace state pointer can be accessed from multiple
threads, use atomics to access it.

Regtested on x86_64-pc-linux-gnu.

libgfortran/ChangeLog:

2018-12-02  Janne Blomqvist  

Backport from trunk
PR libfortran/88137
* runtime/backtrace.c (show_backtrace): Use atomic load/store to
access the static lbstate pointer.

Modified:
branches/gcc-8-branch/libgfortran/ChangeLog
branches/gcc-8-branch/libgfortran/runtime/backtrace.c

[Bug fortran/88137] BACKTRACE seems to have a memory leak

2018-12-02 Thread jb at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88137

--- Comment #6 from Janne Blomqvist  ---
Author: jb
Date: Sun Dec  2 15:12:44 2018
New Revision: 266724

URL: https://gcc.gnu.org/viewcvs?rev=266724=gcc=rev
Log:
Use atomic load/store to access static backtrace state pointer

As the static backtrace state pointer can be accessed from multiple
threads, use atomics to access it.

Regtested on x86_64-pc-linux-gnu.

libgfortran/ChangeLog:

2018-12-02  Janne Blomqvist  

PR libfortran/88137
* runtime/backtrace.c (show_backtrace): Use atomic load/store to
access the static lbstate pointer.

Modified:
trunk/libgfortran/ChangeLog
trunk/libgfortran/runtime/backtrace.c

[Bug fortran/88137] BACKTRACE seems to have a memory leak

2018-11-30 Thread jb at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88137

--- Comment #5 from Janne Blomqvist  ---
Author: jb
Date: Fri Nov 30 16:46:55 2018
New Revision: 266678

URL: https://gcc.gnu.org/viewcvs?rev=266678=gcc=rev
Log:
Initialize backtrace state once

From backtrace.h for backtrace_create_state:

   Calling this function allocates resources that can not be freed.
   There is no backtrace_free_state function.  The state is used to
   cache information that is expensive to recompute.  Programs are
   expected to call this function at most once and to save the return
   value for all later calls to backtrace functions.

So instead of calling backtrace_create_state every time we wish to
show a backtrace, do it once and store the result in a static
variable.  libbacktrace allows multiple threads to access the state,
so no need to use TLS.

Regtested on x86_64-pc-linux-gnu.

Backport from trunk.

libgfortran/ChangeLog:

2018-11-30  Janne Blomqvist  

PR libfortran/88137
* runtime/backtrace.c (show_backtrace): Make lbstate a static
variable, initialize once.

Modified:
branches/gcc-8-branch/libgfortran/ChangeLog
branches/gcc-8-branch/libgfortran/runtime/backtrace.c

[Bug fortran/88137] BACKTRACE seems to have a memory leak

2018-11-30 Thread jb at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88137

--- Comment #4 from Janne Blomqvist  ---
Author: jb
Date: Fri Nov 30 16:44:27 2018
New Revision: 266677

URL: https://gcc.gnu.org/viewcvs?rev=266677=gcc=rev
Log:
Initialize backtrace state once

From backtrace.h for backtrace_create_state:

   Calling this function allocates resources that can not be freed.
   There is no backtrace_free_state function.  The state is used to
   cache information that is expensive to recompute.  Programs are
   expected to call this function at most once and to save the return
   value for all later calls to backtrace functions.

So instead of calling backtrace_create_state every time we wish to
show a backtrace, do it once and store the result in a static
variable.  libbacktrace allows multiple threads to access the state,
so no need to use TLS.

Regtested on x86_64-pc-linux-gnu.

libgfortran/ChangeLog:

2018-11-30  Janne Blomqvist  

PR libfortran/88137
* runtime/backtrace.c (show_backtrace): Make lbstate a static
variable, initialize once.

Modified:
trunk/libgfortran/ChangeLog
trunk/libgfortran/runtime/backtrace.c

[Bug fortran/88137] BACKTRACE seems to have a memory leak

2018-11-22 Thread jb at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88137

Janne Blomqvist  changed:

   What|Removed |Added

URL||https://gcc.gnu.org/ml/gcc-
   ||patches/2018-11/msg01901.ht
   ||ml

--- Comment #3 from Janne Blomqvist  ---
Patch here: https://gcc.gnu.org/ml/gcc-patches/2018-11/msg01901.html

[Bug fortran/88137] BACKTRACE seems to have a memory leak

2018-11-22 Thread jb at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88137

Janne Blomqvist  changed:

   What|Removed |Added

   Assignee|unassigned at gcc dot gnu.org  |jb at gcc dot gnu.org

--- Comment #2 from Janne Blomqvist  ---
In backtrace.h (the header for the libbacktrace library that we use to print
backtraces) we have for the backtrace_create_state function:

   Calling this function allocates resources that can not be freed.
   There is no backtrace_free_state function.  The state is used to
   cache information that is expensive to recompute.  Programs are
   expected to call this function at most once and to save the return
   value for all later calls to backtrace functions.


In libgfortran we don't do this, but rather with call backtrace_create_state()
again for every invocation of the GFortran backtrace intrinsic.

Assigning to myself.

[Bug fortran/88137] BACKTRACE seems to have a memory leak

2018-11-22 Thread jb at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88137

Janne Blomqvist  changed:

   What|Removed |Added

 Status|UNCONFIRMED |NEW
   Last reconfirmed||2018-11-22
 CC||jb at gcc dot gnu.org
 Ever confirmed|0   |1

--- Comment #1 from Janne Blomqvist  ---
Confirmed on latest trunk (9.0.0 20181122), x86_64-pc-linux-gnu

Changing the example to execute 10 iterations of the loop, and running via
/usr/bin/time shows

(0avgtext+0avgdata 67124maxresident)k

and with 100 iterations

(0avgtext+0avgdata 644684maxresident)k