Sunday, February 10, 2008

Java 6 & AMD64

I've noticed that Java 6 update 4 for amd64 always crashes in arbitrary places (for instance, eclipse crashes compiling a class). Whenever you need to use Java 6 Update 4 on amd64 but it keeps crashing, use -Djava.compiler=none - to disable Java6's buggy JIT. In a case your requirements are not Java 6 you can use Java 5 update 14 on amd 64 for it looks stable.

Current thread (0x00002aab2d10e800): JavaThread "CompilerThread1" daemon [_thread_in_native, id=20462, stack(0x00000000406b2000,0x00000000407b3000)]

siginfo:si_signo=SIGSEGV: si_errno=0, si_code=1 (SEGV_MAPERR), si_addr=0x0000000000000000

Registers:
RAX=0x0000000000000000, RBX=0x00002aab311cc4d8, RCX=0x00002aab3137e9b0, RDX=0x0000000000000046
RSP=0x00000000407aee70, RBP=0x00000000407aeee0, RSI=0x00002aab3137e9b0, RDI=0x00002aab311cc4d8
R8 =0x00002aab3137ea08, R9 =0x00002aab3137e9b0, R10=0x00002aab3137e9b0, R11=0x0000000000000000
R12=0x00002aab311cc4a0, R13=0x0000000000000000, R14=0x00002aab2cd3b870, R15=0x0000000000000001
RIP=0x00002b5f70ae122a, EFL=0x0000000000010246, CSGSFS=0x0000000000000033, ERR=0x0000000000000004
TRAPNO=0x000000000000000e

Top of Stack: (sp=0x00000000407aee70)
0x00000000407aee70: 00002aab30548b88 00000001ffffffff
0x00000000407aee80: 00002aab3137e9b0 0000000270a85331
0x00000000407aee90: 00002aab30548b80 00000007407afaa0
0x00000000407aeea0: 00000000407afb68 01000000000004a7
0x00000000407aeeb0: 00000000407afaa0 00002b5f7112a4f0
0x00000000407aeec0: 00000000407afaa0 00000000407af030
0x00000000407aeed0: 00000000407aeff0 00000000407aefc0
0x00000000407aeee0: 00000000407af100 00002b5f70ae076c
0x00000000407aeef0: 00000000407afb68 00000000407af0b0
0x00000000407aef00: 00002aab330b0fb0 00002aab30000020
0x00000000407aef10: 00000000407aef80 00002b5f711438d0
0x00000000407aef20: 00002aab307d8a20 0000000000000151
0x00000000407aef30: 00000000407afbc0 00002b5f70608bbc
0x00000000407aef40: 00000000407b2950 00000000407aef80
0x00000000407aef50: 00002b5f71146040 00002aab3100b990
0x00000000407aef60: 0000000000000151 00002b5f70f1a9d2
0x00000000407aef70: 0000000040110b90 00002b5f70f1aaa1
0x00000000407aef80: 00000000407b2950 00000000407aefc0
0x00000000407aef90: 00002b5f71146040 0000000000007fe8
0x00000000407aefa0: 00002aab307f5d10 00002b5f70f1a9d2
0x00000000407aefb0: 0000000040110b90 00002b5f70f1aaa1
0x00000000407aefc0: 00002b5f7112a4f0 00002b5f0000000e
0x00000000407aefd0: 00000000407b1450 00000000407afaa0
0x00000000407aefe0: 00000000000008c8 00002aab2d10ec70
0x00000000407aeff0: 000000000000000d 00000000407b1450
0x00000000407af000: 00002aab32c78490 00002b5f70a84d00
0x00000000407af010: 00002aab311bd4b0 00000000000004a8
0x00000000407af020: 00000000407af0b0 00002aab332443e0
0x00000000407af030: 000000000000000c 00000000407b1450
0x00000000407af040: 00002aab3178f090 00002aab31ce1aa0
0x00000000407af050: 00002aab3184eb70 00002aab3184f6b0
0x00000000407af060: 00002aab330c8c60 00000000407afbc0

Instructions: (pc=0x00002b5f70ae122a)
0x00002b5f70ae121a: 48 89 cf 41 ff 95 80 00 00 00 48 89 df 49 89 c5
0x00002b5f70ae122a: 8b 00 41 21 44 24 38 41 8b 45 04 21 43 04 41 8b
Stack: [0x00000000406b2000,0x00000000407b3000], sp=0x00000000407aee70, free space=1011k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
V [libjvm.so+0x1f122a]
V [libjvm.so+0x1f076c]
V [libjvm.so+0x244525]
V [libjvm.so+0x241035]
V [libjvm.so+0x1e05c7]
V [libjvm.so+0x248ec8]
V [libjvm.so+0x248866]
V [libjvm.so+0x62a3f9]
V [libjvm.so+0x6246a1]
V [libjvm.so+0x505eea]


