"Reprint" Android Studio set memory size and principle

Source: Internet
Author: User

Http://www.cnblogs.com/justinzhang/p/4274985.html

Http://tsroad.lofter.com/post/376316_69363ae

Android Studio 1.0.2 default maximum memory is 750M, so run up very card, unbearable, machine is not SSD, finally found that this default value is can be modified in Android Studio directory found: Studio64.exe.vmoptions file, the green part for the modified parameters (-xmx1050m), the default parameters modified to 1050MB, so that the running is very smooth, if it is not smooth enough, you can change the higher:

-xms128m-xmx1050m-xx:maxpermsize=350m-xx:reservedcodecachesize=96m-ea-dsun.io.usecanoncaches= False-djava.net.preferipv4stack=true-djna.nosys=true-djna.boot.library.path=-djna.debug_load=true-djna.debug_ LOAD.JNA=TRUE-DJSSE.ENABLESNIEXTENSION=FALSE-XX:+USECODECACHEFLUSHING-XX:+USECONCMARKSWEEPGC-XX: Softreflrupolicymspermb=50-didea.platform.prefix=androidstudio-didea.paths.selector=androidstudio

Contents-bin-studio.vmoptions in the Android Studio package content under Mac system

If this setting does not take effect, in file->ivalidate caches, selecting Ivalidate and restart can take effect:

Finally, as you can see in the Explorer, Studio64.exe's memory footprint has risen to more than 1GB in an instant.

————————————————————————————————————————————

Learn something about the next JVM from the startup parameters of Androidstudio (memory usage, JIT, etc.)

If you use Androidstudio often feel very card, it is possible because the system to the as allocated memory is not enough reason. Open/applications/android studio.app/contents/bin/studio.vmoptions (MAC) and you can see the following configuration:

-xms128m-xmx750m-xx:maxpermsize=350m-xx:reservedcodecachesize=96m-xx:+usecompressedoops

What do these parameters mean, respectively?

-xms128m

THE-XMS option sets the initial and minimum Java heap size. The Java heap (the "heap") is the part of the memory where blocks of memory was allocated to objects and freed during garb Age collection.

Is the starting heap memory that the JVM initiates, and heap memory is the memory allocated to the object. Here, I changed it to 512m.

-xmx750m

This option sets the maximum Java heap size.

Which is the maximum heap memory that Androidstudio can use, and here I changed it to 2048m.

Both of these parameters are X-first and represent nonstandard parameters. What do you mean by non-standard? We know that there are many implementations of the JVM, Oracle, OPENJDK, and so on, where the-x parameter, which is used by the Oracle JVM implementation, is not necessarily openjdk, which means that the parameters are not standardized so that all JVM implementations can be used.

-xx:maxpermsize=350m

This parameter specifies the maximum permanent generation size.
According to Oracle's documentation:

Permanent Generation (non-heap): The pool containing all the reflective data of the virtual machine itself, such as class and method objects. With Java VMs, the use of class data sharing, this generation are divided into read-only and read-write areas.

It is known that Permanent generation is also a memory area, different from the heap, which is stored in the class itself (not objects), as well as methods, some fixed strings and so on. More about Permanent Generation

-xx:reservedcodecachesize=90m

Reservedcodecachesize (and Initialcodecachesize) is a option for the (just-in-time) compiler of the Java Hotspot VM. Basically it sets the maximum size for the compiler ' s code cache.

Sets the maximum code cache for JIT Java compiler at compile time. Simply put, the JIT (Just in time) compiler needs to cache something when compiling the code, which specifies how much memory can be used to cache these things.
What does JIT mean? Read Wikipedia's explanation:

In Computing, Just-in-time compilation (JIT), also known as Dynamic Translation, was compilation done during of a Program–at run time–rather than prior to execution. Most often the consists of translation to machine code, which are then executed directly, but can also refer to Translatio N to another format. JIT compilation is a combination of the and traditional approaches to translation to machine Code–ahead-of-time Compilat Ion (AOT), and Interpretation–and combines some advantages and drawbacks of both. [1] Roughly, JIT compilation combines the speed of compiled code with the flexibility of interpretation, with the overhead of a interpreter and the additional overhead of compiling (not just interpreting). JIT compilation is a form of the dynamic compilation, and allows adaptive optimization such as dynamic Recompilation–thus in Principle JIT compilation can yield faster execution than static compilation. Interpretation and JIT compilation is particularly suited for dynAmic programming languages, as the runtime system can handle late-bound data types and enforce security guarantees.

We know that the programming language is divided into two kinds:-compile-type, the code is compiled into assembly or machine language, one code and then execute. -interpreted type, does not need to compile, the person writes the code one piece to take over once executes, takes first one, executes, finishes and then removes one, then executes.

For Java, this is a very special situation, because in Java, the JVM first compiles the Java code into bytecode, and then executes the bytecode code within the JVM. You say it is a compiled type, bytecode do not have to compile into machine code, and the second is a bytecode one execution. You say it's an explanatory type, and it has a compilation process. There is no final verdict as to whether Java is a compiled or interpreted type. However, we can still discuss the JIT-compiling technology of Java.
Just said, at the bytecode level, the code is interpreted to perform. The interpreted language is slower because it has no way to optimize the code based on context. And the compiled language can be optimized. Java's JIT technology, is in the bytecode interpretation of execution, it is not necessarily an explanation of the execution, the second is to take a piece of code, compiled into machine code, and then execute, so there is the context, you can optimize the code, so the execution speed will be faster.
As can be seen, JIT technology combines the advantages of both compiled (faster) and interpreted languages (more flexible code). is a very big advantage for dynamic language execution.

-xx:+usecompressedoops

This parameter allows the system to store the reference (reference) type in the code with 32 bits, while allowing the reference to use a 64-bit memory size.
We know that modern machines are basically 64-bit, in which case the reference type in the Java code is also changed to 64 bits to store, which leads to two problems:
1.64 bit more than 32 for larger, accounted for more memory, this is obvious, of course, this problem is not obvious in the entire program, because even if the system has 1000 references exist, the memory of more than 4 m, this is not important, because now mobile phones are several g, the large server is even more needless to say. More important is the 2nd. 2. Relative to memory, the CPU cache is small poor, when the reference from 32bit to 64bit, the cache can be stored in the number of reference is immediately a lot less. So 64bit reference to the cache is a big problem, so there is this option, you can allow the system to use 32bit to store reference, so that the cache can store more reference, without affecting the reference of the range of access. As to how they do it, I don't know ...

The above three parameters start with-XX, according to Oracle's instructions,

Options that is specified with-xx is not stable and is subject to the change without notice.

"Reprint" Android Studio set memory size and principle

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.