Harmony
  1. Harmony
  2. HARMONY-5523

[drlvm][gc][lang-management][geronimo] MemoryUsage returns incorrect values

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 5.0M4, 5.0M5
    • Fix Version/s: None
    • Labels:
      None

      Description

      The following test demonstrates the problem:

      public class Test {
      public static void main(String[] args) throws Exception

      { System.out.println(java.lang.management.ManagementFactory.getMemoryMXBean().getHeapMemoryUsage()); }

      }

      Output on RI:

      $ java Test
      init = 0(0K) used = 162416(158K) committed = 2031616(1984K) max = 66650112(65088K)

      $ java -Xms128M -Xmx256M Test
      init = 134217728(131072K) used = 166480(162K) committed = 133234688(130112K) max = 266403840(260160K)

      Output on Harmony:

      $ java Test
      MemoryUsage: init=16777216used=16777216committed=16777216max=16777216

      $ java -Xms128M -Xmx256M Test
      MemoryUsage: init=134217728used=134217728committed=134217728max=134217728

      Clearly enough, the following problems do exist:

      1. getUsed() method always returns the -Xms value instead of actual used memory amount.
      2. getMax() method returns the -Xms value instead of -Xmx value.
      3. toString() method works incorrectly (output is badly readable).

      This issues causes the Geronimo console to display the used memory information incorrectly.

        Activity

        Hide
        Vasily Zakharov added a comment -

        The actual source for the returned information resides in working_vm/vm/vmcore/src/kernel_classes/native/org_apache_harmony_lang_management_MemoryMXBeanImpl.cpp, lines 84-87:

        jlong init = ((JavaVM_Internal*)vm)>vm_env>init_gc_used_memory;
        jlong used = gc_total_memory();
        jlong committed = gc_total_memory();
        jlong max = gc_max_memory();

        Functions gc_total_memory() and gc_max_memory() are implemented identically in working_vm/vm/gc_gen/src/common/gc_for_vm.cpp, lines 277-298, using functions gc_*_total_memory_size() defined in working_vm/vm/gc_gen/src/gen/gen.h, lines 172-175 and working_vm/vm/gc_gen/src/mark_sweep/gc_ms.h, lines 110-111.

        So, there're the following problems here:
        1. 'used' uses the same gc_total_memory() method as 'committed'.
        2. gc_total_memory() and gc_max_memory() are implemented identically.
        3. gc_*_total_memory_size() methods return -Xms value, not -Xmx.

        So, I'm requalifying this issue as [drlvm], though the fixes are necessary to:

        • JLM natives
        • GC
        • JLM classlib code (toString() method, see above)
        Show
        Vasily Zakharov added a comment - The actual source for the returned information resides in working_vm/vm/vmcore/src/kernel_classes/native/org_apache_harmony_lang_management_MemoryMXBeanImpl.cpp, lines 84-87: jlong init = ((JavaVM_Internal*)vm) >vm_env >init_gc_used_memory; jlong used = gc_total_memory(); jlong committed = gc_total_memory(); jlong max = gc_max_memory(); Functions gc_total_memory() and gc_max_memory() are implemented identically in working_vm/vm/gc_gen/src/common/gc_for_vm.cpp, lines 277-298, using functions gc_*_total_memory_size() defined in working_vm/vm/gc_gen/src/gen/gen.h, lines 172-175 and working_vm/vm/gc_gen/src/mark_sweep/gc_ms.h, lines 110-111. So, there're the following problems here: 1. 'used' uses the same gc_total_memory() method as 'committed'. 2. gc_total_memory() and gc_max_memory() are implemented identically. 3. gc_*_total_memory_size() methods return -Xms value, not -Xmx. So, I'm requalifying this issue as [drlvm] , though the fixes are necessary to: JLM natives GC JLM classlib code (toString() method, see above)
        Hide
        Vasily Zakharov added a comment -

        Attached a patch to classlib that adjusts the MemoryUsage.toString() output to a more readable format, like this:

        init = 134217728 (131072K) used = 134217728 (131072K) committed = 134217728 (131072K) max = 134217728 (131072K)

        Show
        Vasily Zakharov added a comment - Attached a patch to classlib that adjusts the MemoryUsage.toString() output to a more readable format, like this: init = 134217728 (131072K) used = 134217728 (131072K) committed = 134217728 (131072K) max = 134217728 (131072K)
        Hide
        Andrey Yakushev added a comment -

        I'd implemented:

        jlong used = gc_total_memory();
        jlong committed = gc_total_memory();

        because vm<->gc interface didn't have the request for committed memory, and I didn't imagine the situation when returning "used" instead of "committed" could confuse any requster.

        Nevertheless for pure imlementation we can add precise committed value.

        Could we extend vm<->gc interface for such request and implement it in gc_gen?

        Show
        Andrey Yakushev added a comment - I'd implemented: jlong used = gc_total_memory(); jlong committed = gc_total_memory(); because vm<->gc interface didn't have the request for committed memory, and I didn't imagine the situation when returning "used" instead of "committed" could confuse any requster. Nevertheless for pure imlementation we can add precise committed value. Could we extend vm<->gc interface for such request and implement it in gc_gen?
        Hide
        Vasily Zakharov added a comment -

        r643014: committed a fix to issue 3: toString() method works incorrectly (output is badly readable).

        Now the output on Harmony looks like this:

        init = 268435456 (262144K) used = 268435456 (262144K) committed = 268435456 (262144K) max = 268435456 (262144K)

        Show
        Vasily Zakharov added a comment - r643014: committed a fix to issue 3: toString() method works incorrectly (output is badly readable). Now the output on Harmony looks like this: init = 268435456 (262144K) used = 268435456 (262144K) committed = 268435456 (262144K) max = 268435456 (262144K)
        Hide
        Vasily Zakharov added a comment -

        Xiao-Feng Li commented in the dev-list:

        There is gc_free_memory() API, which can be used to compute the used memory.

        http://article.gmane.org/gmane.comp.java.harmony.devel/32032

        Show
        Vasily Zakharov added a comment - Xiao-Feng Li commented in the dev-list: There is gc_free_memory() API, which can be used to compute the used memory. http://article.gmane.org/gmane.comp.java.harmony.devel/32032

          People

          • Assignee:
            Unassigned
            Reporter:
            Vasily Zakharov
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:

              Development