in jvm, the range of short is much smaller than that of int, but it takes up the same size of slot as int. Is the storage mode of short a legendary complement, in order to improve the query speed
?in jvm, the range of short is much smaller than that of int, but it takes up the same size of slot as int. Is the storage mode of short a legendary complement, in order to improve the query speed
? the slot
you mentioned is the variable slot in the local variable table. The virtual machine specification does not specify the amount of memory space that slot
should occupy, but directively says that each slot
should store a boolean
, byte
, char
, short
, int
, float
, reference
, or returnAddress
type data. The slot size should be less than or equal to the word length of the operating system, that is, the bus width. For example, a 32-bit machine has a word length of 32 bits.
take a 32-bit machine as an example. CPU reading data from main memory will read 32bit at one time, and it is atomic, so the size of a slot is set to 32 bits, short
occupies 16bit in heap memory, and padding to 32 bits in stack memory by means of alignment.
imagine storing two short
in one slot, so it is very difficult for the first data not to affect the second data when calculating.
first of all, memory usage is related to version and jvm implementation.
if you just declare a single variable
such as
short a;
it can be considered that there is no difference between short and int in operation and memory use, because of jvm alignment, memory consumption may be 4 bytes, but
if serialization or array allocation, memory footprint and storage space are not the same.
refer to the following code to compare the difference in file size between the two stores
import java.io.FileOutputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
public class MemTest {
public static void main(String[] args) {
new MemTest().save(new Address());
}
public void save(Address address) {
try (ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("address2.ser"))) {
oos.writeObject(address);
System.out.println("Done");
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
class Address implements Serializable{
//int a[]= new int[1000];
short a[]= new short[1000];
public Address(){
for(int i=0; i<1000;iPP){
a[i]=1024;
}
}
}
is CAS compare and set or compare and sweep, or are these two different things ...
in JAVA, running programs can be managed and monitored through the JMX interface. you can obtain the program GC through the open function of JMX, as follows: public class TestJMX { public static void main(String[] args) { List<GarbageC...
for example, if the machine full gc seven or eight times at regular intervals in an afternoon, how to start to query the problem? I feel that I can t see anything when I look at the jstack log. Mengxin asks for help. ...
see a paragraph: < H2 > before Minor GC occurs, the virtual machine checks whether the largest contiguous space available in the old era is larger than the total space of all objects in the new generation. If this condition is true, then Minor GC can e...
https: www.cnblogs.com ggjuc. this article says: < H2 > 1 CMS will not defragment the heap, so in order to prevent full gc, from causing heap fragmentation, merge the fragments by opening the CMS phase: < H2 > does this mean that after CMS full g...
< H2 > the book says: during the concurrent cleanup phase, the user thread is still running, and new garbage may be generated during this period. New garbage cannot be removed this time GC, but can only be cleaned up next time. These rubbish have a profe...
Why can t JVM tuning be automated? ...
Java71-:"";""...
import java.io.IOException; import java.util.Properties; public class PropertyUtil { public static void main(String[] args) { Properties properties = new Properties(); try { properties.load(PropertyUtil.class.getClassLoade...
in working memory, there are method stack frames and registers. Pc, is understandable, but why should some referenced main memory variables be copied to working memory? I don t think it s necessary at all, which leads to cache consistency problems. Or...
< H2 > the main method executes an exception and does not exit the program all the time < H2 > A RuntimeException,Spring container startup interrupt is thrown in the static code block of the class, but the program has not been terminated. I don t kn...
ladies and gentlemen, I have encountered a problem when using G1. The termination phase of G1 takes more than 90% of the total young gc, which is generally about 100ms, which leads to the failure of the whole program. GC log is as follows: 2018-05-16T...
console shows that ChildClass has been loaded, why not output c init ...
in most cases in JAVA, objects are allocated in Eden by default, and when GC is triggered, if there is not enough space in survivor, it will be put into the old age. suppose the following scenario: eden:80M survivor1:10M survivor2:10M now survivor2 is...
Let s not talk about the principle of the train algorithm here. the train algorithm is the gc algorithm used by the G1 collector D _ C are three objects that need to be called to each other. There are no other citations. But when the algorithm sc...
the program first executes a start method to take up a lot of memory, and then executes endEmpty to call System.gc () to run, the task manager can see that the memory footprint of the program immediately reaches 4G, but the memory footprint of th...
ask two questions: is there any difference in jvm execution between using fully qualified names and using import, except for the difference in length? If there is a difference, which is more efficient? use the class name. What is the difference in ...
The code is as follows: package referenceCoutingGC; ** * * testGC()ogjAogjBGC * * public class referenceCoutingGC { public Object instance = null; private static final int _1MB = 1024*1024; private byte[] bigSize = ...
Why does JAVA have multiple loaders I know that the function of the loader is to get the binary byte stream through the class name. It is mainly divided into four kinds of loaders: startup class-> extension class-> application class-> custom class. I al...
for example, the member variable of a class: Object obj = new Object(); obj is an instance of an object. In a broad sense, it is stored on the "stack " and points to the memory address on the "heap ". Specifically, I have the impression that obj sho...