This article belongs to the Java Basic Interview series: the type of int in 32-bit and 64-bit what is different I read the topic after I think is not very understanding, should be unrelated to the operating system, online search is not a good article specifically described, more confused, consultation under the title: is plainly street ask, Or try to understand their own ideas to write. Main feedback "Some compilers are compiled into bytecode to give this type of 8 bytes allocated, the object header size is really related to the number of digits, this is the size of the object, is independent of the reference to the base type declaration. Now that you have something to do with the compiler, you can refer to the notes that were previously sorted, Http://bohu83.blog.163.com/blog/static/35417565201623113356903/?newFollowBlog Java Basics Learning-java The memory footprint of common objects
Write a demo verify: public static void Main (string[] args) {//TODO auto-generated method stub int a =1; byte[] b = new byte[2]; Har c = ' a '; System.out.println ("object:" + sizeofobject.sizeof (New object ()); SYSTEM.OUT.PRINTLN ("int" +sizeofobject.sizeof (a)); System.out.println ("byte[2]" +sizeofobject.sizeof (b)); System.out.println ("Char" +sizeofobject.sizeof (c)); Specific actions refer to the previous note, mainly using the instrumentation API, which has a method called Getobjectsize () which runs the following results (I am the jdk1.7 64: Default turn on pointer compression): Object header: 32-bit system occupies 8bytes , the 64-bit system occupies 16bytes;
Not open below: New Byte[2] 2*1+16+8=26+padding (8) =32, int 4+16+4 =24
For open: Object header, uncompressed by a native-sized mark word 8bytes plus a class word 8bytes, a total of 16bytes. The use of compression, class word reduced to 4bytes, is a total of 12bytes occupied;
2. Reference type, reduced from 8bytes to 4bytes; 3. Array length, reduced from 8bytes to 4bytes. After the compression of the situation: new Byte[2] 2*1+12+4=18+padding (6) =24 int 4+12=16 ******************** Summary ************************* int is related to different bit compilers, on the object storage structure, regardless of the reference to the base type declaration, regardless of the operating system.