1 Reply Latest reply: Jun 10, 2014 6:13 AM by 821bcfe9-ad4a-4829-8441-68643978a4df RSS

    JvmTI agent problem

    821bcfe9-ad4a-4829-8441-68643978a4df

      My jvm agent as follows:

       

      JNIEXPORT jint JNICALL

      Agent_OnLoad(JavaVM *jvm, char *options, void *reserved)

      {

        // simple code

      printf("Test for jvm agent \n");

      return 0;

      }

       

       

       

      JNIEXPORT void JNICALL

      Agent_OnUnload(JavaVM *vm)

      {

      // nothing to do.

      }

       

      2. and my makefile:

      AVA_HOME =C:\Dev_Tools\Java\jdk1.6.0_26

      JDK_HOME = C:\Dev_Tools\Java\jdk1.6.0_26

       

       

      C = gcc

      CXX = gcc

      OPT = -O2

      DEBUG = -g

      INCDIR = -I.

      LIBDIR = -L.

      CFLAGS = -fno-strict-aliasing -fPIC -fno-omit-frame-pointer -W -Wall -DSC_INCLUDE_FX -m32 -static-libgcc  -kill-at

      LINKFLAGS = -D_JNI_IMPLEMENTATION_ -fno-omit-frame-pointer -m32 -static-libgcc -shared

       

       

      JDK_INCL = -I$(JDK_HOME)/include -I$(JDK_HOME)/include/win32

      DYLIB_FLAGS = -dynamiclib -flat_namespace -undefined suppress

       

       

      CXXCOMPILE = $(CXX) -c $(CFLAGS) $(INCDIR) $(LIBDIR) $(JDK_INCL)

      CXXLINK = $(CXX) $(LINKFLAGS) $(LIBDIR)

      LIBS = -lm

       

       

       

       

      EXEC = TraceAgent.dll

      HEADS =

      IMPLS = $(HEADS:.h=.c)

      SRCS = main.c $(IMPLS)

      OBJS = $(SRCS:.c=.o)

      COMMON =

       

       

      all: $(EXEC)

       

       

      $(EXEC): $(OBJS)

        $(CXXLINK) -o $(EXEC) $(OBJS) $(LIBS)

       

       

      main.o: main.c $(HEADS) $(COMMON)

        $(CXXCOMPILE) -o $@ $<

       

       

      %.o: %.c %.h $(COMMON)

        $(CXXCOMPILE) -o $@ $<

       

       

      clean:

        rm $(EXEC) $(OBJS) *~

       

      cmd> make all

       

      and gen a dll file named : TraceAgent.dll

       

      And I copy this dll file to my fold

      java code:  java -agentpath:E:\moaworksp\JvmTest\bin\TraceAgent.dll com.AgentSample

       

       

      but eror as follows:

       

      Error occurred during initialization of VM

      Could not find Agent_OnLoad function in the agent library: E:\moaworksp\JvmTest\bin\TraceAgent.dll

       

      How can I do?

      By the way ,my Java source file AgentSamole is a simple main java for test.

       

      Thanks in advance.