Practical
Embedded Java

HeapTest


A practical engineering approach to using embedded Java in real-world applications.


...



Description:
First attempt at a simple program with methods which allocate some large arrays, copy data between them, and return. The methods are then called again, until an Exception is caught or the program fails due to an uncatchable error. The GC should reclaim the memory when the method terminates so the program should never fail. The program outputs the amount of total and free memory as it runs, using the Runtime class methods totalMemory() and freeMemory().
About java.lang.OutOfMemoryError

According to the java.lang API javadocs:
An Error is a subclass of Throwable that indicates serious problems that a reasonable application should not try to catch. Most such errors are abnormal conditions. A method is not required to declare in its throws clause any subclasses of Error that might be thrown during the execution of the method but not caught, since these errors are abnormal conditions that should never occur. However you can catch an Error just as you can catch an Exception.

Other possible investigations:

How do different JVMs allocate and garbage collect the heap among mutliple processes?
Which JVMs might suffer from heap fragmentation?

Comments and Disclaimer:
This is probably not the greatest heap test, but it is based on the BenchMark source code since that is where I first noticed this problem.

HeapTest 0.1f (improved threads) 2003 Feb 28
What's new in 0.1f

Many improvements and better reporting of any runtime errors, and final results.
Please see the source code for other comments.

Files
Here is the HeapTest_01f ZIP file which contains the source, build, and output captures.

HeapTest 0.1e (threads) 2003 Feb 25
What's new in 0.1e

Array element (chunkSize) now defaults to 1000 hex but can be entered on the command line: "java HeapTest.tini 3000 &"
Three threads attempt to start and allocate two arrays of chunkSize, chunkSize/2 and chunkSize * 3/2 total bytes, one size per thread.
Please see the source code for other comments.

Files
Here is the HeapTest_01e ZIP file which contains the source, build, and output captures.

HeapTest 0.1d 2003 Feb 25
What's new in 0.1d

Array element (chunkSize) 0x500
Dueling processes - start up two HeapTest processes and have them compete for heap space

Files
Here is the HeapTest_01d ZIP file which contains the source, build, and output captures.

HeapTest 0.1c 2003 Feb 25
What's new in 0.1c

Added some more try-catch blocks and messages to pin down where the OutOfMemory error occurs.
Ran this on a 512K TINI 390 with 1.02e, it fails after 3 to 45 iterations. Sample output is below.

Iteration 43 : Memory total=0x12860/75584 free=0x12600/75136
  byte arrays with 32768 elements
  1st array OK
  2nd array OK
  byte array Test OK
  int arrays with 8191 elements
  1st array OK
  2nd array OK
  int array Test OK
Iteration 44 : Memory total=0xb020/44800 free=0xadc0/44352
  byte arrays with 32768 elements
java.lang.OutOfMemoryError
No other stack trace info available.
Files
Here is the HeapTest_01c.zip file which contains the source, build, and output captures.

HeapTest 0.1a 2003 Feb 24
What's new in 0.1a
First attempt at a simple program with methods which allocate some large arrays, copy data between them, and return. The methods are then called again, until an Exception is caught.
Files
Here is the HeapTest_01a.zip file and the raw results_01a.txt capture file.
For more technical details on these modules, see this feature comparison table.

 
Systronix® 939 Edison St, Salt Lake City, Utah, USA 84111
Tel +1-801-534-1017, Fax +1-801-534-1019
contact us     Time Zone: MDT (UTC-6)
 

Java and all Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries.
Systronix is independent of Sun Microsystems, Inc.
TStik, JStik, JCX, JStamp, JSimm, JDroid, and JRealTime are trademarks of Systronix, Inc.
1-Wire, iButton and TINI are trademarks of Dallas Semiconductor
Simmstick is a trademark of Dontronics
LEGO® is a trademark of Lego A/S, Denmark