[PATCH] Java profiling: opagent: fwrite_unlocked failed

Maynard Johnson <[email protected]>
Newsgroups gmane.linux.oprofile
Message-ID <[email protected]>
Note: The patch below has already been committed upstream.

-----------------------------------------------------------------

Java profiling: opagent: fwrite_unlocked failed

Certain Java Virtual Machines do not provide full code information in
the JNI callbacks to oprofile's java agent library; in particular,
the code size argument may be set to zero even if the code address
is non-null. The libopagent/opagent.c:op_write_native_code function
was not properly handling this case and would print the message
   opagent: fwrite_unlocked failed
and return a -1, causing the caller to display a message like
   Error: op_write_native_code(): Success

This patch fixes that issue.

Signed-off-by: Maynard Johnson <[email protected]>
---
 libopagent/opagent.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/libopagent/opagent.c b/libopagent/opagent.c
index 59b7bb6..f280880 100644
--- a/libopagent/opagent.c
+++ b/libopagent/opagent.c
@@ -376,7 +376,9 @@ again:
 	    fwrite_unlocked(symbol_name, sz_symb_name, 1, dumpfile)) {
 		size_t expected_sz, sz;
 		expected_sz = sz = 0;
-		if (code) {
+		// Note: Some JVMs always pass size=zero, so it's not enough just to check
+		// if 'code' is non-null.
+		if (code && size) {
 			sz = fwrite_unlocked(code, size, 1, dumpfile);
 			expected_sz++;
 		}
@@ -390,7 +392,7 @@ again:
 		funlockfile(dumpfile);
 		flock(dumpfd, LOCK_UN);
 		if (sz != expected_sz) {
-			printf("opagent: fwrite_unlocked failed");
+			printf("opagent: fwrite_unlocked failed\n");
 			return -1;
 		}
 		return 0;
-- 
1.7.1


------------------------------------------------------------------------------
Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer
Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports
Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper
Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer
http://pubads.g.doubleclick.net/gampad/clk?id=154622311&iu=/4140/ostg.clktrk
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.