Changeset 224938 in webkit for trunk/Source/JavaScriptCore/tools
- Timestamp:
- Nov 16, 2017, 3:44:12 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/tools/JSDollarVM.cpp
r224838 r224938 29 29 #include "CodeBlock.h" 30 30 #include "FunctionCodeBlock.h" 31 #include "JSArrayBuffer.h" 31 32 #include "JSCInlines.h" 32 33 #include "VMInspector.h" 34 #include <wtf/Atomics.h> 33 35 #include <wtf/DataLog.h> 34 36 #include <wtf/ProcessID.h> … … 58 60 { 59 61 return JSValue::encode(jsBoolean(false)); 62 } 63 64 static EncodedJSValue JSC_HOST_CALL functionCpuMfence(ExecState*) 65 { 66 #if CPU(X86_64) && !OS(WINDOWS) 67 asm volatile("mfence" ::: "memory"); 68 #endif 69 return JSValue::encode(jsUndefined()); 70 } 71 72 static EncodedJSValue JSC_HOST_CALL functionCpuRdtsc(ExecState*) 73 { 74 #if CPU(X86_64) && !OS(WINDOWS) 75 unsigned high; 76 unsigned low; 77 asm volatile ("rdtsc" : "=a"(low), "=d"(high)); 78 return JSValue::encode(jsNumber(low)); 79 #else 80 return JSValue::encode(jsNumber(0)); 81 #endif 82 } 83 84 static EncodedJSValue JSC_HOST_CALL functionCpuCpuid(ExecState*) 85 { 86 #if CPU(X86_64) && !OS(WINDOWS) 87 WTF::x86_cpuid(); 88 #endif 89 return JSValue::encode(jsUndefined()); 90 } 91 92 static EncodedJSValue JSC_HOST_CALL functionCpuPause(ExecState*) 93 { 94 #if CPU(X86_64) && !OS(WINDOWS) 95 asm volatile ("pause" ::: "memory"); 96 #endif 97 return JSValue::encode(jsUndefined()); 98 } 99 100 // This takes either a JSArrayBuffer, JSArrayBufferView*, or any other object as its first 101 // argument. The second argument is expected to be an integer. 102 // 103 // If the first argument is a JSArrayBuffer, it'll clflush on that buffer 104 // plus the second argument as a byte offset. It'll also flush on the object 105 // itself so its length, etc, aren't in the cache. 106 // 107 // If the first argument is not a JSArrayBuffer, we load the butterfly 108 // and clflush at the address of the butterfly. 109 static EncodedJSValue JSC_HOST_CALL functionCpuClflush(ExecState* exec) 110 { 111 #if CPU(X86_64) && !OS(WINDOWS) 112 VM& vm = exec->vm(); 113 114 if (!exec->argument(1).isInt32()) 115 return JSValue::encode(jsBoolean(false)); 116 117 auto clflush = [] (void* ptr) { 118 char* ptrToFlush = static_cast<char*>(ptr); 119 asm volatile ("clflush %0" :: "m"(*ptrToFlush) : "memory"); 120 }; 121 122 uint32_t offset = exec->argument(1).asUInt32(); 123 124 char* ptr = nullptr; 125 if (JSArrayBuffer* buffer = jsDynamicCast<JSArrayBuffer*>(vm, exec->argument(0))) { 126 if (ArrayBuffer* impl = buffer->impl()) { 127 if (offset < impl->byteLength()) { 128 clflush(impl); 129 ptr = bitwise_cast<char*>(impl) + offset; 130 } 131 } 132 } else if (JSArrayBufferView* view = jsDynamicCast<JSArrayBufferView*>(vm, exec->argument(0))) 133 ptr = bitwise_cast<char*>(view); 134 else if (JSObject* object = jsDynamicCast<JSObject*>(vm, exec->argument(0))) { 135 switch (object->indexingType()) { 136 case ALL_INT32_INDEXING_TYPES: 137 case ALL_CONTIGUOUS_INDEXING_TYPES: 138 case ALL_DOUBLE_INDEXING_TYPES: 139 clflush(object); 140 ptr = bitwise_cast<char*>(object->butterfly()) + offset; 141 } 142 } 143 144 if (!ptr) 145 return JSValue::encode(jsBoolean(false)); 146 147 clflush(ptr); 148 return JSValue::encode(jsBoolean(true)); 149 #else 150 UNUSED_PARAM(exec); 151 return JSValue::encode(jsBoolean(false)); 152 #endif 60 153 } 61 154 … … 271 364 272 365 putDirectNativeFunction(vm, globalObject, Identifier::fromString(&vm, "dfgTrue"), 0, functionDFGTrue, DFGTrueIntrinsic, static_cast<unsigned>(PropertyAttribute::DontEnum)); 366 367 putDirectNativeFunction(vm, globalObject, Identifier::fromString(&vm, "cpuMfence"), 0, functionCpuMfence, CPUMfenceIntrinsic, 0); 368 putDirectNativeFunction(vm, globalObject, Identifier::fromString(&vm, "cpuRdtsc"), 0, functionCpuRdtsc, CPURdtscIntrinsic, 0); 369 putDirectNativeFunction(vm, globalObject, Identifier::fromString(&vm, "cpuCpuid"), 0, functionCpuCpuid, CPUCpuidIntrinsic, 0); 370 putDirectNativeFunction(vm, globalObject, Identifier::fromString(&vm, "cpuPause"), 0, functionCpuPause, CPUPauseIntrinsic, 0); 371 addFunction(vm, globalObject, "cpuClflush", functionCpuClflush, 2); 273 372 274 373 addFunction(vm, globalObject, "llintTrue", functionLLintTrue, 0);
Note:
See TracChangeset
for help on using the changeset viewer.