MantisBT
Mantis Bug Tracker Workflow

View Issue Details Jump to Notes ] Related Changesets ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0026551Open CASCADE[OCCT] OCCT:Foundation Classespublic2015-08-12 07:202016-06-09 09:50
Reporterabv 
Assigned Tobugmaster 
PrioritynormalSeverityfeature 
StatusclosedResolutionfixed 
PlatformOSOS Version
Product Version 
Target Version[OCCT] 7.0.0Fixed in Version[OCCT] 7.0.0 
Summary0026551: Optimization of initialization of OCCT RTTI
DescriptionSince about version 6.5.0, OCCT RTTI system initializes all type descriptors defined in a library by the time of loading that library, via use of global variables. This is done in order to prevent possible data races if type descriptors are initialized upon first use (defined as static variables in corresponding getter function) in multithreaded applications.

In OCCT 7 (see 0024947) this feature is also implicitly used to optimize implementation of Standard_Type class: it stores pointers to strings defining its name (user and system) without copying it. This works only if each type descriptor is removed (when last library using it is unloaded) while these pointers are still valid (i.e. they are not part of another library that might have been unloaded previously). Initialization of all descriptors upon library loading is a means to ensure that.

C++11 adds a requirement that static variables should be protected against concurrent initialization (see http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2660.htm [^]), this would make global variables for types not necessary. Unfortunately, this C++11 feature is not supported by Visual Studio until version 15 (GCC supports it since 4.3).

On the other side, even if not guaranteed by compiler, current implementation of OCCT RTTI should make initialization of type objects as static variables reasonably safe, even in case of concurrency. The point is that types are created in single function (Standard_Type::Register()) which is protected by
mutex. Hence, in the the worst case of concurrency static variable (handle to the type) will be initialized twice, by the same pointer. This will lead to twice incrementing reference counter, and leak of the type descriptor when library is unloaded. This should not be harmful (apart of minor memory leak).

Thus it is proposed to eliminate global type variables (Standard_Type::myInstance). The instance of Standard_Type should keep names of the type as string objects (not as pointers to string literals, as now -- these can be already unloaded by the time of destruction of the type descriptor).

That change should reduce time of loading OCCT libraries, and memory consumption (see timings attached to 0024947).
Steps To Reproducea) test perf fclasses bug24947

b) Start DRAW in Debug mode and then exit it by closing window; look for debug asserts
TagsNo tags attached.
Test case number
Attached Filesxlsx file icon occt_perf-2.xlsx (12,912 bytes) 2015-12-13 23:11

- Relationships
related to 0026913closedbugmaster Community Vulnerable mechanism in Standard_Type leads to assert 
related to 0027016closedbugmaster Open CASCADE Restore global type descriptors for old compilers 
related to 0027584closedabv Community __gnu_cxx::recursive_init_error thrown when concurrently accessing STANDARD_TYPE 

-  Notes
(0049070)
git (administrator)
2015-12-12 19:08

Branch CR26551 has been created by abv.

SHA-1: e34b1b3e4ea2eca1b0dd70500e094343ddb6286c


Detailed log of new commits:

Author: abv
Date: Sat Dec 12 19:07:35 2015 +0300

    0026551: Optimization of initialization of OCCT RTTI
    
    Global instances of type descriptors are eliminated as unnecessary

Author: Roman Lygin
Date: Sun Nov 22 14:54:39 2015 +0400

    0026913: Vulnerable mechanism in Standard_Type leads to assert
(0049074)
abv (manager)
2015-12-13 23:24

Change (based on previous fix made for 0026913) is pushed to CR26551, please review.

Note that by my measurements, it yields considerable decrease of size of libraries and load time of OCCT dlls (see attached Excel table), due to elimination of global variables holding type descriptors, and deferring initialization of descriptors to the time of first access.

On modern compilers (VC++ 14, GCC since 4.3, CLang since 2.9) it should be safe, since type descriptors instantiated as static variables in function should be protected against concurrent initialization. On older compilers, this should be safe anyway due to the fact that registry of the types is protected by mutex.

For status of compilers, see "magic statics" or N2660 in:
VC++: https://msdn.microsoft.com/ru-ru/library/hh567368.aspx#concurrencytable [^]
GCC: https://gcc.gnu.org/projects/cxx0x.html [^]
CLang: http://clang.llvm.org/cxx_status.html [^]
(0049077)
kgv (developer)
2015-12-14 09:49

Please test the patch.
(0049219)
bugmaster (administrator)
2015-12-16 21:04

Fix has been tested with fix for issue 0026988
(0049321)
abv (manager)
2015-12-19 14:21

This change proved to be unsafe for VC++ 10 and 12, see 0027016
(0053024)
git (administrator)
2016-04-17 14:01

Branch CR26551 has been deleted by kgv.

SHA-1: e34b1b3e4ea2eca1b0dd70500e094343ddb6286c

- Related Changesets
occt: master 795be040
Timestamp: 2015-12-12 16:07:35
Author: abv
Committer: bugmaster
Details ] Diff ]
0026551: Optimization of initialization of OCCT RTTI

Global instances of type descriptors are eliminated as unnecessary
mod - src/Standard/Standard_Type.cxx Diff ] File ]
mod - src/Standard/Standard_Type.hxx Diff ] File ]

- Issue History
Date Modified Username Field Change
2015-08-12 07:20 abv New Issue
2015-08-12 07:20 abv Assigned To => abv
2015-11-22 13:59 abv Relationship added related to 0026913
2015-12-12 19:08 git Note Added: 0049070
2015-12-13 23:11 abv File Added: occt_perf-2.xlsx
2015-12-13 23:24 abv Note Added: 0049074
2015-12-13 23:24 abv Assigned To abv => kgv
2015-12-13 23:24 abv Status new => resolved
2015-12-14 09:49 kgv Note Added: 0049077
2015-12-14 09:49 kgv Assigned To kgv => bugmaster
2015-12-14 09:49 kgv Status resolved => reviewed
2015-12-16 21:04 bugmaster Note Added: 0049219
2015-12-16 21:04 bugmaster Status reviewed => tested
2015-12-18 15:25 bugmaster Changeset attached => occt master 795be040
2015-12-18 15:25 bugmaster Status tested => verified
2015-12-18 15:25 bugmaster Resolution open => fixed
2015-12-19 14:15 abv Relationship added related to 0027016
2015-12-19 14:21 abv Note Added: 0049321
2016-04-17 14:01 git Note Added: 0053024
2016-04-20 15:42 aiv Fixed in Version => 7.0.0
2016-04-20 15:50 aiv Status verified => closed
2016-06-09 09:50 Roman Lygin Relationship added related to 0027584


Copyright © 2000 - 2020 MantisBT Team
Powered by Mantis Bugtracker