Bug 69390 - JSC objects need to know their own cell size at runtime.
Summary: JSC objects need to know their own cell size at runtime.
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Mark Hahnenberg
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-10-04 18:17 PDT by Mark Hahnenberg
Modified: 2011-10-06 10:42 PDT (History)
2 users (show)

See Also:


Attachments
Patch (79.00 KB, patch)
2011-10-05 11:28 PDT, Mark Hahnenberg
no flags Details | Formatted Diff | Diff
Patch (3.66 KB, patch)
2011-10-05 12:07 PDT, Mark Hahnenberg
no flags Details | Formatted Diff | Diff
Patch (12.65 KB, patch)
2011-10-05 13:52 PDT, Mark Hahnenberg
no flags Details | Formatted Diff | Diff
Patch (11.94 KB, patch)
2011-10-05 14:17 PDT, Mark Hahnenberg
no flags Details | Formatted Diff | Diff
Fixing windows (12.92 KB, patch)
2011-10-05 19:05 PDT, Mark Hahnenberg
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Mark Hahnenberg 2011-10-04 18:17:20 PDT
This information is necessary for the GC work that Oliver is doing.  We'll add the relevant information to the ClassInfo struct.
Comment 1 Mark Hahnenberg 2011-10-05 11:28:48 PDT
Created attachment 109828 [details]
Patch
Comment 2 Oliver Hunt 2011-10-05 11:30:00 PDT
Comment on attachment 109828 [details]
Patch

I think a simpler approach would just be to make the method table contain this information, as CREATE_METHOD_TABLE  already has the class name
Comment 3 Mark Hahnenberg 2011-10-05 11:31:26 PDT
> I think a simpler approach would just be to make the method table contain this information, as CREATE_METHOD_TABLE  already has the class name

:-(
Comment 4 Mark Hahnenberg 2011-10-05 12:07:28 PDT
Created attachment 109834 [details]
Patch
Comment 5 Oliver Hunt 2011-10-05 12:11:01 PDT
Comment on attachment 109834 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=109834&action=review

> Source/JavaScriptCore/runtime/WriteBarrier.h:50
> +    ASSERT(WTF::RemovePointer<T>::Type::s_info.cellSize == sizeof(typename WTF::RemovePointer<T>::Type));

This isn't a safe assertion

class A {
 ...
}

class B : A {
  int aNewField;
}

validateCell<A*>(&someB)

would fail this assertion as B's classinfo will (correctly) report a larger cell size than A's.
Comment 6 Geoffrey Garen 2011-10-05 12:38:27 PDT
Comment on attachment 109834 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=109834&action=review

> Source/JavaScriptCore/runtime/JSCell.h:66
> +        size_t cellSize() const;

I don't think JSCell needs this helper function. We can write classInfo()->cellSize at the call site.

>> Source/JavaScriptCore/runtime/WriteBarrier.h:50
>> +    ASSERT(WTF::RemovePointer<T>::Type::s_info.cellSize == sizeof(typename WTF::RemovePointer<T>::Type));
> 
> This isn't a safe assertion
> 
> class A {
>  ...
> }
> 
> class B : A {
>   int aNewField;
> }
> 
> validateCell<A*>(&someB)
> 
> would fail this assertion as B's classinfo will (correctly) report a larger cell size than A's.

Maybe you can turn this ASSERT into >=? That would still catch some bugs.

A better place for an ASSERT might be allocateCell<T>: ASSERT(T::s_info.cellSize == sizeof(T)).
Comment 7 Oliver Hunt 2011-10-05 12:41:50 PDT
(In reply to comment #6)
> (From update of attachment 109834 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=109834&action=review
> 
> > Source/JavaScriptCore/runtime/JSCell.h:66
> > +        size_t cellSize() const;
> 
> I don't think JSCell needs this helper function. We can write classInfo()->cellSize at the call site.
> 
> >> Source/JavaScriptCore/runtime/WriteBarrier.h:50
> >> +    ASSERT(WTF::RemovePointer<T>::Type::s_info.cellSize == sizeof(typename WTF::RemovePointer<T>::Type));
> > 
> > This isn't a safe assertion
> > 
> > class A {
> >  ...
> > }
> > 
> > class B : A {
> >   int aNewField;
> > }
> > 
> > validateCell<A*>(&someB)
> > 
> > would fail this assertion as B's classinfo will (correctly) report a larger cell size than A's.
> 
> Maybe you can turn this ASSERT into >=? That would still catch some bugs.
> 
> A better place for an ASSERT might be allocateCell<T>: ASSERT(T::s_info.cellSize == sizeof(T)).
Yeah i spoke to mark and that's what he's doing :D
Comment 8 Mark Hahnenberg 2011-10-05 13:52:10 PDT
Created attachment 109855 [details]
Patch
Comment 9 Geoffrey Garen 2011-10-05 13:56:25 PDT
Comment on attachment 109855 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=109855&action=review

> Source/JavaScriptCore/runtime/JSObject.h:494
> +inline size_t JSCell::cellSize() const
> +{
> +    return classInfo()->cellSize;
> +}

This function is unused. I still think it can be inlined at the call site when used.
Comment 10 Mark Hahnenberg 2011-10-05 14:17:18 PDT
Created attachment 109860 [details]
Patch
Comment 11 Geoffrey Garen 2011-10-05 14:22:06 PDT
Comment on attachment 109860 [details]
Patch

r=me
Comment 12 Mark Hahnenberg 2011-10-05 19:05:00 PDT
Created attachment 109904 [details]
Fixing windows
Comment 13 Geoffrey Garen 2011-10-05 19:06:38 PDT
Comment on attachment 109904 [details]
Fixing windows

r=me
Comment 14 WebKit Review Bot 2011-10-06 10:41:58 PDT
Comment on attachment 109904 [details]
Fixing windows

Clearing flags on attachment: 109904

Committed r96831: <http://trac.webkit.org/changeset/96831>
Comment 15 WebKit Review Bot 2011-10-06 10:42:02 PDT
All reviewed patches have been landed.  Closing bug.