Java8_ from permanent generation to Metaspace

Source: Internet
Author: User
Tags deprecated

Java8_ from permanent generation to Metaspace


JAVA8 has removed the memory area of the permanent generation (Permanent Generation) , and a new memory region meta-space (Metaspace) has occurred.


Permanent Generation what does this memory mainly hold?

So the Java classes is stored in the permanent generation. What is does that entail? Besides the basic fields of a Java class there is

    • Methods of a class (including the Bytecodes)

    • Names of the classes (in the form of an object, points to a, string also in the permanent generation)

    • Constant Pool information (data read from the class file, see Chapter 4 of the JVM specification for all the Deta ILS).

    • object arrays and type arrays associated with a class (e.g., an object array containing references to methods).

    • Internal objects created by the JVM (Java/lang/object or java/lang/exception for instance)

    • Information used for optimization by the compilers (jits)


Common Oom Exceptions: Outofmemoryerror:permgen space

This is often caused by a class loader-related memory leak and the creation of a new class loader, usually in the case of a code hot deployment. This is why the problem occurs more frequently on the development machine than the formal product. When it appears in the product, the developer can get the generated heap dump file and use a tool like Eclipse Memory Analyzer Toolkit to find the ClassLoader that should be unloaded without being unloaded. PermGen is also garbage collected unless it is blocked by a specific configuration. However, there is nothing to recycle when there is a memory leak .


Related JVM parameters: (JDK7)

-xx:maxpermsize=64m   Size of the Permanent Generation. [5.0 and newer:64 bit VMs are scaled 30% larger; 1.4 amd64:96m; 1.3.1-client:32m.]

In Jdk8, the relevant parameters have not been used:

-xx:maxpermsize=size

Sets the maximum permanent generation space size (in bytes). This option is deprecated in JDK 8, and superseded by the-xx:maxmetaspacesize option.

-xx:permsize=size

Sets the space (in bytes) allocated to the permanent generation, triggers a garbage collection if it is exceeded. This option is deprecated UN JDK 8, and superseded by the-xx:metaspacesize option.


Metaspace

There is no more permgen in Java 8. Some of these parts, such as the intern string, have been moved to the normal heap in Java 7. The remaining structures are moved to the native memory area called "Metaspace" in Java 8, which is automatically grown by default and is garbage collected. It has two tags: metaspacesize and maxmetaspacesize.


related JVM parameters: -xx:metaspacesize=size

sets the size of the allocated class metadata space that would trigger a garbage collection the first time it is exceed Ed. This threshold for a garbage collection was increased or decreased depending on the amount of metadata used. The default size depends on the platform.

-xx:maxmetaspacesize=size

sets the maximum amount of native memory that can is allocated for class metadata. By default, the size was not limited. The amount of metadata for a application depends on the application itself, other running applications, and the Amou NT of memory available on the system.

The following example shows how to set the maximum class metadata size to:-xx:maxmetaspacesize=256m


PermGen Space situation

This memory space is completely removed.

The PermSize and MaxPermSize JVM arguments are ignored and a warning be issued if present at start-up.


Metaspace Memory allocation model

Most allocations for the class metadata is now allocated out of native memory.

The klasses, were used to describe class metadata has been removed.


Metaspace capacity

By default class metadata allocation was limited by the amount of available native memory (capacity would of course depend I f you use a 32-bit JVM vs. 64-bit along with OS virtual memory availability).

A new flag is available (maxmetaspacesize), allowing your to limit the amount of native memory used for class metadata. If you don't specify this flag, the Metaspace would dynamically re-size depending of the application demand at Runt IME.


Metaspace Garbage Collection

Garbage collection of the dead classes and classloaders is triggered (triggered) Once the class metadata usage reaches the "Maxme Taspacesize ".

Proper Monitoring & tuning of the metaspace would obviously be required on order to limit the frequency or delay of suc H Garbage Collections. Excessive metaspace garbage collections is a symptom of classes, classloaders memory leak or inadequate sizing for you R application.


Java Heap Space Impact

Some miscellaneous data have been moved to the Java heap space. This means is observe a increase of the Java heap space following a future JDK 8 upgrade.


Metaspace Monitoring

Metaspace usage is available from the HotSpot 1.8 verbose GC log output.

Jstat & JVISUALVM has not been updated at this point based on our testing with b75 and the old PermGen space Referenc ES is still present.

====end====


Java8_ from permanent generation to Metaspace

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.