Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 471622 | Differences between
and this patch

Collapse All | Expand All

(-)a/js/src/jsatom.cpp (-2 / +2 lines)
Lines 431-447 js_SweepAtomState(JSContext *cx) Link Here
431
            e.removeFront();
431
            e.removeFront();
432
    }
432
    }
433
}
433
}
434
434
435
bool
435
bool
436
AtomIsInterned(JSContext *cx, JSAtom *atom)
436
AtomIsInterned(JSContext *cx, JSAtom *atom)
437
{
437
{
438
    /* We treat static strings as interned because they're never collected. */
438
    /* We treat static strings as interned because they're never collected. */
439
    if (StaticStrings::isStatic(atom))
439
    if (cx->runtime->staticStrings.isStatic(atom))
440
        return true;
440
        return true;
441
441
442
    AutoLockAtomsCompartment lock(cx);
442
    AutoLockAtomsCompartment lock(cx);
443
    AtomSet::Ptr p = cx->runtime->atomState.atoms.lookup(atom);
443
    AtomSet::Ptr p = cx->runtime->atomState.atoms.lookup(atom);
444
    if (!p)
444
    if (!p)
445
        return false;
445
        return false;
446
446
447
    return p->isTagged();
447
    return p->isTagged();
Lines 520-536 Atomize(JSContext *cx, const jschar **pc Link Here
520
}
520
}
521
521
522
JSAtom *
522
JSAtom *
523
js_AtomizeString(JSContext *cx, JSString *str, InternBehavior ib)
523
js_AtomizeString(JSContext *cx, JSString *str, InternBehavior ib)
524
{
524
{
525
    if (str->isAtom()) {
525
    if (str->isAtom()) {
526
        JSAtom &atom = str->asAtom();
526
        JSAtom &atom = str->asAtom();
527
        /* N.B. static atoms are effectively always interned. */
527
        /* N.B. static atoms are effectively always interned. */
528
        if (ib != InternAtom || js::StaticStrings::isStatic(&atom))
528
        if (ib != InternAtom || cx->runtime->staticStrings.isStatic(&atom))
529
            return &atom;
529
            return &atom;
530
530
531
        /* Here we have to check whether the atom is already interned. */
531
        /* Here we have to check whether the atom is already interned. */
532
        AutoLockAtomsCompartment lock(cx);
532
        AutoLockAtomsCompartment lock(cx);
533
533
534
        AtomSet &atoms = cx->runtime->atomState.atoms;
534
        AtomSet &atoms = cx->runtime->atomState.atoms;
535
        AtomSet::Ptr p = atoms.lookup(AtomHasher::Lookup(&atom));
535
        AtomSet::Ptr p = atoms.lookup(AtomHasher::Lookup(&atom));
536
        JS_ASSERT(p); /* Non-static atom must exist in atom state set. */
536
        JS_ASSERT(p); /* Non-static atom must exist in atom state set. */
(-)a/js/src/jsgcchunk.cpp (+25 lines)
Lines 30-45 Link Here
30
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
 *
31
 *
32
 * ***** END LICENSE BLOCK ***** */
32
 * ***** END LICENSE BLOCK ***** */
33
33
34
#include <stdlib.h>
34
#include <stdlib.h>
35
#include "jstypes.h"
35
#include "jstypes.h"
36
#include "jsstdint.h"
36
#include "jsstdint.h"
37
#include "jsgcchunk.h"
37
#include "jsgcchunk.h"
38
#include "yarr/PageBlock.h" /* for pageSize() */
38
39
39
#ifdef XP_WIN
40
#ifdef XP_WIN
40
# include "jswin.h"
41
# include "jswin.h"
41
42
42
# ifdef _MSC_VER
43
# ifdef _MSC_VER
43
#  pragma warning( disable: 4267 4996 4146 )
44
#  pragma warning( disable: 4267 4996 4146 )
44
# endif
45
# endif
45
46
Lines 299-314 UnmapPages(void *addr, size_t size) Link Here
299
    JS_ALWAYS_TRUE(munmap((caddr_t) addr, size) == 0);
300
    JS_ALWAYS_TRUE(munmap((caddr_t) addr, size) == 0);
300
#else
301
#else
301
    JS_ALWAYS_TRUE(munmap(addr, size) == 0);
302
    JS_ALWAYS_TRUE(munmap(addr, size) == 0);
302
#endif
303
#endif
303
}
304
}
304
305
305
#endif
306
#endif
306
307
308
static size_t
309
RoundUpToPage(size_t size)
310
{
311
    size_t page = pageSize();
312
    size_t mask = page - 1;
313
    return (size + mask) & ~mask;
314
}
315
307
namespace js {
316
namespace js {
308
namespace gc {
317
namespace gc {
309
318
310
static inline void *
319
static inline void *
311
FindChunkStart(void *p)
320
FindChunkStart(void *p)
312
{
321
{
313
    jsuword addr = reinterpret_cast<jsuword>(p);
322
    jsuword addr = reinterpret_cast<jsuword>(p);
314
    addr = (addr + ChunkMask) & ~ChunkMask;
323
    addr = (addr + ChunkMask) & ~ChunkMask;
Lines 402-412 DecommitMemory(void *addr, size_t size) Link Here
402
    JS_ASSERT(uintptr_t(addr) % 4096UL == 0);
411
    JS_ASSERT(uintptr_t(addr) % 4096UL == 0);
403
    int result = madvise(addr, size, MADV_DONTNEED);
412
    int result = madvise(addr, size, MADV_DONTNEED);
404
    return result != -1;
413
    return result != -1;
405
}
414
}
406
#else
415
#else
407
# error "No CommitMemory defined on this platform."
416
# error "No CommitMemory defined on this platform."
408
#endif
417
#endif
409
418
419
void *
420
MapMemory(size_t size)
421
{
422
#ifdef JS_GC_HAS_MAP_ALIGN
423
    return MapAlignedPages(RoundUpToPage(size), pageSize()); 
424
#else
425
    return MapPages(NULL, RoundUpToPage(size)); 
426
#endif /* !JS_GC_HAS_MAP_ALIGN */
427
}
428
429
void
430
UnmapMemory(void *addr, size_t size)
431
{
432
    UnmapPages(addr, RoundUpToPage(size));
433
}
434
410
} /* namespace gc */
435
} /* namespace gc */
411
} /* namespace js */
436
} /* namespace js */
412
437
(-)a/js/src/jsgcchunk.h (+6 lines)
Lines 57-68 void Link Here
57
FreeChunk(void *p);
57
FreeChunk(void *p);
58
58
59
bool
59
bool
60
CommitMemory(void *addr, size_t size);
60
CommitMemory(void *addr, size_t size);
61
61
62
bool
62
bool
63
DecommitMemory(void *addr, size_t size);
63
DecommitMemory(void *addr, size_t size);
64
64
65
void *
66
MapMemory(size_t size);
67
68
void
69
UnmapMemory(void *addr, size_t size);
70
65
} /* namespace gc */
71
} /* namespace gc */
66
} /* namespace js */
72
} /* namespace js */
67
73
68
#endif /* jsgchunk_h__ */
74
#endif /* jsgchunk_h__ */
(-)a/js/src/vm/String.cpp (-27 / +75 lines)
Lines 39-54 Link Here
39
 * ***** END LICENSE BLOCK ***** */
