简体   繁体   English

Eclipse MAT OQL 某类列表 package

[英]Eclipse MAT OQL list of classes in a certain package

using Eclipse MAT 1.9.1 OQL使用 Eclipse MAT 1.9.1 OQL

I want to list all the classes in the heap dump in a certain package.我想列出某个 package 中堆转储中的所有类。

I am trying the query:我正在尝试查询:

SELECT c.getName() as name, c.getName().indexOf("com.mycompany") as idx FROM java.lang.Class c WHERE idx > 0 

getting:得到:

java.lang.NullPointerException: idx at org.eclipse.mat.parser.internal.oql.compiler.Operation$GreaterThan.evalNull(Operation.java:232) at org.eclipse.mat.parser.internal.oql.compiler.Operation$RelationalOperation.compute(Operation.java:92) at org.eclipse.mat.parser.internal.oql.OQLQueryImpl.accept(OQLQueryImpl.java:1161) at org.eclipse.mat.parser.internal.oql.OQLQueryImpl.accept(OQLQueryImpl.java:1151) at org.eclipse.mat.parser.internal.oql.OQLQueryImpl.filterClasses(OQLQueryImpl.java:1133) at org.eclipse.mat.parser.internal.oql.OQLQueryImpl.doFromItem(OQLQueryImpl.java:921) at org.eclipse.mat.parser.internal.oql.OQLQueryImpl.internalExecute(OQLQueryImpl.java:690) at org.eclipse.mat.parser.internal.oql.OQLQueryImpl.execute(OQLQueryImpl.java:667) at org.eclipse.mat.inspections.OQLQuery.execute(OQLQuery.java:52) at org.88317647 java.lang.NullPointerException: idx at org.eclipse.mat.parser.internal.oql.compiler.Operation$GreaterThan.evalNull(Operation.java:232) at org.eclipse.compiler.oqleration.mat.oql.parser. $RelationalOperation.compute(Operation.java:92) 在 org.eclipse.mat.parser.internal.oql.OQLQueryImpl.accept(OQLQueryImpl.java:1161) 在 org.883176477Q88788.mat.oqIql.internal (OQLQueryImpl.java:1151) at org.eclipse.mat.parser.internal.oql.OQLQueryImpl.filterClasses(OQLQueryImpl.java:1133) at org.eclipse.mat.parser.internal.oql.OQLQueryImpl.doFromItem(OQLQueryImpl.java :921) 在 org.eclipse.mat.parser.internal.oql.OQLQueryImpl.internalExecute(OQLQueryImpl.java:690) 在 org.eclipse.mat.parser.internal.oql.OQLQueryImpl.execute(OQLQueryImpl.java:690) org.eclipse.mat.inspections.OQLQuery.execute(OQLQuery.java:52) 在 org.88317647 788788.mat.inspections.OQLQuery.execute(OQLQuery.java:1) at org.eclipse.mat.query.registry.ArgumentSet.execute(ArgumentSet.java:132) at org.eclipse.mat.ui.snapshot.panes.OQLPane$OQLJob.doRun(OQLPane.java:468) at org.eclipse.mat.ui.editor.AbstractPaneJob.run(AbstractPaneJob.java:34) at org.eclipse.core.internal.jobs.Worker.run(Worker.java:60) 788788.mat.inspections.OQLQuery.execute(OQLQuery.java:1) 在 org.eclipse.mat.query.registry.ArgumentSet.execute(ArgumentSet.java:132) 在 org.883176477.887s.88.matsu OQLPane$OQLJob.doRun(OQLPane.java:468) 在 org.eclipse.mat.ui.editor.AbstractPaneJob.run(AbstractPaneJob.java:34) 在 org.eclipse.Workerrun.jobcore.internal java:60)

Please advise.请指教。

There are several things wrong with that query.该查询有几处错误。 idx in SELECT c.getName() as name, c.getName().indexOf("com.mycompany") as idx FROM java.lang.Class c WHERE idx > 0 is a column name, so is not visible to the WHERE clause. idx in SELECT c.getName() as name, c.getName().indexOf("com.mycompany") as idx FROM java.lang.Class c WHERE idx > 0 WHERE不可见条款。 OQL evaluates the FROM clause first selecting a list of objects, then the c variable is visible to the WHERE clause where each of the objects is examined to see if it will be passed to the SELECT clauses. OQL 首先选择对象列表评估FROM子句,然后c变量对WHERE子句可见,其中检查每个对象以查看它是否将传递给SELECT子句。 So try:所以尝试:

SELECT c.getName() as name, c.getName().indexOf("com.mycompany") as idx FROM java.lang.Class c WHERE c.getName().indexOf("com.mycompany") > 0

but that fails for the reason:但失败的原因是:

Problem reported: 
Method getName() not found in object java.lang.Class [id=0x6c027f2c8] of type org.eclipse.mat.parser.model.InstanceImpl

because some java.lang.Class objects in the heap dump are in fact not ordinary classes which could have instances, but plain object instances of type java.lang.Class.因为堆转储中的某些 java.lang.Class 对象实际上不是可以具有实例的普通类,而是 java.lang.Class 类型的普通 object 实例。 That sounds odd, but those objects are byte , short , int , long , float , double , char , boolean , void .这听起来很奇怪,但这些对象是byteshortintlongfloatdoublecharbooleanvoid They are just used to describe classes and methods for reflection - but instances of those can't exist.它们只是用来描述用于反射的类和方法——但它们的实例不存在。

Inside of MAT objects in the heap dump are represented as org.eclipse.mat.snapshot.model.IObject and some are also of a subtype org.eclipse.mat.snapshot.model.IClass .堆转储中的 MAT 对象内部表示为org.eclipse.mat.snapshot.model.IObject并且一些也是子类型org.eclipse.mat.snapshot.model.IClass We need to exclude those 9 special objects above.我们需要排除上面的那 9 个特殊对象。 I've changed your query to look for com.sun as my dumps won't have com.mycompany objects.我已将您的查询更改为查找 com.sun,因为我的转储不会包含 com.mycompany 对象。

SELECT c.getName() AS name, c.getName().indexOf("com.sun") AS idx 
FROM java.lang.Class c 
WHERE ((c implements org.eclipse.mat.snapshot.model.IClass) and (c.getName().indexOf("com.sun") > 0))

This still doesn't work, because if the class name starts with 'com.sun' the index will be 0 and will fail the test.这仍然不起作用,因为如果 class 名称以 'com.sun' 开头,索引将为 0 并且将无法通过测试。 Change the test operator:更改测试操作员:

SELECT c.getName() AS name, c.getName().indexOf("com.sun") AS idx 
FROM java.lang.Class c 
WHERE ((c implements org.eclipse.mat.snapshot.model.IClass) and (c.getName().indexOf("com.sun") >= 0))

This now works and finds some classes.这现在可以工作并找到一些类。

We can simplify the query a little by using attribute notation, where @val is a bean introspection which is the equivalent of getVal().我们可以通过使用属性符号稍微简化查询,其中@val 是一个 bean 自省,它等同于 getVal()。

SELECT c.@name AS name, c.@name.indexOf("com.sun") AS idx 
FROM java.lang.Class c 
WHERE ((c implements org.eclipse.mat.snapshot.model.IClass) and (c.getName().indexOf("com.sun") >= 0)) 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM