You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by gs...@apache.org on 2007/04/16 16:22:06 UTC

svn commit: r529260 - in /harmony/enhanced/drlvm/trunk/vm: port/include/port_vmem.h port/src/vmem/linux/port_vmem.c vmcore/src/kernel_classes/native/org_apache_harmony_lang_management_MemoryMXBeanImpl.cpp

Author: gshimansky
Date: Mon Apr 16 07:22:05 2007
New Revision: 529260

URL: http://svn.apache.org/viewvc?view=rev&rev=529260
Log:
Applied 2nd patch in HARMONY-3427 [drlvm][lang-management] MemoryMXBean native methods implementation


Modified:
    harmony/enhanced/drlvm/trunk/vm/port/include/port_vmem.h
    harmony/enhanced/drlvm/trunk/vm/port/src/vmem/linux/port_vmem.c
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/org_apache_harmony_lang_management_MemoryMXBeanImpl.cpp

Modified: harmony/enhanced/drlvm/trunk/vm/port/include/port_vmem.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/port/include/port_vmem.h?view=diff&rev=529260&r1=529259&r2=529260
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/port/include/port_vmem.h (original)
+++ harmony/enhanced/drlvm/trunk/vm/port/include/port_vmem.h Mon Apr 16 07:22:05 2007
@@ -136,22 +136,26 @@
 APR_DECLARE(size_t *) port_vmem_page_sizes();
 
 /**
- * Returns the amount of currently used memory in bytes.
+ * Returns the amount of currently used memory in bytes
+ * or 0 if this value could not be calculated.
  */
 APR_DECLARE(size_t) port_vmem_used_size();
 
 /**
- * Returns the amount of committed memory in bytes.
+ * Returns the amount of committed memory in bytes
+ * or 0 if this value could not be calculated.
  */
 APR_DECLARE(size_t) port_vmem_committed_size();
 
 /**
- * Returns the amount of reserved memory in bytes.
+ * Returns the amount of reserved memory in bytes
+ * or 0 if this value could not be calculated.
  */
 APR_DECLARE(size_t) port_vmem_reserved_size();
 
 /**
- * Returns the maximum amount of memory which could be reserved in bytes.
+ * Returns the maximum amount of memory which could be reserved in bytes
+ * or 0 if this value could not be calculated
  */
 APR_DECLARE(size_t) port_vmem_max_size();
 

Modified: harmony/enhanced/drlvm/trunk/vm/port/src/vmem/linux/port_vmem.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/port/src/vmem/linux/port_vmem.c?view=diff&rev=529260&r1=529259&r2=529260
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/port/src/vmem/linux/port_vmem.c (original)
+++ harmony/enhanced/drlvm/trunk/vm/port/src/vmem/linux/port_vmem.c Mon Apr 16 07:22:05 2007
@@ -144,27 +144,43 @@
 }
 
 APR_DECLARE(size_t) port_vmem_committed_size(){
-    char buf[PATH_MAX];
+    char* buf = (char*) malloc(PATH_MAX + 1);
 
-    pid_t pid = getpid();
-    sprintf(buf, "/proc/%d/statm", pid);
-    FILE* file = fopen(buf, "rt");
+    pid_t my_pid = getpid();
+    sprintf(buf, "/proc/%d/statm", my_pid);
+    FILE* file = fopen(buf, "r");
     if (!file) {
-        return port_vmem_page_sizes()[0];
+        return 0;
+    }
+    size_t size = 0;
+    ssize_t len = getline(&buf, &size, file);
+    if (len == -1) {
+        return 0;
     }
     size_t vmem;
     int res = sscanf(buf, "%lu", &vmem);
+    if (res < 1) {
+        return 0;
+    }
+    if (buf) {
+        free(buf);
+    }
     return vmem * port_vmem_page_sizes()[0];
 }
 
 APR_DECLARE(size_t) port_vmem_max_size(){
-    char buf[PATH_MAX];
+    char* buf = (char*) malloc(PATH_MAX + 1);
 
-    pid_t mypid = getpid();
-    sprintf(buf, "/proc/%d/stat", mypid);
-    FILE* file = fopen(buf, "rt");
+    pid_t my_pid = getpid();
+    sprintf(buf, "/proc/%d/stat", my_pid);
+    FILE* file = fopen(buf, "r");
     if (!file) {
-        return UINT_MAX;
+        return 0;
+    }
+    size_t size = 0;
+    ssize_t len = getline(&buf, &size, file);
+    if (len == -1) {
+        return 0;
     }
     int pid, ppid, pgrp, session, tty_nr, tpgid, exit_signal, processor;
     char comm[PATH_MAX];
@@ -183,7 +199,7 @@
         &startcode, &endcode, &startstack, &kstkesp, &kstkeip, &signal, &blocked,
         &sigignore, &sigcatch, &wchan, &nswap, &cnswap, &exit_signal, &processor);
     if (res < 25) { // rlim position
-        return UINT_MAX;
+        return 0;
     };
     return rlim;
 }

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/org_apache_harmony_lang_management_MemoryMXBeanImpl.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/org_apache_harmony_lang_management_MemoryMXBeanImpl.cpp?view=diff&rev=529260&r1=529259&r2=529260
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/org_apache_harmony_lang_management_MemoryMXBeanImpl.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/org_apache_harmony_lang_management_MemoryMXBeanImpl.cpp Mon Apr 16 07:22:05 2007
@@ -117,19 +117,21 @@
         - ((JavaVM_Internal*)vm)->vm_env->init_gc_used_memory;
     if (init <= 0) {init = -1;}
 
-    jlong used = port_vmem_used_size() - gc_total_memory();
+    jlong used = port_vmem_used_size();
     if (used < init) {used = init;}
+    if (used == -1) {used = 0;}
 
-    jlong committed = port_vmem_committed_size() - gc_total_memory();
+    jlong committed = port_vmem_committed_size();
     if (committed < used) {committed = used;}
+    if (committed == -1) {committed = 0;}
 
-    jlong max = port_vmem_max_size() - gc_total_memory();
-    if (max < committed) {max = committed;}
+    jlong max = port_vmem_max_size();
+    if ((max < committed) && (max != -1)) {max = committed;}
 
     jclass memoryUsageClazz =jenv->FindClass("java/lang/management/MemoryUsage");
-    if (jenv->ExceptionCheck()) {return NULL;};
+    if (jenv->ExceptionCheck()) {return NULL;}
     jmethodID memoryUsageClazzConstructor = jenv->GetMethodID(memoryUsageClazz, "<init>", "(JJJJ)V");
-    if (jenv->ExceptionCheck()) {return NULL;};
+    if (jenv->ExceptionCheck()) {return NULL;}
 
     jobject memoryUsage = jenv->NewObject(memoryUsageClazz, memoryUsageClazzConstructor, init, used,
         committed, max);