错误问题

  • Caused by: java.lang.IllegalStateException: Unmapped 
    relationship: 7 
    at com.sun.jna.platform.win32.WinNT$SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX.fromPointer(WinNT.java:3033)
    .......
    

解决方法

  • jna依赖较旧,换用新版jna依赖。下载地址:jna github

错误原因

  • Windows新增了新的逻辑处理器映射关系(LOGICAL_PROCESSOR_RELATIONSHIP),其值为567。有issue提到:issue。体现在升级到windows11后,可能抛出错误问题中的异常。
    下方代码无法处理新的映射关系,故抛出异常。该问题已在jna新版本被处理,故升级依赖就能解决。
public static WinNT.SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX fromPointer(Pointer memory) {
            int relationship = memory.getInt(0L);
            Object result;
            switch(relationship) {
            case 0:
            case 3:
                result = new WinNT.PROCESSOR_RELATIONSHIP(memory);
                break;
            case 1:
                result = new WinNT.NUMA_NODE_RELATIONSHIP(memory);
                break;
            case 2:
                result = new WinNT.CACHE_RELATIONSHIP(memory);
                break;
            case 4:
                result = new WinNT.GROUP_RELATIONSHIP(memory);
                break;
            default:
                throw new IllegalStateException("Unmapped relationship: " + relationship);
            }

            ((WinNT.SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX)result).read();
            return (WinNT.SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX)result;
        }