forked from openjdk/jdk17u-dev
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Roman Marchenko
committed
Mar 8, 2024
1 parent
815699c
commit c0d28d4
Showing
3 changed files
with
161 additions
and
0 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/extcallback/Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved. | ||
* Copyright (c) 2024, Azul Systems, Inc. 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. | ||
*/ | ||
|
||
/* | ||
* @test | ||
* | ||
* @summary Tests subscribing ClassUnload JVMTI extension event after unsubscribing all events. | ||
* @bug 8286490 | ||
* @requires vm.jvmti | ||
* @library /vmTestbase | ||
* /test/lib | ||
* @run driver nsk.share.ExtraClassesBuilder loadClass | ||
* @run main/othervm/native nsk.jvmti.unit.extcallback.Test | ||
*/ | ||
|
||
package nsk.jvmti.unit.extcallback; | ||
|
||
import jdk.test.lib.process.ProcessTools; | ||
|
||
public class Test { | ||
|
||
public static void main(String[] args) throws Exception { | ||
ProcessTools.executeTestJvm("-agentlib:extcallback", Test1.class.getName()) | ||
.shouldHaveExitValue(0) | ||
.shouldContain("callbackClassUnload called"); | ||
} | ||
|
||
public static class Test1 { | ||
public static void main(String[] args) throws Exception { | ||
System.out.println("App started"); | ||
{ | ||
var unloader = new nsk.share.ClassUnloader(); | ||
unloader.loadClass("nsk.jvmti.unit.extcallback.Test2", "./bin/loadClass"); | ||
unloader.unloadClass(); | ||
unloader = null; | ||
} | ||
System.gc(); | ||
System.out.println("App finished"); | ||
} | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/extcallback/libextcallback.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved. | ||
* Copyright (c) 2024, Azul Systems, Inc. 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 <jvmti.h> | ||
#include <string.h> | ||
|
||
void JNICALL callbackClassUnload(jvmtiEnv* jvmti_env, ...) { | ||
printf("callbackClassUnload called\n"); | ||
fflush(NULL); | ||
} | ||
|
||
void JNICALL callbackClassLoad(jvmtiEnv* jvmti_env, JNIEnv* jni_env, jthread thread, jclass klass) { | ||
// nothing to do, just a stub | ||
} | ||
|
||
JNIEXPORT jint JNICALL Agent_OnLoad(JavaVM* jvm, char* options, void* reserved) { | ||
printf("%s:%d : %s : JVMTI agent loading...\n", __FILE__, __LINE__, __FUNCTION__); | ||
|
||
jvmtiEnv* jvmti = NULL; | ||
jint extensionEventCount = 0; | ||
jvmtiExtensionEventInfo* extensionEvents = NULL; | ||
(*jvm)->GetEnv(jvm, (void**)&jvmti, JVMTI_VERSION_1_0); | ||
|
||
// Set extension event callback | ||
(*jvmti)->GetExtensionEvents(jvmti, &extensionEventCount, &extensionEvents); | ||
for (int i = 0; i < extensionEventCount; ++i) { | ||
if (0 == strcmp("com.sun.hotspot.events.ClassUnload", extensionEvents[i].id)) { | ||
(*jvmti)->SetExtensionEventCallback(jvmti, extensionEvents[i].extension_event_index, &callbackClassUnload); | ||
} | ||
} | ||
|
||
{ | ||
// Set some event callbacks | ||
jvmtiEventCallbacks callbacks; | ||
memset(&callbacks, 0, sizeof(callbacks)); | ||
callbacks.ClassLoad = &callbackClassLoad; | ||
(*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); | ||
|
||
// Clear event callbacks | ||
memset(&callbacks, 0, sizeof(callbacks)); | ||
(*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks)); | ||
} | ||
|
||
return JNI_OK; | ||
} | ||
|
||
JNIEXPORT void JNICALL Agent_OnUnload(JavaVM* jvm) { | ||
printf("%s:%d : %s : JVMTI agent unloading...\n", __FILE__, __LINE__, __FUNCTION__); | ||
} |
29 changes: 29 additions & 0 deletions
29
test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/extcallback/loadClass/Test2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved. | ||
* Copyright (c) 2024, Azul Systems, Inc. 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. | ||
*/ | ||
|
||
package nsk.jvmti.unit.extcallback; | ||
|
||
public class Test2 { | ||
public Test2() {} | ||
} |