OutputEntry createOutputEntry(TraceEntry te) {
   BdynCallback cb = bdyn_factory.getCallback(te.getEntryLocation());
   OutputEntry oe = new OutputEntry(te.getTime(), 0, this, current_transaction, cb);
   if (te.getUseCount() > 1) oe.setUse(te.getUseCount(), te.getFractionUsed());
   output_set.add(oe);
   if (trace_writer != null)
     trace_writer.println(
         "START " + cb.getId() + " " + nest_level + " " + te.getTime() + " " + oe.hashCode());
   return oe;
 }
  private BdynRangeSet addToRange(long start, long t0, long t1, BdynRangeSet rslt) {
    OutputEntry timee = new OutputEntry(start);
    SortedSet<OutputEntry> ss = output_set.tailSet(timee);
    for (OutputEntry e1 : ss) {
      if (e1.getStartTime() > t1) break;
      if (e1.getEndTime(t1) >= t0) {
        ThreadData td = e1.getThread();
        if (rslt == null) rslt = new BdynRangeSet();
        Set<BdynEntry> r1 = rslt.get(td);
        if (r1 == null) {
          r1 = new HashSet<BdynEntry>();
          rslt.put(td, r1);
        }
        r1.add(e1);
      }
    }

    return rslt;
  }
 void mergeWith(OutputEntry oe) {
   num_traces += oe.num_traces;
   double tot = getTotalTime(0) + oe.getTotalTime(0);
   finish_time = oe.finish_time;
   trace_fraction = ((float) (tot / (finish_time - start_time)));
 }
    void beginTask(TraceEntry te) {
      BdynCallback cb = bdyn_factory.getCallback(te.getEntryLocation());
      if (cb == null) return;

      if (trace_writer != null)
        trace_writer.println(
            "PROCESS " + te.getEntryLocation() + " " + te.isExit() + " " + te.getTime());

      if (current_transaction == null) {
        OutputTask ot = null;
        if (te.isExit()) return;
        int i0 = te.getObject1();
        int i1 = te.getObject2();
        if (i0 != 0) {
          ot = object_tasks.get(i0);
          if (ot == dummy_task) ot = null;
        }
        if (ot == null) {
          if (i1 != 0) {
            ot = object_tasks.get(i1);
            if (ot == dummy_task) ot = null;
          }
        }
        if (ot == null) {
          ot = new OutputTask(++task_counter, cb);
        }
        current_transaction = ot;
        nest_level = 0;
      }
      if (!te.isExit()) {
        OutputEntry oe = null;
        if (nest_level == 0) {
          oe = createOutputEntry(te);
        } else if (cb.getCallbackType() == CallbackType.KEY
            && BdynFactory.getOptions().useKeyCallback()) {
          for (int i = output_stack.size() - 1; i >= 0; --i) {
            OutputEntry poe = output_stack.get(i);
            if (poe != null) {
              poe.finishAt(te.getTime());
              if (trace_writer != null)
                trace_writer.println(
                    "FINISHINT "
                        + poe.getEntryTask().getId()
                        + " "
                        + nest_level
                        + " "
                        + poe.getTotalTime(0)
                        + " "
                        + poe.hashCode());
              break;
            }
          }
          oe = createOutputEntry(te);
        } else {
          if (trace_writer != null) trace_writer.println("IGNORE " + cb.getId() + " " + nest_level);
          // System.err.println("TRACE: Ignore " + cb.getDisplayName() + " " + nest_level);
        }
        output_stack.push(oe);
        active_threads.add(this);
        ++nest_level;
      } else {
        if (nest_level <= 0) {
          return;
        }
        --nest_level;
        OutputEntry oe = output_stack.pop();
        if (oe != null) {
          // TODO: max_delta doesn't take into account calls that haven't ended yet
          max_delta = Math.max(max_delta, te.getTime() - oe.getStartTime());
          oe.finishAt(te.getTime());
          if (trace_writer != null)
            trace_writer.println(
                "FINISH "
                    + oe.getEntryTask().getId()
                    + " "
                    + nest_level
                    + " "
                    + oe.getTotalTime(0)
                    + " "
                    + oe.hashCode());
          if (!oe.isRelevant()) {
            output_set.remove(oe);
            if (trace_writer != null)
              trace_writer.println("REMOVE KEY " + oe.getEntryTask().getId() + " " + nest_level);
            // System.err.println("REMOVE KEY " + oe.getEntryTask().getDisplayName());
            oe = null;
            for (int i = output_stack.size() - 1; i >= 0; --i) {
              OutputEntry poe = output_stack.get(i);
              if (poe != null) {
                poe.finishAt(0);
                if (trace_writer != null)
                  trace_writer.println(
                      "NO END "
                          + poe.getEntryTask().getId()
                          + " "
                          + nest_level
                          + " "
                          + poe.hashCode());
                break;
              }
            }
          }
        }

        if (last_entry != null
            && oe != null
            && last_entry.getEntryTask() == oe.getEntryTask()
            && (te.getTime() - last_entry.getStartTime()) < MERGE_TIME) {
          last_entry.mergeWith(oe);
          output_set.remove(oe);
          if (trace_writer != null)
            trace_writer.println("MERGE KEY " + oe.getEntryTask().getId() + " " + nest_level);
          // System.err.println("REMOVE " + oe.getEntryTask().getDisplayName());
        }

        if (oe != null) last_entry = oe;

        if (nest_level == 0) endTask();
        else if (oe != null) {
          for (int i = output_stack.size() - 1; i >= 0; --i) {
            OutputEntry poe = output_stack.get(i);
            if (poe != null) {
              if (!poe.isSignificant()) {
                output_set.remove(poe);
              }
              if (trace_writer != null)
                trace_writer.println(
                    "NEST KEY "
                        + poe.getEntryTask().getId()
                        + " "
                        + nest_level
                        + " "
                        + poe.isSignificant());
              oe = new OutputEntry(te.getTime(), 0, this, current_transaction, poe.getEntryTask());
              oe.setDeletable();
              output_set.add(oe);
              output_stack.set(i, oe);
              break;
            }
          }
        }
      }
    }