JDK9的新特性:JVM的xlog
简介
在java程序中,我们通过日志来定位和发现项目中可能出现的问题。在现代java项目中,我们使用log4j或者slf4j,Logback等日志记录框架来处理日志问题。
JVM是java程序运行的基础,JVM中各种事件比如:GC,class loading,JPMS,heap,thread等等其实都可以有日志来记录。通过这些日志,我们可以监控JVM中的事件,并可以依次来对java应用程序进行调优。
在JDK9中引入的Xlog日志服务就是为这个目的而创建的。
通过xlog,JDK将JVM中的各种事件统一起来,以统一的形式对外输出。通过tag参数来区分子系统,通过log level来区分事件的紧急性,通过logging output来配置输出的地址。
更多内容请访问www.flydean.com
xlog的使用
先看一个最简单的xlog的使用例子:
java -Xlog -version
输出结果:
[0.016s][info][os] Use of CLOCK_MONOTONIC is supported
[0.016s][info][os] Use of pthread_condattr_setclock is not supported
[0.016s][info][os] Relative timed-wait using pthread_cond_timedwait is associated with the default clock
[0.017s][info][os] SafePoint Polling address, bad (protected) page:0x0000000108901000, good (unprotected) page:0x0000000108902000
[0.022s][info][biasedlocking] Aligned thread 0x00007f983e008200 to 0x00007f983e008800
[0.023s][info][os,thread ] Thread attached (tid: 10499, pthread id: 123145571979264).
日志非常非常长,这里就不全部列出来了。从输出的日志我们可以看到java -verson命令中JVM执行了诸多的操作。
我们可以看到日志中对每一个操作都列出了操作花费的时间,日志级别和操作所属的分类。
通过这些日志,我们对于JVM的运行可以有更加深入的理解。
使用java -Xlog:help命令我们看一下xlog的基本格式:
-Xlog Usage: -Xlog[:[selections][:[output][:[decorators][:output-options]]]]
where 'selections' are combinations of tags and levels of the form tag1[+tag2...][*][=level][,...]
NOTE: Unless wildcard (*) is specified, only log messages tagged with exactly the tags specified will be matched.
selections
selections表示的是到底需要输出哪些信息。是以tag=level来表示的。
tag表示的是JVM中的事件或者子系统:
Available log tags:
add, age, alloc, annotation, aot, arguments, attach, barrier, biasedlocking, blocks, bot, breakpoint, bytecode, cds, census, class, classhisto, cleanup, codecache, compaction, compilation, constantpool, constraints, container, coops, cpu, cset, data, datacreation, dcmd, decoder, defaultmethods, director, dump, dynamic, ergo, event, exceptions, exit, fingerprint, free, freelist, gc, handshake, hashtables, heap, humongous, ihop, iklass, init, inlining, install, interpreter, itables, jfr, jit, jni, jvmti, liveness, load, loader, logging, malloc, mark, marking, membername, memops, metadata, metaspace, methodcomparator, mirror, mmu, module, monitorinflation, monitormismatch, nestmates, nmethod, normalize, numa, objecttagging, obsolete, oldobject, oom, oopmap, oops, oopstorage, os, pagesize, parser, patch, path, perf, periodic, phases, plab, preorder, preview, promotion, protectiondomain, ptrqueue, purge, record, redefine, ref, refine, region, reloc, remset, resolve, safepoint, sampling, scavenge, setting, smr, stackmap, stacktrace, stackwalk, start, startuptime, state, stats, streaming, stringdedup, stringtable, subclass, survivor, sweep, symboltable, system, table, task, thread, time, timer, tlab, tracking, unload, unshareable, update, verification, verify, vmmutex, vmoperation, vmthread, vtables, vtablestubs, workgang
Specifying 'all' instead of a tag combination matches all tag combinations
levels表示的是日志的级别:
Available log levels:
off, trace, debug, info, warning, error
下面举个例子:
java -Xlog:os,class=info -version
输出结果:
[0.002s][info][os] Use of CLOCK_MONOTONIC is supported
[0.002s][info][os] Use of pthread_condattr_setclock is not supported
[0.002s][info][os] Relative timed-wait using pthread_cond_timedwait is associated with the default clock
[0.003s][info][os] SafePoint Polling address, bad (protected) page:0x0000000109543000, good (unprotected) page:0x0000000109544000
[0.006s][info][os] attempting shared library load of /Library/Java/JavaVirtualMachines/jdk-14.0.1.jdk/Contents/Home/lib/libjava.dylib
[0.007s][info][os] shared library load of /Library/Java/JavaVirtualMachines/jdk-14.0.1.jdk/Contents/Home/lib/libjava.dylib was successful
[0.007s][info][os] attempting shared library load of /Library/Java/JavaVirtualMachines/jdk-14.0.1.jdk/Contents/Home/lib/libzip.dylib
[0.010s][info][os] shared library load of /Library/Java/JavaVirtualMachines/jdk-14.0.1.jdk/Contents/Home/lib/libzip.dylib was successful
output
output表示将日志输出到什么地方。
output的可选项:
stdout/stderr
file=<filename>
stdout表示标准输出,stderr表示标准错误。file表示输出到文件里面。
举个例子:
java -Xlog:all=debug:file=debug.log -version
decorators
decorators表示输出哪些内容到日志中。
time (t), utctime (utc), uptime (u), timemillis (tm), uptimemillis (um), timenanos (tn), uptimenanos (un), hostname (hn), pid (p), tid (ti), level (l), tags (tg)
Decorators can also be specified as 'none' for no decoration
看下这个例子:
java -Xlog:gc*=debug:stdout:time,uptimemillis,tid -version
输出结果:
[2020-05-05T16:12:06.871-0800][32ms][9475] Heap region size: 1M
[2020-05-05T16:12:06.871-0800][32ms][9475] Minimum heap 8388608 Initial heap 134217728 Maximum heap 2147483648
[2020-05-05T16:12:06.872-0800][33ms][9475] Heap address: 0x0000000780000000, size: 2048 MB, Compressed Oops mode: Zero based, Oop shift amount: 3
[2020-05-05T16:12:06.872-0800][33ms][9475] ConcGCThreads: 1 offset 8
[2020-05-05T16:12:06.872-0800][33ms][9475] ParallelGCThreads: 4
总结
xlog是JDK9中提供的非常有用的一个功能。大家可以在日常的工作中使用。
更多精彩内容且看:
- 区块链从入门到放弃系列教程-涵盖密码学,超级账本,以太坊,Libra,比特币等持续更新
- Spring Boot 2.X系列教程:七天从无到有掌握Spring Boot-持续更新
- Spring 5.X系列教程:满足你对Spring5的一切想象-持续更新
- java程序员从小工到专家成神之路(2020版)-持续更新中,附详细文章教程
本文作者:flydean程序那些事
本文链接:http://www.flydean.com/jdk9-jvm-xlog/
本文来源:flydean的博客
欢迎关注我的公众号:程序那些事,更多精彩等着您!
JDK9的新特性:JVM的xlog的更多相关文章
- Jdk14 都要出了,Jdk9 的新特性还不了解一下?
Java 9 中最大的亮点是 Java 平台模块化的引入,以及模块化 JDK.但是 Java 9 还有很多其他新功能,这篇文字会将重点介绍开发人员特别感兴趣的几种功能. 这篇文章也是 Java 新特性 ...
- Java12新特性 -- JVM 常量 API
Java 12 中引入 JVM 常量 API,用来更容易地对关键类文件 (key class-file) 和运行时构件(artefact)的名义描述 (nominal description) 进行建 ...
- 最通俗易懂的 Java 11 新特性讲解
大多数开发者还是沉浸在 Java 8 中,而 Java 14 将要在 2020 年 3 月 17 日发布了,而我还在写着 Java 11 的新特性.Java 11 是 Java 8 之后的第一个 LT ...
- Java8新特性【转】
地址:http://ifeve.com/java-8-features-tutorial/ 1.简介 毫无疑问,Java 8是自Java 5(2004年)发布以来Java语言最大的一次版本升级,Ja ...
- 聊聊 Java8 以后各个版本的新特性
作者:ZY5A59 juejin.im/post/5d5950806fb9a06b0a277412 某天在网上闲逛,突然看到有篇介绍 Java 11 新特性的文章,顿时心里一惊,毕竟我对于 Java ...
- JDK9 新特性
JDK9 新特性目录导航 目录结构 模块化系统 jshell 多版本兼容JAR 接口的私有方法 改进try-with-resourcs 改进砖石操作符 限制使用单独下划线标识符 String存储结构变 ...
- 一文带你看遍 JDK9~14 的重要新特性!
Java9 发布于 2017 年 9 月 21 日 .作为 Java8 之后 3 年半才发布的新版本,Java 9 带 来了很多重大的变化其中最重要的改动是 Java 平台模块系统的引入,其他还有诸如 ...
- 深入理解JVM内幕:从基本结构到Java 7新特性
转自:http://www.importnew.com/1486.html 每个Java开发者都知道Java字节码是执行在JRE((Java Runtime Environment Java运行时环境 ...
- JVM的运行原理以及JDK 7增加的新特性(二)
JVM结构 Java编写的代码会按照下图的流程来执行 类装载器装载负责装载编译后的字节码,并加载到运行时数据区(Runtime Data Area),然后执行引擎执行会执行这些字节码. 类加载器(Cl ...
- JDK9新特性实战:流关闭新姿势
做Java开发的都知道,每个资源的打开都需要对应的关闭操作,不然就会使资源一直占用而造成资源浪费,从而降低系统性能. 关于资源的关闭操作,从JDK7-JDK9有了不少的提升及简化. JDK6 在JDK ...
随机推荐
- 【LeetCode贪心#04】跳跃游戏I + II
跳跃游戏 力扣题目链接(opens new window) 给定一个非负整数数组,你最初位于数组的第一个位置. 数组中的每个元素代表你在该位置可以跳跃的最大长度. 判断你是否能够到达最后一个位置. 示 ...
- 【Azure Developer】Windows中通过pslist命令查看到Java进程和线程信息,但为什么和代码中打印出来的进程号不一致呢?
通过PSLIST查看Windwos中的进程信息及线程信息 一:下载PSLIST小工具:https://docs.microsoft.com/en-us/sysinternals/downloads/p ...
- Java 异常处理(1) : try-catch- finally中finally的使用
1 package com.bytezero.throwable; 2 3 import java.io.File; 4 import java.io.FileInputStream; 5 impor ...
- Acwing第132场周赛
AcWing 5366. 大小写转换 签到题,可以用stl里面的tolower函数 #include <bits/stdc++.h> #define ls p<<1 #defi ...
- java基础 韩顺平老师的 面向对象(基础) 自己记的部分笔记
194,对象内存布局 基本数据类型放在堆里面,字符串类型放在方法区. 栈:一般存放基本数据类型(局部变量) 堆:存放对象(Cat cat,数组等) 方法区:常量池(常量,比如字符串),类加载信息 19 ...
- WPF入门教程系列目录
WPF入门教程系列一--基础 WPF入门教程系列二--Application介绍 WPF入门教程系列三--Application介绍(续) WPF入门教程系列四--Dispatcher介绍 WPF入门 ...
- MySql学习之初识SQLyog
•SQLyog安装与配置 [安装包,提取码:w6sj] [安装教程,提取码:cwqu] •MySQL的语法规范 不区分大小写,但建议关键字大写,表名.列名小写 每条命令最好用分号结尾 每条命令根据需要 ...
- 面试官问我会ES么,我说不会,抓紧学起【ES(一)聚合分析篇】
ES聚合分析 1.metric(指标)聚合 1.1 单值分析 min 求指定字段的最小值 # 求价格的最小值 { "size":0, "aggs":{ &quo ...
- vscode 智能提示 函数提示右侧有所在目录 Show Inline Details
vscode 智能提示 函数提示右侧有所在目录 Show Inline Details 有目录提示的 没有目录提示的 默认是有目录提示,我那个配置单啊~ "editor.suggest.sh ...
- SpringBoot单次执行任务,退出异常NoClassDefFoundError: ch/qos/logback/classic/spi/ThrowableProxy
背景 使用SpringBoot 运行一次性作业,用于初始化 问题:直接使用System.exit退出时,遇到异常:NoClassDefFoundError: ch/qos/logback/classi ...