This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: zero-alloc cache (was Re: [v3] Fix PR libstdc++/10276)


Carlo Wood writes:
 > Hiya Jerry,
 > 
 > how is this going?  I synced with cvs yesterday, and the last
 > patch is still from a week ago (2003-04-04).
 > 
 > Can you give me an estimation of when you think the zero-alloc
 > cache patch will be finished and applied?


Hi, Carlo.  I took BenK's patch and fleshed it out some.  This is the
potential patch for 3.3.  I'm working up one for mainline as well.

What do you think?  Does this do the job for 3.3?

04-18-2003  Jerry Quinn  <jlquinn at optonline dot net>
	    Benjamin Kosnik <bkoz at redhat dot com>

	* include/bits/basic_ios.h (ios_base::Init::_S_ios_create):
        Declare friend.
	(basic_ios::init, basic_ios::_M_cache_locale): Add locale
        cache argument.
	* include/bits/basic_ios.tcc (basic_ios::init): Pass cache to
        _M_cache_locale.
	(basic_ios::_M_cache_locale): Use placement new if cache is
        provided.  Track the distinction in iword(0).
	* include/bits/locale_facets.tcc
        (__locale_cache::_S_callback): Only delete cache if iword(0)
        is 0, i.e. not static.
	* src/globals.cc: Allocate space for __locale_cache objects.
	* src/ios.cc (__gnu_cxx): Declare extern __locale_cache objects
	for standard wide and narrow stream objects.	
	(ios_base::Init::_S_ios_create): Use them.


Index: include/bits/basic_ios.h
===================================================================
RCS file: /cvsroot/gcc/gcc/libstdc++-v3/include/bits/basic_ios.h,v
retrieving revision 1.14.2.3
diff -u -r1.14.2.3 basic_ios.h
--- include/bits/basic_ios.h	9 Mar 2003 02:00:51 -0000	1.14.2.3
+++ include/bits/basic_ios.h	18 Apr 2003 03:41:34 -0000
@@ -81,6 +81,8 @@
       typedef istreambuf_iterator<_CharT, _Traits>   __istreambuf_iter;
       typedef num_get<_CharT, __istreambuf_iter>     __numget_type;
       //@}
+
+      friend void ios_base::Init::_S_ios_create(bool);
       
       // Data members:
     protected:
@@ -418,10 +420,13 @@
        *  @brief  All setup is performed here.
        *
        *  This is called from the public constructor.  It is not virtual and
-       *  cannot be redefined.
+       *  cannot be redefined.  The second argument, __cache, is used
+       *  to initialize the standard streams without allocating
+       *  memory.
       */
       void 
-      init(basic_streambuf<_CharT, _Traits>* __sb);
+      init(basic_streambuf<_CharT, _Traits>* __sb,
+ 	   __locale_cache<_CharT>* __cache=0);
 
       bool
       _M_check_facet(const locale::facet* __f) const
@@ -432,7 +437,7 @@
       }
 
       void
-      _M_cache_locale(const locale& __loc);
+      _M_cache_locale(const locale& __loc,__locale_cache<_CharT>* __cache = 0);
 
 #if 1
       // XXX GLIBCXX_ABI Deprecated, compatibility only.
Index: include/bits/basic_ios.tcc
===================================================================
RCS file: /cvsroot/gcc/gcc/libstdc++-v3/include/bits/basic_ios.tcc,v
retrieving revision 1.17.4.2
diff -u -r1.17.4.2 basic_ios.tcc
--- include/bits/basic_ios.tcc	5 Mar 2003 04:40:07 -0000	1.17.4.2
+++ include/bits/basic_ios.tcc	18 Apr 2003 03:41:35 -0000
@@ -144,11 +144,12 @@
 
   template<typename _CharT, typename _Traits>
     void
