This discussion is archived
2 Replies Latest reply: Jul 29, 2010 5:21 AM by 791266 RSS

Getting started with JVMTI on Linux

843798 Newbie
Currently Being Moderated
Hi All,

I've been doing some JVMTI code for a while using windows, and I want to get that code working on Linux. The problem is that I can't seem to get even the simplest agent running on Linux. I can't figure out how to troubleshoot this, so any help would be appreciated. Here is my simple agent:
 * TestAgent.cpp
 *  Created on: Nov 30, 2009
 *      Author: delmyers

#include <iostream>
#include "TestAgent.hpp"

JNIEXPORT jint JNICALL Agent_OnLoad(JavaVM *vm, char *options, void *reserved) {
     std::cout << "Agent loaded" << std::endl;
     return 0;
JNIEXPORT void JNICALL Agent_OnUnload(JavaVM *vm) {
     std::cout << "Agent Unloaded" << std::endl;
As you can see, all it does is print the status of the load and unload operations. It compiles and links fine. Here are the commands for compile and link:

g++ -I/usr/java/latest/include -I/usr/java/latest/include/linux -O0 -g3 -Wall -c -fmessage-length=0 -D_JNI_IMPLEMENTATION_ -DDEBUG -fno-omit-frame-pointer -m32 -MMD -MP -MF"src/TestAgent.d" -MT"src/TestAgent.d" -o"src/TestAgent.o" "../src/TestAgent.cpp"

g++ -D_JNI_IMPLEMENTATION_ -fno-omit-frame-pointer -m32 -static-libgcc -shared -Wl,-soname=TestAgent -o"" ./src/TestAgent.o

But when I try to run an application (a simple hello world, for example), the agent never seems to load or unload. The JVM doesn't complain or anything: it just doesn't load the agent. A simple example launch would look like:

java -agentlib:LinuxAgentTest HelloWorld

I'm getting the typical "Could not find agent library on the library path...." error. Any suggestions?