|knowyourmeme.com/photos/531557 thx to @mihn|
native part of Java. I spent some time to achieve proper state of my JDK to do that, so short description probably will be useful for ones starting their trip. I'll use the brand new OpenJDK 9!
At first you have to obtain main repository by typing:
hg clone http://hg.openjdk.java.net/jdk9/jdk9 openjdk9Then in the openjdk9 directory type:
bash get_source.shThat will download all sources to you local filesystem.
Theoretically compiling openjdk is not a big deal, but there are some (hmmm....) strange behaviours if you want to use it for debugging.
At first of course we need to call ./configure to prepare specific makefiles for our system. We can read in documentation that we have to add --enable-debug flag to prepare fastdebug build. If you don't have proper libs or tools installed in your system it's right moment to install dependencies (configure output will clearly point out any lacks). After configuring and invoking make command you can face with such problem:
warning _FORTIFY_SOURCE requires compiling with optimization (-O) Generating buffer classes Generating exceptions classes cc1plus: all warnings being treated as errorsCool :) It happens only on some specific linux instalations (unfortunately including Fedora 20 :)). To solve it we have to remove _FORTIFY_SOURCE flag. Just comment (#) lines containing _FORTIFY_SOURCE in the following files:
Finished building OpenJDK for target 'default'Now it's time to import project to IDE Since we're still waiting for good C++ IDE from JetBrains we have to use NetBeans or even Eclipse. After finishing few steps needed to setup debugging commands (for example even for java -version). Start debugging, and... SIGSEGV received. Let's solve it by creating .gdbinit file in user home directory containing following lines:
handle SIGSEGV pass noprint nostop handle SIGUSR1 pass noprint nostop handle SIGUSR2 pass noprint nostopStart debugging one more time - now it's better! Let's continue by adding line breakpoint. Start debugging, and... not working... :( I've extended .gdbinit by adding.
set logging onOne more debug try and in gdb.txt I saw such line:
No source file named hotspot/src/share/vm/memory/genCollectedHeap.cppI was pretty sure that --enable-debug will add -g flag to gcc compiler, but it seems I was wrong. I spent few hours googling and trying to solve it by changing gdb configurations, NetBeans config, etc. Still no effect. Fortunately Michal Warecki pointed me that probably OpenJDK during debug builds zips all debuginfo and if you want to debug (of course prepared debug build due to some other purposes?). After grepping makefiles I've found promising disable-zip-debug-info flag. So let's include it into our configure invocation. Also believe me it's hard to debug optimized code in C++ (you can try, but you will encounter strange thing happening, like debugger stepping lines in incorrect order (like starting method from line 4, going back to 2, then to 5 and to 3 :)). So we'll choose slowdebug option to avoid code optimization. Whole proper configure command is:
bash ./configure --with-debug-level=slowdebug --with-target-bits=64 --disable-zip-debug-infoNow we can invoke:
makeand wait for compilation to finish. Now you can check if everything works correctly by invoking ./java -version in
You should see:
openjdk version "1.9.0-internal-debug" OpenJDK Runtime Environment (build 1.9.0-internal-debug-kuba_2014_08_20_14_02-b00) OpenJDK 64-Bit Server VM (build 1.9.0-internal-debug-kuba_2014_08_20_14_02-b00, mixed mode)Let's try debugging. Add line breakpoint, start debugging, and... finally it's green! Have fun!