src/java.base/share/native/libjava/System.c
author rriggs
Wed, 28 Nov 2018 15:53:49 -0500
changeset 52724 0bdbf854472f
parent 52478 b915bd68d907
child 52725 c470f977ade8
permissions -rw-r--r--
4947890: Minimize JNI upcalls in system-properties initialization Reviewed-by: erikj, mchung, bchristi, ihse, coleenp, stuefe
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
52724
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
     2
 * Copyright (c) 1994, 2018, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5168
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5168
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5168
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5168
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5168
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
#include <string.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
#include "jni.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#include "jni_util.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#include "jvm.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
#include "java_props.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
#include "java_lang_System.h"
52724
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
    34
#include "jdk_internal_util_SystemProps_Raw.h"
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
#define OBJ "Ljava/lang/Object;"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
/* Only register the performance-critical methods */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
static JNINativeMethod methods[] = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    {"currentTimeMillis", "()J",              (void *)&JVM_CurrentTimeMillis},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    {"nanoTime",          "()J",              (void *)&JVM_NanoTime},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    {"arraycopy",     "(" OBJ "I" OBJ "II)V", (void *)&JVM_ArrayCopy},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
#undef OBJ
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
Java_java_lang_System_registerNatives(JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    (*env)->RegisterNatives(env, cls,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
                            methods, sizeof(methods)/sizeof(methods[0]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
JNIEXPORT jint JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
Java_java_lang_System_identityHashCode(JNIEnv *env, jobject this, jobject x)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    return JVM_IHashCode(env, x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
52724
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
    60
/* VENDOR, VENDOR_URL, VENDOR_URL_BUG are set in VersionProps.java.template. */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
52724
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
    62
/*
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
    63
 * Store the UTF-8 string encoding of the value in the array
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
    64
 * at the index if the value is non-null.  Store nothing if the value is null.
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
    65
 * On any error, return from Java_jdk_internal_util_SystemProps_00024Raw_platformProperties.
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
    66
 */
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
    67
#define PUTPROP(array, prop_index, val)                    \
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
    68
    if (val != NULL) {                                     \
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
    69
        jstring jval = (*env)->NewStringUTF(env, val);     \
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
    70
        if (jval == NULL)                                  \
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
    71
            return NULL;                                   \
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
    72
        (*env)->SetObjectArrayElement(env, array, jdk_internal_util_SystemProps_Raw_##prop_index, jval); \
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
    73
        if ((*env)->ExceptionOccurred(env))                \
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
    74
            return NULL;                                   \
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
    75
        (*env)->DeleteLocalRef(env, jval);                 \
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    76
    }
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    77
52724
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
    78
/*
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
    79
 * Store the Platform string encoding of the value in the array
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
    80
 * at the index if the value is non-null.  Store nothing if the value is null.
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
    81
 * On any error, return from Java_jdk_internal_util_SystemProps_00024Raw_platformProperties.
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
    82
 */
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
    83
#define PUTPROP_PlatformString(array, prop_index, val)     \
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
    84
    if (val != NULL) {                                     \
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
    85
        jstring jval = GetStringPlatform(env, val);        \
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
    86
        if (jval == NULL)                                  \
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
    87
            return NULL;                                   \
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
    88
        (*env)->SetObjectArrayElement(env, array, jdk_internal_util_SystemProps_Raw_##prop_index, jval); \
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
    89
        if ((*env)->ExceptionOccurred(env))                \
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
    90
            return NULL;                                   \
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
    91
        (*env)->DeleteLocalRef(env, jval);                 \
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
    92
    }
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    93
52724
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
    94
/*
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
    95
 * Gather the system properties and return as a String[].
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
    96
 * The first FIXED_LENGTH entries are the platform defined property values, no names.
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
    97
 * The remaining array indices are alternating key/value pairs
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
    98
 * supplied by the VM including those defined on the command line
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
    99
 * using -Dkey=value that may override the platform defined value.
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   100
 * The caller is responsible for replacing platform provided values as needed.
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   101
 *
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   102
 * Class:     jdk_internal_util_SystemProps_Raw
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   103
 * Method:    platformProperties
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   104
 * Signature: ()[Ljava/lang/String;
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   105
 */
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   106
JNIEXPORT jobjectArray JNICALL
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   107
Java_jdk_internal_util_SystemProps_00024Raw_platformProperties(JNIEnv *env, jclass cla)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
{
22641
e47f8892133e 8033372: Check jdk/src/share/native/java/lang for JNI pending exception issues
alanb
parents: 21130
diff changeset
   109
    java_props_t *sprops;
52724
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   110
    jobject propArray = NULL;
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   111
    jclass classString;
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   112
    int nstrings = jdk_internal_util_SystemProps_Raw_FIXED_LENGTH;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
52724
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   114
    // Get the platform specific values
22641
e47f8892133e 8033372: Check jdk/src/share/native/java/lang for JNI pending exception issues
alanb
parents: 21130
diff changeset
   115
    sprops = GetJavaProperties(env);
e47f8892133e 8033372: Check jdk/src/share/native/java/lang for JNI pending exception issues
alanb
parents: 21130
diff changeset
   116
    CHECK_NULL_RETURN(sprops, NULL);
e47f8892133e 8033372: Check jdk/src/share/native/java/lang for JNI pending exception issues
alanb
parents: 21130
diff changeset
   117
52724
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   118
    /*
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   119
     * !!! DO NOT call PUTPROP_PlatformString (NewStringPlatform) before this line !!!
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   120
     */
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   121
    InitializeEncoding(env, sprops->sun_jnu_encoding);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
52724
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   123
    // Ensure capacity for the array and for a string for each fixed length element
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   124
    if ((*env)->EnsureLocalCapacity(env, nstrings + 2) < 0) {
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   125
        return NULL;
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   126
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
52724
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   128
    // Allocate an array of String for all the well known props
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   129
    classString = JNU_ClassString(env);
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   130
    CHECK_NULL_RETURN(classString, NULL);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
52724
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   132
    propArray = (*env)->NewObjectArray(env, nstrings, classString, NULL);
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   133
    CHECK_NULL_RETURN(propArray, NULL);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    /* os properties */
52724
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   136
    PUTPROP(propArray, _os_name_NDX, sprops->os_name);
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   137
    PUTPROP(propArray, _os_version_NDX, sprops->os_version);
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   138
    PUTPROP(propArray, _os_arch_NDX, sprops->os_arch);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
16041
b9d38accf302 8005545: Add System property to identify ARCH specific details such as ARM hard-float binaries
vladidan
parents: 15004
diff changeset
   140
#ifdef JDK_ARCH_ABI_PROP_NAME
52724
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   141
    PUTPROP(propArray, _sun_arch_abi_NDX, sprops->sun_arch_abi);
16041
b9d38accf302 8005545: Add System property to identify ARCH specific details such as ARM hard-float binaries
vladidan
parents: 15004
diff changeset
   142
#endif
b9d38accf302 8005545: Add System property to identify ARCH specific details such as ARM hard-float binaries
vladidan
parents: 15004
diff changeset
   143
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    /* file system properties */
52724
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   145
    PUTPROP(propArray, _file_separator_NDX, sprops->file_separator);
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   146
    PUTPROP(propArray, _path_separator_NDX, sprops->path_separator);
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   147
    PUTPROP(propArray, _line_separator_NDX, sprops->line_separator);
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   148
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   149
    PUTPROP(propArray, _file_encoding_NDX, sprops->encoding);
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   150
    PUTPROP(propArray, _sun_jnu_encoding_NDX, sprops->sun_jnu_encoding);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    /*
49292
dde7eaaa3ddc 8199756: Simplify language, country, script, and variant property initialization
rriggs
parents: 49213
diff changeset
   153
     * file encoding for stdout and stderr
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     */
52724
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   155
    PUTPROP(propArray, _sun_stdout_encoding_NDX, sprops->sun_stdout_encoding);
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   156
    PUTPROP(propArray, _sun_stderr_encoding_NDX, sprops->sun_stderr_encoding);
11906
dc984e35d8a6 4153167: separate between ANSI and OEM code pages on Windows
sherman
parents: 9036
diff changeset
   157
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    /* unicode_encoding specifies the default endianness */
52724
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   159
    PUTPROP(propArray, _sun_io_unicode_encoding_NDX, sprops->unicode_encoding);
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   160
    PUTPROP(propArray, _sun_cpu_endian_NDX, sprops->cpu_endian);
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   161
    PUTPROP(propArray, _sun_cpu_isalist_NDX, sprops->cpu_isalist);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11906
diff changeset
   162
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11906
diff changeset
   163
#ifdef MACOSX
52724
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   164
    PUTPROP(propArray, _java_awt_headless_NDX, sprops->awt_headless);
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   165
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11906
diff changeset
   166
    /* Proxy setting properties */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11906
diff changeset
   167
    if (sprops->httpProxyEnabled) {
52724
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   168
        PUTPROP(propArray, _http_proxyHost_NDX, sprops->httpHost);
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   169
        PUTPROP(propArray, _http_proxyPort_NDX, sprops->httpPort);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11906
diff changeset
   170
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11906
diff changeset
   171
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11906
diff changeset
   172
    if (sprops->httpsProxyEnabled) {
52724
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   173
        PUTPROP(propArray, _https_proxyHost_NDX, sprops->httpsHost);
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   174
        PUTPROP(propArray, _https_proxyPort_NDX, sprops->httpsPort);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11906
diff changeset
   175
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11906
diff changeset
   176
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11906
diff changeset
   177
    if (sprops->ftpProxyEnabled) {
52724
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   178
        PUTPROP(propArray, _ftp_proxyHost_NDX, sprops->ftpHost);
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   179
        PUTPROP(propArray, _ftp_proxyPort_NDX, sprops->ftpPort);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11906
diff changeset
   180
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11906
diff changeset
   181
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11906
diff changeset
   182
    if (sprops->socksProxyEnabled) {
52724
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   183
        PUTPROP(propArray, _socksProxyHost_NDX, sprops->socksHost);
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   184
        PUTPROP(propArray, _socksProxyPort_NDX, sprops->socksPort);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11906
diff changeset
   185
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11906
diff changeset
   186
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11906
diff changeset
   187
    if (sprops->gopherProxyEnabled) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11906
diff changeset
   188
        // The gopher client is different in that it expects an 'is this set?' flag that the others don't.
52724
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   189
        PUTPROP(propArray, _gopherProxySet_NDX, "true");
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   190
        PUTPROP(propArray, _gopherProxyHost_NDX, sprops->gopherHost);
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   191
        PUTPROP(propArray, _gopherProxyPort_NDX, sprops->gopherPort);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11906
diff changeset
   192
    } else {
52724
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   193
        PUTPROP(propArray, _gopherProxySet_NDX, "false");
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11906
diff changeset
   194
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11906
diff changeset
   195
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11906
diff changeset
   196
    // Mac OS X only has a single proxy exception list which applies
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11906
diff changeset
   197
    // to all protocols
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11906
diff changeset
   198
    if (sprops->exceptionList) {
52724
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   199
        PUTPROP(propArray, _http_nonProxyHosts_NDX, sprops->exceptionList);
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   200
        PUTPROP(propArray, _ftp_nonProxyHosts_NDX, sprops->exceptionList);
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   201
        PUTPROP(propArray, _socksNonProxyHosts_NDX, sprops->exceptionList);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11906
diff changeset
   202
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11906
diff changeset
   203
#endif
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11906
diff changeset
   204
52724
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   205
    /* data model */
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   206
    if (sizeof(sprops) == 4) {
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   207
        sprops->data_model = "32";
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   208
    } else if (sizeof(sprops) == 8) {
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   209
        sprops->data_model = "64";
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   210
    } else {
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   211
        sprops->data_model = "unknown";
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   212
    }
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   213
    PUTPROP(propArray, _sun_arch_data_model_NDX, sprops->data_model);
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   214
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   215
    /* patch level */
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   216
    PUTPROP(propArray, _sun_os_patch_level_NDX, sprops->patch_level);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    /* Printing properties */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    /* Note: java.awt.printerjob is an implementation private property which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * just happens to have a java.* name because it is referenced in
6676
c8629a8bbd7d 6946527: rebranding system properties per Oracle Requirements (vendor)
ohair
parents: 5506
diff changeset
   221
     * a java.awt class. It is the mechanism by which the implementation
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * finds the appropriate class in the JRE for the platform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * It is explicitly not designed to be overridden by clients as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * a way of replacing the implementation class, and in any case
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * the mechanism by which the class is loaded is constrained to only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * find and load classes that are part of the JRE.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * This property may be removed if that mechanism is redesigned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     */
52724
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   229
    PUTPROP(propArray, _java_awt_printerjob_NDX, sprops->printerJob);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
52724
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   231
    PUTPROP(propArray, _awt_toolkit_NDX, sprops->awt_toolkit);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    /* Java2D properties */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    /* Note: java.awt.graphicsenv is an implementation private property which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * just happens to have a java.* name because it is referenced in
6676
c8629a8bbd7d 6946527: rebranding system properties per Oracle Requirements (vendor)
ohair
parents: 5506
diff changeset
   236
     * a java.awt class. It is the mechanism by which the implementation
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * finds the appropriate class in the JRE for the platform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * It is explicitly not designed to be overridden by clients as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * a way of replacing the implementation class, and in any case
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * the mechanism by which the class is loaded is constrained to only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * find and load classes that are part of the JRE.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * This property may be removed if that mechanism is redesigned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     */
52724
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   244
    PUTPROP(propArray, _java_awt_graphicsenv_NDX, sprops->graphics_env);
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   245
    PUTPROP_PlatformString(propArray, _sun_java2d_fontpath_NDX, sprops->font_dir);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
52724
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   247
    /*
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   248
     * The sun.desktop property is currently only set for Gnome and Windows desktops.
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   249
     */
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   250
    PUTPROP(propArray, _sun_desktop_NDX, sprops->desktop);
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   251
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   252
    PUTPROP_PlatformString(propArray, _java_io_tmpdir_NDX, sprops->tmp_dir);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
52724
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   254
    PUTPROP_PlatformString(propArray, _user_name_NDX, sprops->user_name);
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   255
    PUTPROP_PlatformString(propArray, _user_home_NDX, sprops->user_home);
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   256
    PUTPROP_PlatformString(propArray, _user_dir_NDX, sprops->user_dir);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
52724
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   258
   /*
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   259
    * Set i18n related property fields from platform.
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   260
    */
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   261
   PUTPROP(propArray, _display_language_NDX, sprops->display_language);
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   262
   PUTPROP(propArray, _display_script_NDX, sprops->display_script);
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   263
   PUTPROP(propArray, _display_country_NDX, sprops->display_country);
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   264
   PUTPROP(propArray, _display_variant_NDX, sprops->display_variant);
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   265
52724
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   266
   PUTPROP(propArray, _format_language_NDX, sprops->format_language);
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   267
   PUTPROP(propArray, _format_script_NDX, sprops->format_script);
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   268
   PUTPROP(propArray, _format_country_NDX, sprops->format_country);
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   269
   PUTPROP(propArray, _format_variant_NDX, sprops->format_variant);
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   270
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   271
   return propArray;
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   272
}
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   273
52724
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   274
/*
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   275
 * Gather the VM and command line properties and return as a String[].
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   276
 * The array indices are alternating key/value pairs
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   277
 * supplied by the VM including those defined on the command line
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   278
 * using -Dkey=value that may override the platform defined value.
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   279
 *
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   280
 * Note: The platform encoding must have been set.
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   281
 *
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   282
 * Class:     jdk_internal_util_SystemProps_Raw
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   283
 * Method:    vmProperties
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   284
 * Signature: ()[Ljava/lang/String;
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   285
 */
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   286
JNIEXPORT jobjectArray JNICALL
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   287
Java_jdk_internal_util_SystemProps_00024Raw_vmProperties(JNIEnv *env, jclass cla)
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   288
{
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   289
    jobjectArray cmdProps = JVM_GetProperties(env);
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52478
diff changeset
   290
    return cmdProps;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
 * The following three functions implement setter methods for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
 * java.lang.System.{in, out, err}. They are natively implemented
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
 * because they violate the semantics of the language (i.e. set final
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
 * variable).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
Java_java_lang_System_setIn0(JNIEnv *env, jclass cla, jobject stream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    jfieldID fid =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        (*env)->GetStaticFieldID(env,cla,"in","Ljava/io/InputStream;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    if (fid == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    (*env)->SetStaticObjectField(env,cla,fid,stream);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
Java_java_lang_System_setOut0(JNIEnv *env, jclass cla, jobject stream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    jfieldID fid =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        (*env)->GetStaticFieldID(env,cla,"out","Ljava/io/PrintStream;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    if (fid == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    (*env)->SetStaticObjectField(env,cla,fid,stream);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
Java_java_lang_System_setErr0(JNIEnv *env, jclass cla, jobject stream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    jfieldID fid =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        (*env)->GetStaticFieldID(env,cla,"err","Ljava/io/PrintStream;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    if (fid == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    (*env)->SetStaticObjectField(env,cla,fid,stream);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
static void cpchars(jchar *dst, char *src, int n)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    for (i = 0; i < n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        dst[i] = src[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
JNIEXPORT jstring JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
Java_java_lang_System_mapLibraryName(JNIEnv *env, jclass ign, jstring libname)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    int len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    int prefix_len = (int) strlen(JNI_LIB_PREFIX);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    int suffix_len = (int) strlen(JNI_LIB_SUFFIX);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    jchar chars[256];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    if (libname == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        JNU_ThrowNullPointerException(env, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    len = (*env)->GetStringLength(env, libname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    if (len > 240) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        JNU_ThrowIllegalArgumentException(env, "name too long");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    cpchars(chars, JNI_LIB_PREFIX, prefix_len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    (*env)->GetStringRegion(env, libname, 0, len, chars + prefix_len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    len += prefix_len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    cpchars(chars + len, JNI_LIB_SUFFIX, suffix_len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    len += suffix_len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    return (*env)->NewString(env, chars, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
}