[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: DeadAssignmentEliminator
> > if(!method.isStatic() &&
> > ((InstanceFieldRef)rhs).getBase() == body.getThisLocal()) {
> > isEssential = false;
I think that:
if (((InstanceFieldRef)rhs).getBase() == body.getThisLocal()) {
isEssential = false;
is enough as:
"The keyword this may be used only in the body of an instance method,
instance initializer or constructor, or in the initializer of an instance
variable of a class. If it appears anywhere else, a compile-time error
occurs."
I think it is also true in byte-code. This should be checked by the verifier.
> I just checked that this is a final variable for javac, so it can't be
> changed in java code.
"this" is not really final, but according to the Language spec:
"When used as a primary expression, the keyword this denotes a value, that is
a reference to the object for which the instance method was invoked (§15.12),
or to the object being constructed."
AND
"The result of the first operand of an assignment operator must be a variable"
So this=... is impossible (hopefully). However, I did not check in the VM
spec and I don't know if you can produce bytecode with the same effect.
Fabien
--
---- Fabien Deschodt Sable Research Group
------ fabien@deschodt.net http://www.sable.mcgill.ca
---- http://www.deschodt.net
--