当前位置:网站首页>偏向锁、轻量级锁测试工具类级相关命令
偏向锁、轻量级锁测试工具类级相关命令
2022-07-29 05:27:00 【魔道不误砍柴功】
依赖包
依赖包推荐使用 0.9 版本的,其他版本可能有不一样的效果,珍重。
<dependency>
<groupId>org.openjdk.jol</groupId>
<artifactId>jol-core</artifactId>
<version>0.9</version>
</dependency>
演示代码
package com.xxl.job.admin.mytest;
import org.openjdk.jol.info.ClassLayout;
import java.util.concurrent.TimeUnit;
public class ObjectMarkWordDemo {
public void test() {
Object obj = new Object();
synchronized (obj) {
System.out.println("111");
}
synchronized (obj) {
System.out.println("111");
}
synchronized (obj) {
System.out.println("111");
}
}
public static void main(String[] args) throws InterruptedException {
// 打印 JVM 相关的信息
// System.out.println(VM.current().details());
// 打印每个对象是否为 8 的整数倍大小
// System.out.println(VM.current().objectAlignment());
MyObject myObject = new MyObject();
System.out.println(Integer.toHexString(myObject.hashCode()));
new Thread(()->{
// 在 myObject 对象头上进行加锁(默认直接干到轻量级锁,这里我非要把他干到偏向锁状态)
// 默认是开启偏向锁的,所以这里我们只需要把开启偏向锁的延迟时间修改成 0 方便看效果 -XX:+BiasedLockingStartupDelay=0
synchronized (myObject) {
// 给这个线程加锁,并且还设置了偏向线程 ID
System.out.println(ClassLayout.parseInstance(myObject).toPrintable());
}
}).start();
TimeUnit.MICROSECONDS.sleep(500);
// 锁被释放了,所以这里打印的肯定是无锁状态 001
System.out.println(ClassLayout.parseInstance(myObject).toPrintable());
}
}
class MyObject {
}
运行结果:
76fb509a
# WARNING: Unable to attach Serviceability Agent. You can try again with escalated privileges. Two options: a) use -Djol.tryWithSudo=true to try with sudo; b) echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope
com.xxl.job.admin.mytest.MyObject object internals:
OFFSET SIZE TYPE DESCRIPTION VALUE
0 4 (object header) e8 29 c3 0a (11101000 00101001 11000011 00001010) (180562408)
4 4 (object header) 03 00 00 00 (00000011 00000000 00000000 00000000) (3)
8 4 (object header) 44 c1 00 f8 (01000100 11000001 00000000 11111000) (-134168252)
12 4 (loss due to the next object alignment)
Instance size: 16 bytes
Space losses: 0 bytes internal + 4 bytes external = 4 bytes total
# WARNING: Unable to attach Serviceability Agent. You can try again with escalated privileges. Two options: a) use -Djol.tryWithSudo=true to try with sudo; b) echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope
com.xxl.job.admin.mytest.MyObject object internals:
OFFSET SIZE TYPE DESCRIPTION VALUE
0 4 (object header) e8 29 c3 0a (11101000 00101001 11000011 00001010) (180562408)
4 4 (object header) 03 00 00 00 (00000011 00000000 00000000 00000000) (3)
8 4 (object header) 44 c1 00 f8 (01000100 11000001 00000000 11111000) (-134168252)
12 4 (loss due to the next object alignment)
Instance size: 16 bytes
Space losses: 0 bytes internal + 4 bytes external = 4 bytes total
常用命令
设置 JVM 堆大小
-Xms10m -Xmx10m
查询 JVM 启动运行了那些命令
java -XX:+PrintCommandLineFlags -version
关闭对象头中类指针的压缩配置
-XX:-UseCompressedClassPointers
查询偏向锁是否开启
java -XX:+PrintFlagsInitial | grep BiasedLock
运行结果:
intx BiasedLockingBulkRebiasThreshold = 20 {
product}
intx BiasedLockingBulkRevokeThreshold = 40 {
product}
intx BiasedLockingDecayTime = 25000 {
product}
// 然后偏向锁开启之后默认会有4s钟的延迟,测试的时候需要注意,可以将这个值设置成0,方便查看效果
intx BiasedLockingStartupDelay = 4000 {
product}
bool TraceBiasedLocking = false {
product}
// JVM 默认开启了偏向锁的设置
bool UseBiasedLocking = true {
product}
开启偏向锁设置
-XX:+UseBiasedLocking -XX:BiasedLockingStartupDelay=0
边栏推荐
- day02_ Basic grammar
- Understand the great changes of network security in five years
- 软件包设置成——>YUM源
- Floating point addition and subtraction method of vivado IP core floating point
- 软件定义边界SDP
- 10种常见的软件架构模式
- Hongke case | PAC: an integrated control solution integrating SoftPLC control logic, HMI and other service functions
- MQTT服务器搭建以及使用MQTT.fx测试
- Common server faults and their solutions
- 软件测试职业发展:软件测试人员该何去何从
猜你喜欢

成长为架构师途中的一些思考

Arrays & object & System & Math & random & Packaging

FIR filter design (2) -- vivado calls IP core to design FIR filter

Ansible(自动化软件)

day12_多线程

Design and simulation code of 4-bit subtracter based on FPGA

5G服务化接口和参考点

比较单片机3种时钟电路方案

Hongke | uses jesd204 serial interface to bridge analog and digital worlds at high speed

FIR filter design (1) -- using the FDATool toolbox of MATLAB to design FIR filter parameters
随机推荐
三、广域通信网
Scanbasepackages scanning range configuration
Idea practical shortcut key novice must see
Raw advanced socket experiment
Traffic characteristics of webshell management tools
多路IO用法
Hongke automation SoftPLC | Hongke kPa modk operation environment and construction steps (3) -- modk routine test
Online multiplayer chat room based on UDP communication
ping 原理
What are the advantages of software testing? See how much you know
What is the lifecycle of automated testing?
Verilog中for语句的使用
Leetcode刷题记录
10种常见的软件架构模式
TCP socket communication experiment
如何判断业务被DDoS攻击?又会造成哪些危害?
Hongke case | PAC: an integrated control solution integrating SoftPLC control logic, HMI and other service functions
Arrays & object & System & Math & random & Packaging
Joint use skills of joiner.on and stream().Map
Is it OK to directly compare the size of two numbers in FPGA?