39
 * ***** END LICENSE BLOCK ***** */
40
40
41
#include "mozilla/RangedPtr.h"
41
#include "mozilla/RangedPtr.h"
42
42
43
#include "jsgcmark.h"
43
#include "jsgcmark.h"
44
44
45
#include "String.h"
45
#include "String.h"
46
#include "String-inl.h"
46
#include "String-inl.h"
47
#include "jsgcchunk.h"
47
48
48
using namespace mozilla;
49
using namespace mozilla;
49
using namespace js;
50
using namespace js;
50
51
51
bool
52
bool
52
JSString::isShort() const
53
JSString::isShort() const
53
{
54
{
54
    bool is_short = (getAllocKind() == gc::FINALIZE_SHORT_STRING);
55
    bool is_short = (getAllocKind() == gc::FINALIZE_SHORT_STRING);
Lines 393-449 JSFlatString::isIndex(uint32 *indexp) co Link Here
393
 * the lowercase letters, and the next 26 are the uppercase letters.
394
 * the lowercase letters, and the next 26 are the uppercase letters.
394
 */
395
 */
395
#define TO_SMALL_CHAR(c) ((c) >= '0' && (c) <= '9' ? (c) - '0' :              \
396
#define TO_SMALL_CHAR(c) ((c) >= '0' && (c) <= '9' ? (c) - '0' :              \
396
                          (c) >= 'a' && (c) <= 'z' ? (c) - 'a' + 10 :         \
397
                          (c) >= 'a' && (c) <= 'z' ? (c) - 'a' + 10 :         \
397
                          (c) >= 'A' && (c) <= 'Z' ? (c) - 'A' + 36 :         \
398
                          (c) >= 'A' && (c) <= 'Z' ? (c) - 'A' + 36 :         \
398
                          StaticStrings::INVALID_SMALL_CHAR)
399
                          StaticStrings::INVALID_SMALL_CHAR)
