Needing to gather some details to help answer a question regarding JVM memory and the the distinctions of Perm Space. I thought it might be helpful to post the links of what I thought were incredibly great posts from the past... It is now 2009 and the best posts on this matter appear to come from 2006. Hmm.... perhaps there has been a JDK release in some time :)
On the subject of; the reason the permanent space exists. Jon explains the details of instances of objects and their dependencies on instances of classes and the need for their order as it relates to garbage collection. He also discussions the klassKlass... interesting stuff.
On the subject of String intern, XML parsing and it's effect on Perm Space. haakon or what I assume to be Jenny details the effect of String.intern() and how an out of memory can occur. She does a great job of explaining their troubleshooting approach.
And my favorite book on the JVM spec is Inside the JVM. It turns out there are free chapters of this on the web now and chapter 5 is the chapter detailing the taxonomy of the JVM memory space.
The weakest coverage of any subject based on my searches, is the subject of root sets. Brian Goetz's article on Java Theory and Practice is rock solid.
Thursday, February 5, 2009
Monday, January 26, 2009
Java is a 2nd Class Citizen on MAC OSX
Having made several comments over the last several months, and in particular over the last couple of days regarding Java on the Mac, several people have asked me to explain myself. So here goes.
When I first moved to the MBP as my primary development machine, I was very pleased. As a developer, I was amazed at how all my development tools were just there. Ruby, Rails, cvs, subversion, 2 Java JDKs, it just worked out of the box.
When I first discovered the difference
I have a standard demo I use when show other developers some of the nifty debugging tools like visualgc or visualvm. In order to show the tool off, I need to start another Java process. So I standardly go to the demo directory and start the Java2d.jar. Oh but wait... where is that on the mac. This lead to the discovery that the jdk is in several different directories /locations.
JAVA_HOME = /System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home
Demos: /Developer/Examples/Java/
Bin:/usr/bin/java
Headers/Lib: /Developer/SDKs/MacOSX10.5.sdk/System/Library/Frameworks/JavaVM.framework/Versions/xxx
Java Lib: /Library/Java/Extensions; /usr/lib/java
Endorsed Dirs:$JAVA_HOME/lib/endorsed
System jars: /System/Library/Frameworks/JavaVM.framework/Versions/1.6/Classes
OK... I'll live with that. I quickly discovered a very useful scipt for switch between JDKs. I've modified the original if anyone interested let me know. But since we are on the subject of being a second class citizen, If you go out to the Sun site and look for the latest jdk, the options are windows, linux, and solaris.
Other Issues in Jakarta
Then the next issue came up... jhat was broken. I wrote a lengthy blog post on how to fix this. The issue... Apple didn't include the javascript libraries, which are necessary for these tools to work.
So now I'm taking a serious look at btrace, which is a great tool. Just trying to do the simple stuff, works fine on Windows... but no joy for the Mac. I'm still looking into it, but it appears that Instrumentation..appendToSystemClassLoaderSearch() fails on the Mac. Could be something else... still looking.
If you are doing standard Java development or Groovy and Grails... you may never notice the Mac difference. When you venture into the debugging and instrumentation realm of Java be prepared for some frustrations. As I get a solution for the btrace issue I will post it.
On the positive side, I enjoy the development experience on the MBP better than my experiences on Windows and linux. The memory management is better and the startup times on Java processes is fantastic.
When I first moved to the MBP as my primary development machine, I was very pleased. As a developer, I was amazed at how all my development tools were just there. Ruby, Rails, cvs, subversion, 2 Java JDKs, it just worked out of the box.
When I first discovered the difference
I have a standard demo I use when show other developers some of the nifty debugging tools like visualgc or visualvm. In order to show the tool off, I need to start another Java process. So I standardly go to the demo directory and start the Java2d.jar. Oh but wait... where is that on the mac. This lead to the discovery that the jdk is in several different directories /locations.
JAVA_HOME = /System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home
Demos: /Developer/Examples/Java/
Bin:/usr/bin/java
Headers/Lib: /Developer/SDKs/MacOSX10.5.sdk/System/Library/Frameworks/JavaVM.framework/Versions/xxx
Java Lib: /Library/Java/Extensions; /usr/lib/java
Endorsed Dirs:$JAVA_HOME/lib/endorsed
System jars: /System/Library/Frameworks/JavaVM.framework/Versions/1.6/Classes
OK... I'll live with that. I quickly discovered a very useful scipt for switch between JDKs. I've modified the original if anyone interested let me know. But since we are on the subject of being a second class citizen, If you go out to the Sun site and look for the latest jdk, the options are windows, linux, and solaris.
Other Issues in Jakarta
Then the next issue came up... jhat was broken. I wrote a lengthy blog post on how to fix this. The issue... Apple didn't include the javascript libraries, which are necessary for these tools to work.
So now I'm taking a serious look at btrace, which is a great tool. Just trying to do the simple stuff, works fine on Windows... but no joy for the Mac. I'm still looking into it, but it appears that Instrumentation..appendToSystemClassLoaderSearch() fails on the Mac. Could be something else... still looking.
If you are doing standard Java development or Groovy and Grails... you may never notice the Mac difference. When you venture into the debugging and instrumentation realm of Java be prepared for some frustrations. As I get a solution for the btrace issue I will post it.
On the positive side, I enjoy the development experience on the MBP better than my experiences on Windows and linux. The memory management is better and the startup times on Java processes is fantastic.
Saturday, January 24, 2009
JSR-299 Web Bean Review
As several JCP specifications are reaching there final stages, I decided to have a look at two of them. Truth be known, I actually was going to look at one of them jsr-299, the specification previously known as web beans, here forth now known as Java Contexts and Dependency Inject. There was sufficient enough mention of ejb-lite that I decided to have a look at its specification, jsr-318.
Before I get started, my position on the subject of ejbs should be known. I actually thought that ejbs were on the way out... with the lack of testability and the extra unnecessary complexity for most projects prior to ejb3. EJB3 greatly improved this, but IMHO was too little too late. Spring + Tomcat already provided what folks were looking for. Additionally the number of clients using JSF is a dying breed. Once again, JSF 1.0 missed the boat with non-bookmarkable pages, etc. While there are shops sticking with these Sun driven standards which are produced out of the JCP, the majority of support appears to come out of vendor interest and not developer interest. My earlier work on projects with JSF led me to appreciate a couple of frameworks; 1. facelets, 2. a4jsf, and 3. SEAM (when working on jboss). jsr-299 (web beans) seems to be the formal standardization of SEAM.
My thoughts on jsr-299
It appears that @ annotations are the new shiny toy, and there is no end to specifications going crazy with them. jsr-299 defines 34 new annotations. The goal of the specification as defined on the spec home page, is to unify JSF managed bean component model with the EJB component model... well I've stated my position on this. So either this specification is too little too late and a benefit mainly to jboss, or perhaps there is something to be gained beyond this spec stated goal.
There were several interesting ideas out of the specification. The first was the creation of an extensible annotation model. So if there are not enough annotations in the world for you, you can create your own that work with the framework. This is accomplished through the new javax.inject.@BindingType. This appears to provide fine grain autowiring qualifier. One of the examples given defines
@LDAP
class LdapAuthenticator
implements Authenticator { ... }
followed by the declared injection of an LDAP Authenticator:
@LDAP Authenticator authenticator
Another interesting idea is producers... I really like the concept here. Page 3 and 4 illustrate an example where a @SessionScoped @Model Login class has a @Produces @LoggedIn User getCurrentUser() method. Abbreviated below:
@SessionScoped @Model public class Login {
@Current Credentials credentials;
@PersistenceContext EntityManager userDatabase;
private User user;
@Produces @LoggedIn User getCurrentUser() {
if (user==null) {
throw new NotLoggedInException();
} else {
return user;
}
}
Then the getCurrentUser() method is invoked for the inject as listed below:
@Model
public class DocumentEditor {
@Current Document document;
@LoggedIn User user;
@PersistenceContext EntityManager docDatabase;
public void save() {
document.setCreatedBy(currentUser);
em.persist(document);
}
}
The last interesting part of the specification is the event framework. I don't understand why this is in the specification. There appears to be no dependency for the event framework on the other parts of the specification. It doesn't comply with the stated goal of unification of JSF and EJB. It would make sense for this to be separate. Mainly to use it separate from all other aspects of web beans.
Thoughts on jsr-318
I did not review the entire specification yet. I was checking out some of the mentioned ejb-light details mentioned in jsr299. As mentioned, outside of being required by clients to help them with ejbs or ejb light projects, I'm really not interested. There is however one very interesting addition to the ejb specification, that is the @Asynchronous annotation. This is long over due. In addition to its obvious benefits, a method annotated as asynchronous can also return a value defined as java.util.concurrent.Future where V is the return value type. The return of the Future object provides the ability to check status (isDone()) or to cancel the request. Very cool. For a quick list of EJB 3.1 changes, checkout Ken Saks blog.
The concept of EJB-lite is lost on me... I already have that it is Spring.
Summary
If you are looking to stay in the world of EJBs and JSF, then these newly defined specifications are of great value to you and your shop. jsr-299 fills a number of gaps in the jee space and provides the power of Spring in a standardized way. Clearly jsr-299 will be part of the new jee 1.6 specification, at least in several of the profiles. If you are not using either JSF or EJB or nether, then it is unclear what value this brings to the community. It will be interesting to see if a vendor implements this specification (or a portion of it), in a world without JSF. It appears that the jsr-299 specification helps vendors more than it helps developers.
Before I get started, my position on the subject of ejbs should be known. I actually thought that ejbs were on the way out... with the lack of testability and the extra unnecessary complexity for most projects prior to ejb3. EJB3 greatly improved this, but IMHO was too little too late. Spring + Tomcat already provided what folks were looking for. Additionally the number of clients using JSF is a dying breed. Once again, JSF 1.0 missed the boat with non-bookmarkable pages, etc. While there are shops sticking with these Sun driven standards which are produced out of the JCP, the majority of support appears to come out of vendor interest and not developer interest. My earlier work on projects with JSF led me to appreciate a couple of frameworks; 1. facelets, 2. a4jsf, and 3. SEAM (when working on jboss). jsr-299 (web beans) seems to be the formal standardization of SEAM.
My thoughts on jsr-299
It appears that @ annotations are the new shiny toy, and there is no end to specifications going crazy with them. jsr-299 defines 34 new annotations. The goal of the specification as defined on the spec home page, is to unify JSF managed bean component model with the EJB component model... well I've stated my position on this. So either this specification is too little too late and a benefit mainly to jboss, or perhaps there is something to be gained beyond this spec stated goal.
There were several interesting ideas out of the specification. The first was the creation of an extensible annotation model. So if there are not enough annotations in the world for you, you can create your own that work with the framework. This is accomplished through the new javax.inject.@BindingType. This appears to provide fine grain autowiring qualifier. One of the examples given defines
@LDAP
class LdapAuthenticator
implements Authenticator { ... }
followed by the declared injection of an LDAP Authenticator:
@LDAP Authenticator authenticator
Another interesting idea is producers... I really like the concept here. Page 3 and 4 illustrate an example where a @SessionScoped @Model Login class has a @Produces @LoggedIn User getCurrentUser() method. Abbreviated below:
@SessionScoped @Model public class Login {
@Current Credentials credentials;
@PersistenceContext EntityManager userDatabase;
private User user;
@Produces @LoggedIn User getCurrentUser() {
if (user==null) {
throw new NotLoggedInException();
} else {
return user;
}
}
Then the getCurrentUser() method is invoked for the inject as listed below:
@Model
public class DocumentEditor {
@Current Document document;
@LoggedIn User user;
@PersistenceContext EntityManager docDatabase;
public void save() {
document.setCreatedBy(currentUser);
em.persist(document);
}
}
The last interesting part of the specification is the event framework. I don't understand why this is in the specification. There appears to be no dependency for the event framework on the other parts of the specification. It doesn't comply with the stated goal of unification of JSF and EJB. It would make sense for this to be separate. Mainly to use it separate from all other aspects of web beans.
Thoughts on jsr-318
I did not review the entire specification yet. I was checking out some of the mentioned ejb-light details mentioned in jsr299. As mentioned, outside of being required by clients to help them with ejbs or ejb light projects, I'm really not interested. There is however one very interesting addition to the ejb specification, that is the @Asynchronous annotation. This is long over due. In addition to its obvious benefits, a method annotated as asynchronous can also return a value defined as java.util.concurrent.Future
The concept of EJB-lite is lost on me... I already have that it is Spring.
Summary
If you are looking to stay in the world of EJBs and JSF, then these newly defined specifications are of great value to you and your shop. jsr-299 fills a number of gaps in the jee space and provides the power of Spring in a standardized way. Clearly jsr-299 will be part of the new jee 1.6 specification, at least in several of the profiles. If you are not using either JSF or EJB or nether, then it is unclear what value this brings to the community. It will be interesting to see if a vendor implements this specification (or a portion of it), in a world without JSF. It appears that the jsr-299 specification helps vendors more than it helps developers.
Sunday, January 11, 2009
Windows 7 Download Frustration
The danger in posting this blog entry is that I will be counted as a anti-Microsoft person... which is just not true. I happen to like using the best tool for the job which is not all the time from Microsoft (and sometimes it is). In 2008 I switch my primary system to an Apple Mac. There were many factors as to why and frankly I love it! But I'll always be a technical junkie.
With a number of friends (such as Denny Boynton and Ted Neward) posting about their experiences with Windows 7, I thought it was time to take a look. I thought it was going to be a matter of download, get key, start up vmware fusion and I way I go... but I was wrong.
First I went to the public beta site: http://www.microsoft.com/windows/windows-7/beta-download.aspx and selected the 64-bit version in english and got this. WTF?? Repeated attempts resulted in the same. An oops page with a pre-canned search. Where did I go wrong? Well as you can tell, I'm on my Mac. So I pulled out fusion to launch Windows XP for round 2 of the attempt.
I thought this is just wrong, but determined to get a look, I switch to windows and my suspicions were confirmed when I got one page further. I got the download page with a couple of large buttons on the bottm of the page and one read "Download Now". Hey, that's what I want... I want to download now. I clicked the button and... nothing. Click... Nothing... No way... they didn't. Round 2 was in XP, but with firefox.
Round 3 as you would expect is XP with IE. That combination was successful and I'm now 29% into my download.
BTW... In the process of testing a few more times in writing up this blog, the round 1 mac failure was fixed to the point where you will get download page (nice response time msft), however the download button fails.
Why is it necessary to be like this? Why is it so hard to put up a link to a download which is platform neutral? Wouldn't Microsoft want to attract customers from other platforms? Does it always have to be all or nothing?
With a number of friends (such as Denny Boynton and Ted Neward) posting about their experiences with Windows 7, I thought it was time to take a look. I thought it was going to be a matter of download, get key, start up vmware fusion and I way I go... but I was wrong.

First I went to the public beta site: http://www.microsoft.com/windows/windows-7/beta-download.aspx and selected the 64-bit version in english and got this. WTF?? Repeated attempts resulted in the same. An oops page with a pre-canned search. Where did I go wrong? Well as you can tell, I'm on my Mac. So I pulled out fusion to launch Windows XP for round 2 of the attempt.
I thought this is just wrong, but determined to get a look, I switch to windows and my suspicions were confirmed when I got one page further. I got the download page with a couple of large buttons on the bottm of the page and one read "Download Now". Hey, that's what I want... I want to download now. I clicked the button and... nothing. Click... Nothing... No way... they didn't. Round 2 was in XP, but with firefox.
Round 3 as you would expect is XP with IE. That combination was successful and I'm now 29% into my download.
BTW... In the process of testing a few more times in writing up this blog, the round 1 mac failure was fixed to the point where you will get download page (nice response time msft), however the download button fails.
Why is it necessary to be like this? Why is it so hard to put up a link to a download which is platform neutral? Wouldn't Microsoft want to attract customers from other platforms? Does it always have to be all or nothing?
Tuesday, December 23, 2008
Speaking at Code Mash 2009

I will be speaking on Spring MVC. The title says Spring 2.5 MVC... But I'm throwing a curve ball... it will be Spring 3.0 MVC. See you there!
Monday, December 22, 2008
Complexity and Architecture
It has been too long since I had a post... I have a number of scribbled notes of blog ideas, but little time. I'm in the process of starting to write the spring 3 book, which may take me off grid more than normal. I will make an effort to post a couple of times a month (more if there is something cool to document). Currently my mind has been on 3 subjects; Spring, Architecture and languages. This blog is regarding one of the often forgotten concerns of architecture... complexity.
Defining Software Architecture
I have been in a large number of conference BOFs this year. When the audience is slow in starting a conversation, the question we gravitate to is: "What is a Software Architect?" or its keen "What is Software Architecture?". I guess I shouldn't be surprised, but it is amazing how diverse the answers to these questions are. It is a reflection of at least two things... 1) the immaturity of our industry and /or 2) the lack of standardization in this space. The conversation spans from design decisions to application architecture to enterprise architecture.
Martin Fowler defines architecture as "things that people per-ceive as hard to change". This is a really responisble definition.
I like to define it as "making decisions on all the non-funcational requirements" and "managing all the things you can't control"
The area of non-functional requirements would include:
The subject that is rarely vocalized and debated in architecture is that of complexity. Neal Ford, in a couple of his talks with NFJS, talks about principles that were documented by anciet philosophers... that of essential and accidental properties. He carries this forward into software architecture in a way that we as an industry really need to talk about. That of software architecture decisions moving the enterprise forward in a way that has essential complexity or in a way that increases the accidental complexity. Neal further clarifies the point with the following comments... We have a hard problem (Essential complexity) and we have made our problem hard (Accidental complexity). Well done Neal! Very easy to envision.
Is complexity one of the non-functional requirements which your architecture team is looking at? If not, It seems likely that what is left is accidental.
What is a concrete example of this?
Let's say that your enterprise has just purchased a shiny new ESB. Suppose there wasn't a project need for it... it was just the stated SOA direction of your organization. When down from on high the edict is brought to your project that you must use the ESB in order to justify the $1M expense. Perhaps it is a fit... but perhaps you are about to fit the square peg in the round hole... in other words accidental complexity.
Where does Accidental Complexity come from?
Neal would say that it comes from vendors who are the pushers of accidental complexity... however there is something deeper here. The reason they are referred to as the pushers is that they are incented to sell you a solution. The solution may not fit your needs exactly, but hey, if they can show you a vision of how it could help, then there is a framework to following and life should be more simplified. So essentially we are saying that any choice which doesn't provide the best solution brings complexity.
We could also say that the more stuff / more solutions we have brings complexity. So by adding more frameworks and options we have added complexity. Conversely, many organizations fall into the trap of standardizing certain aspects of development... like everything is an EJB or we don't use store procedures here. In this situation what happens is that the architect and developers will have to come up with a more complex solution in order to be compliant with the corporate standards.
I'm open to suggestions and challenges... but I think we can conclude that much of our accident complexity comes from not applying the best solution to the problem. I would expect that most teams would not do this deliberately. So the team is either 1) ignorant of the best option (which can be fixed through experience and training) or 2) it is forced upon them.
I will close with the following challenges and questions:
Next time you are looking at a software component... Ask yourself the following
1) Does it simplify the problem?
2) Is there a more simplified solution?
3) Is it testable and verifiable?
4) Does it add complexity upstream or downstream of the problem?
When evaluating solutions... try to put a value on the level of complexity. Here are some ideas:
1) If it moves code or configuration into a proprietary solution then increase its complexity score.
2) If it allows you to write less code for the same functionality then decrease its complexity score.
3) If it enhances testability, decrease its complexity score.
4) How easy is it to monitor and maintain?
5) How easy is it to integrate with and is it standards compliant?
Good luck and Happy Holidays!
Defining Software Architecture
I have been in a large number of conference BOFs this year. When the audience is slow in starting a conversation, the question we gravitate to is: "What is a Software Architect?" or its keen "What is Software Architecture?". I guess I shouldn't be surprised, but it is amazing how diverse the answers to these questions are. It is a reflection of at least two things... 1) the immaturity of our industry and /or 2) the lack of standardization in this space. The conversation spans from design decisions to application architecture to enterprise architecture.
Martin Fowler defines architecture as "things that people per-ceive as hard to change". This is a really responisble definition.
I like to define it as "making decisions on all the non-funcational requirements" and "managing all the things you can't control"
The area of non-functional requirements would include:
- User Experience
- Performance / Response Time
- Scalability
- Security
- Frameworks
- Complexity
- On public web: Number of Requests
- Number of Threads / Connections
- Number of returns from a user generated search
- Items in a batch
The subject that is rarely vocalized and debated in architecture is that of complexity. Neal Ford, in a couple of his talks with NFJS, talks about principles that were documented by anciet philosophers... that of essential and accidental properties. He carries this forward into software architecture in a way that we as an industry really need to talk about. That of software architecture decisions moving the enterprise forward in a way that has essential complexity or in a way that increases the accidental complexity. Neal further clarifies the point with the following comments... We have a hard problem (Essential complexity) and we have made our problem hard (Accidental complexity). Well done Neal! Very easy to envision.
Is complexity one of the non-functional requirements which your architecture team is looking at? If not, It seems likely that what is left is accidental.
What is a concrete example of this?
Let's say that your enterprise has just purchased a shiny new ESB. Suppose there wasn't a project need for it... it was just the stated SOA direction of your organization. When down from on high the edict is brought to your project that you must use the ESB in order to justify the $1M expense. Perhaps it is a fit... but perhaps you are about to fit the square peg in the round hole... in other words accidental complexity.
Where does Accidental Complexity come from?
Neal would say that it comes from vendors who are the pushers of accidental complexity... however there is something deeper here. The reason they are referred to as the pushers is that they are incented to sell you a solution. The solution may not fit your needs exactly, but hey, if they can show you a vision of how it could help, then there is a framework to following and life should be more simplified. So essentially we are saying that any choice which doesn't provide the best solution brings complexity.
We could also say that the more stuff / more solutions we have brings complexity. So by adding more frameworks and options we have added complexity. Conversely, many organizations fall into the trap of standardizing certain aspects of development... like everything is an EJB or we don't use store procedures here. In this situation what happens is that the architect and developers will have to come up with a more complex solution in order to be compliant with the corporate standards.
I'm open to suggestions and challenges... but I think we can conclude that much of our accident complexity comes from not applying the best solution to the problem. I would expect that most teams would not do this deliberately. So the team is either 1) ignorant of the best option (which can be fixed through experience and training) or 2) it is forced upon them.
I will close with the following challenges and questions:
Next time you are looking at a software component... Ask yourself the following
1) Does it simplify the problem?
2) Is there a more simplified solution?
3) Is it testable and verifiable?
4) Does it add complexity upstream or downstream of the problem?
When evaluating solutions... try to put a value on the level of complexity. Here are some ideas:
1) If it moves code or configuration into a proprietary solution then increase its complexity score.
2) If it allows you to write less code for the same functionality then decrease its complexity score.
3) If it enhances testability, decrease its complexity score.
4) How easy is it to monitor and maintain?
5) How easy is it to integrate with and is it standards compliant?
Good luck and Happy Holidays!
Thursday, November 13, 2008
Boulder / Denver JUG Talks
It seems I can't escape Denver. I was there last month at the JUG meeting. Matthew McCullough has some commentary on his blog. It seems Matt did a presentation on iPhone development this month. I will be speaking at NFJS this weekend in Denver. My topics include:
- Java Memory Management and GC
- Hacking - The Dark Arts
- Security Code Review
- Spring / JPA
- Spring 2.5 - Spring without XML
- Architecture and Scaling
- Java Memory Management and GC
- Hacking - The Dark Arts
- Security Code Review
- Spring / JPA
- Spring 2.5 - Spring without XML
- Architecture and Scaling
Subscribe to:
Posts (Atom)
