SlideShare une entreprise Scribd logo
1  sur  24
Télécharger pour lire hors ligne
MYSAFE
github.com/serkan-ozal/mysafe
SERKAN ÖZAL
AGENDA
● WHAT IS MYSAFE?
● MOTIVATION
● STATE OF ART
● HOW TO USE?
● FEATURES & DEMO
● ROADMAP
WHAT IS MYSAFE?
● Intercepts “sun.misc.Unsafe” calls
● Can track memory allocations and frees
● Can track memory accesses (reads/writes)
● Can align memory accesses (reads/writes)
● Can track custom memory allocations/frees
○ Ex. your custom memory manager implementation
● Can track memory allocation paths
○ Find the origins of leaked (non-free) memories
MOTIVATION
● Debugging memory allocations and frees
○ Checking native memory leaks over “Unsafe”
○ Detecting causes of native memory leaks
● Debugging memory accesses (reads/writes)
○ Finding the causes of illegal memory accesses
● Handle unaligned memory accesses (causes SIGBUS)
○ SPARC
○ ...
STATE OF ART
● Inspect application classes while loading
○ At “ClassFileTransformer” level
○ At “Classloader” level
● Redirect “Unsafe” calls to MySafe
● MySafe handles the call
● Proceeds to “Unsafe”
WHY NOT JUST INST. UNSAFE?
● Use “java.lang.Instrument#setNativeMethodPrefix”
● Add new wrapper methods for native methods
● Requires new method addition
● So class redefinition is not an option
● Hook into “Unsafe” classloading process
● “Unsafe” is already loaded before
○ Java agent
○ User classloader
● Use native JVMTI agent at startup (on the roadmap)
HOW TO USE?
● Java Agent Based Usage by VM Argument
○ -javaagent:<path_to_jillegal_agent><jillegal_agent_jar>=
"-p tr.com.serkanozal.mysafe.impl.processor.MySafeProcessor".
● Java Agent Based Usage Programmatically
○ MySafe.youAreMine();
● ClassLoader Based Usage by VM Argument
○ -Djava.system.class.loader=
tr.com.serkanozal.mysafe.impl.classloader.MySafeClassLoader
FEATURES & DEMO
● Memory Explorer API & Demo
● Memory Listener API & Demo
● Illegal Memory Access Listener API & Demo
● Custom Memory Management & Demo
● Tracing Allocation Path & Demo
Memory Explorer API
● Iterate on allocated memories
● Dump allocated memories
● MemoryExplorerDemo.java
Memory Listener API
● Be notified before/after allocate
● Be notified before/after reallocate
● Be notified before/after free
● MemoryListenerDemo.java
Illegal Mem. Acc. Listener API
● Be notified on illegal memory accesses (reads/writes)
● Be notified on un-allocated memory reallocations/frees
● Throws “IllegalArgumentException”
● IllegalMemoryAccessListenerDemo.java
Custom Memory Management
● Tracks custom memory mng. points instead of “Unsafe”
● Memory management points refers to methods which
○ allocate
○ reallocate
○ free
● Custom memory mng. points can be configured by:
○ @AllocationPoint
○ @FreePoint
○ @ReallocationPoint
● CustomMemoryManagementDemo.java
Tracing Allocation Path
● Alloc. path = stack trace of caller which allocates memory
● Dump active allocation paths
● Generate diagram of active allocation paths
● Alloc. paths are provided via “AllocPathManager” API
○ Instrumentation based (currently in use)
■ Pros: Very fast, low CPU and GC overhead
■ Cons: Not detailed, might be trashed
○ Java 9’s StackWalker API based (on the roadmap)
■ Pros: Detailed, no need to be trashed
■ Cons: Not fast as much as Inst. based one
● NativeMemoryLeakHuntingDemo.java
Inst. Based Alloc. Path Manager
● Identify each method which exist in the any alloc. path
● Inject code into methods to provide them as alloc. path
○ Push method identifier to thread-local call stack
○ Proceed actual call
○ Pop method identifier from thread-local call stack
● Generate alloc. path id from alloc. point (method) ids
○ Each alloc. point id is 2 bytes short number
○ Whole alloc. path is represented with 8 bytes long number
○ There can be at most 4 alloc. points, old ones are evicted
foo1 [1]
1
foo1 [1]
bar1 [2]
1 2
foo1 [1]
bar1 [2]
foo2 [3]
1 2 3
foo1 [1]
bar1 [2]
foo2 [3]
bar2 [4]
1 2 3 4
foo1 [1]
bar1 [2]
foo2 [3]
bar2 [4]
foo3 [5]
2 3 4 5
foo1 [1]
bar1 [2]
foo2 [3]
bar2 [4]
foo3 [5]
bar3 [6]
3 4 5 6
foo1 [1]
bar1 [2]
foo2 [3]
bar2 [4]
foo3 [5]
bar3 [6]
malloc
3 4 5 6
foo2 => bar2 => foo3 => bar3
ROADMAP
● Ability to track line numbers also
● More detailed and accurate allocation path detection
● Ability to inspect “Unsafe” directly
● Java 9 support
● Allocation path detection via Java 9’s StackWalker API
● Flame graph support
THANKS

