Last Comment Bug 664353 - Make alloc policy realloc() easier to implement
: Make alloc policy realloc() easier to implement
Status: RESOLVED FIXED
:
Product: Core
Classification: Components
Component: JavaScript Engine (show other bugs)
: unspecified
: x86_64 Linux
: -- normal (vote)
: ---
Assigned To: David Anderson [:dvander]
:
Mentors:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2011-06-14 19:04 PDT by David Anderson [:dvander]
Modified: 2011-06-15 18:13 PDT (History)
1 user (show)
See Also:
Crash Signature:
(edit)
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---


Attachments
fix (5.78 KB, patch)
2011-06-14 19:04 PDT, David Anderson [:dvander]
luke: review+
Details | Diff | Splinter Review

Description David Anderson [:dvander] 2011-06-14 19:04:22 PDT
Created attachment 539397 [details] [diff] [review]
fix

realloc() is annoying to implement in a bump allocator like IonAllocPolicy, so this changes jsvector to pass in the old size.
Comment 1 Luke Wagner [:luke] 2011-06-15 10:04:24 PDT
Comment on attachment 539397 [details] [diff] [review]
fix

Review of attachment 539397 [details] [diff] [review]:
-----------------------------------------------------------------

::: js/src/ion/IonAllocPolicy.h
@@ +62,5 @@
> +    void *realloc_(void *p, size_t oldBytes, size_t bytes) {
> +        void *n = malloc_(bytes);
> +        if (!n)
> +            return n;
> +        memcpy(n, p, oldBytes);

In theory, bytes can be less than oldBytes in which case you need a Min() here.

::: js/src/jsvector.h
@@ +157,5 @@
>  
>      static inline bool growTo(Vector<T,N,AP> &v, size_t newcap) {
>          JS_ASSERT(!v.usingInlineStorage());
>          size_t bytes = sizeof(T) * newcap;
> +        size_t oldBytes = sizeof(T) * v.mLength;

Could you comment in jsalloc.h (first big comment) that realloc is passed the *used* bytes of the previous buffer, and not the total bytes allocated.
Comment 2 David Anderson [:dvander] 2011-06-15 18:13:52 PDT
http://hg.mozilla.org/tracemonkey/rev/21e26c404883

Note You need to log in before you can comment on or make changes to this bug.