Questions about JVM

Source: Internet
Author: User

Looking at the beauty of programming, I saw a well-versed definition of the operating system. For example, I wrote a program to draw a sine curve from the CPU curve of the task manager, this practical hands-on capability deserves our attention.

I was just reading a book. I suddenly thought of the following questions about virtual machine rules:

  1. Provides a piece of code that will cause heap memory overflow;
  2. A piece of code is provided for the VM stack and local method stack overflow: stackoverflowerror and outofmemoryerror are given for the program;
  3. Provides a piece of code that can cause frequent pool overflow;
  4. Provide a piece of code that can overflow the method area.

These questions not only examine the understanding of Java memory allocation, but also handle memory problems from actual operations. Understanding this type of question is conducive to exception correction and system tuning.

Gorgeous split line ----------------------------------------------------------------------

The following provides some ideas. In fact, we will give the second question.

  1. Heap Overflow: new objects are stored in the heap, so this part is simple and new objects can be added constantly. However, to prevent GC after the new object is generated, so put the new object in a list. For better results, you can adjust the heap parameters before running.
  2. For stack overflow in the hotspot virtual machine, if the requested stack depth is greater than the maximum depth allowed by the virtual machine, stackoverflowerror is thrown. If the virtual machine cannot apply for sufficient space during expansion, an outofmemoryerror exception is thrown. It is easy to think that in the single-thread heap, we constantly increase the number of member variables, and the units that hold this variable cannot afford this variable, so we will throw stackoverflowerror. This is

    The requested stack depth is greater than the maximum depth allowed by the virtual machine. In other cases, you can open as many threads as possible and call the native method in each thread.
    Outofmemoryerror.
  3. Run-Time pool overflow: the run-time pool is a part of the method area. It stores the symbolic reference described in the class file. The intern method of the string class can be used.
  4. The method area stores class information, constants, and static variables. The overflow of this part can be enhanced by class loading.

 

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.