 |
AppletTalk.com Java discussions newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
habib Guest
|
Posted: Fri Oct 21, 2005 7:15 am Post subject: Manipulate objects in heap |
|
|
Hi there,
I would like to access and manipulate live objects in heap directly in
a Java program.
Does the Sun JVM or other implementations of JVM allow this via their
APIs or I need to edit source code of an implementation and create some
APIs for this need?
Thank you in advance,
Habib
|
|
| Back to top |
|
 |
Stefan Schulz Guest
|
Posted: Fri Oct 21, 2005 12:03 pm Post subject: Re: Manipulate objects in heap |
|
|
On Fri, 21 Oct 2005 00:15:01 -0700, habib wrote:
| Quote: | Hi there,
I would like to access and manipulate live objects in heap directly in
a Java program.
Does the Sun JVM or other implementations of JVM allow this via their
APIs or I need to edit source code of an implementation and create some
APIs for this need?
|
class Foo {
int x = 5;
public int setX(int newX){
x = newX;
}
}
calling setX will manipulate the x field, which is in the heap. However,
i do not know if this is what you wanted to do. What do you want to do?
--
You can't run away forever,
But there's nothing wrong with getting a good head start.
--- Jim Steinman, "Rock and Roll Dreams Come Through"
|
|
| Back to top |
|
 |
habib Guest
|
Posted: Fri Oct 21, 2005 4:06 pm Post subject: Re: Manipulate objects in heap |
|
|
I need to add a method to a class, for example, in runtime. So, I need
to edit the heap in some way.
Anyway, thank you for your reply.
Habib
|
|
| Back to top |
|
 |
Oliver Wong Guest
|
Posted: Fri Oct 21, 2005 4:31 pm Post subject: Re: Manipulate objects in heap |
|
|
"habib" <habib.seif (AT) gmail (DOT) com> wrote
| Quote: | Hi there,
I would like to access and manipulate live objects in heap directly in
a Java program.
Does the Sun JVM or other implementations of JVM allow this via their
APIs or I need to edit source code of an implementation and create some
APIs for this need?
Thank you in advance,
Habib
|
"habib" <habib.seif (AT) gmail (DOT) com> wrote
| Quote: | I need to add a method to a class, for example, in runtime. So, I need
to edit the heap in some way.
|
To answer your original question, I don't think there's an API provided
to do what you want to do.
I'm also curious as to why you *need* to add methods to a class. I'm
pretty sure whatever you want to do by adding methods to a class at runtime
can be done without adding methods to a class at runtime (my evidence is
Turing-Completeness of the Java language), so as Stefan mentioned in an
earlier post:
"Stefan Schulz" <terra (AT) spacetime (DOT) de> wrote
| Quote: | What do you want to do?
|
- Oliver
|
|
| Back to top |
|
 |
Andrew Thompson Guest
|
Posted: Fri Oct 21, 2005 5:02 pm Post subject: Re: Manipulate objects in heap |
|
|
Oliver Wong wrote:
| Quote: | I'm also curious as to why you *need* to add methods to a class.
|
To the OP. Can you fill in the blank?
This feature provides ______ to the end user.
[ I think that will help us all understand what you are
trying to achieve. ]
|
|
| Back to top |
|
 |
Thomas Fritsch Guest
|
Posted: Fri Oct 21, 2005 5:14 pm Post subject: Re: Manipulate objects in heap |
|
|
habib wrote:
| Quote: | I need to add a method to a class, for example, in runtime. So, I need
to edit the heap in some way.
Anyway, thank you for your reply.
There are very few reasons thinkable, why one may want to add a method |
to a class at runtime.
The only place I know of, where such things are done, are profilers or
coverage tools. Such tools hook themselves into class-loading and add
some byte-code to the loaded classes. Since Java1.5 there is package
java.lang.instrument, which makes developing of such tools easier.
<http://java.sun.com/j2se/1.5.0/docs/api/java/lang/instrument/package-summary.html>
But I very much doubt, that your application falls into this category.
--
"Thomas:Fritsch$ops:de".replace(':','.').replace('$','@')
|
|
| Back to top |
|
 |
Ross Bamford Guest
|
Posted: Fri Oct 21, 2005 7:24 pm Post subject: Re: Manipulate objects in heap |
|
|
On Fri, 21 Oct 2005 17:06:00 +0100, habib <habib.seif (AT) gmail (DOT) com> wrote:
| Quote: | I need to add a method to a class, for example, in runtime. So, I need
to edit the heap in some way.
Anyway, thank you for your reply.
Habib
|
Whether you can do exactly what you want to do depends on a number of
factors, such as:
+ is the class final?
+ do you need data from existing instances, or new instances with new
features?
+ Are you in a security managed environment? Do you have the ability to
set permissions?
There is an open source API to do what you want to do -
http://jen.dev.java.net/ . It can do pretty much anything to a class
(including at runtime) but whether you can then do anything with the
result very much depends on the answers you gave above.
The other question is, do you want to add a method to a class, or create a
subclass with a new method? Again, you can do both, but the above
questions have a bearing on how you use the result, and which of the
provided tools will do the job.
--
Ross Bamford - [email]rosco (AT) roscopeco (DOT) remove.co.uk[/email]
|
|
| Back to top |
|
 |
habib Guest
|
Posted: Fri Oct 21, 2005 7:24 pm Post subject: Re: Manipulate objects in heap |
|
|
Hi all,
It sounds all of you intersted in my reason of changing classes in
runtime.
If we could so, we could change software without stopping it and
therefore avalibility becomes higher.
Anyway, thank you for your replies.
|
|
| Back to top |
|
 |
Oliver Wong Guest
|
Posted: Fri Oct 21, 2005 9:59 pm Post subject: Re: Manipulate objects in heap |
|
|
"habib" <habib.seif (AT) gmail (DOT) com> wrote
| Quote: | Hi all,
It sounds all of you intersted in my reason of changing classes in
runtime.
If we could so, we could change software without stopping it and
therefore avalibility becomes higher.
Anyway, thank you for your replies.
|
Well, presumably, not only will you then need to add methods to a class,
but also to somehow modify existing methods. Or else how do you plan on
calling the newly added methods?
And if you're going to modify existing methods, you might have to
untangle the optimized code that the JIT compiler produced, and that sounds
like a big headache.
What about the solution of unloading a class, modifying the class file,
and then reloading it? Or having "two versions" of the "same" class loaded
in memory at a time, with one of them considered deprecated, and released as
soon as the last client code finishes using it?
Anyway, if you really are going this route, I'd imagine
comp.lang.java.machine might be a more appropriate group, since knowledge of
the implementations of JVMs will undoubtly be helpful in implementing what
you're trying to do.
- Oliver
|
|
| Back to top |
|
 |
Roedy Green Guest
|
Posted: Sat Oct 22, 2005 1:19 am Post subject: Re: Manipulate objects in heap |
|
|
On 21 Oct 2005 09:06:00 -0700, "habib" <habib.seif (AT) gmail (DOT) com> wrote or
quoted :
| Quote: | I need to add a method to a class, for example, in runtime. So, I need
to edit the heap in some way.
Anyway, thank you for your reply.
|
You came from a SmallTalk environment?
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
|
|
| Back to top |
|
 |
Roedy Green Guest
|
Posted: Sat Oct 22, 2005 1:49 am Post subject: Re: Manipulate objects in heap |
|
|
On Fri, 21 Oct 2005 21:59:17 GMT, "Oliver Wong" <owong (AT) castortech (DOT) com>
wrote or quoted :
| Quote: | And if you're going to modify existing methods, you might have to
untangle the optimized code that the JIT compiler produced, and that sounds
like a big headache.
|
understatement of the year.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
|
|
| Back to top |
|
 |
Ross Bamford Guest
|
Posted: Sat Oct 22, 2005 2:01 am Post subject: Re: Manipulate objects in heap |
|
|
On Sat, 22 Oct 2005 02:49:11 +0100, Roedy Green
<my_email_is_posted_on_my_website (AT) munged (DOT) invalid> wrote:
| Quote: | On Fri, 21 Oct 2005 21:59:17 GMT, "Oliver Wong"
wrote or quoted :
And if you're going to modify existing methods, you might have to
untangle the optimized code that the JIT compiler produced, and that
sounds
like a big headache.
understatement of the year.
|
It's not as big a concern as you'd imagine if done correctly. You must
remember that the JIT operates entirely transparently and entirely
optionally, even from the point of view of the .class file and bytecode
therein. So when a method changes a naive (but workable) option would be
to dump any optimizations from the prior one, and start from scratch.
The more complicated problem (as Oliver touched on) is you have to take
into account currently executing methods. The way they tackled this in the
1.5 instrumentation API (and especially in Mustang, which adds the ability
to retransform, as well as redefine classes, which effectively means we
can change methods on instances from 1.6 up) was to have the transformed
method applied only to post-transform invocations, while the previous code
was retained (presumably at a relocated index) while it had active stack
frames. So of course any JIT'd code for those would stick around, until
the method itself is cleared (assuming, of course, that it is).
--
Ross Bamford - [email]rosco (AT) roscopeco (DOT) remove.co.uk[/email]
|
|
| Back to top |
|
 |
habib Guest
|
|
| Back to top |
|
 |
habib Guest
|
Posted: Sat Oct 22, 2005 1:22 pm Post subject: Re: Manipulate objects in heap |
|
|
I think about all of issues you wrote. There are so many solutions to
them if you look at some papers in this area.
I myself write a paper and introduce some of isuues and their solutions
but my problem is implementing them.
Of course, the two excellent sites Ross sent, can help me in
implementing my ideas in a JVM a lot.
|
|
| Back to top |
|
 |
Ross Bamford Guest
|
Posted: Sat Oct 22, 2005 2:57 pm Post subject: Re: Manipulate objects in heap |
|
|
On Sat, 22 Oct 2005 14:17:17 +0100, habib <habib.seif (AT) gmail (DOT) com> wrote:
| Quote: | The site you introduced helped me a lot.
|
Glad to be of service I'd definitely be interested to know how your
research turns out.
--
Ross Bamford - [email]rosco (AT) roscopeco (DOT) remove.co.uk[/email]
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|