-
Sub-task
-
Resolution: Fixed
-
P3
-
8u40
-
b37
-
generic
-
generic
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8085762 | emb-9 | Attila Szegedi | P3 | Resolved | Fixed | team |
JDK-8064261 | 8u45 | Attila Szegedi | P3 | Resolved | Fixed | b01 |
JDK-8070498 | emb-8u47 | Attila Szegedi | P3 | Resolved | Fixed | team |
asm.js uses the "x|0" idiom to coerce the argument to int32, and the "x>>>0" idiom to coerce the argument to uint32. Currently, nashorn compiles these to
<load x as int>
ICONST_0
IOR
and
<load x as int>
ICONST_0
IUSHR
<convert to uint>
the ICONST_0, IOR|IUSHR are unnecessary. In case "x" is already an int local variable, "x|0" nicely just becomes an ILOAD.
Further, <convert to uint> is currently implemented by emitting
I2L
LDC 0xFFFF_FFFFL
LAND
which is 5 bytes long. Encapsulating it in "long JSType.uint32(int)" would result in it needing only 3 bytes for INVOKESTATIC.
Using both these optimizations, we can translate x>>>0 for an already int variable from
ILOAD x
ICONST_0
IUSHR
I2L
LDC 0xFFFF_FFFFL
LAND
to much nicer:
ILOAD x
INVOKESTATIC JSType.toUint32(I)J
For large asm.js-compliant, emscripten/mandreel generated code the savings in bytecode size for emitted methods can be quite significant, e.g. "function a8" in zlib got reduced from ~6400 bytes to ~6000.
<load x as int>
ICONST_0
IOR
and
<load x as int>
ICONST_0
IUSHR
<convert to uint>
the ICONST_0, IOR|IUSHR are unnecessary. In case "x" is already an int local variable, "x|0" nicely just becomes an ILOAD.
Further, <convert to uint> is currently implemented by emitting
I2L
LDC 0xFFFF_FFFFL
LAND
which is 5 bytes long. Encapsulating it in "long JSType.uint32(int)" would result in it needing only 3 bytes for INVOKESTATIC.
Using both these optimizations, we can translate x>>>0 for an already int variable from
ILOAD x
ICONST_0
IUSHR
I2L
LDC 0xFFFF_FFFFL
LAND
to much nicer:
ILOAD x
INVOKESTATIC JSType.toUint32(I)J
For large asm.js-compliant, emscripten/mandreel generated code the savings in bytecode size for emitted methods can be quite significant, e.g. "function a8" in zlib got reduced from ~6400 bytes to ~6000.
- backported by
-
JDK-8064261 asm.js idioms result in unnecessarily code emission
-
- Resolved
-
-
JDK-8070498 asm.js idioms result in unnecessarily code emission
-
- Resolved
-
-
JDK-8085762 asm.js idioms result in unnecessarily code emission
-
- Resolved
-