jdk/src/share/native/common/jdk_util.c
author dsimms
Wed, 11 Jun 2014 12:09:12 +0200
changeset 25056 5ad92b0d1beb
parent 10895 7434064aba55
permissions -rw-r--r--
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical. Summary: Wrapped memory with standard bounds checking "GuardedMemory". Reviewed-by: zgu, fparain, dcubed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
9286
b960a50a7052 6994753: Optional tracking of JRE usage.
kevinw
parents: 7668
diff changeset
     2
 * Copyright (c) 2005, 2011, 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: 2
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: 2
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: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
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 <stdlib.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
#include <string.h>
7042
56e990297bc5 6994413: JDK_GetVersionInfo0 only expects a two digit build number
mchung
parents: 6850
diff changeset
    28
#include <ctype.h>
56e990297bc5 6994413: JDK_GetVersionInfo0 only expects a two digit build number
mchung
parents: 6850
diff changeset
    29
#include <assert.h>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
#include "jvm.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
#include "jdk_util.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
#ifndef JDK_UPDATE_VERSION
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
   /* if not defined set to 00 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
   #define JDK_UPDATE_VERSION "00"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
JNIEXPORT void
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
JDK_GetVersionInfo0(jdk_version_info* info, size_t info_size) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    /* These JDK_* macros are set at Makefile or the command line */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    const unsigned int jdk_major_version =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
        (unsigned int) atoi(JDK_MAJOR_VERSION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    const unsigned int jdk_minor_version =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
        (unsigned int) atoi(JDK_MINOR_VERSION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    const unsigned int jdk_micro_version =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
        (unsigned int) atoi(JDK_MICRO_VERSION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    const char* jdk_build_string = JDK_BUILD_NUMBER;
7042
56e990297bc5 6994413: JDK_GetVersionInfo0 only expects a two digit build number
mchung
parents: 6850
diff changeset
    50
    char build_number[4];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    unsigned int jdk_build_number = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    const char* jdk_update_string = JDK_UPDATE_VERSION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    unsigned int jdk_update_version = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    char update_ver[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    char jdk_special_version = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    /* If the JDK_BUILD_NUMBER is of format bXX and XX is an integer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     * XX is the jdk_build_number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     */
7042
56e990297bc5 6994413: JDK_GetVersionInfo0 only expects a two digit build number
mchung
parents: 6850
diff changeset
    61
    int len = strlen(jdk_build_string);
56e990297bc5 6994413: JDK_GetVersionInfo0 only expects a two digit build number
mchung
parents: 6850
diff changeset
    62
    if (jdk_build_string[0] == 'b' && len >= 2) {
56e990297bc5 6994413: JDK_GetVersionInfo0 only expects a two digit build number
mchung
parents: 6850
diff changeset
    63
        int i = 0;
56e990297bc5 6994413: JDK_GetVersionInfo0 only expects a two digit build number
mchung
parents: 6850
diff changeset
    64
        for (i = 1; i < len; i++) {
56e990297bc5 6994413: JDK_GetVersionInfo0 only expects a two digit build number
mchung
parents: 6850
diff changeset
    65
            if (isdigit(jdk_build_string[i])) {
56e990297bc5 6994413: JDK_GetVersionInfo0 only expects a two digit build number
mchung
parents: 6850
diff changeset
    66
                build_number[i-1] = jdk_build_string[i];
56e990297bc5 6994413: JDK_GetVersionInfo0 only expects a two digit build number
mchung
parents: 6850
diff changeset
    67
            } else {
56e990297bc5 6994413: JDK_GetVersionInfo0 only expects a two digit build number
mchung
parents: 6850
diff changeset
    68
                // invalid build number
56e990297bc5 6994413: JDK_GetVersionInfo0 only expects a two digit build number
mchung
parents: 6850
diff changeset
    69
                i = -1;
56e990297bc5 6994413: JDK_GetVersionInfo0 only expects a two digit build number
mchung
parents: 6850
diff changeset
    70
                break;
56e990297bc5 6994413: JDK_GetVersionInfo0 only expects a two digit build number
mchung
parents: 6850
diff changeset
    71
            }
56e990297bc5 6994413: JDK_GetVersionInfo0 only expects a two digit build number
mchung
parents: 6850
diff changeset
    72
        }
56e990297bc5 6994413: JDK_GetVersionInfo0 only expects a two digit build number
mchung
parents: 6850
diff changeset
    73
        if (i == len) {
56e990297bc5 6994413: JDK_GetVersionInfo0 only expects a two digit build number
mchung
parents: 6850
diff changeset
    74
            build_number[len-1] = '\0';
56e990297bc5 6994413: JDK_GetVersionInfo0 only expects a two digit build number
mchung
parents: 6850
diff changeset
    75
            jdk_build_number = (unsigned int) atoi(build_number) ;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    }
7042
56e990297bc5 6994413: JDK_GetVersionInfo0 only expects a two digit build number
mchung
parents: 6850
diff changeset
    78
56e990297bc5 6994413: JDK_GetVersionInfo0 only expects a two digit build number
mchung
parents: 6850
diff changeset
    79
    assert(jdk_build_number >= 0 && jdk_build_number <= 255);
56e990297bc5 6994413: JDK_GetVersionInfo0 only expects a two digit build number
mchung
parents: 6850
diff changeset
    80
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    if (strlen(jdk_update_string) == 2 || strlen(jdk_update_string) == 3) {
7042
56e990297bc5 6994413: JDK_GetVersionInfo0 only expects a two digit build number
mchung
parents: 6850
diff changeset
    82
        if (isdigit(jdk_update_string[0]) && isdigit(jdk_update_string[1])) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            update_ver[0] = jdk_update_string[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            update_ver[1] = jdk_update_string[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            update_ver[2] = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            jdk_update_version = (unsigned int) atoi(update_ver);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            if (strlen(jdk_update_string) == 3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                jdk_special_version = jdk_update_string[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
6850
56966b0a6a0d 6989466: Miscellaneous compiler warnings in java/lang, java/util, java/io, sun/misc native code
alanb
parents: 5506
diff changeset
    93
    memset(info, 0, info_size);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    info->jdk_version = ((jdk_major_version & 0xFF) << 24) |
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                        ((jdk_minor_version & 0xFF) << 16) |
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                        ((jdk_micro_version & 0xFF) << 8)  |
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                        (jdk_build_number & 0xFF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    info->update_version = jdk_update_version;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    info->special_update_version = (unsigned int) jdk_special_version;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    info->thread_park_blocker = 1;
9286
b960a50a7052 6994753: Optional tracking of JRE usage.
kevinw
parents: 7668
diff changeset
   101
    // Advertise presence of sun.misc.PostVMInitHook:
b960a50a7052 6994753: Optional tracking of JRE usage.
kevinw
parents: 7668
diff changeset
   102
    // future optimization: detect if this is enabled.
b960a50a7052 6994753: Optional tracking of JRE usage.
kevinw
parents: 7668
diff changeset
   103
    info->post_vm_init_hook_enabled = 1;
10895
7434064aba55 4243978: (ref) Race condition in Reference.enqueue()
ysr
parents: 9286
diff changeset
   104
    info->pending_list_uses_discovered_field = 1;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
}