Getting reference
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Sebastien_Comeau
Posted On:   Thursday, June 14, 2001 08:12 AM

Hi, I want to write a command line (or shell) for an application we are developping. I managed to create the command line and it works. My shell use reflection to create and manipulate objects. Now, the next task is to get reference to the objects in the application. Let's say I want to instantiate an object that take as an argument, the parent window. I want to be able to get a reference to the parent window and pass it to the object I want to create. The parent window is instantiated by the application. I want to search the heap or do something else, to get the reference to an object I know is instantiated by the application. Is this possible? If so, what should I use? JNI? Create a debugger and get    More>>

Hi,


I want to write a command line (or shell) for an application we are developping. I managed to create the command line and it works. My shell use reflection to create and manipulate objects.



Now, the next task is to get reference to the objects in the application. Let's say I want to instantiate an object that take as an argument, the parent window. I want to be able to get a reference to the parent window and pass it to the object I want to create. The parent window is instantiated by the application. I want to search the heap or do something else, to get the reference to an object I know is instantiated by the application.



Is this possible? If so, what should I use? JNI? Create a debugger and get the reference from the vm that runs the application?


thanks,

Sebastien

   <<Less

Re: Getting reference

Posted By:   Sandip_Chitale  
Posted On:   Thursday, June 14, 2001 09:25 AM

No it cannot be done easily.



The references returned by the debugger are proxies and not the original object references. i.e. There Types are completely different e.g. JPDA returns
com.sun.jdi.ObjectReference (implementation) for every object reference in the debugee.


Unless you intercept the creation of every object in the VM, store the reference to it in a WeakHashMap (otherwise the garbage
collection will never work) using some kind of name(?) as a key. You could use
a the name to look it up in the
WeakHashMap later. You will have to basically maintain a Symbol Table. You may want to implement Symbol Scopes and soon you software starts approaching what are called Java Shells. That wheel has already been invented several times.
Please look into -



  • BeanShell (www.beanshell.org)

  • DynamicJava (http://www-sop.inria.fr/koala/djava/)

  • PNUTS (http://javacenter.sun.co.jp/pnuts/)


But the fact that it is possible to write such a tool (using Reflection) in Java is fantastic.
About | Sitemap | Contact