399
400
400
#define R TO_SMALL_CHAR
401
#define R TO_SMALL_CHAR
402
#ifdef JS_MMEM_FOR_STATIC_STRINGS
403
const StaticStrings::SmallChar StaticStrings::toSmallCharConstImage[] = { R7(0) };
404
#else /* JS_MMEM_FOR_STATIC_STRINGS */
401
const StaticStrings::SmallChar StaticStrings::toSmallChar[] = { R7(0) };
405
const StaticStrings::SmallChar StaticStrings::toSmallChar[] = { R7(0) };
406
#endif /* JS_MMEM_FOR_STATIC_STRINGS */
402
#undef R
407
#undef R
403
408
409
StaticStrings::~StaticStrings()
410
{
411
#ifdef JS_MMEM_FOR_STATIC_STRINGS
412
    if (initialized) {
413
        gc::UnmapMemory(mappedMem, sizeof(*mappedMem));
414
    }
415
#endif /* JS_MMEM_FOR_STATIC_STRINGS */
416
}
417
404
bool
418
bool
405
StaticStrings::init(JSContext *cx)
419
StaticStrings::init(JSContext *cx)
406
{
420
{
407
    SwitchToCompartment sc(cx, cx->runtime->atomsCompartment);
421
    if (!initialized) {
408
422
409
    for (uint32 i = 0; i < UNIT_STATIC_LIMIT; i++) {
423
#ifdef JS_MMEM_FOR_STATIC_STRINGS
410
        jschar buffer[] = { i, 0x00 };
411
        JSFixedString *s = js_NewStringCopyN(cx, buffer, 1);
412
        if (!s)
413
            return false;
414
        unitStaticTable[i] = s->morphAtomizedStringIntoAtom();
415
    }
416
424
417
    for (uint32 i = 0; i < NUM_SMALL_CHARS * NUM_SMALL_CHARS; i++) {
425
		mappedMem = reinterpret_cast<MappedTables*>(gc::MapMemory(sizeof(*mappedMem)));
418
        jschar buffer[] = { FROM_SMALL_CHAR(i >> 6), FROM_SMALL_CHAR(i & 0x3F), 0x00 };
426
        if (!mappedMem)
419
        JSFixedString *s = js_NewStringCopyN(cx, buffer, 2);
420
        if (!s)
421
            return false;
427
            return false;
422
        length2StaticTable[i] = s->morphAtomizedStringIntoAtom();
428
		
423
    }
429
        length2StaticTable = mappedMem->length2StaticTable;
430
        intStaticTable = mappedMem->intStaticTable;
431
        unitStaticTable = mappedMem->unitStaticTable;
432
        toSmallChar = mappedMem->toSmallChar;
433
434
        for (uint32 i = 0;
435
             i < sizeof(toSmallCharConstImage)/sizeof(toSmallCharConstImage[0]);
436
             i++)
437
            mappedMem->toSmallChar[i] = toSmallCharConstImage[i];
438
439
#endif /* JS_MMEM_FOR_STATIC_STRINGS */
440
441
        SwitchToCompartment sc(cx, cx->runtime->atomsCompartment);
442
443
        for (uint32 i = 0; i < UNIT_STATIC_LIMIT; i++) {
444
            jschar buffer[] = { i, 0x00 };
445
            JSFixedString *s = js_NewStringCopyN(cx, buffer, 1);
446
            if (!s) {
447
#ifdef JS_MMEM_FOR_STATIC_STRINGS
448
                gc::UnmapMemory(mappedMem, sizeof(*mappedMem));
449
#endif /* JS_MMEM_FOR_STATIC_STRINGS */
450
                return false;
451
            }
452
            unitStaticTable[i] = s->morphAtomizedStringIntoAtom();
453
        }
424
454
425
    for (uint32 i = 0; i < INT_STATIC_LIMIT; i++) {
455
        for (uint32 i = 0; i < NUM_SMALL_CHARS * NUM_SMALL_CHARS; i++) {
426
        if (i < 10) {
456
            jschar buffer[] = { FROM_SMALL_CHAR(i >> 6), FROM_SMALL_CHAR(i & 0x3F), 0x00 };
427
            intStaticTable[i] = unitStaticTable[i + '0'];
457
            JSFixedString *s = js_NewStringCopyN(cx, buffer, 2);
428
        } else if (i < 100) {
458
            if (!s) {
429
            size_t index = ((size_t)TO_SMALL_CHAR((i / 10) + '0') << 6) +
459
#ifdef JS_MMEM_FOR_STATIC_STRINGS
430
                TO_SMALL_CHAR((i % 10) + '0');
460
                gc::UnmapMemory(mappedMem, sizeof(*mappedMem));
431
            intStaticTable[i] = length2StaticTable[index];
461
#endif /* JS_MMEM_FOR_STATIC_STRINGS */
432
        } else {
433
            jschar buffer[] = { (i / 100) + '0', ((i / 10) % 10) + '0', (i % 10) + '0', 0x00 };
434
            JSFixedString *s = js_NewStringCopyN(cx, buffer, 3);
435
            if (!s)
436
                return false;
462
                return false;
437
            intStaticTable[i] = s->morphAtomizedStringIntoAtom();
463
            }
464
            length2StaticTable[i] = s->morphAtomizedStringIntoAtom();
438
        }
465
        }
466
467
        for (uint32 i = 0; i < INT_STATIC_LIMIT; i++) {
468
            if (i < 10) {
469
                intStaticTable[i] = unitStaticTable[i + '0'];
470
            } else if (i < 100) {
471
                size_t index = ((size_t)TO_SMALL_CHAR((i / 10) + '0') << 6) +
472
                    TO_SMALL_CHAR((i % 10) + '0');
473
                intStaticTable[i] = length2StaticTable[index];
474
            } else {
475
                jschar buffer[] = { (i / 100) + '0', ((i / 10) % 10) + '0', (i % 10) + '0', 0x00 };
476
                JSFixedString *s = js_NewStringCopyN(cx, buffer, 3);
477
                if (!s) {
478
#ifdef JS_MMEM_FOR_STATIC_STRINGS
479
                    gc::UnmapMemory(mappedMem, sizeof(*mappedMem));
480
#endif /* JS_MMEM_FOR_STATIC_STRINGS */
481
                    return false;
482
                }
483
                intStaticTable[i] = s->morphAtomizedStringIntoAtom();
484
            }
485
        }
486
487
        initialized = true;
439
    }
488
    }
440
489
441
    initialized = true;
442
    return true;
490
    return true;
443
}
491
}
444
492
445
void
493
void
446
StaticStrings::trace(JSTracer *trc)
494
StaticStrings::trace(JSTracer *trc)
447
{
495
{
448
    if (!initialized)
496
    if (!initialized)
449
        return;
497
        return;
(-)a/js/src/vm/String.h (-9 / +55 lines)
Lines 41-56 Link Here
41
#ifndef String_h_
41
#ifndef String_h_
42
#define String_h_
42
#define String_h_
43
43
44
#include "mozilla/Util.h"
44
#include "mozilla/Util.h"
45
45
46
#include "jsapi.h"
46
#include "jsapi.h"
47
#include "jscell.h"
47
#include "jscell.h"
48
48
49
#if defined(__ia64__)
50
/*
51
 * Don't use static strings in static memory on ia64 since the compiler may
52
 * put it out of the acceptable 47-bit jsval pointer range. Use dynamic memory
53
 * which is mapped to 47-bit jsval pointer range instead. Enabling the JIT
54
 * isn't possible with that.
55
 */
56
# define JS_MMEM_FOR_STATIC_STRINGS
57
#endif
58
49
class JSString;
59
class JSString;
50
class JSDependentString;
60
class JSDependentString;
51
class JSUndependedString;
61
class JSUndependedString;
52
class JSExtensibleString;
62
class JSExtensibleString;
53
class JSExternalString;
63
class JSExternalString;
54
class JSLinearString;
64
class JSLinearString;
55
class JSFixedString;
65
class JSFixedString;
56
class JSRope;
66
class JSRope;
Lines 702-754 class StaticStrings Link Here
702
    bool initialized;
712
    bool initialized;
703
713
704
    /* Bigger chars cannot be in a length-2 string. */
714
    /* Bigger chars cannot be in a length-2 string. */
705
    static const size_t SMALL_CHAR_LIMIT    = 128U;
715
    static const size_t SMALL_CHAR_LIMIT    = 128U;
706
    static const size_t NUM_SMALL_CHARS     = 64U;
716
    static const size_t NUM_SMALL_CHARS     = 64U;
707
717
708
    static const size_t INT_STATIC_LIMIT    = 256U;
718
    static const size_t INT_STATIC_LIMIT    = 256U;
709
719
720
  public:
721
    /* We keep these public for the methodjit. */
722
    static const size_t UNIT_STATIC_LIMIT   = 256U;
723
724
  private:
725
    typedef uint8 SmallChar;
726
    static const SmallChar INVALID_SMALL_CHAR = -1;
727
728
#ifdef JS_MMEM_FOR_STATIC_STRINGS
729
730
  private:
731
    /* The array has NUM_SMALL_CHARS * NUM_SMALL_CHARS elements. */
732
    JSAtom **length2StaticTable;
733
    /* The array has INT_STATIC_LIMIT elements. */
734
    JSAtom **intStaticTable;
735
  public:
736
    /* We keep these public for the methodjit. */
737
    /* The array has UNIT_STATIC_LIMIT elements. */
738
    JSAtom **unitStaticTable;
739
  private:
740
    static const SmallChar toSmallCharConstImage[];
741
    /* The array has SMALL_CHAR_LIMIT elements. */
742
    const SmallChar *toSmallChar;
743
744
    struct MappedTables
745
    {
746
        JSAtom *length2StaticTable[NUM_SMALL_CHARS * NUM_SMALL_CHARS];
747
        JSAtom *intStaticTable[INT_STATIC_LIMIT];
748
        JSAtom *unitStaticTable[UNIT_STATIC_LIMIT];
749
        SmallChar toSmallChar[SMALL_CHAR_LIMIT];
750
    };
751
752
    MappedTables *mappedMem;
753
754
#else /* JS_MMEM_FOR_STATIC_STRINGS */
755
756
  private:
710
    JSAtom *length2StaticTable[NUM_SMALL_CHARS * NUM_SMALL_CHARS];
757
    JSAtom *length2StaticTable[NUM_SMALL_CHARS * NUM_SMALL_CHARS];
711
    JSAtom *intStaticTable[INT_STATIC_LIMIT];
758
    JSAtom *intStaticTable[INT_STATIC_LIMIT];
712
713
  public:
759
  public:
714
    /* We keep these public for the methodjit. */
760
    /* We keep these public for the methodjit. */
715
    static const size_t UNIT_STATIC_LIMIT   = 256U;
716
    JSAtom *unitStaticTable[UNIT_STATIC_LIMIT];
761
    JSAtom *unitStaticTable[UNIT_STATIC_LIMIT];
762
  private:
763
    static const SmallChar toSmallChar[];
764
765
#endif /* JS_MMEM_FOR_STATIC_STRINGS */
717
766
767
  public:
718
    StaticStrings() : initialized(false) {}
768
    StaticStrings() : initialized(false) {}
769
    ~StaticStrings();
719
770
720
    bool init(JSContext *cx);
771
    bool init(JSContext *cx);
721
    void trace(JSTracer *trc);
772
    void trace(JSTracer *trc);
722
773
723
    static inline bool hasUint(uint32 u);
774
    static inline bool hasUint(uint32 u);
724
    inline JSAtom *getUint(uint32 u);
775
    inline JSAtom *getUint(uint32 u);
725
776
726
    static inline bool hasInt(int32 i);
777
    static inline bool hasInt(int32 i);
727
    inline JSAtom *getInt(jsint i);
778
    inline JSAtom *getInt(jsint i);
728
779
729
    static inline bool hasUnit(jschar c);
780
    static inline bool hasUnit(jschar c);
730
    JSAtom *getUnit(jschar c);
781
    JSAtom *getUnit(jschar c);
731
782
732
    /* May not return atom, returns null on (reported) failure. */
783
    /* May not return atom, returns null on (reported) failure. */
733
    inline JSLinearString *getUnitStringForElement(JSContext *cx, JSString *str, size_t index);
784
    inline JSLinearString *getUnitStringForElement(JSContext *cx, JSString *str, size_t index);
734
785
735
    static bool isStatic(JSAtom *atom);
786
    bool isStatic(JSAtom *atom);
736
787
737
    /* Return null if no static atom exists for the given (chars, length). */
788
    /* Return null if no static atom exists for the given (chars, length). */
738
    inline JSAtom *lookup(const jschar *chars, size_t length);
789
    inline JSAtom *lookup(const jschar *chars, size_t length);
739
790
740
  private:
791
  private:
741
    typedef uint8 SmallChar;
792
    inline bool fitsInSmallChar(jschar c);
742
    static const SmallChar INVALID_SMALL_CHAR = -1;
743
744
    static inline bool fitsInSmallChar(jschar c);
745
746
    static const SmallChar toSmallChar[];
747
793
748
    JSAtom *getLength2(jschar c1, jschar c2);
794
    JSAtom *getLength2(jschar c1, jschar c2);
749
    JSAtom *getLength2(uint32 i);
795
    JSAtom *getLength2(uint32 i);
750
};
796
};
751
797
752
/*
798
/*
753
 * Represents an atomized string which does not contain an index (that is, an
799
 * Represents an atomized string which does not contain an index (that is, an
754
 * unsigned 32-bit value).  Thus for any PropertyName propname,
800
 * unsigned 32-bit value).  Thus for any PropertyName propname,

Return to bug 471622