void HPI::initialize() // REMOVEME { TRACESUBSYSTEMINITIALIZATION("hpi_init"); // Load libhpi.so VM* vm = VM::get_current(); Properties& properties = vm->get_properties(); const char* boot_library_path = properties.get("sun.boot.library.path"); // Use Buffer to assemble library path. Buffer<> buf; buf.write(boot_library_path); buf.write("/native_threads/libhpi.so"); Utf8String u = buf.utf8_str(); if (opt_TraceHPI) log_println("HPI::initialize: Loading HPI %s ", buf.c_str()); NativeLibrary nl(u); void* handle = nl.open(); if (handle == NULL) if (opt_TraceHPI) os::abort("HPI::initialize: HPI open failed"); // Resolve the DLL_Initialize function from the library. void* dll_initialize = os::dlsym(handle, "DLL_Initialize"); jint (JNICALL *DLL_Initialize)(GetInterfaceFunc*, void*); DLL_Initialize = (jint (JNICALL *)(GetInterfaceFunc*, void*)) (uintptr_t) dll_initialize; if (opt_TraceHPI && DLL_Initialize == NULL) log_println("hpi_init: HPI dlsym of DLL_Initialize failed: %s", os::dlerror()); if (DLL_Initialize == NULL || (*DLL_Initialize)(&_get_interface, &callbacks) < 0) { if (opt_TraceHPI) vm_abort("hpi_init: HPI DLL_Initialize failed"); } NativeLibraries& nls = vm->get_nativelibraries(); nls.add(nl); if (opt_TraceHPI) log_println("HPI::initialize: HPI loaded successfully"); // Resolve the interfaces. /* NOTE: The intptr_t-case is only to prevent the a compiler warning with -O2: warning: dereferencing type-punned pointer will break strict-aliasing rules */ int result; result = (*_get_interface)((void**) (uintptr_t) &_file, "File", 1); if (result != 0) os::abort("hpi_init: Can't find HPI_FileInterface"); result = (*_get_interface)((void**) (uintptr_t) &_library, "Library", 1); if (result != 0) os::abort("hpi_init: Can't find HPI_LibraryInterface"); result = (*_get_interface)((void**) (uintptr_t) &_system, "System", 1); if (result != 0) os::abort("hpi_init: Can't find HPI_SystemInterface"); }