Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we view objects in the JVM memory?

At work we found that on some instances (particulary the slow ones) we have a different behaviour, acquired at the reboot.

We guess a cache is not initialized correctly, or maybe a concurrency problem... Anyway it's not reproductible in any other env than production.

We actually don't have loggers to activate... it's an old component...

Thus i'd like to know if there are tools that can help us to see the different objets present in the JVM memory in order to check the content of the cache...

Thank you!

Edit:

I don't have access to the production servers directly, our app server is weblogic 10, i don't have a pointer to the object but i know the cache object type...

Edit2:

Our servers are running on jre 1.5, is it possible to use jmap? Can't find it in a jdk5 :( Also, remote debugging could be nice but we can't for security reasons...

Edit3:

Actually jhat + VisualVM is ok for me, i found my object in dump but i'm not able to read the hashmap (object containing about 60000 items) properly... Is there a tool to read a concurrenthashmap in a friendly way? i need to find the value of a key (or its existence in the map) without browsing manually the 60k records. Actually i read on eclipse MAT forum that it's also not possible with it...

Edit4: After some experiences i really like tools like VisualVM. Also used YourKit. There are some useful features like OQL to find the right instances you need to look at...

like image 729
Sebastien Lorber Avatar asked May 11 '10 17:05

Sebastien Lorber


People also ask

How are objects stored in JVM?

Every time when a string object is created, JVM will create it in a heap memory. In this case, the JVM will not check whether the string already exists or not. If a string already exist , then also for every string object the memory will get created separately. Here, the JVM is bond to create a new memory.

In which memory is objects created in JVM?

3. Heap Space in Java. Heap space is used for the dynamic memory allocation of Java objects and JRE classes at runtime. New objects are always created in heap space, and the references to these objects are stored in stack memory.

Where does the JVM store objects?

When we create an object for the class that . class file will be loaded into the jvm heap. And that object reference will be stored in the stack memory.

How objects are stored in memory in Java?

In Java, all objects are dynamically allocated on Heap. This is different from C++ where objects can be allocated memory either on Stack or on Heap. In C++, when we allocate the object using new(), the object is allocated on Heap, otherwise on Stack if not global or static.


2 Answers

This is basically to expand on what Will said. I've had great success by having our admins do a heapdump of our production systems, though with the caveat that the particular server you are dumping will be non-responsive until the dump completes. Then getting that file and using the Eclipse MAT plugin to look at it. If you don't like Eclipse, Netbeans and the plain VisualVM plugin can be used as well. This can create some big files though, you may need to run on a 64 bit system.

like image 65
mezmo Avatar answered Sep 20 '22 10:09

mezmo


It's fairly easy to run jmap to dump a COUNT of object instances, but I don't know if that's what you're really interested in.

You can also use jmap to do a heap dump of the entire heap, and with that (and jhat), you can see object RELATIONSHIPs (i.e. what object points to what), but not necessarily object CONTENTS.

Certainly the data is there in the heap dump, it's not "click away" visible.

Some of the professional profilers I think will let you introspect objects in a heap dump.

Otherewise you'd be better off adding some specific instrumentation to the application to provide the specific introspection you're looking for, triggered by custom code, JMX, or whatever.

like image 34
Will Hartung Avatar answered Sep 20 '22 10:09

Will Hartung