Opened 14 years ago

Closed 13 years ago

Last modified 13 years ago

#3491 closed defect (fixed)

Mapserver crashes: Windows 2008; Java; 64 Bit

Reported by: bene Owned by: tamas
Priority: normal Milestone:
Component: MapScript-Java Version: unspecified
Severity: normal Keywords:
Cc: tamas

Description

I want to use Mapserver in TomCat6; Windows 2008; 64 Bit; Sun-Java 1.6..21 Mapserver compiled by Tamas Szekeres: release-1500-x64-gdal-1-7-mapserver-5-6.zip (vbkto.dyndns.org/sdk/Default.aspx )

Unfortunately the Java-VM crashes!

To reduce the problem I tried example-programs in <UMN>\mapscript\java\examples\

As far as I can see, the crash occurs every time, when a string-parameter ist provided to the Mapserver API. I think, that the VM-crash occurs, when the function "JNU_GetStringNativeChars(jenv, jarg1)" from mapscript_wrap.c is called.

Surprinsingly the error occurs with other  release-XXX-packages from Tamas too.

It even occurs, when I use a 32-Bit-Environment an MS4w on this computer.

I attach an hs_err_pid-xxxx.log-File.

Does anybody have any advice?

Attachments (2)

release-1500-x64-gdal-1-7-mapserver-5-6.log (10.5 KB ) - added by bene 14 years ago.
javamodule.i (5.7 KB ) - added by bene 14 years ago.
Patched javamodule.i

Download all attachments as: .zip

Change History (14)

comment:1 by tamas, 14 years ago

Cc: tamas added; szekerest@… removed

comment:2 by bene, 14 years ago

I think, I got it.

When a java-string-parameter is provided to Mapserver it will be converted to a char* with JNU_GetStringNativeChars. This function allocates the memory with malloc.

This char* will be freed at the end of each function with ReleaseStringUTFChars. But the counterpart of malloc should be free.

Sine I'm not familiar with swig I patched only one function (Java_edu_umn_gis_mapscript_mapscriptJNI_new_1mapObj). After this the crash didn't occure in this function anymore. (Unfortunately it still occured in the next function-call with a string-parameter).

Sorry. I a quick solution for this. Can anyone give advise how to proceed?

comment:3 by bene, 14 years ago

Less important and maybe only a theoretical problem:

Take Java_edu_umn_gis_mapscript_mapscriptJNI_new_1mapObj for example.

In the beginning:

char *arg1 = (char *) "" ;

At the end:

if (arg1)   dealloc(arg1)

In the case that arg1 is not given any value inside the function the constant String "" will be freed.

in reply to:  2 comment:4 by unicoletti, 14 years ago

Replying to bene:

I think, I got it.

When a java-string-parameter is provided to Mapserver it will be converted to a char* with JNU_GetStringNativeChars. This function allocates the memory with malloc.

This char* will be freed at the end of each function with ReleaseStringUTFChars. But the counterpart of malloc should be free.

Sine I'm not familiar with swig I patched only one function (Java_edu_umn_gis_mapscript_mapscriptJNI_new_1mapObj). After this the crash didn't occure in this function anymore. (Unfortunately it still occured in the next function-call with a string-parameter).

Hi Benedict, Could you post the exact changes that you made?

Thanks, Umberto

Sorry. I a quick solution for this. Can anyone give advise how to proceed?

comment:5 by bene, 14 years ago

Hi Umberto

I changed mapscript_wrap.c directly. Lines of the form

  if (arg1) (*jenv)->ReleaseStringUTFChars(jenv, jarg1, (const char *)arg1);

are now

  if  (arg1) free  (arg1) ;

Unfortunately I am overextended to make the proper changes in swig. I hope you can ...

As far as I can see, this bug was introduced when fixing #1753. Before this bugfix the C-String was allocated by the JVM (GetStringUTFChars), wasn't it? The discussion in http://www.velocityreviews.com/forums/t144581-crash-while-calling-releasestringutfchars-for-newstringutf-string.html shows a slightly different but comparable problem.

Btw: I should stress, that the need for a quick solution isn't there anymore. I patched all these lines with an awk-script. Works for me and the moment now...

{
  if ($0 ~ /ReleaseStringUTFChars/) {
    print "if ", $2, "free ", $2 ,";";
  }
  else {
    print $0;
  }
}

comment:6 by unicoletti, 14 years ago

Status: newassigned

This

http://www.java-forums.org/advanced-java/29484-exception_access_violation-windows-7-64-bit-os.html

seems to confirm your diagnosis. A more thorough solution probably requires rewriting the JNU_GetStringNativeChars method in javamodule.i

If you can apply patches, recompile and test for me I'll send you a patch as soon as I can work on it.

in reply to:  6 comment:7 by bene, 14 years ago

Replying to unicoletti:

The link you've provided is about exactly the same problem...

A more thorough solution probably requires rewriting the JNU_GetStringNativeChars method in javamodule.i

Uuh. I hope the benefits of #1753 won't be imperiled. Isn't it possible to change the deallocation instead? Seems less hazzardous to me...

If you can apply patches, recompile and test for me I'll send you a patch as soon as I can work on it.

Sorry. From Monday (July 19) on I'll be in hollidays for soem weeks. No work in http://maps.google.com/maps?q=antibes&ie=UTF8&hq=&hnear=Antibes,+Seealpen,+Provence-Alpes-C%C3%B4te+d'Azur,+Frankreich&ei=6Bg_TLWAHMmAOMCZwJsH&ved=0CCwQ8gEwAA&z=12

comment:8 by bene, 14 years ago

Hi Umberto

I had a look on swig and how it works. I didn't really understand the codegenerator but I could change it :-)

Add the line

%typemap(freearg, noblock=1) char * { if ($1) free ($1); }

to mapserver\mapscript\java\javamodule.i

To be unambiguous I attach javamodule.i.

by bene, 14 years ago

Attachment: javamodule.i added

Patched javamodule.i

comment:9 by bene, 14 years ago

Sorry, : Does anybody still take care of this one?

Although I found a patch for me: I'd really like to be able to work with a regular mapserver-distribution. So I'm interested to find a solution in a regular mapserver-release...

in reply to:  9 comment:10 by tamas, 13 years ago

Owner: changed from unicoletti to tamas
Status: assignednew

Replying to bene:

Sorry, : Does anybody still take care of this one?

I've now committed the changes in SVN trunk, branch-5-6 and branch-5-4 with the following changesets.

r10660, r10661, r10662, r10663

Thank you for discovering the solution. It appears to be the same problem I've already run into with the x64 java tests in http://vbkto.dyndns.org/sdk and I had to suppress the java tests in the x64 builds. This change will allow to bring these tests alive again.

comment:11 by tamas, 13 years ago

Resolution: fixed
Status: newclosed

comment:12 by bene, 13 years ago

Thank you

Note: See TracTickets for help on using tickets.