SlideShare a Scribd company logo
HOW TO BUILD A
DEBUGGABLE
RUNTIME
IMPORTANT DISCLAIMERS
• THE INFORMATION CONTAINED IN THIS PRESENTATION IS PROVIDED FOR INFORMATIONAL PURPOSES ONLY.
• WHILST EFFORTS WERE MADE TO VERIFY THE COMPLETENESS AND ACCURACY OF THE INFORMATION CONTAINED IN THIS PRESENTATION, IT IS
PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED.
• ALL PERFORMANCE DATA INCLUDED IN THIS PRESENTATION HAVE BEEN GATHERED IN A CONTROLLED ENVIRONMENT. YOUR OWN TEST RESULTS
MAY VARY BASED ON HARDWARE, SOFTWARE OR INFRASTRUCTURE DIFFERENCES.
• ALL DATA INCLUDED IN THIS PRESENTATION ARE MEANT TO BE USED ONLY AS A GUIDE.
• IN ADDITION, THE INFORMATION CONTAINED IN THIS PRESENTATION IS BASED ON IBM’S CURRENT PRODUCT PLANS AND STRATEGY, WHICH ARE
SUBJECT TO CHANGE BY IBM, WITHOUT NOTICE.
• IBM AND ITS AFFILIATED COMPANIES SHALL NOT BE RESPONSIBLE FOR ANY DAMAGES ARISING OUT OF THE USE OF, OR OTHERWISE RELATED TO,
THIS PRESENTATION OR ANY OTHER DOCUMENTATION.
• NOTHING CONTAINED IN THIS PRESENTATION IS INTENDED TO, OR SHALL HAVE THE EFFECT OF:
• - CREATING ANY WARRANT OR REPRESENTATION FROM IBM, ITS AFFILIATED COMPANIES OR ITS OR THEIR SUPPLIERS AND/OR LICENSORS
INTRODUCTION
• TOBI AJILA – OPENJ9 DEVELOPER
• TOBI_AJILA@CA.IBM.COM
• BJØRN VÅRDAL – OPENJ9 DEVELOPER
• BJORNVAR@CA.IBM.COM
WHAT IS
DEBUGGING
?
Making sure all your assumptions
about a system are true
When you find something that
disproves your assumption, you’re
a step closer to finding the bug
APPROACHES TO DEBUGGING
Historical Data
Generate Historical Data
•Tracing code (printf, cout, etc.)
•Logs
Program State
Capture Program state
•Setting breakpoints
•Generating core dumps
Analysis
Perform analysis on
acquired data
•GDB to analyze core files
DEBUGGABLE RUNTIMES
Ability to capture
runtime and
language state
Built-In logging
mechanism
Simplify or
automate analysis
on captured data
AGENDA
• WHAT ARE TOOLS USED IN OPENJ9 TO MAKE DEBUGGING EASIER?
• HOW HAVE WE HAVE BUILT THESE TOOLS?
• WHAT PROBLEMS DO THESE TOOLS HELP YOU SOLVE?
ECLIPSE OMR
Reliable Shared Components for High Performance
Language Runtimes
http://www.eclipse.org/omr
https://github.com/eclipse/omr
https://developer.ibm.com/open/omr
Currently used in OpenJ9
http://www.eclipse.org/openj9/
https://github.com/eclipse/openj9
OMR
TRACE
Trace Engine that Logs Language and Runtime
events
Trace info can be captured for Runtime internals
(GC activity, JIT compilation, classloading) as well
as Language events (method entry/exit)
Used in Openj9 to debug the JVM and Java
applications
HOW DOES IT WORK?
• TRACEPOINTS ARE DEFINED IN A TRACE DEFINITION FILE
• TRACEPOINT TYPES FOR METHOD ENTRY & EXIT, EVENT, ASSERTION AND
EXCEPTION
• EACH TRACEPOINT TYPE HAS A UNIQUE FORMAT TO DISTINGUISH THEM
• TRACE ASSERTIONS TRIGGER SYSTEM DUMPS
• TRACEPOINTS ARE ASSOCIATED WITH A LEVEL SO THEIR INCLUSION CAN BE
TOGGLED AT RUNTIME
HOW DOES IT WORK CONT.
• TRACEPOINTS ARE STORED IN AN INTERNAL CIRCULAR BUFFER ON EACH
THREAD
• ONLY MOST RECENT MESSAGES ARE KEPT
• EACH TRACEPOINT IS TIMESTAMPED AND HAS A UNIQUE ID
• STORED IN BINARY FORMAT TO MINIMIZE FOOTPRINT
• A TRACEFORMAT TOOL IS USED TO CONVERT THE BINARY DATA TO HUMAN
READABLE FORMAT
TRACE EXAMPLE #1
Level 2 trace of Memory Manager printed to console
“-Xtrace:print={j9mm{level2}}”
TRACE EXAMPLE #2
Trace of all java methods in java/lang/Module printed to
the console
“-Xtrace:print=mt,methods={java/lang/Module.*()}”
TRACE OPTIONS
• OUTPUT
• DEFAULT MODE STORES TRACE OUPUT IN INTERNAL BUFFERS WHICH ARE ACCESSIBLE FROM CORE DUMBS OR
TRACE DUMPS (MORE LATER)
• SUPPORTS OUTPUT TO CONSOLE, FILES OR EXTERNAL LISTENERS VIA JVMTI
REGISTERTRACEPOINTSUBSCRIBER()
• QUANTITY
• MODIFIABLE BUFFER SIZE, MINIMAL AND MAXIMAL OUTPUT MODES
• COMPONENT
• ALL RUNTIME NATIVE LIBRARIES (INTERPRETER, GC, PORT, JIT, ETC.)
• JAVA METHODS, INPUT PARAMETERS AND RETURN VALUES
• CONTROL
• TRIGGERS FOR SLEEPTIME, SUSPEND, SUSPENDCOUNT (PER THREAD), RESUME, RESUMECOUNT (PER THREAD)
WHAT
PROBLEM
S CAN
YOU
SOLVE
WITH
THIS
Quick
Triaging
• Shows last events before Problem
occurred
Asynchronous
bugs
• Trace allows one to see the order in
which events occur
Bad
Parameters
• Trace lets you see what parameters
were passed in leading to the problem
XDUMP
• OPENJ9 OPTION TO EXTRACT STATE INFORMATION FROM THE JVM
• SYSTEM CORES (DEBUGGABLE ON GDB), HEAP DUMPS, JAVA CORES, SNAP TRACES,
STACKTRACES THREAD AND JIT DUMPS
• CAN BE TRIGGERED ON EVENTS
• VMSTART/VMSTOP, EXCEPTIONS, SIGNALS (GPF, SIGQUIT, SIGABORT), GC, CLASS
LOADS AND MORE
• SOME EVENTS CAN BE FILTERED FOR SPECIFIC CLASSES, EXCEPTION MESSAGES, EXIT
CODES
• CAN PERFORM ADDITIONAL REQUESTS
• COMPACT HEAP, ATTACH THREAD, PREEMPT THREADS, SUSPEND OTHER DUMPS AND
MORE
HOW DOES IT WORK?
• OPENJ9 HAS A HOOK MECHANISM BUILT ON OMR HOOK GEN
• EVENTS SUCH AS CLASSLOADING & UNLOADING, GC, STARTUP & SHUTDOWN,
EXCEPTIONS, THREADSTART, ETC. TRIGGER HOOKS FOR JVMTI AGENTS, JIT
BOOKKEEPING
• XDUMP AGENT LEVERAGES HOOK SYSTEM AND REGISTERS LISTENERS FOR
HOOKS DEPENDING ON THE CONFIGURATION
• WHEN HOOKS ARE TRIGGERED DUMP AGENT CHECKS IF EVENTDATA MATCHES
FILTERING REQUIREMENTS
• IE. DID THE THROWN EXCEPTION MATCH THE FILTER
HOW DOES IT WORK CONT.
• WHEN AN EVENT TRIGGERS A DUMP ALL THREADS ARE HALTED
• FOR SYSTEM DUMPS OMR PORTLIBRARY API IS USED TO PRODUCE A CORE
• JAVACORES AND HEAPDUMPS USE JVMTI HEAP ITERATORS AND CLASSTABLE
ITERATORS TO COLLECT NECESSARY INFORMATION
• FOR TRACE DUMPS INTERNAL TRACE BUFFERS ARE WRITTEN OUT
XDUMP EXAMPLE #1
Create a system dump when a NullPointerException is thrown in TestClass
“-Xdump:system:events=throw,filter=*NullPointerException#com/test/TestClass*”
XDUMP EXAMPLE #2
Create a heap dump when JVM is a user
signal
-Xdump:heap:events=user
XDUMP EXAMPLE #3
For full list of options
“-Xdump:help”
WHAT
PROBLEM
S CAN
YOU
SOLVE
WITH
THIS
Debugging
hangs
•Generating a sequence of dumps will
help identify whether progress is
being made or if the application is
deadlocked/livelocked or starved
Intermittent
Issues
•Generating a core when a certain
exception is thrown/caught
DDR INTERACTIVE + OMR DDRGEN
• Dynamic Dump Reader what allows users to inspect JVM system
Dumps and perform analysis
DDR Interactive
• Generates DDR resources (generates blob and code)
DDR gen
OMR DDRGEN
Compile
with
debug
symbols
ddrge
n
blob.dat
Load into
memory at
runtime
Scan
source
files for
build flags
./getMacros.sh .
libdwarf
DDR INTERACTIVE CLASS GENERATION
superset.ou
t
DDR
Interactive
(j9ddr.jar)
Generate Java
structure
classes
superset.ou
t
Generate Java
pointer
classes
DDR INTERACTIVE STARTUP
Generated
Java classes
DDR
Interactive
DDR blob
from core file
DDR
ClassLoad
er
Template
Field
offsets
Load
structure
classes
DDR OVERVIEW
Runtime
DDR
Interactive
DDR data
generator
DD
R
blo
b
Core
dumpDD
R
blo
b
Generated
code
DDR EXAMPLE #1
Inspect threads, print stack traces
DDR EXAMPLE #2
Print more detailed stack
DDR EXAMPLE #3
Dump a Java object
DDR EXAMPLE #4
DDR OPTIONS
GDB VS DDR
• DDR
• Has intimate knowledge about
the JVM internal structures
• Doesn’t require debug symbols
• Cross JVM version
• Cross platform
• GDB
• Requires intimate
knowledge about the
JVM internal structures
• Requires debug
symbols
• Source must match
• Platform specific
GDB VS DDR (JAVA STACKTRACE)
GDB
DDR
XCHECK
• COMMAND LINE OPTION THAT PERFORMS VERIFICATION CHECKS ON VARIOUS
JVM COMPONENTS
• GC (HEAP WALKABILITY)
• JNI (TRACE, WARNINGS AND ADVICE)
• MEMORY (ALLOCATION/DEALLOCATION)
HOW DOES IT WORK (GC CHECK)
• USES HOOK MECHANISM TO REGISTER LISTENERS FOR GC EVENTS
• GC CYCLE START & END, SCAVENGER BACKOUT, REMEMBERED SET OVERFLOW
• PERFORMS VERIFICATION CHECKS ON ALL ROOTS
• CHECKS JAVA STACK TO ENSURE O-SLOTS POINT TO THE HEAP
• VERIFIES REMEMBERED SET SLOT POINTS TO DIFFERENT GENERATION
• LOOKS FOR CLASS EYECATCHERS IN OBJECTS
• PERFORMS A HEAP WALK
XCHECK EXAMPLE #1
Performs object heap walk to verify heap is in walkable state
-Xcheck:gc:heap
HOW DOES IT WORK (JNI CHECK)
• REPLACE STANDARD JNI FUNCTION TABLE WITH WRAPPED VERSION
• WRAPPED CALLS STANDARD JNI FUNCTIONS BUT ADDS ADDITIONAL CHECKS
• CHECK VALIDITY OF ARGUMENTS (ENV POINTER, CLASS POINTER, ARG TYPES,
ARG VALUES)
• CHECKS IF EXCEPTIONS WHERE CHECKED BY USER
• TRACES ALL FUNCTION CALLS
XCHECK EXAMPLE #2
Print on JNI operations
-Xcheck:jni:warn
HOW DOES IT WORK (MEMORY CHECK)
• AT STARTUP A NEW PORT LIBRARY IS ALLOCATED
• INSTALLS NEW MEMORY ALLOCATORS & DEALLOCATORS
• ALLOCATORS CAN ADD GUARD PAGES BEFORE AND/OR AFTER REQUESTED
MEMORY REGION
• DEALLOCATORS WRITE OVER FREED MEMORY
• GUARD PAGES CAN ALSO BE MEMORY PROTECTED
• KEEPS TRACK OF ALL ALLOCATIONS IN A LIST CHECKS AT SHUTDOWN FOR ALL
UNFREED BLOCKS
WHAT PROBLEMS CAN YOU SOLVE WITH THIS
• HELPS DETERMINE WHETHER A PROBLEM IS A JVM PROBLEM OR A USER PROBLEM
• HELPS DETERMINE WHICH COMPONENT THE PROBLEM WAS CAUSED IN
• CAN AUTOMATE THE PROCESS OF FINDING ISSUES IN VERY COMPLEX CASES
• DID THE PROBLEM OCCUR IN MID SCAVENGE?
• IS THIS REALLY AN OBJECT REFERENCE?
• IS THE PROBLEM CAUSED BY A BUFFER OVERFLOW?
• IS IT REFERENCING FREED MEMORY?
CONCLUSION
• JVMS ARE HARD! MORE TOOLS YOU HAVE THE MORE EFFICIENT YOU CAN BE IN SOLVING
PROBLEMS
• VALIDATING INDIVIDUAL COMPONENTS HELPS NARROW DOWN THE PROBLEM
• IT HELPS IF YOU BUILD DEBUGGING TOOLS INTO YOUR SYSTEM
• SOME DEBUGGING FEATURES CAN LEVERAGE EXISTING FEATURES
• AUTOMATING CHECKS CAN MAKE VERY HARD BUGS EASY TO SPOT
TAKEAWAY
• WHAT TOOLS CAN YOU BUILD INTO YOUR APPLICATION TO
MAKE DEBUGGING EASIER?
QUESTION
S

