* src/native/vm/openjdk/hpi.h: Likewise.
* src/native/vm/openjdk/hpi.cpp: New file.
* src/native/vm/openjdk/hpi.hpp: Likewise.
* src/native/vm/nativevm.c,
src/native/vm/openjdk/Makefile.am,
src/native/vm/openjdk/jvm.cpp,
src/vm/vm.hpp: Related changes.
--HG--
rename : src/native/vm/openjdk/hpi.c => src/native/vm/openjdk/hpi.cpp
rename : src/native/vm/openjdk/hpi.h => src/native/vm/openjdk/hpi.hpp
# include "native/native.hpp"
-# include "native/vm/openjdk/hpi.h"
+# include "native/vm/openjdk/hpi.hpp"
# include "vm/globals.hpp"
# include "vm/properties.hpp"
/* Initialize the HPI. */
- hpi_initialize();
+ HPI_initialize();
_Jv_sun_misc_Unsafe_init();
libnativevmcore.la
libnativevmcore_la_SOURCES = \
- hpi.c \
- hpi.h \
+ hpi.cpp \
+ hpi.hpp \
jvm.cpp \
management.cpp \
management.hpp
+++ /dev/null
-/* src/native/vm/openjdk/hpi.c - HotSpot HPI interface functions
-
- Copyright (C) 2008
- CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
-
- This file is part of CACAO.
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 2, or (at
- your option) any later version.
-
- This program 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 for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- 02110-1301, USA.
-
-*/
-
-
-#include "config.h"
-
-// Include our JNI header before the HPI headers, because the HPI
-// headers include jni.h and we want to override the typedefs in
-// jni.h.
-#include "native/jni.hpp"
-
-// We include hpi_md.h before hpi.h as the latter includes the former.
-#include INCLUDE_HPI_MD_H
-#include INCLUDE_HPI_H
-
-#include "mm/memory.h"
-
-#include "native/native.hpp"
-
-#include "native/vm/openjdk/hpi.h"
-
-#include "vm/options.h"
-#include "vm/os.hpp"
-#include "vm/properties.hpp"
-#include "vm/utf8.h"
-#include "vm/vm.hpp"
-
-
-/* VM callback functions ******************************************************/
-
-static vm_calls_t callbacks = {
- /* TODO What should we use here? */
-/* jio_fprintf, */
-/* unimplemented_panic, */
-/* unimplemented_monitorRegister, */
- NULL,
- NULL,
- NULL,
-
- NULL, /* unused */
- NULL, /* unused */
- NULL /* unused */
-};
-
-
-/* HPI interfaces *************************************************************/
-
-GetInterfaceFunc hpi_get_interface = NULL;
-HPI_FileInterface *hpi_file = NULL;
-HPI_SocketInterface *hpi_socket = NULL;
-HPI_LibraryInterface *hpi_library = NULL;
-HPI_SystemInterface *hpi_system = NULL;
-
-
-/* hpi_initialize **************************************************************
-
- Initialize the Host Porting Interface (HPI).
-
-*******************************************************************************/
-
-void hpi_initialize(void)
-{
- const char* boot_library_path;
- int len;
- char* p;
- utf* u;
- void* handle;
- void* dll_initialize;
- int result;
-
- jint (JNICALL * DLL_Initialize)(GetInterfaceFunc *, void *);
-
- TRACESUBSYSTEMINITIALIZATION("hpi_init");
-
- /* Load libhpi.so */
-
- boot_library_path = Properties_get("sun.boot.library.path");
-
- len =
- os_strlen(boot_library_path) +
- os_strlen("/native_threads/libhpi.so") +
- os_strlen("0");
-
- p = MNEW(char, len);
-
- os_strcpy(p, boot_library_path);
- os_strcat(p, "/native_threads/libhpi.so");
-
- u = utf_new_char(p);
-
- if (opt_TraceHPI)
- log_println("hpi_init: Loading HPI %s ", p);
-
- MFREE(p, char, len);
-
- handle = native_library_open(u);
-
- if (handle == NULL)
- if (opt_TraceHPI)
- vm_abort("hpi_init: HPI open failed");
-
- /* Resolve the DLL_Initialize function from the library. */
-
- dll_initialize = os_dlsym(handle, "DLL_Initialize");
-
- DLL_Initialize = (jint (JNICALL *)(GetInterfaceFunc *, void *)) (intptr_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)(&hpi_get_interface, &callbacks) < 0) {
-
- if (opt_TraceHPI)
- vm_abort("hpi_init: HPI DLL_Initialize failed");
- }
-
- native_library_add(u, NULL, handle);
-
- if (opt_TraceHPI)
- log_println("hpi_init: 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 */
-
- result = (*hpi_get_interface)((void **) (intptr_t) &hpi_file, "File", 1);
-
- if (result != 0)
- vm_abort("hpi_init: Can't find HPI_FileInterface");
-
- result = (*hpi_get_interface)((void **) (intptr_t) &hpi_library, "Library", 1);
-
- if (result != 0)
- vm_abort("hpi_init: Can't find HPI_LibraryInterface");
-
- result = (*hpi_get_interface)((void **) (intptr_t) &hpi_system, "System", 1);
-
- if (result != 0)
- vm_abort("hpi_init: Can't find HPI_SystemInterface");
-}
-
-
-/* hpi_initialize_socket_library ***********************************************
-
- Initialize the library Host Porting Interface (HPI).
-
-*******************************************************************************/
-
-int hpi_initialize_socket_library(void)
-{
- int result;
-
- /* Resolve the socket library interface. */
-
- result = (*hpi_get_interface)((void **) (intptr_t) &hpi_socket, "Socket", 1);
-
- if (result != 0) {
- if (opt_TraceHPI)
- log_println("hpi_initialize_socket_library: Can't find HPI_SocketInterface");
-
- return JNI_ERR;
- }
-
- return JNI_OK;
-}
-
-
-/*
- * These are local overrides for various environment variables in Emacs.
- * Please do not remove this and leave it at the end of the file, where
- * Emacs will automagically detect them.
- * ---------------------------------------------------------------------
- * Local variables:
- * mode: c
- * indent-tabs-mode: t
- * c-basic-offset: 4
- * tab-width: 4
- * End:
- * vim:noexpandtab:sw=4:ts=4:
- */
--- /dev/null
+/* src/native/vm/openjdk/hpi.cpp - HotSpot HPI interface functions
+
+ Copyright (C) 2008
+ CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
+
+ This file is part of CACAO.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ This program 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 for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
+
+*/
+
+
+#include "config.h"
+
+// Include this one early.
+#include "native/vm/openjdk/hpi.hpp"
+
+#include "mm/memory.h"
+
+#include "native/native.hpp"
+
+#include "vm/options.h"
+#include "vm/os.hpp"
+#include "vm/properties.hpp"
+#include "vm/utf8.h"
+#include "vm/vm.hpp"
+
+
+/* VM callback functions ******************************************************/
+
+static vm_calls_t callbacks = {
+ /* TODO What should we use here? */
+/* jio_fprintf, */
+/* unimplemented_panic, */
+/* unimplemented_monitorRegister, */
+ NULL,
+ NULL,
+ NULL,
+
+ NULL, /* unused */
+ NULL, /* unused */
+ NULL /* unused */
+};
+
+
+/**
+ * Initialize the Host Porting Interface (HPI).
+ */
+HPI::HPI()
+{
+}
+
+void HPI::initialize() // REMOVEME
+{
+ TRACESUBSYSTEMINITIALIZATION("hpi_init");
+
+ // Load libhpi.so
+ Properties& properties = VM::get_current()->get_properties();
+ const char* boot_library_path = properties.get("sun.boot.library.path");
+
+ size_t len =
+ os::strlen(boot_library_path) +
+ os::strlen("/native_threads/libhpi.so") +
+ os::strlen("0");
+
+ char* p = MNEW(char, len);
+
+ os::strcpy(p, boot_library_path);
+ os::strcat(p, "/native_threads/libhpi.so");
+
+ utf* u = utf_new_char(p);
+
+ if (opt_TraceHPI)
+ log_println("HPI::initialize: Loading HPI %s ", p);
+
+ MFREE(p, char, len);
+
+ void* handle = native_library_open(u);
+
+ 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");
+ }
+
+ native_library_add(u, NULL, handle);
+
+ 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");
+}
+
+
+/**
+ * Initialize the Host Porting Interface (HPI) socket library.
+ */
+int HPI::initialize_socket_library()
+{
+ // Resolve the socket library interface.
+ int result = (*_get_interface)((void**) (uintptr_t) &_socket, "Socket", 1);
+
+ if (result != 0) {
+ if (opt_TraceHPI)
+ log_println("HPI::initialize_socket_library: Can't find HPI_SocketInterface");
+
+ return JNI_ERR;
+ }
+
+ return JNI_OK;
+}
+
+
+// Legacy C interface.
+extern "C" {
+ void HPI_initialize() { VM::get_current()->get_hpi().initialize(); }
+}
+
+
+/*
+ * These are local overrides for various environment variables in Emacs.
+ * Please do not remove this and leave it at the end of the file, where
+ * Emacs will automagically detect them.
+ * ---------------------------------------------------------------------
+ * Local variables:
+ * mode: c++
+ * indent-tabs-mode: t
+ * c-basic-offset: 4
+ * tab-width: 4
+ * End:
+ * vim:noexpandtab:sw=4:ts=4:
+ */
+++ /dev/null
-/* src/native/vm/openjdk/hpi.h - HotSpot HPI interface functions
-
- Copyright (C) 2008
- CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
-
- This file is part of CACAO.
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 2, or (at
- your option) any later version.
-
- This program 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 for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- 02110-1301, USA.
-
-*/
-
-
-#ifndef _HPI_H
-#define _HPI_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include "config.h"
-
-/* HPI headers *****************************************************************
-
- We include hpi_md.h before hpi.h as the latter includes the former.
-
- These includes define:
-
- #define _JAVASOFT_HPI_MD_H_
- #define _JAVASOFT_HPI_H_
-
-*******************************************************************************/
-
-#include INCLUDE_HPI_MD_H
-#include INCLUDE_HPI_H
-
-
-/* HPI interfaces *************************************************************/
-
-extern HPI_FileInterface *hpi_file;
-extern HPI_SocketInterface *hpi_socket;
-extern HPI_LibraryInterface *hpi_library;
-extern HPI_SystemInterface *hpi_system;
-
-
-/* functions ******************************************************************/
-
-void hpi_initialize(void);
-int hpi_initialize_socket_library(void);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _HPI_H */
-
-
-/*
- * These are local overrides for various environment variables in Emacs.
- * Please do not remove this and leave it at the end of the file, where
- * Emacs will automagically detect them.
- * ---------------------------------------------------------------------
- * Local variables:
- * mode: c
- * indent-tabs-mode: t
- * c-basic-offset: 4
- * tab-width: 4
- * End:
- * vim:noexpandtab:sw=4:ts=4:
- */
--- /dev/null
+/* src/native/vm/openjdk/hpi.hpp - HotSpot HPI interface functions
+
+ Copyright (C) 2008
+ CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
+
+ This file is part of CACAO.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ This program 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 for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
+
+*/
+
+
+#ifndef _HPI_HPP
+#define _HPI_HPP
+
+#include "config.h"
+
+/* HPI headers *****************************************************************
+
+ We include hpi_md.h before hpi.h as the latter includes the former.
+
+ These includes define:
+
+ #define _JAVASOFT_HPI_MD_H_
+ #define _JAVASOFT_HPI_H_
+
+*******************************************************************************/
+
+// Include our JNI header before the HPI headers, because the HPI
+// headers include jni.h and we want to override the typedefs in
+// jni.h.
+#include "native/jni.hpp"
+
+#include INCLUDE_HPI_MD_H
+#include INCLUDE_HPI_H
+
+
+#ifdef __cplusplus
+
+/**
+ * Host Porting Interface (HPI).
+ */
+class HPI {
+private:
+ GetInterfaceFunc _get_interface;
+ HPI_FileInterface* _file;
+ HPI_SocketInterface* _socket;
+ HPI_LibraryInterface* _library;
+ HPI_SystemInterface* _system;
+
+public:
+ HPI();
+
+ inline HPI_FileInterface& get_file () const { return *_file; }
+ inline HPI_SocketInterface& get_socket () const { return *_socket; }
+ inline HPI_LibraryInterface& get_library() const { return *_library; }
+ inline HPI_SystemInterface& get_system () const { return *_system; }
+
+ void initialize(); // REMOVEME
+ int initialize_socket_library();
+};
+
+#else
+
+void HPI_initialize();
+
+#endif
+
+#endif // _HPI_HPP
+
+
+/*
+ * These are local overrides for various environment variables in Emacs.
+ * Please do not remove this and leave it at the end of the file, where
+ * Emacs will automagically detect them.
+ * ---------------------------------------------------------------------
+ * Local variables:
+ * mode: c++
+ * indent-tabs-mode: t
+ * c-basic-offset: 4
+ * tab-width: 4
+ * End:
+ * vim:noexpandtab:sw=4:ts=4:
+ */
#include "native/vm/reflection.hpp"
-#include "native/vm/openjdk/hpi.h"
+#include "native/vm/openjdk/hpi.hpp"
#include "native/vm/openjdk/management.hpp"
#include "threads/lock.hpp"
/* JVM_GetLastErrorString */
-jint JVM_GetLastErrorString(char *buf, int len)
+jint JVM_GetLastErrorString(char* buf, int len)
{
TRACEJVMCALLS(("JVM_GetLastErrorString(buf=%p, len=%d", buf, len));
- return hpi_system->GetLastErrorString(buf, len);
+ HPI& hpi = VM::get_current()->get_hpi();
+ return hpi.get_system().GetLastErrorString(buf, len);
}
/* JVM_NativePath */
-char *JVM_NativePath(char *path)
+char *JVM_NativePath(char* path)
{
TRACEJVMCALLS(("JVM_NativePath(path=%s)", path));
- return hpi_file->NativePath(path);
+ HPI& hpi = VM::get_current()->get_hpi();
+ return hpi.get_file().NativePath(path);
}
*/
#define JVM_EEXIST -100
-jint JVM_Open(const char *fname, jint flags, jint mode)
+jint JVM_Open(const char* fname, jint flags, jint mode)
{
int result;
TRACEJVMCALLS(("JVM_Open(fname=%s, flags=%d, mode=%d)", fname, flags, mode));
- result = hpi_file->Open(fname, flags, mode);
+ HPI& hpi = VM::get_current()->get_hpi();
+ result = hpi.get_file().Open(fname, flags, mode);
if (result >= 0) {
return result;
{
TRACEJVMCALLS(("JVM_Close(fd=%d)", fd));
- return hpi_file->Close(fd);
+ HPI& hpi = VM::get_current()->get_hpi();
+ return hpi.get_file().Close(fd);
}
/* JVM_Read */
-jint JVM_Read(jint fd, char *buf, jint nbytes)
+jint JVM_Read(jint fd, char* buf, jint nbytes)
{
TRACEJVMCALLS(("JVM_Read(fd=%d, buf=%p, nbytes=%d)", fd, buf, nbytes));
- return (jint) hpi_file->Read(fd, buf, nbytes);
+ HPI& hpi = VM::get_current()->get_hpi();
+ return (jint) hpi.get_file().Read(fd, buf, nbytes);
}
/* JVM_Write */
-jint JVM_Write(jint fd, char *buf, jint nbytes)
+jint JVM_Write(jint fd, char* buf, jint nbytes)
{
TRACEJVMCALLS(("JVM_Write(fd=%d, buf=%s, nbytes=%d)", fd, buf, nbytes));
- return (jint) hpi_file->Write(fd, buf, nbytes);
+ HPI& hpi = VM::get_current()->get_hpi();
+ return (jint) hpi.get_file().Write(fd, buf, nbytes);
}
/* JVM_Available */
-jint JVM_Available(jint fd, jlong *pbytes)
+jint JVM_Available(jint fd, jlong* pbytes)
{
TRACEJVMCALLS(("JVM_Available(fd=%d, pbytes=%p)", fd, pbytes));
- return hpi_file->Available(fd, pbytes);
+ HPI& hpi = VM::get_current()->get_hpi();
+ return hpi.get_file().Available(fd, pbytes);
}
{
TRACEJVMCALLS(("JVM_Lseek(fd=%d, offset=%ld, whence=%d)", fd, offset, whence));
- return hpi_file->Seek(fd, (off_t) offset, whence);
+ HPI& hpi = VM::get_current()->get_hpi();
+ return hpi.get_file().Seek(fd, (off_t) offset, whence);
}
{
TRACEJVMCALLS(("JVM_SetLength(fd=%d, length=%ld)", length));
- return hpi_file->SetLength(fd, length);
+ HPI& hpi = VM::get_current()->get_hpi();
+ return hpi.get_file().SetLength(fd, length);
}
{
TRACEJVMCALLS(("JVM_Sync(fd=%d)", fd));
- return hpi_file->Sync(fd);
+ HPI& hpi = VM::get_current()->get_hpi();
+ return hpi.get_file().Sync(fd);
}
{
TRACEJVMCALLS(("JVM_InitializeSocketLibrary()"));
- return hpi_initialize_socket_library();
+ HPI& hpi = VM::get_current()->get_hpi();
+ return hpi.initialize_socket_library();
}
/* JVM_FindLibraryEntry */
-void *JVM_FindLibraryEntry(void *handle, const char *name)
+void *JVM_FindLibraryEntry(void* handle, const char* name)
{
void* symbol;
TRACEJVMCALLSENTER(("JVM_FindLibraryEntry(handle=%p, name=%s)", handle, name));
- symbol = hpi_library->FindLibraryEntry(handle, name);
+ HPI& hpi = VM::get_current()->get_hpi();
+ symbol = hpi.get_library().FindLibraryEntry(handle, name);
TRACEJVMCALLSEXIT(("->%p", symbol));
#include "native/jni.hpp"
#if defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
+# include "native/vm/openjdk/hpi.hpp"
# include "native/vm/openjdk/management.hpp"
#endif
Recompiler _recompiler; ///< JIT recompilation framework.
#endif
#if defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
+ HPI _hpi;
Management _management;
#endif
Properties& get_properties() { return _properties; }
Recompiler& get_recompiler() { return _recompiler; } // REMOVEME
#if defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
+ HPI& get_hpi () { return _hpi; }
Management& get_management() { return _management; }
#endif
};