Location/Rationale of generated code

22 views
Skip to first unread message

Juan Manuel

unread,
Jul 25, 2019, 1:57:34 PM7/25/19
to mozilla-rhino
I am using Rhino for a research project, and I need to understand certain parts of the system.

I came across the switch statement in https://github.com/mozilla/rhino/blob/master/src/org/mozilla/javascript/TokenStream.java#L167 and I am very curious about it. I have two questions:
  1. It seems to be generated code but I can't seem to find how it is generated. Where is the logic that generates this code?
  2. What is the rationale for using this switch instead of simply using a set with the keywords, for example?
Thank you.

Gregory Brail

unread,
Jul 25, 2019, 4:12:18 PM7/25/19
to mozill...@googlegroups.com
That's a fun one, and it's used all over Rhino.

The code is generated by "idswitch" -- the source is in the "tools" directory. 

It is used in every native Rhino class that needs to look up a property name from a string, and does so more efficiently than a long sequence of individual string comparisons.

The Rhino codebase dates back to the earliest days of Java, and I presume that back then this type of generated code made a meaningful performance difference versus, say, a static hash table. It'd be fun to do some research and see if that's still the case.

--
You received this message because you are subscribed to the Google Groups "mozilla-rhino" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mozilla-rhin...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mozilla-rhino/993847e7-3117-4c6f-b6df-5fbb1928451b%40googlegroups.com.

Juan Manuel

unread,
Jul 25, 2019, 5:12:25 PM7/25/19
to mozilla-rhino
Thank you! That's very interesting, I didn't realize Rhino was that old


On Thursday, July 25, 2019 at 4:12:18 PM UTC-4, Gregory Brail wrote:
That's a fun one, and it's used all over Rhino.

The code is generated by "idswitch" -- the source is in the "tools" directory. 

It is used in every native Rhino class that needs to look up a property name from a string, and does so more efficiently than a long sequence of individual string comparisons.

The Rhino codebase dates back to the earliest days of Java, and I presume that back then this type of generated code made a meaningful performance difference versus, say, a static hash table. It'd be fun to do some research and see if that's still the case.

On Thu, Jul 25, 2019 at 10:57 AM Juan Manuel <jmflo...@gmail.com> wrote:
I am using Rhino for a research project, and I need to understand certain parts of the system.

I came across the switch statement in https://github.com/mozilla/rhino/blob/master/src/org/mozilla/javascript/TokenStream.java#L167 and I am very curious about it. I have two questions:
  1. It seems to be generated code but I can't seem to find how it is generated. Where is the logic that generates this code?
  2. What is the rationale for using this switch instead of simply using a set with the keywords, for example?
Thank you.

--
You received this message because you are subscribed to the Google Groups "mozilla-rhino" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mozill...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages