Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
fceef8e0
Commit
fceef8e0
authored
Jun 20, 2014
by
antirez
Browse files
Jemalloc updated to 3.6.0.
Not a single bug in about 3 months, and our previous version was too old (3.2.0).
parent
fe596d67
Changes
143
Hide whitespace changes
Inline
Side-by-side
deps/jemalloc/test/include/test/SFMT-params4253.h
0 → 100644
View file @
fceef8e0
/*
* This file derives from SFMT 1.3.3
* (http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/SFMT/index.html), which was
* released under the terms of the following license:
*
* Copyright (c) 2006,2007 Mutsuo Saito, Makoto Matsumoto and Hiroshima
* University. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of the Hiroshima University nor the names of
* its contributors may be used to endorse or promote products
* derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef SFMT_PARAMS4253_H
#define SFMT_PARAMS4253_H
#define POS1 17
#define SL1 20
#define SL2 1
#define SR1 7
#define SR2 1
#define MSK1 0x9f7bffffU
#define MSK2 0x9fffff5fU
#define MSK3 0x3efffffbU
#define MSK4 0xfffff7bbU
#define PARITY1 0xa8000001U
#define PARITY2 0xaf5390a3U
#define PARITY3 0xb740b3f8U
#define PARITY4 0x6c11486dU
/* PARAMETERS FOR ALTIVEC */
#if defined(__APPLE__)
/* For OSX */
#define ALTI_SL1 (vector unsigned int)(SL1, SL1, SL1, SL1)
#define ALTI_SR1 (vector unsigned int)(SR1, SR1, SR1, SR1)
#define ALTI_MSK (vector unsigned int)(MSK1, MSK2, MSK3, MSK4)
#define ALTI_MSK64 \
(vector unsigned int)(MSK2, MSK1, MSK4, MSK3)
#define ALTI_SL2_PERM \
(vector unsigned char)(1,2,3,23,5,6,7,0,9,10,11,4,13,14,15,8)
#define ALTI_SL2_PERM64 \
(vector unsigned char)(1,2,3,4,5,6,7,31,9,10,11,12,13,14,15,0)
#define ALTI_SR2_PERM \
(vector unsigned char)(7,0,1,2,11,4,5,6,15,8,9,10,17,12,13,14)
#define ALTI_SR2_PERM64 \
(vector unsigned char)(15,0,1,2,3,4,5,6,17,8,9,10,11,12,13,14)
#else
/* For OTHER OSs(Linux?) */
#define ALTI_SL1 {SL1, SL1, SL1, SL1}
#define ALTI_SR1 {SR1, SR1, SR1, SR1}
#define ALTI_MSK {MSK1, MSK2, MSK3, MSK4}
#define ALTI_MSK64 {MSK2, MSK1, MSK4, MSK3}
#define ALTI_SL2_PERM {1,2,3,23,5,6,7,0,9,10,11,4,13,14,15,8}
#define ALTI_SL2_PERM64 {1,2,3,4,5,6,7,31,9,10,11,12,13,14,15,0}
#define ALTI_SR2_PERM {7,0,1,2,11,4,5,6,15,8,9,10,17,12,13,14}
#define ALTI_SR2_PERM64 {15,0,1,2,3,4,5,6,17,8,9,10,11,12,13,14}
#endif
/* For OSX */
#define IDSTR "SFMT-4253:17-20-1-7-1:9f7bffff-9fffff5f-3efffffb-fffff7bb"
#endif
/* SFMT_PARAMS4253_H */
deps/jemalloc/test/include/test/SFMT-params44497.h
0 → 100644
View file @
fceef8e0
/*
* This file derives from SFMT 1.3.3
* (http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/SFMT/index.html), which was
* released under the terms of the following license:
*
* Copyright (c) 2006,2007 Mutsuo Saito, Makoto Matsumoto and Hiroshima
* University. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of the Hiroshima University nor the names of
* its contributors may be used to endorse or promote products
* derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef SFMT_PARAMS44497_H
#define SFMT_PARAMS44497_H
#define POS1 330
#define SL1 5
#define SL2 3
#define SR1 9
#define SR2 3
#define MSK1 0xeffffffbU
#define MSK2 0xdfbebfffU
#define MSK3 0xbfbf7befU
#define MSK4 0x9ffd7bffU
#define PARITY1 0x00000001U
#define PARITY2 0x00000000U
#define PARITY3 0xa3ac4000U
#define PARITY4 0xecc1327aU
/* PARAMETERS FOR ALTIVEC */
#if defined(__APPLE__)
/* For OSX */
#define ALTI_SL1 (vector unsigned int)(SL1, SL1, SL1, SL1)
#define ALTI_SR1 (vector unsigned int)(SR1, SR1, SR1, SR1)
#define ALTI_MSK (vector unsigned int)(MSK1, MSK2, MSK3, MSK4)
#define ALTI_MSK64 \
(vector unsigned int)(MSK2, MSK1, MSK4, MSK3)
#define ALTI_SL2_PERM \
(vector unsigned char)(3,21,21,21,7,0,1,2,11,4,5,6,15,8,9,10)
#define ALTI_SL2_PERM64 \
(vector unsigned char)(3,4,5,6,7,29,29,29,11,12,13,14,15,0,1,2)
#define ALTI_SR2_PERM \
(vector unsigned char)(5,6,7,0,9,10,11,4,13,14,15,8,19,19,19,12)
#define ALTI_SR2_PERM64 \
(vector unsigned char)(13,14,15,0,1,2,3,4,19,19,19,8,9,10,11,12)
#else
/* For OTHER OSs(Linux?) */
#define ALTI_SL1 {SL1, SL1, SL1, SL1}
#define ALTI_SR1 {SR1, SR1, SR1, SR1}
#define ALTI_MSK {MSK1, MSK2, MSK3, MSK4}
#define ALTI_MSK64 {MSK2, MSK1, MSK4, MSK3}
#define ALTI_SL2_PERM {3,21,21,21,7,0,1,2,11,4,5,6,15,8,9,10}
#define ALTI_SL2_PERM64 {3,4,5,6,7,29,29,29,11,12,13,14,15,0,1,2}
#define ALTI_SR2_PERM {5,6,7,0,9,10,11,4,13,14,15,8,19,19,19,12}
#define ALTI_SR2_PERM64 {13,14,15,0,1,2,3,4,19,19,19,8,9,10,11,12}
#endif
/* For OSX */
#define IDSTR "SFMT-44497:330-5-3-9-3:effffffb-dfbebfff-bfbf7bef-9ffd7bff"
#endif
/* SFMT_PARAMS44497_H */
deps/jemalloc/test/include/test/SFMT-params607.h
0 → 100644
View file @
fceef8e0
/*
* This file derives from SFMT 1.3.3
* (http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/SFMT/index.html), which was
* released under the terms of the following license:
*
* Copyright (c) 2006,2007 Mutsuo Saito, Makoto Matsumoto and Hiroshima
* University. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of the Hiroshima University nor the names of
* its contributors may be used to endorse or promote products
* derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef SFMT_PARAMS607_H
#define SFMT_PARAMS607_H
#define POS1 2
#define SL1 15
#define SL2 3
#define SR1 13
#define SR2 3
#define MSK1 0xfdff37ffU
#define MSK2 0xef7f3f7dU
#define MSK3 0xff777b7dU
#define MSK4 0x7ff7fb2fU
#define PARITY1 0x00000001U
#define PARITY2 0x00000000U
#define PARITY3 0x00000000U
#define PARITY4 0x5986f054U
/* PARAMETERS FOR ALTIVEC */
#if defined(__APPLE__)
/* For OSX */
#define ALTI_SL1 (vector unsigned int)(SL1, SL1, SL1, SL1)
#define ALTI_SR1 (vector unsigned int)(SR1, SR1, SR1, SR1)
#define ALTI_MSK (vector unsigned int)(MSK1, MSK2, MSK3, MSK4)
#define ALTI_MSK64 \
(vector unsigned int)(MSK2, MSK1, MSK4, MSK3)
#define ALTI_SL2_PERM \
(vector unsigned char)(3,21,21,21,7,0,1,2,11,4,5,6,15,8,9,10)
#define ALTI_SL2_PERM64 \
(vector unsigned char)(3,4,5,6,7,29,29,29,11,12,13,14,15,0,1,2)
#define ALTI_SR2_PERM \
(vector unsigned char)(5,6,7,0,9,10,11,4,13,14,15,8,19,19,19,12)
#define ALTI_SR2_PERM64 \
(vector unsigned char)(13,14,15,0,1,2,3,4,19,19,19,8,9,10,11,12)
#else
/* For OTHER OSs(Linux?) */
#define ALTI_SL1 {SL1, SL1, SL1, SL1}
#define ALTI_SR1 {SR1, SR1, SR1, SR1}
#define ALTI_MSK {MSK1, MSK2, MSK3, MSK4}
#define ALTI_MSK64 {MSK2, MSK1, MSK4, MSK3}
#define ALTI_SL2_PERM {3,21,21,21,7,0,1,2,11,4,5,6,15,8,9,10}
#define ALTI_SL2_PERM64 {3,4,5,6,7,29,29,29,11,12,13,14,15,0,1,2}
#define ALTI_SR2_PERM {5,6,7,0,9,10,11,4,13,14,15,8,19,19,19,12}
#define ALTI_SR2_PERM64 {13,14,15,0,1,2,3,4,19,19,19,8,9,10,11,12}
#endif
/* For OSX */
#define IDSTR "SFMT-607:2-15-3-13-3:fdff37ff-ef7f3f7d-ff777b7d-7ff7fb2f"
#endif
/* SFMT_PARAMS607_H */
deps/jemalloc/test/include/test/SFMT-params86243.h
0 → 100644
View file @
fceef8e0
/*
* This file derives from SFMT 1.3.3
* (http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/SFMT/index.html), which was
* released under the terms of the following license:
*
* Copyright (c) 2006,2007 Mutsuo Saito, Makoto Matsumoto and Hiroshima
* University. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of the Hiroshima University nor the names of
* its contributors may be used to endorse or promote products
* derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef SFMT_PARAMS86243_H
#define SFMT_PARAMS86243_H
#define POS1 366
#define SL1 6
#define SL2 7
#define SR1 19
#define SR2 1
#define MSK1 0xfdbffbffU
#define MSK2 0xbff7ff3fU
#define MSK3 0xfd77efffU
#define MSK4 0xbf9ff3ffU
#define PARITY1 0x00000001U
#define PARITY2 0x00000000U
#define PARITY3 0x00000000U
#define PARITY4 0xe9528d85U
/* PARAMETERS FOR ALTIVEC */
#if defined(__APPLE__)
/* For OSX */
#define ALTI_SL1 (vector unsigned int)(SL1, SL1, SL1, SL1)
#define ALTI_SR1 (vector unsigned int)(SR1, SR1, SR1, SR1)
#define ALTI_MSK (vector unsigned int)(MSK1, MSK2, MSK3, MSK4)
#define ALTI_MSK64 \
(vector unsigned int)(MSK2, MSK1, MSK4, MSK3)
#define ALTI_SL2_PERM \
(vector unsigned char)(25,25,25,25,3,25,25,25,7,0,1,2,11,4,5,6)
#define ALTI_SL2_PERM64 \
(vector unsigned char)(7,25,25,25,25,25,25,25,15,0,1,2,3,4,5,6)
#define ALTI_SR2_PERM \
(vector unsigned char)(7,0,1,2,11,4,5,6,15,8,9,10,17,12,13,14)
#define ALTI_SR2_PERM64 \
(vector unsigned char)(15,0,1,2,3,4,5,6,17,8,9,10,11,12,13,14)
#else
/* For OTHER OSs(Linux?) */
#define ALTI_SL1 {SL1, SL1, SL1, SL1}
#define ALTI_SR1 {SR1, SR1, SR1, SR1}
#define ALTI_MSK {MSK1, MSK2, MSK3, MSK4}
#define ALTI_MSK64 {MSK2, MSK1, MSK4, MSK3}
#define ALTI_SL2_PERM {25,25,25,25,3,25,25,25,7,0,1,2,11,4,5,6}
#define ALTI_SL2_PERM64 {7,25,25,25,25,25,25,25,15,0,1,2,3,4,5,6}
#define ALTI_SR2_PERM {7,0,1,2,11,4,5,6,15,8,9,10,17,12,13,14}
#define ALTI_SR2_PERM64 {15,0,1,2,3,4,5,6,17,8,9,10,11,12,13,14}
#endif
/* For OSX */
#define IDSTR "SFMT-86243:366-6-7-19-1:fdbffbff-bff7ff3f-fd77efff-bf9ff3ff"
#endif
/* SFMT_PARAMS86243_H */
deps/jemalloc/test/include/test/SFMT-sse2.h
0 → 100644
View file @
fceef8e0
/*
* This file derives from SFMT 1.3.3
* (http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/SFMT/index.html), which was
* released under the terms of the following license:
*
* Copyright (c) 2006,2007 Mutsuo Saito, Makoto Matsumoto and Hiroshima
* University. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of the Hiroshima University nor the names of
* its contributors may be used to endorse or promote products
* derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @file SFMT-sse2.h
* @brief SIMD oriented Fast Mersenne Twister(SFMT) for Intel SSE2
*
* @author Mutsuo Saito (Hiroshima University)
* @author Makoto Matsumoto (Hiroshima University)
*
* @note We assume LITTLE ENDIAN in this file
*
* Copyright (C) 2006, 2007 Mutsuo Saito, Makoto Matsumoto and Hiroshima
* University. All rights reserved.
*
* The new BSD License is applied to this software, see LICENSE.txt
*/
#ifndef SFMT_SSE2_H
#define SFMT_SSE2_H
/**
* This function represents the recursion formula.
* @param a a 128-bit part of the interal state array
* @param b a 128-bit part of the interal state array
* @param c a 128-bit part of the interal state array
* @param d a 128-bit part of the interal state array
* @param mask 128-bit mask
* @return output
*/
JEMALLOC_ALWAYS_INLINE
__m128i
mm_recursion
(
__m128i
*
a
,
__m128i
*
b
,
__m128i
c
,
__m128i
d
,
__m128i
mask
)
{
__m128i
v
,
x
,
y
,
z
;
x
=
_mm_load_si128
(
a
);
y
=
_mm_srli_epi32
(
*
b
,
SR1
);
z
=
_mm_srli_si128
(
c
,
SR2
);
v
=
_mm_slli_epi32
(
d
,
SL1
);
z
=
_mm_xor_si128
(
z
,
x
);
z
=
_mm_xor_si128
(
z
,
v
);
x
=
_mm_slli_si128
(
x
,
SL2
);
y
=
_mm_and_si128
(
y
,
mask
);
z
=
_mm_xor_si128
(
z
,
x
);
z
=
_mm_xor_si128
(
z
,
y
);
return
z
;
}
/**
* This function fills the internal state array with pseudorandom
* integers.
*/
JEMALLOC_INLINE
void
gen_rand_all
(
sfmt_t
*
ctx
)
{
int
i
;
__m128i
r
,
r1
,
r2
,
mask
;
mask
=
_mm_set_epi32
(
MSK4
,
MSK3
,
MSK2
,
MSK1
);
r1
=
_mm_load_si128
(
&
ctx
->
sfmt
[
N
-
2
].
si
);
r2
=
_mm_load_si128
(
&
ctx
->
sfmt
[
N
-
1
].
si
);
for
(
i
=
0
;
i
<
N
-
POS1
;
i
++
)
{
r
=
mm_recursion
(
&
ctx
->
sfmt
[
i
].
si
,
&
ctx
->
sfmt
[
i
+
POS1
].
si
,
r1
,
r2
,
mask
);
_mm_store_si128
(
&
ctx
->
sfmt
[
i
].
si
,
r
);
r1
=
r2
;
r2
=
r
;
}
for
(;
i
<
N
;
i
++
)
{
r
=
mm_recursion
(
&
ctx
->
sfmt
[
i
].
si
,
&
ctx
->
sfmt
[
i
+
POS1
-
N
].
si
,
r1
,
r2
,
mask
);
_mm_store_si128
(
&
ctx
->
sfmt
[
i
].
si
,
r
);
r1
=
r2
;
r2
=
r
;
}
}
/**
* This function fills the user-specified array with pseudorandom
* integers.
*
* @param array an 128-bit array to be filled by pseudorandom numbers.
* @param size number of 128-bit pesudorandom numbers to be generated.
*/
JEMALLOC_INLINE
void
gen_rand_array
(
sfmt_t
*
ctx
,
w128_t
*
array
,
int
size
)
{
int
i
,
j
;
__m128i
r
,
r1
,
r2
,
mask
;
mask
=
_mm_set_epi32
(
MSK4
,
MSK3
,
MSK2
,
MSK1
);
r1
=
_mm_load_si128
(
&
ctx
->
sfmt
[
N
-
2
].
si
);
r2
=
_mm_load_si128
(
&
ctx
->
sfmt
[
N
-
1
].
si
);
for
(
i
=
0
;
i
<
N
-
POS1
;
i
++
)
{
r
=
mm_recursion
(
&
ctx
->
sfmt
[
i
].
si
,
&
ctx
->
sfmt
[
i
+
POS1
].
si
,
r1
,
r2
,
mask
);
_mm_store_si128
(
&
array
[
i
].
si
,
r
);
r1
=
r2
;
r2
=
r
;
}
for
(;
i
<
N
;
i
++
)
{
r
=
mm_recursion
(
&
ctx
->
sfmt
[
i
].
si
,
&
array
[
i
+
POS1
-
N
].
si
,
r1
,
r2
,
mask
);
_mm_store_si128
(
&
array
[
i
].
si
,
r
);
r1
=
r2
;
r2
=
r
;
}
/* main loop */
for
(;
i
<
size
-
N
;
i
++
)
{
r
=
mm_recursion
(
&
array
[
i
-
N
].
si
,
&
array
[
i
+
POS1
-
N
].
si
,
r1
,
r2
,
mask
);
_mm_store_si128
(
&
array
[
i
].
si
,
r
);
r1
=
r2
;
r2
=
r
;
}
for
(
j
=
0
;
j
<
2
*
N
-
size
;
j
++
)
{
r
=
_mm_load_si128
(
&
array
[
j
+
size
-
N
].
si
);
_mm_store_si128
(
&
ctx
->
sfmt
[
j
].
si
,
r
);
}
for
(;
i
<
size
;
i
++
)
{
r
=
mm_recursion
(
&
array
[
i
-
N
].
si
,
&
array
[
i
+
POS1
-
N
].
si
,
r1
,
r2
,
mask
);
_mm_store_si128
(
&
array
[
i
].
si
,
r
);
_mm_store_si128
(
&
ctx
->
sfmt
[
j
++
].
si
,
r
);
r1
=
r2
;
r2
=
r
;
}
}
#endif
deps/jemalloc/test/include/test/SFMT.h
0 → 100644
View file @
fceef8e0
/*
* This file derives from SFMT 1.3.3
* (http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/SFMT/index.html), which was
* released under the terms of the following license:
*
* Copyright (c) 2006,2007 Mutsuo Saito, Makoto Matsumoto and Hiroshima
* University. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of the Hiroshima University nor the names of
* its contributors may be used to endorse or promote products
* derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @file SFMT.h
*
* @brief SIMD oriented Fast Mersenne Twister(SFMT) pseudorandom
* number generator
*
* @author Mutsuo Saito (Hiroshima University)
* @author Makoto Matsumoto (Hiroshima University)
*
* Copyright (C) 2006, 2007 Mutsuo Saito, Makoto Matsumoto and Hiroshima
* University. All rights reserved.
*
* The new BSD License is applied to this software.
* see LICENSE.txt
*
* @note We assume that your system has inttypes.h. If your system
* doesn't have inttypes.h, you have to typedef uint32_t and uint64_t,
* and you have to define PRIu64 and PRIx64 in this file as follows:
* @verbatim
typedef unsigned int uint32_t
typedef unsigned long long uint64_t
#define PRIu64 "llu"
#define PRIx64 "llx"
@endverbatim
* uint32_t must be exactly 32-bit unsigned integer type (no more, no
* less), and uint64_t must be exactly 64-bit unsigned integer type.
* PRIu64 and PRIx64 are used for printf function to print 64-bit
* unsigned int and 64-bit unsigned int in hexadecimal format.
*/
#ifndef SFMT_H
#define SFMT_H
typedef
struct
sfmt_s
sfmt_t
;
uint32_t
gen_rand32
(
sfmt_t
*
ctx
);
uint32_t
gen_rand32_range
(
sfmt_t
*
ctx
,
uint32_t
limit
);
uint64_t
gen_rand64
(
sfmt_t
*
ctx
);
uint64_t
gen_rand64_range
(
sfmt_t
*
ctx
,
uint64_t
limit
);
void
fill_array32
(
sfmt_t
*
ctx
,
uint32_t
*
array
,
int
size
);
void
fill_array64
(
sfmt_t
*
ctx
,
uint64_t
*
array
,
int
size
);
sfmt_t
*
init_gen_rand
(
uint32_t
seed
);
sfmt_t
*
init_by_array
(
uint32_t
*
init_key
,
int
key_length
);
void
fini_gen_rand
(
sfmt_t
*
ctx
);
const
char
*
get_idstring
(
void
);
int
get_min_array_size32
(
void
);
int
get_min_array_size64
(
void
);
#ifndef JEMALLOC_ENABLE_INLINE
double
to_real1
(
uint32_t
v
);
double
genrand_real1
(
sfmt_t
*
ctx
);
double
to_real2
(
uint32_t
v
);
double
genrand_real2
(
sfmt_t
*
ctx
);
double
to_real3
(
uint32_t
v
);
double
genrand_real3
(
sfmt_t
*
ctx
);
double
to_res53
(
uint64_t
v
);
double
to_res53_mix
(
uint32_t
x
,
uint32_t
y
);
double
genrand_res53
(
sfmt_t
*
ctx
);
double
genrand_res53_mix
(
sfmt_t
*
ctx
);
#endif
#if (defined(JEMALLOC_ENABLE_INLINE) || defined(SFMT_C_))
/* These real versions are due to Isaku Wada */
/** generates a random number on [0,1]-real-interval */
JEMALLOC_INLINE
double
to_real1
(
uint32_t
v
)
{
return
v
*
(
1.0
/
4294967295.0
);
/* divided by 2^32-1 */
}
/** generates a random number on [0,1]-real-interval */
JEMALLOC_INLINE
double
genrand_real1
(
sfmt_t
*
ctx
)
{
return
to_real1
(
gen_rand32
(
ctx
));
}
/** generates a random number on [0,1)-real-interval */
JEMALLOC_INLINE
double
to_real2
(
uint32_t
v
)
{
return
v
*
(
1.0
/
4294967296.0
);
/* divided by 2^32 */
}
/** generates a random number on [0,1)-real-interval */
JEMALLOC_INLINE
double
genrand_real2
(
sfmt_t
*
ctx
)
{
return
to_real2
(
gen_rand32
(
ctx
));
}
/** generates a random number on (0,1)-real-interval */
JEMALLOC_INLINE
double
to_real3
(
uint32_t
v
)
{
return
(((
double
)
v
)
+
0.5
)
*
(
1.0
/
4294967296.0
);
/* divided by 2^32 */
}
/** generates a random number on (0,1)-real-interval */
JEMALLOC_INLINE
double
genrand_real3
(
sfmt_t
*
ctx
)
{
return
to_real3
(
gen_rand32
(
ctx
));
}
/** These real versions are due to Isaku Wada */
/** generates a random number on [0,1) with 53-bit resolution*/
JEMALLOC_INLINE
double
to_res53
(
uint64_t
v
)
{
return
v
*
(
1.0
/
18446744073709551616.0
L
);
}
/** generates a random number on [0,1) with 53-bit resolution from two
* 32 bit integers */
JEMALLOC_INLINE
double
to_res53_mix
(
uint32_t
x
,
uint32_t
y
)
{
return
to_res53
(
x
|
((
uint64_t
)
y
<<
32
));
}
/** generates a random number on [0,1) with 53-bit resolution
*/
JEMALLOC_INLINE
double
genrand_res53
(
sfmt_t
*
ctx
)
{
return
to_res53
(
gen_rand64
(
ctx
));
}
/** generates a random number on [0,1) with 53-bit resolution
using 32bit integer.
*/
JEMALLOC_INLINE
double
genrand_res53_mix
(
sfmt_t
*
ctx
)
{
uint32_t
x
,
y
;
x
=
gen_rand32
(
ctx
);
y
=
gen_rand32
(
ctx
);
return
to_res53_mix
(
x
,
y
);
}
#endif
#endif
deps/jemalloc/test/include/test/jemalloc_test.h.in
0 → 100644
View file @
fceef8e0
#include <stdlib.h>
#include <stdarg.h>
#include <stdbool.h>
#include <errno.h>
#include <inttypes.h>
#include <math.h>
#include <string.h>
#ifdef _WIN32
# include <windows.h>
#else
# include <pthread.h>
#endif
/******************************************************************************/
/*
* Define always-enabled assertion macros, so that test assertions execute even
* if assertions are disabled in the library code. These definitions must
* exist prior to including "jemalloc/internal/util.h".
*/
#define assert(e) do { \
if (!(e)) { \
malloc_printf( \
"<jemalloc>: %s:%d: Failed assertion: \"%s\"\n", \
__FILE__, __LINE__, #e); \
abort(); \
} \
} while (0)
#define not_reached() do { \
malloc_printf( \
"<jemalloc>: %s:%d: Unreachable code reached\n", \
__FILE__, __LINE__); \
abort(); \
} while (0)
#define not_implemented() do { \
malloc_printf("<jemalloc>: %s:%d: Not implemented\n", \
__FILE__, __LINE__); \
abort(); \
} while (0)
#define assert_not_implemented(e) do { \
if (!(e)) \
not_implemented(); \
} while (0)
#include "test/jemalloc_test_defs.h"
#ifdef JEMALLOC_OSSPIN
# include <libkern/OSAtomic.h>
#endif
#if defined(HAVE_ALTIVEC) && !defined(__APPLE__)
# include <altivec.h>
#endif
#ifdef HAVE_SSE2
# include <emmintrin.h>
#endif
/******************************************************************************/
/*
* For unit tests, expose all public and private interfaces.
*/
#ifdef JEMALLOC_UNIT_TEST
# define JEMALLOC_JET
# define JEMALLOC_MANGLE
# include "jemalloc/internal/jemalloc_internal.h"
/******************************************************************************/
/*
* For integration tests, expose the public jemalloc interfaces, but only
* expose the minimum necessary internal utility code (to avoid re-implementing
* essentially identical code within the test infrastructure).
*/
#elif defined(JEMALLOC_INTEGRATION_TEST)
# define JEMALLOC_MANGLE
# include "jemalloc/jemalloc@install_suffix@.h"
# include "jemalloc/internal/jemalloc_internal_defs.h"
# include "jemalloc/internal/jemalloc_internal_macros.h"
# define JEMALLOC_N(n) @private_namespace@##n
# include "jemalloc/internal/private_namespace.h"
# define JEMALLOC_H_TYPES
# define JEMALLOC_H_STRUCTS
# define JEMALLOC_H_EXTERNS
# define JEMALLOC_H_INLINES
# include "jemalloc/internal/util.h"
# include "jemalloc/internal/qr.h"
# include "jemalloc/internal/ql.h"
# undef JEMALLOC_H_TYPES
# undef JEMALLOC_H_STRUCTS
# undef JEMALLOC_H_EXTERNS
# undef JEMALLOC_H_INLINES
/******************************************************************************/
/*
* For stress tests, expose the public jemalloc interfaces with name mangling
* so that they can be tested as e.g. malloc() and free(). Also expose the
* public jemalloc interfaces with jet_ prefixes, so that stress tests can use
* a separate allocator for their internal data structures.
*/
#elif defined(JEMALLOC_STRESS_TEST)
# include "jemalloc/jemalloc@install_suffix@.h"
# include "jemalloc/jemalloc_protos_jet.h"
# define JEMALLOC_JET
# include "jemalloc/internal/jemalloc_internal.h"
# include "jemalloc/internal/public_unnamespace.h"
# undef JEMALLOC_JET
# include "jemalloc/jemalloc_rename.h"
# define JEMALLOC_MANGLE
# ifdef JEMALLOC_STRESS_TESTLIB
# include "jemalloc/jemalloc_mangle_jet.h"
# else
# include "jemalloc/jemalloc_mangle.h"
# endif
/******************************************************************************/
/*
* This header does dangerous things, the effects of which only test code
* should be subject to.
*/
#else
# error "This header cannot be included outside a testing context"
#endif
/******************************************************************************/
/*
* Common test utilities.
*/
#include "test/math.h"
#include "test/mtx.h"
#include "test/mq.h"
#include "test/test.h"
#include "test/thd.h"
#define MEXP 19937
#include "test/SFMT.h"
deps/jemalloc/test/include/test/jemalloc_test_defs.h.in
0 → 100644
View file @
fceef8e0
#include "jemalloc/internal/jemalloc_internal_defs.h"
/* For use by SFMT. */
#undef HAVE_SSE2
#undef HAVE_ALTIVEC
deps/jemalloc/test/include/test/math.h
0 → 100644
View file @
fceef8e0
#ifndef JEMALLOC_ENABLE_INLINE
double
ln_gamma
(
double
x
);
double
i_gamma
(
double
x
,
double
p
,
double
ln_gamma_p
);
double
pt_norm
(
double
p
);
double
pt_chi2
(
double
p
,
double
df
,
double
ln_gamma_df_2
);
double
pt_gamma
(
double
p
,
double
shape
,
double
scale
,
double
ln_gamma_shape
);
#endif
#if (defined(JEMALLOC_ENABLE_INLINE) || defined(MATH_C_))
/*
* Compute the natural log of Gamma(x), accurate to 10 decimal places.
*
* This implementation is based on:
*
* Pike, M.C., I.D. Hill (1966) Algorithm 291: Logarithm of Gamma function
* [S14]. Communications of the ACM 9(9):684.
*/
JEMALLOC_INLINE
double
ln_gamma
(
double
x
)
{
double
f
,
z
;
assert
(
x
>
0
.
0
);
if
(
x
<
7
.
0
)
{
f
=
1
.
0
;
z
=
x
;
while
(
z
<
7
.
0
)
{
f
*=
z
;
z
+=
1
.
0
;
}
x
=
z
;
f
=
-
log
(
f
);
}
else
f
=
0
.
0
;
z
=
1
.
0
/
(
x
*
x
);
return
(
f
+
(
x
-
0
.
5
)
*
log
(
x
)
-
x
+
0
.
918938533204673
+
(((
-
0
.
0005
95238095238
*
z
+
0
.
0007
93650793651
)
*
z
-
0
.
00277777777777
8
)
*
z
+
0
.
083333333333333
)
/
x
);
}
/*
* Compute the incomplete Gamma ratio for [0..x], where p is the shape
* parameter, and ln_gamma_p is ln_gamma(p).
*
* This implementation is based on:
*
* Bhattacharjee, G.P. (1970) Algorithm AS 32: The incomplete Gamma integral.
* Applied Statistics 19:285-287.
*/
JEMALLOC_INLINE
double
i_gamma
(
double
x
,
double
p
,
double
ln_gamma_p
)
{
double
acu
,
factor
,
oflo
,
gin
,
term
,
rn
,
a
,
b
,
an
,
dif
;
double
pn
[
6
];
unsigned
i
;
assert
(
p
>
0
.
0
);
assert
(
x
>=
0
.
0
);
if
(
x
==
0
.
0
)
return
(
0
.
0
);
acu
=
1.0e-10
;
oflo
=
1.0e30
;
gin
=
0
.
0
;
factor
=
exp
(
p
*
log
(
x
)
-
x
-
ln_gamma_p
);
if
(
x
<=
1
.
0
||
x
<
p
)
{
/* Calculation by series expansion. */
gin
=
1
.
0
;
term
=
1
.
0
;
rn
=
p
;
while
(
true
)
{
rn
+=
1
.
0
;
term
*=
x
/
rn
;
gin
+=
term
;
if
(
term
<=
acu
)
{
gin
*=
factor
/
p
;
return
(
gin
);
}
}
}
else
{
/* Calculation by continued fraction. */
a
=
1
.
0
-
p
;
b
=
a
+
x
+
1
.
0
;
term
=
0
.
0
;
pn
[
0
]
=
1
.
0
;
pn
[
1
]
=
x
;
pn
[
2
]
=
x
+
1
.
0
;
pn
[
3
]
=
x
*
b
;
gin
=
pn
[
2
]
/
pn
[
3
];
while
(
true
)
{
a
+=
1
.
0
;
b
+=
2
.
0
;
term
+=
1
.
0
;
an
=
a
*
term
;
for
(
i
=
0
;
i
<
2
;
i
++
)
pn
[
i
+
4
]
=
b
*
pn
[
i
+
2
]
-
an
*
pn
[
i
];
if
(
pn
[
5
]
!=
0
.
0
)
{
rn
=
pn
[
4
]
/
pn
[
5
];
dif
=
fabs
(
gin
-
rn
);
if
(
dif
<=
acu
&&
dif
<=
acu
*
rn
)
{
gin
=
1
.
0
-
factor
*
gin
;
return
(
gin
);
}
gin
=
rn
;
}
for
(
i
=
0
;
i
<
4
;
i
++
)
pn
[
i
]
=
pn
[
i
+
2
];
if
(
fabs
(
pn
[
4
])
>=
oflo
)
{
for
(
i
=
0
;
i
<
4
;
i
++
)
pn
[
i
]
/=
oflo
;
}
}
}
}
/*
* Given a value p in [0..1] of the lower tail area of the normal distribution,
* compute the limit on the definite integral from [-inf..z] that satisfies p,
* accurate to 16 decimal places.
*
* This implementation is based on:
*
* Wichura, M.J. (1988) Algorithm AS 241: The percentage points of the normal
* distribution. Applied Statistics 37(3):477-484.
*/
JEMALLOC_INLINE
double
pt_norm
(
double
p
)
{
double
q
,
r
,
ret
;
assert
(
p
>
0
.
0
&&
p
<
1
.
0
);
q
=
p
-
0
.
5
;
if
(
fabs
(
q
)
<=
0
.
425
)
{
/* p close to 1/2. */
r
=
0
.
180625
-
q
*
q
;
return
(
q
*
(((((((
2.5090809287301226727e3
*
r
+
3.3430575583588128105e4
)
*
r
+
6.7265770927008700853e4
)
*
r
+
4.5921953931549871457e4
)
*
r
+
1.3731693765509461125e4
)
*
r
+
1.9715909503065514427e3
)
*
r
+
1.3314166789178437745e2
)
*
r
+
3.3871328727963666080e0
)
/
(((((((
5.2264952788528545610e3
*
r
+
2.8729085735721942674e4
)
*
r
+
3.9307895800092710610e4
)
*
r
+
2.1213794301586595867e4
)
*
r
+
5.3941960214247511077e3
)
*
r
+
6.8718700749205790830e2
)
*
r
+
4.2313330701600911252e1
)
*
r
+
1
.
0
));
}
else
{
if
(
q
<
0
.
0
)
r
=
p
;
else
r
=
1
.
0
-
p
;
assert
(
r
>
0
.
0
);
r
=
sqrt
(
-
log
(
r
));
if
(
r
<=
5
.
0
)
{
/* p neither close to 1/2 nor 0 or 1. */
r
-=
1
.
6
;
ret
=
((((((((
7.74545014278341407640e-4
*
r
+
2.27238449892691845833e-2
)
*
r
+
2.41780725177450611770e-1
)
*
r
+
1.27045825245236838258e0
)
*
r
+
3.64784832476320460504e0
)
*
r
+
5.76949722146069140550e0
)
*
r
+
4.63033784615654529590e0
)
*
r
+
1.42343711074968357734e0
)
/
(((((((
1.05075007164441684324e-9
*
r
+
5.47593808499534494600e-4
)
*
r
+
1.51986665636164571966e-2
)
*
r
+
1.48103976427480074590e-1
)
*
r
+
6.89767334985100004550e-1
)
*
r
+
1.67638483018380384940e0
)
*
r
+
2.05319162663775882187e0
)
*
r
+
1
.
0
));
}
else
{
/* p near 0 or 1. */
r
-=
5
.
0
;
ret
=
((((((((
2.01033439929228813265e-7
*
r
+
2.71155556874348757815e-5
)
*
r
+
1.24266094738807843860e-3
)
*
r
+
2.65321895265761230930e-2
)
*
r
+
2.96560571828504891230e-1
)
*
r
+
1.78482653991729133580e0
)
*
r
+
5.46378491116411436990e0
)
*
r
+
6.65790464350110377720e0
)
/
(((((((
2.04426310338993978564e-15
*
r
+
1.42151175831644588870e-7
)
*
r
+
1.84631831751005468180e-5
)
*
r
+
7.86869131145613259100e-4
)
*
r
+
1.48753612908506148525e-2
)
*
r
+
1.36929880922735805310e-1
)
*
r
+
5.99832206555887937690e-1
)
*
r
+
1
.
0
));
}
if
(
q
<
0
.
0
)
ret
=
-
ret
;
return
(
ret
);
}
}
/*
* Given a value p in [0..1] of the lower tail area of the Chi^2 distribution
* with df degrees of freedom, where ln_gamma_df_2 is ln_gamma(df/2.0), compute
* the upper limit on the definite integral from [0..z] that satisfies p,
* accurate to 12 decimal places.
*
* This implementation is based on:
*
* Best, D.J., D.E. Roberts (1975) Algorithm AS 91: The percentage points of
* the Chi^2 distribution. Applied Statistics 24(3):385-388.
*
* Shea, B.L. (1991) Algorithm AS R85: A remark on AS 91: The percentage
* points of the Chi^2 distribution. Applied Statistics 40(1):233-235.
*/
JEMALLOC_INLINE
double
pt_chi2
(
double
p
,
double
df
,
double
ln_gamma_df_2
)
{
double
e
,
aa
,
xx
,
c
,
ch
,
a
,
q
,
p1
,
p2
,
t
,
x
,
b
,
s1
,
s2
,
s3
,
s4
,
s5
,
s6
;
unsigned
i
;
assert
(
p
>=
0
.
0
&&
p
<
1
.
0
);
assert
(
df
>
0
.
0
);
e
=
5.0e-7
;
aa
=
0
.
6931471805
;
xx
=
0
.
5
*
df
;
c
=
xx
-
1
.
0
;
if
(
df
<
-
1
.
24
*
log
(
p
))
{
/* Starting approximation for small Chi^2. */
ch
=
pow
(
p
*
xx
*
exp
(
ln_gamma_df_2
+
xx
*
aa
),
1
.
0
/
xx
);
if
(
ch
-
e
<
0
.
0
)
return
(
ch
);
}
else
{
if
(
df
>
0
.
32
)
{
x
=
pt_norm
(
p
);
/*
* Starting approximation using Wilson and Hilferty
* estimate.
*/
p1
=
0
.
222222
/
df
;
ch
=
df
*
pow
(
x
*
sqrt
(
p1
)
+
1
.
0
-
p1
,
3
.
0
);
/* Starting approximation for p tending to 1. */
if
(
ch
>
2
.
2
*
df
+
6
.
0
)
{
ch
=
-
2
.
0
*
(
log
(
1
.
0
-
p
)
-
c
*
log
(
0
.
5
*
ch
)
+
ln_gamma_df_2
);
}
}
else
{
ch
=
0
.
4
;
a
=
log
(
1
.
0
-
p
);
while
(
true
)
{
q
=
ch
;
p1
=
1
.
0
+
ch
*
(
4
.
67
+
ch
);
p2
=
ch
*
(
6
.
73
+
ch
*
(
6
.
66
+
ch
));
t
=
-
0
.
5
+
(
4
.
67
+
2
.
0
*
ch
)
/
p1
-
(
6
.
73
+
ch
*
(
13
.
32
+
3
.
0
*
ch
))
/
p2
;
ch
-=
(
1
.
0
-
exp
(
a
+
ln_gamma_df_2
+
0
.
5
*
ch
+
c
*
aa
)
*
p2
/
p1
)
/
t
;
if
(
fabs
(
q
/
ch
-
1
.
0
)
-
0
.
01
<=
0
.
0
)
break
;
}
}
}
for
(
i
=
0
;
i
<
20
;
i
++
)
{
/* Calculation of seven-term Taylor series. */
q
=
ch
;
p1
=
0
.
5
*
ch
;
if
(
p1
<
0
.
0
)
return
(
-
1
.
0
);
p2
=
p
-
i_gamma
(
p1
,
xx
,
ln_gamma_df_2
);
t
=
p2
*
exp
(
xx
*
aa
+
ln_gamma_df_2
+
p1
-
c
*
log
(
ch
));
b
=
t
/
ch
;
a
=
0
.
5
*
t
-
b
*
c
;
s1
=
(
210
.
0
+
a
*
(
140
.
0
+
a
*
(
105
.
0
+
a
*
(
84
.
0
+
a
*
(
70
.
0
+
60
.
0
*
a
)))))
/
420
.
0
;
s2
=
(
420
.
0
+
a
*
(
735
.
0
+
a
*
(
966
.
0
+
a
*
(
1141
.
0
+
1278
.
0
*
a
))))
/
2520
.
0
;
s3
=
(
210
.
0
+
a
*
(
462
.
0
+
a
*
(
707
.
0
+
932
.
0
*
a
)))
/
2520
.
0
;
s4
=
(
252
.
0
+
a
*
(
672
.
0
+
1182
.
0
*
a
)
+
c
*
(
294
.
0
+
a
*
(
889
.
0
+
1740
.
0
*
a
)))
/
5040
.
0
;
s5
=
(
84
.
0
+
264
.
0
*
a
+
c
*
(
175
.
0
+
606
.
0
*
a
))
/
2520
.
0
;
s6
=
(
120
.
0
+
c
*
(
346
.
0
+
127
.
0
*
c
))
/
5040
.
0
;
ch
+=
t
*
(
1
.
0
+
0
.
5
*
t
*
s1
-
b
*
c
*
(
s1
-
b
*
(
s2
-
b
*
(
s3
-
b
*
(
s4
-
b
*
(
s5
-
b
*
s6
))))));
if
(
fabs
(
q
/
ch
-
1
.
0
)
<=
e
)
break
;
}
return
(
ch
);
}
/*
* Given a value p in [0..1] and Gamma distribution shape and scale parameters,
* compute the upper limit on the definite integeral from [0..z] that satisfies
* p.
*/
JEMALLOC_INLINE
double
pt_gamma
(
double
p
,
double
shape
,
double
scale
,
double
ln_gamma_shape
)
{
return
(
pt_chi2
(
p
,
shape
*
2
.
0
,
ln_gamma_shape
)
*
0
.
5
*
scale
);
}
#endif
deps/jemalloc/test/include/test/mq.h
0 → 100644
View file @
fceef8e0
/*
* Simple templated message queue implementation that relies on only mutexes for
* synchronization (which reduces portability issues). Given the following
* setup:
*
* typedef struct mq_msg_s mq_msg_t;
* struct mq_msg_s {
* mq_msg(mq_msg_t) link;
* [message data]
* };
* mq_gen(, mq_, mq_t, mq_msg_t, link)
*
* The API is as follows:
*
* bool mq_init(mq_t *mq);
* void mq_fini(mq_t *mq);
* unsigned mq_count(mq_t *mq);
* mq_msg_t *mq_tryget(mq_t *mq);
* mq_msg_t *mq_get(mq_t *mq);
* void mq_put(mq_t *mq, mq_msg_t *msg);
*
* The message queue linkage embedded in each message is to be treated as
* externally opaque (no need to initialize or clean up externally). mq_fini()
* does not perform any cleanup of messages, since it knows nothing of their
* payloads.
*/
#define mq_msg(a_mq_msg_type) ql_elm(a_mq_msg_type)
#define mq_gen(a_attr, a_prefix, a_mq_type, a_mq_msg_type, a_field) \
typedef struct { \
mtx_t lock; \
ql_head(a_mq_msg_type) msgs; \
unsigned count; \
} a_mq_type; \
a_attr bool \
a_prefix##init(a_mq_type *mq) { \
\
if (mtx_init(&mq->lock)) \
return (true); \
ql_new(&mq->msgs); \
mq->count = 0; \
return (false); \
} \
a_attr void \
a_prefix##fini(a_mq_type *mq) \
{ \
\
mtx_fini(&mq->lock); \
} \
a_attr unsigned \
a_prefix##count(a_mq_type *mq) \
{ \
unsigned count; \
\
mtx_lock(&mq->lock); \
count = mq->count; \
mtx_unlock(&mq->lock); \
return (count); \
} \
a_attr a_mq_msg_type * \
a_prefix##tryget(a_mq_type *mq) \
{ \
a_mq_msg_type *msg; \
\
mtx_lock(&mq->lock); \
msg = ql_first(&mq->msgs); \
if (msg != NULL) { \
ql_head_remove(&mq->msgs, a_mq_msg_type, a_field); \
mq->count--; \
} \
mtx_unlock(&mq->lock); \
return (msg); \
} \
a_attr a_mq_msg_type * \
a_prefix##get(a_mq_type *mq) \
{ \
a_mq_msg_type *msg; \
struct timespec timeout; \
\
msg = a_prefix##tryget(mq); \
if (msg != NULL) \
return (msg); \
\
timeout.tv_sec = 0; \
timeout.tv_nsec = 1; \
while (true) { \
nanosleep(&timeout, NULL); \
msg = a_prefix##tryget(mq); \
if (msg != NULL) \
return (msg); \
if (timeout.tv_sec == 0) { \
/* Double sleep time, up to max 1 second. */
\
timeout.tv_nsec <<= 1; \
if (timeout.tv_nsec >= 1000*1000*1000) { \
timeout.tv_sec = 1; \
timeout.tv_nsec = 0; \
} \
} \
} \
} \
a_attr void \
a_prefix##put(a_mq_type *mq, a_mq_msg_type *msg) \
{ \
\
mtx_lock(&mq->lock); \
ql_elm_new(msg, a_field); \
ql_tail_insert(&mq->msgs, msg, a_field); \
mq->count++; \
mtx_unlock(&mq->lock); \
}
deps/jemalloc/test/include/test/mtx.h
0 → 100644
View file @
fceef8e0
/*
* mtx is a slightly simplified version of malloc_mutex. This code duplication
* is unfortunate, but there are allocator bootstrapping considerations that
* would leak into the test infrastructure if malloc_mutex were used directly
* in tests.
*/
typedef
struct
{
#ifdef _WIN32
CRITICAL_SECTION
lock
;
#elif (defined(JEMALLOC_OSSPIN))
OSSpinLock
lock
;
#else
pthread_mutex_t
lock
;
#endif
}
mtx_t
;
bool
mtx_init
(
mtx_t
*
mtx
);
void
mtx_fini
(
mtx_t
*
mtx
);
void
mtx_lock
(
mtx_t
*
mtx
);
void
mtx_unlock
(
mtx_t
*
mtx
);
deps/jemalloc/test/include/test/test.h
0 → 100644
View file @
fceef8e0
#define ASSERT_BUFSIZE 256
#define assert_cmp(t, a, b, cmp, neg_cmp, pri, fmt...) do { \
t a_ = (a); \
t b_ = (b); \
if (!(a_ cmp b_)) { \
char prefix[ASSERT_BUFSIZE]; \
char message[ASSERT_BUFSIZE]; \
malloc_snprintf(prefix, sizeof(prefix), \
"%s:%s:%d: Failed assertion: " \
"(%s) "#cmp" (%s) --> " \
"%"pri" "#neg_cmp" %"pri": ", \
__func__, __FILE__, __LINE__, \
#a, #b, a_, b_); \
malloc_snprintf(message, sizeof(message), fmt); \
p_test_fail(prefix, message); \
} \
} while (0)
#define assert_ptr_eq(a, b, fmt...) assert_cmp(void *, a, b, ==, \
!=, "p", fmt)
#define assert_ptr_ne(a, b, fmt...) assert_cmp(void *, a, b, !=, \
==, "p", fmt)
#define assert_ptr_null(a, fmt...) assert_cmp(void *, a, NULL, ==, \
!=, "p", fmt)
#define assert_ptr_not_null(a, fmt...) assert_cmp(void *, a, NULL, !=, \
==, "p", fmt)
#define assert_c_eq(a, b, fmt...) assert_cmp(char, a, b, ==, !=, "c", fmt)
#define assert_c_ne(a, b, fmt...) assert_cmp(char, a, b, !=, ==, "c", fmt)
#define assert_c_lt(a, b, fmt...) assert_cmp(char, a, b, <, >=, "c", fmt)
#define assert_c_le(a, b, fmt...) assert_cmp(char, a, b, <=, >, "c", fmt)
#define assert_c_ge(a, b, fmt...) assert_cmp(char, a, b, >=, <, "c", fmt)
#define assert_c_gt(a, b, fmt...) assert_cmp(char, a, b, >, <=, "c", fmt)
#define assert_x_eq(a, b, fmt...) assert_cmp(int, a, b, ==, !=, "#x", fmt)
#define assert_x_ne(a, b, fmt...) assert_cmp(int, a, b, !=, ==, "#x", fmt)
#define assert_x_lt(a, b, fmt...) assert_cmp(int, a, b, <, >=, "#x", fmt)
#define assert_x_le(a, b, fmt...) assert_cmp(int, a, b, <=, >, "#x", fmt)
#define assert_x_ge(a, b, fmt...) assert_cmp(int, a, b, >=, <, "#x", fmt)
#define assert_x_gt(a, b, fmt...) assert_cmp(int, a, b, >, <=, "#x", fmt)
#define assert_d_eq(a, b, fmt...) assert_cmp(int, a, b, ==, !=, "d", fmt)
#define assert_d_ne(a, b, fmt...) assert_cmp(int, a, b, !=, ==, "d", fmt)
#define assert_d_lt(a, b, fmt...) assert_cmp(int, a, b, <, >=, "d", fmt)
#define assert_d_le(a, b, fmt...) assert_cmp(int, a, b, <=, >, "d", fmt)
#define assert_d_ge(a, b, fmt...) assert_cmp(int, a, b, >=, <, "d", fmt)
#define assert_d_gt(a, b, fmt...) assert_cmp(int, a, b, >, <=, "d", fmt)
#define assert_u_eq(a, b, fmt...) assert_cmp(int, a, b, ==, !=, "u", fmt)
#define assert_u_ne(a, b, fmt...) assert_cmp(int, a, b, !=, ==, "u", fmt)
#define assert_u_lt(a, b, fmt...) assert_cmp(int, a, b, <, >=, "u", fmt)
#define assert_u_le(a, b, fmt...) assert_cmp(int, a, b, <=, >, "u", fmt)
#define assert_u_ge(a, b, fmt...) assert_cmp(int, a, b, >=, <, "u", fmt)
#define assert_u_gt(a, b, fmt...) assert_cmp(int, a, b, >, <=, "u", fmt)
#define assert_ld_eq(a, b, fmt...) assert_cmp(long, a, b, ==, \
!=, "ld", fmt)
#define assert_ld_ne(a, b, fmt...) assert_cmp(long, a, b, !=, \
==, "ld", fmt)
#define assert_ld_lt(a, b, fmt...) assert_cmp(long, a, b, <, \
>=, "ld", fmt)
#define assert_ld_le(a, b, fmt...) assert_cmp(long, a, b, <=, \
>, "ld", fmt)
#define assert_ld_ge(a, b, fmt...) assert_cmp(long, a, b, >=, \
<, "ld", fmt)
#define assert_ld_gt(a, b, fmt...) assert_cmp(long, a, b, >, \
<=, "ld", fmt)
#define assert_lu_eq(a, b, fmt...) assert_cmp(unsigned long, \
a, b, ==, !=, "lu", fmt)
#define assert_lu_ne(a, b, fmt...) assert_cmp(unsigned long, \
a, b, !=, ==, "lu", fmt)
#define assert_lu_lt(a, b, fmt...) assert_cmp(unsigned long, \
a, b, <, >=, "lu", fmt)
#define assert_lu_le(a, b, fmt...) assert_cmp(unsigned long, \
a, b, <=, >, "lu", fmt)
#define assert_lu_ge(a, b, fmt...) assert_cmp(unsigned long, \
a, b, >=, <, "lu", fmt)
#define assert_lu_gt(a, b, fmt...) assert_cmp(unsigned long, \
a, b, >, <=, "lu", fmt)
#define assert_qd_eq(a, b, fmt...) assert_cmp(long long, a, b, ==, \
!=, "qd", fmt)
#define assert_qd_ne(a, b, fmt...) assert_cmp(long long, a, b, !=, \
==, "qd", fmt)
#define assert_qd_lt(a, b, fmt...) assert_cmp(long long, a, b, <, \
>=, "qd", fmt)
#define assert_qd_le(a, b, fmt...) assert_cmp(long long, a, b, <=, \
>, "qd", fmt)
#define assert_qd_ge(a, b, fmt...) assert_cmp(long long, a, b, >=, \
<, "qd", fmt)
#define assert_qd_gt(a, b, fmt...) assert_cmp(long long, a, b, >, \
<=, "qd", fmt)
#define assert_qu_eq(a, b, fmt...) assert_cmp(unsigned long long, \
a, b, ==, !=, "qu", fmt)
#define assert_qu_ne(a, b, fmt...) assert_cmp(unsigned long long, \
a, b, !=, ==, "qu", fmt)
#define assert_qu_lt(a, b, fmt...) assert_cmp(unsigned long long, \
a, b, <, >=, "qu", fmt)
#define assert_qu_le(a, b, fmt...) assert_cmp(unsigned long long, \
a, b, <=, >, "qu", fmt)
#define assert_qu_ge(a, b, fmt...) assert_cmp(unsigned long long, \
a, b, >=, <, "qu", fmt)
#define assert_qu_gt(a, b, fmt...) assert_cmp(unsigned long long, \
a, b, >, <=, "qu", fmt)
#define assert_jd_eq(a, b, fmt...) assert_cmp(intmax_t, a, b, ==, \
!=, "jd", fmt)
#define assert_jd_ne(a, b, fmt...) assert_cmp(intmax_t, a, b, !=, \
==, "jd", fmt)
#define assert_jd_lt(a, b, fmt...) assert_cmp(intmax_t, a, b, <, \
>=, "jd", fmt)
#define assert_jd_le(a, b, fmt...) assert_cmp(intmax_t, a, b, <=, \
>, "jd", fmt)
#define assert_jd_ge(a, b, fmt...) assert_cmp(intmax_t, a, b, >=, \
<, "jd", fmt)
#define assert_jd_gt(a, b, fmt...) assert_cmp(intmax_t, a, b, >, \
<=, "jd", fmt)
#define assert_ju_eq(a, b, fmt...) assert_cmp(uintmax_t, a, b, ==, \
!=, "ju", fmt)
#define assert_ju_ne(a, b, fmt...) assert_cmp(uintmax_t, a, b, !=, \
==, "ju", fmt)
#define assert_ju_lt(a, b, fmt...) assert_cmp(uintmax_t, a, b, <, \
>=, "ju", fmt)
#define assert_ju_le(a, b, fmt...) assert_cmp(uintmax_t, a, b, <=, \
>, "ju", fmt)
#define assert_ju_ge(a, b, fmt...) assert_cmp(uintmax_t, a, b, >=, \
<, "ju", fmt)
#define assert_ju_gt(a, b, fmt...) assert_cmp(uintmax_t, a, b, >, \
<=, "ju", fmt)
#define assert_zd_eq(a, b, fmt...) assert_cmp(ssize_t, a, b, ==, \
!=, "zd", fmt)
#define assert_zd_ne(a, b, fmt...) assert_cmp(ssize_t, a, b, !=, \
==, "zd", fmt)
#define assert_zd_lt(a, b, fmt...) assert_cmp(ssize_t, a, b, <, \
>=, "zd", fmt)
#define assert_zd_le(a, b, fmt...) assert_cmp(ssize_t, a, b, <=, \
>, "zd", fmt)
#define assert_zd_ge(a, b, fmt...) assert_cmp(ssize_t, a, b, >=, \
<, "zd", fmt)
#define assert_zd_gt(a, b, fmt...) assert_cmp(ssize_t, a, b, >, \
<=, "zd", fmt)
#define assert_zu_eq(a, b, fmt...) assert_cmp(size_t, a, b, ==, \
!=, "zu", fmt)
#define assert_zu_ne(a, b, fmt...) assert_cmp(size_t, a, b, !=, \
==, "zu", fmt)
#define assert_zu_lt(a, b, fmt...) assert_cmp(size_t, a, b, <, \
>=, "zu", fmt)
#define assert_zu_le(a, b, fmt...) assert_cmp(size_t, a, b, <=, \
>, "zu", fmt)
#define assert_zu_ge(a, b, fmt...) assert_cmp(size_t, a, b, >=, \
<, "zu", fmt)
#define assert_zu_gt(a, b, fmt...) assert_cmp(size_t, a, b, >, \
<=, "zu", fmt)
#define assert_d32_eq(a, b, fmt...) assert_cmp(int32_t, a, b, ==, \
!=, PRId32, fmt)
#define assert_d32_ne(a, b, fmt...) assert_cmp(int32_t, a, b, !=, \
==, PRId32, fmt)
#define assert_d32_lt(a, b, fmt...) assert_cmp(int32_t, a, b, <, \
>=, PRId32, fmt)
#define assert_d32_le(a, b, fmt...) assert_cmp(int32_t, a, b, <=, \
>, PRId32, fmt)
#define assert_d32_ge(a, b, fmt...) assert_cmp(int32_t, a, b, >=, \
<, PRId32, fmt)
#define assert_d32_gt(a, b, fmt...) assert_cmp(int32_t, a, b, >, \
<=, PRId32, fmt)
#define assert_u32_eq(a, b, fmt...) assert_cmp(uint32_t, a, b, ==, \
!=, PRIu32, fmt)
#define assert_u32_ne(a, b, fmt...) assert_cmp(uint32_t, a, b, !=, \
==, PRIu32, fmt)
#define assert_u32_lt(a, b, fmt...) assert_cmp(uint32_t, a, b, <, \
>=, PRIu32, fmt)
#define assert_u32_le(a, b, fmt...) assert_cmp(uint32_t, a, b, <=, \
>, PRIu32, fmt)
#define assert_u32_ge(a, b, fmt...) assert_cmp(uint32_t, a, b, >=, \
<, PRIu32, fmt)
#define assert_u32_gt(a, b, fmt...) assert_cmp(uint32_t, a, b, >, \
<=, PRIu32, fmt)
#define assert_d64_eq(a, b, fmt...) assert_cmp(int64_t, a, b, ==, \
!=, PRId64, fmt)
#define assert_d64_ne(a, b, fmt...) assert_cmp(int64_t, a, b, !=, \
==, PRId64, fmt)
#define assert_d64_lt(a, b, fmt...) assert_cmp(int64_t, a, b, <, \
>=, PRId64, fmt)
#define assert_d64_le(a, b, fmt...) assert_cmp(int64_t, a, b, <=, \
>, PRId64, fmt)
#define assert_d64_ge(a, b, fmt...) assert_cmp(int64_t, a, b, >=, \
<, PRId64, fmt)
#define assert_d64_gt(a, b, fmt...) assert_cmp(int64_t, a, b, >, \
<=, PRId64, fmt)
#define assert_u64_eq(a, b, fmt...) assert_cmp(uint64_t, a, b, ==, \
!=, PRIu64, fmt)
#define assert_u64_ne(a, b, fmt...) assert_cmp(uint64_t, a, b, !=, \
==, PRIu64, fmt)
#define assert_u64_lt(a, b, fmt...) assert_cmp(uint64_t, a, b, <, \
>=, PRIu64, fmt)
#define assert_u64_le(a, b, fmt...) assert_cmp(uint64_t, a, b, <=, \
>, PRIu64, fmt)
#define assert_u64_ge(a, b, fmt...) assert_cmp(uint64_t, a, b, >=, \
<, PRIu64, fmt)
#define assert_u64_gt(a, b, fmt...) assert_cmp(uint64_t, a, b, >, \
<=, PRIu64, fmt)
#define assert_b_eq(a, b, fmt...) do { \
bool a_ = (a); \
bool b_ = (b); \
if (!(a_ == b_)) { \
char prefix[ASSERT_BUFSIZE]; \
char message[ASSERT_BUFSIZE]; \
malloc_snprintf(prefix, sizeof(prefix), \
"%s:%s:%d: Failed assertion: " \
"(%s) == (%s) --> %s != %s: ", \
__func__, __FILE__, __LINE__, \
#a, #b, a_ ? "true" : "false", \
b_ ? "true" : "false"); \
malloc_snprintf(message, sizeof(message), fmt); \
p_test_fail(prefix, message); \
} \
} while (0)
#define assert_b_ne(a, b, fmt...) do { \
bool a_ = (a); \
bool b_ = (b); \
if (!(a_ != b_)) { \
char prefix[ASSERT_BUFSIZE]; \
char message[ASSERT_BUFSIZE]; \
malloc_snprintf(prefix, sizeof(prefix), \
"%s:%s:%d: Failed assertion: " \
"(%s) != (%s) --> %s == %s: ", \
__func__, __FILE__, __LINE__, \
#a, #b, a_ ? "true" : "false", \
b_ ? "true" : "false"); \
malloc_snprintf(message, sizeof(message), fmt); \
p_test_fail(prefix, message); \
} \
} while (0)
#define assert_true(a, fmt...) assert_b_eq(a, true, fmt)
#define assert_false(a, fmt...) assert_b_eq(a, false, fmt)
#define assert_str_eq(a, b, fmt...) do { \
if (strcmp((a), (b))) { \
char prefix[ASSERT_BUFSIZE]; \
char message[ASSERT_BUFSIZE]; \
malloc_snprintf(prefix, sizeof(prefix), \
"%s:%s:%d: Failed assertion: " \
"(%s) same as (%s) --> " \
"\"%s\" differs from \"%s\": ", \
__func__, __FILE__, __LINE__, #a, #b, a, b); \
malloc_snprintf(message, sizeof(message), fmt); \
p_test_fail(prefix, message); \
} \
} while (0)
#define assert_str_ne(a, b, fmt...) do { \
if (!strcmp((a), (b))) { \
char prefix[ASSERT_BUFSIZE]; \
char message[ASSERT_BUFSIZE]; \
malloc_snprintf(prefix, sizeof(prefix), \
"%s:%s:%d: Failed assertion: " \
"(%s) differs from (%s) --> " \
"\"%s\" same as \"%s\": ", \
__func__, __FILE__, __LINE__, #a, #b, a, b); \
malloc_snprintf(message, sizeof(message), fmt); \
p_test_fail(prefix, message); \
} \
} while (0)
#define assert_not_reached(fmt...) do { \
char prefix[ASSERT_BUFSIZE]; \
char message[ASSERT_BUFSIZE]; \
malloc_snprintf(prefix, sizeof(prefix), \
"%s:%s:%d: Unreachable code reached: ", \
__func__, __FILE__, __LINE__); \
malloc_snprintf(message, sizeof(message), fmt); \
p_test_fail(prefix, message); \
} while (0)
/*
* If this enum changes, corresponding changes in test/test.sh.in are also
* necessary.
*/
typedef
enum
{
test_status_pass
=
0
,
test_status_skip
=
1
,
test_status_fail
=
2
,
test_status_count
=
3
}
test_status_t
;
typedef
void
(
test_t
)(
void
);
#define TEST_BEGIN(f) \
static void \
f(void) \
{ \
p_test_init(#f);
#define TEST_END \
goto label_test_end; \
label_test_end: \
p_test_fini(); \
}
#define test(tests...) \
p_test(tests, NULL)
#define test_skip_if(e) do { \
if (e) { \
test_skip("%s:%s:%d: Test skipped: (%s)", \
__func__, __FILE__, __LINE__, #e); \
goto label_test_end; \
} \
} while (0)
void
test_skip
(
const
char
*
format
,
...)
JEMALLOC_ATTR
(
format
(
printf
,
1
,
2
));
void
test_fail
(
const
char
*
format
,
...)
JEMALLOC_ATTR
(
format
(
printf
,
1
,
2
));
/* For private use by macros. */
test_status_t
p_test
(
test_t
*
t
,
...);
void
p_test_init
(
const
char
*
name
);
void
p_test_fini
(
void
);
void
p_test_fail
(
const
char
*
prefix
,
const
char
*
message
);
deps/jemalloc/test/include/test/thd.h
0 → 100644
View file @
fceef8e0
/* Abstraction layer for threading in tests */
#ifdef _WIN32
typedef
HANDLE
thd_t
;
#else
typedef
pthread_t
thd_t
;
#endif
void
thd_create
(
thd_t
*
thd
,
void
*
(
*
proc
)(
void
*
),
void
*
arg
);
void
thd_join
(
thd_t
thd
,
void
**
ret
);
deps/jemalloc/test/ALLOC
M
_ARENA.c
→
deps/jemalloc/test/
integration/M
ALLOC
X
_ARENA.c
View file @
fceef8e0
#define JEMALLOC_MANGLE
#include "jemalloc_test.h"
#include "test/jemalloc_test.h"
#define NTHREADS 10
void
*
je_threa
d_start
(
void
*
arg
)
th
d_start
(
void
*
arg
)
{
unsigned
thread_ind
=
(
unsigned
)(
uintptr_t
)
arg
;
unsigned
arena_ind
;
int
r
;
void
*
p
;
size_t
rsz
,
sz
;
size_t
sz
;
sz
=
sizeof
(
arena_ind
);
if
(
mallctl
(
"arenas.extend"
,
&
arena_ind
,
&
sz
,
NULL
,
0
)
!=
0
)
{
malloc_printf
(
"Error in arenas.extend
\n
"
);
abort
();
}
assert_d_eq
(
mallctl
(
"arenas.extend"
,
&
arena_ind
,
&
sz
,
NULL
,
0
),
0
,
"Error in arenas.extend"
);
if
(
thread_ind
%
4
!=
3
)
{
size_t
mib
[
3
];
size_t
miblen
=
sizeof
(
mib
)
/
sizeof
(
size_t
);
const
char
*
dss_precs
[]
=
{
"disabled"
,
"primary"
,
"secondary"
};
const
char
*
dss
=
dss_precs
[
thread_ind
%
4
];
if
(
mallctlnametomib
(
"arena.0.dss"
,
mib
,
&
miblen
)
!=
0
)
{
malloc_printf
(
"Error in mallctlnametomib()
\n
"
);
abort
();
}
const
char
*
dss
=
dss_precs
[
thread_ind
%
(
sizeof
(
dss_precs
)
/
sizeof
(
char
*
))];
assert_d_eq
(
mallctlnametomib
(
"arena.0.dss"
,
mib
,
&
miblen
),
0
,
"Error in mallctlnametomib()"
);
mib
[
1
]
=
arena_ind
;
if
(
mallctlbymib
(
mib
,
miblen
,
NULL
,
NULL
,
(
void
*
)
&
dss
,
sizeof
(
const
char
*
)))
{
malloc_printf
(
"Error in mallctlbymib()
\n
"
);
abort
();
}
assert_d_eq
(
mallctlbymib
(
mib
,
miblen
,
NULL
,
NULL
,
(
void
*
)
&
dss
,
sizeof
(
const
char
*
)),
0
,
"Error in mallctlbymib()"
);
}
r
=
allocm
(
&
p
,
&
rsz
,
1
,
ALLOCM_ARENA
(
arena_ind
));
if
(
r
!=
ALLOCM_SUCCESS
)
{
malloc_printf
(
"Unexpected allocm() error
\n
"
);
abort
();
}
p
=
mallocx
(
1
,
MALLOCX_ARENA
(
arena_ind
));
assert_ptr_not_null
(
p
,
"Unexpected mallocx() error"
);
dallocx
(
p
,
0
);
return
(
NULL
);
}
int
main
(
void
)
TEST_BEGIN
(
test_ALLOCM_ARENA
)
{
je_threa
d_t
th
rea
ds
[
NTHREADS
];
th
d_t
thds
[
NTHREADS
];
unsigned
i
;
malloc_printf
(
"Test begin
\n
"
);
for
(
i
=
0
;
i
<
NTHREADS
;
i
++
)
{
je_threa
d_create
(
&
th
rea
ds
[
i
],
je_threa
d_start
,
th
d_create
(
&
thds
[
i
],
th
d_start
,
(
void
*
)(
uintptr_t
)
i
);
}
for
(
i
=
0
;
i
<
NTHREADS
;
i
++
)
je_thread_join
(
threads
[
i
],
NULL
);
thd_join
(
thds
[
i
],
NULL
);
}
TEST_END
int
main
(
void
)
{
malloc_printf
(
"Test end
\n
"
);
return
(
0
);
return
(
test
(
test_ALLOCM_ARENA
)
);
}
deps/jemalloc/test/aligned_alloc.c
→
deps/jemalloc/test/
integration/
aligned_alloc.c
View file @
fceef8e0
#define JEMALLOC_MANGLE
#include "jemalloc_test.h"
#include "test/jemalloc_test.h"
#define
CHUNK 0x400000
#define
CHUNK 0x400000
/* #define MAXALIGN ((size_t)UINT64_C(0x80000000000)) */
#define
MAXALIGN ((size_t)0x2000000LU)
#define
NITER 4
#define
MAXALIGN ((size_t)0x2000000LU)
#define
NITER 4
int
main
(
void
)
TEST_BEGIN
(
test_alignment_errors
)
{
size_t
alignment
,
size
,
total
;
unsigned
i
;
void
*
p
,
*
ps
[
NITER
];
malloc_printf
(
"Test begin
\n
"
);
size_t
alignment
;
void
*
p
;
/* Test error conditions. */
alignment
=
0
;
set_errno
(
0
);
p
=
aligned_alloc
(
alignment
,
1
);
if
(
p
!=
NULL
||
get_errno
()
!=
EINVAL
)
{
malloc_printf
(
"Expected error for invalid alignment %zu
\n
"
,
alignment
);
}
assert_false
(
p
!=
NULL
||
get_errno
()
!=
EINVAL
,
"Expected error for invalid alignment %zu"
,
alignment
);
for
(
alignment
=
sizeof
(
size_t
);
alignment
<
MAXALIGN
;
alignment
<<=
1
)
{
set_errno
(
0
);
p
=
aligned_alloc
(
alignment
+
1
,
1
);
if
(
p
!=
NULL
||
get_errno
()
!=
EINVAL
)
{
malloc_printf
(
"Expected error for invalid alignment %zu
\n
"
,
alignment
+
1
);
}
assert_false
(
p
!=
NULL
||
get_errno
()
!=
EINVAL
,
"Expected error for invalid alignment %zu"
,
alignment
+
1
);
}
}
TEST_END
TEST_BEGIN
(
test_oom_errors
)
{
size_t
alignment
,
size
;
void
*
p
;
#if LG_SIZEOF_PTR == 3
alignment
=
UINT64_C
(
0x8000000000000000
);
...
...
@@ -44,26 +41,22 @@ main(void)
#endif
set_errno
(
0
);
p
=
aligned_alloc
(
alignment
,
size
);
if
(
p
!=
NULL
||
get_errno
()
!=
ENOMEM
)
{
malloc_printf
(
"Expected error for aligned_alloc(%zu, %zu)
\n
"
,
alignment
,
size
);
}
assert_false
(
p
!=
NULL
||
get_errno
()
!=
ENOMEM
,
"Expected error for aligned_alloc(%zu, %zu)"
,
alignment
,
size
);
#if LG_SIZEOF_PTR == 3
alignment
=
UINT64_C
(
0x4000000000000000
);
size
=
UINT64_C
(
0x
84
00000000000001
);
size
=
UINT64_C
(
0x
c0
00000000000001
);
#else
alignment
=
0x40000000LU
;
size
=
0x
84
000001LU
;
size
=
0x
c0
000001LU
;
#endif
set_errno
(
0
);
p
=
aligned_alloc
(
alignment
,
size
);
if
(
p
!=
NULL
||
get_errno
()
!=
ENOMEM
)
{
malloc_printf
(
"Expected error for aligned_alloc(%zu, %zu)
\n
"
,
alignment
,
size
);
}
assert_false
(
p
!=
NULL
||
get_errno
()
!=
ENOMEM
,
"Expected error for aligned_alloc(%zu, %zu)"
,
alignment
,
size
);
alignment
=
0x10LU
;
#if LG_SIZEOF_PTR == 3
...
...
@@ -73,11 +66,17 @@ main(void)
#endif
set_errno
(
0
);
p
=
aligned_alloc
(
alignment
,
size
);
if
(
p
!=
NULL
||
get_errno
()
!=
ENOMEM
)
{
malloc_printf
(
"Expected error for aligned_alloc(&p, %zu, %zu)
\n
"
,
alignment
,
size
);
}
assert_false
(
p
!=
NULL
||
get_errno
()
!=
ENOMEM
,
"Expected error for aligned_alloc(&p, %zu, %zu)"
,
alignment
,
size
);
}
TEST_END
TEST_BEGIN
(
test_alignment_and_size
)
{
size_t
alignment
,
size
,
total
;
unsigned
i
;
void
*
ps
[
NITER
];
for
(
i
=
0
;
i
<
NITER
;
i
++
)
ps
[
i
]
=
NULL
;
...
...
@@ -86,7 +85,6 @@ main(void)
alignment
<=
MAXALIGN
;
alignment
<<=
1
)
{
total
=
0
;
malloc_printf
(
"Alignment: %zu
\n
"
,
alignment
);
for
(
size
=
1
;
size
<
3
*
alignment
&&
size
<
(
1U
<<
31
);
size
+=
(
alignment
>>
(
LG_SIZEOF_PTR
-
1
))
-
1
)
{
...
...
@@ -95,11 +93,11 @@ main(void)
if
(
ps
[
i
]
==
NULL
)
{
char
buf
[
BUFERROR_BUF
];
buferror
(
buf
,
sizeof
(
buf
));
malloc_printf
(
"Error for
size %zu (%#zx): %s
\n
"
,
size
,
size
,
buf
);
exit
(
1
);
buferror
(
get_errno
(),
buf
,
sizeof
(
buf
));
test_fail
(
"Error for
alignment=%zu, "
"
size
=%zu (%#zx): %s"
,
alignment
,
size
,
size
,
buf
);
}
total
+=
malloc_usable_size
(
ps
[
i
]);
if
(
total
>=
(
MAXALIGN
<<
1
))
...
...
@@ -113,7 +111,15 @@ main(void)
}
}
}
}
TEST_END
int
main
(
void
)
{
malloc_printf
(
"Test end
\n
"
);
return
(
0
);
return
(
test
(
test_alignment_errors
,
test_oom_errors
,
test_alignment_and_size
));
}
deps/jemalloc/test/allocated.c
→
deps/jemalloc/test/
integration/
allocated.c
View file @
fceef8e0
#define JEMALLOC_MANGLE
#include "jemalloc_test.h"
#include "test/jemalloc_test.h"
static
const
bool
config_stats
=
#ifdef JEMALLOC_STATS
true
#else
false
#endif
;
void
*
je_threa
d_start
(
void
*
arg
)
th
d_start
(
void
*
arg
)
{
int
err
;
void
*
p
;
...
...
@@ -12,71 +19,57 @@ je_thread_start(void *arg)
sz
=
sizeof
(
a0
);
if
((
err
=
mallctl
(
"thread.allocated"
,
&
a0
,
&
sz
,
NULL
,
0
)))
{
if
(
err
==
ENOENT
)
{
#ifdef JEMALLOC_STATS
assert
(
false
);
#endif
goto
label_return
;
}
malloc_printf
(
"%s(): Error in mallctl(): %s
\n
"
,
__func__
,
if
(
err
==
ENOENT
)
goto
label_ENOENT
;
test_fail
(
"%s(): Error in mallctl(): %s"
,
__func__
,
strerror
(
err
));
exit
(
1
);
}
sz
=
sizeof
(
ap0
);
if
((
err
=
mallctl
(
"thread.allocatedp"
,
&
ap0
,
&
sz
,
NULL
,
0
)))
{
if
(
err
==
ENOENT
)
{
#ifdef JEMALLOC_STATS
assert
(
false
);
#endif
goto
label_return
;
}
malloc_printf
(
"%s(): Error in mallctl(): %s
\n
"
,
__func__
,
if
(
err
==
ENOENT
)
goto
label_ENOENT
;
test_fail
(
"%s(): Error in mallctl(): %s"
,
__func__
,
strerror
(
err
));
exit
(
1
);
}
assert
(
*
ap0
==
a0
);
assert_u64_eq
(
*
ap0
,
a0
,
"
\"
thread.allocatedp
\"
should provide a pointer to internal "
"storage"
);
sz
=
sizeof
(
d0
);
if
((
err
=
mallctl
(
"thread.deallocated"
,
&
d0
,
&
sz
,
NULL
,
0
)))
{
if
(
err
==
ENOENT
)
{
#ifdef JEMALLOC_STATS
assert
(
false
);
#endif
goto
label_return
;
}
malloc_printf
(
"%s(): Error in mallctl(): %s
\n
"
,
__func__
,
if
(
err
==
ENOENT
)
goto
label_ENOENT
;
test_fail
(
"%s(): Error in mallctl(): %s"
,
__func__
,
strerror
(
err
));
exit
(
1
);
}
sz
=
sizeof
(
dp0
);
if
((
err
=
mallctl
(
"thread.deallocatedp"
,
&
dp0
,
&
sz
,
NULL
,
0
)))
{
if
(
err
==
ENOENT
)
{
#ifdef JEMALLOC_STATS
assert
(
false
);
#endif
goto
label_return
;
}
malloc_printf
(
"%s(): Error in mallctl(): %s
\n
"
,
__func__
,
if
(
err
==
ENOENT
)
goto
label_ENOENT
;
test_fail
(
"%s(): Error in mallctl(): %s"
,
__func__
,
strerror
(
err
));
exit
(
1
);
}
assert
(
*
dp0
==
d0
);
assert_u64_eq
(
*
dp0
,
d0
,
"
\"
thread.deallocatedp
\"
should provide a pointer to internal "
"storage"
);
p
=
malloc
(
1
);
if
(
p
==
NULL
)
{
malloc_printf
(
"%s(): Error in malloc()
\n
"
,
__func__
);
exit
(
1
);
}
assert_ptr_not_null
(
p
,
"Unexpected malloc() error"
);
sz
=
sizeof
(
a1
);
mallctl
(
"thread.allocated"
,
&
a1
,
&
sz
,
NULL
,
0
);
sz
=
sizeof
(
ap1
);
mallctl
(
"thread.allocatedp"
,
&
ap1
,
&
sz
,
NULL
,
0
);
assert
(
*
ap1
==
a1
);
assert
(
ap0
==
ap1
);
assert_u64_eq
(
*
ap1
,
a1
,
"Dereferenced
\"
thread.allocatedp
\"
value should equal "
"
\"
thread.allocated
\"
value"
);
assert_ptr_eq
(
ap0
,
ap1
,
"Pointer returned by
\"
thread.allocatedp
\"
should not change"
);
usize
=
malloc_usable_size
(
p
);
assert
(
a0
+
usize
<=
a1
);
assert_u64_le
(
a0
+
usize
,
a1
,
"Allocated memory counter should increase by at least the amount "
"explicitly allocated"
);
free
(
p
);
...
...
@@ -84,35 +77,49 @@ je_thread_start(void *arg)
mallctl
(
"thread.deallocated"
,
&
d1
,
&
sz
,
NULL
,
0
);
sz
=
sizeof
(
dp1
);
mallctl
(
"thread.deallocatedp"
,
&
dp1
,
&
sz
,
NULL
,
0
);
assert
(
*
dp1
==
d1
);
assert
(
dp0
==
dp1
);
assert_u64_eq
(
*
dp1
,
d1
,
"Dereferenced
\"
thread.deallocatedp
\"
value should equal "
"
\"
thread.deallocated
\"
value"
);
assert_ptr_eq
(
dp0
,
dp1
,
"Pointer returned by
\"
thread.deallocatedp
\"
should not change"
);
assert
(
d0
+
usize
<=
d1
);
assert_u64_le
(
d0
+
usize
,
d1
,
"Deallocated memory counter should increase by at least the amount "
"explicitly deallocated"
);
label_return:
return
(
NULL
);
label_ENOENT:
assert_false
(
config_stats
,
"ENOENT should only be returned if stats are disabled"
);
test_skip
(
"
\"
thread.allocated
\"
mallctl not available"
);
return
(
NULL
);
}
int
main
(
void
)
TEST_BEGIN
(
test_main_thread
)
{
int
ret
=
0
;
je_thread_t
thread
;
malloc_printf
(
"Test begin
\n
"
);
je_thread_start
(
NULL
);
je_thread_create
(
&
thread
,
je_thread_start
,
NULL
);
je_thread_join
(
thread
,
(
void
*
)
&
ret
);
thd_start
(
NULL
);
}
TEST_END
je_thread_start
(
NULL
);
TEST_BEGIN
(
test_subthread
)
{
thd_t
thd
;
je_thread_create
(
&
thread
,
je_thread_start
,
NULL
);
je_thread_join
(
thread
,
(
void
*
)
&
ret
);
thd_create
(
&
thd
,
thd_start
,
NULL
);
thd_join
(
thd
,
NULL
);
}
TEST_END
je_thread_start
(
NULL
);
int
main
(
void
)
{
malloc_printf
(
"Test end
\n
"
);
return
(
ret
);
/* Run tests multiple times to check for bad interactions. */
return
(
test
(
test_main_thread
,
test_subthread
,
test_main_thread
,
test_subthread
,
test_main_thread
));
}
deps/jemalloc/test/integration/allocm.c
0 → 100644
View file @
fceef8e0
#include "test/jemalloc_test.h"
#define CHUNK 0x400000
#define MAXALIGN (((size_t)1) << 25)
#define NITER 4
TEST_BEGIN
(
test_basic
)
{
size_t
nsz
,
rsz
,
sz
;
void
*
p
;
sz
=
42
;
nsz
=
0
;
assert_d_eq
(
nallocm
(
&
nsz
,
sz
,
0
),
ALLOCM_SUCCESS
,
"Unexpected nallocm() error"
);
rsz
=
0
;
assert_d_eq
(
allocm
(
&
p
,
&
rsz
,
sz
,
0
),
ALLOCM_SUCCESS
,
"Unexpected allocm() error"
);
assert_zu_ge
(
rsz
,
sz
,
"Real size smaller than expected"
);
assert_zu_eq
(
nsz
,
rsz
,
"nallocm()/allocm() rsize mismatch"
);
assert_d_eq
(
dallocm
(
p
,
0
),
ALLOCM_SUCCESS
,
"Unexpected dallocm() error"
);
assert_d_eq
(
allocm
(
&
p
,
NULL
,
sz
,
0
),
ALLOCM_SUCCESS
,
"Unexpected allocm() error"
);
assert_d_eq
(
dallocm
(
p
,
0
),
ALLOCM_SUCCESS
,
"Unexpected dallocm() error"
);
nsz
=
0
;
assert_d_eq
(
nallocm
(
&
nsz
,
sz
,
ALLOCM_ZERO
),
ALLOCM_SUCCESS
,
"Unexpected nallocm() error"
);
rsz
=
0
;
assert_d_eq
(
allocm
(
&
p
,
&
rsz
,
sz
,
ALLOCM_ZERO
),
ALLOCM_SUCCESS
,
"Unexpected allocm() error"
);
assert_zu_eq
(
nsz
,
rsz
,
"nallocm()/allocm() rsize mismatch"
);
assert_d_eq
(
dallocm
(
p
,
0
),
ALLOCM_SUCCESS
,
"Unexpected dallocm() error"
);
}
TEST_END
TEST_BEGIN
(
test_alignment_and_size
)
{
int
r
;
size_t
nsz
,
rsz
,
sz
,
alignment
,
total
;
unsigned
i
;
void
*
ps
[
NITER
];
for
(
i
=
0
;
i
<
NITER
;
i
++
)
ps
[
i
]
=
NULL
;
for
(
alignment
=
8
;
alignment
<=
MAXALIGN
;
alignment
<<=
1
)
{
total
=
0
;
for
(
sz
=
1
;
sz
<
3
*
alignment
&&
sz
<
(
1U
<<
31
);
sz
+=
(
alignment
>>
(
LG_SIZEOF_PTR
-
1
))
-
1
)
{
for
(
i
=
0
;
i
<
NITER
;
i
++
)
{
nsz
=
0
;
r
=
nallocm
(
&
nsz
,
sz
,
ALLOCM_ALIGN
(
alignment
)
|
ALLOCM_ZERO
);
assert_d_eq
(
r
,
ALLOCM_SUCCESS
,
"nallocm() error for alignment=%zu, "
"size=%zu (%#zx): %d"
,
alignment
,
sz
,
sz
,
r
);
rsz
=
0
;
r
=
allocm
(
&
ps
[
i
],
&
rsz
,
sz
,
ALLOCM_ALIGN
(
alignment
)
|
ALLOCM_ZERO
);
assert_d_eq
(
r
,
ALLOCM_SUCCESS
,
"allocm() error for alignment=%zu, "
"size=%zu (%#zx): %d"
,
alignment
,
sz
,
sz
,
r
);
assert_zu_ge
(
rsz
,
sz
,
"Real size smaller than expected for "
"alignment=%zu, size=%zu"
,
alignment
,
sz
);
assert_zu_eq
(
nsz
,
rsz
,
"nallocm()/allocm() rsize mismatch for "
"alignment=%zu, size=%zu"
,
alignment
,
sz
);
assert_ptr_null
(
(
void
*
)((
uintptr_t
)
ps
[
i
]
&
(
alignment
-
1
)),
"%p inadequately aligned for"
" alignment=%zu, size=%zu"
,
ps
[
i
],
alignment
,
sz
);
sallocm
(
ps
[
i
],
&
rsz
,
0
);
total
+=
rsz
;
if
(
total
>=
(
MAXALIGN
<<
1
))
break
;
}
for
(
i
=
0
;
i
<
NITER
;
i
++
)
{
if
(
ps
[
i
]
!=
NULL
)
{
dallocm
(
ps
[
i
],
0
);
ps
[
i
]
=
NULL
;
}
}
}
}
}
TEST_END
int
main
(
void
)
{
return
(
test
(
test_basic
,
test_alignment_and_size
));
}
deps/jemalloc/test/integration/mallocx.c
0 → 100644
View file @
fceef8e0
#include "test/jemalloc_test.h"
#define CHUNK 0x400000
#define MAXALIGN (((size_t)1) << 25)
#define NITER 4
TEST_BEGIN
(
test_basic
)
{
size_t
nsz
,
rsz
,
sz
;
void
*
p
;
sz
=
42
;
nsz
=
nallocx
(
sz
,
0
);
assert_zu_ne
(
nsz
,
0
,
"Unexpected nallocx() error"
);
p
=
mallocx
(
sz
,
0
);
assert_ptr_not_null
(
p
,
"Unexpected mallocx() error"
);
rsz
=
sallocx
(
p
,
0
);
assert_zu_ge
(
rsz
,
sz
,
"Real size smaller than expected"
);
assert_zu_eq
(
nsz
,
rsz
,
"nallocx()/sallocx() size mismatch"
);
dallocx
(
p
,
0
);
p
=
mallocx
(
sz
,
0
);
assert_ptr_not_null
(
p
,
"Unexpected mallocx() error"
);
dallocx
(
p
,
0
);
nsz
=
nallocx
(
sz
,
MALLOCX_ZERO
);
assert_zu_ne
(
nsz
,
0
,
"Unexpected nallocx() error"
);
p
=
mallocx
(
sz
,
MALLOCX_ZERO
);
assert_ptr_not_null
(
p
,
"Unexpected mallocx() error"
);
rsz
=
sallocx
(
p
,
0
);
assert_zu_eq
(
nsz
,
rsz
,
"nallocx()/sallocx() rsize mismatch"
);
dallocx
(
p
,
0
);
}
TEST_END
TEST_BEGIN
(
test_alignment_and_size
)
{
size_t
nsz
,
rsz
,
sz
,
alignment
,
total
;
unsigned
i
;
void
*
ps
[
NITER
];
for
(
i
=
0
;
i
<
NITER
;
i
++
)
ps
[
i
]
=
NULL
;
for
(
alignment
=
8
;
alignment
<=
MAXALIGN
;
alignment
<<=
1
)
{
total
=
0
;
for
(
sz
=
1
;
sz
<
3
*
alignment
&&
sz
<
(
1U
<<
31
);
sz
+=
(
alignment
>>
(
LG_SIZEOF_PTR
-
1
))
-
1
)
{
for
(
i
=
0
;
i
<
NITER
;
i
++
)
{
nsz
=
nallocx
(
sz
,
MALLOCX_ALIGN
(
alignment
)
|
MALLOCX_ZERO
);
assert_zu_ne
(
nsz
,
0
,
"nallocx() error for alignment=%zu, "
"size=%zu (%#zx)"
,
alignment
,
sz
,
sz
);
ps
[
i
]
=
mallocx
(
sz
,
MALLOCX_ALIGN
(
alignment
)
|
MALLOCX_ZERO
);
assert_ptr_not_null
(
ps
[
i
],
"mallocx() error for alignment=%zu, "
"size=%zu (%#zx)"
,
alignment
,
sz
,
sz
);
rsz
=
sallocx
(
ps
[
i
],
0
);
assert_zu_ge
(
rsz
,
sz
,
"Real size smaller than expected for "
"alignment=%zu, size=%zu"
,
alignment
,
sz
);
assert_zu_eq
(
nsz
,
rsz
,
"nallocx()/sallocx() size mismatch for "
"alignment=%zu, size=%zu"
,
alignment
,
sz
);
assert_ptr_null
(
(
void
*
)((
uintptr_t
)
ps
[
i
]
&
(
alignment
-
1
)),
"%p inadequately aligned for"
" alignment=%zu, size=%zu"
,
ps
[
i
],
alignment
,
sz
);
total
+=
rsz
;
if
(
total
>=
(
MAXALIGN
<<
1
))
break
;
}
for
(
i
=
0
;
i
<
NITER
;
i
++
)
{
if
(
ps
[
i
]
!=
NULL
)
{
dallocx
(
ps
[
i
],
0
);
ps
[
i
]
=
NULL
;
}
}
}
}
}
TEST_END
int
main
(
void
)
{
return
(
test
(
test_basic
,
test_alignment_and_size
));
}
deps/jemalloc/test/mremap.c
→
deps/jemalloc/test/
integration/
mremap.c
View file @
fceef8e0
#define JEMALLOC_MANGLE
#include "jemalloc_test.h"
#include "test/jemalloc_test.h"
int
main
(
void
)
TEST_BEGIN
(
test_mremap
)
{
int
ret
,
err
;
int
err
;
size_t
sz
,
lg_chunk
,
chunksize
,
i
;
char
*
p
,
*
q
;
malloc_printf
(
"Test begin
\n
"
);
sz
=
sizeof
(
lg_chunk
);
if
((
err
=
mallctl
(
"opt.lg_chunk"
,
&
lg_chunk
,
&
sz
,
NULL
,
0
)))
{
assert
(
err
!=
ENOENT
);
malloc_printf
(
"%s(): Error in mallctl(): %s
\n
"
,
__func__
,
strerror
(
err
));
ret
=
1
;
goto
label_return
;
}
err
=
mallctl
(
"opt.lg_chunk"
,
&
lg_chunk
,
&
sz
,
NULL
,
0
);
assert_d_eq
(
err
,
0
,
"Error in mallctl(): %s"
,
strerror
(
err
));
chunksize
=
((
size_t
)
1U
)
<<
lg_chunk
;
p
=
(
char
*
)
malloc
(
chunksize
);
if
(
p
==
NULL
)
{
malloc_printf
(
"malloc(%zu) --> %p
\n
"
,
chunksize
,
p
);
ret
=
1
;
goto
label_return
;
}
assert_ptr_not_null
(
p
,
"malloc(%zu) --> %p"
,
chunksize
,
p
);
memset
(
p
,
'a'
,
chunksize
);
q
=
(
char
*
)
realloc
(
p
,
chunksize
*
2
);
if
(
q
==
NULL
)
{
malloc_printf
(
"realloc(%p, %zu) --> %p
\n
"
,
p
,
chunksize
*
2
,
q
);
ret
=
1
;
goto
label_return
;
}
assert_ptr_not_null
(
q
,
"realloc(%p, %zu) --> %p"
,
p
,
chunksize
*
2
,
q
);
for
(
i
=
0
;
i
<
chunksize
;
i
++
)
{
assert
(
q
[
i
]
==
'a'
);
assert_c_eq
(
q
[
i
],
'a'
,
"realloc() should preserve existing bytes across copies"
);
}
p
=
q
;
q
=
(
char
*
)
realloc
(
p
,
chunksize
);
if
(
q
==
NULL
)
{
malloc_printf
(
"realloc(%p, %zu) --> %p
\n
"
,
p
,
chunksize
,
q
);
ret
=
1
;
goto
label_return
;
}
assert_ptr_not_null
(
q
,
"realloc(%p, %zu) --> %p"
,
p
,
chunksize
,
q
);
for
(
i
=
0
;
i
<
chunksize
;
i
++
)
{
assert
(
q
[
i
]
==
'a'
);
assert_c_eq
(
q
[
i
],
'a'
,
"realloc() should preserve existing bytes across copies"
);
}
free
(
q
);
}
TEST_END
int
main
(
void
)
{
ret
=
0
;
label_return:
malloc_printf
(
"Test end
\n
"
);
return
(
ret
);
return
(
test
(
test_mremap
));
}
deps/jemalloc/test/posix_memalign.c
→
deps/jemalloc/test/
integration/
posix_memalign.c
View file @
fceef8e0
#define JEMALLOC_MANGLE
#include "jemalloc_test.h"
#include "test/jemalloc_test.h"
#define
CHUNK 0x400000
#define
CHUNK 0x400000
/* #define MAXALIGN ((size_t)UINT64_C(0x80000000000)) */
#define
MAXALIGN ((size_t)0x2000000LU)
#define
NITER 4
#define
MAXALIGN ((size_t)0x2000000LU)
#define
NITER 4
int
main
(
void
)
TEST_BEGIN
(
test_alignment_errors
)
{
size_t
alignment
,
size
,
total
;
unsigned
i
;
int
err
;
void
*
p
,
*
ps
[
NITER
];
malloc_printf
(
"Test begin
\n
"
);
size_t
alignment
;
void
*
p
;
/* Test error conditions. */
for
(
alignment
=
0
;
alignment
<
sizeof
(
void
*
);
alignment
++
)
{
err
=
posix_memalign
(
&
p
,
alignment
,
1
);
if
(
err
!=
EINVAL
)
{
malloc_printf
(
"Expected error for invalid alignment %zu
\n
"
,
alignment
);
}
assert_d_eq
(
posix_memalign
(
&
p
,
alignment
,
1
),
EINVAL
,
"Expected error for invalid alignment %zu"
,
alignment
);
}
for
(
alignment
=
sizeof
(
size_t
);
alignment
<
MAXALIGN
;
alignment
<<=
1
)
{
err
=
posix_memalign
(
&
p
,
alignment
+
1
,
1
);
if
(
err
==
0
)
{
malloc_printf
(
"Expected error for invalid alignment %zu
\n
"
,
alignment
+
1
);
}
assert_d_ne
(
posix_memalign
(
&
p
,
alignment
+
1
,
1
),
0
,
"Expected error for invalid alignment %zu"
,
alignment
+
1
);
}
}
TEST_END
TEST_BEGIN
(
test_oom_errors
)
{
size_t
alignment
,
size
;
void
*
p
;
#if LG_SIZEOF_PTR == 3
alignment
=
UINT64_C
(
0x8000000000000000
);
...
...
@@ -43,26 +37,20 @@ main(void)
alignment
=
0x80000000LU
;
size
=
0x80000000LU
;
#endif
err
=
posix_memalign
(
&
p
,
alignment
,
size
);
if
(
err
==
0
)
{
malloc_printf
(
"Expected error for posix_memalign(&p, %zu, %zu)
\n
"
,
alignment
,
size
);
}
assert_d_ne
(
posix_memalign
(
&
p
,
alignment
,
size
),
0
,
"Expected error for posix_memalign(&p, %zu, %zu)"
,
alignment
,
size
);
#if LG_SIZEOF_PTR == 3
alignment
=
UINT64_C
(
0x4000000000000000
);
size
=
UINT64_C
(
0x
84
00000000000001
);
size
=
UINT64_C
(
0x
c0
00000000000001
);
#else
alignment
=
0x40000000LU
;
size
=
0x
84
000001LU
;
size
=
0x
c0
000001LU
;
#endif
err
=
posix_memalign
(
&
p
,
alignment
,
size
);
if
(
err
==
0
)
{
malloc_printf
(
"Expected error for posix_memalign(&p, %zu, %zu)
\n
"
,
alignment
,
size
);
}
assert_d_ne
(
posix_memalign
(
&
p
,
alignment
,
size
),
0
,
"Expected error for posix_memalign(&p, %zu, %zu)"
,
alignment
,
size
);
alignment
=
0x10LU
;
#if LG_SIZEOF_PTR == 3
...
...
@@ -70,12 +58,18 @@ main(void)
#else
size
=
0xfffffff0LU
;
#endif
err
=
posix_memalign
(
&
p
,
alignment
,
size
);
if
(
err
==
0
)
{
malloc_printf
(
"Expected error for posix_memalign(&p, %zu, %zu)
\n
"
,
alignment
,
size
);
}
assert_d_ne
(
posix_memalign
(
&
p
,
alignment
,
size
),
0
,
"Expected error for posix_memalign(&p, %zu, %zu)"
,
alignment
,
size
);
}
TEST_END
TEST_BEGIN
(
test_alignment_and_size
)
{
size_t
alignment
,
size
,
total
;
unsigned
i
;
int
err
;
void
*
ps
[
NITER
];
for
(
i
=
0
;
i
<
NITER
;
i
++
)
ps
[
i
]
=
NULL
;
...
...
@@ -84,7 +78,6 @@ main(void)
alignment
<=
MAXALIGN
;
alignment
<<=
1
)
{
total
=
0
;
malloc_printf
(
"Alignment: %zu
\n
"
,
alignment
);
for
(
size
=
1
;
size
<
3
*
alignment
&&
size
<
(
1U
<<
31
);
size
+=
(
alignment
>>
(
LG_SIZEOF_PTR
-
1
))
-
1
)
{
...
...
@@ -92,10 +85,13 @@ main(void)
err
=
posix_memalign
(
&
ps
[
i
],
alignment
,
size
);
if
(
err
)
{
malloc_printf
(
"Error for size %zu (%#zx): %s
\n
"
,
size
,
size
,
strerror
(
err
));
exit
(
1
);
char
buf
[
BUFERROR_BUF
];
buferror
(
get_errno
(),
buf
,
sizeof
(
buf
));
test_fail
(
"Error for alignment=%zu, "
"size=%zu (%#zx): %s"
,
alignment
,
size
,
size
,
buf
);
}
total
+=
malloc_usable_size
(
ps
[
i
]);
if
(
total
>=
(
MAXALIGN
<<
1
))
...
...
@@ -109,7 +105,15 @@ main(void)
}
}
}
}
TEST_END
int
main
(
void
)
{
malloc_printf
(
"Test end
\n
"
);
return
(
0
);
return
(
test
(
test_alignment_errors
,
test_oom_errors
,
test_alignment_and_size
));
}
Prev
1
2
3
4
5
6
7
8
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment