OQLは特定のクラスオブジェクト検索を行えるものです。
オブジェクト問い合わせ言語 (オブジェクトといあわせげんご、オブジェクト照会言語、OQL、英: Object Query Language) は、Object Data Management Group (ODMG) に準拠したオブジェクトデータベースに対する問い合わせと更新を行うための宣言型の問い合わせ言語 (データベース言語) である。 OQLは、宣言型言語であり、手続き型言語ではない。 OQLは、関係データベース (リレーショナルデータベース) の問い合わせ言語 (データベース言語) SQL をもとにしている。 OQLは、ODMGによって開発され標準仕様として公開された。
※Wikiより
なお、このページでは扱うOQL (Object Query Language):は、Javaヒープの検索をするために利用できるSQLのような問い合わせ言語です。OQLはJAVAヒープから必要な情報を選択したり、フィルターしたりすることができます。
メモリリーク解析のため、ヒープのスナップショットをとって、ビューアでみることまでできたが、インスタンスがたくさんありすぎる。
見つけたいのは、循環参照しているインスタンスだ。
それを絞り込むのに、OQLってつかえるの?っておもって情報を集めるというのが、このページの目的
OQLは、JavaScrip?埋め込み型言語(JavaScript? Expression Language)をベースとしています。
select <JavaScript expression to select> [ from [instanceof] <class name> <identifier> [ where <JavaScript boolean expression to filter> ]
自分では、まだ、問い合わせ文をつくれないので、サイトに掲載されている例文をまとめてみます。
ただし、これらのクエリーは発展途上なので、安定してるという保証はありません。
たとえば、下記のサンプルで、
Fileオブジェクトの持っている path フィールドの中身の値を一覧で表示
というのがありますが、実際に、jvisualvm.exeでやってみると、
OK | select x from java.io.File x |
OK | select x.path from java.io.File x |
ERROR | select x.path.value from java.io.File x |
javax.script.ScriptException: sun.org.mozilla.javascript.internal.WrappedException: Wrapped java.lang.reflect.UndeclaredThrowableException
でした。
あたらしいプラグインをjvisualvmでとりこもうとしたら、
あなたのjvisualvmは古いので、このプラグインは取り込めません的なメッセージがでてきた。
たしかに、バージョンふるいかもしれない。Java7がでているのに、Java6のjvisualvmつかっている自分がいけないのかもしれない。
だから、あたらしい、バージョンのJavaをダウンロードしてきてそのなかのツールを使うようにしてみたら、新しいプラグインを取り込めていいかもしれないです。
SELECT s FROM java.lang.String s WHERE (s.count >= 100)
select {instance: s, content: s.toString()} from java.lang.String s where /java/(s.toString())
select toHtml(x)+" "+x.toString() from java.lang.String x where x.count>10 &&
x.toString().substring(0,5)=="<html"
select file.path.value.toString() from java.io.File file
SELECT classof(cl).name FROM INSTANCEOF java.lang.ClassLoader cl
select a from int[] a where a.length >= 256
例1
select classof(o).name from instanceof java.lang.ref.Reference o
例2
SELECT ac FROM INSTANCEOF android.app.Activity ac
例3
select heap.findClass("java.io.InputStream").subclasses()
例
select heap.findClass("java.io.BufferedInputStream").superclasses()
select identical(heap.findClass("Foo").statics.bar, heap.findClass("AnotherClass").statics.bar)
だれか訳して
select objectid(o) from java.lang.Object o
0xd404b198 の場合
select o from instanceof 0xd404b198 o
または
select heap.findObject("0xd404b198")
例:"java.lang.System"でstaticsなpropsメソッドの場合
select heap.findClass("java.lang.System").statics.props
例:"java.lang.System"でpropsメソッドの場合
select heap.findClass("java.lang.System").props
例:"java.lang.System"の場合
select heap.findClass("java.lang.String").fields.length
select reachables(p) from java.util.Properties p
select reachables(u, 'java.net.URL.handler') from java.net.URL u
select { name: t.name? t.name.toString() : "null", thread: t } from instanceof java.lang.Thread t
select count(referrers(o)) from java.lang.Object o
select referrers(f) from java.io.File f
select u from java.net.URL u where count(referrers(u)) > 2
select referees(heap.findClass("java.io.File"))
select filter(heap.classes(), "/java.net./(it.name)")
select sizeof(o) from int[] o
select rsizeof(o) from instanceof java.lang.HashMap o
select "<b>" + toHtml(o) + "</b>" from java.lang.Object o
select f.referent from java.lang.ref.SoftReference? f
where f.referent != null
select f.referent from java.lang.ref.Finalizer f where f.referent != null
訳すの疲れた
詳しくは、ここみて
https://blogs.oracle.com/sundararajan/entry/querying_java_heap_with_oql
select { obj: f.referent, size: sum(map(reachables(f.referent), "sizeof(it)")) } from java.lang.ref.Finalizer f where f.referent != null
countとか、maxとか まとめるのめんどくさくなってきたので、
http://visualvm.java.net/oqlhelp.html
みてね。
select map(sort(map(heap.objects('java.lang.ClassLoader'), '{ loader: it, count: it.classes.elementCount }'), 'lhs.count < rhs.count'), 'toHtml(it) + "<br>"')
システムの変数を列挙します。
select map(filter(heap.findClass('java.lang.System').props.table, 'it != null && it.key != null && it.value != null'), function (it) { var res = it.key.toString() + ' = ' + it.value.toString(); return res; });
select role.name, (select u from User u where u = role.user) from Role role;
SELECT t.name FROM ( SELECT t FROM Tutors t WHERE t.salary > 300 ) r, r.students s WHERE s.fee > 30
SELECT p.name FROM p in People WHERE not ( p.name in SELECT t.name FROM t in TAs )
http://www.topazproject.org/trac/wiki/Topaz/Manual/Section11
こんな書き方ができるんやね。ってことでまとめてみる
http://stackoverflow.com/questions/8242205/java-heap-analysis-with-oql-count-unique-strings
var counts={}; var alreadyReturned={}; filter( sort( map(heap.objects("java.lang.String"), function(heapString){ if( ! counts[heapString.toString()]){ counts[heapString.toString()] = 1; } else { counts[heapString.toString()] = counts[heapString.toString()] + 1; } return { string:heapString.toString(), count:counts[heapString.toString()]}; }), 'lhs.count < rhs.count'), function(countObject) { if( ! alreadyReturned[countObject.string]){ alreadyReturned[countObject.string] = true; return true; } else { return false; } } );
select map(heap.objects("java.lang.String"), function tally(obj) { if(typeof tally.total == 'undefined') { tally.total = 0; tally.count = 0; } tally.total += sum(map(reachables(obj), "sizeof(it)")); tally.count++; return tally.total/tally.count; } );
http://andbrowser.com/development/knowhow/289/eclipse-android-memory-leak-mat-oql/
https://blogs.oracle.com/poonam/resource/OQL.htm
http://help.eclipse.org/juno/ntopic/org.eclipse.mat.ui.help/doc/org/eclipse/mat/snapshot/OQL.html