You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Emmanuel Bourg (JIRA)" <ji...@apache.org> on 2014/04/24 16:07:17 UTC

[jira] [Updated] (BCEL-161) InstructionTargeters not being properly cleaned up.

     [ https://issues.apache.org/jira/browse/BCEL-161?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Emmanuel Bourg updated BCEL-161:
--------------------------------

    Description: 
It seems that InstructionTargeters are not being properly cleaned up when they are not used anymore. That is, when a targeter is replaced or removed (e.g., a LocalVariableGen is removed from a method), the targeter remains in the targeters list of its targets.

For example, MethodGen's constructor which receives a Method uses its other constructor to initialize the object:

{code}
public MethodGen(Method m, String class_name, ConstantPoolGen cp) {
   this(
       m.getAccessFlags(), 
       Type.getReturnType(m.getSignature()),
       Type.getArgumentTypes(m.getSignature()),
       null /* may be overridden anyway */,
       m.getName(), 
       class_name,
       ((m.getAccessFlags() & (Constants.ACC_ABSTRACT | Constants.ACC_NATIVE)) == 0) ? new InstructionList(m.getCode().getCode()) : null, cp);
...
}
{code}

Because this call passes null as its 4th argument, the constructor will create placeholder LocalVariableGen for the arguments (like arg0, arg1, etc). Later in this constructor the arguments will be overridden (as indicated by the comment). However, the LocalVariableGens of the placeholder arguments (as well as the LocalVariableGen for the "this" variable) will remain in the targeter lists of the first and last instructions of the instruction list.

To avoid this problem I am submitting a patch in attachment. It adds a new method to InstructionTargeter:

{code}
    /**
     * Removes all targets of this targeter.
     */
    void removeTargets();
{code}

and implements it to remove the targeter from the target's lists. The patch also calls removeTargets() when discarding targeters in MethodGen.

  was:
It seems that InstructionTargeters are not being properly cleaned up when they are not used anymore. That is, when a targeter is replaced or removed (e.g., a LocalVariableGen is removed from a method), the targeter remains in the targeters list of its targets.

For example, MethodGen's constructor which receives a Method uses its other constructor to initialize the object:

public MethodGen(Method m, String class_name, ConstantPoolGen cp) {
   this(
       m.getAccessFlags(), 
       Type.getReturnType(m.getSignature()),
       Type.getArgumentTypes(m.getSignature()),
       null /* may be overridden anyway */,
       m.getName(), 
       class_name,
       ((m.getAccessFlags() & (Constants.ACC_ABSTRACT | Constants.ACC_NATIVE)) == 0) ? new InstructionList(m.getCode().getCode()) : null, cp);
...
}

Because this call passes null as its 4th argument, the constructor will create placeholder LocalVariableGen for the arguments (like arg0, arg1, etc). Later in this constructor the arguments will be overridden (as indicated by the comment). However, the LocalVariableGens of the placeholder arguments (as well as the LocalVariableGen for the "this" variable) will remain in the targeter lists of the first and last instructions of the instruction list.

To avoid this problem I am submitting a patch in attachment. It adds a new method to InstructionTargeter:

    /**
     * Removes all targets of this targeter.
     */
    void removeTargets();

and implements it to remove the targeter from the target's lists. The patch also calls removeTargets() when discarding targeters in MethodGen.

       Priority: Minor
    Environment:     (was: Operating System: Linux
Platform: PC)
       Priority:   (was: P2)
       Severity:   (was: minor)

> InstructionTargeters not being properly cleaned up.
> ---------------------------------------------------
>
>                 Key: BCEL-161
>                 URL: https://issues.apache.org/jira/browse/BCEL-161
>             Project: Commons BCEL
>          Issue Type: Bug
>          Components: Main
>    Affects Versions: 5.3
>            Reporter: Thiago
>            Assignee: Apache Commons Developers
>            Priority: Minor
>         Attachments: patch.diff
>
>
> It seems that InstructionTargeters are not being properly cleaned up when they are not used anymore. That is, when a targeter is replaced or removed (e.g., a LocalVariableGen is removed from a method), the targeter remains in the targeters list of its targets.
> For example, MethodGen's constructor which receives a Method uses its other constructor to initialize the object:
> {code}
> public MethodGen(Method m, String class_name, ConstantPoolGen cp) {
>    this(
>        m.getAccessFlags(), 
>        Type.getReturnType(m.getSignature()),
>        Type.getArgumentTypes(m.getSignature()),
>        null /* may be overridden anyway */,
>        m.getName(), 
>        class_name,
>        ((m.getAccessFlags() & (Constants.ACC_ABSTRACT | Constants.ACC_NATIVE)) == 0) ? new InstructionList(m.getCode().getCode()) : null, cp);
> ...
> }
> {code}
> Because this call passes null as its 4th argument, the constructor will create placeholder LocalVariableGen for the arguments (like arg0, arg1, etc). Later in this constructor the arguments will be overridden (as indicated by the comment). However, the LocalVariableGens of the placeholder arguments (as well as the LocalVariableGen for the "this" variable) will remain in the targeter lists of the first and last instructions of the instruction list.
> To avoid this problem I am submitting a patch in attachment. It adds a new method to InstructionTargeter:
> {code}
>     /**
>      * Removes all targets of this targeter.
>      */
>     void removeTargets();
> {code}
> and implements it to remove the targeter from the target's lists. The patch also calls removeTargets() when discarding targeters in MethodGen.



--
This message was sent by Atlassian JIRA
(v6.2#6252)