1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
|
/*
* Copyright (c) 2003, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
#include <stdio.h>
#include <string.h>
#include <jvmti.h>
#include "agent_common.hpp"
#include "nsk_tools.hpp"
#include "jni_tools.hpp"
#include "JVMTITools.hpp"
#include "jvmti_tools.hpp"
extern "C" {
#define CLS_NUM 5 /* overall number of tested classes */
#define STATUS_FAILED 2
#define PASSED 0
/* expected class signatures are below */
static const char *class_sig[][CLS_NUM] = {
{ "getclsig006", "Lnsk/jvmti/GetClassSignature/getclsig006;", "null" },
{ "getclsig006b", "Lnsk/jvmti/GetClassSignature/getclsig006b;",
"<L:Ljava/lang/String;>Ljava/lang/Object;" },
{ "getclsig006c", "Lnsk/jvmti/GetClassSignature/getclsig006c;",
"<A:Ljava/lang/Object;B:Ljava/lang/Integer;>Ljava/lang/Object;" },
{ "getclsig006if", "Lnsk/jvmti/GetClassSignature/getclsig006if;",
"<I:Ljava/lang/Object;>Ljava/lang/Object;" },
{ "getclsig006g", "Lnsk/jvmti/GetClassSignature/getclsig006g;",
"<E:Lnsk/jvmti/GetClassSignature/getclsig006e;:Lnsk/jvmti/GetClassSignature/getclsig006if;>Ljava/lang/Object;" }
};
static jvmtiEnv *jvmti = nullptr;
static int checkSig(JNIEnv *jni_env, jclass testedCls, int idx) {
int totRes = PASSED;
char *sign;
char *gen_sign;
if (!NSK_JVMTI_VERIFY(jvmti->GetClassSignature(testedCls, &sign, &gen_sign))) {
NSK_COMPLAIN1("TEST FAILED: unable to get class signature for \"%s\"\n\n",
class_sig[idx][0]);
return STATUS_FAILED;
} else {
NSK_DISPLAY1(">>> Checking signatures for \"%s\" ...\n",
class_sig[idx][0]);
if (strcmp(class_sig[idx][1], sign) != 0 ||
strcmp(class_sig[idx][2], (gen_sign == nullptr) ? "null" : gen_sign) != 0) {
NSK_COMPLAIN5(
"TEST FAILED: class: \"%s\" has\n"
"\tsignature: \"%s\"\n"
"\tgeneric signature: \"%s\"\n\n"
"\tExpected: \"%s\"\n"
"\t\"%s\"\n\n",
class_sig[idx][0],
sign, (gen_sign == nullptr) ? "null" : gen_sign,
class_sig[idx][1], class_sig[idx][2]);
totRes = STATUS_FAILED;
}
else
NSK_DISPLAY2("CHECK PASSED: signature: \"%s\",\n\tgeneric signature: \"%s\"\n",
sign, (gen_sign == nullptr) ? "null" : gen_sign);
NSK_DISPLAY0("Deallocating the signature array\n");
if (!NSK_JVMTI_VERIFY(jvmti->Deallocate((unsigned char*) sign))) {
totRes = STATUS_FAILED;
}
if (gen_sign != nullptr)
if (!NSK_JVMTI_VERIFY(jvmti->Deallocate((unsigned char*) gen_sign))) {
totRes = STATUS_FAILED;
}
NSK_DISPLAY0("<<<\n");
}
return totRes;
}
JNIEXPORT jint JNICALL
Java_nsk_jvmti_GetClassSignature_getclsig006_check(
JNIEnv *jni, jobject obj) {
int res = PASSED, i;
jclass testedCls;
for (i=0; i<CLS_NUM; i++) {
if (!NSK_JNI_VERIFY(jni, (testedCls = jni->FindClass(class_sig[i][1])) != nullptr)) {
NSK_COMPLAIN1("TEST FAILURE: unable to find class \"%s\"\n\n",
class_sig[i][0]);
res = STATUS_FAILED;
continue;
}
if (checkSig(jni, testedCls, i) == STATUS_FAILED)
res = STATUS_FAILED;
}
return res;
}
#ifdef STATIC_BUILD
JNIEXPORT jint JNICALL Agent_OnLoad_getclsig006(JavaVM *jvm, char *options, void *reserved) {
return Agent_Initialize(jvm, options, reserved);
}
JNIEXPORT jint JNICALL Agent_OnAttach_getclsig006(JavaVM *jvm, char *options, void *reserved) {
return Agent_Initialize(jvm, options, reserved);
}
JNIEXPORT jint JNI_OnLoad_getclsig006(JavaVM *jvm, char *options, void *reserved) {
return JNI_VERSION_1_8;
}
#endif
jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
/* init framework and parse options */
if (!NSK_VERIFY(nsk_jvmti_parseOptions(options)))
return JNI_ERR;
/* create JVMTI environment */
if (!NSK_VERIFY((jvmti =
nsk_jvmti_createJVMTIEnv(jvm, reserved)) != nullptr))
return JNI_ERR;
return JNI_OK;
}
}
|