Files

128 lines
7.3 KiB
JSON
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
{
"topic": "gc-deep-dive",
"type": "fill_blank",
"schema_version": "1.0.0",
"generated": "2026-09-03T00:00:00Z",
"questions": [
{
"id": "fb-001",
"type": "fill_blank",
"difficulty": 1,
"tags": ["gc", "memory", "jvm", "three-color-marking", "collections"],
"question": "Python 默认采用的 GC 机制是___计数,而 Java 与 Go 采用的则是从 GC Roots 出发的___分析;Rust 则在编译期通过___所有权机制来管理内存。",
"answer": ["引用计数", "可达性", "所有权"],
"answer_rule": "all",
"explanation": "Python 使用引用计数(配合周期检测器处理循环引用);Java/Go 使用追踪式可达性分析;Rust 依赖编译期的所有权(ownership)和借用规则,无需运行时 GC。",
"source": null,
"related": []
},
{
"id": "fb-002",
"type": "fill_blank",
"difficulty": 1,
"tags": ["gc", "jvm", "memory", "collections"],
"question": "Swift 采用的自动引用计数简称__,它属于___计数类回收机制而非追踪式 GC。",
"answer": ["ARC", "引用"],
"answer_rule": "all",
"explanation": "Swift 的 ARC(Automatic Reference Counting)在编译期插入 retain/release,是一种引用计数式方案,与 Java/Go 的追踪式 GC 不同。",
"source": null,
"related": []
},
{
"id": "fb-003",
"type": "fill_blank",
"difficulty": 2,
"tags": ["gc", "jvm", "memory", "collections"],
"question": "JVM 进行垃圾回收时所有业务线程必须暂停,这一现象缩写作 ___;STW 之外,GC 带来的主要副产品还包括额外的内存开销,通常约为堆的 ___%。",
"answer": ["STW", "5%到20%"],
"answer_rule": "all",
"explanation": "STW = Stop-The-World,指 GC 期间暂停用户线程;追踪式 GC 通常额外占用 5%~20% 的堆内存(如对象头标记、卡片表、缓冲等)。",
"source": null,
"related": []
},
{
"id": "fb-004",
"type": "fill_blank",
"difficulty": 2,
"tags": ["gc", "memory", "collections"],
"question": "针对内存碎片治理,标记-清除完成后可继续压缩以提高熵密度;另一种思路是___算法把存活对象复制到另一块连续区域;G1 等现代回收器则采用按 ___ 划分 Region 的自适应方式。",
"answer": ["复制", "区域"],
"answer_rule": "all",
"explanation": "复制(copying)算法从一块空间复制存活对象到另一块以消除碎片;分代/区域式采用自适应的复制与晋升策略管理碎片。",
"source": null,
"related": []
},
{
"id": "fb-005",
"type": "fill_blank",
"difficulty": 2,
"tags": ["gc", "jvm", "memory", "collections"],
"question": "经典 HotSpot 新生代内存被划分为三个区,默认占比为 Eden 占 80%、存活区 S0 与 S1 各占 ___%;对象经历一次 Minor GC 后年龄加 1,达到晋升阈值默认值 ___ 时被提升至老年代。",
"answer": ["10%", "15"],
"answer_rule": "all",
"explanation": "默认 Eden(80%)/S0(10%)/S1(10%),晋升阈值 -XX:MaxTenuringThreshold 默认 15,对象年龄达到即晋升到老年代。",
"source": null,
"related": []
},
{
"id": "fb-006",
"type": "fill_blank",
"difficulty": 3,
"tags": ["gc", "jvm", "memory", "collections"],
"question": "CMS 垃圾回收器(旧)采用标记-清除,大致经历四个阶段;而 G1 不再沿用固定分区,而是把堆划分为等大小的 ___ 来承载新生代/老年代;ZGC 则使用 ___ 来快速记录对象状态以支撑极低的暂停。",
"answer": ["Region", "染色指针"],
"answer_rule": "all",
"explanation": "G1(Garbage First)把堆抽象地划分成若干等大小 Region;ZGC 采用了染色指针(colored pointers)将部分状态编码在地址指针上,实现极低延迟。",
"source": null,
"related": []
},
{
"id": "fb-007",
"type": "fill_blank",
"difficulty": 4,
"tags": ["gc", "jvm", "memory", "three-color-marking", "collections"],
"question": "三色标记法中:灰色表示对象已被扫描但其若干子对象还未遍历完,白色表示___候选,黑色表示已全部处理完成;若某存活对象在所有引用恢复之后仍被标成白色,则发生了漏标,需满足两个条件。",
"answer": ["待回收", "漏标"],
"answer_rule": "all",
"explanation": "三色标记:白=未访问(潜在垃圾候选)、灰=已访问但子对象未完、黑=子对象已全处理。并发标记时需要满足条件之一(增量更新或 SATB)来避免漏标。",
"source": null,
"related": []
},
{
"id": "fb-008",
"type": "fill_blank",
"difficulty": 4,
"tags": ["gc", "jvm", "memory", "collections"],
"question": "在增量更新的三色标记中,防止存活对象被误回收(漏标)需要同时满足两个条件:在垃圾收集器标记期间,某对象字段上的新指针必须记录到当前视图,并且该对象本身必须属于___(已被标记)集合。G1 默认采用基于栈的 ___ 快照来记录这些变化。",
"answer": ["灰色", "SATB"],
"answer_rule": "all",
"explanation": "漏标的两条件:①对某字段写入一个新引用(引用替换);②在抛弃的旧引用被记录前回收前,该对象已被标记过。G1 采用 SATB(增量式)保存开始时快照并记录变化,保证不漏标。",
"source": null,
"related": []
},
{
"id": "fb-009",
"type": "fill_blank",
"difficulty": 5,
"tags": ["gc", "jvm", "memory", "three-color-marking", "collections"],
"question": "三色标记中的“漏标”指存活对象被错误当作白色从而被回收冻结的 bug。避免漏标需要两个条件同时成立:①某白色对象被(已被标记的)黑色对象引用(即写入了新引用);②在该黑色对象的新引用被记录(额外扫描机会)之前,其旧引用已被收集器丢弃。若破坏其中任一条件即可避免漏标,CMS 使用___更新,G1 采用“起始于快照”(___)策略。",
"answer": ["增量", "SATB"],
"answer_rule": "all",
"explanation": "防止漏标的两策略:增量更新(CMS,把被修改对象的灰色标记重新传播)与 SATB(Snapshot-at-the-Beginning,G1,记录并发开始的引用快照)。",
"source": null,
"related": []
},
{
"id": "fb-010",
"type": "fill_blank",
"difficulty": 5,
"tags": ["gc", "jvm", "memory", "three-color-marking", "collections"],
"question": "进行可达性分析的垃圾回收时,标记阶段从若干被外部持有的根(Roots)出发,主要根类型包括:Java 虚拟机栈中帧局部的局部变量/参数、___中的静态对象、JNI 本地/全局引用、运行时常量池中的对象等。",
"answer": ["方法区或堆中静态引用域"],
"answer_rule": "all",
"explanation": "GC Roots 的典型成员:栈帧局部变量表、方法区静态字段/引用、JNI 引用、运行时常量池里的字符串等。此处提供“方法区/堆静态引用”类答案。",
"source": null,
"related": []
}
]
}