Signed-off-by: Tomek Grabiec <tgrab...@gmail.com> --- jit/invoke-bc.c | 16 ++++++++++++++++ test/jit/bc-test-utils.c | 11 +++++++++++ test/jit/bc-test-utils.h | 1 + test/jit/invoke-bc-test.c | 15 ++++++++++----- 4 files changed, 38 insertions(+), 5 deletions(-)
diff --git a/jit/invoke-bc.c b/jit/invoke-bc.c index 7735cec..41c0f8b 100644 --- a/jit/invoke-bc.c +++ b/jit/invoke-bc.c @@ -98,6 +98,20 @@ static struct methodblock *resolve_invoke_target(struct parse_context *ctx) return resolveMethod(ctx->cu->method->class, idx); } +/* Replaces first argument with null check expression on that argument */ +static void null_check_first_arg(struct expression *arg) +{ + struct expression *expr; + + if (expr_type(arg) == EXPR_ARG) { + expr = null_check_expr(to_expr(arg->arg_expression)); + arg->arg_expression = &expr->node; + } + + if (expr_type(arg) == EXPR_ARGS_LIST) + null_check_first_arg(to_expr(arg->args_right)); +} + int convert_invokevirtual(struct parse_context *ctx) { struct methodblock *invoke_target; @@ -144,6 +158,8 @@ int convert_invokespecial(struct parse_context *ctx) if (err) goto failed; + null_check_first_arg(to_expr(expr->args_list)); + err = insert_invoke_expr(ctx, expr); if (err) goto failed; diff --git a/test/jit/bc-test-utils.c b/test/jit/bc-test-utils.c index a3a2657..b93dec3 100644 --- a/test/jit/bc-test-utils.c +++ b/test/jit/bc-test-utils.c @@ -72,6 +72,17 @@ void assert_value_expr(enum vm_type expected_vm_type, assert_int_equals(expected_value, expr->value); } +void assert_nullcheck_value_expr(enum vm_type expected_vm_type, + long long expected_value, + struct tree_node *node) +{ + struct expression *expr = to_expr(node); + + assert_int_equals(EXPR_NULL_CHECK, expr_type(expr)); + assert_value_expr(expected_vm_type, expected_value, + expr->null_check_ref); +} + void assert_fvalue_expr(enum vm_type expected_vm_type, double expected_value, struct tree_node *node) { diff --git a/test/jit/bc-test-utils.h b/test/jit/bc-test-utils.h index 8ec8535..99b46f2 100644 --- a/test/jit/bc-test-utils.h +++ b/test/jit/bc-test-utils.h @@ -20,6 +20,7 @@ void __free_simple_bb(struct basic_block *); void free_simple_bb(struct basic_block *); void assert_value_expr(enum vm_type, long long, struct tree_node *); +void assert_nullcheck_value_expr(enum vm_type, long long, struct tree_node *); void assert_fvalue_expr(enum vm_type, double, struct tree_node *); void assert_local_expr(enum vm_type, unsigned long, struct tree_node *); void assert_temporary_expr(struct tree_node *); diff --git a/test/jit/invoke-bc-test.c b/test/jit/invoke-bc-test.c index f4228fb..a8f73c9 100644 --- a/test/jit/invoke-bc-test.c +++ b/test/jit/invoke-bc-test.c @@ -128,7 +128,8 @@ static void assert_invoke_expression_type(enum expression_type expected_type, un __free_simple_bb(bb); } -static void assert_invoke_passes_objectref(unsigned char invoke_opc) +static void assert_invoke_passes_objectref(unsigned char invoke_opc, + bool nullcheck) { struct expression *invoke_expr; struct expression *arg_expr; @@ -141,8 +142,12 @@ static void assert_invoke_passes_objectref(unsigned char invoke_opc) invoke_expr = to_expr(stmt->expression); arg_expr = to_expr(invoke_expr->args_list); - assert_value_expr(J_REFERENCE, 0xdeadbeef, arg_expr->arg_expression); - + if (nullcheck) + assert_nullcheck_value_expr(J_REFERENCE, 0xdeadbeef, + arg_expr->arg_expression); + else + assert_value_expr(J_REFERENCE, 0xdeadbeef, + arg_expr->arg_expression); __free_simple_bb(bb); } @@ -267,7 +272,7 @@ void test_invokespecial_should_be_converted_to_invokespecial_expr(void) void test_invokespecial_should_pass_objectref_as_first_argument(void) { - assert_invoke_passes_objectref(OPC_INVOKESPECIAL); + assert_invoke_passes_objectref(OPC_INVOKESPECIAL, true); } void test_invokespecial_converts_to_invoke_expr(void) @@ -304,7 +309,7 @@ void test_invokevirtual_should_be_converted_to_invokevirtual_expr(void) void test_invokevirtual_should_pass_objectref_as_first_argument(void) { - assert_invoke_passes_objectref(OPC_INVOKEVIRTUAL); + assert_invoke_passes_objectref(OPC_INVOKEVIRTUAL, false); } void test_invokevirtual_should_parse_passed_arguments(void) -- 1.6.0.6 ------------------------------------------------------------------------------ Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT is a gathering of tech-side developers & brand creativity professionals. Meet the minds behind Google Creative Lab, Visual Complexity, Processing, & iPhoneDevCamp as they present alongside digital heavyweights like Barbarian Group, R/GA, & Big Spaceship. http://p.sf.net/sfu/creativitycat-com _______________________________________________ Jatovm-devel mailing list Jatovm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jatovm-devel