jdk/src/share/native/sun/misc/VM.c
author mchung
Mon, 05 Oct 2009 18:15:32 -0700
changeset 3958 b8acd5ee4f4f
parent 3111 fefdeafb7ab9
child 5506 202f599c92aa
permissions -rw-r--r--
6612680: Remove classloader dependency on jkernel Summary: Add a new sun.misc.BootClassLoaderHook that DownloadManager will implement Reviewed-by: alanb, forax, igor
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2004-2005 Sun Microsystems, Inc.  All Rights Reserved.
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
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 "jni.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
#include "jni_util.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
#include "jlong.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#include "jvm.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#include "jdk_util.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
#include "sun_misc_VM.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
typedef jintArray (JNICALL *GET_THREAD_STATE_VALUES_FN)(JNIEnv *, jint);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
typedef jobjectArray (JNICALL *GET_THREAD_STATE_NAMES_FN)(JNIEnv *, jint, jintArray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
static GET_THREAD_STATE_VALUES_FN GetThreadStateValues_fp = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
static GET_THREAD_STATE_NAMES_FN GetThreadStateNames_fp = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
static void get_thread_state_info(JNIEnv *env, jint state,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
                                      jobjectArray stateValues,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
                                      jobjectArray stateNames) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    char errmsg[128];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    jintArray values;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    jobjectArray names;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    values = (*GetThreadStateValues_fp)(env, state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    if (values == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
        sprintf(errmsg, "Mismatched VM version: Thread state (%d) "
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
                        "not supported", state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        JNU_ThrowInternalError(env, errmsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    /* state is also used as the index in the array */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    (*env)->SetObjectArrayElement(env, stateValues, state, values);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    names = (*GetThreadStateNames_fp)(env, state, values);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    if (names == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        sprintf(errmsg, "Mismatched VM version: Thread state (%d) "
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
                        "not supported", state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        JNU_ThrowInternalError(env, errmsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    (*env)->SetObjectArrayElement(env, stateNames, state, names);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
Java_sun_misc_VM_getThreadStateValues(JNIEnv *env, jclass cls,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
                                      jobjectArray values,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
                                      jobjectArray names)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    char errmsg[128];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    // check if the number of Thread.State enum constants
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    // matches the number of states defined in jvm.h
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    jsize len1 = (*env)->GetArrayLength(env, values);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    jsize len2 = (*env)->GetArrayLength(env, names);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    if (len1 != JAVA_THREAD_STATE_COUNT || len2 != JAVA_THREAD_STATE_COUNT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        sprintf(errmsg, "Mismatched VM version: JAVA_THREAD_STATE_COUNT = %d "
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
                " but JDK expects %d / %d",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
                JAVA_THREAD_STATE_COUNT, len1, len2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        JNU_ThrowInternalError(env, errmsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    if (GetThreadStateValues_fp == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        GetThreadStateValues_fp = (GET_THREAD_STATE_VALUES_FN)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            JDK_FindJvmEntry("JVM_GetThreadStateValues");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        if (GetThreadStateValues_fp == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            JNU_ThrowInternalError(env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                 "Mismatched VM version: JVM_GetThreadStateValues not found");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        GetThreadStateNames_fp = (GET_THREAD_STATE_NAMES_FN)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            JDK_FindJvmEntry("JVM_GetThreadStateNames");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        if (GetThreadStateNames_fp == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            JNU_ThrowInternalError(env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                 "Mismatched VM version: JVM_GetThreadStateNames not found");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            return ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    get_thread_state_info(env, JAVA_THREAD_STATE_NEW, values, names);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    get_thread_state_info(env, JAVA_THREAD_STATE_RUNNABLE, values, names);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    get_thread_state_info(env, JAVA_THREAD_STATE_BLOCKED, values, names);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    get_thread_state_info(env, JAVA_THREAD_STATE_WAITING, values, names);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    get_thread_state_info(env, JAVA_THREAD_STATE_TIMED_WAITING, values, names);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    get_thread_state_info(env, JAVA_THREAD_STATE_TERMINATED, values, names);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
3111
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   112
typedef void (JNICALL *GetJvmVersionInfo_fp)(JNIEnv*, jvm_version_info*, size_t);
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   113
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
Java_sun_misc_VM_initialize(JNIEnv *env, jclass cls) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    char errmsg[128];
3111
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   117
    GetJvmVersionInfo_fp func_p;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    if (!JDK_InitJvmHandle()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        JNU_ThrowInternalError(env, "Handle for JVM not found for symbol lookup");
3111
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   121
        return;
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   122
    }
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   123
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   124
    func_p = (GetJvmVersionInfo_fp) JDK_FindJvmEntry("JVM_GetVersionInfo");
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   125
     if (func_p != NULL) {
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   126
        char errmsg[100];
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   127
        jfieldID fid;
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   128
        jvm_version_info info;
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   129
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   130
        memset(&info, 0, sizeof(info));
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   131
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   132
        /* obtain the JVM version info */
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   133
        (*func_p)(env, &info, sizeof(info));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
}
3111
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   136