Contenu connexe

Similaire à Track Memory Allocations and Accesses with MySafe

Adv java unit 1 M.Sc CS.pdf
Adv java unit 1 M.Sc CS.pdfAdv java unit 1 M.Sc CS.pdf
Adv java unit 1 M.Sc CS.pdfKALAISELVI P
 
[Kiwicon 2011] Post Memory Corruption Memory Analysis
[Kiwicon 2011] Post Memory Corruption Memory Analysis[Kiwicon 2011] Post Memory Corruption Memory Analysis
[Kiwicon 2011] Post Memory Corruption Memory AnalysisMoabi.com
 
WIndows Kernel-Land exploitation
WIndows Kernel-Land exploitationWIndows Kernel-Land exploitation
WIndows Kernel-Land exploitationkyaw thiha
 
Veil-PowerView - NovaHackers
Veil-PowerView - NovaHackersVeil-PowerView - NovaHackers
Veil-PowerView - NovaHackersVeilFramework
 
Session - Debugging memory stomps and other atrocities - Stefan Reinalter - T...
Session - Debugging memory stomps and other atrocities - Stefan Reinalter - T...Session - Debugging memory stomps and other atrocities - Stefan Reinalter - T...
Session - Debugging memory stomps and other atrocities - Stefan Reinalter - T...Mary Chan
 
Scalability, Fidelity and Stealth in the DRAKVUF Dynamic Malware Analysis System
Scalability, Fidelity and Stealth in the DRAKVUF Dynamic Malware Analysis SystemScalability, Fidelity and Stealth in the DRAKVUF Dynamic Malware Analysis System
Scalability, Fidelity and Stealth in the DRAKVUF Dynamic Malware Analysis SystemTamas K Lengyel
 
[HITB Malaysia 2011] Exploit Automation
[HITB Malaysia 2011] Exploit Automation[HITB Malaysia 2011] Exploit Automation
[HITB Malaysia 2011] Exploit AutomationMoabi.com
 
Ansible for Configuration Management for Lohika DevOps training 2018 @ Lohika...
Ansible for Configuration Management for Lohika DevOps training 2018 @ Lohika...Ansible for Configuration Management for Lohika DevOps training 2018 @ Lohika...
Ansible for Configuration Management for Lohika DevOps training 2018 @ Lohika...Ihor Banadiga
 
CSW2017 Henry li how to find the vulnerability to bypass the control flow gua...
CSW2017 Henry li how to find the vulnerability to bypass the control flow gua...CSW2017 Henry li how to find the vulnerability to bypass the control flow gua...
CSW2017 Henry li how to find the vulnerability to bypass the control flow gua...CanSecWest
 
Group meeting: UniSan - Proactive Kernel Memory Initialization to Eliminate D...
Group meeting: UniSan - Proactive Kernel Memory Initialization to Eliminate D...Group meeting: UniSan - Proactive Kernel Memory Initialization to Eliminate D...
Group meeting: UniSan - Proactive Kernel Memory Initialization to Eliminate D...Yu-Hsin Hung
 
Java SpringMVC SpringBOOT (Divergent).ppt
Java SpringMVC SpringBOOT (Divergent).pptJava SpringMVC SpringBOOT (Divergent).ppt
Java SpringMVC SpringBOOT (Divergent).pptAayush Chimaniya
 
