Yes we have an interpreter for C to run C extensions. It runs real C extensions from Oily PNG and PSD Native 3x faster than native, due to inlining C and Ruby together.
People are now working on an LLVM bitcode interpreter instead, as this should support many languages not just C. There will be info about this at FOSDEM.
The Truffle backend in JRuby+Truffle uses a different class hierarchy that makes supporting the Java extension API tricky. It's certainly doable and we haven't ruled it out, but the API parts of JRuby really need to be ironed out first. Right now it's essentially anything that's public in JRuby core, which is a bad situation to be in. Various attempts at rectifying that have predictably broken third party code, so it needs to be handled with care.
Of course, rather than trying to fix the general problem, we could support the most common JRuby gems out there or the core subset of the API they use. These are just the sorts of things we need to look at a bit more.
thanks for replying.
What you are talking about is potentially a big issue. Like it or not, the biggest usage of jruby is in running Rails. Unlike jython, which not a lot of people use, jruby is extremely popular.
one of the reasons for its popularity is the way it can be hosted using Tomcat or build a jar and drop it in a container ... a nice little trojan horse into the world of enterprisey software.
I would be very excited for Truffle+Jruby if it outperforms in this usecase. Where do you envision Truffle/Jruby being used - as a dropin replacement for MRI or for JRuby ?
Or are you thinking of a third ecosystem around this project ?
One of our stated goals is to run code is to run code without modification, including extensions. We have no intention of creating a third ecosystem. However, with Truffle's polyglot interface, someone certainly could write a JRuby+Truffle specific extension -- that's just not our general plan for extensions.
Early in its life, JRuby+Truffle was a separate project and its goal was to run everything MRI can. Thanks to efforts on both the JRuby and Oracle sides, the project was open-sourced and merged with JRuby. That brought along a ton of benefits for us, but did open the JRuby ext. can of worms.
I'm trying hard to answer your question without committing to solve a problem we haven't looked at in depth. I suspect we'll wind up supporting some portion of the JRuby ext. API, but whether that ends up via an alternative implementation, a sandboxed JRuby runtime, a bytecode processor using something like a hypothetical TruffleJava, or something entirely different, I don't know. We've had enough pure Ruby code to try to get working that we've been able to defer the extension discussion for a bit.
Having said all that, to really get the benefits of JRuby+Truffle you're going to want to use Graal. While JEP 243 [1] should make deployment scenarios much easier starting with Java 9, you'll probably still need to coordinate with your ops team since the JAR needs to be on the bootclasspath. That's really just to say that you won't be able to just drop the JRuby JAR in and get optimal performance -- there's still going to be a second step that you might not be able to "backdoor" into your stack.
Look, I appreciate the engineering, but I'm genuinely curious if you think taking the JVM + building a MRI-compatible stack with C-transpilation is the perfect first order goal.
I'm not sure why you refer to Jruby ext api as a can of worms - perhaps there is some VM level dragons that I'm not aware of... but the Jruby ecosystem is brilliant. I built my first software services startup on top of Jruby - custom enterprise software that runs on Tomcat (the idea came from Mingle - a JRuby based enterprisey Basecamp from Thoughtworks)
Even in a general usecase, Jruby is brilliant when used with Puma. This deployment is unbeatable by any other ruby server. However, startup times in the java world is definitely a pain.. which is why developers tend to use MRI. In fact I know lots of developers who develop in MRI and deploy in jruby.
I think if you decide to take the direction of building a jruby compatible implementation with MRI beating startup times and with even one fourth of the performance you are talking about... tell me where to sign the cheque ;)
Hi there - no problem. Feel free to ask any question you'd like. You're not going to hurt our feelings and we'd rather clarify any confusion than let it linger and manifest into some weird FUD. On that note, we're quite active in the JRuby IRC and gitter rooms, so you ever have a question you want answered more real time, feel free to hop in and ask away.
The "can of worms" comment wasn't meant to be pejorative -- only that there's a lot to the problem and it's not exactly clean. There simply isn't an extension API in JRuby. There's just the JRuby JAR and whatever is publicly reachable.
The situation today is there are two backends available for JRuby: the standard IR-based one and the Truffle-based one. The two backends make use of shared infrastructure, but are otherwise quite distinct. E.g., both backends have different object models for Ruby-level classes & objects. Take Ruby strings for instance. They use a shared abstraction for the underlying implementation, but there's no shared interface -- it's all composition. Creating a Ruby string in a Java extension means importing org.jruby.RubyString and creating an instance of it. JRuby+Truffle represents strings differently, so creating a string that way presents a problem.
The simplest thing to do is translate everything between the two runtimes, but that incurs a lot of overhead, unnecessary object allocations, and grossly limits our ability to optimize calls. The harder solution is to provide a JRuby+Truffle implementation of the API, but given its current lack of definition, we'd have to support the de facto API for 100% compatibility and the de facto API is massive. We're working with the JRuby core team to annotate a portion of the API to be used for extensions, at which point the problem becomes much easier to manage.
FWIW - Prior to joining Oracle Labs I made a big gamble on JRuby for my start-up (Mogotest). I love JRuby and have been working with it for years outside of my current gig. I'd love to see JRuby+Truffle simply work with Java extensions, because they can be really nice (JDBC + Sequel is amazingly fast). Unfortunately, it's just a messy issue at the moment.
May I suggest a blog post on this. What you have written here on HN has been far,far more interesting than the original blog post and is making me excited to dive into the source code.
Comments
Was this the project that had some special plan for making native extensions work? I remember seeing something like that a while back on HN.
Yes we have an interpreter for C to run C extensions. It runs real C extensions from Oily PNG and PSD Native 3x faster than native, due to inlining C and Ruby together.
http://chrisseaton.com/rubytruffle/cext/
People are now working on an LLVM bitcode interpreter instead, as this should support many languages not just C. There will be info about this at FOSDEM.
Why are you doing that? Jruby has been a complete ecosystem in itself and very few MRI specific gems need porting over.
You could spend a whole bunch of time on this and actually not make an impact on people who actually use jruby in production
EDIT: now that I think of it, there's one extension that would be very useful - libgit2 + Rugged.
The Truffle backend in JRuby+Truffle uses a different class hierarchy that makes supporting the Java extension API tricky. It's certainly doable and we haven't ruled it out, but the API parts of JRuby really need to be ironed out first. Right now it's essentially anything that's public in JRuby core, which is a bad situation to be in. Various attempts at rectifying that have predictably broken third party code, so it needs to be handled with care.
Of course, rather than trying to fix the general problem, we could support the most common JRuby gems out there or the core subset of the API they use. These are just the sorts of things we need to look at a bit more.
thanks for replying. What you are talking about is potentially a big issue. Like it or not, the biggest usage of jruby is in running Rails. Unlike jython, which not a lot of people use, jruby is extremely popular.
one of the reasons for its popularity is the way it can be hosted using Tomcat or build a jar and drop it in a container ... a nice little trojan horse into the world of enterprisey software.
I would be very excited for Truffle+Jruby if it outperforms in this usecase. Where do you envision Truffle/Jruby being used - as a dropin replacement for MRI or for JRuby ?
Or are you thinking of a third ecosystem around this project ?
One of our stated goals is to run code is to run code without modification, including extensions. We have no intention of creating a third ecosystem. However, with Truffle's polyglot interface, someone certainly could write a JRuby+Truffle specific extension -- that's just not our general plan for extensions.
Early in its life, JRuby+Truffle was a separate project and its goal was to run everything MRI can. Thanks to efforts on both the JRuby and Oracle sides, the project was open-sourced and merged with JRuby. That brought along a ton of benefits for us, but did open the JRuby ext. can of worms.
I'm trying hard to answer your question without committing to solve a problem we haven't looked at in depth. I suspect we'll wind up supporting some portion of the JRuby ext. API, but whether that ends up via an alternative implementation, a sandboxed JRuby runtime, a bytecode processor using something like a hypothetical TruffleJava, or something entirely different, I don't know. We've had enough pure Ruby code to try to get working that we've been able to defer the extension discussion for a bit.
Having said all that, to really get the benefits of JRuby+Truffle you're going to want to use Graal. While JEP 243 [1] should make deployment scenarios much easier starting with Java 9, you'll probably still need to coordinate with your ops team since the JAR needs to be on the bootclasspath. That's really just to say that you won't be able to just drop the JRuby JAR in and get optimal performance -- there's still going to be a second step that you might not be able to "backdoor" into your stack.
[1] -- http://openjdk.java.net/jeps/243
hi - thanks for taking the time to answer.
Look, I appreciate the engineering, but I'm genuinely curious if you think taking the JVM + building a MRI-compatible stack with C-transpilation is the perfect first order goal.
I'm not sure why you refer to Jruby ext api as a can of worms - perhaps there is some VM level dragons that I'm not aware of... but the Jruby ecosystem is brilliant. I built my first software services startup on top of Jruby - custom enterprise software that runs on Tomcat (the idea came from Mingle - a JRuby based enterprisey Basecamp from Thoughtworks)
Even in a general usecase, Jruby is brilliant when used with Puma. This deployment is unbeatable by any other ruby server. However, startup times in the java world is definitely a pain.. which is why developers tend to use MRI. In fact I know lots of developers who develop in MRI and deploy in jruby.
I think if you decide to take the direction of building a jruby compatible implementation with MRI beating startup times and with even one fourth of the performance you are talking about... tell me where to sign the cheque ;)
Hi there - no problem. Feel free to ask any question you'd like. You're not going to hurt our feelings and we'd rather clarify any confusion than let it linger and manifest into some weird FUD. On that note, we're quite active in the JRuby IRC and gitter rooms, so you ever have a question you want answered more real time, feel free to hop in and ask away.
The "can of worms" comment wasn't meant to be pejorative -- only that there's a lot to the problem and it's not exactly clean. There simply isn't an extension API in JRuby. There's just the JRuby JAR and whatever is publicly reachable.
The situation today is there are two backends available for JRuby: the standard IR-based one and the Truffle-based one. The two backends make use of shared infrastructure, but are otherwise quite distinct. E.g., both backends have different object models for Ruby-level classes & objects. Take Ruby strings for instance. They use a shared abstraction for the underlying implementation, but there's no shared interface -- it's all composition. Creating a Ruby string in a Java extension means importing org.jruby.RubyString and creating an instance of it. JRuby+Truffle represents strings differently, so creating a string that way presents a problem.
The simplest thing to do is translate everything between the two runtimes, but that incurs a lot of overhead, unnecessary object allocations, and grossly limits our ability to optimize calls. The harder solution is to provide a JRuby+Truffle implementation of the API, but given its current lack of definition, we'd have to support the de facto API for 100% compatibility and the de facto API is massive. We're working with the JRuby core team to annotate a portion of the API to be used for extensions, at which point the problem becomes much easier to manage.
FWIW - Prior to joining Oracle Labs I made a big gamble on JRuby for my start-up (Mogotest). I love JRuby and have been working with it for years outside of my current gig. I'd love to see JRuby+Truffle simply work with Java extensions, because they can be really nice (JDBC + Sequel is amazingly fast). Unfortunately, it's just a messy issue at the moment.
Thank you - you have been incredibly patient!
May I suggest a blog post on this. What you have written here on HN has been far,far more interesting than the original blog post and is making me excited to dive into the source code.
Glad it was helpful. I do need to start blogging more. 2016!
The same system is used by Graal.js and the other languages for their native extensions.