Sunday, June 17, 2012

Java Performance mind map

On the last week I had visited our local Oracle branch (where smart guys develop very important parts of JVM) because there was very interesting presentation about Java Performance. I made some mind map based on the presentation and verbal information from speakers and translated it into English (because the original presentation was in Russian). You can see the Mind Map image through the link http://igormaznitsa.com/mindmaps/JavaPerformanceMindMap.png

I have used below information sources to make the mind map:
 - the JEEconf 2012 presentation of Aleksander Shipilev and Sergey Kuksenko
 - the Russian presentation  of Aleksander Shipilev and Sergey Kuksenko on JUG.RU (14 june 2012)
 - the high level of their mind map included into  the presentation (they used the map as the speech plan)   

also there are a lot of interesting stuff on the home page of Aleksander Shipilev (http://shipilev.net) but mainly that information in Russian.

Tuesday, January 24, 2012

A Mockup hard case

   Imagine that you need to test some piece of code which needs a 3th part developed class that is placed into a non-controllable library and you need to get some mockup of the class, of course you will use a mockup framework like Mockito and will not get any problem if the class is a usual "right" class but imagine that the class is not so usual one but it is a final one and furthermore it has a private constructor (because you have to create it through a special class factory method). In the case the Mockito framework will tell you "sorry, it is a final class, I can't make any mockup". 
   Fortunately there is very strong mockup framework called PowerMock and it allows make very interesting and helpful things in such hard cases. As instance, I needed to make a org.apache.bcel.generic.BranchHandle object for some test case but the class is both a final one and it has the private constructor.

public final class BranchHandle extends InstructionHandle {

private BranchInstruction bi;
private static BranchHandle bh_list;

private BranchHandle(BranchInstruction i) {
//compiled code
throw new RuntimeException("Compiled Code");
}
...
}

The class has the factory method
static final BranchHandle getBranchHandle(BranchInstruction i) {
//compiled code
throw new RuntimeException("Compiled Code");
}
but the factory method is not accessible for me because it has the package view modifier.
Fortunately there is a very useful class org.powermock.reflect.Whitebox within the PowerMock framework that allows me to solve the problem
final BranchInstruction instructionInstance = instruction.getConstructor(InstructionHandle.class).newInstance(mockTarget);
final BranchHandle branchHandle = Whitebox.invokeMethod(BranchHandle.class, "getBranchHandle", instructionInstance);
As you can see in the code snippet above, the Whitebox utility class allows you to call a non-visible method of a class. Also the utility class allows you to create instance of the class without any call the private constructor through its newInstance() static method
Whitebox.newInstance(BranchInstruction.class);

Sunday, January 8, 2012

Translation JVM bytecodes into Z80 machine codes

I had some free time during these holidays and have made some "spike" to check possibility to translate JVM byte-codes into Z80 commands and it works. You can see screenshot of a Java program and its translated version execution under the Fuse ZX-Spectrum emulator. The length of translated binary block is 376 bytes but mainly (80%) it contains some garbage imported from the class constant pool.

Wednesday, December 28, 2011

About "silver bullets"

It is very often when I see companies looking for a "silver bullet" that will solve all their problems, as a rule - those companies just don't have a gun

Wednesday, December 14, 2011

A Thought gained through suffering

After more than 14 years in commercial software development I can say with confidence that the most major part of any software is ARCHITECTURE!!! You may have stupid coders, UI-designers and even product owners but you must have a clever experienced system architect!!!

Sunday, December 4, 2011

JCP 5.0 is out!!!

The Java Comment Preprocessor 5.0 has been published and can be downloaded from the project page http://code.google.com/p/java-comment-preprocessor/

Monday, November 21, 2011

Java Comment Preprocessor

I have moved my pet project called Java Comment Preprocessor from my home page to the Google Code service and currently the project page is http://code.google.com/p/java-comment-preprocessor/