We should not push EXPR_CLASS_FIELD and EXPR_INSTANCE_FIELD onto
mimic-stack because another operation can change the value of the
field and when EXPR_*_FIELD will be popped from stack it's value will
be different from the one that it had when it was pushed. It breaks
language semantics.

Signed-off-by: Tomek Grabiec <[email protected]>
---
 jit/object-bc.c |   22 ++++++++++++++++------
 1 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/jit/object-bc.c b/jit/object-bc.c
index 8b8658b..b4a6ed9 100644
--- a/jit/object-bc.c
+++ b/jit/object-bc.c
@@ -79,6 +79,7 @@ static struct vm_field *lookup_field(struct parse_context 
*ctx)
 
 int convert_getstatic(struct parse_context *ctx)
 {
+       struct expression *value_dup;
        struct expression *value;
        struct vm_field *fb;
 
@@ -90,7 +91,11 @@ int convert_getstatic(struct parse_context *ctx)
        if (!value)
                return -ENOMEM;
 
-       convert_expression(ctx, value);
+       value_dup = dup_expr(ctx, value);
+       if (!value_dup)
+               return -ENOMEM;
+
+       convert_expression(ctx, value_dup);
        return 0;
 }
 
@@ -108,7 +113,7 @@ int convert_putstatic(struct parse_context *ctx)
        dest = class_field_expr(vm_field_type(fb), fb);
        if (!dest)
                return -ENOMEM;
-       
+
        store_stmt = alloc_statement(STMT_STORE);
        if (!store_stmt) {
                expr_put(dest);
@@ -117,13 +122,14 @@ int convert_putstatic(struct parse_context *ctx)
        store_stmt->store_dest = &dest->node;
        store_stmt->store_src = &src->node;
        convert_statement(ctx, store_stmt);
-       
+
        return 0;
 }
 
 int convert_getfield(struct parse_context *ctx)
 {
        struct expression *objectref;
+       struct expression *value_dup;
        struct expression *value;
        struct vm_field *fb;
 
@@ -137,7 +143,11 @@ int convert_getfield(struct parse_context *ctx)
        if (!value)
                return -ENOMEM;
 
-       convert_expression(ctx, value);
+       value_dup = dup_expr(ctx, value);
+       if (!value_dup)
+               return -ENOMEM;
+
+       convert_expression(ctx, value_dup);
        return 0;
 }
 
@@ -157,7 +167,7 @@ int convert_putfield(struct parse_context *ctx)
        dest = instance_field_expr(vm_field_type(fb), fb, objectref);
        if (!dest)
                return -ENOMEM;
-       
+
        store_stmt = alloc_statement(STMT_STORE);
        if (!store_stmt) {
                expr_put(dest);
@@ -166,7 +176,7 @@ int convert_putfield(struct parse_context *ctx)
        store_stmt->store_dest = &dest->node;
        store_stmt->store_src = &src->node;
        convert_statement(ctx, store_stmt);
-       
+
        return 0;
 }
 
-- 
1.6.0.6


------------------------------------------------------------------------------
_______________________________________________
Jatovm-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jatovm-devel

Reply via email to