[prev in list] [next in list] [prev in thread] [next in thread]
List: openjdk-serviceability-dev
Subject: RFR(L): 8056049: getProcessCpuLoad() stops working in one process when a different process exits
From: Markus Grönlund <markus.gronlund () oracle ! com>
Date: 2014-10-22 9:43:49
Message-ID: d040c10a-9198-427b-8f90-d7fc0acf65fb () default
[Download RAW message or body]
Greetings,
Kindly asking for reviews for the following changeset.
Bug: https://bugs.openjdk.java.net/browse/JDK-8056049
Webrev: http://cr.openjdk.java.net/~mgronlun/8056049/webrev01/
Description:
The issue is Windows specific. And the problem relates to using the Performance Data \
Helper API (PDH), more specifically how to use the "Process" PDH object in PDH \
queries:
// code comment extract
/*
* Working against the Process object and it's related counters is inherently \
problematic
* when using the PDH API:
*
* For PDH, a process is not primarily identified by it's process id,
* but with a sequential number, for example \Process(java#0), \Process(java#1), ....
* The really bad part is that this list is reset as soon as one process exits:
* If \Process(java#1) exits, \Process(java#3) now becomes \Process(java#2) etc.
*
* The PDH query api requires a process identifier to be submitted when registering
* a query, but as soon as the list resets, the query is invalidated (since the name
* changed).
*
* Solution:
* The #number identifier for a Process query can only decrease after process \
creation.
*
* Therefore we create an array of counter queries for all process object instances
* up to and including ourselves:
*
* Ex. we come in as third process instance (java#2), we then create and register
* queries for the following Process object instances:
* java#0, java#1, java#2
*
* currentQueryIndexForProcess() keeps track of the current "correct" query
* (in order to keep this index valid when the list resets from underneath,
* ensure to call getCurrentQueryIndexForProcess() before every query involving
* Process object instance data).
*/
I have already fixed this in the VM as of \
https://bugs.openjdk.java.net/browse/JDK-8019921
In the process of fixing this issue now in the JDK, I realized that the previous \
implementation of using PDH in the JDK was a bit convoluted - especially if you would \
like to reuse functionality / add new counters.
Therefore this change also includes an overall rewrite of the how the JDK will \
interface with the PDH library, a rewrite of which (hopefully) improves both \
readability and extensibility.
I can do a code walkthrough live if anyone is interested to know the exact details of \
this change.
Testing completed : Testset SVC (includes jdk_instrument, jdk_management, jdk_jmx, \
jdk_jdi)
Thanks in advance
Markus
[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=iso-8859-1"><meta name=Generator content="Microsoft Word \
12 (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:Consolas;
panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri","sans-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.EmailStyle17
{mso-style-type:personal-compose;
font-family:"Calibri","sans-serif";
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:70.85pt 70.85pt 70.85pt 70.85pt;}
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=SV link=blue vlink=purple><div \
class=WordSection1><p class=MsoNormal><span \
lang=EN-US>Greetings,<o:p></o:p></span></p><p class=MsoNormal><span \
lang=EN-US><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US>Kindly \
asking for reviews for the following changeset.<o:p></o:p></span></p><p \
class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><p class=MsoNormal><span \
lang=EN-US>Bug: <a href="https://bugs.openjdk.java.net/browse/JDK-8056049">https://bugs.openjdk.java.net/browse/JDK-8056049</a> \
<o:p></o:p></span></p><p class=MsoNormal>Webrev: <a \
href="http://cr.openjdk.java.net/~mgronlun/8056049/webrev01/">http://cr.openjdk.java.net/~mgronlun/8056049/webrev01/</a> \
<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p \
class=MsoNormal>Description:<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p \
class=MsoNormal><span lang=EN-US>The issue is Windows specific. And the problem \
relates to using the Performance Data Helper API (PDH), more specifically how to use \
the “Process” PDH object in PDH queries:<o:p></o:p></span></p><p \
class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><p class=MsoNormal><span \
lang=EN-US>// code comment extract<o:p></o:p></span></p><p class=MsoNormal><span \
lang=EN-US><o:p> </o:p></span></p><p class=MsoNormal \
style='text-autospace:none'><span lang=EN-US \
style='font-size:9.5pt;font-family:Consolas;color:green'>/*</span><span lang=EN-US \
style='font-size:9.5pt;font-family:Consolas'><o:p></o:p></span></p><p class=MsoNormal \
style='text-autospace:none'><span lang=EN-US \
style='font-size:9.5pt;font-family:Consolas;color:green'> * Working against the \
Process object and it's related counters is inherently problematic</span><span \
lang=EN-US style='font-size:9.5pt;font-family:Consolas'><o:p></o:p></span></p><p \
class=MsoNormal style='text-autospace:none'><span lang=EN-US \
style='font-size:9.5pt;font-family:Consolas;color:green'> * when using the PDH \
API:</span><span lang=EN-US \
style='font-size:9.5pt;font-family:Consolas'><o:p></o:p></span></p><p class=MsoNormal \
style='text-autospace:none'><span lang=EN-US \
style='font-size:9.5pt;font-family:Consolas;color:green'> *</span><span lang=EN-US \
style='font-size:9.5pt;font-family:Consolas'><o:p></o:p></span></p><p class=MsoNormal \
style='text-autospace:none'><span lang=EN-US \
style='font-size:9.5pt;font-family:Consolas;color:green'> * For PDH, a process is not \
primarily identified by it's process id,</span><span lang=EN-US \
style='font-size:9.5pt;font-family:Consolas'><o:p></o:p></span></p><p class=MsoNormal \
style='text-autospace:none'><span lang=EN-US \
style='font-size:9.5pt;font-family:Consolas;color:green'> * but with a sequential \
number, for example \Process(java#0), \Process(java#1), ....</span><span lang=EN-US \
style='font-size:9.5pt;font-family:Consolas'><o:p></o:p></span></p><p class=MsoNormal \
style='text-autospace:none'><span lang=EN-US \
style='font-size:9.5pt;font-family:Consolas;color:green'> * The really bad part is \
that this list is reset as soon as one process exits:</span><span lang=EN-US \
style='font-size:9.5pt;font-family:Consolas'><o:p></o:p></span></p><p class=MsoNormal \
style='text-autospace:none'><span lang=EN-US \
style='font-size:9.5pt;font-family:Consolas;color:green'> * If \Process(java#1) \
exits, \Process(java#3) now becomes \Process(java#2) etc.</span><span lang=EN-US \
style='font-size:9.5pt;font-family:Consolas'><o:p></o:p></span></p><p class=MsoNormal \
style='text-autospace:none'><span lang=EN-US \
style='font-size:9.5pt;font-family:Consolas;color:green'> *</span><span lang=EN-US \
style='font-size:9.5pt;font-family:Consolas'><o:p></o:p></span></p><p class=MsoNormal \
style='text-autospace:none'><span lang=EN-US \
style='font-size:9.5pt;font-family:Consolas;color:green'> * The PDH query api \
requires a process identifier to be submitted when registering</span><span lang=EN-US \
style='font-size:9.5pt;font-family:Consolas'><o:p></o:p></span></p><p class=MsoNormal \
style='text-autospace:none'><span lang=EN-US \
style='font-size:9.5pt;font-family:Consolas;color:green'> * a query, but as soon as \
the list resets, the query is invalidated (since the name</span><span lang=EN-US \
style='font-size:9.5pt;font-family:Consolas'><o:p></o:p></span></p><p class=MsoNormal \
style='text-autospace:none'><span lang=EN-US \
style='font-size:9.5pt;font-family:Consolas;color:green'> * changed).</span><span \
lang=EN-US style='font-size:9.5pt;font-family:Consolas'><o:p></o:p></span></p><p \
class=MsoNormal style='text-autospace:none'><span lang=EN-US \
style='font-size:9.5pt;font-family:Consolas;color:green'> *</span><span lang=EN-US \
style='font-size:9.5pt;font-family:Consolas'><o:p></o:p></span></p><p class=MsoNormal \
style='text-autospace:none'><span lang=EN-US \
style='font-size:9.5pt;font-family:Consolas;color:green'> * Solution:</span><span \
lang=EN-US style='font-size:9.5pt;font-family:Consolas'><o:p></o:p></span></p><p \
class=MsoNormal style='text-autospace:none'><span lang=EN-US \
style='font-size:9.5pt;font-family:Consolas;color:green'> * The #number identifier \
for a Process query can only decrease after process creation.</span><span lang=EN-US \
style='font-size:9.5pt;font-family:Consolas'><o:p></o:p></span></p><p class=MsoNormal \
style='text-autospace:none'><span lang=EN-US \
style='font-size:9.5pt;font-family:Consolas;color:green'> *</span><span lang=EN-US \
style='font-size:9.5pt;font-family:Consolas'><o:p></o:p></span></p><p class=MsoNormal \
style='text-autospace:none'><span lang=EN-US \
style='font-size:9.5pt;font-family:Consolas;color:green'> * Therefore we create an \
array of counter queries for all process object instances</span><span lang=EN-US \
style='font-size:9.5pt;font-family:Consolas'><o:p></o:p></span></p><p class=MsoNormal \
style='text-autospace:none'><span lang=EN-US \
style='font-size:9.5pt;font-family:Consolas;color:green'> * up to and including \
ourselves:</span><span lang=EN-US \
style='font-size:9.5pt;font-family:Consolas'><o:p></o:p></span></p><p class=MsoNormal \
style='text-autospace:none'><span lang=EN-US \
style='font-size:9.5pt;font-family:Consolas;color:green'> *</span><span lang=EN-US \
style='font-size:9.5pt;font-family:Consolas'><o:p></o:p></span></p><p class=MsoNormal \
style='text-autospace:none'><span lang=EN-US \
style='font-size:9.5pt;font-family:Consolas;color:green'> * Ex. we come in as third \
process instance (java#2), we then create and register</span><span lang=EN-US \
style='font-size:9.5pt;font-family:Consolas'><o:p></o:p></span></p><p class=MsoNormal \
style='text-autospace:none'><span lang=EN-US \
style='font-size:9.5pt;font-family:Consolas;color:green'> * queries for the following \
Process object instances:</span><span lang=EN-US \
style='font-size:9.5pt;font-family:Consolas'><o:p></o:p></span></p><p class=MsoNormal \
style='text-autospace:none'><span lang=EN-US \
style='font-size:9.5pt;font-family:Consolas;color:green'> * java#0, java#1, \
java#2</span><span lang=EN-US \
style='font-size:9.5pt;font-family:Consolas'><o:p></o:p></span></p><p class=MsoNormal \
style='text-autospace:none'><span lang=EN-US \
style='font-size:9.5pt;font-family:Consolas;color:green'> *</span><span lang=EN-US \
style='font-size:9.5pt;font-family:Consolas'><o:p></o:p></span></p><p class=MsoNormal \
style='text-autospace:none'><span lang=EN-US \
style='font-size:9.5pt;font-family:Consolas;color:green'> * \
currentQueryIndexForProcess() keeps track of the current "correct" \
query</span><span lang=EN-US \
style='font-size:9.5pt;font-family:Consolas'><o:p></o:p></span></p><p class=MsoNormal \
style='text-autospace:none'><span lang=EN-US \
style='font-size:9.5pt;font-family:Consolas;color:green'> * (in order to keep this \
index valid when the list resets from underneath,</span><span lang=EN-US \
style='font-size:9.5pt;font-family:Consolas'><o:p></o:p></span></p><p class=MsoNormal \
style='text-autospace:none'><span lang=EN-US \
style='font-size:9.5pt;font-family:Consolas;color:green'> * ensure to call \
getCurrentQueryIndexForProcess() before every query involving</span><span lang=EN-US \
style='font-size:9.5pt;font-family:Consolas'><o:p></o:p></span></p><p class=MsoNormal \
style='text-autospace:none'><span lang=EN-US \
style='font-size:9.5pt;font-family:Consolas;color:green'> </span><span \
style='font-size:9.5pt;font-family:Consolas;color:green'>* Process object instance \
data).</span><span style='font-size:9.5pt;font-family:Consolas'><o:p></o:p></span></p><p \
class=MsoNormal style='text-autospace:none'><span \
style='font-size:9.5pt;font-family:Consolas;color:green'> */<o:p></o:p></span></p><p \
class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><p class=MsoNormal><span \
lang=EN-US>I have already fixed this in the VM as of <a \
href="https://bugs.openjdk.java.net/browse/JDK-8019921">https://bugs.openjdk.java.net/browse/JDK-8019921</a> \
<o:p></o:p></span></p><p class=MsoNormal><span \
lang=EN-US><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US>In the \
process of fixing this issue now in the JDK, I realized that the previous \
implementation of using PDH in the JDK was a bit convoluted – especially if you \
would like to reuse functionality / add new counters.<o:p></o:p></span></p><p \
class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><p class=MsoNormal><span \
lang=EN-US>Therefore this change also includes an overall rewrite of the how the JDK \
will interface with the PDH library, a rewrite of which (hopefully) improves both \
readability and extensibility.<o:p></o:p></span></p><p class=MsoNormal><span \
lang=EN-US><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US>I can do a \
code walkthrough live if anyone is interested to know the exact details of this \
change.<o:p></o:p></span></p><p class=MsoNormal><span \
lang=EN-US><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US>Testing \
completed : Testset SVC (includes jdk_instrument, jdk_management, jdk_jmx, \
jdk_jdi)<o:p></o:p></span></p><p class=MsoNormal><span \
lang=EN-US><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US>Thanks in \
advance<o:p></o:p></span></p><p class=MsoNormal><span \
lang=EN-US>Markus<o:p></o:p></span></p><p class=MsoNormal><span \
lang=EN-US><o:p> </o:p></span></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