[prev in list] [next in list] [prev in thread] [next in thread] 

List:       openjdk-serviceability-dev
Subject:    RE: javaone 2012 presentation on Diagnosing Your Application on the JVM : Question on attach on Wind
From:       "Bacchu, Anjan" <anjan.bacchu () hpe ! com>
Date:       2016-03-31 11:30:39
Message-ID: F53B76A14E75764283B3CFF6D24B9DCD0FDA672C () G4W3205 ! americas ! hpqcorp ! net
[Download RAW message or body]

[Attachment #2 (text/plain)]

Hi Staffan,

      Thank you very much for the presentation and the quick response.

      Jcmd/jmap : Unfortunately, we ship only the Client JRE with our product. \
Customer doesn't have access to jcmd/jmap. That's why I was looking for an outside \
solution.

Then I came across https://github.com/apangin/jattach – however this is only for \
linux/bsd. I wanted to use "HotSpot Dynamic Attach Mechanism" to dump the heap on \
Windows by writing a similar utility for windows.

Thanks again,

BR,
~A




From: Staffan Larsen [mailto:staffan.larsen@oracle.com]
Sent: Thursday, March 31, 2016 12:53 AM
To: Bacchu, Anjan <anjan.bacchu@hpe.com>
Cc: serviceability-dev@openjdk.java.net
Subject: Re: javaone 2012 presentation on Diagnosing Your Application on the JVM : \
Question on attach on Windows


On 30 mars 2016, at 09:40, Bacchu, Anjan \
<anjan.bacchu@hpe.com<mailto:anjan.bacchu@hpe.com>> wrote:

Hi Staffan,

      I just now saw the presentation slides at \
http://www.slideshare.net/stalar/diagnosing-your-application-on-the-jvm.

On Slide 16 of the presentation, you show the details of the "HotSpot Dynamic Attach \
Mechanism" for Windows.

1)  You talk about Remote process injecting code into the JVM using combination of \
VirtualAllocEx and 2)  WriteProcessMemory. Further it goes ahead and creates a Remote \
thread in the JVM to call above code.


Do you have some sample code which does this, to say, dump the heap ?

If you want to dump the heap, take a look at "jcmd <pid> GC.heap_dump":

----------
Generate a HPROF format dump of the Java heap.

Impact: High: Depends on Java heap size and content. Request a full GC unless the \
'-all' option is specified.

Permission: java.lang.management.ManagementPermission(monitor)

Syntax : GC.heap_dump [options] <filename>

Arguments:
            filename :  Name of the dump file (STRING, no default value)

Options: (options must be specified using the <key> or <key>=<value> syntax)
            -all : [optional] Dump all objects, including unreachable objects \
                (BOOLEAN, false)
----------

You can also use "jmap -dump <pid>.



I used to develop windows application long ago and just from the slide #16 \
andhttp://openjdk.java.net/groups/hotspot/docs/Serviceability.html#battach, I'm \
unable to proceed further.

The source code is in the VirtualMachineImpl.c file for windows: \
http://hg.openjdk.java.net/jdk9/jdk9/jdk/file/1565a0efe6f0/src/jdk.attach/windows/native/libattach/VirtualMachineImpl.c






All help will be useful.

Thank you very much,

BR,
~A


