SlideShare une entreprise Scribd logo
1  sur  23
Télécharger pour lire hors ligne
GC in C++0x

  Aug. 8th 2010 / Reading session for GC book

  Yasutaka ATARASHI
  @yak_ex
Self introduction
 Name: Yasutaka ATARASHI
 Twitter ID: yak_ex
 Web: http://yak3.myhome.cx:8080/junks
  (written in Japanese)

 Main languages: C++ / Perl
 Currently, not coding in office
 Coding in programming competitions
  (TopCoder and Codeforces)
 Not familiar with GC
   Therefore, this slide may include errors :p
GC is widely spread
 Languages in Google Code Jam 2010 Qualifier

  1st   C++    4911 6th       Ruby        221
  2nd   Java   2762 7th       PHP         170
  3rd   Python 1459 8th       Perl        146
  4th   C       751 9th       Haskell     118
  5th   C#      648 10th      Pascal       95
GC is widely spread
 Languages in Google Code Jam 2010 Qualifier

  1st   C++    4911 6th       Ruby        221
  2nd   Java   2762 7th       PHP         170
  3rd   Python 1459 8th       Perl        146
  4th   C       751 9th       Haskell     118
  5th   C#      648 10th      Pascal       95
 Yellow means languages with GC
GC is widely spread
 Languages in Google Code Jam 2010 Qualifier

  1st   C++    4911 6th       Ruby        221
  2nd   Java   2762 7th       PHP         170
  3rd   Python 1459 8th       Perl        146
  4th   C       751 9th       Haskell     118
  5th   C#      648 10th      Pascal       95
 Yellow means languages with GC
 C++ is outlier: Widely used but without GC
GC is widely spread
 Languages in Google Code Jam 2010 Qualifier

  1st    C++    4911 6th        Ruby         221
  2nd    Java   2762 7th        PHP          170
  3rd    Python 1459 8th        Perl         146
  4th    C       751 9th        Haskell      118
  5th    C#      648 10th       Pascal        95
 Yellow means languages with GC
 C++ is outlier: Widely used but without GC
    However, C++ is the extreme multi-paradigm language.
     Finally, it has …
C++: The extreme multi-paradigm
language
 The next standard, aka C++0x, has

           Support for
       Garbage Collection
               and
Reachability-Based Leak Detection
C++: The extreme multi-paradigm
language
 The next standard, aka C++0x, has

  Minimal Support for
       Garbage Collection
               and
Reachability-Based Leak Detection
Minimal Support for GC (snip)
 Some concepts
   Traceable pointer object
   Safely-derived pointer (value)
 5 functions
   get_pointer_safety()
   (un)declare_no_pointers()
   (un)declare_reachable()
Some concepts (1)
 Traceable pointer object
   Pointer object, or
   Integer object whose size is enough to hold
     pointer, or
   A sequence of elements in an array of character
     type
     (Probably, strict aliasing rule restricts that they
     type is character type only)
  -> Object that implementation can recognize that it
     may have pointer value
  = Assuming the other area don’t have pointer value
Some concepts (2)
 Safely-derived pointer (value)
    The value returned by ::operator new (e.g. new T), or
    Operations on safely-derived pointer value, or
       Address taken on dereference (e.g. &*p)
       Well-defined pointer arithmetic (e.g. p+1)
       Well-defined pointer conversion
        (e.g. static_cast<void*>(p))
       reinterpret_cast between pointer and integer
        (e.g. reinterpret_cast<intptr_t>(p))
   -> Pointer value that implementation can trace that
       the area designated by the pointer is allocated
        by ::operator new and
       the pointer value is valid
Some concepts (3)
 Safely-derived pointer (value)
                             This is safely-derived pointer value

  T *p = new T;
  intptr_t x = reinterpret_cast<intptr_t>(p) ^ 0x555
  a:
  T *q = reinterpret_cast<T*>(x ^ 0x555);
  T y = *q;

                       This is not safely-derived pointer value

                    This is NOT safely-derived pointer value, either!
                        The value is the same as p but determined
                        not by value but by process
Minimal Support for GC (snip)
 Some concepts
   Traceable pointer object
   Safely-derived pointer (value)
 5 functions
   get_pointer_safety()
   (un)declare_no_pointers()
   (un)declare_reachable()
Function: get_pointer_safety()
 Returns pointer-safety of the
  implementation
                 Behavior does not depend on whether the
   relaxed:     value is safely-derived pointer, like as C++03
                  • relaxed and preferred are implementation-
   preferred:      defined
                      • In the case of “preferred”, there may be
                        leak detector
                      • In VC2010, relaxed is always returned
                        and the other functions has no-effect.
   strict:      Undefined behavior when dereferencing
                 or deallocating via not safely-derived pointer
                 value which declare_reachable(), as
                 described later, is not called for.
Strict pointer safety
 Safely-derived pointer (value)
                             This is safely-derived pointer value

  T *p = new T;
  intptr_t x = reinterpret_cast<intptr_t>(p) ^ 0x555
  a:
  T *q = reinterpret_cast<T*>(x ^ 0x555);
  T y = *q;

                       This is not safely-derived pointer value

                    This is NOT safely-derived pointer value, either!
   Undefined
                        The value is the same as p but determined
   behavior
                        not by value but by process
Function:
(un)declare_no_pointers()
 void declare_no_pointers(char *p,
  size_t n);
 void undeclare_no_pointers(char *p,
  size_t n);
 Declares or undeclares that the
  specified area does not have pointer
  value
-> Enable to restrict scan area by GC
Function: (un)declare_reachable
 void declare_reachable(void *p);
   Declare that object designated by safely-
     derived pointer value p is reachable
  -> Excludes the object from target of GC
 template<class T>
  T* undeclare_reachable(T *p);
   Returns safely-derived pointer value which is the
     same value as p. The object designated by p
     must be reachable.
  -> The object becomes target of GC again
    (NOTE: The return value is safely-derived so that
     the object is not GC-ed while the value is alive)
Usage of (un)declare_reachable()
 Why needed?                    This is safely-derived pointer value

    T *p = new T;
    intptr_t x = reinterpret_cast<intptr_t>(p) ^ 0x555
    a:
    T *q = reinterpret_cast<T*>(x ^ 0x555);
    T y = *q;

                           This is not safely-derived pointer value

                        This is NOT safely-derived pointer value, either!
      Undefined
                            The value is the same as p but determined
      behavior
                            not by value but by process
A GC at label a might reclaim the object designated by p   ???
Usage of (un)declare_reachable()
 Why needed?                    This is safely-derived pointer value

    T *p = new T;
    intptr_t x = reinterpret_cast<intptr_t>(p) ^ 0x555
    a:
    T *q = reinterpret_cast<T*>(x ^ 0x555);
    T y = *q;

                           This is not safely-derived pointer value

                        This is NOT safely-derived pointer value, either!
      Undefined
                            The value is the same as p but determined
      behavior
                            not by value but by process
A GC at label a might reclaim the object designated by p   Optimization
                                                           issue
Usage of (un)declare_reachable()
 Why needed?
    T *p = new T;                                          p is not used
    intptr_t x = reinterpret_cast<intptr_t>(p) ^ 0x555     afterwards
    a:
    T *q = reinterpret_cast<T*>(x ^ 0x555);
    T y = *q;

     NOTE: p, x, q can be assigned to the same register     x is not used
     -> the value p does not exist anywhere at the label a afterwards
     -> the object designated by p (and q) can be collected
     by GC!!
     -> *q causes undefined behavior

A GC at label a might reclaim the object designated by p   Optimization
                                                           issue
Usage of (un)declare_reachable()
       Correct code in C++0x
