Skip to content

[Feature] Enable CDS support - #153

Open
sendaoYan wants to merge 1 commit into
bytedance:jdk17u-target8from
sendaoYan:support-cds
Open

[Feature] Enable CDS support#153
sendaoYan wants to merge 1 commit into
bytedance:jdk17u-target8from
sendaoYan:support-cds

Conversation

@sendaoYan

@sendaoYan sendaoYan commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Fix CDS (Class Data Sharing) to work correctly when the JDK17 VM is compiled with --with-hotspot-target-classlib=8 (JDK8 class library).

Issue: #150

背景

CompoundVM 项目使用 JDK17 HotSpot VM + JDK8 类库的混合构建(--with-hotspot-target-classlib=8)。在此构建模式下,JDK8 没有模块化的 lib/modules jimage 文件,而 JDK17 的 CDS 实现在多处假定该文件一定存在,导致 -Xshare:dump 失败并报错 "CDS is not supported in exploded JDK build"。

修改概要

共修改 7 个 C++ 文件 + 1 个 Java 文件:

  1. CDS 核心适配(classLoader / filemap / arguments)

JDK17 CDS 代码中有多处检查 has_jimage() 和 has_jrt_entry() 的地方,这些检查对 JDK9+ 模块化构建是正确的,但对 JDK8 类库构建不适用。修改策略:用 #if !defined(HOTSPOT_TARGET_CLASSLIB) || HOTSPOT_TARGET_CLASSLIB >= 9 守卫这些检查点,使它们在 classlib=8 时被跳过。

具体改动包括:

  • CDS dump 时的 jimage 检查(3 处 vm_exit / fail_continue)
  • CDS dump 时的 has_jrt_entry() 断言(record_result() / classLoader_init2())
  • Boot classpath index 范围适配(classlib 8 下从 i >= 0 开始,因为没有 index 0 的 jrt_entry)
  • CDS shared path table 构造:用 get_first_append_entry() 替代 get_jrt_entry() 作为 boot classpath 遍历起点
  • skip_first_path_entry():classlib 8 下无需跳过 modules image
  • Archive 验证阶段的多处 shared_path(0)->is_modules_image() 断言守卫
  1. CDS helper 函数适配(classLoader.inline.hpp)
  • num_boot_classpath_entries(): classlib 8 下计数从 0 开始(无 jrt_entry 计入)
  • get_next_boot_classpath_entry(): classlib 8 下无需 jrt -> append 桥接
  1. CDS dump 输出兼容(arguments.cpp / archiveUtils.cpp)
  • -Xshare:dump 时自动启用 log_info(cds) 输出到 stdout,使JDK8兼容的进度信息(如 "Loading classes to share")可见
  • DumpRegion::print() 日志级别从 log_debug 提升至 log_info
  • 修复格式字符串 "%-3s space:" -> "%s space:",消除多余空格
  1. alt_kernel 兼容(Thread.java)
  • 添加 private native boolean isInterrupted(boolean) 方法声明。该方法仅用于 JDK8 libjava.so 中 registerNatives() 的兼容性绑定,不会被实际调用(alt_kernel 的 Thread 使用字段读写方式处理中断状态)。

本地测试验证

如下几个测试在本地已经全部测试通过,没有新增测试失败

  • make -f cvm.mk test_jtreg8_jdk_tier1
  • make -f cvm.mk test_jtreg8_langtools
  • make -f cvm.mk test_jtreg8_hotspot8
  • make -f cvm.mk test_jtreg8_cvm8
  • make -f cvm.mk test_gtest_hotspot17

已知限制

  1. runtime/CDSCompressedKPtrs/CDSCompressedKPtrsError.java用例不适合hotspot8,原因见Problemlist注释
  2. runtime/SharedArchiveFile/LimitSharedSizes.java用例不适合hotsport8,原因见Problemlist注释

Fix CDS (Class Data Sharing) to work correctly when the JDK17 VM is
compiled with --with-hotspot-target-classlib=8 (JDK8 class library).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant