From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-0.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 15952 invoked from network); 1 Nov 2020 22:36:06 -0000 Received: from hurricane.the-brannons.com (2605:2700:0:17:a800:ff:fe3e:bc77) by inbox.vuxu.org with ESMTPUTF8; 1 Nov 2020 22:36:06 -0000 Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by hurricane.the-brannons.com (Postfix) with ESMTP id CA81D21DE04 for ; Sun, 1 Nov 2020 14:36:02 -0800 (PST) Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by hurricane.the-brannons.com (Postfix) with ESMTPS id A71A821DE02 for ; Sun, 1 Nov 2020 14:36:02 -0800 (PST) Received: by mail-wr1-x42c.google.com with SMTP id i16so7028636wrv.1 for ; Sun, 01 Nov 2020 14:36:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=6hwbFM5gacIGV03tZNcN2/pDz+1k1IK2wOO8u8Kz0FA=; b=jdpss2GgWlOs9VyZaawJlH/u0/dzMK1VtMi5Zn829/2ICBo9YlTFW9BDNCZO4lEEDN 0I0Uve26iYnDDWW7CBMQM4rMWQ/jRFexSdQ9O9wVqbMJWmFLQxZYGfff+NlyOw33GK8x 4NtA9vgD6JQuXwOCgYd+q8gXmDfpKnleRspTTDY+26EawTImgdly0YWcNI9SkYSZympQ Nd0kX0sKwBTnqQVlQsh3mvVu71ZJ29skTiOdjqFW5PMOVivzM54igN+lkGiC//E+SBKk DzqIB4pSJhbIVbGZKIrZyswFcCPidylGAFM1tsLLqd/ELxMLPSJxK0YE615Tkw/hnmSz JhdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=6hwbFM5gacIGV03tZNcN2/pDz+1k1IK2wOO8u8Kz0FA=; b=objB5QMlmLb+h5M8qi1HZZCUp1L02xo7B+Zp980b7CdUdhW2phSMvHoIHZkD7o7hWE h3UQk+pxpBmOBhwQXtzWwrO3wzow2E1ZACQrbLAMZAs1wgPNqeEh5E/3Lx/4ytBMbY29 aUVnSauTJM7v+7+1lPkfeR7at16QsRV8pJEjbIYn598RO44p4cdPhtpm3NcMRtcfBKpL bZWu7THeQ4moluUAq8rs2laosSU0aioYJJZAbPyCLbEP6B98pBTsjN+OwufDg9SaWlOd lh3j0CBKw9VH7pOFmdZkKqroYEQkj1HC22605Bu4Tw10jGbiGxziTHexfKC3BTNFriGx X0VA== X-Gm-Message-State: AOAM533BsWhaXk4BTiWGF9YjvtKjTOqZSVKxbCGtxhNhbSpP4S0H74ko IL21MF8juvvbPCRaYvlkXPw= X-Google-Smtp-Source: ABdhPJzjN9HG1UDS4fsmyFIdp4fN/Llr5U5dFIl8ocQD7tjVI0OR0EbLMAvQPgw5ot9fwVIU/CaFMw== X-Received: by 2002:a5d:4f8c:: with SMTP id d12mr17197430wru.351.1604270160852; Sun, 01 Nov 2020 14:36:00 -0800 (PST) Received: from toaster (b.5.b.9.4.f.e.f.f.f.c.f.1.b.a.e.1.4.0.9.2.4.1.1.0.b.8.0.1.0.0.2.ip6.arpa. [2001:8b0:1142:9041:eab1:fcff:fef4:9b5b]) by smtp.gmail.com with ESMTPSA id i33sm20754108wri.79.2020.11.01.14.35.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Nov 2020 14:36:00 -0800 (PST) Date: Sun, 1 Nov 2020 22:35:58 +0000 From: Adam Thompson To: Karl Dahlke Cc: edbrowse-dev@edbrowse.org Subject: Re: [edbrowse-dev] Rooted Message-ID: <20201101223558.GA333510@toaster> References: <20200931232349.eklhad@comcast.net> X-BeenThere: edbrowse-dev@edbrowse.org List-Id: Edbrowse Development List MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200931232349.eklhad@comcast.net> Appologies if I'm missing a bunch of the discussion, haven't been keeping up with IRC for a long time now. On Sat, Oct 31, 2020 at 11:23:49PM -0400, Karl Dahlke wrote: > Spider monkey has a rooting guide, which I bookmarked, and I need to read, but sometimes I learn more just playing withthe the software. > > First the existential crisis. > I stored a pointer to the document object, swallowed startwindow.js and third.js, which is a lot of stuff, > Fetched the document object from the global object, and verified that the pointer changed out from under me. > Pointer to object is not permanent and guaranteed, as it is in duktape. > Just one of many reasons duktape is sooooo much easier to use. > We have to have reliable pointers. > When I go to a hyperlink, tag, there's an object with that, > edbrowse keeps a pointer to that object, I need to be able to bounce through that pointer and look at the object, > and see if the href has changed, or if there is onclick code to run, and so on and so on. > If the garbage collector has moved that object somewhere else, or if it moved by realloc because it got bigger, > then I'm fucking screwed. > A seg fault that I'll never be able to debug. > That is the existential crisis. > And the crisis is confirmed by my hello program, wherein the document object moved to a new location because of executing 16,000 lines of js. > This of course put me into a deep depression, along with everything else that is happening in my life. > > But I wanted to learn something. > Still haven't read the rooting guide, but I knew it had something to do with rooting. > > There is a general Rooted class. > > template > class Rooted { ... } > > (This is where you have to learn c++.) > > Lots of things can be rooted but I'm mostly interested in objects. > So specialize the template as > > Rooted > > They have some convenient typedefs for the common ones. > > typedef Rooted RootedObject; > typedef Rooted RootedValue; > > A rooted thing is 12 bytes. > The first 8 bytes do the rooting, somehow, and the last 4 bytes point to the thing. > The * operator is overloaded to push the pointer out. > (Other important operators are overloaded as well.) > So if d is an object from class Rooted, then *d returns those last 4 bytes, which is a pointer to something of type foo. > But only use that pointer in a transient way. > I thought rooting would prevent the pointer from changing, prevent the thing from moving. > WRONG! > But it does update the pointer in each root if it does move. > So, my document object moved, and it updated the pointer in my rooted document object. > In fact they really want you to deal with the rooted things, not the pointers at all, if you can help it. > Their functions take and return rooted things. > If objects move around in memory, all the rooted things are updated. That's not going to be nice for us to work with. > I have a structure htmlTag, with a member jv, javascript variable. > It's just a void * > I could point to the object and feel good about it, in duktape, because the object never moved. > In mozjs, I can't just point to the object, it might move, I have to use something rooted. > I could have RootedObject in the html tag, but then all of edbrowse has to read in jsapi.h, > and all of edbrowse has to know about RootedObject, and all of edbrowse has to be processed by g++. > There's no more encapsulation, keeping it all within jseng-moz.cpp. > That would piss me off! > (Yeah, that's how we handled it many years ago.) Yeah, that wouldn't be nice. > Or I could just say ok, jv is an opaque 12 bytes that I don't know anything about, but that's hardly portable. > What if it's 16 bytes on some other machine, or even 24? Or the API changes which changes its size. > I could point to or index an array of rooted things that is only known inside jseng-moz.cpp. > I sort of like that idea but not sure how to implement it in practice. Yeah. The easy (and problematic) option is just to have an array and store indices in the structure. It'll really be horrible and require some method of management. Either that or we have an opaque type which is only defined in the mozjs stuff which hides the c++ part but I suspect this may only work properly with some compilers (and no I'm not sure on that). > Holy shit this stuff is complicated. Yes. I have to ask at this stage, why would we want to go back to mozjs? I've no doubt things've changed but last time I looked at it it was becoming increasingly not suited to our design as well as having an approach where they could alter it in any way they needed to to make Firefox work. I remember having all sorts of issues trying to work out what'd changed which was part of the reason for changing engines I think. As I said at the start of this email, I admit I've not really been keeping up with this stuff. However, I'm interested if there's something here I've missed. Cheers, Adam.