hotspot/test/serviceability/jvmti/GetNamedModule/libGetNamedModuleTest.c
author lana
Thu, 23 Feb 2017 17:30:12 +0000
changeset 44011 5eea3031ae7b
parent 39706 8b8fd966478b
child 44330 aaa5ce0d9d01
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
39706
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
     1
/*
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
     4
 *
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
     7
 * published by the Free Software Foundation.
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
     8
 *
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    13
 * accompanied this code).
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    14
 *
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    18
 *
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    21
 * questions.
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    22
 */
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    23
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    24
#include <stdio.h>
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    25
#include <string.h>
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    26
#include "jvmti.h"
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    27
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    28
#ifdef __cplusplus
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    29
extern "C" {
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    30
#endif
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    31
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    32
#ifndef JNI_ENV_ARG
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    33
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    34
#ifdef __cplusplus
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    35
#define JNI_ENV_ARG(x, y) y
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    36
#define JNI_ENV_PTR(x) x
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    37
#else
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    38
#define JNI_ENV_ARG(x,y) x, y
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    39
#define JNI_ENV_PTR(x) (*x)
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    40
#endif
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    41
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    42
#endif
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    43
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    44
#define TranslateError(err) "JVMTI error"
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    45
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    46
#define PASSED 0
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    47
#define FAILED 2
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    48
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    49
static const char *EXC_CNAME = "java/lang/Exception";
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    50
static const char* MOD_CNAME = "Ljava/lang/reflect/Module;";
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    51
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    52
static jvmtiEnv *jvmti = NULL;
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    53
static jint result = PASSED;
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    54
static jboolean printdump = JNI_FALSE;
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    55
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    56
static jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved);
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    57
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    58
JNIEXPORT
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    59
jint JNICALL Agent_OnLoad(JavaVM *jvm, char *options, void *reserved) {
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    60
    return Agent_Initialize(jvm, options, reserved);
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    61
}
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    62
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    63
JNIEXPORT
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    64
jint JNICALL Agent_OnAttach(JavaVM *jvm, char *options, void *reserved) {
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    65
    return Agent_Initialize(jvm, options, reserved);
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    66
}
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    67
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    68
JNIEXPORT
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    69
jint JNICALL JNI_OnLoad(JavaVM *jvm, void *reserved) {
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    70
    return JNI_VERSION_1_8;
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    71
}
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    72
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    73
static
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    74
jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    75
    jint res;
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    76
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    77
    if (options != NULL && strcmp(options, "printdump") == 0) {
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    78
        printdump = JNI_TRUE;
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    79
    }
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    80
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    81
    res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti),
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    82
        JVMTI_VERSION_9);
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    83
    if (res != JNI_OK || jvmti == NULL) {
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    84
        printf("    Error: wrong result of a valid call to GetEnv!\n");
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    85
        return JNI_ERR;
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    86
    }
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    87
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    88
    return JNI_OK;
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    89
}
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    90
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    91
static
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    92
jint throw_exc(JNIEnv *env, char *msg) {
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    93
    jclass exc_class = JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG(env, EXC_CNAME));
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    94
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    95
    if (exc_class == NULL) {
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    96
        printf("throw_exc: Error in FindClass(env, %s)\n", EXC_CNAME);
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    97
        return -1;
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    98
    }
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
    99
    return JNI_ENV_PTR(env)->ThrowNew(JNI_ENV_ARG(env, exc_class), msg);
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   100
}
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   101
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   102
static
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   103
jobject get_class_loader(jclass cls) {
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   104
    jvmtiError err = JVMTI_ERROR_NONE;
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   105
    jobject loader = NULL;
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   106
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   107
    if (printdump == JNI_TRUE) {
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   108
        printf(">>> getting class loader ...\n");
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   109
    }
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   110
    err = (*jvmti)->GetClassLoader(jvmti, cls, &loader);
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   111
    if (err != JVMTI_ERROR_NONE) {
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   112
        printf("    Error in GetClassLoader: %s (%d)\n", TranslateError(err), err);
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   113
    }
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   114
    return loader;
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   115
}
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   116
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   117
static
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   118
jclass jlrM(JNIEnv *env) {
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   119
    jclass cls = NULL;
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   120
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   121
    cls = JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG(env, MOD_CNAME));
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   122
    if (cls == NULL) {
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   123
        printf("    Error in JNI FindClass: %s\n", MOD_CNAME);
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   124
    }
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   125
    return cls;
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   126
}
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   127
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   128
jmethodID
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   129
get_method(JNIEnv *env, jclass clazz, const char * name, const char *sig) {
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   130
    jmethodID method = NULL;
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   131
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   132
    method = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, clazz), name, sig);
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   133
    if (method == NULL) {
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   134
        printf("    Error in JNI GetMethodID %s with signature %s", name, sig);
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   135
    }
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   136
    return method;
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   137
}
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   138
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   139
static
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   140
jobject get_module_loader(JNIEnv *env, jobject module) {
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   141
    static jmethodID cl_method = NULL;
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   142
    jobject loader = NULL;
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   143
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   144
    if (cl_method == NULL) {
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   145
        cl_method = get_method(env, jlrM(env), "getClassLoader", "()Ljava/lang/ClassLoader;");
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   146
    }
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   147
    loader = (jobject)JNI_ENV_PTR(env)->CallObjectMethod(JNI_ENV_ARG(env, module), cl_method);
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   148
    return loader;
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   149
}
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   150
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   151
static
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   152
const char* get_module_name(JNIEnv *env, jobject module) {
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   153
    static jmethodID method = NULL;
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   154
    jobject loader = NULL;
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   155
    jstring jstr = NULL;
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   156
    const char *name = NULL;
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   157
    const char *nstr = NULL;
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   158
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   159
    if (method == NULL) {
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   160
        method = get_method(env, jlrM(env), "getName", "()Ljava/lang/String;");
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   161
    }
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   162
    jstr = (jstring)JNI_ENV_PTR(env)->CallObjectMethod(JNI_ENV_ARG(env, module), method);
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   163
    if (jstr != NULL) {
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   164
        name = JNI_ENV_PTR(env)->GetStringUTFChars(JNI_ENV_ARG(env, jstr), NULL);
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   165
    }
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   166
    loader = get_module_loader(env, module);
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   167
    nstr = (name == NULL) ? "<UNNAMED>" : name;
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   168
    printf("    loader: %p, module: %p, name: %s\n", loader, module, nstr);
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   169
    return name;
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   170
}
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   171
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   172
static
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   173
jvmtiError get_module(JNIEnv *env,
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   174
                      jobject loader,
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   175
                      const char* pkg_name,
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   176
                      jobject* module_ptr,
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   177
                      const char** mod_name_ptr) {
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   178
    jvmtiError err = JVMTI_ERROR_NONE;
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   179
    const char* name = (pkg_name == NULL) ? "<NULL>" : pkg_name;
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   180
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   181
    printf(">>> getting module by loader %p and package \"%s\"\n", loader, name);
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   182
    *mod_name_ptr = NULL;
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   183
    err = (*jvmti)->GetNamedModule(jvmti, loader, pkg_name, module_ptr);
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   184
    if (err != JVMTI_ERROR_NONE) {
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   185
        printf("    Error in GetNamedModule for package \"%s\": %s (%d)\n",
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   186
               pkg_name, TranslateError(err), err);
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   187
        return err;
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   188
    }
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   189
    printf("    returned module: %p\n", *module_ptr);
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   190
    if (*module_ptr == NULL) { // named module was not found
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   191
        return err;
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   192
    }
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   193
    *mod_name_ptr = get_module_name(env, *module_ptr);
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   194
    return err;
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   195
}
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   196
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   197
static
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   198
jint get_all_modules(JNIEnv *env) {
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   199
    jvmtiError err;
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   200
    jint cnt = -1;
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   201
    jint idx = 0;
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   202
    jobject* modules;
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   203
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   204
    printf(">>> Inspecting modules with GetAllModules\n");
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   205
    err = (*jvmti)->GetAllModules(jvmti, &cnt, &modules);
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   206
    if (err != JVMTI_ERROR_NONE) {
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   207
        printf("Error in GetAllModules: %d\n", err);
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   208
        return -1;
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   209
    }
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   210
    for (idx = 0; idx < cnt; ++idx) {
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   211
        get_module_name(env, modules[idx]);
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   212
    }
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   213
    return cnt;
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   214
}
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   215
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   216
static
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   217
jint check_bad_loader(JNIEnv *env, jobject loader) {
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   218
    jvmtiError err = JVMTI_ERROR_NONE;
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   219
    jobject module = NULL;
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   220
    const char* mod_name = NULL;
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   221
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   222
    err = get_module(env, loader, "", &module, &mod_name);
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   223
    if (err != JVMTI_ERROR_ILLEGAL_ARGUMENT) {
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   224
        return FAILED;
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   225
    }
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   226
    printf("    got expected JVMTI_ERROR_ILLEGAL_ARGUMENT for bad loader\n");
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   227
    return PASSED;
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   228
}
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   229
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   230
static
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   231
jint check_system_loader(JNIEnv *env, jobject loader) {
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   232
    jvmtiError err = JVMTI_ERROR_NONE;
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   233
    jobject module = NULL;
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   234
    const char* exp_name = NULL;
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   235
    const char* mod_name = NULL;
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   236
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   237
    // NULL pointer for package name
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   238
    err = get_module(env, loader, NULL, &module, &mod_name);
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   239
    if (err != JVMTI_ERROR_NULL_POINTER) {
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   240
        throw_exc(env, "check #SN1: failed to return JVMTI_ERROR_NULL_POINTER for NULL package");
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   241
        return FAILED;
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   242
    }
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   243
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   244
    // NULL pointer for module_ptr
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   245
    err = (*jvmti)->GetNamedModule(jvmti, loader, "", NULL);
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   246
    if (err != JVMTI_ERROR_NULL_POINTER) {
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   247
        throw_exc(env, "check #SN2: failed to return JVMTI_ERROR_NULL_POINTER for NULL module_ptr");
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   248
        return FAILED;
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   249
    }
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   250
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   251
    // Unnamed/default package ""
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   252
    err = get_module(env, loader, "", &module, &mod_name);
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   253
    if (err != JVMTI_ERROR_NONE) {
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   254
        throw_exc(env, "check #S1: failed to return JVMTI_ERROR_NONE for default package");
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   255
        return FAILED;
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   256
    }
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   257
    if (module != NULL || mod_name != NULL) {
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   258
        throw_exc(env, "check #S2: failed to return NULL-module for default package");
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   259
        return FAILED;
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   260
    }
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   261
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   262
    // Test package: MyPackage
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   263
    err = get_module(env, loader, "MyPackage", &module, &mod_name);
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   264
    if (err != JVMTI_ERROR_NONE) {
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   265
        throw_exc(env, "check #S3: failed to return JVMTI_ERROR_NONE for MyPackage");
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   266
        return FAILED;
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   267
    }
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   268
    if (module != NULL || mod_name != NULL) {
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   269
        throw_exc(env, "check #S4: failed to return NULL-module for MyPackage");
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   270
        return FAILED;
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   271
    }
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   272
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   273
    // Package: com/sun/jdi
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   274
    exp_name = "jdk.jdi";
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   275
    err = get_module(env, loader, "com/sun/jdi", &module, &mod_name);
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   276
    if (err != JVMTI_ERROR_NONE) {
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   277
        throw_exc(env, "check #S5: failed to return JVMTI_ERROR_NONE for test package");
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   278
        return FAILED;
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   279
    }
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   280
    if (module == NULL || mod_name == NULL) {
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   281
        throw_exc(env, "check #S6: failed to return named module for com/sun/jdi package");
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   282
        return FAILED;
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   283
    }
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   284
    if (strcmp(mod_name, exp_name) != 0) {
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   285
        printf("check #S7: failed to return right module, expected: %s, returned: %s\n",
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   286
               exp_name, mod_name);
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   287
        throw_exc(env, "check #S7: failed to return jdk.jdi module for com/sun/jdi package");
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   288
        return FAILED;
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   289
    }
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   290
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   291
    // Non-existing package: "bad/package/name"
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   292
    err = get_module(env, loader, "bad/package/name", &module, &mod_name);
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   293
    if (err != JVMTI_ERROR_NONE) {
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   294
        throw_exc(env, "check #S8: failed to return JVMTI_ERROR_NONE for bad package");
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   295
        return FAILED;
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   296
    }
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   297
    if (module != NULL || mod_name != NULL) {
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   298
        throw_exc(env, "check #S9: failed to return NULL-module for bad package");
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   299
        return FAILED;
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   300
    }
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   301
    return PASSED;
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   302
}
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   303
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   304
static
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   305
jint check_bootstrap_loader(JNIEnv *env, jobject loader) {
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   306
    jvmtiError err = JVMTI_ERROR_NONE;
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   307
    jobject module = NULL;
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   308
    const char* exp_name = NULL;
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   309
    const char* mod_name = NULL;
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   310
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   311
    // NULL pointer for package name
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   312
    err = get_module(env, loader, NULL, &module, &mod_name);
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   313
    if (err != JVMTI_ERROR_NULL_POINTER) {
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   314
        throw_exc(env, "check #BN1: failed to return JVMTI_ERROR_NULL_POINTER for NULL package");
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   315
        return FAILED;
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   316
    }
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   317
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   318
    // NULL pointer for module_ptr
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   319
    err = (*jvmti)->GetNamedModule(jvmti, loader, "", NULL);
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   320
    if (err != JVMTI_ERROR_NULL_POINTER) {
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   321
        throw_exc(env, "check #BN2: failed to return JVMTI_ERROR_NULL_POINTER for NULL module_ptr");
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   322
        return FAILED;
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   323
    }
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   324
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   325
    // Unnamed/default package ""
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   326
    err = get_module(env, loader, "", &module, &mod_name);
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   327
    if (err != JVMTI_ERROR_NONE) {
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   328
        throw_exc(env, "check #B1: failed to return JVMTI_ERROR_NONE for default package");
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   329
        return FAILED;
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   330
    }
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   331
    if (module != NULL || mod_name != NULL) {
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   332
        throw_exc(env, "check #B2: failed to return NULL-module for default package");
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   333
        return FAILED;
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   334
    }
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   335
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   336
    // Normal package from java.base module: "java/lang"
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   337
    exp_name = "java.base";
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   338
    err = get_module(env, loader, "java/lang", &module, &mod_name);
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   339
    if (err != JVMTI_ERROR_NONE) {
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   340
        throw_exc(env, "check #B3: failed to return JVMTI_ERROR_NONE for java/lang package");
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   341
        return FAILED;
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   342
    }
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   343
    if (module == NULL || mod_name == NULL) {
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   344
        throw_exc(env, "check #B4: failed to return named module for java/lang package");
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   345
        return FAILED;
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   346
    }
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   347
    if (strcmp(exp_name, mod_name) != 0) {
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   348
        printf("check #B5: failed to return right module, expected: %s, returned: %s\n",
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   349
               exp_name, mod_name);
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   350
        throw_exc(env, "check #B5: failed to return expected module for java/lang package");
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   351
        return FAILED;
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   352
    }
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   353
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   354
    // Non-existing package: "bad/package/name"
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   355
    err = get_module(env, loader, "bad/package/name", &module, &mod_name);
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   356
    if (err != JVMTI_ERROR_NONE) {
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   357
        throw_exc(env, "check #B6: failed to return JVMTI_ERROR_NONE for bad package");
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   358
        return FAILED;
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   359
    }
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   360
    if (module != NULL || mod_name != NULL) {
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   361
        throw_exc(env, "check #B7: failed to return NULL-module for bad package");
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   362
        return FAILED;
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   363
    }
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   364
    return PASSED;
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   365
}
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   366
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   367
JNIEXPORT jint JNICALL
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   368
Java_MyPackage_GetNamedModuleTest_check(JNIEnv *env, jclass cls) {
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   369
    jobject loader = NULL;
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   370
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   371
    if (jvmti == NULL) {
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   372
        throw_exc(env, "JVMTI client was not properly loaded!\n");
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   373
        return FAILED;
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   374
    }
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   375
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   376
    get_all_modules(env);
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   377
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   378
    printf("\n*** Check for bad ClassLoader ***\n\n");
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   379
    result = check_bad_loader(env, (jobject)cls);
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   380
    if (result != PASSED) {
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   381
        throw_exc(env, "check #L1: failed to return JVMTI_ERROR_ILLEGAL_ARGUMENT for bad loader");
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   382
        return result;
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   383
    }
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   384
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   385
    loader = get_class_loader(cls);
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   386
    if (loader == NULL) {
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   387
        throw_exc(env, "check #L2: failed to return non-NULL loader for valid test class");
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   388
        return FAILED;
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   389
    }
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   390
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   391
    printf("\n*** Checks for System ClassLoader ***\n\n");
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   392
    result = check_system_loader(env, loader);
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   393
    if (result != PASSED) {
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   394
        return result;
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   395
    }
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   396
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   397
    printf("\n*** Checks for Bootstrap ClassLoader ***\n\n");
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   398
    result = check_bootstrap_loader(env, NULL);
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   399
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   400
    return result;
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   401
}
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   402
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   403
#ifdef __cplusplus
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   404
}
8b8fd966478b 8159145: Add JVMTI function GetNamedModule
sspitsyn
parents:
diff changeset
   405
#endif