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
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Optimizing Java Applications for Arm64 in the Cloud
  • Understanding Root Causes of Out of Memory (OOM) Issues in Java Containers
  • Charge Vertical Scaling With the Latest Java GCs
  • Java Thread Dump Analysis

Trending

  • Building a Feature Store With Neo4j and Feast
  • Microsoft Foundry Agent Debugging Dashboard with Microsoft Fabric Eventhouse, KQL, Docker and Grafana
  • Chaos Engineering and Kafka In Action: Topic Level Idempotence and Retry Check
  • Gitember: Building a Git Client Beyond Commit, Push, and Pull

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Coding
  3. Java
  4. A Closer Look at the Java VirtualMachineError

A Closer Look at the Java VirtualMachineError

Want to learn more about the different types of characteristics of the Java VirtualMachineError?

By 
Ram Lakshmanan
DZone Core CORE ·
Jan. 29, 19 · Presentation
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
18.0K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

Java.lang.VirtualMachineError is thrown when the Java virtual machine encounters an internal error or resource limitation, which prevents it from functioning. It’s a self-defensive mechanism employed by JVM to prevent the entire application from crashing. In this article, let's discuss different types of VirtualMachineError, their characteristics, reasons why they get triggered, and potential solutions to fix them.

Types of VirtualMachineError

There are four different types of VirtualMachineError:

a. OutOfMemoryError

b. StackOverflowError

c. InternalError

d. UnknownError

Let’s review these types in detail in this section:

Virtual error Diagram (2)

Fig: Java Throwable class hierarchy

OutOfMemoryError

Just like the OMG (Oh My God) acronym, OOM ( OutOfMemoryError) is quite popular among the DevOps community. Most DevOps engineers think that there is one OutOfMemoryError. But there are eight different kinds of OutOfMemoryError:

  1. java.lang.OutOfMemoryError: Java heap space
  2. java.lang.OutOfMemoryError: GC Overhead limit exceeded
  3. java.lang.OutOfMemoryError: Requested array size exceeds VM limit
  4. java.lang.OutOfMemoryError: Permgen space
  5. java.lang.OutOfMemoryError: Metaspace
  6. java.lang.OutOfMemoryError: Unable to create new native thread
  7. java.lang.OutOfMemoryError: Kill process or sacrifice child
  8. java.lang.OutOfMemoryError: reason stack_trace_with_native_method

Each flavor is triggered for different reasons. Similarly, solutions are also different for each type of OutOfMemoryError. Here is a beautiful, one-page document that summarizes all the different types of OutOfMemoryError, their causes, and solutions.

In general, the OutOfMemoryError can be diagnosed and fixed by analyzing Garbage Collection logs and Heap Dumps. Since analyzing Garbage Collection logs manually can be tedious, you may consider using free tools like GCeasy, HP Jmeter, and IBM GC analyzer. Similarly to analyze heap dumps, you may consider using free tools like HeapHero, Eclipse MAT.

StackOverflowError

Thread stack is storing information about the methods it’s executing, primitive datatype values, local variables, object pointers, and return values. All of them consume memory. If thread stack sizes grow beyond the allocated memory limit, then the java.lang.StackOverflowError is thrown. This problem typically happens when a thread recursively invokes the same function again and again as a result of a bug in the executing program. More details on how to debug StackOverflowError and all possible solutions to fix it can be found in this article.

InternalError

java.lang.InternalError is thrown by the JVM when there is a:

  1. Fault in the software implementing the virtual machine
  2. Fault in the underlying host system software
  3. Fault in the hardware.

But rarely you will encounter the InternalError. To understand what specific scenarios may cause the InternalError, you may search for ‘InternalError’ string in Oracle’s Java Bug database. At the time of writing this article (Dec’ 20, 2018), there are only 200 defects reported for this error in Oracle Java bug database. Most of them are fixed.

UnknownError

java.lang.UnknownError is thrown when an exception or error has occurred, but the Java virtual machine is unable to report the actual exception or error. Seldom you will see the UnknownError. In fact, when searching for ‘UnknownError’ in the Oracle Java Bug database, at the time of writing this article (Dec’ 20, 2018), there are only two defects found and reported.

Characteristics

 VirtualMachineError has a couple of primary characteristics:

  1. Unchecked Exception
  2. Synchronous and asynchronous delivery

Let’s discuss these two characteristics in this section.

Unchecked Exception

There are two types of Exceptions:

  • Checked exceptions
  • Unchecked exceptions

Exceptions that are checked at compile time are called Checked Exceptions. If some methods in your code throw a checked exception, then the method must either handle the exception or it must specify the exception using throws keyword. Examples of checked exceptions are IOException, SQLException , DataAccessException, ClassNotFoundException , etc.

Unchecked exceptions do not have this requirement. They don’t have to be caught or declared thrown. All types of VirtualMachineError are unchecked exceptions.

Synchronous and Asynchronous Delivery

Exceptions can be thrown in two modes:

  • Synchronous
  • Asynchronous

Synchronous exceptions happen at a specific program statement, no matter how many numbers of times the program is executed in a similar environment. Examples of synchronous exceptions are  NullPointerException, ArrayIndexOutOfBoundException, etc.

Asynchronous exceptions can happen at any point in time and it can happen in any part of the program statement. There will be no consistency where it can be thrown. All  VirtualMachineErrors are thrown asynchronously, but sometimes, they can also be thrown synchronously. StackOverflowError may be thrown synchronously by method invocation as well as asynchronously due to native method execution or Java Virtual Machine resource limitations. Similarly, OutOfMemoryError may be thrown synchronously during object creation, array creation, class initialization, and boxing conversion, as well as asynchronously.

Java (programming language) Java virtual machine Virtual Machine garbage collection

Opinions expressed by DZone contributors are their own.

Related

  • Optimizing Java Applications for Arm64 in the Cloud
  • Understanding Root Causes of Out of Memory (OOM) Issues in Java Containers
  • Charge Vertical Scaling With the Latest Java GCs
  • Java Thread Dump Analysis

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

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 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook