upgrade vendored vs-natives

This commit is contained in:
Matthew Griffith 2021-07-03 11:12:03 -04:00
parent ca7475f7c9
commit bba5d5314c
7 changed files with 43 additions and 285 deletions

View File

@ -1,6 +1,6 @@
/*
--------------------------------------
(c)2014-2019, Nathanael Anderson.
(c)2014-2021, Nathanael Anderson.
Repository: https://github.com/Nathanaela/v8-Natives
--------------------------------------
v8-Natives is under The MIT License (MIT)
@ -30,9 +30,9 @@
(function (_global) {
function testIfAllowNativeSyntax() {
var native = false;
let native = false;
try {
eval('%GetHeapUsage();');
eval('%CollectGarbage(null);');
native = true;
}
catch (err) {
@ -47,11 +47,11 @@
function printStatus(fn, fName) {
if (v8.isNative() === false) return -1;
var optStatus = v8.getOptimizationStatus(fn);
let optStatus = v8.getOptimizationStatus(fn);
if (fName == null || fName === '') {
fName = v8.functionGetName(fn);
}
var optStat = [];
let optStat = [];
if (checkBitmap(optStatus,1)) {
optStat.push("is Function");
}
@ -102,7 +102,7 @@
}
function testIsDebugging() {
var _test = function() { return true; };
const _test = function() { return true; };
_test();
try {
v8.optimizeFunctionOnNextCall(_test);
@ -110,7 +110,7 @@
return true
}
_test();
var res = v8.getOptimizationStatus(_test);
const res = v8.getOptimizationStatus(_test);
return !((res & 16) === 16);
}
@ -124,11 +124,11 @@
if (Array.isArray(f)) {
f[0]();
for (var i = 0; i < f.length; i++) {
for (let i = 0; i < f.length; i++) {
v8.optimizeFunctionOnNextCall(f[i]);
}
f[0]();
for (var j = 0; j < f.length; j++) {
for (let j = 0; j < f.length; j++) {
printStatus(f[j], fname[j]);
}
} else {
@ -141,7 +141,7 @@
function benchmark(count, f, params) {
if (v8.isNative() === false || f === null || count < 1) return -1;
var cnt = parseInt(count, 10);
const cnt = parseInt(count, 10);
if (typeof params === 'undefined') {
// Prime both Functions for Optimization
benchmarkNoParams(1, f);
@ -174,7 +174,7 @@
}
function benchmarkParams(itter, f, params) {
var startTime, i = 0;
let startTime, i = 0;
v8.collectGarbage();
startTime = performance.now();
for (; i < itter; ++i) f(params);
@ -182,7 +182,7 @@
}
function benchmarkNoParams(itter, f) {
var startTime, i = 0;
let startTime, i = 0;
v8.collectGarbage();
startTime = performance.now();
for (; i < itter; ++i) f();
@ -192,8 +192,8 @@
if (testIfAllowNativeSyntax()) {
console.log("Using native");
var v8 = _global.v8 = new Function('"use strict";\
// v8 Functions are located in v8/lib/runtime.cc & runtime.h\
let v8 = _global.v8 = new Function('"use strict";\
// v8 Functions are located in v8/src/runtime/runtime.cc & runtime.h\
// SMI = SMall Integer\n\
\
return {\
@ -223,7 +223,8 @@
return %CollectGarbage(null);\
},\
getHeapUsage: function() {\
return %GetHeapUsage();\
console.log("This command no longer works, in a browser please use: window.performance.memory (with the --enable-precise-memory-info flag).");\
return 0\
},\
hasFastProperties: function(data) {\
return %HasFastProperties(data);\
@ -295,7 +296,7 @@
console.warn("v8 engine is not running with --allow-natives-syntax; Native v8 functions are not available and will be shimmed with dummies.");
}
var v8 = _global.v8 = {
let v8 = _global.v8 = {
isNative: function () {
return false;
}
@ -322,4 +323,4 @@
_global.v8.helpers = {printStatus: printStatus, testOptimization: testOptimization, benchmark: benchmark};
}(typeof exports === 'undefined' ? this : exports));
}(typeof exports === 'undefined' ? this : exports));

View File

@ -1,6 +1,6 @@
/*
--------------------------------------
(c)2014-2019, Nathanael Anderson.
(c)2014-2021, Nathanael Anderson.
Repository: https://github.com/Nathanaela/v8-Natives
--------------------------------------
v8-Natives is under The MIT License (MIT)
@ -31,9 +31,9 @@
(function (_global) {
function testIfAllowNativeSyntax() {
var native = false;
let native = false;
try {
eval('%GetHeapUsage();');
eval('%CollectGarbage(null);');
native = true;
}
catch (err) {
@ -43,12 +43,12 @@
}
function loadScript(file, cb) {
var src = document.currentScript.src, path="";
var idx = src.lastIndexOf('/');
let src = document.currentScript.src, path="";
let idx = src.lastIndexOf('/');
if (idx >= 0) path = src.substring(0, idx+1);
var newScript = document.createElement('script');
var existingScript = document.getElementsByTagName('script')[0];
let newScript = document.createElement('script');
let existingScript = document.getElementsByTagName('script')[0];
newScript.src = path+file;
newScript.onload = cb;
existingScript.parentNode.insertBefore(newScript, existingScript);
@ -60,11 +60,11 @@
function printStatus(fn, fName) {
if (v8.isNative() === false) return -1;
var optStatus = v8.getOptimizationStatus(fn);
let optStatus = v8.getOptimizationStatus(fn);
if (fName == null || fName === '') {
fName = v8.functionGetName(fn);
}
var optStat = [];
let optStat = [];
if (checkBitmap(optStatus,1)) {
optStat.push("is Function");
}
@ -115,7 +115,7 @@
}
function testIsDebugging() {
var _test = function() { return true; };
let _test = function() { return true; };
_test();
_test(); // Have to Run this Twice now in v8 (See notes above)
try {
@ -124,7 +124,7 @@
return true
}
_test();
var res = v8.getOptimizationStatus(_test);
let res = v8.getOptimizationStatus(_test);
return !((res & 16) === 16);
}
@ -137,14 +137,14 @@
}
if (Array.isArray(f)) {
for (var i = 0; i < f.length; i++) {
for (let i = 0; i < f.length; i++) {
v8.optimizeFunctionOnNextCall(f[i]);
v8.CompileOptimized(f[i], true);
}
try {
f[0]();
} catch (e) {}
for (var j = 0; j < f.length; j++) {
for (let j = 0; j < f.length; j++) {
printStatus(f[j], fname[j]);
}
} else {
@ -159,7 +159,7 @@
function benchmark(count, f, params) {
if (v8.isNative() === false || f === null || count < 1) return -1;
var cnt = parseInt(count, 10);
let cnt = parseInt(count, 10);
if (typeof params === 'undefined') {
// Prime both Functions for Optimization
benchmarkNoParams(1, f);
@ -194,7 +194,7 @@
}
function benchmarkParams(itter, f, params) {
var startTime, i = 0;
let startTime, i = 0;
v8.collectGarbage();
startTime = performance.now();
for (; i < itter; ++i) f(params);
@ -202,7 +202,7 @@
}
function benchmarkNoParams(itter, f) {
var startTime, i = 0;
let startTime, i = 0;
v8.collectGarbage();
startTime = performance.now();
for (; i < itter; ++i) f();
@ -231,4 +231,4 @@
// Add this helper function
_global.waitForV8 = waitForV8;
}(typeof exports === 'undefined' ? this : exports));
}(typeof exports === 'undefined' ? this : exports));

View File

@ -1,6 +1,6 @@
/*
--------------------------------------
(c)2014-2019, Nathanael Anderson.
(c)2014-2021, Nathanael Anderson.
Repository: https://github.com/Nathanaela/v8-Natives
--------------------------------------
v8-Natives is under The MIT License (MIT)
@ -32,7 +32,7 @@
"use strict";
// v8 Functions are located in v8/lib/runtime.cc & runtime.h
// v8 Functions are located in v8/src/runtime/runtime.cc & runtime.h
// SMI = SMall Integer
_global.v8 = {
@ -62,7 +62,8 @@ _global.v8 = {
return %CollectGarbage(null);
},
getHeapUsage: function() {
return %GetHeapUsage();
console.log("This command no longer works, in a browser please use: window.performance.memory (with the --enable-precise-memory-info flag), if using node: process.memoryUsage();");
return 0;
},
hasFastProperties: function(data) {
return %HasFastProperties(data);
@ -122,4 +123,4 @@ _global.v8 = {
};
}(typeof exports === 'undefined' ? this : exports));
}(typeof exports === 'undefined' ? this : exports));

View File

@ -1,6 +1,6 @@
/*
--------------------------------------
(c)2014-2017, Nathanael Anderson.
(c)2014-2021, Nathanael Anderson.
Repository: https://github.com/Nathanaela/v8-Natives
--------------------------------------
v8-Natives is under The MIT License (MIT)
@ -61,4 +61,3 @@ _global.v8 = v8;
}(typeof exports === 'undefined' ? this : exports));

View File

@ -1,6 +1,6 @@
/*
--------------------------------------
(c)2014-2019, Nathanael Anderson.
(c)2014-2021, Nathanael Anderson.
Repository: https://github.com/Nathanaela/v8-Natives
--------------------------------------
v8-Natives is under The MIT License (MIT)
@ -223,4 +223,3 @@ v8.helpers = {printStatus: printStatus, testOptimization: testOptimization, benc
module.exports = v8;

View File

@ -1,242 +0,0 @@
/*
--------------------------------------
(c)2014-2019, Nathanael Anderson.
Repository: https://github.com/Nathanaela/v8-Natives
--------------------------------------
v8-Natives is under The MIT License (MIT)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
// Notes:
// The reason we are calling the functions twice before running optimizeFunctionOnNextCall, is
// because 2 calls are needed to go from uninitialized -> pre-monomorphic -> monomorphic
(function (_global) {
function testIfAllowNativeSyntax() {
var native = false;
try {
eval('%GetHeapUsage();');
native = true;
} catch (err) {
native = false;
}
return native;
}
function loadScript(file, cb) {
var src = document.currentScript.src,
path = '';
var idx = src.lastIndexOf('/');
if (idx >= 0) path = src.substring(0, idx + 1);
var newScript = document.createElement('script');
var existingScript = document.getElementsByTagName('script')[0];
newScript.src = path + file;
newScript.onload = cb;
existingScript.parentNode.insertBefore(newScript, existingScript);
}
function checkBitmap(value, bit) {
return (value & bit) === bit;
}
function printStatus(fn, fName) {
if (v8.isNative() === false) return -1;
var optStatus = v8.getOptimizationStatus(fn);
if (fName == null || fName === '') {
fName = v8.functionGetName(fn);
}
var optStat = [];
if (checkBitmap(optStatus, 1)) {
optStat.push('is Function');
}
if (checkBitmap(optStatus, 2)) {
optStat.push('Never Optimized');
}
if (checkBitmap(optStatus, 4)) {
optStat.push('Always Optimized');
}
if (checkBitmap(optStatus, 8)) {
optStat.push('Maybe Deopted');
}
if (checkBitmap(optStatus, 16)) {
optStat.push('Optimized');
}
if (checkBitmap(optStatus, 32)) {
optStat.push('TurboFanned');
}
if (checkBitmap(optStatus, 64)) {
optStat.push('Interpreted');
}
if (checkBitmap(optStatus, 128)) {
optStat.push('Marked for Optimization');
}
if (checkBitmap(optStatus, 256)) {
optStat.push('Marked for Concurrent Optimization');
}
if (checkBitmap(optStatus, 512)) {
optStat.push('Concurrently Optimizing');
}
if (checkBitmap(optStatus, 1024)) {
optStat.push('Is Executing');
}
if (checkBitmap(optStatus, 2048)) {
optStat.push('Topmost frame is Turbo Fanned');
}
if (checkBitmap(optStatus, 4096)) {
optStat.push('Lite Mode');
}
if (checkBitmap(optStatus, 8192)) {
optStat.push('Marked for de-optimization');
}
console.log('', fName, optStat.join(', '));
return optStatus;
}
function testIsDebugging() {
var _test = function () {
return true;
};
_test();
_test(); // Have to Run this Twice now in v8 (See notes above)
try {
v8.optimizeFunctionOnNextCall(_test);
} catch (e) {
return true;
}
_test();
var res = v8.getOptimizationStatus(_test);
return !((res & 16) === 16);
}
function testOptimization(f, fname) {
if (v8.isNative() === false) return -1;
if (testIsDebugging()) {
if (console && console.warn)
console.warn(
'Debug Console is open, please close Debug Console to run Tests!'
);
return -1;
}
if (Array.isArray(f)) {
for (var i = 0; i < f.length; i++) {
v8.optimizeFunctionOnNextCall(f[i]);
v8.CompileOptimized(f[i], true);
}
try {
f[0]();
} catch (e) {}
for (var j = 0; j < f.length; j++) {
printStatus(f[j], fname[j]);
}
} else {
v8.optimizeFunctionOnNextCall(f);
v8.CompileOptimized(f, true);
try {
f();
} catch (e) {}
printStatus(f, fname);
}
}
function benchmark(count, f, params) {
if (v8.isNative() === false || f === null || count < 1) return -1;
var cnt = parseInt(count, 10);
if (typeof params === 'undefined') {
// Prime both Functions for Optimization
benchmarkNoParams(1, f);
benchmarkNoParams(1, f); // Have to Run this Twice now in v8 (See notes above)
// Have the V8 engine tag them for optimization
v8.optimizeFunctionOnNextCall(f);
v8.optimizeFunctionOnNextCall(benchmarkNoParams);
// Have the V8 Engine actually do the optimization
benchmarkNoParams(1, f);
// Prime the Engine so that it can do the benchmark as fast as possible
benchmarkNoParams(cnt, f);
// Run the benchmark and return the time
return benchmarkNoParams(cnt, f);
} else {
// Prime both Functions for Optimization
benchmarkParams(1, f, params);
benchmarkParams(1, f, params); // Have to Run this Twice now in v8 (See notes above)
// Have the V8 engine tag them for optimization
v8.optimizeFunctionOnNextCall(f);
v8.optimizeFunctionOnNextCall(benchmarkParams);
// Have the V8 Engine actually do the optimization
benchmarkParams(1, f, params);
// Prime the Engine so that it can do the benchmark as fast as possible
benchmarkParams(cnt, f, params);
// Run the benchmark and return the time
return benchmarkParams(cnt, f, params);
}
}
function benchmarkParams(itter, f, params) {
var startTime,
i = 0;
v8.collectGarbage();
startTime = performance.now();
for (; i < itter; ++i) f(params);
return performance.now() - startTime;
}
function benchmarkNoParams(itter, f) {
var startTime,
i = 0;
v8.collectGarbage();
startTime = performance.now();
for (; i < itter; ++i) f();
return performance.now() - startTime;
}
function finishSetup() {
_global.v8.helpers = {
printStatus: printStatus,
testOptimization: testOptimization,
benchmark: benchmark,
};
}
function waitForV8(cb) {
// Simple Hack to make sure we have the V8 namespace...
if (typeof _global.v8 === 'undefined') {
setTimeout(waitForV8, 100, cb);
return;
}
cb();
}
if (testIfAllowNativeSyntax()) {
loadScript('v8-native-calls.js', finishSetup);
} else {
loadScript('v8-native-dummy.js', finishSetup);
}
// Add this helper function
_global.waitForV8 = waitForV8;
})(typeof exports === 'undefined' ? this : exports);

View File

@ -18,6 +18,6 @@
});
}
</script>
<script src="output/v8.js" onload="waitForV8(start)"></script>
<script src="output/v8-browser.js" onload="waitForV8(start)"></script>
</body>
</html>