Author: rhuijben
Date: Fri Aug  5 08:07:41 2011
New Revision: 1154115

URL: http://svn.apache.org/viewvc?rev=1154115&view=rev
Log:
In JavaHL: Be a better JVM citizen by not changing global locale state that
applies to all java code and by returning apr allocated memory back to the
OS (or in this case the JVM and other modules).

This change should considerably reduce the amount of memory used by Subclipse
after operations like merging.
(This same problem made easly AnkhSVN 2.0 versions unusable for many users,
 but nobody told us as it was hard to diagnose...)

* subversion/bindings/javahl/native/JNIUtil.cpp
  (JNIUtil::JNIGlobalInit): Don't change the C locale as that should be managed
    by the JVM instead of individual modules.
    (If everybody changes that setting, no module will work as expected...)

    Set the max free count of the global allocator.
    And use a subpool in a bit of Win32 code.

Modified:
    subversion/trunk/subversion/bindings/javahl/native/JNIUtil.cpp

Modified: subversion/trunk/subversion/bindings/javahl/native/JNIUtil.cpp
URL: 
http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/javahl/native/JNIUtil.cpp?rev=1154115&r1=1154114&r2=1154115&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/javahl/native/JNIUtil.cpp (original)
+++ subversion/trunk/subversion/bindings/javahl/native/JNIUtil.cpp Fri Aug  5 
08:07:41 2011
@@ -127,39 +127,7 @@ bool JNIUtil::JNIGlobalInit(JNIEnv *env)
 
   apr_status_t status;
 
-  /* C programs default to the "C" locale. But because svn is supposed
-     to be i18n-aware, it should inherit the default locale of its
-     environment.  */
-  if (!setlocale(LC_ALL, ""))
-    {
-      if (stderr)
-        {
-          const char *env_vars[] = { "LC_ALL", "LC_CTYPE", "LANG", NULL };
-          const char **env_var = &env_vars[0], *env_val = NULL;
-          while (*env_var)
-            {
-              env_val = getenv(*env_var);
-              if (env_val && env_val[0])
-                break;
-              ++env_var;
-            }
-
-          if (!*env_var)
-            {
-              /* Unlikely. Can setlocale fail if no env vars are set? */
-              --env_var;
-              env_val = "not set";
-            }
 
-          fprintf(stderr,
-                  "%s: error: cannot set LC_ALL locale\n"
-                  "%s: error: environment variable %s is %s\n"
-                  "%s: error: please check that your locale name is "
-                  "correct\n",
-                  "svnjavahl", "svnjavahl", *env_var, env_val, "svnjavahl");
-        }
-      return FALSE;
-    }
 
   /* Initialize the APR subsystem, and register an atexit() function
    * to Uninitialize that subsystem at program exit. */
@@ -196,6 +164,19 @@ bool JNIUtil::JNIGlobalInit(JNIEnv *env)
       return FALSE;
     }
 
+  /* Create our top-level pool. */
+  g_pool = svn_pool_create(NULL);
+
+  apr_allocator_t* allocator = apr_pool_allocator_get(g_pool);
+
+  if (allocator)
+    {
+      /* Keep a maximum of 1 free block, to release memory back to the JVM
+         (and other modules). */
+      apr_allocator_max_free_set(allocator, 1);
+    }
+
+
 #ifdef ENABLE_NLS
 #ifdef WIN32
   {
@@ -207,7 +188,7 @@ bool JNIUtil::JNIGlobalInit(JNIEnv *env)
     apr_size_t inwords, outbytes;
     unsigned int outlength;
 
-    apr_pool_create(&pool, 0);
+    pool = svn_pool_create(g_pool);
     /* get dll name - our locale info will be in '../share/locale' */
     inwords = sizeof(ucs2_path) / sizeof(ucs2_path[0]);
     HINSTANCE moduleHandle = GetModuleHandle("libsvnjavahl-1");
@@ -232,16 +213,13 @@ bool JNIUtil::JNIGlobalInit(JNIEnv *env)
     internal_path = svn_dirent_join(internal_path, SVN_LOCALE_RELATIVE_PATH,
                                   pool);
     bindtextdomain(PACKAGE_NAME, internal_path);
-    apr_pool_destroy(pool);
+    svn_pool_destroy(pool);
   }
 #else
   bindtextdomain(PACKAGE_NAME, SVN_LOCALE_DIR);
 #endif
 #endif
 
-  /* Create our top-level pool. */
-  g_pool = svn_pool_create(NULL);
-
 #if defined(WIN32) || defined(__CYGWIN__)
   /* See 
http://svn.apache.org/repos/asf/subversion/trunk/notes/asp-dot-net-hack.txt */
   /* ### This code really only needs to be invoked by consumers of


Reply via email to