Re: Bugs at my web site

From: glen herrmannsfeldt (gah_at_ugcs.caltech.edu)
Date: 01/21/04


Date: Wed, 21 Jan 2004 09:06:05 GMT

Dr Chaos wrote:

(snip about bounds checking)

> But in Java you can catch the exception caused by the
> array bounds violation---and legally continue execution.

Continue somewhere else, but you can't fixup the failed
subscript and continue. Compare/contrast with the PL/I ON unit,
where you can change variables and return to the cause of the
error.

> This means that an evil subroutine might use this intentionally, and
> in a legal program you would have to expect that all the processing
> right up to that point where the exception was thrown was done and all
> mutable data properly stored.

Yes, you could do that.

> So seeing ahead of time (before entering a loop) if
> an array bounds violation has occured and breaking if it has isn't
> good enough.

> I guess you could conceivably generate double code for every loop, but
> that seems insane.

The only question is for JIT compilers. At least for Java/JVM
the bounds checking is done at run time by the JVM, not by the
Java compiler. Compiling two loops isn't so hard in that case.

It may be able to figure out that bounds cannot be violated.
Consider a constant loop, or a loop with the limit equal to the
array size. That can be tested at JIT time, and the appropriate
code compiled.

> What if you have multiple nested loops whose inner array bounds
> are computed by some formula each time?

Then they get checked the old fashioned way.

> I think Java made a huge blunder by having the bounds
> exception be guaranteed to be catchable.

Java was not meant for number crunching, though with JIT it
is usually fast enough. The slow part of object oriented
programming is memory allocation/deallocation. Number crunching
programs don't do much of that.

> I think that as a violated precondition it is an 'a priori' error and
> shouldn't usually be catchable except in the context of a development
> environment.

The JIT compiler can also test for a try/catch block and only generate
the special two loop code in that case. Without it, bounds violation
is a fatal error. With JIT on, you don't get location information.

-- glen



Relevant Pages

  • Re: optimized code
    ... the Managed C++ compiler should still be better. ... > are left to the JIT. ... I assume the JIT is limited to peephole optimizations? ... If I have an inner loop of something like: ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Speed-up for loops
    ... be nice if you could directly code low-level algorithms in it without ... Are you volunteering to write the JIT ... any real code that would need to be put in a for loop is almost certainly ... going to be too complicated for the JIT compiler to benefit greatly. ...
    (comp.lang.python)
  • Re: Managed vs Unmanaged Bare Bones Performance Test
    ... The reason for the huge difference is that the C++ compiler hoists the loop, as it sees no sensible reason to call an empty function 50000 times, the C# compiler does not do this, it simply calls the function which only contains a ret. ... True for optimized builds, the call is hoisted, but the loop is not hoisted by the JIT, the C++ compiler effectively hoists the loop. ...
    (microsoft.public.dotnet.framework.clr)
  • Re: Interpretor
    ... called (i.e. if you have a loop that calls a function is it interpreted each time?). ... compiled with a Just In Time (JIT) compiler as they are executed -- so a code ... not to be turned into internal threaded interpreted code until ...
    (comp.soft-sys.matlab)
  • Re: Letter to US Sen. Byron Dorgan re unpaid overtime
    ... >> both less efficient and less safe than the Fortran and Basic standard. ... >> The C for loop is actually trying to do what a do loop does. ... sloppy thinking that results from confusing a programming language ... > I do not believe that you are capable of writing a conforming C compiler. ...
    (comp.programming)