gpt4 book ai didi

System.getProperty("os.arch") different between Java 17 and Java 8(在Java 17和Java 8之间,System.getProperty(“os.ch”)不同)

转载 作者:bug小助手 更新时间:2023-10-25 17:56:34 29 4
gpt4 key购买 nike



I have this method

我有一种方法


static String getArchSuffix() {
String arch = System.getProperty("os.arch");
if (arch.equals("i686")) {
return "x86";
} else if (arch.equals("amd64")) {
return "x86_64";
} else if (arch.equals("nacl")) {
return "armv7l";
} else if (arch.equals("aarch64")) {
return "armv7l";
}
return arch;
}

In Java 8, it worked well for my Macbook pro M2.

在Java 8中,它在我的Macbook Pro M2上运行得很好。


The result was:

结果是:


arch = x86_64

Now after migrating to Java 17, I get

现在在迁移到Java 17之后,我得到了


arch = aarch64

I expected the same behavior for the two versions. What am I missing?

我预计这两个版本的行为是相同的。我遗漏了什么?


I expected that this method works and outputs the same values for Java 17, and Java 1.8.

我原以为这个方法对Java 17和Java 1.8起作用并输出相同的值。


更多回答
优秀答案推荐

The os.arch property is reporting the native instruction set of the JVM executable that is running, and that is different in your Java 8 and Java 17 cases.

Os.ch属性报告正在运行的JVM可执行文件的本机指令集,这在您的Java 8和Java 17中有所不同。


Here's what I think has happened.

以下是我认为已经发生的事情。



  • The Java 8 installation you were previously using was a x86_64 build, and you were using MacOS's x86_64 emulation, Rosetta 2.

  • The Java 17 installation is a native ARM64 build.





I'm expecting that this method works and output same values for jdk17 and jdk1.8.



That would only happen if the Java builds had the same target architecture. If you wanted an ARM64 build for Java 8, you could potentially get one from a third party vendor; see Will x64 jdk-1.8 work in Mac with Apple Silicon (M1) Chip?.

只有当Java构建具有相同的目标体系结构时,才会发生这种情况。如果您想要一个用于Java 8的ARM64版本,您可以从第三方供应商那里获得一个;请参阅x64 JDK-1.8能否在Mac上与Apple Silicon(M1)芯片一起工作?



You're now running on a JVM which is native aarch64 (ARM64), where previously you were running a x86_64 (AMD64) JVM which was translated to M2 using Rosetta 2 technology.

您现在运行的JVM是原生的aarch64(ARM64),在此之前您运行的是x86_64(AMD64)JVM,该JVM使用Rosetta 2技术转换为M2。


To be clear, x86_64 is the Intel/AMD x86 64-bit instruction set, while the M2 is actually aarch64 (ARM64). So technically, the Java 8 version was 'lying' to you, because it actually ran on a x86-64 emulation layer.

需要明确的是,x86_64是Intel/AMD x86 64位指令集,而M2实际上是aarch64(ARM64)。因此,从技术上讲,Java 8版本是在“撒谎”,因为它实际上运行在x86-64模拟层上。


更多回答

"So technically, the Java 8 version was 'lying' to you, because it actually ran on a x86-64 emulation layer." - It's not a lie if you unknowingly say something that is untrue :-)

“所以从技术上讲,Java 8版本是在对你‘撒谎’,因为它实际上运行在x86-64模拟层上。”-如果你无意中说了一些不真实的话,这不是谎言:-)

@StephenC Which is why I have lying in quotes.

@StehenC,这就是为什么我会用引号撒谎。

We should judge the truth of the property value by the purpose of the property. If you want to know the architecture of the native libraries you can link to the JVM runtime, the answer was correct in either case. That’s not different to a 32 bit JVM reporting a 32 bit architecture despite running on a 64 bit CPU.

我们应该根据财产的用途来判断财产价值的真实性。如果您想知道可以链接到JVM运行时的本机库的体系结构,答案在任何一种情况下都是正确的。这与报告32位体系结构的32位JVM没有什么不同,尽管它运行在64位CPU上。

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com