Expressions with volatile content should not be pushed onto mimic-stack because there is a possibility that their content will be modified before their value is accessed. An example of this situation is this java snippet:
int x = 0; int y; y = x++; Which compiles to the following instructions: 0: iconst_0 1: istore_1 2: iload_1 3: iinc 1, 1 6: istore_2 Instriction at pc=2 pushes EXPR_LOCAL onto mimic-stack. Instruction at pc=3 modifies value of local variable. Instruction at pc=6 generates STMT_STORE with source popped from mimic-stack (EXPR_LOCAL) which has invalid value - it was modified while in mimic-stack. The solution for this is to generate STMT_STORE which copies the value of local variable into a new temporary at *load bytecodes and push corresponding EXPR_TEMPORARY on stack. Signed-off-by: Tomek Grabiec <tgrab...@gmail.com> --- jit/load-store-bc.c | 10 +++++++++- 1 files changed, 9 insertions(+), 1 deletions(-) diff --git a/jit/load-store-bc.c b/jit/load-store-bc.c index ec0036d..9f3e02f 100644 --- a/jit/load-store-bc.c +++ b/jit/load-store-bc.c @@ -12,6 +12,7 @@ #include <jit/compiler.h> #include <jit/statement.h> +#include <jit/expression.h> #include <vm/bytecode.h> #include <vm/bytecodes.h> @@ -178,13 +179,20 @@ int convert_ldc2_w(struct parse_context *ctx) static int convert_load(struct parse_context *ctx, unsigned char index, enum vm_type type) { + struct expression *tmp_expr; struct expression *expr; expr = local_expr(type, index); if (!expr) return -ENOMEM; - convert_expression(ctx, expr); + tmp_expr = copy_expr_value(ctx, expr); + if (!tmp_expr) { + expr_put(expr); + return -ENOMEM; + } + + convert_expression(ctx, tmp_expr); return 0; } -- 1.6.0.6 ------------------------------------------------------------------------------ _______________________________________________ Jatovm-devel mailing list Jatovm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jatovm-devel