www.heteroclinic.net
Review C malloc before Rolling Java Native Interface Dice 20150131
Recently, C++ and OS changed much, but we still can use malloc with the newest compiler. My test environment is listed in the next section.
|
||
Lightly Modified the JNI Tutorial 20150131
We have to alternate the procedure of the JNI tutorial post in Wikipedia as the following.
|
||
Hack the HelloWorld to Stress malloc in JNI 20150131
I tried to branch the JNI tutorial and use a different set of variables names and class names. But due to some modifications wrong with the machine generated code, I just hacked directedly the HellowWorld tutorial. In the before section, we know, even it is from Wikipedia (to some sense, much peer reviewed), engineering is still a fitting circle to square practice.
The following is the result, note the '-l stdc++' flag needed.
|
||
JNI malloc Test - Discussion 20150131
This excercise shows when running JNI malloc, the vm settings of memory constraints do not apply to the native code in execution.
20150131
We continue the engineering of null pointer exception. If memory allocation is not properly handled, the error is neglected/eaten up in a complex program structure, deep in the thread or delegate stack, it may emerge and make even a single thread program demonstrate random or choatic behavior. The following snippet shows the NullPointerException may happen at given points but randomly in a single thread program. Please note this behavior does not limit to Java, in fact, any program without proper transaction design, tuning/profiling (producer consumer), as far I jumped to some at my C codes, will demonstrate such behavior. For short, to engineer the working condition of a product, but beyond the scope of this disucssion, is not this discussed here.
Source Code
How to:
Gathered data sample one and two, you may have different resuts: |