当前位置:网站首页>StringTable Detailed String Pool Performance Tuning String Concatenation
StringTable Detailed String Pool Performance Tuning String Concatenation
2022-08-01 20:34:00 【Jing <>】
1. Composition:

2. The relationship between the constant pool and the string pool:

The constant pool originally exists in the bytecode file. When running, the information in the constant pool will be loaded into the runtime constant pool. At this time, a, b, and ab are all symbols in the constant pool, and there is no changeinto a java string object, when it is executed to the line of code that references him, the a symbol will be turned into an object, and a space for the StringTable string pool will be prepared at the same time, and the generated object "a" will be used as the key.Find it in the pool, if not, put the newly generated object a into the string pool.(Note: each string object is only put into the string pool when this sentence is executed, not in advance)
The data structure of StringTable is hashtable, which has a fixed length and cannot be expanded.
3. String variable concatenation
eg: the following example is false

s3 is in the string pool, and s4 is the spliced ab. Under the action of toString, the spliced data is turned into a new string, which exists in the heap, which is equivalent to new String ("ab")
The following is the source code of toString

eg: The following example is true

s5 is because of the optimization of javac during compilation, it will consider "a" and "b" to be constants, and the splicing result is determined. The result has been determined as ab at compile time and will not change, so it is put into the string pool.The previous one is a variable, and its value may be modified at runtime, so it needs to be spliced with SringBuilder at runtime.

Lines 6 and 29 both find a symbol with a value of ab at position 4 in the constant pool, so when s3 is executed, it is found that there is no such object in the string pool, and the ab object is created according to the ab symbol, it will be put into the string pool, and when the execution reaches s5, the ab symbol will be found at position 4, so no new objects will be created, and the objects in the string pool will be used directly.
Only constant strings are stored in the string pool.
4.Characteristics of StringTable:
1. The strings in the constant pool are only symbols, and will become objects when they are used for the first time
2. Use the mechanism of string pool to avoid repeated creation of string objects
3. The principle of string variable splicing is StringBuilder (jdk1.8)
4. The principle of string constant concatenation is compile-time optimization
5. You can use the intern method to actively put the string objects that are not yet in the string pool into the string pool, and put the address (if there is one in 1.8, it will not be put in, if not, it will be put directly, regardless of whether it is there or not.All directly return the object value in the string pool. In 1.6, if there is one, it will not be put in, if not, a copy will be assigned and put in, and the object value in the string pool will be returned directly regardless of whether there is or not.)
Example:

If the position is changed as follows: x2 is successfully entered into the pool, but also exists in the heap at the same time
Version 1.6:

5. Location of StringTable


StringTable garbage collection:
StringTable will also be garbage collected, and garbage collection will occur when the memory is not very sufficient.
5.StringTable performance tuning
Two considerations:
①Mainly adjust the number of hashtable buckets,
The larger the number of buckets, the faster the operation will be.There will be better hash distribution and reduce hash conflicts
You can use -XX:StringTableSize=Number of buckets to adjust

②Consider whether to put the string object into the pool. After entering the pool, it will take up much less memory
边栏推荐
- 算法---解码方法(Kotlin)
- Little data on how to learn?Jida latest small learning data review, 26 PDF page covers the 269 - page document small data learning theory, method and application are expounded
- STAHL触摸屏维修一体机显示屏ET-316-TX-TFT常见故障
- 我的驾照考试笔记(2)
- idea插件generateAllSetMethod一键生成set/get方法以及bean对象转换
- Does LabVIEW really close the COM port using VISA Close?
- 任务调度线程池-应用定时任务
- 【Social Media Marketing】How to know if your WhatsApp is blocked?
- To promote energy conservation institute 】 【 the opinions of the agricultural water price reform
- LinkedList源码分享
猜你喜欢

OSG笔记:设置DO_NOT_COMPUTE_NEAR_FAR,手动计算远近平面
Godaddy domain name resolution is slow and how to use DNSPod resolution to solve it

进行交互或动画时如何选择Visibility, Display, and Opacity

虚拟机的IP地址自动变为127.0.0.1

第59章 ApplicationPart内置依赖注入中间件

Buttons with good user experience should not have hover state on mobile phones

第55章 业务逻辑之订单、支付实体定义
Godaddy域名解析速度慢问题以及如何使用DNSPod解析解决

泰德制药董事长郑翔玲荣膺“2022卓越影响力企业家奖” 泰德制药荣获“企业社会责任典范奖”

第56章 业务逻辑之物流/配送实体定义
随机推荐
】 【 nn. The Parameter () to generate and why do you want to initialize
Debug一个ECC的ODP数据源
密码学的基础:X.690和对应的BER CER DER编码
【nn.Parameter()】生成和为什么要初始化
【多任务模型】Progressive Layered Extraction: A Novel Multi-Task Learning Model for Personalized(RecSys‘20)
[Multi-task learning] Modeling Task Relationships in Multi-task Learning with Multi-gate Mixture-of-Experts KDD18
Zheng Xiangling, Chairman of Tide Pharmaceuticals, won the "2022 Outstanding Influential Entrepreneur Award" Tide Pharmaceuticals won the "Corporate Social Responsibility Model Award"
Buttons with good user experience should not have hover state on mobile phones
Arthas 常用命令
大整数相加,相减,相乘,大整数与普通整数的相乘,相除
SIPp 安装及使用
ARTS_202207W2
【个人作品】无线网络图传模块
第57章 业务逻辑之业务实体与数据库表的映射规则定义
洛谷 P2440 木材加工
Multithreaded producers and consumers
C语言实现-直接插入排序(带图详解)
StringTable详解 串池 性能调优 字符串拼接
不同的操作加不同的锁详解
【无标题】