RPM Package Manager, CVS Repository http://rpm5.org/cvs/ ____________________________________________________________________________
Server: rpm5.org Name: Jeff Johnson Root: /v/rpm/cvs Email: j...@rpm5.org Module: rpm Date: 07-Jul-2017 00:11:17 Branch: rpm-5_4 Handle: 2017070622111700 Modified files: (Branch: rpm-5_4) rpm/rpmio rpmjs45.cpp rpmjss.inp Log: - rpmjss: WIP. Summary: Revision Changes Path 1.1.2.23 +358 -6 rpm/rpmio/rpmjs45.cpp 1.1.2.12 +23 -22 rpm/rpmio/rpmjss.inp ____________________________________________________________________________ patch -p0 <<'@@ .' Index: rpm/rpmio/rpmjs45.cpp ============================================================================ $ cvs diff -u -r1.1.2.22 -r1.1.2.23 rpmjs45.cpp --- rpm/rpmio/rpmjs45.cpp 4 Jul 2017 08:51:53 -0000 1.1.2.22 +++ rpm/rpmio/rpmjs45.cpp 6 Jul 2017 22:11:17 -0000 1.1.2.23 @@ -141,7 +141,7 @@ }; namespace js { -bool gCanUseExtraThreads = false; +bool gCanUseExtraThreads = true; namespace shell { #ifdef NOTYET @@ -1428,8 +1428,10 @@ return false; RootedObject object(cx, &value.toObject()); +#ifdef FIXME if (!object->is<JSFunction>()) return false; +#endif resultOut.set(&object->as<JSFunction>()); return true; @@ -4462,12 +4464,14 @@ return false; args.rval().setObject(*module); + return true; #else JSAutoByteString chars(cx, args[0].toString()); if (!chars) return false; + + return false; #endif - return true; } static bool @@ -8019,8 +8023,10 @@ if (const char* path = op->getStringOption("module-load-path")) moduleLoadPath = path; +#ifdef FIXME if (!modulePaths.empty() && !InitModuleLoader(cx)) return EXIT_FAILURE; +#endif while (!filePaths.empty() || !codeChunks.empty() || !modulePaths.empty()) { size_t fpArgno = filePaths.empty() ? SIZE_MAX : filePaths.argno(); @@ -8350,9 +8356,11 @@ if (op->getBoolOption("no-ggc")) noggc.emplace(cx->runtime()); +#ifdef FIXME Maybe<AutoDisableCompactingGC> nocgc; if (op->getBoolOption("no-cgc")) nocgc.emplace(cx->runtime()); +#endif JSAutoRequest ar(cx); @@ -8375,8 +8383,10 @@ int result = ProcessArgs(cx, op); +#ifdef FIXME if (enableDisassemblyDumps) js::DumpCompartmentPCCounts(cx); +#endif if (!op->getBoolOption("no-js-cache-per-process")) { if (jsCacheAsmJSPath) { @@ -8622,6 +8632,342 @@ #include <poptIO.h> /*==============================================================*/ +static int mozShellMain(int argc, char **argv, char **envp) +{ + sArgc = argc; + sArgv = argv; + + JSRuntime* rt; + JSContext* cx; + int result; + +#ifdef HAVE_SETLOCALE + setlocale(LC_ALL, ""); +#endif + + MaybeOverrideOutFileFromEnv("JS_STDERR", stderr, &gErrFile); + MaybeOverrideOutFileFromEnv("JS_STDOUT", stdout, &gOutFile); + + OptionParser op("Usage: {progname} [options] [[script] scriptArgs*]"); + + op.setDescription("The SpiderMonkey shell provides a command line interface to the " + "JavaScript engine. Code and file options provided via the command line are " + "run left to right. If provided, the optional script argument is run after " + "all options have been processed. Just-In-Time compilation modes may be enabled via " + "command line options."); + op.setDescriptionWidth(72); + op.setHelpWidth(80); + op.setVersion(JS_GetImplementationVersion()); + + if (!op.addMultiStringOption('f', "file", "PATH", "File path to run") + || !op.addMultiStringOption('m', "module", "PATH", "Module path to run") + || !op.addMultiStringOption('e', "execute", "CODE", "Inline code to run") + || !op.addBoolOption('i', "shell", "Enter prompt after running code") + || !op.addBoolOption('c', "compileonly", "Only compile, don't run (syntax checking mode)") + || !op.addBoolOption('w', "warnings", "Emit warnings") + || !op.addBoolOption('W', "nowarnings", "Don't emit warnings") + || !op.addBoolOption('s', "strict", "Check strictness") + || !op.addBoolOption('D', "dump-bytecode", "Dump bytecode with exec count for all scripts") + || !op.addBoolOption('b', "print-timing", "Print sub-ms runtime for each file that's run") + || !op.addStringOption('\0', "js-cache", "[path]", + "Enable the JS cache by specifying the path of the directory to use " + "to hold cache files") + || !op.addBoolOption('\0', "no-js-cache-per-process", + "Deactivates cache per process. Otherwise, generate a separate cache" + "sub-directory for this process inside the cache directory" + "specified by --js-cache. This cache directory will be removed" + "when the js shell exits. This is useful for running tests in" + "parallel.") + || !op.addBoolOption('\0', "code-coverage", "Enable code coverage instrumentation.") +#ifdef DEBUG + || !op.addBoolOption('O', "print-alloc", "Print the number of allocations at exit") +#endif + || !op.addOptionalStringArg("script", "A script to execute (after all options)") + || !op.addOptionalMultiStringArg("scriptArgs", + "String arguments to bind as |scriptArgs| in the " + "shell's global") + || !op.addIntOption('\0', "thread-count", "COUNT", "Use COUNT auxiliary threads " + "(default: # of cores - 1)", -1) + || !op.addBoolOption('\0', "ion", "Enable IonMonkey (default)") + || !op.addBoolOption('\0', "no-ion", "Disable IonMonkey") + || !op.addBoolOption('\0', "no-asmjs", "Disable asm.js compilation") + || !op.addBoolOption('\0', "no-native-regexp", "Disable native regexp compilation") + || !op.addBoolOption('\0', "no-unboxed-objects", "Disable creating unboxed plain objects") + || !op.addBoolOption('\0', "unboxed-arrays", "Allow creating unboxed arrays") + || !op.addStringOption('\0', "ion-shared-stubs", "on/off", + "Use shared stubs (default: off, on to enable)") + || !op.addStringOption('\0', "ion-scalar-replacement", "on/off", + "Scalar Replacement (default: on, off to disable)") + || !op.addStringOption('\0', "ion-gvn", "[mode]", + "Specify Ion global value numbering:\n" + " off: disable GVN\n" + " on: enable GVN (default)\n") + || !op.addStringOption('\0', "ion-licm", "on/off", + "Loop invariant code motion (default: on, off to disable)") + || !op.addStringOption('\0', "ion-edgecase-analysis", "on/off", + "Find edge cases where Ion can avoid bailouts (default: on, off to disable)") + || !op.addStringOption('\0', "ion-pgo", "on/off", + "Profile guided optimization (default: off, on to enable)") + || !op.addStringOption('\0', "ion-range-analysis", "on/off", + "Range analysis (default: on, off to disable)") +#if defined(__APPLE__) + || !op.addStringOption('\0', "ion-sincos", "on/off", + "Replace sin(x)/cos(x) to sincos(x) (default: on, off to disable)") +#else + || !op.addStringOption('\0', "ion-sincos", "on/off", + "Replace sin(x)/cos(x) to sincos(x) (default: off, on to enable)") +#endif + || !op.addStringOption('\0', "ion-sink", "on/off", + "Sink code motion (default: off, on to enable)") + || !op.addStringOption('\0', "ion-loop-unrolling", "on/off", + "Loop unrolling (default: off, on to enable)") + || !op.addStringOption('\0', "ion-instruction-reordering", "on/off", + "Instruction reordering (default: off, on to enable)") + || !op.addBoolOption('\0', "ion-check-range-analysis", + "Range analysis checking") + || !op.addBoolOption('\0', "ion-extra-checks", + "Perform extra dynamic validation checks") + || !op.addStringOption('\0', "ion-inlining", "on/off", + "Inline methods where possible (default: on, off to disable)") + || !op.addStringOption('\0', "ion-osr", "on/off", + "On-Stack Replacement (default: on, off to disable)") + || !op.addStringOption('\0', "ion-limit-script-size", "on/off", + "Don't compile very large scripts (default: on, off to disable)") + || !op.addIntOption('\0', "ion-warmup-threshold", "COUNT", + "Wait for COUNT calls or iterations before compiling " + "(default: 1000)", -1) + || !op.addStringOption('\0', "ion-regalloc", "[mode]", + "Specify Ion register allocation:\n" + " backtracking: Priority based backtracking register allocation (default)\n" + " testbed: Backtracking allocator with experimental features\n" + " stupid: Simple block local register allocation") + || !op.addBoolOption('\0', "ion-eager", "Always ion-compile methods (implies --baseline-eager)") + || !op.addStringOption('\0', "ion-offthread-compile", "on/off", + "Compile scripts off thread (default: on)") + || !op.addStringOption('\0', "ion-parallel-compile", "on/off", + "--ion-parallel compile is deprecated. Use --ion-offthread-compile.") + || !op.addBoolOption('\0', "baseline", "Enable baseline compiler (default)") + || !op.addBoolOption('\0', "no-baseline", "Disable baseline compiler") + || !op.addBoolOption('\0', "baseline-eager", "Always baseline-compile methods") + || !op.addIntOption('\0', "baseline-warmup-threshold", "COUNT", + "Wait for COUNT calls or iterations before baseline-compiling " + "(default: 10)", -1) + || !op.addBoolOption('\0', "non-writable-jitcode", "Allocate JIT code as non-writable memory.") + || !op.addBoolOption('\0', "no-fpu", "Pretend CPU does not support floating-point operations " + "to test JIT codegen (no-op on platforms other than x86).") + || !op.addBoolOption('\0', "no-sse3", "Pretend CPU does not support SSE3 instructions and above " + "to test JIT codegen (no-op on platforms other than x86 and x64).") + || !op.addBoolOption('\0', "no-sse4", "Pretend CPU does not support SSE4 instructions" + "to test JIT codegen (no-op on platforms other than x86 and x64).") + || !op.addBoolOption('\0', "enable-avx", "AVX is disabled by default. Enable AVX. " + "(no-op on platforms other than x86 and x64).") + || !op.addBoolOption('\0', "no-avx", "No-op. AVX is currently disabled by default.") + || !op.addBoolOption('\0', "fuzzing-safe", "Don't expose functions that aren't safe for " + "fuzzers to call") + || !op.addBoolOption('\0', "disable-oom-functions", "Disable functions that cause " + "artificial OOMs") + || !op.addBoolOption('\0', "no-threads", "Disable helper threads") +#ifdef DEBUG + || !op.addBoolOption('\0', "dump-entrained-variables", "Print variables which are " + "unnecessarily entrained by inner functions") +#endif + || !op.addBoolOption('\0', "no-ggc", "Disable Generational GC") + || !op.addBoolOption('\0', "no-cgc", "Disable Compacting GC") + || !op.addBoolOption('\0', "no-incremental-gc", "Disable Incremental GC") + || !op.addIntOption('\0', "available-memory", "SIZE", + "Select GC settings based on available memory (MB)", 0) +#if defined(JS_CODEGEN_ARM) + || !op.addStringOption('\0', "arm-hwcap", "[features]", + "Specify ARM code generation features, or 'help' to list all features.") + || !op.addIntOption('\0', "arm-asm-nop-fill", "SIZE", + "Insert the given number of NOP instructions at all possible pool locations.", 0) + || !op.addIntOption('\0', "asm-pool-max-offset", "OFFSET", + "The maximum pc relative OFFSET permitted in pool reference instructions.", 1024) +#endif +#if defined(JS_SIMULATOR_ARM) + || !op.addBoolOption('\0', "arm-sim-icache-checks", "Enable icache flush checks in the ARM " + "simulator.") + || !op.addIntOption('\0', "arm-sim-stop-at", "NUMBER", "Stop the ARM simulator after the given " + "NUMBER of instructions.", -1) +#elif defined(JS_SIMULATOR_MIPS32) || defined(JS_SIMULATOR_MIPS64) + || !op.addBoolOption('\0', "mips-sim-icache-checks", "Enable icache flush checks in the MIPS " + "simulator.") + || !op.addIntOption('\0', "mips-sim-stop-at", "NUMBER", "Stop the MIPS simulator after the given " + "NUMBER of instructions.", -1) +#endif + || !op.addIntOption('\0', "nursery-size", "SIZE-MB", "Set the maximum nursery size in MB", 16) +#ifdef JS_GC_ZEAL + || !op.addStringOption('z', "gc-zeal", "LEVEL[,N]", gc::ZealModeHelpText) +#endif + || !op.addStringOption('\0', "module-load-path", "DIR", "Set directory to load modules from") + ) + { + return EXIT_FAILURE; + } + + op.setArgTerminatesOptions("script", true); + op.setArgCapturesRest("scriptArgs"); + + switch (op.parseArgs(argc, argv)) { + case OptionParser::EarlyExit: + return EXIT_SUCCESS; + case OptionParser::ParseError: + op.printHelp(argv[0]); + return EXIT_FAILURE; + case OptionParser::Fail: + return EXIT_FAILURE; + case OptionParser::Okay: + break; + } + + if (op.getHelpOption()) + return EXIT_SUCCESS; + +#ifdef DEBUG + /* + * Process OOM options as early as possible so that we can observe as many + * allocations as possible. + */ + OOM_printAllocationCount = op.getBoolOption('O'); +#endif + +#ifdef FIXME +#ifdef JS_CODEGEN_X86 + if (op.getBoolOption("no-fpu")) + js::jit::CPUInfo::SetFloatingPointDisabled(); +#endif + +#if defined(JS_CODEGEN_X86) || defined(JS_CODEGEN_X64) + if (op.getBoolOption("no-sse3")) { + js::jit::CPUInfo::SetSSE3Disabled(); + PropagateFlagToNestedShells("--no-sse3"); + } + if (op.getBoolOption("no-sse4")) { + js::jit::CPUInfo::SetSSE4Disabled(); + PropagateFlagToNestedShells("--no-sse4"); + } + if (op.getBoolOption("enable-avx")) { + js::jit::CPUInfo::SetAVXEnabled(); + PropagateFlagToNestedShells("--enable-avx"); + } +#endif +#endif /* FIXME */ + + if (op.getBoolOption("no-threads")) + js::DisableExtraThreads(); + + // Start the engine. + if (!JS_Init()) + return 1; + + if (!InitSharedArrayBufferMailbox()) + return 1; + + // The fake thread count must be set before initializing the Runtime, + // which spins up the thread pool. +#ifdef FIXME + int32_t threadCount = op.getIntOption("thread-count"); + if (threadCount >= 0) + SetFakeCPUCount(threadCount); +#endif + + size_t nurseryBytes = JS::DefaultNurseryBytes; + nurseryBytes = op.getIntOption("nursery-size") * 1024L * 1024L; + + /* Use the same parameters as the browser in xpcjsruntime.cpp. */ + rt = JS_NewRuntime(JS::DefaultHeapMaxBytes, nurseryBytes); + if (!rt) + return 1; + + mozilla::UniquePtr<ShellRuntime> sr = MakeUnique<ShellRuntime>(); + if (!sr) + return 1; + + JS_SetRuntimePrivate(rt, sr.get()); + JS_SetErrorReporter(rt, my_ErrorReporter); + JS::SetOutOfMemoryCallback(rt, my_OOMCallback, nullptr); + if (!SetRuntimeOptions(rt, op)) + return 1; + + sr->interruptFunc.init(rt, NullValue()); + sr->lastWarning.init(rt, NullValue()); + + JS_SetGCParameter(rt, JSGC_MAX_BYTES, 0xffffffff); + + size_t availMem = op.getIntOption("available-memory"); + if (availMem > 0) + JS_SetGCParametersBasedOnAvailableMemory(rt, availMem); + + JS_SetTrustedPrincipals(rt, &ShellPrincipals::fullyTrusted); + JS_SetSecurityCallbacks(rt, &ShellPrincipals::securityCallbacks); + JS_InitDestroyPrincipalsCallback(rt, ShellPrincipals::destroy); + +#ifdef NOTYET + JS_SetInterruptCallback(rt, ShellInterruptCallback); +#endif /* NOTYET */ + JS::SetAsmJSCacheOps(rt, &asmJSCacheOps); + + JS_SetNativeStackQuota(rt, gMaxStackSize); + +#ifdef FIXME + JS::dbg::SetDebuggerMallocSizeOf(rt, moz_malloc_size_of); +#endif + +#ifdef FIXME + if (!offThreadState.init()) + return 1; +#endif + + if (!InitWatchdog(rt)) + return 1; + + cx = NewContext(rt); + if (!cx) + return 1; + + JS_SetGCParameter(rt, JSGC_MODE, JSGC_MODE_INCREMENTAL); + JS_SetGCParameterForThread(cx, JSGC_MAX_CODE_CACHE_BYTES, 16 * 1024 * 1024); + + JS::SetLargeAllocationFailureCallback(rt, my_LargeAllocFailCallback, (void*)cx); + + // Set some parameters to allow incremental GC in low memory conditions, + // as is done for the browser, except in more-deterministic builds or when + // disabled by command line options. +#ifndef JS_MORE_DETERMINISTIC + if (!op.getBoolOption("no-incremental-gc")) { + JS_SetGCParameter(rt, JSGC_DYNAMIC_HEAP_GROWTH, 1); + JS_SetGCParameter(rt, JSGC_DYNAMIC_MARK_SLICE, 1); + JS_SetGCParameter(rt, JSGC_SLICE_TIME_BUDGET, 10); + } +#endif + + js::SetPreserveWrapperCallback(rt, DummyPreserveWrapperCallback); + + result = Shell(cx, &op, envp); + +#ifdef DEBUG + if (OOM_printAllocationCount) + printf("OOM max count: %u\n", OOM_counter); +#endif + + JS::SetLargeAllocationFailureCallback(rt, nullptr, nullptr); + + DestroyContext(cx, true); + + KillWatchdog(rt); + + MOZ_ASSERT_IF(!CanUseExtraThreads(), workerThreads.empty()); + for (size_t i = 0; i < workerThreads.length(); i++) + PR_JoinThread(workerThreads[i]); + + DestructSharedArrayBufferMailbox(); + + JS_DestroyRuntime(rt); + JS_ShutDown(); + return result; +} + +/*==============================================================*/ struct rpmjss_s _jss; rpmjss jss = &_jss; @@ -8858,8 +9204,9 @@ POPT_TABLEEND }; -int main(int argc, char *argv[]) +int main(int argc, char *argv[], char *envp[]) { +#ifdef HACK poptContext con = rpmioInit(argc, argv, rpmjssOptionsTable); int rc = 0; @@ -8874,11 +9221,13 @@ int ac = argvCount(av); for (int i = 0; i < ac; i++) { - const char * script = av[i]; + const char * code = av[i]; const char * result = NULL; - rc = mozRun(jss, &result, script, _fn, i); - fprintf(stderr, "<== result |%s| from |%s|\n", result, script); + rc = mozRun(jss, &result, code, _fn, i); + fprintf(stderr, "<== result |%s| from |%s|\n", result, code); result = _free(result); + if (!strcasecmp(code, "quit")) + break; } mozFini(jss); @@ -8887,5 +9236,8 @@ con = rpmioFini(con); return rc; +#else + return mozShellMain(argc, argv, envp); +#endif } #endif /* RPMJSS_SELF_TEST */ @@ . patch -p0 <<'@@ .' Index: rpm/rpmio/rpmjss.inp ============================================================================ $ cvs diff -u -r1.1.2.11 -r1.1.2.12 rpmjss.inp --- rpm/rpmio/rpmjss.inp 4 Jul 2017 08:51:53 -0000 1.1.2.11 +++ rpm/rpmio/rpmjss.inp 6 Jul 2017 22:11:17 -0000 1.1.2.12 @@ -21,49 +21,49 @@ print(foo) var foo = "print"; print(foo) var foo = "printErr"; printErr(foo) -var foo = "putstr"; putstr(foo) +var foo = "putstr"; putstr(foo); print("") dateNow() var foo = 0; assertEq(foo, foo) startTimingMutator() stopTimingMutator() -throwError() -disassemble() // XXX DEBUG -dis() // XXX DEBUG -disfile() // XXX DEBUG -dissrc() // XXX DEBUG -notes() // XXX DEBUG -stackDump() // XXX DEBUG +//throwError() +//disassemble() // XXX DEBUG +//dis() // XXX DEBUG +//disfile() // XXX DEBUG +//dissrc() // XXX DEBUG +//notes() // XXX DEBUG +//stackDump() // XXX DEBUG intern("intern") -var slx = null; getslx(slx) -evalcx('lazy'), null) -evalInWorker("version();") +//function func() {return;}; getslx(func) +//evalcx('lazy'), null) // missing ; before statement +//evalInWorker("version();") // XXX threads getSharedArrayBuffer() setSharedArrayBuffer() var obj = new Date; shapeOf(obj) -arrayInfo() // XX DEBUG +//arrayInfo() // XX DEBUG sleep(1) compile("var foo = true") -parseModule("js/import.js") +//parseModule("import.js") // XXX gutted function func() {return;}; setModuleResolveHook(func) getModuleLoadPath() parse("true") syntaxParse("true") -offThreadCompileScript("true") -runOffThreadScript() +//offThreadCompileScript("true") // XXX threads +//runOffThreadScript() // XXX threads timeout(1) interruptIf(true) -var func = null; invokeInterruptCallback(func) -function func() {return;}; setInterruptCallback(func) +//function func() {return;}; invokeInterruptCallback(func) +//function func() {return;}; setInterruptCallback(func) disableLastWarning() enableLastWarning() getLastWarning() clearLastWarning() elapsed() -decompileFunction() +function func() {return;}; decompileFunction(func) decompileThis() thisFilename() newGlobal() -var ccw = null; nukeCCW(ccw) +//var ccw = null; nukeCCW(ccw) // XXX invalid args createMappedArrayBuffer("js/createMappedArrayBuffer") getMaxArgs() objectEmulatingUndefined() @@ -71,10 +71,11 @@ setCachingEnabled(true) cacheEntry("cacheEntry") printProfilerEvents() -enableSingleStepProfiling() -disableSingleStepProfiling() +//enableSingleStepProfiling() // XXX disabled +//disableSingleStepProfiling() // XXX disabled isLatin1("isLatin1") stackPointerInfo() -entryPoints() +//entryPoints() // XXX wrong no. of args help(help) +print("quit") quit() @@ . ______________________________________________________________________ RPM Package Manager http://rpm5.org CVS Sources Repository rpm-cvs@rpm5.org