[Attachment #3 (text/html)]

<html xmlns:v="urn:schemas-microsoft-com:vml" \
xmlns:o="urn:schemas-microsoft-com:office:office" \
xmlns:w="urn:schemas-microsoft-com:office:word" \
xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" \
xmlns="http://www.w3.org/TR/REC-html40"> <head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
	{font-family:"Cambria Math";
	panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
	{font-family:Calibri;
	panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
	{font-family:Inconsolata;
	panose-1:2 11 6 9 3 0 3 0 0 0;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
	{margin:0in;
	margin-bottom:.0001pt;
	font-size:12.0pt;
	font-family:"Times New Roman",serif;}
a:link, span.MsoHyperlink
	{mso-style-priority:99;
	color:blue;
	text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
	{mso-style-priority:99;
	color:purple;
	text-decoration:underline;}
span.apple-converted-space
	{mso-style-name:apple-converted-space;}
span.apple-tab-span
	{mso-style-name:apple-tab-span;}
span.EmailStyle19
	{mso-style-type:personal-reply;
	font-family:Inconsolata;
	color:#1F497D;}
.MsoChpDefault
	{mso-style-type:export-only;
	font-size:10.0pt;}
@page WordSection1
	{size:8.5in 11.0in;
	margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
	{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:Inconsolata;color:#1F497D">Hi \
Staffan,<o:p></o:p></span></p> <p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:Inconsolata;color:#1F497D"><o:p>&nbsp;</o:p></span></p>
 <p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:Inconsolata;color:#1F497D">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
Thank you very much for the presentation and the quick \
response.<o:p></o:p></span></p> <p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:Inconsolata;color:#1F497D"><o:p>&nbsp;</o:p></span></p>
 <p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:Inconsolata;color:#1F497D">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
Jcmd/jmap : Unfortunately, we ship only the Client JRE with our product. Customer \
doesn't have access to jcmd/jmap. That's why I was looking for an outside \
solution.<o:p></o:p></span></p> <p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:Inconsolata;color:#1F497D"><o:p>&nbsp;</o:p></span></p>
 <p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:Inconsolata;color:#1F497D">Then I came across <a \
href="https://github.com/apangin/jattach">https://github.com/apangin/jattach</a> \
</span><span style="font-size:11.0pt;font-family:&quot;Courier \
New&quot;;color:#1F497D">–</span><span \
style="font-size:11.0pt;font-family:Inconsolata;color:#1F497D"> however this is only \
for linux/bsd. I wanted to use "</span><span \
style="font-size:11.0pt;font-family:Inconsolata">HotSpot  Dynamic Attach \
Mechanism</span><span \
style="font-size:11.0pt;font-family:Inconsolata;color:#1F497D">" to dump the heap on \
Windows by writing a similar utility for windows.<o:p></o:p></span></p> <p \
class="MsoNormal"><span \
style="font-size:11.0pt;font-family:Inconsolata;color:#1F497D"><o:p>&nbsp;</o:p></span></p>
 <p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:Inconsolata;color:#1F497D">Thanks \
again,<o:p></o:p></span></p> <p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:Inconsolata;color:#1F497D"><o:p>&nbsp;</o:p></span></p>
 <p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:Inconsolata;color:#1F497D">BR,<o:p></o:p></span></p>
 <p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:Inconsolata;color:#1F497D">~A<o:p></o:p></span></p>
 <p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:Inconsolata;color:#1F497D"><o:p>&nbsp;</o:p></span></p>
 <p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:Inconsolata;color:#1F497D"><o:p>&nbsp;</o:p></span></p>
 <p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:Inconsolata;color:#1F497D">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 <o:p></o:p></span></p>
<p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:Inconsolata;color:#1F497D"><o:p>&nbsp;</o:p></span></p>
 <div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif">From:</span></b><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif"> Staffan Larsen \
[mailto:staffan.larsen@oracle.com] <br>
<b>Sent:</b> Thursday, March 31, 2016 12:53 AM<br>
<b>To:</b> Bacchu, Anjan &lt;anjan.bacchu@hpe.com&gt;<br>
<b>Cc:</b> serviceability-dev@openjdk.java.net<br>
<b>Subject:</b> Re: javaone 2012 presentation on Diagnosing Your Application on the \
JVM : Question on attach on Windows<o:p></o:p></span></p> </div>
</div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
<div>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<div>
<p class="MsoNormal">On 30 mars 2016, at 09:40, Bacchu, Anjan &lt;<a \
href="mailto:anjan.bacchu@hpe.com">anjan.bacchu@hpe.com</a>&gt; wrote:<o:p></o:p></p> \
</div> <p class="MsoNormal"><o:p>&nbsp;</o:p></p>
<div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:Inconsolata">Hi \
Staffan,</span><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif"><o:p></o:p></span></p>
 </div>
<div>
<p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:Inconsolata">&nbsp;</span><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif"><o:p></o:p></span></p>
 </div>
<div>
<p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:Inconsolata">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; I \
just now saw the presentation slides at<span \
class="apple-converted-space">&nbsp;</span><a \
href="http://www.slideshare.net/stalar/diagnosing-your-application-on-the-jvm"><span \
style="color:#954F72">http://www.slideshare.net/stalar/diagnosing-your-application-on-the-jvm</span></a>.</span><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif"><o:p></o:p></span></p>
 </div>
<div>
<p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:Inconsolata">&nbsp;</span><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif"><o:p></o:p></span></p>
 </div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:Inconsolata">On Slide \
16 of the presentation, you show the details of the "HotSpot Dynamic Attach \
Mechanism" for Windows.</span><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif"><o:p></o:p></span></p>
 </div>
<div>
<p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:Inconsolata">&nbsp;</span><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif"><o:p></o:p></span></p>
 </div>
<div style="margin-left:.5in">
<p class="MsoNormal" style="text-indent:-.25in"><span \
style="font-size:11.0pt;font-family:Inconsolata">1)</span><span \
style="font-size:7.0pt">&nbsp;<span \
class="apple-converted-space">&nbsp;</span></span><span \
style="font-size:11.0pt;font-family:Inconsolata">You talk  about Remote process \
injecting code into the JVM using combination of VirtualAllocEx and</span><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif"><o:p></o:p></span></p>
 </div>
<div style="margin-left:.5in">
<p class="MsoNormal" style="text-indent:-.25in"><span \
style="font-size:11.0pt;font-family:Inconsolata">2)</span><span \
style="font-size:7.0pt">&nbsp;<span \
class="apple-converted-space">&nbsp;</span></span><span \
style="font-size:11.0pt;font-family:Inconsolata">WriteProcessMemory.  Further it goes \
ahead and creates a Remote thread in the JVM to call above code.</span><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif"><o:p></o:p></span></p>
 </div>
<div>
<p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:Inconsolata">&nbsp;</span><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif"><o:p></o:p></span></p>
 </div>
<div>
<p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:Inconsolata">&nbsp;</span><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif"><o:p></o:p></span></p>
 </div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:Inconsolata">Do you \
have some sample code which does this, to say, dump the heap ?</span><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif"><o:p></o:p></span></p>
 </div>
</div>
</blockquote>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
<div>
<p class="MsoNormal">If you want to dump the heap, take a look at "jcmd \
&lt;pid&gt;&nbsp;GC.heap_dump":&nbsp;<o:p></o:p></p> </div>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
<div>
<p class="MsoNormal">----------<o:p></o:p></p>
<div>
<p class="MsoNormal">Generate a HPROF format dump of the Java heap.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
<div>
<p class="MsoNormal">Impact: High: Depends on Java heap size and content. Request a \
full GC unless the '-all' option is specified.<o:p></o:p></p> </div>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
<div>
<p class="MsoNormal">Permission: \
java.lang.management.ManagementPermission(monitor)<o:p></o:p></p> </div>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
<div>
<p class="MsoNormal">Syntax : GC.heap_dump [options] &lt;filename&gt;<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
<div>
<p class="MsoNormal">Arguments:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span \
class="apple-tab-span">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
</span>filename : &nbsp;Name of the dump file (STRING, no default \
value)<o:p></o:p></p> </div>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
<div>
<p class="MsoNormal">Options: (options must be specified using the &lt;key&gt; or \
&lt;key&gt;=&lt;value&gt; syntax)<o:p></o:p></p> </div>
<div>
<p class="MsoNormal"><span \
class="apple-tab-span">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
</span>-all : [optional] Dump all objects, including unreachable objects (BOOLEAN, \
false)<o:p></o:p></p> </div>
<div>
<p class="MsoNormal">----------<o:p></o:p></p>
</div>
</div>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
<div>
<p class="MsoNormal">You can also use "jmap -dump &lt;pid&gt;.<o:p></o:p></p>
</div>
<p class="MsoNormal"><br>
<br>
<o:p></o:p></p>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<div>
<div>
<p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:Inconsolata">&nbsp;</span><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif"><o:p></o:p></span></p>
 </div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:Inconsolata">I used to \
develop windows application long ago and just from the slide #16 and<a \
href="http://openjdk.java.net/groups/hotspot/docs/Serviceability.html#battach"><span \
style="color:#954F72">http://openjdk.java.net/groups/hotspot/docs/Serviceability.html#battach</span></a>,
  I'm unable to proceed further.</span><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif"><o:p></o:p></span></p>
 </div>
</div>
</blockquote>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
<div>
<p class="MsoNormal">The source code is in the VirtualMachineImpl.c file for \
windows:&nbsp;<a href="http://hg.openjdk.java.net/jdk9/jdk9/jdk/file/1565a0efe6f0/src/ \
jdk.attach/windows/native/libattach/VirtualMachineImpl.c">http://hg.openjdk.java.net/j \
dk9/jdk9/jdk/file/1565a0efe6f0/src/jdk.attach/windows/native/libattach/VirtualMachineImpl.c</a><o:p></o:p></p>
 </div>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
<p class="MsoNormal"><br>
<br>
<o:p></o:p></p>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<div>
<div>
<p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:Inconsolata">&nbsp;</span><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif"><o:p></o:p></span></p>
 </div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:Inconsolata">All help \
will be useful.</span><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif"><o:p></o:p></span></p>
 </div>
<div>
<p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:Inconsolata">&nbsp;</span><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif"><o:p></o:p></span></p>
 </div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:Inconsolata">Thank you \
very much,</span><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif"><o:p></o:p></span></p>
 </div>
<div>
<p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:Inconsolata">&nbsp;</span><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif"><o:p></o:p></span></p>
 </div>
<div>
<p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:Inconsolata">BR,</span><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif"><o:p></o:p></span></p>
 </div>
<div>
<p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:Inconsolata">~A</span><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif"><o:p></o:p></span></p>
 </div>
</div>
</blockquote>
</div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
</body>
</html>



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic