AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Manipulate objects in heap
Goto page 1, 2  Next
 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Help
View previous topic :: View next topic  
Author Message
habib
Guest





PostPosted: Fri Oct 21, 2005 7:15 am    Post subject: Manipulate objects in heap Reply with 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

Back to top
Stefan Schulz
Guest





PostPosted: Fri Oct 21, 2005 12:03 pm    Post subject: Re: Manipulate objects in heap Reply with quote



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





PostPosted: Fri Oct 21, 2005 4:06 pm    Post subject: Re: Manipulate objects in heap Reply with 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

Back to top
Oliver Wong
Guest





PostPosted: Fri Oct 21, 2005 4:31 pm    Post subject: Re: Manipulate objects in heap Reply with quote


"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





PostPosted: Fri Oct 21, 2005 5:02 pm    Post subject: Re: Manipulate objects in heap Reply with quote

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





PostPosted: Fri Oct 21, 2005 5:14 pm    Post subject: Re: Manipulate objects in heap Reply with quote

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





PostPosted: Fri Oct 21, 2005 7:24 pm    Post subject: Re: Manipulate objects in heap Reply with quote

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





PostPosted: Fri Oct 21, 2005 7:24 pm    Post subject: Re: Manipulate objects in heap Reply with 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.

Back to top
Oliver Wong
Guest





PostPosted: Fri Oct 21, 2005 9:59 pm    Post subject: Re: Manipulate objects in heap Reply with quote


"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





PostPosted: Sat Oct 22, 2005 1:19 am    Post subject: Re: Manipulate objects in heap Reply with quote

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





PostPosted: Sat Oct 22, 2005 1:49 am    Post subject: Re: Manipulate objects in heap Reply with quote

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





PostPosted: Sat Oct 22, 2005 2:01 am    Post subject: Re: Manipulate objects in heap Reply with quote

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





PostPosted: Sat Oct 22, 2005 1:17 pm    Post subject: Re: Manipulate objects in heap Reply with quote

The site you introduced helped me a lot.
I think https://jen.dev.java.net and http://asm.objectweb.org have a
lot for me.

Back to top
habib
Guest





PostPosted: Sat Oct 22, 2005 1:22 pm    Post subject: Re: Manipulate objects in heap Reply with quote

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





PostPosted: Sat Oct 22, 2005 2:57 pm    Post subject: Re: Manipulate objects in heap Reply with quote

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 Smile 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
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Help All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.