Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 324967 - Hide queries which are not relevant
Summary: Hide queries which are not relevant
Status: RESOLVED FIXED
Alias: None
Product: MAT
Classification: Tools
Component: GUI (show other bugs)
Version: 1.1   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: 1.10.0   Edit
Assignee: Andrew Johnson CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-09-10 10:10 EDT by Andrew Johnson CLA
Modified: 2019-10-29 05:21 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Johnson CLA 2010-09-10 10:10:06 EDT
Some user written queries might only apply for dumps when certain software was running. Having the queries appear all the time in the query menu and query browser is confusing, and will get more so with additional queries e.g. JRuby

The queries are context sensitive and will only appear if the required data is available. This is useful for queries such as unreachable objects, or path to GC roots which doesn't work with multiple objects.

If this could be extended, e.g. so queries only appear if a certain class is present in the dump or as the type of objects in the  selection then that might help.

The @Subject annotation is used for name resolvers. Perhaps this could be used for queries.
Comment 1 Andrew Johnson CLA 2011-11-28 07:55:56 EST
One way would be tagging queries as:
@Subject("org.eclipse.osgi.framework.internal.core.BundleRepository")
public class BundleRegistryQuery implements IQuery

Another would be something like this to indicate that the IClass should be filled in with the particular class. (Consider duplicate classes though.) How does this work with object selections - does the selection have to be a class object, or does it take the type of the selected object?
public class BundleRegistryQuery implements IQuery
    @Argument(filter="org.eclipse.osgi.framework.internal.core.BundleRepository")
    public IClass cls;
    
Another would be the following to say that all objects need to be of a particular type. Would this reject the query if not all the selection were of the required type, or would it just omit those objects (and possibly reject the query if no objects were then found)?

public class BundleRegistryQuery implements IQuery
    @Argument(filter="java.util.AbstractMap")
    public IHeapObjectArgument args;
    
or

public class BundleRegistryQuery implements IQuery
    @Subject("java.util.AbstractMap")
    @Argument
    public IHeapObjectArgument args;

@Subject is declared in the org.eclipse.mat.api bundle so isn't available to the org.eclipse.mat.report bundle, so QueryDescriptor can't do anything with @Subject

The normal way of checking whether queries can be used is something like:
query.accept(editor.getQueryContext()) && policy.accept(query)

The first part says whether the data type is available for each argument, and then policy determines whether the selection context e.g. single or multiple objects or none etc. is suitable for the query, so e.g. a query not expecting an object or selection won't appear as a pop-up query.

query is QueryDescriptor.accept in o.e.mat.report, which for each argument does 
if (!context.available(argument.getType(), argument.getAdvice()) && //
                            !context.converts(argument.getType(), argument.getAdvice()))

and the context.available() is defined in o.e.mat.api or o.e.mat.ui
context.available() is used to see if a particular type is available from the query context, with a little bit of extra information from the Advice for the particular argument. There isn't quite enough information to tag say an IClass argument with a name to say only fill this in with a particular class as the Advice is just an Enum, and the whole argument is not available to the context.available call.
The actual instance of the query is not yet available, so we cannot see if the argument has a default value and use that to flag the argument as being required to be a particular type.

The policy might be usable to control how or whether arguments are filled in.

It would be useful if new queries still worked on old versions of MAT.
Comment 2 Andrew Johnson CLA 2012-01-27 08:57:58 EST
I have check in some code to use Subject and Subjects annotations on queries. I've marked this use as experimental as I'm not sure if this is the best way yet.

I've also modified the query history so it only displays a query in the history if the context, policy and subjects support it.

I've also tagged the two Eclipse queries, the bundle explorer and leaking bundles query. This showed a bug as the leaking bundles query
didn't appear on an Eclipse dump, and it seems the class name has changed, so I updated the query.

@Subjects({"org.eclipse.osgi.framework.internal.core.BundleLoaderProxy", "org.eclipse.osgi.internal.loader.BundleLoaderProxy"})
Comment 3 Eclipse Genie CLA 2019-03-14 12:16:10 EDT
New Gerrit change created: https://git.eclipse.org/r/138741
Comment 5 Andrew Johnson CLA 2019-10-24 06:19:24 EDT
The above are changes for @Subject for the weak reference and finalizer reference queries.
Comment 6 Andrew Johnson CLA 2019-10-24 10:11:56 EDT
Ideally the ArraysBySizeQuery would have:
@Subjects({"byte[]", "boolean[]", "short[]", "char[]", "int[]", "float[]", "long[]", "double[]", "java.lang.Object[]"})

and QueryContextMenu - the pop-up menu on button 2 clicking on some results would only show the query if at least one object matched that selection.
We have to be a bit careful for performance - we can't check millions of objects.
We also need to be careful about matching subclasses. In the Java language, Object[] has a superclass of Object, and String[][] also has a superclass of
object, but is an instance of Object[][] or even Object[]. It would be useful though if Subjects("java.lang.Number[][]") matched java.lang.Long[][].

Possible technique:
Check the subject classes exist in the dump - if there are not then disallow the query.
Check up to a limit (1000?, 1000?) objects to see if any match the subjects. If there are more objects than the limit, allow the query.
Special case IContextObjectSet from a class histogram or superclass histogram as we can just check the class type instead of all the objects.
Comment 7 Eclipse Genie CLA 2019-10-25 10:30:49 EDT
New Gerrit change created: https://git.eclipse.org/r/151634
Comment 9 Eclipse Genie CLA 2019-10-27 09:30:22 EDT
New Gerrit change created: https://git.eclipse.org/r/151671
Comment 11 Andrew Johnson CLA 2019-10-27 10:39:26 EDT
I've done the changes I have in mind - now it is a case of testing them.
Comment 12 Andrew Johnson CLA 2019-10-27 10:40:03 EDT
The collection queries now have @Subjects annotations so they only appear when useful.
Comment 13 Eclipse Genie CLA 2019-10-29 02:35:54 EDT
New Gerrit change created: https://git.eclipse.org/r/151726
Comment 15 Andrew Johnson CLA 2019-10-29 05:21:22 EDT
I have done all my changes.
We just need to check that the context menu pop-up isn't slow on huge dumps. If it is then we need to know the exact type of selection, from which query and
which selected objects, so that we can fix QueryContextMenu.