The JVM OOM common types

Java in the OOM

  • java.lang.StackOverflowError
  • java.lang.OutMemoryError:Java heap space
  • java.lang.OutMemoryError: GC overhead limit exceeded: Gc outofmemoryerror recovery will occur too long, long defined, if more than 98% of the time to do the GC, and recovered less than 2% of the heap, repeatedly recovery of less than 2% of cases will run out of charge of a vicious cycle, gc clean up the memory is filled up again, forcing the gc to perform again.
        /*
        -Xmx10m -Xms10m -XX:+PrintGCDetails -XX:MaxDirectMemorySize=5m
         */
        public static void main(String[] args){
    
            int i = 0;
            List<String> list = new ArrayList<>();
    
            try{
                while (true){
                    list.add(String.valueOf(new Random().nextInt(1111111)).intern());
                }
            }catch (Throwable e){
                e.printStackTrace();
            }
        }
  • java.lang.OutMemoryError: Direct buffer memory: write NIO ByteBuffer uses to read or write data, which is based on the channel (channel) and buffer (buffer) in the manner IO, Native libraries can be used directly allocated heap memory, then through a stack of DirectByteBuffer stored in Java objects of this memory as a reference to operate, so that the performance can be improved in some scenarios, avoiding the native Java heap and stack replicate data.
    • ByteBuffer.allocate (capability) allocating a first embodiment JVM memory, fall within the jurisdiction of GC, it needs to be copied relatively slow
    • ByteBuffer.allocateDirect (capability) OS local memory allocated second embodiment, not within the jurisdiction of GC, since no memory copy, and therefore faster
          /*
          -Xmx10m -Xms10m -XX:+PrintGCDetails -XX:MaxDirectMemorySize=5m
           */
          static void directMemory(){
      
              System.out.println("配置的MaxDirectMemory:" + sun.misc.VM.maxDirectMemory()/ (double)1024 / 1024 + "MB");
      
              ByteBuffer.allocateDirect(6 * 1024 * 1024);
          }
  • java.lang.OutMemoryError: unable to create new native thread: in times of high concurrent requests to the server, an application process creates too many threads, exceed the carrying capacity of the system. Your server does not allow applications to create so many threads, Linux default one process can create up to 1024 threads (solution: reduction of threads to create or modify the default server configuration, expand the default limit).
  • java.lang.OutMemoryError: Metaspace: java8metaspace substituted permanent generation using local memory for storage. Metaspace is a method implemented in the HotSpot, namely in java8, classe metadata is stored in native memory Metaspace of (permanent behalf / metaspace: virtual machine loaded typology, constant pool, static variables, the code-time compilation)

Guess you like

Origin www.cnblogs.com/shemlo/p/11665917.html