Skip to content

Commit 829eed3

Browse files
committed
java/se: add object layout and add jmh note
1 parent 00a34af commit 829eed3

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

java/javase/javas-jhm/readme.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
## jmh
2+
3+
1. @WarmUp(iterations=1, time=3)
4+
- 预热, 由于存在本地优化, 所以预热很重要: 多次执行 JIT 会优化的
5+
2. @Measurement(iterations=1, time=3)
6+
- 总共执行多少次测试
7+
3. @Timeout
8+
4. @Fork
9+
- 线程数
10+
5. @BenchmarkMode(Mode.Throughput)
11+
- 基准测试的模式
12+
- Throughput: 每秒吞吐量
13+
6. @Benchmark
14+
- 测试的代码段

java/javase/javase-jvm/src/main/java/cn/edu/ntu/javase/jvm/MemoryStruct.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import java.util.ArrayList;
1010
import java.util.HashMap;
1111
import java.util.Map;
12+
import java.util.concurrent.atomic.AtomicLong;
1213
import java.util.stream.IntStream;
1314

1415
/**
@@ -66,6 +67,12 @@ public void testObject() {
6667
log.info(ClassLayout.parseInstance(o).toPrintable());
6768
}
6869

70+
@Test
71+
public void testAtomicLong() {
72+
AtomicLong o = new AtomicLong();
73+
log.info(ClassLayout.parseInstance(o).toPrintable());
74+
}
75+
6976
@Test
7077
public void testPaddedAtomicLong() {
7178
PaddedAtomicLong o = new PaddedAtomicLong();

0 commit comments

Comments
 (0)