More Related Content

PPTX
Using the big guns: Advanced OS performance tools for troubleshooting databas...
PDF
OSMC 2008 | Monitoring Tools Shootout by Tom De Cooman
PDF
GOoDA tutorial
PDF
Training Slides: 252 - Monitoring & Troubleshooting
PPTX
Introduction to .NET Performance Measurement
PDF
Ranger BSides-FINAL
PPTX
[CB16] COFI break – Breaking exploits with Processor trace and Practical cont...
PPTX
Practical Windows Kernel Exploitation
Using the big guns: Advanced OS performance tools for troubleshooting databas...
OSMC 2008 | Monitoring Tools Shootout by Tom De Cooman
GOoDA tutorial
Training Slides: 252 - Monitoring & Troubleshooting
Introduction to .NET Performance Measurement
Ranger BSides-FINAL
[CB16] COFI break – Breaking exploits with Processor trace and Practical cont...
Practical Windows Kernel Exploitation

Similar to How to build a debuggle runtime (20)

PDF
Java Performance Tuning
PPTX
Performance tuning Grails Applications GR8Conf US 2014
PPT
代码大全(内训)
PDF
Monitoring your WebObjects apps
PPTX
FOSDEM 2017 - Open J9 The Next Free Java VM
PPTX
Hadoop cluster performance profiler
PDF
DEF CON 27 - CHRISTOPHER ROBERTS - firmware slap
PDF
Web Sphere Problem Determination Ext
PPTX
Security Vulnerabilities in Mobile Applications (Kristaps Felzenbergs)
PDF
Oracle WebLogic Diagnostics & Perfomance tuning
PDF
Performance tuning Grails applications
PDF
Teach your application eloquence. Logs, metrics, traces - Dmytro Shapovalov (...
PPTX
Glass fish performance tuning tips from the field
PDF
Performance tuning Grails applications
PDF
Getting started with RISC-V verification what's next after compliance testing
PDF
PAC 2019 virtual Christoph NEUMÜLLER
PDF
Debugging Java from Dumps
PPTX
Stop Feeding IBM i Performance Hogs - Robot
PDF
Create an architecture for web test automation
PDF
Basics of JVM Tuning
Java Performance Tuning
Performance tuning Grails Applications GR8Conf US 2014
代码大全(内训)
Monitoring your WebObjects apps
FOSDEM 2017 - Open J9 The Next Free Java VM
Hadoop cluster performance profiler
DEF CON 27 - CHRISTOPHER ROBERTS - firmware slap
Web Sphere Problem Determination Ext
Security Vulnerabilities in Mobile Applications (Kristaps Felzenbergs)
Oracle WebLogic Diagnostics & Perfomance tuning
Performance tuning Grails applications
Teach your application eloquence. Logs, metrics, traces - Dmytro Shapovalov (...
Glass fish performance tuning tips from the field
Performance tuning Grails applications
Getting started with RISC-V verification what's next after compliance testing
PAC 2019 virtual Christoph NEUMÜLLER
Debugging Java from Dumps
Stop Feeding IBM i Performance Hogs - Robot
Create an architecture for web test automation
Basics of JVM Tuning
Ad

Recently uploaded (20)

PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PPTX
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PPTX
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
PDF
Well-logging-methods_new................
PPT
CRASH COURSE IN ALTERNATIVE PLUMBING CLASS
PPTX
UNIT 4 Total Quality Management .pptx
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PPTX
CH1 Production IntroductoryConcepts.pptx
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PDF
Automation-in-Manufacturing-Chapter-Introduction.pdf
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PPTX
Sustainable Sites - Green Building Construction
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PPTX
Geodesy 1.pptx...............................................
PDF
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
Embodied AI: Ushering in the Next Era of Intelligent Systems
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
Well-logging-methods_new................
CRASH COURSE IN ALTERNATIVE PLUMBING CLASS
UNIT 4 Total Quality Management .pptx
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
CH1 Production IntroductoryConcepts.pptx
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
Automation-in-Manufacturing-Chapter-Introduction.pdf
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
Sustainable Sites - Green Building Construction
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
Geodesy 1.pptx...............................................
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
Ad

How to build a debuggle runtime

  • 1. HOW TO BUILD A DEBUGGABLE RUNTIME
  • 2. IMPORTANT DISCLAIMERS • THE INFORMATION CONTAINED IN THIS PRESENTATION IS PROVIDED FOR INFORMATIONAL PURPOSES ONLY. • WHILST EFFORTS WERE MADE TO VERIFY THE COMPLETENESS AND ACCURACY OF THE INFORMATION CONTAINED IN THIS PRESENTATION, IT IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED. • ALL PERFORMANCE DATA INCLUDED IN THIS PRESENTATION HAVE BEEN GATHERED IN A CONTROLLED ENVIRONMENT. YOUR OWN TEST RESULTS MAY VARY BASED ON HARDWARE, SOFTWARE OR INFRASTRUCTURE DIFFERENCES. • ALL DATA INCLUDED IN THIS PRESENTATION ARE MEANT TO BE USED ONLY AS A GUIDE. • IN ADDITION, THE INFORMATION CONTAINED IN THIS PRESENTATION IS BASED ON IBM’S CURRENT PRODUCT PLANS AND STRATEGY, WHICH ARE SUBJECT TO CHANGE BY IBM, WITHOUT NOTICE. • IBM AND ITS AFFILIATED COMPANIES SHALL NOT BE RESPONSIBLE FOR ANY DAMAGES ARISING OUT OF THE USE OF, OR OTHERWISE RELATED TO, THIS PRESENTATION OR ANY OTHER DOCUMENTATION. • NOTHING CONTAINED IN THIS PRESENTATION IS INTENDED TO, OR SHALL HAVE THE EFFECT OF: • - CREATING ANY WARRANT OR REPRESENTATION FROM IBM, ITS AFFILIATED COMPANIES OR ITS OR THEIR SUPPLIERS AND/OR LICENSORS
  • 3. INTRODUCTION • TOBI AJILA – OPENJ9 DEVELOPER • TOBI_AJILA@CA.IBM.COM • BJØRN VÅRDAL – OPENJ9 DEVELOPER • BJORNVAR@CA.IBM.COM
  • 4. WHAT IS DEBUGGING ? Making sure all your assumptions about a system are true When you find something that disproves your assumption, you’re a step closer to finding the bug
  • 5. APPROACHES TO DEBUGGING Historical Data Generate Historical Data •Tracing code (printf, cout, etc.) •Logs Program State Capture Program state •Setting breakpoints •Generating core dumps Analysis Perform analysis on acquired data •GDB to analyze core files
  • 6. DEBUGGABLE RUNTIMES Ability to capture runtime and language state Built-In logging mechanism Simplify or automate analysis on captured data
  • 7. AGENDA • WHAT ARE TOOLS USED IN OPENJ9 TO MAKE DEBUGGING EASIER? • HOW HAVE WE HAVE BUILT THESE TOOLS? • WHAT PROBLEMS DO THESE TOOLS HELP YOU SOLVE?
  • 8. ECLIPSE OMR Reliable Shared Components for High Performance Language Runtimes http://www.eclipse.org/omr https://github.com/eclipse/omr https://developer.ibm.com/open/omr Currently used in OpenJ9 http://www.eclipse.org/openj9/ https://github.com/eclipse/openj9
  • 9. OMR TRACE Trace Engine that Logs Language and Runtime events Trace info can be captured for Runtime internals (GC activity, JIT compilation, classloading) as well as Language events (method entry/exit) Used in Openj9 to debug the JVM and Java applications
  • 10. HOW DOES IT WORK? • TRACEPOINTS ARE DEFINED IN A TRACE DEFINITION FILE • TRACEPOINT TYPES FOR METHOD ENTRY & EXIT, EVENT, ASSERTION AND EXCEPTION • EACH TRACEPOINT TYPE HAS A UNIQUE FORMAT TO DISTINGUISH THEM • TRACE ASSERTIONS TRIGGER SYSTEM DUMPS • TRACEPOINTS ARE ASSOCIATED WITH A LEVEL SO THEIR INCLUSION CAN BE TOGGLED AT RUNTIME
  • 11. HOW DOES IT WORK CONT. • TRACEPOINTS ARE STORED IN AN INTERNAL CIRCULAR BUFFER ON EACH THREAD • ONLY MOST RECENT MESSAGES ARE KEPT • EACH TRACEPOINT IS TIMESTAMPED AND HAS A UNIQUE ID • STORED IN BINARY FORMAT TO MINIMIZE FOOTPRINT • A TRACEFORMAT TOOL IS USED TO CONVERT THE BINARY DATA TO HUMAN READABLE FORMAT
  • 12. TRACE EXAMPLE #1 Level 2 trace of Memory Manager printed to console “-Xtrace:print={j9mm{level2}}”
  • 13. TRACE EXAMPLE #2 Trace of all java methods in java/lang/Module printed to the console “-Xtrace:print=mt,methods={java/lang/Module.*()}”
  • 14. TRACE OPTIONS • OUTPUT • DEFAULT MODE STORES TRACE OUPUT IN INTERNAL BUFFERS WHICH ARE ACCESSIBLE FROM CORE DUMBS OR TRACE DUMPS (MORE LATER) • SUPPORTS OUTPUT TO CONSOLE, FILES OR EXTERNAL LISTENERS VIA JVMTI REGISTERTRACEPOINTSUBSCRIBER() • QUANTITY • MODIFIABLE BUFFER SIZE, MINIMAL AND MAXIMAL OUTPUT MODES • COMPONENT • ALL RUNTIME NATIVE LIBRARIES (INTERPRETER, GC, PORT, JIT, ETC.) • JAVA METHODS, INPUT PARAMETERS AND RETURN VALUES • CONTROL • TRIGGERS FOR SLEEPTIME, SUSPEND, SUSPENDCOUNT (PER THREAD), RESUME, RESUMECOUNT (PER THREAD)
  • 15. WHAT PROBLEM S CAN YOU SOLVE WITH THIS Quick Triaging • Shows last events before Problem occurred Asynchronous bugs • Trace allows one to see the order in which events occur Bad Parameters • Trace lets you see what parameters were passed in leading to the problem
  • 16. XDUMP • OPENJ9 OPTION TO EXTRACT STATE INFORMATION FROM THE JVM • SYSTEM CORES (DEBUGGABLE ON GDB), HEAP DUMPS, JAVA CORES, SNAP TRACES, STACKTRACES THREAD AND JIT DUMPS • CAN BE TRIGGERED ON EVENTS • VMSTART/VMSTOP, EXCEPTIONS, SIGNALS (GPF, SIGQUIT, SIGABORT), GC, CLASS LOADS AND MORE • SOME EVENTS CAN BE FILTERED FOR SPECIFIC CLASSES, EXCEPTION MESSAGES, EXIT CODES • CAN PERFORM ADDITIONAL REQUESTS • COMPACT HEAP, ATTACH THREAD, PREEMPT THREADS, SUSPEND OTHER DUMPS AND MORE
  • 17. HOW DOES IT WORK? • OPENJ9 HAS A HOOK MECHANISM BUILT ON OMR HOOK GEN • EVENTS SUCH AS CLASSLOADING & UNLOADING, GC, STARTUP & SHUTDOWN, EXCEPTIONS, THREADSTART, ETC. TRIGGER HOOKS FOR JVMTI AGENTS, JIT BOOKKEEPING • XDUMP AGENT LEVERAGES HOOK SYSTEM AND REGISTERS LISTENERS FOR HOOKS DEPENDING ON THE CONFIGURATION • WHEN HOOKS ARE TRIGGERED DUMP AGENT CHECKS IF EVENTDATA MATCHES FILTERING REQUIREMENTS • IE. DID THE THROWN EXCEPTION MATCH THE FILTER
  • 18. HOW DOES IT WORK CONT. • WHEN AN EVENT TRIGGERS A DUMP ALL THREADS ARE HALTED • FOR SYSTEM DUMPS OMR PORTLIBRARY API IS USED TO PRODUCE A CORE • JAVACORES AND HEAPDUMPS USE JVMTI HEAP ITERATORS AND CLASSTABLE ITERATORS TO COLLECT NECESSARY INFORMATION • FOR TRACE DUMPS INTERNAL TRACE BUFFERS ARE WRITTEN OUT
  • 19. XDUMP EXAMPLE #1 Create a system dump when a NullPointerException is thrown in TestClass “-Xdump:system:events=throw,filter=*NullPointerException#com/test/TestClass*”
  • 20. XDUMP EXAMPLE #2 Create a heap dump when JVM is a user signal -Xdump:heap:events=user
  • 21. XDUMP EXAMPLE #3 For full list of options “-Xdump:help”
  • 22. WHAT PROBLEM S CAN YOU SOLVE WITH THIS Debugging hangs •Generating a sequence of dumps will help identify whether progress is being made or if the application is deadlocked/livelocked or starved Intermittent Issues •Generating a core when a certain exception is thrown/caught
  • 23. DDR INTERACTIVE + OMR DDRGEN • Dynamic Dump Reader what allows users to inspect JVM system Dumps and perform analysis DDR Interactive • Generates DDR resources (generates blob and code) DDR gen
  • 24. OMR DDRGEN Compile with debug symbols ddrge n blob.dat Load into memory at runtime Scan source files for build flags ./getMacros.sh . libdwarf
  • 25. DDR INTERACTIVE CLASS GENERATION superset.ou t DDR Interactive (j9ddr.jar) Generate Java structure classes superset.ou t Generate Java pointer classes
  • 26. DDR INTERACTIVE STARTUP Generated Java classes DDR Interactive DDR blob from core file DDR ClassLoad er Template Field offsets Load structure classes
  • 28. DDR EXAMPLE #1 Inspect threads, print stack traces
  • 29. DDR EXAMPLE #2 Print more detailed stack
  • 30. DDR EXAMPLE #3 Dump a Java object
  • 33. GDB VS DDR • DDR • Has intimate knowledge about the JVM internal structures • Doesn’t require debug symbols • Cross JVM version • Cross platform • GDB • Requires intimate knowledge about the JVM internal structures • Requires debug symbols • Source must match • Platform specific
  • 34. GDB VS DDR (JAVA STACKTRACE) GDB DDR
  • 35. XCHECK • COMMAND LINE OPTION THAT PERFORMS VERIFICATION CHECKS ON VARIOUS JVM COMPONENTS • GC (HEAP WALKABILITY) • JNI (TRACE, WARNINGS AND ADVICE) • MEMORY (ALLOCATION/DEALLOCATION)
  • 36. HOW DOES IT WORK (GC CHECK) • USES HOOK MECHANISM TO REGISTER LISTENERS FOR GC EVENTS • GC CYCLE START & END, SCAVENGER BACKOUT, REMEMBERED SET OVERFLOW • PERFORMS VERIFICATION CHECKS ON ALL ROOTS • CHECKS JAVA STACK TO ENSURE O-SLOTS POINT TO THE HEAP • VERIFIES REMEMBERED SET SLOT POINTS TO DIFFERENT GENERATION • LOOKS FOR CLASS EYECATCHERS IN OBJECTS • PERFORMS A HEAP WALK
  • 37. XCHECK EXAMPLE #1 Performs object heap walk to verify heap is in walkable state -Xcheck:gc:heap
  • 38. HOW DOES IT WORK (JNI CHECK) • REPLACE STANDARD JNI FUNCTION TABLE WITH WRAPPED VERSION • WRAPPED CALLS STANDARD JNI FUNCTIONS BUT ADDS ADDITIONAL CHECKS • CHECK VALIDITY OF ARGUMENTS (ENV POINTER, CLASS POINTER, ARG TYPES, ARG VALUES) • CHECKS IF EXCEPTIONS WHERE CHECKED BY USER • TRACES ALL FUNCTION CALLS
  • 39. XCHECK EXAMPLE #2 Print on JNI operations -Xcheck:jni:warn
  • 40. HOW DOES IT WORK (MEMORY CHECK) • AT STARTUP A NEW PORT LIBRARY IS ALLOCATED • INSTALLS NEW MEMORY ALLOCATORS & DEALLOCATORS • ALLOCATORS CAN ADD GUARD PAGES BEFORE AND/OR AFTER REQUESTED MEMORY REGION • DEALLOCATORS WRITE OVER FREED MEMORY • GUARD PAGES CAN ALSO BE MEMORY PROTECTED • KEEPS TRACK OF ALL ALLOCATIONS IN A LIST CHECKS AT SHUTDOWN FOR ALL UNFREED BLOCKS
  • 41. WHAT PROBLEMS CAN YOU SOLVE WITH THIS • HELPS DETERMINE WHETHER A PROBLEM IS A JVM PROBLEM OR A USER PROBLEM • HELPS DETERMINE WHICH COMPONENT THE PROBLEM WAS CAUSED IN • CAN AUTOMATE THE PROCESS OF FINDING ISSUES IN VERY COMPLEX CASES • DID THE PROBLEM OCCUR IN MID SCAVENGE? • IS THIS REALLY AN OBJECT REFERENCE? • IS THE PROBLEM CAUSED BY A BUFFER OVERFLOW? • IS IT REFERENCING FREED MEMORY?
  • 42. CONCLUSION • JVMS ARE HARD! MORE TOOLS YOU HAVE THE MORE EFFICIENT YOU CAN BE IN SOLVING PROBLEMS • VALIDATING INDIVIDUAL COMPONENTS HELPS NARROW DOWN THE PROBLEM • IT HELPS IF YOU BUILD DEBUGGING TOOLS INTO YOUR SYSTEM • SOME DEBUGGING FEATURES CAN LEVERAGE EXISTING FEATURES • AUTOMATING CHECKS CAN MAKE VERY HARD BUGS EASY TO SPOT
  • 43. TAKEAWAY • WHAT TOOLS CAN YOU BUILD INTO YOUR APPLICATION TO MAKE DEBUGGING EASIER?

Editor's Notes

  • #5: What is debugging? Debugging, in the most general sense, is finding out which assumptions are wrong about a system. Finding the wrong assumptions lead you a step closer to finding the problem Another way to look at it is: debugging is confirming all the things you believe to be true about a system.
  • #6: If debugging is about finding which assumptions are wrong, what are the types of information that can help us. Historical Data – what happened? when did it happen? In which order did it happen? A common strategy is to put printfs in the code A similar technique is track events in logs Program State - what is the big picture view of the system at the time of the problem? Setting breakpoints to stop execution making it possible to inspect variables Generate a core dump to get a picture of the entire system at the time of the problem - Analysis – And once you have gathered all your data, you perform analysis to determine what the problem is or what additional data you need to find the problem
  • #7: A debuggable runtime is a runtime that has: Builtin mechanism to capture historical data It always nice if logging Is a facility that you can simply turn on/off, instead of having to instrument code each time you run into a problem extract state of both the runtime and the language This is not trivial, external tools do not know enough about the runtime to distinguish between what is language state and what is runtime state Simplify or automate the process of analyzing the program state to find bugs Some bugs require a lot of effort to determine cause, if you have noticed patterns with these issues in the past you can add some checks to help you identify the problem in case you run into it again
  • #8: So for this talk I will discuss What tools we have built into Openj9 to make debugging easier How did we create these tools What problems can we solve with these tools
  • #9: Before we get into the JVM details I would like to first talk to you about Eclipse OMR – Open source Runtime toolkit Contains components that can be used to build language runtimes Components include GC – framework for managed heaps Compiler – components for building a compiler technologies (JIT compilers) Omrtrace – tracing library, also used for communication with IBM health centre monitoring tools Port library – platform porting library And more We have used some of these components in Openj9 to build debugging tools as you will see later
  • #10: Constantly adding logging can be very burdensome and time consuming given that JVMs have many components many and 1000s of lines of code. A better solution is to add logging as you develop the JVM OMR TRACE component enables runtime developers to log internal and language events, which are called tracepoints. In openj9 they are used to log Gc activity, Jit compilation, classloading, etc as well as language events such as entering and exiting a method
  • #11: Trace points are defined in a .tdf file. There is a .tdf for each component (one for gc, jit, vm, bcutil, etc. ) in the JVM There are different kinds of tracepoints each with a unique format (indentations for method entry/exit) Trace assertions are special in that they trigger system dumps (more on that later) Each trace point is associated with a level, so they can be turn on or off with commandline options
  • #12: Tracepoints are stored in an internal circular buffer so only the most recent events are kept, and there is one for each thread Each tracepoint is timestamped and has a unique ID. Tracepoints can also be turned on indiviualling by specifying their ID They are stored in binary nonhuman readable format to conserve memory A tool called traceformat which comes with Openj9 is used to convert the binary data in to human readable format
  • #13: Here is an example of this tool in action In this particular scenario we are dump all the trace out to the console (that’s the ‘:print’ part) And we are targeting all level2 and under tracepoints in the memory manager module In the example we see that we failed to allocate an object which triggers a local GC Notice timestamp and traceID
  • #14: In this example we are tracing all methods in the j.l.Module class So we can trace but internal JVM events as well as language events Also it can show input parameters and return values This could be usefull for application developers to debug their applications as well
  • #15: This is not a complete list but covers most of the things you can do with tracepoints Output: There are many configurations in which you can run the trace tool In the examples we saw how they can be outputted to the console. By default they are kept in internal trace buffers which can retrieved with a system core or using trace dump agents (more on that later) They can also be written to files or external listeners using the JVMTI RegisterTracePointSubscriber() (extended JVMTI feature) Quantity: You modify the trace buffer size to increase or decrease amount of history you want to keep track of There are also minimal and maximal modes which determine how much information each tracepoint stores (minimal only stores traceID and timestamp) Content We have tracpoints in all JVM components, interpreter, GC, JIT, Classloading, internal natives, etc Lets you trace java method entry/exit, also you can set it to show input parameters and return values Control: Trace points can be triggered to sleep, resumes, suspend if certain conditions are met. Ie. When method Foo is called sleep for 10seconds
  • #16: Trace shows you the steps leading up to a problem. Ie. You have some corruption which make you jump to random location, tracepoints will help pinpoint where that corruption happened Usefull incases where a certain unpredictable order of events may cause a failure, Trace will help you see which order these events occurred Trace lets you see what parameters were passed in leading to the problem
  • #17: Openj9 comes with dump agents that allow you to configure the conditions for when you want the different types of dumps to occur. This is done using the -Xdump JVM command line option. The types of dumps are, system, heap, java, trace, stacktraces, thread and jitdumps Stack dumps write basic information to stderr. System, java and heap give you a picture of the entire JVM state JIT is diagnostic data for the JIT compiler. Each dump agent is triggered by a configurable event, e.g. filtered exception or loading a specific class (it’s regex, so it could even be any class in a package). You can use specify multiple dump agents to cover different scenarios. For example, you can get a heap dump on every GC or on OOM, a system core if a GPF occurs, and a java core when the JVM shuts down. Xdump also allows you to preform requests such as a heap compaction dumping a system core
  • #18: Openj9 has a hook mechanism built on omr hook gen This is used for events such as classloading, GC, startup/shutdown, etc. for jvmti agents, jit bookeeping (flush method cache if class is unloaded) Xdump piggybacks on the hook system and registers listeners for certain hooks depending on the chosen configuration When hooks are triggered dump agent checks the event data to see if it matches the filter (ie. did the thrown exception match the filter)
  • #19: When we do get a match, al threads are halted For system dumps we use an omrport function to do the system dump For javacores and heapdumps we use a combination of jvmti heap iterators and vm classtable iterators to collect the necesarry data and write out to a file For trace dumps we simply write the trace buffers to a file
  • #20: Here are some examples of the xdump option The first dumps a system core when a Null pointer exception is throw in TestClass Shows you can filter on certain typs of exceptions, in certain classes (or even methods within those classes)
  • #21: The second produces a heap dump when it receives a user signal (kill -3 [PID])
  • #22: And the third lists all the available options This is not a complete list, but entering that command will show you all the options
  • #23: This very usefull for debugging hangs, you could configure it to generate a sequence of dumps to see whether any progress is being made It can also be used to debug intermittent issues, ie. Produces a core when a certain exception is thrown. And since you have the complete state, you can use it to find user level problems as well
  • #24: DDR (dynamic dump reader) allows users inspect system cores It contains layout info of the JVM process, all the data structures, and can map out the entire JVM DDR is also aware of internal JVM algorithms. For example, it knows how to walk the Java stack. Or find the root path for a given object This tool Is also extensible, so developers can add their own custom commands With this knowledge, we get a powerful debugging tool… DDR-gen generates blob and java code (more on that later) required for ddr interactive
  • #25: compile the JVM with debug symbols Scan source for macros and compiler flags Ddrgen which makes use of libdwarf to inspect the compiled library to find sizes and offsets and output to blob.dat. Structures can be compiled to different size on different platforms, void* will be different on 32 and 64bit platforms, same as a long. Some platforms will add padding and some will not. Blob.dat is loadd into memory at runtime superset.dat contains names of all structures and their members
  • #26: Use the superset file to generate sturcture and pointer classes Functions have getters for all members of stuctures, also have gettters for address of members
  • #27: When ddr is started it loads the generated classes and the ddr blob At this point we know all the structures and all their sizes and offsets This appproach also lets us be platform agnostic because all the platform information we need (sizes and offsets) is in the core
  • #28: Here is how everything fits together At AOT we do the DDR generation (superset, generated classes, blob) At runtime JVM contains DDR blob When a system dump is triggered, the core also contains DDR blob DDR makes use of use of superset, generated classes and blob
  • #29: Here is an example print all java threads and inspect java stacktrace It gives me the address of the Java thread, the thread ID and the name. But it also gives my suggestions for commands to further explore the threads. !j9vmthread will let me explore the J9 VM thread structure stored at that address. !stack will give me the information about the thread stack. This is possible because DDR knows how to walk a Java stack. Let’s run the !stack command on the main thread. This is just a test scenario, so we only get this minimal thread stack. We get another suggestion – we can explore the method(s) that are on the stack. … and I can keep digging: I can explore the constant pool or take a look at bytecodes of this method. This is particularly useful when looking at bytecodes that are modified when loaded, for example the way J9 handles MethodHandle invocations.
  • #30: Here is different stack trace with more detail In this case, we see frame details like SP, BP, A0 We can also see the address of local variables We can also see whether the method is interpreted or Jitted which is usefull for problem determination
  • #31: Here is an example where we dump a string object We can see all the fields, even the “hidden” ones like the class reference
  • #32: And it doesn’t just print things out, it can also do some analysis for you We have a deadlock command that will show you any deadlocks. Requires no effort on your part which is nice
  • #33: There are many more features, you can find them by !j9help
  • #34: GDB – they can also inspect core files but it doesn’t know enough about the VM to print out structures (which will require debug symbols) or objects (which it simply cannot do). - Requires you to understand the JVM (where is the starting point, how do I make sense of these structures) DDR can explore the system core without source code and debug symbols. And, in the spirit of Java, it’s backwards compatible, so you can read core dumps produced by older JVMs because DDR keeps track of structure versions. Also GDB is platform specific whereas you can take a core from an AIX PPC 64-way machine and debug it on an intel ubuntu laptop using DDR
  • #35: Just to drive home the point Here is a java stracktrace on GDB and DDR As you can see one is a lot easier to read and understand
  • #36: Xcheck is a verification tool built into the JVM It can run checks on GCs, JNI calls and memory alloc/dealloc
  • #37: Leverages hook mechanism for gc events A bascially performs sanity checks for GC bookeeping Any bad objects on the stack Are Remembered set slots actually pointing to different generations Is the slot in the object really a class pointer Us the heap walkable This checks make it very easy to find bugs that could take a long time to discover
  • #38: Little example of the tool in action,
  • #39: Basically your regular jni call with additional checks for Args types/ values Calss pointer Env point Exception checking Also does function tracing
  • #40: Very usefull for JVM developers but JVM users could also make use of this to verify their JNI code Our service team has found many bugs user JNI code, and a feature like this makes it less likely
  • #41: At startup we install new port lib with new alloc and free functions Allocators can add graurd pages around requested memory region Deallocators write over freed memory and do header and footer checks for corruption,(very usefull for detecting underflows and overflows) Guard pages can be mem protected so you can find out exactly when corruption occurred And we keep track of all allocations in a list and check at shutdown for all unfreed blocks We keep a memtag so we know file and line number of each allocation
  • #42: Helps out a lot with analysis, Is the problem in the JVM? Is it in user code? Is it a GC problem? In the VM? Are we leaking memory? And its all automated!
  • #44: You’ve seen what we have done in openj9, what can you do in your applications to make debugging easier