Wednesday, February 17, 2010

Java Hotspot JVM crashes in Windows/Solaris-SPARC: libjvm.so GenCollectForAllocation SIGSEGV UseAdaptiveSizePolicy UseConcMarkSweepGC

Yesterday it seemed I encounter a bug in the new garbage collector of Hotspot JVM version 14+. Basically the application crashed during the startup, the platform was solaris 9 and windows 2003 r2.

The hs_err_pid reported to us:
#  SIGSEGV (0xb) at pc=0xfe847fc0, pid=9196, tid=6
#
# JRE version: 6.0_18-b07
# Java VM: Java HotSpot(TM) Server VM (16.0-b13 mixed mode solaris-sparc )
# Problematic frame:
# V [libjvm.so+0x447fc0]
#
# If you would like to submit a bug report, please visit:
# http://java.sun.com/webapps/bugreport/crash.jsp
#

--------------- T H R E A D ---------------

Current thread (0x00125400): VMThread [stack: 0xd7980000,0xd7a00000] [id=6]

siginfo:si_signo=SIGSEGV: si_errno=0, si_code=2 (SEGV_ACCERR), si_addr=0xfbe88fc6

Registers:
O0=0x0006ffe8 O1=0xf8616088 O2=0x00000000 O3=0x00000000
O4=0x00000000 O5=0x00000000 O6=0xd79ff108 O7=0x00000000
G1=0xfee56000 G2=0xfee39800 G3=0xf7c2c258 G4=0xd79ff5b0
G5=0xd9c00000 G6=0x00000000 G7=0xff330a00 Y=0x00000000
PC=0xfe847fc0 nPC=0xfe847fc4


Top of Stack: (sp=0xd79ff108)
0xd79ff108: fe7f7fcc fee2622c d7c00000 000361d8
0xd79ff118: fee3d000 fbc00000 24000000 09000000
0xd79ff128: d79ff59c fb7c2000 006c6fc6 00000011
0xd79ff138: 00038d98 00034d08 d79ff168 feb66578
0xd79ff148: 00000000 00000000 00000000 00000000
0xd79ff158: 00000000 00000009 d9c11abb 00000000
0xd79ff168: fee39ac4 fee560c8 00122260 00000008
0xd79ff178: 00000032 00000033 d8df8dd4 d8dcf9d8

Instructions: (pc=0xfe847fc0)
0xfe847fb0: fa 06 20 10 b6 10 20 11 f8 07 60 08 f2 07 20 4c
0xfe847fc0: f6 2e 40 1a 81 c7 e0 08 81 e8 20 00 9d e3 bf a0

Stack: [0xd7980000,0xd7a00000], sp=0xd79ff108, free space=1fcfe847fc0k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
V [libjvm.so+0x447fc0]
V [libjvm.so+0x766580]
V [libjvm.so+0x766dc8]
V [libjvm.so+0x765b5c]
V [libjvm.so+0x73b1a0]
V [libjvm.so+0x4b8048]
V [libjvm.so+0x3ff9b0]
V [libjvm.so+0x84cb38]
V [libjvm.so+0x1e002c]
V [libjvm.so+0x84f7bc]
V [libjvm.so+0x84fd54]
V [libjvm.so+0x25f7e0]
V [libjvm.so+0x728448]