Current CompileTask:
C2:581 org.eclipse.core.internal.dtree.DataTreeNode.forwardDeltaWith([Lorg/eclipse/core/internal/dtree/AbstractDataTreeNode;[Lorg/eclipse/core/internal/dtree/AbstractDataTreeNode;Lorg/eclipse/core/internal/dtree/IComparator;)[Lorg/eclipse/core/internal/dtree/AbstractDataTreeNode; (469 bytes)

Saturday, February 2, 2008

Debian + Eclipse + Java + AMD64

This is for those who use debian on amd64 with java from package . If you have a problem running eclipse (exit code=13 or alike) just install sun's java and enjoy! There is a something wrong with the java package in debian (sun-java6-*). I've spent two days trying get it to work.

Monday, October 8, 2007

Interesting Design Principle

Design for extension. I think it's rare case when you need to override methods without being afraid to break something.

P.S. Eclipse project leverages this principle all over the sources.

Wednesday, September 19, 2007

Web programming

It is not as bad as I thought. I am even starting to get pleasure from using dojo (ajax framework) and firebug (plugin for firefox).

Update: Only thing disappointing me is a lack of javascript support in eclipse.

Monday, August 20, 2007

Portlets and AJAX: ZK, GWT, DOJO

I've tried to leverage ZK in a portal environment. Yes, it's possible, but there can be only one ZK portlet within portal's page becouse ZK uses global javascript variables. So it's sux. Anyway, don't try to use DhtmlPortlet otherwise you will end up with exception from tomcat telling about SRV spec violations. Instead, just include zk page from your custom portlet class.

The same is about GWT. It's pain to build a GWT project with maven. GWT plugin for maven looks immature and abandoned. The idea behind GWT is very hackish.

DOJO is a lowlevel set of javascript functions. That makes possible to implement custom widgets suitable for portal environment. Besides, there is DIJIT widgets collection built on top of DOJO. Injection of dijit css styles to portat theme is required to start using DIJIT widgets. Lack of real documentation for DOJO/DIJIT is the only thing really disappointing.

Sunday, August 5, 2007

SpringMeasure 1.0

I don't understand how I've ever been without Spring framework. It is so tasty. I will use it whenever I can. Do you think a step from EJB 2.1 to EJB 3.0 is a revolution? Then step from EJB 3.0 to Spring 2.0 is a revolution no less: flexible IoC, nasty testing out of box, standalone or web or whatever execution, annotations, if you prefer your app knows nothing about spring (no direct dependencies on spring classes) and so on. But that is not an issue of this post. As an example of spring ideas I am going to show you how spring can be easily extended for your needs. In my case I wanted to use measured values right in a bean property definition. I.e. instead of using a value 120013 calculated behind the scene (60*2*1000 + 13) I wanted a human suitable representation like a "2min 13ms". And to achive it I've created a small project.

Download the archive.
Uncompress it.
Do mvn install from command line inside the archive's folder.

Now you can use springmeasure as the dependency in your own project (artifactId: springmeasure, groupId: ru.toril.springmeasure, verision: 1.0).

In your application context xml add the following line:
<bean class="ru.toril.springmeasure.MeasureConfigurer" />

From now you can write following (as an example):

<bean class="some class you want"
p:value1="{${test.length}}m"
p:value2="{4GiB 200MiB}MiB"
p:value3="{400ms}s." />

The property value1 is configured with PropertyPlaceholderConfigurer in addition to MeasureConfigurer, whereas test.length property is set to "8km".

As you already noticed springmeasure is written to support symbols of Si. A format of value is as following:

{sequence of space-separated values with symbol suffix joined to value}outputSymbol

An output symbol may be followed by the dot marking that an output value is not to be rounded.
You may find out more about format looking at the following test lines:

// IT symbols (bits, bytes)
assertEquals ("2048", convert ("{2KiB}B"));
assertEquals ("16384", convert ("{2KiB}b"));
assertEquals ("11", convert ("{1B 3b}b"));
assertEquals ("10000000", convert ("{ 10MB }B"));
assertEquals ("500", convert ("{ 0.5kB }B"));
assertEquals ("2", convert (" { 2048B 100B 3b }KiB "));
assertEquals ("2.098", convert (" { 2048B 100B 3b }KiB. ").substring (0, 5));

// Time (minutes, seconds, hours, days)
assertEquals ("600", convert ("{10min}s"));
assertEquals ("615", convert ("{10min 15s}s"));
assertEquals ("615000", convert ("{10min 15s}ms"));
assertEquals ("615001000000003", convert ("{10min 15s 1ms 3ps}ps"));
assertEquals ("70", convert ("{1h 10min}min"));

// Length (meters)
assertEquals ("0.5", convert ("{5mm}cm."));
assertEquals ("2", convert ("{2000mm}m"));

// Any other Si value
assertEquals ("0.5", convert ("{5m*}c*."));
assertEquals ("2", convert ("{2000m*}*"));

Here is a real life usage examples:

<bean id="monitorTask" class="org.springframework.scheduling.timer.ScheduledTimerTask"
p:period="{30s}ms" ... />

<bean id="monitor"
class="ru.toril.....model.Monitor"
p:maxAllowedIdle="{2h}ms"
p:maxAllowedSize="{2MiB}B"
p:minFreeSize="{2GiB}B"
p:maxSleepTime="{1min}ms" ... />

Saturday, August 4, 2007

Wow

JBoss 4.2.1 uses 120M of memory running on Java 5, while only 91M on Java 6. Only what I can guess is that Java 6 leverages some new memory page allocation strategy or may be I just wrong and there is something completely different :).

Also it means I've replaced Sun Application Server 9 (based on glassfish) with jboss, becouse Sun AS has been eating twice as more memory than JBOSS 4.2.1 and I've read that Sun Portal requires 2 GB of memory to run and a lot of dependencies!