Steve Jiang

Ranch Hand
+ Follow
since May 17, 2004
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Steve Jiang

Hi,

I tried to use hprof paramter to get the HPROF for memory usage checking. The command is like below. (I used the simple sample code for testing)

java -Xrunhprof:heap=all,cpu=old,depth=6 test/com/timerTest


I got the hprof file. Based on trace ID, some trace id is very clear and useful. Based on the traceID , like 301586, I can see exact line which spend the memory , like


5066 TRACE 301586:
5067 java.lang.AbstractStringBuilder.<init>(AbstractStringBuilder.java:63)
5068 java.lang.StringBuilder.<init>(StringBuilder.java:85)
5069 test.com.timerTest.main(timerTest.java:14)




but some of memory usage with trace id 300000, I can not find the valuable information for the memory usage from hprof file, It just marked as empty, and I don't know what exactly means for those memory usage , and which part is using that.

I attached the source and the hrpof file in the thread. Also I list the sumary of hprof file and some trace id 3000000 below.

I hope to understand , what is the memoryt usage for trace ID 300000, and how it involves the memory usage.

Does someone know how we can find tracce 300000 memory usage?




TRACE 300000:
<empty>
.............
ROOT 0 (kind=<thread>, id=200000, trace=300000)
ROOT 50000c6a (kind=<thread>, id=200003, trace=300001)
ROOT 50000c6a (kind=<thread block>, thread=200003)
ROOT 50000c73 (kind=<thread>, id=200004, trace=300000)
ROOT 50000c73 (kind=<thread block>, thread=200004)
ROOT 50000c73 (kind=<JNI local ref>, thread=200000, frame=0)
ROOT 50000c74 (kind=<thread>, id=200005, trace=300000)CLS 5001b4bd (name=javax.lang.model.element.VariableElement[], trace=300000)
super 50000119
CLS 5001b4be (name=javax.lang.model.element.Element[], trace=300000)
super 50000119

................

SITES BEGIN (ordered by live bytes) Tue Mar 15 14:07:10 2016
percent live alloc'ed stack class
rank self accum bytes objs bytes objs trace name
1 16.76% 16.76% 131200 8 131200 8 300827 char[]
2 10.52% 27.29% 82336 861 82336 861 300000 char[]
3 8.39% 35.68% 65664 8 65664 8 300815 byte[]
4 3.26% 38.94% 25536 9 25536 9 300000 byte[]
5 2.68% 41.62% 20960 134 20960 134 300039 char[]
6 2.67% 44.28% 20864 847 20864 847 300000 java.lang.String
7 1.67% 45.95% 13040 302 13040 302 300000 java.lang.Object[]
8 1.55% 47.50% 12144 109 12144 109 300048 char[]
9 1.51% 49.01% 11832 66 11832 66 300084 byte[]
10 0.95% 49.96% 7440 121 7440 121 300919 char[]
11 0.74% 50.71% 5808 11 5808 11 300769 byte[]
12 0.62% 51.33% 4848 66 4848 66 300087 byte[]
13 0.55% 51.87% 4272 178 4272 178 300934 java.util.LinkedList$Node
14 0.55% 52.42% 4272 117 4272 117 300000 java.util.Hashtable$Entry
15 0.51% 52.92% 3960 28 3960 28 300298 char[]
16 0.49% 53.42% 3872 121 3872 121 300375 java.util.HashMap$Entry
17 0.46% 53.88% 3600 77 3600 77 300000 java.lang.ref.SoftReference
18 0.45% 54.33% 3552 25 3552 25 300292 char[]
19 0.43% 54.76% 3376 11 3376 11 300770 byte[]









Thanks
8 years ago
Hi,

I tried to use hprof paramter to get the HPROF for memory usage checking. The command is like below.

javac -J-agentlib:hprof=heap=dump test.java

I got the hprof file. Based on trace ID, I can find most code which spend the memory from hprof file, but some of memory usage with trace id 300000, I can not find the valuable information for the memory usage from hprof file, It just marked as empty, and I don't know what exactly means for those memory usage , and which part is using that.

I atatched the sumary of hprof file and some trace id 3000000 below. Does someone know how we can find tracce 300000 memory usage?


TRACE 300000:
<empty>
.............

CLS 5001b4bd (name=javax.lang.model.element.VariableElement[], trace=300000)
super 50000119
CLS 5001b4be (name=javax.lang.model.element.Element[], trace=300000)
super 50000119

................

rank self accum bytes objs bytes objs trace name
1 46.98% 46.98% 11534304 240298 77470080 1613960 305622 java.nio.HeapCharBuffer
2 46.98% 93.97% 11534256 240297 77469984 1613958 305825 java.nio.HeapCharBuffer

4 0.81% 95.60% 200016 1 200016 1 303579 java.lang.Object[]
5 0.51% 96.10% 124640 1569 124640 1569 300000 char[]
6 0.38% 96.49% 94504 376 94504 376 301147 byte[]
7 0.15% 96.64% 37864 1556 37864 1556 300000 java.lang.String
8 0.12% 96.76% 28512 571 28512 571 300000 java.lang.Object[]
9 0.11% 96.87% 28152 589 28152 589 301144 char[]
10 0.10% 96.98% 25504 8 25504 8 300000 byte[]
11 0.10% 97.08% 24448 326 24448 326 306292 int[]

13 0.06% 97.23% 14136 589 14136 589 301143 java.lang.String
14 0.04% 97.28% 10432 326 10432 326 306294 sun.misc.FDBigInteger

16 0.04% 97.36% 10064 74 10064 74 305763 long[]
17 0.04% 97.40% 9584 112 9968 117 303246 char[]
18 0.04% 97.43% 8768 3 8768 3 303134 java.nio.ByteBuffer[]

20 0.03% 97.50% 8208 1 8208 1 305607 byte[]

23 0.02% 97.57% 4640 257 4640 257 300000 java.lang.Integer
24 0.02% 97.59% 4416 105 4968 117 303252 char[]


Thanks

8 years ago
I add all int to list, and it converts int to Integer. From some link http://www.javaworld.com/article/2077496/testing-debugging/java-tip-130--do-you-know-your-data-size-.html , we see Inetger spends 16 bytes and int for 4 bytes. So if here are same capactivity for 1M, arraylist should be 16M and array could be 4M. It could explains most part for arraylist use more than array. Looks like they are still more than 4 times of array, maybe there are some other related stuff, but at least it is not different as expected so much.

Thanks
8 years ago
Thanks, Campbell! The explanation is very make sense and similar as I thought.

also one more informaiton for the test, the jvm paramter is "-Xmx256m -Xms8m"

if I do nothing, and only print hello world, I can see the memory usage is around 10M

so if only tetsing creating 1M array, I get the memory usage arund 14M , which means the new array used additional 4M , which make sense, since int as 32 bit and 4 bytes, * 1M = 4M



For arrayList , as you described, I assume when I add the data less the 600K, (less than loading factor 0.75) it should be similar usage as array, around 4M , and when I insert 1M data, list will double the size , and it may use 8M for 2M int array.

insert 1M data for arraylist, the memory usage is 36M , which meeans the arraylist could use 36M -10M = 26 M
insert 0.5M data in arraylist, the memory usage is 24.6M (around 25M), which means 15M = 25M - 10M




For hashmap, I did same thing for 1M data, and 0.5M


1M data in hashmap, the memory usage is 119M . it means double hashmap (for 2m) could use 119 - 10 = 109 M
0.5M data in hashmap , the memory usage is 72M, it means the hashmap could use 72M - 10 M = 62M




Looks like the array usage is match what I think, but arraylist, and hashmap use more than I expected. Not sure if jvm also need to allocate other memory for the arraylist and hashmap memory?


Thanks

8 years ago
I just comments out the code if that part is not for testing. test it with multiple combination. It is 64 bit machine. I don't need to get the exact memory usage for these data structire, but try to understand the reason for different structure.

Especially, why arraylist use more memory than array, also hashmap look like spend much more than the array with same capacity?

Thanks
8 years ago
the memory usage is monitored from Activity Monitor from Mac OS . Active Monitor will show how many memory is used for this Java process.
8 years ago
Hi,

I try to compare the memory usage between hashmap and arraylist using the following code.

I got the following result, the memory usage is monitored from Activity Monitor from Mac OS

NO list, and no Map : 10 M
No list and new HashMap: 10.1M
No Map , and creating new ArrayList: 13.9M
creating both Map and arraylist : 13.9M

Looks like hashmap doesn't use memory, but arrayList spend aroun 4M for 1M size list.





Another tetst code to put the value , I git the different value as below

No map, list: 10M
only Map: 116M
only List : 35M
Both Map and list : 119 M

Array (with/without setting) : 14M





I was thinking when the hashMap and list were created , the memory will be allocated. and we should not be that much difference between setting the data or not. Looks like arrayList and hashMap doesn't allocate the memory even it was set the init capacity. but I hope to confirm if this is the right reason for the different memory usage.

Also I can see much difference between arraylIst and array. Is there more information to explain why ArrayList use more memory 35M than array 14M?

Thanks

8 years ago
Hi,

Could J2ME SDK used in Mac? I checked the https://docs.oracle.com/javame/dev-tools/jme-sdk-3.0-mac/BinaryReleaseNotes.html#requirements, and it listed below

3. Installation Instructions

Follow these instructions to install the Java ME SDK on Mac OS.

Verify that your system meets the preceding system requirements.
Download the DMG file from http://java.sun.com/javame/downloads/sdk30.jsp.
Double-click the DMG file.
Click Agree to accept the license and continue the installation.
The installer displays the following panel. Dragging the Java ME SDK application icon over the Applications folder link will install Java ME SDK in the Applications folder. You can also use the Finder to move the application.
In the Applications directory, click the Java ME SDK icon to start the application. Wait a few seconds for the Device Manager to detect the default devices delivered with the SDK.



But when I click http://java.sun.com/javame/downloads/sdk30.jsp., there is no DMG file, and only has the exe file for windows OS.


Oracle Java ME SDK 8.1
Release Notes
Developer's Guide 31 MB Downloads Iconoracle-jmesdk-8-1-rr-win-bin.exe
Oracle Java ME SDK 8.1 Plugins for NetBeans 8 2.2 MB Downloads Iconoracle-jmesdk-8-1-rr-nb-plugins.zip
Oracle Java ME SDK 8.1 Eclipse Plugins 4.7 MB Downloads Iconoracle-jmesdk-8-1-rr-eclipse-plugins.zip



Does someone install J2ME SDK in Mac and can share the experience?

Thank you for any comments!

8 years ago
Thanks, Bear!

Hi Srping Guru,

Any suggestions to integrate the Spring with Java Me form spring ?

Thanks

8 years ago
Hi Bear,

We could run the application on auto equipment or some controller for oil plant, etc. For some reason, we can't use Android. Except Android/IOS , J2ME, is there other framework for embedded devices?

Thanks
8 years ago
Thanks, Bear Bibeault!

Could I see and be notified if there are responses from Spring forum after it is linked to Spring Forum?

Thanks

8 years ago
There are some reason we can't use Android. What else would you suggest for embedded device?

Thanks
8 years ago
HI,

I hope to check if we can use the standard spring in Java ME? I saw other spring product , like Signal Framework in http://www.javaexpress.pl/article/show/Signal_Framework_for_Java_ME , and hope to get the suggestion if people use spring in J2ME and the recommendation for different spring product in J2ME.

Any suggestions or comments for J2ME spring are appreciated.

Thanks


8 years ago
Hi,

We have a java application in Java SE , we hope to transfer existing java application from Java SE to Java ME , in order to get the less memory and CPU usage for the the application. Our code is most backend code, and no UI part.

I tested the most simple "Hello Word" Java application spends a round 10M memory. We need much less memory in embedded device and hope to use Java ME , instead Java SE, and hope to get better performance usage for CPU and memory.

I am new to Java ME and have a few question for Java ME development.


1, could we porting the existing Jave SE code to Java ME? Any recommendation for related document or link to potting existing java SE code to Java ME? ( Sorry I didn't find much, or I don't get the correct one)

2, From Oracle DOc, looks like Java ME need to run on Raspberry PI , etc from http://www.oracle.com/technetwork/java/embedded/javame/embed-me/downloads/index.html. Does that mean Java ME must run on those device? Could we develop the code in Eclipse and port to embedded device in the final stage when development is completed?

3, Jave ME SDK only has windows version? I am using Mac, is there Java ME Mac version?



Thank you very much for any comments and suggestions!




8 years ago