SlideShare a Scribd company logo
1 of 48
Aspect Oriented Programming:
Hidden Toolkit That You Already Have
Dmitry Vinnik
Senior Software Engineer
dvinnik@salesforce.com
JEEConf 2017
Talk Outline
● AOP Overview
● Anatomy of AspectJ
● Spring AOP
● Java Agents Overview
● AOP Implementations
Talk Motivation
Everyday challenges: profiling, code coverage, HotSwap, and monitoring.
Aspect Oriented Programing (AOP) is a solution to all these problems.
AOP is a Hidden Toolkit that everyone knows, but very few use.
This talk aims to change that.
Aspect Oriented Programming
Overview
Aspect Oriented Programming (AOP)
Overview
AOP is Cross-Cutting Concerns paradigm
Answers Questions:
● What is my code coverage?
● Is my JVM even running?
● Ahh, do I have to restart my app again?
● How long does this process take?
Hidden Toolkit: AOP Simple Example
1: 1
2: 1
...
39: 63245986
40: 102334155
Process: 1837 ms
Code Sample: Output:
Hidden Toolkit: AspectJ
Overview
Hidden Toolkit: AspectJ Overview
Defining Aspect
1) Definition
3) Advice
2)
Pointc
ut
Hidden Toolkit: AspectJ
Pointcuts Overview
Hidden Toolkit: AspectJ Pointcuts
Anatomy of Pointcut
1) Definition
2)
Ty
pe
3)
Expressi
on
Hidden Toolkit: AspectJ Pointcuts - Continue
Methods/Constructors:
1) call(Signature)
2) execution(Signature)
Fields (specific to AspectJ):
1) get(Signature)
2) set(Signature)
Exceptions Handler:
1) handler(TypePattern)
Types of Pointcuts
Hidden Toolkit: AspectJ Pointcuts - Continue
1) Signature
1) TypePattern
Pointcut Expressions
3) Pointcut/Combination
Hidden Toolkit: AspectJ
Advices Overview
Hidden Toolkit: AspectJ Advice
Anatomy of AspectJ Advice
1) Advice Type
2) Pointcut
Binding
3) Main
Logic
Hidden Toolkit: AspectJ Advice - Continue
Types of Advices
1) Before
1) After
1) Around
Hidden Toolkit: AspectJ Advice - Continue
1. Single Pointcut
2. Joint Pointcuts
3. Inline Pointcut
4. Parameterized Pointcut
Pointcut Binding
Hidden Toolkit: AspectJ
Additional Information
Hidden Toolkit: AspectJ - Advanced
1) Generics
2) Abstract Aspects
3) Declare Parents
4) Declare Soft
Generics and Declarations
Hidden Toolkit: AspectJ Execution
1) Switching to ‘ajc’ compiler
Aspect Process started
1: 1
2: 1
...
39: 63245986
40: 102334155
Aspect Process took: 1845 ms
2) Run function bound by the Aspect
3) Output:
Hidden Toolkit: AspectJ
Annotations Development Style
Hidden Toolkit: AspectJ - Annotations Usage
1) Aspect Initialization
1) Pointcut Definition
Annotations Development Style - Aspect Core
Hidden Toolkit: AspectJ - Annotations Usage
1) Before
1) After
1) Around
Annotations Development Style - Advices
Hidden Toolkit: Spring AOP
Spring AOP Overview
Hidden Toolkit: Spring AOP - Configuration
@Configuration and XML
XML@Configuration
Hidden Toolkit: Spring AOP - AspectJ Annotation
Native AspectJ Support:
1. Aspect
2. Pointcut
3. Before
4. After
5. Around
Spring AspectJ Support
Hidden Toolkit: Spring AOP - Schema-Based Aspects
XML Aspects:
1. Aspect
2. Pointcut
3. Before
4. After
5. Around
Spring XML-based Aspects
Hidden Toolkit: Spring AOP - AspectJ vs. Schema
AspectJ Annotations:
● (+) DRY by-design
● (+) Pointcut combination
● (+) Reusable outside of Spring
● (-) Requires >Java 5 support
Spring XML:
● (+) Best for Enterprise services
● (+) Summary of enabled aspects
● (-) No separation of concerns
● (-) No Pointcut combinations
Comparing Two Approaches
Hidden Toolkit: Spring AOP - Limitations
● No Field-level interception allowed (i.e. #set(), #get())
● Limited support for objects not managed by Spring
● No support for certain general pointcuts (ex. handler, call)
Limitation of Spring In Comparison With Native AspectJ
Hidden Toolkit:
Anatomy of Java Agents
Overview
Hidden Toolkit: Anatomy of Java Agents
Building Java Agents
1) Premain Java Agent class
2) Implement ClassFileTransformer (next slide)
3) Compile java agent and run as:
java -javaagent:simple-agent.jar -jar test-app.jar
Hidden Toolkit: Building Java Agents
Defining Class Transformer
AOP Implementations
Overview
AOP Implementations
Main Types:
1. Code Coverage: JaCoCo, Clover
2. Benchmarks/Profilers: JMH, AppDynamics
3. Improved Compilation: HotswapAgent, JRebel
4. Application Monitoring: AppDynamics
Main Types of AOP Implementations
AOP Implementations
Code Coverage
AOP Implementation: Code Coverage
JaCoCo[1]
Report:
Class Info:
AOP Implementation: Code Coverage - Continue
● No setup required (i.e. Java Agent)
● Produces detailed reports of Code Coverage
● Highlights coverage down to code lines
● Instruments Running/Pre-Execution code
Why AOP with JaCoCo?
AOP Implementation: Code Coverage - Continue
● Classes are instrumented on the fly by Java Agent
a. Performs in-memory pre-processing of all files
b. Instruments using java.lang.instrument.Instrumentation
● Collects coverage data into .exec files
● Process collected data into .html reports
How It Actually Works
AOP Implementations
Benchmarks
AOP Implementation: Benchmarks
# Benchmark mode: Throughput, ops/time
# Benchmark:
org.sample.MyBenchmark.testMethod
# Run progress: 0.00% complete, ETA
00:06:40
# Fork: 1 of 10
# Warmup Iteration 1: 0.414 ops/s
# Warmup Iteration 2: 0.416 ops/s
# Warmup Iteration 3: 0.417 ops/s
Java Microbenchmark Harness, JMH[1]
Code Sample: Output:
AOP Implementation: Benchmark - Continue
● Reliable measure of individual units (ex. microservices)
● Supported by Oracle
● Highly customizable:
• State
• Time Unit
• Mode
Why AOP with JMH?
AOP Implementations
Improved Compilation
AOP Implementation: Improved Compilation
Default Java Hotswap handles re-compilation of java files.
Does Not Handle:
● Renaming/Addition/Deletion of Methods
● Changes to Static/Non-Static Fields
● Changes to Enum Classes
● Changes to Class Hierarchy (interfaces/superclasses)
Java Hotswap
AOP Implementation: Improved Compilation
● Java Agent that handles imperfections of Java Hotswap.
● Can be run as a javaagent on a start of JVM:
• java -XXaltjvm=dcevm -javaagent:hotswap-agent.jar test-app.jar
● Can be attached to running JVM via com.sun.tools.attach.VirtualMachine calls
● Currently in beta version
Note: Java agents like HotswapAgent do not directly change main binaries, but
rather modify proxied copy of the binaries.
HotswapAgent[1]
AOP Implementation: Improved Compilation
● No setup required (i.e. Java Agent)
● Productivity Booster (especially in enterprise)
● More Control over JVM
● Verbose Logging
Why AOP with HotswapAgent?
AOP Implementations
Other Solutions
AOP Implementations: Other Solutions
● Atlassian Clover (Code Coverage)
● JCov (Code Coverage)
● AppDynamics (Benchmark, Monitoring)
● Statsd-JVM (Profiler)
● JRebel (Improved Compilation)
Q/A
About Speaker
Twitter: @DmitryVinnik
LinkedIn: in/dmitry-vinnik/
Email: dvinnik@salesforce.com
Dmitry Vinnik

