1
1
/*
2
- * Copyright (c) 2003, 2020 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2003, 2021 , Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
@@ -62,6 +62,12 @@ static class_info classes[] = {
62
62
{ " Lnsk/jvmti/ClassPrepare/classprep001$TestInterface;" , EXP_STATUS, 2 , 1 , 0 },
63
63
{ " Lnsk/jvmti/ClassPrepare/classprep001$TestClass;" , EXP_STATUS, 3 , 2 , 1 }
64
64
};
65
+ // These classes are loaded on a different thread.
66
+ // We should not get ClassPrepare events for them.
67
+ static const class_info unexpectedClasses[] = {
68
+ { " Lnsk/jvmti/ClassPrepare/classprep001$TestInterface2;" , 0 , 0 , 0 , 0 },
69
+ { " Lnsk/jvmti/ClassPrepare/classprep001$TestClass2;" , 0 , 0 , 0 , 0 }
70
+ };
65
71
66
72
void printStatus (jint status) {
67
73
int flags = 0 ;
@@ -87,6 +93,17 @@ void printStatus(jint status) {
87
93
printf (" (0x%x)\n " , status);
88
94
}
89
95
96
+ const size_t NOT_FOUND = (size_t )(-1 );
97
+
98
+ size_t findClass (const char *classSig, const class_info *arr, int size) {
99
+ for (int i = 0 ; i < size; i++) {
100
+ if (strcmp (classSig, arr[i].sig ) == 0 ) {
101
+ return i;
102
+ }
103
+ }
104
+ return NOT_FOUND;
105
+ }
106
+
90
107
void JNICALL ClassPrepare (jvmtiEnv *jvmti_env, JNIEnv *env,
91
108
jthread thr, jclass cls) {
92
109
jvmtiError err;
@@ -188,19 +205,25 @@ void JNICALL ClassPrepare(jvmtiEnv *jvmti_env, JNIEnv *env,
188
205
printf (" \n " );
189
206
}
190
207
191
- if (eventsCount >= eventsExpected) {
192
- printf (" (#%" PRIuPTR " ) too many events: %" PRIuPTR " , expected: %" PRIuPTR " \n " ,
193
- eventsCount, eventsCount + 1 , eventsExpected);
194
- result = STATUS_FAILED;
208
+ size_t expectedClassIdx = findClass (inf.sig , classes, sizeof (classes)/sizeof (class_info));
209
+ // Test classes loading may cause system classes loading - skip them.
210
+ if (expectedClassIdx == NOT_FOUND) {
211
+ size_t unexpectedClassIdx = findClass (inf.sig , unexpectedClasses,
212
+ sizeof (unexpectedClasses)/sizeof (class_info));
213
+ if (unexpectedClassIdx != NOT_FOUND) {
214
+ printf (" # wrong class: \" %s\"\n " , inf.sig );
215
+ result = STATUS_FAILED;
216
+ }
195
217
return ;
196
218
}
197
219
198
- if (inf.sig == NULL || strcmp (inf.sig , classes[eventsCount].sig ) != 0 ) {
199
- printf (" (#%" PRIuPTR " ) wrong class: \" %s\" " ,
200
- eventsCount, inf.sig );
201
- printf (" , expected: \" %s\"\n " , classes[eventsCount].sig );
220
+ if (eventsCount != expectedClassIdx) {
221
+ printf (" (#%" PRIuPTR " ) unexpected order: %" PRIuPTR " , expected: %" PRIuPTR " \n " ,
222
+ eventsCount, expectedClassIdx, eventsCount);
202
223
result = STATUS_FAILED;
224
+ return ;
203
225
}
226
+
204
227
if (inf.status != classes[eventsCount].status ) {
205
228
printf (" (#%" PRIuPTR " ) wrong status: " , eventsCount);
206
229
printStatus (inf.status );
@@ -266,24 +289,16 @@ jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
266
289
}
267
290
268
291
JNIEXPORT void JNICALL
269
- Java_nsk_jvmti_ClassPrepare_classprep001_getReady (JNIEnv *env, jclass cls) {
292
+ Java_nsk_jvmti_ClassPrepare_classprep001_getReady (JNIEnv *env, jclass cls, jthread thread ) {
270
293
jvmtiError err;
271
- jthread prep_thread;
272
294
273
295
if (jvmti == NULL ) {
274
296
printf (" JVMTI client was not properly loaded!\n " );
275
297
return ;
276
298
}
277
299
278
- err = jvmti->GetCurrentThread (&prep_thread);
279
- if (err != JVMTI_ERROR_NONE) {
280
- printf (" Failed to get current thread: %s (%d)\n " , TranslateError (err), err);
281
- result = STATUS_FAILED;
282
- return ;
283
- }
284
-
285
300
err = jvmti->SetEventNotificationMode (JVMTI_ENABLE,
286
- JVMTI_EVENT_CLASS_PREPARE, prep_thread );
301
+ JVMTI_EVENT_CLASS_PREPARE, thread );
287
302
if (err == JVMTI_ERROR_NONE) {
288
303
eventsExpected = sizeof (classes)/sizeof (class_info);
289
304
} else {
@@ -294,23 +309,16 @@ Java_nsk_jvmti_ClassPrepare_classprep001_getReady(JNIEnv *env, jclass cls) {
294
309
}
295
310
296
311
JNIEXPORT jint JNICALL
297
- Java_nsk_jvmti_ClassPrepare_classprep001_check (JNIEnv *env, jclass cls) {
312
+ Java_nsk_jvmti_ClassPrepare_classprep001_check (JNIEnv *env, jclass cls, jthread thread ) {
298
313
jvmtiError err;
299
- jthread prep_thread;
300
314
301
315
if (jvmti == NULL ) {
302
316
printf (" JVMTI client was not properly loaded!\n " );
303
317
return STATUS_FAILED;
304
318
}
305
319
306
- err = jvmti->GetCurrentThread (&prep_thread);
307
- if (err != JVMTI_ERROR_NONE) {
308
- printf (" Failed to get current thread: %s (%d)\n " , TranslateError (err), err);
309
- return STATUS_FAILED;
310
- }
311
-
312
320
err = jvmti->SetEventNotificationMode (JVMTI_DISABLE,
313
- JVMTI_EVENT_CLASS_PREPARE, prep_thread );
321
+ JVMTI_EVENT_CLASS_PREPARE, thread );
314
322
if (err != JVMTI_ERROR_NONE) {
315
323
printf (" Failed to disable JVMTI_EVENT_CLASS_PREPARE: %s (%d)\n " ,
316
324
TranslateError (err), err);
1 commit comments
openjdk-notifier[bot] commentedon May 6, 2021
Review
Issues