VM_Operation (0xd5b3bf2c): GenCollectForAllocation, mode: safepoint, requested by thread 0x006e3c00
...
VM Arguments:
jvm_args: -ea -Djava.io.tmpdir=tmp -Dcom.sun.management.jmxremote -Xss256k -XX:+UseAdaptiveSizePolicy -XX:+UseConcMarkSweepGC -Djava.awt.headless=true -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 ...
...
Signal Handlers:
SIGSEGV: [libjvm.so+0x84c6bc], sa_mask[0]=0x7fbffeff, sa_flags=0x0000000c
SIGBUS: [libjvm.so+0x84c6bc], sa_mask[0]=0x7fbffeff, sa_flags=0x0000000c
SIGFPE: [libjvm.so+0x1c0168], sa_mask[0]=0x7fbffeff, sa_flags=0x0000000c
SIGPIPE: [libjvm.so+0x1c0168], sa_mask[0]=0x7fbffeff, sa_flags=0x0000000c
SIGXFSZ: [libjvm.so+0x1c0168], sa_mask[0]=0x7fbffeff, sa_flags=0x0000000c
SIGILL: [libjvm.so+0x1c0168], sa_mask[0]=0x7fbffeff, sa_flags=0x0000000c
SIGUSR1: SIG_DFL, sa_mask[0]=0x00000000, sa_flags=0x00000000
SIGUSR2: SIG_DFL, sa_mask[0]=0x00000000, sa_flags=0x00000000
SIGQUIT: [libjvm.so+0x72abdc], sa_mask[0]=0x7fbffeff, sa_flags=0x00000004
SIGHUP: [libwrapper-solaris-sparc-32.so+0x23b8], sa_mask[0]=0x00000000, sa_flags=0x00000012
SIGINT: [libwrapper-solaris-sparc-32.so+0x2378], sa_mask[0]=0x00000000, sa_flags=0x00000012
SIGTERM: [libwrapper-solaris-sparc-32.so+0x2398], sa_mask[0]=0x00000000, sa_flags=0x00000012
SIG39: [libjvm.so+0x72e608], sa_mask[0]=0x00000000, sa_flags=0x00000008
SIG40: [libjvm.so+0x1c0168], sa_mask[0]=0x7fbffeff, sa_flags=0x0000000c


--------------- S Y S T E M ---------------

OS: Solaris 9 9/04 s9s_u7wos_09 SPARC
Copyright 2004 Sun Microsystems, Inc. All Rights Reserved.
Use is subject to license terms.
Assembled 29 June 2004

uname:SunOS 5.9 Generic_117171-07 sun4u (T2 libthread)
rlimit: STACK 8192k, CORE infinity, NOFILE 4096, AS infinity
load average:1.08 0.42 0.26

CPU:total 2 has_v8, has_v9, has_vis1, has_vis2, is_ultra3

Memory: 8k page, physical 2097152k(1453840k free)

vm_info: Java HotSpot(TM) Server VM (16.0-b13) for solaris-sparc JRE (1.6.0_18-b07), built on Dec 17 2009 14:12:56 by "" with Workshop 5.8

time: Tue Feb 16 10:42:22 2010
elapsed time: 7 seconds


I have googled a lot of pages and no luck. I thought it's related to whether my solaris was not updated enough. My HelloWorld can be run without any problem as well. Therefore, I was thinking maybe it's related to the garbage collector somehow due to the word "collect" in GenCollectForAllocation.

From the vm arguments above, you could see it's using -XX:+UseAdaptiveSizePolicy and actually this argument should be an no-op according to here. Once I removed it, everything works fine now.

So, maybe there is a bug in having UseAdaptiveSizePolicy and UseConcMarkSweepGC crashing the windows/solaris latest hotspot JVMs.

Tuesday, February 09, 2010

GWT: java.lang.UnsatisfiedLinkError: com.google.gwt.user.client.Random.nextDouble()

Just started learning GWT, and running through the tutorials. The first error I encountered is java.lang.UnsatisfiedLinkError: com.google.gwt.user.client.Random.nextDouble() when running the example. The reason is listed here and here. The reason I posted this blog entry is that, searching the exact string of my title in google yielded nothing. The reason may be that people had problems in nextInt more often.

Monday, December 28, 2009

Friday, December 18, 2009

C input routine for single character and string

By answering some beginner questions in the programming forum, I am trying to learn some C/C++ again. As a matter of course, I learned something new as always, this is a page I referred to when trying to clear the buffer in stdin.

The first example is for capturing single character and check if it is a number between 1 and 4:

char option;
int number;
do {
puts("Please enter your choice:");
fflush(stdout);
if (fgets(&option, 2, stdin) != NULL) {
if (option != '\n') {
scanf("%*[^\n]"); // get rid of the non-newline characters
scanf("%*c"); // get rid of the newline character
}
}
} while (!(sscanf(&option, "%d", &number) == 1 &&
number >= 1 && number <= 4));


The 2nd example is for capturing a string with trimming, overflow protection and emptyness checking:


char fileStr[20];
char *pointer = fileStr;
bool tooLong = false;

do {
printf("\nPlease input a file name: ");
fflush(stdout);
if (fgets(fileStr, sizeof fileStr, stdin) != NULL) {
tooLong = false;
if (*fileStr != '\n') {
// search for newline character
char *newline = strchr(fileStr, '\n');
if (newline != NULL) {
*newline = '\0'; /* overwrite trailing newline */
pointer = trimwhitespace(pointer); /* trim the line */
} else {
/* clear the stdin since user input too much */
tooLong = true;
scanf("%*[^\n]");
scanf("%*c");
}
}
}
} while (tooLong || *pointer == '\0' || *pointer == '\n');

