js/src/jit-test/tests/gc/bug-820186.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/jit-test/tests/gc/bug-820186.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,297 @@
     1.4 +// |jit-test| slow;
     1.5 +
     1.6 +function randomRecursion() {
     1.7 +    var y = ""
     1.8 +    if (rnd(2)) {
     1.9 +        var x = 2;
    1.10 +        "{" + x + "}";
    1.11 +        randomRecursion();
    1.12 +        randomRecursion();
    1.13 +        return [""];
    1.14 +    }
    1.15 +    return [""];
    1.16 +}
    1.17 +
    1.18 +function thisFunctionIsNeverCalled() {
    1.19 +}
    1.20 +
    1.21 +function testOne() {
    1.22 +    ox = newGlobal();
    1.23 +    var code = randomRecursion()[rnd(3)];
    1.24 +}
    1.25 +
    1.26 +initRnd();
    1.27 +gczeal(10, 3);
    1.28 +
    1.29 +for (var count = 0; count < 20; count++) {
    1.30 +    print(count);
    1.31 +    testOne()
    1.32 +}
    1.33 +
    1.34 +// ==========================================================================================
    1.35 +
    1.36 +// this program is a JavaScript version of Mersenne Twister, with concealment and encapsulation in class,
    1.37 +// an almost straight conversion from the original program, mt19937ar.c,
    1.38 +// translated by y. okada on July 17, 2006.
    1.39 +// Changes by Jesse Ruderman: added "var" keyword in a few spots; added export_mta etc; pasted into fuzz.js.
    1.40 +// in this program, procedure descriptions and comments of original source code were not removed.
    1.41 +// lines commented with //c// were originally descriptions of c procedure. and a few following lines are appropriate JavaScript descriptions.
    1.42 +// lines commented with /* and */ are original comments.
    1.43 +// lines commented with // are additional comments in this JavaScript version.
    1.44 +// before using this version, create at least one instance of MersenneTwister19937 class, and initialize the each state, given below in c comments, of all the instances.
    1.45 +/*
    1.46 +   A C-program for MT19937, with initialization improved 2002/1/26.
    1.47 +   Coded by Takuji Nishimura and Makoto Matsumoto.
    1.48 +
    1.49 +   Before using, initialize the state by using init_genrand(seed)
    1.50 +   or init_by_array(init_key, key_length).
    1.51 +
    1.52 +   Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura,
    1.53 +   All rights reserved.
    1.54 +
    1.55 +   Redistribution and use in source and binary forms, with or without
    1.56 +   modification, are permitted provided that the following conditions
    1.57 +   are met:
    1.58 +
    1.59 +     1. Redistributions of source code must retain the above copyright
    1.60 +        notice, this list of conditions and the following disclaimer.
    1.61 +
    1.62 +     2. Redistributions in binary form must reproduce the above copyright
    1.63 +        notice, this list of conditions and the following disclaimer in the
    1.64 +        documentation and/or other materials provided with the distribution.
    1.65 +
    1.66 +     3. The names of its contributors may not be used to endorse or promote
    1.67 +        products derived from this software without specific prior written
    1.68 +        permission.
    1.69 +
    1.70 +   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    1.71 +   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    1.72 +   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    1.73 +   A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
    1.74 +   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
    1.75 +   EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
    1.76 +   PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
    1.77 +   PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
    1.78 +   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
    1.79 +   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
    1.80 +   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    1.81 +
    1.82 +
    1.83 +   Any feedback is very welcome.
    1.84 +   http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html
    1.85 +   email: m-mat @ math.sci.hiroshima-u.ac.jp (remove space)
    1.86 +*/
    1.87 +
    1.88 +function MersenneTwister19937()
    1.89 +{
    1.90 +	/* Period parameters */
    1.91 +	//c//#define N 624
    1.92 +	//c//#define M 397
    1.93 +	//c//#define MATRIX_A 0x9908b0dfUL   /* constant vector a */
    1.94 +	//c//#define UPPER_MASK 0x80000000UL /* most significant w-r bits */
    1.95 +	//c//#define LOWER_MASK 0x7fffffffUL /* least significant r bits */
    1.96 +	var N = 624;
    1.97 +	var M = 397;
    1.98 +	var MATRIX_A = 0x9908b0df;   /* constant vector a */
    1.99 +	var UPPER_MASK = 0x80000000; /* most significant w-r bits */
   1.100 +	var LOWER_MASK = 0x7fffffff; /* least significant r bits */
   1.101 +	//c//static unsigned long mt[N]; /* the array for the state vector  */
   1.102 +	//c//static int mti=N+1; /* mti==N+1 means mt[N] is not initialized */
   1.103 +	var mt = new Array(N);   /* the array for the state vector  */
   1.104 +	var mti = N+1;           /* mti==N+1 means mt[N] is not initialized */
   1.105 +
   1.106 +	function unsigned32 (n1) // returns a 32-bits unsiged integer from an operand to which applied a bit operator.
   1.107 +	{
   1.108 +		return n1 < 0 ? (n1 ^ UPPER_MASK) + UPPER_MASK : n1;
   1.109 +	}
   1.110 +
   1.111 +	function subtraction32 (n1, n2) // emulates lowerflow of a c 32-bits unsiged integer variable, instead of the operator -. these both arguments must be non-negative integers expressible using unsigned 32 bits.
   1.112 +	{
   1.113 +		return n1 < n2 ? unsigned32((0x100000000 - (n2 - n1)) & 0xffffffff) : n1 - n2;
   1.114 +	}
   1.115 +
   1.116 +	function addition32 (n1, n2) // emulates overflow of a c 32-bits unsiged integer variable, instead of the operator +. these both arguments must be non-negative integers expressible using unsigned 32 bits.
   1.117 +	{
   1.118 +		return unsigned32((n1 + n2) & 0xffffffff)
   1.119 +	}
   1.120 +
   1.121 +	function multiplication32 (n1, n2) // emulates overflow of a c 32-bits unsiged integer variable, instead of the operator *. these both arguments must be non-negative integers expressible using unsigned 32 bits.
   1.122 +	{
   1.123 +		var sum = 0;
   1.124 +		for (var i = 0; i < 32; ++i){
   1.125 +			if ((n1 >>> i) & 0x1){
   1.126 +				sum = addition32(sum, unsigned32(n2 << i));
   1.127 +			}
   1.128 +		}
   1.129 +		return sum;
   1.130 +	}
   1.131 +
   1.132 +	/* initializes mt[N] with a seed */
   1.133 +	//c//void init_genrand(unsigned long s)
   1.134 +	this.init_genrand = function (s)
   1.135 +	{
   1.136 +		//c//mt[0]= s & 0xffffffff;
   1.137 +		mt[0]= unsigned32(s & 0xffffffff);
   1.138 +		for (mti=1; mti<N; mti++) {
   1.139 +			mt[mti] =
   1.140 +			//c//(1812433253 * (mt[mti-1] ^ (mt[mti-1] >> 30)) + mti);
   1.141 +			addition32(multiplication32(1812433253, unsigned32(mt[mti-1] ^ (mt[mti-1] >>> 30))), mti);
   1.142 +			/* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */
   1.143 +			/* In the previous versions, MSBs of the seed affect   */
   1.144 +			/* only MSBs of the array mt[].                        */
   1.145 +			/* 2002/01/09 modified by Makoto Matsumoto             */
   1.146 +			//c//mt[mti] &= 0xffffffff;
   1.147 +			mt[mti] = unsigned32(mt[mti] & 0xffffffff);
   1.148 +			/* for >32 bit machines */
   1.149 +		}
   1.150 +	}
   1.151 +
   1.152 +	/* initialize by an array with array-length */
   1.153 +	/* init_key is the array for initializing keys */
   1.154 +	/* key_length is its length */
   1.155 +	/* slight change for C++, 2004/2/26 */
   1.156 +	//c//void init_by_array(unsigned long init_key[], int key_length)
   1.157 +	this.init_by_array = function (init_key, key_length)
   1.158 +	{
   1.159 +		//c//int i, j, k;
   1.160 +		var i, j, k;
   1.161 +		//c//init_genrand(19650218);
   1.162 +		this.init_genrand(19650218);
   1.163 +		i=1; j=0;
   1.164 +		k = (N>key_length ? N : key_length);
   1.165 +		for (; k; k--) {
   1.166 +			//c//mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 30)) * 1664525))
   1.167 +			//c//	+ init_key[j] + j; /* non linear */
   1.168 +			mt[i] = addition32(addition32(unsigned32(mt[i] ^ multiplication32(unsigned32(mt[i-1] ^ (mt[i-1] >>> 30)), 1664525)), init_key[j]), j);
   1.169 +			mt[i] =
   1.170 +			//c//mt[i] &= 0xffffffff; /* for WORDSIZE > 32 machines */
   1.171 +			unsigned32(mt[i] & 0xffffffff);
   1.172 +			i++; j++;
   1.173 +			if (i>=N) { mt[0] = mt[N-1]; i=1; }
   1.174 +			if (j>=key_length) j=0;
   1.175 +		}
   1.176 +		for (k=N-1; k; k--) {
   1.177 +			//c//mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 30)) * 1566083941))
   1.178 +			//c//- i; /* non linear */
   1.179 +			mt[i] = subtraction32(unsigned32((dbg=mt[i]) ^ multiplication32(unsigned32(mt[i-1] ^ (mt[i-1] >>> 30)), 1566083941)), i);
   1.180 +			//c//mt[i] &= 0xffffffff; /* for WORDSIZE > 32 machines */
   1.181 +			mt[i] = unsigned32(mt[i] & 0xffffffff);
   1.182 +			i++;
   1.183 +			if (i>=N) { mt[0] = mt[N-1]; i=1; }
   1.184 +		}
   1.185 +		mt[0] = 0x80000000; /* MSB is 1; assuring non-zero initial array */
   1.186 +	}
   1.187 +
   1.188 +  this.export_state = function() { return [mt, mti]; };
   1.189 +  this.import_state = function(s) { mt = s[0]; mti = s[1]; };
   1.190 +  this.export_mta = function() { return mt; };
   1.191 +  this.import_mta = function(_mta) { mt = _mta };
   1.192 +  this.export_mti = function() { return mti; };
   1.193 +  this.import_mti = function(_mti) { mti = _mti; }
   1.194 +
   1.195 +	/* generates a random number on [0,0xffffffff]-interval */
   1.196 +	//c//unsigned long genrand_int32(void)
   1.197 +	this.genrand_int32 = function ()
   1.198 +	{
   1.199 +		//c//unsigned long y;
   1.200 +		//c//static unsigned long mag01[2]={0x0UL, MATRIX_A};
   1.201 +		var y;
   1.202 +		var mag01 = new Array(0x0, MATRIX_A);
   1.203 +		/* mag01[x] = x * MATRIX_A  for x=0,1 */
   1.204 +
   1.205 +		if (mti >= N) { /* generate N words at one time */
   1.206 +			//c//int kk;
   1.207 +			var kk;
   1.208 +
   1.209 +			if (mti == N+1)   /* if init_genrand() has not been called, */
   1.210 +				//c//init_genrand(5489); /* a default initial seed is used */
   1.211 +				this.init_genrand(5489); /* a default initial seed is used */
   1.212 +
   1.213 +			for (kk=0;kk<N-M;kk++) {
   1.214 +				//c//y = (mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK);
   1.215 +				//c//mt[kk] = mt[kk+M] ^ (y >> 1) ^ mag01[y & 0x1];
   1.216 +				y = unsigned32((mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK));
   1.217 +				mt[kk] = unsigned32(mt[kk+M] ^ (y >>> 1) ^ mag01[y & 0x1]);
   1.218 +			}
   1.219 +			for (;kk<N-1;kk++) {
   1.220 +				//c//y = (mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK);
   1.221 +				//c//mt[kk] = mt[kk+(M-N)] ^ (y >> 1) ^ mag01[y & 0x1];
   1.222 +				y = unsigned32((mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK));
   1.223 +				mt[kk] = unsigned32(mt[kk+(M-N)] ^ (y >>> 1) ^ mag01[y & 0x1]);
   1.224 +			}
   1.225 +			//c//y = (mt[N-1]&UPPER_MASK)|(mt[0]&LOWER_MASK);
   1.226 +			//c//mt[N-1] = mt[M-1] ^ (y >> 1) ^ mag01[y & 0x1];
   1.227 +			y = unsigned32((mt[N-1]&UPPER_MASK)|(mt[0]&LOWER_MASK));
   1.228 +			mt[N-1] = unsigned32(mt[M-1] ^ (y >>> 1) ^ mag01[y & 0x1]);
   1.229 +			mti = 0;
   1.230 +		}
   1.231 +
   1.232 +		y = mt[mti++];
   1.233 +
   1.234 +		/* Tempering */
   1.235 +		//c//y ^= (y >> 11);
   1.236 +		//c//y ^= (y << 7) & 0x9d2c5680;
   1.237 +		//c//y ^= (y << 15) & 0xefc60000;
   1.238 +		//c//y ^= (y >> 18);
   1.239 +		y = unsigned32(y ^ (y >>> 11));
   1.240 +		y = unsigned32(y ^ ((y << 7) & 0x9d2c5680));
   1.241 +		y = unsigned32(y ^ ((y << 15) & 0xefc60000));
   1.242 +		y = unsigned32(y ^ (y >>> 18));
   1.243 +
   1.244 +		return y;
   1.245 +	}
   1.246 +
   1.247 +	/* generates a random number on [0,0x7fffffff]-interval */
   1.248 +	//c//long genrand_int31(void)
   1.249 +	this.genrand_int31 = function ()
   1.250 +	{
   1.251 +		//c//return (genrand_int32()>>1);
   1.252 +		return (this.genrand_int32()>>>1);
   1.253 +	}
   1.254 +
   1.255 +	/* generates a random number on [0,1]-real-interval */
   1.256 +	//c//double genrand_real1(void)
   1.257 +	this.genrand_real1 = function ()
   1.258 +	{
   1.259 +		//c//return genrand_int32()*(1.0/4294967295.0);
   1.260 +		return this.genrand_int32()*(1.0/4294967295.0);
   1.261 +		/* divided by 2^32-1 */
   1.262 +	}
   1.263 +
   1.264 +	/* generates a random number on [0,1)-real-interval */
   1.265 +	//c//double genrand_real2(void)
   1.266 +	this.genrand_real2 = function ()
   1.267 +	{
   1.268 +		//c//return genrand_int32()*(1.0/4294967296.0);
   1.269 +		return this.genrand_int32()*(1.0/4294967296.0);
   1.270 +		/* divided by 2^32 */
   1.271 +	}
   1.272 +
   1.273 +	/* generates a random number on (0,1)-real-interval */
   1.274 +	//c//double genrand_real3(void)
   1.275 +	this.genrand_real3 = function ()
   1.276 +	{
   1.277 +		//c//return ((genrand_int32()) + 0.5)*(1.0/4294967296.0);
   1.278 +		return ((this.genrand_int32()) + 0.5)*(1.0/4294967296.0);
   1.279 +		/* divided by 2^32 */
   1.280 +	}
   1.281 +
   1.282 +	/* generates a random number on [0,1) with 53-bit resolution*/
   1.283 +	//c//double genrand_res53(void)
   1.284 +	this.genrand_res53 = function ()
   1.285 +	{
   1.286 +		//c//unsigned long a=genrand_int32()>>5, b=genrand_int32()>>6;
   1.287 +		var a=this.genrand_int32()>>>5, b=this.genrand_int32()>>>6;
   1.288 +		return(a*67108864.0+b)*(1.0/9007199254740992.0);
   1.289 +	}
   1.290 +	/* These real versions are due to Isaku Wada, 2002/01/09 added */
   1.291 +}
   1.292 +
   1.293 +function initRnd() {
   1.294 +  var fuzzMT = new MersenneTwister19937;
   1.295 +  var fuzzSeed = 53;
   1.296 +  fuzzMT.init_genrand(fuzzSeed);
   1.297 +  rnd = function (n) { var v = Math.floor(fuzzMT.genrand_real2() * n); return v; };
   1.298 +  rnd.rndReal = function() { return fuzzMT.genrand_real2(); };
   1.299 +  rnd.fuzzMT = fuzzMT;
   1.300 +}

mercurial