Stack属于栈的区域,属于每条线程私有的。

方法区和本地方法栈有很大的不同,方法区是用Java级别角度做的代码,本地方法栈指向的是C/C++。

Java开发,对象就在堆中,一般而言,堆中只有对象。

堆溢出测试:程序运行设置:-verbose:gc -Xms10M -Xmx10M -Xss128k -XX:+PrintGCDetails
package com.dt.spark.jvm.basics;

import java.util.ArrayList;

import java.util.List;

class Person{ }

public class HelloHeapOutOfMemory {

         public static void main(String[] args) {

                   System.out.println("HelloHeapOutOfMemory");

                   List persons = new ArrayList();

                   int counter = ;

                while(true){

                         persons.add(new Person());

                         System.out.println("Instance: " + (++counter));

                }

         }

}
报错:Exception in thread "main" java.lang.OutOfMemoryError: Java heap space

栈溢出测试:

package com.dt.spark.jvm.basics;

public class  HelloStackOverFlow {

    private int counter;

    public void count() {

       counter++;

       count();

    }

    public static void main(String[] args) {

        System.out.println("HelloStackOverFlow");

        HelloStackOverFlow helloStackOverFlow= new HelloStackOverFlow();

        try {

            helloStackOverFlow.count();

        } catch(Exception e) {

            e.printStackTrace();

            throw e;

        }   

    }

}
报错:Exception in thread "main" java.lang.StackOverflowError

常量区溢出报错测试

package com.dt.spark.jvm.basics;

import java.util.ArrayList;

import java.util.List;

public class HelloConstantOutOfMemory {

         public static void main(String[] args) {

                    try {

                    List stringList = new ArrayList();

                    int item = ;

                    while(true){

                       stringList.add(String.valueOf(item++).intern());

                    }

                } catch (Exception e) {

                    e.printStackTrace();

                    throw e;

                }

         }

}
报错:Exception in thread "main" [Full GC (Ergonomics) java.lang.OutOfMemoryError: GC overhead limit exceeded

DirectMemory溢出报错测试:

package com.dt.spark.jvm.basics;

import java.nio.ByteBuffer;

public class HelloDirectMemoryOutOfmemory {

    private static final int ONE_GB = **;

     private static int count= ;

    public static void main(String[] args) {

          try {          

               while (true) {

                  ByteBuffer buffer = ByteBuffer.allocateDirect(ONE_GB);

                  count++;
} } catch (Exception e) { System.out.println("Exception:instance created "+count); e.printStackTrace(); } catch (Error e) { System.out.println("Error:instance created "+count); e.printStackTrace(); }
} }
报错:java.lang.OutOfMemoryError: Direct buffer memory

JVM内存四大类型:Heap,Stack,Contant,DirectMemory等的更多相关文章

  1. 转:JVM 内存初学 (堆(heap)、栈(stack)和方法区(method) )

    原文地址:JVM 内存初学 (堆(heap).栈(stack)和方法区(method) ) 博主推荐 深入浅出JVM 这本书 先了解具体的概念:JAVA的JVM的内存可分为3个区:堆(heap).栈( ...

  2. [转]JVM 内存初学 (堆(heap)、栈(stack)和方法区(method) )

    这两天看了一下深入浅出JVM这本书,推荐给高级的java程序员去看,对你了解JAVA的底层和运行机制有比较大的帮助.废话不想讲了.入主题: 先了解具体的概念:JAVA的JVM的内存可分为3个区:堆(h ...

  3. JVM 内存初学 堆(heap)、栈(stack)和方法区(method)

    这两天看了一下深入浅出JVM这本书,推荐给高级的java程序员去看,对你了解JAVA的底层和运行机制有比较大的帮助.废话不想讲了.入主题:先了解具体的概念:JAVA的JVM的内存可分为3个区:堆(he ...

  4. JVM 内存初学 (堆(heap)、栈(stack)和方法区(method) )(转载)

    想想面试的时候很多会问jvm这方面的问题虽然还是菜鸟不太能用到现在但是还是了解一下, 找资料的时候看见个大佬写的很好转载到这方便以后自己复习和给大佬做宣传 以下为大佬的博客原文: 这两天看了一下深入浅 ...

  5. JVM内存—堆(heap)栈(stack)方法区(method) (转)

    JAVA的JVM的内存可分为3个区:堆(heap).栈(stack)和方法区(method) 堆区:1.存储的全部是对象,每个对象都包含一个与之对应的class的信息.(class的目的是得到操作指令 ...

  6. JVM内存模型——堆(heap)、栈(stack)和方法区(method)

      JAVA的JVM的内存可分为3个区:堆(heap).栈(stack)和方法区(method) 堆区:堆内存用于存放由new创建的对象和数组.堆是JVM管理的内存中最大的一块,堆被所有线程共享,目的 ...

  7. JVM 内存 (堆(heap)、栈(stack)和方法区(method) )

    JVM 内存初学 (堆(heap).栈(stack)和方法区(method) ) 堆区: 1.存储的全部是对象,每个对象都包含一个与之对应的class的信息.(class的目的是得到操作指令)2.jv ...

  8. JVM内存区域参数配置

    转自:https://www.jianshu.com/p/5946c0a414b5 需要提前了解的知识点: JVM内存模型 JVM垃圾回收算法 下图是JVM内存区域划分的逻辑图   JVM内存区域逻辑 ...

  9. JVM 内存区域大小参数设置

    JVM内存包括区域 Heap(堆区) New Generation(新生代) Eden 伊甸园 Survivor From Survivor To Old Generation(老年代) 方法区 Pe ...

随机推荐

  1. mysql 分区 限制

    MySQL分区的限制 •   只能对数据表的整型列进行分区源码天空,或者数据列可以通过分区函数转化成整型列 •   最大分区数目不能超过1024 •   如果含有唯一索引或者主键,则分区列必须包含在所 ...

  2. Httpclient远程调用WebService示例(Eclipse+httpclient)

    package cn.com.taiji.pos.httpserver; import java.io.BufferedInputStream;import java.io.ByteArrayOutp ...

  3. Desugar Scala(15) -- unapply和unapplySeq方法

    欢迎关注我的新博客地址:http://cuipengfei.me/ 实在想不到什么动词可以当做脱衣服来讲了,所以从现在开始这系列博文就叫做Desugar Scala了.除非哪天才思泉涌,又想到了新词: ...

  4. 构造方法也可以实现overloading

    构造方法也可以实现overloading.例: public void teach(){}; public void teach(int a){}; public void teach(String ...

  5. 面向对象方法的重载(overloading)和覆盖(overriding)

    面向对象方法的重载(overloading)和覆盖(overriding). 在有些JAVA书籍中将overriding称为重载,overloading称为过载. Overloading在一个类中可以 ...

  6. Linux下面变量的疑问处

    SHLVL是Shell累加器的变量,具体请看下面 http://www.cnblogs.com/ziyunfei/p/4803832.html OLDPWD = old pwd(就是是之前一次的pwd ...

  7. ActiveMQ搭建

    下载 到ActiveMQ官网,找到下载点. 目前, 官网为http://activemq.apache.org/ Linux版本下载点之一为:http://apache.fayea.com/activ ...

  8. hdu 1513(dp+滚动数组)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1513 思路:n这么大,可以采用滚动数组,然后就是求原串和反串的LCS了. #include<io ...

  9. ArcGIS 同一要素图层合并

  10. Android自定义控件之圆形进度条ImageView

    From:http://blog.csdn.net/xiadik/article/details/41648181package com.wangran.beautiful_girl_show.vie ...