Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JVM crashes with EXCEPTION_ACCESS_VIOLATION #2091

Closed
clo-vis opened this issue Jul 3, 2020 · 10 comments
Closed

JVM crashes with EXCEPTION_ACCESS_VIOLATION #2091

clo-vis opened this issue Jul 3, 2020 · 10 comments
Assignees
Labels
Bug Lang: Java Java wrapper issue OS: Windows Windows OS Solver: Routing Uses the Routing library and the original CP solver
Milestone

Comments

@clo-vis
Copy link

clo-vis commented Jul 3, 2020

What version of OR-tools and what language are you using?
Version: or-tools_VisualStudio2019-64bit_v7.6.7691
Language: Java

Which solver are you using
Routing Solver

What operating system and version?
Microsoft Windows [Version 10.0.16299.1932]

What did you do?
I put the method main of the example TspCities.java in an infinite loop; that is, in that example, I changed
public static void main(String[] args) throws Exception { … }
to
public static void _main(String[] args) throws Exception { … }
and added
public static void main(String[] args) throws Exception { while(true) _main(args); }

What did you expect to see
I expected to see no crash in the JVM

What did you see instead?
The JVM crashed after a few seconds with

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x00007ffa50da9b2a, pid=8984, tid=11524
#
# JRE version: OpenJDK Runtime Environment (14.0.1+7) (build 14.0.1+7)
# Java VM: OpenJDK 64-Bit Server VM (14.0.1+7, mixed mode, sharing, tiered, compressed oops, g1 gc, windows-amd64)
# Problematic frame:
# V  [jvm.dll+0x349b2a]
#
# No core dump will be written. Minidumps are not enabled by default on client versions of Windows
@Mizux Mizux added Bug Lang: Java Java wrapper issue OS: Windows Windows OS Solver: Routing Uses the Routing library and the original CP solver labels Jul 3, 2020
@Mizux Mizux added this to the v7.8 milestone Jul 3, 2020
@Mizux
Copy link
Collaborator

Mizux commented Jul 3, 2020

First we should test using the C++ sample, i'm pretty sure the leak comes from the SWIG wrapper...

@Mizux
Copy link
Collaborator

Mizux commented Jul 3, 2020

Coud you try to call the garbage collector between each iteration ?
e.g.

note/ AFAIK this test always fails (90%) on windows CI...

@clo-vis
Copy link
Author

clo-vis commented Jul 3, 2020

If the garbage collector is called after each solution is computed, the JVM does not crash (or, at least, it doesn't crash right after a few seconds). That's what I do now as workaround. For the example above:

public static void main(String[] args) throws Exception {
        while (true) {  _main(args); System.gc(); }
}

By invoking the garbage collector after a couple of solutions are computed, the JVM takes longer to crash, but it crashes eventually.

public static void main(String[] args) throws Exception {
        int i = 0;
        while (true) { _main(args); if (++i % 8 == 0) System.gc(); }
}

@clo-vis
Copy link
Author

clo-vis commented Jul 3, 2020

Another workaround, which is faster, reliable, and works as long as you have enough memory, is storing the reference to all RoutingModel instances created in a static (global) variable:

private static final List<RoutingModel> workaround = new ArrayList<>();

public static void _main(String[] args) throws Exception {
…
    RoutingModel routing = new RoutingModel(manager);
    workaround.add(routing);
…
}

That is, preventing RoutingModel from bein garbage collected also prevents the JVM from crashing.

@HugoSart
Copy link

HugoSart commented Jul 23, 2020

I'm having the same issue. Any updates on this?
Unfortunately, I cannot use the workarounds above due to performance issues.

JVM crash log here: https://pastebin.com/1VJCsa1F

EDIT: I also tested on Debian and Alpine and the problem persists.

@Mizux Mizux modified the milestones: v7.8, v7.9 Jul 24, 2020
@Mizux Mizux self-assigned this Jul 24, 2020
@clo-vis
Copy link
Author

clo-vis commented Aug 3, 2020

That is, preventing RoutingModel from bein garbage collected also prevents the JVM from crashing.

No, sooner or later the JVM crashes, no matter which workaround is used.

@Mizux
Copy link
Collaborator

Mizux commented Aug 4, 2020

IIRC java swig wrapper may use globals to store reference to callback, need to check if it can cause a leak or a double free error causing the JVM to crash, I'll try to investigate it...

note: Usually we only instantiate one routing model, solve it, send/display/save result then close the program, i.e. we spawn one program per instance to solve -> need to add some tests and debug how well a server/daemon in Java is stable.

@Mizux Mizux modified the milestones: v8.0, v8.1 Sep 29, 2020
@Mizux Mizux modified the milestones: v8.1, v8.0 Oct 1, 2020
@Mizux Mizux modified the milestones: v8.0, v8.1 Oct 11, 2020
@Mizux Mizux modified the milestones: v8.1, v8.2 Nov 24, 2020
@Mizux Mizux modified the milestones: v8.2, v8.3 Feb 10, 2021
@Mizux Mizux modified the milestones: v9.0, v9.1 Mar 22, 2021
@Mizux Mizux modified the milestones: v9.1, v9.2 Aug 9, 2021
@Mizux Mizux modified the milestones: v9.2, v9.1 Sep 10, 2021
@Mizux
Copy link
Collaborator

Mizux commented Sep 10, 2021

Should be fixed on master see:

@Mizux Mizux closed this as completed Sep 10, 2021
@JavierPelegrin
Copy link

It still crashes, i try to run the first example of CP_SAT (https://developers.google.com/optimization/cp/cp_example) and it still crashed.

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x00007ff9a2eb2c10, pid=5812, tid=1700
#
# JRE version: OpenJDK Runtime Environment (18.0.1.1+2) (build 18.0.1.1+2-6)
# Java VM: OpenJDK 64-Bit Server VM (18.0.1.1+2-6, mixed mode, sharing, tiered, compressed oops, compressed class ptrs, g1 gc, windows-amd64)
# Problematic frame:
# C  [msvcp140.dll+0x12c10]
#
# No core dump will be written. Minidumps are not enabled by default on client versions of Windows
#
# An error report file with more information is saved as:
# C:\Users\jpelegri\Documents\maps-algo\maps-algo-planning-constraint\hs_err_pid5812.log
#
# If you would like to submit a bug report, please visit:
#   https://bugreport.java.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#

@ChrisMLikesMath
Copy link

I see a similar error running the same CP_SAT example file. I get as far as

Starting serach at 0.01s with 12 workers
...
3 helper subsolvers...

Then
# A fatal error has been detected by the JRE
# EXEPTION_ACCESSS_VIOLATION...
# Problematic frame:
# C [MSVCP140.dll...
Using openJDK Corettor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Lang: Java Java wrapper issue OS: Windows Windows OS Solver: Routing Uses the Routing library and the original CP solver
Projects
None yet
Development

No branches or pull requests

5 participants