Pages

Wednesday, February 23, 2011

Java Bytecode Fundamentals. Part II. Passing parameters

Judging from the feedback, the first Java Bytecode Fundamentals was rather a success. So I though maybe it is worth to continue the series on some other aspects of the topic.

The interesting part of the bytecode is the one that covers method invocation and parameter passing. I have put up a full-blown post here: Java Bytecode Fundamentals: Using Objects and Calling Methods. The article covers how objects are created at the bytecode level, what the opcodes for method invocation are, how parameters are passed to the method invocations and how the return value is passed back. The important part to understand is how the stack is involved into the operations, along with the local variable table taking part in the game.

Just to reveal some parts of the full post, here's the slidecast demonstrating the parameter passing process in method invocation:

Jfokus 2011 in Pictures

Tuesday, February 1, 2011

Technology Radar 2011

ThoughWorks has published the brand new edition of Technology Radar for 2011. Honestly, some of the things look really weird compared to the previous editions. But also some of the technologies mentioned are rather surprising/positive.

Techniques


Real-time business intelligence. The radar says that batch jobs are the outdated form of data processing and business cannot rely on that if one aims to be on global markets. I can say that I have experienced that myself during last 5 years fighting for batch jobs performance for almost every project that I have worked on - the amount of data doesn't allow you to fit into the maintenance window. Moving to real-time or event-based systems/architectures is inevitable as there's the need to distribute the processing load in time. The only thing I wander is why is this still in the Assess phase? It should be Adopted already!

DevOps looks like the new hype to me. I think it will hardly happen at the full scale. It is hard to find good developers, it is hard to find ninja-sysadmins, where do you find good devops?

Automated database deployment - that's an interesting topic for the last few years already. I hardly believe the topic just made it to the radar.

Concurrency abstractions and patterns section mentions Clojure, Erlang, Retlang. That's interesting, as these languages hardly can take the niche of application programming languages like Java or C#, but specifically for concurrency - this is a very compelling alternative. My personal preference is Erlang, and I think it would be a good idea to take a look at Erjang as well.

Catagorization of technical debt. Oh yes, Captain Obvious!

Tools


The first thing I'm thinking of when I hear "Insfrastructure as Code", is Puppet! And what do you know, it is on the radar! :) Some interesting tools are mentioned as well - Vagrant, Deltacloud, Splunk, etc. I only wander why these tools are on the radar - I kind of doubt that these tools are unique.

The biggest surprise in the Tools section is the state of Subversion. AFAIK, Subversion was loosing popularity according to the last year radar's editions, and now it is in the Adopt phase again.

I wonder why JRebel isn't on the list?? :)

Languages


The report suggests that Ruby, JRuby, C# are mature enough to start using these language for production. Well, this somehow correlates with the job posts for JRuby that I have seen last months. Looks rather positive to me! :) On the other hand the report suggests to consider "Java language EOF". You know what - that's a speculation, even if Oracle owns Java now.

javaScript as first-class language? Noooooooooooooooooooooooo!

Scala and Groovy are in the Trial phase... Don't care really.

Domain-Specific Languages is an old technique that we think is significantly under-used.

It seems that the DSL hype is shrinking. Maybe it is partly because that a good API is a DSL in some sense? My opinion is, the biggest problem of DSLs is that they are mostly usable by their authors :)

Platforms


OpenStack looks quite interesting for infrastructure solution. Kind of surprising that KVM has made it right to the center of the radar's target.

Surprising is that GWT is on Hold while Node.js is in Assess phase according to the report. Node.js is probably the argument for having JavaScript as the first-class language. Well, I haven't tried it myself yet and feel quite doubtful about it. Maybe one day...

Heroku looks like an interesting PaaS for ruby devs. I think this is something worth trying if you do ruby development.

Not a surprise, Android has reached the center of the radar, I'd expect an exploading growth of jobs for Android devs despite the Google-Oracle law suite.

