所有可能的值都在32位JRE和64位Jre中 [英] All possible values os.arch in 32bit JRE and in 64bit Jre

查看:204
本文介绍了所有可能的值都在32位JRE和64位Jre中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在Linux,Solaris和Windows上的JRE 1.6中对os.arch属性的所有可能值进行最新编译。
如果可能,请引用您的调查结果来源。
我需要这个值来选择我的JNLP文件中的资源。基本上我需要根据JRE是32位还是64位来分配不同的JVM内存。
等待你的回答。
谢谢

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

推荐答案

您可以在自己的jdk中找到它的最佳位置。

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

查看 java.lang.System ,您可以看到属性在 initializeSystemClass 方法使用 initProperties 方法,该方法使用 JNI 依赖本机代码:

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
    ...
    ...
}

如果您检查从 initProperties 调用的本机代码的来源,您可以看到 os.arch <的可能值/ code>系统属性。所以一步一步来做:

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:

首先看一下 System.c ,看看 java.lang.System.initProperties 调用的JNI 方法。来自 System.c

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);

所以你可以看到 os.arch 来自 PUTPROP(道具,os.arch,sprops-> os_arch); sprops 它是使用 java_props_t * sprops = GetJavaProperties(env); 实现。所以让我们看一下 GetJavaProperties(env),这个方法在 java_props.h as:

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.

所以最后查看 GetJavaProperties 的具体实现; Windows中的
此属性可能采用的值是 ia64 amd64 x86 ,或未知。你可以从 java_props_md.c 文件

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

对于Solaris来说似乎更复杂,因为本机代码中的属性值来自 java_props_md.c 特定于solaris:

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;

这个宏在下面的 Makefile as:

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

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

所以它看起来像是来自环境,它是编译的(抱歉,我不是C专家,我只是猜测,但是我可以指导你一点)。

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).

src / linux / native / 的Linux文件夹中,没有 java_props_md.c 所以我想在这种情况下使用与solaris相同的来源(我再次猜测......)。

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...).

注意:我使用1.6版本获取此值,但是最新的Java版本中可以添加新值,因此请检查所需的版本。

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.

希望它有所帮助,

这篇关于所有可能的值都在32位JRE和64位Jre中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