Re: Byte code execution count
Kenneth P. Turvey wrote On 10/23/07 11:25,:
I'm thinking about working on a project with a friend of mine, but there
are some issues that I'm not sure how to handle. I'm going to break them
into a few different posts since the issues are unrelated to each other
and people may choose to ignore some of them that way.
I understand that Java doesn't allow one to find out how much CPU time was
used by a process. That's fine. This isn't really a good measure for
what we want anyway since it would be vastly different from CPU to CPU.
What we really want is a way to measure how much work was done by a given
CPU on a given job.
What I was thinking would be a good measure was a simple count of the java
byte code instructions executed on a given machine. Is there anyway to
determine how many byte code instructions have been executed by a given
thread since it started?
I'm sure there is a way to do this with the debugging information, but I
don't want to slow down the process too much. Basically I'd like to be
able to start a thread and then wait until it exits and then ask how many
byte code instructions it processed? Any idea how one would do this?
Any other ideas on how to solve this sort of problem?
I think you're out of luck, and for more than one
reason.
First, I can think of no way to discover which of
the machine's CPU's ran which parts of your Java code.
That's difficult to do even in assembly, let alone in
Java.
Second, bytecode count is unlikely to be a very
accurate "progress" measure. Bytecode instructions
like iconst_0 are very simple, take little time, and
make little "progress." Instructions like athrow do
considerably more work, take more time, and make more
"progress" (although perhaps in reverse ...).
Finally, ask yourself how many bytecodes a method
executes after it's been JITted ...
"Progress" is really an application-specific notion,
not a machine-provided commodity. The machine can only
run the program; it can't tell whether the program is
"doing something" or just sitting in a polling loop
waiting for something else. If you want to keep track
of "progress," I think you need to establish milestones
within the application itself and count them as they pass.
--
Eric.Sosman@sun.com