Oom Exception Java Memory overflow

Source: Internet
Author: User
Tags xms

1.OutOfMemoryError
    • Determine if a heap overflow or stack overflow after throwing an exception
    • Memory leak: Memory Leak failed to release the requested RAM after applying to memory, which is why an object has been referenced this way.
    • Memory overflow: The memory OverFlow: There is not enough room to use when applying for RAM, throw oom.
    • You can use Eclipse Memory Analyzer or Jprofiler (IDEA) to analyze whether or not a leak
  1. Heap overflow: Java.lang.OutOfMemoryError:Java heap Space
    1. -XMS set the initial heap size, set to 20mb-xms20m
    2. -xmx Setting the maximum heap size
  2. Virtual machine stack Overflow and local method stack Overflow
    1. The HotSpot virtual machine does not differentiate between the virtual machine stack and the local method stack he fits together. So the-xoos used to set the local method stack size has no effect.
    2. -XSS Set Stack capacity size
    3. Stack can throw 2 kinds of exceptions
      • The stack depth requested by the Stackoverflowerror thread is greater than the maximum allowable depth for the virtual machine.
      • Unable to request sufficient memory when outofmemoryerror the expansion stack
    4. The memory assigned to each process by the operating system is limited, such as 32-bit win to process allocated 2G, stack memory = 2GB-Heap Xmx-method area MaxPermSize
    5. The more threads allocate less stack memory, the more stack capacity each thread allocates, the fewer threads, and the easier it is to drain the remaining memory.
    6. JVM By default the stack depth average of 1000-2000 (stack frame number is the number of methods), if you can not replace the higher number of operating system can not reduce the number of threads, you can reduce the maximum capacity of the heap to yield a portion of memory to the stack, avoid stack memory overflow.
  3. Method area and run-time-constant pool overflow
    1. Outofmemoryerror:permgen space run constant pool in the method area he throws this exception in both.
    2. -xx:permsize method Area Initial value size
    3. -xx:maxpermsize Method Area Maximum Value
    4. Since the 1.8 goes to the permanent band and joins the Metaspace meta space, the above configuration 1.8 cannot be invalidated at first.
    5. -xx:metaspacesize the size of the meta space,-xx:maxmetaspace the maximum value of the meta space.
  4. Native Direct Memory Overflow
    1. -xx:maxdirectmemorysize can specify the maximum value if the default is not specified and the heap is as large.
    2. Because direct memory is not in the heap, it is for NIO use, so after throwing an oom exception through the JVM Memory detection tool There is no obvious error in heap dump, but the dump file is small to consider a direct memory overflow
Knowledge Points:
  1. String.intern () is a local method that returns only that string that is unique in a constant pool of strings.
            New // initial string constant pool does not exist  mibloom        New StringBuilder ("Ja"). Append ("va"). toString (); // initial string constant pool exists in  Java        System.out.println (st1.intern () = = St1); // 1.6 is false,1.7 to true        System.out.println (st2.intern () = = St2); // is always true
      1. If the string constant pool already contains a symbol equal to this string object, the object in the string constant pool is returned.
      2. If the string constant pool does not have a string in the constant pool and returns the object in the string constant pool, this join operation differs in jdk1.6 and 1.7.
      3. In 1.6, the first occurrence of string in the string constant pool is copied directly into the permanent generation in the string constant pool, so the address changes.
      4. 1.7 The first occurrence of string join string constant pool is the copy string reference into the constant pool, so the address does not change. 1.7 Starts the string constant pool is moved to the heap.
  2. JVM Additional configuration parameters
    //Common configuration rollups//Heap Settings-Xms: initial heap Size-Xmx: Maximum heap size-xx:newsize=N: Set the young generation size-xx:newratio=n: Sets the ratio of the young generation to the old generation. For example: 3, the ratio of the younger generation to the old generation is 1:3, the younger generation accounts for the entire young generation of the old generation and the-xx:survivorratio=n: The ratio of Eden in the young generation to two Survivor districts. Note The Survivor area has two. For example: 3, which represents Eden:survivor=3:2, a Survivor area of the entire young generation 1/5-xx:maxpermsize=N: Set the persistent generation size//Collector Settings-xx:+USESERIALGC: Setting up the serial collector-xx:+USEPARALLELGC: Setting up a parallel collector-xx:+USEPARALLEDLOLDGC: Setting up a parallel old generation collector-xx:+USECONCMARKSWEEPGC: Setting the concurrency collector//Garbage Collection Statistics-xx:+PRINTGC-xx:+printgcdetails-xx:+Printgctimestamps-Xloggc:filename//Parallel Collector Settings-xx:parallelgcthreads=n: Sets the number of CPUs used when the parallel collector is collected. Parallel collection//The number of threads.-xx:maxgcpausemillis=N: Set maximum pause time for parallel collection-xx:gctimeratio=n: Sets the percentage of time that garbage collection takes to run the program. The formula is 1/(1 +N)//Concurrent Collector Settings-xx:+Cmsincrementalmode: Set to incremental mode. Applies to single CPU conditions.-xx:parallelgcthreads=N: Set the concurrency collector the number of CPUs used by the young generation collection method for parallel collection. The number of parallel collection threads.

Oom Exception Java Memory overflow

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.