Is ObjectSpace still disabled in jruby 9.1.5.0 (2.3.1)?
If it's not just my installation (Arch Linux, up-to-date) having a bug, I get the suspicion that ObjectSpace has changed in recent jruby: Trying to reproduce the behaviour described in jruby's wiki entry about performance, I get the following reaction:
$> jruby -O
jruby: unknown option -O
$> jruby -J-Djruby.objectspace.enabled=false
puts ObjectSpace.each_object(Class).inspect
#<Enumerator: ObjectSpace:each_object(Class)>
$> jruby -v
jruby 9.1.5.0 (2.3.1) 2016-09-07 036ce39 Java HotSpot(TM) 64-Bit Server VM 25.102-b14 on 1.8.0_102-b14 +jit [linux-x86_64]
So what is the up-to-date situation? Is it now safe / recommended to use OpenSpace in modern jruby?
it hasn't changed - is the same as in previous JRuby (1.7.x)
ObjectSpace (even while disabled) works for meta-classes ... it is used by Rails and is easy to implement in JRuby without the performance cost.
Related
Based on this page on the JRuby wiki and other resources I see the recommendation is
to always use jruby -S.
because
The -S parameter tells JRuby to use its version of the installed binary, as opposed to some other version (such as an MRI version) that might be on your PATH.
Using rbenv and rvm I've had issues when using -S with JRuby (see this question) and my understanding is that both those version managers solve the problem -S attempts to address.
You do not need to run the gem command with jruby -S gem if you are using a Ruby manager such as rbenv or rvm. Those tools manage your command path for you so that the correct Ruby runtime and the correct version of rubygems are used. Similar applies to the rake.
Per http://jruby.org/2014/01/09/jruby-1-7-10.html, the subject problem is supposed to be fixed in 1.7.10 via https://github.com/jruby/jruby/pull/1252. However, my experience is otherwise, per:
MacbookAir1:javlats palfvin$ jruby -v
jruby 1.7.10 (2.0.0p195) 2014-01-09 c4ecd6b on Java HotSpot(TM) 64-Bit Server VM 1.6.0_65-b14-462-11M4609 [darwin-x86_64]
MacbookAir1:javlats palfvin$ jruby
(1..2).size
NoMethodError: undefined method `size' for 1..2:Range
(root) at -:1
MacbookAir1:javlats palfvin$
I haven't figured out how to look at the Java code in an installed JRuby version, so I wasn't able to compare the installed Java source code to the version on github, but this seems so basic it's hard to believe there's anything in my environment that is messing it up. I Googled to see if anyone else had encountered this, but didn't find anything.
Any ideas?
If my git-fu is right, I don't think this commit was included in 1.7.10. Indeed, it looks to only be in master:
$ git show -s --oneline 01be8f85522e4da8df3968e622fa2c947ea6712c
01be8f8 Add a size method to RubyRange to resolve #1252
$ git branch -r --contains 01be8f85522e4da8df3968e622fa2c947ea6712c
upstream/master
upstream/unbox_opts
$ git tag --contains 01be8f85522e4da8df3968e622fa2c947ea6712c
Perhaps there was a confusing merge somewhere in JRuby land?
I did a fresh install of jruby 1.6.2, and then wanted to install some gems.
I ran this command:
jruby -S gem install cucumber
And got this error message:
JRuby limited openssl loaded. http://jruby.org/openssl
gem install jruby-openssl for full support.
LoadError: OpenSSL::SSL requires the jruby-openssl gem
(root) at /Users/Staffr02/Development/jruby-1.6.2/lib/ruby/site_ruby/shared/jruby/openssl/autoloads/ssl.rb:8
use_ssl= at /Users/Staffr02/Development/jruby-1.6.2/lib/ruby/site_ruby/shared/jruby/openssl/autoloads/ssl.rb:124
connection_for at /Users/Staffr02/Development/jruby-1.6.2/lib/ruby/site_ruby/1.8/rubygems/remote_fetcher.rb:267
request at /Users/Staffr02/Development/jruby-1.6.2/lib/ruby/site_ruby/1.8/rubygems/remote_fetcher.rb:349
open_uri_or_path at /Users/Staffr02/Development/jruby-1.6.2/lib/ruby/site_ruby/1.8/rubygems/remote_fetcher.rb:306
fetch_path at /Users/Staffr02/Development/jruby-1.6.2/lib/ruby/site_ruby/1.8/rubygems/remote_fetcher.rb:181
load_specs at /Users/Staffr02/Development/jruby-1.6.2/lib/ruby/site_ruby/1.8/rubygems/spec_fetcher.rb:251
load_specs at /Users/Staffr02/Development/jruby-1.6.2/lib/ruby/site_ruby/1.8/rubygems/maven_gemify.rb:72
list at /Users/Staffr02/Development/jruby-1.6.2/lib/ruby/site_ruby/1.8/rubygems/spec_fetcher.rb:224
each at org/jruby/RubyArray.java:1602
list at /Users/Staffr02/Development/jruby-1.6.2/lib/ruby/site_ruby/1.8/rubygems/spec_fetcher.rb:220
list at /Users/Staffr02/Development/jruby-1.6.2/lib/ruby/site_ruby/1.8/rubygems/maven_gemify.rb:63
find_matching_with_errors at /Users/Staffr02/Development/jruby-1.6.2/lib/ruby/site_ruby/1.8/rubygems/spec_fetcher.rb:143
find_matching_with_errors at /Users/Staffr02/Development/jruby-1.6.2/lib/ruby/site_ruby/1.8/rubygems/maven_gemify.rb:54
fetch_with_errors at /Users/Staffr02/Development/jruby-1.6.2/lib/ruby/site_ruby/1.8/rubygems/spec_fetcher.rb:83
find_gems_with_sources at /Users/Staffr02/Development/jruby-1.6.2/lib/ruby/site_ruby/1.8/rubygems/dependency_installer.rb:108
find_spec_by_name_and_version at /Users/Staffr02/Development/jruby-1.6.2/lib/ruby/site_ruby/1.8/rubygems/dependency_installer.rb:212
install at /Users/Staffr02/Development/jruby-1.6.2/lib/ruby/site_ruby/1.8/rubygems/dependency_installer.rb:244
execute at /Users/Staffr02/Development/jruby-1.6.2/lib/ruby/site_ruby/1.8/rubygems/commands/install_command.rb:120
each at org/jruby/RubyArray.java:1602
execute at /Users/Staffr02/Development/jruby-1.6.2/lib/ruby/site_ruby/1.8/rubygems/commands/install_command.rb:115
invoke at /Users/Staffr02/Development/jruby-1.6.2/lib/ruby/site_ruby/1.8/rubygems/command.rb:278
process_args at /Users/Staffr02/Development/jruby-1.6.2/lib/ruby/site_ruby/1.8/rubygems/command_manager.rb:133
run at /Users/Staffr02/Development/jruby-1.6.2/lib/ruby/site_ruby/1.8/rubygems/command_manager.rb:103
run at /Users/Staffr02/Development/jruby-1.6.2/lib/ruby/site_ruby/1.8/rubygems/gem_runner.rb:63
(root) at /Users/Staffr02/Development/jruby-1.6.2/bin/gem:21
So then I tried this:
jruby -S gem install jruby-openssl
And I got the same error, which seemed a little odd. I'm running Mac OS 10.6.6.
I did some googling, and couldn't really find anything, except for a page that said this:
However, this breaks programs that use require 'openssl' as a test for whether openssl is available or not. Soap4r is one such program. In order to support this behavior, simply add
require 'jruby/openssl/gem_only'
So I tracked down the file that seemed to have the error (gem_runner.rb) and added the require line in there. I ran jruby -S gem install jruby-openssl again, and got this error:
ERROR: While executing gem ... (NameError)
uninitialized constant Net::HTTP::OpenSSL
Has anyone else had this problem before? I don't understand what I did wrong! Are there some independent openssl settings that I should delete first?
Any guidance would be much appreciated - thanks,
Rebecca
So, I have rvm installed on my machine, and I type:
rvm install jruby
Everything looks good at first, but eventually I get:
jruby-1.5.6 - #fetching
jruby-1.5.6 - #extracted to /home/jenny/.rvm/src/jruby-1.5.6 (already extracted)
Building Nailgun
jruby-1.5.6 - #installing to /home/jenny/.rvm/rubies/jruby-1.5.6
jruby-1.5.6 - #importing default gemsets (/home/jenny/.rvm/gemsets/)
Copying across included gems
Exception in thread "main" java.lang.NoClassDefFoundError: org.jruby.Main
at gnu.java.lang.MainThread.run(libgcj.so.9)
Caused by: java.lang.ClassNotFoundException: org.jruby.Main not found in gnu.gcj.runtime.SystemClassLoader{urls=[file:./], parent=gnu.gcj.runtime.ExtensionClassLoader{urls=[], parent=null}}
at java.net.URLClassLoader.findClass(libgcj.so.9)
at gnu.gcj.runtime.SystemClassLoader.findClass(libgcj.so.9)
at java.lang.ClassLoader.loadClass(libgcj.so.9)
at java.lang.ClassLoader.loadClass(libgcj.so.9)
at gnu.java.lang.MainThread.run(libgcj.so.9)
jenny#linux-auvv:~/workspace/pcms_stable>
I have absolutly no context for debugging this... I honestly have no idea what to do...
I'm on OpenSuse, and when I type "java -version", I get:
java version "1.6.0_0"
OpenJDK Runtime Environment (build 1.6.0_0-b11)
OpenJDK Server VM (build 1.6.0_0-b11, mixed mode)
I can't see any references to java requirements for JRuby, though...
As far as RVM, I'm running:
rvm 1.2.4 by Wayne E. Seguin (wayneeseguin#gmail.com) [http://rvm.beginrescueend.com/]
I can install other rubies with RVM (1.9.2, 1.8.7, that sort of thing) with no problem, this is the first issue I've ever found.
It doesn't seem to matter WHICH jruby I install, either. My rvm knows about:
# JRuby
jruby-1.2.0
jruby-1.3.1
jruby-1.4.0
jruby[-1.5.6]
jruby-head
I don't even get the same errors for each one of them:
For 1.2.0, 1.3.1, 1.4.0 I get:
Fatal: GCJ (GNU Compiler for Java) is not supported by JRuby.
Where 1.5.6 and head get me the error I mentioned first.
I WANT to use JRuby with Rails 3, so I'm figuring I want the newest version I can get (which is having the exceptions)
Is there ANYTHING I can do, or am I just doomed to not be able to use RVM for my purposes?
EDIT:
I have confirmed that it's not just RVM, it is JRuby that is to blame. To test, I downloaded JRuby without rvm at all, through the website (I chose version 1.6). I unpacked it as per the instructions, and typed:
bin/jruby -v
in the extracted directory.
I got the exact same error:
jenny#linux-auvv:~/jruby-1.6.0.RC1> bin/jruby -v
Exception in thread "main" java.lang.NoClassDefFoundError: org.jruby.Main
at gnu.java.lang.MainThread.run(libgcj.so.9)
Caused by: java.lang.ClassNotFoundException: org.jruby.Main not found in gnu.gcj.runtime.SystemClassLoader{urls=[file:./], parent=gnu.gcj.runtime.ExtensionClassLoader{urls=[], parent=null}}
at java.net.URLClassLoader.findClass(libgcj.so.9)
at gnu.gcj.runtime.SystemClassLoader.findClass(libgcj.so.9)
at java.lang.ClassLoader.loadClass(libgcj.so.9)
at java.lang.ClassLoader.loadClass(libgcj.so.9)
at gnu.java.lang.MainThread.run(libgcj.so.9)
So, still have no clue what's going on, but at least I know now it's a jruby issue, and not an rvm one (though I still WANT it installed through rvm)
Edit:
So, I tried updating my OpenJDK, and it was no dice, but I found ANOTHER version of OpenJDK (that I didn't have installed) through YAST, and installed THAT one, and suddenly my manually installed jruby works just fine:
jenny#linux-auvv:~/jruby-1.6.0.RC1> bin/jruby -v
jruby 1.6.0.RC1 (ruby 1.8.7 patchlevel 330) (2011-01-10 769f847) (OpenJDK Client VM 1.6.0_0) [linux-i386-java]
When I type java -version, I even get something different:
jenny#linux-auvv:~/jruby-1.6.0.RC1> java -version
java version "1.6.0_0"
OpenJDK Runtime Environment (IcedTea6 1.6.2) (suse-0.1.1-i386)
OpenJDK Server VM (build 14.0-b16, mixed mode)
It even works in RVM, so hooray!
I would try installing the Sun JRE/JDK.
Or perhaps you could reinstall OpenJDK(probably the easiest way to reset it to being the default on your system).
Update:
To change the default java do this. First check which Javas are available:
update-alternatives --list java
To actually change which one you are using do this:
update-alternatives --config java
I think the clue is in this:
Fatal: GCJ (GNU Compiler for Java) is not supported by JRuby.
For whatever reason, your system is configured to fire up GCJ instead of your OpenJDK compiler. Check the docs on your system for how it handles the case where multiple things can provide the same service name (multiple versions of compilers, for example, or multiple interpreters) and see what you can do to have OpenJDK be the default handler for Java compilation and execution.
Ubuntu 10.04LTS
Netbeans 6.9.1 (with embedded JRuby 1.5.1)
JDK6u17 (installed in /opt)
GlassFish Gem 1.0.2
I am using a old JDK because of this bug: http://jira.codehaus.org/browse/JRUBY-4785
I want to install RVM and install another instance of JRuby. But i cant find any information how to set JRuby Java environment to JDK6u17(directory /opt).
I would be grateful for the help.
JRuby on default use system Java. So if i change "system" Java, JRuby will use that one.
I have figured two ways to set specific Java environment.
Set JAVA_HOME.
Here is a good one tutorial:
http://vietpad.sourceforge.net/javaonlinux.html
Update java setting from terminal(works only for JVM installed from apt-get or aptitude).
sudo update-alternatives --config java
That JRuby bug is marked as fixed for JRuby 1.6RC1, so you no longer need to use the old JDK.
I am using RVM and JRuby 1.6RC1 on Ubuntu 10.04 LTS just fine. There are instructions on my website for working with this version of Ubuntu, RVM and JRuby.
You don't need all the instructions, but some of the commands might help, if you get stuck.
http://www.scottlowe.eu/deploying-rails-3-with-jruby-daemonized-glass
(It does tell you how to get a modern JDK installed)