Re: [PATCH] x86: Introduce workarounds for valgrind to work with jato.

2009-09-01 Thread Pekka Enberg
On Mon, 2009-08-31 at 16:14 +0200, Tomek Grabiec wrote:
 Jato can be compiled with workarounds which make valgrind
 work with jato.
 
 To do so, define VALGRIND variable for make:
 make jato VALGRIND=y

We can auto-detect whether we're running on valgrind or not:

  #include valgrind/valgrind.h
  #include stdio.h

  int main(int argc, char *argv[])
  {
if (RUNNING_ON_VALGRIND)
  printf(Running on valgrind\n);
else
  printf(Not running on valgrind\n);

return 0;
  }

I guess we should do that in main() and enable the workarounds if we're
on valgrind.

Pekka



--
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
___
Jatovm-devel mailing list
Jatovm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jatovm-devel


[PATCH] x86: Introduce workarounds for valgrind to work with jato.

2009-08-31 Thread Tomek Grabiec
Jato can be compiled with workarounds which make valgrind
work with jato.

To do so, define VALGRIND variable for make:
make jato VALGRIND=y

Currently workarounds eliminate class initialization
from signal handler by unconditionally selecting
calls to vm_class_ensure_init().

Signed-off-by: Tomek Grabiec tgrab...@gmail.com
---
 Makefile   |5 +
 arch/x86/insn-selector.brg |   44 
 2 files changed, 49 insertions(+), 0 deletions(-)

diff --git a/Makefile b/Makefile
index 55ef9ba..f9c8d9b 100644
--- a/Makefile
+++ b/Makefile
@@ -177,6 +177,11 @@ INSTALL:= install
 
 DEFAULT_CFLAGS += $(ARCH_CFLAGS) -g -rdynamic -std=gnu99 -D_GNU_SOURCE 
-fstack-protector-all -D_FORTIFY_SOURCE=2
 
+ifdef VALGRIND
+DEFAULT_CFLAGS += -DCONFIG_VALGRIND
+MB_DEFINES += -DCONFIG_VALGRIND
+endif
+
 # XXX: Temporary hack -Vegard
 DEFAULT_CFLAGS += -DNOT_IMPLEMENTED='fprintf(stderr, %s:%d: warning: %s not 
implemented\n, __FILE__, __LINE__, __func__)'
 
diff --git a/arch/x86/insn-selector.brg b/arch/x86/insn-selector.brg
index 8522667..9c8dd70 100644
--- a/arch/x86/insn-selector.brg
+++ b/arch/x86/insn-selector.brg
@@ -1051,6 +1051,14 @@ reg: EXPR_CLASS_FIELD 1
vmc_state = vmc-state;
vm_monitor_unlock(vmc-monitor);
 
+%ifdef CONFIG_VALGRIND
+   select_insn(s, tree, imm_insn(INSN_PUSH_IMM, (unsigned long)vmc));
+   select_insn(s, tree, rel_insn(INSN_CALL_REL, (unsigned 
long)vm_class_ensure_init));
+   method_args_cleanup(s, tree, 1);
+
+   mov_insn = memdisp_reg_insn(INSN_MOV_MEMDISP_REG,
+   (unsigned long) vmc-static_values + 
vmf-offset, out);
+%else
if (vmc_state = VM_CLASS_INITIALIZING) {
/* Class is already initialized; no need for fix-up. We also
 * don't want the fixup if we're already inside the
@@ -1064,6 +1072,7 @@ reg:  EXPR_CLASS_FIELD 1
/* XXX: Check return value */
add_getstatic_fixup_site(mov_insn, vmf, s-b_parent);
}
+%endif /* CONFIG_VALGRIND */
 
select_insn(s, tree, mov_insn);
 
@@ -1097,6 +1106,18 @@ freg:EXPR_FLOAT_CLASS_FIELD 1
vmc_state = vmc-state;
vm_monitor_unlock(vmc-monitor);
 
