Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8224760

Enhancing j.l.Runtime/System::gc specification with an explicit 'no guarantee' statement

    XMLWordPrintable

Details

    • CSR
    • Resolution: Approved
    • P3
    • 13
    • core-libs
    • None
    • behavioral
    • minimal
    • Hide
      No change is being made to behavior of GC implementations.
      Show
      No change is being made to behavior of GC implementations.
    • Java API
    • SE

    Description

      Summary

      System.gc() and Runtime.gc() methods clarify that implementations of JVM garbage collection make no guarantees about the timing or results of requests to make memory available.

      Problem

      The descriptions of java.lang.System.gc and java.lang.Runtime.gc methods make statements about the behavior of calling System.gc that are subject to interpretation including that gc will happen at all.

      Solution

      Revise the specification of j.l.System.gc and j.l.Runtime.gc. Use the same specification for both methods. System.gc() delegates to Runtime.gc().

      Specification

      In java.lang.System.gc:

         /**
           * Runs the garbage collector in the Java Virtual Machine.
           * <p>
           * Calling the {@code gc} method suggests that the Java Virtual Machine
           * expend effort toward recycling unused objects in order to
           * make the memory they currently occupy available for reuse
           * by the Java Virtual Machine.
           * When control returns from the method call, the Java Virtual Machine
           * has made a best effort to reclaim space from all unused objects.
           * There is no guarantee that this effort will recycle any particular
           * number of unused objects, reclaim any particular amount of space, or
           * complete at any particular time, if at all, before the method returns or ever.
           * <p>
           * The call {@code System.gc()} is effectively equivalent to the
           * call:
           * <blockquote><pre>
           * Runtime.getRuntime().gc()
           * </pre></blockquote>
           *
           * @see     java.lang.Runtime#gc()
           */

      In java.lang.Runtime.gc:

          /**
           * Runs the garbage collector in the Java Virtual Machine.
           * <p>
           * Calling this method suggests that the Java Virtual Machine
           * expend effort toward recycling unused objects in order to
           * make the memory they currently occupy available for reuse
           * by the Java Virtual Machine.
           * When control returns from the method call, the Java Virtual Machine
           * has made a best effort to reclaim space from all unused objects.
           * There is no guarantee that this effort will recycle any particular
           * number of unused objects, reclaim any particular amount of space, or
           * complete at any particular time, if at all, before the method returns or ever.
           * <p>
           * The name {@code gc} stands for "garbage
           * collector". The Java Virtual Machine performs this recycling
           * process automatically as needed, in a separate thread, even if the
           * {@code gc} method is not invoked explicitly.
           * <p>
           * The method {@link System#gc()} is the conventional and convenient
           * means of invoking this method.
           */

      Attachments

        Issue Links

          Activity

            People

              rriggs Roger Riggs
              dbessono Dmitry Bessonov
              Mandy Chung
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: