Benefit from computing String Hash at compile time?
fredrik.ohrstrom at oracle.com
Wed Jan 6 01:19:12 PST 2010
Joseph D. Darcy skrev:
> And implicit in mandating that formula is mandating that formula going
> forward for all subsequent releases. Otherwise, there is often not
> much point in specifying a particular hash function.
The best would be to defer the choice how to implement the string switch
entirely to the JVM, akin to how the plain switch does it. Obviously
this is not an option since string switch belongs to project Coin that
cannot change the bytecodes.
Thus Joe's design is good since it gives the best worst case behavior
for interpreting and non-optimizing JVMs. Our JVM will probably detect
the string switch pattern and rip out all the hashcode and everything
and replace it with something more optimized when it will give us a
performance advantage. Thus the generated string switch bytecode should
be as easy to detect and rip out as possible. (Which was the reason for
my previous gripe where I wanted a simpler pattern, but I forgot about
the low end JVMs.) Computing the hash at runtime would make the pattern
worse and gain nothing since the hash is indeed specified in the
More information about the coin-dev