8187305: Add logging for shared library loads/unloads
Add logging to JVM_LoadLibrary(), JVM_UnloadLibrary(), and JVM_FindLibraryEntry(). Reviewed-by: dholmes, coleenp
This commit is contained in:
parent
cea8931aed
commit
bf6c14f034
@ -89,6 +89,7 @@
|
||||
LOG_TAG(jit) \
|
||||
LOG_TAG(jni) \
|
||||
LOG_TAG(jvmti) \
|
||||
LOG_TAG(library) \
|
||||
LOG_TAG(liveness) \
|
||||
LOG_TAG(load) /* Trace all classes loaded */ \
|
||||
LOG_TAG(loader) \
|
||||
|
@ -3371,6 +3371,7 @@ JVM_ENTRY_NO_ENV(void*, JVM_LoadLibrary(const char* name))
|
||||
|
||||
THROW_HANDLE_0(h_exception);
|
||||
}
|
||||
log_info(library)("Loaded library %s, handle " INTPTR_FORMAT, name, p2i(load_result));
|
||||
return load_result;
|
||||
JVM_END
|
||||
|
||||
@ -3378,12 +3379,17 @@ JVM_END
|
||||
JVM_LEAF(void, JVM_UnloadLibrary(void* handle))
|
||||
JVMWrapper("JVM_UnloadLibrary");
|
||||
os::dll_unload(handle);
|
||||
log_info(library)("Unloaded library with handle " INTPTR_FORMAT, p2i(handle));
|
||||
JVM_END
|
||||
|
||||
|
||||
JVM_LEAF(void*, JVM_FindLibraryEntry(void* handle, const char* name))
|
||||
JVMWrapper("JVM_FindLibraryEntry");
|
||||
return os::dll_lookup(handle, name);
|
||||
void* find_result = os::dll_lookup(handle, name);
|
||||
log_info(library)("%s %s in library with handle " INTPTR_FORMAT,
|
||||
find_result != NULL ? "Found" : "Failed to find",
|
||||
name, p2i(handle));
|
||||
return find_result;
|
||||
JVM_END
|
||||
|
||||
|
||||
|
@ -0,0 +1,94 @@
|
||||
/*
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.FileChannel;
|
||||
|
||||
public class LoadLibrary {
|
||||
|
||||
public static String testClasses;
|
||||
|
||||
public static void runTest() throws Exception {
|
||||
// create a classloader and load a class that loads a library.
|
||||
MyClassLoader myLoader = new MyClassLoader();
|
||||
Class<?> c = Class.forName("LoadLibraryClass", true, myLoader);
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
testClasses = args[0];
|
||||
runTest();
|
||||
ClassUnloadCommon.triggerUnloading();
|
||||
}
|
||||
|
||||
public static class MyClassLoader extends ClassLoader {
|
||||
|
||||
public static final String CLASS_NAME = "LoadLibraryClass";
|
||||
|
||||
static ByteBuffer readClassFile(String name) {
|
||||
File f = new File(testClasses, name);
|
||||
try (FileInputStream fin = new FileInputStream(f);
|
||||
FileChannel fc = fin.getChannel())
|
||||
{
|
||||
return fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size());
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Can't open file: " + name +
|
||||
", exception: " + e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
protected Class<?> loadClass(String name, boolean resolve)
|
||||
throws ClassNotFoundException {
|
||||
Class<?> c;
|
||||
if (!"LoadLibraryClass".equals(name)) {
|
||||
c = super.loadClass(name, resolve);
|
||||
} else {
|
||||
// should not delegate to the system class loader
|
||||
c = findClass(name);
|
||||
if (resolve) {
|
||||
resolveClass(c);
|
||||
}
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
protected Class<?> findClass(String name) throws ClassNotFoundException {
|
||||
if (!"LoadLibraryClass".equals(name)) {
|
||||
throw new ClassNotFoundException("Unexpected class: " + name);
|
||||
}
|
||||
return defineClass(name, readClassFile(name + ".class"), null);
|
||||
}
|
||||
} // MyClassLoader
|
||||
|
||||
}
|
||||
|
||||
|
||||
class LoadLibraryClass {
|
||||
static {
|
||||
System.loadLibrary("LoadLibraryClass");
|
||||
nTest();
|
||||
}
|
||||
native static void nTest();
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8187305
|
||||
* @summary Tests logging of shared library loads and unloads.
|
||||
* @library /runtime/testlibrary /test/lib
|
||||
* @compile LoadLibrary.java
|
||||
* @run main LoadLibraryTest
|
||||
*/
|
||||
|
||||
import jdk.test.lib.process.ProcessTools;
|
||||
import jdk.test.lib.process.OutputAnalyzer;
|
||||
|
||||
public class LoadLibraryTest {
|
||||
|
||||
public static void main(String... args) throws Exception {
|
||||
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
|
||||
"-Xlog:library=info", "-Djava.library.path=" + System.getProperty("java.library.path"),
|
||||
"LoadLibrary", System.getProperty("test.classes"));
|
||||
|
||||
OutputAnalyzer output = new OutputAnalyzer(pb.start());
|
||||
output.shouldContain("Loaded library");
|
||||
output.shouldContain("Found Java_LoadLibraryClass_nTest in library");
|
||||
output.shouldContain("Unloaded library with handle");
|
||||
output.shouldHaveExitValue(0);
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Native test for LoadLibraryTest.
|
||||
*/
|
||||
|
||||
#include "jni.h"
|
||||
|
||||
JNIEXPORT void JNICALL Java_LoadLibraryClass_nTest(JNIEnv* env, jclass jclazz) { }
|
Loading…
x
Reference in New Issue
Block a user