This project contains a test case reducer for Java bytecode in the spirit of C-Reduce. It provides multiple modules that apply different reduction techniques to selected bytecodes in order to remove complex instruction sequences and unused members.
To initiate a reduction sequence, the following command line options are supported:
jreduce [-d <arg>] [-f <arg>] [-help] [-i <arg>] [-k] [-l] [-out <arg>] [-q | -v] [-t <arg>] [-tmp <arg>] [-version]
Argument | Description |
---|---|
-d,--working-dir | The working directory in which the task is run (if omitted, the current directory is assumed) |
-f,--filter | Choose individual operations or modules to apply |
-help,--help | Display information about application usage |
-i,--i-tests | The interestingness test file (test.{sh,bat} is assumed if no argument is supplied) |
-k,--keep | Keep temporary test directories and files |
-l,--list-modules | List all available transformation modules |
-out,--out-dir | The directory where results will be placed |
-q,--quiet | Suppress log messages |
-t,--timeout | The timeout in seconds until runs of the test files are interrupted (to prevent infinite loops) |
-tmp,--temp-dir | The temporary directory where the intermediate test results will be placed |
-v,--verbose | Verbose logging |
-version,--version | Print program version |
-
Fields
-
Remove all field attributes
Attempts to strip fields of all their attributes (effectively making them package-protected instance variables)
-
Remove random field attributes
Attempts to randomly remove field attributes (e.g.
STATIC
,FINAL
,PRIVATE
) -
Remove read-only fields
Removes fields that are only read and never updated (except initial assignment in constructor / initializer)
-
Remove static field attributes
Attempts to remove static attributes of fields (making them instance variables)
-
Remove unused fields
Searches for fields that are never used (except in initial assignment) and removes them
-
Remove write-only fields
Searches for fields that are only updated but never queried and remove them
-
-
Methods
-
Remove all method attributes
Strips all attributes of a method (effectively making them package-protected instance methods)
-
Remove empty methods
Removes (void) methods that only consist of
return
instructions -
Remove initializers
Removes constructors and static initializers (skipping the implicitly created default constructor)
-
Remove random method attributes
Attempts to randomly remove a method attribute (e.g.
STATIC
,FINAL
,SYNCHRONIZED
) -
Remove unused methods
Searches for methods that are never called and removes them - this includes self-recursions i.e.
public void aMethod() { aMethod(); }
-
Remove void method calls
Randomly removes call sites of
void
methods -
Replace method calls
Replaces non-
void
method call sites with assignments to default values - i.e.int i = getInt(); // becomes int i = 0;
-
-
Control flow
-
Remove constant assignments
This low-level module removes consecutive constant assignments - i.e.
iconst_0 istore_0
-
Remove instruction sequences
This low-level module keeps track of the stack size and removes instruction sequences that start at and then again lead to an empty stack
-
Remove stack-neutral instructions
Low-level module that removes (replaced with
nop
) single instructions that do not change the stack level (even if they push and pop elements)
-
-
Miscellaneous
-
Shrink constant pool
Removes elements from the constant pool that are no longer referenced
-
Remove NOPs
Removes any remaining
nop
from the bytecode
-
To run the tool, the project has to be downloaded or cloned. Using the provided Gradle Wrapper, it is possible to run the tool by executing
./gradlew run --args='<args>'
(Linux)
./gradlew.bat run --args='<args>'
(Windows)
from within the application directory.
Additionally, it is also possible to generate a JAR from the sources by executing
./gradlew jar
(Linux)
./gradlew.bat jar
(Windows)
This generates the executable JAR file ./build/libs/jreduce.jar
, which in turn can be run using
java -jar jreduce.jar <args>
The samples folder contains both class file samples and corresponding interestingness tests for both Windows and Linux.