More Related Content

What's hot

Spring AOP Introduction
Spring AOP IntroductionSpring AOP Introduction
Spring AOP Introductionb0ris_1
 
TestWorks Conf Performance testing made easy with gatling - Guillaume Corré
TestWorks Conf Performance testing made easy with gatling - Guillaume CorréTestWorks Conf Performance testing made easy with gatling - Guillaume Corré
TestWorks Conf Performance testing made easy with gatling - Guillaume CorréXebia Nederland BV
 
Sista: Improving Cog’s JIT performance
Sista: Improving Cog’s JIT performanceSista: Improving Cog’s JIT performance
Sista: Improving Cog’s JIT performanceESUG
 
Application of the Actor Model to Large Scale NDE Data Analysis
Application of the Actor Model to Large Scale NDE Data AnalysisApplication of the Actor Model to Large Scale NDE Data Analysis
Application of the Actor Model to Large Scale NDE Data AnalysisChrisCoughlin9
 
C# 8 in Libraries and Applications - BASTA! Frankfurt 2020
C# 8 in Libraries and Applications - BASTA! Frankfurt 2020C# 8 in Libraries and Applications - BASTA! Frankfurt 2020
C# 8 in Libraries and Applications - BASTA! Frankfurt 2020Christian Nagel
 
Automation is Easy! (python version)
Automation is Easy! (python version)Automation is Easy! (python version)
Automation is Easy! (python version)Iakiv Kramarenko
 
