michael@0: // |reftest| skip-if(!xulRuntime.shell||Android) slow -- bug 504632 michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: //----------------------------------------------------------------------------- michael@0: var BUGNUMBER = 456826; michael@0: var summary = 'Do not assert with JIT during OOM'; michael@0: var actual = 'No Crash'; michael@0: var expect = 'No Crash'; michael@0: michael@0: michael@0: //----------------------------------------------------------------------------- michael@0: test(); michael@0: //----------------------------------------------------------------------------- michael@0: michael@0: function test() michael@0: { michael@0: enterFunc ('test'); michael@0: printBugNumber(BUGNUMBER); michael@0: printStatus (summary); michael@0: michael@0: jit(true); michael@0: michael@0: if (typeof gcparam != 'undefined') michael@0: { michael@0: gc(); michael@0: gc(); michael@0: gcparam("maxBytes", gcparam("gcBytes") + 4*1024); michael@0: expectExitCode(5); michael@0: } michael@0: michael@0: const numRows = 600; michael@0: const numCols = 600; michael@0: var scratch = {}; michael@0: var scratchZ = {}; michael@0: michael@0: function complexMult(a, b) { michael@0: var newr = a.r * b.r - a.i * b.i; michael@0: var newi = a.r * b.i + a.i * b.r; michael@0: scratch.r = newr; michael@0: scratch.i = newi; michael@0: return scratch; michael@0: } michael@0: michael@0: function complexAdd(a, b) { michael@0: scratch.r = a.r + b.r; michael@0: scratch.i = a.i + b.i; michael@0: return scratch; michael@0: } michael@0: michael@0: function abs(a) { michael@0: return Math.sqrt(a.r * a.r + a.i * a.i); michael@0: } michael@0: michael@0: function computeEscapeSpeed(c) { michael@0: scratchZ.r = scratchZ.i = 0; michael@0: const scaler = 5; michael@0: const threshold = (colors.length - 1) * scaler + 1; michael@0: for (var i = 1; i < threshold; ++i) { michael@0: scratchZ = complexAdd(c, complexMult(scratchZ, scratchZ)); michael@0: if (scratchZ.r * scratchZ.r + scratchZ.i * scratchZ.i > 4) { michael@0: return Math.floor((i - 1) / scaler) + 1; michael@0: } michael@0: } michael@0: return 0; michael@0: } michael@0: michael@0: const colorStrings = [ michael@0: "black", michael@0: "green", michael@0: "blue", michael@0: "red", michael@0: "purple", michael@0: "orange", michael@0: "cyan", michael@0: "yellow", michael@0: "magenta", michael@0: "brown", michael@0: "pink", michael@0: "chartreuse", michael@0: "darkorange", michael@0: "crimson", michael@0: "gray", michael@0: "deeppink", michael@0: "firebrick", michael@0: "lavender", michael@0: "lawngreen", michael@0: "lightsalmon", michael@0: "lime", michael@0: "goldenrod" michael@0: ]; michael@0: michael@0: var colors = []; michael@0: michael@0: function createMandelSet(realRange, imagRange) { michael@0: var start = new Date(); michael@0: michael@0: // Set up our colors michael@0: for each (var color in colorStrings) { michael@0: var [r, g, b] = [0, 0, 0]; michael@0: colors.push([r, g, b, 0xff]); michael@0: } michael@0: michael@0: var realStep = (realRange.max - realRange.min)/numCols; michael@0: var imagStep = (imagRange.min - imagRange.max)/numRows; michael@0: for (var i = 0, curReal = realRange.min; michael@0: i < numCols; michael@0: ++i, curReal += realStep) { michael@0: for (var j = 0, curImag = imagRange.max; michael@0: j < numRows; michael@0: ++j, curImag += imagStep) { michael@0: var c = { r: curReal, i: curImag } michael@0: var n = computeEscapeSpeed(c); michael@0: } michael@0: } michael@0: print(Date.now() - start); michael@0: } michael@0: michael@0: var realRange = { min: -2.1, max: 2 }; michael@0: var imagRange = { min: -2, max: 2 }; michael@0: createMandelSet(realRange, imagRange); michael@0: michael@0: jit(false); michael@0: michael@0: reportCompare(expect, actual, summary); michael@0: michael@0: exitFunc ('test'); michael@0: }