Annotations and Java's hotspot compiler

Annotations can be used to speed up java.

A lot of people may try to murder me for this suggestion, but I believe Princec mentioned this in another thread but it never took off, conversation wise anyway.

The ability to manipulate the hotspot compiler using annotations in the code.

What this could mean?
Removal of bounds checking on arrays in loops, in collections, in methods and classes.

IE: “Object[] a = new Object[4096]; @bounds_removal

or


Object[] stuff = new Object[4096];
....
@remove_bounds
public Object findObject(long id, String name, etc ...)
{
    Object hnd = null;
    ....
    return hnd;
}

At this moment it’s the only thing I can come up with.
However the power of annotations could be expanded, the beauty of this is that newcomers to Java don’t need to know this stuff, nor will they be taught this stuff at low levels.

The benefits would outweigh the pains.
After you’ve finished your game or application you would profile it.
You would visit the hotspots and do standard code optimisations on it, however even after you have visited every hotspot you may decide that there are areas where further improvements would be extremely beneficial as a whole.
In those areas are where developers will gain the advantage of using annotations to create hints for the hotspot compiler.

What do you guys think? Is this a great idea or am I just a paranoid delusional power user?

In your example you use code to give a hint to the VM that it should become unsafe in order to get some performance boost. This is just not possible for java. The VM should always decide when and where it’s safe to remove bounds checks, not the programmer, or else you throw one of java’s most important features out of the window which is safety.
This will never happen. If you don’t want bounds checks, use a native compiler (you can disable bounds checking in GCJ), or use C/C++.
Personally, I don’t think using an aot compiler is worth it just for the tiny performance boost you might get from disabled bounds checks.

Second thought :slight_smile:
Maybe such a hint should not cause the VM to blindly disable bounds checks, but immediately at load time start investigating the code to see if it’s safe to do so. This could maybe improve warm-up behaviour somewhat (not run-time performance), although I have no idea how much, or if it’ll even be worthwhile. But worth some more thought maybe.

I reckon annotations would be a great way of introducing mapped objects (“structs”).

Cas :slight_smile: