DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workkloads.

Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Unleash Peak Performance in Java Applications: Overview of Profile-Guided Optimization (PGO)
  • Legacy Code Refactoring: Tips, Steps, and Best Practices
  • Beginner's Guide to Compilation in Java
  • Dynamically Evaluate Dataweave Scripts

Trending

  • Fixing Common Oracle Database Problems
  • Unlocking AI Coding Assistants Part 1: Real-World Use Cases
  • Internal Developer Portals: Modern DevOps's Missing Piece
  • It’s Not About Control — It’s About Collaboration Between Architecture and Security
  1. DZone
  2. Coding
  3. Java
  4. Client, Server, and Tiered Compilation

Client, Server, and Tiered Compilation

Particularly useful for pre-Java 8 users, let's explore how to get the best of both Client and Server compiling by using them together.

By 
Grzegorz Mirek user avatar
Grzegorz Mirek
·
Updated Aug. 03, 17 · Tutorial
Likes (8)
Comment
Save
Tweet
Share
20.7K Views

Join the DZone community and get the full member experience.

Join For Free

There are two basic types of Just-In-Time Java compilers: Client and Server. Traditionally, the Client and the Server compilers are called C1 and C2 respectively.

The main difference between the Client and the Server compilers is the aggressiveness in the way they compile code. The Client compiler is optimized to make an application start up faster, whereas the Server compiler gives better performance in the long run. As you might have guessed, the Client compiler is dedicated to any type of client application (usually GUI-based), whereas the Server compiler is designed for long-running server side applications.

Why is the Server compiler faster eventually? It’s because the Server compiler observes and analyzes the code for a longer period of time, and that knowledge allows the Server compiler to make better optimizations in the compiled code. On the contrary, the Client compiler tries to optimize and compile code as soon as possible, which lowers the start-up time.

The obvious question you might ask is whether it’s possible to make a mix of both the Client and Server compilers to have both fast startup and as good performance as possible in the long run? The answer is yes. We've had it since Java 7, and it’s called Tiered compilation.

Tiered Compilation

With Tiered compilation, the Client compiler is used at the beginning to make startup fast, then, when the code becomes hot and profile data is collected, it is recompiled by the Server compiler.

Even though there are only two basic compilers (+ interpreter) in Java, there are five levels of execution, because the Client compiler (C1) has three different levels of compilation and the Server compiler (C2) has only one.

  • Level 0 – interpreted code

  • Level 1 – simple C1 compiled code (with no profiling)

  • Level 2 – limited C1 compiled code (with light profiling)

  • Level 3 – full C1 compiled code (with full profiling)

  • Level 4 – C2 compiled code (uses profile data from the previous steps)

The usual path is 0 -> 3 -> 4, so the code is interpreted first, then, when it gets hot enough, it’s compiled by C1 with full profiling enabled and, finally, C2 compiles the code using profile data collected by C1.

But there are three exceptions.

The Method Is Simple

If the method to be compiled is trivial, then it is compiled only at level 1 (C1 without profiling) because the Server compiler wouldn’t make it faster – there is no point in doing extensive profiling to find out how the code is used if it can be made fast without it.

C2 Is Busy

If at some point the Server compiler queue gets full, the method will be taken from the Server queue and compiled at level 2 (with light profiling, which compiles the method sooner). After some time, the code will be compiled at level 3 (with full profiling) and finally, when the Server queue is less busy, it will be compiled by the Server compiler (again, using profile data collected at level 3).

C1 Is Busy, but C2 Is Not

If the C1 queue is full, but the C2 queue is not, then the method can be profiled by the interpreter (level 0) and then it can go directly to C2 (so the Client compiler is not involved at all).

It is worth mentioning that compiler queues are not standard FIFO, but priority ones. In Java 8, Tiered compilation is enabled by default.

Java (programming language) optimization Compiled language

Published at DZone with permission of Grzegorz Mirek, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Unleash Peak Performance in Java Applications: Overview of Profile-Guided Optimization (PGO)
  • Legacy Code Refactoring: Tips, Steps, and Best Practices
  • Beginner's Guide to Compilation in Java
  • Dynamically Evaluate Dataweave Scripts

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!