本文整理汇总了C++中AsmJSModule类的典型用法代码示例。如果您正苦于以下问题:C++ AsmJSModule类的具体用法?C++ AsmJSModule怎么用?C++ AsmJSModule使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AsmJSModule类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LinkModuleToHeap
static bool
LinkModuleToHeap(JSContext *cx, AsmJSModule &module, Handle<ArrayBufferObject*> heap)
{
if (!IsValidAsmJSHeapLength(heap->byteLength())) {
ScopedJSFreePtr<char> msg(
JS_smprintf("ArrayBuffer byteLength 0x%x is not a valid heap length. The next "
"valid length is 0x%x",
heap->byteLength(),
RoundUpToNextValidAsmJSHeapLength(heap->byteLength())));
return LinkFail(cx, msg.get());
}
// This check is sufficient without considering the size of the loaded datum because heap
// loads and stores start on an aligned boundary and the heap byteLength has larger alignment.
JS_ASSERT((module.minHeapLength() - 1) <= INT32_MAX);
if (heap->byteLength() < module.minHeapLength()) {
ScopedJSFreePtr<char> msg(
JS_smprintf("ArrayBuffer byteLength of 0x%x is less than 0x%x (which is the"
"largest constant heap access offset rounded up to the next valid "
"heap size).",
heap->byteLength(),
module.minHeapLength()));
return LinkFail(cx, msg.get());
}
if (!ArrayBufferObject::prepareForAsmJS(cx, heap))
return LinkFail(cx, "Unable to prepare ArrayBuffer for asm.js use");
module.initHeap(heap, cx);
return true;
}
示例2: Activation
AsmJSActivation::AsmJSActivation(JSContext *cx, AsmJSModule &module)
: Activation(cx, AsmJS),
module_(module),
entrySP_(nullptr),
profiler_(nullptr),
resumePC_(nullptr),
fp_(nullptr),
exitReason_(AsmJSExit::None)
{
(void) entrySP_; // squelch GCC warning
// NB: this is a hack and can be removed once Ion switches over to
// JS::ProfilingFrameIterator.
if (cx->runtime()->spsProfiler.enabled()) {
profiler_ = &cx->runtime()->spsProfiler;
profiler_->enterAsmJS("asm.js code :0", this);
}
prevAsmJSForModule_ = module.activation();
module.activation() = this;
prevAsmJS_ = cx->mainThread().asmJSActivationStack_;
cx->mainThread().asmJSActivationStack_ = this;
// Now that the AsmJSActivation is fully initialized, make it visible to
// asynchronous profiling.
registerProfiling();
}
示例3: SendFunctionsToPerf
static bool
SendFunctionsToPerf(JSContext *cx, AsmJSModule &module)
{
if (!PerfFuncEnabled())
return true;
uintptr_t base = (uintptr_t) module.codeBase();
const char *filename = module.scriptSource()->filename();
for (unsigned i = 0; i < module.numPerfFunctions(); i++) {
const AsmJSModule::ProfiledFunction &func = module.perfProfiledFunction(i);
uintptr_t start = base + (unsigned long) func.startCodeOffset;
uintptr_t end = base + (unsigned long) func.endCodeOffset;
JS_ASSERT(end >= start);
size_t size = end - start;
JSAutoByteString bytes;
const char *name = AtomToPrintableString(cx, func.name, &bytes);
if (!name)
return false;
writePerfSpewerAsmJSFunctionMap(start, size, filename, func.lineno, func.columnIndex, name);
}
return true;
}
示例4: lock
AsmJSActivation::AsmJSActivation(JSContext *cx, AsmJSModule &module)
: Activation(cx, AsmJS),
module_(module),
errorRejoinSP_(nullptr),
profiler_(nullptr),
resumePC_(nullptr),
fp_(nullptr),
exitReason_(AsmJSExit::None)
{
if (cx->runtime()->spsProfiler.enabled()) {
// Use a profiler string that matches jsMatch regex in
// browser/devtools/profiler/cleopatra/js/parserWorker.js.
// (For now use a single static string to avoid further slowing down
// calls into asm.js.)
profiler_ = &cx->runtime()->spsProfiler;
profiler_->enterAsmJS("asm.js code :0", this);
}
prevAsmJSForModule_ = module.activation();
module.activation() = this;
prevAsmJS_ = cx->mainThread().asmJSActivationStack_;
JSRuntime::AutoLockForInterrupt lock(cx->runtime());
cx->mainThread().asmJSActivationStack_ = this;
(void) errorRejoinSP_; // squelch GCC warning
}
示例5: SendBlocksToPerf
static bool
SendBlocksToPerf(JSContext *cx, AsmJSModule &module)
{
if (!PerfBlockEnabled())
return true;
unsigned long funcBaseAddress = (unsigned long) module.codeBase();
const char *filename = module.scriptSource()->filename();
for (unsigned i = 0; i < module.numPerfBlocksFunctions(); i++) {
const AsmJSModule::ProfiledBlocksFunction &func = module.perfProfiledBlocksFunction(i);
size_t size = func.endCodeOffset - func.startCodeOffset;
JSAutoByteString bytes;
const char *name = AtomToPrintableString(cx, func.name, &bytes);
if (!name)
return false;
writePerfSpewerAsmJSBlocksMap(funcBaseAddress, func.startCodeOffset,
func.endInlineCodeOffset, size, filename, name, func.blocks);
}
return true;
}
示例6: SendBlocksToPerf
static bool
SendBlocksToPerf(JSContext *cx, AsmJSModule &module)
{
if (!PerfBlockEnabled())
return true;
AsmJSPerfSpewer spewer;
unsigned long funcBaseAddress = (unsigned long) module.functionCode();
const AsmJSModule::PostLinkFailureInfo &info = module.postLinkFailureInfo();
const char *filename = const_cast<char *>(info.scriptSource->filename());
for (unsigned i = 0; i < module.numPerfBlocksFunctions(); i++) {
const AsmJSModule::ProfiledBlocksFunction &func = module.perfProfiledBlocksFunction(i);
unsigned long size = (unsigned long)func.endCodeOffset - (unsigned long)func.startCodeOffset;
JSAutoByteString bytes;
const char *method_name = AtomToPrintableString(cx, func.name, &bytes);
if (!method_name)
return false;
spewer.writeBlocksMap(funcBaseAddress, func.startCodeOffset, size, filename, method_name, func.blocks);
}
return true;
}
示例7: SendFunctionsToPerf
static bool
SendFunctionsToPerf(JSContext *cx, AsmJSModule &module)
{
if (!PerfFuncEnabled())
return true;
AsmJSPerfSpewer perfSpewer;
unsigned long base = (unsigned long) module.functionCode();
const AsmJSModule::PostLinkFailureInfo &info = module.postLinkFailureInfo();
const char *filename = const_cast<char *>(info.scriptSource->filename());
for (unsigned i = 0; i < module.numPerfFunctions(); i++) {
const AsmJSModule::ProfiledFunction &func = module.perfProfiledFunction(i);
unsigned long start = base + (unsigned long) func.startCodeOffset;
unsigned long end = base + (unsigned long) func.endCodeOffset;
JS_ASSERT(end >= start);
unsigned long size = (end - start);
JSAutoByteString bytes;
const char *method_name = AtomToPrintableString(cx, func.name, &bytes);
if (!method_name)
return false;
unsigned lineno = func.lineno;
unsigned columnIndex = func.columnIndex;
perfSpewer.writeFunctionMap(start, size, filename, lineno, columnIndex, method_name);
}
return true;
}
示例8: HandleDynamicLinkFailure
static bool
HandleDynamicLinkFailure(JSContext *cx, CallArgs args, AsmJSModule &module, HandlePropertyName name)
{
if (cx->isExceptionPending())
return false;
uint32_t begin = module.charsBegin();
uint32_t end = module.charsEnd();
Rooted<JSStableString*> src(cx, module.scriptSource()->substring(cx, begin, end));
if (!src)
return false;
RootedFunction fun(cx, NewFunction(cx, NullPtr(), nullptr, 0, JSFunction::INTERPRETED,
cx->global(), name, JSFunction::FinalizeKind,
TenuredObject));
if (!fun)
return false;
AutoNameVector formals(cx);
formals.reserve(3);
if (module.globalArgumentName())
formals.infallibleAppend(module.globalArgumentName());
if (module.importArgumentName())
formals.infallibleAppend(module.importArgumentName());
if (module.bufferArgumentName())
formals.infallibleAppend(module.bufferArgumentName());
CompileOptions options(cx);
options.setPrincipals(cx->compartment()->principals)
.setOriginPrincipals(module.scriptSource()->originPrincipals())
.setCompileAndGo(false)
.setNoScriptRval(false);
if (!frontend::CompileFunctionBody(cx, &fun, options, formals, src->chars().get(), end - begin))
return false;
// Call the function we just recompiled.
unsigned argc = args.length();
InvokeArgs args2(cx);
if (!args2.init(argc))
return false;
args2.setCallee(ObjectValue(*fun));
args2.setThis(args.thisv());
for (unsigned i = 0; i < argc; i++)
args2[i].set(args[i]);
if (!Invoke(cx, args2))
return false;
args.rval().set(args2.rval());
return true;
}
示例9: SendModuleToAttachedProfiler
static bool
SendModuleToAttachedProfiler(JSContext* cx, AsmJSModule& module)
{
#if defined(MOZ_VTUNE)
if (IsVTuneProfilingActive() && !SendFunctionsToVTune(cx, module))
return false;
#endif
#if defined(JS_ION_PERF)
if (module.numExportedFunctions() > 0) {
size_t firstEntryCode = size_t(module.codeBase() + module.functionBytes());
writePerfSpewerAsmJSEntriesAndExits(firstEntryCode, module.codeBytes() - module.functionBytes());
}
if (!SendFunctionsToPerf(cx, module))
return false;
#endif
return true;
}
示例10: LinkModuleToHeap
static bool
LinkModuleToHeap(JSContext* cx, AsmJSModule& module, Handle<ArrayBufferObjectMaybeShared*> heap)
{
uint32_t heapLength = heap->byteLength();
if (!IsValidAsmJSHeapLength(heapLength)) {
ScopedJSFreePtr<char> msg(
JS_smprintf("ArrayBuffer byteLength 0x%x is not a valid heap length. The next "
"valid length is 0x%x",
heapLength,
RoundUpToNextValidAsmJSHeapLength(heapLength)));
return LinkFail(cx, msg.get());
}
// This check is sufficient without considering the size of the loaded datum because heap
// loads and stores start on an aligned boundary and the heap byteLength has larger alignment.
MOZ_ASSERT((module.minHeapLength() - 1) <= INT32_MAX);
if (heapLength < module.minHeapLength()) {
ScopedJSFreePtr<char> msg(
JS_smprintf("ArrayBuffer byteLength of 0x%x is less than 0x%x (the size implied "
"by const heap accesses and/or change-heap minimum-length requirements).",
heapLength,
module.minHeapLength()));
return LinkFail(cx, msg.get());
}
if (heapLength > module.maxHeapLength()) {
ScopedJSFreePtr<char> msg(
JS_smprintf("ArrayBuffer byteLength 0x%x is greater than maximum length of 0x%x",
heapLength,
module.maxHeapLength()));
return LinkFail(cx, msg.get());
}
// If we've generated the code with signal handlers in mind (for bounds
// checks on x64 and for interrupt callback requesting on all platforms),
// we need to be able to use signals at runtime. In particular, a module
// can have been created using signals and cached, and executed without
// signals activated.
if (module.usesSignalHandlersForInterrupt() && !cx->canUseSignalHandlers())
return LinkFail(cx, "Code generated with signal handlers but signals are deactivated");
if (heap->is<ArrayBufferObject>()) {
Rooted<ArrayBufferObject*> abheap(cx, &heap->as<ArrayBufferObject>());
if (!ArrayBufferObject::prepareForAsmJS(cx, abheap, module.usesSignalHandlersForOOB()))
return LinkFail(cx, "Unable to prepare ArrayBuffer for asm.js use");
}
module.initHeap(heap, cx);
return true;
}
示例11: SendModuleToAttachedProfiler
static bool
SendModuleToAttachedProfiler(JSContext *cx, AsmJSModule &module)
{
#if defined(MOZ_VTUNE)
if (IsVTuneProfilingActive() && !SendFunctionsToVTune(cx, module))
return false;
#endif
#if defined(JS_ION_PERF)
if (module.numExportedFunctions() > 0) {
size_t firstEntryCode = (size_t) module.entryTrampoline(module.exportedFunction(0));
writePerfSpewerAsmJSEntriesAndExits(firstEntryCode, (size_t) module.globalData() - firstEntryCode);
}
if (!SendBlocksToPerf(cx, module))
return false;
if (!SendFunctionsToPerf(cx, module))
return false;
#endif
return true;
}
示例12: HandleDynamicLinkFailure
static bool
HandleDynamicLinkFailure(JSContext *cx, CallArgs args, AsmJSModule &module, HandlePropertyName name)
{
if (cx->isExceptionPending())
return false;
const AsmJSModule::PostLinkFailureInfo &info = module.postLinkFailureInfo();
uint32_t length = info.bufEnd_ - info.bufStart_;
Rooted<JSFlatString*> src(cx, info.scriptSource_->substring(cx, info.bufStart_, info.bufEnd_));
const jschar *chars = src->chars();
RootedFunction fun(cx, NewFunction(cx, NullPtr(), NULL, 0, JSFunction::INTERPRETED,
cx->global(), name));
if (!fun)
return false;
AutoNameVector formals(cx);
formals.reserve(3);
if (module.globalArgumentName())
formals.infallibleAppend(module.globalArgumentName());
if (module.importArgumentName())
formals.infallibleAppend(module.importArgumentName());
if (module.bufferArgumentName())
formals.infallibleAppend(module.bufferArgumentName());
if (!frontend::CompileFunctionBody(cx, &fun, info.options_, formals, chars, length,
/* isAsmJSRecompile = */ true))
return false;
// Call the function we just recompiled.
unsigned argc = args.length();
JS_ASSERT(argc <= 3);
InvokeArgsGuard args2;
if (!cx->stack.pushInvokeArgs(cx, args.length(), &args2))
return false;
args2.setCallee(ObjectValue(*fun));
args2.setThis(args.thisv());
if (argc > 0)
args2[0] = args[0];
if (argc > 1)
args2[1] = args[1];
if (argc > 2)
args2[2] = args[2];
if (!Invoke(cx, args2))
return false;
args.rval().set(args2.rval());
return true;
}
示例13: ChangeHeap
static bool
ChangeHeap(JSContext *cx, AsmJSModule &module, CallArgs args)
{
HandleValue bufferArg = args.get(0);
if (!IsArrayBuffer(bufferArg)) {
ReportIncompatible(cx, args);
return false;
}
Rooted<ArrayBufferObject*> newBuffer(cx, &bufferArg.toObject().as<ArrayBufferObject>());
uint32_t heapLength = newBuffer->byteLength();
if (heapLength & module.heapLengthMask() ||
heapLength < module.minHeapLength() ||
heapLength > module.maxHeapLength())
{
args.rval().set(BooleanValue(false));
return true;
}
if (!module.hasArrayView()) {
args.rval().set(BooleanValue(true));
return true;
}
MOZ_ASSERT(IsValidAsmJSHeapLength(heapLength));
MOZ_ASSERT(!IsDeprecatedAsmJSHeapLength(heapLength));
if (!ArrayBufferObject::prepareForAsmJS(cx, newBuffer, module.usesSignalHandlersForOOB()))
return false;
args.rval().set(BooleanValue(module.changeHeap(newBuffer, cx)));
return true;
}
示例14: AssertMatchesCallSite
static inline void
AssertMatchesCallSite(const AsmJSModule &module, const AsmJSModule::CodeRange *calleeCodeRange,
void *callerPC, void *callerFP, void *fp)
{
#ifdef DEBUG
const AsmJSModule::CodeRange *callerCodeRange = module.lookupCodeRange(callerPC);
JS_ASSERT(callerCodeRange);
if (callerCodeRange->isEntry()) {
JS_ASSERT(callerFP == nullptr);
return;
}
const CallSite *callsite = module.lookupCallSite(callerPC);
if (calleeCodeRange->isThunk()) {
JS_ASSERT(!callsite);
JS_ASSERT(callerCodeRange->isFunction());
} else {
JS_ASSERT(callsite);
JS_ASSERT(callerFP == (uint8_t*)fp + callsite->stackDepth());
}
#endif
}
示例15: ValidateGlobalVariable
static bool
ValidateGlobalVariable(JSContext *cx, const AsmJSModule &module, AsmJSModule::Global &global,
HandleValue importVal)
{
JS_ASSERT(global.which() == AsmJSModule::Global::Variable);
void *datum = module.globalVarIndexToGlobalDatum(global.varIndex());
switch (global.varInitKind()) {
case AsmJSModule::Global::InitConstant: {
const Value &v = global.varInitConstant();
switch (global.varInitCoercion()) {
case AsmJS_ToInt32:
*(int32_t *)datum = v.toInt32();
break;
case AsmJS_ToNumber:
*(double *)datum = v.toDouble();
break;
case AsmJS_FRound:
*(float *)datum = static_cast<float>(v.toDouble());
break;
}
break;
}
case AsmJSModule::Global::InitImport: {
RootedPropertyName field(cx, global.varImportField());
RootedValue v(cx);
if (!GetDataProperty(cx, importVal, field, &v))
return false;
switch (global.varInitCoercion()) {
case AsmJS_ToInt32:
if (!ToInt32(cx, v, (int32_t *)datum))
return false;
break;
case AsmJS_ToNumber:
if (!ToNumber(cx, v, (double *)datum))
return false;
break;
case AsmJS_FRound:
if (!RoundFloat32(cx, v, (float *)datum))
return false;
break;
}
break;
}
}
return true;
}