You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by "Shapira, Yoav" <Yo...@mpi.com> on 2003/05/12 21:21:51 UTC

[OFF-TOPIC] Detecting recursion

Howdy,
Does anyone know of a tool that will analyze source code or compiled
bytecode to detect recursive function calls?  I've looked at PMD, JLint,
findBugs, and others, but couldn't find one.  I'm actually talking about
adding this to PMD with Tom Copeland, its architect, but that may take a
while.

I would like to catch cross-method recursion, but I'll settle for same
method recursion for now, i.e.:

int methodA() {
 ... do something ...
 methodA();
 ... do more ...
}

(Cross-method recursion would look like this: )
int methodA() {
  ... do something ...
  methodB();
  ... do more ...
}

int methodB(){ 
  ... do something ...
  methodA();
  ... do more ...
}

The two methods may even be located in different classes.

I realize this is a very difficult code analysis problem, just
wondering...

Yoav Shapira
Millennium ChemInformatics





This e-mail, including any attachments, is a confidential business communication, and may contain information that is confidential, proprietary and/or privileged.  This e-mail is intended only for the individual(s) to whom it is addressed, and may not be saved, copied, printed, disclosed or used by anyone else.  If you are not the(an) intended recipient, please immediately delete this e-mail from your computer system and notify the sender.  Thank you.


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: [OFF-TOPIC] Detecting recursion

Posted by Tim Funk <fu...@joedog.org>.
At compile time - can't think of one. But at run time it could be "easy" to 
detect by having the debugger look at the current stack trace every once in a 
while and a recursion warning could be thrown if the same (class and) method 
name appear in the stack trace more than N times.

This could also be done with commons-logging (and a lot of overhead in tracemode)
/*
     Since a line looks like this:
	at java.lang.Class.getMethod(Class.java:883)
     Just split the thing into lines and count the dups.
*/
if (logger.isTraceEnabled()){
   Map map = new HashMap();
   String stackTrace = magicalGetCurrentStackTrace();
   List lines = magicalSplitMethod(stackTrace);
   for (Iterator i=lines.iterator();i.hasNext();){
     String line = (String)i.next();
     Long c = map.get(line);
     if (c==null)
         c=new Long(1);
     else
         c=new Long(c.longValue()+1);
     /* Does the same method signature appear more than 5 times? */
     if (c.longValue()>5) { /* or whatever */
        logger.trace("Possible Recursion for line: " + line);
     }
   }
}

-Tim

Shapira, Yoav wrote:
> Howdy,
> Does anyone know of a tool that will analyze source code or compiled
> bytecode to detect recursive function calls?  I've looked at PMD, JLint,
> findBugs, and others, but couldn't find one.  I'm actually talking about
> adding this to PMD with Tom Copeland, its architect, but that may take a
> while.
> 
> I would like to catch cross-method recursion, but I'll settle for same
> method recursion for now, i.e.:
> 
> int methodA() {
>  ... do something ...
>  methodA();
>  ... do more ...
> }
> 
> (Cross-method recursion would look like this: )
> int methodA() {
>   ... do something ...
>   methodB();
>   ... do more ...
> }
> 
> int methodB(){ 
>   ... do something ...
>   methodA();
>   ... do more ...
> }
> 
> The two methods may even be located in different classes.
> 
> I realize this is a very difficult code analysis problem, just
> wondering...
> 
> Yoav Shapira
> Millennium ChemInformatics
> 
>  


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: [OFF-TOPIC] Detecting recursion

Posted by Dan Tarkenton <ta...@yahoo.com>.
Hmmm, Yoav, were you the one that had a problem going from jdk1.3 and JAAS to jdk1.4 and it's inclusion of JAAS as a core API?  I seem to remember something along the lines of one class, Permission, or maybe Principal doing recursive lookups.

"Shapira, Yoav" <Yo...@mpi.com> wrote:
Howdy,
Does anyone know of a tool that will analyze source code or compiled
bytecode to detect recursive function calls? I've looked at PMD, JLint,
findBugs, and others, but couldn't find one. I'm actually talking about
adding this to PMD with Tom Copeland, its architect, but that may take a
while.

I would like to catch cross-method recursion, but I'll settle for same
method recursion for now, i.e.:

int methodA() {
... do something ...
methodA();
... do more ...
}

(Cross-method recursion would look like this: )
int methodA() {
... do something ...
methodB();
... do more ...
}

int methodB(){
... do something ...
methodA();
... do more ...
}

The two methods may even be located in different classes.

I realize this is a very difficult code analysis problem, just
wondering...

Yoav Shapira
Millennium ChemInformatics





This e-mail, including any attachments, is a confidential business communication, and may contain information that is confidential, proprietary and/or privileged. This e-mail is intended only for the individual(s) to whom it is addressed, and may not be saved, copied, printed, disclosed or used by anyone else. If you are not the(an) intended recipient, please immediately delete this e-mail from your computer system and notify the sender. Thank you.


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


---------------------------------
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.