🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.arch
Article #950

Re: Large constants in RISC

#950
From: aph
Date: Wed, 25 Nov 2026 15:57
67 lines
4846 bytes
Stefan Monnier <monnier@iro.umontreal.ca> wrote:
> aph@littlepinkcloud.invalid [2026-11-24 13:46:24] wrote:
>> Stefan Monnier <monnier@iro.umontreal.ca> wrote:
>>> Hmm... didn't think of that.  Indeed this could lead to actual
>>> addresses embedded in the code.  Then again, I'd expect most such JIT
>>> setups to want to keep most of those addresses in data rather than in
>>> the code so the GC can more easily trace through them.
>> GCs have not the slightest difficulty tracing through embedded
>> addresses. We use whatever form of address constants is fastest.
> 
> Maybe it's not "hard" compared to the rest of what it takes to write
> a high performance GC, but it's still a fair bit more work to have to
> tell the GC where to find the few bitfields that need to be stitched
> together to make up the actual pointer (it definitely makes tracing
> through such references slower), and if you have a moving GC it also
> makes moves harder, because of the need to both retrofit the new address
> into the corresponding bitfields (which also means you can't use an
> instruction sequence special-tailored to the original address) and take
> care of updating/flushing the I-cache.

Yes, we have to do all of that, but it's very-well-understood
technology that we've been using for decades. Object references in
code are treated as "old": the referenced objects are in regions that
rarely get moved. We have to be able to scan live stacks and code and
a variety of other places, and compared with that unpacking address
constants is a fairly easy case.

>>> Andrew, do you know what causes all those large constant addresses
>>> you're seeing?
>>
>> Very common constants are classes used in expressions, such as
>>
>>   new File("filename")
>>
>> or casts between types
>>
>>   File x = (File)anObject;
>>
>> Casts are more common than is immediately apparent, because the
>> compiler inserts them when it can't prove the type of an object.
> 
> Interesting, thanks.  So it is indeed the JIT case suggested by Anton!

Yes.

>> The other important case is metadata. We gather a lot of information
>> about running code: branch frequency, type frequency, and so on. Every
>> metadata address is a constant in the generated code. After a while,
>> code is recompiled and we use all the gathered informtion to drive
>> inlining and other optimizations.
> 
> Hmm... even more interesting: since the metadata-gathering is part of
> the code that's generated cheaply,

Why is emitting three instructions harder than emitting a PC-relative
load and storing a pointer somewhere?

> I'd have expected that code to use a simple approach that always
> loads the large constants from some data section rather than "use
> whatever form of address constants is fastest" (which I would have
> expected is used only for the high-performance version of the code).

Metadata is very rarely moved, so there's no disadvantage to just
embedding addresses in the code. Sure, we could put address constants
in a local pool instead, but it wouldn't save any space.

Andrew.
Technical Details
Message-ID: <ZmqdnX3Eg4cYmJr2nZ2dnZfqnPednZ2d@supernews.com>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!weretis.net!feeder9.news.weretis.net!border-3.nntp.ord.giganews.com!nntp.giganews.com!Xl.tags.giganews.com!local-2.nntp.ord.giganews.com!nntp.supernews.com!news.supernews.com.POSTED!not-for-mail
References: <11d76uq$11cdc$1@paganini.bofh.team> <11d7ct8$17akn$1@dont-email.me> <11d7ih2$11orr$1@paganini.bofh.team> <11d9d0d$1rsce$1@dont-email.me> <11d9tq8$1b9c1$2@paganini.bofh.team> <2026Nov14.201017@mips.complang.tuwien.ac.at> <6af911ea.18530156@news.eternal-september.org> <SYScnWsR3rgGWWP3nZ2dnZfqn_WdnZ2d@supernews.com> <jwv1p8hhqmy.fsf-monnier+comp.arch@gnu.org> <4m2MS.132607$Lt64.106487@fx41.iad> <jwvo6bidgit.fsf-monnier+comp.arch@gnu.org> <8OWcnVnljcStCJj2nZ2dnZfqnPqdnZ2d@supernews.com> <jwvv75l7dsm.fsf-monnier+comp.arch@gnu.org>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!weretis.net!feeder9.news.weretis.net!border-3.nntp.ord.giganews.com!nntp.giganews.com!Xl.tags.giganews.com!local-2.nntp.ord.giganews.com!nntp.supernews.com!news.supernews.com.POSTED!not-for-mail
NNTP-Posting-Date: Wed, 25 Nov 2026 15:57:56 +0000
Sender: Andrew Haley <aph@li-f2cf9ecc-3241-11b2-a85c-b613f11f80f0.ibm.com>
From: aph@littlepinkcloud.invalid
Subject: Re: Large constants in RISC
Newsgroups: comp.arch
References: <11d76uq$11cdc$1@paganini.bofh.team> <11d7ct8$17akn$1@dont-email.me> <11d7ih2$11orr$1@paganini.bofh.team> <11d9d0d$1rsce$1@dont-email.me> <11d9tq8$1b9c1$2@paganini.bofh.team> <2026Nov14.201017@mips.complang.tuwien.ac.at> <6af911ea.18530156@news.eternal-september.org> <SYScnWsR3rgGWWP3nZ2dnZfqn_WdnZ2d@supernews.com> <jwv1p8hhqmy.fsf-monnier+comp.arch@gnu.org> <4m2MS.132607$Lt64.106487@fx41.iad> <jwvo6bidgit.fsf-monnier+comp.arch@gnu.org> <8OWcnVnljcStCJj2nZ2dnZfqnPqdnZ2d@supernews.com> <jwvv75l7dsm.fsf-monnier+comp.arch@gnu.org>
User-Agent: tin/1.9.2-20070201 ("Dalaruan") (UNIX) (Linux/7.3.3-100.fc43.x86_64 (x86_64))
Message-ID: <ZmqdnX3Eg4cYmJr2nZ2dnZfqnPednZ2d@supernews.com>
Date: Wed, 25 Nov 2026 15:57:57 +0000
Lines: 67
X-Trace: sv3-vhj6iqlzt83LBmxL8PtMKWccjT3ba3qDoDLDf4HEj8jKYPv7AGqUpJM5ELjmI9oh8PH+siuryJCfHvq!rCJH8mnrlVyXvFtb2ymO1oLyogGz1AXpQsmjGUQRjdPOyPRIDHSRAuZhaIRyoNGxP4scDzP1uJFu!ElotlPhN6TyN
X-Complaints-To: www.supernews.com/docs/abuse.html
X-DMCA-Complaints-To: www.supernews.com/docs/dmca.html
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40