0

We are using the JVM 32-bit on the Windows 64-bit operating system and I'm trying to know the actual OS arch value in java.

System.getProperty("os.name");

This ways gives the values as x86.

As mentioned here https://stackoverflow.com/a/5940770/5662508

But 64 bit Windows platforms will lie to the JVM if it is a 32 bit JVM. Actually 64 bit Windows will lie to any 32 bit process about the environment to help old 32 bit programs work properly on a 64 bit OS. Read the MSDN article about WOW64 for more information.

As a result of WOW64, a 32 bit JVM calling System.getProperty("os.arch") will return "x86". If you want to get the real architecture of the underlying OS on Windows, use the following logic:

So I have tried using the System.getenv("PROCESSOR_ARCHITECTURE") as well. This also gives the x86 in the Java output, but when I execute the same from the command prompt it gives following output.

C:\Users\Administrator\Desktop>echo %PROCESSOR_ARCHITECTURE%
AMD64

C:\Users\Administrator\Desktop>echo %PROCESSOR_ARCHITEW6432% 
%PROCESSOR_ARCHITEW6432%

Neither PROCESSOR_ARCHITECTURE or PROCESSOR_ARCHITEW6432 not working in my case.

My Java class

public class Test {
  public static void main(String[] args) {
    
    String osName       = System.getProperty("os.name");
    String osArch       = System.getProperty("os.arch");
    System.out.println(osArch);
    
      try {
         String procArch = System.getenv("PROCESSOR_ARCHITECTURE");
         System.out.println(procArch);
         if (osName.toLowerCase().contains("windows") && "x86".equals(osArch) && null != procArch) {
             System.out.println("in side");
            osArch = procArch.toLowerCase();
         }
      } catch (Exception e) {
      }
      System.out.println(osArch);
  }
}

output:

x86
x86
in side
x86

How can we get the actual processor architetecture value?

Nagaraju Chitimilla
  • 530
  • 3
  • 7
  • 23
  • 3
    What exactly is your question? FYI: this is intentional: Windows acts as if it is 32-bits for 32-bit application, because 32-bit applications cannot use 64-bit libraries, etc. – Mark Rotteveel Mar 23 '21 at 09:43
  • how can we get the actual os arch i.e. AMD64 (in this case). – Nagaraju Chitimilla Mar 23 '21 at 09:45
  • 1
    Please [edit] your question to include your actual question. You need to understand that for 32-bit applications, the actual architecture **is** x86. Applications for example use this information to load DLLs, if they were informed that they were AMD64, they would attempt to load a 64-bit DLL which wouldn't work because it is a 32-bit application. – Mark Rotteveel Mar 23 '21 at 09:47
  • According to the answer you linked, you should check the value of environment variable `PROCESSOR_ARCHITEW6432` – Mark Rotteveel Mar 23 '21 at 10:01
  • PROCESSOR_ARCHITEW6432 is not available `C:\Users\Administrator\Desktop>echo %PROCESSOR_ARCHITEW6432% %PROCESSOR_ARCHITEW6432%` That's the reason i have raised this question. Neither PROCESSOR_ARCHITECTURE or PROCESSOR_ARCHITEW6432 not working in my case. – Nagaraju Chitimilla Mar 23 '21 at 10:03
  • Have you tried getting `PROCESSOR_ARCHITEW6432` from within your Java application, AFAIK, that environment variable only exists for 32-bit applications, exactly for the purpose you want. – Mark Rotteveel Mar 23 '21 at 10:06
  • Yes I have tried but this gives me null as the value `System.out.println(System.getenv("PROCESSOR_ARCHITEW6432"));` – Nagaraju Chitimilla Mar 23 '21 at 10:08
  • Why did you close this as duplicate? – Nagaraju Chitimilla Mar 23 '21 at 10:29
  • Because it is the same question – Mark Rotteveel Mar 23 '21 at 10:30
  • But the same answers is not working – Nagaraju Chitimilla Mar 23 '21 at 10:31
  • 1
    I tried a simple program using a 32-bit Java 8 JVM, and using `System.out.println(System.getenv("PROCESSOR_ARCHITEW6432"))` correctly reports AMD64 as expected. So maybe you're assumptions about your program is wrong, maybe it is running on a 32-bit machine (or VM). – Mark Rotteveel Mar 23 '21 at 12:07
  • I'm sure I'm on the 64 bit machine as if I execute the `echo %PROCESSOR_ARCHITECTURE%` from command prompt it gives the AMD64 as the value. – Nagaraju Chitimilla Mar 24 '21 at 06:36

0 Answers0