No locked doors, no windows barred: hacking OpenAM infrastructure
No locked doors, no windows barred: hacking OpenAM infrastructureNo locked doors, no windows barred: hacking OpenAM infrastructure
No locked doors, no windows barred: hacking OpenAM infrastructureAndrew Petukhov
 
Metasploit For Beginners
Metasploit For BeginnersMetasploit For Beginners
Metasploit For BeginnersRamnath Shenoy
 
Distributed Coordination with Python
Distributed Coordination with PythonDistributed Coordination with Python
Distributed Coordination with PythonOSCON Byrum
 

Similaire à Track Memory Allocations and Accesses with MySafe (20)

Adv java unit 1 M.Sc CS.pdf
Adv java unit 1 M.Sc CS.pdfAdv java unit 1 M.Sc CS.pdf
Adv java unit 1 M.Sc CS.pdf
 
Unsafe Java
Unsafe JavaUnsafe Java
Unsafe Java
 
Advanced Arm Exploitation
Advanced Arm ExploitationAdvanced Arm Exploitation
Advanced Arm Exploitation
 
Troubleshooting Java HotSpot VM
Troubleshooting Java HotSpot VMTroubleshooting Java HotSpot VM
Troubleshooting Java HotSpot VM
 
[Kiwicon 2011] Post Memory Corruption Memory Analysis
[Kiwicon 2011] Post Memory Corruption Memory Analysis[Kiwicon 2011] Post Memory Corruption Memory Analysis
[Kiwicon 2011] Post Memory Corruption Memory Analysis
 
WIndows Kernel-Land exploitation
WIndows Kernel-Land exploitationWIndows Kernel-Land exploitation
WIndows Kernel-Land exploitation
 
Veil-PowerView - NovaHackers
Veil-PowerView - NovaHackersVeil-PowerView - NovaHackers
Veil-PowerView - NovaHackers
 
Session - Debugging memory stomps and other atrocities - Stefan Reinalter - T...
Session - Debugging memory stomps and other atrocities - Stefan Reinalter - T...Session - Debugging memory stomps and other atrocities - Stefan Reinalter - T...
Session - Debugging memory stomps and other atrocities - Stefan Reinalter - T...
 
Emulating With JavaScript
Emulating With JavaScriptEmulating With JavaScript
Emulating With JavaScript
 
Scalability, Fidelity and Stealth in the DRAKVUF Dynamic Malware Analysis System
Scalability, Fidelity and Stealth in the DRAKVUF Dynamic Malware Analysis SystemScalability, Fidelity and Stealth in the DRAKVUF Dynamic Malware Analysis System
Scalability, Fidelity and Stealth in the DRAKVUF Dynamic Malware Analysis System
 
[HITB Malaysia 2011] Exploit Automation
[HITB Malaysia 2011] Exploit Automation[HITB Malaysia 2011] Exploit Automation
[HITB Malaysia 2011] Exploit Automation
 
Ansible for Configuration Management for Lohika DevOps training 2018 @ Lohika...
Ansible for Configuration Management for Lohika DevOps training 2018 @ Lohika...Ansible for Configuration Management for Lohika DevOps training 2018 @ Lohika...
Ansible for Configuration Management for Lohika DevOps training 2018 @ Lohika...
 
CSW2017 Henry li how to find the vulnerability to bypass the control flow gua...
CSW2017 Henry li how to find the vulnerability to bypass the control flow gua...CSW2017 Henry li how to find the vulnerability to bypass the control flow gua...
CSW2017 Henry li how to find the vulnerability to bypass the control flow gua...
 
Group meeting: UniSan - Proactive Kernel Memory Initialization to Eliminate D...
Group meeting: UniSan - Proactive Kernel Memory Initialization to Eliminate D...Group meeting: UniSan - Proactive Kernel Memory Initialization to Eliminate D...
Group meeting: UniSan - Proactive Kernel Memory Initialization to Eliminate D...
 
MSL2009. Valgrind
MSL2009. ValgrindMSL2009. Valgrind
MSL2009. Valgrind
 
Java SpringMVC SpringBOOT (Divergent).ppt
Java SpringMVC SpringBOOT (Divergent).pptJava SpringMVC SpringBOOT (Divergent).ppt
Java SpringMVC SpringBOOT (Divergent).ppt
 
Java 2
Java 2Java 2
Java 2
 
No locked doors, no windows barred: hacking OpenAM infrastructure
No locked doors, no windows barred: hacking OpenAM infrastructureNo locked doors, no windows barred: hacking OpenAM infrastructure
No locked doors, no windows barred: hacking OpenAM infrastructure
 
Metasploit For Beginners
Metasploit For BeginnersMetasploit For Beginners
Metasploit For Beginners
 
Distributed Coordination with Python
Distributed Coordination with PythonDistributed Coordination with Python
Distributed Coordination with Python
 

Plus de Serkan Özal

Flying Server-less on the Cloud with AWS Lambda
Flying Server-less on the Cloud with AWS LambdaFlying Server-less on the Cloud with AWS Lambda
Flying Server-less on the Cloud with AWS LambdaSerkan Özal
 
Improving performance of decision support queries in columnar cloud database ...
Improving performance of decision support queries in columnar cloud database ...Improving performance of decision support queries in columnar cloud database ...
Improving performance of decision support queries in columnar cloud database ...Serkan Özal
 
JVM Under the Hood
JVM Under the HoodJVM Under the Hood
JVM Under the HoodSerkan Özal
 
Ankara JUG Big Data Presentation
Ankara JUG Big Data PresentationAnkara JUG Big Data Presentation
Ankara JUG Big Data PresentationSerkan Özal
 
AWS EMR - Amazon Elastic Map Reduce
AWS EMR - Amazon Elastic Map ReduceAWS EMR - Amazon Elastic Map Reduce
AWS EMR - Amazon Elastic Map ReduceSerkan Özal
 

Plus de Serkan Özal (7)

Flying Server-less on the Cloud with AWS Lambda
Flying Server-less on the Cloud with AWS LambdaFlying Server-less on the Cloud with AWS Lambda
Flying Server-less on the Cloud with AWS Lambda
 
Improving performance of decision support queries in columnar cloud database ...
Improving performance of decision support queries in columnar cloud database ...Improving performance of decision support queries in columnar cloud database ...
Improving performance of decision support queries in columnar cloud database ...
 
JVM Under the Hood
JVM Under the HoodJVM Under the Hood
JVM Under the Hood
 
Big data on aws
Big data on awsBig data on aws
Big data on aws
 
Ankara JUG Big Data Presentation
Ankara JUG Big Data PresentationAnkara JUG Big Data Presentation
Ankara JUG Big Data Presentation
 
AWS EMR - Amazon Elastic Map Reduce
AWS EMR - Amazon Elastic Map ReduceAWS EMR - Amazon Elastic Map Reduce
AWS EMR - Amazon Elastic Map Reduce
 
Big data concepts
Big data conceptsBig data concepts
Big data concepts
 

Dernier

Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfMarharyta Nedzelska
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringHironori Washizaki
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsChristian Birchler
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Rob Geurden
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
Understanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM ArchitectureUnderstanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM Architecturerahul_net
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...OnePlan Solutions
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Cizo Technology Services
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfStefano Stabellini
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf31events.com
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Developmentvyaparkranti
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 

Dernier (20)

Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdf
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their Engineering
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
Understanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM ArchitectureUnderstanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM Architecture
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
 
2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdf
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Development
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 

