(AC_CHECK_WITH_HPI_H): Likewise.
* m4/classpath.m4 (AC_CHECK_WITH_CLASSPATH_CLASSES): Changed default
for OpenJDK.
(AC_CHECK_WITH_CLASSPATH_LIBDIR): Likewise.
(AC_CHECK_WITH_JNI_MD_H): Likewise.
(AC_CHECK_WITH_JNI_H): Likewise.
* m4/hpi.m4: New file.
* src/native/vm/nativevm.c (nativevm_preinit): Call hpi_initialize.
* src/native/vm/sun/Makefile.am (libnativevmcore_la_SOURCES): Added
hpi.[ch].
* src/native/vm/sun/hpi.c: New file.
* src/native/vm/sun/hpi.h: Likewise.
* src/native/vm/sun/jvm.c (JVM_GetLastErrorString): Use HPI function.
(JVM_NativePath): Likewise.
(JVM_Open): Likewise.
(JVM_Close): Likewise.
(JVM_Read): Likewise.
(JVM_Write): Likewise.
(JVM_Available): Likewise.
(JVM_Lseek): Likewise.
(JVM_SetLength): Likewise.
(JVM_Sync): Likewise.
(JVM_InitializeSocketLibrary): Call hpi_initialize_socket_library.
* src/vmcore/options.c (opt_TraceHPI): Added global variable.
(options_xx): Handle new option.
* src/vmcore/options.h: Likewise.
AC_CHECK_WITH_JNI_MD_H
AC_CHECK_WITH_JNI_H
+dnl HPI is only required for OpenJDK
+case "${WITH_CLASSPATH}" in
+ sun)
+ AC_CHECK_WITH_HPI_MD_H
+ AC_CHECK_WITH_HPI_H
+ ;;
+ *)
+ ;;
+esac
dnl check for some programs we need
AC_DEFUN([AC_CHECK_WITH_CLASSPATH_CLASSES],[
AC_MSG_CHECKING(where Java core library classes are installed)
AC_ARG_WITH([classpath-classes],
- [AS_HELP_STRING(--with-classpath-classes=<path>,path to Java core library classes (includes the name of the file and may be flat) [[default=CLASSPATH_PREFIX/{share/classpath/glibj.zip,classes}]])],
+ [AS_HELP_STRING(--with-classpath-classes=<path>,path to Java core library classes (includes the name of the file and may be flat) [[default=(gnu:${CLASSPATH_PREFIX}/share/classpath/glibj.zip,sun:${CLASSPATH_PREFIX}/control/build/${OS_DIR}-${JAVA_ARCH}/classes,*:${CLASSPATH_PREFIX})]])],
[CLASSPATH_CLASSES=${withval}],
[case "${WITH_CLASSPATH}" in
gnu)
CLASSPATH_CLASSES=${CLASSPATH_PREFIX}/share/classpath/glibj.zip
;;
sun)
- CLASSPATH_CLASSES=${CLASSPATH_PREFIX}/classes
+ CLASSPATH_CLASSES=${CLASSPATH_PREFIX}/control/build/${OS_DIR}-${JAVA_ARCH}/classes
;;
*)
CLASSPATH_CLASSES=${CLASSPATH_PREFIX}
AC_DEFUN([AC_CHECK_WITH_CLASSPATH_LIBDIR],[
AC_MSG_CHECKING(where Java core library native libraries are installed)
AC_ARG_WITH([classpath-libdir],
- [AS_HELP_STRING(--with-classpath-libdir=<dir>,installation directory of Java core library native libraries [[default=CLASSPATH_PREFIX/{lib,lib/${JAVA_ARCH}]])],
+ [AS_HELP_STRING(--with-classpath-libdir=<dir>,installation directory of Java core library native libraries [[default=(gnu:${CLASSPATH_PREFIX}/lib,sun:${CLASSPATH_PREFIX}/control/build/${OS_DIR}-${JAVA_ARCH}/lib/${JAVA_ARCH},*:${CLASSPATH_PREFIX})]])],
[CLASSPATH_LIBDIR=${withval}],
[case "${WITH_CLASSPATH}" in
gnu)
CLASSPATH_LIBDIR=${CLASSPATH_PREFIX}/lib
;;
sun)
- CLASSPATH_LIBDIR=${CLASSPATH_PREFIX}/lib/${JAVA_ARCH}
+ CLASSPATH_LIBDIR=${CLASSPATH_PREFIX}/control/build/${OS_DIR}-${JAVA_ARCH}/lib/${JAVA_ARCH}
;;
*)
CLASSPATH_LIBDIR=${CLASSPATH_PREFIX}
AC_DEFUN([AC_CHECK_WITH_JNI_MD_H],[
AC_MSG_CHECKING(where jni_md.h is installed)
AC_ARG_WITH([jni_md_h],
- [AS_HELP_STRING(--with-jni_md_h=<dir>,path to jni_md.h [[default=(sun:CLASSPATH_PREFIX/include/linux,*:CLASSPATH_PREFIX/include)]])],
+ [AS_HELP_STRING(--with-jni_md_h=<dir>,path to jni_md.h [[default=(sun:${CLASSPATH_PREFIX}/jdk/src/solaris/javavm/export,*:${CLASSPATH_PREFIX}/include)]])],
[WITH_JNI_MD_H=${withval}],
[case "${WITH_CLASSPATH}" in
sun)
- WITH_JNI_MD_H=${CLASSPATH_PREFIX}/include/linux
+ WITH_JNI_MD_H=${CLASSPATH_PREFIX}/jdk/src/solaris/javavm/export
;;
*)
WITH_JNI_MD_H=${CLASSPATH_PREFIX}/include
AC_DEFUN([AC_CHECK_WITH_JNI_H],[
AC_MSG_CHECKING(where jni.h is installed)
AC_ARG_WITH([jni_h],
- [AS_HELP_STRING(--with-jni_h=<dir>,path to jni.h [[default=CLASSPATH_PREFIX/include]])],
+ [AS_HELP_STRING(--with-jni_h=<dir>,path to jni.h [[default=(sun:${CLASSPATH_PREFIX}/jdk/src/share/javavm/export,*:${CLASSPATH_PREFIX}/include)]])],
[WITH_JNI_H=${withval}],
- [WITH_JNI_H=${CLASSPATH_PREFIX}/include])
+ [case "${WITH_CLASSPATH}" in
+ sun)
+ WITH_JNI_H=${CLASSPATH_PREFIX}/jdk/src/share/javavm/export
+ ;;
+ *)
+ WITH_JNI_H=${CLASSPATH_PREFIX}/include
+ ;;
+ esac])
AC_MSG_RESULT(${WITH_JNI_H})
dnl We use CPPFLAGS so jni.h can find jni_md.h
--- /dev/null
+dnl m4/hpi.m4
+dnl
+dnl Copyright (C) 2008
+dnl CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
+dnl
+dnl This file is part of CACAO.
+dnl
+dnl This program is free software; you can redistribute it and/or
+dnl modify it under the terms of the GNU General Public License as
+dnl published by the Free Software Foundation; either version 2, or (at
+dnl your option) any later version.
+dnl
+dnl This program is distributed in the hope that it will be useful, but
+dnl WITHOUT ANY WARRANTY; without even the implied warranty of
+dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+dnl General Public License for more details.
+dnl
+dnl You should have received a copy of the GNU General Public License
+dnl along with this program; if not, write to the Free Software
+dnl Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+dnl 02110-1301, USA.
+
+
+dnl where hpi_md.h is installed
+
+AC_DEFUN([AC_CHECK_WITH_HPI_MD_H],[
+AC_MSG_CHECKING(where hpi_md.h is installed)
+AC_ARG_WITH([hpi_md_h],
+ [AS_HELP_STRING(--with-hpi_md_h=<dir>,path to hpi_md.h (only with --with-classpath=sun) [[default=${CLASSPATH_PREFIX}/jdk/src/solaris/hpi/export]])],
+ [WITH_HPI_MD_H=${withval}],
+ [case "${WITH_CLASSPATH}" in
+ sun)
+ WITH_HPI_MD_H=${CLASSPATH_PREFIX}/jdk/src/solaris/hpi/export
+ ;;
+ *)
+ ;;
+ esac])
+AC_MSG_RESULT(${WITH_HPI_MD_H})
+
+dnl We use CPPFLAGS so hpi.h can find hpi_md.h
+CPPFLAGS="${CPPFLAGS} -I${WITH_HPI_MD_H}"
+
+AC_CHECK_HEADER([${WITH_HPI_MD_H}/hpi_md.h],
+ [AC_DEFINE_UNQUOTED([INCLUDE_HPI_MD_H], "${WITH_HPI_MD_H}/hpi_md.h", [Java core library hpi_md.h header])],
+ [AC_MSG_ERROR(cannot find hpi_md.h)])
+])
+
+
+dnl where hpi.h is installed
+
+AC_DEFUN([AC_CHECK_WITH_HPI_H],[
+AC_MSG_CHECKING(where hpi.h is installed)
+AC_ARG_WITH([hpi_h],
+ [AS_HELP_STRING(--with-hpi_h=<dir>,path to hpi.h (only with --with-classpath=sun) [[default=${CLASSPATH_PREFIX}/jdk/src/share/hpi/export]])],
+ [WITH_HPI_H=${withval}],
+ [WITH_HPI_H=${CLASSPATH_PREFIX}/jdk/src/share/hpi/export])
+AC_MSG_RESULT(${WITH_HPI_H})
+
+dnl We use CPPFLAGS so hpi.h can find hpi_md.h
+CPPFLAGS="${CPPFLAGS} -I${WITH_HPI_H}"
+
+AC_CHECK_HEADER([${WITH_HPI_H}/hpi.h],
+ [AC_DEFINE_UNQUOTED([INCLUDE_HPI_H], "${WITH_HPI_H}/hpi.h", [Java core library hpi.h header])],
+ [AC_MSG_ERROR(cannot find hpi.h)],
+ [#include INCLUDE_HPI_MD_H])
+])
# include "native/native.h"
+# include "native/vm/sun/hpi.h"
+
# include "vm/properties.h"
# include "vm/vm.h"
native_library_add(u, NULL, handle);
+ /* Initialize the HPI. */
+
+ hpi_initialize();
+
_Jv_sun_misc_Unsafe_init();
# else
## src/native/vm/sun/Makefile.am
##
-## Copyright (C) 2007 R. Grafl, A. Krall, C. Kruegel,
-## C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
-## E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
-## J. Wenninger, Institut f. Computersprachen - TU Wien
+## Copyright (C) 2007, 2008
+## CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
##
## This file is part of CACAO.
##
libnativevmcore.la
libnativevmcore_la_SOURCES = \
+ hpi.c \
+ hpi.h \
jvm.c
--- /dev/null
+/* src/native/vm/sun/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"
+
+/* 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/jni.h"
+#include "native/native.h"
+
+#include "vm/properties.h"
+#include "vm/vm.h"
+
+#include "vmcore/options.h"
+#include "vmcore/system.h"
+#include "vmcore/utf8.h"
+
+
+/* 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)
+{
+ char *boot_library_path;
+ int len;
+ char *p;
+ utf *u;
+ lt_dlhandle handle;
+ lt_ptr 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 =
+ system_strlen(boot_library_path) +
+ system_strlen("/native_threads/libhpi.so") +
+ system_strlen("0");
+
+ p = MNEW(char, len);
+
+ system_strcpy(p, boot_library_path);
+ system_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 = lt_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", lt_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. */
+
+ result = (*hpi_get_interface)((void **) &hpi_file, "File", 1);
+
+ if (result != 0)
+ vm_abort("hpi_init: Can't find HPI_FileInterface");
+
+ result = (*hpi_get_interface)((void **) &hpi_library, "Library", 1);
+
+ if (result != 0)
+ vm_abort("hpi_init: Can't find HPI_LibraryInterface");
+
+ result = (*hpi_get_interface)((void **) &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 **) &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/sun/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
+
+#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);
+
+#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:
+ */
#include "native/vm/java_lang_reflect_Method.h"
#include "native/vm/reflect.h"
+#include "native/vm/sun/hpi.h"
+
#include "threads/lock-common.h"
#include "threads/threads-common.h"
jint JVM_GetLastErrorString(char *buf, int len)
{
- const char *s;
- int n;
-
- if (errno == 0) {
- return 0;
- }
- else {
- s = strerror(errno);
- n = strlen(s);
-
- if (n >= len)
- n = len - 1;
-
- strncpy(buf, s, n);
-
- buf[n] = '\0';
+ TRACEJVMCALLS(("JVM_GetLastErrorString(buf=%p, len=%d", buf, len));
- return n;
- }
+ return hpi_system->GetLastErrorString(buf, len);
}
{
TRACEJVMCALLS(("JVM_NativePath(path=%s)", path));
- /* XXX is this correct? */
-
- return path;
+ return hpi_file->NativePath(path);
}
TRACEJVMCALLS(("JVM_Open(fname=%s, flags=%d, mode=%d)", fname, flags, mode));
- result = system_open(fname, flags, mode);
+ result = hpi_file->Open(fname, flags, mode);
if (result >= 0) {
return result;
{
TRACEJVMCALLS(("JVM_Close(fd=%d)", fd));
- return system_close(fd);
+ return hpi_file->Close(fd);
}
{
TRACEJVMCALLS(("JVM_Read(fd=%d, buf=%p, nbytes=%d)", fd, buf, nbytes));
- return system_read(fd, buf, nbytes);
+ return (jint) hpi_file->Read(fd, buf, nbytes);
}
{
TRACEJVMCALLS(("JVM_Write(fd=%d, buf=%s, nbytes=%d)", fd, buf, nbytes));
- return system_write(fd, buf, nbytes);
+ return (jint) hpi_file->Write(fd, buf, nbytes);
}
jint JVM_Available(jint fd, jlong *pbytes)
{
-#if defined(FIONREAD)
- int bytes;
- int result;
-
TRACEJVMCALLS(("JVM_Available(fd=%d, pbytes=%p)", fd, pbytes));
- *pbytes = 0;
-
- result = ioctl(fd, FIONREAD, &bytes);
-
- if (result < 0)
- return 0;
-
- *pbytes = bytes;
-
- return 1;
-#else
-# error FIONREAD not defined
-#endif
+ return hpi_file->Available(fd, pbytes);
}
{
TRACEJVMCALLS(("JVM_Lseek(fd=%d, offset=%ld, whence=%d)", fd, offset, whence));
- return (jlong) system_lseek(fd, (off_t) offset, whence);
+ return hpi_file->Seek(fd, (off_t) offset, whence);
}
{
TRACEJVMCALLS(("JVM_SetLength(fd=%d, length=%ld)", length));
- return system_ftruncate(fd, length);
+ return hpi_file->SetLength(fd, length);
}
{
TRACEJVMCALLS(("JVM_Sync(fd=%d)", fd));
- return system_fsync(fd);
+ return hpi_file->Sync(fd);
}
jint JVM_InitializeSocketLibrary()
{
- log_println("JVM_InitializeSocketLibrary: IMPLEMENT ME!");
+ TRACEJVMCALLS(("JVM_InitializeSocketLibrary()"));
- return 0;
+ return hpi_initialize_socket_library();
}
#endif
int opt_TraceCompilerCalls = 0;
int opt_TraceExceptions = 0;
+int opt_TraceHPI = 0;
#if defined(ENABLE_INLINING) && !defined(NDEBUG)
int opt_TraceInlining = 0;
#endif
OPT_TestReplacement,
OPT_TraceCompilerCalls,
OPT_TraceExceptions,
+ OPT_TraceHPI,
OPT_TraceInlining,
OPT_TraceJavaCalls,
OPT_TraceJNICalls,
#endif
{ "TraceCompilerCalls", OPT_TraceCompilerCalls, OPT_TYPE_BOOLEAN, "trace JIT compiler calls" },
{ "TraceExceptions", OPT_TraceExceptions, OPT_TYPE_BOOLEAN, "trace Exception throwing" },
+ { "TraceHPI", OPT_TraceHPI, OPT_TYPE_BOOLEAN, "Trace Host Porting Interface (HPI)" },
#if defined(ENABLE_INLINING) && !defined(NDEBUG)
{ "TraceInlining", OPT_TraceInlining, OPT_TYPE_VALUE, "trace method inlining with the given verbosity level (default: 1)" },
#endif
opt_TraceExceptions = enable;
break;
+ case OPT_TraceHPI:
+ opt_TraceHPI = enable;
+ break;
+
#if defined(ENABLE_INLINING) && !defined(NDEBUG)
case OPT_TraceInlining:
if (value == NULL)
#endif
extern int opt_TraceCompilerCalls;
extern int opt_TraceExceptions;
+extern int opt_TraceHPI;
#if defined(ENABLE_INLINING) && !defined(NDEBUG)
extern int opt_TraceInlining;
#endif