.net 9 编译异常 (File: D:\a\_work\1\s\src\coreclr\vm\threads.cpp)

CLR: Assert failure(PID 24664 [0x00006058], Thread: 8860 [0x229c]): !AreShadowStacksEnabled() || UseSpecialUserModeApc()
    File: D:\a\_work\1\s\src\coreclr\vm\threads.cpp:7954 Image:
F:\XXXX\ConsoleApp2\ConsoleApp2\bin\Debug\net9.0\ConsoleApp2.exe

在项目文件中增加节点

<CETCompat>false</CETCompat>

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net9.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <CETCompat>false</CETCompat>
  </PropertyGroup>

# # There is insufficient memory for the Java Runtime Environment to continue. # Native memory allocation (malloc) failed to allocate 952528 bytes. Error detail: Chunk::new # Possible reasons: # The system is out of physical RAM or swap space # This process is running with CompressedOops enabled, and the Java Heap may be blocking the growth of the native heap # Possible solutions: # Reduce memory load on the system # Increase physical memory or swap space # Check if swap backing store is full # Decrease Java heap size (-Xmx/-Xms) # Decrease number of Java threads # Decrease Java thread stack sizes (-Xss) # Set larger code cache with -XX:ReservedCodeCacheSize= # JVM is running with Unscaled Compressed Oops mode in which the Java heap is # placed in the first 4GB address space. The Java Heap base address is the # maximum limit for the native heap growth. Please use -XX:HeapBaseMinAddress # to set the Java Heap base and to place the Java Heap above 4GB virtual address. # This output file may be truncated or incomplete. # # Out of Memory Error (arena.cpp:168), pid=97348, tid=7672 # # JRE version: OpenJDK Runtime Environment JBR-21.0.5+8-631.30-jcef (21.0.5+8) (build 21.0.5+8-b631.30) # Java VM: OpenJDK 64-Bit Server VM JBR-21.0.5+8-631.30-jcef (21.0.5+8-b631.30, mixed mode, sharing, tiered, compressed oops, compressed class ptrs, g1 gc, windows-amd64) # No core dump will be written. Minidumps are not enabled by default on client versions of Windows # --------------- S U M M A R Y ------------ Command Line: abort vfprintf -XX:ErrorFile=C:\Users\h60095350\java_error_in_pycharm_%p.log -XX:HeapDumpPath=C:\Users\h60095350\java_error_in_pycharm.hprof -Xms256m -Xmx2048m -XX:ReservedCodeCacheSize=512m -XX:+HeapDumpOnOutOfMemoryError -XX:-OmitStackTraceInFastThrow -XX:CICompilerCount=2 -XX:+IgnoreUnrecognizedVMOptions -ea -Dsun.io.useCanonCaches=false -Dsun.java2d.metal=true -Djbr.catch.SIGABRT=true -Djdk.http.auth.tunneling.disabledSchemes="" -Djdk.attach.allowAttachSelf=true -Djdk.module.illegalAccess.silent=true -Djdk.nio.maxCachedBufferSize=2097152 -Djava.util.zip.use.nio.for.zip.file.access=true -Dkotlinx.coroutines.debug=off -XX:+UnlockDiagnosticVMOptions -XX:TieredOldPercentage=100000 -Dwelcome.screen.defaultWidth=1000 -Dwelcome.screen.defaultHeight=720 -Dwsl.use.remote.agent.for.nio.filesystem=true -Djava.nio.file.spi.DefaultFileSystemProvider=com.intellij.platform.core.nio.fs.MultiRoutingFileSystemProvider -Djava.security.manager=com.intellij.platform.core.nio.fs.CoreBootstrapSecurityManager -Didea.cycle.buffer.size=4096 -Djb.vmOptionsFile=C:\Users\h60095350\AppData\Roaming\JetBrains\PyCharm2024.3\pycharm64.exe.vmoptions -Djava.system.class.loader=com.intellij.util.lang.PathClassLoader -Didea.vendor.name=JetBrains -Didea.paths.selector=PyCharm2024.3 -Djna.boot.library.path=D:\JetBrains\PyCharm 2024.3.2/lib/jna/amd64 -Dpty4j.preferred.native.folder=D:\JetBrains\PyCharm 2024.3.2/lib/pty4j -Djna.nosys=true -Djna.noclasspath=true -Dintellij.platform.runtime.repository.path=D:\JetBrains\PyCharm 2024.3.2/modules/module-descriptors.jar -Didea.platform.prefix=Python -Dsplash=true -Daether.connector.resumeDownloads=false -Dcompose.swing.render.on.graphics=true --add-opens=java.base/java.io=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.ref=ALL-UNNAMED --add-opens=java.base/java.lang.reflect=ALL-UNNAMED --add-opens=java.base/java.net=ALL-UNNAMED --add-opens=java.base/java.nio=ALL-UNNAMED --add-opens=java.base/java.nio.charset=ALL-UNNAMED --add-opens=java.base/java.text=ALL-UNNAMED --add-opens=java.base/java.time=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.util.concurrent=ALL-UNNAMED --add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED --add-opens=java.base/java.util.concurrent.locks=ALL-UNNAMED --add-opens=java.base/jdk.internal.vm=ALL-UNNAMED --add-opens=java.base/sun.net.dns=ALL-UNNAMED --add-opens=java.base/sun.nio.ch=ALL-UNNAMED --add-opens=java.base/sun.nio.fs=ALL-UNNAMED --add-opens=java.base/sun.security.ssl=ALL-UNNAMED --add-opens=java.base/sun.security.util=ALL-UNNAMED --add-opens=java.desktop/com.sun.java.swing=ALL-UNNAMED --add-opens=java.desktop/java.awt=ALL-UNNAMED --add-opens=java.desktop/java.awt.dnd.peer=ALL-UNNAMED --add-opens=java.desktop/java.awt.event=ALL-UNNAMED --add-opens=java.desktop/java.awt.font=ALL-UNNAMED --add-opens=java.desktop/java.awt.image=ALL-UNNAMED --add-opens=java.desktop/java.awt.peer=ALL-UNNAMED --add-opens=java.desktop/javax.swing=ALL-UNNAMED --add-opens=java.desktop/javax.swing.plaf.basic=ALL-UNNAMED --add-opens=java.desktop/javax.swing.text=ALL-UNNAMED --add-opens=java.desktop/javax.swing.text.html=ALL-UNNAMED --add-opens=java.desktop/sun.awt=ALL-UNNAMED --add-opens=java.desktop/sun.awt.datatransfer=ALL-UNNAMED --add-opens=java.desktop/sun.awt.image=ALL-UNNAMED --add-opens=java.desktop/sun.awt.windows=ALL-UNNAMED --add-opens=java.desktop/sun.font=ALL-UNNAMED --add-opens=java.desktop/sun.java2d=ALL-UNNAMED --add-opens=java.desktop/sun.swing=ALL-UNNAMED --add-opens=java.management/sun.management=ALL-UNNAMED --add-opens=jdk.attach/sun.tools.attach=ALL-UNNAMED --add-opens=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-opens=jdk.internal.jvmstat/sun.jvmstat.monitor=ALL-UNNAMED --add-opens=jdk.jdi/com.sun.tools.jdi=ALL-UNNAMED -Dide.native.launcher=true -Djcef.sandbox.ptr=0000015B99EFEDE0 -Djcef.sandbox.cefVersion=122.1.9+gd14e051+chromium-122.0.6261.94 com.intellij.idea.Main Host: Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz, 12 cores, 31G, Windows 10 , 64 bit Build 19041 (10.0.19041.4717) Time: Wed Aug 20 10:54:06 2025 Windows 10 , 64 bit Build 19041 (10.0.19041.4717) elapsed time: 64.235615 seconds (0d 0h 1m 4s) --------------- T H R E A D --------------- Current thread (0x0000015bc5abdd10): JavaThread "C2 CompilerThread0" daemon [_thread_in_native, id=7672, stack(0x000000093ba00000,0x000000093bb00000) (1024K)] Current CompileTask: C2:64235 41919 4 com.intellij.openapi.editor.impl.view.IterationState::advance (339 bytes) Stack: [0x000000093ba00000,0x000000093bb00000] Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code) V [jvm.dll+0x6e52b9] V [jvm.dll+0x8c3633] V [jvm.dll+0x8c5b8e] V [jvm.dll+0x8c6273] V [jvm.dll+0x288f46] V [jvm.dll+0xc66dd] V [jvm.dll+0xc6c13] V [jvm.dll+0x3c456b] V [jvm.dll+0x3901c7] V [jvm.dll+0x38f63a] V [jvm.dll+0x2507a2] V [jvm.dll+0x24fd71] V [jvm.dll+0x1cd6a4] V [jvm.dll+0x25f5dc] V [jvm.dll+0x25db26] V [jvm.dll+0x3ff5e6] V [jvm.dll+0x86b248] V [jvm.dll+0x6e3abd] C [ucrtbase.dll+0x21bb2] C [KERNEL32.DLL+0x17374] C [ntdll.dll+0x4cc91] com.intellij.diagnostic.JBRCrash
08-21
在提供的代码中,`Test()` 方法包含一个无限循环,该循环对局部变量 `flag` 进行反复取反操作。这种设计会导致线程持续运行而无法退出循环,最终可能引发资源耗尽或程序响应迟缓的问题[^1]。此外,由于该循环没有任何退出条件,它也可能导致程序失去响应或崩溃,尤其是在没有合理线程管理的情况下。 ### 原因分析 1. **死循环导致资源耗尽**:无限循环持续运行,占用大量 CPU 资源,可能导致程序无法正常响应其他任务。 2. **线程管理问题**:通过 `Task.Run` 启动的线程被 `.Wait()` 阻塞,这可能导致线程池资源被占用,进而引发死锁风险。 3. **未处理的异常**:如果循环内部发生异常且未捕获,可能会导致线程终止并引发程序崩溃。 4. **硬件或操作系统限制**:在某些环境下,长时间运行的线程可能会触发操作系统或运行时环境的保护机制,强制终止进程。 ### 解决方法 1. **避免死循环**: - 为循环添加退出条件,例如通过外部信号或计数器控制循环终止。 - 示例修改代码: ```csharp static void Test() { var flag = true; int iteration = 0; while (iteration < 1000000) // 添加迭代次数限制 { flag = !flag; iteration++; } } ``` 2. **合理管理线程**: - 避免在主线程中直接使用 `.Wait()`,可以考虑使用 `async/await` 来避免阻塞线程。 - 示例修改代码: ```csharp static async Task Main(string[] args) { await Task.Run(() => Test()); } ``` 3. **异常处理**: - 在循环内部添加 `try-catch` 块,捕获并处理可能发生的异常,防止线程意外终止。 - 示例代码: ```csharp static void Test() { var flag = true; int iteration = 0; while (iteration < 1000000) { try { flag = !flag; iteration++; } catch (Exception ex) { Console.WriteLine($"发生异常: {ex.Message}"); break; } } } ``` 4. **性能监控与调试**: - 使用性能分析工具(如 Visual Studio 的诊断工具)监控 CPU 和内存使用情况,识别潜在的资源瓶颈。 - 在调试时设置断点,逐步执行代码以确认循环行为是否符合预期。 ###
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值