[9] RFR (S): 8153540: C2 intrinsic for Unsafe.allocateInstance doesn't properly filter out array classes

Aleksey Shipilev aleksey.shipilev at oracle.com
Fri Apr 8 18:42:14 UTC 2016


On 04/08/2016 07:47 PM, Vladimir Ivanov wrote:
> http://cr.openjdk.java.net/~vlivanov/8153540/webrev.00/hotspot/
> http://cr.openjdk.java.net/~vlivanov/8153540/webrev.00/jdk/
> 
> https://bugs.openjdk.java.net/browse/JDK-8153540
> 
> Unsafe.allocateInstance intrinsic can instantiate arrays, but the
> allocation logic is broken.
> 
> The proposed fix is to perform necessary checks in Java code before
> calling the intrinsic.

I like Java-side fix better.

> I did some performance measurements [1] and reflection (non-constant
> class) case (non-constant class) regressed ~5-10% due to new guards added.

My quick perfasm runs seems to show this is because a subtle difference:
  http://cr.openjdk.java.net/~shade/8153540/baseline.perfasm
  http://cr.openjdk.java.net/~shade/8153540/patched.perfasm

If you compare these, then the difference seems to be the instruction
scheduling and a branch in the guards code.

Baseline:

  0.60%    0.53%    0x00007fafafd34dac: mov    0xc(%rsi),%r10d
  3.43%    4.47%    0x00007fafafd34db0: mov    0x50(%r10),%rsi
  0.30%    0.24%    0x00007fafafd34db4: movzbl 0x172(%rsi),%r8d
  1.40%    2.09%    0x00007fafafd34dbc: mov    0x8(%rsi),%r10d
  0.98%    1.48%    0x00007fafafd34dc0: add    $0xfffffffc,%r8d
  2.71%    4.28%    0x00007fafafd34dc4: mov    %r10d,%r11d
  0.03%    0.04%    0x00007fafafd34dc7: and    $0x1,%r11d
  1.02%    1.41%    0x00007fafafd34dcb: or     %r11d,%r8d
  2.51%    2.49%    0x00007fafafd34dce: test   %r8d,%r8d

Patched:

  0.59%    0.76%   0x00007fd1c4de1c2c: mov    0xc(%rsi),%r11d
  3.48%    3.83%   0x00007fd1c4de1c30: mov    0x50(%r11),%rsi
  0.35%    0.36%   0x00007fd1c4de1c34: mov    0x8(%rsi),%r10d
  1.47%    1.69%   0x00007fd1c4de1c38: test   %r10d,%r10d
                   0x00007fd1c4de1c3b: jl     0x00007fd1c4de1ce5
  1.18%    1.48%   0x00007fd1c4de1c41: movzbl 0x172(%rsi),%r11d
  2.82%    3.93%   0x00007fd1c4de1c49: mov    %r10d,%r9d
  0.01%    0.03%   0x00007fd1c4de1c4c: and    $0x1,%r9d
  0.33%    0.59%   0x00007fd1c4de1c50: add    $0xfffffffc,%r11d
  0.93%    0.92%   0x00007fd1c4de1c54: or     %r9d,%r11d
  2.65%    2.47%   0x00007fd1c4de1c57: test   %r11d,%r11d

Unfortunately, a simple fix of replacing "||" with "|" explodes the
generated code. Maybe something else is doable there.


> [1] http://cr.openjdk.java.net/~vlivanov/8153540/AllocInstance.java

Suggestions to improve fidelity:
  * Run allocation benchmarks with -Xmx1g -Xms1g; this improves variance
  * Add @CompilerControl(CompilerControl.Mode.DONT_INLINE) on
@Benchmarks if you want to use -prof perfasm

Thanks,
-Aleksey


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: OpenPGP digital signature
URL: <http://mail.openjdk.java.net/pipermail/hotspot-compiler-dev/attachments/20160408/f81e2678/signature.asc>


More information about the hotspot-compiler-dev mailing list