|
1 // |reftest| skip-if(!xulRuntime.shell||Android) slow -- bug 504632 |
|
2 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
3 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
4 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
6 |
|
7 //----------------------------------------------------------------------------- |
|
8 var BUGNUMBER = 456826; |
|
9 var summary = 'Do not assert with JIT during OOM'; |
|
10 var actual = 'No Crash'; |
|
11 var expect = 'No Crash'; |
|
12 |
|
13 |
|
14 //----------------------------------------------------------------------------- |
|
15 test(); |
|
16 //----------------------------------------------------------------------------- |
|
17 |
|
18 function test() |
|
19 { |
|
20 enterFunc ('test'); |
|
21 printBugNumber(BUGNUMBER); |
|
22 printStatus (summary); |
|
23 |
|
24 jit(true); |
|
25 |
|
26 if (typeof gcparam != 'undefined') |
|
27 { |
|
28 gc(); |
|
29 gc(); |
|
30 gcparam("maxBytes", gcparam("gcBytes") + 4*1024); |
|
31 expectExitCode(5); |
|
32 } |
|
33 |
|
34 const numRows = 600; |
|
35 const numCols = 600; |
|
36 var scratch = {}; |
|
37 var scratchZ = {}; |
|
38 |
|
39 function complexMult(a, b) { |
|
40 var newr = a.r * b.r - a.i * b.i; |
|
41 var newi = a.r * b.i + a.i * b.r; |
|
42 scratch.r = newr; |
|
43 scratch.i = newi; |
|
44 return scratch; |
|
45 } |
|
46 |
|
47 function complexAdd(a, b) { |
|
48 scratch.r = a.r + b.r; |
|
49 scratch.i = a.i + b.i; |
|
50 return scratch; |
|
51 } |
|
52 |
|
53 function abs(a) { |
|
54 return Math.sqrt(a.r * a.r + a.i * a.i); |
|
55 } |
|
56 |
|
57 function computeEscapeSpeed(c) { |
|
58 scratchZ.r = scratchZ.i = 0; |
|
59 const scaler = 5; |
|
60 const threshold = (colors.length - 1) * scaler + 1; |
|
61 for (var i = 1; i < threshold; ++i) { |
|
62 scratchZ = complexAdd(c, complexMult(scratchZ, scratchZ)); |
|
63 if (scratchZ.r * scratchZ.r + scratchZ.i * scratchZ.i > 4) { |
|
64 return Math.floor((i - 1) / scaler) + 1; |
|
65 } |
|
66 } |
|
67 return 0; |
|
68 } |
|
69 |
|
70 const colorStrings = [ |
|
71 "black", |
|
72 "green", |
|
73 "blue", |
|
74 "red", |
|
75 "purple", |
|
76 "orange", |
|
77 "cyan", |
|
78 "yellow", |
|
79 "magenta", |
|
80 "brown", |
|
81 "pink", |
|
82 "chartreuse", |
|
83 "darkorange", |
|
84 "crimson", |
|
85 "gray", |
|
86 "deeppink", |
|
87 "firebrick", |
|
88 "lavender", |
|
89 "lawngreen", |
|
90 "lightsalmon", |
|
91 "lime", |
|
92 "goldenrod" |
|
93 ]; |
|
94 |
|
95 var colors = []; |
|
96 |
|
97 function createMandelSet(realRange, imagRange) { |
|
98 var start = new Date(); |
|
99 |
|
100 // Set up our colors |
|
101 for each (var color in colorStrings) { |
|
102 var [r, g, b] = [0, 0, 0]; |
|
103 colors.push([r, g, b, 0xff]); |
|
104 } |
|
105 |
|
106 var realStep = (realRange.max - realRange.min)/numCols; |
|
107 var imagStep = (imagRange.min - imagRange.max)/numRows; |
|
108 for (var i = 0, curReal = realRange.min; |
|
109 i < numCols; |
|
110 ++i, curReal += realStep) { |
|
111 for (var j = 0, curImag = imagRange.max; |
|
112 j < numRows; |
|
113 ++j, curImag += imagStep) { |
|
114 var c = { r: curReal, i: curImag } |
|
115 var n = computeEscapeSpeed(c); |
|
116 } |
|
117 } |
|
118 print(Date.now() - start); |
|
119 } |
|
120 |
|
121 var realRange = { min: -2.1, max: 2 }; |
|
122 var imagRange = { min: -2, max: 2 }; |
|
123 createMandelSet(realRange, imagRange); |
|
124 |
|
125 jit(false); |
|
126 |
|
127 reportCompare(expect, actual, summary); |
|
128 |
|
129 exitFunc ('test'); |
|
130 } |