src/share/native/java/lang/System.c

Print this page




  41     {"arraycopy",     "(" OBJ "I" OBJ "II)V", (void *)&JVM_ArrayCopy},
  42 };
  43 
  44 #undef OBJ
  45 
  46 JNIEXPORT void JNICALL
  47 Java_java_lang_System_registerNatives(JNIEnv *env, jclass cls)
  48 {
  49     (*env)->RegisterNatives(env, cls,
  50                             methods, sizeof(methods)/sizeof(methods[0]));
  51 }
  52 
  53 JNIEXPORT jint JNICALL
  54 Java_java_lang_System_identityHashCode(JNIEnv *env, jobject this, jobject x)
  55 {
  56     return JVM_IHashCode(env, x);
  57 }
  58 
  59 #define PUTPROP(props, key, val) \
  60     if (1) { \
  61         jstring jkey = (*env)->NewStringUTF(env, key); \
  62         jstring jval = (*env)->NewStringUTF(env, val); \
  63         jobject r = (*env)->CallObjectMethod(env, props, putID, jkey, jval); \




  64         if ((*env)->ExceptionOccurred(env)) return NULL; \
  65         (*env)->DeleteLocalRef(env, jkey); \
  66         (*env)->DeleteLocalRef(env, jval); \
  67         (*env)->DeleteLocalRef(env, r); \
  68     } else ((void) 0)
  69 
  70 /*  "key" is a char type string with only ASCII character in it.
  71     "val" is a nchar (typedefed in java_props.h) type string  */
  72 
  73 #define PUTPROP_ForPlatformNString(props, key, val) \
  74     if (1) { \
  75         jstring jkey = (*env)->NewStringUTF(env, key);  \
  76         jstring jval = GetStringPlatform(env, val); \
  77         jobject r = (*env)->CallObjectMethod(env, props, putID, jkey, jval); \




  78         if ((*env)->ExceptionOccurred(env)) return NULL; \
  79         (*env)->DeleteLocalRef(env, jkey); \
  80         (*env)->DeleteLocalRef(env, jval); \
  81         (*env)->DeleteLocalRef(env, r); \
  82     } else ((void) 0)
  83 #define REMOVEPROP(props, key) \
  84     if (1) { \
  85         jstring jkey = JNU_NewStringPlatform(env, key); \
  86         jobject r = (*env)->CallObjectMethod(env, props, removeID, jkey); \



  87         if ((*env)->ExceptionOccurred(env)) return NULL; \
  88         (*env)->DeleteLocalRef(env, jkey); \
  89         (*env)->DeleteLocalRef(env, r); \
  90     } else ((void) 0)
  91 #define GETPROP(props, key, jret) \
  92     if (1) { \
  93         jstring jkey = JNU_NewStringPlatform(env, key); \

  94         jret = (*env)->CallObjectMethod(env, props, getPropID, jkey); \
  95         if ((*env)->ExceptionOccurred(env)) return NULL; \
  96         (*env)->DeleteLocalRef(env, jkey); \
  97     } else ((void) 0)
  98 
  99 #ifndef VENDOR /* Third party may overwrite this. */
 100 #define VENDOR "Oracle Corporation"
 101 #define VENDOR_URL "http://java.oracle.com/"
 102 #define VENDOR_URL_BUG "http://bugreport.sun.com/bugreport/"
 103 #endif
 104 
 105 #define JAVA_MAX_SUPPORTED_VERSION 52
 106 #define JAVA_MAX_SUPPORTED_MINOR_VERSION 0
 107 
 108 #ifdef JAVA_SPECIFICATION_VENDOR /* Third party may NOT overwrite this. */
 109   #error "ERROR: No override of JAVA_SPECIFICATION_VENDOR is allowed"
 110 #else
 111   #define JAVA_SPECIFICATION_VENDOR "Oracle Corporation"
 112 #endif
 113 


 152 
 153         /* user.xxx.format property */
 154         jio_snprintf(buf, sizeof(buf), "%s.format", baseKey);
 155         GETPROP(props, buf, jVMVal);
 156         if (jVMVal == NULL) {
 157             if (platformFmtVal && (strcmp(baseVal, platformFmtVal) != 0)) {
 158                 PUTPROP(props, buf, platformFmtVal);
 159             }
 160         } else {
 161             (*env)->DeleteLocalRef(env, jVMVal);
 162         }
 163     }
 164 
 165     return NULL;
 166 }
 167 
 168 JNIEXPORT jobject JNICALL
 169 Java_java_lang_System_initProperties(JNIEnv *env, jclass cla, jobject props)
 170 {
 171     char buf[128];
 172     java_props_t *sprops = GetJavaProperties(env);
 173     jmethodID putID = (*env)->GetMethodID(env,







 174                                           (*env)->GetObjectClass(env, props),
 175                                           "put",
 176             "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
 177     jmethodID removeID = (*env)->GetMethodID(env,


 178                                           (*env)->GetObjectClass(env, props),
 179                                           "remove",
 180             "(Ljava/lang/Object;)Ljava/lang/Object;");
 181     jmethodID getPropID = (*env)->GetMethodID(env,


 182                                           (*env)->GetObjectClass(env, props),
 183                                           "getProperty",
 184             "(Ljava/lang/String;)Ljava/lang/String;");
 185     jobject ret = NULL;
 186     jstring jVMVal = NULL;
 187 
 188     if (sprops == NULL || putID == NULL ) return NULL;
 189 
 190     PUTPROP(props, "java.specification.version",
 191             JDK_MAJOR_VERSION "." JDK_MINOR_VERSION);
 192     PUTPROP(props, "java.specification.name",
 193             "Java Platform API Specification");
 194     PUTPROP(props, "java.specification.vendor",
 195             JAVA_SPECIFICATION_VENDOR);
 196 
 197     PUTPROP(props, "java.version", RELEASE);
 198     PUTPROP(props, "java.vendor", VENDOR);
 199     PUTPROP(props, "java.vendor.url", VENDOR_URL);
 200     PUTPROP(props, "java.vendor.url.bug", VENDOR_URL_BUG);
 201 
 202     jio_snprintf(buf, sizeof(buf), "%d.%d", JAVA_MAX_SUPPORTED_VERSION,
 203                                             JAVA_MAX_SUPPORTED_MINOR_VERSION);
 204     PUTPROP(props, "java.class.version", buf);
 205 
 206     if (sprops->awt_toolkit) {
 207         PUTPROP(props, "awt.toolkit", sprops->awt_toolkit);
 208     }


 365         PUTPROP(props, "sun.desktop", sprops->desktop);
 366     }
 367 
 368     /*
 369      * unset "user.language", "user.script", "user.country", and "user.variant"
 370      * in order to tell whether the command line option "-DXXXX=YYYY" is
 371      * specified or not.  They will be reset in fillI18nProps() below.
 372      */
 373     REMOVEPROP(props, "user.language");
 374     REMOVEPROP(props, "user.script");
 375     REMOVEPROP(props, "user.country");
 376     REMOVEPROP(props, "user.variant");
 377     REMOVEPROP(props, "file.encoding");
 378 
 379     ret = JVM_InitProperties(env, props);
 380 
 381     /* Check the compatibility flag */
 382     GETPROP(props, "sun.locale.formatasdefault", jVMVal);
 383     if (jVMVal) {
 384         const char * val = (*env)->GetStringUTFChars(env, jVMVal, 0);

 385         fmtdefault = !strcmp(val, "true");
 386         (*env)->ReleaseStringUTFChars(env, jVMVal, val);
 387         (*env)->DeleteLocalRef(env, jVMVal);
 388     }
 389 
 390     /* reconstruct i18n related properties */
 391     fillI18nProps(env, props, "user.language", sprops->display_language,
 392         sprops->format_language, putID, getPropID);
 393     fillI18nProps(env, props, "user.script",
 394         sprops->display_script, sprops->format_script, putID, getPropID);
 395     fillI18nProps(env, props, "user.country",
 396         sprops->display_country, sprops->format_country, putID, getPropID);
 397     fillI18nProps(env, props, "user.variant",
 398         sprops->display_variant, sprops->format_variant, putID, getPropID);
 399     GETPROP(props, "file.encoding", jVMVal);
 400     if (jVMVal == NULL) {
 401 #ifdef MACOSX
 402         /*
 403          * Since sun_jnu_encoding is now hard-coded to UTF-8 on Mac, we don't
 404          * want to use it to overwrite file.encoding




  41     {"arraycopy",     "(" OBJ "I" OBJ "II)V", (void *)&JVM_ArrayCopy},
  42 };
  43 
  44 #undef OBJ
  45 
  46 JNIEXPORT void JNICALL
  47 Java_java_lang_System_registerNatives(JNIEnv *env, jclass cls)
  48 {
  49     (*env)->RegisterNatives(env, cls,
  50                             methods, sizeof(methods)/sizeof(methods[0]));
  51 }
  52 
  53 JNIEXPORT jint JNICALL
  54 Java_java_lang_System_identityHashCode(JNIEnv *env, jobject this, jobject x)
  55 {
  56     return JVM_IHashCode(env, x);
  57 }
  58 
  59 #define PUTPROP(props, key, val)                                     \
  60     if (1) {                                                         \
  61         jstring jkey, jval;                                          \
  62         jobject r;                                                   \
  63         jkey = (*env)->NewStringUTF(env, key);                       \
  64         if (jkey == NULL) return NULL;                               \
  65         jval = (*env)->NewStringUTF(env, val);                       \
  66         if (jval == NULL) return NULL;                               \
  67         r = (*env)->CallObjectMethod(env, props, putID, jkey, jval); \
  68         if ((*env)->ExceptionOccurred(env)) return NULL;             \
  69         (*env)->DeleteLocalRef(env, jkey);                           \
  70         (*env)->DeleteLocalRef(env, jval);                           \
  71         (*env)->DeleteLocalRef(env, r);                              \
  72     } else ((void) 0)
  73 
  74 /*  "key" is a char type string with only ASCII character in it.
  75     "val" is a nchar (typedefed in java_props.h) type string  */
  76 
  77 #define PUTPROP_ForPlatformNString(props, key, val)                  \
  78     if (1) {                                                         \
  79         jstring jkey, jval;                                          \
  80         jobject r;                                                   \
  81         jkey = (*env)->NewStringUTF(env, key);                       \
  82         if (jkey == NULL) return NULL;                               \
  83         jval = GetStringPlatform(env, val);                          \
  84         if (jval == NULL) return NULL;                               \
  85         r = (*env)->CallObjectMethod(env, props, putID, jkey, jval); \
  86         if ((*env)->ExceptionOccurred(env)) return NULL;             \
  87         (*env)->DeleteLocalRef(env, jkey);                           \
  88         (*env)->DeleteLocalRef(env, jval);                           \
  89         (*env)->DeleteLocalRef(env, r);                              \
  90     } else ((void) 0)
  91 #define REMOVEPROP(props, key)                                    \
  92     if (1) {                                                      \
  93         jstring jkey;                                             \
  94         jobject r;                                                \
  95         jkey = JNU_NewStringPlatform(env, key);                   \
  96         if (jkey == NULL) return NULL;                            \
  97         r = (*env)->CallObjectMethod(env, props, removeID, jkey); \
  98         if ((*env)->ExceptionOccurred(env)) return NULL;          \
  99         (*env)->DeleteLocalRef(env, jkey);                        \
 100         (*env)->DeleteLocalRef(env, r);                           \
 101     } else ((void) 0)
 102 #define GETPROP(props, key, jret)                                     \
 103     if (1) {                                                          \
 104         jstring jkey = JNU_NewStringPlatform(env, key);               \
 105         if (jkey == NULL) return NULL;                                \
 106         jret = (*env)->CallObjectMethod(env, props, getPropID, jkey); \
 107         if ((*env)->ExceptionOccurred(env)) return NULL;              \
 108         (*env)->DeleteLocalRef(env, jkey);                            \
 109     } else ((void) 0)
 110 
 111 #ifndef VENDOR /* Third party may overwrite this. */
 112 #define VENDOR "Oracle Corporation"
 113 #define VENDOR_URL "http://java.oracle.com/"
 114 #define VENDOR_URL_BUG "http://bugreport.sun.com/bugreport/"
 115 #endif
 116 
 117 #define JAVA_MAX_SUPPORTED_VERSION 52
 118 #define JAVA_MAX_SUPPORTED_MINOR_VERSION 0
 119 
 120 #ifdef JAVA_SPECIFICATION_VENDOR /* Third party may NOT overwrite this. */
 121   #error "ERROR: No override of JAVA_SPECIFICATION_VENDOR is allowed"
 122 #else
 123   #define JAVA_SPECIFICATION_VENDOR "Oracle Corporation"
 124 #endif
 125 


 164 
 165         /* user.xxx.format property */
 166         jio_snprintf(buf, sizeof(buf), "%s.format", baseKey);
 167         GETPROP(props, buf, jVMVal);
 168         if (jVMVal == NULL) {
 169             if (platformFmtVal && (strcmp(baseVal, platformFmtVal) != 0)) {
 170                 PUTPROP(props, buf, platformFmtVal);
 171             }
 172         } else {
 173             (*env)->DeleteLocalRef(env, jVMVal);
 174         }
 175     }
 176 
 177     return NULL;
 178 }
 179 
 180 JNIEXPORT jobject JNICALL
 181 Java_java_lang_System_initProperties(JNIEnv *env, jclass cla, jobject props)
 182 {
 183     char buf[128];
 184     java_props_t *sprops;
 185     jmethodID putID, removeID, getPropID;
 186     jobject ret = NULL;
 187     jstring jVMVal = NULL;
 188 
 189     sprops = GetJavaProperties(env);
 190     CHECK_NULL_RETURN(sprops, NULL);
 191 
 192     putID = (*env)->GetMethodID(env,
 193                                 (*env)->GetObjectClass(env, props),
 194                                 "put",
 195             "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
 196     CHECK_NULL_RETURN(putID, NULL);
 197 
 198     removeID = (*env)->GetMethodID(env,
 199                                    (*env)->GetObjectClass(env, props),
 200                                    "remove",
 201             "(Ljava/lang/Object;)Ljava/lang/Object;");
 202     CHECK_NULL_RETURN(removeID, NULL);
 203 
 204     getPropID = (*env)->GetMethodID(env,
 205                                     (*env)->GetObjectClass(env, props),
 206                                     "getProperty",
 207             "(Ljava/lang/String;)Ljava/lang/String;");
 208     CHECK_NULL_RETURN(getPropID, NULL);



 209 
 210     PUTPROP(props, "java.specification.version",
 211             JDK_MAJOR_VERSION "." JDK_MINOR_VERSION);
 212     PUTPROP(props, "java.specification.name",
 213             "Java Platform API Specification");
 214     PUTPROP(props, "java.specification.vendor",
 215             JAVA_SPECIFICATION_VENDOR);
 216 
 217     PUTPROP(props, "java.version", RELEASE);
 218     PUTPROP(props, "java.vendor", VENDOR);
 219     PUTPROP(props, "java.vendor.url", VENDOR_URL);
 220     PUTPROP(props, "java.vendor.url.bug", VENDOR_URL_BUG);
 221 
 222     jio_snprintf(buf, sizeof(buf), "%d.%d", JAVA_MAX_SUPPORTED_VERSION,
 223                                             JAVA_MAX_SUPPORTED_MINOR_VERSION);
 224     PUTPROP(props, "java.class.version", buf);
 225 
 226     if (sprops->awt_toolkit) {
 227         PUTPROP(props, "awt.toolkit", sprops->awt_toolkit);
 228     }


 385         PUTPROP(props, "sun.desktop", sprops->desktop);
 386     }
 387 
 388     /*
 389      * unset "user.language", "user.script", "user.country", and "user.variant"
 390      * in order to tell whether the command line option "-DXXXX=YYYY" is
 391      * specified or not.  They will be reset in fillI18nProps() below.
 392      */
 393     REMOVEPROP(props, "user.language");
 394     REMOVEPROP(props, "user.script");
 395     REMOVEPROP(props, "user.country");
 396     REMOVEPROP(props, "user.variant");
 397     REMOVEPROP(props, "file.encoding");
 398 
 399     ret = JVM_InitProperties(env, props);
 400 
 401     /* Check the compatibility flag */
 402     GETPROP(props, "sun.locale.formatasdefault", jVMVal);
 403     if (jVMVal) {
 404         const char * val = (*env)->GetStringUTFChars(env, jVMVal, 0);
 405         CHECK_NULL_RETURN(val, NULL);
 406         fmtdefault = !strcmp(val, "true");
 407         (*env)->ReleaseStringUTFChars(env, jVMVal, val);
 408         (*env)->DeleteLocalRef(env, jVMVal);
 409     }
 410 
 411     /* reconstruct i18n related properties */
 412     fillI18nProps(env, props, "user.language", sprops->display_language,
 413         sprops->format_language, putID, getPropID);
 414     fillI18nProps(env, props, "user.script",
 415         sprops->display_script, sprops->format_script, putID, getPropID);
 416     fillI18nProps(env, props, "user.country",
 417         sprops->display_country, sprops->format_country, putID, getPropID);
 418     fillI18nProps(env, props, "user.variant",
 419         sprops->display_variant, sprops->format_variant, putID, getPropID);
 420     GETPROP(props, "file.encoding", jVMVal);
 421     if (jVMVal == NULL) {
 422 #ifdef MACOSX
 423         /*
 424          * Since sun_jnu_encoding is now hard-coded to UTF-8 on Mac, we don't
 425          * want to use it to overwrite file.encoding