Java Shared classes

Source: Internet
Author: User

To really isolate Java applications from each other, you essentially need multiple JVMs, but startup costs and memory footprint make this a less desirable approach. Shared classes can solve both problems at the same time. In a multiple JVM environment, a shared class can share these classes in multiple JVMs by loading a set of core system classes into shared memory. These shared classes are placed in a shared area of memory, where they are consistent for all JVMs. As a result, shared classes need to be loaded into memory only on first use, eliminating the fixed cost of loading them each time the JVM calls, and reducing the memory footprint in each JVM.

IBM implements shared-class technology on the z/OS platform. Apple Computer Inc. implemented a shared class called Java shared Archive (JSA) on Mac OS X, while Sun introduced the JSA technology-based class Data sharing in J2SE version 1.5 ( CDS). Let's analyze how these implementations work.

IBM's implementation

Since J2se 1.3.1, IBM has provided shared-class technology implementations on the z/OS platform. This implementation is accomplished by having a master (or master) JVM load the core system classes into shared memory, so what exactly does that mean?

Decomposition heap

Memory is divided into shared heap and Java heap. The main JVM allocates the system heap (that is, the shared heap) to shared memory, where the system classes are placed. The system heap persists throughout the lifetime of the main JVM and is not affected by garbage collection (GC). Each subsequent (or worker) JVM is attached to the system heap, as shown in Figure 1, and allocates unshared memory for its own Java heap, which is affected by garbage collection. The Java heap contains unshared classes and all instantiated objects that are specific to the application running by each worker JVM.

Figure 1. Shared class decomposition Heap

Shared class Loader

Each worker JVM can load a class into a shared heap by placing it in the classpath of the shared class loader. Shared classes are loaded the same way as normal classes--using parent-delegation mode.

Each class loader in the hierarchy checks its cache to determine if the class is already loaded. If it is not yet mounted, then the class loader passes a check mount request to its parent class loader, which goes back to the primordial or bootstrap class loader at the top of the hierarchy. If this class is not found in any buffer, then each class loader will attempt to load the class from its own repository and, if successful, return the class. Otherwise, it passes the request to the loader below the hierarchy. This model ensures that the most trusted repositories are checked first, and that code that has low levels of trust replaces the trusted core API classes with the same name as the core API members.

If the class is a primordial class or a defined class loader is a shared class loader, then the class object is created in the shared heap, and the class is marked as a shared class. Figure 2 shows the bootstrap class loader at the top of the class loader hierarchy and is responsible for loading the classes in the core APIs. These classes are the highest level of trust. The extended class loader loads the classes in the standard extension JAR file in the extensions directory. The shared Application class loader can be used to share users or application classes.

Figure 2. Class loader Hierarchy

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.