Browse Source

fix memory crashes on win32/Eigen build

David Rose 14 years ago
parent
commit
6e5dd2cc63

+ 0 - 4
dtool/Config.FreeBSD.pp

@@ -289,10 +289,6 @@
 // We need 64-bit file i/o
 #define __USE_LARGEFILE64 1
 
-// Modern versions of gcc do support the latest STL allocator
-// definitions.
-#define USE_STL_ALLOCATOR 1
-
 // The dynamic library file extension (usually .so .dll or .dylib):
 #define DYNAMIC_LIB_EXT .so
 #define STATIC_LIB_EXT .a

+ 0 - 4
dtool/Config.Linux.pp

@@ -332,10 +332,6 @@
 // We need 64-bit file i/o
 #define __USE_LARGEFILE64 1
 
-// Modern versions of gcc do support the latest STL allocator
-// definitions.
-#define USE_STL_ALLOCATOR 1
-
 // The dynamic library file extension (usually .so .dll or .dylib):
 #define DYNAMIC_LIB_EXT .so
 #define STATIC_LIB_EXT .a

+ 0 - 4
dtool/Config.OSX.pp

@@ -277,10 +277,6 @@
 // Do we have RTTI (and <typeinfo>)?
 #define HAVE_RTTI 1
 
-// Modern versions of gcc do support the latest STL allocator
-// definitions.
-#define USE_STL_ALLOCATOR 1
-
 // Do we have <stdint.h>?
 #define PHAVE_STDINT_H 1
 

+ 0 - 3
dtool/Config.Win32.pp

@@ -160,9 +160,6 @@
 // Do we have <stdint.h>?
 #define PHAVE_STDINT_H
 
-// MSVC7 does support the latest STL allocator definitions.
-#define USE_STL_ALLOCATOR 1
-
 // can Intel C++ build this directory successfully (if not, change CC to msvc)
 #define NOT_INTEL_BUILDABLE false
 

+ 0 - 3
dtool/Config.Win64.pp

@@ -160,9 +160,6 @@
 // Do we have <stdint.h>?
 #define PHAVE_STDINT_H
 
-// MSVC7 does support the latest STL allocator definitions.
-#define USE_STL_ALLOCATOR 1
-
 // can Intel C++ build this directory successfully (if not, change CC to msvc)
 #define NOT_INTEL_BUILDABLE false
 

+ 7 - 0
dtool/Config.pp

@@ -381,6 +381,13 @@
 // on DirectX rendering.
 #defer SUPPORT_IMMEDIATE_MODE $[<= $[OPTIMIZE], 3]
 
+// These are two optional alternative memory-allocation schemes
+// available within Panda.  You can experiment with either of them to
+// see if they give better performance than the system malloc(), but
+// at the time of this writing, it doesn't appear that they do.
+#define USE_MEMORY_DLMALLOC
+#define USE_MEMORY_PTMALLOC2
+
 // Panda contains some experimental code to compile for IPhone.  This
 // requires the Apple IPhone SDK, which is currently only available
 // for OS X platforms.  Set this to either "iPhoneSimulator" or

+ 4 - 36
dtool/LocalSetup.pp

@@ -501,6 +501,10 @@ $[cdefine SIMULATE_NETWORK_DELAY]
 /* Define if we want to allow immediate mode OpenGL rendering.  */
 $[cdefine SUPPORT_IMMEDIATE_MODE]
 
+/* Define for either of the alternative malloc schemes. */
+$[cdefine USE_MEMORY_DLMALLOC]
+$[cdefine USE_MEMORY_PTMALLOC2]
+
 /* Define if we want to compile in support for pipelining.  */
 $[cdefine DO_PIPELINING]
 
@@ -695,38 +699,6 @@ $[cdefine USE_TAU]
 /* Define if needed to have 64-bit file i/o */
 $[cdefine __USE_LARGEFILE64]
 