-    basic_ios<_CharT, _Traits>::init(basic_streambuf<_CharT, _Traits>* __sb)
+    basic_ios<_CharT, _Traits>::init(basic_streambuf<_CharT, _Traits>* __sb,
+				     __locale_cache<_CharT>* __cache)
     {
       // NB: This may be called more than once on the same object.
       ios_base::_M_init();
-      _M_cache_locale(_M_ios_locale);
+      _M_cache_locale(_M_ios_locale, __cache);
       _M_tie = 0;
 
       // NB: The 27.4.4.1 Postconditions Table specifies requirements
@@ -173,7 +174,8 @@
 
   template<typename _CharT, typename _Traits>
     void
-    basic_ios<_CharT, _Traits>::_M_cache_locale(const locale& __loc)
+    basic_ios<_CharT, _Traits>::_M_cache_locale(const locale& __loc,
+						__locale_cache<_CharT>* __cache)
     {
       if (__builtin_expect(has_facet<__ctype_type>(__loc), true))
 	_M_fctype = &use_facet<__ctype_type>(__loc);
@@ -189,7 +191,16 @@
 	_M_fnumget = 0;
       typedef __locale_cache<_CharT> __cache_t;
       if (!pword(0)) {
-	pword(0) = auto_ptr<__cache_t>(new __cache_t()).release();
+	// We store the cache at pword(0).  iword(0) is set to 1 to
+	// indicate that this is a static storage cache that shouldn't
+	// be deleted.
+	if (__cache)
+	  {
+	    pword(0) = auto_ptr<__cache_t>(new (__cache) __cache_t()).release();
+	    iword(0) = 1;		// so we don't try to clobber static cache
+	  }
+	else
+	  pword(0) = auto_ptr<__cache_t>(new __cache_t()).release();
 	register_callback(__cache_t::_S_callback, 0);
       }
       static_cast<__cache_t&>(_M_cache())._M_init(__loc);
Index: include/bits/locale_facets.tcc
===================================================================
RCS file: /cvsroot/gcc/gcc/libstdc++-v3/include/bits/locale_facets.tcc,v
retrieving revision 1.82.4.8
diff -u -r1.82.4.8 locale_facets.tcc
--- include/bits/locale_facets.tcc	7 Mar 2003 17:26:26 -0000	1.82.4.8
+++ include/bits/locale_facets.tcc	18 Apr 2003 03:41:35 -0000
@@ -2293,7 +2293,7 @@
       switch (__ev)
 	{
 	case ios_base::erase_event:
-	  if (__io.pword(0))
+	  if (__io.pword(0) && !__io.iword(0))
 	    delete &__io._M_cache();
 	  break;
 
@@ -2307,6 +2307,7 @@
 	  // basic_ios::_M_cache_locale.
 	  typedef __locale_cache<_CharT> __cache_t;
 	  __io.pword(0) = auto_ptr<__cache_t>(new __cache_t()).release();
+	  __io.iword(0) = 0;
 	  break;
 	}
     }
Index: src/globals.cc
===================================================================
RCS file: /cvsroot/gcc/gcc/libstdc++-v3/src/globals.cc,v
retrieving revision 1.12.4.1
diff -u -r1.12.4.1 globals.cc
--- src/globals.cc	4 Mar 2003 02:17:56 -0000	1.12.4.1
+++ src/globals.cc	18 Apr 2003 03:41:36 -0000
@@ -48,6 +48,23 @@
 {
   using namespace std;
 
+  // Also, need locale caches for standard stream objects...
+  typedef char fake_locale_cache[sizeof(__locale_cache<char>)]
+  __attribute__ ((aligned(__alignof__(__locale_cache<char>))));
+  fake_locale_cache locale_cache_cout;
+  fake_locale_cache locale_cache_cin;
+  fake_locale_cache locale_cache_cerr;
+  fake_locale_cache locale_cache_clog;
+
+#ifdef _GLIBCPP_USE_WCHAR_T
+  typedef char fake_wlocale_cache[sizeof(__locale_cache<wchar_t>)]
+  __attribute__ ((aligned(__alignof__(__locale_cache<wchar_t>))));
+  fake_wlocale_cache locale_cache_wcout;
+  fake_wlocale_cache locale_cache_wcin;
+  fake_wlocale_cache locale_cache_wcerr;
+  fake_wlocale_cache locale_cache_wclog;
+#endif
+ 
   typedef char fake_facet_name[sizeof(char*)]
   __attribute__ ((aligned(__alignof__(char*))));
   fake_facet_name facet_name[6 + _GLIBCPP_NUM_CATEGORIES];
Index: src/ios.cc
===================================================================
RCS file: /cvsroot/gcc/gcc/libstdc++-v3/src/ios.cc,v
retrieving revision 1.33.2.5
diff -u -r1.33.2.5 ios.cc
--- src/ios.cc	4 Apr 2003 14:59:59 -0000	1.33.2.5
+++ src/ios.cc	18 Apr 2003 03:41:36 -0000
@@ -48,11 +48,19 @@
   extern stdio_filebuf<char> buf_cout;
   extern stdio_filebuf<char> buf_cin;
   extern stdio_filebuf<char> buf_cerr;
+  extern std::__locale_cache<char> locale_cache_cout;
+  extern std::__locale_cache<char> locale_cache_cin;
+  extern std::__locale_cache<char> locale_cache_cerr;
+  extern std::__locale_cache<char> locale_cache_clog;
 
 #ifdef _GLIBCPP_USE_WCHAR_T
   extern stdio_filebuf<wchar_t> buf_wcout;
   extern stdio_filebuf<wchar_t> buf_wcin;
   extern stdio_filebuf<wchar_t> buf_wcerr;
+  extern std::__locale_cache<wchar_t> locale_cache_wcout;
+  extern std::__locale_cache<wchar_t> locale_cache_wcin;
+  extern std::__locale_cache<wchar_t> locale_cache_wcerr;
+  extern std::__locale_cache<wchar_t> locale_cache_wclog;
 #endif
 } // namespace __gnu_cxx
 
@@ -173,10 +181,15 @@
     new (&buf_cout) stdio_filebuf<char>(stdout, ios_base::out, __out_size);
     new (&buf_cin) stdio_filebuf<char>(stdin, ios_base::in, __in_size);
     new (&buf_cerr) stdio_filebuf<char>(stderr, ios_base::out, __out_size);
+
     new (&cout) ostream(&buf_cout);
     new (&cin) istream(&buf_cin);
     new (&cerr) ostream(&buf_cerr);
     new (&clog) ostream(&buf_cerr);
+    cout.init(&buf_cout, &locale_cache_cout);
+    cin.init(&buf_cin, &locale_cache_cin);
+    cerr.init(&buf_cerr, &locale_cache_cerr);
+    clog.init(&buf_cerr, &locale_cache_clog);
     cin.tie(&cout);
     cerr.flags(ios_base::unitbuf);
     
@@ -188,6 +201,10 @@
     new (&wcin) wistream(&buf_wcin);
     new (&wcerr) wostream(&buf_wcerr);
     new (&wclog) wostream(&buf_wcerr);
+    wcout.init(&buf_wcout, &locale_cache_wcout);
+    wcin.init(&buf_wcin, &locale_cache_wcin);
+    wcerr.init(&buf_wcerr, &locale_cache_wcerr);
+    wclog.init(&buf_wcerr, &locale_cache_wclog);
     wcin.tie(&wcout);
     wcerr.flags(ios_base::unitbuf);
 #endif


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]