Question on COMPONENT_REF
Angelo Corsaro
corsaro@cse.wustl.edu
Wed Mar 19 01:17:00 GMT 2003
Hello,
As part of my RTSJ extension to GCJ, I've been implementing store
checks for array and Object fields. It was pretty straight forward
to get them in the case in which native code is generated from .class
files, but I am having some trouble with the case in which source
files are compiled.
The function that craft the call to the check is the following:
tree
build_java_memref_check(from, to)
tree from, to;
{
tree check;
if (from != NULL_TREE) {
check = build (CALL_EXPR, ptr_type_node,
build_address_of (soft_checkmemref_node),
tree_cons (NULL_TREE, from,
build_tree_list (NULL_TREE, to)),
NULL_TREE);
}
else {
check = build (CALL_EXPR,
ptr_type_node,
build_address_of (soft_check_static_memref_node),
build_tree_list (NULL_TREE, to),
NULL_TREE);
}
TREE_SIDE_EFFECTS (check) = 1;
return check;
}
What this does is crafting the call to the appropriate library
function, which in turns returns the pointer to the "to" object
in case the reference is safe and throws an IllegalReferenceException
in the other case.
To emit this check for fields assignment in the case Java source files
are compiled that's what I've added to parse.y
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/parse.y,v
retrieving revision 1.405.2.8
diff -r1.405.2.8 parse.y
12933c12933
<
---
>12982a12983,13006
>>> if (TREE_CODE(lvalue) == COMPONENT_REF)
> {
> tree mem_ref_check, self_ref;
>> /* Save RHS so that it doesn't get re-evaluated by the store
check. */
> new_rhs = save_expr (new_rhs);
>> /* Get the INDIRECT_REF. */
> self_ref= TREE_OPERAND (TREE_OPERAND (lvalue, 0), 0);
> /* Get the pointer expr. */
> self_ref = TREE_OPERAND (self_ref, 0);
>> new_rhs = build_java_memref_check(self_ref, new_rhs);
> }
This code is in the patch_assignemt function, right before the ending
of the method i.e. right before:
TREE_OPERAND (node, 0) = lvalue;
TREE_OPERAND (node, 1) = new_rhs;
TREE_TYPE (node) = lhs_type;
return node;
The change above does not seem to work, and the compiler segfaults.
I know that the change should be pretty straigh forward (it was so for
the .class case), but I am new to the GCC frontend. I have some
questions that might help me out understand what is going wrong:
- When lvalue is a COMPONENT_ REF, with:
self_ref= TREE_OPERAND (TREE_OPERAND (lvalue, 0), 0);
self_ref = TREE_OPERAND (self_ref, 0);
Do I really get the pointer to the object for which the field
is being referenced, and NULL_TREE if the field is static?
- If I remove the line:
new_rhs = build_java_memref_check(self_ref, new_rhs);
Things work fine, but clearly I don't get the check emitted.
With the call in place GCJ segfaults while compiling the
source. Am I missing something in placing the call?
Cheers,
Angelo
--
Angelo Corsaro
Department of Computer Science
Washington University
One Brookings Drive, Box 1045
St. Louis, MO 63130
http://www.cs.wustl.edu/~corsaro
More information about the Java
mailing list