LinuxPerfAsmProfiler 显示 Java 代码对应的汇编热点 Java 8,但不显示 Java 14
LinuxPerfAsmProfiler shows Java code corresponding assembly hot spot for Java 8, but not for Java 14
在调查与 Spring 的 org.springframework.util.ConcurrentReferenceHashMap
(从 spring-core-5.1.3.RELEASE
开始)实例化相关的问题时,我使用了与 JMH 一起提供的 LinuxPerfAsmProfiler
来生成配置文件组装.
我只是运行这个
@Benchmark
public Object measureInit() {
return new ConcurrentReferenceHashMap<>();
}
在 JDK 8 上进行基准测试可以识别一个不明显的热点:
0.61% 0x00007f32d92772ea: lock addl [=14=]x0,(%rsp) ;*putfield count
; - org.springframework.util.ConcurrentReferenceHashMap$Segment::<init>@11 (line 476)
; - org.springframework.util.ConcurrentReferenceHashMap::<init>@141 (line 184)
15.81% 0x00007f32d92772ef: mov 0x60(%r15),%rdx
这对应于将默认值不必要地分配给可变字段:
protected final class Segment extends ReentrantLock {
private volatile int count = 0;
}
和 Segment
依次在 CCRHM
:
的构造函数中循环实例化
public ConcurrentReferenceHashMap(
int initialCapacity, float loadFactor, int concurrencyLevel, ReferenceType referenceType) {
this.loadFactor = loadFactor;
this.shift = calculateShift(concurrencyLevel, MAXIMUM_CONCURRENCY_LEVEL);
int size = 1 << this.shift;
this.referenceType = referenceType;
int roundedUpSegmentCapacity = (int) ((initialCapacity + size - 1L) / size);
this.segments = (Segment[]) Array.newInstance(Segment.class, size);
for (int i = 0; i < this.segments.length; i++) {
this.segments[i] = new Segment(roundedUpSegmentCapacity);
}
}
所以这个指令很可能真的很热门。程序集的完整布局可以在我的 gist
中找到
然后我 运行 在 JDK 14 上使用相同的基准并再次使用 LinuxPerfAsmProfiler
,但现在我没有任何明确指向 volatile int count = 0
in captured assembly.
寻找 lock addl [=26=]x0
指令,它是 lock
前缀下 0
的赋值 我发现了这个:
0.08% │ 0x00007f3717d46187: lock addl [=17=]x0,-0x40(%rsp)
23.74% │ 0x00007f3717d4618d: mov 0x120(%r15),%rbx
这很可能对应于 volatile int count = 0
,因为它遵循 Segment
的超类 ReentrantLock
:
的构造函数调用
0.77% │ 0x00007f3717d46140: movq [=18=]x0,0x18(%rax) ;*new {reexecute=0 rethrow=0 return_oop=0}
│ ; - java.util.concurrent.locks.ReentrantLock::<init>@5 (line 294)
│ ; - org.springframework.util.ConcurrentReferenceHashMap$Segment::<init>@6 (line 484)
│ ; - org.springframework.util.ConcurrentReferenceHashMap::<init>@141 (line 184)
0.06% │ 0x00007f3717d46148: mov %r8,%rcx
0.05% │ 0x00007f3717d4614b: mov %rax,%rbx
0.03% │ 0x00007f3717d4614e: shr [=18=]x3,%rbx
0.74% │ 0x00007f3717d46152: mov %ebx,0xc(%r8)
0.06% │ 0x00007f3717d46156: mov %rax,%rbx
0.05% │ 0x00007f3717d46159: xor %rcx,%rbx
0.02% │ 0x00007f3717d4615c: shr [=18=]x14,%rbx
0.72% │ 0x00007f3717d46160: test %rbx,%rbx
╭ │ 0x00007f3717d46163: je 0x00007f3717d4617f
│ │ 0x00007f3717d46165: shr [=18=]x9,%rcx
│ │ 0x00007f3717d46169: movabs [=18=]x7f370a872000,%rdi
│ │ 0x00007f3717d46173: add %rcx,%rdi
│ │ 0x00007f3717d46176: cmpb [=18=]x8,(%rdi)
0.00% │ │ 0x00007f3717d46179: jne 0x00007f3717d46509
0.04% ↘ │ 0x00007f3717d4617f: movl [=18=]x0,0x14(%r8)
0.08% │ 0x00007f3717d46187: lock addl [=18=]x0,-0x40(%rsp)
23.74% │ 0x00007f3717d4618d: mov 0x120(%r15),%rbx
问题是我在生成的程序集中根本没有提到 putfield count
。
谁能解释一下为什么我看不到它?
事实证明,您不能使用为例如构建的 hsdis。 JDK 8 与 JDK 11。为了完美匹配,您需要从 JDK 源构建 hsdis,然后构建 JDK 本身和 运行 应用程序ad-hoc 构建。
当我调查 时,这种方法对我来说非常有效。
在调查与 Spring 的 org.springframework.util.ConcurrentReferenceHashMap
(从 spring-core-5.1.3.RELEASE
开始)实例化相关的问题时,我使用了与 JMH 一起提供的 LinuxPerfAsmProfiler
来生成配置文件组装.
我只是运行这个
@Benchmark
public Object measureInit() {
return new ConcurrentReferenceHashMap<>();
}
在 JDK 8 上进行基准测试可以识别一个不明显的热点:
0.61% 0x00007f32d92772ea: lock addl [=14=]x0,(%rsp) ;*putfield count
; - org.springframework.util.ConcurrentReferenceHashMap$Segment::<init>@11 (line 476)
; - org.springframework.util.ConcurrentReferenceHashMap::<init>@141 (line 184)
15.81% 0x00007f32d92772ef: mov 0x60(%r15),%rdx
这对应于将默认值不必要地分配给可变字段:
protected final class Segment extends ReentrantLock {
private volatile int count = 0;
}
和 Segment
依次在 CCRHM
:
public ConcurrentReferenceHashMap(
int initialCapacity, float loadFactor, int concurrencyLevel, ReferenceType referenceType) {
this.loadFactor = loadFactor;
this.shift = calculateShift(concurrencyLevel, MAXIMUM_CONCURRENCY_LEVEL);
int size = 1 << this.shift;
this.referenceType = referenceType;
int roundedUpSegmentCapacity = (int) ((initialCapacity + size - 1L) / size);
this.segments = (Segment[]) Array.newInstance(Segment.class, size);
for (int i = 0; i < this.segments.length; i++) {
this.segments[i] = new Segment(roundedUpSegmentCapacity);
}
}
所以这个指令很可能真的很热门。程序集的完整布局可以在我的 gist
中找到然后我 运行 在 JDK 14 上使用相同的基准并再次使用 LinuxPerfAsmProfiler
,但现在我没有任何明确指向 volatile int count = 0
in captured assembly.
寻找 lock addl [=26=]x0
指令,它是 lock
前缀下 0
的赋值 我发现了这个:
0.08% │ 0x00007f3717d46187: lock addl [=17=]x0,-0x40(%rsp)
23.74% │ 0x00007f3717d4618d: mov 0x120(%r15),%rbx
这很可能对应于 volatile int count = 0
,因为它遵循 Segment
的超类 ReentrantLock
:
0.77% │ 0x00007f3717d46140: movq [=18=]x0,0x18(%rax) ;*new {reexecute=0 rethrow=0 return_oop=0}
│ ; - java.util.concurrent.locks.ReentrantLock::<init>@5 (line 294)
│ ; - org.springframework.util.ConcurrentReferenceHashMap$Segment::<init>@6 (line 484)
│ ; - org.springframework.util.ConcurrentReferenceHashMap::<init>@141 (line 184)
0.06% │ 0x00007f3717d46148: mov %r8,%rcx
0.05% │ 0x00007f3717d4614b: mov %rax,%rbx
0.03% │ 0x00007f3717d4614e: shr [=18=]x3,%rbx
0.74% │ 0x00007f3717d46152: mov %ebx,0xc(%r8)
0.06% │ 0x00007f3717d46156: mov %rax,%rbx
0.05% │ 0x00007f3717d46159: xor %rcx,%rbx
0.02% │ 0x00007f3717d4615c: shr [=18=]x14,%rbx
0.72% │ 0x00007f3717d46160: test %rbx,%rbx
╭ │ 0x00007f3717d46163: je 0x00007f3717d4617f
│ │ 0x00007f3717d46165: shr [=18=]x9,%rcx
│ │ 0x00007f3717d46169: movabs [=18=]x7f370a872000,%rdi
│ │ 0x00007f3717d46173: add %rcx,%rdi
│ │ 0x00007f3717d46176: cmpb [=18=]x8,(%rdi)
0.00% │ │ 0x00007f3717d46179: jne 0x00007f3717d46509
0.04% ↘ │ 0x00007f3717d4617f: movl [=18=]x0,0x14(%r8)
0.08% │ 0x00007f3717d46187: lock addl [=18=]x0,-0x40(%rsp)
23.74% │ 0x00007f3717d4618d: mov 0x120(%r15),%rbx
问题是我在生成的程序集中根本没有提到 putfield count
。
谁能解释一下为什么我看不到它?
事实证明,您不能使用为例如构建的 hsdis。 JDK 8 与 JDK 11。为了完美匹配,您需要从 JDK 源构建 hsdis,然后构建 JDK 本身和 运行 应用程序ad-hoc 构建。
当我调查