Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Kaz Kylheku <kaz@kylheku.com> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: code snippet |
| Date | 2012-01-04 03:37 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <20120103190941.684@kylheku.com> (permalink) |
| References | (15 earlier) <slrnjf6ocv.1rti.usenet-nospam@guild.seebs.net> <jcvrjq$feg$1@dont-email.me> <4F035609.2E6947C8@bytecraft.com> <20120103113739.535@kylheku.com> <9mhsc5FpeqU5@mid.individual.net> |
On 2012-01-04, Ian Collins <ian-news@hotmail.com> wrote: > On 01/ 4/12 08:58 AM, Kaz Kylheku wrote: >> On 2012-01-03, Walter Banks<walter@bytecraft.com> wrote: >>> >>> First there is very few things that can be done in asm that cannot be done in C. >> >> For instance, take garbage collection. Suppose that in some function there is >> a statement "x = NULL", where x is local and there are no more uses of x in the >> remaining block. An optimizing C compiler could simply not bother with this >> assignment since x has no next use. But what if there is garbage collection? >> The variable x could be the last reference to a large amount of memory, whose >> reclamation will be prevented if the assignment is optimized away. > > Only for as long as x remains in scope. Yes, but that could be a long extent of computation, under which there are lots of nested computations. E.g. if x is in the scope of some upper level function, like main(), it is now prevented from gc for nearly whole lifetime of the program. >> The C compiler does not know that x has a kind of next use: it can be visited >> "behind the scenes" by the garbage collector! C compilers are GC-unfriendly in >> numerous ways, one of which is this generation of semantic garbage: keeping >> values in memory or registers beyond the point at which they have become >> garbage in the source semantics. In assembly we don't have this problem; >> since we know what we put into every memory location and register. > > Again, for how long? If a value is no longer used, the optimiser will > reuse the register. If a block if dynamic memory is no longer used, why So you would think, but it doesn't always work out that way. Sometimes the object is actually in memory. The variable is no longer live, and the C compiler does not waste any time by overwriting that variable with null just because it is no longer live, since this is of no consequence in the normal C paradigm. Your naive conservative garbage collector (the only kind you can realistically achieve under C) has to treat that memory location as a live reference, lacking the liveness info from the compiler. Sometimes a related problem can happens. A variable holds some dynamic object, and that variable is overwritten with a new value. However, the new value is held in a register, while the old value had been spilled into the underlying memory location for that variable and is persisting there. > keep the pointer to it in scope? Okay, so how do you not keep the pointer? What is the "unkeep" operation? Even clobbering the pointer with NULL doesn't do the trick, necessarily. The optimizer will see: hey, this variable is no longer live at this assignment, so just throw the assignment away. This is okay in normal C, because if you didn't need the dynamic object, you would have called free on it, right? A pointer to some dynamic object which has no next use, and which is the last reference to that object is a leak under the explicit memory management paradigm. > It sounds like you are trying to > compensate form poor design, at least in the context of gc. One "solution" is to call a dummy external function, which receives the address of the variable. This will force most compilers to spill the up-to-date register-cached value into the underlying storage, clobbering any stale value. This is not a nice thing to have to do everywhere. (I've done this as a reactive approach in response to confirmed cases of the problem.) >> We would like to be able to extend the C compiler with new rules such as >> "whenever a pointer variable has no next use, generate code to overwrite it >> with null", but the language doesn't give us a way to direct the translation in >> such ways. > > I still don't see why. If the pointer is in the current scope, the work > is probably unnecessary. Yes, it probably is unnecessary. Except for the rare situation when this crops up and bites you. > If not, the work may be a very expensive way > to fix a bad design. What is the inexpensive way to fix the design?
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
code snippet "Bill Cunningham" <nospam@nspam.invalid> - 2011-12-18 20:51 -0500
Re: code snippet Geoff <geoff@invalid.invalid> - 2011-12-18 18:29 -0800
Re: code snippet "Bill Cunningham" <nospam@nspam.invalid> - 2011-12-18 21:51 -0500
Re: code snippet "Bill Cunningham" <nospam@nspam.invalid> - 2011-12-18 22:24 -0500
Re: code snippet Geoff <geoff@invalid.invalid> - 2011-12-18 19:53 -0800
Re: code snippet "Bill Cunningham" <nospam@nspam.invalid> - 2011-12-18 23:32 -0500
Re: code snippet Geoff <geoff@invalid.invalid> - 2011-12-18 20:57 -0800
Re: code snippet "Bill Cunningham" <nospam@nspam.invalid> - 2011-12-19 00:01 -0500
Re: code snippet Geoff <geoff@invalid.invalid> - 2011-12-18 21:13 -0800
Re: code snippet "Bill Cunningham" <nospam@nspam.invalid> - 2011-12-19 16:42 -0500
Re: code snippet Keith Thompson <kst-u@mib.org> - 2011-12-18 20:14 -0800
Re: code snippet "Bill Cunningham" <nospam@nspam.invalid> - 2011-12-18 23:27 -0500
Re: code snippet Rui Maciel <rui.maciel@gmail.com> - 2011-12-19 12:33 +0000
Re: code snippet "Bill Cunningham" <nospam@nspam.invalid> - 2011-12-19 16:33 -0500
Re: code snippet Rui Maciel <rui.maciel@gmail.com> - 2011-12-20 00:20 +0000
Re: code snippet "Bill Cunningham" <nospam@nspam.invalid> - 2011-12-19 19:46 -0500
Re: code snippet Rui Maciel <rui.maciel@gmail.com> - 2011-12-20 01:14 +0000
Re: code snippet "Bill Cunningham" <nospam@nspam.invalid> - 2011-12-20 15:51 -0500
Re: code snippet Rui Maciel <rui.maciel@gmail.com> - 2011-12-21 14:11 +0000
Re: code snippet 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-21 07:03 -0800
Re: code snippet Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-12-21 21:41 +0000
Re: code snippet 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-21 16:35 -0800
Re: code snippet Seebs <usenet-nospam@seebs.net> - 2011-12-22 01:03 +0000
Re: code snippet Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-12-22 03:19 +0000
Re: code snippet 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-22 07:11 -0800
Re: code snippet Seebs <usenet-nospam@seebs.net> - 2011-12-22 16:59 +0000
Re: code snippet "io_x" <a@b.c.invalid> - 2011-12-22 18:38 +0100
Re: code snippet 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-22 10:40 -0800
Re: code snippet Markus Wichmann <nullplan@gmx.net> - 2011-12-22 19:12 +0100
Re: code snippet Nick Keighley <nick_keighley_nospam@hotmail.com> - 2011-12-28 03:50 -0800
Re: code snippet "io_x" <a@b.c.invalid> - 2011-12-28 17:06 +0100
Re: code snippet "io_x" <a@b.c.invalid> - 2012-01-01 20:04 +0100
Re: code snippet Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-01-01 12:38 -0800
Re: code snippet "io_x" <a@b.c.invalid> - 2012-01-02 10:14 +0100
Re: code snippet Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-01-03 04:56 -0800
Re: code snippet "io_x" <a@b.c.invalid> - 2012-01-03 18:26 +0100
Re: code snippet Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-01-04 00:09 -0800
Re: code snippet Ian Collins <ian-news@hotmail.com> - 2012-01-04 21:53 +1300
Re: code snippet "io_x" <a@b.c.invalid> - 2012-01-04 16:14 +0100
Re: code snippet Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-01-01 12:28 -0800
Re: code snippet "io_x" <a@b.c.invalid> - 2012-01-02 10:18 +0100
Re: code snippet Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-01-03 04:56 -0800
Re: code snippet "BartC" <bc@freeuk.com> - 2011-12-22 18:05 +0000
Re: code snippet Seebs <usenet-nospam@seebs.net> - 2011-12-22 18:14 +0000
Re: code snippet superpollo <superpollo@tznvy.pbz> - 2011-12-22 20:00 +0100
Re: code snippet Seebs <usenet-nospam@seebs.net> - 2011-12-22 19:08 +0000
Re: code snippet superpollo <superpollo@tznvy.pbz> - 2011-12-22 22:43 +0100
Re: code snippet Seebs <usenet-nospam@seebs.net> - 2011-12-22 21:57 +0000
Re: code snippet BruceS <bruces42@hotmail.com> - 2011-12-23 16:26 -0800
Re: code snippet Rui Maciel <rui.maciel@gmail.com> - 2011-12-22 19:21 +0000
Re: code snippet 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-22 11:33 -0800
Re: code snippet "io_x" <a@b.c.invalid> - 2011-12-23 09:10 +0100
Re: code snippet Rui Maciel <rui.maciel@gmail.com> - 2011-12-23 14:43 +0000
Re: code snippet Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-12-23 17:14 +0000
Re: code snippet Keith Thompson <kst-u@mib.org> - 2011-12-23 12:10 -0800
Re: code snippet Walter Banks <walter@bytecraft.com> - 2012-01-03 14:24 -0500
Re: code snippet Kaz Kylheku <kaz@kylheku.com> - 2012-01-03 19:58 +0000
Re: code snippet Walter Banks <walter@bytecraft.com> - 2012-01-03 16:15 -0500
Re: code snippet blp@cs.stanford.edu (Ben Pfaff) - 2012-01-03 13:26 -0800
Re: code snippet Kaz Kylheku <kaz@kylheku.com> - 2012-01-03 22:04 +0000
Re: code snippet Ian Collins <ian-news@hotmail.com> - 2012-01-04 15:44 +1300
Re: code snippet "BartC" <bc@freeuk.com> - 2012-01-04 23:34 +0000
Re: code snippet James Harris <james.harris.1@googlemail.com> - 2012-01-04 15:57 -0800
Re: code snippet 88888 Dihedral <dihedral88888@googlemail.com> - 2012-01-05 23:34 -0800
Re: code snippet Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-01-06 00:40 -0800
Re: code snippet Kleuske <kleuske@nowhere.net> - 2012-01-06 10:33 +0000
Re: code snippet 88888 Dihedral <dihedral88888@googlemail.com> - 2012-01-06 04:30 -0800
Re: code snippet Ian Collins <ian-news@hotmail.com> - 2012-01-04 15:37 +1300
Re: code snippet Kaz Kylheku <kaz@kylheku.com> - 2012-01-04 03:37 +0000
Re: code snippet Ian Collins <ian-news@hotmail.com> - 2012-01-04 20:23 +1300
Re: code snippet jacob navia <jacob@spamsink.net> - 2011-12-22 18:26 +0100
Re: code snippet Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-12-22 19:34 +0000
Re: code snippet 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-22 11:57 -0800
Re: code snippet Seebs <usenet-nospam@seebs.net> - 2011-12-22 20:18 +0000
Re: code snippet 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-22 12:52 -0800
Re: code snippet Seebs <usenet-nospam@seebs.net> - 2011-12-22 20:37 +0000
Re: code snippet 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-22 13:27 -0800
Re: code snippet Seebs <usenet-nospam@seebs.net> - 2011-12-22 21:57 +0000
Re: code snippet 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-22 14:09 -0800
Re: code snippet Seebs <usenet-nospam@seebs.net> - 2011-12-22 21:57 +0000
Re: code snippet 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-23 04:01 -0800
Re: code snippet 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-22 14:24 -0800
Re: code snippet Seebs <usenet-nospam@seebs.net> - 2011-12-22 21:57 +0000
Re: code snippet 88888 Dihedral <dihedral88888@googlemail.com> - 2012-01-01 23:06 -0800
Re: code snippet Hans Vlems <hvlems@freenet.de> - 2011-12-22 23:35 -0800
Re: code snippet "BartC" <bc@freeuk.com> - 2011-12-23 12:26 +0000
Re: code snippet jacob navia <jacob@spamsink.net> - 2011-12-23 18:32 +0100
Re: code snippet Nick Keighley <nick_keighley_nospam@hotmail.com> - 2011-12-28 04:04 -0800
Re: code snippet "io_x" <a@b.c.invalid> - 2011-12-23 09:10 +0100
Re: code snippet 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-25 11:13 -0800
Re: code snippet Seebs <usenet-nospam@seebs.net> - 2011-12-25 19:31 +0000
Re: code snippet Rui Maciel <rui.maciel@gmail.com> - 2011-12-26 21:53 +0000
Re: code snippet 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-26 16:10 -0800
Re: code snippet Keith Thompson <kst-u@mib.org> - 2011-12-26 18:11 -0800
Re: code snippet 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-26 23:56 -0800
Re: code snippet "Bill Cunningham" <nospam@nspam.invalid> - 2011-12-20 15:57 -0500
Re: code snippet Rui Maciel <rui.maciel@gmail.com> - 2011-12-21 12:39 +0000
Re: code snippet Bill Reid <hormelfree@gmail.com> - 2011-12-22 15:29 -0800
Re: code snippet Geoff <geoff@invalid.invalid> - 2011-12-19 19:19 -0800
Re: code snippet "Bill Cunningham" <nospam@nspam.invalid> - 2011-12-20 13:51 -0500
Re: code snippet Geoff <geoff@invalid.invalid> - 2011-12-20 11:08 -0800
Re: code snippet Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-12-19 11:37 +0000
Re: code snippet "Bill Cunningham" <nospam@nspam.invalid> - 2011-12-19 16:38 -0500
Re: code snippet "Morris Keesan" <mkeesan@post.harvard.edu> - 2011-12-19 17:02 -0500
Re: code snippet "Bill Cunningham" <nospam@nspam.invalid> - 2011-12-19 17:21 -0500
Re: code snippet John Gordon <gordon@panix.com> - 2011-12-19 22:35 +0000
csiph-web