-/* Which memory allocation scheme should we use? */
-#define USE_MEMORY_DLMALLOC
-#define USE_MEMORY_PTMALLOC2
-#define USE_MEMORY_MALLOC
-#define USE_MEMORY_NOWRAPPERS
-#if $[ALTERNATIVE_MALLOC]
-  #if $[and $[WIN32_PLATFORM], $[HAVE_THREADS], $[not $[SIMPLE_THREADS]]]
-    // A fast thread-safe alternative implementation, but which only
-    // seems to be a good choice on Windows.  (It crashes on Linux and
-    // isn't thread-safe on OSX).
-    #set USE_MEMORY_PTMALLOC2 1
-  #else
-    // A faster, but non-thread-safe, alternative implementation.
-    // When threading support is compiled in, we use a global mutex to
-    // protect it.
-    #set USE_MEMORY_DLMALLOC 1
-  #endif
-#else
-  #if $[DO_MEMORY_USAGE]
-    // Redefine new and delete to malloc(), and also provide hooks for
-    // the benefit of the MemoryUsage class.
-    #set USE_MEMORY_MALLOC 1
-  #else
-    // Don't redefine new and delete at all.
-    #set USE_MEMORY_NOWRAPPERS 1
-  #endif
-#endif
-$[cdefine USE_MEMORY_DLMALLOC]
-$[cdefine USE_MEMORY_PTMALLOC2]
-$[cdefine USE_MEMORY_MALLOC]
-$[cdefine USE_MEMORY_NOWRAPPERS]
-
 // To activate the DELETED_CHAIN macros.
 $[cdefine USE_DELETED_CHAIN]
 
@@ -740,10 +712,6 @@ $[cdefine WANT_NATIVE_NET]
         # pragma warning( disable : 4996 4275 4267 4099 4049 4013 4005 )
 #endif
 
-
-/* Can we define a modern-style STL allocator? */
-$[cdefine USE_STL_ALLOCATOR]
-
 /* Static linkage instead of the normal dynamic linkage? */
 $[cdefine LINK_ALL_STATIC]
 

+ 2 - 3
dtool/pptempl/compilerSettings.pp

@@ -179,7 +179,7 @@
   #define LDFLAGS_OPT3 /NODEFAULTLIB:MSVCRTD.LIB /OPT:REF
   #define LDFLAGS_OPT4 /NODEFAULTLIB:MSVCRTD.LIB /OPT:REF $[LDFLAGS_OPT4]
 
-  #define COMMONFLAGS /DHAVE_DINKUM /Zc:forScope
+  #define COMMONFLAGS /DHAVE_DINKUM /Zc:forScope /bigobj
 
   // use "unsafe" QIfist flt->int rounding only if FAST_FLT_TO_INT is defined
   #define REGULAR_OPTFLAGS /O2 /Ob2 $[if $[ne $[FAST_FLT_TO_INT],], /QIfist,]
@@ -260,8 +260,7 @@
   #define LDFLAGS_OPT3 /NODEFAULTLIB:MSVCRTD.LIB /OPT:REF
   #define LDFLAGS_OPT4 /NODEFAULTLIB:MSVCRTD.LIB /OPT:REF $[LDFLAGS_OPT4]
 
-  // use /bigobj in 64-bit environment
-  #define COMMONFLAGS /DHAVE_DINKUM /Zc:forScope $[if $[eq $[USE_COMPILER],MSVC9x64], /bigobj,]
+  #define COMMONFLAGS /DHAVE_DINKUM /Zc:forScope /bigobj
 
   // use "unsafe" QIfist flt->int rounding only if FAST_FLT_TO_INT is defined
   #define REGULAR_OPTFLAGS /O2 /Ob2 $[if $[ne $[FAST_FLT_TO_INT],], /QIfist,]

+ 12 - 0
dtool/src/dtoolbase/dtoolbase.h

@@ -336,6 +336,18 @@
 #define ALIGN_16BYTE
 #endif
 
