On Sun, 2009-09-06 at 10:23 +0200, Vegard Nossum wrote:
> 2009/9/5 Pekka Enberg <penb...@cs.helsinki.fi>:
> > Vegard Nossum wrote:
> >>
> >> 2009/9/5 Pekka Enberg <penb...@cs.helsinki.fi>:
> >>>
> >>> Good point. I wonder why we have methods without code attribute in
> >>> classfiles.
> >>>
> >>
> >> Native and abstract methods don't have code. It's all here:
> >>
> >>
> >> http://java.sun.com/docs/books/jvms/second_edition/html/ClassFile.doc.html#1546
> >>
> >> I think I tried once to skip the prepare-for-jit call, but something
> >> crashed. But I think it's a good idea to try to fix it.
> >
> > Actually, we *do* need to prepare for jit because trampolines work on struct
> > compilation_unit. So we probably need to initialize the cafebabe struct
> > anyway.
> >
> 
> int vm_method_init(struct vm_method *vmm,
>         struct vm_class *vmc, unsigned int method_index)
> {
> ...
>         if (vm_method_is_native(vmm) || vm_method_is_abstract(vmm)) {
>                 /* Hm, we're now modifying a cafebabe structure. */
>                 vmm->code_attribute.max_stack = 0;
>                 vmm->code_attribute.max_locals = vmm->args_count;
> 
>                 vmm->line_number_table_attribute.line_number_table_length = 0;
>                 vmm->line_number_table_attribute.line_number_table = NULL;
>                 return 0;
>         }
> 
> This is where we are initializing the code_attribute if it doesn't really 
> exist.
> 
> I think it's probably the fault of vm_method_init_from_interface()
> which doesn't initialize code_attribute and should do the above
> unconditionally (initialize to zero) because interface methods are
> always abstract.

OK, so why is that better than using calloc()? Here's an alternative
patch that fixes the problem as well.

                        Pekka

>From 2f0fef1b8cc3c9b9b14a2470195d088c41e60e73 Mon Sep 17 00:00:00 2001
From: Pekka Enberg <penb...@cs.helsinki.fi>
Date: Sun, 6 Sep 2009 11:27:24 +0300
Subject: [PATCH] vm: Initialize interface methods properly

Signed-off-by: Pekka Enberg <penb...@cs.helsinki.fi>
---
 vm/method.c |   20 ++++++++++++++------
 1 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/vm/method.c b/vm/method.c
index e6512c2..bfb8948 100644
--- a/vm/method.c
+++ b/vm/method.c
@@ -18,6 +18,16 @@
 #include "jit/args.h"
 #include "jit/cu-mapping.h"
 
+static void init_abstract_method(struct vm_method *vmm)
+{
+       /* Hm, we're now modifying a cafebabe structure. */
+       vmm->code_attribute.max_stack = 0;
+       vmm->code_attribute.max_locals = vmm->args_count;
+
+       vmm->line_number_table_attribute.line_number_table_length = 0;
+       vmm->line_number_table_attribute.line_number_table = NULL;
+}
+
 int vm_method_init(struct vm_method *vmm,
        struct vm_class *vmc, unsigned int method_index)
 {
@@ -88,12 +98,7 @@ int vm_method_init(struct vm_method *vmm,
         * with loading attributes which native and abstract methods don't have.
         */
        if (vm_method_is_native(vmm) || vm_method_is_abstract(vmm)) {
-               /* Hm, we're now modifying a cafebabe structure. */
-               vmm->code_attribute.max_stack = 0;
-               vmm->code_attribute.max_locals = vmm->args_count;
-
-               vmm->line_number_table_attribute.line_number_table_length = 0;
-               vmm->line_number_table_attribute.line_number_table = NULL;
+               init_abstract_method(vmm);
                return 0;
        }
 
@@ -158,6 +163,9 @@ int vm_method_init_from_interface(struct vm_method *vmm, 
struct vm_class *vmc,
 
        vmm->args_count = interface_method->args_count;
        vmm->is_vm_native = false;
+
+       init_abstract_method(vmm);
+
        return 0;
 }
 
-- 
1.5.6.3




------------------------------------------------------------------------------
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

Reply via email to