harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arc...@apache.org
Subject svn commit: r373688 - in /incubator/harmony/enhanced/jchevm: ./ libjc/ libjc/arch/ libjc/arch/i386/ libjc/arch/ppc/
Date Tue, 31 Jan 2006 03:42:54 GMT
Author: archie
Date: Mon Jan 30 19:42:43 2006
New Revision: 373688

URL: http://svn.apache.org/viewcvs?rev=373688&view=rev
Log:
Replace use of getcontext() with setjmp() for stack clipping, and scan
the jmp_buf conservatively instead of requiring reference-holding
saved registers to be specified. This makes the code more portable.

Modified:
    incubator/harmony/enhanced/jchevm/configure.ac
    incubator/harmony/enhanced/jchevm/libjc/arch/arch_definitions.h
    incubator/harmony/enhanced/jchevm/libjc/arch/arch_libjc.h
    incubator/harmony/enhanced/jchevm/libjc/arch/i386/i386_definitions.h
    incubator/harmony/enhanced/jchevm/libjc/arch/i386/i386_libjc.h
    incubator/harmony/enhanced/jchevm/libjc/arch/ppc/ppc_definitions.h
    incubator/harmony/enhanced/jchevm/libjc/arch/ppc/ppc_libjc.h
    incubator/harmony/enhanced/jchevm/libjc/gc_root.c
    incubator/harmony/enhanced/jchevm/libjc/libjc.h
    incubator/harmony/enhanced/jchevm/libjc/stack.c
    incubator/harmony/enhanced/jchevm/libjc/structures.h

Modified: incubator/harmony/enhanced/jchevm/configure.ac
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/jchevm/configure.ac?rev=373688&r1=373687&r2=373688&view=diff
==============================================================================
--- incubator/harmony/enhanced/jchevm/configure.ac (original)
+++ incubator/harmony/enhanced/jchevm/configure.ac Mon Jan 30 19:42:43 2006
@@ -94,12 +94,6 @@
 AC_CHECK_HEADERS(sys/mman.h sys/wait.h pthread.h fcntl.h signal.h \
 	ctype.h errno.h dlfcn.h sched.h math.h pwd.h zlib.h, [],
 	[AC_MSG_ERROR([required header file missing])])
-AC_CHECK_HEADERS([ucontext.h], [],
-	[AC_MSG_ERROR([required header file missing])],
-[#if HAVE_SIGNAL_H
-# include <signal.h>
-# endif
-])
 
 AC_CHECK_HEADERS(inttypes.h)
 
@@ -107,9 +101,6 @@
 AC_FUNC_MMAP
 AC_CHECK_FUNCS([getcwd gettimeofday memmove memset munmap], , \
     [AC_MSG_ERROR([required function missing])])
-
-# Check for optional library functions
-AC_CHECK_FUNCS([getcontext])
 
 # See if pthread_attr_setstack() is available
 AC_CHECK_FUNCS([pthread_attr_setstack])

Modified: incubator/harmony/enhanced/jchevm/libjc/arch/arch_definitions.h
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/jchevm/libjc/arch/arch_definitions.h?rev=373688&r1=373687&r2=373688&view=diff
==============================================================================
--- incubator/harmony/enhanced/jchevm/libjc/arch/arch_definitions.h (original)
+++ incubator/harmony/enhanced/jchevm/libjc/arch/arch_definitions.h Mon Jan 30 19:42:43 2006
@@ -72,14 +72,6 @@
 
     _JC_BIG_ENDIAN	1 if big endian, 0 if little endian
 
-Other definitions
------------------
-
-    _JC_REGISTER_OFFS	Initializer for an array of integers representing
-    			the offsets into a mcontext_t structure where the
-			registers possibly containing references live.
-			Used for garbage collection.
-
 */
 
 /************************************************************************

Modified: incubator/harmony/enhanced/jchevm/libjc/arch/arch_libjc.h
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/jchevm/libjc/arch/arch_libjc.h?rev=373688&r1=373687&r2=373688&view=diff
==============================================================================
--- incubator/harmony/enhanced/jchevm/libjc/arch/arch_libjc.h (original)
+++ incubator/harmony/enhanced/jchevm/libjc/arch/arch_libjc.h Mon Jan 30 19:42:43 2006
@@ -100,9 +100,9 @@
 memory, etc. See "arch/arch_structures.h".
 
     const void *
-    _jc_mcontext_sp(const mcontext_t *mctx)
+    _jc_jmpbuf_sp(const jmp_buf *buf)
 
-    	Returns the saved stack pointer from an mcontext_t structure.
+    	Returns the saved stack pointer from a jmp_buf structure.
 
 */
 
@@ -121,7 +121,7 @@
 				_jc_word *words, _jc_rvalue *retval);
 
 /* Stack pointer functions */
-extern const void	*_jc_mcontext_sp(const mcontext_t *mctx);
+extern const void	*_jc_jmpbuf_sp(const jmp_buf buf);
 
 /************************************************************************
  *			Architecture-specific functions			*

Modified: incubator/harmony/enhanced/jchevm/libjc/arch/i386/i386_definitions.h
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/jchevm/libjc/arch/i386/i386_definitions.h?rev=373688&r1=373687&r2=373688&view=diff
==============================================================================
--- incubator/harmony/enhanced/jchevm/libjc/arch/i386/i386_definitions.h (original)
+++ incubator/harmony/enhanced/jchevm/libjc/arch/i386/i386_definitions.h Mon Jan 30 19:42:43
2006
@@ -31,49 +31,5 @@
 
 #define _JC_BIG_ENDIAN		0
 
-#ifdef __FreeBSD__
-
-#define	_JC_REGISTER_OFFS	{					\
-	_JC_OFFSETOF(mcontext_t, mc_gs),				\
-	_JC_OFFSETOF(mcontext_t, mc_fs),				\
-	_JC_OFFSETOF(mcontext_t, mc_es),				\
-	_JC_OFFSETOF(mcontext_t, mc_ds),				\
-	_JC_OFFSETOF(mcontext_t, mc_edi),				\
-	_JC_OFFSETOF(mcontext_t, mc_esi),				\
-	_JC_OFFSETOF(mcontext_t, mc_ebp),				\
-	_JC_OFFSETOF(mcontext_t, mc_isp),				\
-	_JC_OFFSETOF(mcontext_t, mc_ebx),				\
-	_JC_OFFSETOF(mcontext_t, mc_edx),				\
-	_JC_OFFSETOF(mcontext_t, mc_ecx),				\
-	_JC_OFFSETOF(mcontext_t, mc_eax),				\
-	_JC_OFFSETOF(mcontext_t, mc_cs),				\
-	_JC_OFFSETOF(mcontext_t, mc_esp),				\
-	_JC_OFFSETOF(mcontext_t, mc_ss),				\
-    }
-
-#elif defined(__linux__)
-
-#define	_JC_REGISTER_OFFS	{					\
-	_JC_OFFSETOF(mcontext_t, gregs) + REG_GS  * sizeof(greg_t),	\
-	_JC_OFFSETOF(mcontext_t, gregs) + REG_FS  * sizeof(greg_t),	\
-	_JC_OFFSETOF(mcontext_t, gregs) + REG_ES  * sizeof(greg_t),	\
-	_JC_OFFSETOF(mcontext_t, gregs) + REG_DS  * sizeof(greg_t),	\
-	_JC_OFFSETOF(mcontext_t, gregs) + REG_EDI * sizeof(greg_t),	\
-	_JC_OFFSETOF(mcontext_t, gregs) + REG_ESI * sizeof(greg_t),	\
-	_JC_OFFSETOF(mcontext_t, gregs) + REG_EBP * sizeof(greg_t),	\
-	_JC_OFFSETOF(mcontext_t, gregs) + REG_ESP * sizeof(greg_t),	\
-	_JC_OFFSETOF(mcontext_t, gregs) + REG_EBX * sizeof(greg_t),	\
-	_JC_OFFSETOF(mcontext_t, gregs) + REG_EDX * sizeof(greg_t),	\
-	_JC_OFFSETOF(mcontext_t, gregs) + REG_ECX * sizeof(greg_t),	\
-	_JC_OFFSETOF(mcontext_t, gregs) + REG_EAX * sizeof(greg_t),	\
-	_JC_OFFSETOF(mcontext_t, gregs) + REG_CS  * sizeof(greg_t),	\
-	_JC_OFFSETOF(mcontext_t, gregs) + REG_UESP* sizeof(greg_t),	\
-	_JC_OFFSETOF(mcontext_t, gregs) + REG_SS  * sizeof(greg_t),	\
-    }
-
-#else
-#error "Unsupported O/S for i386 _JC_REGISTER_OFFS"
-#endif
-
 #endif	/* _ARCH_I386_DEFINITIONS_H_ */
 

Modified: incubator/harmony/enhanced/jchevm/libjc/arch/i386/i386_libjc.h
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/jchevm/libjc/arch/i386/i386_libjc.h?rev=373688&r1=373687&r2=373688&view=diff
==============================================================================
--- incubator/harmony/enhanced/jchevm/libjc/arch/i386/i386_libjc.h (original)
+++ incubator/harmony/enhanced/jchevm/libjc/arch/i386/i386_libjc.h Mon Jan 30 19:42:43 2006
@@ -48,17 +48,17 @@
 #ifdef __FreeBSD__
 
 extern inline const void *
-_jc_mcontext_sp(const mcontext_t *mctx)
+_jc_jmpbuf_sp(const jmp_buf buf)
 {
-	return (const void *)mctx->mc_esp;
+	return (const void *)buf[0]._jb[0];
 }
 
 #elif defined(__linux__)
 
 extern inline const void *
