How can I tell if I'm running in 64-bit JVM or 32-bit JVM (from within a program)?

前端 未结 12 2108
滥情空心
滥情空心 2020-11-22 09:39

How can I tell if the JVM in which my application runs is 32 bit or 64-bit? Specifically, what functions or properties I can used to detect this within the program?

12条回答
  •  北荒
    北荒 (楼主)
    2020-11-22 10:11

    Complementary info:

    On a running process you may use (at least with some recent Sun JDK5/6 versions):

    $ /opt/java1.5/bin/jinfo -sysprops 14680 | grep sun.arch.data.model
    Attaching to process ID 14680, please wait...
    Debugger attached successfully.
    Server compiler detected.
    JVM version is 1.5.0_16-b02
    sun.arch.data.model = 32
    

    where 14680 is PID of jvm running the application. "os.arch" works too.

    Also other scenarios are supported:

    jinfo [ option ] pid
    jinfo [ option ] executable core
    jinfo [ option ] [server-id@]remote-hostname-or-IP 
    

    However consider also this note:

    "NOTE - This utility is unsupported and may or may not be available in future versions of the JDK. In Windows Systems where dbgent.dll is not present, 'Debugging Tools for Windows' needs to be installed to have these tools working. Also the PATH environment variable should contain the location of jvm.dll used by the target process or the location from which the Crash Dump file was produced."

提交回复
热议问题