Skip to content

fix(ModLaunch): 修复使用JAVA7及更早版本时,未设置永久代内存导致游戏频繁内存溢出崩溃的问题#2637

Closed
MegaWall3 wants to merge 1 commit intoPCL-Community:devfrom
MegaWall3:dev
Closed

fix(ModLaunch): 修复使用JAVA7及更早版本时,未设置永久代内存导致游戏频繁内存溢出崩溃的问题#2637
MegaWall3 wants to merge 1 commit intoPCL-Community:devfrom
MegaWall3:dev

Conversation

@MegaWall3
Copy link

@MegaWall3 MegaWall3 commented Mar 23, 2026

Java 7 及更早版本使用永久代 (PermGen)​ 存储类元数据,其大小固定(默认约64-128MB),而往后的 Java 8 用元空间 (Metaspace)​ 替代了 PermGen,可自动扩展。

在使用Java7游玩1.6.4老版本怀旧时,频繁出现"java.lang.OutOfMemoryError: PermGen space"错误致客户端崩溃。

该PR永久修复了此问题,当检测到用户选择了老版本Java时,如果用户未指定这个参数,自动添加了PermGen参数,扩充预分配的内存额度。

在官方版提交完发现这里也有这个问题=v=

Summary by Sourcery

在使用旧版 Java 启动 Minecraft 实例时,确保正确配置 JVM 内存设置,以防止与 PermGen 相关的崩溃。

Bug 修复:

  • 当用户未显式设置时,对 Java 7 及更早版本自动配置 PermGen 内存选项,以避免在游戏启动过程中出现 OutOfMemoryError: PermGen space

增强功能:

  • 记录 PermGen 选项是被自动添加还是由于用户自定义设置而跳过,以便提供更完善的启动诊断信息。
Original summary in English

Summary by Sourcery

Ensure proper JVM memory configuration when launching Minecraft instances with older Java versions to prevent PermGen-related crashes.

Bug Fixes:

  • Automatically configure PermGen memory options for Java 7 and earlier when not explicitly set by the user to avoid OutOfMemoryError: PermGen space during game launch.

Enhancements:

  • Log whether PermGen options were auto-added or skipped due to user-defined settings for better launch diagnostics.

@pcl-ce-automation pcl-ce-automation bot added 🛠️ 等待审查 Pull Request 已完善,等待维护者或负责人进行代码审查 size: XS PR 大小评估:微型 labels Mar 23, 2026
@sourcery-ai
Copy link

sourcery-ai bot commented Mar 23, 2026

审阅者指南(在小型 PR 上折叠)

审阅者指南

在使用 Java 7 或更早版本启动 Minecraft 时自动添加 PermGen JVM 选项,以防止 PermGen 空间 OutOfMemory 错误,同时尊重用户已指定的 PermGen 设置并记录相关行为。

带条件 PermGen 选项的 Minecraft 启动时序图

sequenceDiagram
    actor User
    participant Launcher
    participant JavaInstallation
    participant JVM

    User->>Launcher: StartMinecraftInstance()
    Launcher->>JavaInstallation: Get MajorVersion
    JavaInstallation-->>Launcher: MajorVersion

    Launcher->>Launcher: Initialize DataList with base JVM args
    alt MajorVersion <= 7
        Launcher->>Launcher: Check DataList for PermSize or MaxPermSize
        alt No existing PermGen options
            Launcher->>Launcher: DataList.Add -XX:PermSize=128m
            Launcher->>Launcher: DataList.Add -XX:MaxPermSize=256m
            Launcher->>Launcher: McLaunchLog auto added PermGen options
        else User already set PermGen options
            Launcher->>Launcher: McLaunchLog skip auto add
        end
    else MajorVersion > 7
        Launcher->>Launcher: Do not modify PermGen options
    end

    Launcher->>Launcher: Add -Djava.library.path
    Launcher->>Launcher: Add -cp ${classpath}
    Launcher->>JVM: Launch with DataList arguments
    JVM-->>User: Run Minecraft instance
Loading

文件级变更

变更 详情 文件
当使用 Java 7 或更早版本且用户未显式设置时,自动配置 PermGen JVM 选项,并记录日志。
  • 在计算完 -Xmn 和 -Xmx 之后,检测所选 Java 运行时的主版本号是否为 7 或更低。
  • 如果运行在 Java 7 或更早版本上,并且现有 JVM 参数中不包含 -XX:PermSize 或 -XX:MaxPermSize,则在 JVM 参数列表末尾追加 -XX:PermSize=128m 和 -XX:MaxPermSize=256m。
  • 当自动添加 PermGen 参数时记录一条日志消息,其中包括检测到的 Java 主版本号。
  • 如果 JVM 参数中已经存在 PermGen 选项,则跳过自动注入,并记录正在尊重用户自定义值的日志。
Plain Craft Launcher 2/Modules/Minecraft/ModLaunch.vb

技巧与命令

与 Sourcery 交互

  • 触发一次新的审阅: 在 pull request 中评论 @sourcery-ai review
  • 继续讨论: 直接回复 Sourcery 的审阅评论。
  • 从审阅评论生成 GitHub issue: 在审阅评论下回复,请求 Sourcery 从该评论创建一个 issue。你也可以在审阅评论下回复 @sourcery-ai issue 来从该评论创建 issue。
  • 生成 pull request 标题: 在 pull request 标题中的任意位置写上 @sourcery-ai,即可随时生成标题。你也可以在 pull request 中评论 @sourcery-ai title 来(重新)生成标题。
  • 生成 pull request 摘要: 在 pull request 正文中的任意位置写上 @sourcery-ai summary,即可在你希望的位置生成 PR 摘要。你也可以在 pull request 中评论 @sourcery-ai summary 来在任意时间(重新)生成摘要。
  • 生成审阅者指南: 在 pull request 中评论 @sourcery-ai guide,即可在任意时间(重新)生成审阅者指南。
  • 解决所有 Sourcery 评论: 在 pull request 中评论 @sourcery-ai resolve,以解决所有 Sourcery 评论。如果你已经处理完所有评论且不想再看到它们,这会很有用。
  • 关闭所有 Sourcery 审阅: 在 pull request 中评论 @sourcery-ai dismiss,以关闭所有现有的 Sourcery 审阅。特别适用于你想从头开始新一轮审阅的情况——别忘了再评论 @sourcery-ai review 以触发新的审阅!

自定义你的体验

访问你的 仪表盘 来:

  • 启用或禁用审阅功能,例如 Sourcery 生成的 pull request 摘要、审阅者指南等。
  • 更改审阅语言。
  • 添加、移除或编辑自定义审阅指令。
  • 调整其他审阅设置。

获取帮助

Original review guide in English
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adds automatic PermGen JVM options when launching Minecraft with Java 7 or earlier to prevent PermGen space OutOfMemory errors, while respecting any user-specified PermGen settings and logging the behavior.

Sequence diagram for Minecraft launch with conditional PermGen options

sequenceDiagram
    actor User
    participant Launcher
    participant JavaInstallation
    participant JVM

    User->>Launcher: StartMinecraftInstance()
    Launcher->>JavaInstallation: Get MajorVersion
    JavaInstallation-->>Launcher: MajorVersion

    Launcher->>Launcher: Initialize DataList with base JVM args
    alt MajorVersion <= 7
        Launcher->>Launcher: Check DataList for PermSize or MaxPermSize
        alt No existing PermGen options
            Launcher->>Launcher: DataList.Add -XX:PermSize=128m
            Launcher->>Launcher: DataList.Add -XX:MaxPermSize=256m
            Launcher->>Launcher: McLaunchLog auto added PermGen options
        else User already set PermGen options
            Launcher->>Launcher: McLaunchLog skip auto add
        end
    else MajorVersion > 7
        Launcher->>Launcher: Do not modify PermGen options
    end

    Launcher->>Launcher: Add -Djava.library.path
    Launcher->>Launcher: Add -cp ${classpath}
    Launcher->>JVM: Launch with DataList arguments
    JVM-->>User: Run Minecraft instance
Loading

File-Level Changes

Change Details Files
Automatically configure PermGen JVM options for Java 7 and earlier when not explicitly set by the user, with logging.
  • After computing -Xmn and -Xmx, detect if the selected Java runtime has a major version of 7 or below.
  • If running on Java 7 or earlier and no existing JVM argument contains -XX:PermSize or -XX:MaxPermSize, append -XX:PermSize=128m and -XX:MaxPermSize=256m to the JVM argument list.
  • Log a message when PermGen parameters are auto-added, including the detected Java major version.
  • If PermGen options are already present in the JVM arguments, skip auto-injection and log that user-defined values are being respected.
Plain Craft Launcher 2/Modules/Minecraft/ModLaunch.vb

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - 我在这里给出了一些总体反馈:

  • 硬编码的 -XX:PermSize=128m-XX:MaxPermSize=256m 配置可能不适用于所有内存设置;建议根据所选 RAM 进行推导(类似于 -Xmx/-Xmn),或者将这些值集中为可配置常量。
  • 当前检测已有 PermGen 选项的方式是对完整参数字符串使用 Contains,在某些边缘场景下可能会产生误报;建议更严格地匹配参数键(例如使用相等判断,或检查 -XX:PermSize= / -XX:MaxPermSize= 前缀)。
