int interpreter = 0;
int internal = 0;
  private static StackTraceElement[] sanitizeStack(StackTraceElement[] elements,						   Throwable t)  {    StackTraceElement[] stack;    String className = t.getClass().getName();    String consName;    int lastDot = className.lastIndexOf('.');    if (lastDot == -1)      consName = className + '(';    else      consName = className.substring(lastDot + 1) + '(';    int unknown = 0;    int interpreter = 0;    int last_throw = -1;    int length = elements.length;    int end = length-1;    for (int i = 0; i < length; i++)      {	String CName = elements[i].getClassName();	String MName = elements[i].getMethodName();	if ((CName == null && MName != null && MName.startsWith("_Jv_Throw"))	  ||	   (CName != null	    && (CName.equals(className)		|| CName.equals("java.lang.Throwable")		|| CName.equals("java.lang.VMThrowable"))	    && MName != null	    && (MName.startsWith(consName)		|| MName.startsWith("Throwable(")		|| MName.startsWith("fillInStackTrace("))))	  {	    last_throw = i;	    // Reset counting of unknown and interpreter frames.	    unknown = 0;	    interpreter = 0;	  }	else if (remove_unknown && CName == null 		 && (MName == null || MName.startsWith("0x")))	  unknown++;	else if (remove_interpreter		 && ((CName == null		      && MName != null && MName.startsWith("ffi_"))		     || (CName != null && CName.equals("_Jv_InterpMethod"))))	  interpreter++;	else if ("main(java.lang.String[])".equals(MName))	  {	    end = i;	    break;	  }      }    int begin = last_throw+1;    // Now filter out everything at the start and the end that is not part    // of the "normal" user program including any elements that are interpreter    // calls or have no usefull information whatsoever.    // Unless that means we filter out all info.    int nr_elements = end-begin-unknown-interpreter+1;    if ((begin > 0 || end < length-1 || unknown > 0 || interpreter > 0)	&& nr_elements > 0)      {	stack = new StackTraceElement[nr_elements];	int pos =0;	for (int i=begin; i<=end; i++)	  {	    String MName = elements[i].getMethodName();	    String CName = elements[i].getClassName();	    if (remove_unknown && CName == null 		 && (MName == null || MName.startsWith("0x")))	      ; // Skip unknown frame	    else if (remove_interpreter		     && ((CName == null			 && MName != null && MName.startsWith("ffi_"))			|| (CName != null && CName.equals("_Jv_InterpMethod"))))	      ; // Skip interpreter runtime frame	    else	      {		stack[pos] = elements[i];		pos++;	      }	  }      }    else      stack = elements;    return stack;  }