# Where's the bytecode from Ruby 1.9

**URL:** <https://www.ruby-forum.com/t/wheres-the-bytecode-from-ruby-1-9/124421>\
**Category:** Ruby\
**Created:** [December 28, 2007, 4:18pm UTC](https://www.ruby-forum.com/t/wheres-the-bytecode-from-ruby-1-9/124421 "2007-12-28T16:18:20Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![jimdeuc](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b77776/32.png) [@jimdeuc](https://www.ruby-forum.com/u/jimdeuc)\
**Post date:** [December 28, 2007, 4:18pm UTC](https://www.ruby-forum.com/t/wheres-the-bytecode-from-ruby-1-9/124421/1 "2007-12-28T16:18:20Z")

</div>

From what I understand, the big goal of YARV was to spit out bytecode  
from your ruby scripts. From what I understand of bytecode, it can be  
executed faster and also hides the source code. I may be  
misunderstanding bytecode, but my question is can the just released Ruby  
1.9.0 produce bytecode?

---

<div class="post-metadata">

**Author:** ![jimdeuc](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b77776/32.png) [@jimdeuc](https://www.ruby-forum.com/u/jimdeuc)\
**Post date:** [January 1, 2008, 3:55pm UTC](https://www.ruby-forum.com/t/wheres-the-bytecode-from-ruby-1-9/124421/2 "2008-01-01T15:55:19Z")

</div>

James D. wrote:

> > From what I understand, the big goal of YARV was to spit out bytecode  
> > from your ruby scripts. From what I understand of bytecode, it can be  
> > executed faster and also hides the source code. I may be  
> > misunderstanding bytecode, but my question is can the just released Ruby  
> > 1.9.0 produce bytecode?

It uses a bytecode representation internally, but doesn’t currently  
write the bytecode to disk like python does.

The VM::InstructionSequence class gives some access to the bytecode.  
You can get the individual elements of the sequence by calling #to\_a.

There is support in Nodewrap for saving/restoring instruction sequences,  
but needs to be updated for the latest 1.9.

Paul

---

<div class="post-metadata">

**Author:** ![jimdeuc](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b77776/32.png) [@jimdeuc](https://www.ruby-forum.com/u/jimdeuc)\
**Post date:** [January 2, 2008, 3:35pm UTC](https://www.ruby-forum.com/t/wheres-the-bytecode-from-ruby-1-9/124421/3 "2008-01-02T15:35:32Z")

</div>

Paul B. wrote:

> It uses a bytecode representation internally, but doesn’t currently  
> write the bytecode to disk like python does.
> 
> The VM::InstructionSequence class gives some access to the bytecode.  
> You can get the individual elements of the sequence by calling #to\_a.
> 
> There is support in Nodewrap for saving/restoring instruction sequences,  
> but needs to be updated for the latest 1.9.
> 
> Paul

Thanks for the reply. There would be some startup-time savings if it  
just converted to bytecode once, saved it to disk, and then could be  
loaded straight from bytecode, right? Does anyone know if that  
functionality is on the horizon? Of course there is a finite amount of  
time in a day for the developers to work on ruby, so I have no problem  
being patient. I just think ruby may get more business backing if it  
can hide it’s source code (for those who write closed-source software)  
and would also keep people from making a “quick change” to production  
code (ie introduce breakage to production code).

I would guess if it is already converting to bytecode internally than it  
is getting some runtime performance benefits from it, and that’s where I  
personally would rather see the biggest speed improvements anyway.

James

---

<div class="post-metadata">

**Author:** ![jimdeuc](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b77776/32.png) [@jimdeuc](https://www.ruby-forum.com/u/jimdeuc)\
**Post date:** [January 3, 2008, 1:44am UTC](https://www.ruby-forum.com/t/wheres-the-bytecode-from-ruby-1-9/124421/4 "2008-01-03T01:44:09Z")

</div>

Joseph L. wrote:

> > I would guess if it is already converting to bytecode internally than it  
> > is getting some runtime performance benefits from it, and that’s where I  
> > personally would rather see the biggest speed improvements anyway.
> > 
> > James
> 
> I dunno about Python, but Java bytecode can be easily decompiled.

In JRuby’s case, we do support dumping bytecode to disk as Java .class  
files. This would be roughly equivalent to Python’s pyc files. And  
although you can decompile Java bytecode, you’d end up decompiling it to  
a mishmash of JRuby internal calls…it would be quite a bit harder to  
decompile all the way to Ruby.

- Charlie

---

<div class="post-metadata">

**Author:** ![jimdeuc](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b77776/32.png) [@jimdeuc](https://www.ruby-forum.com/u/jimdeuc)\
**Post date:** [January 2, 2008, 8:24pm UTC](https://www.ruby-forum.com/t/wheres-the-bytecode-from-ruby-1-9/124421/5 "2008-01-02T20:24:38Z")

</div>

James D. wrote:

> Thanks for the reply. There would be some startup-time savings if it  
> just converted to bytecode once, saved it to disk, and then could be  
> loaded straight from bytecode, right? Does anyone know if that  
> functionality is on the horizon? Of course there is a finite amount of  
> time in a day for the developers to work on ruby, so I have no problem  
> being patient. I just think ruby may get more business backing if it  
> can hide it’s source code (for those who write closed-source software)  
> and would also keep people from making a “quick change” to production  
> code (ie introduce breakage to production code).
> 
> I would guess if it is already converting to bytecode internally than it  
> is getting some runtime performance benefits from it, and that’s where I  
> personally would rather see the biggest speed improvements anyway.
> 
> James

I dunno about Python, but Java bytecode can be easily decompiled.

Joe.

---

<div class="post-metadata">

**Author:** ![jimdeuc](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b77776/32.png) [@jimdeuc](https://www.ruby-forum.com/u/jimdeuc)\
**Post date:** [January 3, 2008, 3:15am UTC](https://www.ruby-forum.com/t/wheres-the-bytecode-from-ruby-1-9/124421/6 "2008-01-03T03:15:53Z")

</div>

On Jan 2, 8:35 am, James D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > Paul
> 
> I would guess if it is already converting to bytecode internally than it  
> is getting some runtime performance benefits from it, and that’s where I  
> personally would rather see the biggest speed improvements anyway.
> 
> ## James
> 
> Posted viahttp://www.ruby-forum.com/.

IIRC, before YARV was merged, it had an option to save / load bytecode  
to / from files. But it’s been a year or two and my memory is kind of  
cloudy. Maybe it was a test or example ruby script that did it rather  
than YARV core…hmm…can’t recall. But if so (either from core or  
from exposed API), then it seems like a good bet that KRI will be able  
to do that someday (and like Charlie said, JRuby is already adding  
support, which will presumably be made binary-compatible with a dump  
from KRI if / when it’s implemented).

Regards,  
Jordan

---

<div class="post-metadata">

**Author:** ![jimdeuc](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b77776/32.png) [@jimdeuc](https://www.ruby-forum.com/u/jimdeuc)\
**Post date:** [January 3, 2008, 6:38pm UTC](https://www.ruby-forum.com/t/wheres-the-bytecode-from-ruby-1-9/124421/7 "2008-01-03T18:38:55Z")

</div>

On Jan 3, 2008 11:26 AM, James D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Waitaminute. So if I have a paid-for application from some company and  
> they wrote it in java, it would be possible for me to decompile it into  
> the sourcecode?

## Yep, try googling “java decompiler”

Rick DeNatale

My blog on Ruby  
[http://talklikeaduck.denhaven2.com/](http://talklikeaduck.denhaven2.com/)

---

<div class="post-metadata">

**Author:** ![jimdeuc](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b77776/32.png) [@jimdeuc](https://www.ruby-forum.com/u/jimdeuc)\
**Post date:** [January 3, 2008, 5:26pm UTC](https://www.ruby-forum.com/t/wheres-the-bytecode-from-ruby-1-9/124421/8 "2008-01-03T17:26:49Z")

</div>

Charles Oliver N. wrote:

> In JRuby’s case, we do support dumping bytecode to disk as Java .class  
> files. This would be roughly equivalent to Python’s pyc files. And  
> although you can decompile Java bytecode, you’d end up decompiling it to  
> a mishmash of JRuby internal calls…it would be quite a bit harder to  
> decompile all the way to Ruby.
> 
> - Charlie

Waitaminute. So if I have a paid-for application from some company and  
they wrote it in java, it would be possible for me to decompile it into  
the sourcecode? I figured there must be some way to hide it, otherwise  
proprietary software wouldn’t use it?

---

<div class="post-metadata">

**Author:** ![jimdeuc](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b77776/32.png) [@jimdeuc](https://www.ruby-forum.com/u/jimdeuc)\
**Post date:** [January 4, 2008, 2:16am UTC](https://www.ruby-forum.com/t/wheres-the-bytecode-from-ruby-1-9/124421/9 "2008-01-04T02:16:35Z")

</div>

James D. wrote:

> Waitaminute. So if I have a paid-for application from some company and  
> they wrote it in java, it would be possible for me to decompile it into  
> the sourcecode?

Yes, it’s also a lot of fun to do that.

> I figured there must be some way to hide it, otherwise  
> proprietary software wouldn’t use it?

Not, really. There are obfuscators available, that rename classes,  
methods, etc. but this merely increases the challenge a bit.

---

<div class="post-metadata">

**Author:** ![jimdeuc](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b77776/32.png) [@jimdeuc](https://www.ruby-forum.com/u/jimdeuc)\
**Post date:** [January 4, 2008, 5:51pm UTC](https://www.ruby-forum.com/t/wheres-the-bytecode-from-ruby-1-9/124421/10 "2008-01-04T17:51:44Z")

</div>

Florian F. wrote:

> James D. wrote:
> 
> > Waitaminute. So if I have a paid-for application from some company and  
> > they wrote it in java, it would be possible for me to decompile it into  
> > the sourcecode?
> 
> Yes, it’s also a lot of fun to do that.
> 
> > I figured there must be some way to hide it, otherwise  
> > proprietary software wouldn’t use it?
> 
> Not, really. There are obfuscators available, that rename classes,  
> methods, etc. but this merely increases the challenge a bit.

Thanks everyone for the info. So when the Rubinius website says this:

“The Rubinius compiler generates bytecode that you can distribute in  
easy-to-install packages similar to jar files. Other measures to protect  
intellectual property can be easily added.”

I take it they are just talking about the same thing… bytecode with  
obfuscators and such.
