# Where's the bytecode from Ruby 1.9

**URL:** <https://rubytalk.org/t/wheres-the-bytecode-from-ruby-1-9/43377>\
**Category:** ruby-talk\
**Created:** [28 December 2007 15:18 UTC](https://rubytalk.org/t/wheres-the-bytecode-from-ruby-1-9/43377 "2007-12-28T15:18:15Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![James\_Dinkel](https://avatars.discourse-cdn.com/v4/letter/j/e8c25b/32.png) [@James\_Dinkel](https://rubytalk.org/u/James_Dinkel)\
**Post date:** [28 December 2007 15:18 UTC](https://rubytalk.org/t/wheres-the-bytecode-from-ruby-1-9/43377/1 "2007-12-28T15:18:15Z")

</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?

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![Paul\_Brannan](https://avatars.discourse-cdn.com/v4/letter/p/76d3ee/32.png) [@Paul\_Brannan](https://rubytalk.org/u/Paul_Brannan)\
**Post date:** [1 January 2008 14:54 UTC](https://rubytalk.org/t/wheres-the-bytecode-from-ruby-1-9/43377/2 "2008-01-01T14:54:44Z")

</div>

James Dinkel 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:** ![James\_Dinkel](https://avatars.discourse-cdn.com/v4/letter/j/e8c25b/32.png) [@James\_Dinkel](https://rubytalk.org/u/James_Dinkel)\
**Post date:** [2 January 2008 14:35 UTC](https://rubytalk.org/t/wheres-the-bytecode-from-ruby-1-9/43377/3 "2008-01-02T14:35:27Z")

</div>

Paul Brannan 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

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Joseph\_Lenton](https://avatars.discourse-cdn.com/v4/letter/j/45deac/32.png) [@Joseph\_Lenton](https://rubytalk.org/u/Joseph_Lenton)\
**Post date:** [2 January 2008 19:24 UTC](https://rubytalk.org/t/wheres-the-bytecode-from-ruby-1-9/43377/4 "2008-01-02T19:24:33Z")

</div>

James Dinkel 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.

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Jordan\_Callicoat](https://avatars.discourse-cdn.com/v4/letter/j/9de053/32.png) [@Jordan\_Callicoat](https://rubytalk.org/u/Jordan_Callicoat)\
**Post date:** [3 January 2008 02:14 UTC](https://rubytalk.org/t/wheres-the-bytecode-from-ruby-1-9/43377/5 "2008-01-03T02:14:59Z")

</div>

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

> **···**
>
> On Jan 2, 8:35 am, James Dinkel \<jdin...@bucoks.com\> wrote:
> 
> > Paul Brannan 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  
> > --  
> > Posted viahttp://www.ruby-forum.com/.

---

<div class="post-metadata">

**Author:** ![Charles\_Oliver\_Nutte](https://avatars.discourse-cdn.com/v4/letter/c/71e660/32.png) [@Charles\_Oliver\_Nutte](https://rubytalk.org/u/Charles_Oliver_Nutte)\
**Post date:** [3 January 2008 00:43 UTC](https://rubytalk.org/t/wheres-the-bytecode-from-ruby-1-9/43377/6 "2008-01-03T00:43:28Z")

</div>

Joseph Lenton wrote:

> James Dinkel 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.

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:** ![James\_Dinkel](https://avatars.discourse-cdn.com/v4/letter/j/e8c25b/32.png) [@James\_Dinkel](https://rubytalk.org/u/James_Dinkel)\
**Post date:** [3 January 2008 16:26 UTC](https://rubytalk.org/t/wheres-the-bytecode-from-ruby-1-9/43377/7 "2008-01-03T16:26:47Z")

</div>

Charles Oliver Nutter 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?

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Rick\_DeNatale1](https://avatars.discourse-cdn.com/v4/letter/r/bbce88/32.png) [@Rick\_DeNatale1](https://rubytalk.org/u/Rick_DeNatale1)\
**Post date:** [3 January 2008 17:37 UTC](https://rubytalk.org/t/wheres-the-bytecode-from-ruby-1-9/43377/8 "2008-01-03T17:37:58Z")

</div>

Yep, try googling "java decompiler"

> **···**
>
> On Jan 3, 2008 11:26 AM, James Dinkel \<jdinkel@bucoks.com\> wrote:
> 
> > Charles Oliver Nutter 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?
> 
> --  
> Rick DeNatale
> 
> My blog on Ruby  
> [http://talklikeaduck.denhaven2.com/](http://talklikeaduck.denhaven2.com/)

---

<div class="post-metadata">

**Author:** ![Florian\_Frank2](https://avatars.discourse-cdn.com/v4/letter/f/a587f6/32.png) [@Florian\_Frank2](https://rubytalk.org/u/Florian_Frank2)\
**Post date:** [4 January 2008 01:15 UTC](https://rubytalk.org/t/wheres-the-bytecode-from-ruby-1-9/43377/9 "2008-01-04T01:15:36Z")

</div>

James Dinkel 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.

> **···**
>
> --  
> Florian Frank

---

<div class="post-metadata">

**Author:** ![James\_Dinkel](https://avatars.discourse-cdn.com/v4/letter/j/e8c25b/32.png) [@James\_Dinkel](https://rubytalk.org/u/James_Dinkel)\
**Post date:** [4 January 2008 16:52 UTC](https://rubytalk.org/t/wheres-the-bytecode-from-ruby-1-9/43377/10 "2008-01-04T16:52:04Z")

</div>

Florian Frank wrote:

> James Dinkel 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.

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).
