title: Is there a simple way of obtaining all object instances of a specific class in Java
body: <p>Currently I am working on a Java agent to assemble memory stats. With the help of the <a href="https://docs.oracle.com/javase/6/docs/api/java/lang/instrument/Instrumentation.html" rel="nofollow noreferrer">instrumentation API</a> I can get a hold of the classes (and manipulate them). With plain Java I can get an estimate of the resources used for each object. So far, so good.</p>
  <p>The question I am faced with right now is &quot;how to get a hold of every Object instance of a specific class&quot;. I can do byte code manipulation in order to get a hold of the object instance, but I was hoping there is another API I am not aware of, helping me to accomplish my goal without such a rather heavy intrusive step. At the end, the performance impact should be kept to a minimum. Any ideas?</p>