Java Source Code Obfuscator/Optimisation

Hi,

Intellij planing to support source code obfuscation/optimisation, such as

1. Removing dead code
    - of unused public, protected, package, private classes, methods and variable
   - This depends on the root class provided e.g main in java class, applet class for applets, midlet class in j2me midlets
2. Class/Interface merging
    Support class and interface merging so as to reduce no of classes/interfaces.
    .eg if a program has intefaces A and B with both having public static final variables only,     B extends A and overides few of the public static final variables. If the program uses the refeces to B
every where then , We could copy all the public static final variables which are not over ridden in B to B and remove A completely.

There are many such obfusators/optimisations already avaiable and popular at class byte level. However none is popular at source code level.
e.g of class obfuscators are prograourd, retroguard etc..
e.g of java source code are http://www.pcsentinelsoftware.com/products/mangleitjava/install_mangler_java.php

I am sure what I said or of such optimsations and once this approach become popular, there could n such optimisation possible and help in software source code maintance.

Regards,
Raja Nagendra Kumar,
C.T.O
www.tejasoft.com

8 comments
Comment actions Permalink

1. Removing dead code
    - of unused public, protected, package, private classes, methods and variable
   - This depends on the root class provided e.g main in java class, applet class for applets, midlet class in j2me midlets

IDEA already has some inspections for detecting code which is not used. See the Declaration Redundancy category in the inspection profiles. Quite many of them are available only when selecting Analyze | Inspect Code. There are also refactorings for moving class members (e.g. Move, Pull Members Up, Push Members Down), like in your second example.

I don't quite understand why you mention "obfuscation" and "source code" in the same sentence. According to a dictionary obfuscation is "the activity of obscuring people's understanding, leaving them baffled or bewildered". Obfuscating source code would make maintenance a pain, so that's why it's typically used only for bytecode, which does not need to be edited. Also at bytecode level more obfuscations are possible, so that the bytecode is harder to convert back to Java code.

0
Comment actions Permalink

obfuscation is useless anyway.
Not only is it ineffective (you can always revert back to code, and that's true for any binary, not just Java) but your code isn't in need of protecting because it's not as brilliant as you think it is by far.

If there are security reasons, you're far better off changing your distribution model so no code is ever delivered to anyone.

-1
Comment actions Permalink

jwenting wrote:

obfuscation is useless anyway.
Not only is it ineffective (you can always revert back to code, and that's true for any binary, not just Java) but your code isn't in need of protecting because it's not as brilliant as you think it is by far.


If there are security reasons, you're far better off changing your distribution model so no code is ever delivered to anyone.

Obfuscation is not useless.
1 - you can't revert back any piece of code, especially from Java 5
2 - it takes much longer to understand an obfuscated code and this is already a good point for many cases

I'm waiting for you to convince Jetbrains team to not obfuscate IDEA jars (which would be great for plugin developers)

0
Comment actions Permalink

I'm waiting for you to convince Jetbrains team to not obfuscate IDEA jars (which would be great for plugin developers)

+1

I dislike making plugins for IDEA because it's extremely hard to figure out how something should be done, when you can not for example find all usages of some public interface, or look at the implementation of some action so that you could write a similar action.

Instead of obfuscation and keeping the source code private, it would be better for programs to provide the full source code (and test cases) and restrict their usage with license conditions. It would make using that code much easier, even if the license would not allow you to modify or copy code from it.

0
Comment actions Permalink

Hello Sylvain,

I'm waiting for you to convince Jetbrains team to not obfuscate IDEA
jars (which would be great for
plugin developers)


Obfuscation is beneficial to ordinary users (no names of private methods
in class files => less code to read from disk => faster startup) and shouldn't
affect plugin developers (because only private methods are obfuscated).

--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0
Comment actions Permalink

Hello Dmitry,

This was just an ironic note towards previous poster, I was not really complaining about IDEA obfuscation.

And when I said it did affect plugin developers, I meant that, since lots of IDEA API are not documented, obfuscated code remains very valuable to find use cases, even though it's sometimes tedious

Sylvain

0
Comment actions Permalink

> I don't quite understand why you mention "obfuscation" and "source code" in the same sentence. ;) According to a dictionary obfuscation is "the activity of obscuring people's understanding, leaving them baffled or bewildered". Obfuscating source code would make maintenance a pain, so that's why it's typically used only for bytecode, which does not need to


Sorry for the wrong term.. I ment to say code shrinking and optimisation  (In the JavaME world all these are also treated as part of obfuscation)


Intent is to remove from the source code the unused parts of the current release and maintain only that code in the branch etc.

Regards,
Raja Nagendra Kumar

0
Comment actions Permalink

>IDEA already has some inspections for detecting code which is not used. See the Declaration Redundancy category in the inspection profiles. Quite many of them are available only when selecting Analyze | Inspect Code. There are also refactorings for moving class members (e.g. Move, Pull Members Up, Push Members Down), like in your second example.

What would be much nicer would be to give code optimization screen with options of project specific interfaces which could merged, the methods which could removed and impact on the code lines which gets reduced and probable jar size reduction.

May be if intellij looks at this need as a way for the users to play with many of the optimization options which can be done at code level (with specific UI) then its use would be very immense and as IDE it demands low profile users to understand and play with code which is leading to product code optimisation.

On of the goal of analysis could be Code Optimisation and provide list of options and show the impact of each as preview etc.

Current Analysis is great.. but with HTML kind of approach and huge number of issues it is not in par with many other pure UI features of Intellij. Analyse with Pleasure is missing..


Regards,
Raja Nagendra Kumar,
C.T.O
www.tejasoft.com

0

Please sign in to leave a comment.