Stay organized with collections
Save and categorize content based on your preferences.
Cycle Finder Tool
Usage
Here's a simple example with a cycle between two classes, Foo and Bar.
cat Foo.java
package mypkg;
public class Foo {
Bar myBar;
}
cat Bar.java
package mypkg;
public class Bar {
Foo myFoo;
}
cycle_finder Foo.java Bar.java
acceptAST: mypkg/Bar.java
acceptAST: mypkg/Foo.java
***** Found reference cycle *****
Bar -> (field myFoo with type Foo)
Foo -> (field myBar with type Bar)
----- Full Types -----
Lmypkg/Bar;
Lmypkg/Foo;
1 CYCLES FOUND.
In the output you will first see acceptAST
for each java file being parsed. This is just informative logging.
For each cycle, there will be printed two lists. The first list contains a description of the cycle. Each line lists an edge in the reference graph. The edge description will show the origin type followed by a description of how the origin type might refer to the target type.
The second list, under Full Types
shows the unique type keys for each type in the cycle. This is useful as it provides the full package of each type.
Suppress Lists
Some detected cycles will not require any corrective action. This may be because the cycle contains long-lived objects that don't need to be deallocated. Or the tool may detect a theoretical cycle based on the types of certain fields where it is provable that the objects involved will never form a cycle. For these cases we can use suppress-list files to not report these cycles.
The tool accepts suppress-list files using the --suppress-list
option. Suppress-list files are plain text files containing one-line entries. A suppress-list entry may take one of 4 forms demonstrated in the below example. It is recommended when adding suppress-list entries to be as specific as possible to avoid suppressing a legitimate cycle. Comments can be added using the '#' character.
# Specifies that "fieldA" in ClassA will not refer to any object that is a subtype of ClassB.
FIELD my.pkg.ClassA.fieldA my.pkg.ClassB
# Suppresses all cycles containing "fieldA" in ClassA.
FIELD my.pkg.ClassA.fieldA
# Suppresses all cycles containing any field of ClassA.
TYPE my.pkg.ClassA
# Suppress all cycles containing the Inner's outer reference to ClassA.
OUTER my.pkg.ClassA.Inner
# Suppress all cycles containing the outer reference from an anonymous class declared in myMethod.
OUTER my.pkg.ClassA.myMethod.$
# Suppresses all cycles containing any type in package "my.pkg".
NAMESPACE my.pkg
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-07-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-07-10 UTC."],[[["\u003cp\u003eThe tool identifies and reports reference cycles within Java code, aiding in memory management and preventing leaks.\u003c/p\u003e\n"],["\u003cp\u003eEach identified cycle is described with a detailed chain of references and the involved types' full package information.\u003c/p\u003e\n"],["\u003cp\u003eCustomizable suppress lists can be used to ignore known or irrelevant cycles based on fields, types, outer class references, or namespaces.\u003c/p\u003e\n"],["\u003cp\u003eSuppress list entries allow for specific filtering or broad suppression of cycles depending on the provided criteria.\u003c/p\u003e\n"],["\u003cp\u003eUsers are encouraged to utilize specific entries in suppress lists to avoid unintentional suppression of legitimate issues.\u003c/p\u003e\n"]]],[],null,["Cycle Finder Tool\n=================\n\n### Usage\n\nHere's a simple example with a cycle between two classes, Foo and Bar. \n\n cat Foo.java\n package mypkg;\n public class Foo {\n Bar myBar;\n }\n\n cat Bar.java\n package mypkg;\n public class Bar {\n Foo myFoo;\n }\n\n cycle_finder Foo.java Bar.java\n acceptAST: mypkg/Bar.java\n acceptAST: mypkg/Foo.java\n\n ***** Found reference cycle *****\n Bar -\u003e (field myFoo with type Foo)\n Foo -\u003e (field myBar with type Bar)\n ----- Full Types -----\n Lmypkg/Bar;\n Lmypkg/Foo;\n\n 1 CYCLES FOUND.\n\nIn the output you will first see `acceptAST` for each java file being parsed. This is just informative logging.\n\nFor each cycle, there will be printed two lists. The first list contains a description of the cycle. Each line lists an edge in the reference graph. The edge description will show the origin type followed by a description of how the origin type might refer to the target type.\n\nThe second list, under `Full Types` shows the unique type keys for each type in the cycle. This is useful as it provides the full package of each type.\n\n### Suppress Lists\n\nSome detected cycles will not require any corrective action. This may be because the cycle contains long-lived objects that don't need to be deallocated. Or the tool may detect a theoretical cycle based on the types of certain fields where it is provable that the objects involved will never form a cycle. For these cases we can use suppress-list files to not report these cycles.\n\nThe tool accepts suppress-list files using the `--suppress-list` option. Suppress-list files are plain text files containing one-line entries. A suppress-list entry may take one of 4 forms demonstrated in the below example. It is recommended when adding suppress-list entries to be as specific as possible to avoid suppressing a legitimate cycle. Comments can be added using the '#' character. \n\n # Specifies that \"fieldA\" in ClassA will not refer to any object that is a subtype of ClassB.\n FIELD my.pkg.ClassA.fieldA my.pkg.ClassB\n\n # Suppresses all cycles containing \"fieldA\" in ClassA.\n FIELD my.pkg.ClassA.fieldA\n\n # Suppresses all cycles containing any field of ClassA.\n TYPE my.pkg.ClassA\n\n # Suppress all cycles containing the Inner's outer reference to ClassA.\n OUTER my.pkg.ClassA.Inner\n\n # Suppress all cycles containing the outer reference from an anonymous class declared in myMethod.\n OUTER my.pkg.ClassA.myMethod.$\n\n # Suppresses all cycles containing any type in package \"my.pkg\".\n NAMESPACE my.pkg"]]