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

loop allocates needless memory #2785

Closed
ecin opened this issue Mar 30, 2015 · 5 comments
Closed

loop allocates needless memory #2785

ecin opened this issue Mar 30, 2015 · 5 comments

Comments

@ecin
Copy link

ecin commented Mar 30, 2015

Version: jruby 1.7.19 (1.9.3p551) 2015-01-29 20786bd on Java HotSpot(TM) 64-Bit Server VM 1.7.0_72-b14 +jit [darwin-x86_64]

Also reproducible on Java 8 (1.8.0 b25-b17).

Using loop seems to allocate needless memory when compared to while true:

require "java"
require "jruby"

thread = Thread.new { loop { } }
native_thread = JRuby.reference(thread).native_thread

thread_bean = java.lang.management.ManagementFactory.thread_mx_bean
loop { puts thread_bean.get_thread_allocated_bytes([native_thread.id].to_java(:long))[0]; sleep 1 }
# outputs ever increasing number

Thread.new { while true; end } does not cause the same unexpected memory allocation.

@headius
Copy link
Member

headius commented Apr 2, 2015

Both JRuby 1.7 and 9k do have some allocation for every block invocation, usually to box arguments into an array used by our block argument logic to assign local variables. However, this particular case seems like it shouldn't need to allocate anything; the block is created once, and it receives no arguments.

@headius
Copy link
Member

headius commented Apr 2, 2015

Hmm...I am confused. I do not see this allocation happening when I run your script with JRuby 1.7.19 and 9k (master):

[] ~/projects/jruby $ jruby -v blah.rb
jruby 9.0.0.0-SNAPSHOT (2.2.1) 2015-03-30 31451d2 Java HotSpot(TM) 64-Bit Server VM 25.40-b23 on 1.8.0_40-ea-b19 +jit [darwin-x86_64]
18032
21272
21272
21272
21272
21272
21272
21272
21272
21272
^C
[] ~/projects/jruby $ rvm jruby-1.7.19 do jruby -v blah.rb
jruby 1.7.19 (1.9.3p551) 2015-01-29 20786bd on Java HotSpot(TM) 64-Bit Server VM 1.8.0_40-ea-b19 +jit [darwin-x86_64]
38968
41744
41744
41744
41744
41744
41744
41744
41744
41744
^C

We need from you:

  • Your results from running this script
  • Do a run with -J-Xrunhprof:depth=0 (JVM flag for profiling allocations). You'll get a file called java.hprof.txt whenever you Control-C the process. At the bottom is a histogram of allocated objects; look for the top 10-20 lines and report them to us.

@headius
Copy link
Member

headius commented Apr 2, 2015

You may also be running this in the interpreter. Do you have the --dev flag or -X-C flag set for your JRuby runs?

@nirvdrum
Copy link
Contributor

@ecin Any update?

@headius
Copy link
Member

headius commented Apr 17, 2015

Closing because I don't believe this is really an issue and the reporter seems to have gone away.

@headius headius closed this as completed Apr 17, 2015
@enebo enebo added this to the Invalid or Duplicate milestone Apr 28, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants