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

JRuby never end when running this code #2550

Closed
kokizzu opened this issue Feb 2, 2015 · 2 comments
Closed

JRuby never end when running this code #2550

kokizzu opened this issue Feb 2, 2015 · 2 comments

Comments

@kokizzu
Copy link

kokizzu commented Feb 2, 2015

I'm trying to run this script:

##############################
# comb.rb
def newGap gap
    gap /= 1.3;
    gap = gap.to_i;
    return 11 if gap == 9 or gap == 10
    return 1 if gap < 1
    gap
end
def combSort a
    len = a.length
    gap = len
    swapped = false
    begin
        swapped = false
        gap = newGap gap
        (0...(len-gap)).each do |i|
            if a[i] > a[i+gap]
                swapped = true
                a[i], a[i+gap] = a[i+gap], a[i]
            end
        end
    end while gap > 1 or swapped
end
N = 10000000;
arr = (1..N).to_a.reverse!
combSort arr
(1...N).each do |z|
    print '!' if arr[z]<arr[z-1]
end

when using ruby 2.2.0 it works fine, done in less than a minute, rubinius too, less than two minutes, but when using JRuby, it never ends, I wait for about 5 minutes, but it still haven't done yet, and it uses all CPU cores. Is this JRuby's bug?

JRuby version: jruby 1.7.18 (1.9.3p551) 2014-12-22 625381c on OpenJDK 64-Bit Server VM 1.7.0_71-b14 +jit [linux-amd64] and jruby 9.0.0.0.pre1 (2.2.0p0) 2015-01-20 d537cab OpenJDK 64-Bit Server VM 24.65-b04 on 1.7.0_71-b14 +jit [linux-amd64]

@kokizzu kokizzu changed the title JRuby never end JRuby never end when running this code Feb 2, 2015
@kokizzu kokizzu closed this as completed Feb 2, 2015
@kokizzu kokizzu reopened this Feb 2, 2015
@dtamai
Copy link

dtamai commented Feb 9, 2015

I ran that code on jruby 9.0.0.0.pre1 (2.2.0p0) 2015-01-20 d537cab Java HotSpot(TM) 64-Bit Server VM 25.25-b02 on 1.8.0_25-b17 +jit [linux-amd64] and got an OutOfMemoryError, so I played with the Xmx argument and got the following results:

Memory (-J-Xmx<value>) Result
256m OutOfMemory in 25 seconds
500m (default) OutOfMemory in 45 seconds
768m 100% on all cores for 12 minutes then I aborted the program
1024m Done in 3 minutes

My guess is that it is too much memory for an OutOfMemoryError but too few to run.

Try changing the that JVM argument and see if something changes.

@enebo enebo added this to the Invalid or Duplicate milestone May 17, 2017
@enebo
Copy link
Member

enebo commented May 17, 2017

Resolving this. MRI runs this in 34s on my machine. JRuby runs it as 40s with default params and 33s with compile.invokedynamic. Whatever memory issue we had seems to no longer be an issue any more.

@enebo enebo closed this as completed May 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants