Open Bug 1243367 Opened 10 years ago Updated 1 year ago

Deal with remaining js_free instances inlined into JSAPI

Categories

(Core :: JavaScript Engine, defect)

defect

Tracking

()

ASSIGNED

People

(Reporter: bzbarsky, Assigned: sfink)

References

(Depends on 1 open bug, Blocks 3 open bugs)

Details

Attachments

(1 external file)

This is typically a problem because it leads to the wrong DLL's heap being used on Windows, as in bug 1007136. js_free per se is not a problem. The problem is when it appears inline in a public API class. I just looked at js_free in headers in js/public and jsapi.h, and we have the following: 1) ~NotableClassInfo in js/public/MemoryMetrics.h 2) ~NotableStringInfo in js/public/MemoryMetrics.h 3) ~NotableScriptSourceInfo in js/public/MemoryMetrics.h 4) The FreePolicy struct in js/public/Utility.h 5) ~SourceBufferHolder in jsapi.h Nicholas, are those first three public API that API consumers would be putting on the stack? Luke, do you know what allocator is used for the FreePolicy stuff? Is it always called in the same DLL as the FreePolicy consumer? As for the SourceBufferHolder, I think it's totally broken. Its documentation says to allocate with js_malloc and free with js_free, which would work fine if the alloc and free were both done by the API consumer. But it has a way to take the buffer too, and once that's done inside the engine we lose. This class should be using JS_malloc and JS_free...
Flags: needinfo?(n.nethercote)
Flags: needinfo?(luke)
Oh, do you mean it's not enough to call js_free, but you also have to call it from within SM code? Ugh. Don't we have a shared libc (such that it doesn't matter which DLL you call 'free' from)? I've been wondering recently whether we can just remove js_malloc/js_free and do the same thing as Gecko...
Flags: needinfo?(luke)
> but you also have to call it from within SM code? Well, that depends. If you did your allocation from inside the SM DLL, then you also need to do the deallocation from inside it too. > Don't we have a shared libc (such that it doesn't matter which DLL you call 'free' from)? Gecko and SpiderMonkey do. Other SpiderMonkey embedders clearly do not; see bug 1007136 and the recent thread in m.d.t.js-engine where this came up.
(In reply to Boris Zbarsky [:bz] from comment #0) > > 1) ~NotableClassInfo in js/public/MemoryMetrics.h > 2) ~NotableStringInfo in js/public/MemoryMetrics.h > 3) ~NotableScriptSourceInfo in js/public/MemoryMetrics.h > > Nicholas, are those first three public API that API consumers would be > putting on the stack? I'm not sure if I understand the question. Those three classes are used deep within RuntimeStats, which callers will instantiate on the stack (to pass to CollectRuntimeStats()) but those three classes appear within vectors within structs within RuntimeStats. So... maybe? If you want to move the destructors from MemoryMetrics.h to MemoryMetrics.cpp, that would be fine, and might be the easiest thing.
Flags: needinfo?(n.nethercote)
Yeah, that might be the way to go. At least if we expect non-Firefox embedders to use this.
Depends on: 1478749

Note that this situation is much worse after bug 1309552, which put a js_free call in AllocPolicyBase and TempAllocPolicy. (Though I don't know how many of those get instantiated in header files.)

Assignee: nobody → sphink
Status: NEW → ASSIGNED
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: