J2V8 icon indicating copy to clipboard operation
J2V8 copied to clipboard

JVM crash seemingly at random on 64-bit Windows

Open ccantill opened this issue 11 years ago • 19 comments

We're seeing random JVM crashes on 64-bit Windows when calling J2V8 methods. We only encounter them when running our main application, and have been unable to isolate the issue in a JUnit test. Crash logs are here: https://gist.github.com/ccantill/42826929a65576823920 and https://gist.github.com/ccantill/c9c9d70ece25eb69f3fe Any hints as to what could be causing this or how to avoid this issue would be most welcome.

ccantill avatar Sep 10 '15 15:09 ccantill

Third user with the same issue. Crash log: https://gist.github.com/ccantill/bbcb6e98f6f37df7a08f We have to revert to Nashorn if this persists, but that would entail an eight-fold performance decrease, so really looking forward to a fix for this.

ccantill avatar Sep 18 '15 09:09 ccantill

All the crash logs point to a problem in registerJavaMethod. This is responsible for registering a callback from JS to Java. Do you do this often in your code, or just a few up front? I've only done a few registrations up front, but maybe there is a problem with a large number of registered Java methods.

On Fri, Sep 18, 2015 at 2:49 AM, Christoph Cantillon < [email protected]> wrote:

Third user with the same issue. Crash log: https://gist.github.com/ccantill/bbcb6e98f6f37df7a08f We have to revert to Nashorn if this persists, but that would entail an eight-fold performance decrease, so really looking forward to a fix for this.

— Reply to this email directly or view it on GitHub https://github.com/eclipsesource/J2V8/issues/90#issuecomment-141406843.

R. Ian Bull | EclipseSource Victoria | +1 250 477 7484 http://eclipsesource.com | http://twitter.com/eclipsesource

irbull avatar Sep 18 '15 15:09 irbull

@ccantill Can you try something like this:

    public class Bar {
        public void foo() {

        }
    }

    @Test
    public void testLotsOfRegistration() {
        for (int i = 0; i < 10000000; i++) {
            Bar bar = new Bar();
            V8Object o = new V8Object(v8);
            o.registerJavaMethod(bar, "foo", "foo", new Class<?>[0]);
            o.release();
        }
    }

I'm running this on MacOS right now. Just seeing if lots of registrations work.

irbull avatar Sep 18 '15 16:09 irbull

I only call it three times for each run, and as it happens quite early it can't have been called a lot yet. I just use it to register the info, debug and warn methods of our logger instance. However, the logger is static, so it could be shared across threads. Could that be the issue here?

I'm on a Linux machine myself so I can't really test this, and everyone else has already left the office so I'll have a colleague run that test on Monday.

ccantill avatar Sep 18 '15 16:09 ccantill

Are you running with multiple V8 runtimes (and multiple threads)? Just looking at some hints on where to focus on work here.

On Fri, Sep 18, 2015 at 9:42 AM, Christoph Cantillon < [email protected]> wrote:

I only call it three times for each run, and as it happens quite early it can't have been called a lot yet. I just use it to register the info, debug and warn methods of our logger instance. However, the logger is static, so it could be shared across threads. Could that be the issue here?

I'm on a Linux machine myself so I can't really test this, and everyone else has already left the office so I'll have a colleague run that test on Monday.

— Reply to this email directly or view it on GitHub https://github.com/eclipsesource/J2V8/issues/90#issuecomment-141503921.

R. Ian Bull | EclipseSource Victoria | +1 250 477 7484 http://eclipsesource.com | http://twitter.com/eclipsesource

irbull avatar Sep 18 '15 16:09 irbull

I've managed to reproduce it with the following test case.

   public static class Bar {
        public Bar() {
            V8 v8 = new V8();
            v8.registerJavaMethod(this, "foo", "foo", new Class<?>[0]);
        }

        public static void foo() {

        }
    }

    @Test
    public void testLotsOfRegistration() {
        for (int i = 0; i < 10000; i++) {
            Bar bar = new Bar();
        }
    }

This fails on Win32_64. I will test this on MacOS as well.

irbull avatar Sep 18 '15 19:09 irbull

I think I've figured this out.

Turns out we were treating jlong and long as the same thing. jlong is the JNI type that represents a Java long. We would then cast this to a long to use in C++. We use the jlong / long to hold a pointer to the C++ data structure.

However, jlong and long are not the same and casting from a jlong to long and then to a pointer was not producing the correct result (in some cases).

I will put a point release together for this and update the bug report.

irbull avatar Sep 18 '15 23:09 irbull

The fix for this is at b60f8c29bf6e0de779e553fd3a2ccf05132675ff. I will push this to maven central for testing. Thanks for reporting this.

BTW, if you are using J2V8 for anything, please let me know. I'd love to update the list of people using J2V8 in the README.

irbull avatar Sep 18 '15 23:09 irbull

I've pushed a point release to Maven Central. The version is 3.0.2 and it contains the fix for this. Can you test this (and double check that you have the right jar file), and let me know if it works.

irbull avatar Sep 19 '15 05:09 irbull

Seems fine so far. Thanks for the quick help :) We'll continue testing throughout the day.

As to what we're using it for; at PearlChain.net we develop an ERP solution. One of the components is a highly configurable data grid that uses spreadsheet-like formula's which we calculate on the fly in the browser. It allows us to create real-time pricing grids, for example. To reuse the same calculation engine on the backend side we used to use Rhino and then Nashorn, but now with V8 it's about 8 times faster.

ccantill avatar Sep 21 '15 06:09 ccantill

Spoke too soon. It worked fine for several hours, and then it stopped working altogether even though there were no changes. I don't even get the crash report anymore now, just a Windows dialog telling me the process stopped working, but it happens as soon as the V8 bindings are hit. I even tried removing the calls to the registerJavaMethod (which were only used for logging anyway), so all I'm running then is JavaScript code with some data injected using V8Object.

Tried running the JUnit test you mentioned above, and got another crash log: https://gist.github.com/ccantill/fd2cc57a1f29492f1172 You'll see it already crashes trying to create the V8 instance.

ccantill avatar Sep 21 '15 15:09 ccantill

Are you disposing of the isolates? I can reproduce this if I create (and do not dispose) several thousand isolates. This could basically be an out of memory error.

On Mon, Sep 21, 2015 at 8:37 AM, Christoph Cantillon < [email protected]> wrote:

Spoke too soon. It worked fine for several hours, and then it stopped working altogether even though there were no changes. I don't even get the crash report anymore now, just a Windows dialog telling me the process stopped working, but it happens as soon as the V8 bindings are hit. I even tried removing the calls to the registerJavaMethod (which were only used for logging anyway), so all I'm running then is JavaScript code with some data injected using V8Object.

Tried running the JUnit test you mentioned above, and got another crash log: https://gist.github.com/ccantill/fd2cc57a1f29492f1172 You'll see it already crashes trying to create the V8 instance.

— Reply to this email directly or view it on GitHub https://github.com/eclipsesource/J2V8/issues/90#issuecomment-142017895.

R. Ian Bull | EclipseSource Victoria | +1 250 477 7484 http://eclipsesource.com | http://twitter.com/eclipsesource

irbull avatar Sep 21 '15 15:09 irbull

That makes sense. I added the release to the test case and it doesn't crash anymore. I was naively hoping garbage collection would take care of that. Not sure this is the same issue as what I'm seeing in the actual application though. I'll do some more testing tomorrow. Thanks for the help.

ccantill avatar Sep 21 '15 15:09 ccantill

No, because there is native resources (an instance of V8) created when you create the isolate, you need to release it. I didn't add the release to the test case because I wanted to see how many instances we could create. With 3.0.1 we could only create about 160 instances because after that it started to allocated V8 instances at higher memory addresses and the conversion from jlong to long was loosing these addresses. Now we can create a few thousand.

Also, depending on what you are doing, you don't need a new isolate each time. They are expensive to create, so reusing them may help with performance too.

On Mon, Sep 21, 2015 at 8:52 AM, Christoph Cantillon < [email protected]> wrote:

That makes sense. I added the release to the test case and it doesn't crash anymore. I was naively hoping garbage collection would take care of that. Not sure this is the same issue as what I'm seeing in the actual application though. I'll do some more testing tomorrow. Thanks for the help.

— Reply to this email directly or view it on GitHub https://github.com/eclipsesource/J2V8/issues/90#issuecomment-142024056.

R. Ian Bull | EclipseSource Victoria | +1 250 477 7484 http://eclipsesource.com | http://twitter.com/eclipsesource

irbull avatar Sep 21 '15 15:09 irbull

Yes, I should have though of that. Unfortunately the issue I'm seeing is not related to the releasing. I can reliably reproduce a crash in my application on the first V8 instance I create. Unfortunately, I'm unable to isolate it in a unit test, and I can't seem to get the debugger to work so I can't see on what line in the JS code it stops working. All I have is the crash info from the Windows Event Viewer, as the JVM doesn't even get to writing a crash log. Hoping this could be useful I posted it here: https://gist.github.com/ccantill/c1c008d824d289eca991

ccantill avatar Sep 22 '15 09:09 ccantill

After a lot of debugging I managed to reduce it to the following:

     V8 runtime = V8.createV8Runtime();
     runtime.executeScript("Math.pow(NaN, -1)");

I can only reproduce this on our AWS server running 64-bit Windows 2007 Server SP2. Tried it with multiple versions of the JRE (1.7.0_79, 1.8.0_60, 1.8.0_40) and they all give the same result. However, I can not reproduce it on my own Linux machine or on my colleagues Windows 7 laptop with any of those versions of the JRE.

ccantill avatar Sep 22 '15 14:09 ccantill

Just to be clear, this seems like an entirely different issue than the windows one, right? The first issue here was about memory access violations on windows, whereas this is about JS crashing on Linux? On Sep 22, 2015 7:02 AM, "Christoph Cantillon" [email protected] wrote:

After a lot of debugging I managed to reduce it to the following:

 V8 runtime = V8.createV8Runtime();
 runtime.executeScript("Math.pow(NaN, -1)");

I can only reproduce this on our AWS server running 64-bit Windows 2007 Server SP2. Tried it with multiple versions of the JRE (1.7.0_79, 1.8.0_60, 1.8.0_40) and they all give the same result. However, I can not reproduce it on my own Linux machine or on my colleagues Windows 7 laptop with any of those versions of the JRE.

— Reply to this email directly or view it on GitHub https://github.com/eclipsesource/J2V8/issues/90#issuecomment-142297877.

irbull avatar Sep 22 '15 14:09 irbull

Sorry, shouldn't try to read github issues on my phone. This also a windows (on aws) issue too. But not necessarily related to access violations. On Sep 22, 2015 7:30 AM, "Ian Bull" [email protected] wrote:

Just to be clear, this seems like an entirely different issue than the windows one, right? The first issue here was about memory access violations on windows, whereas this is about JS crashing on Linux? On Sep 22, 2015 7:02 AM, "Christoph Cantillon" [email protected] wrote:

After a lot of debugging I managed to reduce it to the following:

 V8 runtime = V8.createV8Runtime();
 runtime.executeScript("Math.pow(NaN, -1)");

I can only reproduce this on our AWS server running 64-bit Windows 2007 Server SP2. Tried it with multiple versions of the JRE (1.7.0_79, 1.8.0_60, 1.8.0_40) and they all give the same result. However, I can not reproduce it on my own Linux machine or on my colleagues Windows 7 laptop with any of those versions of the JRE.

— Reply to this email directly or view it on GitHub https://github.com/eclipsesource/J2V8/issues/90#issuecomment-142297877.

irbull avatar Sep 22 '15 14:09 irbull

Correct, probably not related to the original issue. I'll open a new ticket.

ccantill avatar Sep 22 '15 14:09 ccantill