Please review JDK-8017010
Marcus Lagergren
marcus.lagergren at oracle.com
Mon Mar 25 02:50:16 PDT 2013
http://cr.openjdk.java.net/~lagergren/8017010/
In a self modifying store, when we have compound index operators, where the index calculation requires a temporary storage, e.g. a[x+y+z] (in this case two temporary storages), these have to be forced to be bytecode local variables. Otherwise they cannot be reused properly on the stack for the self modifying expression's intermediate result.
It turned out that if we have the very simple case
function f() {
for(j=0;j<100;j++) {
whatever += array[j];
}
}
broke, because it forced j to a slot, even though it very much should be scope here.
Only temporaries that have to be brought out in the middle of the index calculation needs to be local vars - otherwise scope is fine - calculation is done outside and has the same effect, stack wise.
It should be noted that the above function is less performant javascript than this:
function f() {
for(var j=0;j<100;j++) {
whatever += array[j];
}
}
because, seriously, who writes code that intentionally has to put j in memory?
/M
More information about the nashorn-dev
mailing list