SlideShare a Scribd company logo
1 of 60
Download to read offline
- JDK Flight Recorder -
2019 6 27
Duke An Oracle blog about Oracle Enterprise Pack for Eclipse Java 8 Launch!
Java Log4j Logback
JDK11 JDK Flight Recorder
JDK Flight
Recorder
0 1 400 4 154 000 1 800
JFR disabled JFR enabled,
stackdepth=1
log4j OFF log4j INFO j.u.logging OFF j.u.logging INFO Redirected
System.out
NANOS/OPERATION
JMC, 8 THREADS
Logging Benchmark
120 000 00043 000 000
JFR
Jfokus Developer Conference 2018 Mission Possible -Near Zero overhead profiling
java.util.logging System.outJDK Flight Recorder Apache Log4j
ON
OFF
ON
OFF
ON
OFF
Logger Layout Appender
Application DB
output
Console
info( )
debug( )
error( )
warn( )
File
Logger Layout Appender
Application DB
output
Console
info( )
debug( )
error( )
warn( )
File
Logger Layout Appender
Application DB
output
Console
info( )
debug( )
error( )
warn( )
File
Logger Layout Appender
Application DB
output
Console
info( )
debug( )
error( )
warn( )
File
ERROR
WARN
INFO
DEBUG
etc… DEBUG TRACE
※ SLF4J
public class Example {
private static final Logger logger = LogFactory.getLogger(getClass());
public Integer calculate(Integer x, Integer y) {
try {
logger.info(“calculate {‘x’:’{}’,‘y’:’{}’}”, x, y);
//
if (logger.isDebug()) {
//
logger.debug(“calculate {‘base’:’{}’,’seed’:’{}’”, base, seed);
}
} catch (Exception ex) {
logger.error(“Failed to calculate. {‘x’:’{}’,‘y’:’{}’}”, x, y, ex);
}
logger.info(“Success calculate {‘x’:’{}’,’y’:’{}’,’return’:’{}’}“, x, y, z);
return z;
}
}
error( ) warn( ) info( ) debug( ) trace( )
ERROR
WARN
INFO
DEBUG
TRACE
JFR
public static void setProperty(String key, String datum) {
check("setProperty." + key);
props.put(key, datum);
invalidateSMCache(key); /* See below. */
SecurityPropertyModificationEvent spe = new SecurityPropertyModificationEvent();
// following is a no-op if event is disabled
spe.key = key;
spe.value = datum;
spe.commit();
if (EventHelper.isLoggingSecurity()) {
EventHelper.logSecurityPropertyEvent(key, datum);
}
}
/src/java.base/share/classes/java/security/Security.java
Event
※ JFR JDK Flight Recorder
JFR Event
<setting name="threshold" control="socket-io-threshold">20 ms</setting>
</event>
<event name="jdk.SecurityPropertyModification">
<setting name="enabled">false</setting>
<setting name="stackTrace">true</setting>
</event>
<event name="jdk.TLSHandshake">
<setting name="enabled">true</setting>
<setting name="stackTrace">true</setting>
</event>
<event name="jdk.X509Validation">
<setting name="enabled">false</setting>
<setting name="stackTrace">true</setting>
</event>
<event name="jdk.X509Certificate">
<setting name="enabled">true</setting>
<setting name="stackTrace">true</setting>
</event>
<event name="jdk.JavaExceptionThrow">
<setting name="enabled" control="enable-exceptions">false</setting>
/src/jdk.jfr/share/conf/jfr/default.jfc
Layout Appender
Application DB
output
Console File
Logger
info( )
debug( )
error( )
warn( )
ID”yyyyyy” “xxx” ”80”
”TLS_DHE_DSS_WITH_AES_256_CBC_SHA256” TLS“1.3”
TLS {“peer_host”:”xxx”, “peer_port”:80,
“protocol_version”:”1.3”, “certificate_id”:”yyyyyy”,
“cipher_suite”:”TLS_DHE_DSS_WITH_AES_256_CBC_SHA256”}
JFR
@Category({"Java Development Kit", "Security"})
@Label("TLS Handshake")
@Name("jdk.TLSHandshake")
@Description("Parameters used in TLS Handshake")
public final class TLSHandshakeEvent extends AbstractJDKEvent {
@Label("Peer Host")
public String peerHost;
@Label("Peer Port")
public int peerPort;
@Label("Protocol Version")
public String protocolVersion;
@Label("Cipher Suite")
public String cipherSuite;
@Label("Certificate Id")
@Description("Peer Certificate Id")
@CertificateId
public long certificateId;
}
/src/jdk.jfr/share/classes/jdk/jfr/events/TLSHandshakeEvent.java
Layout Appender
DB
output
Console File
Logger
Application
info( )
debug( )
error( )
warn( )
%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
2019-06-27 16:32:18.549 [main] INFO example.Example - TLS
{“peer_host”:”xxx”, “peer_port”:80, “protocol_version”:”1.3”, “certificate_id”:”yyyyyy”,
“cipher_suite”:”TLS_DHE_DSS_WITH_AES_256_CBC_SHA256”}
※ Logback PatternLayout
Logger LoggingEvent
Logger
LoggingEvent
Layout Appender
Application DB
info( )
debug( )
new
output
level
message
throwable
thread name
Console
error( )
warn( )
File
JFR
JFR Event
Application
new
fields
timestamp
stack trace
thread name
Logger Layout Appender
DB
output
Console
info( )
debug( )
error( )
warn( )
File
commit( )
field1 = xxxx;
JMC※ JMC JDK Mission Control
File
Logger Layout Appender
Application DB
info( )
debug( )
output
Console
error( )
warn( )
Appender
Appender
ConsoleAppender
FileAppender
RollingFileAppender
TimeBasedRollingPolicy
SizeBasedTriggeringPolicy
DBAppender DB
SMTPAppender ERROR
※ Logback Appender
JFR
Java API
Events
JavaVM
/ OS Events
Repository
(disk storage)
Global
Buffer
-a
-b
Global
Buffer
Global
Buffer
Global
Buffer
Global
Buffer
Global
Buffer
Global
Buffer
Global
Buffer
When full, is copied into
Thread
Buffer
Event
Event
Event
Event
When full,

is copied into
JFR File
When triggered, is dumped into
DBConsole File
Layout Appender
info( )
debug( )
error( )
warn( )
output
Application
Logger
Filter
LevelFilter
GEventEvaluator
Groovy onMatch onMismatch
DuplicateMessageFilter
※ Logback Filter
Settings Annotation
EnabledSetting @Enabled
ThreasholdSetting @Threshold
PeriodSetting @Period
StackTraceSetting @StackTrace
Event#commit()
JFR
JFR
Event Setting …
1. Event @SettingDefinition
2. SettingControl
public class HTTPRequestEvent extends Event {
@Label("Request URI")
protected String uri;
@Label("Servlet URI Filter")
@SettingDefinition
protected boolean uriFilter(RegExpControl regExp) {
return regExp.matches(this.uri);
}
}
@SettingDefinition SettingControl
class ExampleServlet extends HTTPServlet {
protected void doGet(HttpServletRequest req, HttpServletResponse resp) {
HTTPRequestEvent event = new HTTPRequestEvent();
event.begin();
event.uri = req.getRequestURI();
...
event.end();
event.commit();
}
...
}
final class RegExpControl extends SettingControl {
private Pattern pattern = Pattern.compile(“.*");
public boolean matches(String s) {
return this.pattern.matcher(s).find();
}
@Override
public String combine(Set<String> values) {
return String.join("|", values);
}
@Override
public void setValue(String value) {
this.pattern = Pattern.compile(value);
}
@Override
public String getValue() {
return this.pattern.toString();
}
}
LayoutLogger Appender
Application DB
output
Console
info( )
debug( )
error( )
warn( )
File
public class Example {
private static final Logger logger = LogFactory.getLogger(getClass());
public Integer calculate(Integer x, Integer y) {
try {
logger.info(“calculate {‘x’:’{}’,‘y’:’{}’}”, x, y);
//
if (logger.isDebug()) {
//
logger.debug(“calculate {‘base’:’{}’,’seed’:’{}’”, base, seed);
}
} catch (Exception ex) {
logger.error(“Failed to calculate. {‘x’:’{}’,‘y’:’{}’}”, x, y, ex);
}
logger.info(“Success calculate {‘x’:’{}’,’y’:’{}’,’return’:’{}’}“, x, y, z);
return z;
}
}
※ Logback PatternLayout
PatternLayout Conversion Word
%C{30} , %class{48}
%M , %method
%F , %file
%L , %line
JFR shouldCommit( )
private static void recordEvent(SSLSessionImpl session) {
TLSHandshakeEvent event = new TLSHandshakeEvent();
if (event.shouldCommit()) {
int peerCertificateId = 0;
try {
// use hash code for Id
peerCertificateId = session.getCertificateChain()[0].hashCode();
} catch (SSLPeerUnverifiedException e) {
// not verified msg
}
event.peerHost = session.getPeerHost();
event.peerPort = session.getPeerPort();
event.cipherSuite = session.getCipherSuite();
event.protocolVersion = session.getProtocol();
event.certificateId = peerCertificateId;
event.commit();
}
}
if (event.isEnabled()) {
Enabled @SettingDefinition
JFR Event
public static void setProperty(String key, String datum) {
check("setProperty." + key);
props.put(key, datum);
invalidateSMCache(key); /* See below. */
SecurityPropertyModificationEvent spe = new SecurityPropertyModificationEvent();
// following is a no-op if event is disabled
spe.key = key;
spe.value = datum;
spe.commit();
if (EventHelper.isLoggingSecurity()) {
EventHelper.logSecurityPropertyEvent(key, datum);
}
}
/src/java.base/share/classes/java/security/Security.java
JDK Flight Recorder
0 1 400 4 154 000 1 800
JFR disabled JFR enabled,
stackdepth=1
log4j OFF log4j INFO j.u.logging OFF j.u.logging INFO Redirected
System.out
NANOS/OPERATION
JMC, 8 THREADS
Logging Benchmark
120 000 00043 000 000
Jfokus Developer Conference 2018 Mission Possible -Near Zero overhead profiling
java.util.logging System.outJDK Flight Recorder Apache Log4j
ON
OFF
ON
OFF
ON
OFF
JFR
public static void setProperty(String key, String datum) {
check("setProperty." + key);
props.put(key, datum);
invalidateSMCache(key); /* See below. */
SecurityPropertyModificationEvent spe = new SecurityPropertyModificationEvent();
// following is a no-op if event is disabled
spe.key = key;
spe.value = datum;
spe.commit();
if (EventHelper.isLoggingSecurity()) {
EventHelper.logSecurityPropertyEvent(key, datum);
}
}
/src/java.base/share/classes/java/security/Security.java
@Enabled(false) Event
!?
!?
jdk.jfr
Event
Event
jdk.jfr.events
SecurityPropertyModificationEvent
AbstractJDKEvent
jdk.internal.event
Event
jdk.jfr
java.base
example.jfr
MyEvent
my.module
“ ” Event
@Enabled(true)
@StackTrace(true)
@Registered(true)
public abstract class Event extends jdk.internal.event.Event {
protected Event() {
}
final public void begin() {
}
final public void end() {
}
final public void commit() {
}
final public boolean shouldCommit() {
return false;
}
....
/src/jdk.jfr/share/classes/jdk/jfr/Event.java
public static void setProperty(String key, String datum) {
check("setProperty." + key);
props.put(key, datum);
invalidateSMCache(key); /* See below. */
SecurityPropertyModificationEvent spe = new SecurityPropertyModificationEvent();
// following is a no-op if event is disabled
spe.key = key;
spe.value = datum;
spe.commit();
if (EventHelper.isLoggingSecurity()) {
EventHelper.logSecurityPropertyEvent(key, datum);
}
}
@Enabled(false) Event
JIT Compiler 

Dead Code Elimination
spe.commit();
/src/java.base/share/classes/java/security/Security.java
Public class Example {
static Event event;
public static void main(String[] args) {
event = new Event();
event.key = key;
event.value = datum;
event.commit();
}
JIT Compiler EA (Escape Analysis)
Public class Example {
public static void main(String[] args) {
Event event = new Event();
record(event);
}
public static record(Event event) {
event.key = key;
event.value = datum;
event.commit();
}
GlobalEscape
ArgEscape
Public class Example {
public static void main(String[] args) {
Event event = new Event();
event.key = key;
event.value = datum;
event.commit();
}
NoEscape
JIT Compiler 

Scalar Replacement
public static void setProperty(String key, String datum) {
check("setProperty." + key);
props.put(key, datum);
invalidateSMCache(key); /* See below. */
SecurityPropertyModificationEvent spe = new SecurityPropertyModificationEvent();
// following is a no-op if event is disabled
spe.key = key;
spe.value = datum;
spe.commit();
if (EventHelper.isLoggingSecurity()) {
EventHelper.logSecurityPropertyEvent(key, datum);
}
}
/src/java.base/share/classes/java/security/Security.java
@Enabled(false) Event
- Escape Analysis -
GlobalEscape ArgEscape NoEscape
public static void setProperty(String key, String datum) {
check("setProperty." + key);
props.put(key, datum);
invalidateSMCache(key); /* See below. */
SecurityPropertyModificationEvent spe = new SecurityPropertyModificationEvent();
// following is a no-op if event is disabled
spe.key = key;
spe.value = datum;
spe.commit();
if (EventHelper.isLoggingSecurity()) {
EventHelper.logSecurityPropertyEvent(key, datum);
}
}
@Enabled(false) Event
Scalar Replacement
spe.key = key; ! String scalar_1 = key;
spe.value = datum; ! String scalar_2 = value;
/src/java.base/share/classes/java/security/Security.java
public static void setProperty(String key, String datum) {
check("setProperty." + key);
props.put(key, datum);
invalidateSMCache(key); /* See below. */
SecurityPropertyModificationEvent spe = new SecurityPropertyModificationEvent();
// following is a no-op if event is disabled
spe.key = key;
spe.value = datum;
spe.commit();
if (EventHelper.isLoggingSecurity()) {
EventHelper.logSecurityPropertyEvent(key, datum);
}
}
@Enabled(false) Event
spe.key = key; ! String scalar_1 = key;
spe.value = datum; ! String scalar_2 = value;
JIT Compiler 

Dead Code Elimination
/src/java.base/share/classes/java/security/Security.java
public static void setProperty(String key, String datum) {
check("setProperty." + key);
props.put(key, datum);
invalidateSMCache(key); /* See below. */
SecurityPropertyModificationEvent spe = new SecurityPropertyModificationEvent();
// following is a no-op if event is disabled
spe.key = key;
spe.value = datum;
spe.commit();
if (EventHelper.isLoggingSecurity()) {
EventHelper.logSecurityPropertyEvent(key, datum);
}
}
/src/java.base/share/classes/java/security/Security.java
@Enabled(false) Event
spe.key = key; ! String scalar_1 = key;
spe.value = datum; ! String scalar_2 = value;
‼
!!
0 1 400 4 154 000 1 800
JFR disabled JFR enabled,
stackdepth=1
log4j OFF log4j INFO j.u.logging OFF j.u.logging INFO Redirected
System.out
NANOS/OPERATION
JMC, 8 THREADS
Logging Benchmark
120 000 00043 000 000
Jfokus Developer Conference 2018 Mission Possible -Near Zero overhead profiling
java.util.logging System.outJDK Flight Recorder Apache Log4j
ON
OFF
ON
OFF
ON
OFF
JFR
@Enabled(true)
@StackTrace(true)
@Registered(true)
public abstract class Event extends jdk.internal.event.Event {
protected Event() {
}
final public void begin() {
}
final public void end() {
}
final public void commit() {
}
final public boolean shouldCommit() {
return false;
}
....
@Enabled(true) Event
Event “ ”
ASM : Bytecode Manipulation Library
final public void begin() {
startTime = EventHandler.timestamp();
}
final public void end() {
duration = EventHandler.duration(startTime);
}
final public void commit() {
if (!isEnable()) {
return;
}
if (startTime == 0) {
....
}
final public boolean shouldCommit() {
....
public static void setProperty(String key, String datum) {
check("setProperty." + key);
props.put(key, datum);
invalidateSMCache(key); /* See below. */
SecurityPropertyModificationEvent spe = new SecurityPropertyModificationEvent();
// following is a no-op if event is disabled
spe.key = key;
spe.value = datum;
spe.commit();
if (EventHelper.isLoggingSecurity()) {
EventHelper.logSecurityPropertyEvent(key, datum);
}
}
/src/java.base/share/classes/java/security/Security.java
@Enabled(true) Event
JDK Flight Recorder
JFR
JFR Event
JFR
JFR
JMC
JFR
JFR
JFR
JFR shouldCommit( )
JFR Event
JDK Flight Recorder
JDK Flight Recorder
1. Flight Recorder start
2. Flight Recorder stop
3. JDK Mission Control
JEP 349 : Event Streaming
https://openjdk.java.net/jeps/349
APPENDIX
OpenJDK JDK 12 - 8148188: Enhance the security libraries to record events
of interest (changeset 52621:f7309a1491d9)
http://hg.openjdk.java.net/jdk/jdk12/rev/f7309a1491d9
JEP 349: JFR Event Streaming
https://openjdk.java.net/jeps/349
JDK Flight Recorder
https://www.slideshare.net/tokumasu123/jdk-flight-recorder-126001298
HotSpot JIT - Java Magazine March April 2018
https://www.oracle.com/webfolder/technetwork/jp/javamagazine/
Java_MA18_JVMEscapeAnalysis.pdf
ASM
https://asm.ow2.io
ASM - Java Magazine July August 2018
https://www.oracle.com/webfolder/technetwork/jp/javamagazine/Java-JA18-
RealWorldASM.pdf
jdk.jfr.Event
https://github.com/openjdk/jdk/blob/master/src/jdk.jfr/share/classes/jdk/jfr/Event.java
jdk.jfr.internal.EventInstrumentation
https://github.com/openjdk/jdk/blob/master/src/jdk.jfr/share/classes/jdk/jfr/internal/
EventInstrumentation.java
jdk.jfr.internal.JVMUpcalls
https://github.com/openjdk/jdk/blob/master/src/jdk.jfr/share/classes/jdk/jfr/internal/
JVMUpcalls.java
jdk.jfr
https://docs.oracle.com/javase/jp/12/docs/api/jdk.jfr/jdk/jfr/package-summary.html
jdk.jfr/jdk.jfr.SettingDefinition
https://docs.oracle.com/javase/jp/12/docs/api/jdk.jfr/jdk/jfr/SettingDefinition.html
jdk.jfr/jdk.jfr.SettingContorl
https://docs.oracle.com/javase/jp/12/docs/api/jdk.jfr/jdk/jfr/SettingControl.html
Logback Documentation Chapter 4: Appenders
https://logback.qos.ch/manual/appenders.html
PatternLayout Conversion Word - Logback Documentation Chapter 6:
Layouts
https://logback.qos.ch/manual/layouts.html#conversionWord
Logback Documentation Chapter 7: Filters
https://logback.qos.ch/manual/filters.html
- JDK Flight Recorder -
ログ出力を改めて考える - JDK Flight Recorder の活用

More Related Content

What's hot

Jdk 7 4-forkjoin
Jdk 7 4-forkjoinJdk 7 4-forkjoin
Jdk 7 4-forkjoinknight1128
 
Linux seccomp(2) vs OpenBSD pledge(2)
Linux seccomp(2) vs OpenBSD pledge(2)Linux seccomp(2) vs OpenBSD pledge(2)
Linux seccomp(2) vs OpenBSD pledge(2)Giovanni Bechis
 
Jersey framework
Jersey frameworkJersey framework
Jersey frameworkknight1128
 
How to cook lettuce @Java casual
How to cook lettuce @Java casualHow to cook lettuce @Java casual
How to cook lettuce @Java casualGo Hagiwara
 
How and Why Prometheus' New Storage Engine Pushes the Limits of Time Series D...
How and Why Prometheus' New Storage Engine Pushes the Limits of Time Series D...How and Why Prometheus' New Storage Engine Pushes the Limits of Time Series D...
How and Why Prometheus' New Storage Engine Pushes the Limits of Time Series D...Docker, Inc.
 
GroovyServ - Technical Part
GroovyServ - Technical PartGroovyServ - Technical Part
GroovyServ - Technical PartYasuharu Nakano
 
OSGi and Eclipse RCP
OSGi and Eclipse RCPOSGi and Eclipse RCP
OSGi and Eclipse RCPEric Jain
 
Kernel Recipes 2015: Introduction to Kernel Power Management
Kernel Recipes 2015: Introduction to Kernel Power ManagementKernel Recipes 2015: Introduction to Kernel Power Management
Kernel Recipes 2015: Introduction to Kernel Power ManagementAnne Nicolas
 
Проведение криминалистической экспертизы и анализа руткит-программ на примере...
Проведение криминалистической экспертизы и анализа руткит-программ на примере...Проведение криминалистической экспертизы и анализа руткит-программ на примере...
Проведение криминалистической экспертизы и анализа руткит-программ на примере...Alex Matrosov
 
Varnish presentation for the Symfony Zaragoza user group
Varnish presentation for the Symfony Zaragoza user groupVarnish presentation for the Symfony Zaragoza user group
Varnish presentation for the Symfony Zaragoza user groupJorge Nerín
 
Advanced administration and problem determination
Advanced administration and problem determinationAdvanced administration and problem determination
Advanced administration and problem determinationsolarisyougood
 
Counter Wars (JEEConf 2016)
Counter Wars (JEEConf 2016)Counter Wars (JEEConf 2016)
Counter Wars (JEEConf 2016)Alexey Fyodorov
 
From Zero To Production (NixOS, Erlang) @ Erlang Factory SF 2016
From Zero To Production (NixOS, Erlang) @ Erlang Factory SF 2016From Zero To Production (NixOS, Erlang) @ Erlang Factory SF 2016
From Zero To Production (NixOS, Erlang) @ Erlang Factory SF 2016Susan Potter
 
Deterministic simulation testing
Deterministic simulation testingDeterministic simulation testing
Deterministic simulation testingFoundationDB
 
Csw2016 gawlik bypassing_differentdefenseschemes
Csw2016 gawlik bypassing_differentdefenseschemesCsw2016 gawlik bypassing_differentdefenseschemes
Csw2016 gawlik bypassing_differentdefenseschemesCanSecWest
 

What's hot (20)

Pledge in OpenBSD
Pledge in OpenBSDPledge in OpenBSD
Pledge in OpenBSD
 
Jdk 7 4-forkjoin
Jdk 7 4-forkjoinJdk 7 4-forkjoin
Jdk 7 4-forkjoin
 
Linux seccomp(2) vs OpenBSD pledge(2)
Linux seccomp(2) vs OpenBSD pledge(2)Linux seccomp(2) vs OpenBSD pledge(2)
Linux seccomp(2) vs OpenBSD pledge(2)
 
Jersey framework
Jersey frameworkJersey framework
Jersey framework
 
How to cook lettuce @Java casual
How to cook lettuce @Java casualHow to cook lettuce @Java casual
How to cook lettuce @Java casual
 
How and Why Prometheus' New Storage Engine Pushes the Limits of Time Series D...
How and Why Prometheus' New Storage Engine Pushes the Limits of Time Series D...How and Why Prometheus' New Storage Engine Pushes the Limits of Time Series D...
How and Why Prometheus' New Storage Engine Pushes the Limits of Time Series D...
 
GroovyServ - Technical Part
GroovyServ - Technical PartGroovyServ - Technical Part
GroovyServ - Technical Part
 
OSGi and Eclipse RCP
OSGi and Eclipse RCPOSGi and Eclipse RCP
OSGi and Eclipse RCP
 
Apache ZooKeeper
Apache ZooKeeperApache ZooKeeper
Apache ZooKeeper
 
Kernel Recipes 2015: Introduction to Kernel Power Management
Kernel Recipes 2015: Introduction to Kernel Power ManagementKernel Recipes 2015: Introduction to Kernel Power Management
Kernel Recipes 2015: Introduction to Kernel Power Management
 
Проведение криминалистической экспертизы и анализа руткит-программ на примере...
Проведение криминалистической экспертизы и анализа руткит-программ на примере...Проведение криминалистической экспертизы и анализа руткит-программ на примере...
Проведение криминалистической экспертизы и анализа руткит-программ на примере...
 
Varnish presentation for the Symfony Zaragoza user group
Varnish presentation for the Symfony Zaragoza user groupVarnish presentation for the Symfony Zaragoza user group
Varnish presentation for the Symfony Zaragoza user group
 
Ak13 pam
Ak13 pamAk13 pam
Ak13 pam
 
Testing with Node.js
Testing with Node.jsTesting with Node.js
Testing with Node.js
 
Advanced administration and problem determination
Advanced administration and problem determinationAdvanced administration and problem determination
Advanced administration and problem determination
 
Counter Wars (JEEConf 2016)
Counter Wars (JEEConf 2016)Counter Wars (JEEConf 2016)
Counter Wars (JEEConf 2016)
 
From Zero To Production (NixOS, Erlang) @ Erlang Factory SF 2016
From Zero To Production (NixOS, Erlang) @ Erlang Factory SF 2016From Zero To Production (NixOS, Erlang) @ Erlang Factory SF 2016
From Zero To Production (NixOS, Erlang) @ Erlang Factory SF 2016
 
Deterministic simulation testing
Deterministic simulation testingDeterministic simulation testing
Deterministic simulation testing
 
Csw2016 gawlik bypassing_differentdefenseschemes
Csw2016 gawlik bypassing_differentdefenseschemesCsw2016 gawlik bypassing_differentdefenseschemes
Csw2016 gawlik bypassing_differentdefenseschemes
 
Request process
Request processRequest process
Request process
 

Similar to ログ出力を改めて考える - JDK Flight Recorder の活用

Silicon Valley JUG: JVM Mechanics
Silicon Valley JUG: JVM MechanicsSilicon Valley JUG: JVM Mechanics
Silicon Valley JUG: JVM MechanicsAzul Systems, Inc.
 
Monitoring with Syslog and EventMachine (RailswayConf 2012)
Monitoring  with  Syslog and EventMachine (RailswayConf 2012)Monitoring  with  Syslog and EventMachine (RailswayConf 2012)
Monitoring with Syslog and EventMachine (RailswayConf 2012)Wooga
 
JMC/JFR: Kotlin spezial
JMC/JFR: Kotlin spezialJMC/JFR: Kotlin spezial
JMC/JFR: Kotlin spezialMiro Wengner
 
REST made simple with Java
REST made simple with JavaREST made simple with Java
REST made simple with Javaelliando dias
 
Taking Jenkins Pipeline to the Extreme
Taking Jenkins Pipeline to the ExtremeTaking Jenkins Pipeline to the Extreme
Taking Jenkins Pipeline to the Extremeyinonavraham
 
JVM Mechanics: When Does the JVM JIT & Deoptimize?
JVM Mechanics: When Does the JVM JIT & Deoptimize?JVM Mechanics: When Does the JVM JIT & Deoptimize?
JVM Mechanics: When Does the JVM JIT & Deoptimize?Doug Hawkins
 
DevDays: Profiling With Java Flight Recorder
DevDays: Profiling With Java Flight RecorderDevDays: Profiling With Java Flight Recorder
DevDays: Profiling With Java Flight RecorderMiro Wengner
 
ASML_FlightRecorderMeetsJava.pdf
ASML_FlightRecorderMeetsJava.pdfASML_FlightRecorderMeetsJava.pdf
ASML_FlightRecorderMeetsJava.pdfMiro Wengner
 
Hack an ASP .NET website? Hard, but possible!
Hack an ASP .NET website? Hard, but possible! Hack an ASP .NET website? Hard, but possible!
Hack an ASP .NET website? Hard, but possible! Vladimir Kochetkov
 
GateIn Frameworks
GateIn FrameworksGateIn Frameworks
GateIn Frameworksjviet
 
DWR, Hibernate and Dojo.E - A Tutorial
DWR, Hibernate and Dojo.E - A TutorialDWR, Hibernate and Dojo.E - A Tutorial
DWR, Hibernate and Dojo.E - A Tutorialjbarciauskas
 
Android 4.2 Internals - Bluetooth and Network
Android 4.2 Internals - Bluetooth and NetworkAndroid 4.2 Internals - Bluetooth and Network
Android 4.2 Internals - Bluetooth and NetworkCaio Pereira
 
Speed up your Web applications with HTML5 WebSockets
Speed up your Web applications with HTML5 WebSocketsSpeed up your Web applications with HTML5 WebSockets
Speed up your Web applications with HTML5 WebSocketsYakov Fain
 
FwDays 2021: Metarhia Technology Stack for Node.js
FwDays 2021: Metarhia Technology Stack for Node.jsFwDays 2021: Metarhia Technology Stack for Node.js
FwDays 2021: Metarhia Technology Stack for Node.jsTimur Shemsedinov
 
Azure Durable Functions (2019-04-27)
Azure Durable Functions (2019-04-27)Azure Durable Functions (2019-04-27)
Azure Durable Functions (2019-04-27)Paco de la Cruz
 
Bang-Bang, you have been hacked - Yonatan Levin, KolGene
Bang-Bang, you have been hacked - Yonatan Levin, KolGeneBang-Bang, you have been hacked - Yonatan Levin, KolGene
Bang-Bang, you have been hacked - Yonatan Levin, KolGeneDroidConTLV
 
Architecting Alive Apps
Architecting Alive AppsArchitecting Alive Apps
Architecting Alive AppsJorge Ortiz
 
Resiliency & Security_Ballerina Day CMB 2018
Resiliency & Security_Ballerina Day CMB 2018  Resiliency & Security_Ballerina Day CMB 2018
Resiliency & Security_Ballerina Day CMB 2018 Ballerina
 
Rapid java backend and api development for mobile devices
Rapid java backend and api development for mobile devicesRapid java backend and api development for mobile devices
Rapid java backend and api development for mobile devicesciklum_ods
 

Similar to ログ出力を改めて考える - JDK Flight Recorder の活用 (20)

Silicon Valley JUG: JVM Mechanics
Silicon Valley JUG: JVM MechanicsSilicon Valley JUG: JVM Mechanics
Silicon Valley JUG: JVM Mechanics
 
Monitoring with Syslog and EventMachine (RailswayConf 2012)
Monitoring  with  Syslog and EventMachine (RailswayConf 2012)Monitoring  with  Syslog and EventMachine (RailswayConf 2012)
Monitoring with Syslog and EventMachine (RailswayConf 2012)
 
JMC/JFR: Kotlin spezial
JMC/JFR: Kotlin spezialJMC/JFR: Kotlin spezial
JMC/JFR: Kotlin spezial
 
REST made simple with Java
REST made simple with JavaREST made simple with Java
REST made simple with Java
 
Taking Jenkins Pipeline to the Extreme
Taking Jenkins Pipeline to the ExtremeTaking Jenkins Pipeline to the Extreme
Taking Jenkins Pipeline to the Extreme
 
JVM Mechanics: When Does the JVM JIT & Deoptimize?
JVM Mechanics: When Does the JVM JIT & Deoptimize?JVM Mechanics: When Does the JVM JIT & Deoptimize?
JVM Mechanics: When Does the JVM JIT & Deoptimize?
 
DevDays: Profiling With Java Flight Recorder
DevDays: Profiling With Java Flight RecorderDevDays: Profiling With Java Flight Recorder
DevDays: Profiling With Java Flight Recorder
 
ASML_FlightRecorderMeetsJava.pdf
ASML_FlightRecorderMeetsJava.pdfASML_FlightRecorderMeetsJava.pdf
ASML_FlightRecorderMeetsJava.pdf
 
Hack an ASP .NET website? Hard, but possible!
Hack an ASP .NET website? Hard, but possible! Hack an ASP .NET website? Hard, but possible!
Hack an ASP .NET website? Hard, but possible!
 
GateIn Frameworks
GateIn FrameworksGateIn Frameworks
GateIn Frameworks
 
DWR, Hibernate and Dojo.E - A Tutorial
DWR, Hibernate and Dojo.E - A TutorialDWR, Hibernate and Dojo.E - A Tutorial
DWR, Hibernate and Dojo.E - A Tutorial
 
Android 4.2 Internals - Bluetooth and Network
Android 4.2 Internals - Bluetooth and NetworkAndroid 4.2 Internals - Bluetooth and Network
Android 4.2 Internals - Bluetooth and Network
 
Learning Dtrace
Learning DtraceLearning Dtrace
Learning Dtrace
 
Speed up your Web applications with HTML5 WebSockets
Speed up your Web applications with HTML5 WebSocketsSpeed up your Web applications with HTML5 WebSockets
Speed up your Web applications with HTML5 WebSockets
 
FwDays 2021: Metarhia Technology Stack for Node.js
FwDays 2021: Metarhia Technology Stack for Node.jsFwDays 2021: Metarhia Technology Stack for Node.js
FwDays 2021: Metarhia Technology Stack for Node.js
 
Azure Durable Functions (2019-04-27)
Azure Durable Functions (2019-04-27)Azure Durable Functions (2019-04-27)
Azure Durable Functions (2019-04-27)
 
Bang-Bang, you have been hacked - Yonatan Levin, KolGene
Bang-Bang, you have been hacked - Yonatan Levin, KolGeneBang-Bang, you have been hacked - Yonatan Levin, KolGene
Bang-Bang, you have been hacked - Yonatan Levin, KolGene
 
Architecting Alive Apps
Architecting Alive AppsArchitecting Alive Apps
Architecting Alive Apps
 
Resiliency & Security_Ballerina Day CMB 2018
Resiliency & Security_Ballerina Day CMB 2018  Resiliency & Security_Ballerina Day CMB 2018
Resiliency & Security_Ballerina Day CMB 2018
 
Rapid java backend and api development for mobile devices
Rapid java backend and api development for mobile devicesRapid java backend and api development for mobile devices
Rapid java backend and api development for mobile devices
 

Recently uploaded

How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
Clustering techniques data mining book ....
Clustering techniques data mining book ....Clustering techniques data mining book ....
Clustering techniques data mining book ....ShaimaaMohamedGalal
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfCionsystems
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 

Recently uploaded (20)

How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Clustering techniques data mining book ....
Clustering techniques data mining book ....Clustering techniques data mining book ....
Clustering techniques data mining book ....
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdf
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 

ログ出力を改めて考える - JDK Flight Recorder の活用

  • 1. - JDK Flight Recorder - 2019 6 27 Duke An Oracle blog about Oracle Enterprise Pack for Eclipse Java 8 Launch!
  • 2. Java Log4j Logback JDK11 JDK Flight Recorder JDK Flight Recorder
  • 3. 0 1 400 4 154 000 1 800 JFR disabled JFR enabled, stackdepth=1 log4j OFF log4j INFO j.u.logging OFF j.u.logging INFO Redirected System.out NANOS/OPERATION JMC, 8 THREADS Logging Benchmark 120 000 00043 000 000 JFR Jfokus Developer Conference 2018 Mission Possible -Near Zero overhead profiling java.util.logging System.outJDK Flight Recorder Apache Log4j ON OFF ON OFF ON OFF
  • 4.
  • 5. Logger Layout Appender Application DB output Console info( ) debug( ) error( ) warn( ) File
  • 6. Logger Layout Appender Application DB output Console info( ) debug( ) error( ) warn( ) File
  • 7. Logger Layout Appender Application DB output Console info( ) debug( ) error( ) warn( ) File
  • 8. Logger Layout Appender Application DB output Console info( ) debug( ) error( ) warn( ) File
  • 10. public class Example { private static final Logger logger = LogFactory.getLogger(getClass()); public Integer calculate(Integer x, Integer y) { try { logger.info(“calculate {‘x’:’{}’,‘y’:’{}’}”, x, y); // if (logger.isDebug()) { // logger.debug(“calculate {‘base’:’{}’,’seed’:’{}’”, base, seed); } } catch (Exception ex) { logger.error(“Failed to calculate. {‘x’:’{}’,‘y’:’{}’}”, x, y, ex); } logger.info(“Success calculate {‘x’:’{}’,’y’:’{}’,’return’:’{}’}“, x, y, z); return z; } }
  • 11. error( ) warn( ) info( ) debug( ) trace( ) ERROR WARN INFO DEBUG TRACE
  • 12. JFR public static void setProperty(String key, String datum) { check("setProperty." + key); props.put(key, datum); invalidateSMCache(key); /* See below. */ SecurityPropertyModificationEvent spe = new SecurityPropertyModificationEvent(); // following is a no-op if event is disabled spe.key = key; spe.value = datum; spe.commit(); if (EventHelper.isLoggingSecurity()) { EventHelper.logSecurityPropertyEvent(key, datum); } } /src/java.base/share/classes/java/security/Security.java Event ※ JFR JDK Flight Recorder
  • 13. JFR Event <setting name="threshold" control="socket-io-threshold">20 ms</setting> </event> <event name="jdk.SecurityPropertyModification"> <setting name="enabled">false</setting> <setting name="stackTrace">true</setting> </event> <event name="jdk.TLSHandshake"> <setting name="enabled">true</setting> <setting name="stackTrace">true</setting> </event> <event name="jdk.X509Validation"> <setting name="enabled">false</setting> <setting name="stackTrace">true</setting> </event> <event name="jdk.X509Certificate"> <setting name="enabled">true</setting> <setting name="stackTrace">true</setting> </event> <event name="jdk.JavaExceptionThrow"> <setting name="enabled" control="enable-exceptions">false</setting> /src/jdk.jfr/share/conf/jfr/default.jfc
  • 14. Layout Appender Application DB output Console File Logger info( ) debug( ) error( ) warn( )
  • 15. ID”yyyyyy” “xxx” ”80” ”TLS_DHE_DSS_WITH_AES_256_CBC_SHA256” TLS“1.3” TLS {“peer_host”:”xxx”, “peer_port”:80, “protocol_version”:”1.3”, “certificate_id”:”yyyyyy”, “cipher_suite”:”TLS_DHE_DSS_WITH_AES_256_CBC_SHA256”}
  • 16. JFR @Category({"Java Development Kit", "Security"}) @Label("TLS Handshake") @Name("jdk.TLSHandshake") @Description("Parameters used in TLS Handshake") public final class TLSHandshakeEvent extends AbstractJDKEvent { @Label("Peer Host") public String peerHost; @Label("Peer Port") public int peerPort; @Label("Protocol Version") public String protocolVersion; @Label("Cipher Suite") public String cipherSuite; @Label("Certificate Id") @Description("Peer Certificate Id") @CertificateId public long certificateId; } /src/jdk.jfr/share/classes/jdk/jfr/events/TLSHandshakeEvent.java
  • 18. %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 2019-06-27 16:32:18.549 [main] INFO example.Example - TLS {“peer_host”:”xxx”, “peer_port”:80, “protocol_version”:”1.3”, “certificate_id”:”yyyyyy”, “cipher_suite”:”TLS_DHE_DSS_WITH_AES_256_CBC_SHA256”} ※ Logback PatternLayout
  • 19. Logger LoggingEvent Logger LoggingEvent Layout Appender Application DB info( ) debug( ) new output level message throwable thread name Console error( ) warn( ) File
  • 20. JFR JFR Event Application new fields timestamp stack trace thread name Logger Layout Appender DB output Console info( ) debug( ) error( ) warn( ) File commit( ) field1 = xxxx;
  • 21. JMC※ JMC JDK Mission Control
  • 22. File Logger Layout Appender Application DB info( ) debug( ) output Console error( ) warn( )
  • 24. JFR Java API Events JavaVM / OS Events Repository (disk storage) Global Buffer -a -b Global Buffer Global Buffer Global Buffer Global Buffer Global Buffer Global Buffer Global Buffer When full, is copied into Thread Buffer Event Event Event Event When full,
 is copied into JFR File When triggered, is dumped into
  • 25. DBConsole File Layout Appender info( ) debug( ) error( ) warn( ) output Application Logger
  • 27. Settings Annotation EnabledSetting @Enabled ThreasholdSetting @Threshold PeriodSetting @Period StackTraceSetting @StackTrace Event#commit() JFR
  • 28. JFR Event Setting … 1. Event @SettingDefinition 2. SettingControl
  • 29. public class HTTPRequestEvent extends Event { @Label("Request URI") protected String uri; @Label("Servlet URI Filter") @SettingDefinition protected boolean uriFilter(RegExpControl regExp) { return regExp.matches(this.uri); } } @SettingDefinition SettingControl class ExampleServlet extends HTTPServlet { protected void doGet(HttpServletRequest req, HttpServletResponse resp) { HTTPRequestEvent event = new HTTPRequestEvent(); event.begin(); event.uri = req.getRequestURI(); ... event.end(); event.commit(); } ... } final class RegExpControl extends SettingControl { private Pattern pattern = Pattern.compile(“.*"); public boolean matches(String s) { return this.pattern.matcher(s).find(); } @Override public String combine(Set<String> values) { return String.join("|", values); } @Override public void setValue(String value) { this.pattern = Pattern.compile(value); } @Override public String getValue() { return this.pattern.toString(); } }
  • 31. public class Example { private static final Logger logger = LogFactory.getLogger(getClass()); public Integer calculate(Integer x, Integer y) { try { logger.info(“calculate {‘x’:’{}’,‘y’:’{}’}”, x, y); // if (logger.isDebug()) { // logger.debug(“calculate {‘base’:’{}’,’seed’:’{}’”, base, seed); } } catch (Exception ex) { logger.error(“Failed to calculate. {‘x’:’{}’,‘y’:’{}’}”, x, y, ex); } logger.info(“Success calculate {‘x’:’{}’,’y’:’{}’,’return’:’{}’}“, x, y, z); return z; } }
  • 32. ※ Logback PatternLayout PatternLayout Conversion Word %C{30} , %class{48} %M , %method %F , %file %L , %line
  • 33. JFR shouldCommit( ) private static void recordEvent(SSLSessionImpl session) { TLSHandshakeEvent event = new TLSHandshakeEvent(); if (event.shouldCommit()) { int peerCertificateId = 0; try { // use hash code for Id peerCertificateId = session.getCertificateChain()[0].hashCode(); } catch (SSLPeerUnverifiedException e) { // not verified msg } event.peerHost = session.getPeerHost(); event.peerPort = session.getPeerPort(); event.cipherSuite = session.getCipherSuite(); event.protocolVersion = session.getProtocol(); event.certificateId = peerCertificateId; event.commit(); } } if (event.isEnabled()) { Enabled @SettingDefinition
  • 34. JFR Event public static void setProperty(String key, String datum) { check("setProperty." + key); props.put(key, datum); invalidateSMCache(key); /* See below. */ SecurityPropertyModificationEvent spe = new SecurityPropertyModificationEvent(); // following is a no-op if event is disabled spe.key = key; spe.value = datum; spe.commit(); if (EventHelper.isLoggingSecurity()) { EventHelper.logSecurityPropertyEvent(key, datum); } } /src/java.base/share/classes/java/security/Security.java
  • 36. 0 1 400 4 154 000 1 800 JFR disabled JFR enabled, stackdepth=1 log4j OFF log4j INFO j.u.logging OFF j.u.logging INFO Redirected System.out NANOS/OPERATION JMC, 8 THREADS Logging Benchmark 120 000 00043 000 000 Jfokus Developer Conference 2018 Mission Possible -Near Zero overhead profiling java.util.logging System.outJDK Flight Recorder Apache Log4j ON OFF ON OFF ON OFF JFR
  • 37. public static void setProperty(String key, String datum) { check("setProperty." + key); props.put(key, datum); invalidateSMCache(key); /* See below. */ SecurityPropertyModificationEvent spe = new SecurityPropertyModificationEvent(); // following is a no-op if event is disabled spe.key = key; spe.value = datum; spe.commit(); if (EventHelper.isLoggingSecurity()) { EventHelper.logSecurityPropertyEvent(key, datum); } } /src/java.base/share/classes/java/security/Security.java @Enabled(false) Event !? !?
  • 39. “ ” Event @Enabled(true) @StackTrace(true) @Registered(true) public abstract class Event extends jdk.internal.event.Event { protected Event() { } final public void begin() { } final public void end() { } final public void commit() { } final public boolean shouldCommit() { return false; } .... /src/jdk.jfr/share/classes/jdk/jfr/Event.java
  • 40. public static void setProperty(String key, String datum) { check("setProperty." + key); props.put(key, datum); invalidateSMCache(key); /* See below. */ SecurityPropertyModificationEvent spe = new SecurityPropertyModificationEvent(); // following is a no-op if event is disabled spe.key = key; spe.value = datum; spe.commit(); if (EventHelper.isLoggingSecurity()) { EventHelper.logSecurityPropertyEvent(key, datum); } } @Enabled(false) Event JIT Compiler 
 Dead Code Elimination spe.commit(); /src/java.base/share/classes/java/security/Security.java
  • 41. Public class Example { static Event event; public static void main(String[] args) { event = new Event(); event.key = key; event.value = datum; event.commit(); } JIT Compiler EA (Escape Analysis) Public class Example { public static void main(String[] args) { Event event = new Event(); record(event); } public static record(Event event) { event.key = key; event.value = datum; event.commit(); } GlobalEscape ArgEscape Public class Example { public static void main(String[] args) { Event event = new Event(); event.key = key; event.value = datum; event.commit(); } NoEscape JIT Compiler 
 Scalar Replacement
  • 42. public static void setProperty(String key, String datum) { check("setProperty." + key); props.put(key, datum); invalidateSMCache(key); /* See below. */ SecurityPropertyModificationEvent spe = new SecurityPropertyModificationEvent(); // following is a no-op if event is disabled spe.key = key; spe.value = datum; spe.commit(); if (EventHelper.isLoggingSecurity()) { EventHelper.logSecurityPropertyEvent(key, datum); } } /src/java.base/share/classes/java/security/Security.java @Enabled(false) Event - Escape Analysis - GlobalEscape ArgEscape NoEscape
  • 43. public static void setProperty(String key, String datum) { check("setProperty." + key); props.put(key, datum); invalidateSMCache(key); /* See below. */ SecurityPropertyModificationEvent spe = new SecurityPropertyModificationEvent(); // following is a no-op if event is disabled spe.key = key; spe.value = datum; spe.commit(); if (EventHelper.isLoggingSecurity()) { EventHelper.logSecurityPropertyEvent(key, datum); } } @Enabled(false) Event Scalar Replacement spe.key = key; ! String scalar_1 = key; spe.value = datum; ! String scalar_2 = value; /src/java.base/share/classes/java/security/Security.java
  • 44. public static void setProperty(String key, String datum) { check("setProperty." + key); props.put(key, datum); invalidateSMCache(key); /* See below. */ SecurityPropertyModificationEvent spe = new SecurityPropertyModificationEvent(); // following is a no-op if event is disabled spe.key = key; spe.value = datum; spe.commit(); if (EventHelper.isLoggingSecurity()) { EventHelper.logSecurityPropertyEvent(key, datum); } } @Enabled(false) Event spe.key = key; ! String scalar_1 = key; spe.value = datum; ! String scalar_2 = value; JIT Compiler 
 Dead Code Elimination /src/java.base/share/classes/java/security/Security.java
  • 45. public static void setProperty(String key, String datum) { check("setProperty." + key); props.put(key, datum); invalidateSMCache(key); /* See below. */ SecurityPropertyModificationEvent spe = new SecurityPropertyModificationEvent(); // following is a no-op if event is disabled spe.key = key; spe.value = datum; spe.commit(); if (EventHelper.isLoggingSecurity()) { EventHelper.logSecurityPropertyEvent(key, datum); } } /src/java.base/share/classes/java/security/Security.java @Enabled(false) Event spe.key = key; ! String scalar_1 = key; spe.value = datum; ! String scalar_2 = value; ‼ !!
  • 46. 0 1 400 4 154 000 1 800 JFR disabled JFR enabled, stackdepth=1 log4j OFF log4j INFO j.u.logging OFF j.u.logging INFO Redirected System.out NANOS/OPERATION JMC, 8 THREADS Logging Benchmark 120 000 00043 000 000 Jfokus Developer Conference 2018 Mission Possible -Near Zero overhead profiling java.util.logging System.outJDK Flight Recorder Apache Log4j ON OFF ON OFF ON OFF JFR
  • 47. @Enabled(true) @StackTrace(true) @Registered(true) public abstract class Event extends jdk.internal.event.Event { protected Event() { } final public void begin() { } final public void end() { } final public void commit() { } final public boolean shouldCommit() { return false; } .... @Enabled(true) Event Event “ ” ASM : Bytecode Manipulation Library final public void begin() { startTime = EventHandler.timestamp(); } final public void end() { duration = EventHandler.duration(startTime); } final public void commit() { if (!isEnable()) { return; } if (startTime == 0) { .... } final public boolean shouldCommit() { ....
  • 48. public static void setProperty(String key, String datum) { check("setProperty." + key); props.put(key, datum); invalidateSMCache(key); /* See below. */ SecurityPropertyModificationEvent spe = new SecurityPropertyModificationEvent(); // following is a no-op if event is disabled spe.key = key; spe.value = datum; spe.commit(); if (EventHelper.isLoggingSecurity()) { EventHelper.logSecurityPropertyEvent(key, datum); } } /src/java.base/share/classes/java/security/Security.java @Enabled(true) Event
  • 49.
  • 50. JDK Flight Recorder JFR JFR Event JFR JFR JMC JFR JFR JFR JFR shouldCommit( ) JFR Event JDK Flight Recorder
  • 51. JDK Flight Recorder 1. Flight Recorder start 2. Flight Recorder stop 3. JDK Mission Control
  • 52. JEP 349 : Event Streaming https://openjdk.java.net/jeps/349
  • 54. OpenJDK JDK 12 - 8148188: Enhance the security libraries to record events of interest (changeset 52621:f7309a1491d9) http://hg.openjdk.java.net/jdk/jdk12/rev/f7309a1491d9 JEP 349: JFR Event Streaming https://openjdk.java.net/jeps/349 JDK Flight Recorder https://www.slideshare.net/tokumasu123/jdk-flight-recorder-126001298
  • 55. HotSpot JIT - Java Magazine March April 2018 https://www.oracle.com/webfolder/technetwork/jp/javamagazine/ Java_MA18_JVMEscapeAnalysis.pdf ASM https://asm.ow2.io ASM - Java Magazine July August 2018 https://www.oracle.com/webfolder/technetwork/jp/javamagazine/Java-JA18- RealWorldASM.pdf
  • 58. Logback Documentation Chapter 4: Appenders https://logback.qos.ch/manual/appenders.html PatternLayout Conversion Word - Logback Documentation Chapter 6: Layouts https://logback.qos.ch/manual/layouts.html#conversionWord Logback Documentation Chapter 7: Filters https://logback.qos.ch/manual/filters.html
  • 59. - JDK Flight Recorder -