Bug 945596 - Define getJitCompilerOption to confirm jit-compiler-options. r=nbp, r=h4writer
authormasaya iseki <iseki.m.aa@gmail.com>
Mon, 06 Jan 2014 10:03:41 -0500
changeset 162184 a9d9eb8a7d88d094bc5c4cc837a6f6eac5748c75
parent 162183 72ec313006629b6a85eacc0c613450c159c18292
child 162185 3b57aef6724b42b9859f2d037fbe0cec47ca8a5b
push idunknown
push userunknown
push dateunknown
reviewersnbp, h4writer
bugs945596
milestone29.0a1
Bug 945596 - Define getJitCompilerOption to confirm jit-compiler-options. r=nbp, r=h4writer
js/src/builtin/TestingFunctions.cpp
js/src/jit-test/tests/ion/bug909997.js
js/src/jsapi.cpp
js/src/jsapi.h
--- a/js/src/builtin/TestingFunctions.cpp
+++ b/js/src/builtin/TestingFunctions.cpp
@@ -1123,16 +1123,40 @@ SetJitCompilerOption(JSContext *cx, unsi
 
     JS_SetGlobalJitCompilerOption(cx, opt, uint32_t(number));
 
     args.rval().setUndefined();
     return true;
 }
 
 static bool
+GetJitCompilerOptions(JSContext *cx, unsigned argc, jsval *vp)
+{
+    RootedObject info(cx, JS_NewObject(cx, nullptr, nullptr, nullptr));
+    if (!info)
+        return false;
+
+    RootedValue value(cx);
+
+#define JIT_COMPILER_MATCH(key, string)                         \
+    opt = JSJITCOMPILER_ ## key;                                \
+    value.setInt32(JS_GetGlobalJitCompilerOption(cx, opt));     \
+    if (!JS_SetProperty(cx, info, string, value))               \
+        return false;
+
+    JSJitCompilerOption opt = JSJITCOMPILER_NOT_AN_OPTION;
+    JIT_COMPILER_OPTIONS(JIT_COMPILER_MATCH);
+#undef JIT_COMPILER_MATCH
+
+    *vp = ObjectValue(*info);
+
+    return true;
+}
+
+static bool
 SetIonCheckGraphCoherency(JSContext *cx, unsigned argc, jsval *vp)
 {
     CallArgs args = CallArgsFromVp(argc, vp);
 #ifdef JS_ION
     jit::js_JitOptions.checkGraphConsistency = ToBoolean(args.get(0));
 #endif
     args.rval().setUndefined();
     return true;
@@ -1541,16 +1565,20 @@ static const JSFunctionSpecWithHelp Test
 "  inferred name based on where the function was defined. This can be\n"
 "  different from the 'name' property on the function."),
 
     JS_FN_HELP("isAsmJSCompilationAvailable", IsAsmJSCompilationAvailable, 0, 0,
 "isAsmJSCompilationAvailable",
 "  Returns whether asm.js compilation is currently available or whether it is disabled\n"
 "  (e.g., by the debugger)."),
 
+    JS_FN_HELP("getJitCompilerOptions", GetJitCompilerOptions, 0, 0,
+"getCompilerOptions()",
+"Return an object describing some of the JIT compiler options.\n"),
+
     JS_FN_HELP("isAsmJSModule", IsAsmJSModule, 1, 0,
 "isAsmJSModule(fn)",
 "  Returns whether the given value is a function containing \"use asm\" that has been\n"
 "  validated according to the asm.js spec."),
 
     JS_FN_HELP("isAsmJSModuleLoadedFromCache", IsAsmJSModuleLoadedFromCache, 1, 0,
 "isAsmJSModuleLoadedFromCache(fn)",
 "  Return whether the given asm.js module function has been loaded directly\n"
--- a/js/src/jit-test/tests/ion/bug909997.js
+++ b/js/src/jit-test/tests/ion/bug909997.js
@@ -16,11 +16,14 @@ var method_D = function() {
     for (var t = 0; t < wait; ++t) {}
 }
 
 var func = [method_A, method_B, method_C, method_D]
 
 for (var n = 0; n < 4; ++n) {
     setJitCompilerOption("baseline.enable", n & 1);
     setJitCompilerOption("ion.enable", n & 2 ? 1: 0);
+    var opt = getJitCompilerOptions();
+    assertEq(opt["baseline.enable"], n & 1);
+    assertEq(opt["ion.enable"], n & 2 ? 1 : 0);
     for (var i = 0; i < 1001; ++i)
         func[n]();
 }
\ No newline at end of file
--- a/js/src/jsapi.cpp
+++ b/js/src/jsapi.cpp
@@ -6035,16 +6035,36 @@ JS_SetGlobalJitCompilerOption(JSContext 
         }
         break;
       default:
         break;
     }
 #endif
 }
 
+JS_PUBLIC_API(int)
+JS_GetGlobalJitCompilerOption(JSContext *cx, JSJitCompilerOption opt)
+{
+#ifdef JS_ION
+    switch (opt) {
+      case JSJITCOMPILER_BASELINE_USECOUNT_TRIGGER:
+        return jit::js_JitOptions.baselineUsesBeforeCompile;
+      case JSJITCOMPILER_ION_USECOUNT_TRIGGER:
+        return jit::js_JitOptions.forcedDefaultIonUsesBeforeCompile;
+      case JSJITCOMPILER_ION_ENABLE:
+        return JS::ContextOptionsRef(cx).ion();
+      case JSJITCOMPILER_BASELINE_ENABLE:
+        return JS::ContextOptionsRef(cx).baseline();
+      default:
+        break;
+    }
+#endif
+    return 0;
+}
+
 /************************************************************************/
 
 #if !defined(STATIC_EXPORTABLE_JS_API) && !defined(STATIC_JS_API) && defined(XP_WIN)
 
 #include "jswin.h"
 
 /*
  * Initialization routine for the JS DLL.
--- a/js/src/jsapi.h
+++ b/js/src/jsapi.h
@@ -4552,16 +4552,18 @@ typedef enum JSJitCompilerOption {
     JIT_COMPILER_OPTIONS(JIT_COMPILER_DECLARE)
 #undef JIT_COMPILER_DECLARE
 
     JSJITCOMPILER_NOT_AN_OPTION
 } JSJitCompilerOption;
 
 extern JS_PUBLIC_API(void)
 JS_SetGlobalJitCompilerOption(JSContext *cx, JSJitCompilerOption opt, uint32_t value);
+extern JS_PUBLIC_API(int)
+JS_GetGlobalJitCompilerOption(JSContext *cx, JSJitCompilerOption opt);
 
 /*
  * Convert a uint32_t index into a jsid.
  */
 extern JS_PUBLIC_API(bool)
 JS_IndexToId(JSContext *cx, uint32_t index, JS::MutableHandleId);
 
 /*