Closed Bug 543589 Opened 16 years ago Closed 16 years ago

AvmCore::current() would be handy.

Categories

(Tamarin Graveyard :: Virtual Machine, enhancement)

enhancement
Not set
normal

Tracking

(Not tracked)

VERIFIED FIXED

People

(Reporter: kpalacz, Assigned: kpalacz)

References

Details

Attachments

(1 file, 3 obsolete files)

A lot of gymnastics is often involved in getting a reference the current AvmCore.
Attached patch Impl. as per Tommy's suggestion. (obsolete) — Splinter Review
Assignee: nobody → kpalacz
Attachment #424670 - Flags: superreview?(edwsmith)
Attachment #424670 - Flags: review?(treilly)
Could we introduce a GC::current and have AvmCore::current use that? A little too much MMgc guts bleeding into AvmCore for my liking.
Attachment #424670 - Flags: review?(treilly) → review+
Comment on attachment 424670 [details] [diff] [review] Impl. as per Tommy's suggestion. +1 with the caveat that GCHeap::GetGCHeap()->GetEnterFrame()->GetActiveGC() expression becomes GC::current() and moves to the GC.
Attachment #424670 - Attachment is obsolete: true
Attachment #424803 - Flags: superreview?(edwsmith)
Attachment #424670 - Flags: superreview?(edwsmith)
Note that I get to SR any and all API changes to the GC, and I'm not likely to SR+ a new method with a name as generic as "current".
Lar's probably wants something like: static GC *GetCurrentActiveEnterFrameThreadLocalGC() ;-)
(In reply to comment #6) > Lar's probably wants something like: > > static GC *GetCurrentActiveEnterFrameThreadLocalGC() > > ;-) Actually Lars doesn't quite understand why current() is a method on GC, since the threadlocal (currently hidden inside GCHeap) is just a global variable anyway. But sure, why not. GC::GetActiveGC is probably more along the lines of what Lars was looking for. (Lars know what you're thinking, he would call it get-active-gc if he could. And indeed he would.)
Let me rephrase that. If the threadlocal is hidden inside GCHeap, and the logic for the enterframe stuff is tied to the GCHeap, then the getter for the current GC really belongs on the GCHeap, no?
Not knowing anything about it, I'd look for a way to get the current instance of GC among the methods of GC (much like Thread::current(), a common idiom).
That the current implementation piggy back's on the GCHeap's thread local EnterFrame is an implementation detail to me that could change and having a static API in GC feels "right" to me. Actually I think it would be cleaner for the GC to have its own thread local but its best not to have too many thread locals.
I have to say the concept of this makes me nervous, as it's effectively taking a global variable access and making it appear not to be one. If we find that we frequently need this global variable access, well, eek.
Perhaps this bug and the api should be motivated by what AvmCore::current() is for. In an email conversation, Krzystof mentioned that its handy for debugging, when you're stopped in the code and don't have a pointer to an object that you can get the AvmCore* pointer from. if thats the use case (and nothing more) then the api and comment-documentation should make that clear. and sure, if its handy and not fundamentally broken or unmaintainable, cool. The other potential extreme is a general replacement for foo->core(), or passing AvmCore* around as an argument. This may also be a fine proposal (its not unheard of to have at least one TLS "context" variable, at least for allocation). But thats more ambitious and justifies more rigor, for example: whats the plan to refactor all the code? who will set it on vm entry ? what is the performance of TLS variables on various platforms? what is the testing strategy? etc.
Hmm, the way I see it, it's the converse: AvmCore is not a global variable (many instances can coexist in a single program), and we make it nearly as easily accessible as a global variable. I don't think the addition would violate the principle of least authority (POLA) any more than the existing codebase already does, because nearly every method already has access to a reference to AvmCore, and if it doesn't, it'll need it soon enough to access the console to print debugging info. If we are concerned about POLA, then AvmCore should be broken up into smaller classes.
re comment 12: Agreed; Krzystof's example of being able to call DebugCLI::bt() and have it display an AS stack from within a gdb prompt, is convincing enough to allow it in debug shell/players.
We currently rely on the EnterFrame thread local's GC field in a couple different places, OOM and the Sampler for one and if you try to allocate any GC memory without setting it we assert. So this mechanism can be relied upon. This bug is mostly about cosmetic issues and where API's should live as I see it. It might not be the most performant API, we use the generic OS thread local API's and don't attempt to use the tricky fast ones that certain compilers support.
Attachment #424803 - Attachment is obsolete: true
Attachment #424922 - Flags: superreview?(lhansen)
Attachment #424922 - Flags: review?(edwsmith)
Attachment #424803 - Flags: superreview?(edwsmith)
Comment on attachment 424922 [details] [diff] [review] New and improved, now with a better name. Speaking for myself I'm happy with the GC change, though I don't know why the other function shouldn't be called AvmCore::GetActiveCore or somesuch. Leaving that up to Ed though.
Attachment #424922 - Flags: superreview?(lhansen) → superreview+
Comment on attachment 424922 [details] [diff] [review] New and improved, now with a better name. lets go for self-consistency, AvmCore::getActiveCore(), R+ from me with that tweak. cool feature, btw.
Attachment #424922 - Flags: review?(edwsmith) → review+
Attached patch final renameSplinter Review
Attachment #424922 - Attachment is obsolete: true
Blocks: 544048
Status: NEW → RESOLVED
Closed: 16 years ago
Resolution: --- → FIXED
Status: RESOLVED → VERIFIED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: