OLD | NEW |
---|---|
1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
113 // Only works with --allow-natives-syntax. | 113 // Only works with --allow-natives-syntax. |
114 var assertOptimized; | 114 var assertOptimized; |
115 var assertUnoptimized; | 115 var assertUnoptimized; |
116 | 116 |
117 // Assert that a string contains another expected substring. | 117 // Assert that a string contains another expected substring. |
118 var assertContains; | 118 var assertContains; |
119 | 119 |
120 // Assert that a string matches a given regex. | 120 // Assert that a string matches a given regex. |
121 var assertMatches; | 121 var assertMatches; |
122 | 122 |
123 // These bits must be in sync with bits defined in Runtime_GetOptimizationStatus | |
Michael Achenbach
2017/01/26 13:05:18
Please update the fake mjsunit.js used by internal
| |
124 var V8OptimizationStatus = { | |
125 kIsFunction: 1 << 0, | |
126 kNeverOptimize: 1 << 1, | |
127 kAlwaysOptimize: 1 << 2, | |
128 kMaybeDeopted: 1 << 3, | |
129 kOptimized: 1 << 4, | |
130 kTurboFanned: 1 << 5, | |
131 kInterpreted: 1 << 6 | |
132 }; | |
133 | |
134 // Returns true if --no-crankshaft mode is on. | |
135 var isNeverOptimize; | |
136 | |
137 // Returns true if --always-opt mode is on. | |
138 var isAlwaysOptimize; | |
139 | |
140 // Returns true if given function in interpreted. | |
141 var isInterpreted; | |
142 | |
143 // Returns true if given function is compiled by a base-line compiler. | |
144 var isBaselined; | |
145 | |
146 // Returns true if given function is optimized. | |
147 var isOptimized; | |
148 | |
149 // Returns true if given function is compiled by Crankshaft. | |
150 var isCrankshafted; | |
151 | |
152 // Returns true if given function is compiled by TurboFan. | |
153 var isTurboFanned; | |
154 | |
123 | 155 |
124 (function () { // Scope for utility functions. | 156 (function () { // Scope for utility functions. |
125 | 157 |
126 var ObjectPrototypeToString = Object.prototype.toString; | 158 var ObjectPrototypeToString = Object.prototype.toString; |
127 var NumberPrototypeValueOf = Number.prototype.valueOf; | 159 var NumberPrototypeValueOf = Number.prototype.valueOf; |
128 var BooleanPrototypeValueOf = Boolean.prototype.valueOf; | 160 var BooleanPrototypeValueOf = Boolean.prototype.valueOf; |
129 var StringPrototypeValueOf = String.prototype.valueOf; | 161 var StringPrototypeValueOf = String.prototype.valueOf; |
130 var DatePrototypeValueOf = Date.prototype.valueOf; | 162 var DatePrototypeValueOf = Date.prototype.valueOf; |
131 var RegExpPrototypeToString = RegExp.prototype.toString; | 163 var RegExpPrototypeToString = RegExp.prototype.toString; |
132 var ArrayPrototypeMap = Array.prototype.map; | 164 var ArrayPrototypeMap = Array.prototype.map; |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
455 "fun", "sync", "return %GetOptimizationStatus(fun, sync);"); | 487 "fun", "sync", "return %GetOptimizationStatus(fun, sync);"); |
456 } catch (e) { | 488 } catch (e) { |
457 throw new Error("natives syntax not allowed"); | 489 throw new Error("natives syntax not allowed"); |
458 } | 490 } |
459 } | 491 } |
460 return OptimizationStatusImpl(fun, sync_opt); | 492 return OptimizationStatusImpl(fun, sync_opt); |
461 } | 493 } |
462 | 494 |
463 assertUnoptimized = function assertUnoptimized(fun, sync_opt, name_opt) { | 495 assertUnoptimized = function assertUnoptimized(fun, sync_opt, name_opt) { |
464 if (sync_opt === undefined) sync_opt = ""; | 496 if (sync_opt === undefined) sync_opt = ""; |
465 assertTrue(OptimizationStatus(fun, sync_opt) !== 1, name_opt); | 497 var opt_status = OptimizationStatus(fun, sync_opt); |
498 assertTrue((opt_status & V8OptimizationStatus.kIsFunction) !== 0, name_opt); | |
499 assertFalse((opt_status & V8OptimizationStatus.kOptimized) !== 0, name_opt); | |
466 } | 500 } |
467 | 501 |
468 assertOptimized = function assertOptimized(fun, sync_opt, name_opt) { | 502 assertOptimized = function assertOptimized(fun, sync_opt, name_opt) { |
469 if (sync_opt === undefined) sync_opt = ""; | 503 if (sync_opt === undefined) sync_opt = ""; |
470 assertTrue(OptimizationStatus(fun, sync_opt) !== 2, name_opt); | 504 var opt_status = OptimizationStatus(fun, sync_opt); |
505 assertTrue((opt_status & V8OptimizationStatus.kIsFunction) !== 0, name_opt); | |
506 if ((opt_status & V8OptimizationStatus.kNeverOptimize) !== 0) { | |
507 // TODO(ishell): every test that calls %OptimizeFunctionOnNextCall() | |
508 // does not make sense when --no-crankshaft option is provided. | |
509 return; | |
510 } | |
511 assertTrue((opt_status & V8OptimizationStatus.kOptimized) !== 0, name_opt); | |
512 } | |
513 | |
514 isNeverOptimize = function isNeverOptimize() { | |
515 var opt_status = OptimizationStatus(undefined, ""); | |
516 return (opt_status & V8OptimizationStatus.kNeverOptimize) !== 0; | |
517 } | |
518 | |
519 isAlwaysOptimize = function isAlwaysOptimize() { | |
520 var opt_status = OptimizationStatus(undefined, ""); | |
521 return (opt_status & V8OptimizationStatus.kAlwaysOptimize) !== 0; | |
522 } | |
523 | |
524 isInterpreted = function isInterpreted(fun) { | |
525 var opt_status = OptimizationStatus(fun, ""); | |
526 assertTrue((opt_status & V8OptimizationStatus.kIsFunction) !== 0, | |
527 "not a function"); | |
528 return (opt_status & V8OptimizationStatus.kOptimized) === 0 && | |
529 (opt_status & V8OptimizationStatus.kInterpreted) !== 0; | |
530 } | |
531 | |
532 // NOTE: This predicate also returns true for functions that have never | |
533 // been compiled (i.e. that have LazyCompile stub as a code). | |
534 isBaselined = function isBaselined(fun) { | |
535 var opt_status = OptimizationStatus(fun, ""); | |
536 assertTrue((opt_status & V8OptimizationStatus.kIsFunction) !== 0, | |
537 "not a function"); | |
538 return (opt_status & V8OptimizationStatus.kOptimized) === 0 && | |
539 (opt_status & V8OptimizationStatus.kInterpreted) === 0; | |
540 } | |
541 | |
542 isOptimized = function isOptimized(fun) { | |
543 var opt_status = OptimizationStatus(fun, ""); | |
544 assertTrue((opt_status & V8OptimizationStatus.kIsFunction) !== 0, | |
545 "not a function"); | |
546 return (opt_status & V8OptimizationStatus.kOptimized) !== 0; | |
547 } | |
548 | |
549 isCrankshafted = function isCrankshafted(fun) { | |
550 var opt_status = OptimizationStatus(fun, ""); | |
551 assertTrue((opt_status & V8OptimizationStatus.kIsFunction) !== 0, | |
552 "not a function"); | |
553 return (opt_status & V8OptimizationStatus.kOptimized) !== 0 && | |
554 (opt_status & V8OptimizationStatus.kTurboFanned) === 0; | |
555 } | |
556 | |
557 isTurboFanned = function isTurboFanned(fun) { | |
558 var opt_status = OptimizationStatus(fun, ""); | |
559 assertTrue((opt_status & V8OptimizationStatus.kIsFunction) !== 0, | |
560 "not a function"); | |
561 return (opt_status & V8OptimizationStatus.kOptimized) !== 0 && | |
562 (opt_status & V8OptimizationStatus.kTurboFanned) !== 0; | |
471 } | 563 } |
472 | 564 |
473 })(); | 565 })(); |
OLD | NEW |