Skip to content

Commit 90960c5

Browse files
committed
8252657: JVMTI agent is not unloaded when Agent_OnAttach is failed
Reviewed-by: dholmes, sspitsyn
1 parent e3b548a commit 90960c5

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

src/hotspot/share/prims/jvmti.xml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -686,9 +686,11 @@ Agent_OnUnload_L(JavaVM *vm)</example>
686686
The library will be unloaded (unless it is statically linked into the
687687
executable) and this function will be called if some platform specific
688688
mechanism causes the unload (an unload mechanism is not specified in this document)
689-
or the library is (in effect) unloaded by the termination of the VM whether through
690-
normal termination or VM failure, including start-up failure.
691-
Uncontrolled shutdown is, of course, an exception to this rule.
689+
or the library is (in effect) unloaded by the termination of the VM.
690+
VM termination includes normal termination and VM failure, including start-up failure,
691+
but not, of course, uncontrolled shutdown. An implementation may also
692+
choose to not call this function if the <code>Agent_OnAttach</code>/
693+
<code>Agent_OnAttach_L</code> function reported an error (returned a non-zero value).
692694
Note the distinction between this function and the
693695
<eventlink id="VMDeath">VM Death event</eventlink>: for the VM Death event
694696
to be sent, the VM must have run at least to the point of initialization and a valid

src/hotspot/share/prims/jvmtiExport.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2700,6 +2700,9 @@ jint JvmtiExport::load_agent_library(const char *agent, const char *absParam,
27002700
if (result == JNI_OK) {
27012701
Arguments::add_loaded_agent(agent_lib);
27022702
} else {
2703+
if (!agent_lib->is_static_lib()) {
2704+
os::dll_unload(library);
2705+
}
27032706
delete agent_lib;
27042707
}
27052708

test/hotspot/jtreg/serviceability/dcmd/jvmti/AttachFailed/AttachReturnError.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -25,7 +25,7 @@
2525

2626
/*
2727
* @test
28-
* @bug 8165736
28+
* @bug 8165736 8252657
2929
* @library /test/lib
3030
* @run testng AttachReturnError
3131
*/
@@ -36,8 +36,13 @@ public void run(CommandExecutor executor) {
3636
String libpath = getSharedObjectPath("ReturnError");
3737
OutputAnalyzer output = null;
3838

39+
// Check return code
3940
output = executor.execute("JVMTI.agent_load " + libpath);
4041
output.shouldContain("return code: -1");
42+
43+
// Check loaded libraries
44+
output = executor.execute("VM.dynlibs");
45+
output.shouldNotContain(libpath);
4146
} catch (Exception e) {
4247
throw new RuntimeException(e);
4348
}

0 commit comments

Comments
 (0)