Ticket #3491 (closed defect: fixed)

Opened 3 years ago

Last modified 3 years ago

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 TomCat?6; 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\ - MakePoint? runs without error. - QueryByAttribute? results in the same crash as the "big-tomcat-environment" does.

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

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

Change History

Changed 3 years ago by bene

  Changed 3 years ago by tamas

  • cc tamas added; szekerest@… removed

follow-up: ↓ 4   Changed 3 years ago by 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).

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

  Changed 3 years ago by bene

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   Changed 3 years ago by unicoletti

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?

  Changed 3 years ago by bene

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;
  }
}

follow-up: ↓ 7   Changed 3 years ago by unicoletti

  • status changed from new to assigned

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   Changed 3 years ago by bene

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

  Changed 3 years ago by bene

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.

Changed 3 years ago by bene

Patched javamodule.i

follow-up: ↓ 10   Changed 3 years ago by bene

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   Changed 3 years ago by tamas

  • owner changed from unicoletti to tamas
  • status changed from assigned to new

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.

  Changed 3 years ago by tamas

  • status changed from new to closed
  • resolution set to fixed

  Changed 3 years ago by bene

Thank you

Note: See TracTickets for help on using tickets.