Michael Goffioul <michael.goffi...@gmail.com> writes:

> On Wed, Jun 20, 2012 at 7:17 AM, Sébastien Villemot 
> <sebastien.ville...@ens.fr> wrote:
>
>     Still I’m clueless about what’s corrupting the memory under OpenJDK
>     7. The valgrind log does not differ from the one that I obtain under
>     OpenJDK 6. JWE has kindly volunteered to help, maybe there is some hope
>     :)
>
> I've recompiled octave dev branch on my F16 (x86_64) box. I've also
> added the java and io package. Simple tests of the java package work
> fine (like "l = java_new('java.util.ArrayList'); l.add(10); l.toString
> ();"). This is done
> using java-1.7.0-openjdk-1.7.0.3-2.2.1.fc16.7.x86_64
>
> Running octave within valgrind shows a bunch of invalid writes when
> loading the JVM, but I the same bunch of messages when running java
> alone, so I don't think these are relevant (given the fact that JVM
> manages its own memory space, I'm not that surprized).
>
> If you could provide and example of how to reproduce your issue, I
> could give it a try here.

I have solved this issue. It was not a memory corruption problem but a
locale settings corruption.

What happens is that OpenJDK 7 changes the locale settings and, in
locale environments where the decimal separator is a comma and not a
point, that makes Octave crash when reading a decimal number (as simple
as "0.1").

The solution is to restore the locale settings after initializing the
JVM. I attach the patch that will be incorporated into the Debian
package. You will probably want to adapt it to make it portable to
non-POSIX systems.

Thanks for your help,
Description: Restore the locale after initializing the JVM
 OpenJDK 7 messes up the locale settings (and LC_NUMERIC in particular), so
 Octave is no longer able to read a decimal number in locales for which the
 decimal separator is a comma instead of a point.
Author: Sébastien Villemot <sebastien.ville...@ens.fr>
Bug-Debian: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=676800
Forwarded: no
Last-Update: 2012-07-08
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
--- a/src/__java__.cc
+++ b/src/__java__.cc
@@ -34,6 +34,8 @@
 #include <iostream>
 #include <fstream>
 
+#include <clocale>
+
 typedef jint (JNICALL *JNI_CreateJavaVM_t) (JavaVM **pvm, JNIEnv **penv, void *args);
 typedef jint (JNICALL *JNI_GetCreatedJavaVMs_t) (JavaVM **pvm, jsize bufLen, jsize *nVMs);
 
@@ -385,6 +387,9 @@
 
   if (jvm) return;
 
+  const char *static_locale = setlocale(LC_ALL, NULL);
+  const std::string locale(static_locale);
+
 #if defined (__WIN32__)
 
   HMODULE hMod = GetModuleHandle("jvm.dll");
@@ -534,6 +539,8 @@
   }
 
 #endif
+
+  setlocale(LC_ALL, locale.c_str());
 }
 
 static void terminate_jvm(void)
-- 
Sébastien Villemot
Researcher in Economics & Debian Maintainer
http://www.dynare.org/sebastien
Phone: +33-1-40-77-84-04 - GPG Key: 4096R/381A7594

Attachment: pgp1bjb5FoHCJ.pgp
Description: PGP signature

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Octave-dev mailing list
Octave-dev@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/octave-dev

Reply via email to