*p is
reachable     T *p = new T;
=             declare_reachable(p); // Call before disguising
Ignored       intptr_t x = reinterpret_cast<intptr_t>(p) ^ 0x555
by GC         a:
              // T z = *reinterpret_cast<T*>(x ^ 0x555); // Legal
              // Call undeclare_reachable() after disguising
              T *q = undeclare_reachable(reinterpret_cast<T*>(x ^ 0x555));
              T y = *q;
NOTE
- The same value called for declare_reachable is dereferencable even though it is not safely-derived.
- Argument of undeclare_reachable is not needed to be safely-derived, and must be reachable.
- Regarding declare_reachable, the problem is disguising pointer
   Considering functions separated at the a:, the same discussion is applicable w/o optimization.
Summary
 C++0x has minimal support for GC
   Concept: Safely-derived pointer
    = Valid pointer value which is target of GC
   5 new functions
 C++03 behavior is conformant in relaxed
  safety
   Unlikely to release strict-safety implementation
    immediately
 Code disguising pointer value needs
  modification by using
  declare_reachable() / undeclare_reachable()
Reference
 N2670: Minimal Support for Garbage
  Collection and Reachability-Based Leak
  Detection (revised)
  http://www.open-
  std.org/jtc1/sc22/wg21/docs/papers/2008/
  n2670.htm
 Garbage Collection in the Next C++
  Standard
  http://www.hpl.hp.com/techreports/2009/H
  PL-2009-360.pdf

Contenu connexe

Tendances

C++ Function
C++ FunctionC++ Function
C++ FunctionHajar
 
C++ functions presentation by DHEERAJ KATARIA
C++ functions presentation by DHEERAJ KATARIAC++ functions presentation by DHEERAJ KATARIA
C++ functions presentation by DHEERAJ KATARIADheeraj Kataria
 
CS106 Lab 9 - 1D array
CS106 Lab 9 - 1D arrayCS106 Lab 9 - 1D array
CS106 Lab 9 - 1D arrayNada Kamel
 
(chapter 5) A Concise and Practical Introduction to Programming Algorithms in...
(chapter 5) A Concise and Practical Introduction to Programming Algorithms in...(chapter 5) A Concise and Practical Introduction to Programming Algorithms in...
(chapter 5) A Concise and Practical Introduction to Programming Algorithms in...Frank Nielsen
 
Functions in C++
Functions in C++Functions in C++
Functions in C++home
 
Function overloading(C++)
Function overloading(C++)Function overloading(C++)
Function overloading(C++)Ritika Sharma
 
Understanding Javascript Engine to Code Better
Understanding Javascript Engine to Code BetterUnderstanding Javascript Engine to Code Better
Understanding Javascript Engine to Code BetterIhsan Fauzi Rahman
 
CPP Language Basics - Reference
CPP Language Basics - ReferenceCPP Language Basics - Reference
CPP Language Basics - ReferenceMohammed Sikander
 

Tendances (14)

C++ Function
C++ FunctionC++ Function
C++ Function
 
C++ functions presentation by DHEERAJ KATARIA
C++ functions presentation by DHEERAJ KATARIAC++ functions presentation by DHEERAJ KATARIA
C++ functions presentation by DHEERAJ KATARIA
 
CS106 Lab 9 - 1D array
CS106 Lab 9 - 1D arrayCS106 Lab 9 - 1D array
CS106 Lab 9 - 1D array
 
C function
C functionC function
C function
 
Algorithmic Notations
Algorithmic NotationsAlgorithmic Notations
Algorithmic Notations
 
(chapter 5) A Concise and Practical Introduction to Programming Algorithms in...
(chapter 5) A Concise and Practical Introduction to Programming Algorithms in...(chapter 5) A Concise and Practical Introduction to Programming Algorithms in...
(chapter 5) A Concise and Practical Introduction to Programming Algorithms in...
 
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 
Function overloading(C++)
Function overloading(C++)Function overloading(C++)
Function overloading(C++)
 
Functions struct&union
Functions struct&unionFunctions struct&union
Functions struct&union
 
Understanding Javascript Engine to Code Better
Understanding Javascript Engine to Code BetterUnderstanding Javascript Engine to Code Better
Understanding Javascript Engine to Code Better
 
20BCE1734.pdf
20BCE1734.pdf20BCE1734.pdf
20BCE1734.pdf
 
CPP Language Basics - Reference
CPP Language Basics - ReferenceCPP Language Basics - Reference
CPP Language Basics - Reference
 
lets play with "c"..!!! :):)
lets play with "c"..!!! :):)lets play with "c"..!!! :):)
lets play with "c"..!!! :):)
 

En vedette

C++0x in programming competition
C++0x in programming competitionC++0x in programming competition
C++0x in programming competitionyak1ex
 
Tribocracy.com presentation
Tribocracy.com presentationTribocracy.com presentation
Tribocracy.com presentationKwamecorp
 
Brief introduction of Boost.ICL [PDF]
Brief introduction of Boost.ICL [PDF]Brief introduction of Boost.ICL [PDF]
Brief introduction of Boost.ICL [PDF]yak1ex
 
kwamecorp open design
kwamecorp open design kwamecorp open design
kwamecorp open design Kwamecorp
 
Kwamecorp at Droidcon Berlin 2013
Kwamecorp at Droidcon Berlin 2013Kwamecorp at Droidcon Berlin 2013
Kwamecorp at Droidcon Berlin 2013Kwamecorp
 
GC in C++0x
GC in C++0xGC in C++0x
GC in C++0xyak1ex
 
Introduction to programming competition
Introduction to programming competitionIntroduction to programming competition
Introduction to programming competitionyak1ex
 

En vedette (8)

C++0x in programming competition
C++0x in programming competitionC++0x in programming competition
C++0x in programming competition
 
Impossible
ImpossibleImpossible
Impossible
 
Tribocracy.com presentation
Tribocracy.com presentationTribocracy.com presentation
Tribocracy.com presentation
 
Brief introduction of Boost.ICL [PDF]
Brief introduction of Boost.ICL [PDF]Brief introduction of Boost.ICL [PDF]
Brief introduction of Boost.ICL [PDF]
 
kwamecorp open design
kwamecorp open design kwamecorp open design
kwamecorp open design
 
Kwamecorp at Droidcon Berlin 2013
Kwamecorp at Droidcon Berlin 2013Kwamecorp at Droidcon Berlin 2013
Kwamecorp at Droidcon Berlin 2013
 
GC in C++0x
GC in C++0xGC in C++0x
GC in C++0x
 
Introduction to programming competition
Introduction to programming competitionIntroduction to programming competition
Introduction to programming competition
 

Similaire à GC in C++0x [eng]

Cluj.py Meetup: Extending Python in C
Cluj.py Meetup: Extending Python in CCluj.py Meetup: Extending Python in C
Cluj.py Meetup: Extending Python in CSteffen Wenz
 
Crypto cs36 39
Crypto cs36 39Crypto cs36 39
Crypto cs36 39sravanbabu
 
46630497 fun-pointer-1
46630497 fun-pointer-146630497 fun-pointer-1
46630497 fun-pointer-1AmIt Prasad
 
Value Objects, Full Throttle (to be updated for spring TC39 meetings)
Value Objects, Full Throttle (to be updated for spring TC39 meetings)Value Objects, Full Throttle (to be updated for spring TC39 meetings)
Value Objects, Full Throttle (to be updated for spring TC39 meetings)Brendan Eich
 
PVS-Studio team experience: checking various open source projects, or mistake...
PVS-Studio team experience: checking various open source projects, or mistake...PVS-Studio team experience: checking various open source projects, or mistake...
PVS-Studio team experience: checking various open source projects, or mistake...Andrey Karpov
 
02 functions, variables, basic input and output of c++
02   functions, variables, basic input and output of c++02   functions, variables, basic input and output of c++
02 functions, variables, basic input and output of c++Manzoor ALam
 
BKK16-503 Undefined Behavior and Compiler Optimizations – Why Your Program St...
BKK16-503 Undefined Behavior and Compiler Optimizations – Why Your Program St...BKK16-503 Undefined Behavior and Compiler Optimizations – Why Your Program St...
BKK16-503 Undefined Behavior and Compiler Optimizations – Why Your Program St...Linaro
 
Advanced Web Technology ass.pdf
Advanced Web Technology ass.pdfAdvanced Web Technology ass.pdf
Advanced Web Technology ass.pdfsimenehanmut
 
Paradigmas de Linguagens de Programacao - Aula #4
Paradigmas de Linguagens de Programacao - Aula #4Paradigmas de Linguagens de Programacao - Aula #4
Paradigmas de Linguagens de Programacao - Aula #4Ismar Silveira
 
Let Us Learn Lambda Using C# 3.0
Let Us Learn Lambda Using C# 3.0Let Us Learn Lambda Using C# 3.0
Let Us Learn Lambda Using C# 3.0Sheik Uduman Ali
 
Notes about moving from python to c++ py contw 2020
Notes about moving from python to c++ py contw 2020Notes about moving from python to c++ py contw 2020
Notes about moving from python to c++ py contw 2020Yung-Yu Chen
 
Intro To C++ - Class #17: Pointers!, Objects Talking To Each Other
Intro To C++ - Class #17: Pointers!, Objects Talking To Each OtherIntro To C++ - Class #17: Pointers!, Objects Talking To Each Other
Intro To C++ - Class #17: Pointers!, Objects Talking To Each OtherBlue Elephant Consulting
 
openMP loop parallelization
openMP loop parallelizationopenMP loop parallelization
openMP loop parallelizationAlbert DeFusco
 

Similaire à GC in C++0x [eng] (20)

Lecture 1
Lecture 1Lecture 1
Lecture 1
 
Cluj.py Meetup: Extending Python in C
Cluj.py Meetup: Extending Python in CCluj.py Meetup: Extending Python in C
Cluj.py Meetup: Extending Python in C
 
Crypto cs36 39
Crypto cs36 39Crypto cs36 39
Crypto cs36 39
 
46630497 fun-pointer-1
46630497 fun-pointer-146630497 fun-pointer-1
46630497 fun-pointer-1
 
Value Objects, Full Throttle (to be updated for spring TC39 meetings)
Value Objects, Full Throttle (to be updated for spring TC39 meetings)Value Objects, Full Throttle (to be updated for spring TC39 meetings)
Value Objects, Full Throttle (to be updated for spring TC39 meetings)
 
Lecture2.ppt
Lecture2.pptLecture2.ppt
Lecture2.ppt
 
PVS-Studio team experience: checking various open source projects, or mistake...
PVS-Studio team experience: checking various open source projects, or mistake...PVS-Studio team experience: checking various open source projects, or mistake...
PVS-Studio team experience: checking various open source projects, or mistake...
 
Code optimization
Code optimization Code optimization
Code optimization
 
Code optimization
Code optimization Code optimization
Code optimization
 
02 functions, variables, basic input and output of c++
02   functions, variables, basic input and output of c++02   functions, variables, basic input and output of c++
02 functions, variables, basic input and output of c++
 
BKK16-503 Undefined Behavior and Compiler Optimizations – Why Your Program St...
BKK16-503 Undefined Behavior and Compiler Optimizations – Why Your Program St...BKK16-503 Undefined Behavior and Compiler Optimizations – Why Your Program St...
BKK16-503 Undefined Behavior and Compiler Optimizations – Why Your Program St...
 
C++ Language
C++ LanguageC++ Language
C++ Language
 
Lecture 3 c++
Lecture 3 c++Lecture 3 c++
Lecture 3 c++
 
Advanced Web Technology ass.pdf
Advanced Web Technology ass.pdfAdvanced Web Technology ass.pdf
Advanced Web Technology ass.pdf
 
Paradigmas de Linguagens de Programacao - Aula #4
Paradigmas de Linguagens de Programacao - Aula #4Paradigmas de Linguagens de Programacao - Aula #4
Paradigmas de Linguagens de Programacao - Aula #4
 
Let Us Learn Lambda Using C# 3.0
Let Us Learn Lambda Using C# 3.0Let Us Learn Lambda Using C# 3.0
Let Us Learn Lambda Using C# 3.0
 
Notes about moving from python to c++ py contw 2020
Notes about moving from python to c++ py contw 2020Notes about moving from python to c++ py contw 2020
Notes about moving from python to c++ py contw 2020
 
Function in C program
Function in C programFunction in C program
Function in C program
 
Intro To C++ - Class #17: Pointers!, Objects Talking To Each Other
Intro To C++ - Class #17: Pointers!, Objects Talking To Each OtherIntro To C++ - Class #17: Pointers!, Objects Talking To Each Other
Intro To C++ - Class #17: Pointers!, Objects Talking To Each Other
 
openMP loop parallelization
openMP loop parallelizationopenMP loop parallelization
openMP loop parallelization
 

Plus de yak1ex

C++0x in programming competition
C++0x in programming competitionC++0x in programming competition
C++0x in programming competitionyak1ex
 
Introduction to programming competition [revised][PDF]
Introduction to programming competition [revised][PDF]Introduction to programming competition [revised][PDF]
Introduction to programming competition [revised][PDF]yak1ex
 
Introduction to programming competition [revised]
Introduction to programming competition [revised]Introduction to programming competition [revised]
Introduction to programming competition [revised]yak1ex
 
Impractical Introduction of Boost Spirit Qi [PPT]
Impractical Introduction of Boost Spirit Qi [PPT]Impractical Introduction of Boost Spirit Qi [PPT]
Impractical Introduction of Boost Spirit Qi [PPT]yak1ex
 
Brief introduction of Boost.ICL
Brief introduction of Boost.ICLBrief introduction of Boost.ICL
Brief introduction of Boost.ICLyak1ex
 
Brief introduction of Boost.ICL
Brief introduction of Boost.ICLBrief introduction of Boost.ICL
Brief introduction of Boost.ICLyak1ex
 

Plus de yak1ex (6)

C++0x in programming competition
C++0x in programming competitionC++0x in programming competition
C++0x in programming competition
 
Introduction to programming competition [revised][PDF]
Introduction to programming competition [revised][PDF]Introduction to programming competition [revised][PDF]
Introduction to programming competition [revised][PDF]
 
Introduction to programming competition [revised]
Introduction to programming competition [revised]Introduction to programming competition [revised]
Introduction to programming competition [revised]
 
Impractical Introduction of Boost Spirit Qi [PPT]
Impractical Introduction of Boost Spirit Qi [PPT]Impractical Introduction of Boost Spirit Qi [PPT]
Impractical Introduction of Boost Spirit Qi [PPT]
 
Brief introduction of Boost.ICL
Brief introduction of Boost.ICLBrief introduction of Boost.ICL
Brief introduction of Boost.ICL
 
Brief introduction of Boost.ICL
Brief introduction of Boost.ICLBrief introduction of Boost.ICL
Brief introduction of Boost.ICL
 

Dernier

08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 

Dernier (20)

08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 

GC in C++0x [eng]

  • 1. GC in C++0x Aug. 8th 2010 / Reading session for GC book Yasutaka ATARASHI @yak_ex
  • 2. Self introduction  Name: Yasutaka ATARASHI  Twitter ID: yak_ex  Web: http://yak3.myhome.cx:8080/junks (written in Japanese)  Main languages: C++ / Perl  Currently, not coding in office  Coding in programming competitions (TopCoder and Codeforces)  Not familiar with GC  Therefore, this slide may include errors :p
  • 3. GC is widely spread  Languages in Google Code Jam 2010 Qualifier 1st C++ 4911 6th Ruby 221 2nd Java 2762 7th PHP 170 3rd Python 1459 8th Perl 146 4th C 751 9th Haskell 118 5th C# 648 10th Pascal 95
  • 4. GC is widely spread  Languages in Google Code Jam 2010 Qualifier 1st C++ 4911 6th Ruby 221 2nd Java 2762 7th PHP 170 3rd Python 1459 8th Perl 146 4th C 751 9th Haskell 118 5th C# 648 10th Pascal 95  Yellow means languages with GC
  • 5. GC is widely spread  Languages in Google Code Jam 2010 Qualifier 1st C++ 4911 6th Ruby 221 2nd Java 2762 7th PHP 170 3rd Python 1459 8th Perl 146 4th C 751 9th Haskell 118 5th C# 648 10th Pascal 95  Yellow means languages with GC  C++ is outlier: Widely used but without GC
  • 6. GC is widely spread  Languages in Google Code Jam 2010 Qualifier 1st C++ 4911 6th Ruby 221 2nd Java 2762 7th PHP 170 3rd Python 1459 8th Perl 146 4th C 751 9th Haskell 118 5th C# 648 10th Pascal 95  Yellow means languages with GC  C++ is outlier: Widely used but without GC  However, C++ is the extreme multi-paradigm language. Finally, it has …
  • 7. C++: The extreme multi-paradigm language  The next standard, aka C++0x, has Support for Garbage Collection and Reachability-Based Leak Detection
  • 8. C++: The extreme multi-paradigm language  The next standard, aka C++0x, has Minimal Support for Garbage Collection and Reachability-Based Leak Detection
  • 9. Minimal Support for GC (snip)  Some concepts  Traceable pointer object  Safely-derived pointer (value)  5 functions  get_pointer_safety()  (un)declare_no_pointers()  (un)declare_reachable()
  • 10. Some concepts (1)  Traceable pointer object  Pointer object, or  Integer object whose size is enough to hold pointer, or  A sequence of elements in an array of character type (Probably, strict aliasing rule restricts that they type is character type only) -> Object that implementation can recognize that it may have pointer value = Assuming the other area don’t have pointer value
  • 11. Some concepts (2)  Safely-derived pointer (value)  The value returned by ::operator new (e.g. new T), or  Operations on safely-derived pointer value, or  Address taken on dereference (e.g. &*p)  Well-defined pointer arithmetic (e.g. p+1)  Well-defined pointer conversion (e.g. static_cast<void*>(p))  reinterpret_cast between pointer and integer (e.g. reinterpret_cast<intptr_t>(p)) -> Pointer value that implementation can trace that  the area designated by the pointer is allocated by ::operator new and  the pointer value is valid
  • 12. Some concepts (3)  Safely-derived pointer (value) This is safely-derived pointer value T *p = new T; intptr_t x = reinterpret_cast<intptr_t>(p) ^ 0x555 a: T *q = reinterpret_cast<T*>(x ^ 0x555); T y = *q; This is not safely-derived pointer value This is NOT safely-derived pointer value, either! The value is the same as p but determined not by value but by process
  • 13. Minimal Support for GC (snip)  Some concepts  Traceable pointer object  Safely-derived pointer (value)  5 functions  get_pointer_safety()  (un)declare_no_pointers()  (un)declare_reachable()
  • 14. Function: get_pointer_safety()  Returns pointer-safety of the implementation Behavior does not depend on whether the  relaxed: value is safely-derived pointer, like as C++03 • relaxed and preferred are implementation-  preferred: defined • In the case of “preferred”, there may be leak detector • In VC2010, relaxed is always returned and the other functions has no-effect.  strict: Undefined behavior when dereferencing or deallocating via not safely-derived pointer value which declare_reachable(), as described later, is not called for.
  • 15. Strict pointer safety  Safely-derived pointer (value) This is safely-derived pointer value T *p = new T; intptr_t x = reinterpret_cast<intptr_t>(p) ^ 0x555 a: T *q = reinterpret_cast<T*>(x ^ 0x555); T y = *q; This is not safely-derived pointer value This is NOT safely-derived pointer value, either! Undefined The value is the same as p but determined behavior not by value but by process
  • 16. Function: (un)declare_no_pointers()  void declare_no_pointers(char *p, size_t n);  void undeclare_no_pointers(char *p, size_t n);  Declares or undeclares that the specified area does not have pointer value -> Enable to restrict scan area by GC
  • 17. Function: (un)declare_reachable  void declare_reachable(void *p);  Declare that object designated by safely- derived pointer value p is reachable -> Excludes the object from target of GC  template<class T> T* undeclare_reachable(T *p);  Returns safely-derived pointer value which is the same value as p. The object designated by p must be reachable. -> The object becomes target of GC again (NOTE: The return value is safely-derived so that the object is not GC-ed while the value is alive)
  • 18. Usage of (un)declare_reachable()  Why needed? This is safely-derived pointer value T *p = new T; intptr_t x = reinterpret_cast<intptr_t>(p) ^ 0x555 a: T *q = reinterpret_cast<T*>(x ^ 0x555); T y = *q; This is not safely-derived pointer value This is NOT safely-derived pointer value, either! Undefined The value is the same as p but determined behavior not by value but by process A GC at label a might reclaim the object designated by p ???
  • 19. Usage of (un)declare_reachable()  Why needed? This is safely-derived pointer value T *p = new T; intptr_t x = reinterpret_cast<intptr_t>(p) ^ 0x555 a: T *q = reinterpret_cast<T*>(x ^ 0x555); T y = *q; This is not safely-derived pointer value This is NOT safely-derived pointer value, either! Undefined The value is the same as p but determined behavior not by value but by process A GC at label a might reclaim the object designated by p Optimization issue
  • 20. Usage of (un)declare_reachable()  Why needed? T *p = new T; p is not used intptr_t x = reinterpret_cast<intptr_t>(p) ^ 0x555 afterwards a: T *q = reinterpret_cast<T*>(x ^ 0x555); T y = *q; NOTE: p, x, q can be assigned to the same register x is not used -> the value p does not exist anywhere at the label a afterwards -> the object designated by p (and q) can be collected by GC!! -> *q causes undefined behavior A GC at label a might reclaim the object designated by p Optimization issue
  • 21. Usage of (un)declare_reachable()  Correct code in C++0x *p is reachable T *p = new T; = declare_reachable(p); // Call before disguising Ignored intptr_t x = reinterpret_cast<intptr_t>(p) ^ 0x555 by GC a: // T z = *reinterpret_cast<T*>(x ^ 0x555); // Legal // Call undeclare_reachable() after disguising T *q = undeclare_reachable(reinterpret_cast<T*>(x ^ 0x555)); T y = *q; NOTE - The same value called for declare_reachable is dereferencable even though it is not safely-derived. - Argument of undeclare_reachable is not needed to be safely-derived, and must be reachable. - Regarding declare_reachable, the problem is disguising pointer Considering functions separated at the a:, the same discussion is applicable w/o optimization.
  • 22. Summary  C++0x has minimal support for GC  Concept: Safely-derived pointer = Valid pointer value which is target of GC  5 new functions  C++03 behavior is conformant in relaxed safety  Unlikely to release strict-safety implementation immediately  Code disguising pointer value needs modification by using declare_reachable() / undeclare_reachable()
  • 23. Reference  N2670: Minimal Support for Garbage Collection and Reachability-Based Leak Detection (revised) http://www.open- std.org/jtc1/sc22/wg21/docs/papers/2008/ n2670.htm  Garbage Collection in the Next C++ Standard http://www.hpl.hp.com/techreports/2009/H PL-2009-360.pdf