Александр Махомет "Feature Flags. Уменьшаем риски при выпуске изменений"
Александр Махомет "Feature Flags. Уменьшаем риски при выпуске изменений" Александр Махомет "Feature Flags. Уменьшаем риски при выпуске изменений"
Александр Махомет "Feature Flags. Уменьшаем риски при выпуске изменений" Fwdays
 
Boost your App with Gatling
Boost your App with GatlingBoost your App with Gatling
Boost your App with GatlingKnoldus Inc.
 
EclipseCon Eu 2015 - Breathe life into your Designer!
EclipseCon Eu 2015 - Breathe life into your Designer!EclipseCon Eu 2015 - Breathe life into your Designer!
EclipseCon Eu 2015 - Breathe life into your Designer!melbats
 
Automation testing
Automation testingAutomation testing
Automation testingkamilkaide
 
Measuring Performance / iOS Apps
Measuring Performance / iOS AppsMeasuring Performance / iOS Apps
Measuring Performance / iOS AppsIgor Mandrigin
 
TRACK H: Using Formal Tools to Improve the Productivity of Verification at ST...
TRACK H: Using Formal Tools to Improve the Productivity of Verification at ST...TRACK H: Using Formal Tools to Improve the Productivity of Verification at ST...
TRACK H: Using Formal Tools to Improve the Productivity of Verification at ST...chiportal
 
Tech Days 2015: Ada 2012 and Spark Crazyflie and Railway Demo
Tech Days 2015: Ada 2012 and Spark Crazyflie and Railway DemoTech Days 2015: Ada 2012 and Spark Crazyflie and Railway Demo
Tech Days 2015: Ada 2012 and Spark Crazyflie and Railway DemoAdaCore
 
Bsides Knoxville - APT2
Bsides Knoxville - APT2Bsides Knoxville - APT2
Bsides Knoxville - APT2Adam Compton
 
Test Automation for Embedded Devices
Test Automation for Embedded DevicesTest Automation for Embedded Devices
Test Automation for Embedded DevicesScott Barber
 

What's hot (20)

Into the domain
Into the domainInto the domain
Into the domain
 
Spring AOP Introduction
Spring AOP IntroductionSpring AOP Introduction
Spring AOP Introduction
 
TestWorks Conf Performance testing made easy with gatling - Guillaume Corré
TestWorks Conf Performance testing made easy with gatling - Guillaume CorréTestWorks Conf Performance testing made easy with gatling - Guillaume Corré
TestWorks Conf Performance testing made easy with gatling - Guillaume Corré
 
Sista: Improving Cog’s JIT performance
Sista: Improving Cog’s JIT performanceSista: Improving Cog’s JIT performance
Sista: Improving Cog’s JIT performance
 
Application of the Actor Model to Large Scale NDE Data Analysis
Application of the Actor Model to Large Scale NDE Data AnalysisApplication of the Actor Model to Large Scale NDE Data Analysis
Application of the Actor Model to Large Scale NDE Data Analysis
 
1.qtp basics
1.qtp basics1.qtp basics
1.qtp basics
 
C# 8 in Libraries and Applications - BASTA! Frankfurt 2020
C# 8 in Libraries and Applications - BASTA! Frankfurt 2020C# 8 in Libraries and Applications - BASTA! Frankfurt 2020
C# 8 in Libraries and Applications - BASTA! Frankfurt 2020
 
Automation is Easy! (python version)
Automation is Easy! (python version)Automation is Easy! (python version)
Automation is Easy! (python version)
 
Александр Махомет "Feature Flags. Уменьшаем риски при выпуске изменений"
Александр Махомет "Feature Flags. Уменьшаем риски при выпуске изменений" Александр Махомет "Feature Flags. Уменьшаем риски при выпуске изменений"
Александр Махомет "Feature Flags. Уменьшаем риски при выпуске изменений"
 
Boost your App with Gatling
Boost your App with GatlingBoost your App with Gatling
Boost your App with Gatling
 
