| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -66,6 +66,8 @@ using CFunctionCallbackWithUint8ArrayUint32Int64Bool = | |||
| 66 | 66 | v8::FastApiCallbackOptions&); | |
| 67 | 67 | using CFunctionWithUint32 = uint32_t (*)(v8::Local<v8::Value>, | |
| 68 | 68 | const uint32_t input); | |
| 69 | + using CFunctionWithReturnUint32 = uint32_t (*)(v8::Local<v8::Value>); | ||
| 70 | + using CFunctionWithReturnDouble = double (*)(v8::Local<v8::Value>); | ||
| 69 | 71 | using CFunctionWithDoubleReturnDouble = double (*)(v8::Local<v8::Value>, | |
| 70 | 72 | v8::Local<v8::Value>, | |
| 71 | 73 | const double); | |
@@ -107,6 +109,7 @@ class ExternalReferenceRegistry { | |||
| 107 | 109 | V(CFunctionCallbackReturnBool) \ | |
| 108 | 110 | V(CFunctionCallbackReturnDouble) \ | |
| 109 | 111 | V(CFunctionCallbackReturnInt32) \ | |
| 112 | + V(CFunctionWithReturnUint32) \ | ||
| 110 | 113 | V(CFunctionCallbackValueReturnDouble) \ | |
| 111 | 114 | V(CFunctionCallbackValueReturnDoubleUnusedReceiver) \ | |
| 112 | 115 | V(CFunctionCallbackWithInt64) \ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -20,6 +20,7 @@ | |||
| 20 | 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. | |
| 21 | 21 | ||
| 22 | 22 | #include "env-inl.h" | |
| 23 | + #include "node_debug.h" | ||
| 23 | 24 | #include "node_external_reference.h" | |
| 24 | 25 | #include "string_bytes.h" | |
| 25 | 26 | ||
@@ -148,12 +149,26 @@ static void GetFreeMemory(const FunctionCallbackInfo<Value>& args) { | |||
| 148 | 149 | args.GetReturnValue().Set(amount); | |
| 149 | 150 | } | |
| 150 | 151 | ||
| 152 | + static double FastGetFreeMemory(Local<Value> receiver) { | ||
| 153 | + TRACK_V8_FAST_API_CALL("os.freemem"); | ||
| 154 | + return static_cast<double>(uv_get_free_memory()); | ||
| 155 | + } | ||
| 156 | + | ||
| 157 | + static v8::CFunction fast_get_free_memory( | ||
| 158 | + v8::CFunction::Make(FastGetFreeMemory)); | ||
| 151 | 159 | ||
| 152 | 160 | static void GetTotalMemory(const FunctionCallbackInfo<Value>& args) { | |
| 153 | 161 | double amount = static_cast<double>(uv_get_total_memory()); | |
| 154 | 162 | args.GetReturnValue().Set(amount); | |
| 155 | 163 | } | |
| 156 | 164 | ||
| 165 | + double FastGetTotalMemory(Local<Value> receiver) { | ||
| 166 | + TRACK_V8_FAST_API_CALL("os.totalmem"); | ||
| 167 | + return static_cast<double>(uv_get_total_memory()); | ||
| 168 | + } | ||
| 169 | + | ||
| 170 | + static v8::CFunction fast_get_total_memory( | ||
| 171 | + v8::CFunction::Make(FastGetTotalMemory)); | ||
| 157 | 172 | ||
| 158 | 173 | static void GetUptime(const FunctionCallbackInfo<Value>& args) { | |
| 159 | 174 | Environment* env = Environment::GetCurrent(args); | |
@@ -398,6 +413,14 @@ static void GetAvailableParallelism(const FunctionCallbackInfo<Value>& args) { | |||
| 398 | 413 | args.GetReturnValue().Set(parallelism); | |
| 399 | 414 | } | |
| 400 | 415 | ||
| 416 | + uint32_t FastGetAvailableParallelism(v8::Local<v8::Value> receiver) { | ||
| 417 | + TRACK_V8_FAST_API_CALL("os.availableParallelism"); | ||
| 418 | + return uv_available_parallelism(); | ||
| 419 | + } | ||
| 420 | + | ||
| 421 | + static v8::CFunction fast_get_available_parallelism( | ||
| 422 | + v8::CFunction::Make(FastGetAvailableParallelism)); | ||
| 423 | + | ||
| 401 | 424 | void Initialize(Local<Object> target, | |
| 402 | 425 | Local<Value> unused, | |
| 403 | 426 | Local<Context> context, | |
@@ -406,16 +429,21 @@ void Initialize(Local<Object> target, | |||
| 406 | 429 | SetMethod(context, target, "getHostname", GetHostname); | |
| 407 | 430 | SetMethod(context, target, "getLoadAvg", GetLoadAvg); | |
| 408 | 431 | SetMethod(context, target, "getUptime", GetUptime); | |
| 409 | - SetMethod(context, target, "getTotalMem", GetTotalMemory); | ||
| 410 | - SetMethod(context, target, "getFreeMem", GetFreeMemory); | ||
| 432 | + SetFastMethodNoSideEffect( | ||
| 433 | + context, target, "getTotalMem", GetTotalMemory, &fast_get_total_memory); | ||
| 434 | + SetFastMethodNoSideEffect( | ||
| 435 | + context, target, "getFreeMem", GetFreeMemory, &fast_get_free_memory); | ||
| 411 | 436 | SetMethod(context, target, "getCPUs", GetCPUInfo); | |
| 412 | 437 | SetMethod(context, target, "getInterfaceAddresses", GetInterfaceAddresses); | |
| 413 | 438 | SetMethod(context, target, "getHomeDirectory", GetHomeDirectory); | |
| 414 | 439 | SetMethod(context, target, "getUserInfo", GetUserInfo); | |
| 415 | 440 | SetMethod(context, target, "setPriority", SetPriority); | |
| 416 | 441 | SetMethod(context, target, "getPriority", GetPriority); | |
| 417 | - SetMethod( | ||
| 418 | - context, target, "getAvailableParallelism", GetAvailableParallelism); | ||
| 442 | + SetFastMethodNoSideEffect(context, | ||
| 443 | + target, | ||
| 444 | + "getAvailableParallelism", | ||
| 445 | + GetAvailableParallelism, | ||
| 446 | + &fast_get_available_parallelism); | ||
| 419 | 447 | SetMethod(context, target, "getOSInformation", GetOSInformation); | |
| 420 | 448 | target | |
| 421 | 449 | ->Set(context, | |
@@ -429,14 +457,20 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) { | |||
| 429 | 457 | registry->Register(GetLoadAvg); | |
| 430 | 458 | registry->Register(GetUptime); | |
| 431 | 459 | registry->Register(GetTotalMemory); | |
| 460 | + registry->Register(FastGetTotalMemory); | ||
| 461 | + registry->Register(fast_get_total_memory.GetTypeInfo()); | ||
| 432 | 462 | registry->Register(GetFreeMemory); | |
| 463 | + registry->Register(FastGetFreeMemory); | ||
| 464 | + registry->Register(fast_get_free_memory.GetTypeInfo()); | ||
| 433 | 465 | registry->Register(GetCPUInfo); | |
| 434 | 466 | registry->Register(GetInterfaceAddresses); | |
| 435 | 467 | registry->Register(GetHomeDirectory); | |
| 436 | 468 | registry->Register(GetUserInfo); | |
| 437 | 469 | registry->Register(SetPriority); | |
| 438 | 470 | registry->Register(GetPriority); | |
| 439 | 471 | registry->Register(GetAvailableParallelism); | |
| 472 | + registry->Register(FastGetAvailableParallelism); | ||
| 473 | + registry->Register(fast_get_available_parallelism.GetTypeInfo()); | ||
| 440 | 474 | registry->Register(GetOSInformation); | |
| 441 | 475 | } | |
| 442 | 476 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,30 @@ | |||
| 1 | + // Flags: --expose-internals --no-warnings --allow-natives-syntax | ||
| 2 | + 'use strict'; | ||
| 3 | + | ||
| 4 | + const common = require('../common'); | ||
| 5 | + const assert = require('assert'); | ||
| 6 | + const { | ||
| 7 | + totalmem, | ||
| 8 | + freemem, | ||
| 9 | + availableParallelism, | ||
| 10 | + } = require('os'); | ||
| 11 | + | ||
| 12 | + const { internalBinding } = require('internal/test/binding'); | ||
| 13 | + | ||
| 14 | + function testFastOs() { | ||
| 15 | + assert.strictEqual(typeof totalmem(), 'number'); | ||
| 16 | + assert.strictEqual(typeof freemem(), 'number'); | ||
| 17 | + assert.strictEqual(typeof availableParallelism(), 'number'); | ||
| 18 | + } | ||
| 19 | + | ||
| 20 | + eval('%PrepareFunctionForOptimization(testFastOs)'); | ||
| 21 | + testFastOs(); | ||
| 22 | + eval('%OptimizeFunctionOnNextCall(testFastOs)'); | ||
| 23 | + testFastOs(); | ||
| 24 | + | ||
| 25 | + if (common.isDebug) { | ||
| 26 | + const { getV8FastApiCallCount } = internalBinding('debug'); | ||
| 27 | + assert.strictEqual(getV8FastApiCallCount('os.totalmem'), 1); | ||
| 28 | + assert.strictEqual(getV8FastApiCallCount('os.freemem'), 1); | ||
| 29 | + assert.strictEqual(getV8FastApiCallCount('os.availableParallelism'), 1); | ||
| 30 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments