Skip to main content

Complete Loop Elimination

7 replies [Last post]
jeremygwa
Offline
Joined: 2006-01-17
Points: 0

An Idea....is it possible?

suppose I can programmatically compile java code, and store in memory ..*not disk*?
when a method contains a loop, during first execution, copy contents of loop into string
then compile programmatically the string into memory.
when that same method is called the second time, it is replaced by the newly compiled method, which
-has no loop.
-may have no need for array element, in which would reuse objects.
-if it was an array we were performing on, check array size, before attempting to use the memory copy.

would this be known as caching?
how about, loop memoization. ....is this already fully done by the JIT - eg loop unrolling?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
ahabra
Offline
Joined: 2004-01-13
Points: 0

I do not understand what are you trying to acheive.
Can you please give a very simple example of such a loop and what do you want to cache.

linuxhippy
Offline
Joined: 2004-01-07
Points: 0

yes some more explanation would be great. I also have problems understanding what you try to archive :-/

jeremygwa
Offline
Joined: 2006-01-17
Points: 0

eg.
[code]
void method () {
for(int i=0;i {
array[i] =... //perform on array
... // do something else, like a graphics paint, or other logic.
}

}
[/code]
when method is done executing and it is called again, i would like to eliminate the loop, just perform the content/body. if the array changes size, re-loop....

so we need a cached "method" with no loop that is generated by the "method" that has a loop.

so I will need to compile the body as a string, and store the method in memory..if possible.

I will need to be able to override the original "method", if a condition has not changed, (array.length)......if the condition has changed, I would like to be able to execute the original "method", not the generated one.

I would also like the cached "method" and the original "method",to have no difference in name or arguments.

I am just wondering if all this is really necessary, if it is true that loop unrolling performed by the JIT, does all this?

-Jer A.

linuxhippy
Offline
Joined: 2004-01-07
Points: 0

> I am just wondering if all this is really necessary,
> if it is true that loop unrolling performed by the
> JIT, does all this?
Basically yes. I wonder why you want to solve problems you don't have.
Believe me you waste your time since you solve problems that do not exist - deisgn carefully and when done use a profiler.

lg Clemens

jeremygwa
Offline
Joined: 2006-01-17
Points: 0

is it necessary to use exception terminated loops as an performance enhancement, or does the JIT do it.

eg.
[code]
try {
for(int i=0;;i++)
{
...
}
} catch (ArrayIndexOutOfBoundsException e){}
[/code]

I have been reading O'reilly's "Java Performance Tuning, 2nd Edition". How much of these optimizations can I really use, that would make a difference?

-Jer A.

linuxhippy
Offline
Joined: 2004-01-07
Points: 0

do you have actual problems or is it just for fun?
If its not for fun you're clearly wasting your time.

http://developers.sun.com/learning/javaoneonline/2005/coreplatform/TS-32...

alexlamsl
Offline
Joined: 2004-09-02
Points: 0

You can use the Compiler API in JavaSE 6 to do what you want.

Depending on the scenario, generating code snipplets on the fly might do good performance-wise. The closest analogy I can think of is java.util.regex.Pattern.compile()