+/* Determine our memory-allocation requirements. */
+#if defined(USE_MEMORY_PTMALLOC2) || defined(USE_MEMORY_DLMALLOC) || defined(DO_MEMORY_USAGE)
+/* If we are using our own alternative malloc, or if we're building
+   with DO_MEMORY_USAGE in effect, it follows we need to use our
+   custom STL allocator. */
+#define USE_STL_ALLOCATOR 1
+#else 
+/* Otherwise, if we have no custom memory management needs at all, we
+   might as well turn it all off and go straight to the OS-level
+   calls. */
+#define USE_MEMORY_NOWRAPPERS 1
+#endif
 
 /*
  We define the macros BEGIN_PUBLISH and END_PUBLISH to bracket

+ 15 - 8
dtool/src/dtoolbase/memoryHook.h

@@ -23,22 +23,29 @@
 
 class DeletedBufferChain;
 
+
 // Do we need to implement memory-alignment enforcement within the
 // MemoryHook class, or will the underlying malloc implementation
 // provide it automatically?
-#if defined(USE_MEMORY_DLMALLOC) || defined(USE_MEMORY_PTMALLOC2)
-// Both of these specialized malloc implementations perform the
-// required alignment.
+#if !defined(LINMATH_ALIGN)
+// We don't actually require any special memory-alignment beyond what
+// the underlying implementation is likely to provide anyway.
 #undef MEMORY_HOOK_DO_ALIGN
 
-#elif defined(IS_OSX) || defined(_WIN64)
-// The OS-provided malloc implementation will do the required
+#elif defined(USE_MEMORY_DLMALLOC)
+// This specialized malloc implementation can perform the required
 // alignment.
 #undef MEMORY_HOOK_DO_ALIGN
 
-#elif !defined(LINMATH_ALIGN)
-// We don't actually require any special memory-alignment beyond what
-// the underlying implementation is likely to provide anyway.
+#elif defined(USE_MEMORY_PTMALLOC2)
+// But not this one.  For some reason it crashes when we try to build
+// it with alignment 16.  So if we're using ptmalloc2, we need to
+// enforce alignment externally.
+#define MEMORY_HOOK_DO_ALIGN 1
+
+#elif defined(IS_OSX) || defined(_WIN64)
+// The OS-provided malloc implementation will do the required
+// alignment.
 #undef MEMORY_HOOK_DO_ALIGN
 
 #else

+ 2 - 6
dtool/src/dtoolbase/ptmalloc2_smp_src.cxx

@@ -749,12 +749,8 @@ extern "C" {
   are optimized for the case of 8-byte alignment.
 */
 
-#ifdef LINMATH_ALIGN
-// drose: We require 16-byte alignment of certain structures, to
-// support SSE2.  We don't strictly have to align *everything*, but
-// it's just easier to do so.
-#define MALLOC_ALIGNMENT ((size_t)16U)
-#endif
+/* drose: it turns out that setting MALLOC_ALIGNMENT to 16 doesn't
+   work; something crashes internally.  Too bad. */
 
 #ifndef MALLOC_ALIGNMENT
 #define MALLOC_ALIGNMENT       (2 * SIZE_SZ)

+ 0 - 4
makepanda/makepanda.py

@@ -1526,10 +1526,6 @@ DTOOL_CONFIG=[
     ("IS_OSX",                         'UNDEF',                  'UNDEF'),
     ("IS_FREEBSD",                     'UNDEF',                  'UNDEF'),
     ("GLOBAL_OPERATOR_NEW_EXCEPTIONS", 'UNDEF',                  '1'),
-    ("USE_STL_ALLOCATOR",              '1',                      '1'),
-    ("USE_MEMORY_DLMALLOC",            'UNDEF',                  'UNDEF'),
-    ("USE_MEMORY_PTMALLOC2",           '1',                      'UNDEF'),
-    ("USE_MEMORY_MALLOC",              'UNDEF',                  '1'),
     ("HAVE_EIGEN",                     'UNDEF',                  'UNDEF'),
     ("LINMATH_ALIGN",                  '1',                      '1'),
     ("HAVE_ZLIB",                      'UNDEF',                  'UNDEF'),