What is Klass & KlassKlass

What is Klass and KlassKlass in the JVM Hotspot implementation?

As far as I understood from the article Introducing the Perm Generation , Klass is an internal representation of the Java class (say A ), and it will contain basic information about the structure of the class, including bytecode. It will be stored as the object itself. Each class A object will have a pointer to the Klass internal representation present in PermGen

KlassKlass is an internal representation of the Klass class itself. Why is KlassKlass required? What additional information does it store?

In addition, the KlassKlass's Klass pointer points to itself, I also did not understand this.

+20
java jvm permgen jvm-hotspot
May 23 '13 at 18:11
source share
3 answers

The permanent generation aka permgen is a link to the place where all class-related information is stored. This is sometimes called the scope of the method.

Let's look at an example of the following code:

 public class Parent { ... } 

Here:

  • new Parent() is an object of class Parent .
  • (new Parent()).getClass() refers to the Klass for the parent. The link type for this object will be java.lang.Class<Parent> . This will save information about Parent annotations, constructors, fields, methods, its inheritance (superclass, interfaces), etc.
  • The KlassKlass class will be (new Parent()).getClass().getClass() . The link type for this object will be java.lang.Class<java.lang.Class> . This defines information about java.lang.Class annotations, constructors, fields, methods, its inheritance (superclass, interfaces), etc.

Theoretically, this chain could go on, but the KlassKlassKlass class will be the same as the KlassKlass.

Turning on, KlassKlass means that you will have one java.lang.Class object that defines the behavior of java.lang.Class itself.

Hope this helps

+20
Jun 11 '13 at 20:22
source share

You seem to have a good understanding of storage management in HotSpot. To get more specific details, it's a good idea to go to the horse's mouth - in this case, the HotSpot developers. This page is a description of the storage management system.

In situations where I want to find out what code I am trying to find and find the code and read it. In this case, we can find an implementation of the KlassKlass class here . This does not seem to add additional information on top of Klass - which is very interesting to see. Note that KlassKlass continues with Klass .

So why do we need this? Well, we can highlight the Klass hierarchy of a particular program as a tree, where one Klass describes another. Everything needs a description, but we cannot continue it like this forever, we need to find a fixed point where the thing that we use to describe something is itself - so we can stop!

So, in a resume, KlassKlass does nothing more useful than the existing one. It must exist, but its existence is reasonably uninteresting.

+1
Jun 11 '13 at 23:10
source share

A class can be defined as a pattern / blue print describing the behavior / states that an object of its type supports.

-one
May 27 '13 at 10:13
source share



All Articles