static JSObject* PreWrap(JSContext* cx, JS::HandleObject scope, JS::HandleObject obj, JS::HandleObject objectPassedToWrap) { JS_GC(JS_GetRuntime(cx)); return obj; }
/** * shell_global_gc: * @global: A #ShellGlobal * * Start a garbage collection process. For more information, see * https://developer.mozilla.org/En/JS_GC */ void shell_global_gc (ShellGlobal *global) { JSContext *context = gjs_context_get_native_context (global->js_context); JS_GC (context); }
static JSBool gc(JSContext* cx, JSObject* obj, uintN argc, jsval* argv, jsval* rval) { JS_GC(cx); *rval = JSVAL_VOID; return JS_TRUE; }
JSObject *newDelegate() { static const JSClass delegateClass = { "delegate", JSCLASS_GLOBAL_FLAGS | JSCLASS_HAS_RESERVED_SLOTS(1), JS_PropertyStub, JS_DeletePropertyStub, JS_PropertyStub, JS_StrictPropertyStub, JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, nullptr, nullptr, nullptr, nullptr, JS_GlobalObjectTraceHook }; /* Create the global object. */ JS::CompartmentOptions options; options.setVersion(JSVERSION_LATEST); JS::RootedObject global(cx); global = JS_NewGlobalObject(cx, &delegateClass, nullptr, JS::FireOnNewGlobalHook, options); JS_SetReservedSlot(global, 0, JS::Int32Value(42)); /* * Ensure the delegate is not in the nursery because for the purpose of this * test we're going to put it in a private slot where it won't get updated. */ JS_GC(rt); return global; }
static JSBool gc(JSContext* cx, uintN argc, jsval* vp) { JS_GC(cx); JS_SET_RVAL(cx, vp, JSVAL_VOID); return JS_TRUE; }
void nsXREDirProvider::DoShutdown() { if (mProfileNotified) { nsCOMPtr<nsIObserverService> obsSvc = mozilla::services::GetObserverService(); NS_ASSERTION(obsSvc, "No observer service?"); if (obsSvc) { static const char16_t kShutdownPersist[] = MOZ_UTF16("shutdown-persist"); obsSvc->NotifyObservers(nullptr, "profile-change-net-teardown", kShutdownPersist); obsSvc->NotifyObservers(nullptr, "profile-change-teardown", kShutdownPersist); // Phase 2c: Now that things are torn down, force JS GC so that things which depend on // resources which are about to go away in "profile-before-change" are destroyed first. JSRuntime *rt = xpc::GetJSRuntime(); if (rt) { JS_GC(rt); } // Phase 3: Notify observers of a profile change obsSvc->NotifyObservers(nullptr, "profile-before-change", kShutdownPersist); obsSvc->NotifyObservers(nullptr, "profile-before-change2", kShutdownPersist); } mProfileNotified = false; } }
static JSObject * SameCompartmentWrap(JSContext *cx, JSObject *objArg) { JS::RootedObject obj(cx, objArg); JS_GC(JS_GetRuntime(cx)); return obj; }
static JSBool js_gc(JSContext *cx, uintN argc, jsval *arglist) { JSObject *obj=JS_THIS_OBJECT(cx, arglist); jsval *argv=JS_ARGV(cx, arglist); JSBool forced=JS_TRUE; js_callback_t* cb; JS_SET_RVAL(cx, arglist, JSVAL_VOID); if((cb=(js_callback_t*)JS_GetPrivate(cx,obj))==NULL) return(JS_FALSE); if(argc) JS_ValueToBoolean(cx,argv[0],&forced); if(forced) JS_GC(cx); else JS_MaybeGC(cx); cb->gc_attempts++; return(JS_TRUE); }
JS_NEVER_INLINE bool cls_testIsAboutToBeFinalized_bug528645::createAndTestRooted() { jsvalRoot root(cx); /* * Check various types of GC things against JS_IsAboutToBeFinalized. * Make sure to include unit and numeric strings to the set. */ EVAL("var x = 1.1; " "[''+x, 'a', '123456789', 'something'.substring(1), " "{}, [], new Function('return 10;'), <xml/>];", root.addr()); JSObject *array = JSVAL_TO_OBJECT(root.value()); JS_ASSERT(JS_IsArrayObject(cx, array)); JSBool ok = JS_GetArrayLength(cx, array, &checkPointersLength); CHECK(ok); checkPointers = (void **) malloc(sizeof(void *) * checkPointersLength); CHECK(checkPointers); checkPointersStaticStrings = 0; for (jsuint i = 0; i != checkPointersLength; ++i) { jsval v; ok = JS_GetElement(cx, array, i, &v); CHECK(ok); JS_ASSERT(JSVAL_IS_GCTHING(v)); JS_ASSERT(!JSVAL_IS_NULL(v)); checkPointers[i] = JSVAL_TO_GCTHING(v); if (JSString::isStatic(checkPointers[i])) ++checkPointersStaticStrings; } oldGCCallback = JS_SetGCCallback(cx, TestAboutToBeFinalizedCallback); JS_GC(cx); /* * All GC things are rooted via the root holding the array containing them * and TestAboutToBeFinalizedCallback must keep them as is. */ for (jsuint i = 0; i != checkPointersLength; ++i) CHECK(checkPointers[i]); /* * Overwrite the registers and stack with new GC things to avoid false * positives with the finalization test. */ EVAL("[]", root.addr()); array = JSVAL_TO_OBJECT(root.value()); JS_ASSERT(JS_IsArrayObject(cx, array)); jsuint tmp; CHECK(JS_GetArrayLength(cx, array, &tmp)); CHECK(ok); return true; }
static void PreWrap(JSContext* cx, JS::HandleObject scope, JS::HandleObject obj, JS::HandleObject objectPassedToWrap, JS::MutableHandleObject retObj) { JS_GC(cx); retObj.set(obj); }
static JSObject * PreWrap(JSContext *cx, JSObject *scopeArg, JSObject *objArg, unsigned flags) { JS::RootedObject scope(cx, scopeArg); JS::RootedObject obj(cx, objArg); JS_GC(JS_GetRuntime(cx)); return obj; }
static JSTrapStatus EmptyTrapHandler(JSContext *cx, JSScript *script, jsbytecode *pc, jsval *rval, jsval closure) { JS_GC(JS_GetRuntime(cx)); if (JSVAL_IS_STRING(closure)) ++emptyTrapCallCount; return JSTRAP_CONTINUE; }
void ScriptInterface::DumpHeap() { #if MOZJS_DEBUG_ABI JS_DumpHeap(GetJSRuntime(), stderr, NULL, JSTRACE_OBJECT, NULL, (size_t)-1, NULL); #endif fprintf(stderr, "# Bytes allocated: %u\n", JS_GetGCParameter(GetJSRuntime(), JSGC_BYTES)); JS_GC(GetJSRuntime()); fprintf(stderr, "# Bytes allocated after GC: %u\n", JS_GetGCParameter(GetJSRuntime(), JSGC_BYTES)); }
static JSBool AfxGlobal_gc(JSContext *cx, unsigned argc, JS::Value *vp) { JS::CallReceiver rec = JS::CallReceiverFromVp(vp); JS_GC(g_JsRt); rec.rval().set(JSVAL_VOID); return JS_TRUE; }
JsExecutionContext::~JsExecutionContext() { JS_SetContextThread(cx); JS_GC(cx); JS_BeginRequest(cx); JS_ClearScope(cx, obj); JS_EndRequest(cx); JS_ClearContextThread(cx); JS_DestroyContext(cx); JS_DestroyRuntime(rt); }
static JSBool gjs_gc(JSContext *context, unsigned argc, jsval *vp) { jsval *argv = JS_ARGV(cx, vp); if (!gjs_parse_args(context, "gc", "", argc, argv)) return JS_FALSE; JS_GC(JS_GetRuntime(context)); return JS_TRUE; }
/** Garbage Collector method for Javascript. * One optional argument, boolean, whether or not to force the garbage collection. */ static JSBool vm_gc(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { JSBool b; if (argc == 0) { JS_GC(cx); } else { if (JS_ValueToBoolean(cx, argv[0], &b) == JS_FALSE) return JS_FALSE; if (b) JS_GC(cx); else JS_MaybeGC(cx); } return JS_TRUE; }
char *sm_eval(jaegermonkey_vm *vm, const char *filename, const char *code, int handle_retval) { char *retval = NULL; JSScript *script; jsval result; begin_request(vm); script = JS_CompileScript(vm->context, vm->global, code, strlen(code), filename, 1); jaegermonkey_error *error = (jaegermonkey_error *) JS_GetContextPrivate(vm->context); if (error == NULL) { JS_ClearPendingException(vm->context); JS_ExecuteScript(vm->context, vm->global, script, &result); vm->invoke_count++; error = (jaegermonkey_error *) JS_GetContextPrivate(vm->context); if (error == NULL) { if (handle_retval) { if (JSVAL_IS_STRING(result)) { JSString *str = JS_ValueToString(vm->context, result); retval = copy_jsstring(str); } else if(strcmp(JS_GetStringBytes(JS_ValueToString(vm->context, result)), "undefined") == 0) { retval = copy_string("{\"error\": \"Expression returned undefined\", \"lineno\": 0, \"source\": \"unknown\"}"); } else { retval = copy_string("{\"error\": \"non-JSON return value\", \"lineno\": 0, \"source\": \"unknown\"}"); } } JS_DestroyScript(vm->context, script); } else { retval = error_to_json(error); free_error(error); JS_SetContextPrivate(vm->context, NULL); } } else { retval = error_to_json(error); free_error(error); JS_SetContextPrivate(vm->context, NULL); } if (vm->invoke_count > 200) { JS_GC(vm->context); vm->invoke_count = 0; } else { JS_MaybeGC(vm->context); } end_request(vm); return retval; }
void TraceMonkeyValue::invalidate() { assert(isValid()); Logging::log(Logging::INFO, "Removing TM root for %s\r\n", debugName.c_str()); bool success = JS_RemoveRoot(TraceMonkeyEngine::context, &(this->value)); // Allow GCing (unless others use it) assert(success); JS_GC(TraceMonkeyEngine::context); // XXX For debugging purposes ScriptValue::invalidate(); // call parent }
bool tryScript(JS::HandleObject global, JSScript *scriptArg) { JS::RootedScript script(cx, scriptArg); CHECK(script); JS_GC(rt); /* After a garbage collection, the script should still work. */ JS::RootedValue result(cx); CHECK(JS_ExecuteScript(cx, global, script, result.address())); return true; }
JSBool branch_cb(JSContext* jscx, JSScript* script) { Context* pycx = (Context*) JS_GetContextPrivate(jscx); time_t now = time(NULL); if(pycx == NULL) { JS_ReportError(jscx, "Failed to find Python context."); return JS_FALSE; } // Get out quick if we don't have any quotas. if(pycx->max_time == 0 && pycx->max_heap == 0) { return JS_TRUE; } // Only check occasionally for resource usage. pycx->branch_count++; if((pycx->branch_count > 0x3FFF) != 1) { return JS_TRUE; } pycx->branch_count = 0; if(pycx->max_heap > 0 && jscx->runtime->gcBytes > pycx->max_heap) { // First see if garbage collection gets under the threshold. JS_GC(jscx); if(jscx->runtime->gcBytes > pycx->max_heap) { PyErr_NoMemory(); return JS_FALSE; } } if( pycx->max_time > 0 && pycx->start_time > 0 && pycx->max_time < now - pycx->start_time ) { PyErr_SetNone(PyExc_SystemError); return JS_FALSE; } return JS_TRUE; }
bool RenderArea::on_expose_event (GdkEventExpose *event) { try { /*GdkGLDrawable *gldrawable =*/ gtk_widget_get_gl_drawable (GTK_WIDGET(gobj())); ScopedGLContext myContext(this); if (_myRenderer && _myScene) { if (_isFirstFrame) { _myRenderer->getCurrentScene()->updateAllModified(); _isFirstFrame = false; } STOP_TIMER(frames); asl::getDashboard().cycle(); START_TIMER(frames); onFrame(); //START_TIMER(dispatchEvents); //y60::EventDispatcher::get().dispatch(); //STOP_TIMER(dispatchEvents); START_TIMER(handleRequests); _myRequestManager.handleRequests(); STOP_TIMER(handleRequests); renderFrame(); swapBuffers(); /** done rendering **/ } else { // nothing to render... just clear the buffer to avoid pixel garbage glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); swapBuffers(); } if (_myJSContext) { MAKE_SCOPE_TIMER(gc); JS_GC(_myJSContext); } } catch (const asl::Exception & ex) { AC_FATAL << "Exception caught: " << ex; } catch (const exception & ex) { AC_FATAL << "Exception caught: " << ex.what(); } catch (...) { AC_FATAL << "Unknown exception"; } return true; }
JSBool on_branch(JSContext *context) { JSBool return_value = JS_TRUE; spidermonkey_state *state = (spidermonkey_state *) JS_GetContextPrivate(context); state->branch_count++; if (state->terminate) { return_value = JS_FALSE; } else if (state->branch_count == 550) { JS_GC(context); state->branch_count = 0; } else if(state->branch_count % 100 == 0) { JS_MaybeGC(context); } return return_value; }
bool MozJSImplScope::_interruptCallback(JSContext* cx) { auto scope = getScope(cx); if (scope->_pendingGC.load()) { scope->_pendingGC.store(false); JS_GC(scope->_runtime); } else { JS_MaybeGC(cx); } bool kill = scope->isKillPending(); if (kill) { scope->_engine->getDeadlineMonitor().stopDeadline(scope); scope->unregisterOperation(); } return !kill; }
/*---------------------------------------------------------------------------*/ WebcJSBrowserContext::~WebcJSBrowserContext (void) { JSContext* acx = 0; JSContext* iterp = WEBC_NULL; #if (WEBC_DEBUG_JSCRIPT) if (mJSDebug) WEBC_DELETE(mJSDebug); #endif while ((acx = JS_ContextIterator(mRuntime, &iterp)) != WEBC_NULL) { JS_GC(acx); JS_DestroyContext(acx); iterp = WEBC_NULL; } JS_DestroyRuntime(mRuntime); JS_ShutDown(); }
bool parseECMAScript(const char *name) {// begin parseECMAScript jsval rval; uintN lineno = 0; g_bJSSuccess = 0; printf("Spidermonkey compiling \"%s\"...",name); FILE *file = fopen(name, "r"); JSScript *pJSScript = JS_CompileFileHandle(g_pCx, g_pObject, name, file);; #warning potential leak here /* In normal operation the file is closed by JS_CompileFileHandle (jsapi.c:3772) JS_CompileFileHandleForPrincipals (jsapi.c:3795) CompileTokenStream (jsapi.c:3609) js_CloseTokenStream (jsscan.c:322) */ /* DOUBLE CLOSE fclose(file); */ printf("Done.\n"); if(pJSScript != NULL) {// begin execute external file char curDir[PATH_MAX + 1]; char scriptPath[strlen(name) + 1]; strcpy(scriptPath, name); ADM_PathStripName(scriptPath); getcwd(curDir, PATH_MAX); chdir(scriptPath); printf("Spidermonkey executing \"%s\"...",name); JSBool ok = JS_ExecuteScript(g_pCx, g_pObject, pJSScript, &rval); JS_DestroyScript(g_pCx,pJSScript); printf("Done.\n"); chdir(curDir); }// end execute external file // Run garbage collector now, it is safe JS_GC(g_pCx); A_Resync(); return g_bJSSuccess; }// end parseECMAScript
TraceMonkeyValue::TraceMonkeyValue(ScriptEngine* _engine, double _value) : ScriptValue(_engine) { debugName = "double value no. " + Utility::toString(__nameCounter); Logging::log(Logging::INFO, "Going to create a TM value of: %s\r\n", debugName.c_str()); INDENT_LOG(Logging::INFO); value = DOUBLE_TO_JSVAL(_value); bool ret = JS_AddNamedRoot(TraceMonkeyEngine::context, &(this->value), debugName.c_str()); // Ensure our value won't be GCed assert(ret); printJSVAL(value); Logging::log(Logging::INFO, "Created a TM value of: %s\r\n", debugName.c_str()); __nameCounter += 1; JS_GC(TraceMonkeyEngine::context); // XXX For debugging purposes Logging::log(Logging::INFO, "post-creation GC ok.\r\n"); }
GC(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { JSRuntime *rt; uint32 preBytes; rt = cx->runtime; preBytes = rt->gcBytes; JS_GC(cx); fprintf(gOutFile, "before %lu, after %lu, break %08lx\n", (unsigned long)preBytes, (unsigned long)rt->gcBytes, #ifdef XP_UNIX (unsigned long)sbrk(0) #else 0 #endif ); #ifdef JS_GCMETER js_DumpGCStats(rt, stdout); #endif return JS_TRUE; }
cl_mem dpoCContext::CreateBuffer(JSContext *cx, cl_mem_flags flags, size_t size, void *ptr, cl_int *err) { #ifdef INCREMENTAL_MEM_RELEASE int freed; cl_mem result; bool didGC = false; do { freed = CheckFree(); result = clCreateBuffer(context, flags, size, ptr, err); if ((*err != CL_OUT_OF_HOST_MEMORY) && (*err != CL_MEM_OBJECT_ALLOCATION_FAILURE) && (*err != CL_OUT_OF_RESOURCES)) break; if (!freed && !didGC) { JS_GC(JS_GetRuntime(cx)); didGC = freed = true; } } while (freed); return result; #else /* INCREMENTAL_MEM_RELEASE */ return clCreateBuffer(context, flags, size, ptr, err); #endif /* INCREMENTAL_MEM_RELEASE */ }
NS_IMETHODIMP nsJSSh::Cleanup() { nsCOMPtr<nsIXPConnect> xpc = do_GetService(nsIXPConnect::GetCID()); if (!xpc) { NS_ERROR("failed to get xpconnect service"); return NS_ERROR_FAILURE; } { JSAutoRequest ar(mJSContext); if (mContextObj != mGlobal) JS_RemoveRoot(mJSContext, &(mContextObj)); JS_ClearScope(mJSContext, mGlobal); JS_GC(mJSContext); } JS_DestroyContext(mJSContext); return NS_OK; }