常量池在方法区中,和堆不是相同的概念。不要把常量池和堆混起来。
按照Inside the java virtual machine这本书上的说法,static的数据放在方法区中。
按照Inside the java virtual machine这本书上的说法,static的数据放在方法区中。
解决方案 »
- 在做SSH 操作 oracle Clob 字段 时 发生 的问题 急急~~~
- petstore如何安装
- 关于j2ee web中进程的问题,主要是实现内容里的一个功能
- Java+数据库开发项目对视图层和数据库相关操作出现乱码汇总资料?
- 谁有Display Tag的源代码,给100分谢谢
- 存在threadLocal里面的httpSession,过了一分钟之后怎么就没有啦
- 阅读development without ejb 的问题?
- 一个关于限制页面大小的问题(struts系统中).谢谢!!!在线等
- J2EE 1.4标准教材(第二版)(The J2EE Tutorial Second Edition)这本书怎么样??
- 有什么好的工具可以讲html帮助制作成chm文件吗?
- Struts2传参问题
- SSH整合问题????
这中情况i是当作一个立即数压入栈里的。
对于在short类型表示之外的int数,放在常量池中,需要的时候放到栈里。
举个例子:public class Test{
public static void main(String []args){
int i=1;
int j=18;
int k=128;
int kk=32768;
int kk2=32768;
}
}察看其class文件Compiled from "Test.java"
public class Test extends java.lang.Object
SourceFile: "Test.java"
minor version: 0
major version: 49
Constant pool: //下面是常量池里的内容
const #1 = Method #4.#13; // java/lang/Object."<init>":()V
const #2 = int 32768; //这个数在常量池中
const #3 = class #14; // Test
const #4 = class #15; // java/lang/Object
const #5 = Asciz <init>;
const #6 = Asciz ()V;
const #7 = Asciz Code;
const #8 = Asciz LineNumberTable;
const #9 = Asciz main;
const #10 = Asciz ([Ljava/lang/String;)V;
const #11 = Asciz SourceFile;
const #12 = Asciz Test.java;
const #13 = NameAndType #5:#6;// "<init>":()V
const #14 = Asciz Test;
const #15 = Asciz java/lang/Object;{
public Test();
Code:
Stack=1, Locals=1, Args_size=1
0: aload_0
1: invokespecial #1; //Method java/lang/Object."<init>":()V
4: return
LineNumberTable:
line 1: 0public static void main(java.lang.String[]);
Code:
Stack=1, Locals=6, Args_size=1
0: iconst_1 //常数1的处理
1: istore_1
2: bipush 18 //b开头可以理解为byte操作
4: istore_2
5: sipush 128 //s开头可以理解为short操作
8: istore_3
9: ldc #2; //int 32768 后面这两个都是从常量池中取数,都是从#2取
11: istore 4
13: ldc #2; //int 32768
15: istore 5
17: return
LineNumberTable:
line 3: 0
line 4: 2
line 5: 5
line 6: 9
line 7: 13
line 8: 17}
Constant Type Value
CONSTANT_Class 7
CONSTANT_Fieldref 9
CONSTANT_Methodref 10
CONSTANT_InterfaceMethodref 11
CONSTANT_String 8
CONSTANT_Integer 3
CONSTANT_Float 4
CONSTANT_Long 5
CONSTANT_Double 6
CONSTANT_NameAndType 12
CONSTANT_Utf8 1
其中Integer,Float,Double,Long存放的就是基本类型的常数字面量。基本类型的变量是在栈里。
Runtime Data Areas
1 The pc Register
2 Java Virtual Machine Stacks
3 Heap
4 Method Area
5 Runtime Constant Pool
6 Native Method Stacks