ThoughWorks radar is always an interesting read, but it seems to be a little biased as .NET world is almost unmentioned there (OK, C# and F# are on the list, but it is almost unnoticeable) and the most traction is still around the Java platform (yay!).

Sunday, January 16, 2011

Java snippet: get PID at runtime

package my.pid;

import java.lang.management.ManagementFactory;

public class MyPid {
  public static void main(String[] args) {
    String nameOfRunningVM = ManagementFactory.getRuntimeMXBean().getName();
    int p = nameOfRunningVM.indexOf('@');
    String pid = nameOfRunningVM.substring(0, p);
    System.out.println("Java app PID: " + pid);
  }
}

Sunday, January 2, 2011

Java Bytecode Fundamentals

Java bytecode is a bread and butter of JRebel, the productivity tool for Java developers. This is why I decided that it would be a good thing to write a blog post on this subject. This blog post is a summary of various sources that I've found while googling on the subject. Hopefully someone may find it relevant and useful. What is a little weird is that there's not much information on the subject, either books or articles. BTW, if you have anything to add or comment - don't hesitate to post to comments :)

UPDATE This blog post, along with many improvements is a part of my article for RebelLabs' report on Java Bytecode that can be found here: http://zeroturnaround.com/rebellabs/rebel-labs-report-mastering-java-bytecode-at-the-core-of-the-jvm/


The developers who use Java for application development, usually do not need to be aware of the bytecode that is being executed in the VM. However, those developers who implement the state-of-the-art frameworks, compilers, or even Java tooling - may need to understand and may even be using bytecode directly. While special libraries (like ASM, cglib, Javassist) do help regarding bytecode manipulation, it is still important to understand the fundamentals in order to make the effective use of those tools.


Let's start off with a simple example - a POJO, with one field, a getter and a setter.

public class Foo {
    private String bar;

    public String getBar(){ 
      return bar; 
    }

    public void setBar(String bar) {
      this.bar = bar;
    }
  }

First of all, one you compile the class using javac Foo.java, you'll have the Foo.class, which now contains the bytecode. Here's how it looks in the hex editor:


Each pair of hex numbers (a byte) is actually translatable to opcodes (mnemonics), but obviously it would be too brutal to start reading it in the binary format. Let's proceed to the mnemonical representation.

Executing javap -c Foo will print out the bytecode:
public class Foo extends java.lang.Object {
public Foo();
  Code:
   0:   aload_0
   1:   invokespecial   #1; //Method java/lang/Object."<init>":()V
   4:   return

public java.lang.String getBar();
  Code:
   0:   aload_0
   1:   getfield        #2; //Field bar:Ljava/lang/String;
   4:   areturn

public void setBar(java.lang.String);
  Code:
   0:   aload_0
   1:   aload_1
   2:   putfield        #2; //Field bar:Ljava/lang/String;
   5:   return

}
The class is very simple and it is easy to see the relation between the sourced code and the generated bytecode. First of all we notice that in the bytecode version of the class the compiler inferred the default constructor (as promised by the JVM spec).

Thursday, December 16, 2010

Apples vs Oranges. Java Container Startup Times

Just recently with @toomasr we've studied how fast are the Java application servers at the boot time. The boot time for an application server is an integral part of what we call the developers' productivity.

The most surprising this thing about the results was that the JBoss 7 average startup times where extremely fast compared to the previous JBoss versions.



At the beginning we couldn't believe this improvement is for real and assumed that JBoss 7 is an OSGi container. But just a bit later some JBossAS developers commented on the blog entry, that actually JBoss 7 has been completely redesigned for classloading performance.

Andy Miller said:
The startup times really don't have anything do with the OSGi stuff that is in there. It's based on a new services architecture underneath, which can start services and load classes in parallel (there are some JVM limits in class loading that make it serial, but we hope that will disappear), and take advantage of the fact that there are multiple cores on virtually every machine someone would use today.

To learn about the new features in JBoss 7, the highly recommended listening can be found at the JBoss Asylum podcasts page.

Thumbs up for the JBoss engineers, really! At least some AS vendors do care about the developers productivity! :)

Tuesday, December 14, 2010

LiveRebel Product Demo

JetBrains Youtrack

Recently, I've spent some time playing with Youtrack, the bug tracker by JetBrains. The last time I was looking at it was about 2 years ago, when it was announced under the name Charisma.

Long story short - I've a very pleasant experience while trying Youtrack now. But let's take a closer look!


I kick ass withAJAX-based issue management system
What are the features that I've noticed and liked:

The command-line with auto-complete. Sometimes I get really lazy and just unwilling to use the bugtracker as I have to use the mouse and click over several screens in the bugtracker's UI to get the job done. With Youtrack, I can make queries in the command-line that has autocompletion, which is awesome!
Project settings and administration. It took me just a couple of minutes to configure a project and the users. And also I figured out very quickly how to the user roles work. Considering I'm just an ordinary user for this type of software - this is a good sign!
Shortcuts are configured just like in IntelliJ IDEA, which I'm being a big fan of. I think this is an awesome feature for any IntelliJ user trying to use Youtrack.
The UI did not cause any animosity during use for me. Also, you can make screenshots just from the form where you report an issue - a very handy feature I have to say.

Disqus for Code Impossible