Skip to main content

Posts

Showing posts from September, 2020

Dynamic Method Tracing in Java: The Implementation

In the last blog entry, I talked about the need for a tool in Java that can be configured easily to log method calls without redeploying a binary, attaching a debugger, or obtaining root in order to trace system calls. In this blog, I'll dive into some of how the tool was implemented.A caveat: I knocked this tool together in my spare time one afternoon while working on a bunch of other things, so it's a bit rough around the edges. I'm also not a particularly experienced C programmer, so apologies if my code is a bit rough. However, it's already proven useful to me, and hopefully either the tool itself or the approach will be useful to others. I found a general lack of detailed information about using JVMTI when doing research.OnLoad: Config, capabilities, events, and callbacksThe main entrypoint to a native JVMTI agent is the Agent_OnLoad function. I want to do three main things when my agent is loaded:Load the configuration file so we know which breakpoints to set.Let…

Dynamic method tracing in in Java

Are you a printf debugger? I certainly am. IDE based Debuggers (or tools like jdb / gdb) have their place, and I use them a lot too. But I often want to know when and why some function is called in contexts where attaching a debugger isn't an option.  As one example, a lot of people at my current company use IntelliJ / Android Studio. Like other large companies, we have a gigantic monorepo. Understanding how and why the IDE accesses the filesystem can help us understand performance problems. Everyone experiences slightly different behavior with the filesystem depending on what has been changed, and what's being cached. I'd like to turn on verbose logging of filesystem operations remotely for particular users so we can diagnose issues they're having, and I want to do this in a way that doesn't degrade performance. Just add logging (or println!) This is often a simple and good choice, although it often leads to this kind of thing:  public void doSomethingIntere…

Hello again :)

After a long absence I'm planning to blog a bit more actively. This is partly motivated by the fact that I've been working on some quite fun, gnarly stuff recently, and I think it'd be useful to me to get back into the habit of writing more about the things I'm futzing around with.Quite a lot has changed since I last wrote in this blog eleven and a half years ago (oh, wow), in the world, and in my own life. The world seems exceptionally messed up in a variety of ways, and I wish it'd be better, but I sort of try to be eternally optimistic about things and hope that we're going through a tough patch and we'll all pull together and make things better (and I'm not just talking about Coronavirus, although that's pretty terrible in its own right). In my own life, since I last wrote, I got married to the most amazing person in the world, grew two cheeky and rambunctious kids who are lovely and keep me terribly busy, and manage to surprise and fascinate me…