[kaffe] OutOfMemoryError
Dalibor Topic
robilad@yahoo.com
Sun, 11 Aug 2002 15:11:25 -0700 (PDT)
Hallo Arne,
--- Arne Woerner <woerner@mediabase-gmbh.de> wrote:
> I would like to use Kaffe in a productive
> high-availability environment.
Cool.
> I wrote the java application listed in appendix SRC.
> Then I executed it using
> the commands listed in appendix SH. Then I got the
> output in appendix RT1/RT2
> and a file Kaffe.core (size: 268018180 bytes in the
> case of SH1). By the way:
> The Kaffe performance gets rather bad (4% cpu
> utilization, 96% of time blocked
> due to swapping) after the datasize increases to
> 200% of the physical memory
> on my machine...
You said that it doesn't work at all with other VMs,
so that's at least something ;)
> It does not look so gracefully... I wish that I
> could catch an
> OutOfMemoryError Throwable and do something
> appropriate (I mean in a real
> world application).
Well, I just tried it with latest version form CVS,
and it terminates the way you described it. So what's
really happening?
When you get an OutOfMemoryError the VM is trying to
tell you that it has really run out of memory, and all
the sophisticated garbage collection didn't help to
allocate more space. Try configuring kaffe with
--enable-debug, recompiling, and running with -vmdebug
ELOOKUP, then you should see that it finds a handler
and the exception is handled.
But just because you caught the exception, you don't
get extra memory ;) So if you want to handle the
situation yourself, you have to take great care in
your memory cleanup code not to allocate any
additional memory. That's really hard, as you have
seen. Trying to print out messages is a no-no (at
least with kaffe's current implementation), as that
action leads to a series of new objects being created.
Take a look at this call-trace created by running
kaffe with -verbosecall for a
System.out.println(String):
soft_trace:
java/io/PrintStream.println(Ljava/lang/String;)V
soft_trace:
java/io/PrintStream.print(Ljava/lang/String;)V
soft_trace: java/lang/String.getBytes()[B
soft_trace:
kaffe/io/CharToByteConverter.getDefault()Lkaffe/io/CharToByteConverter;
soft_trace:
kaffe/io/CharToByteConverter.getConverter(Ljava/lang/String;)Lkaffe/io/CharToByteConverter;
soft_trace:
kaffe/io/CharToByteConverter.getConverterInternal(Ljava/lang/String;)Lkaffe/io/CharToByteConverter;
soft_trace:
java/util/Hashtable.get(Ljava/lang/Object;)Ljava/lang/Object;
soft_trace:
java/util/HashMap.get(Ljava/lang/Object;)Ljava/lang/Object;
soft_trace:
java/util/HashMap.find(Ljava/lang/Object;)Ljava/util/HashMap$Entry;
soft_trace:
java/util/HashMap.bucket(Ljava/lang/Object;I)I
soft_trace: java/lang/String.hashCode()I
soft_trace:
java/util/HashMap.find(Ljava/lang/Object;I)Ljava/util/HashMap$Entry;
soft_trace:
java/lang/String.equals(Ljava/lang/Object;)Z
soft_trace:
java/lang/Class.newInstance()Ljava/lang/Object;
soft_trace: java/lang/reflect/Modifier.isAbstract(I)Z
soft_trace:
java/lang/Class.getDeclaredConstructor([Ljava/lang/Class;)Ljava/lang/reflect/Constructor;
soft_trace:
java/lang/System.getSecurityManager()Ljava/lang/SecurityManager;
soft_trace:
java/lang/reflect/Constructor.newInstance([Ljava/lang/Object;)Ljava/lang/Object;
soft_trace:
java/lang/reflect/Method.<init>(Ljava/lang/Class;ILjava/lang/String;Ljava/lang/Class;[Ljava/lang/Class;[Ljava/lang/Class;)V
soft_trace:
java/lang/reflect/AccessibleObject.<init>()V
soft_trace:
java/lang/reflect/Method.invoke(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;
soft_trace:
java/lang/String.equals(Ljava/lang/Object;)Z
soft_trace:
java/lang/reflect/Method.getParameterTypes()[Ljava/lang/Class;
soft_trace: kaffe/io/CharToByteDefault.<init>()V
soft_trace: kaffe/io/CharToByteConverter.<init>()V
soft_trace:
java/lang/String.getBytes(Lkaffe/io/CharToByteConverter;)[B
soft_trace: java/io/ByteArrayOutputStream.<init>(I)V
soft_trace: java/io/OutputStream.<init>()V
soft_trace: java/io/ByteArrayOutputStream.write([BII)V
soft_trace:
java/io/ByteArrayOutputStream.ensureCapacity(I)V
soft_trace: kaffe/io/CharToByteConverter.flush([BII)I
soft_trace:
java/io/ByteArrayOutputStream.toByteArray()[B
soft_trace: java/io/PrintStream.print([B)V
soft_trace: java/io/PrintStream.write([BII)V
soft_trace: java/io/BufferedOutputStream.write([BII)V
soft_trace: java/io/PrintStream.flush()V
soft_trace: java/io/BufferedOutputStream.flush()V
soft_trace: java/io/FileOutputStream.write([BII)V
soft_trace: java/io/PrintStream.flush()V
soft_trace: java/io/BufferedOutputStream.flush()V
soft_trace: java/io/PrintStream.println()V
soft_trace: java/io/PrintStream.print([C)V
soft_trace:
java/lang/String.valueOf([C)Ljava/lang/String;
soft_trace: java/lang/String.<init>([C)V
soft_trace: java/lang/String.<init>([CII)V
soft_trace: java/lang/String.getBytes()[B
soft_trace:
kaffe/io/CharToByteConverter.getDefault()Lkaffe/io/CharToByteConverter;
soft_trace:
kaffe/io/CharToByteConverter.getConverter(Ljava/lang/String;)Lkaffe/io/CharToByteConverter;
soft_trace:
kaffe/io/CharToByteConverter.getConverterInternal(Ljava/lang/String;)Lkaffe/io/CharToByteConverter;
soft_trace:
java/util/Hashtable.get(Ljava/lang/Object;)Ljava/lang/Object;
soft_trace:
java/util/HashMap.get(Ljava/lang/Object;)Ljava/lang/Object;
soft_trace:
java/util/HashMap.find(Ljava/lang/Object;)Ljava/util/HashMap$Entry;
soft_trace:
java/util/HashMap.bucket(Ljava/lang/Object;I)I
soft_trace: java/lang/String.hashCode()I
soft_trace:
java/util/HashMap.find(Ljava/lang/Object;I)Ljava/util/HashMap$Entry;
soft_trace:
java/lang/String.equals(Ljava/lang/Object;)Z
soft_trace:
java/lang/Class.newInstance()Ljava/lang/Object;
soft_trace: java/lang/reflect/Modifier.isAbstract(I)Z
soft_trace:
java/lang/Class.getDeclaredConstructor([Ljava/lang/Class;)Ljava/lang/reflect/Constructor;
soft_trace:
java/lang/System.getSecurityManager()Ljava/lang/SecurityManager;
soft_trace:
java/lang/reflect/Constructor.newInstance([Ljava/lang/Object;)Ljava/lang/Object;
soft_trace:
java/lang/reflect/Method.<init>(Ljava/lang/Class;ILjava/lang/String;Ljava/lang/Class;[Ljava/lang/Class;[Ljava/lang/Class;)V
soft_trace:
java/lang/reflect/AccessibleObject.<init>()V
soft_trace:
java/lang/reflect/Method.invoke(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;
soft_trace:
java/lang/String.equals(Ljava/lang/Object;)Z
soft_trace:
java/lang/reflect/Method.getParameterTypes()[Ljava/lang/Class;
soft_trace: kaffe/io/CharToByteDefault.<init>()V
soft_trace: kaffe/io/CharToByteConverter.<init>()V
soft_trace:
java/lang/String.getBytes(Lkaffe/io/CharToByteConverter;)[B
soft_trace: java/io/ByteArrayOutputStream.<init>(I)V
soft_trace: java/io/OutputStream.<init>()V
soft_trace: java/io/ByteArrayOutputStream.write([BII)V
soft_trace:
java/io/ByteArrayOutputStream.ensureCapacity(I)V
soft_trace: kaffe/io/CharToByteConverter.flush([BII)I
soft_trace:
java/io/ByteArrayOutputStream.toByteArray()[B
soft_trace: java/io/PrintStream.print([B)V
soft_trace: java/io/PrintStream.write([BII)V
soft_trace: java/io/BufferedOutputStream.write([BII)V
soft_trace: java/io/PrintStream.flush()V
soft_trace: java/io/BufferedOutputStream.flush()V
soft_trace: java/io/FileOutputStream.write([BII)V
soft_trace: java/io/PrintStream.flush()V
soft_trace: java/io/BufferedOutputStream.flush()V
soft_trace: java/io/PrintStream.flush()V
soft_trace: java/io/BufferedOutputStream.flush()V
You will see a couple of objects being instantiated
(<init>). So if you want to be able to print messages
when you receive an OutOfMemoryError you should take a
look at kaffe's class library implementation and see
if you can come up with a more memory efficient
implementation of the methods mentioned above.
> Do you know a solution for my problem (buying more
> physical memory excluded
> :-) ) (the Kaffe version I use is: "Engine:
> Just-in-time v3 Version: 1.0.6
> Java Version: 1.1" (version 1.0.7 does not help,
> too))? I could try to find
> the bug(-s) myself, but I think you will be
> faster... :-)
It's not really a bug in my opinion, as you are trying
to allocate more memory even after being told by the
VM that there is no memory left ;)
What you can do, is to see (using -verbosecall) what
happens in/after your exception handling code, where
objects are allocated, and try to come up with a
better implementation of kaffe's libraries that you
want to use.
Patches are most welcome.
best regards,
dalibor topic
__________________________________________________
Do You Yahoo!?
HotJobs - Search Thousands of New Jobs
http://www.hotjobs.com