Thursday, August 21, 2008

Fixing Java Memory Tools on Mac OS X

A number of the Java memory management tools with the default distribution on Mac OS X Leopard are broken. The information to repair the situation seems to be hard to come by. This post will detail the steps necessary to get jmap and jhat to work on a Mac for Java 6. I assume that Java 5 has the same issue but haven't checked.


Setting up a test Java process to profile.
1. From the terminal: cd /Developer/Examples/Java/JFC/Java2D/
2. From the terminal: java -jar Java2D.jar &
3. After the process starts it should indicate the pid (in this example it is 5510)
4. You can also use jps to discover the pid: jps -l (then look for the Java2D.jar)

Fixing jmap
If you type jmap , you would expect to get a high-level memory dump... instead you get a message like:
attach: task_for_pid(5510) failed (5)
Error attaching to process: Error attaching to process, or no such process

To fix this, do a sudo, such as sudo jmap .
Debugger attached successfully.
Server compiler detected.
JVM version is 1.6.0_05-b13-52

using thread-local object allocation.
Mark Sweep Compact GC

Heap Configuration:
MinHeapFreeRatio = 40
MaxHeapFreeRatio = 70
MaxHeapSize = 88080384 (84.0MB)
NewSize = 2686976 (2.5625MB)
MaxNewSize = -65536 (-0.0625MB)
OldSize = 5439488 (5.1875MB)
NewRatio = 2
SurvivorRatio = 6
PermSize = 21757952 (20.75MB)
MaxPermSize = 88080384 (84.0MB)

Heap Usage:
New Generation (Eden + 1 Survivor Space):
capacity = 10551296 (10.0625MB)
used = 4592152 (4.379417419433594MB)
free = 5959144 (5.683082580566406MB)
43.52216069002329% used

At this point it looks like it is working, however the file dump doesn't work.

Fixing jhat
When running jhat on the hump dump, you get the following error:
Eliminating duplicate references.....................
Snapshot resolved.
Exception in thread "main" java.lang.RuntimeException: java.lang.NullPointerException
at com.sun.tools.hat.internal.oql.OQLEngine.init(OQLEngine.java:277)
at com.sun.tools.hat.internal.oql.OQLEngine.(OQLEngine.java:51)
at com.sun.tools.hat.internal.server.QueryListener.setModel(QueryListener.java:59)
at com.sun.tools.hat.Main.main(Main.java:189)
Caused by: java.lang.NullPointerException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.sun.tools.hat.internal.oql.OQLEngine.init(OQLEngine.java:256)
... 3 more

It took me a little hunting to uncover the issue. It turns out that jhat uses the Java 6 js engine. If you go to the terminal again and run: jrunscript , it indicates that the script engine for language js can not be found. On the mac, if you execute: jrunscript -q, which provides a listing of script engines you'll see:
Language AppleScript 2.0.1 implemention "AppleScriptEngine" 1.0
Thank you apple!

As a side note if you actually wanted to run AppleScript as a shell, type jrunscript -l AppleScript

Let's get to fixing the issue
  1. Download JSR-223's engines https://scripting.dev.java.net/files/documents/4957/37593/jsr223-engines.zip
  2. Download Rhino http://www.mozilla.org/rhino/download.html
  3. Copy jsr223-engines/javascript/build/js-engine.jar to /System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home/lib/ext/
  4. Copy rhino1_7R1/js.jar to /System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home/lib/ext/
** you have to be sudo to do steps 3 and 4.

now jrunscript -q should look like this:
Language EmbeddedECMAScript 1.6 implemention "Mozilla Rhino" 1.6 release 2
Language AppleScript 2.0.1 implemention "AppleScriptEngine" 1.0
Language ECMAScript 1.6 implemention "Mozilla Rhino" 1.6R7

... and jrunscript will put you in a js shell.
... and jhat heap.out now works! Point your browser at http://localhost:7000 and object browse!

Also something I didn't realize until I was preparing for this post... jmap worked for the console dump if I sudo'd the command. However it would not do a file dump. I did the file dump using jconsole and jmx. Now that the scripting issue is fixed, jmap is improved in the following manner:
  1. if you type jmap , it now prompts you for your admin password (instead of just failing)
  2. jmap -dump:live,format=b.file=heap.out 5510 now works

It makes me wonder what else wasn't working! Happy Coding!

74 comments:

Stu Thompson said...

You are officially "Internet Hero of the Week". This post saved me time mucking about, and kept on tract to debug own application. Thanks a zillion. If you ever find yourself in Zürich, let me know...I owe you a beer!

Unknown said...

Thank you very much for this blog. You saved me so much time to get jhat running on Leopard. Now i am able to debug my issue about PermGen and Classloader leaks.

If you are visiting germany I owe you a beer too.

Unknown said...

Hi all,
Instead of using jhat I would suggest you to check the Eclipse Memory Analyzer.

It's really (attention, I'm biased ;) ) much better than JHAT.

interbine said...

Definitely the "Hero of the Week".

You have a beer waiting for you in Tel Aviv too...

Ori

Charles Oliver Nutter said...

Another kudos from me...I never would have figured this out. Now we just need to get Apple to ship a non-broken Java 6.

Unknown said...

Wow, thanks for taking the time to explain how to fix this.

To add to your "free beer tour of the world," we have a beer waiting for you in Toronto.

Bruno Duarte said...

Thank you for the fix.

You have a grapes juice waiting for you in Cambridge.

aaronyo said...

And there's now a micro brew waiting for you in Bend, OR, USA. Thanks for the time saver.

Kedar Mhaswade said...

Kudos!

You are an Internet Hero of another week. This is April 2009. Thank you!

-Kedar

Nate said...

Awesome, thanks! I doubt I would have been able to figure this out on my own.

Aria Kerry said...
This comment has been removed by the author.
Christina Gomes said...

You're Internet Hero of another week this is April 2009. Ab Belt

davidbieber80 said...

Also something I didn't realize until I was preparing for this post... jmap worked for the console dump if I sudo'd the command. However it would not do a file dump. I did the file dump using jconsole and jmx. Now that the scripting issue is fixed, jmap is improved in the following manner:
jump higher save fuel Electronic Cigarette tava tea error fix

fantu❤ said...

Your blog site is excellent. Say thanks to you truly for providing plenty of both useful and interesting advise. I will bookmark bookmark your website and will be absolutely coming back. Again, I truly appreciate all your work furthermore providing plenty of worthwhile info for the audience.
louis vuitton papillon | louis vuitton tresor wallet | louis vuitton musette | louis vuitton theda gm

Herman S. Calderon said...

Thanks to explain step by step now i got your point.
Catherine A. Murphy

The Jump Manual said...

I need those two versions in order to log into a particular piece of equipment and have been unable to get them installed. jump higher

Mark said...

Do you want to find out more about android apps, which ones are the best, where to download them and how they can improve your experience with the android platform? If so, keep reading this article to find out the most important things you have to know about android apps.


best android apps

free google sms said...

CNA Training I really have learned a lot from you.Thanks for sharing. CNA Classes Online

hiumeshSINGH said...

I could notify that we’re on a single interest and obsession. Good to understand an individual I could reveal my concepts. Getting excited about know and find out more of your stuff.
Web Designing
Property in Noida

marven said...

hank you for sharing This knowledge.Thank you very much for sharing this knowledge.this graph really conveyed the part which i was looking for. company logo design

arghya said...

I got many unknown information from this informative site. This is an excellent blog.
weight loss supplements

onwebmedia said...

Personally, the post is in fact the most excellent on this impressive topic. I harmonize with your conclusions and will keenly look further to your future updates.
Stag and Hen Weekends in London and Nottingham

Net Job said...

Excellent blog. Thanks for sharing your excellent information with all. Best regards from RSR Infocom

Arghya Chakraborty said...

This blog is totally superb. I got many unknown information from this post. chocolate hampers

Anonymous said...

Great blog.Very informative.I am very happy to leave comment here for you!Thank u.
Joomla developer

Android app development said...

Java is one of the Object Oriented programming language.By using this language we can easily develop this Android application.
Android app developers

Milda Ragus said...

Excellent blog I like it so much. That is nice info, I can not wait the continuation of your blog. I appreciate great work done by author.

PALACE HOTEL NEW YORK

Op Dr Ali Mezdeği said...

you have a nice site.thanks for sharing this site. various kinds of ebooks are available here
fuesacekimi

andrew said...

Thanks for posting this. Looking forward to the last article.evdo wireless internet.

andrew said...

That is the suitable weblog for anybody who needs to seek out out about this topic. wireless internet .

andrew said...

Thank you very much for this blog. You saved me so much time to jhat run in Leopard. Now I can debug my PermGen and class loader leak problem. wireless internet .

Unknown said...

Your blog article is very intersting and fanstic,at the same time the blog theme is unique and perfect,great job.
web designing bangalore

Online Beauty Store said...

I am really happy to see your article. Thanks for sharing useful information. Web Development Company Bangalore

Unknown said...

SUperb article, Thanks!!!

Ecommerce Design Company Bangalore

Unknown said...

Valuable information and excellent information you done here..I really enjoyed reading.Thanks for the post.Stansted Airport Parking

Unknown said...

Nice post. thanks for sharing this post... Stone Sales

Unknown said...

Its great really! thanx for share to everyone...

convenient money transfer

Unknown said...

Nice Blog...this post is outstanding in regards of both information as well as information.thanks for talking about you post with us.

Unknown said...

Your blog article is very Intersting and Fantastic,at the same time the blog theme is unique and perfect,great job..

Web Designing Company Bangalore

francy said...

Your Post is really Good..and beautiful..
Web Design Company Bangalore
Web Designing Bangalore
Web Designer Bangalore

Unknown said...

Nice article...

gps child locator india

Karen Jain said...

Great info!! Thanks for sharing.
Online Marketing Company|Web Designing Company

Unknown said...

I am happy to find this very useful for me, as it contains lot of information. I always prefer to read the quality content.
Web Designing Company Bangalore | Web Development Company Bangalore

priya said...

Thanks for the share.We offers an extensive range of services like web application development, website designing, e-commerce solutions, application development.
SEO Companies Bangalore|Web Development Company Bangalore

Unknown said...

Great post,a website is more environmental friendly when it comes to advertising and marketing and also having a website can build better relationships with the customers.
SEO Services India|Web Designing Company India

Unknown said...

Great publish you could have done below. I am really happy to learn this specific. It is a very helpful matter that you are picked. keep writing.nimble storage pricing

Unknown said...

This post will detail the steps necessary to get jmap and jhat to work on a Mac for Java 6. I assume that Java 5 has the same issue but haven't checked.iPhone repair nottingham

Unknown said...

Java is very good blog,it's highly professional course.Thanks for info
java online course Bangalore

Ancy merina said...
This comment has been removed by the author.
Unknown said...

Webtrackker is one only IT company who will provide you best class training with real time working on marketing from last 4 to 8 Years Experience Employee. We make you like a strong technically sound employee with our best class training.


WEBTRACKKER TECHNOLOGY (P) LTD.
C - 67, sector- 63, Noida, India.
F -1 Sector 3 (Near Sector 16 metro station) Noida, India.
+91 - 8802820025
0120-433-0760



Best SAS Training Institute in delhi

SAS Training in Delhi

SAS Training center in Delhi

Best Sap Training Institute in delhi

Best Sap Training center in delhi


Sap Training in delhi

Best Software Testing Training Institute in delhi

Software Testing Training in delhi

Software Testing Training center in delhi


Best Salesforce Training Institute in delhi


Salesforce Training in delhi

Salesforce Training center in delhi

Best Python Training Institute in delhi

Python Training in delhi

Best Python Training center in delhi

Best Android Training Institute In delhi

Android Training In delhi

best Android Training center In delhi

svrtechnologies said...

Quite interesting post,Thanks for sharing the information.Keep updating good stuff...
sap abap training

sandhiya said...

I am really enjoying reading your well written articles.
It looks like you spend a lot of effort and time on your blog.Keep Doing.
Data Science Training Institutes in Bangalore
Data Science Certification Bangalore
best analytics courses in bangalore
best data analytics courses in bangalore
big data analytics certification in bangalore

Vicky Ram said...

Thanks for sharing this article, really helpful

Education
Technology

service care said...

Thank you for allowing me to read it, welcome to the next in a recent article. And thanks for sharing the nice article, keep posting or updating news article
lg mobile service center
lg mobile service chennai
lg mobile repair
lg mobile service center near me

easylearn said...

Hi,
Good job & thank you very much for the new information, i learned something new. Very well written. It was sooo good to read and usefull to improve knowledge. Who want to learn this information most helpful. One who wanted to learn this technology IT employees will always suggest you take python training in pune. Because python course in pune is one of the best that one can do while choosing the course.

Faizal said...

Thanks for this Beautiful works...I am very happy to visit your site, Excellent!!!
Java training in chennai | Java training in annanagar | Java training in omr | Java training in porur | Java training in tambaram | Java training in velachery

Aishwariya said...

wonderful article contains lot of valuable information. Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article.
AWS course in Chennai

Tamil novels said...

Excellent article. Thank you for sharing with us.
Tamil novels pdf
Ramanichandran novels PDF
srikala novels PDF
Mallika manivannan novels PDF
muthulakshmi raghavan novels PDF
Infaa Alocious Novels PDF
N Seethalakshmi Novels PDF
Sashi Murali Tamil Novels

Let2know said...

Obviously a satisfying estimation. i've affirmation this bewildering announce. much obliged to you for sharing proposal generally it. I in truth further to that. much appreciated accurately part to your meet. Wifi Hacking Online

Links For You said...

I waterfrontt any expression to understand this call.....truely i'm dazzled from this make recognized....the person that make this screen it changed into an excellent human..thanks for shared this long past us. Norton Internet Security Full Crack

haseeb said...

Glorious web site! I love the way it is straightforward upon my eyes it's far. I'm contemplating the way in which I might be prompted whenever another conspicuous screen has been made. glancing through out extra new updates. Have a colossal extensive stretches of significant stretches of light hours!! Birthday Wishes Son In Law

Jennifer said...

Great article! So, we're going to put a link to this great article on our Keep writing page.
Color Finale Pro

ZZxmzn said...

yo bro

ZZxmzn said...

เกมการพนันที่เล่นง่าย อะไรจะง่ายไปกว่าการเลือกตัวเลขและหวังให้ดีที่สุด? การจ่ายเงินจะแตกต่างกันไปขึ้นอยู่กับคาสิโน และมักจะขึ้นอยู่กับการเดิมพัน หมายเลขที่เลือก และจำนวนการแข่งขัน สล็อตเว็บตรงpg รูปแบบบางอย่างรวมถึงแม้ว่าคุณจะไม่เคยไปคาสิโนมาก่อน อย่างน้อยคุณก็ต้องเคยได้ยินเกี่ยวกับแบล็คแจ็ค เนื่องจากเป็นเกมคาสิโนที่มีชื่อเสียงและเล่นง่ายที่สุดเกมหนึ่ง แบล็คแจ็คเป็น

ZZxmzn said...

10.00 น. ถึง 06.00 น. สำหรับเครื่องสล็อต และตั้งแต่ 16.00 น. สำหรับเครื่องสล็อต ถึง 02.00 น. สำหรับโต๊ะเล่นเกม คาสิโนแห่งนี้มีชื่อเสียงในด้านเครื่องสล็อต 480 เครื่อง สล็อตเว็บตรงแท้ นอกจากข้อเสนอที่น่าประทับใจนี้แล้ว ยังมี Black Jack, English Roulette และ Poker Texas Hold'em Ultimate อีกด้วย มีลานสำหรับสูบบุหรี่สองแห่งที่คุณสามารถเล่นได้พร้อมชมสวนของคาสิโน ในคาสิโนทั้งสองแห่ง เดิมพันขั้นต่ำคือหนึ่งเซ็นต์ - ในเครื่องสล็อตบางเครื่อง - แต่โดย

ZZxmzn said...

จะแพ้ หากไพ่ของผู้เล่นมีอันดับต่ำกว่าไพ่ของเจ้ามือ เจ้ามือจะชนะ และผู้เล่นจะเสียเงินเดิมพันเริ่มต้นและเดิมพันเสมอ (ถ้ามี) หากไพ่ของผู้เล่นและของเจ้ามือ ไพ่มีอันดับเท่ากัน (เสมอกัน) การเดิมพันเสมอจะจ่าย 10 ต่อ 1 (ดูตัวเลือกที่มีให้สำหรับผู้เล่นด้านล่าง)2 การเดิมพันเริ่มต้นและการเดิมพันเสมอที่เสียทั้งหมดจะถูกรวบรวมโดยเจ้ามือและวางไว้ด้านหน้าของ เว็บสล็อตแท้ ตัวแทนจำหน่าย ดีลเลอร์จะเป็นผู้จ่ายเดิมพันเริ่มต้นและไทเกอร์ที่ชนะทั้งหมด 3 หลังจากตกลงเดิม

ZZxmzn said...

$2/$3 No-Limit Hold’em อาจมีการซื้อเข้าขั้นต่ำ $40 และสูงสุด $300 ในเวลาใดก็ได้ในระหว่างเกม คุณสามารถ "เติมเงิน" และเติมสแต็คของคุณกลับขึ้นไปที่บายอินสูงสุด เว็บสล็อตแท้ หากต้องการซื้อชิปที่โต๊ะ โดยทั่วไปคุณสามารถวางเงินสดไว้บนโต๊ะแล้วบอกดีลเลอร์ที่คุณต้องการ ซื้อชิป คุณสามารถลุกขึ้นและออกจากโต๊ะได้ตลอดเวลา มองหากรงแคชเชียร์เพื่อแปลงชิปโป๊กเกอร์ของคุณ

ZZxmzn said...

อึดอัด เขามองดูนาฬิกาและขอให้ดีลเลอร์รีบขึ้นในขณะที่ถอนหายใจทุกครั้งที่ต้องหมอบพรีฟลอป คุณไม่จำเป็นต้องเป็นนักอ่านความคิดเพื่อรู้ว่าคู่ต่อสู้ของคุณต้องจากไป สล็อตเว็บตรงแท้ เนื่องจากเขามีแนวโน้มที่จะไล่ตามการสูญเสียหรือพยายามที่จะเติมเต็ม การแก้ไขการพนันของเขา คุณสามารถใช้ประโยชน์จากความโกรธเคืองของเขาโดยการเดิมพันแบบคุ้มค่ามากขึ้นและเบาบางลง หากเขากำลังไล่ตามความสูญเสีย เขาจะไม่อยู่ในอารมณ์พับ หากเขายังไม่ได้รับการแก้ไข การ

ZZxmzn said...

กองไว้ในวิธีที่ใช้งานได้จริงและเพื่อให้ผู้เล่นคนอื่นสามารถทราบจำนวนชิปของคุณได้ ไม่ คุณไม่ได้ให้ข้อมูลที่มีค่าโดยบอกจำนวนชิปของคุณ ทุกคนที่โต๊ะควรจะรู้ว่าเขาอยู่ที่ไหน รวมถึงคุณด้วย การไม่เป็นระเบียบด้วยชิปของคุณจะทำให้เกมช้าลงและทำให้คุณดูโง่ไปหน่อย อย่าแสดงความคิดเห็นเกี่ยวกับมือที่กำลังเล่นอยู่หากคุณไม่ได้อยู่ในนั้น สล็อตpgแท้ คุณเป็นผู้เล่น ไม่ใช่นอร์แมน ชาด การแสดงความคิดเห็นเกี่ยวกับมือของผู้อื่นอาจถูกมองว่าเป็นการสมรู้ร่วมคิดและอาจเปลี่ยนผลลัพธ์ของมือได้ สิ่งนี้เกิดขึ้นบ่อยครั้งใน WSOP, EPT และทัวร์นา

ZZxmzn said...

เล่นตั้งแต่ 1 ถึง 8 คนจะเล่นพร้อมกัน และเมื่อดีลเลอร์/เจ้ามือการพนันเรียกร้องให้วางเดิมพัน ลูกบอลจะ วางบนวงล้อรูเล็ตและหมุน เมื่อลูกบอลเหลืออีก 2 รอบ เจ้ามือการพนันจะประกาศว่าจะไม่ยอมรับการเดิมพันอีกต่อไป เจ้ามือการพนันจะขานหมายเลขที่ชนะเมื่อลูกบอลหยุดและตกลงในช่องใดก็ได้จาก 37 ช่อง เว็บสล็อตแท้ การเดิมพันที่แพ้จะมอบให้เจ้ามือ และการเดิมพันที่ชนะทั้งหมดจะจ่ายให้

ZZxmzn said...

กายแบบลำลองได้ แต่ควรหลีกเลี่ยงรองเท้าที่ไม่เหมาะสม เช่น รองเท้าแตะ รองเท้าผ้าใบหรือรองเท้าแตะ หรือชุดกีฬาและกางเกงยีนส์ อนุญาตให้แต่งกายลำลองในห้อง Salle Europe ระหว่างเวลา 14:00 น. - 19:00 น. แต่ควรปฏิบัติตามข้อจำกัดเดียวกันกับรองเท้า ชุดกีฬา สล็อตเว็บตรงpg และกางเกงยีนส์ ในช่วงเย็น สุภาพบุรุษควรสวมแจ็กเก็ตและรองเท้าอัจฉริยะ ส่วนสุภาพสตรีสามารถ สวมชุดราตรี

ZZxmzn said...

แล้วพยายามทำแต้มก่อนเจ็ด เช่นเดียวกับผู้เล่นก่อนหน้าการเดิมพันในแครปส์และกลยุทธ์แครปส์ เมื่อเล่นแคร็ปส์ การเดิมพันแครปส์ที่พบมากที่สุด ได้แก่ การวางเดิมพันแบบพาสไลน์ การเดิมพันแบบฮาร์ดเวย์ เว็บสล็อตแท้ และแครปส์แอนด์อีเลฟเว่น ด้านล่างนี้เป็นเงื่อนไขการเดิมพันหลายข้อที่คุณควรทำความคุ้นเคยในขณะที่เล่น craps.Pass Line Bet: ผู้เล่นกำลังเดิมพันว่าในม้วนแรก 7 หรือ 11 ม้วนจะชนะ 2, 3 หรือ 12 แพ้ หากเป็นตัวเลขเช่น: 4, 5, 6, 8, 9 หรือ 10 การหมุน

ZZxmzn said...

อพาร์ตเมนต์พร้อมบริการอินเทอร์เน็ต อาจไม่สามารถเปลี่ยนผู้ให้บริการอินเทอร์เน็ต (ISP) ได้ อีกทางหนึ่ง คุณอาจอาศัยอยู่ในพื้นที่ที่ให้บริการโดย ISP หนึ่งรายเท่านั้น สล็อตพีจีเว็บตรง หรือมีผู้ให้บริการหลายรายซึ่งล้วนให้บริการที่ไม่ดี สุดท้าย คุณอาจต้องพึ่งพาผู้ให้บริการมือถือที่ดีซึ่งมีความครอบคลุมในพื้นที่เฉพาะของคุณไม่ดี ในกรณีเหล่านี้และบางกรณีซึ่งการให้บริการเองเป็นปัญหา อาจไม่มี

ZZxmzn said...

สก์ท็อป ให้แรงม้าเพียงพอสำหรับการเล่นเกมการพนันส่วนใหญ่ แม้ว่าคุณจะซื้อสินค้าได้เฉพาะที่ Walmart หรือ Target คุณก็ยังมีโอกาสพบคอมพิวเตอร์ราคาถูกที่สามารถใช้งานรายการโปรดทั้งหมดของคุณได้ สล็อตpgแท้ อย่างไรก็ตาม เพียงเพราะเกมเหล่านี้ดำเนินอยู่ ไม่ได้หมายความว่าประสบการณ์จะสมบูรณ์แบบหรือในบางกรณีก็สนุกที่จะเล่น นั่นเป็นเหตุผลที่เราได้รวบรวมรายละเอียดสั้นๆ ของสิ่งที่ควรมองหาในคอมพิวเตอร์เดสก์ท็อปหรือแล็ปท็อป สิ่งที่ควรมองหา