Management of Java Virtual Machine, memory Section

1. Introduction

This tutorial aims at reviewing some basic knowledge of Java. If you are preparing for an interview or want to enhance your understanding of Java language, you can subscribe to this series. My plan is to create serval tutorials covering topics from JVM, Hashmap, basic data structure, spring and more!

2. JVM

The Java Virtual Machine (AKA. JVM) is the core component of Java programing language. To better understand, we can treat JVM as a program that helps us execute other programs. To handle daily work better, we need to understand many crucial functions and principles in JVM. This tutorial will focus on better memory allocation and higher GC efficiency in JVM management. 

3. Stack Memory in Java

Static memory allocation and the execution of a thread

1. primitive values that are specific to a method

2. references of objects in hemp

3. When new block is created, a space is created in the stack, methods finish, space out

4. The stack is fast and threadsafe since each thread operates in its stack.

Hemp space in Java

Hemp space is used for the dynamic memory allocation of Java objects and JRE classes at runtime. New Object is stored in heap space while its reference is stored in the stack.

The hemp memory space can be further divided into three smaller parts:

  1. Young Generation: this is where all new objects are stored. A new GC process will be executed when this part is filled up.
  2. Old or tenured Generation: when the new Generation's time is up, it will be sent to this Generation.
  3. Permanent Generation: JVM metadata, runtime classes and application methods

  • This memory, in contrast to stack, isn't automatically deallocated. It needs Garbage Collector to free up unused objects to keep the efficiency of the memory usage. Changing the memory allocation of different generations is the crucial logic of JVM performance maintenance.

Red-black tree

The red-black tree is a kind of binary search tree. However, the most crucial feature is that the red-black tree is self-balanced by default. Compared to a typical binary search tree, the red-black tree solved unbalanced structure problems that happen in some extreme instances. There are a few essential rules that each red-black tree must follow:

  1. It must follow the standard binary search tree rule.
  2. The root node must be black.
  3. Each node is either red or black.
  4. the end leaf, which is always black
  5. the child node of red nodes must be black

Finally is the crucial rule: every path from the root node to the nil node must contain the same number of black nodes.

When the above rules are followed, a standard red-black tree will be formed automatically! The hashmap data structure applies the red-black tree, which is why it can use the null key and value.

The difference between Hashmap and Hashtable

Hashmap and Hashtable are two commonly used map collections in Java. However, many people are unfamiliar with these two classes' differences. Here, I listed some basic information about the difference between Hashmap and Hashtable:

  1. Since Java 1.8, Hashmap uses the red-black tree as its memory method, while Hashtable still uses array and LinkedList.
  2. HashMap's key and value could be null, but Hashtable couldn't.
  3. The hash algorithm is different between Hashmap and Hashtable. Hashtable uses the class's own hashcode() method.
  4. Hashmap is not synchronized while Hashtable is. In other words, the efficiency of Hashmap is higher than Hashtable, although Hashtable is concurrency secured.

These are some essential points in differentiating Hashmap and Hashtable. In the following tutorial, we will look at some basic information about the life cycle of servlet and spring, as well as HTTP and tcp protocol.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Memory hierarchy management refers to the process of organizing and managing the different levels of memory in a computer system, including the cache, main memory, and secondary storage. The goal of memory hierarchy management is to optimize the use of memory resources and improve system performance. This is achieved through a combination of hardware and software techniques that help to minimize the amount of time it takes to access data from memory. At the lowest level of the memory hierarchy is the main memory, which is typically implemented using dynamic random-access memory (DRAM) chips. Main memory is fast but expensive, so it is relatively small compared to the amount of data that needs to be stored in a typical computer system. To make up for the limited capacity of main memory, computer systems use caching techniques to store frequently accessed data in a faster, smaller cache memory. The cache is typically implemented using static random-access memory (SRAM) chips, which are much faster than DRAM but more expensive. Memory hierarchy management involves coordinating the movement of data between the different levels of the memory hierarchy, based on factors such as the frequency of access, the size of the data, and the available memory resources. This is done using algorithms such as cache replacement policies, which determine which data should be evicted from the cache to make room for new data. Other memory management techniques include virtual memory, which allows the operating system to use secondary storage as an extension of main memory, and memory compression, which compresses data in memory to free up space for additional data. Overall, memory hierarchy management is critical to the performance and efficiency of modern computer systems, and requires a careful balance of hardware and software optimizations to achieve optimal results.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值