Track Memory Allocations and Accesses with MySafe

  • 2. AGENDA ● WHAT IS MYSAFE? ● MOTIVATION ● STATE OF ART ● HOW TO USE? ● FEATURES & DEMO ● ROADMAP
  • 3. WHAT IS MYSAFE? ● Intercepts “sun.misc.Unsafe” calls ● Can track memory allocations and frees ● Can track memory accesses (reads/writes) ● Can align memory accesses (reads/writes) ● Can track custom memory allocations/frees ○ Ex. your custom memory manager implementation ● Can track memory allocation paths ○ Find the origins of leaked (non-free) memories
  • 4. MOTIVATION ● Debugging memory allocations and frees ○ Checking native memory leaks over “Unsafe” ○ Detecting causes of native memory leaks ● Debugging memory accesses (reads/writes) ○ Finding the causes of illegal memory accesses ● Handle unaligned memory accesses (causes SIGBUS) ○ SPARC ○ ...
  • 5. STATE OF ART ● Inspect application classes while loading ○ At “ClassFileTransformer” level ○ At “Classloader” level ● Redirect “Unsafe” calls to MySafe ● MySafe handles the call ● Proceeds to “Unsafe”
  • 6. WHY NOT JUST INST. UNSAFE? ● Use “java.lang.Instrument#setNativeMethodPrefix” ● Add new wrapper methods for native methods ● Requires new method addition ● So class redefinition is not an option ● Hook into “Unsafe” classloading process ● “Unsafe” is already loaded before ○ Java agent ○ User classloader ● Use native JVMTI agent at startup (on the roadmap)
  • 7. HOW TO USE? ● Java Agent Based Usage by VM Argument ○ -javaagent:<path_to_jillegal_agent><jillegal_agent_jar>= "-p tr.com.serkanozal.mysafe.impl.processor.MySafeProcessor". ● Java Agent Based Usage Programmatically ○ MySafe.youAreMine(); ● ClassLoader Based Usage by VM Argument ○ -Djava.system.class.loader= tr.com.serkanozal.mysafe.impl.classloader.MySafeClassLoader
  • 8. FEATURES & DEMO ● Memory Explorer API & Demo ● Memory Listener API & Demo ● Illegal Memory Access Listener API & Demo ● Custom Memory Management & Demo ● Tracing Allocation Path & Demo
  • 9. Memory Explorer API ● Iterate on allocated memories ● Dump allocated memories ● MemoryExplorerDemo.java
  • 10. Memory Listener API ● Be notified before/after allocate ● Be notified before/after reallocate ● Be notified before/after free ● MemoryListenerDemo.java
  • 11. Illegal Mem. Acc. Listener API ● Be notified on illegal memory accesses (reads/writes) ● Be notified on un-allocated memory reallocations/frees ● Throws “IllegalArgumentException” ● IllegalMemoryAccessListenerDemo.java
  • 12. Custom Memory Management ● Tracks custom memory mng. points instead of “Unsafe” ● Memory management points refers to methods which ○ allocate ○ reallocate ○ free ● Custom memory mng. points can be configured by: ○ @AllocationPoint ○ @FreePoint ○ @ReallocationPoint ● CustomMemoryManagementDemo.java
  • 13. Tracing Allocation Path ● Alloc. path = stack trace of caller which allocates memory ● Dump active allocation paths ● Generate diagram of active allocation paths ● Alloc. paths are provided via “AllocPathManager” API ○ Instrumentation based (currently in use) ■ Pros: Very fast, low CPU and GC overhead ■ Cons: Not detailed, might be trashed ○ Java 9’s StackWalker API based (on the roadmap) ■ Pros: Detailed, no need to be trashed ■ Cons: Not fast as much as Inst. based one ● NativeMemoryLeakHuntingDemo.java
  • 14.
  • 15. Inst. Based Alloc. Path Manager ● Identify each method which exist in the any alloc. path ● Inject code into methods to provide them as alloc. path ○ Push method identifier to thread-local call stack ○ Proceed actual call ○ Pop method identifier from thread-local call stack ● Generate alloc. path id from alloc. point (method) ids ○ Each alloc. point id is 2 bytes short number ○ Whole alloc. path is represented with 8 bytes long number ○ There can be at most 4 alloc. points, old ones are evicted
  • 19. foo1 [1] bar1 [2] foo2 [3] bar2 [4] 1 2 3 4
  • 20. foo1 [1] bar1 [2] foo2 [3] bar2 [4] foo3 [5] 2 3 4 5
  • 21. foo1 [1] bar1 [2] foo2 [3] bar2 [4] foo3 [5] bar3 [6] 3 4 5 6
  • 22. foo1 [1] bar1 [2] foo2 [3] bar2 [4] foo3 [5] bar3 [6] malloc 3 4 5 6 foo2 => bar2 => foo3 => bar3
  • 23. ROADMAP ● Ability to track line numbers also ● More detailed and accurate allocation path detection ● Ability to inspect “Unsafe” directly ● Java 9 support ● Allocation path detection via Java 9’s StackWalker API ● Flame graph support