org.jikesrvm.runtime
Class DynamicLibrary

java.lang.Object
  extended by org.jikesrvm.runtime.DynamicLibrary

public final class DynamicLibrary
extends Object

Interface to the dynamic libraries of our underlying operating system.


Field Summary
private static ImmutableEntryHashMapRVM<String,DynamicLibrary> dynamicLibraries
          Currently loaded dynamic libraries.
private  Address jniOnLoad
          Address of JNI_OnLoad method
private  Address jniOnUnload
          Address of JNI_OnUnLoad
private  Address libHandler
          Value returned from dlopen
private  String libName
          The name of the library
 
Constructor Summary
private DynamicLibrary(String libraryName)
          Load a dynamic library and maintain it in this object.
 
Method Summary
static void boot()
          Add symbol for the boot image runner to find symbols within it.
private  void callOnLoad()
          Called after we've successfully loaded the shared library
private static void checkJNIVersion(int version)
          Check JNI version is ≤ 1.4 and if not throw an UnsatisfiedLinkError
 void clean()
          Tell the operating system to remove the dynamic library from the system space.
private  Address getJNI_OnLoad()
          Get the unique JNI_OnLoad symbol associated with this library
private  Address getJNI_OnUnload()
          Get the unique JNI_OnUnload symbol associated with this library
 String getLibName()
           
 Address getSymbol(String symbolName)
          look up this dynamic library for a symbol
static int load(String libname)
          Load a dynamic library
static Address resolveSymbol(String symbol)
          Resolve a symbol to an address in a currently loaded dynamic library.
private static int runJNI_OnLoad(Address JNI_OnLoadAddress)
          Method call to run the onload method.
 String toString()
           
 void unload()
          unload a dynamic library
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

dynamicLibraries

private static final ImmutableEntryHashMapRVM<String,DynamicLibrary> dynamicLibraries
Currently loaded dynamic libraries.


libName

private final String libName
The name of the library


libHandler

private final Address libHandler
Value returned from dlopen


jniOnLoad

private final Address jniOnLoad
Address of JNI_OnLoad method


jniOnUnload

private final Address jniOnUnload
Address of JNI_OnUnLoad

Constructor Detail

DynamicLibrary

private DynamicLibrary(String libraryName)
Load a dynamic library and maintain it in this object.

Parameters:
libraryName - library name
Method Detail

boot

public static void boot()
Add symbol for the boot image runner to find symbols within it.


getJNI_OnLoad

private Address getJNI_OnLoad()
Get the unique JNI_OnLoad symbol associated with this library

Returns:
JNI_OnLoad address or zero if not present

getJNI_OnUnload

private Address getJNI_OnUnload()
Get the unique JNI_OnUnload symbol associated with this library

Returns:
JNI_OnUnload address or zero if not present

callOnLoad

private void callOnLoad()
Called after we've successfully loaded the shared library


runJNI_OnLoad

private static int runJNI_OnLoad(Address JNI_OnLoadAddress)
Method call to run the onload method. Performed as a native method as the JNI_OnLoad method may contain JNI calls and we need the RVMThread of the JNIEnv to be correctly populated (this wouldn't happen with a SysCall)

Parameters:
JNI_OnLoadAddress - address of JNI_OnLoad function
Returns:
the JNI version returned by the JNI_OnLoad function

checkJNIVersion

private static void checkJNIVersion(int version)
Check JNI version is ≤ 1.4 and if not throw an UnsatisfiedLinkError

Parameters:
version - to check

getLibName

public String getLibName()
Returns:
the true name of the dynamic library

getSymbol

public Address getSymbol(String symbolName)
look up this dynamic library for a symbol

Parameters:
symbolName - symbol name
Returns:
The Address of the symbol system handler (actually an address to an AixLinkage triplet). (-1: not found or couldn't be created)

unload

public void unload()
unload a dynamic library


clean

public void clean()
Tell the operating system to remove the dynamic library from the system space.


toString

public String toString()
Overrides:
toString in class Object

load

public static int load(String libname)
Load a dynamic library

Parameters:
libname - the name of the library to load.
Returns:
0 on failure, 1 on success

resolveSymbol

public static Address resolveSymbol(String symbol)
Resolve a symbol to an address in a currently loaded dynamic library.

Returns:
the address of the symbol of Address.zero() if it cannot be resolved