Bit support in Java (32 or 64 bit)

I came across a task to find out the bit support level in the installed java. This has to be done from the command line and the solution has to be unique across Solaris and Linux. I presumed it to be an easy problem, however it is not so. Below describes the different solution that I tried and the problems I faced in those

  1. Java –version
  2. The very first solution that came to my mind is to parse the output of java –version assuming the output to have some details about the bit support level. Happily the below output from Linux 64 bit server supports my assumption


    java version “1.6.0_20″
    Java(TM) SE Runtime Environment (build 1.6.0_20-b02)
    Java HotSpot(TM) 64-Bit Server VM (build 16.3-b01, mixed mode)

    Sadly, similar output, stating the bit support level, is not shown in Solaris 64 bit SPARC server.


    java version “1.6.0_22″
    Java(TM) SE Runtime Environment (build 1.6.0_22-b04)
    Java HotSpot(TM) Client VM (build 17.1-b03, mixed mode, sharing)

  3. file command
  4. Those worked in nix* systems should be familiar of the file command. For others, file command determines the type of the file. Again, in Linux the output shows that java.exe is 64 bit compiled however in Solaris it is not so. Output from both the OS are as below


    Linux: java: ELF 64-bit LSB executable, [snipped]
    Solaris: java: ELF 32-bit MSB executable SPARC Version 1, dynamically linked, not stripped, no debugging information available

    The disparity of output between the OSes is because 64 bit version of java in Solaris SPARC is actually a patch over corresponding 32 bit version. Not sure of this special treatment for Solaris SPARC. Let me know if you have idea on this.

    Caveat: All the java installation notes mentions installation of 64 bit java in a 64 bit Solaris SPARC server is two step process. The first step is to install 32 bit java and then install “supplemental files” for 64-bit support. However the download page doesn’t indicate any file as supplemental files. See below,

     

    File names and description on download

    Both the file has the same name and description too. Even the installation doesn’t give any indication to the user. This is the starting point for most of the confusion. Will Oracle fix this?

  5. 64 bit OS is not default
  6. This is something interesting. Java provides a property “sun.arch.data.model” that provides the bit support of the JVM. Executing a simple code that prints the output of the above property reveals that Solaris SPARC servers doesn’t take 64 bit by default. If 64 bit support is needed then it should be indicated with the option –d[support_level]

Point 3 reveals a new way to find out the bit support level in java for both Solaris and Linux OSes. Proper completion of the command java –d64 –version shows that 64 bit java is installed in the server. If there is some error then probable causes could be no java is installed or installed java supports only 32 bit. By executing java –version we could find the exact cause.
Snippet

 Java -d64 -version 2>/dev/null
 if [ $? -eq 0 ]
then 
	echo “64 bit”
else
	echo “32 bit”

Let me know if you have some efficient way than this

Add to FacebookAdd to DiggAdd to Del.icio.usAdd to StumbleuponAdd to RedditAdd to BlinklistAdd to TwitterAdd to TechnoratiAdd to Yahoo BuzzAdd to Newsvine

About these ads

8 Responses

  1. Good one. Keep going.

  2. Hi,

    JVM implementation for Sun can work with “sun.arch.data.model”. for the JVM implementor’s other than Sun, we need to check for another property.

    Regards
    Sivashankar.R

  3. That’s a good point. Yes all JVM except GNU JVM supports this. Refer http://stackoverflow.com/questions/807263/how-do-i-detect-which-kind-of-jre-is-installed-32bit-vs-64bit. However the proposed solution works with GNU jvm too as it is not dependent on the property

  4. java -version -server should do

  5. I tried this one in a solaris machine..

    @/export/home/omcadm>java -version -server
    java version “1.5.0_16″
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_16-b02)
    Java HotSpot(TM) 64-Bit Server VM (build 1.5.0_16-b02, mixed mode)

  6. In my Solaris Sunfire server it is not

    bash-3.00# java -version -server
    java version “1.6.0_22″
    Java(TM) SE Runtime Environment (build 1.6.0_22-b04)
    Java HotSpot(TM) Server VM (build 17.1-b03, mixed mode)

    Is this a breakage in 1.6 version? Do you have any aliases set for java ? What is the output of java -d32 -version -server ?

  7. @/omcsw/35.0.1.70.01/lib/3pt/jre/bin>java -d32 -version -server
    execve(): No such file or directory
    Error trying to exec /omcsw/35.0.1.70.01/lib/3pt/jdk/jre/bin/../java.
    Check if file exists and permissions are set correctly.
    Failed to start a 32-bit JVM process from a 64-bit JVM.
    Verify all necessary J2SE components have been installed.
    (Solaris SPARC 64-bit components must be installed after 32-bit components.)
    @/omcsw/35.0.1.70.01/lib/3pt/jre/bin>

  8. I have a different solution for this.
    http://shiv.me/blog/2010/11/03/power.html

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: