What's different about the Java grooming-int type in 32-bit and 64-bit __java

Source: Internet
Author: User
Tags array length
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.

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.