-_jc_mcontext_sp(const mcontext_t *mctx)
+_jc_jmpbuf_sp(const jmp_buf buf)
 {
-	return (const void *)mctx->gregs[REG_ESP];
+	return (const void *)buf[0].__jmpbuf[4];
 }
 
 #else

Modified: incubator/harmony/enhanced/jchevm/libjc/arch/ppc/ppc_definitions.h
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/jchevm/libjc/arch/ppc/ppc_definitions.h?rev=373688&r1=373687&r2=373688&view=diff
==============================================================================
--- incubator/harmony/enhanced/jchevm/libjc/arch/ppc/ppc_definitions.h (original)
+++ incubator/harmony/enhanced/jchevm/libjc/arch/ppc/ppc_definitions.h Mon Jan 30 19:42:43
2006
@@ -30,23 +30,5 @@
 
 #define _JC_BIG_ENDIAN		1
 
-#define	_JC_REGISTER_OFFS	{					\
-	_JC_OFFSETOF(mcontext_t, mc_gs),				\
-	_JC_OFFSETOF(mcontext_t, mc_fs),				\
-	_JC_OFFSETOF(mcontext_t, mc_es),				\
-	_JC_OFFSETOF(mcontext_t, mc_ds),				\
-	_JC_OFFSETOF(mcontext_t, mc_edi),				\
-	_JC_OFFSETOF(mcontext_t, mc_esi),				\
-	_JC_OFFSETOF(mcontext_t, mc_ebp),				\
-	_JC_OFFSETOF(mcontext_t, mc_isp),				\
-	_JC_OFFSETOF(mcontext_t, mc_ebx),				\
-	_JC_OFFSETOF(mcontext_t, mc_edx),				\
-	_JC_OFFSETOF(mcontext_t, mc_ecx),				\
-	_JC_OFFSETOF(mcontext_t, mc_eax),				\
-	_JC_OFFSETOF(mcontext_t, mc_cs),				\
-	_JC_OFFSETOF(mcontext_t, mc_esp),				\
-	_JC_OFFSETOF(mcontext_t, mc_ss),				\
-    }
-
 #endif	/* _ARCH_PPC_DEFINITIONS_H_ */
 

Modified: incubator/harmony/enhanced/jchevm/libjc/arch/ppc/ppc_libjc.h
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/jchevm/libjc/arch/ppc/ppc_libjc.h?rev=373688&r1=373687&r2=373688&view=diff
==============================================================================
--- incubator/harmony/enhanced/jchevm/libjc/arch/ppc/ppc_libjc.h (original)
+++ incubator/harmony/enhanced/jchevm/libjc/arch/ppc/ppc_libjc.h Mon Jan 30 19:42:43 2006
@@ -62,9 +62,9 @@
  * @todo Returning NULL to be compile-clean for the moment.
  */
 extern inline const void *
-_jc_mcontext_sp(const mcontext_t *mctx)
+_jc_jmpbuf_sp(const jmp_buf buf)
 {
-	fprintf(stderr, "WARNING: call to unimplemented function _jc_mcontext_sp(...)\n");
+	fprintf(stderr, "WARNING: call to unimplemented function _jc_jmpbuf_sp(...)\n");
 	exit(0);
 	return (const void *) NULL;
 }

Modified: incubator/harmony/enhanced/jchevm/libjc/gc_root.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/jchevm/libjc/gc_root.c?rev=373688&r1=373687&r2=373688&view=diff
==============================================================================
--- incubator/harmony/enhanced/jchevm/libjc/gc_root.c (original)
+++ incubator/harmony/enhanced/jchevm/libjc/gc_root.c Mon Jan 30 19:42:43 2006
@@ -20,10 +20,6 @@
 
 #include "libjc.h"
 
-/* Internal definitions */
-#define _JC_NUM_REGISTER_OFFS						\
-	(sizeof(_jc_register_offs) / sizeof(*_jc_register_offs))
-
 /* Internal functions */
 static _jc_object	*_jc_locate_object(_jc_jvm *vm,
 				const _jc_word *info, const void *ptr);
@@ -34,9 +30,6 @@
 static int		_jc_scan_c_stack(_jc_jvm *vm, _jc_c_stack *cstack,
 				const _jc_word *info, _jc_object ***refsp);
 
-/* Internal variables */
-static const int	_jc_register_offs[] = _JC_REGISTER_OFFS;
-
 /*
  * Find the head of the object given a pointer into its interior.
  * This is used for conservative GC scan.
@@ -316,15 +309,15 @@
 	_jc_object *obj;
 	const char *ptr;
 	int count = 0;
-	int regnum;
+	int i;
 
 	/* Get references from saved registers */
