Exemple #1
0
  public static IRubyObject INTERPRET_METHOD(
      ThreadContext context,
      InterpretedIRMethod irMethod,
      IRubyObject self,
      String name,
      IRubyObject[] args,
      Block block,
      Block.Type blockType,
      boolean isTraceable) {
    Ruby runtime = context.runtime;
    IRScope scope = irMethod.getIRMethod();
    RubyModule implClass = irMethod.getImplementationClass();
    Visibility viz = irMethod.getVisibility();
    boolean syntheticMethod = name == null || name.equals("");

    try {
      if (!syntheticMethod)
        ThreadContext.pushBacktrace(context, name, scope.getFileName(), context.getLine());
      if (isTraceable) methodPreTrace(runtime, context, name, implClass);
      return interpret(context, self, scope, viz, implClass, args, block, blockType);
    } finally {
      if (isTraceable) {
        try {
          methodPostTrace(runtime, context, name, implClass);
        } finally {
          if (!syntheticMethod) ThreadContext.popBacktrace(context);
        }
      } else {
        if (!syntheticMethod) ThreadContext.popBacktrace(context);
      }
    }
  }
Exemple #2
0
 public static IRubyObject INTERPRET_BLOCK(
     ThreadContext context,
     IRubyObject self,
     IRScope scope,
     IRubyObject[] args,
     String name,
     Block block,
     Block.Type blockType) {
   try {
     ThreadContext.pushBacktrace(context, name, scope.getFileName(), context.getLine());
     return interpret(context, self, scope, null, null, args, block, blockType);
   } finally {
     ThreadContext.popBacktrace(context);
   }
 }
Exemple #3
0
 public String getFile() {
   return method.getFileName();
 }
Exemple #4
0
  private static void outputProfileStats() {
    ArrayList<IRScope> scopes = new ArrayList<IRScope>(scopeThreadPollCounts.keySet());
    Collections.sort(
        scopes,
        new java.util.Comparator<IRScope>() {
          @Override
          public int compare(IRScope a, IRScope b) {
            // In non-methods and non-closures, we may not have any thread poll instrs.
            int aden = a.getThreadPollInstrsCount();
            if (aden == 0) aden = 1;
            int bden = b.getThreadPollInstrsCount();
            if (bden == 0) bden = 1;

            // Use estimated instr count to order scopes -- rather than raw thread-poll count
            float aCount =
                scopeThreadPollCounts.get(a).count
                    * (1.0f * a.getInstrsForInterpretation().length / aden);
            float bCount =
                scopeThreadPollCounts.get(b).count
                    * (1.0f * b.getInstrsForInterpretation().length / bden);
            if (aCount == bCount) return 0;
            return (aCount < bCount) ? 1 : -1;
          }
        });

    /*
    LOG.info("------------------------");
    LOG.info("Stats after " + globalThreadPollCount + " thread polls:");
    LOG.info("------------------------");
    LOG.info("# instructions: " + interpInstrsCount);
    LOG.info("# code modifications in this period : " + codeModificationsCount);
    LOG.info("------------------------");
    */
    int i = 0;
    float f1 = 0.0f;
    for (IRScope s : scopes) {
      long n = scopeThreadPollCounts.get(s).count;
      float p1 = ((n * 1000) / globalThreadPollCount) / 10.0f;
      String msg =
          i
              + ". "
              + s
              + " [file:"
              + s.getFileName()
              + ":"
              + s.getLineNumber()
              + "] = "
              + n
              + "; ("
              + p1
              + "%)";
      if (s instanceof IRClosure) {
        IRMethod m = s.getNearestMethod();
        // if (m != null) LOG.info(msg + " -- nearest enclosing method: " + m);
        // else LOG.info(msg + " -- no enclosing method --");
      } else {
        // LOG.info(msg);
      }

      i++;
      f1 += p1;

      // Top 20 or those that account for 95% of thread poll events.
      if (i == 20 || f1 >= 95.0) break;
    }

    // reset code modification counter
    codeModificationsCount = 0;

    // Every 1M thread polls, discard stats by reallocating the thread-poll count map
    if (globalThreadPollCount % 1000000 == 0) {
      // System.out.println("---- resetting thread-poll counters ----");
      scopeThreadPollCounts = new HashMap<IRScope, Counter>();
      globalThreadPollCount = 0;
    }
  }