供 AI 代理使用的提示词
Please address the comments from this code review:

## Overall Comments
- The hardcoded `-XX:PermSize=128m` and `-XX:MaxPermSize=256m` values might not suit all memory configurations; consider deriving them from the selected RAM (similar to `-Xmx`/`-Xmn`) or centralizing them as configurable constants.
- The detection of existing PermGen options uses `Contains` on the full argument string, which could give false positives in edge cases; consider matching the argument key more strictly (e.g., equality or prefix check with `-XX:PermSize=` / `-XX:MaxPermSize=`).

Sourcery 对开源项目是免费的——如果你觉得我们的代码评审有帮助,欢迎分享 ✨
帮我变得更有用!请对每条评论点 👍 或 👎,我会根据你的反馈改进后续评审。
Original comment in English

Hey - I've left some high level feedback:

  • The hardcoded -XX:PermSize=128m and -XX:MaxPermSize=256m values might not suit all memory configurations; consider deriving them from the selected RAM (similar to -Xmx/-Xmn) or centralizing them as configurable constants.
  • The detection of existing PermGen options uses Contains on the full argument string, which could give false positives in edge cases; consider matching the argument key more strictly (e.g., equality or prefix check with -XX:PermSize= / -XX:MaxPermSize=).
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The hardcoded `-XX:PermSize=128m` and `-XX:MaxPermSize=256m` values might not suit all memory configurations; consider deriving them from the selected RAM (similar to `-Xmx`/`-Xmn`) or centralizing them as configurable constants.
- The detection of existing PermGen options uses `Contains` on the full argument string, which could give false positives in edge cases; consider matching the argument key more strictly (e.g., equality or prefix check with `-XX:PermSize=` / `-XX:MaxPermSize=`).

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link
Member

@MoYuan-CN MoYuan-CN left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

参考上方 Sourcery Review 内容
另外,你需要对 Git 提交进行签名,请参考 GPG Key 完全配置指南,并对已有的提交重新签名后 Force-Push 到你的分支

@MegaWall3 MegaWall3 requested a review from MoYuan-CN March 24, 2026 03:23
@MegaWall3
Copy link
Author

AI审查水平不佳 未遵循KISS原则 过度设计不符合工程实践

1.永久代内存主要存储类元数据,分配多少取决于扩展多少Mod,与总分配内存无关,且128M相比JAVA7硬编码值扩大一倍,最大256M存在扩展性,完全合理。

2.JVM参数大小写敏感,且无相似易混淆的其他参数,边缘场景不存在,无实际意义。

另外,此代码由 Claude 高阶模型生成,建议 Reviewer 关注业务逻辑本身,而非盲从免费 AI 生成的泛化建议。

Copy link
Member

@LinQingYuu LinQingYuu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/PCL-Community/PCL-CE/wiki/%E5%BC%80%E5%8F%91%E6%8C%87%E5%8D%97#git-%E6%8F%90%E4%BA%A4%E7%AD%BE%E5%90%8D

请使用 SSH 或 GPG Key 对提交进行签名,并确保在 GitHub 账户上添加了对应公钥

@ruattd
Copy link
Contributor

ruattd commented Mar 24, 2026

  1. PCL CE 正常情况下会遵循版本 JSON 的 JVM 参数声明,直接为特殊需求的整合包添加特殊的 JVM 参数声明是解决某些可能情况下永久代空间不足的正确做法(事实上有的整合包就是这么做的),若旧版本由于某些原因没有遵循,这是一个问题,但目前并没有发现这个问题,且这个 PR 很明显与该问题无关
  2. 若非整合包,此类问题也应当由用户自行解决(即自行对实例添加额外 JVM 参数),不应由启动器硬编码,即便要让启动器自动加,也必须给出适当的配置项,以防止其不适用于可能存在的意外情况
  3. 不管站在什么角度上,我们不接受提交者甚至不愿意尝试理解 AI 究竟添加了什么行为及副作用的贡献,首先这是 AI 的贡献,其次代码质量大多数情况下不过关,会浪费开发者 review 的时间
  4. 签名问题,已由其他开发者提及,不多赘述

@ruattd ruattd closed this Mar 24, 2026
@pcl-ce-automation pcl-ce-automation bot removed 🛠️ 等待审查 Pull Request 已完善,等待维护者或负责人进行代码审查 size: XS PR 大小评估:微型 labels Mar 24, 2026
@ruattd
Copy link
Contributor

ruattd commented Mar 24, 2026

欢迎修复上述问题之后再次发起 PR,但十分不建议尝试使用 AI 添加配置项等相关更改

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.

4 participants