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 | |
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 // Tests that use assertOptimized() do not make sense if --always-opt | |
499 // option is provided. Such tests must add --no-always-opt to flags comment. | |
500 assertFalse((opt_status & V8OptimizationStatus.kAlwaysOptimize) !== 0, | |
501 "test does not make sense with --always-opt"); | |
502 assertTrue((opt_status & V8OptimizationStatus.kIsFunction) !== 0, name_opt); | |
503 assertFalse((opt_status & V8OptimizationStatus.kOptimized) !== 0, name_opt); | |
466 } | 504 } |
467 | 505 |
468 assertOptimized = function assertOptimized(fun, sync_opt, name_opt) { | 506 assertOptimized = function assertOptimized(fun, sync_opt, name_opt) { |
469 if (sync_opt === undefined) sync_opt = ""; | 507 if (sync_opt === undefined) sync_opt = ""; |
470 assertTrue(OptimizationStatus(fun, sync_opt) !== 2, name_opt); | 508 var opt_status = OptimizationStatus(fun, sync_opt); |
509 // Tests that use assertOptimized() do not make sense if --no-crankshaft | |
510 // option is provided. Such tests must add --crankshaft to flags comment. | |
511 assertFalse((opt_status & V8OptimizationStatus.kNeverOptimize) !== 0, | |
512 "test does not make sense with --no-crankshaft"); | |
513 assertTrue((opt_status & V8OptimizationStatus.kIsFunction) !== 0, name_opt); | |
514 if ((opt_status & V8OptimizationStatus.kMaybeDeopted) !== 0) { | |
Igor Sheludko
2017/01/27 09:33:06
This case is new.
Michael Starzinger
2017/01/27 10:10:24
Acknowledged.
| |
515 // When --deopt-every-n-times flag is specified it's no longer guaranteed | |
516 // that particular function is still optimized, so keep running the test | |
517 // to stress test the deoptimizer. | |
518 return; | |
519 } | |
520 assertTrue((opt_status & V8OptimizationStatus.kOptimized) !== 0, name_opt); | |
521 } | |
522 | |
523 isNeverOptimize = function isNeverOptimize() { | |
524 var opt_status = OptimizationStatus(undefined, ""); | |
525 return (opt_status & V8OptimizationStatus.kNeverOptimize) !== 0; | |
526 } | |
527 | |
528 isAlwaysOptimize = function isAlwaysOptimize() { | |
529 var opt_status = OptimizationStatus(undefined, ""); | |
530 return (opt_status & V8OptimizationStatus.kAlwaysOptimize) !== 0; | |
531 } | |
532 | |
533 isInterpreted = function isInterpreted(fun) { | |
534 var opt_status = OptimizationStatus(fun, ""); | |
535 assertTrue((opt_status & V8OptimizationStatus.kIsFunction) !== 0, | |
536 "not a function"); | |
537 return (opt_status & V8OptimizationStatus.kOptimized) === 0 && | |
538 (opt_status & V8OptimizationStatus.kInterpreted) !== 0; | |
539 } | |
540 | |
541 // NOTE: This predicate also returns true for functions that have never | |
542 // been compiled (i.e. that have LazyCompile stub as a code). | |
543 isBaselined = function isBaselined(fun) { | |
544 var opt_status = OptimizationStatus(fun, ""); | |
545 assertTrue((opt_status & V8OptimizationStatus.kIsFunction) !== 0, | |
546 "not a function"); | |
547 return (opt_status & V8OptimizationStatus.kOptimized) === 0 && | |
548 (opt_status & V8OptimizationStatus.kInterpreted) === 0; | |
549 } | |
550 | |
551 isOptimized = function isOptimized(fun) { | |
552 var opt_status = OptimizationStatus(fun, ""); | |
553 assertTrue((opt_status & V8OptimizationStatus.kIsFunction) !== 0, | |
554 "not a function"); | |
555 return (opt_status & V8OptimizationStatus.kOptimized) !== 0; | |
556 } | |
557 | |
558 isCrankshafted = function isCrankshafted(fun) { | |
559 var opt_status = OptimizationStatus(fun, ""); | |
560 assertTrue((opt_status & V8OptimizationStatus.kIsFunction) !== 0, | |
561 "not a function"); | |
562 return (opt_status & V8OptimizationStatus.kOptimized) !== 0 && | |
563 (opt_status & V8OptimizationStatus.kTurboFanned) === 0; | |
564 } | |
565 | |
566 isTurboFanned = function isTurboFanned(fun) { | |
567 var opt_status = OptimizationStatus(fun, ""); | |
568 assertTrue((opt_status & V8OptimizationStatus.kIsFunction) !== 0, | |
569 "not a function"); | |
570 return (opt_status & V8OptimizationStatus.kOptimized) !== 0 && | |
571 (opt_status & V8OptimizationStatus.kTurboFanned) !== 0; | |
471 } | 572 } |
472 | 573 |
473 })(); | 574 })(); |
OLD | NEW |