Friday Jan 16, 2009

Getting PermGen information using jmap

The permanent generation is the area of heap that holds all the reflective data of the virtual machine
itself, such as class and method objects.
Configuring the size of the permanent generation can be important for applications that dynamically
generate and load a very large number of classes. If an application loads “too many” classes then it is possible it will abort with an OutOfMemoryError.
The specific error will look like :
“Exception in thread XXXX java.lang.OutOfMemoryError: PermGen space”

In 1 terminal start an application.
I am just using the jfc Notepad application here, since it is pretty passive and doesn't interfere with the screen while I am trying to write this.

bash-3.00$ ./java -jar ../demo/jfc/Notepad/Notepad.jar

Get the pid in this case 2239
bash-3.00$ ./jps
3131 Jps
2239 Notepad.jar
22305
10792 Main

Now in another terminal try running this

bash-3.00$ ./jmap -permstat 2239
Attaching to process ID 2239, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 14.0-b10
finding class loader instances ..Finding object size using Printezis bits and skipping over...
Finding object size using Printezis bits and skipping over...
Finding object size using Printezis bits and skipping over...
done.
computing per loader stat ..done.
please wait.. computing liveness.....done.

class_loader    classes bytes   parent_loader   alive?  type

<bootstrap> 1596 7131080 null live <internal>
0xe6e91088 1 1152 null dead sun/reflect/DelegatingClassLoader@0xb7847 8d0
0xe65142c8 6 17968 0xe6424958 dead sun/reflect/misc/MethodUtil@0xb7d67248
0xe6426528 0 0 0xe6424958 live java/util/ResourceBundle$RBClassLoader@0x b796ec78
0xe6e8a128 1 1152 null dead sun/reflect/DelegatingClassLoader@0xb7847 8d0
0xe656d8a0 1 1184 0xe65142c8 dead sun/reflect/DelegatingClassLoader@0xb7847 8d0
0xe693cd20 1 1792 null dead sun/reflect/DelegatingClassLoader@0xb7847 8d0
0xe641e710 1 8080 null live sun/misc/Launcher$ExtClassLoader@0xb79214 78
0xe6e8ee40 1 1152 null dead sun/reflect/DelegatingClassLoader@0xb7847 8d0
0xe6555668 1 1752 null dead sun/reflect/DelegatingClassLoader@0xb7847 8d0
0xe6e8cd78 1 1768 null dead sun/reflect/DelegatingClassLoader@0xb7847 8d0
0xe6424958 87 810144 0xe641e710 live sun/misc/Launcher$AppClassLoader@0xb7964f d0

total = 12 1697 7977224 N/A alive=4, dead=8 N/A


Typically, we get the output in this form.
For each class loader object, the following details are printed:
1. The address of the class loader object – at the snapshot when the utility was run.
2. The number of classes loaded (defined by this loader with the method(java.lang.ClassLoader.defineClass).
3. The approximate number of bytes consumed by meta-data for all classes loaded by this class loader.
4. The address of the parent class loader (if any).
5. A “live” or “dead” indication – indicates whether the loader object will be garbage collected in the future.
6. The class name of this class loader.

Tuesday Dec 09, 2008

Java FX is out - javafx.com

Java FX was officially released last week.
The response has been huge in terms of numbers, leaving aside whether it was positive or negative.

I haven't been exploring Java FX much until recently. Of course it has been talked about since Java One 2007 and was also Sun's focus in 2008 J1.

However, now that it is stable, I did give it a try.
My first reaction was a positive one, although I would be the first to agree that there is whole bunch of things that needs improvement. Speed being a major concern, apart from certain other requirements that developers have suggested or criticized for not being included in it already.

A small sample that me and Vaibhav tried is here.
Of course, I did some work on this with Vaibhav that's why I am linking to it.

Wednesday Jun 11, 2008

Jar changes in jdk6

Consider 3 java files in the package pack1.


public class Main {

public static void main(String[] args) {
System.out.println("Main in Main.java");
}
}
public class Main2 {
public static void main(String[] args) {
System.out.println("Main in Main2.java");
}
}
public class Main3 {
public static void main(String[] args) {
System.out.println("Main in Main3.java");
}
}

Compiling all of them gives us the 3 files in the folder pack1.
Main.class Main2.class Main3.class

Now,
bash$jar cvfe main.jar pack1.Main2 pack1
added manifest
adding: pack1/(in = 0) (out= 0)(stored 0%)
adding: pack1/Main.class(in = 533) (out= 329)(deflated 38%)
adding: pack1/Main2.class(in = 537) (out= 331)(deflated 38%)
adding: pack1/Main3.class(in = 537) (out= 332)(deflated 38%)

bash$java -jar main.jar
Main in Main2.java

1 more run for the files without any recompilation or source change
bash$jar cvfe main.jar pack1.Main3 pack1
added manifest
adding: pack1/(in = 0) (out= 0)(stored 0%)
adding: pack1/Main.class(in = 533) (out= 329)(deflated 38%)
adding: pack1/Main2.class(in = 537) (out= 331)(deflated 38%)
adding: pack1/Main3.class(in = 537) (out= 332)(deflated 38%)

bash$java -jar main.jar
Main in Main3.java

Specifying the -e argument to the jar command we can specify which entry point we want in the jar file when running as the standalone application.
This has been added on in JDK 6 onwards.

Also, the timestamps of extracted files are those listed in the archive, instead of the time of extraction.
Eg for the same.
The current time is: 15:54:00.89
And the files information is
06/11/2008 03:46p 533 Main.class
06/11/2008 03:46p 537 Main2.class
06/11/2008 03:46p 537 Main3.class
The file information is the one when I created the class files.

Thursday Apr 03, 2008

Some 'javac' and 'java' options

Normally we use plain javac to compile all java files.

In this I will try to elicit some of the useful options associated with javac.
A normal compilation puts the class files in the same directory as the java files.

project1
|
|--------src
|        |
|        |----Class1.java
|
|--------classes

This seems to be a better structure for the same.
bash$pwd
/project1
bash$javac -d classes src/Class1.java
This will put the class file in the classes directory.
Also, 1 important point is that this command will take care of the package structure automatically.
The last thing about this is that if the classes directory didn't exist we will get a compiler error.
src/Class1.java:1: error while writing Class1: classes/Class1.class (No such file or directory)
public class Class1{
\^
1 error

Running with java
bash$java -cp classes Class1
Hello World

We are all familiar with this run.

Consider this.
bash$java -Dmyprop=myValue -cp classes Class1
Hello World

It still gives the same output. What's the difference?
To state in 1 line -D switch creates a system property with the name myprop and assigns the value myValue to it.
This is useful in running a single app over multiple environments with a little customized start up script.
In case you don't know system properties.
Run this
bash-3.00$ cat src/TestProps.java
import java.util.\*;
public class TestProps {
public static void main(String[] args) {
Properties p = System.getProperties();
p.list(System.out);
}
}

bash-3.00$ java -cp classes/ TestProps
-- listing properties --
java.runtime.name=Java(TM) 2 Runtime Environment, Stand...
sun.boot.library.path=/usr/jdk/instances/jdk1.5.0/jre/lib/s...
java.vm.version=1.5.0_14-b03
java.vm.vendor=Sun Microsystems Inc.
java.vendor.url=http://java.sun.com/
path.separator=:
java.vm.name=Java HotSpot(TM) Server VM
file.encoding.pkg=sun.io
sun.java.launcher=SUN_STANDARD
sun.os.patch.level=unknown
java.vm.specification.name=Java Virtual Machine Specification
user.dir=/net/jpsesvr/space2/jpse/vikram/files...
java.runtime.version=1.5.0_14-b03
java.awt.graphicsenv=sun.awt.X11GraphicsEnvironment
java.endorsed.dirs=/usr/jdk/instances/jdk1.5.0/jre/lib/e...
os.arch=sparc
java.io.tmpdir=/var/tmp/
line.separator=

java.vm.specification.vendor=Sun Microsystems Inc.
os.name=SunOS
myProp=myValue
sun.jnu.encoding=ISO646-US
java.library.path=/usr/jdk/instances/jdk1.5.0/jre/lib/s...
java.specification.name=Java Platform API Specification
java.class.version=49.0
sun.management.compiler=HotSpot Server Compiler
os.version=5.10
user.home=/home/va203678
user.timezone=
java.awt.printerjob=sun.print.PSPrinterJob
file.encoding=ISO646-US
java.specification.version=1.5
user.name=va203678
java.class.path=classes/
java.vm.specification.version=1.0
sun.arch.data.model=32
java.home=/usr/jdk/instances/jdk1.5.0/jre
java.specification.vendor=Sun Microsystems Inc.
user.language=en
java.vm.info=mixed mode
java.version=1.5.0_14
java.ext.dirs=/usr/jdk/instances/jdk1.5.0/jre/lib/ext
sun.boot.class.path=/usr/jdk/instances/jdk1.5.0/jre/lib/r...
java.vendor=Sun Microsystems Inc.
file.separator=/
java.vendor.url.bug=http://java.sun.com/cgi-bin/bugreport...
sun.cpu.endian=big
sun.io.unicode.encoding=UnicodeBig
sun.desktop=gnome
sun.cpu.isalist=sparcv9 sparcv8plus sparcv8 sparcv8-f...

Tuesday Apr 01, 2008

serialver or serialver.exe

In the ${JAVA_HOME}/bin/ folder there is a executable file serialver.

What does this file do?
This file is used to find out whether a class is Serializable or not.

Just use it like a normal java <classname>.

Look at the sample code below.
Obviously the same thing works on any other OS.

bash$pwd
/Java/jdk1.6.0_10/bin

bash$cat Class1.java

public class Class1 {

}

bash$cat Class2.java
import java.io.\*;
public class Class2 implements Serializable{

}

bash$serialver Class1
Class Class1 is not Serializable.

bash$serialver Class2
Class2: static final long serialVersionUID = 8006342768338701979L;

Thursday Feb 21, 2008

Mercurial Basics

Open JDK moved to mercurial based repository system recently.

There is a lot of discussion going about it.

There are many open source projects that have recently migrated to Mercurial.
Sun sponsored projects are Open JDK, Open Solaris.

I made a small presentation for the basics of Mercurial that I shared across my team.

Here is the Presentation

Drop me a mail/comment if you use it.

Tuesday Feb 19, 2008

Blog addition 1

I edited my blog template today.

To see the changes, look at the "My Blog Extras" section on the right hand side.
This is not originally present in the theme

The code for the same was as follows

<!-- Vikram start changes-->
<div class="navcol">
<div class="innernavcol">
<div class="about navsect">
<div class="navhead">
<h2>Get Java</h2>
</div>
<div class="navbody">

Content

</div>
</div>
</div>
</div>

<!--Vikram End Changes-->



These changes are applicable on the Sun blogging site only.
And that is if you have based your custom template on the Sun Pacifico theme.

Tuesday Feb 12, 2008

When I met Martin Fowler

Last Saturday on 09 Feb 2008.

I had been to attend Devcamp 2008 with one of my senior friends who personally knows many famous people.

With him, I had a good opportunity to meet Martin Fowler.
A very tall person he had a great down to earth attitude like all the greats.

About

I am Vikram Aroskar working in the Java team based out of India.

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today