edbrowse-dev - development list for edbrowse
 help / color / mirror / Atom feed
From: Adam Thompson <arthompson1990@gmail.com>
To: Karl Dahlke <eklhad@comcast.net>
Cc: edbrowse-dev@edbrowse.org
Subject: Re: [edbrowse-dev] Rooted
Date: Sun, 1 Nov 2020 22:35:58 +0000	[thread overview]
Message-ID: <20201101223558.GA333510@toaster> (raw)
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, <a> 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 <t>
> class Rooted<t> { ... }
> (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<Object>
> They have some convenient typedefs for the common ones.
> typedef Rooted<Object> RootedObject;
> typedef Rooted<Value> 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<Foo>, 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.
> 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


  reply	other threads:[~2020-11-01 22:36 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-01  3:23 Karl Dahlke
2020-11-01 22:35 ` Adam Thompson [this message]
2020-11-01 23:27   ` Karl Dahlke
2020-11-09 22:58     ` Adam Thompson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201101223558.GA333510@toaster \
    --to=arthompson1990@gmail.com \
    --cc=edbrowse-dev@edbrowse.org \
    --cc=eklhad@comcast.net \


* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).