From 980d5a75556f802e412d24b14a48a49c76126e19 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Fri, 31 Aug 2012 16:30:58 -0500 Subject: MAINT-1503 Fix for ll_aligned_realloc returning non-aligned pointers on linux --- indra/llmath/llvolume.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'indra/llmath') diff --git a/indra/llmath/llvolume.cpp b/indra/llmath/llvolume.cpp index c85e1b1fb3..02c8d2b86f 100644 --- a/indra/llmath/llvolume.cpp +++ b/indra/llmath/llvolume.cpp @@ -6693,19 +6693,20 @@ void LLVolumeFace::pushVertex(const LLVector4a& pos, const LLVector4a& norm, con { S32 new_verts = mNumVertices+1; S32 new_size = new_verts*16; -// S32 old_size = mNumVertices*16; + S32 old_size = mNumVertices*16; //positions - mPositions = (LLVector4a*) ll_aligned_realloc_16(mPositions, new_size); + mPositions = (LLVector4a*) ll_aligned_realloc_16(mPositions, new_size, old_size); ll_assert_aligned(mPositions,16); //normals - mNormals = (LLVector4a*) ll_aligned_realloc_16(mNormals, new_size); + mNormals = (LLVector4a*) ll_aligned_realloc_16(mNormals, new_size, old_size); ll_assert_aligned(mNormals,16); //tex coords new_size = ((new_verts*8)+0xF) & ~0xF; - mTexCoords = (LLVector2*) ll_aligned_realloc_16(mTexCoords, new_size); + old_size = ((mNumVertices*8)+0xF) & ~0xF; + mTexCoords = (LLVector2*) ll_aligned_realloc_16(mTexCoords, new_size, old_size); ll_assert_aligned(mTexCoords,16); @@ -6759,7 +6760,7 @@ void LLVolumeFace::pushIndex(const U16& idx) S32 old_size = ((mNumIndices*2)+0xF) & ~0xF; if (new_size != old_size) { - mIndices = (U16*) ll_aligned_realloc_16(mIndices, new_size); + mIndices = (U16*) ll_aligned_realloc_16(mIndices, new_size, old_size); ll_assert_aligned(mIndices,16); } @@ -6801,11 +6802,11 @@ void LLVolumeFace::appendFace(const LLVolumeFace& face, LLMatrix4& mat_in, LLMat } //allocate new buffer space - mPositions = (LLVector4a*) ll_aligned_realloc_16(mPositions, new_count*sizeof(LLVector4a)); + mPositions = (LLVector4a*) ll_aligned_realloc_16(mPositions, new_count*sizeof(LLVector4a), mNumVertices*sizeof(LLVector4a)); ll_assert_aligned(mPositions, 16); - mNormals = (LLVector4a*) ll_aligned_realloc_16(mNormals, new_count*sizeof(LLVector4a)); + mNormals = (LLVector4a*) ll_aligned_realloc_16(mNormals, new_count*sizeof(LLVector4a), mNumVertices*sizeof(LLVector4a)); ll_assert_aligned(mNormals, 16); - mTexCoords = (LLVector2*) ll_aligned_realloc_16(mTexCoords, (new_count*sizeof(LLVector2)+0xF) & ~0xF); + mTexCoords = (LLVector2*) ll_aligned_realloc_16(mTexCoords, (new_count*sizeof(LLVector2)+0xF) & ~0xF, (mNumVertices*sizeof(LLVector2)+0xF) & ~0xF); ll_assert_aligned(mTexCoords, 16); mNumVertices = new_count; @@ -6852,7 +6853,7 @@ void LLVolumeFace::appendFace(const LLVolumeFace& face, LLMatrix4& mat_in, LLMat new_count = mNumIndices + face.mNumIndices; //allocate new index buffer - mIndices = (U16*) ll_aligned_realloc_16(mIndices, (new_count*sizeof(U16)+0xF) & ~0xF); + mIndices = (U16*) ll_aligned_realloc_16(mIndices, (new_count*sizeof(U16)+0xF) & ~0xF, (mNumIndices*sizeof(U16)+0xF) & ~0xF); //get destination address into new index buffer U16* dst_idx = mIndices+mNumIndices; -- cgit v1.2.3 From d1c34bff3787c6228b5d89316079011a7f098cfc Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Mon, 10 Sep 2012 13:16:10 -0500 Subject: Fix for alignment_test.cpp compilation errors. --- indra/llmath/tests/alignment_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/llmath') diff --git a/indra/llmath/tests/alignment_test.cpp b/indra/llmath/tests/alignment_test.cpp index ac0c45ae6f..5c426c57c3 100644 --- a/indra/llmath/tests/alignment_test.cpp +++ b/indra/llmath/tests/alignment_test.cpp @@ -78,7 +78,7 @@ void alignment_test_object_t::test<1>() align_ptr = ll_aligned_malloc_16(sizeof(MyVector4a)); ensure("ll_aligned_malloc_16 failed", is_aligned(align_ptr,16)); - align_ptr = ll_aligned_realloc_16(align_ptr,2*sizeof(MyVector4a)); + align_ptr = ll_aligned_realloc_16(align_ptr,2*sizeof(MyVector4a), sizeof(MyVector4a)); ensure("ll_aligned_realloc_16 failed", is_aligned(align_ptr,16)); ll_aligned_free_16(align_ptr); -- cgit v1.2.3 From 8b4d91e2f32062684b64d6dd9eb86dd89ad078f0 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Tue, 11 Sep 2012 16:58:36 -0500 Subject: Another stab at fixing alignment_test.cpp --- indra/llmath/tests/alignment_test.cpp | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'indra/llmath') diff --git a/indra/llmath/tests/alignment_test.cpp b/indra/llmath/tests/alignment_test.cpp index 5c426c57c3..b28b2cee6e 100644 --- a/indra/llmath/tests/alignment_test.cpp +++ b/indra/llmath/tests/alignment_test.cpp @@ -34,16 +34,6 @@ #include "../llsimdmath.h" #include "../llvector4a.h" -void* operator new(size_t size) -{ - return ll_aligned_malloc_16(size); -} - -void operator delete(void *p) -{ - ll_aligned_free_16(p); -} - namespace tut { @@ -59,6 +49,17 @@ tut::alignment_test_t tut_alignment_test("LLAlignment"); LL_ALIGN_PREFIX(16) class MyVector4a { +public: + void* operator new(size_t size) + { + return ll_aligned_malloc_16(size); + } + + void operator delete(void *p) + { + ll_aligned_free_16(p); + } + LLQuad mQ; } LL_ALIGN_POSTFIX(16); @@ -68,7 +69,7 @@ template<> template<> void alignment_test_object_t::test<1>() { # ifdef LL_DEBUG - skip("This test fails on Windows when compiled in debug mode."); +// skip("This test fails on Windows when compiled in debug mode."); # endif const int num_tests = 7; @@ -105,7 +106,7 @@ template<> template<> void alignment_test_object_t::test<3>() { # ifdef LL_DEBUG - skip("This test fails on Windows when compiled in debug mode."); +// skip("This test fails on Windows when compiled in debug mode."); # endif const int ARR_SIZE = 7; -- cgit v1.2.3 From 094a5bc89ea62110898c775643517173073f9add Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Wed, 12 Sep 2012 16:13:01 -0500 Subject: Attempt to unblock build. --- indra/llmath/tests/alignment_test.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'indra/llmath') diff --git a/indra/llmath/tests/alignment_test.cpp b/indra/llmath/tests/alignment_test.cpp index b28b2cee6e..2f8c50fd5b 100644 --- a/indra/llmath/tests/alignment_test.cpp +++ b/indra/llmath/tests/alignment_test.cpp @@ -68,6 +68,7 @@ public: template<> template<> void alignment_test_object_t::test<1>() { + skip("Skipping known failure."); # ifdef LL_DEBUG // skip("This test fails on Windows when compiled in debug mode."); # endif @@ -94,6 +95,7 @@ void alignment_test_object_t::test<1>() template<> template<> void alignment_test_object_t::test<2>() { + skip("Skipping known failure."); MyVector4a vec1; ensure("LLAlignment vec1 unaligned", is_aligned(&vec1,16)); @@ -105,6 +107,7 @@ void alignment_test_object_t::test<2>() template<> template<> void alignment_test_object_t::test<3>() { + skip("Skipping known failure."); # ifdef LL_DEBUG // skip("This test fails on Windows when compiled in debug mode."); # endif -- cgit v1.2.3 From 8a359ddaea5ff24233b758ee2697234d9e6d0d9c Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Wed, 12 Sep 2012 16:55:19 -0500 Subject: Another attempt at unsticking build. --- indra/llmath/tests/alignment_test.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'indra/llmath') diff --git a/indra/llmath/tests/alignment_test.cpp b/indra/llmath/tests/alignment_test.cpp index 2f8c50fd5b..289d25a63c 100644 --- a/indra/llmath/tests/alignment_test.cpp +++ b/indra/llmath/tests/alignment_test.cpp @@ -73,7 +73,7 @@ void alignment_test_object_t::test<1>() // skip("This test fails on Windows when compiled in debug mode."); # endif - const int num_tests = 7; + /*const int num_tests = 7; void *align_ptr; for (int i=0; i() align_ptr = ll_aligned_malloc_32(sizeof(MyVector4a)); ensure("ll_aligned_malloc_32 failed", is_aligned(align_ptr,32)); ll_aligned_free_32(align_ptr); - } + }*/ } // In-place allocation of objects and arrays. @@ -96,11 +96,11 @@ template<> template<> void alignment_test_object_t::test<2>() { skip("Skipping known failure."); - MyVector4a vec1; + /*MyVector4a vec1; ensure("LLAlignment vec1 unaligned", is_aligned(&vec1,16)); MyVector4a veca[12]; - ensure("LLAlignment veca unaligned", is_aligned(veca,16)); + ensure("LLAlignment veca unaligned", is_aligned(veca,16));*/ } // Heap allocation of objects and arrays. @@ -112,7 +112,7 @@ void alignment_test_object_t::test<3>() // skip("This test fails on Windows when compiled in debug mode."); # endif - const int ARR_SIZE = 7; + /*const int ARR_SIZE = 7; for(int i=0; i() { std::cout << "veca[" << i << "]" << std::endl; ensure("LLAlignment veca member unaligned", is_aligned(&veca[i],16)); - } + }*/ } } -- cgit v1.2.3 From cd315c0ecdf0dbcc6a5fb18d60cbb31ee06e9acd Mon Sep 17 00:00:00 2001 From: "simon@Simon-PC.lindenlab.com" Date: Wed, 12 Sep 2012 16:00:12 -0700 Subject: Fix alignment_test for array allocations. Reviewed by Runitai --- indra/llmath/tests/alignment_test.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'indra/llmath') diff --git a/indra/llmath/tests/alignment_test.cpp b/indra/llmath/tests/alignment_test.cpp index 289d25a63c..bbc68fc498 100644 --- a/indra/llmath/tests/alignment_test.cpp +++ b/indra/llmath/tests/alignment_test.cpp @@ -60,6 +60,16 @@ public: ll_aligned_free_16(p); } + void* operator new[](size_t count) + { // try to allocate count bytes for an array + return ll_aligned_malloc_16(count); + } + + void operator delete[](void *p) + { + ll_aligned_free_16(p); + } + LLQuad mQ; } LL_ALIGN_POSTFIX(16); @@ -112,7 +122,7 @@ void alignment_test_object_t::test<3>() // skip("This test fails on Windows when compiled in debug mode."); # endif - /*const int ARR_SIZE = 7; + const int ARR_SIZE = 7; for(int i=0; i() } MyVector4a *veca = new MyVector4a[ARR_SIZE]; + //std::cout << "veca base is " << (S32) veca << std::endl; ensure("LLAligment veca base", is_aligned(veca,16)); for(int i=0; i Date: Wed, 12 Sep 2012 18:08:35 -0700 Subject: Restore alignment tests that were removed earlier --- indra/llmath/tests/alignment_test.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'indra/llmath') diff --git a/indra/llmath/tests/alignment_test.cpp b/indra/llmath/tests/alignment_test.cpp index bbc68fc498..ced039b2c6 100644 --- a/indra/llmath/tests/alignment_test.cpp +++ b/indra/llmath/tests/alignment_test.cpp @@ -78,12 +78,11 @@ public: template<> template<> void alignment_test_object_t::test<1>() { - skip("Skipping known failure."); # ifdef LL_DEBUG // skip("This test fails on Windows when compiled in debug mode."); # endif - /*const int num_tests = 7; + const int num_tests = 7; void *align_ptr; for (int i=0; i() align_ptr = ll_aligned_malloc_32(sizeof(MyVector4a)); ensure("ll_aligned_malloc_32 failed", is_aligned(align_ptr,32)); ll_aligned_free_32(align_ptr); - }*/ + } } // In-place allocation of objects and arrays. template<> template<> void alignment_test_object_t::test<2>() { - skip("Skipping known failure."); - /*MyVector4a vec1; + MyVector4a vec1; ensure("LLAlignment vec1 unaligned", is_aligned(&vec1,16)); MyVector4a veca[12]; - ensure("LLAlignment veca unaligned", is_aligned(veca,16));*/ + ensure("LLAlignment veca unaligned", is_aligned(veca,16)); } // Heap allocation of objects and arrays. template<> template<> void alignment_test_object_t::test<3>() { - skip("Skipping known failure."); # ifdef LL_DEBUG // skip("This test fails on Windows when compiled in debug mode."); # endif -- cgit v1.2.3 From d5dbd2e9c1b82e475bd5650a39b3c40fd4c5b51d Mon Sep 17 00:00:00 2001 From: Oz Linden Date: Thu, 27 Sep 2012 13:02:07 -0400 Subject: fix dos line endings --- indra/llmath/tests/alignment_test.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'indra/llmath') diff --git a/indra/llmath/tests/alignment_test.cpp b/indra/llmath/tests/alignment_test.cpp index ced039b2c6..5ee3c45502 100644 --- a/indra/llmath/tests/alignment_test.cpp +++ b/indra/llmath/tests/alignment_test.cpp @@ -60,11 +60,11 @@ public: ll_aligned_free_16(p); } - void* operator new[](size_t count) - { // try to allocate count bytes for an array - return ll_aligned_malloc_16(count); - } - + void* operator new[](size_t count) + { // try to allocate count bytes for an array + return ll_aligned_malloc_16(count); + } + void operator delete[](void *p) { ll_aligned_free_16(p); -- cgit v1.2.3 From 7ebbb5067db4e1fc32a0e60449b52e3c110f3207 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Thu, 11 Oct 2012 17:02:45 -0500 Subject: MAINT-1709 Factor out realloc Reviewed by VoidPointer --- indra/llmath/lloctree.h | 52 +++++++++++++++++++++---------------------------- 1 file changed, 22 insertions(+), 30 deletions(-) (limited to 'indra/llmath') diff --git a/indra/llmath/lloctree.h b/indra/llmath/lloctree.h index c3f6f7de2a..68d8110f1d 100644 --- a/indra/llmath/lloctree.h +++ b/indra/llmath/lloctree.h @@ -78,7 +78,7 @@ public: typedef LLOctreeTraveler oct_traveler; typedef LLTreeTraveler tree_traveler; - typedef LLPointer* element_list; + typedef std::vector> element_list; typedef LLPointer* element_iter; typedef const LLPointer* const_element_iter; typedef typename std::vector*>::iterator tree_listener_iter; @@ -106,8 +106,9 @@ public: : mParent((oct_node*)parent), mOctant(octant) { - mData = NULL; - mDataEnd = NULL; + //always keep a NULL terminated list to avoid out of bounds exceptions in debug builds + mData.push_back(NULL); + mDataEnd = &mData[0]; mCenter = center; mSize = size; @@ -133,9 +134,9 @@ public: mData[i] = NULL; } - free(mData); - mData = NULL; - mDataEnd = NULL; + mData.clear(); + mData.push_back(NULL); + mDataEnd = &mData[0]; for (U32 i = 0; i < getChildCount(); i++) { @@ -239,9 +240,9 @@ public: bool isEmpty() const { return mElementCount == 0; } element_list& getData() { return mData; } const element_list& getData() const { return mData; } - element_iter getDataBegin() { return mData; } + element_iter getDataBegin() { return &mData[0]; } element_iter getDataEnd() { return mDataEnd; } - const_element_iter getDataBegin() const { return mData; } + const_element_iter getDataBegin() const { return &mData[0]; } const_element_iter getDataEnd() const { return mDataEnd; } U32 getChildCount() const { return mChildCount; } @@ -321,14 +322,10 @@ public: if ((getElementCount() < gOctreeMaxCapacity && contains(data->getBinRadius()) || (data->getBinRadius() > getSize()[0] && parent && parent->getElementCount() >= gOctreeMaxCapacity))) { //it belongs here + mData.push_back(NULL); + mData[mElementCount] = data; mElementCount++; - mData = (element_list) realloc(mData, sizeof(LLPointer)*mElementCount); - - //avoid unref on uninitialized memory - memset(mData+mElementCount-1, 0, sizeof(LLPointer)); - - mData[mElementCount-1] = data; - mDataEnd = mData + mElementCount; + mDataEnd = &mData[mElementCount]; data->setBinIndex(mElementCount-1); BaseType::insert(data); return true; @@ -364,14 +361,10 @@ public: if( lt == 0x7 ) { + mData.push_back(NULL); + mData[mElementCount] = data; mElementCount++; - mData = (element_list) realloc(mData, sizeof(LLPointer)*mElementCount); - - //avoid unref on uninitialized memory - memset(mData+mElementCount-1, 0, sizeof(LLPointer)); - - mData[mElementCount-1] = data; - mDataEnd = mData + mElementCount; + mDataEnd = &mData[mElementCount]; data->setBinIndex(mElementCount-1); BaseType::insert(data); return true; @@ -436,16 +429,15 @@ public: mData[i]->setBinIndex(i); } - mData[mElementCount] = NULL; //needed for unref - mData = (element_list) realloc(mData, sizeof(LLPointer)*mElementCount); - mDataEnd = mData+mElementCount; + mData[mElementCount] = NULL; + mData.pop_back(); + mDataEnd = &mData[mElementCount]; } else { - mData[0] = NULL; //needed for unref - free(mData); - mData = NULL; - mDataEnd = NULL; + mData.clear(); + mData.push_back(NULL); + mDataEnd = &mData[0]; } notifyRemoval(data); @@ -491,7 +483,7 @@ public: } //node is now root - llwarns << "!!! OCTREE REMOVING FACE BY ADDRESS, SEVERE PERFORMANCE PENALTY |||" << llendl; + llwarns << "!!! OCTREE REMOVING ELEMENT BY ADDRESS, SEVERE PERFORMANCE PENALTY |||" << llendl; node->removeByAddress(data); llassert(data->getBinIndex() == -1); return true; -- cgit v1.2.3 From 8c8c2f3b940059f82777c9b0b9f40e4d2f7bc6ab Mon Sep 17 00:00:00 2001 From: "simon@Simon-PC.lindenlab.com" Date: Wed, 17 Oct 2012 11:28:51 -0700 Subject: Fix angry Linux and Mac builds --- indra/llmath/lloctree.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/llmath') diff --git a/indra/llmath/lloctree.h b/indra/llmath/lloctree.h index 68d8110f1d..7348904c61 100644 --- a/indra/llmath/lloctree.h +++ b/indra/llmath/lloctree.h @@ -78,7 +78,7 @@ public: typedef LLOctreeTraveler oct_traveler; typedef LLTreeTraveler tree_traveler; - typedef std::vector> element_list; + typedef std::vector< LLPointer > element_list; // note: don't remove the whitespace between "> >" typedef LLPointer* element_iter; typedef const LLPointer* const_element_iter; typedef typename std::vector*>::iterator tree_listener_iter; -- cgit v1.2.3