diff options
author | Michael Meeks <michael.meeks@collabora.com> | 2017-12-07 21:19:09 +0000 |
---|---|---|
committer | Michael Meeks <michael.meeks@collabora.com> | 2017-12-15 10:22:03 +0000 |
commit | 556e121379494d4bed9738d9c7539ac5afc8f6f4 (patch) | |
tree | 26ac1061ee6916376bf2906b3259f5a067c7b3b3 /sal/qa/rtl/alloc | |
parent | 6d03c1367f0955900194287805324a8b4144e124 (diff) |
sal: add pre-initialization scheme for allocations.
This saves several megabytes of dirtied pages for each LOK
client of Online.
Change-Id: I425a2e7896879f0a64d71fcc0655e9e1fa1256aa
Diffstat (limited to 'sal/qa/rtl/alloc')
-rw-r--r-- | sal/qa/rtl/alloc/rtl_alloc.cxx | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/sal/qa/rtl/alloc/rtl_alloc.cxx b/sal/qa/rtl/alloc/rtl_alloc.cxx index 30aadcc94f69..6a4c1648ff53 100644 --- a/sal/qa/rtl/alloc/rtl_alloc.cxx +++ b/sal/qa/rtl/alloc/rtl_alloc.cxx @@ -18,11 +18,14 @@ */ #include <rtl/alloc.h> +#include <rtl/ustrbuf.hxx> #include <sal/types.h> #include <cppunit/TestFixture.h> #include <cppunit/extensions/HelperMacros.h> #include <cppunit/plugin/TestPlugIn.h> +#include <sal/rtl/strimp.hxx> + #include <memory.h> namespace rtl_alloc @@ -132,8 +135,75 @@ public: CPPUNIT_TEST_SUITE_END(); }; +class TestPreinit : public CppUnit::TestFixture +{ +public: + TestPreinit() + { + } + + // initialise your test code values here. + void setUp() override + { + } + + void tearDown() override + { + } + + // insert your test code here. + + void test() + { + const char *sample = "Hello World"; + std::vector<OUString> aStrings; + + rtl_alloc_preInit(true); + + OUString aFoo("foo"); + + // fill some cache bits + for (int iter = 0; iter < 4; iter++) + { + for (int i = 1; i < 4096; i += 8) + { + OUStringBuffer aBuf(i); + aBuf.appendAscii(sample, (i/8) % (sizeof(sample)-1)); + OUString aStr = aBuf.makeStringAndClear(); + aStrings.push_back(aStr); + } + // free some pieces to make holes + for (size_t i = iter; i < aStrings.size(); i += 17) + aStrings[i] = aFoo; + } + + for (size_t i = 0; i < aStrings.size(); ++i) + { + CPPUNIT_ASSERT_MESSAGE( "not static before.", !(aStrings[i].pData->refCount & SAL_STRING_STATIC_FLAG) ); + } + + // should static-ize all the strings. + rtl_alloc_preInit(false); + + for (size_t i = 0; i < aStrings.size(); ++i) + CPPUNIT_ASSERT_MESSAGE( "static after.", (aStrings[i].pData->refCount & SAL_STRING_STATIC_FLAG) ); + } + + void test2() + { + // should never happen but lets try it again. + test(); + } + + CPPUNIT_TEST_SUITE(TestPreinit); + CPPUNIT_TEST(test); + CPPUNIT_TEST(test2); + CPPUNIT_TEST_SUITE_END(); +}; + CPPUNIT_TEST_SUITE_REGISTRATION(rtl_alloc::Memory); CPPUNIT_TEST_SUITE_REGISTRATION(rtl_alloc::TestZeroMemory); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_alloc::TestPreinit); } // namespace rtl_alloc CPPUNIT_PLUGIN_IMPLEMENT(); |