JDK-4675952 : java.util.regex routines should use less stack space
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.util.regex
  • Affected Version: 1.4.1
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • OS: generic
  • CPU: x86
  • Submitted: 2002-04-26
  • Updated: 2006-12-17
Related Reports
Relates :  
Description
The following magic program breaks on most x86 platforms.

Sparc 32-bit:----------
Runs with 6meg of stack; dies with stackoverflow with 4meg for both client and server, -Xint more or -Xmixed.

WinNT:----------
Dies with stackoverflow for both client & server, in mixed and -Xint modes for both, up to -Xss128m.

At -Xss256m, client -Xint crashes; server -Xint gets a 
Fatal: Unable to create signal thread (may be due to resource limit)

Linux:-----------
RUNS -client with no other stack options.
Dies with -client -Xint with stackoverflow.
Dies with -client -Xint -Xss128meg with stackoverflow.
Dies with -server, -server -Xint, -server -Xint -Xss128meg, -server -Xss128meg with stack overflow

SolX86:-----------
Runs with 4meg of stack; dies with stackoverflow with 4meg for both client and server, -Xint more or -Xmixed.

###@###.### 2002-04-26


import java.util.regex.*;
public class JavaBenchmark {
 public static void main(String [] args)
 {
   Matcher Regex1 = Pattern.compile("^(a|b|c|d|e|f|g)+$").matcher("");
   Matcher Regex2 = Pattern.compile("^[a-g]+$").matcher("");
   long TimesToDo = 2000;

   StringBuffer Temp = new StringBuffer();
   for (int i = 500; i > 0; i--)
           Temp.append("abababdedfg");
   String TestString = Temp.toString();

   // Time first one...
   long Count = TimesToDo;
   long StartTime = System.currentTimeMillis();
   while (--Count > 0)
         Regex1.reset(TestString).matches();
   double Seconds = (System.currentTimeMillis()-StartTime)/1000.0;
   System.out.println("Alternation takes " + Seconds + " seconds");

   // Time second one...
   Count = TimesToDo;
   StartTime = System.currentTimeMillis();
   while (--Count > 0)
         Regex2.reset(TestString).matches();
   Seconds = (System.currentTimeMillis()-StartTime)/1000.0;
   System.out.println("Character Class takes " + Seconds + " seconds");
 }
}

Comments
EVALUATION ###@###.### 2002-05-22 Transferring this bug from hotspot to classes_util_regex; the problem is that the regex routines use too much stack space. Created a separate bug (4689767) for the strange behavior of -Xss<N> on windows & linux. The program runs on linux with -client because on RH6.x, the default stack size is 2MB. It overflows the stack with -Xint on RH6.x, but -Xint stack frames are larger. A modified copy of the example which can run in a separate thread is attached as badregex.java; use 'java badregex -t' to run in a separate thread. See the eval of 4689767 for the reasons that testing should _not_ be done in the main thread. Since this bug is fragmenting into multiple bugs I am changing the synopsis and priority as appropriate for this fragment. This is not going to be fixed for hopper. ###@###.### 2002-05-22
22-05-2002