javaのgcについて理解する〜基本的な仕組みへん

  Eden From To
|ーーーー|ーー|ーー|ーーーーーーーー|ーーーーーーーーーーーーーーーー|
|ーーーーーーーーーー|ーーーーーーーー|ーーーーーーーーーーーーーーーー|
    New         Old
|ーーーーーーーーーーーーーーーーーーー|ーーーーーーーーーーーーーーーー|
       heap               Permanent

■New世代GC
1. オブジェクトは生成され、Eden領域に割り当てられる
2. Eden領域が不足すると、New世代領域を対象にしたgcが実行される
2-1. Eden領域内のライブオブジェクトが検出され、To領域にコピーされる
2-2. このgcごとにFromとTo領域の役割が交代するので、領域名を形式的に入れ替える
3. 2に戻る
3-1. ただし、前回To領域(現在のFrom領域)も対象なので、Eden領域とFrom領域から現在のTo領域にコピーされる。

■Old世代GC(Full GC
1. New世代GC中は、長命オブジェクトはFromとToを行き来し、コスト面であまりよろしくないので、そのようなオブジェクトはOld領域へ異動させる
※そのため、各オブジェクトに年齢属性(GCの回数)をもたせてる。
2. Old領域のo空き領域が不足するとOld世代GCが実行される
2-1. Old領域内の非ライブオブジェクトのメモリ領域を解放する


・ヒープが小さい
 -> gcが頻発する
 ->必要量を下回るとOOMエラーが発生する
・ヒープサイズが大木
 -> gc1回あたりの処理時間(アプリケーションの停止時間)が長くなる
・-Xmsと-Xmxと異なる値に設定する
 -> JVMヒープが足りないと判断されたとき最大値まで拡大させる
 -> ヒープサイズのオーバーヘッドコストがかかる

GCの種類
・シリアルGC
・パラレルGC(-XX:+UseParallelGC、-XX:+UseParNewGC)
 ->複数スレッドを使って同時に実行できる※マルチコア環境ではこちらがデフォルト
 -> gc時間の現象、スループットの向上が期待できる
・コンカレントGC(-XX:+UseConcMarkSweepGC)
 -> アプリケーションと並行して処理できる(一部の処理のときのみ停止させる)
・ガベージファーストGC

http://www.atmarkit.co.jp/ait/articles/0404/02/news079.html
http://gihyo.jp/dev/serial/01/jvm-arc/0001
今回は基本へんなのでこの辺参考にしたけどちょっと古いので現バージョンのも調べなくては。

コードカバレッジ

「 カバレッジ
  なにそれ、おいしいの? 」
状態だったので、調べてみた。

コッドカバレッジとは、
テスト対象をどの程度網羅したテストなのかを示す指標のひとつ
らしい。

カバレッジ
・C0:命令網羅
・C1:分岐網羅
 ∟Line(JMockit)
・C2:条件網羅
・C2:複合条件網羅
 ∟Path(JMockit)

http://akademeia.info/index.php?%A5%B3%A1%BC%A5%C9%A5%AB%A5%D0%A5%EC%A5%C3%A5%B8:コードカバレッジ
http://softest.cocolog-nifty.com/blog/2008/03/post_7864.html:コードカバレッジまとめ

なんかブログ書こうとしたらかなり前のこんなキャッシュがでてきた。。。。
なにまとめようとしたんだろう。。。

gitをいじる会(`ω´)キリッ〜その3のその1〜git-svn

svnを使いつつ、ローカルではgitを使いたい!!
待ちに待ったテーマー゚+。:.゚ヽ(*´∀`)ノ゚.:。+゚


svnリポジトリからgitプロジェクトとしてチェックアウトしてくる

git svn clone -s https://git-svn-sample.googlecode.com/svn/
  • s:自動的にtrunkとbranchを見分けてgitリポジトリに取り込んでくれる!

あとはgitプロジェクトのごとく、
addしたりcommitしたり。。。

ただし!!
git svnはgitのようにpushはできない!
git pushにあたるのは

git svn dcommit

ちなみに、pullもできないので

git svn rebase

で、pullする。

※rebase
mergeとは違う!
ブランチをmasterにする?感じ?
merge:マージしたログが残る
rebase:マージ履歴がのこらない。(masterを切り捨てる)ログがきれいに残る!
    上級者はこっちをうまいこと使うよ(`Д´)
svn updateはrebaseよりな感じ!

ちょっといい感じのsvn環境がなかったので
今回はコマンドだけー

gitをいじる会(`ω´)キリッ〜その2のその2w

ブランチをつくってみる!

[nashuaki@hostname nashuaki_tips]$ git branch branch_name

[nashuaki@hostname nashuaki_tips]$ git branch
* master
 branch_name

branch_nameっていうブランチができた!
*がついてるのが現在選択中のブランチみたい

[nashuaki@hostname nashuaki_tips]$ git checkout branch_name
Switched to branch 'branch_name'

※ブランチを切り替えることでHEADがかわることに注意!

branch-masterをマージする!
ブランチからマスターにマージ

[nashuaki@hostname nashuaki_tips]$ git checkout master
※マージされる方のブランチにいること!

[nashuaki@hostname nashuaki_tips]$ git merge branch_name
Auto-merging branch_name/first.txt
Merge made by the 'recursive' strategy.



 3 files changed, 8 insertions(+), 1 deletion(-)
 create mode 100644 branch_name/diff.txt/diff.txt
 create mode 100644 branch_name/git_tips.txt


以下、参考に。

コミットログとかがみれるよー

[nashuaki@hostname nashuaki_tips]$ git log --graph --decorate

macであればgui版があるらしいよ!
gui版(参照のみ)

[nashuaki@hostname nashuaki_tips]$ git k


ブランチはいらなくなったら消すこと!
ごちゃごちゃしちゃうからね。

git branch -d ブランチ名

ちなみに、
マージする前のは消せないので、
どうしても削除したい場合は

git branch -D ブランチ名

これで強制削除できるよ!

gitでは、
ローカルでのブランチの作成ができるので、
こやってローカルでブランチつくってmasterにマージ!
って作業をよくやるらしい。
svnではブランチっていうとどうしてもリモートにしか作れないからね。

今回も大変勉強になりました!

gitをいじる会(`ω´)キリッ〜その2

第2回のgit勉強会だよーγ(▽´ )ツヾ( `▽)ゞ
前回はこちらー
http://d.hatena.ne.jp/nashuaki/20120814/1344954499


まずはローカルリポジトリを最新にしよう!

[nashuaki@hostname nashuaki_tips]$ git pull -u origin master

first.txtの最後の行に、
mumumu
を追加してみたよ。

ワーキングdirとステージ(addしたとこ)の差分

[nashuaki@hostname nashuaki_tips]$git diff .
diff --git a/first.txt b/first.txt
index b400f6a..06a9b00 100644
--- a/first.txt
+++ b/first.txt
@@ -1,2 +1,3 @@
 hello git!
 bye
+mumumu

ワーキングdirとローカルリポジトリの差分

[nashuaki@hostname nashuaki_tips]$git diff HEAD
diff --git a/first.txt b/first.txt
index b400f6a..06a9b00 100644
--- a/first.txt
+++ b/first.txt
@@ -1,2 +1,3 @@
 hello git!
 bye
+mumumu

ローカルリポジトリとステージの差分

[nashuaki@hostname nashuaki_tips]$git diff --cached

first.txtをステージにあげてみた。

ワーキングdirとステージ(addしたとこ)の差分

[nashuaki@hostname nashuaki_tips]$git diff .

ワーキングdirとローカルリポジトリの差分

[nashuaki@hostname nashuaki_tips]$git diff HEAD
diff --git a/first.txt b/first.txt
index b400f6a..06a9b00 100644
--- a/first.txt
+++ b/first.txt
@@ -1,2 +1,3 @@
 hello git!
 bye
+mumumu

ローカルリポジトリとステージの差分

[nashuaki@hostname nashuaki_tips]$git diff --cached
diff --git a/first.txt b/first.txt
index b400f6a..06a9b00 100644
--- a/first.txt
+++ b/first.txt
@@ -1,2 +1,3 @@
 hello git!
 bye
+mumumu


ここでローカルリポジトリにコミット

ワーキングdirとステージ(addしたとこ)の差分

[nashuaki@hostname nashuaki_tips]$git diff .

ワーキングdirとローカルリポジトリの差分

[nashuaki@hostname nashuaki_tips]$git diff HEAD

ローカルリポジトリとステージの差分

[nashuaki@hostname nashuaki_tips]$git diff --cached

これで
ワーキングdir
=ステージ
=ローカルリポジトリ
の状態

fufufuの追加ー

[nashuaki@hostname nashuaki_tips]$ git diff .
diff --git a/first.txt b/first.txt
index 06a9b00..5b48c23 100644
--- a/first.txt
+++ b/first.txt
@@ -1,3 +1,4 @@
 hello git!
 bye
 mumumu
+fufufu
[nashuaki@hostname nashuaki_tips]$ git add first.txt

heheheの追加ー

[nashuaki@hostname nashuaki_tips]$ git diff .
diff --git a/first.txt b/first.txt
index 5b48c23..ddf996c 100644
--- a/first.txt
+++ b/first.txt
@@ -2,3 +2,4 @@ hello git!
 bye
 mumumu
 fufufu
+hehehe


ステージにあげたものをきり戻すよ!

[nashuaki@hostname nashuaki_tips]$ git reset first.txt
Unstaged changes after reset:
M     first.txt
[nashuaki@hostname nashuaki_tips]$ git diff first.txt
diff --git a/first.txt b/first.txt
index 06a9b00..ddf996c 100644
--- a/first.txt
+++ b/first.txt
@@ -1,3 +1,5 @@
 hello git!
 bye
 mumumu
+fufufu
+hehehe

[nashuaki@hostname nashuaki_tips]$ cat first.txt
hello git!
bye
mumumu
fufufu
hehehe
[nashuaki@hostname nashuaki_tips]$ git checkout -- first.txt

[nashuaki@hostname nashuaki_tips]$ git diff first.txt

[nashuaki@hostname nashuaki_tips]$ cat first.txt
hello git!
bye
mumumu

checkoutしちゃうとワーキングのみの変更はかき消されちゃうよ(ノД`)・゜・。

ちなみに、
ローカルリポジトリにコミットしたものをもとに戻す場合は、

[nashuaki@hostname nashuaki_tips]$ git chekout HEAD -- filename

[nashuaki@hostname nashuaki_tips]$ git reset HEAD^ filename

diffはだいぶなれたけど、
resetとかはなんかややこい(●´⌓`●)
この辺参考になりそうかなー
http://d.hatena.ne.jp/murank/20110320/1300619118
http://d.hatena.ne.jp/murank/20110327/1301224770
http://redtower.plala.jp/2010/09/30/git-git-reset.html

とりあえずきりがいいのでここまでー!
今日はブランチまでやったんだけど、それは別更新にしておきます。

プロセスごとのメモリ使用量を調べる

[user@hostname ~]$ ps alx

F   UID   PID  PPID PRI  NI    VSZ   RSS WCHAN  STAT TTY        TIME COMMAND
4     0  1375     1  15   0  54696  1676 -      Ss   ?          0:15 /usr/libexec/postfix/master
4    89  1383  1375  15   0  52724  1716 -      S    ?          0:01 qmgr -l -t fifo -u
1     0  1516     1  18   0  72956   980 -      Ss   ?          0:06 crond
5    43  1534     1  18   0  18416   624 -      Ss   ?          0:00 xfs -droppriv -daemon
1 30020  1665     1  18   0 231784 128888 184466 Sl  ?          5:48 Rails: /usr/local/redmine-1.1.2                                                                                                                    
0 20253 11168 11167  15   0  64204   928 wait   Ss   pts/0      0:00 -bash
4     0 11281 11168  16   0  64204   916 wait   S    pts/0      0:00 /bin/bash
5    28 11320     1  15   0 213236  3452 stext  Ssl  ?          0:07 /usr/sbin/nscd
0     0 11419 11281  18   0  63552   600 -      S+   pts/0      0:02 less /usr/local/apache/conf/httpd.conf
1 30020 12732     1  19   0 211412 108496 184466 Sl  ?          0:43 Rails: /usr/local/redmine-1.1.2                                                                                                                    
4     0 15789 11437  15   0  64204  1352 wait   S    pts/1      0:02 /bin/bash

これの
RSS
のとこがmemory
の使用量(kb)らしい。

ターゲットのプロセスのメモリのみ抜き出したければ

[user@hostname ~]$ ps alx | grep ${target} | awk '{printf ("%d\t%s\n", $8,$13)}'

MacPortsめも

意味がわからず使ってたものも多いので
ここらでまとめておく。
環境はSnowLeopardね。
前提として、MacPortsが正常にインストールされていること
ちなみに、MacPortsでインストールしたコマンドは

/opt/local/bin:/opt/local/sbin/

にいれてくれる。

MacPorts自体のアップデート

sudo port -d selfupdate

オプション:

インストールできるソフトウェア一覧を更新

sudo port -d sync


${module}がインストールできるか確認。
(部分一致で検索されるよ)

port search ${module}

${module}の説明

port info ${module}

インストール時のオプションを表示

port variants ${module}

インストール

port install ${module}

アップデート

port upgrade ${module}

アンインストール

port uninstall ${module}

インストール済みの${module}の状態を確認

port installed ${module}

インストールされた${module}のファイルパスを表示

port contents ${module}

${module}が依存するモジュールを表示

portdeps ${module}

${module}に依存するモジュールを表示

port dependents ${module}

アップデート可能なインストール済みモジュールを表示

port outdates