1 /* src/native/vm/openjdk/hpi.cpp - HotSpot HPI interface functions
4 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
6 This file is part of CACAO.
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2, or (at
11 your option) any later version.
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
28 // Include this one early.
29 #include "native/vm/openjdk/hpi.hpp"
31 #include "mm/memory.hpp"
33 #include "native/native.hpp"
35 #include "toolbox/sequence.hpp"
37 #include "vm/options.h"
39 #include "vm/properties.hpp"
44 /* VM callback functions ******************************************************/
46 static vm_calls_t callbacks = {
47 /* TODO What should we use here? */
49 /* unimplemented_panic, */
50 /* unimplemented_monitorRegister, */
62 * Initialize the Host Porting Interface (HPI).
68 void HPI::initialize() // REMOVEME
70 TRACESUBSYSTEMINITIALIZATION("hpi_init");
73 VM* vm = VM::get_current();
74 Properties& properties = vm->get_properties();
75 const char* boot_library_path = properties.get("sun.boot.library.path");
77 // Use sequence builder to assemble library path.
80 sb.cat(boot_library_path);
81 sb.cat("/native_threads/libhpi.so");
83 // XXX This should actually be sb.export_symbol()
84 utf* u = utf_new_char(sb.c_str());
87 log_println("HPI::initialize: Loading HPI %s ", sb.c_str());
90 void* handle = nl.open();
94 os::abort("HPI::initialize: HPI open failed");
96 // Resolve the DLL_Initialize function from the library.
97 void* dll_initialize = os::dlsym(handle, "DLL_Initialize");
99 jint (JNICALL *DLL_Initialize)(GetInterfaceFunc*, void*);
100 DLL_Initialize = (jint (JNICALL *)(GetInterfaceFunc*, void*)) (uintptr_t) dll_initialize;
102 if (opt_TraceHPI && DLL_Initialize == NULL)
103 log_println("hpi_init: HPI dlsym of DLL_Initialize failed: %s", os::dlerror());
105 if (DLL_Initialize == NULL || (*DLL_Initialize)(&_get_interface, &callbacks) < 0) {
107 vm_abort("hpi_init: HPI DLL_Initialize failed");
110 NativeLibraries& nls = vm->get_nativelibraries();
114 log_println("HPI::initialize: HPI loaded successfully");
116 // Resolve the interfaces.
117 /* NOTE: The intptr_t-case is only to prevent the a compiler
118 warning with -O2: warning: dereferencing type-punned pointer
119 will break strict-aliasing rules */
123 result = (*_get_interface)((void**) (uintptr_t) &_file, "File", 1);
126 os::abort("hpi_init: Can't find HPI_FileInterface");
128 result = (*_get_interface)((void**) (uintptr_t) &_library, "Library", 1);
131 os::abort("hpi_init: Can't find HPI_LibraryInterface");
133 result = (*_get_interface)((void**) (uintptr_t) &_system, "System", 1);
136 os::abort("hpi_init: Can't find HPI_SystemInterface");
141 * Initialize the Host Porting Interface (HPI) socket library.
143 int HPI::initialize_socket_library()
145 // Resolve the socket library interface.
146 int result = (*_get_interface)((void**) (uintptr_t) &_socket, "Socket", 1);
150 log_println("HPI::initialize_socket_library: Can't find HPI_SocketInterface");
159 // Legacy C interface.
161 void HPI_initialize() { VM::get_current()->get_hpi().initialize(); }
166 * These are local overrides for various environment variables in Emacs.
167 * Please do not remove this and leave it at the end of the file, where
168 * Emacs will automagically detect them.
169 * ---------------------------------------------------------------------
172 * indent-tabs-mode: t
176 * vim:noexpandtab:sw=4:ts=4: