Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

All possible values os.arch in 32bit JRE and in 64bit Jre

Tags:

java

jnlp

I need latest compilation of all possible values of the os.arch property in JRE 1.6 on Linux,Solaris and Windows. If possible please Quote the source of your findings. I need this values to select resources in my JNLP file. Basically I need to assign different JVM memory based on whether the JRE is 32bit or 64bit. Waiting for your answer. Thanks

like image 510
Brahma Avatar asked Jun 01 '12 07:06

Brahma


2 Answers

The best place where you can look for this it's in the own jdk.

Looking on java.lang.System you can see that the properties are initialized in initializeSystemClass method using initProperties method which relies on native code using JNI:

private static native Properties initProperties(Properties props);  /**  * Initialize the system class.  Called after thread initialization.  */ private static void initializeSystemClass() {      // VM might invoke JNU_NewStringPlatform() to set those encoding     // sensitive properties (user.home, user.name, boot.class.path, etc.)     // during "props" initialization, in which it may need access, via     // System.getProperty(), to the related system encoding property that     // have been initialized (put into "props") at early stage of the     // initialization. So make sure the "props" is available at the     // very beginning of the initialization and all system properties to     // be put into it directly.     props = new Properties();     initProperties(props);  // initialized by the VM     ...     ... } 

If you check the source of this native code called from initProperties for the different platforms you can see the possible values for os.arch system property. So do it step by step:

First look at System.c to see the JNI method called from java.lang.System.initProperties. From System.c

JNIEXPORT jobject JNICALL Java_java_lang_System_initProperties(JNIEnv *env, jclass cla, jobject props) {     char buf[128];     java_props_t *sprops = GetJavaProperties(env);     jmethodID putID = (*env)->GetMethodID(env,                                           (*env)->GetObjectClass(env, props),                                           "put",             "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");      if (sprops == NULL || putID == NULL ) return NULL;      PUTPROP(props, "java.specification.version",             JDK_MAJOR_VERSION "." JDK_MINOR_VERSION);     PUTPROP(props, "java.specification.name",             "Java Platform API Specification");     PUTPROP(props, "java.specification.vendor", "Sun Microsystems Inc.");      PUTPROP(props, "java.version", RELEASE);     PUTPROP(props, "java.vendor", VENDOR);     PUTPROP(props, "java.vendor.url", VENDOR_URL);     PUTPROP(props, "java.vendor.url.bug", VENDOR_URL_BUG);      ...      /* os properties */     PUTPROP(props, "os.name", sprops->os_name);     PUTPROP(props, "os.version", sprops->os_version);      // HERE IS THE `os.arch` PROPERTY :)      PUTPROP(props, "os.arch", sprops->os_arch); 

So as you can see the os.arch comes from PUTPROP(props, "os.arch", sprops->os_arch); and the sprops it's achieved using java_props_t *sprops = GetJavaProperties(env);. so lets look at GetJavaProperties(env), this method it's defined in java_props.h as:

java_props_t *GetJavaProperties(JNIEnv *env);

And the implementation seems that depends on OS.

So finally looking a specific implementation for GetJavaProperties; in Windows the possible values which this property can take are ia64, amd64, x86, or unknown. You can see from java_props_md.c file :

#if _M_IA64         sprops.os_arch = "ia64"; #elif _M_AMD64         sprops.os_arch = "amd64"; #elif _X86_         sprops.os_arch = "x86"; #else         sprops.os_arch = "unknown"; #endif 

For Solaris seems more complicated since the property value in the native code comes from a Macro defined in the java_props_md.c specific for solaris as:

sprops.os_arch = ARCHPROPNAME; 

And this Macro it's defined in the follow Makefile as:

OTHER_CPPFLAGS += -DARCHPROPNAME='"$(ARCHPROP)"'

So it looks like this comes from the environment, where it's compiled (sorry I'm not a C expert, I'm just guessing however maybe I can guide you a bit).

In the Linux folder in src/linux/native/ there is no java_props_md.c so I suppose that in this case take the same source as solaris (I'm guessing again...).

NOTE: I use the 1.6 version to get this values, however new values can will be added in newest java versions, so check your required version.

Hope it helps,

like image 197
albciff Avatar answered Sep 28 '22 17:09

albciff


I ran into the same problem in 2019. Especially with regard to arm processors.

After trying it out, the raspberry pi 2 (ARMv7) seems to simply return the string arm.

The raspberry pi 3 (ARMv8) returns aarch64.

x86 64-bit desktops and servers return amd64.

Hope this helps someone.

like image 40
Malt Avatar answered Sep 28 '22 16:09

Malt