Joakim Dahlstedt wrote:
>
> > Speaking of bounds checking, I understand that in at least some JVMs,
> > it'd be even faster to write code like:
> >
> > try
> > {
> > byte[] vgaBuffer = jos.system.machine.getBytes(0xa0000, 0x10000);
> > int i = 0;
> > while (true)
> > vgaBuffer[i++] = 0;
> > }
> > catch (ArrayIndexOutOfBoundsException aioobe)
> > {
> > }
> >
> > basically, don't bother explicitly checking the value of i (like the
> > "for" loop does) since the JVM will be checking it itself anyhow.
>
> I have to comment on this one.
> Please, please, please... don't do that..
> Don't!
> You will make life much harder for an optimizing compiler.
> Constant ranged loops can easily be optimized
> (bounds checking removed, loopunrolling, etc.).
> Please, don't rely on Exception-handling mechanism to handle cases that
> are quite common. Exception handlers should handle exceptions from the
> ordinary,
> things that may take long time.
I guess what "ordinary" is depends on your point of view. The idea
behind that particular trick is that the assignment to the array will be
made without any problem 65536 times and will fail on the 65537th. So
you -could- say that something failing 1/65537th of the time is pretty
uncommon :)
But yeah, a person could always imagine some smart JIT that that trick
would confound - but lacking such a JIT, it's the kind of thing a person
might try in order to get unbearably slow code running a bit faster.
And to be honest, that example was probably unrealistic - it'd be much
better to have some sort of memset() equivalent to fill a range of
bytes.
Barry
(I'm kind of itching now to figure out a way to get jJOS running somehow
so I can play with this stuff)
_______________________________________________
Kernel maillist - [EMAIL PROTECTED]
http://jos.org/mailman/listinfo/kernel