[217] in java-interest
Re: goto and switch
daemon@ATHENA.MIT.EDU (Arthur van Hoff)
Wed Jun 7 15:05:29 1995
Date: Wed, 7 Jun 1995 12:00:28 -0700
From: Arthur.Vanhoff@Eng.Sun.COM (Arthur van Hoff)
To: jeremy@sour.sw.oz.au
Cc: java-interest@java.Eng.Sun.COM
Hi Jeremy,
> > > My concern is that inlining the constants from
> > > another class is effectively inlining part of the implementation which
> > > could change between compile time and link time, and therefore
> > > change the semantics without any obvious errors.
> >
> > Your concern is a valid concern. The avoid this somewhat the compiler
> > automatically does dependency checks (it has a build in make). But you
> > are right that the problems not go away completely.
>
> Yes. The compiler has no control over what version of a class the
> code it's currently compiling will eventually bind against, and
> you might be compiling against a class which you have no source
> for.
Actually, the value of final variables is stored in the class file
so that it can be inlined even when the source if not available.
> > The bottom line is that, if you are really concerned about changing
> > an interface in incompatible ways, then you should not use constants,
> > use variables instead. We chose to inline constants for efficiency,
> > this has the unfortunate side effect of making interfaces a little
> > more brittle. However, it is not obvious whether the alternative would
> > result in acceptable performance.
>
> Because all the switches would become if-else trees? Or just
> because there'd be lots of lookups instead of inline constants?
> Surely if the compiler didn't inline another class's constants,
> the runtime could when it saw a class access another class's member
> which is final? Of course, to get the full effect the runtime
> would have to do some local rewrites of the bytecode, but that
> isn't very expensive.
How would you deal with the case where two case labels turn out
to have the same value at runtime? It is not clear if you can
write all switch statements as if-then-else trees.
By the way, I've thought about this a lot. I really wanted a
way to use Strings as case labels. It turned out to be too hard
given the semantics of the switch statement.
Have fun,
Arthur van Hoff,
x47242, UPAL02-301
http://tachyon.eng/~avh/
-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com