Sagar Acharya
Sagar Acharya

Reputation: 1871

Are JVMs developed according to the OS or the CPU architecture?

I searched a lot for this question but didn't get satisfactory answer. I know about JVM but i really didnt understand if oracle need to make JVM for every type of CPU or just for a specific OS. Correct me if I am wrong but, i came to the conclusion that it is OS centric since JVM is run as a normal program by the OS. If so do oracle need to develop a different JVM for each linux distributions? But while searching the web i found articles taking about the architecture too. I'm really confused. any help is appreciated.

Upvotes: 2

Views: 816

Answers (1)

apangin
apangin

Reputation: 98630

Both.

For example, let's take HotSpot JVM (OpenJDK and Oracle JDK are based on this JVM).

HotSpot sources (written in C++) consist mostly of platform-independent code, but they also include a large amount of CPU-specific code and OS-specific code. Furthermore, there is also platform-dependent code for particular combinations of OS/CPU.

This distinction is reflected in directory structure. Here is how HotSpot sources are organized:

+ src
|
|--+ cpu
|  |
|  |--- ppc
|  |--- sparc
|  |--- x86
|  |--- zero
|
|--+ os
|  |
|  |--- aix
|  |--- bsd
|  |--- linux
|  |--- posix
|  |--- solaris
|  |--- windows
|
|--+ os_cpu
|  |
|  |--- aix_ppc
|  |--- bsd_x86
|  |--- bsd_zero
|  |--- linux_ppc
|  |--- linux_sparc
|  |--- linux_x86
|  |--- linux_zero
|  |--- solaris_sparc
|  |--- solaris_x86
|  |--- windows_x86
|
|--+ share
   |                
   |--+ vm
      |
      |--- classfile
      |--- compiler
      |--- gc_implementation
      |--- gc_interface
      |--- runtime
      |--- services
      |--- etc.

To build JVM binaries for a particular platform, the sources from all related directories are taken. E.g. HotSpot Linux/x86 build requires share, cpu/x86, os/linux and os_cpu/linux_x86.

All valid combinations of OS/CPU are built and tested separately. As a result, you can finally see a bunch of platform-specific binaries on JDK download page.

As to different Linux distributions, there is no need to build separate binaries, as long as the target architecture is the same. JDK has minimum dependencies on third party libraries. JVM is linked againt a rather old version of glibc, so it can run almost on any popular Linux distribution.

Upvotes: 4

Related Questions