+%ifdef CONFIG_VALGRIND
+   select_insn(s, tree, imm_insn(INSN_PUSH_IMM, (unsigned 
long)vmc));
+   select_insn(s, tree, rel_insn(INSN_CALL_REL, (unsigned 
long)vm_class_ensure_init));
+   method_args_cleanup(s, tree, 1);
+
+   if (expr-vm_type == J_FLOAT)
+   mov_insn = memdisp_reg_insn(INSN_MOV_MEMDISP_XMM,
+   (unsigned long) vmc-static_values + 
vmf-offset, out);
+   else
+   mov_insn = memdisp_reg_insn(INSN_MOV_64_MEMDISP_XMM,
+   (unsigned long) vmc-static_values + 
vmf-offset, out);
+%else
if (vmc_state = VM_CLASS_INITIALIZING) {
/* Class is already initialized; no need for fix-up. We also
 * don't want the fixup if we're already inside the
@@ -1118,6 +1139,7 @@ freg: EXPR_FLOAT_CLASS_FIELD 1
/* XXX: Check return value */
add_getstatic_fixup_site(mov_insn, vmf, s-b_parent);
}
+%endif /* CONFIG_VALGRIND */
 
select_insn(s, tree, mov_insn);
 }
@@ -1995,6 +2017,14 @@ stmt:STMT_STORE(EXPR_CLASS_FIELD, reg)
vmc_state = vmc-state;
vm_monitor_unlock(vmc-monitor);
 
+%ifdef CONFIG_VALGRIND
+   select_insn(s, tree, imm_insn(INSN_PUSH_IMM, (unsigned long)vmc));
+   select_insn(s, tree, rel_insn(INSN_CALL_REL, (unsigned 
long)vm_class_ensure_init));
+   method_args_cleanup(s, tree, 1);
+
+   mov_insn = reg_memdisp_insn(INSN_MOV_REG_MEMDISP,
+   src, (unsigned long) vmc-static_values + 
vmf-offset);
+%else
if (vmc_state = VM_CLASS_INITIALIZING) {
/* Class is already initialized; no need for fix-up. We also
 * don't want the fixup if we're already inside the
@@ -2008,6 +2038,7 @@ stmt: STMT_STORE(EXPR_CLASS_FIELD, reg)
/* XXX: Check return value */
add_putstatic_fixup_site(mov_insn, vmf, s-b_parent);
}
+%endif /* CONFIG_VALGRIND */
 
select_insn(s, tree, mov_insn);
 
@@ -2044,6 +2075,18 @@ stmt:STMT_STORE(EXPR_FLOAT_CLASS_FIELD, freg)
vmc_state = vmc-state;
vm_monitor_unlock(vmc-monitor);
 
+%ifdef CONFIG_VALGRIND
+   select_insn(s, tree, imm_insn(INSN_PUSH_IMM, (unsigned long)vmc));
+   select_insn(s, tree, rel_insn(INSN_CALL_REL, (unsigned 
long)vm_class_ensure_init));
+   method_args_cleanup(s, tree, 1);
+
+   if (store_dest-vm_type == J_FLOAT)
+   mov_insn = reg_memdisp_insn(INSN_MOV_XMM_MEMDISP,
+   src, (unsigned long) vmc-static_values + vmf-offset);
+   else
+   mov_insn = 

Re: [PATCH] x86: Introduce workarounds for valgrind to work with jato.

2009-08-31 Thread Pekka Enberg
Hi Tomek,

On Mon, 2009-08-31 at 16:14 +0200, Tomek Grabiec wrote:
 Jato can be compiled with workarounds which make valgrind
 work with jato.
 
 To do so, define VALGRIND variable for make:
 make jato VALGRIND=y
 
 Currently workarounds eliminate class initialization
 from signal handler by unconditionally selecting
 calls to vm_class_ensure_init().
 
 Signed-off-by: Tomek Grabiec tgrab...@gmail.com

Can we turn this into -Xvalgrind command line option instead? We're
still in early stages of development and are likely to use it a lot. An
extra compile-time option will make things debugging than necessary, I
think.

Pekka


--
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
___
Jatovm-devel mailing list
Jatovm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jatovm-devel