Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Memory Analyzer » OQL: how to define JS functions
OQL: how to define JS functions [message #651339] Sat, 29 January 2011 13:50 Go to next message
Iulian Dragos is currently offline Iulian DragosFriend
Messages: 23
Registered: July 2009
Junior Member
Hello,

I'd like to define and use a Javascript function for computing some of the data that I want to extract. I tried something like:

function resourceName(eclipseFile) {
    var name = ""
    for (part in eclipseFile.parts)
		name += "/" + part
	return name
}

select resourceName(ef) from org.eclipse.core.runtime.Path


but it seems to reject it. VisualVM allows full javascript programs, is there a way to achieve the same in MAT?

thanks,
iulian
Re: OQL: how to define JS functions [message #651456 is a reply to message #651339] Mon, 31 January 2011 07:31 Go to previous messageGo to next message
Krum Tsvetkov is currently offline Krum TsvetkovFriend
Messages: 164
Registered: July 2009
Senior Member
Hello,

With MAT you can't use javascript (or other scripting language) for quering the heap dump.
We decided to offer a SQL-like query langluage for simpler queries and Java API for more complex calculations.
For the latter MAT offers a number of (Eclipse) extension points. If you implement for example an IQuery, pack it in a plugin and install it with MAT, then you'll see it as an item in the tool's menus, you can pass it objects from other "standard" MAT commands, etc...

We have some documentation on this topic here:
http://wiki.eclipse.org/index.php?title=MemoryAnalyzer/Contr ibutor_Reference#Writing_plugins_for_the_Memory_Analyzer

Does this help?

Krum
Re: OQL: how to define JS functions [message #651471 is a reply to message #651456] Mon, 31 January 2011 09:55 Go to previous messageGo to next message
Iulian Dragos is currently offline Iulian DragosFriend
Messages: 23
Registered: July 2009
Junior Member
Krum Tsvetkov wrote on Mon, 31 January 2011 02:31
Hello,

With MAT you can't use javascript (or other scripting language) for quering the heap dump.
We decided to offer a SQL-like query langluage for simpler queries and Java API for more complex calculations.
For the latter MAT offers a number of (Eclipse) extension points. If you implement for example an IQuery, pack it in a plugin and install it with MAT, then you'll see it as an item in the tool's menus, you can pass it objects from other "standard" MAT commands, etc...

We have some documentation on this topic here:
http://wiki.eclipse.org/index.php?title=MemoryAnalyzer/Contr ibutor_Reference#Writing_plugins_for_the_Memory_Analyzer

Does this help?



Yes it does, thank you! It would be very nice to present a programatic interface in addition to the extension points. Do you think that's feasible? A query mechanism based on an interpreted language like javascript, a la VisualVM?
Re: OQL: how to define JS functions [message #651484 is a reply to message #651456] Mon, 31 January 2011 10:47 Go to previous messageGo to next message
Iulian Dragos is currently offline Iulian DragosFriend
Messages: 23
Registered: July 2009
Junior Member
Krum Tsvetkov wrote on Mon, 31 January 2011 02:31
Hello,
We have some documentation on this topic here:
http://wiki.eclipse.org/index.php?title=MemoryAnalyzer/Contr ibutor_Reference#Writing_plugins_for_the_Memory_Analyzer

Does this help?


I was trying to write a simple extension for my classes. I could not find the javadocs of MAT, are they published somewhere? Is there a way to specify more than one classname that is handled by my extension? I'd like to pack several in one go.

thanks!
iulian
Re: OQL: how to define JS functions [message #651537 is a reply to message #651484] Mon, 31 January 2011 15:26 Go to previous messageGo to next message
Krum Tsvetkov is currently offline Krum TsvetkovFriend
Messages: 164
Registered: July 2009
Senior Member
Quote:
I could not find the javadocs of MAT, are they published somewhere?

You can currently find the javadoc only in the help of the tool, i.e. if you have MAT installed, the open the Help and then "Memory Analyzer" -> "Reference" -> "API Reference".

There you'll find also some description of the extension points.

Quote:
Is there a way to specify more than one classname that is handled by my extension? I'd like to pack several in one go.

Yes, you can pack more than one IQuery implementations (and also other extensions) in one plugin. MAT itself does this.

I know that we need to improve on documenting how excensions are written and also provide some examples. For the moment you could probably look into MAT sources as a reference.

Quote:
It would be very nice to present a programatic interface in addition to the extension points. Do you think that's feasible?

This would be the middle way - less effort than the extensions implementation, but still more flexibility than plain OQL. However, at the moment such an improvement is not planned. I think it will be better to spend more time documenting how one can use the extension points and provide good samples for this, rather than starting a new alternative, befor having the first really finished. But this is only my personal opinion, I'd be happy to hear more oppinions on this.

Krum
Re: OQL: how to define JS functions [message #651555 is a reply to message #651537] Mon, 31 January 2011 16:11 Go to previous messageGo to next message
Iulian Dragos is currently offline Iulian DragosFriend
Messages: 23
Registered: July 2009
Junior Member
Krum Tsvetkov wrote on Mon, 31 January 2011 10:26
Quote:
I could not find the javadocs of MAT, are they published somewhere?

You can currently find the javadoc only in the help of the tool, i.e. if you have MAT installed, the open the Help and then "Memory Analyzer" -> "Reference" -> "API Reference".
Quote:
It would be very nice to present a programatic interface in addition to the extension points. Do you think that's feasible?

This would be the middle way - less effort than the extensions implementation, but still more flexibility than plain OQL. However, at the moment such an improvement is not planned. I think it will be better to spend more time documenting how one can use the extension points and provide good samples for this, rather than starting a new alternative, befor having the first really finished. But this is only my personal opinion, I'd be happy to hear more oppinions on this.

Krum


Having a programatic interface is nice because one does not need to install new plugins, and can have a much shorter cycle when testing different queries. Deployment is not always easy.

I have my extensions working fine in the debug build (so launching a second instance of Eclipse picks up my changes), but I cannot deploy it in my default Eclipse installation. I followed the guide and exported my plugin to a directory, and placed the resulting jar in the dropins/ directory of my Eclipse installation. My plugin appears in Installation Details, but it doesn't get called. Any idea what is going wrong?

thanks
Re: OQL: how to define JS functions [message #651558 is a reply to message #651555] Mon, 31 January 2011 16:16 Go to previous messageGo to next message
Iulian Dragos is currently offline Iulian DragosFriend
Messages: 23
Registered: July 2009
Junior Member
Iulian Dragos wrote on Mon, 31 January 2011 11:11

I have my extensions working fine in the debug build (so launching a second instance of Eclipse picks up my changes), but I cannot deploy it in my default Eclipse installation. I followed the guide and exported my plugin to a directory, and placed the resulting jar in the dropins/ directory of my Eclipse installation. My plugin appears in Installation Details, but it doesn't get called. Any idea what is going wrong?


Sorry for the noise. I just checked that the exported jar file contained only the sources. It's working fine now.

thank you
Re: OQL: how to define JS functions [message #651678 is a reply to message #651555] Tue, 01 February 2011 08:44 Go to previous messageGo to next message
Krum Tsvetkov is currently offline Krum TsvetkovFriend
Messages: 164
Registered: July 2009
Senior Member
Iulian Dragos wrote on Mon, 31 January 2011 17:11

Having a programatic interface is nice because one does not need to install new plugins, and can have a much shorter cycle when testing different queries. Deployment is not always easy.


I agree. I think we should open a bugzilla ticket for this request. I can't tell currently if and when we'll be able to work on it. I'll be happy if we get some contributions in this area Smile

Will you open the bug, or shall I do it?

Krum
Re: OQL: how to define JS functions [message #651692 is a reply to message #651678] Tue, 01 February 2011 10:17 Go to previous messageGo to next message
Iulian Dragos is currently offline Iulian DragosFriend
Messages: 23
Registered: July 2009
Junior Member
Krum Tsvetkov wrote on Tue, 01 February 2011 03:44
I agree. I think we should open a bugzilla ticket for this request. I can't tell currently if and when we'll be able to work on it. I'll be happy if we get some contributions in this area Smile

Will you open the bug, or shall I do it?



I did: https://bugs.eclipse.org/bugs/show_bug.cgi?id=335943

I would love to help. I don't have much time right now, and I'm not very experienced with Eclipse, but I do have some experience with programming languages. You can see what I managed to do yesterday regarding name resolvers here:

https://github.com/dragos/MAT-name-resolver

Given the right extension points, I could start by contributing some simple plugins.

BTW: the documentation says the following about 'dominators(s)': The objects immediately dominated by s. That's a bit confusing, shouldn't it be 'dominated'? or 'dominatedSet'? To me, dominators sounds more like the nodes that dominate s, directly or indirectly. BTW, I think it would be helpful to have a function 'dominatorChain', which returns the chain of dominators of an object, up to a GC root. Or alternatively, a predicate 'dominates(a, b)' which is true when a dominates b (directly on indirectly). Both functions could be written with the available primitives, so this could be another argument in favor of a scripting engine! Wink

thanks,
iulian
Re: OQL: how to define JS functions [message #656030 is a reply to message #651692] Wed, 23 February 2011 19:46 Go to previous messageGo to next message
Krishna R is currently offline Krishna RFriend
Messages: 5
Registered: February 2011
Junior Member
I second the scripting support request - i'm writing a few queries/reports for my application, and was thinking of writing a Groovy sdk for walking the snapshot, but didn't get the time...

I will post if and when I do something on that...
Re: OQL: how to define JS functions [message #1064334 is a reply to message #656030] Tue, 18 June 2013 19:02 Go to previous messageGo to next message
Robin Salkeld is currently offline Robin SalkeldFriend
Messages: 8
Registered: June 2013
Junior Member
Greetings all,

I know this is an old thread, but I thought I'd post because I've built something that I think addresses this need. I'm a PhD candidate at the University of British Columbia, and as part of my dissertation project I've built a kind of JVM emulator library which is able to simulate executing code without an actual live JVM. In particular, this makes it possible to run code on a heap dump as if it's a live process.

I've always thought that being able to run your own Java code against a heap dump would be a far easier and more effective approach to the kind of programmatic analysis. Take the example at the top of this thread, which involves trying to reconstruct the file path the Eclipse Path object is for. All you'd need to do is call the Path#toString() method, which is actually (looking at the latest version) a lot more complicated than the javascript function!

Anyway, my selfish motive Smile is that I'm trying to come up with some cool examples of using this capability to do useful debugging or analysis of heap dumps. If any of you could describe what you were hoping to do with the scripting support I would greatly appreciate it. I've packaged up my system as a few Eclipse plugins and can make them available to anyone who wants to play with them.

Iulian, you might be particularly interested in this (or would have been two years ago Smile) regarding your Scala name resolver. In a similar vein, I was able to use my tool to print out a Ruby thread dump from a JRuby heap dump!

Thanks,
Robin

[Updated on: Tue, 18 June 2013 19:05]

Report message to a moderator

Re: OQL: how to define JS functions [message #1064365 is a reply to message #1064334] Tue, 18 June 2013 22:15 Go to previous messageGo to next message
Krishna R is currently offline Krishna RFriend
Messages: 5
Registered: February 2011
Junior Member
Hi Robin,

this is very interesting and I would like to sign up for a trial Smile

I have built a "Groovy Query Language" - with simplified APIs to walk the heap and also to add scripts to define NameResolver/ThreadResolvers & Queries. I mean to refactor the code before publishing (which ashamedly never happened).

Please share your stuff - I will test and let know my opinions, I will try to publish mine this weekend anyways...

Cheers,
Krishna
Re: OQL: how to define JS functions [message #1065155 is a reply to message #1064334] Mon, 24 June 2013 14:06 Go to previous messageGo to next message
Iulian Dragos is currently offline Iulian DragosFriend
Messages: 23
Registered: July 2009
Junior Member
Robin Salkeld wrote on Tue, 18 June 2013 15:02
Greetings all,

I know this is an old thread, but I thought I'd post because I've built something that I think addresses this need. I'm a PhD candidate at the University of British Columbia, and as part of my dissertation project I've built a kind of JVM emulator library which is able to simulate executing code without an actual live JVM. In particular, this makes it possible to run code on a heap dump as if it's a live process.


Sounds cool, any pointers/papers?

Quote:
I've always thought that being able to run your own Java code against a heap dump would be a far easier and more effective approach to the kind of programmatic analysis. Take the example at the top of this thread, which involves trying to reconstruct the file path the Eclipse Path object is for. All you'd need to do is call the Path#toString() method, which is actually (looking at the latest version) a lot more complicated than the javascript function!


In general, I want to be able to define my own functions. In this particular case `toString` would suffice, but I need the added flexibility (`toString` might not be defined on other types, or might do the wrong thing)

Quote:
Anyway, my selfish motive Smile is that I'm trying to come up with some cool examples of using this capability to do useful debugging or analysis of heap dumps. If any of you could describe what you were hoping to do with the scripting support I would greatly appreciate it. I've packaged up my system as a few Eclipse plugins and can make them available to anyone who wants to play with them.


Please do, I'd love to give it a try!

iulian
Re: OQL: how to define JS functions [message #1065219 is a reply to message #1065155] Mon, 24 June 2013 20:14 Go to previous messageGo to next message
Robin Salkeld is currently offline Robin SalkeldFriend
Messages: 8
Registered: June 2013
Junior Member
Hi Krishna and iulian,

Fabulous, I will definitely make my tools available for you guys in the near future. Naturally it's a research project so it needs polish, but if you're willing to trip over the occasional error your feedback would be very valuable!

There's no documentation/papers on it out there yet. In fact at the moment I'm pegged trying to get the first paper on it published! Smile Once I get past the deadline in a few weeks I can take some time to clean it up and hook up some missing UI so it's easy to use.

iulian, you will definitely be able to define your own functions too. The trick is to dynamically load Java classes into the simulated JVM. You can write new Java code off to the side (probably static methods), tell a class loader in the JVM to load the bytecode for it, and then invoke the methods from the Eclipse MAT UI. I will be sure to make that workflow as smooth as possible. Smile

Cheers,
Robin
Re: OQL: how to define JS functions [message #1108393 is a reply to message #1065219] Fri, 13 September 2013 20:00 Go to previous message
Robin Salkeld is currently offline Robin SalkeldFriend
Messages: 8
Registered: June 2013
Junior Member
Hi all,

I'm happy to say that I've finally made my tool available for installation into Eclipse. It adds a few additional custom queries to the Memory Analyzer tool.

https://github.com/robinsalkeld/retrospect/

I've done my best to document the basics but it's still very much a research prototype. Smile The technique is described in detail in my upcoming OOPSLA paper: Interacting with Dead Objects.

Enjoy, and don't hesitate to contact me for help or feedback! My email address is rsalkeld "at" cs.ubc.ca.

Cheers,
Robin
Previous Topic:heap dump file size larger than the heap size
Next Topic:What would you do if you could run code on heap dumps?
Goto Forum:
  


Current Time: Thu Mar 28 19:06:09 GMT 2024

Powered by FUDForum. Page generated in 0.04799 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top