Example #1
0
function next(test) {
  // Bug 719185: Have to GC in order to work aroung bug:
  // "Failed to remove trash directory when installing unit-test-addon@jetpack:
  // Component returned failure code: 0x80520015
  // (NS_ERROR_FILE_ACCESS_DENIED) [nsIFile.remove]
  // resource:///modules/XPIProvider.jsm :: recursiveRemove :: line 1233
  Cu.forceGC();
  test.done();
}
Example #2
0
function gc() {
  let { promise, resolve } = defer();

  Cu.forceGC();
  memory.gc();

  Cu.schedulePreciseGC(_ => resolve());

  return promise;
}
Example #3
0
function cleanup() {
  let coverObject = {};
  try {
    loader.unload();

    if (loader.globals.console.errorsLogged && !results.failed) {
      results.failed++;
      console.error("warnings and/or errors were logged.");
    }

    if (consoleListener.errorsLogged && !results.failed) {
      console.warn(consoleListener.errorsLogged + " " +
                   "warnings or errors were logged to the " +
                   "platform's nsIConsoleService, which could " +
                   "be of no consequence; however, they could also " +
                   "be indicative of aberrant behavior.");
    }

    // read the code coverage object, if it exists, from CoverJS-moz
    if (typeof loader.globals.global == "object") {
      coverObject = loader.globals.global['__$coverObject'] || {};
    }

    consoleListener.errorsLogged = 0;
    loader = null;

    consoleListener.unregister();

    Cu.forceGC();
  }
  catch (e) {
    results.failed++;
    console.error("unload.send() threw an exception.");
    console.exception(e);
  };

  setTimeout(require("./options").checkMemory ? checkMemory : showResults, 1);

  // dump the coverobject
  if (Object.keys(coverObject).length){
    const self = require('sdk/self');
    const {pathFor} = require("sdk/system");
    let file = require('sdk/io/file');
    const {env} = require('sdk/system/environment');
    console.log("CWD:", env.PWD);
    let out = file.join(env.PWD,'coverstats-'+self.id+'.json');
    console.log('coverstats:', out);
    let outfh = file.open(out,'w');
    outfh.write(JSON.stringify(coverObject,null,2));
    outfh.flush();
    outfh.close();
  }
}
Example #4
0
  return new Promise(resolve => {
    Cu.forceGC();
    Cu.forceCC();
    let count = 0;
    function genGCCallback() {
      Cu.forceCC();
      return function() {
        if (++count < 5) {
          Cu.schedulePreciseGC(genGCCallback());
        } else {
          resolve();
        }
      }
    }

    Cu.schedulePreciseGC(genGCCallback());
  });
Example #5
0
 forceGarbageCollection: function() {
   for (let i = 0; i < 3; i++) {
     Cu.forceGC();
   }
 },
Example #6
0
 gc: () => {
   os.notifyObservers(null, 'child-gc-request', null);
   Cu.forceGC();
   notify(GCcompleted, app);
 },
Example #7
0
function forceGC() {
    Cu.forceGC();
    os.notifyObservers(null, 'child-gc-request', null);
}
Example #8
0
function getPotentialLeaks() {
  Cu.forceGC();

  // Things we can assume are part of the platform and so aren't leaks
  let GOOD_BASE_URLS = [
    "chrome://",
    "resource:///",
    "resource://app/",
    "resource://gre/",
    "resource://gre-resources/",
    "resource://pdf.js/",
    "resource://pdf.js.components/",
    "resource://services-common/",
    "resource://services-crypto/",
    "resource://services-sync/"
  ];

  let ioService = Cc["@mozilla.org/network/io-service;1"].
                 getService(Ci.nsIIOService);
  let uri = ioService.newURI("chrome://global/content/", "UTF-8");
  let chromeReg = Cc["@mozilla.org/chrome/chrome-registry;1"].
                  getService(Ci.nsIChromeRegistry);
  uri = chromeReg.convertChromeURL(uri);
  let spec = uri.spec;
  let pos = spec.indexOf("!/");
  GOOD_BASE_URLS.push(spec.substring(0, pos + 2));

  let zoneRegExp = new RegExp("^explicit/js-non-window/zones/zone[^/]+/compartment\\((.+)\\)");
  let compartmentRegexp = new RegExp("^explicit/js-non-window/compartments/non-window-global/compartment\\((.+)\\)/");
  let compartmentDetails = new RegExp("^([^,]+)(?:, (.+?))?(?: \\(from: (.*)\\))?$");
  let windowRegexp = new RegExp("^explicit/window-objects/top\\((.*)\\)/active");
  let windowDetails = new RegExp("^(.*), id=.*$");

  function isPossibleLeak(item) {
    if (!item.location)
      return false;

    for (let url of GOOD_BASE_URLS) {
      if (item.location.substring(0, url.length) == url) {
        return false;
      }
    }

    return true;
  }

  let compartments = {};
  let windows = {};
  function logReporter(process, path, kind, units, amount, description) {
    let matches;

    if ((matches = compartmentRegexp.exec(path)) || (matches = zoneRegExp.exec(path))) {
      if (matches[1] in compartments)
        return;

      let details = compartmentDetails.exec(matches[1]);
      if (!details) {
        console.error("Unable to parse compartment detail " + matches[1]);
        return;
      }

      let item = {
        path: matches[1],
        principal: details[1],
        location: details[2] ? details[2].replace(/\\/g, "/") : undefined,
        source: details[3] ? details[3].split(" -> ").reverse() : undefined,
        toString: function() {
          return this.location;
        }
      };

      if (!isPossibleLeak(item))
        return;

      compartments[matches[1]] = item;
      return;
    }

    if ((matches = windowRegexp.exec(path))) {
      if (matches[1] in windows)
        return;

      let details = windowDetails.exec(matches[1]);
      if (!details) {
        console.error("Unable to parse window detail " + matches[1]);
        return;
      }

      let item = {
        path: matches[1],
        location: details[1].replace(/\\/g, "/"),
        source: [details[1].replace(/\\/g, "/")],
        toString: function() {
          return this.location;
        }
      };

      if (!isPossibleLeak(item))
        return;

      windows[matches[1]] = item;
    }
  }

  Cc["@mozilla.org/memory-reporter-manager;1"]
    .getService(Ci.nsIMemoryReporterManager)
    .getReportsForThisProcess(logReporter, null, /* anonymize = */ false);

  return { compartments: compartments, windows: windows };
}