/**
  * Unpin the a given list of variables by setting their "cleanup" status to the values specified
  * by <code>varsStats</code>.
  *
  * <p>Typical usage: <code>
  *    oldStatus = pinVariables(varList);
  *    ...
  *    unpinVariables(varList, oldStatus);
  *    </code> i.e., a call to unpinVariables() is preceded by pinVariables().
  *
  * @param varList variable list
  * @param varsState variable state
  */
 public void unpinVariables(ArrayList<String> varList, HashMap<String, Boolean> varsState) {
   for (String var : varList) {
     // System.out.println("unpin "+var+" ("+varsState.get(var)+")");
     Data dat = _variables.get(var);
     if (dat instanceof MatrixObject) ((MatrixObject) dat).enableCleanup(varsState.get(var));
   }
 }
  /**
   * Pin a given list of variables i.e., set the "clean up" state in corresponding matrix objects,
   * so that the cached data inside these objects is not cleared and the corresponding HDFS files
   * are not deleted (through rmvar instructions).
   *
   * <p>This is necessary for: function input variables, parfor result variables, parfor shared
   * inputs that are passed to functions.
   *
   * <p>The function returns the OLD "clean up" state of matrix objects.
   *
   * @param varList variable list
   * @return map of old cleanup state of matrix objects
   */
  public HashMap<String, Boolean> pinVariables(ArrayList<String> varList) {
    // 2-pass approach since multiple vars might refer to same matrix object
    HashMap<String, Boolean> varsState = new HashMap<String, Boolean>();

    // step 1) get current information
    for (String var : varList) {
      Data dat = _variables.get(var);
      if (dat instanceof MatrixObject) {
        MatrixObject mo = (MatrixObject) dat;
        varsState.put(var, mo.isCleanupEnabled());
        // System.out.println("pre-pin "+var+" ("+mo.isCleanupEnabled()+")");
      }
    }

    // step 2) pin variables
    for (String var : varList) {
      Data dat = _variables.get(var);
      if (dat instanceof MatrixObject) {
        MatrixObject mo = (MatrixObject) dat;
        mo.enableCleanup(false);
        // System.out.println("pin "+var);
      }
    }

    return varsState;
  }