I had some Java language ideas recently, and decided to write them up and post to JavaLobby, but as of yet I’ve had no replies. I decided to post it here too:
http://www.javalobby.org/thread.jspa?forumID=152&threadID=10670
I don’t claim to be an expert in this stuff, but here’s some interesting ideas I had. Comments welcome.
By default, “float” should be optimised for performance while “double” should be optimised for accuracy. In other words, since float is typically used for speed, it should be optimised as such by default and since double is most often used when accuracy is crucial, it should be optimised for accuracy by default. Currently, both are optimised for accuracy by default. (I’m sure the HPC guys want more flexible optimisation options for doubles too, but here’s a quick and simple idea I think most people could agree on)
“primative” class modifier: an instance from a “primative” class does not use references, it uses unique pointers. With the code “int c = 1; int d = c;” the variable c is copied to d, in “Object c = new Object(); Object d = c;” variable d becomes a reference to c. With the new primative class, “PrimativeObject c = new PrimativeObject(); PrimativeObject d = c;” copies c to d - creates new object. A decent JVM optimiser would be able to “inline” most uses so that the JVM doesn’t actually need to do object creation/deletion for them. One major use of this class is to have data structures with minimal memory useage (which may require other features of normal objects to be removed from primative objects too). In other words, an array of 1000 primative classes which just had one non-static variable (an “int”) would take up almost exactly as much memory as int[1000] while being much more useful. This would be good for 3D, multi-media and some maths stuff - eg arrays of complex numbers. Could have a special sub-type of “primative class” for numbers which can use numerical operator overloading - eg could do “ComplexNumber c = new ComplexNumber(1, 1); ComplexNumber d = c * c;” (I’m NOT suggesting operator overloading should be allowed in general)
Number formats with SIMD optimisation support: use standard primative classes with operator overloading to define some new standard classes. This would be to help performance and ease of implementation for user code for multimedia apps, particularly 2D graphics processing for some of the more unusual data types. For example, say you have a 2D image (with 24-bit rgb pixels) and want to brighten the image a bit - you can just add 1 to all the rgb values, but if a value is already at 255 (max of 8 bit unsigned) then adding 1 will make it wrap around to 0, which you don’t want (what will happen in Java will depend on what you use for the calcuations - signed ints or signed bytes). Many modern CPUs have SIMD instructions where you can do the add with the checking to prevent wrap-around in just one cycle, for all 3 values (or 4 if you include alpha-channel). If you have standard data types in Java spec for the various types of multi-media number formats, then the JVM can map operations on these to SIMD instructions in CPUs. So if you have “ARGB c = new ARGB(255,255,255,255); ARGB brighten = new ARGB(0,1,1,1); c+= brighten;” then not only is that much simpler than what you’d have to do today, it could be optimised increadibly well, and in a portable way too.