0

We have a piece of JNI code that lets us link to a legacy C library. The Java app references the C dll/so to call the c methods which create a new Java object with loads of Integers, Longs and Strings and then passes back this object to the Java code. The Java code tries to print these values that it received back from C and randomly crashes at different points in the code. When we run this in Linux it runs with no problems but in Windows it intermittently crashes with:

# A fatal error has been detected by the Java Runtime Environment:
#
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x77e11ed7, pid=893220, 
   tid=887676
#
# JRE version: Java(TM) SE Runtime Environment (8.0_05-b13) (build 1.8.0_05- b13)
# Java VM: Java HotSpot(TM) Client VM (25.5-b02 mixed mode, sharing windows-x86 )
# Problematic frame:
# C  [msvcr100.dll+0x1ed7]
#
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows

I would try to blame it on the god mode shortcut -> Fatal error crashing on latest version of Java on Windows 10 machine

But it only happens with some bits of code and not the others... so it's definitely some thing up how the jni bit was done C side.

halfer
  • 19,824
  • 17
  • 99
  • 186
Javadee
  • 139
  • 10
  • 1
    *When we run this in linux it runs with no problems but in windows it intermittently crashes* Sounds like a perfect description of user-written code that corrupts memory. – Andrew Henle Oct 29 '18 at 12:25
  • The problem is in your C code. Start by looking for uninitialized variables. – mnistic Oct 29 '18 at 12:32
  • 1
    Do you guys know why it crashes in windows but not in linux? – Javadee Oct 29 '18 at 12:54
  • 1
    Undefined behavior manifests differently with different compilers on different OSs. How do you compile your C code on Windows? – mnistic Oct 29 '18 at 13:08
  • 1
    visual studio(dev env) – Javadee Oct 29 '18 at 13:45
  • My experience with this is that GCC was zeroing out uninitialized objects when MSVC wasn't. Obviously your problem could be anything but I would start with that because it's easiest to check. – mnistic Oct 29 '18 at 14:29

2 Answers2

0

Looks like some kind of null pointer problem since the access occurred close to 0 (0xc0000005). Since it is not exactly null there might be some wrongly coded pointer arithmetic in your C code.

TomWolk
  • 968
  • 10
  • 13
0

After a lot of debugging the issue was resolved by changing couple of java inner classes to static. These inner classes were being referenced from the C code.

public class MyClass{
   // public class MyInnerClass{}
   // was changed to 
   public static class MyInnerClass{}
}

Obviously all the jni references from C were also changed to reflect that. Still not sure why but the issue is resolved now.

Javadee
  • 139
  • 10