使用VS2010构建HotSpot工程

1. 下载OpenJDK7的源码:
     http://download.java.net/openjdk/jdk7
     http://download.java.net/openjdk/
    
2. 环境配置
    ▶a. 安装VS2010,并将其添加到PATH环境变量中
          例:PATH=XX\Microsoft Visual Studio 10.0\VC\bin;%PATH%
    ▶b. 设置JAVA_HOME环境变量(使用JDK6u45 版本过高会出现错误)
    ▶c. 安装Cygwin.
    ▶d. 解压的OpenJDK源码路径不要包含中文以及其他符号(如:路径中含有(++)符号).

3. 创建HotSpot的VS2010工程
    ▶a. 运行dos命令行,执行vcvars32.bat命令设置VS2010环境
    ▶b. 进入%OPENJDK_HOME%/hotspot/make/windows/
        执行: create.bat %JAVA_HOME%
     ......
        Writing .vcxproj file: D:\JDK\testjdk\openjdk\hotspot\build\vs-i486\jvm.vcxproj Done.
        Writing .vcxproj.filters file: D:\JDK\testjdk\openjdk\hotspot\build\vs-i486\jvm.vcxproj.filters Done.
        Writing .vcxproj.user file: D:\JDK\testjdk\openjdk\hotspot\build\vs-i486\jvm.vcxproj.user Done.

        输出如上信息代表hotspot编译成功。
    ▶c. 打开VS2010,将%OPENJDK_HOME%/hotspot/build/build\vs-i486/jvm.vcxproj或者直接双击jvm.vcxproj打开HotSpot工程。
    ▶d. 导入成功后,F7编译HotSpot工程,但出现如下错误:
        --------------------------------------------------------------------------------------------------------
 1>Link:1> Creating library C:\openjdk\hotspot\build\vs-i486\compiler1\debug\jvm.lib and object C:\openjdk\hotspot\build\vs-i486\compiler1\debug\jvm.exp
        1>os_windows.obj : error LNK2019: unresolved external symbol _EnumProcessModules@16 referenced in function "public: static int __cdecl os::PSApiDll::EnumProcessModules(void *,struct HINSTANCE__ * *,unsigned long,unsigned long *)" (?EnumProcessModules@PSApiDll@os@@SAHPAXPAPAUHINSTANCE__@@KPAK@Z)
        1>os_windows.obj : error LNK2019: unresolved external symbol _GetModuleFileNameExA@16 referenced in function "public: static unsigned long __cdecl os::PSApiDll::GetModuleFileNameExA(void *,struct HINSTANCE__ *,char *,unsigned long)" (?GetModuleFileNameExA@PSApiDll@os@@SAKPAXPAUHINSTANCE__@@PADK@Z)
        1>os_windows.obj : error LNK2019: unresolved external symbol _GetModuleInformation@16 referenced in function "public: static int __cdecl os::PSApiDll::GetModuleInformation(void *,struct HINSTANCE__ *,struct _MODULEINFO *,unsigned long)" (?GetModuleInformation@PSApiDll@os@@SAHPAXPAUHINSTANCE__@@PAU_MODULEINFO@@K@Z)
        1>C:\openjdk\hotspot\build\vs-i486\compiler1\debug\jvm.dll : fatal error LNK1120: 3 unresolved externals


        原因是缺少psapi.lib库文件,将其添加到:Linker->Input->Additional Dependencies.
    ▶4. 右击jvm选择属性(properties),选择Debugging选项:
         a. Command 代表编译出来的调试启动器hotspot.exe(%OPENJDK_HOME%/hotspot/build/build\vs-i486\compiler1\debug\hotspot.exe,另外还有jvm.dll)
         b. Command Arguments 填写相应的java class。如:-cp <dir> HelloWorld
    ▶5. 由于我们编译仅仅是HotSpot,所以需要一个外挂的JDK提供如:rt.jar的资源,这个外挂的JDK可以在%OPENJDK_HOME%/hotspot/build/build\vs-i486\compiler1\debug\jdkpath.txt中设置JAVA_HOME。

4. 在java.c中设置断点,F10(F5)就可以调试了。

你可能感兴趣的:(HotSpot,OpenJDK,VS2010)