Playing with OSX OpenJDK

4月頃の jdk7u-dev に fastdebug が作ってあったので、少しデバッグを入れてみる。昔のオブジェクトがあればビルドも早いだろう。

次のようなスクリプトを用意しておく。make に fastdebug_build を渡して後は、環境変数

_JAVA_OPTIONS=-Dfile.encoding=ASCII
export _JAVA_OPTIONS
make fastdebug_build ALLOW_DOWNLOADS=true SA_APPLE_BOOT_JAVA=true ALWAYS_PASS_TEST_GAMMA=true ALT_BOOTDIR=`/usr/libexec/java_home -v 1.6` HOTSPOT_BUILD_JOBS=`sysctl -n hw.ncpu`

これを実行する事で、5分ぐらいで出来上がった。 hotspot の部分は10数秒でできていて、なぜか触っていない jdk 部分に大半の時間がかかっている。

ビルドの最後の出力

#-- Build times ----------
Target fastdebug_build
Start 2012-08-08 02:10:43
End   2012-08-08 02:14:58
00:00:08 corba
00:00:14 hotspot
00:00:03 jaxp
00:00:05 jaxws
00:03:39 jdk
00:00:05 langtools
00:04:15 TOTAL
                                                • -

hotspot/make の下で、target を fastdebug にするともっと速いかもと思ったけれど、全てをコンパイルしに行ってる様で、時間がかかりそうだったので、トップでのビルドに戻る。

一見ビルドできているようだが build/macosx-amd64-fastdebug/bin/java を実行しても、変更が反映されていないように見える。find で JVM の実体である libjvm.dylib を探すとふるい物が結構見つかる。

結局、これら全てを削除してからビルドしないと、なぜか少し前の libjvm が動いたりする。この辺は最近のコードではなおってるのかもしれないが、今回は試さなかった。

Tarjan 作られる過程を見てみたかったのだけど、-XX:+PrintDominators は完成した後でないと使えないので、別途関数を作った。debug build では Resoure Area (NTarjan などが取られるところ)は ZapResourceArea のため 0xABABABAB で埋まっているので、Node pointer はそのパターンに関してもチェックが必要。

変更したのは domgraph.cpp .

#ifdef _LP64
static bool NotANode(const Node* n) {
  if (n == NULL)                return true;
  if (((intptr_t)n & 1) != 0)   return true;
  if (n == (Node*)0xababababababababL) return true;
}
#else
static bool NotANode(const Node* n) {
  if (n == NULL)                return true;
  if (((intptr_t)n & 1) != 0)   return true;
  if (n == (Node*)0xabababab)          return true;
}

#endif // _LP64

void dumpTarjanDfsorder(NTarjan* ntj, uint* dfsorder, int size)
{
  tty->print("D: NTarjan dfsorder\n");
  for (int i = 0; i < size; i++) {
    NTarjan* tp = &ntj[i];
    tty->print("%3d: %#lx ", i, tp);
    if (!NotANode(tp->_control)) {
      tty->print("ctrl %#lx ", tp->_control);
      tp->_control->dump();
    }
    tty->print("\n");
    tty->print("  par %#lx lbl %#lx anc %#lx chld %#lx dom %#lx bkt %#lx domcld %#lx domn %#lx\n",
        tp->_parent, tp->_label, tp->_ancestor, tp->_child,
        tp->_dom, tp->_bucket, tp->_dom_child, tp->_dom_next);
    tty->print("  semi %d size %d dfsorder %d\n", tp->_semi, tp->_size, dfsorder[i]);
  }
}

あと、gdb がうまく動いてくれない。これも新しい物があるのかもしれない…

$ gdb /Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home/bin/java /cores/core.60921 
GNU gdb 6.3.50-20050815 (Apple version gdb-1752) (Sat Jan 28 03:02:46 UTC 2012)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin"...
Reading symbols for shared libraries ........ done

Reading symbols for shared libraries . done
Reading symbols for shared libraries .unable to load symbol file: [memory object "/System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa" at 0x7fff97c9b000]: Undefined error: 0
.unable to load symbol file: [memory object "/System/Library/Frameworks/Security.framework/Versions/A/Security" at 0x7fff98cb1000]: Undefined error: 0
.unable to load symbol file: [memory object "/System/Library/Frameworks/ApplicationServices.framework/Versions/A/ApplicationServices" at 0x7fff8fbf1000]: Undefined error: 0
.unable to load symbol file: [memory object "/usr/lib/libz.1.2.5.dylib" at 0x7fff99fd2000]: Undefined error: 0
.unable to load symbol file: [memory object "/usr/lib/libSystem.B.dylib" at 0x7fff92294000]: Undefined error: 0
.unable to load symbol file: [memory object "/usr/lib/libobjc.A.dylib" at 0x7fff90291000]: Undefined error: 0
.unable to load symbol file: [memory object "/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation" at 0x7fff9ae1d000]: Undefined error: 0
.unable to load symbol file: [memory object "/System/Library/Frameworks/AppKit.framework/Versions/C/AppKit" at 0x7fff903b6000]: Undefined error: 0
:
.unable to load symbol file: [memory object "/System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/OpenScripting.framework/Versions/A/OpenScripting" at 0x7fff95f2d000]: Undefined error: 0
.unable to load symbol file: [memory object "/System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/Print.framework/Versions/A/Print" at 0x7fff8ef37000]: Undefined error: 0
.unable to load symbol file: [memory object "/System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/SecurityHI.framework/Versions/A/SecurityHI" at 0x7fff99fca000]: Undefined error: 0
. done
#0  0x00007fff950eece2 in ?? ()
(gdb) where
#0  0x00007fff950eece2 in ?? ()
#1  0x00007fff95f8ca7a in ?? ()
#2  0x000000010ea3641b in os::abort ()
#3  0x000000010eb2458e in VMError::report_and_die ()
#4  0x000000010ea37af5 in JVM_handle_bsd_signal ()
#5  0x00007fff95fedcfa in ?? ()
#6  0x00007fff935b5570 in ?? ()
#7  0x00007fff9ae4d50c in ?? ()
#8  0x00007fff9ae55c74 in ?? ()
#9  0x00007fff9ae55486 in ?? ()
#10 0x000000010e49c4bc in CreateExecutionEnvironment ()
#11 0x000000010e496cac in JLI_Launch ()
#12 0x000000010e49c819 in main ()
(gdb) info thread
error on line 784 of "/SourceCache/gdb/gdb-1752/src/gdb/macosx/macosx-nat-infthread.c" in function "void print_thread_info(thread_t, int *)": (ipc/send) invalid destination port (0x10000003)