Enviar pesquisa
Carregar
Java Code to Java Heap - En Français
•
3 gostaram
•
1,649 visualizações
Chris Bailey
Seguir
Tecnologia
Notícias e política
Denunciar
Compartilhar
Denunciar
Compartilhar
1 de 38
Baixar agora
Baixar para ler offline
Recomendados
Impact2014: Introduction to the IBM Java Tools
Impact2014: Introduction to the IBM Java Tools
Chris Bailey
Impact2014: Practical Performance Troubleshooting
Impact2014: Practical Performance Troubleshooting
Chris Bailey
JavaOne2013: Securing Java in the Server Room - Tim Ellison
JavaOne2013: Securing Java in the Server Room - Tim Ellison
Chris Bailey
Real World Java Compatibility (Tim Ellison)
Real World Java Compatibility (Tim Ellison)
Chris Bailey
Java security in the real world (Ryan Sciampacone)
Java security in the real world (Ryan Sciampacone)
Chris Bailey
JavaOne2013: Implement a High Level Parallel API - Richard Ning
JavaOne2013: Implement a High Level Parallel API - Richard Ning
Chris Bailey
Tuning IBMs Generational GC
Tuning IBMs Generational GC
Chris Bailey
JavaOne2013: Secure Engineering Practices for Java
JavaOne2013: Secure Engineering Practices for Java
Chris Bailey
Recomendados
Impact2014: Introduction to the IBM Java Tools
Impact2014: Introduction to the IBM Java Tools
Chris Bailey
Impact2014: Practical Performance Troubleshooting
Impact2014: Practical Performance Troubleshooting
Chris Bailey
JavaOne2013: Securing Java in the Server Room - Tim Ellison
JavaOne2013: Securing Java in the Server Room - Tim Ellison
Chris Bailey
Real World Java Compatibility (Tim Ellison)
Real World Java Compatibility (Tim Ellison)
Chris Bailey
Java security in the real world (Ryan Sciampacone)
Java security in the real world (Ryan Sciampacone)
Chris Bailey
JavaOne2013: Implement a High Level Parallel API - Richard Ning
JavaOne2013: Implement a High Level Parallel API - Richard Ning
Chris Bailey
Tuning IBMs Generational GC
Tuning IBMs Generational GC
Chris Bailey
JavaOne2013: Secure Engineering Practices for Java
JavaOne2013: Secure Engineering Practices for Java
Chris Bailey
High speed networks and Java (Ryan Sciampacone)
High speed networks and Java (Ryan Sciampacone)
Chris Bailey
Introduction to the IBM Java Tools
Introduction to the IBM Java Tools
Chris Bailey
JavaOne 2014: Java Debugging
JavaOne 2014: Java Debugging
Chris Bailey
Practical Performance: Understand and improve the performance of your applica...
Practical Performance: Understand and improve the performance of your applica...
Chris Bailey
JavaOne 2014: Java vs JavaScript
JavaOne 2014: Java vs JavaScript
Chris Bailey
JavaOne 2015: From Java Code to Machine Code
JavaOne 2015: From Java Code to Machine Code
Chris Bailey
Debugging Java from Dumps
Debugging Java from Dumps
Chris Bailey
JavaOne 2013: Memory Efficient Java
JavaOne 2013: Memory Efficient Java
Chris Bailey
From Java code to Java heap: Understanding and optimizing your application's ...
From Java code to Java heap: Understanding and optimizing your application's ...
Chris Bailey
JavaOne2013: Build Your Own Runtime Monitoring for the IBM JDK with the Healt...
JavaOne2013: Build Your Own Runtime Monitoring for the IBM JDK with the Healt...
Chris Bailey
Node Summit 2016: Web App Architectures
Node Summit 2016: Web App Architectures
Chris Bailey
FrenchKit: End to End Application Development with Swift
FrenchKit: End to End Application Development with Swift
Chris Bailey
QCon Shanghai: Trends in Application Development
QCon Shanghai: Trends in Application Development
Chris Bailey
Swift Summit: Pushing the boundaries of Swift to the Server
Swift Summit: Pushing the boundaries of Swift to the Server
Chris Bailey
O'Reilly Software Architecture Conf: Cloud Economics
O'Reilly Software Architecture Conf: Cloud Economics
Chris Bailey
Jpa(1)
Jpa(1)
Assad Lion
Big sql4meetup
Big sql4meetup
Jacques Milman
Base de données
Base de données
SignOrità Śoukâ
Seance_1_cours_introduction_java_Copie.pptx
Seance_1_cours_introduction_java_Copie.pptx
RihabBENLAMINE
_JCVFr
_JCVFr
JC Viens
OSIS 2017 - Scala REX dans Rudder
OSIS 2017 - Scala REX dans Rudder
RUDDER
Conférence "Architecture Android" du 19 Mars 2013 par Mathias Seguy fondateur...
Conférence "Architecture Android" du 19 Mars 2013 par Mathias Seguy fondateur...
Mathias Seguy
Mais conteúdo relacionado
Destaque
High speed networks and Java (Ryan Sciampacone)
High speed networks and Java (Ryan Sciampacone)
Chris Bailey
Introduction to the IBM Java Tools
Introduction to the IBM Java Tools
Chris Bailey
JavaOne 2014: Java Debugging
JavaOne 2014: Java Debugging
Chris Bailey
Practical Performance: Understand and improve the performance of your applica...
Practical Performance: Understand and improve the performance of your applica...
Chris Bailey
JavaOne 2014: Java vs JavaScript
JavaOne 2014: Java vs JavaScript
Chris Bailey
JavaOne 2015: From Java Code to Machine Code
JavaOne 2015: From Java Code to Machine Code
Chris Bailey
Debugging Java from Dumps
Debugging Java from Dumps
Chris Bailey
JavaOne 2013: Memory Efficient Java
JavaOne 2013: Memory Efficient Java
Chris Bailey
From Java code to Java heap: Understanding and optimizing your application's ...
From Java code to Java heap: Understanding and optimizing your application's ...
Chris Bailey
JavaOne2013: Build Your Own Runtime Monitoring for the IBM JDK with the Healt...
JavaOne2013: Build Your Own Runtime Monitoring for the IBM JDK with the Healt...
Chris Bailey
Node Summit 2016: Web App Architectures
Node Summit 2016: Web App Architectures
Chris Bailey
FrenchKit: End to End Application Development with Swift
FrenchKit: End to End Application Development with Swift
Chris Bailey
QCon Shanghai: Trends in Application Development
QCon Shanghai: Trends in Application Development
Chris Bailey
Swift Summit: Pushing the boundaries of Swift to the Server
Swift Summit: Pushing the boundaries of Swift to the Server
Chris Bailey
O'Reilly Software Architecture Conf: Cloud Economics
O'Reilly Software Architecture Conf: Cloud Economics
Chris Bailey
Destaque
(15)
High speed networks and Java (Ryan Sciampacone)
High speed networks and Java (Ryan Sciampacone)
Introduction to the IBM Java Tools
Introduction to the IBM Java Tools
JavaOne 2014: Java Debugging
JavaOne 2014: Java Debugging
Practical Performance: Understand and improve the performance of your applica...
Practical Performance: Understand and improve the performance of your applica...
JavaOne 2014: Java vs JavaScript
JavaOne 2014: Java vs JavaScript
JavaOne 2015: From Java Code to Machine Code
JavaOne 2015: From Java Code to Machine Code
Debugging Java from Dumps
Debugging Java from Dumps
JavaOne 2013: Memory Efficient Java
JavaOne 2013: Memory Efficient Java
From Java code to Java heap: Understanding and optimizing your application's ...
From Java code to Java heap: Understanding and optimizing your application's ...
JavaOne2013: Build Your Own Runtime Monitoring for the IBM JDK with the Healt...
JavaOne2013: Build Your Own Runtime Monitoring for the IBM JDK with the Healt...
Node Summit 2016: Web App Architectures
Node Summit 2016: Web App Architectures
FrenchKit: End to End Application Development with Swift
FrenchKit: End to End Application Development with Swift
QCon Shanghai: Trends in Application Development
QCon Shanghai: Trends in Application Development
Swift Summit: Pushing the boundaries of Swift to the Server
Swift Summit: Pushing the boundaries of Swift to the Server
O'Reilly Software Architecture Conf: Cloud Economics
O'Reilly Software Architecture Conf: Cloud Economics
Semelhante a Java Code to Java Heap - En Français
Jpa(1)
Jpa(1)
Assad Lion
Big sql4meetup
Big sql4meetup
Jacques Milman
Base de données
Base de données
SignOrità Śoukâ
Seance_1_cours_introduction_java_Copie.pptx
Seance_1_cours_introduction_java_Copie.pptx
RihabBENLAMINE
_JCVFr
_JCVFr
JC Viens
OSIS 2017 - Scala REX dans Rudder
OSIS 2017 - Scala REX dans Rudder
RUDDER
Conférence "Architecture Android" du 19 Mars 2013 par Mathias Seguy fondateur...
Conférence "Architecture Android" du 19 Mars 2013 par Mathias Seguy fondateur...
Mathias Seguy
Spark-adabra, Comment Construire un DATALAKE ! (Devoxx 2017)
Spark-adabra, Comment Construire un DATALAKE ! (Devoxx 2017)
univalence
Réussir une montée en charge avec MongoDB
Réussir une montée en charge avec MongoDB
MongoDB
Crs orm
Crs orm
Wael Aniba
Bluesmvc solutionlinux 2012 eric german
Bluesmvc solutionlinux 2012 eric german
eric German
Javascript & tools
Javascript & tools
Slim Soussi
Net duino et le .net micro framework
Net duino et le .net micro framework
Vincent Hubert
Objet Direct Formation Java pour devenir autonome
Objet Direct Formation Java pour devenir autonome
formationobjetdirect
Etat de l'art Server-Side JavaScript - JS Geneve
Etat de l'art Server-Side JavaScript - JS Geneve
Alexandre Morgaut
Introduction à Hibernate p.1
Introduction à Hibernate p.1
ATHMAN HAJ-HAMOU
Présentation1
Présentation1
Boulkenafet samir
.NET Microframework: du code, de l’électronique, de la robotique
.NET Microframework: du code, de l’électronique, de la robotique
Microsoft
CDI mis en pratique avec Seam Social et Weld OSGI
CDI mis en pratique avec Seam Social et Weld OSGI
Antoine Sabot-Durand
CDI par la pratique
CDI par la pratique
Ippon
Semelhante a Java Code to Java Heap - En Français
(20)
Jpa(1)
Jpa(1)
Big sql4meetup
Big sql4meetup
Base de données
Base de données
Seance_1_cours_introduction_java_Copie.pptx
Seance_1_cours_introduction_java_Copie.pptx
_JCVFr
_JCVFr
OSIS 2017 - Scala REX dans Rudder
OSIS 2017 - Scala REX dans Rudder
Conférence "Architecture Android" du 19 Mars 2013 par Mathias Seguy fondateur...
Conférence "Architecture Android" du 19 Mars 2013 par Mathias Seguy fondateur...
Spark-adabra, Comment Construire un DATALAKE ! (Devoxx 2017)
Spark-adabra, Comment Construire un DATALAKE ! (Devoxx 2017)
Réussir une montée en charge avec MongoDB
Réussir une montée en charge avec MongoDB
Crs orm
Crs orm
Bluesmvc solutionlinux 2012 eric german
Bluesmvc solutionlinux 2012 eric german
Javascript & tools
Javascript & tools
Net duino et le .net micro framework
Net duino et le .net micro framework
Objet Direct Formation Java pour devenir autonome
Objet Direct Formation Java pour devenir autonome
Etat de l'art Server-Side JavaScript - JS Geneve
Etat de l'art Server-Side JavaScript - JS Geneve
Introduction à Hibernate p.1
Introduction à Hibernate p.1
Présentation1
Présentation1
.NET Microframework: du code, de l’électronique, de la robotique
.NET Microframework: du code, de l’électronique, de la robotique
CDI mis en pratique avec Seam Social et Weld OSGI
CDI mis en pratique avec Seam Social et Weld OSGI
CDI par la pratique
CDI par la pratique
Mais de Chris Bailey
NodeJS Interactive 2019: FaaS meets Frameworks
NodeJS Interactive 2019: FaaS meets Frameworks
Chris Bailey
Voxxed Micro-services: Serverless JakartaEE - JAX-RS comes to FaaS
Voxxed Micro-services: Serverless JakartaEE - JAX-RS comes to FaaS
Chris Bailey
Silicon Valley Code Camp 2019 - Reaching the Cloud Native World
Silicon Valley Code Camp 2019 - Reaching the Cloud Native World
Chris Bailey
FaaS Meets Java EE: Developing Cloud Native Applications at Speed
FaaS Meets Java EE: Developing Cloud Native Applications at Speed
Chris Bailey
AltConf 2019: Server-Side Swift State of the Union
AltConf 2019: Server-Side Swift State of the Union
Chris Bailey
Server-side Swift with Swagger
Server-side Swift with Swagger
Chris Bailey
Node Summit 2018: Cloud Native Node.js
Node Summit 2018: Cloud Native Node.js
Chris Bailey
Index - BFFs vs GraphQL
Index - BFFs vs GraphQL
Chris Bailey
Swift Cloud Workshop - Swift Microservices
Swift Cloud Workshop - Swift Microservices
Chris Bailey
Swift Cloud Workshop - Codable, the key to Fullstack Swift
Swift Cloud Workshop - Codable, the key to Fullstack Swift
Chris Bailey
Try!Swift India 2017: All you need is Swift
Try!Swift India 2017: All you need is Swift
Chris Bailey
Swift Summit 2017: Server Swift State of the Union
Swift Summit 2017: Server Swift State of the Union
Chris Bailey
IBM Cloud University: Build, Deploy and Scale Node.js Microservices
IBM Cloud University: Build, Deploy and Scale Node.js Microservices
Chris Bailey
IBM Cloud University: Java, Node.js and Swift
IBM Cloud University: Java, Node.js and Swift
Chris Bailey
Node Interactive: Node.js Performance and Highly Scalable Micro-Services
Node Interactive: Node.js Performance and Highly Scalable Micro-Services
Chris Bailey
FrenchKit 2017: Server(less) Swift
FrenchKit 2017: Server(less) Swift
Chris Bailey
AltConf 2017: Full Stack Swift in 30 Minutes
AltConf 2017: Full Stack Swift in 30 Minutes
Chris Bailey
InterConnect: Server Side Swift for Java Developers
InterConnect: Server Side Swift for Java Developers
Chris Bailey
InterConnect: Java, Node.js and Swift - Which, Why and When
InterConnect: Java, Node.js and Swift - Which, Why and When
Chris Bailey
Playgrounds: Mobile + Swift = BFF
Playgrounds: Mobile + Swift = BFF
Chris Bailey
Mais de Chris Bailey
(20)
NodeJS Interactive 2019: FaaS meets Frameworks
NodeJS Interactive 2019: FaaS meets Frameworks
Voxxed Micro-services: Serverless JakartaEE - JAX-RS comes to FaaS
Voxxed Micro-services: Serverless JakartaEE - JAX-RS comes to FaaS
Silicon Valley Code Camp 2019 - Reaching the Cloud Native World
Silicon Valley Code Camp 2019 - Reaching the Cloud Native World
FaaS Meets Java EE: Developing Cloud Native Applications at Speed
FaaS Meets Java EE: Developing Cloud Native Applications at Speed
AltConf 2019: Server-Side Swift State of the Union
AltConf 2019: Server-Side Swift State of the Union
Server-side Swift with Swagger
Server-side Swift with Swagger
Node Summit 2018: Cloud Native Node.js
Node Summit 2018: Cloud Native Node.js
Index - BFFs vs GraphQL
Index - BFFs vs GraphQL
Swift Cloud Workshop - Swift Microservices
Swift Cloud Workshop - Swift Microservices
Swift Cloud Workshop - Codable, the key to Fullstack Swift
Swift Cloud Workshop - Codable, the key to Fullstack Swift
Try!Swift India 2017: All you need is Swift
Try!Swift India 2017: All you need is Swift
Swift Summit 2017: Server Swift State of the Union
Swift Summit 2017: Server Swift State of the Union
IBM Cloud University: Build, Deploy and Scale Node.js Microservices
IBM Cloud University: Build, Deploy and Scale Node.js Microservices
IBM Cloud University: Java, Node.js and Swift
IBM Cloud University: Java, Node.js and Swift
Node Interactive: Node.js Performance and Highly Scalable Micro-Services
Node Interactive: Node.js Performance and Highly Scalable Micro-Services
FrenchKit 2017: Server(less) Swift
FrenchKit 2017: Server(less) Swift
AltConf 2017: Full Stack Swift in 30 Minutes
AltConf 2017: Full Stack Swift in 30 Minutes
InterConnect: Server Side Swift for Java Developers
InterConnect: Server Side Swift for Java Developers
InterConnect: Java, Node.js and Swift - Which, Why and When
InterConnect: Java, Node.js and Swift - Which, Why and When
Playgrounds: Mobile + Swift = BFF
Playgrounds: Mobile + Swift = BFF
Java Code to Java Heap - En Français
1.
Chris Bailey –
IBM Java Service Architect 9th September 2012 From Java Code to Java Heap Comprendre l'utilisation mémoire de votre application © 2012 IBM Corporation
2.
Important Disclaimers THE INFORMATION
CONTAINED IN THIS PRESENTATION IS PROVIDED FOR INFORMATIONAL PURPOSES ONLY. WHILST EFFORTS WERE MADE TO VERIFY THE COMPLETENESS AND ACCURACY OF THE INFORMATION CONTAINED IN THIS PRESENTATION, IT IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED. ALL PERFORMANCE DATA INCLUDED IN THIS PRESENTATION HAVE BEEN GATHERED IN A CONTROLLED ENVIRONMENT. YOUR OWN TEST RESULTS MAY VARY BASED ON HARDWARE, SOFTWARE OR INFRASTRUCTURE DIFFERENCES. ALL DATA INCLUDED IN THIS PRESENTATION ARE MEANT TO BE USED ONLY AS A GUIDE. IN ADDITION, THE INFORMATION CONTAINED IN THIS PRESENTATION IS BASED ON IBM’S CURRENT PRODUCT PLANS AND STRATEGY, WHICH ARE SUBJECT TO CHANGE BY IBM, WITHOUT NOTICE. IBM AND ITS AFFILIATED COMPANIES SHALL NOT BE RESPONSIBLE FOR ANY DAMAGES ARISING OUT OF THE USE OF, OR OTHERWISE RELATED TO, THIS PRESENTATION OR ANY OTHER DOCUMENTATION. NOTHING CONTAINED IN THIS PRESENTATION IS INTENDED TO, OR SHALL HAVE THE EFFECT OF: - CREATING ANY WARRANT OR REPRESENTATION FROM IBM, ITS AFFILIATED COMPANIES OR ITS OR THEIR SUPPLIERS AND/OR LICENSORS 2 From Java Code to Java Heap: Understanding the Memory Usage of Your Application © 2012 IBM Corporation
3.
Agenda ■
Introduction à la gestion de la mémoire ■ Anatomie d'un objet Java ■ Comprendre les Collections Java ■ Analyser votre Collection Java 3 From Java Code to Java Heap: Understanding the Memory Usage of Your Application © 2012 IBM Corporation
4.
Introduction à la
gestion de la mémoire ■ Java fonctionne comme un Systeme d'Exploitation (SE): 0 GB 2 GB 4 GB -Xmx SE et C-Runtime JVM Tas Natif Tas Java 0x40000000 0xC0000000 0x0 0x80000000 0xFFFFFFFF ■ L'architecture et/ou un SE 32bits offre 4 Go d'espace d'adressage par processus – Beaucoup plus grand pour 64bits ■ Une partie est utilisée par le SE et la C-Runtime ■ Une partie est utilisée par le(s) tas Java …et le reste est utilisé pour le tas “natif” ■ Une partie du tas “natif” est pour la Machine Virtuelle Java (JVM) 4 From Java Code to Java Heap: Understanding the Memory Usage of Your Application © 2012 IBM Corporation
5.
Objets Java utilisants
des resources “natives” ■ Certains Objets Java utilisent des ressources du SE – Par conséquent utilisent la mémoire "native" ■ Exemple: java.lang.Thread Tas Java Tas Natif 5 From Java Code to Java Heap: Understanding the Memory Usage of Your Application © 2012 IBM Corporation
6.
Anatomie d'un objet
Java public class CreateInteger { public static void main(String[] args) { Integer myInteger = new Integer(10); } } ■ Question: Quel est la taille d'un objet de type Integer par rapport a int (par example 10) ? (sur une architecture 32bits) (a) x1 (b) x1.5 (c) x2 (d) x3 ■ Solution: (e) x4 !! 6 From Java Code to Java Heap: Understanding the Memory Usage of Your Application © 2012 IBM Corporation
7.
Anatomie d'un objet
Java ■ Objet Metadata: – Class: pointeur sur une classe – Flags: shape, code de hashage, etc – Lock: verrou ou pointeur sur un moniteur – Size: longueur du tableau (tableau seulement) Taille/Bits 0 32 64 96 128 160 192 224 256 288 320 Pointeur Classe Flags Locks int, eg. 10 Java Objet Pointeur Classe Flags Locks Size int, eg. 10 Array Objet 7 From Java Code to Java Heap: Understanding the Memory Usage of Your Application © 2012 IBM Corporation
8.
Anatomie d'un Objet
Java 64 bits ■ Objet Metadata: – Class:pointeur sur une classe – Flags: shape, code de hashage, etc – Lock: verrou ou pointeur sur un moniteur – Size: longueur du tableau (tableau seulement) Taille/Bits 0 32 64 96 128 160 192 224 256 288 320 Class pointer de Classe Pointeur Flags Locks Flags int Locks int, eg. 10 Java Objet Class pointerde Classe Pointeur Flags Locks Flags Size int Locks Size int, eg. 10 Array Objet ■ L'objet Integer occupe 9 fois plus de mémoire que le int ! 8 From Java Code to Java Heap: Understanding the Memory Usage of Your Application © 2012 IBM Corporation
9.
Tailles des différents
types Field Type Field size/bits 32bits 64bits Objet Tableau Objet Tableau boolean 32 8 32 8 byte 32 8 32 8 char 32 16 32 16 short 32 16 32 16 int 32 32 32 32 float 32 32 32 32 long 64 64 64 64 double 64 64 64 64 Objets 32 32 64* 64 *32bits if Compressed References / Compressed Oops enabled 9 From Java Code to Java Heap: Understanding the Memory Usage of Your Application © 2012 IBM Corporation
10.
Compressed References et
CompressedOOPs ■ Transférer une application d'une architecture 32bits à 64bits augmente l'utilisation mémoire: – Le tas Java est 70% plus grand – Le tas “Natif” est 90% plus grand ■ “Compressed References” et “Compressed Ordinary Object Pointers (Compessed Oops)” – Réduire la consommation mémoire pour 64bits – Les metadata et réferences des objets deviennent 32bits ■ En utilisant “Compressed References” ou “Compressed Oops”: – Le tas Java est 0% plus grand – Le tas “Natif” est 90% plus grand 10 From Java Code to Java Heap: Understanding the Memory Usage of Your Application © 2012 IBM Corporation
11.
Pour les objets
plus complexes ■ Exemple: java.lang.String pour “MyString”: public static void main(String[] args) { String myString = new String("MyString"); } Taille/Bits 0 32 64 96 128 160 192 224 256 288 320 Class pointer Flags Locks hash count offset value java.lang.String char char char char char char char char Class pointer Flags Locks Size M Y S T R I N G char[] ■ Pour 128bits de données de type char, on utilise 480bits de mémoire x3.75 plus – Pour un seul caractère char, l'augmentation est de x24 ! 11 From Java Code to Java Heap: Understanding the Memory Usage of Your Application © 2012 IBM Corporation
12.
Collections Java ■
Chaque Collection Java offre un niveau de fonctionnalités différent, cela induit une consommation mémoire différente Plus de function java.util.HashSet Plus de mémoire java.util.HashMap java.util.Hashtable java.util.LinkedList java.util.ArrayList ■ Utiliser le mauvais type de Collection peut engranger une importante surcharge mémoire. 12 From Java Code to Java Heap: Understanding the Memory Usage of Your Application © 2012 IBM Corporation
13.
HashSet
public static void main(String[] args) { HashSet myHashSet = new HashSet(); } ■ Implémentation HashSet de l'interface Set: – “A collection that contains no duplicate elements. More formally, sets contain no pair of elements e1 and e2 such that e1.equals(e2), and at most one null element. As implied by its name, this interface models the mathematical set abstraction. “ • Java Platform SE 6 API doc ■ L'implémentation est un objet HashMap: ■ Capacité par défaut: 16 ■ Taille vide: 144 octets ■ 16 octets / 128 bits en plus de HashMap 13 From Java Code to Java Heap: Understanding the Memory Usage of Your Application © 2012 IBM Corporation
14.
HashMap
public static void main(String[] args) { HashMap myHashMap = new HashMap(); } ■ Implémentation HashMap de l'interface Map: – “An object that maps keys to values. A map cannot contain duplicate keys; each key can map to at most one value.“ • Java Platform SE 6 API doc ■ L'implémentation est un tableau d'objet HashMap$Entry : ■ Capacité par défaut: 16 ■ Taille vide: 128 octets ■ Mémoire utilisée: 48 octets pour la HashMap, plus (16 + (entries * 4octets)) pour le tableau – Ainsi que la mémoire utilisée par les Objets HashMap$Entry 14 From Java Code to Java Heap: Understanding the Memory Usage of Your Application © 2012 IBM Corporation
15.
HashMap$Entry ■
Chaque HashMap$Entry a: – int KeyHash – Objet next – Objet key – Objet value ■ 32 octets par entrée clé ↔ valeur ■ Mémoire utilisée pour HashMap: – 48 octets + 36 octets pour chaque HashMap$Entry ■ Mémoire utilisée pour 10,000 d'entrée est ~360Ko 15 From Java Code to Java Heap: Understanding the Memory Usage of Your Application © 2012 IBM Corporation
16.
Hashtable
public static void main(String[] args) { Hashtable myHashtable = new Hashtable(); } ■ Implémentation Hashtable de l'interface Map : – “This class implements a hashtable, which maps keys to values. Any non-null object can be used as a key or as a value.“ • Java Platform SE 6 API doc ■ L'implémentation est un tableau d'objets Hashtable$Entry : ■ Capacité par défaut: 11 ■ Taille vide: 104 octets ■ Mémoire utilisée: 40 octets pour la Hashtable, plus (16+(entries * 4octets)) pour le tableau – Ainsi que la mémoire utilisée par les objets Hashtable$Entry 16 From Java Code to Java Heap: Understanding the Memory Usage of Your Application © 2012 IBM Corporation
17.
Hashtable$Entry ■
Chaque Hashtable$Entry a: – int KeyHash – Objet next – Objet key – Objet value ■ 32 octets par entrée clé ↔ valeur ■ Mémoire utilisée pour la Hashtable: – 40 octets + 36 octets pour chaque Hashtable$Entry ■ Mémoire utilisée pour 10,000 entrées est ~360K 17 From Java Code to Java Heap: Understanding the Memory Usage of Your Application © 2012 IBM Corporation
18.
LinkedList
public static void main(String[] args) { LinkedList myLinkedList = new LinkedList(); } ■ L'implémentation LinkedList de l'interface List : – “An ordered collection (also known as a sequence). The user of this interface has precise control over where in the list each element is inserted. The user can access elements by their integer index (position in the list), and search for elements in the list. – Unlike sets, lists typically allow duplicate elements. “ • Java Platform SE 6 API doc ■ L'implémentation est une liste chainée d'objets LinkedList$Entry (ou LinkedList$Link): ■ Capacité par défaut: 1 ■ Taille vide: 48 octets ■ Mémoire utilisée: 24 octets pour la LinkedList – Ainsi que la mémoire utilisée par les objets LinkedList$Entry/Link 18 From Java Code to Java Heap: Understanding the Memory Usage of Your Application © 2012 IBM Corporation
19.
LinkedList$Entry / Link ■
Chaque LinkedList$Entry a: – Objet précédant – Objet suivant – Objet entrée ■ 24 octets par entrée ■ Mémoire utilisée pour la LinkedList: – 24 octets, + 24 octets pour chaque LinkedList$Entry ■ Mémoire utilisée pour 10,000 entrées est ~240Ko 19 From Java Code to Java Heap: Understanding the Memory Usage of Your Application © 2012 IBM Corporation
20.
ArrayList
public static void main(String[] args) { ArrayList myArrayList = new ArrayList(); } ■ L'implémentation ArrayList de l'interface List : – “An ordered collection (also known as a sequence). The user of this interface has precise control over where in the list each element is inserted. The user can access elements by their integer index (position in the list), and search for elements in the list. – Unlike sets, lists typically allow duplicate elements. “ • Java Platform SE 6 API doc ■ L'implémentation est un tableau d'objets: ■ Capacité par défaut: 10 ■ Taille vide: 88 octets ■ Mémoire utilisée: 32 octets pour l'ArrayList, plus (16 + (entries * 4octets)) pour le tableau ■ Mémoire utilisée pour 10,000 entrées est ~40Ko 20 From Java Code to Java Heap: Understanding the Memory Usage of Your Application © 2012 IBM Corporation
21.
Autres types de
“Collections” public static void main(String[] args) { StringBuffer myStringBuffer = new StringBuffer(); } ■ StringBuffers peut être consideré comme un type de collection – “A thread-safe, mutable sequence of characters... .... – Every string buffer has a capacity. As long as the length of the character sequence contained in the string buffer does not exceed the capacity, it is not necessary to allocate a new internal buffer array. If the internal buffer overflows, it is automatically made larger.” • Java Platform SE 6 API doc ■ L'implémentation est un tableau de char ■ Capacité par défaut: 16 ■ Taille vide: 72 octets ■ Mémoire utilisée: 24 octets pour le StringBuffer 21 From Java Code to Java Heap: Understanding the Memory Usage of Your Application © 2012 IBM Corporation
22.
Récapitulatif sur les
Collections Collection Capacité par Taille vide Utilisée pour défaut 10,000 HashSet 16 144 360Ko HashMap 16 128 360Ko Hashtable 11 104 360Ko LinkedList 1 48 240Ko ArrayList 10 88 40Ko StringBuffer 16 72 24 22 From Java Code to Java Heap: Understanding the Memory Usage of Your Application © 2012 IBM Corporation
23.
Hash* collections vs
les autres ■ Les Hash* collections sont beaucoup plus grandes – x9 plus grande que ArrayList ■ La taille supplémentaire permet la recherche / insertion / suppression rapide – Constante pour les collections Hash – Augmentation linéaire pour les collections Array ■ L'utilisation d'une collection coûteuse en mémoire peut être la bonne chose à faire – L'important est de savoir quelle collection remplie le mieux la tâche ! 23 From Java Code to Java Heap: Understanding the Memory Usage of Your Application © 2012 IBM Corporation
24.
L'espace vide dans
des collections ■ Les collections qui contiennent des espaces vides introduisent une charge supplémentaire ■ La taille de la collection par défaut peut ne pas être correcte public static void main(String[] args) { StringBuffer myStringBuffer = new StringBuffer(“My String”); } 0 32 64 96 128 160 192 224 256 288 320 352 384 416 448 480 512 544 576 608 640 Class Flags Locks count value java.lang.StringBuffer Class Flags Locks M Y Size charcharcharcharcharcharcharchar charcharcharcharcharcharcharchar S T R I N G char[] ■ La valeur par défaut de 16 pour la StringBuffer n'est pas optimale pour une chaîne de 9 caractères – 7 entrées supplémentaires dans le char[] – 112 octets inutiles 24 From Java Code to Java Heap: Understanding the Memory Usage of Your Application © 2012 IBM Corporation
25.
Expansion des collections ■
Lorsque les collections atteignent leur taille limite, elles s'agrandissent – Augmente considérablement la taille – Réduit considérablement le ratio “mémoire allouée/mémoire utilisée” (Fill Ratio) ■ Mémoire utilisée supplémentaire: 0 32 64 96 128 160 192 224 256 288 320 352 384 416 448 480 512 544 576 608 640 Class Flags Locks count value java.lang.StringBuffer Class Flags Locks M Y Size char charcharcharcharcharcharchar charcharcharcharcharcharcharcharcharcharcharcharcharcharchar charcharcharcharcharcharcharchar S T R I N G O F T E X T char[] ■ 16 nouvelles entrées char [] pour seulement stocker un char supplémentaire – 240 octets inutiles 25 From Java Code to Java Heap: Understanding the Memory Usage of Your Application © 2012 IBM Corporation
26.
Récapitulatif sur les
Collections Collection Capacité par Taille vide Utilisée pour Aggrandissement défaut 10,000 HashSet 16 144 360Ko x2 HashMap 16 128 360Ko x2 Hashtable 11 104 360Ko x2 + 1 LinkedList 1 48 240Ko +1 ArrayList 10 88 40Ko x1.5 StringBuffer 16 72 24 x2 26 From Java Code to Java Heap: Understanding the Memory Usage of Your Application © 2012 IBM Corporation
27.
Récapitulatif sur les
Collections ■ Les Collections existent en grand nombres dans de nombreuses applications Java ■ Exemple: IBM WebSphere Application Server avec PlantsByWebSphere – 5 utilisateurs, 206MB Java heap: HashTable 262,234 instances, 26.5MB of Java heap WeakHashMap 19,562 instances 2.6MB of Java heap HashMap 10,600 instances 2.3MB of Java heap ArrayList 9,530 instances 0.3MB of Java heap HashSet 1,551 instances 1.0MB of Java heap Vector 1,271 instances 0.04MBof Java heap LinkedList 1,148 instances 0.1MB of Java heap TreeMap 299 instances 0.03MB of Java heap 306,195 32.9MB ■ 16% du Tas Java pour les Collection !! 27 From Java Code to Java Heap: Understanding the Memory Usage of Your Application © 2012 IBM Corporation
28.
Analyse de vos
Collections ■ Eclipse Memory Analyzer Tool (MAT) permet l'analyse des Collections Java: 28 From Java Code to Java Heap: Understanding the Memory Usage of Your Application © 2012 IBM Corporation
29.
Analyse de vos
Collections ■ Vous pouvez selectionner une Collection Java (par example: java.util.Hashtable) 29 From Java Code to Java Heap: Understanding the Memory Usage of Your Application © 2012 IBM Corporation
30.
Analyse de vos
Collections ■ 127,016 instances vides de java.util.Hashtable 30 From Java Code to Java Heap: Understanding the Memory Usage of Your Application © 2012 IBM Corporation
31.
Analyse de vos
Collections ■ Vous pouvez obtenir la liste des objets java.util.Hashtable 31 From Java Code to Java Heap: Understanding the Memory Usage of Your Application © 2012 IBM Corporation
32.
Analyse de vos
Collections ■ Les objets java.util.Hashtable stockent les données de session! 32 From Java Code to Java Heap: Understanding the Memory Usage of Your Application © 2012 IBM Corporation
33.
Techniques pour réduire
l'utilisation mémoire ■ Créer les Collections au bon moment – Ne créer une Collection que lorsque vous avez quelque chose à mettre dedans ■ Ne pas créer de Collections pour un Objet unique! ■ Choisir la taille des Collections correctement – Si seulement 2 entrées seront enregistrées, créer une collection de taille 2: HashMap myHashMap = new HashMap(2); ■ Éviter l'expansion de grandes collections en raison de l'algorithme x2 – 32MB de mémoire utilisée pour 17MB de donnéés ■ Les collections ne rétrécissent pas une fois étendues – Il peut être nécessaire de récréer la Collection 33 From Java Code to Java Heap: Understanding the Memory Usage of Your Application © 2012 IBM Corporation
34.
Récapitulatif ■
Les collections surchargent considérablement vos données! ■ Les applications doivent: – Utiliser les bons types de collection, – Eviter les Collections vides ■ Eclipse Memory Analyzer Tool peut analyser vos Collections Java – et l'utilisation de la mémoire de l'ensemble de votre application 34 From Java Code to Java Heap: Understanding the Memory Usage of Your Application © 2012 IBM Corporation
35.
Lire l'article:
From Java Code to Java Heap on IBM developerWorks: http://www.ibm.com/developerworks/java/library/j-codetoheap/index.html 35 From Java Code to Java Heap: Understanding the Memory Usage of Your Application © 2012 IBM Corporation
36.
Télécharger la présentation:
From Java Code to Java Heap on Slideshare.net: http://www.slideshare.net/cnbailey/java-code-to-java-heap 36 From Java Code to Java Heap: Understanding the Memory Usage of Your Application © 2012 IBM Corporation
37.
Références ■
Get Products and Technologies: – IBM Monitoring and Diagnostic Tools for Java: • https://www.ibm.com/developerworks/java/jdk/tools/ – Eclipse Memory Analyzer Tool: • http://eclipse.org/mat/downloads.php ■ Learn: – Debugging from Dumps: • http://www.ibm.com/developerworks/java/library/j-memoryanalyzer/index.html – Why the Memory Analyzer (with IBM Extensions) isn't just for memory leaks anymore: • http://www.ibm.com/developerworks/websphere/techjournal/1103_supauth/1103_sup auth.html ■ Discuss: – IBM on Troubleshooting Java Applications Blog: • https://www.ibm.com/developerworks/mydeveloperworks/blogs/troubleshootingjava/ – IBM Java Runtimes and SDKs Forum: • http://www.ibm.com/developerworks/forums/forum.jspa?forumID=367&start=0 37 From Java Code to Java Heap: Understanding the Memory Usage of Your Application © 2012 IBM Corporation
38.
Copyright and Trademarks ©
IBM Corporation 2012. All Rights Reserved. IBM, the IBM logo, and ibm.com are trademarks or registered trademarks of International Business Machines Corp., and registered in many jurisdictions worldwide. Other product and service names might be trademarks of IBM or other companies. A current list of IBM trademarks is available on the Web – see the IBM “Copyright and trademark information” page at URL: www.ibm.com/legal/copytrade.shtml 38 From Java Code to Java Heap: Understanding the Memory Usage of Your Application © 2012 IBM Corporation
Baixar agora