SlideShare a Scribd company logo
Do you really get class loaders? Jevgeni KabanovFounder & CTO of ZeroTurnaround
My Background Creator and core developer of JRebel JRebelmaps your project workspace directly to a running application, watches the changes you make to classes and resources, then intelligently reflects them in your application. With JRebel you can get an extra dev month a year by skipping builds & redeploys 30 day trial, just $149 per developer :)
To create JRebel we… Hooked into class loading on the JVM level Integrated with the class loading mechanism in more than 10 different servers Solved hundreds of issues connected to class loading Learned a lot more about class loaders than we wanted to 
Overview Basics What is class loading? How was it meant to work? Problems and solutions How do class loaders leak? OSGi, Spring dm, JBoss and others Conclusions
Basics
Class loader API publicabstractclassClassLoader {   public Class loadClass(String name);   protected Class defineClass(byte[] b);   public URL getResource(String name);   public Enumeration getResources(String name);   publicClassLoadergetParent() }
Class loading publicclass A { publicvoiddoSmth() {     B b = new B(); b.doSmthElse();   } } Causes a call to A.class.getClassLoader().loadClass(“B”);
Delegation Class loaders have a parent class loader The parent is usually consulted first Avoids loading same class several times However in a Java EE web module local classes are searched first In Java EE each WAR module of an EAR gets its own class loader This allows separate namespaces for applications in same container
Java EE Delegation
Problems and solutions
No class found Variants ClassNotFoundException ClassNoDefFoundException Helpful IDE class lookup (Ctrl+Shift+T in Eclipse) find *.jar -exec jar -tf '{}'  | grepMyClass URLClassLoader.getUrls() Container specific logs
Wrong class found Variants IncompatibleClassChangeError AbstractMethodError NoSuch(Method|Field)FoundError ClassCastException, IllegalAccessError Helpful -verbose:class ClassLoader.getResource() javap -private MyClass
More than one class found Variants LinkageError (class loading constraints violated) ClassCastException, IllegalAccessError Helpful -verbose:class ClassLoader.getResource()
More than one class found Shared ClassLoader ClassCastException Util3 Factory3 Factory3.instanceUntyped(); new Util3() Util3 Test3 Web ClassLoader Util3 u = (Util3) Factory3.instanceUntyped();
More than one class found Shared ClassLoader LinkageError Util3 Factory3 Factory3.instance(); new Util3() Util3 Test4 Web ClassLoader Factory3.instance().sayHello();
More than one class found Shared ClassLoader IllegalAccessError Util3 Factory3 Factory3.instancePackage(); new Util3() Util3 Test5 Web ClassLoader Util3 u = (Util3) Factory3.instancePackage();
Reloading an Object OldClassLoader NewClassLoader MyObject.class MyObject.class Recreate the object MyObject MyObject
Leaking ClassLoaders ClassLoader Class1.class Class2.class Class3.class Static Fields Static Fields Static Fields
Leaking ClassLoaders Example.class Example.class Example.class ExampleFactory$1 ExampleFactory$1 ExampleFactory$1 Leak.class Leak.class Leak.class Leak Leak Leak
State of the art
Hierarchy is not enough? Isolation  Different versions of the same library Performance Class lookup is very slow Restricted Why siblings can’t see each other’s classes? OSGi, JBoss, NetBeans and others implement a different system
The Modern Way Each JAR has own class loader All class loaders are siblings, with one central repository Each JAR explicitly declares Packages it exports Packages it imports Repository can find relevant class loaders by package
Modern Filtering classMClassLoaderextendsClassLoader { // Initialized during startup from imports   Set<String> imps; public Class loadClass(Stringname) {     String pkg = name.substring(0,  name.lastIndexOf('.')); if (!imps.contains(pkg)) returnnull; returnrepository.loadClass(name);   } }
Modern Lookup classMRepository {   // Initialized during startup from exports   Map<String,List<MClassLoader>> exps;   publicClass loadClass(String name) {     String pkg = name.substring(0,     name.lastIndexOf('.'));     for (MClassLoadercl : exps.get(pkg)) {       Class result = cl.loadLocalClass(name);       if (result != null) return result;     }     returnnull;   } }
Troubleshooting The same tricks also work with Modern class loading systems ClassLoader.getResource(); -verbose:class Often can be supplemented with custom tools Need to think in terms of export/import in addition to classpath Looking at the pseudocode can help
Problems Too restrictive Import is a one-way street If you want to use Hibernate, you import it, but it cannot access your classes Easy to leak Any references between class loaders are leaks waiting to happen  Deadlocks JVM enforces a global lock on loadClass()
Conclusions The trick of troubleshooting class loaders is understanding how they work :) Modern systems add a level of complexity on top of an abstraction that nobody gets to begin with When redeploying or reloading classes leaking is easy and leads to OOM We need better tools to troubleshoot class loaders!

More Related Content

What's hot

Event Driven Architecture (EDA) Reference Architecture | Anbu Krishnaswamy
Event Driven Architecture (EDA) Reference Architecture | Anbu KrishnaswamyEvent Driven Architecture (EDA) Reference Architecture | Anbu Krishnaswamy
Event Driven Architecture (EDA) Reference Architecture | Anbu KrishnaswamyBob Rhubart
 
Secrets of Performance Tuning Java on Kubernetes
Secrets of Performance Tuning Java on KubernetesSecrets of Performance Tuning Java on Kubernetes
Secrets of Performance Tuning Java on Kubernetes
Bruno Borges
 
Event sourcing - what could possibly go wrong ? Devoxx PL 2021
Event sourcing  - what could possibly go wrong ? Devoxx PL 2021Event sourcing  - what could possibly go wrong ? Devoxx PL 2021
Event sourcing - what could possibly go wrong ? Devoxx PL 2021
Andrzej Ludwikowski
 
Saga about distributed business transactions in microservices world
Saga about distributed business transactions in microservices worldSaga about distributed business transactions in microservices world
Saga about distributed business transactions in microservices world
Mikalai Alimenkou
 
Building Event Driven (Micro)services with Apache Kafka
Building Event Driven (Micro)services with Apache KafkaBuilding Event Driven (Micro)services with Apache Kafka
Building Event Driven (Micro)services with Apache Kafka
Guido Schmutz
 
阿里云CDN技术演进之路
阿里云CDN技术演进之路阿里云CDN技术演进之路
阿里云CDN技术演进之路
Joshua Zhu
 
[백서 요약] Building a Real-Time Bidding Platform on AWS
[백서 요약] Building a Real-Time Bidding Platform on AWS[백서 요약] Building a Real-Time Bidding Platform on AWS
[백서 요약] Building a Real-Time Bidding Platform on AWS
Amazon Web Services Korea
 
Kafka Tutorial - basics of the Kafka streaming platform
Kafka Tutorial - basics of the Kafka streaming platformKafka Tutorial - basics of the Kafka streaming platform
Kafka Tutorial - basics of the Kafka streaming platform
Jean-Paul Azar
 
Maria db 이중화구성_고민하기
Maria db 이중화구성_고민하기Maria db 이중화구성_고민하기
Maria db 이중화구성_고민하기
NeoClova
 
Disaster Recovery Options Running Apache Kafka in Kubernetes with Rema Subra...
 Disaster Recovery Options Running Apache Kafka in Kubernetes with Rema Subra... Disaster Recovery Options Running Apache Kafka in Kubernetes with Rema Subra...
Disaster Recovery Options Running Apache Kafka in Kubernetes with Rema Subra...
HostedbyConfluent
 
Spring + WebSocket integration
Spring + WebSocket integrationSpring + WebSocket integration
Spring + WebSocket integration
Oleksandr Semenov
 
From Mainframe to Microservice: An Introduction to Distributed Systems
From Mainframe to Microservice: An Introduction to Distributed SystemsFrom Mainframe to Microservice: An Introduction to Distributed Systems
From Mainframe to Microservice: An Introduction to Distributed Systems
Tyler Treat
 
AWS Workshop Series: Microsoft licensing and active directory on AWS
AWS Workshop Series: Microsoft licensing and active directory on AWSAWS Workshop Series: Microsoft licensing and active directory on AWS
AWS Workshop Series: Microsoft licensing and active directory on AWS
Amazon Web Services
 
[오픈소스컨설팅] 프로메테우스 모니터링 살펴보고 구성하기
[오픈소스컨설팅] 프로메테우스 모니터링 살펴보고 구성하기[오픈소스컨설팅] 프로메테우스 모니터링 살펴보고 구성하기
[오픈소스컨설팅] 프로메테우스 모니터링 살펴보고 구성하기
Ji-Woong Choi
 
Publish & Subscribe to events using an Event Aggregator
Publish & Subscribe to events using an Event AggregatorPublish & Subscribe to events using an Event Aggregator
Publish & Subscribe to events using an Event Aggregator
Lars-Erik Kindblad
 
High performance and high availability proxies for MySQL
High performance and high availability proxies for MySQLHigh performance and high availability proxies for MySQL
High performance and high availability proxies for MySQL
Mydbops
 
[115]쿠팡 서비스 클라우드 마이그레이션 통해 배운것들
[115]쿠팡 서비스 클라우드 마이그레이션 통해 배운것들[115]쿠팡 서비스 클라우드 마이그레이션 통해 배운것들
[115]쿠팡 서비스 클라우드 마이그레이션 통해 배운것들
NAVER D2
 
Ad-Tech on AWS 세미나 | AWS와 실시간 입찰
Ad-Tech on AWS 세미나 | AWS와 실시간 입찰Ad-Tech on AWS 세미나 | AWS와 실시간 입찰
Ad-Tech on AWS 세미나 | AWS와 실시간 입찰
Amazon Web Services Korea
 
AWS Black Belt Techシリーズ AWS Storage Gateway
AWS Black Belt Techシリーズ  AWS Storage GatewayAWS Black Belt Techシリーズ  AWS Storage Gateway
AWS Black Belt Techシリーズ AWS Storage Gateway
Amazon Web Services Japan
 
Microservice vs. Monolithic Architecture
Microservice vs. Monolithic ArchitectureMicroservice vs. Monolithic Architecture
Microservice vs. Monolithic Architecture
Paul Mooney
 

What's hot (20)

Event Driven Architecture (EDA) Reference Architecture | Anbu Krishnaswamy
Event Driven Architecture (EDA) Reference Architecture | Anbu KrishnaswamyEvent Driven Architecture (EDA) Reference Architecture | Anbu Krishnaswamy
Event Driven Architecture (EDA) Reference Architecture | Anbu Krishnaswamy
 
Secrets of Performance Tuning Java on Kubernetes
Secrets of Performance Tuning Java on KubernetesSecrets of Performance Tuning Java on Kubernetes
Secrets of Performance Tuning Java on Kubernetes
 
Event sourcing - what could possibly go wrong ? Devoxx PL 2021
Event sourcing  - what could possibly go wrong ? Devoxx PL 2021Event sourcing  - what could possibly go wrong ? Devoxx PL 2021
Event sourcing - what could possibly go wrong ? Devoxx PL 2021
 
Saga about distributed business transactions in microservices world
Saga about distributed business transactions in microservices worldSaga about distributed business transactions in microservices world
Saga about distributed business transactions in microservices world
 
Building Event Driven (Micro)services with Apache Kafka
Building Event Driven (Micro)services with Apache KafkaBuilding Event Driven (Micro)services with Apache Kafka
Building Event Driven (Micro)services with Apache Kafka
 
阿里云CDN技术演进之路
阿里云CDN技术演进之路阿里云CDN技术演进之路
阿里云CDN技术演进之路
 
[백서 요약] Building a Real-Time Bidding Platform on AWS
[백서 요약] Building a Real-Time Bidding Platform on AWS[백서 요약] Building a Real-Time Bidding Platform on AWS
[백서 요약] Building a Real-Time Bidding Platform on AWS
 
Kafka Tutorial - basics of the Kafka streaming platform
Kafka Tutorial - basics of the Kafka streaming platformKafka Tutorial - basics of the Kafka streaming platform
Kafka Tutorial - basics of the Kafka streaming platform
 
Maria db 이중화구성_고민하기
Maria db 이중화구성_고민하기Maria db 이중화구성_고민하기
Maria db 이중화구성_고민하기
 
Disaster Recovery Options Running Apache Kafka in Kubernetes with Rema Subra...
 Disaster Recovery Options Running Apache Kafka in Kubernetes with Rema Subra... Disaster Recovery Options Running Apache Kafka in Kubernetes with Rema Subra...
Disaster Recovery Options Running Apache Kafka in Kubernetes with Rema Subra...
 
Spring + WebSocket integration
Spring + WebSocket integrationSpring + WebSocket integration
Spring + WebSocket integration
 
From Mainframe to Microservice: An Introduction to Distributed Systems
From Mainframe to Microservice: An Introduction to Distributed SystemsFrom Mainframe to Microservice: An Introduction to Distributed Systems
From Mainframe to Microservice: An Introduction to Distributed Systems
 
AWS Workshop Series: Microsoft licensing and active directory on AWS
AWS Workshop Series: Microsoft licensing and active directory on AWSAWS Workshop Series: Microsoft licensing and active directory on AWS
AWS Workshop Series: Microsoft licensing and active directory on AWS
 
[오픈소스컨설팅] 프로메테우스 모니터링 살펴보고 구성하기
[오픈소스컨설팅] 프로메테우스 모니터링 살펴보고 구성하기[오픈소스컨설팅] 프로메테우스 모니터링 살펴보고 구성하기
[오픈소스컨설팅] 프로메테우스 모니터링 살펴보고 구성하기
 
Publish & Subscribe to events using an Event Aggregator
Publish & Subscribe to events using an Event AggregatorPublish & Subscribe to events using an Event Aggregator
Publish & Subscribe to events using an Event Aggregator
 
High performance and high availability proxies for MySQL
High performance and high availability proxies for MySQLHigh performance and high availability proxies for MySQL
High performance and high availability proxies for MySQL
 
[115]쿠팡 서비스 클라우드 마이그레이션 통해 배운것들
[115]쿠팡 서비스 클라우드 마이그레이션 통해 배운것들[115]쿠팡 서비스 클라우드 마이그레이션 통해 배운것들
[115]쿠팡 서비스 클라우드 마이그레이션 통해 배운것들
 
Ad-Tech on AWS 세미나 | AWS와 실시간 입찰
Ad-Tech on AWS 세미나 | AWS와 실시간 입찰Ad-Tech on AWS 세미나 | AWS와 실시간 입찰
Ad-Tech on AWS 세미나 | AWS와 실시간 입찰
 
AWS Black Belt Techシリーズ AWS Storage Gateway
AWS Black Belt Techシリーズ  AWS Storage GatewayAWS Black Belt Techシリーズ  AWS Storage Gateway
AWS Black Belt Techシリーズ AWS Storage Gateway
 
Microservice vs. Monolithic Architecture
Microservice vs. Monolithic ArchitectureMicroservice vs. Monolithic Architecture
Microservice vs. Monolithic Architecture
 

Similar to Do you really get class loaders?

Class loader basic
Class loader basicClass loader basic
Class loader basic명철 강
 
Java class loading tips and tricks - Java Colombo Meetup, January, 2014
Java class loading  tips and tricks - Java Colombo Meetup, January, 2014Java class loading  tips and tricks - Java Colombo Meetup, January, 2014
Java class loading tips and tricks - Java Colombo Meetup, January, 2014Sameera Jayasoma
 
Soft-Shake 2016 : Jigsaw est prêt à tuer le classpath
Soft-Shake 2016 : Jigsaw  est prêt à tuer le classpathSoft-Shake 2016 : Jigsaw  est prêt à tuer le classpath
Soft-Shake 2016 : Jigsaw est prêt à tuer le classpath
Alexis Hassler
 
Java Interview Questions Answers Guide
Java Interview Questions Answers GuideJava Interview Questions Answers Guide
Java Interview Questions Answers Guide
DaisyWatson5
 
Java mcq
Java mcqJava mcq
Java mcq
avinash9821
 
Perils Of Url Class Loader
Perils Of Url Class LoaderPerils Of Url Class Loader
Perils Of Url Class LoaderKaniska Mandal
 
Java class loader
Java class loaderJava class loader
Java class loader
benewu
 
Adv kvr -satya
Adv  kvr -satyaAdv  kvr -satya
Adv kvr -satya
Jyothsna Sree
 
Advance java kvr -satya
Advance java  kvr -satyaAdvance java  kvr -satya
Advance java kvr -satya
Satya Johnny
 
Scala presentationjune112011
Scala presentationjune112011Scala presentationjune112011
Scala presentationjune112011
PrasannaKumar Sathyanarayanan
 
Android Training (Java Review)
Android Training (Java Review)Android Training (Java Review)
Android Training (Java Review)
Khaled Anaqwa
 
Advanced java jee material by KV Rao sir
Advanced java jee material by KV Rao sirAdvanced java jee material by KV Rao sir
Advanced java jee material by KV Rao sir
AVINASH KUMAR
 
oops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaoops concept in java | object oriented programming in java
oops concept in java | object oriented programming in java
CPD INDIA
 
Java Class Loading
Java Class LoadingJava Class Loading
Java Class Loading
Sandeep Verma
 
Java Reflection Concept and Working
Java Reflection Concept and WorkingJava Reflection Concept and Working
Java Reflection Concept and Working
Software Productivity Strategists, Inc
 
A Scala tutorial
A Scala tutorialA Scala tutorial
A Scala tutorial
Dima Statz
 
Class
ClassClass
Class
myrajendra
 
Class
ClassClass
Class
myrajendra
 
Framework prototype
Framework prototypeFramework prototype
Framework prototype
DevMix
 

Similar to Do you really get class loaders? (20)

Class loader basic
Class loader basicClass loader basic
Class loader basic
 
Java class loading tips and tricks - Java Colombo Meetup, January, 2014
Java class loading  tips and tricks - Java Colombo Meetup, January, 2014Java class loading  tips and tricks - Java Colombo Meetup, January, 2014
Java class loading tips and tricks - Java Colombo Meetup, January, 2014
 
Soft-Shake 2016 : Jigsaw est prêt à tuer le classpath
Soft-Shake 2016 : Jigsaw  est prêt à tuer le classpathSoft-Shake 2016 : Jigsaw  est prêt à tuer le classpath
Soft-Shake 2016 : Jigsaw est prêt à tuer le classpath
 
Java Interview Questions Answers Guide
Java Interview Questions Answers GuideJava Interview Questions Answers Guide
Java Interview Questions Answers Guide
 
Java mcq
Java mcqJava mcq
Java mcq
 
Perils Of Url Class Loader
Perils Of Url Class LoaderPerils Of Url Class Loader
Perils Of Url Class Loader
 
Java class loader
Java class loaderJava class loader
Java class loader
 
Adv kvr -satya
Adv  kvr -satyaAdv  kvr -satya
Adv kvr -satya
 
Advance java kvr -satya
Advance java  kvr -satyaAdvance java  kvr -satya
Advance java kvr -satya
 
Scala presentationjune112011
Scala presentationjune112011Scala presentationjune112011
Scala presentationjune112011
 
Android Training (Java Review)
Android Training (Java Review)Android Training (Java Review)
Android Training (Java Review)
 
Advanced java jee material by KV Rao sir
Advanced java jee material by KV Rao sirAdvanced java jee material by KV Rao sir
Advanced java jee material by KV Rao sir
 
oops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaoops concept in java | object oriented programming in java
oops concept in java | object oriented programming in java
 
Java Class Loading
Java Class LoadingJava Class Loading
Java Class Loading
 
Java Reflection Concept and Working
Java Reflection Concept and WorkingJava Reflection Concept and Working
Java Reflection Concept and Working
 
A Scala tutorial
A Scala tutorialA Scala tutorial
A Scala tutorial
 
Class
ClassClass
Class
 
Class
ClassClass
Class
 
Class
ClassClass
Class
 
Framework prototype
Framework prototypeFramework prototype
Framework prototype
 

Recently uploaded

UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 

Recently uploaded (20)

UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 

Do you really get class loaders?

  • 1. Do you really get class loaders? Jevgeni KabanovFounder & CTO of ZeroTurnaround
  • 2. My Background Creator and core developer of JRebel JRebelmaps your project workspace directly to a running application, watches the changes you make to classes and resources, then intelligently reflects them in your application. With JRebel you can get an extra dev month a year by skipping builds & redeploys 30 day trial, just $149 per developer :)
  • 3. To create JRebel we… Hooked into class loading on the JVM level Integrated with the class loading mechanism in more than 10 different servers Solved hundreds of issues connected to class loading Learned a lot more about class loaders than we wanted to 
  • 4. Overview Basics What is class loading? How was it meant to work? Problems and solutions How do class loaders leak? OSGi, Spring dm, JBoss and others Conclusions
  • 6. Class loader API publicabstractclassClassLoader { public Class loadClass(String name); protected Class defineClass(byte[] b); public URL getResource(String name); public Enumeration getResources(String name); publicClassLoadergetParent() }
  • 7. Class loading publicclass A { publicvoiddoSmth() { B b = new B(); b.doSmthElse(); } } Causes a call to A.class.getClassLoader().loadClass(“B”);
  • 8. Delegation Class loaders have a parent class loader The parent is usually consulted first Avoids loading same class several times However in a Java EE web module local classes are searched first In Java EE each WAR module of an EAR gets its own class loader This allows separate namespaces for applications in same container
  • 11. No class found Variants ClassNotFoundException ClassNoDefFoundException Helpful IDE class lookup (Ctrl+Shift+T in Eclipse) find *.jar -exec jar -tf '{}' | grepMyClass URLClassLoader.getUrls() Container specific logs
  • 12. Wrong class found Variants IncompatibleClassChangeError AbstractMethodError NoSuch(Method|Field)FoundError ClassCastException, IllegalAccessError Helpful -verbose:class ClassLoader.getResource() javap -private MyClass
  • 13. More than one class found Variants LinkageError (class loading constraints violated) ClassCastException, IllegalAccessError Helpful -verbose:class ClassLoader.getResource()
  • 14. More than one class found Shared ClassLoader ClassCastException Util3 Factory3 Factory3.instanceUntyped(); new Util3() Util3 Test3 Web ClassLoader Util3 u = (Util3) Factory3.instanceUntyped();
  • 15. More than one class found Shared ClassLoader LinkageError Util3 Factory3 Factory3.instance(); new Util3() Util3 Test4 Web ClassLoader Factory3.instance().sayHello();
  • 16. More than one class found Shared ClassLoader IllegalAccessError Util3 Factory3 Factory3.instancePackage(); new Util3() Util3 Test5 Web ClassLoader Util3 u = (Util3) Factory3.instancePackage();
  • 17. Reloading an Object OldClassLoader NewClassLoader MyObject.class MyObject.class Recreate the object MyObject MyObject
  • 18. Leaking ClassLoaders ClassLoader Class1.class Class2.class Class3.class Static Fields Static Fields Static Fields
  • 19. Leaking ClassLoaders Example.class Example.class Example.class ExampleFactory$1 ExampleFactory$1 ExampleFactory$1 Leak.class Leak.class Leak.class Leak Leak Leak
  • 21. Hierarchy is not enough? Isolation Different versions of the same library Performance Class lookup is very slow Restricted Why siblings can’t see each other’s classes? OSGi, JBoss, NetBeans and others implement a different system
  • 22. The Modern Way Each JAR has own class loader All class loaders are siblings, with one central repository Each JAR explicitly declares Packages it exports Packages it imports Repository can find relevant class loaders by package
  • 23. Modern Filtering classMClassLoaderextendsClassLoader { // Initialized during startup from imports Set<String> imps; public Class loadClass(Stringname) { String pkg = name.substring(0, name.lastIndexOf('.')); if (!imps.contains(pkg)) returnnull; returnrepository.loadClass(name); } }
  • 24. Modern Lookup classMRepository { // Initialized during startup from exports Map<String,List<MClassLoader>> exps; publicClass loadClass(String name) { String pkg = name.substring(0, name.lastIndexOf('.')); for (MClassLoadercl : exps.get(pkg)) { Class result = cl.loadLocalClass(name); if (result != null) return result; } returnnull; } }
  • 25. Troubleshooting The same tricks also work with Modern class loading systems ClassLoader.getResource(); -verbose:class Often can be supplemented with custom tools Need to think in terms of export/import in addition to classpath Looking at the pseudocode can help
  • 26. Problems Too restrictive Import is a one-way street If you want to use Hibernate, you import it, but it cannot access your classes Easy to leak Any references between class loaders are leaks waiting to happen Deadlocks JVM enforces a global lock on loadClass()
  • 27. Conclusions The trick of troubleshooting class loaders is understanding how they work :) Modern systems add a level of complexity on top of an abstraction that nobody gets to begin with When redeploying or reloading classes leaking is easy and leads to OOM We need better tools to troubleshoot class loaders!

Editor's Notes

  1. Class loaders are Java objectsClass loaders are responsible forFinding resourcesResolving class names into Class objectsOriginally motivated by applets
  2. Every class has a reference to its class loader objectMyClass.class.getClassLoader()