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
- Java –version
- file command
- 64 bit OS is not default
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)
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,
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?
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.
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