Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752165AbbBRIp3 (ORCPT ); Wed, 18 Feb 2015 03:45:29 -0500 Received: from mga02.intel.com ([134.134.136.20]:43738 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750989AbbBRIp2 (ORCPT ); Wed, 18 Feb 2015 03:45:28 -0500 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.09,595,1418112000"; d="scan'208";a="653690120" Message-ID: <54E450B4.6060100@intel.com> Date: Wed, 18 Feb 2015 10:43:32 +0200 From: Adrian Hunter Organization: Intel Finland Oy, Registered Address: PL 281, 00181 Helsinki, Business Identity Code: 0357606 - 4, Domiciled in Helsinki User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: Stephane Eranian CC: LKML , Arnaldo Carvalho de Melo , Peter Zijlstra , "mingo@elte.hu" , "ak@linux.intel.com" , Jiri Olsa , Namhyung Kim , Rose Belcher , Sukadev Bhattiprolu , Sonny Rao , John Mccutchan Subject: Re: [PATCH 4/4] perf tools: add JVMTI agent library References: <1423611765-18200-1-git-send-email-eranian@google.com> <1423611765-18200-5-git-send-email-eranian@google.com> <54E195CA.3010508@intel.com> In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3308 Lines: 86 On 16/02/15 22:22, Stephane Eranian wrote: > On Mon, Feb 16, 2015 at 2:01 AM, Adrian Hunter wrote: >> On 11/02/15 01:42, Stephane Eranian wrote: >>> This is a standalone JVMTI library to help profile Java jitted >>> code with perf record/perf report. The library is not installed >>> or compiled automatically by perf Makefile. It is not used >>> directly by perf. It is arch agnostic and has been tested on >>> X86 and ARM. It needs to be used with a Java runtime, such >>> as OpenJDK, as follows: >>> >>> $ java -agentpath:libjvmti.so ....... >>> >>> When used this way, java will generate a jitdump binary file in >>> $HOME/.debug/java/jit/java-jit-* >>> >>> This binary dump file contains information to help symbolize and >>> annotate jitted code. >>> >>> The next step is to inject the jitdump information into the >>> perf.data file: >>> $ perf inject -j $HOME/.debug/java/jit/java-jit-XXXX/jit-ZZZ.dump \ >>> -i perf.data -o perf.data.jitted >>> >>> This injects the MMAP records to cover the jitted code and also generates >>> one ELF image for each jitted function. The ELF images are created in the >>> same subdir as the jitdump file. The MMAP records point there too. >>> >>> Then to visualize the function or asm profile, simply use the regular >>> perf commands: >>> $ perf report -i perf.data.jitted >>> or >>> $ perf annotate -i perf.data.jitted >>> >>> JVMTI agent code adapted from OProfile's opagent code. >>> >>> Signed-off-by: Stephane Eranian >>> --- [snip] >>> + >>> +int jvmti_write_code(void *agent, char const *sym, >>> + uint64_t vma, void const *code, unsigned int const size) >>> +{ >>> + static int code_generation = 1; >>> + struct jr_code_load rec; >>> + size_t sym_len; >>> + size_t padding_count; >>> + FILE *fp = agent; >>> + int ret = -1; >>> + >>> + /* don't care about 0 length function, no samples */ >>> + if (size == 0) >>> + return 0; >>> + >>> + if (!fp) { >>> + warnx("jvmti: invalid fd in write_native_code"); >>> + return -1; >>> + } >>> + >>> + sym_len = strlen(sym) + 1; >>> + >>> + rec.p.id = JIT_CODE_LOAD; >>> + rec.p.total_size = sizeof(rec) + sym_len; >>> + padding_count = PADDING_8ALIGNED(rec.p.total_size); >>> + rec.p. total_size += padding_count; >>> + rec.p.timestamp = perf_get_timestamp(perf_fd); >> >> Do you know whether the JVM is guaranteed not to start executing the >> generated code before the return of compiled_method_load_cb(), otherwise the >> timestamp will be too late? >> > I don't know that. I did not check. > But are you saying the callback may be asynchronous with the JIT compiler? Possibly, although it seems unlikely. But perhaps there are other threads waiting for the code and it lets them go at the same time. I guess we can assume that doesn't happen. When we use it with Intel PT it will show up if the timestamp isn't before the first execution, because there will be decoder errors. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/