-	for (regnum = 0; regnum < _JC_NUM_REGISTER_OFFS; regnum++) {
+	for (i = 0; i < sizeof(cstack->regs); i++) {
+		const char *const ptr = (char *)&cstack->regs + i;
 
-		/* Find object pointed to by register, if any */
-		if ((obj = _jc_locate_object(vm, info,
-		    *(_jc_word **)((char *)&cstack->regs
-		      + _jc_register_offs[regnum]))) == NULL)
+		/* Find object pointed into, if any */
+		if ((obj = _jc_locate_object(vm,
+		    info, *(_jc_word **)ptr)) == NULL)
 			continue;
 
 		/* Add object to list */
@@ -341,7 +334,7 @@
 	stack_bot = (const char *)cstack;
 
 	/* Find the top of this Java stack segment */
-	stack_top = _jc_mcontext_sp(&cstack->regs);
+	stack_top = _jc_jmpbuf_sp(cstack->regs);
 
 	/* Sanity check stack alignment */
 	_JC_ASSERT(((_jc_word)stack_top & (_JC_STACK_ALIGN - 1)) == 0);

Modified: incubator/harmony/enhanced/jchevm/libjc/libjc.h
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/jchevm/libjc/libjc.h?rev=373688&r1=373687&r2=373688&view=diff
==============================================================================
--- incubator/harmony/enhanced/jchevm/libjc/libjc.h (original)
+++ incubator/harmony/enhanced/jchevm/libjc/libjc.h Mon Jan 30 19:42:43 2006
@@ -34,7 +34,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <pthread.h>
-#include <ucontext.h>
+#include <setjmp.h>
 #include <limits.h>
 #include <fcntl.h>
 #include <unistd.h>

Modified: incubator/harmony/enhanced/jchevm/libjc/stack.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/jchevm/libjc/stack.c?rev=373688&r1=373687&r2=373688&view=diff
==============================================================================
--- incubator/harmony/enhanced/jchevm/libjc/stack.c (original)
+++ incubator/harmony/enhanced/jchevm/libjc/stack.c Mon Jan 30 19:42:43 2006
@@ -40,49 +40,23 @@
 	_JC_ASSERT(!cstack->clipped);
 
 	/* Grab the current context and clip the Java stack with it */
-#if HAVE_GETCONTEXT
-    {
-	ucontext_t ctx;
+	sigsetjmp(cstack->regs, JNI_FALSE);
 
-	getcontext(&ctx);
-	cstack->regs = ctx.uc_mcontext;
-    }
-#else
+#ifndef NDEBUG
     {
-	mcontext_t ctx;
-
-	/* Sanity check */
-	_JC_ASSERT(env->ctx == NULL);
-
-	/* Get current machine context */
-#if defined(__FreeBSD__) && defined(__i386__)
-	/* Work around for FreeBSD bug threads/75374 */
-	{
-	    jmp_buf buf;
+    	_jc_word diff;
+	const void *sp;
+	const void *here;
+
+	/* Sanity check the _jc_jmpbuf_sp() function */
+	sp = _jc_jmpbuf_sp(cstack->regs);
+	here = &sp;
+	diff = (sp > here) ? sp - here : here - sp;
+	_JC_ASSERT(diff < 0x100);
 
-	    setjmp(buf);
-	    memset(&ctx, 0, sizeof(ctx));
-	    ctx.mc_eip = buf[0]._jb[0];
-	    ctx.mc_ebx = buf[0]._jb[1];
-	    ctx.mc_esp = buf[0]._jb[2];
-	    ctx.mc_ebp = buf[0]._jb[3];
-	    ctx.mc_esi = buf[0]._jb[4];
-	    ctx.mc_edi = buf[0]._jb[5];
-	}
-#else
-	env->ctx = &ctx;
-	pthread_kill(pthread_self(), SIGSEGV);
-	env->ctx = NULL;
-#endif
-
-	/* Use it to clip Java stack */
-	cstack->regs = ctx.uc_mcontext;
-    }
-#endif
-
-#ifndef NDEBUG
 	/* Mark stack as clipped */
 	cstack->clipped = JNI_TRUE;
+    }
 #endif
 }
 

Modified: incubator/harmony/enhanced/jchevm/libjc/structures.h
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/jchevm/libjc/structures.h?rev=373688&r1=373687&r2=373688&view=diff
==============================================================================
--- incubator/harmony/enhanced/jchevm/libjc/structures.h (original)
+++ incubator/harmony/enhanced/jchevm/libjc/structures.h Mon Jan 30 19:42:43 2006
@@ -178,7 +178,7 @@
  */
 struct _jc_c_stack {
 	_jc_c_stack			*next;
-	mcontext_t			regs;
+	jmp_buf				regs;
 #ifndef NDEBUG
 	jboolean			clipped;
 #endif



Mime
View raw message