Question

since one week I'm trying to compile a demo Version of the JVMTI demo set. In this case I tried to compile the HeapViewer Source Code (I just renamed the file HeapViewer.c to HeapViewerByMG). I tried different compiler and used mainly the following code that I found on stackOverflow,too:

// compile with Microsoft Windows C++ compiler
set JAVA_HOME="C:\Program Files\Java\jdk1.6.0_26"
set JVMTI_DEMO=%JAVA_HOME%\demo\jvmti
set AGENT_SRC=%JVMTI_DEMO%\agent_util\src
set CRW_SRC=%JVMTI_DEMO%\java_crw_demo\src
set CFLAGS=/MD /Zi /Ox /Os /Gy /c
cl %CFLAGS% /I%AGENT_SRC% %AGENT_SRC%\agent_util.c /I%CRW_SRC% /I%JAVA_HOME%\include /I%JAVA_HOME%\include\win32
cl %CFLAGS% /I%CRW_SRC% /I%JAVA_HOME%\include /I%JAVA_HOME%\include\win32 %CRW_SRC%\java_crw_demo.c
cl %CFLAGS% /I%AGENT_UTIL% /I%CRW_SRC% /I%JAVA_HOME%\include /I%AGENT_SRC% /I%JAVA_HOME%\include\win32 heapViewerByMG.c
link -dll -out:heapViewerByMG.dll heapViewerByMG.obj java_crw_demo.obj agent_util.obj

// compile with g++ compiler von MINGW
set JAVA_HOME="C:\Program Files\Java\jdk1.6.0_26"
set JVMTI_DEMO=%JAVA_HOME%\demo\jvmti
set AGENT_SRC=%JVMTI_DEMO%\agent_util\src
set CRW_SRC=%JVMTI_DEMO%\java_crw_demo\src
gcc -c -I%AGENT_SRC% %AGENT_SRC%\agent_util.c -I%CRW_SRC% -I%JAVA_HOME%\include -I%JAVA_HOME%\include\win32
gcc -c -I%CRW_SRC% -I%JAVA_HOME%\include -I%JAVA_HOME%\include\win32 %CRW_SRC%\java_crw_demo.c
gcc -c -o heapViewerByMG.dll -I%AGENT_UTIL% -I%AGENT_SRC% -I%CRW_SRC% -I%JAVA_HOME%\include -I%JAVA_HOME%\include\win32 heapViewerByMG.c

My code compiles successful in both cases, but when I try to use the dll files, I will get following error:

"The application or DLL (...)\heapViewerByMG.dll is not a valid Windows image. Please check this against your installation diskette."

I also looked up what this message means. The research told me, that this is then a corrupt file, but I can rule this out since I compiled a given source code by the JVM. Anyhow I believe it is just another option command that I need to let run the file successful. Does anyone of you have an idea?

Here are some details of my system:

C:\>java -version
java version "1.6.0_26"
Java(TM) SE Runtime Environment (build 1.6.0_26-b03)
Java HotSpot(TM) Client VM (build 20.1-b02, mixed mode, sharing)

C:\>gcc --version gcc (GCC) 4.5.2 Copyright (C) 2010 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


C:\>cl -version
Microsoft (R) C/C++ Optimizing Compiler Version 14.00.50727.762 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

Or after I changed the Microsoft Compiler from 64bit to 32bit (because this was one of the older error messages, when I started the agent)

C:\>VCVARS32

C:\>"C:\Program Files\Microsoft Visual Studio 8\Common7\Tools\vsvars32.bat"
Setting environment for using Microsoft Visual Studio 2005 x86 tools.

C:\>cl -version
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.762 for 80x86

Copyright (C) Microsoft Corporation.  All rights reserved.

And I'm running a Microsoft Windows XP Professional Version 2002 Service Pack 3 on a Intel(R) 4 CPU 2.80GHz with 2.00 GB of RAM

Sorry for that system. Usually I'm using a MacBook Pro 2010 (2.8GHz Intel Core i7), but I figured out that MacOS doesn't have included the support of the JVMTI demo-version :(

I hope somebody can help me.

Greetings Markus G.

Was it helpful?

Solution

I don't know where the difference to upper version is, but this command-lines creates an agent that runs well (on upper mentioned system), if you copy the dll-file into the library (..JAVA_HOME\JRE\BIN):

VCVARS32
cd C:\Program Files\Java\jdk1.6.0_26\demo\jvmti\heapViewerByMG\src
set JAVA_HOME="C:\Program Files\Java\jdk1.6.0_26"
set JVMTI_DEMO=%JAVA_HOME%\demo\jvmti
set AGENT_SRC=%JVMTI_DEMO%\agent_util\src
set CRW_SRC=%JVMTI_DEMO%\java_crw_demo\src
set CFLAGS= /Op /Ox /Zi /Gy -DWIN32 /WX
cl %CFLAGS% /I%AGENT_SRC% %AGENT_SRC%\agent_util.c /I%CRW_SRC% /I%JAVA_HOME%\include /I%JAVA_HOME%\include\win32
cl %CFLAGS% /I%CRW_SRC% /I%JAVA_HOME%\include /I%JAVA_HOME%\include\win32 %CRW_SRC%\java_crw_demo.c
cl %CFLAGS% /I%AGENT_UTIL% /I%CRW_SRC% /I%JAVA_HOME%\include /I%AGENT_SRC% /I%JAVA_HOME%\include\win32 heapViewerByMG.c
link -dll -out:heapViewerByMG.dll heapViewerByMG.obj java_crw_demo.obj agent_util.obj

Now,copy the DLL File into upper mentioned directory and use following command line to run the test:

C:\Program Files\Java\jdk1.6.0_26\demo\jvmti\heapViewerByMG\src>java -agentlib:h
eapViewerByMG -version
Compile Time JVMTI Version: 1.1.102 (0x30010166)
Run Time JVMTI Version: 1.2.1 (0x30010201)
java version "1.6.0_26"
Java(TM) SE Runtime Environment (build 1.6.0_26-b03)
Java HotSpot(TM) Client VM (build 20.1-b02, mixed mode, sharing)

Anyhow, I still don't know, why this didn't work earlier ... Markus G.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top