Java Virtual machine Type uninstall and type update resolution

Source: Internet
Author: User
Tags memory usage

First look at how the type uninstall (unloading) is described in the Java Virtual Machine specification:

A class or interface may are unloaded if and only if it class loader is unreachable. The Bootstrap class loader is always reachable; As a Result,system classes may never is unloaded.

The contents of the Java Virtual Machine specification for type unloading are as simple as two sentences, the general meaning is: only if the class loader instance of that type (the class loader type) is loaded as unreachable state, The type that is currently loaded is unloaded. The Start class loader instance is always reachable state, and the type loaded by the boot class loader may never be unloaded.

Let's take a look at more detailed information about type uninstall provided by the Java language Specification (partial excerpt):

Excerpt from JLS 12.7 unloading of Classes and interfaces

1. A implementation of the Java programming language may unload classes.

2, Class unloading is a optimization that helps to reduce memory use. Obviously,the semantics of the A program should not depend on whether and how a system chooses to implement a optimization su CH as class unloading.

3, Consequently,whether a class or interface has been unloaded or not should is transparent to a program

From the above we can conclude that type unloading (unloading) is only as a performance optimization measure to reduce memory usage, specifically related to virtual machine implementation, and transparent to developers.

Looking at the Java language Specification and its associated API specification, the interface for display type uninstall (unloading) is not found, in other words:

1, a loaded type has been unloaded for a very small probability of at least the time to be unloaded is uncertain

2. A type loaded by a particular class loader instance can be considered to be unable to be updated when it is run

"Type Uninstall further analysis"

As mentioned earlier, if you want to uninstall a type, you must ensure that the class loader loading that type is in the unreachable state, now let's look at the explanation of the unreachable state:

1, A reachable object is any object, can be accessed to any potential continuing computation to any live thread.

2. Finalizer-reachable:a Finalizer-reachable object can be reached from some finalizable object through some chain of Refe Rences, but not-any live thread. An unreachable object cannot is reached by either means.

To some extent, in a slightly more complex Java application, it is difficult to determine accurately whether an instance is in the unreachable state, so in order to more accurately approximate this so-called unreachable state, our following test code is as simple as possible.

Related Article

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.