printf("file name = \"%s\"\n", pointer);


Pay special attention on the variable you are gonna use at last, it is "pointer".

Tuesday, December 08, 2009

Birt and java.lang.NoClassDefFoundError: org/w3c/tidy/Tidy Tidy.jar

Lately I have been debugging a customer issue with our birt integration. The exception message is java.lang.NoClassDefFoundError: org/w3c/tidy/Tidy. We have found a lot of posts in google with this error.

Most of the google results and this one are related to the file/folder permission, and the location of the jars in tomcat/websphere. Our integration is not involved with any webapp container, and we double check few times the file/folder permission is okay.

And then, I know that lsof can show what jars the java process has linked. That shows all the jars are marked as "deleted". That is a big hint to me. Something is wrong with the java process and this time, we found that, the same java process had been launched twice. This is a good lsof tutorial btw.

Friday, December 04, 2009

Javascript window.event.keyCode in firefox

This is usually used for capturing the ENTER key pressed in the html text box:
function onkeypressed(e) {
var keyCode = (window.event) ? window.event.keyCode : e.which;
if (keyCode == 13) {
// do something
return true;
} else {
return false;
}
}

Monday, November 02, 2009

Use regular expression to extract / parse a string into a collection of matched results recursively

Helped a person in doing an assignment and almost forgot a routine that I love in parsing a string into an ArrayList of matched results with a regular expression. Here it is:

Pattern p = Pattern.compile(...);
Matcher m = p.matcher(inputString);
List l = new ArrayList();
for (int i = 0; m.find(i); i = m.end()) {
l.add(m.group(index)); // depends on your regular expression grouping
}

Thursday, October 01, 2009

PHP 5.2.10 session ID (sessionId) in URL problem in Solaris (all ZEROes 0000 as the year of the set-cookies)

Wow, I have actually spent 4 hours in looking into what's wrong with this session ID in url problem in a solaris box.

My journey started as turning on all the php log, no luck, nothing in error.log when the problem happened.

Then, I went to play around with all the 0/1 settings in session.* (actually use_only_cookies, use_trans_sid), no luck either.

And then, I went to compare a working windows setup with this solaris setup in php_info()... nothing special there.

I was starting to believe there was something wrong with the cookie, so I tried to use php to setCookie with a timeout. Using the firefox, I found out, the cookie from the solaris apache was not obtained in firefox. Therefore, I started to search google for "apache cookie" and NO, I wasted another hour.

Hmm it seems cookie is actually set in header. Then I used "curl -i" to dump the solaris header, and finally noticed the difference. The year of the expiration date is ALL ZEROes. Confirmed with a cookie WITHOUT timeout, the cookie started to appear in firefox for windows and solaris apache/php.

Googled some more and finally got the correct query: "set-cookie solaris 0000 year", the first result is the answer. Wow, I almost gave up on the way... Created this post for more google result matches.

Thursday, September 24, 2009

Two links for future reference - Spring & inner class and access target from proxy in aop

First link is here, you can create a bean with inner class with a constructor back to the parent class bean or you will get an exception something like no default constructor.

Second link is here, it is basic I know, just something I will most likely forget in the future if I need this again.

Scala 2.8 scala.io.Source throws java.nio.charset.UnmappableCharacterException at an unmappable sequence of bytes by default

Using scala 2.8 to grab a webpage encoded in big5, Source.fromURL throws UnmappableCharacterException at a chinese character (in bytes) that cannot be mapped to the unicode character. The default behavior of the scala Codec is to report this exception.

From reading the Codec source, you could see that Codec is actually composed of java.nio.charset.CharsetDecoder. From reading the javadoc, there is a caller method onUnmappableCharacter, and there should be 3 different CodingErrorAction that you can choose.

In scala.io.Codec source:

def onUnmappableCharacter(newAction: Action): this.type = { _onUnmappableCharacter = newAction ; this }

So that's easy enough,

import java.nio.charset.CodingErrorAction.REPLACE
implicit def codec = Codec("big5").onUnmappableCharacter(REPLACE)
scala.io.Source.fromURL(...) // a big5 encoded page with unmappable

Then everything should go quietly without any error since the unmappable sequence will be replaced by the default value.