Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 1 of 1

Thread: Types of VirtualMachineError

  1. #1
    Junior Member
    Join Date
    Nov 2017
    Thanked 1 Time in 1 Post

    Default Types of VirtualMachineError

    Java.lang.VirtualMachineError is thrown when Java virtual machine encounters any internal error or resource limitation which prevents it from functioning. It’s a self-defensive mechanism employed by JVM to prevent entire application from crashing. In this article lets discuss different types of VirtualMachineError, their characteristics, reasons why they get triggered and potentials 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

    Fig: Java Throwable class hierarchy

    # a. OutOfMemoryError
    Just like OMG (Oh My God) acronym, OOM (OutOfMemoryError) is quite popular among DevOps community :-). Most DevOps engineers think that there is one OutOfMemoryError. But there are 8 different flavors 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 flavor of OutOfMemoryError. Here is a beautiful one-page document that summarizes all different flavors of OutOfMemoryError, their causes and solutions.

    In general, 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, IBM GC analyzer. Similarly to analyze heap dumps, you may consider using free tools like: HeapHero, Eclipse MAT.

    # b. StackOverflowError
    Thread’s 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’s stack sizes grow beyond the allocated memory limit, then java.lang.StackOverflowError is thrown. This problem typically happens when a thread recursively invokes 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.

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

    a. Fault in the software implementing the virtual machine,

    b. Fault in the underlying host system software

    c. Fault in the hardware.

    But rarely you will encounter InternalError. To understand what specific scenarios may cause 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.

    # d. 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 UnknownError. In fact, when searching for ‘UnknownError’ in Oracle Java Bug database at the time of writing this article (Dec’ 20, 2018), there are only 2 defects found reported.

    VirtualMachineError has couple of primary characteristics:

    1. Unchecked Exception
    2. Synchronous & asynchronous delivery

    Let’s discuss these two characteristics in this section.

    (1). Unchecked Exception
    There are two types of Exceptions:

    1.Checked exceptions
    2.Unchecked exceptions
    Exceptions which are checked at compile time called Checked Exception. If some methods in your code throws a checked exception, then the method must either handle the exception or it must specify the exception using throws keyword. Examples of the checked exceptions are: IOException, SQLException, DataAccessException, ClassNotFoundException …

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

    (2). Synchronous & asynchronous Delivery

    Exceptions can be thrown in two modes:

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

    Asynchronous exceptions can happen at any point in time and it can happen in any part of program statement. There will be no consistency where it can be thrown. All the VirtualMachineError 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.
    Last edited by Ram Lakshmanan; January 4th, 2019 at 05:52 AM.

Similar Threads

  1. Incompatible types
    By jadeclan in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 26th, 2012, 07:09 AM
  2. Incompatible types
    By jadeclan in forum What's Wrong With My Code?
    Replies: 5
    Last Post: November 25th, 2012, 04:44 PM
  3. Value vs Reference Types
    By anis.laghaei in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 23rd, 2012, 01:21 PM
  4. Primitive types
    By sudesh in forum What's Wrong With My Code?
    Replies: 4
    Last Post: January 30th, 2012, 01:44 AM
  5. incompatible types!!
    By sneha343 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: November 30th, 2011, 05:48 PM