EclipseCon Eu 2015 - Breathe life into your Designer!
EclipseCon Eu 2015 - Breathe life into your Designer!EclipseCon Eu 2015 - Breathe life into your Designer!
EclipseCon Eu 2015 - Breathe life into your Designer!
 
Automation testing
Automation testingAutomation testing
Automation testing
 
Measuring Performance / iOS Apps
Measuring Performance / iOS AppsMeasuring Performance / iOS Apps
Measuring Performance / iOS Apps
 
TRACK H: Using Formal Tools to Improve the Productivity of Verification at ST...
TRACK H: Using Formal Tools to Improve the Productivity of Verification at ST...TRACK H: Using Formal Tools to Improve the Productivity of Verification at ST...
TRACK H: Using Formal Tools to Improve the Productivity of Verification at ST...
 
Feature toggling
Feature togglingFeature toggling
Feature toggling
 
Tech Days 2015: Ada 2012 and Spark Crazyflie and Railway Demo
Tech Days 2015: Ada 2012 and Spark Crazyflie and Railway DemoTech Days 2015: Ada 2012 and Spark Crazyflie and Railway Demo
Tech Days 2015: Ada 2012 and Spark Crazyflie and Railway Demo
 
Metrics
MetricsMetrics
Metrics
 
Why Automate
Why AutomateWhy Automate
Why Automate
 
Bsides Knoxville - APT2
Bsides Knoxville - APT2Bsides Knoxville - APT2
Bsides Knoxville - APT2
 
Test Automation for Embedded Devices
Test Automation for Embedded DevicesTest Automation for Embedded Devices
Test Automation for Embedded Devices
 

Similar to Aspect Oriented Programming: Hidden Toolkit That You Already Have

Introduction to Aspect Oriented Programming
Introduction to Aspect Oriented ProgrammingIntroduction to Aspect Oriented Programming
Introduction to Aspect Oriented ProgrammingAmir Kost
 
Session 45 - Spring - Part 3 - AOP
Session 45 - Spring - Part 3 - AOPSession 45 - Spring - Part 3 - AOP
Session 45 - Spring - Part 3 - AOPPawanMM
 
Spring - Part 3 - AOP
Spring - Part 3 - AOPSpring - Part 3 - AOP
Spring - Part 3 - AOPHitesh-Java
 
Kostiantyn Yelisavenko "Mastering Macro Benchmarking in .NET"
Kostiantyn Yelisavenko "Mastering Macro Benchmarking in .NET"Kostiantyn Yelisavenko "Mastering Macro Benchmarking in .NET"
Kostiantyn Yelisavenko "Mastering Macro Benchmarking in .NET"LogeekNightUkraine
 
Migration Spring PetClinic to Quarkus
Migration Spring PetClinic to QuarkusMigration Spring PetClinic to Quarkus
Migration Spring PetClinic to QuarkusJonathan Vila
 
Labview1_ Computer Applications in Control_ACRRL
Labview1_ Computer Applications in Control_ACRRLLabview1_ Computer Applications in Control_ACRRL
Labview1_ Computer Applications in Control_ACRRLMohammad Sabouri
 
Gatling - Bordeaux JUG
Gatling - Bordeaux JUGGatling - Bordeaux JUG
Gatling - Bordeaux JUGslandelle
 
Testing with Express, Mocha & Chai
Testing with Express, Mocha & ChaiTesting with Express, Mocha & Chai
Testing with Express, Mocha & ChaiJoerg Henning
 
Java Performance & Profiling
Java Performance & ProfilingJava Performance & Profiling
Java Performance & ProfilingIsuru Perera
 
The evolution of Angular 2 @ AngularJS Munich Meetup #5
The evolution of Angular 2 @ AngularJS Munich Meetup #5The evolution of Angular 2 @ AngularJS Munich Meetup #5
The evolution of Angular 2 @ AngularJS Munich Meetup #5Johannes Weber
 
Meetup 24/3/2016 - Node.js User Group Belgium
Meetup 24/3/2016 - Node.js User Group BelgiumMeetup 24/3/2016 - Node.js User Group Belgium
Meetup 24/3/2016 - Node.js User Group BelgiumDigipolis Antwerpen
 
Angular - Improve Runtime performance 2019
Angular - Improve Runtime performance 2019Angular - Improve Runtime performance 2019
Angular - Improve Runtime performance 2019Eliran Eliassy
 
Angular TS(typescript)
Angular TS(typescript)Angular TS(typescript)
Angular TS(typescript)Ivan Stepić
 
Migration Spring Boot PetClinic REST to Quarkus 1.2.0
Migration Spring Boot PetClinic REST to Quarkus 1.2.0Migration Spring Boot PetClinic REST to Quarkus 1.2.0
Migration Spring Boot PetClinic REST to Quarkus 1.2.0Jonathan Vila
 
Functional Programming in JavaScript & ESNext
Functional Programming in JavaScript & ESNextFunctional Programming in JavaScript & ESNext
Functional Programming in JavaScript & ESNextUnfold UI
 

Similar to Aspect Oriented Programming: Hidden Toolkit That You Already Have (20)

Introduction to Aspect Oriented Programming
Introduction to Aspect Oriented ProgrammingIntroduction to Aspect Oriented Programming
Introduction to Aspect Oriented Programming
 
Spring AOP
Spring AOPSpring AOP
Spring AOP
 
Session 45 - Spring - Part 3 - AOP
Session 45 - Spring - Part 3 - AOPSession 45 - Spring - Part 3 - AOP
Session 45 - Spring - Part 3 - AOP
 
Spring - Part 3 - AOP
Spring - Part 3 - AOPSpring - Part 3 - AOP
Spring - Part 3 - AOP
 
Spring AOP
Spring AOPSpring AOP
Spring AOP
 
Kostiantyn Yelisavenko "Mastering Macro Benchmarking in .NET"
Kostiantyn Yelisavenko "Mastering Macro Benchmarking in .NET"Kostiantyn Yelisavenko "Mastering Macro Benchmarking in .NET"
Kostiantyn Yelisavenko "Mastering Macro Benchmarking in .NET"
 
Callgraph analysis
Callgraph analysisCallgraph analysis
Callgraph analysis
 
Migration Spring PetClinic to Quarkus
Migration Spring PetClinic to QuarkusMigration Spring PetClinic to Quarkus
Migration Spring PetClinic to Quarkus
 
Labview1_ Computer Applications in Control_ACRRL
Labview1_ Computer Applications in Control_ACRRLLabview1_ Computer Applications in Control_ACRRL
Labview1_ Computer Applications in Control_ACRRL
 
Gatling - Bordeaux JUG
Gatling - Bordeaux JUGGatling - Bordeaux JUG
Gatling - Bordeaux JUG
 
Spring aop
Spring aopSpring aop
Spring aop
 
Testing with Express, Mocha & Chai
Testing with Express, Mocha & ChaiTesting with Express, Mocha & Chai
Testing with Express, Mocha & Chai
 
Java Performance & Profiling
Java Performance & ProfilingJava Performance & Profiling
Java Performance & Profiling
 
The evolution of Angular 2 @ AngularJS Munich Meetup #5
The evolution of Angular 2 @ AngularJS Munich Meetup #5The evolution of Angular 2 @ AngularJS Munich Meetup #5
The evolution of Angular 2 @ AngularJS Munich Meetup #5
 
Meetup 24/3/2016 - Node.js User Group Belgium
Meetup 24/3/2016 - Node.js User Group BelgiumMeetup 24/3/2016 - Node.js User Group Belgium
Meetup 24/3/2016 - Node.js User Group Belgium
 
Angular - Improve Runtime performance 2019
Angular - Improve Runtime performance 2019Angular - Improve Runtime performance 2019
Angular - Improve Runtime performance 2019
 
Angular TS(typescript)
Angular TS(typescript)Angular TS(typescript)
Angular TS(typescript)
 
Migration Spring Boot PetClinic REST to Quarkus 1.2.0
Migration Spring Boot PetClinic REST to Quarkus 1.2.0Migration Spring Boot PetClinic REST to Quarkus 1.2.0
Migration Spring Boot PetClinic REST to Quarkus 1.2.0
 
Angular 2
Angular 2Angular 2
Angular 2
 
Functional Programming in JavaScript & ESNext
Functional Programming in JavaScript & ESNextFunctional Programming in JavaScript & ESNext
Functional Programming in JavaScript & ESNext
 

More from Salesforce Engineering

Locker Service Ready Lightning Components With Webpack
Locker Service Ready Lightning Components With WebpackLocker Service Ready Lightning Components With Webpack
Locker Service Ready Lightning Components With WebpackSalesforce Engineering
 
Techniques to Effectively Monitor the Performance of Customers in the Cloud
Techniques to Effectively Monitor the Performance of Customers in the CloudTechniques to Effectively Monitor the Performance of Customers in the Cloud
Techniques to Effectively Monitor the Performance of Customers in the CloudSalesforce Engineering
 
Predictive System Performance Data Analysis
Predictive System Performance Data AnalysisPredictive System Performance Data Analysis
Predictive System Performance Data AnalysisSalesforce Engineering
 
A Smarter Pig: Building a SQL interface to Pig using Apache Calcite
A Smarter Pig: Building a SQL interface to Pig using Apache CalciteA Smarter Pig: Building a SQL interface to Pig using Apache Calcite
A Smarter Pig: Building a SQL interface to Pig using Apache CalciteSalesforce Engineering
 
Implementing a Content Strategy Is Like Running 100 Miles
Implementing a Content Strategy Is Like Running 100 MilesImplementing a Content Strategy Is Like Running 100 Miles
Implementing a Content Strategy Is Like Running 100 MilesSalesforce Engineering
 
Salesforce Cloud Infrastructure and Challenges - A Brief Overview
Salesforce Cloud Infrastructure and Challenges - A Brief OverviewSalesforce Cloud Infrastructure and Challenges - A Brief Overview
Salesforce Cloud Infrastructure and Challenges - A Brief OverviewSalesforce Engineering
 
Global State Management of Micro Services
Global State Management of Micro ServicesGlobal State Management of Micro Services
Global State Management of Micro ServicesSalesforce Engineering
 
Apache BookKeeper Distributed Store- a Salesforce use case
Apache BookKeeper Distributed Store- a Salesforce use caseApache BookKeeper Distributed Store- a Salesforce use case
Apache BookKeeper Distributed Store- a Salesforce use caseSalesforce Engineering
 

More from Salesforce Engineering (20)

Locker Service Ready Lightning Components With Webpack
Locker Service Ready Lightning Components With WebpackLocker Service Ready Lightning Components With Webpack
Locker Service Ready Lightning Components With Webpack
 
Scaling HBase for Big Data
Scaling HBase for Big DataScaling HBase for Big Data
Scaling HBase for Big Data
 
Techniques to Effectively Monitor the Performance of Customers in the Cloud
Techniques to Effectively Monitor the Performance of Customers in the CloudTechniques to Effectively Monitor the Performance of Customers in the Cloud
Techniques to Effectively Monitor the Performance of Customers in the Cloud
 
Predictive System Performance Data Analysis
Predictive System Performance Data AnalysisPredictive System Performance Data Analysis
Predictive System Performance Data Analysis
 
Apache HBase State of the Project
Apache HBase State of the ProjectApache HBase State of the Project
Apache HBase State of the Project
 
Hit the Trail with Trailhead
Hit the Trail with TrailheadHit the Trail with Trailhead
Hit the Trail with Trailhead
 
HBase/PHOENIX @ Scale
HBase/PHOENIX @ ScaleHBase/PHOENIX @ Scale
HBase/PHOENIX @ Scale
 
Scaling up data science applications
Scaling up data science applicationsScaling up data science applications
Scaling up data science applications
 
Containers and Security for DevOps
Containers and Security for DevOpsContainers and Security for DevOps
Containers and Security for DevOps
 
Monitoring @ Scale in Salesforce
Monitoring @ Scale in SalesforceMonitoring @ Scale in Salesforce
Monitoring @ Scale in Salesforce
 
Performance Tuning with XHProf
Performance Tuning with XHProfPerformance Tuning with XHProf
Performance Tuning with XHProf
 
A Smarter Pig: Building a SQL interface to Pig using Apache Calcite
A Smarter Pig: Building a SQL interface to Pig using Apache CalciteA Smarter Pig: Building a SQL interface to Pig using Apache Calcite
A Smarter Pig: Building a SQL interface to Pig using Apache Calcite
 
Implementing a Content Strategy Is Like Running 100 Miles
Implementing a Content Strategy Is Like Running 100 MilesImplementing a Content Strategy Is Like Running 100 Miles
Implementing a Content Strategy Is Like Running 100 Miles
 
Salesforce Cloud Infrastructure and Challenges - A Brief Overview
Salesforce Cloud Infrastructure and Challenges - A Brief OverviewSalesforce Cloud Infrastructure and Challenges - A Brief Overview
Salesforce Cloud Infrastructure and Challenges - A Brief Overview
 
Koober Preduction IO Presentation
Koober Preduction IO PresentationKoober Preduction IO Presentation
Koober Preduction IO Presentation
 
Finding Security Issues Fast!
Finding Security Issues Fast!Finding Security Issues Fast!
Finding Security Issues Fast!
 
Microservices
MicroservicesMicroservices
Microservices
 
Global State Management of Micro Services
Global State Management of Micro ServicesGlobal State Management of Micro Services
Global State Management of Micro Services
 
The Future of Hbase
The Future of HbaseThe Future of Hbase
The Future of Hbase
 
Apache BookKeeper Distributed Store- a Salesforce use case
Apache BookKeeper Distributed Store- a Salesforce use caseApache BookKeeper Distributed Store- a Salesforce use case
Apache BookKeeper Distributed Store- a Salesforce use case
 

Recently uploaded

Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...AliaaTarek5
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesThousandEyes
 

Recently uploaded (20)

Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
 

Aspect Oriented Programming: Hidden Toolkit That You Already Have

  • 1. Aspect Oriented Programming: Hidden Toolkit That You Already Have Dmitry Vinnik Senior Software Engineer dvinnik@salesforce.com JEEConf 2017
  • 2. Talk Outline ● AOP Overview ● Anatomy of AspectJ ● Spring AOP ● Java Agents Overview ● AOP Implementations
  • 3. Talk Motivation Everyday challenges: profiling, code coverage, HotSwap, and monitoring. Aspect Oriented Programing (AOP) is a solution to all these problems. AOP is a Hidden Toolkit that everyone knows, but very few use. This talk aims to change that.
  • 5. Aspect Oriented Programming (AOP) Overview AOP is Cross-Cutting Concerns paradigm Answers Questions: ● What is my code coverage? ● Is my JVM even running? ● Ahh, do I have to restart my app again? ● How long does this process take?
  • 6. Hidden Toolkit: AOP Simple Example 1: 1 2: 1 ... 39: 63245986 40: 102334155 Process: 1837 ms Code Sample: Output:
  • 8. Hidden Toolkit: AspectJ Overview Defining Aspect 1) Definition 3) Advice 2) Pointc ut
  • 10. Hidden Toolkit: AspectJ Pointcuts Anatomy of Pointcut 1) Definition 2) Ty pe 3) Expressi on
  • 11. Hidden Toolkit: AspectJ Pointcuts - Continue Methods/Constructors: 1) call(Signature) 2) execution(Signature) Fields (specific to AspectJ): 1) get(Signature) 2) set(Signature) Exceptions Handler: 1) handler(TypePattern) Types of Pointcuts
  • 12. Hidden Toolkit: AspectJ Pointcuts - Continue 1) Signature 1) TypePattern Pointcut Expressions 3) Pointcut/Combination
  • 14. Hidden Toolkit: AspectJ Advice Anatomy of AspectJ Advice 1) Advice Type 2) Pointcut Binding 3) Main Logic
  • 15. Hidden Toolkit: AspectJ Advice - Continue Types of Advices 1) Before 1) After 1) Around
  • 16. Hidden Toolkit: AspectJ Advice - Continue 1. Single Pointcut 2. Joint Pointcuts 3. Inline Pointcut 4. Parameterized Pointcut Pointcut Binding
  • 18. Hidden Toolkit: AspectJ - Advanced 1) Generics 2) Abstract Aspects 3) Declare Parents 4) Declare Soft Generics and Declarations
  • 19. Hidden Toolkit: AspectJ Execution 1) Switching to ‘ajc’ compiler Aspect Process started 1: 1 2: 1 ... 39: 63245986 40: 102334155 Aspect Process took: 1845 ms 2) Run function bound by the Aspect 3) Output:
  • 21. Hidden Toolkit: AspectJ - Annotations Usage 1) Aspect Initialization 1) Pointcut Definition Annotations Development Style - Aspect Core
  • 22. Hidden Toolkit: AspectJ - Annotations Usage 1) Before 1) After 1) Around Annotations Development Style - Advices
  • 23. Hidden Toolkit: Spring AOP Spring AOP Overview
  • 24. Hidden Toolkit: Spring AOP - Configuration @Configuration and XML XML@Configuration
  • 25. Hidden Toolkit: Spring AOP - AspectJ Annotation Native AspectJ Support: 1. Aspect 2. Pointcut 3. Before 4. After 5. Around Spring AspectJ Support
  • 26. Hidden Toolkit: Spring AOP - Schema-Based Aspects XML Aspects: 1. Aspect 2. Pointcut 3. Before 4. After 5. Around Spring XML-based Aspects
  • 27. Hidden Toolkit: Spring AOP - AspectJ vs. Schema AspectJ Annotations: ● (+) DRY by-design ● (+) Pointcut combination ● (+) Reusable outside of Spring ● (-) Requires >Java 5 support Spring XML: ● (+) Best for Enterprise services ● (+) Summary of enabled aspects ● (-) No separation of concerns ● (-) No Pointcut combinations Comparing Two Approaches
  • 28. Hidden Toolkit: Spring AOP - Limitations ● No Field-level interception allowed (i.e. #set(), #get()) ● Limited support for objects not managed by Spring ● No support for certain general pointcuts (ex. handler, call) Limitation of Spring In Comparison With Native AspectJ
  • 29. Hidden Toolkit: Anatomy of Java Agents Overview
  • 30. Hidden Toolkit: Anatomy of Java Agents Building Java Agents 1) Premain Java Agent class 2) Implement ClassFileTransformer (next slide) 3) Compile java agent and run as: java -javaagent:simple-agent.jar -jar test-app.jar
  • 31. Hidden Toolkit: Building Java Agents Defining Class Transformer
  • 33. AOP Implementations Main Types: 1. Code Coverage: JaCoCo, Clover 2. Benchmarks/Profilers: JMH, AppDynamics 3. Improved Compilation: HotswapAgent, JRebel 4. Application Monitoring: AppDynamics Main Types of AOP Implementations
  • 35. AOP Implementation: Code Coverage JaCoCo[1] Report: Class Info:
  • 36. AOP Implementation: Code Coverage - Continue ● No setup required (i.e. Java Agent) ● Produces detailed reports of Code Coverage ● Highlights coverage down to code lines ● Instruments Running/Pre-Execution code Why AOP with JaCoCo?
  • 37. AOP Implementation: Code Coverage - Continue ● Classes are instrumented on the fly by Java Agent a. Performs in-memory pre-processing of all files b. Instruments using java.lang.instrument.Instrumentation ● Collects coverage data into .exec files ● Process collected data into .html reports How It Actually Works
  • 39. AOP Implementation: Benchmarks # Benchmark mode: Throughput, ops/time # Benchmark: org.sample.MyBenchmark.testMethod # Run progress: 0.00% complete, ETA 00:06:40 # Fork: 1 of 10 # Warmup Iteration 1: 0.414 ops/s # Warmup Iteration 2: 0.416 ops/s # Warmup Iteration 3: 0.417 ops/s Java Microbenchmark Harness, JMH[1] Code Sample: Output:
  • 40. AOP Implementation: Benchmark - Continue ● Reliable measure of individual units (ex. microservices) ● Supported by Oracle ● Highly customizable: • State • Time Unit • Mode Why AOP with JMH?
  • 42. AOP Implementation: Improved Compilation Default Java Hotswap handles re-compilation of java files. Does Not Handle: ● Renaming/Addition/Deletion of Methods ● Changes to Static/Non-Static Fields ● Changes to Enum Classes ● Changes to Class Hierarchy (interfaces/superclasses) Java Hotswap
  • 43. AOP Implementation: Improved Compilation ● Java Agent that handles imperfections of Java Hotswap. ● Can be run as a javaagent on a start of JVM: • java -XXaltjvm=dcevm -javaagent:hotswap-agent.jar test-app.jar ● Can be attached to running JVM via com.sun.tools.attach.VirtualMachine calls ● Currently in beta version Note: Java agents like HotswapAgent do not directly change main binaries, but rather modify proxied copy of the binaries. HotswapAgent[1]
  • 44. AOP Implementation: Improved Compilation ● No setup required (i.e. Java Agent) ● Productivity Booster (especially in enterprise) ● More Control over JVM ● Verbose Logging Why AOP with HotswapAgent?
  • 46. AOP Implementations: Other Solutions ● Atlassian Clover (Code Coverage) ● JCov (Code Coverage) ● AppDynamics (Benchmark, Monitoring) ● Statsd-JVM (Profiler) ● JRebel (Improved Compilation)
  • 47. Q/A
  • 48. About Speaker Twitter: @DmitryVinnik LinkedIn: in/dmitry-vinnik/ Email: dvinnik@salesforce.com Dmitry Vinnik

Editor's Notes

  1. [1] EclEmma, Java Code Coverage, http://www.jacoco.org/
  2. [1] OpenJDK, JMH, http://openjdk.java.net/projects/code-tools/jmh/
  3. [1] Github, HotswapAgent, https://github.com/HotswapProjects/HotswapAgent
  4. [1] Atlassian Documentation, Atlassian Clover, https://confluence.atlassian.com/clover/about-clover-71598399.html [2] OpenJDK, JCov, https://wiki.openjdk.java.net/display/CodeTools/jcov [3] Cisco, AppDynamics, https://www.appdynamics.com/ [4] Github, statsd-jvm-profiler, https://github.com/etsy/statsd-jvm-profiler [5] ZeroTurnaround, JRebel, https://zeroturnaround.com/software/jrebel/