Saturday 21 March 2009

Friday 20 March 2009

java.lang.OutOfMemoryError

Applications may sometimes terminate with java.lang.OutOfMemoryError. The error is thrown when there is insufficient space to allocate an object.

Why do I get this exception?

First, you must inspect the FULL error message: what comes after the java.lang.OutOfMemory error?

* example 1: Java heap space. Two possibilities here. Perhaps the specified heap size is insufficient for the application...in which case bump up the heap size using the -Xmx option. The alternative possibility is a problem in garbage collection e.g. objects that are no longer needed cannot be garbage collected because the application is unintentionally holding references to them. A common source of this error can be excessive use of finalizers such that the thread to invoke the finalizers cannot keep up with the rate of addition of finalizers to the queue. jconsole can monitor the number of objects pending finalization.

* example 2: Java PermGen space. "PermGen space" indicates the permanent generation is full. This is the area of the heap where the JVM stores its metadata. If an application loads a large number of classes the permanent generation may need to be increased (i.e. -XX:MaxPermSize=n, where n is the size).

* example 3: Requested array size exceeds VM limit. e.g. if max heap size is 256MB (2^8), an you try to allocate an array of 512MB (2^9 i.e. double the size) then you get the "array size exceeds VM limit" problem.

To diagnose OutOfMemoryErrors best tools to use are Heap Analysis Tool (HAT), jconsole management tool and the jmap tool with -histo option.

Saturday 7 March 2009

Multi-Language Java: Welcome to "Il Mondo Java"

The Internet is a huge resource for Java programming in multiple languages. Here's a primer on getting the hang of these resources.

Italian Java Phrases:

Sviluppatore - Developer
SO - Italian for "Operating System" (Sistema operativo)
Genere - software genre (e.g. Matematica, Sistemi operativi, emulazione, videoconferenza, compilatori, crittografia/crittazione)
Licenza - license (e.g. Gratis, BSD)
Il mondo Java - java world.
aggiungere e rimuovere - add and remove (e.g. plug-ins, add-ins)
estensioni - extensions
ambiente Java - Java environment
un computer potente - powerful computer
interfacce grafiche - GUI

Wednesday 4 March 2009

Dalla GreenThreads al NativeThreads

Does it make sense to talk about the Java threading model? Java, is of course, a naturally multi-threaded languages, but the threading model is mandated NOT by the spec but by the VM implementation, surely? In particular, what is the relationship between the Solaris threading model and the Java threading model?

threadingmodel( _Java, 1.1, GreenThreads). ? GreenThreads = simulatedThreadsInVm.
threadingmodel( _Java, 1.2, NativeThreads).

advantage( GreenThreads, _Linux, time(X), reason(Y)). ? X = earlyDaysOfJava, Y = saveCost(Z), Z=spawn(A, B), A=process, B=nativeThread.

threadingmodel( _solaris, X). ? X = manytomany, X = onetoone.
alias( manytomany, (_LWP|boundthread) ), alias( onetoone, _SolarisThreads ).
has_a( _LWP, kernelthread ). schedule(kernel, task(X)) :- on_a( X, _LWP ).
too_few(LWP) :- starvation(X), thread(X).


Sun's JVM also maps 1:1 to Windows threads (not multiple processes or fibers).