{"id":531,"date":"2015-03-08T01:03:34","date_gmt":"2015-03-07T16:03:34","guid":{"rendered":"https:\/\/fugutabetai.com\/blog\/2015\/03\/08\/profiling-in-java\/"},"modified":"2015-03-08T01:03:34","modified_gmt":"2015-03-07T16:03:34","slug":"profiling-in-java","status":"publish","type":"post","link":"https:\/\/fugutabetai.com\/blog\/2015\/03\/08\/profiling-in-java\/","title":{"rendered":"Profiling in Java"},"content":{"rendered":"<p>I&#8217;ve recently started doing some manga translation again, but what that means is that I&#8217;ve tried to get my <a href=\"http:\/\/fugutabetai.com\/software\/GMAO\/\">GMAO program<\/a> running on my newer MacBook.  Just trying to run the OSX app that I packaged a few years back brought up a dialog box asking me to install the 1.6 JRE.  I don&#8217;t really want to do that, we&#8217;re in the 21st century now, and I want to run Java 1.8.  So I downloaded that JRE.  Still, I get the message.  It turns out that the type of launcher I use (info.plist XML or whatever) is the style that Apple supported which only works with their JRE, which is only available to 1.6.  And is more or less deprecated now.  <\/p>\n<p\/>\n<p>So I found out that if I download the JDK (and just the JRE) I get the command line tools, and then I can pretty easily start up GMAO from the command line from the .app.  Which still is far from ideal, so I guess I need to re-package it to use the new launcher format.  First though, since I can at least run GMAO on the new laptop, I started to do some translation.  Great.<\/p>\n<p\/>\n<p>Except, it takes about three minutes (wall clock minutes) to load a new image.  That is terrible.  It used to take on the order of seconds, if that.  So I guess there is something in the APIs that have changed to make whatever I&#8217;m doing super slow &#8211; I know my code doesn&#8217;t do anything that should take that long.  So I&#8217;ll have to track that down.  <\/p>\n<p\/>\n<p>I installed Eclipse and copied my code over.  Wow, over 800 warnings.  Mostly about non-parameterized types.  I should probably fix those.  I&#8217;m able to compile under Java 1.8 though, so that is good.  <\/p>\n<p\/>\n<p>Where is all that time going when I load an image?  Let&#8217;s try to profiling.  So, I try to use <a href=\"http:\/\/docs.oracle.com\/javase\/8\/docs\/technotes\/tools\/windows\/jvisualvm.html\">jvisualvm<\/a>.  I can look at the heap and stuff, but CPU profiling is not supported:  &#8220;failed to create jmx connection to target application&#8221;.  I tried many things, but I just couldn&#8217;t get things working.  I enabled some logging and a net connection was timing out.<\/p>\n<p\/>\n<p>RMI uses two ports for communication, which is pretty dumb if you are behind a firewall.  Anyway, I don&#8217;t think that was the problem here, I think it was having trouble finding the host to get the RMI information from. <\/p>\n<p\/>\n<p>Finally I found some java options that I could use to get the connection to work.  On the JVM running the app I want to profile:<\/p>\n<pre>\r\njava -Xmx2048m -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=3333 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=localhost -Dcom.sun.management.jmxremote.rmi.port=3334 -classpath $CP com.FuguTabetai.GMAO.GMAOGUI\r\n<\/pre>\n<p>I was able to start up jvisualvm and connect to the JVM that way.  The profiling was helpful, but didn&#8217;t get me as far as I wanted.  By the way, if you are on OSX and want to start jvisualvm you can just use jvisualvm, but to run Java Mission Control I had to find out where that binary was: <\/p>\n<pre>\r\nfind \/Library\/Java -name jmc\r\n\/Library\/Java\/JavaVirtualMachines\/jdk1.8.0_31.jdk\/Contents\/Home\/bin\/jmc\r\n\/Library\/Java\/JavaVirtualMachines\/jdk1.8.0_31.jdk\/Contents\/Home\/lib\/missioncontrol\/Java Mission Control.app\/Contents\/MacOS\/jmc\r\n<\/pre>\n<p>Here are some other interesting notes.  Using the HPROF option just showed me some garbage, it isn&#8217;t accurate.  See <a href=\"http:\/\/www.brendangregg.com\/blog\/2014-06-09\/java-cpu-sampling-using-hprof.html\">this excellent post for more information about that<\/a>.  <a href=\"https:\/\/blogs.oracle.com\/jmxetc\/entry\/troubleshooting_connection_problems_in_jconsole\">This post was super helpful in tracking down my connection problems with JMX<\/a>.  <a href=\"http:\/\/jeremymanson.blogspot.co.uk\/2013\/07\/lightweight-asynchronous-sampling.html\">Google might have a nice lightweight java profiler<\/a> but I haven&#8217;t read that yet.  <a href=\"http:\/\/stackoverflow.com\/questions\/151238\/has-anyone-ever-got-a-remote-jmx-jconsole-to-work\">This stackoverflow post pointed me in the right direction for finding the critical java.rmi.server.hostname parameter<\/a> (and maybe com.sun.management.jmxremote.rmi.port.)  I&#8217;ll probably need to look more into how to <a href=\"https:\/\/devreboot.wordpress.com\/2014\/03\/30\/java-mac-os-x-app-bundle-machinations\/\">do Java app bundles<\/a> in this brave new Java 1.8 world. <\/p>\n<p><br clear=\"all\"\/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve recently started doing some manga translation again, but what that means is that I&#8217;ve tried to get my GMAO program running on my newer MacBook. Just trying to run the OSX app that I packaged a few years back brought up a dialog box asking me to install the 1.6 JRE. I don&#8217;t really [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[5],"tags":[],"_links":{"self":[{"href":"https:\/\/fugutabetai.com\/blog\/wp-json\/wp\/v2\/posts\/531"}],"collection":[{"href":"https:\/\/fugutabetai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fugutabetai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fugutabetai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fugutabetai.com\/blog\/wp-json\/wp\/v2\/comments?post=531"}],"version-history":[{"count":0,"href":"https:\/\/fugutabetai.com\/blog\/wp-json\/wp\/v2\/posts\/531\/revisions"}],"wp:attachment":[{"href":"https:\/\/fugutabetai.com\/blog\/wp-json\/wp\/v2\/media?parent=531"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fugutabetai.com\/blog\/wp-json\/wp\/v2\/categories?post=531"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fugutabetai.com\/blog\/wp-json\/wp\/v2\/tags?post=531"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}